mach-rx1950.c 13 KB

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