mach-rx1950.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /* linux/arch/arm/mach-s3c2440/mach-rx1950.c
  2. *
  3. * Copyright (c) 2006-2009 Victor Chukhantsev, Denis Grigoriev,
  4. * Copyright (c) 2007-2010 Vasily Khoruzhick
  5. *
  6. * based on smdk2440 written by Ben Dooks
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/list.h>
  17. #include <linux/delay.h>
  18. #include <linux/timer.h>
  19. #include <linux/init.h>
  20. #include <linux/gpio.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/serial_core.h>
  23. #include <linux/input.h>
  24. #include <linux/gpio_keys.h>
  25. #include <linux/sysdev.h>
  26. #include <linux/pwm_backlight.h>
  27. #include <linux/pwm.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <linux/mtd/partitions.h>
  30. #include <linux/mmc/host.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/map.h>
  33. #include <asm/mach-types.h>
  34. #include <mach/regs-gpio.h>
  35. #include <mach/regs-gpioj.h>
  36. #include <mach/h1940.h>
  37. #include <mach/fb.h>
  38. #include <plat/clock.h>
  39. #include <plat/regs-serial.h>
  40. #include <plat/regs-iic.h>
  41. #include <plat/mci.h>
  42. #include <plat/udc.h>
  43. #include <plat/nand.h>
  44. #include <plat/iic.h>
  45. #include <plat/devs.h>
  46. #include <plat/cpu.h>
  47. #include <plat/pm.h>
  48. #include <plat/irq.h>
  49. #include <plat/ts.h>
  50. #define LCD_PWM_PERIOD 192960
  51. #define LCD_PWM_DUTY 127353
  52. static struct map_desc rx1950_iodesc[] __initdata = {
  53. };
  54. static struct s3c24xx_uart_clksrc rx1950_serial_clocks[] = {
  55. [0] = {
  56. .name = "fclk",
  57. .divisor = 0x0a,
  58. .min_baud = 0,
  59. .max_baud = 0,
  60. },
  61. };
  62. static struct s3c2410_uartcfg rx1950_uartcfgs[] __initdata = {
  63. [0] = {
  64. .hwport = 0,
  65. .flags = 0,
  66. .ucon = 0x3c5,
  67. .ulcon = 0x03,
  68. .ufcon = 0x51,
  69. .clocks = rx1950_serial_clocks,
  70. .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
  71. },
  72. [1] = {
  73. .hwport = 1,
  74. .flags = 0,
  75. .ucon = 0x3c5,
  76. .ulcon = 0x03,
  77. .ufcon = 0x51,
  78. .clocks = rx1950_serial_clocks,
  79. .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
  80. },
  81. /* IR port */
  82. [2] = {
  83. .hwport = 2,
  84. .flags = 0,
  85. .ucon = 0x3c5,
  86. .ulcon = 0x43,
  87. .ufcon = 0xf1,
  88. .clocks = rx1950_serial_clocks,
  89. .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
  90. },
  91. };
  92. static struct s3c2410fb_display rx1950_display = {
  93. .type = S3C2410_LCDCON1_TFT,
  94. .width = 240,
  95. .height = 320,
  96. .xres = 240,
  97. .yres = 320,
  98. .bpp = 16,
  99. .pixclock = 260000,
  100. .left_margin = 10,
  101. .right_margin = 20,
  102. .hsync_len = 10,
  103. .upper_margin = 2,
  104. .lower_margin = 2,
  105. .vsync_len = 2,
  106. .lcdcon5 = S3C2410_LCDCON5_FRM565 |
  107. S3C2410_LCDCON5_INVVCLK |
  108. S3C2410_LCDCON5_INVVLINE |
  109. S3C2410_LCDCON5_INVVFRAME |
  110. S3C2410_LCDCON5_HWSWP |
  111. (0x02 << 13) |
  112. (0x02 << 15),
  113. };
  114. static struct s3c2410fb_mach_info rx1950_lcd_cfg = {
  115. .displays = &rx1950_display,
  116. .num_displays = 1,
  117. .default_display = 0,
  118. .lpcsel = 0x02,
  119. .gpccon = 0xaa9556a9,
  120. .gpccon_mask = 0xffc003fc,
  121. .gpcup = 0x0000ffff,
  122. .gpcup_mask = 0xffffffff,
  123. .gpdcon = 0xaa90aaa1,
  124. .gpdcon_mask = 0xffc0fff0,
  125. .gpdup = 0x0000fcfd,
  126. .gpdup_mask = 0xffffffff,
  127. };
  128. static struct pwm_device *lcd_pwm;
  129. void rx1950_lcd_power(int enable)
  130. {
  131. int i;
  132. static int enabled;
  133. if (enabled == enable)
  134. return;
  135. if (!enable) {
  136. /* GPC11-GPC15->OUTPUT */
  137. for (i = 11; i < 16; i++)
  138. gpio_direction_output(S3C2410_GPC(i), 1);
  139. /* Wait a bit here... */
  140. mdelay(100);
  141. /* GPD2-GPD7->OUTPUT */
  142. /* GPD11-GPD15->OUTPUT */
  143. /* GPD2-GPD7->1, GPD11-GPD15->1 */
  144. for (i = 2; i < 8; i++)
  145. gpio_direction_output(S3C2410_GPD(i), 1);
  146. for (i = 11; i < 16; i++)
  147. gpio_direction_output(S3C2410_GPD(i), 1);
  148. /* Wait a bit here...*/
  149. mdelay(100);
  150. /* GPB0->OUTPUT, GPB0->0 */
  151. gpio_direction_output(S3C2410_GPB(0), 0);
  152. /* GPC1-GPC4->OUTPUT, GPC1-4->0 */
  153. for (i = 1; i < 5; i++)
  154. gpio_direction_output(S3C2410_GPC(i), 0);
  155. /* GPC15-GPC11->0 */
  156. for (i = 11; i < 16; i++)
  157. gpio_direction_output(S3C2410_GPC(i), 0);
  158. /* GPD15-GPD11->0, GPD2->GPD7->0 */
  159. for (i = 11; i < 16; i++)
  160. gpio_direction_output(S3C2410_GPD(i), 0);
  161. for (i = 2; i < 8; i++)
  162. gpio_direction_output(S3C2410_GPD(i), 0);
  163. /* GPC6->0, GPC7->0, GPC5->0 */
  164. gpio_direction_output(S3C2410_GPC(6), 0);
  165. gpio_direction_output(S3C2410_GPC(7), 0);
  166. gpio_direction_output(S3C2410_GPC(5), 0);
  167. /* GPB1->OUTPUT, GPB1->0 */
  168. gpio_direction_output(S3C2410_GPB(1), 0);
  169. pwm_config(lcd_pwm, 0, LCD_PWM_PERIOD);
  170. pwm_disable(lcd_pwm);
  171. /* GPC0->0, GPC10->0 */
  172. gpio_direction_output(S3C2410_GPC(0), 0);
  173. gpio_direction_output(S3C2410_GPC(10), 0);
  174. } else {
  175. pwm_config(lcd_pwm, LCD_PWM_DUTY, LCD_PWM_PERIOD);
  176. pwm_enable(lcd_pwm);
  177. gpio_direction_output(S3C2410_GPC(0), 1);
  178. gpio_direction_output(S3C2410_GPC(5), 1);
  179. s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1);
  180. gpio_direction_output(S3C2410_GPC(7), 1);
  181. for (i = 1; i < 5; i++)
  182. s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2));
  183. for (i = 11; i < 16; i++)
  184. s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2));
  185. for (i = 2; i < 8; i++)
  186. s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2));
  187. for (i = 11; i < 16; i++)
  188. s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2));
  189. gpio_direction_output(S3C2410_GPC(10), 1);
  190. gpio_direction_output(S3C2410_GPC(6), 1);
  191. }
  192. enabled = enable;
  193. }
  194. static void rx1950_bl_power(int enable)
  195. {
  196. static int enabled;
  197. if (enabled == enable)
  198. return;
  199. if (!enable) {
  200. gpio_direction_output(S3C2410_GPB(0), 0);
  201. } else {
  202. /* LED driver need a "push" to power on */
  203. gpio_direction_output(S3C2410_GPB(0), 1);
  204. /* Warm up backlight for one period of PWM.
  205. * Without this trick its almost impossible to
  206. * enable backlight with low brightness value
  207. */
  208. ndelay(48000);
  209. s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
  210. }
  211. enabled = enable;
  212. }
  213. static int rx1950_backlight_init(struct device *dev)
  214. {
  215. WARN_ON(gpio_request(S3C2410_GPB(0), "Backlight"));
  216. lcd_pwm = pwm_request(1, "RX1950 LCD");
  217. if (IS_ERR(lcd_pwm)) {
  218. dev_err(dev, "Unable to request PWM for LCD power!\n");
  219. return PTR_ERR(lcd_pwm);
  220. }
  221. rx1950_lcd_power(1);
  222. rx1950_bl_power(1);
  223. return 0;
  224. }
  225. static void rx1950_backlight_exit(struct device *dev)
  226. {
  227. rx1950_bl_power(0);
  228. rx1950_lcd_power(0);
  229. pwm_free(lcd_pwm);
  230. gpio_free(S3C2410_GPB(0));
  231. }
  232. static int rx1950_backlight_notify(struct device *dev, int brightness)
  233. {
  234. if (!brightness) {
  235. rx1950_bl_power(0);
  236. rx1950_lcd_power(0);
  237. } else {
  238. rx1950_lcd_power(1);
  239. rx1950_bl_power(1);
  240. }
  241. return brightness;
  242. }
  243. static struct platform_pwm_backlight_data rx1950_backlight_data = {
  244. .pwm_id = 0,
  245. .max_brightness = 24,
  246. .dft_brightness = 4,
  247. .pwm_period_ns = 48000,
  248. .init = rx1950_backlight_init,
  249. .notify = rx1950_backlight_notify,
  250. .exit = rx1950_backlight_exit,
  251. };
  252. static struct platform_device rx1950_backlight = {
  253. .name = "pwm-backlight",
  254. .dev = {
  255. .parent = &s3c_device_timer[0].dev,
  256. .platform_data = &rx1950_backlight_data,
  257. },
  258. };
  259. static void rx1950_set_mmc_power(unsigned char power_mode, unsigned short vdd)
  260. {
  261. switch (power_mode) {
  262. case MMC_POWER_OFF:
  263. gpio_direction_output(S3C2410_GPJ(1), 0);
  264. break;
  265. case MMC_POWER_UP:
  266. case MMC_POWER_ON:
  267. gpio_direction_output(S3C2410_GPJ(1), 1);
  268. break;
  269. default:
  270. break;
  271. }
  272. }
  273. static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata = {
  274. .gpio_detect = S3C2410_GPF(5),
  275. .gpio_wprotect = S3C2410_GPH(8),
  276. .set_power = rx1950_set_mmc_power,
  277. .ocr_avail = MMC_VDD_32_33,
  278. };
  279. static struct mtd_partition rx1950_nand_part[] = {
  280. [0] = {
  281. .name = "Boot0",
  282. .offset = 0,
  283. .size = 0x4000,
  284. .mask_flags = MTD_WRITEABLE,
  285. },
  286. [1] = {
  287. .name = "Boot1",
  288. .offset = MTDPART_OFS_APPEND,
  289. .size = 0x40000,
  290. .mask_flags = MTD_WRITEABLE,
  291. },
  292. [2] = {
  293. .name = "Kernel",
  294. .offset = MTDPART_OFS_APPEND,
  295. .size = 0x300000,
  296. .mask_flags = 0,
  297. },
  298. [3] = {
  299. .name = "Filesystem",
  300. .offset = MTDPART_OFS_APPEND,
  301. .size = MTDPART_SIZ_FULL,
  302. .mask_flags = 0,
  303. },
  304. };
  305. static struct s3c2410_nand_set rx1950_nand_sets[] = {
  306. [0] = {
  307. .name = "Internal",
  308. .nr_chips = 1,
  309. .nr_partitions = ARRAY_SIZE(rx1950_nand_part),
  310. .partitions = rx1950_nand_part,
  311. },
  312. };
  313. static struct s3c2410_platform_nand rx1950_nand_info = {
  314. .tacls = 25,
  315. .twrph0 = 50,
  316. .twrph1 = 15,
  317. .nr_sets = ARRAY_SIZE(rx1950_nand_sets),
  318. .sets = rx1950_nand_sets,
  319. };
  320. static void rx1950_udc_pullup(enum s3c2410_udc_cmd_e cmd)
  321. {
  322. switch (cmd) {
  323. case S3C2410_UDC_P_ENABLE:
  324. gpio_direction_output(S3C2410_GPJ(5), 1);
  325. break;
  326. case S3C2410_UDC_P_DISABLE:
  327. gpio_direction_output(S3C2410_GPJ(5), 0);
  328. break;
  329. case S3C2410_UDC_P_RESET:
  330. break;
  331. default:
  332. break;
  333. }
  334. }
  335. static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = {
  336. .udc_command = rx1950_udc_pullup,
  337. .vbus_pin = S3C2410_GPG(5),
  338. .vbus_pin_inverted = 1,
  339. };
  340. static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata = {
  341. .delay = 10000,
  342. .presc = 49,
  343. .oversampling_shift = 3,
  344. };
  345. static struct gpio_keys_button rx1950_gpio_keys_table[] = {
  346. {
  347. .code = KEY_POWER,
  348. .gpio = S3C2410_GPF(0),
  349. .active_low = 1,
  350. .desc = "Power button",
  351. .wakeup = 1,
  352. },
  353. {
  354. .code = KEY_F5,
  355. .gpio = S3C2410_GPF(7),
  356. .active_low = 1,
  357. .desc = "Record button",
  358. },
  359. {
  360. .code = KEY_F1,
  361. .gpio = S3C2410_GPG(0),
  362. .active_low = 1,
  363. .desc = "Calendar button",
  364. },
  365. {
  366. .code = KEY_F2,
  367. .gpio = S3C2410_GPG(2),
  368. .active_low = 1,
  369. .desc = "Contacts button",
  370. },
  371. {
  372. .code = KEY_F3,
  373. .gpio = S3C2410_GPG(3),
  374. .active_low = 1,
  375. .desc = "Mail button",
  376. },
  377. {
  378. .code = KEY_F4,
  379. .gpio = S3C2410_GPG(7),
  380. .active_low = 1,
  381. .desc = "WLAN button",
  382. },
  383. {
  384. .code = KEY_LEFT,
  385. .gpio = S3C2410_GPG(10),
  386. .active_low = 1,
  387. .desc = "Left button",
  388. },
  389. {
  390. .code = KEY_RIGHT,
  391. .gpio = S3C2410_GPG(11),
  392. .active_low = 1,
  393. .desc = "Right button",
  394. },
  395. {
  396. .code = KEY_UP,
  397. .gpio = S3C2410_GPG(4),
  398. .active_low = 1,
  399. .desc = "Up button",
  400. },
  401. {
  402. .code = KEY_DOWN,
  403. .gpio = S3C2410_GPG(6),
  404. .active_low = 1,
  405. .desc = "Down button",
  406. },
  407. {
  408. .code = KEY_ENTER,
  409. .gpio = S3C2410_GPG(9),
  410. .active_low = 1,
  411. .desc = "Ok button"
  412. },
  413. };
  414. static struct gpio_keys_platform_data rx1950_gpio_keys_data = {
  415. .buttons = rx1950_gpio_keys_table,
  416. .nbuttons = ARRAY_SIZE(rx1950_gpio_keys_table),
  417. };
  418. static struct platform_device rx1950_device_gpiokeys = {
  419. .name = "gpio-keys",
  420. .dev.platform_data = &rx1950_gpio_keys_data,
  421. };
  422. static struct s3c2410_platform_i2c rx1950_i2c_data = {
  423. .flags = 0,
  424. .slave_addr = 0x42,
  425. .frequency = 400 * 1000,
  426. .sda_delay = S3C2410_IICLC_SDA_DELAY5 | S3C2410_IICLC_FILTER_ON,
  427. };
  428. static struct platform_device *rx1950_devices[] __initdata = {
  429. &s3c_device_lcd,
  430. &s3c_device_wdt,
  431. &s3c_device_i2c0,
  432. &s3c_device_iis,
  433. &s3c_device_usbgadget,
  434. &s3c_device_rtc,
  435. &s3c_device_nand,
  436. &s3c_device_sdi,
  437. &s3c_device_adc,
  438. &s3c_device_ts,
  439. &s3c_device_timer[0],
  440. &s3c_device_timer[1],
  441. &rx1950_backlight,
  442. &rx1950_device_gpiokeys,
  443. };
  444. static struct clk *rx1950_clocks[] __initdata = {
  445. &s3c24xx_clkout0,
  446. &s3c24xx_clkout1,
  447. };
  448. static void __init rx1950_map_io(void)
  449. {
  450. s3c24xx_clkout0.parent = &clk_h;
  451. s3c24xx_clkout1.parent = &clk_f;
  452. s3c24xx_register_clocks(rx1950_clocks, ARRAY_SIZE(rx1950_clocks));
  453. s3c24xx_init_io(rx1950_iodesc, ARRAY_SIZE(rx1950_iodesc));
  454. s3c24xx_init_clocks(16934000);
  455. s3c24xx_init_uarts(rx1950_uartcfgs, ARRAY_SIZE(rx1950_uartcfgs));
  456. /* setup PM */
  457. #ifdef CONFIG_PM_H1940
  458. memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 8);
  459. #endif
  460. s3c_pm_init();
  461. }
  462. static void __init rx1950_init_machine(void)
  463. {
  464. int i;
  465. s3c24xx_fb_set_platdata(&rx1950_lcd_cfg);
  466. s3c24xx_udc_set_platdata(&rx1950_udc_cfg);
  467. s3c24xx_ts_set_platdata(&rx1950_ts_cfg);
  468. s3c24xx_mci_set_platdata(&rx1950_mmc_cfg);
  469. s3c_i2c0_set_platdata(&rx1950_i2c_data);
  470. s3c_nand_set_platdata(&rx1950_nand_info);
  471. /* Turn off suspend on both USB ports, and switch the
  472. * selectable USB port to USB device mode. */
  473. s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
  474. S3C2410_MISCCR_USBSUSPND0 |
  475. S3C2410_MISCCR_USBSUSPND1, 0x0);
  476. WARN_ON(gpio_request(S3C2410_GPJ(5), "UDC pullup"));
  477. gpio_direction_output(S3C2410_GPJ(5), 0);
  478. /* mmc power is disabled by default */
  479. WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power"));
  480. gpio_direction_output(S3C2410_GPJ(1), 0);
  481. for (i = 0; i < 8; i++)
  482. WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power"));
  483. for (i = 10; i < 16; i++)
  484. WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power"));
  485. for (i = 2; i < 8; i++)
  486. WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power"));
  487. for (i = 11; i < 16; i++)
  488. WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power"));
  489. WARN_ON(gpio_request(S3C2410_GPB(1), "LCD power"));
  490. platform_add_devices(rx1950_devices, ARRAY_SIZE(rx1950_devices));
  491. }
  492. MACHINE_START(RX1950, "HP iPAQ RX1950")
  493. /* Maintainers: Vasily Khoruzhick */
  494. .phys_io = S3C2410_PA_UART,
  495. .io_pg_offst = (((u32) S3C24XX_VA_UART) >> 18) & 0xfffc,
  496. .boot_params = S3C2410_SDRAM_PA + 0x100,
  497. .map_io = rx1950_map_io,
  498. .init_irq = s3c24xx_init_irq,
  499. .init_machine = rx1950_init_machine,
  500. .timer = &s3c24xx_timer,
  501. MACHINE_END