mach-h1940.c 21 KB

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