mach-hmt.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* mach-hmt.c - Platform code for Airgoo HMT
  2. *
  3. * Copyright 2009 Peter Korsgaard <jacmet@sunsite.dk>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/serial_core.h>
  13. #include <linux/serial_s3c.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/io.h>
  16. #include <linux/i2c.h>
  17. #include <linux/fb.h>
  18. #include <linux/gpio.h>
  19. #include <linux/delay.h>
  20. #include <linux/leds.h>
  21. #include <linux/pwm.h>
  22. #include <linux/pwm_backlight.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/map.h>
  27. #include <asm/mach/irq.h>
  28. #include <video/samsung_fimd.h>
  29. #include <mach/hardware.h>
  30. #include <mach/map.h>
  31. #include <mach/irqs.h>
  32. #include <asm/irq.h>
  33. #include <asm/mach-types.h>
  34. #include <linux/platform_data/i2c-s3c2410.h>
  35. #include <mach/gpio-samsung.h>
  36. #include <plat/fb.h>
  37. #include <linux/platform_data/mtd-nand-s3c2410.h>
  38. #include <plat/devs.h>
  39. #include <plat/cpu.h>
  40. #include <plat/samsung-time.h>
  41. #include "common.h"
  42. #define UCON S3C2410_UCON_DEFAULT
  43. #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
  44. #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
  45. static struct s3c2410_uartcfg hmt_uartcfgs[] __initdata = {
  46. [0] = {
  47. .hwport = 0,
  48. .flags = 0,
  49. .ucon = UCON,
  50. .ulcon = ULCON,
  51. .ufcon = UFCON,
  52. },
  53. [1] = {
  54. .hwport = 1,
  55. .flags = 0,
  56. .ucon = UCON,
  57. .ulcon = ULCON,
  58. .ufcon = UFCON,
  59. },
  60. [2] = {
  61. .hwport = 2,
  62. .flags = 0,
  63. .ucon = UCON,
  64. .ulcon = ULCON,
  65. .ufcon = UFCON,
  66. },
  67. };
  68. static struct pwm_lookup hmt_pwm_lookup[] = {
  69. PWM_LOOKUP("samsung-pwm", 1, "pwm-backlight.0", NULL,
  70. 1000000000 / (100 * 256 * 20), PWM_POLARITY_NORMAL),
  71. };
  72. static int hmt_bl_init(struct device *dev)
  73. {
  74. int ret;
  75. ret = gpio_request(S3C64XX_GPB(4), "lcd backlight enable");
  76. if (!ret)
  77. ret = gpio_direction_output(S3C64XX_GPB(4), 0);
  78. return ret;
  79. }
  80. static int hmt_bl_notify(struct device *dev, int brightness)
  81. {
  82. /*
  83. * translate from CIELUV/CIELAB L*->brightness, E.G. from
  84. * perceived luminance to light output. Assumes range 0..25600
  85. */
  86. if (brightness < 0x800) {
  87. /* Y = Yn * L / 903.3 */
  88. brightness = (100*256 * brightness + 231245/2) / 231245;
  89. } else {
  90. /* Y = Yn * ((L + 16) / 116 )^3 */
  91. int t = (brightness*4 + 16*1024 + 58)/116;
  92. brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000);
  93. }
  94. gpio_set_value(S3C64XX_GPB(4), brightness);
  95. return brightness;
  96. }
  97. static void hmt_bl_exit(struct device *dev)
  98. {
  99. gpio_free(S3C64XX_GPB(4));
  100. }
  101. static struct platform_pwm_backlight_data hmt_backlight_data = {
  102. .max_brightness = 100 * 256,
  103. .dft_brightness = 40 * 256,
  104. .enable_gpio = -1,
  105. .init = hmt_bl_init,
  106. .notify = hmt_bl_notify,
  107. .exit = hmt_bl_exit,
  108. };
  109. static struct platform_device hmt_backlight_device = {
  110. .name = "pwm-backlight",
  111. .dev = {
  112. .parent = &samsung_device_pwm.dev,
  113. .platform_data = &hmt_backlight_data,
  114. },
  115. };
  116. static struct s3c_fb_pd_win hmt_fb_win0 = {
  117. .max_bpp = 32,
  118. .default_bpp = 16,
  119. .xres = 800,
  120. .yres = 480,
  121. };
  122. static struct fb_videomode hmt_lcd_timing = {
  123. .left_margin = 8,
  124. .right_margin = 13,
  125. .upper_margin = 7,
  126. .lower_margin = 5,
  127. .hsync_len = 3,
  128. .vsync_len = 1,
  129. .xres = 800,
  130. .yres = 480,
  131. };
  132. /* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
  133. static struct s3c_fb_platdata hmt_lcd_pdata __initdata = {
  134. .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
  135. .vtiming = &hmt_lcd_timing,
  136. .win[0] = &hmt_fb_win0,
  137. .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
  138. .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
  139. };
  140. static struct mtd_partition hmt_nand_part[] = {
  141. [0] = {
  142. .name = "uboot",
  143. .size = SZ_512K,
  144. .offset = 0,
  145. },
  146. [1] = {
  147. .name = "uboot-env1",
  148. .size = SZ_256K,
  149. .offset = SZ_512K,
  150. },
  151. [2] = {
  152. .name = "uboot-env2",
  153. .size = SZ_256K,
  154. .offset = SZ_512K + SZ_256K,
  155. },
  156. [3] = {
  157. .name = "kernel",
  158. .size = SZ_2M,
  159. .offset = SZ_1M,
  160. },
  161. [4] = {
  162. .name = "rootfs",
  163. .size = MTDPART_SIZ_FULL,
  164. .offset = SZ_1M + SZ_2M,
  165. },
  166. };
  167. static struct s3c2410_nand_set hmt_nand_sets[] = {
  168. [0] = {
  169. .name = "nand",
  170. .nr_chips = 1,
  171. .nr_partitions = ARRAY_SIZE(hmt_nand_part),
  172. .partitions = hmt_nand_part,
  173. },
  174. };
  175. static struct s3c2410_platform_nand hmt_nand_info = {
  176. .tacls = 25,
  177. .twrph0 = 55,
  178. .twrph1 = 40,
  179. .nr_sets = ARRAY_SIZE(hmt_nand_sets),
  180. .sets = hmt_nand_sets,
  181. };
  182. static struct gpio_led hmt_leds[] = {
  183. { /* left function keys */
  184. .name = "left:blue",
  185. .gpio = S3C64XX_GPO(12),
  186. .default_trigger = "default-on",
  187. },
  188. { /* right function keys - red */
  189. .name = "right:red",
  190. .gpio = S3C64XX_GPO(13),
  191. },
  192. { /* right function keys - green */
  193. .name = "right:green",
  194. .gpio = S3C64XX_GPO(14),
  195. },
  196. { /* right function keys - blue */
  197. .name = "right:blue",
  198. .gpio = S3C64XX_GPO(15),
  199. .default_trigger = "default-on",
  200. },
  201. };
  202. static struct gpio_led_platform_data hmt_led_data = {
  203. .num_leds = ARRAY_SIZE(hmt_leds),
  204. .leds = hmt_leds,
  205. };
  206. static struct platform_device hmt_leds_device = {
  207. .name = "leds-gpio",
  208. .id = -1,
  209. .dev.platform_data = &hmt_led_data,
  210. };
  211. static struct map_desc hmt_iodesc[] = {};
  212. static struct platform_device *hmt_devices[] __initdata = {
  213. &s3c_device_i2c0,
  214. &s3c_device_nand,
  215. &s3c_device_fb,
  216. &s3c_device_ohci,
  217. &samsung_device_pwm,
  218. &hmt_backlight_device,
  219. &hmt_leds_device,
  220. };
  221. static void __init hmt_map_io(void)
  222. {
  223. s3c64xx_init_io(hmt_iodesc, ARRAY_SIZE(hmt_iodesc));
  224. s3c64xx_set_xtal_freq(12000000);
  225. s3c24xx_init_uarts(hmt_uartcfgs, ARRAY_SIZE(hmt_uartcfgs));
  226. samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
  227. }
  228. static void __init hmt_machine_init(void)
  229. {
  230. s3c_i2c0_set_platdata(NULL);
  231. s3c_fb_set_platdata(&hmt_lcd_pdata);
  232. s3c_nand_set_platdata(&hmt_nand_info);
  233. gpio_request(S3C64XX_GPC(7), "usb power");
  234. gpio_direction_output(S3C64XX_GPC(7), 0);
  235. gpio_request(S3C64XX_GPM(0), "usb power");
  236. gpio_direction_output(S3C64XX_GPM(0), 1);
  237. gpio_request(S3C64XX_GPK(7), "usb power");
  238. gpio_direction_output(S3C64XX_GPK(7), 1);
  239. gpio_request(S3C64XX_GPF(13), "usb power");
  240. gpio_direction_output(S3C64XX_GPF(13), 1);
  241. pwm_add_table(hmt_pwm_lookup, ARRAY_SIZE(hmt_pwm_lookup));
  242. platform_add_devices(hmt_devices, ARRAY_SIZE(hmt_devices));
  243. }
  244. MACHINE_START(HMT, "Airgoo-HMT")
  245. /* Maintainer: Peter Korsgaard <jacmet@sunsite.dk> */
  246. .atag_offset = 0x100,
  247. .nr_irqs = S3C64XX_NR_IRQS,
  248. .init_irq = s3c6410_init_irq,
  249. .map_io = hmt_map_io,
  250. .init_machine = hmt_machine_init,
  251. .init_time = samsung_timer_init,
  252. .restart = s3c64xx_restart,
  253. MACHINE_END