mach-h1940.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. * Copyright (c) 2003-2005 Simtec Electronics
  3. * Ben Dooks <ben@simtec.co.uk>
  4. *
  5. * http://www.handhelds.org/projects/h1940.html
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/list.h>
  16. #include <linux/memblock.h>
  17. #include <linux/timer.h>
  18. #include <linux/init.h>
  19. #include <linux/device.h>
  20. #include <linux/serial_core.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/io.h>
  23. #include <linux/gpio.h>
  24. #include <linux/input.h>
  25. #include <linux/gpio_keys.h>
  26. #include <linux/pwm_backlight.h>
  27. #include <linux/i2c.h>
  28. #include <linux/leds.h>
  29. #include <linux/pda_power.h>
  30. #include <linux/s3c_adc_battery.h>
  31. #include <linux/delay.h>
  32. #include <video/platform_lcd.h>
  33. #include <linux/mmc/host.h>
  34. #include <linux/export.h>
  35. #include <asm/irq.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/map.h>
  39. #include <asm/mach/irq.h>
  40. #include <linux/platform_data/i2c-s3c2410.h>
  41. #include <linux/platform_data/mmc-s3cmci.h>
  42. #include <linux/platform_data/touchscreen-s3c2410.h>
  43. #include <linux/platform_data/usb-s3c2410_udc.h>
  44. #include <sound/uda1380.h>
  45. #include <mach/fb.h>
  46. #include <mach/hardware.h>
  47. #include <mach/regs-clock.h>
  48. #include <mach/regs-gpio.h>
  49. #include <mach/regs-lcd.h>
  50. #include <plat/clock.h>
  51. #include <plat/cpu.h>
  52. #include <plat/devs.h>
  53. #include <plat/gpio-cfg.h>
  54. #include <plat/pll.h>
  55. #include <plat/pm.h>
  56. #include <plat/regs-serial.h>
  57. #include <plat/samsung-time.h>
  58. #include "common.h"
  59. #include "h1940.h"
  60. #define H1940_LATCH ((void __force __iomem *)0xF8000000)
  61. #define H1940_PA_LATCH S3C2410_CS2
  62. #define H1940_LATCH_BIT(x) (1 << ((x) + 16 - S3C_GPIO_END))
  63. static struct map_desc h1940_iodesc[] __initdata = {
  64. [0] = {
  65. .virtual = (unsigned long)H1940_LATCH,
  66. .pfn = __phys_to_pfn(H1940_PA_LATCH),
  67. .length = SZ_16K,
  68. .type = MT_DEVICE
  69. },
  70. };
  71. #define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
  72. #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
  73. #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
  74. static struct s3c2410_uartcfg h1940_uartcfgs[] __initdata = {
  75. [0] = {
  76. .hwport = 0,
  77. .flags = 0,
  78. .ucon = 0x3c5,
  79. .ulcon = 0x03,
  80. .ufcon = 0x51,
  81. },
  82. [1] = {
  83. .hwport = 1,
  84. .flags = 0,
  85. .ucon = 0x245,
  86. .ulcon = 0x03,
  87. .ufcon = 0x00,
  88. },
  89. /* IR port */
  90. [2] = {
  91. .hwport = 2,
  92. .flags = 0,
  93. .uart_flags = UPF_CONS_FLOW,
  94. .ucon = 0x3c5,
  95. .ulcon = 0x43,
  96. .ufcon = 0x51,
  97. }
  98. };
  99. /* Board control latch control */
  100. static unsigned int latch_state;
  101. static void h1940_latch_control(unsigned int clear, unsigned int set)
  102. {
  103. unsigned long flags;
  104. local_irq_save(flags);
  105. latch_state &= ~clear;
  106. latch_state |= set;
  107. __raw_writel(latch_state, H1940_LATCH);
  108. local_irq_restore(flags);
  109. }
  110. static inline int h1940_gpiolib_to_latch(int offset)
  111. {
  112. return 1 << (offset + 16);
  113. }
  114. static void h1940_gpiolib_latch_set(struct gpio_chip *chip,
  115. unsigned offset, int value)
  116. {
  117. int latch_bit = h1940_gpiolib_to_latch(offset);
  118. h1940_latch_control(value ? 0 : latch_bit,
  119. value ? latch_bit : 0);
  120. }
  121. static int h1940_gpiolib_latch_output(struct gpio_chip *chip,
  122. unsigned offset, int value)
  123. {
  124. h1940_gpiolib_latch_set(chip, offset, value);
  125. return 0;
  126. }
  127. static int h1940_gpiolib_latch_get(struct gpio_chip *chip,
  128. unsigned offset)
  129. {
  130. return (latch_state >> (offset + 16)) & 1;
  131. }
  132. static struct gpio_chip h1940_latch_gpiochip = {
  133. .base = H1940_LATCH_GPIO(0),
  134. .owner = THIS_MODULE,
  135. .label = "H1940_LATCH",
  136. .ngpio = 16,
  137. .direction_output = h1940_gpiolib_latch_output,
  138. .set = h1940_gpiolib_latch_set,
  139. .get = h1940_gpiolib_latch_get,
  140. };
  141. static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = {
  142. .vbus_pin = S3C2410_GPG(5),
  143. .vbus_pin_inverted = 1,
  144. .pullup_pin = H1940_LATCH_USB_DP,
  145. };
  146. static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
  147. .delay = 10000,
  148. .presc = 49,
  149. .oversampling_shift = 2,
  150. .cfg_gpio = s3c24xx_ts_cfg_gpio,
  151. };
  152. /**
  153. * Set lcd on or off
  154. **/
  155. static struct s3c2410fb_display h1940_lcd __initdata = {
  156. .lcdcon5= S3C2410_LCDCON5_FRM565 | \
  157. S3C2410_LCDCON5_INVVLINE | \
  158. S3C2410_LCDCON5_HWSWP,
  159. .type = S3C2410_LCDCON1_TFT,
  160. .width = 240,
  161. .height = 320,
  162. .pixclock = 260000,
  163. .xres = 240,
  164. .yres = 320,
  165. .bpp = 16,
  166. .left_margin = 8,
  167. .right_margin = 20,
  168. .hsync_len = 4,
  169. .upper_margin = 8,
  170. .lower_margin = 7,
  171. .vsync_len = 1,
  172. };
  173. static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
  174. .displays = &h1940_lcd,
  175. .num_displays = 1,
  176. .default_display = 0,
  177. .lpcsel = 0x02,
  178. .gpccon = 0xaa940659,
  179. .gpccon_mask = 0xffffc0f0,
  180. .gpcup = 0x0000ffff,
  181. .gpcup_mask = 0xffffffff,
  182. .gpdcon = 0xaa84aaa0,
  183. .gpdcon_mask = 0xffffffff,
  184. .gpdup = 0x0000faff,
  185. .gpdup_mask = 0xffffffff,
  186. };
  187. static int power_supply_init(struct device *dev)
  188. {
  189. return gpio_request(S3C2410_GPF(2), "cable plugged");
  190. }
  191. static int h1940_is_ac_online(void)
  192. {
  193. return !gpio_get_value(S3C2410_GPF(2));
  194. }
  195. static void power_supply_exit(struct device *dev)
  196. {
  197. gpio_free(S3C2410_GPF(2));
  198. }
  199. static char *h1940_supplicants[] = {
  200. "main-battery",
  201. "backup-battery",
  202. };
  203. static struct pda_power_pdata power_supply_info = {
  204. .init = power_supply_init,
  205. .is_ac_online = h1940_is_ac_online,
  206. .exit = power_supply_exit,
  207. .supplied_to = h1940_supplicants,
  208. .num_supplicants = ARRAY_SIZE(h1940_supplicants),
  209. };
  210. static struct resource power_supply_resources[] = {
  211. [0] = DEFINE_RES_NAMED(IRQ_EINT2, 1, "ac", IORESOURCE_IRQ \
  212. | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE),
  213. };
  214. static struct platform_device power_supply = {
  215. .name = "pda-power",
  216. .id = -1,
  217. .dev = {
  218. .platform_data =
  219. &power_supply_info,
  220. },
  221. .resource = power_supply_resources,
  222. .num_resources = ARRAY_SIZE(power_supply_resources),
  223. };
  224. static const struct s3c_adc_bat_thresh bat_lut_noac[] = {
  225. { .volt = 4070, .cur = 162, .level = 100},
  226. { .volt = 4040, .cur = 165, .level = 95},
  227. { .volt = 4016, .cur = 164, .level = 90},
  228. { .volt = 3996, .cur = 166, .level = 85},
  229. { .volt = 3971, .cur = 168, .level = 80},
  230. { .volt = 3951, .cur = 168, .level = 75},
  231. { .volt = 3931, .cur = 170, .level = 70},
  232. { .volt = 3903, .cur = 172, .level = 65},
  233. { .volt = 3886, .cur = 172, .level = 60},
  234. { .volt = 3858, .cur = 176, .level = 55},
  235. { .volt = 3842, .cur = 176, .level = 50},
  236. { .volt = 3818, .cur = 176, .level = 45},
  237. { .volt = 3789, .cur = 180, .level = 40},
  238. { .volt = 3769, .cur = 180, .level = 35},
  239. { .volt = 3749, .cur = 184, .level = 30},
  240. { .volt = 3732, .cur = 184, .level = 25},
  241. { .volt = 3716, .cur = 184, .level = 20},
  242. { .volt = 3708, .cur = 184, .level = 15},
  243. { .volt = 3716, .cur = 96, .level = 10},
  244. { .volt = 3700, .cur = 96, .level = 5},
  245. { .volt = 3684, .cur = 96, .level = 0},
  246. };
  247. static const struct s3c_adc_bat_thresh bat_lut_acin[] = {
  248. { .volt = 4130, .cur = 0, .level = 100},
  249. { .volt = 3982, .cur = 0, .level = 50},
  250. { .volt = 3854, .cur = 0, .level = 10},
  251. { .volt = 3841, .cur = 0, .level = 0},
  252. };
  253. static int h1940_bat_init(void)
  254. {
  255. int ret;
  256. ret = gpio_request(H1940_LATCH_SM803_ENABLE, "h1940-charger-enable");
  257. if (ret)
  258. return ret;
  259. gpio_direction_output(H1940_LATCH_SM803_ENABLE, 0);
  260. return 0;
  261. }
  262. static void h1940_bat_exit(void)
  263. {
  264. gpio_free(H1940_LATCH_SM803_ENABLE);
  265. }
  266. static void h1940_enable_charger(void)
  267. {
  268. gpio_set_value(H1940_LATCH_SM803_ENABLE, 1);
  269. }
  270. static void h1940_disable_charger(void)
  271. {
  272. gpio_set_value(H1940_LATCH_SM803_ENABLE, 0);
  273. }
  274. static struct s3c_adc_bat_pdata h1940_bat_cfg = {
  275. .init = h1940_bat_init,
  276. .exit = h1940_bat_exit,
  277. .enable_charger = h1940_enable_charger,
  278. .disable_charger = h1940_disable_charger,
  279. .gpio_charge_finished = S3C2410_GPF(3),
  280. .gpio_inverted = 1,
  281. .lut_noac = bat_lut_noac,
  282. .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
  283. .lut_acin = bat_lut_acin,
  284. .lut_acin_cnt = ARRAY_SIZE(bat_lut_acin),
  285. .volt_channel = 0,
  286. .current_channel = 1,
  287. .volt_mult = 4056,
  288. .current_mult = 1893,
  289. .internal_impedance = 200,
  290. .backup_volt_channel = 3,
  291. /* TODO Check backup volt multiplier */
  292. .backup_volt_mult = 4056,
  293. .backup_volt_min = 0,
  294. .backup_volt_max = 4149288
  295. };
  296. static struct platform_device h1940_battery = {
  297. .name = "s3c-adc-battery",
  298. .id = -1,
  299. .dev = {
  300. .parent = &s3c_device_adc.dev,
  301. .platform_data = &h1940_bat_cfg,
  302. },
  303. };
  304. static DEFINE_SPINLOCK(h1940_blink_spin);
  305. int h1940_led_blink_set(unsigned gpio, int state,
  306. unsigned long *delay_on, unsigned long *delay_off)
  307. {
  308. int blink_gpio, check_gpio1, check_gpio2;
  309. switch (gpio) {
  310. case H1940_LATCH_LED_GREEN:
  311. blink_gpio = S3C2410_GPA(7);
  312. check_gpio1 = S3C2410_GPA(1);
  313. check_gpio2 = S3C2410_GPA(3);
  314. break;
  315. case H1940_LATCH_LED_RED:
  316. blink_gpio = S3C2410_GPA(1);
  317. check_gpio1 = S3C2410_GPA(7);
  318. check_gpio2 = S3C2410_GPA(3);
  319. break;
  320. default:
  321. blink_gpio = S3C2410_GPA(3);
  322. check_gpio1 = S3C2410_GPA(1);
  323. check_gpio2 = S3C2410_GPA(7);
  324. break;
  325. }
  326. if (delay_on && delay_off && !*delay_on && !*delay_off)
  327. *delay_on = *delay_off = 500;
  328. spin_lock(&h1940_blink_spin);
  329. switch (state) {
  330. case GPIO_LED_NO_BLINK_LOW:
  331. case GPIO_LED_NO_BLINK_HIGH:
  332. if (!gpio_get_value(check_gpio1) &&
  333. !gpio_get_value(check_gpio2))
  334. gpio_set_value(H1940_LATCH_LED_FLASH, 0);
  335. gpio_set_value(blink_gpio, 0);
  336. if (gpio_is_valid(gpio))
  337. gpio_set_value(gpio, state);
  338. break;
  339. case GPIO_LED_BLINK:
  340. if (gpio_is_valid(gpio))
  341. gpio_set_value(gpio, 0);
  342. gpio_set_value(H1940_LATCH_LED_FLASH, 1);
  343. gpio_set_value(blink_gpio, 1);
  344. break;
  345. }
  346. spin_unlock(&h1940_blink_spin);
  347. return 0;
  348. }
  349. EXPORT_SYMBOL(h1940_led_blink_set);
  350. static struct gpio_led h1940_leds_desc[] = {
  351. {
  352. .name = "Green",
  353. .default_trigger = "main-battery-full",
  354. .gpio = H1940_LATCH_LED_GREEN,
  355. .retain_state_suspended = 1,
  356. },
  357. {
  358. .name = "Red",
  359. .default_trigger
  360. = "main-battery-charging-blink-full-solid",
  361. .gpio = H1940_LATCH_LED_RED,
  362. .retain_state_suspended = 1,
  363. },
  364. };
  365. static struct gpio_led_platform_data h1940_leds_pdata = {
  366. .num_leds = ARRAY_SIZE(h1940_leds_desc),
  367. .leds = h1940_leds_desc,
  368. .gpio_blink_set = h1940_led_blink_set,
  369. };
  370. static struct platform_device h1940_device_leds = {
  371. .name = "leds-gpio",
  372. .id = -1,
  373. .dev = {
  374. .platform_data = &h1940_leds_pdata,
  375. },
  376. };
  377. static struct platform_device h1940_device_bluetooth = {
  378. .name = "h1940-bt",
  379. .id = -1,
  380. };
  381. static void h1940_set_mmc_power(unsigned char power_mode, unsigned short vdd)
  382. {
  383. switch (power_mode) {
  384. case MMC_POWER_OFF:
  385. gpio_set_value(H1940_LATCH_SD_POWER, 0);
  386. break;
  387. case MMC_POWER_UP:
  388. case MMC_POWER_ON:
  389. gpio_set_value(H1940_LATCH_SD_POWER, 1);
  390. break;
  391. default:
  392. break;
  393. }
  394. }
  395. static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
  396. .gpio_detect = S3C2410_GPF(5),
  397. .gpio_wprotect = S3C2410_GPH(8),
  398. .set_power = h1940_set_mmc_power,
  399. .ocr_avail = MMC_VDD_32_33,
  400. };
  401. static int h1940_backlight_init(struct device *dev)
  402. {
  403. gpio_request(S3C2410_GPB(0), "Backlight");
  404. gpio_direction_output(S3C2410_GPB(0), 0);
  405. s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
  406. s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
  407. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
  408. return 0;
  409. }
  410. static int h1940_backlight_notify(struct device *dev, int brightness)
  411. {
  412. if (!brightness) {
  413. gpio_direction_output(S3C2410_GPB(0), 1);
  414. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  415. } else {
  416. gpio_direction_output(S3C2410_GPB(0), 0);
  417. s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
  418. s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
  419. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
  420. }
  421. return brightness;
  422. }
  423. static void h1940_backlight_exit(struct device *dev)
  424. {
  425. gpio_direction_output(S3C2410_GPB(0), 1);
  426. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  427. }
  428. static struct platform_pwm_backlight_data backlight_data = {
  429. .pwm_id = 0,
  430. .max_brightness = 100,
  431. .dft_brightness = 50,
  432. /* tcnt = 0x31 */
  433. .pwm_period_ns = 36296,
  434. .init = h1940_backlight_init,
  435. .notify = h1940_backlight_notify,
  436. .exit = h1940_backlight_exit,
  437. };
  438. static struct platform_device h1940_backlight = {
  439. .name = "pwm-backlight",
  440. .dev = {
  441. .parent = &s3c_device_timer[0].dev,
  442. .platform_data = &backlight_data,
  443. },
  444. .id = -1,
  445. };
  446. static void h1940_lcd_power_set(struct plat_lcd_data *pd,
  447. unsigned int power)
  448. {
  449. int value, retries = 100;
  450. if (!power) {
  451. gpio_set_value(S3C2410_GPC(0), 0);
  452. /* wait for 3ac */
  453. do {
  454. value = gpio_get_value(S3C2410_GPC(6));
  455. } while (value && retries--);
  456. gpio_set_value(H1940_LATCH_LCD_P2, 0);
  457. gpio_set_value(H1940_LATCH_LCD_P3, 0);
  458. gpio_set_value(H1940_LATCH_LCD_P4, 0);
  459. gpio_direction_output(S3C2410_GPC(1), 0);
  460. gpio_direction_output(S3C2410_GPC(4), 0);
  461. gpio_set_value(H1940_LATCH_LCD_P1, 0);
  462. gpio_set_value(H1940_LATCH_LCD_P0, 0);
  463. gpio_set_value(S3C2410_GPC(5), 0);
  464. } else {
  465. gpio_set_value(H1940_LATCH_LCD_P0, 1);
  466. gpio_set_value(H1940_LATCH_LCD_P1, 1);
  467. gpio_direction_input(S3C2410_GPC(1));
  468. gpio_direction_input(S3C2410_GPC(4));
  469. mdelay(10);
  470. s3c_gpio_cfgpin(S3C2410_GPC(1), S3C_GPIO_SFN(2));
  471. s3c_gpio_cfgpin(S3C2410_GPC(4), S3C_GPIO_SFN(2));
  472. gpio_set_value(S3C2410_GPC(5), 1);
  473. gpio_set_value(S3C2410_GPC(0), 1);
  474. gpio_set_value(H1940_LATCH_LCD_P3, 1);
  475. gpio_set_value(H1940_LATCH_LCD_P2, 1);
  476. gpio_set_value(H1940_LATCH_LCD_P4, 1);
  477. }
  478. }
  479. static struct plat_lcd_data h1940_lcd_power_data = {
  480. .set_power = h1940_lcd_power_set,
  481. };
  482. static struct platform_device h1940_lcd_powerdev = {
  483. .name = "platform-lcd",
  484. .dev.parent = &s3c_device_lcd.dev,
  485. .dev.platform_data = &h1940_lcd_power_data,
  486. };
  487. static struct uda1380_platform_data uda1380_info = {
  488. .gpio_power = H1940_LATCH_UDA_POWER,
  489. .gpio_reset = S3C2410_GPA(12),
  490. .dac_clk = UDA1380_DAC_CLK_SYSCLK,
  491. };
  492. static struct i2c_board_info h1940_i2c_devices[] = {
  493. {
  494. I2C_BOARD_INFO("uda1380", 0x1a),
  495. .platform_data = &uda1380_info,
  496. },
  497. };
  498. #define DECLARE_BUTTON(p, k, n, w) \
  499. { \
  500. .gpio = p, \
  501. .code = k, \
  502. .desc = n, \
  503. .wakeup = w, \
  504. .active_low = 1, \
  505. }
  506. static struct gpio_keys_button h1940_buttons[] = {
  507. DECLARE_BUTTON(S3C2410_GPF(0), KEY_POWER, "Power", 1),
  508. DECLARE_BUTTON(S3C2410_GPF(6), KEY_ENTER, "Select", 1),
  509. DECLARE_BUTTON(S3C2410_GPF(7), KEY_RECORD, "Record", 0),
  510. DECLARE_BUTTON(S3C2410_GPG(0), KEY_F11, "Calendar", 0),
  511. DECLARE_BUTTON(S3C2410_GPG(2), KEY_F12, "Contacts", 0),
  512. DECLARE_BUTTON(S3C2410_GPG(3), KEY_MAIL, "Mail", 0),
  513. DECLARE_BUTTON(S3C2410_GPG(6), KEY_LEFT, "Left_arrow", 0),
  514. DECLARE_BUTTON(S3C2410_GPG(7), KEY_HOMEPAGE, "Home", 0),
  515. DECLARE_BUTTON(S3C2410_GPG(8), KEY_RIGHT, "Right_arrow", 0),
  516. DECLARE_BUTTON(S3C2410_GPG(9), KEY_UP, "Up_arrow", 0),
  517. DECLARE_BUTTON(S3C2410_GPG(10), KEY_DOWN, "Down_arrow", 0),
  518. };
  519. static struct gpio_keys_platform_data h1940_buttons_data = {
  520. .buttons = h1940_buttons,
  521. .nbuttons = ARRAY_SIZE(h1940_buttons),
  522. };
  523. static struct platform_device h1940_dev_buttons = {
  524. .name = "gpio-keys",
  525. .id = -1,
  526. .dev = {
  527. .platform_data = &h1940_buttons_data,
  528. }
  529. };
  530. static struct platform_device *h1940_devices[] __initdata = {
  531. &h1940_dev_buttons,
  532. &s3c_device_ohci,
  533. &s3c_device_lcd,
  534. &s3c_device_wdt,
  535. &s3c_device_i2c0,
  536. &s3c_device_iis,
  537. &s3c_device_usbgadget,
  538. &h1940_device_leds,
  539. &h1940_device_bluetooth,
  540. &s3c_device_sdi,
  541. &s3c_device_rtc,
  542. &s3c_device_timer[0],
  543. &h1940_backlight,
  544. &h1940_lcd_powerdev,
  545. &s3c_device_adc,
  546. &s3c_device_ts,
  547. &power_supply,
  548. &h1940_battery,
  549. };
  550. static void __init h1940_map_io(void)
  551. {
  552. s3c24xx_init_io(h1940_iodesc, ARRAY_SIZE(h1940_iodesc));
  553. s3c24xx_init_clocks(0);
  554. s3c24xx_init_uarts(h1940_uartcfgs, ARRAY_SIZE(h1940_uartcfgs));
  555. samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
  556. /* setup PM */
  557. #ifdef CONFIG_PM_H1940
  558. memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 1024);
  559. #endif
  560. s3c_pm_init();
  561. /* Add latch gpio chip, set latch initial value */
  562. h1940_latch_control(0, 0);
  563. WARN_ON(gpiochip_add(&h1940_latch_gpiochip));
  564. }
  565. /* H1940 and RX3715 need to reserve this for suspend */
  566. static void __init h1940_reserve(void)
  567. {
  568. memblock_reserve(0x30003000, 0x1000);
  569. memblock_reserve(0x30081000, 0x1000);
  570. }
  571. static void __init h1940_init(void)
  572. {
  573. u32 tmp;
  574. s3c24xx_fb_set_platdata(&h1940_fb_info);
  575. s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
  576. s3c24xx_udc_set_platdata(&h1940_udc_cfg);
  577. s3c24xx_ts_set_platdata(&h1940_ts_cfg);
  578. s3c_i2c0_set_platdata(NULL);
  579. /* Turn off suspend on both USB ports, and switch the
  580. * selectable USB port to USB device mode. */
  581. s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
  582. S3C2410_MISCCR_USBSUSPND0 |
  583. S3C2410_MISCCR_USBSUSPND1, 0x0);
  584. tmp = (0x78 << S3C24XX_PLL_MDIV_SHIFT)
  585. | (0x02 << S3C24XX_PLL_PDIV_SHIFT)
  586. | (0x03 << S3C24XX_PLL_SDIV_SHIFT);
  587. writel(tmp, S3C2410_UPLLCON);
  588. gpio_request(S3C2410_GPC(0), "LCD power");
  589. gpio_request(S3C2410_GPC(1), "LCD power");
  590. gpio_request(S3C2410_GPC(4), "LCD power");
  591. gpio_request(S3C2410_GPC(5), "LCD power");
  592. gpio_request(S3C2410_GPC(6), "LCD power");
  593. gpio_request(H1940_LATCH_LCD_P0, "LCD power");
  594. gpio_request(H1940_LATCH_LCD_P1, "LCD power");
  595. gpio_request(H1940_LATCH_LCD_P2, "LCD power");
  596. gpio_request(H1940_LATCH_LCD_P3, "LCD power");
  597. gpio_request(H1940_LATCH_LCD_P4, "LCD power");
  598. gpio_request(H1940_LATCH_MAX1698_nSHUTDOWN, "LCD power");
  599. gpio_direction_output(S3C2410_GPC(0), 0);
  600. gpio_direction_output(S3C2410_GPC(1), 0);
  601. gpio_direction_output(S3C2410_GPC(4), 0);
  602. gpio_direction_output(S3C2410_GPC(5), 0);
  603. gpio_direction_input(S3C2410_GPC(6));
  604. gpio_direction_output(H1940_LATCH_LCD_P0, 0);
  605. gpio_direction_output(H1940_LATCH_LCD_P1, 0);
  606. gpio_direction_output(H1940_LATCH_LCD_P2, 0);
  607. gpio_direction_output(H1940_LATCH_LCD_P3, 0);
  608. gpio_direction_output(H1940_LATCH_LCD_P4, 0);
  609. gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  610. gpio_request(H1940_LATCH_SD_POWER, "SD power");
  611. gpio_direction_output(H1940_LATCH_SD_POWER, 0);
  612. platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
  613. gpio_request(S3C2410_GPA(1), "Red LED blink");
  614. gpio_request(S3C2410_GPA(3), "Blue LED blink");
  615. gpio_request(S3C2410_GPA(7), "Green LED blink");
  616. gpio_request(H1940_LATCH_LED_FLASH, "LED blink");
  617. gpio_direction_output(S3C2410_GPA(1), 0);
  618. gpio_direction_output(S3C2410_GPA(3), 0);
  619. gpio_direction_output(S3C2410_GPA(7), 0);
  620. gpio_direction_output(H1940_LATCH_LED_FLASH, 0);
  621. i2c_register_board_info(0, h1940_i2c_devices,
  622. ARRAY_SIZE(h1940_i2c_devices));
  623. }
  624. MACHINE_START(H1940, "IPAQ-H1940")
  625. /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
  626. .atag_offset = 0x100,
  627. .map_io = h1940_map_io,
  628. .reserve = h1940_reserve,
  629. .init_irq = s3c2410_init_irq,
  630. .init_machine = h1940_init,
  631. .init_time = samsung_timer_init,
  632. .restart = s3c2410_restart,
  633. MACHINE_END