mach-hmt.c 6.2 KB

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