mach-hmt.c 6.3 KB

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