mach-gta02.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // S3C2442 Machine Support for Openmoko GTA02 / FreeRunner.
  4. //
  5. // Copyright (C) 2006-2009 by Openmoko, Inc.
  6. // Authors: Harald Welte <[email protected]>
  7. // Andy Green <[email protected]>
  8. // Werner Almesberger <[email protected]>
  9. // All rights reserved.
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/list.h>
  14. #include <linux/delay.h>
  15. #include <linux/timer.h>
  16. #include <linux/init.h>
  17. #include <linux/gpio/machine.h>
  18. #include <linux/gpio.h>
  19. #include <linux/gpio_keys.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/serial_core.h>
  23. #include <linux/serial_s3c.h>
  24. #include <linux/input.h>
  25. #include <linux/io.h>
  26. #include <linux/i2c.h>
  27. #include <linux/mmc/host.h>
  28. #include <linux/mfd/pcf50633/adc.h>
  29. #include <linux/mfd/pcf50633/backlight.h>
  30. #include <linux/mfd/pcf50633/core.h>
  31. #include <linux/mfd/pcf50633/gpio.h>
  32. #include <linux/mfd/pcf50633/mbc.h>
  33. #include <linux/mfd/pcf50633/pmic.h>
  34. #include <linux/mtd/mtd.h>
  35. #include <linux/mtd/rawnand.h>
  36. #include <linux/mtd/nand-ecc-sw-hamming.h>
  37. #include <linux/mtd/partitions.h>
  38. #include <linux/mtd/physmap.h>
  39. #include <linux/regulator/machine.h>
  40. #include <linux/spi/spi.h>
  41. #include <linux/spi/s3c24xx.h>
  42. #include <asm/irq.h>
  43. #include <asm/mach-types.h>
  44. #include <asm/mach/arch.h>
  45. #include <asm/mach/map.h>
  46. #include <asm/mach/irq.h>
  47. #include <linux/platform_data/i2c-s3c2410.h>
  48. #include <linux/platform_data/mtd-nand-s3c2410.h>
  49. #include <linux/platform_data/touchscreen-s3c2410.h>
  50. #include <linux/platform_data/usb-ohci-s3c2410.h>
  51. #include <linux/platform_data/usb-s3c2410_udc.h>
  52. #include <linux/platform_data/fb-s3c2410.h>
  53. #include "regs-gpio.h"
  54. #include "regs-irq.h"
  55. #include "gpio-samsung.h"
  56. #include "cpu.h"
  57. #include "devs.h"
  58. #include "gpio-cfg.h"
  59. #include "pm.h"
  60. #include "s3c24xx.h"
  61. #include "gta02.h"
  62. static struct pcf50633 *gta02_pcf;
  63. /*
  64. * This gets called frequently when we paniced.
  65. */
  66. static long gta02_panic_blink(int state)
  67. {
  68. char led;
  69. led = (state) ? 1 : 0;
  70. gpio_direction_output(GTA02_GPIO_AUX_LED, led);
  71. return 0;
  72. }
  73. static struct map_desc gta02_iodesc[] __initdata = {
  74. {
  75. .virtual = 0xe0000000,
  76. .pfn = __phys_to_pfn(S3C2410_CS3 + 0x01000000),
  77. .length = SZ_1M,
  78. .type = MT_DEVICE
  79. },
  80. };
  81. #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
  82. #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
  83. #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
  84. static struct s3c2410_uartcfg gta02_uartcfgs[] = {
  85. [0] = {
  86. .hwport = 0,
  87. .flags = 0,
  88. .ucon = UCON,
  89. .ulcon = ULCON,
  90. .ufcon = UFCON,
  91. },
  92. [1] = {
  93. .hwport = 1,
  94. .flags = 0,
  95. .ucon = UCON,
  96. .ulcon = ULCON,
  97. .ufcon = UFCON,
  98. },
  99. [2] = {
  100. .hwport = 2,
  101. .flags = 0,
  102. .ucon = UCON,
  103. .ulcon = ULCON,
  104. .ufcon = UFCON,
  105. },
  106. };
  107. #ifdef CONFIG_CHARGER_PCF50633
  108. /*
  109. * On GTA02 the 1A charger features a 48K resistor to 0V on the ID pin.
  110. * We use this to recognize that we can pull 1A from the USB socket.
  111. *
  112. * These constants are the measured pcf50633 ADC levels with the 1A
  113. * charger / 48K resistor, and with no pulldown resistor.
  114. */
  115. #define ADC_NOM_CHG_DETECT_1A 6
  116. #define ADC_NOM_CHG_DETECT_USB 43
  117. #ifdef CONFIG_PCF50633_ADC
  118. static void
  119. gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
  120. {
  121. int ma;
  122. /* Interpret charger type */
  123. if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2)) {
  124. /*
  125. * Sanity - stop GPO driving out now that we have a 1A charger
  126. * GPO controls USB Host power generation on GTA02
  127. */
  128. pcf50633_gpio_set(pcf, PCF50633_GPO, 0);
  129. ma = 1000;
  130. } else
  131. ma = 100;
  132. pcf50633_mbc_usb_curlim_set(pcf, ma);
  133. }
  134. #endif
  135. static struct delayed_work gta02_charger_work;
  136. static int gta02_usb_vbus_draw;
  137. static void gta02_charger_worker(struct work_struct *work)
  138. {
  139. if (gta02_usb_vbus_draw) {
  140. pcf50633_mbc_usb_curlim_set(gta02_pcf, gta02_usb_vbus_draw);
  141. return;
  142. }
  143. #ifdef CONFIG_PCF50633_ADC
  144. pcf50633_adc_async_read(gta02_pcf,
  145. PCF50633_ADCC1_MUX_ADCIN1,
  146. PCF50633_ADCC1_AVERAGE_16,
  147. gta02_configure_pmu_for_charger,
  148. NULL);
  149. #else
  150. /*
  151. * If the PCF50633 ADC is disabled we fallback to a
  152. * 100mA limit for safety.
  153. */
  154. pcf50633_mbc_usb_curlim_set(gta02_pcf, 100);
  155. #endif
  156. }
  157. #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
  158. static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
  159. {
  160. if (irq == PCF50633_IRQ_USBINS) {
  161. schedule_delayed_work(&gta02_charger_work,
  162. GTA02_CHARGER_CONFIGURE_TIMEOUT);
  163. return;
  164. }
  165. if (irq == PCF50633_IRQ_USBREM) {
  166. cancel_delayed_work_sync(&gta02_charger_work);
  167. gta02_usb_vbus_draw = 0;
  168. }
  169. }
  170. static void gta02_udc_vbus_draw(unsigned int ma)
  171. {
  172. if (!gta02_pcf)
  173. return;
  174. gta02_usb_vbus_draw = ma;
  175. schedule_delayed_work(&gta02_charger_work,
  176. GTA02_CHARGER_CONFIGURE_TIMEOUT);
  177. }
  178. #else /* !CONFIG_CHARGER_PCF50633 */
  179. #define gta02_pmu_event_callback NULL
  180. #define gta02_udc_vbus_draw NULL
  181. #endif
  182. static char *gta02_batteries[] = {
  183. "battery",
  184. };
  185. static struct pcf50633_bl_platform_data gta02_backlight_data = {
  186. .default_brightness = 0x3f,
  187. .default_brightness_limit = 0,
  188. .ramp_time = 5,
  189. };
  190. static struct pcf50633_platform_data gta02_pcf_pdata = {
  191. .resumers = {
  192. [0] = PCF50633_INT1_USBINS |
  193. PCF50633_INT1_USBREM |
  194. PCF50633_INT1_ALARM,
  195. [1] = PCF50633_INT2_ONKEYF,
  196. [2] = PCF50633_INT3_ONKEY1S,
  197. [3] = PCF50633_INT4_LOWSYS |
  198. PCF50633_INT4_LOWBAT |
  199. PCF50633_INT4_HIGHTMP,
  200. },
  201. .batteries = gta02_batteries,
  202. .num_batteries = ARRAY_SIZE(gta02_batteries),
  203. .charger_reference_current_ma = 1000,
  204. .backlight_data = &gta02_backlight_data,
  205. .reg_init_data = {
  206. [PCF50633_REGULATOR_AUTO] = {
  207. .constraints = {
  208. .min_uV = 3300000,
  209. .max_uV = 3300000,
  210. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  211. .always_on = 1,
  212. .apply_uV = 1,
  213. },
  214. },
  215. [PCF50633_REGULATOR_DOWN1] = {
  216. .constraints = {
  217. .min_uV = 1300000,
  218. .max_uV = 1600000,
  219. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  220. .always_on = 1,
  221. .apply_uV = 1,
  222. },
  223. },
  224. [PCF50633_REGULATOR_DOWN2] = {
  225. .constraints = {
  226. .min_uV = 1800000,
  227. .max_uV = 1800000,
  228. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  229. .apply_uV = 1,
  230. .always_on = 1,
  231. },
  232. },
  233. [PCF50633_REGULATOR_HCLDO] = {
  234. .constraints = {
  235. .min_uV = 2000000,
  236. .max_uV = 3300000,
  237. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  238. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  239. REGULATOR_CHANGE_STATUS,
  240. },
  241. },
  242. [PCF50633_REGULATOR_LDO1] = {
  243. .constraints = {
  244. .min_uV = 3300000,
  245. .max_uV = 3300000,
  246. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  247. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  248. .apply_uV = 1,
  249. },
  250. },
  251. [PCF50633_REGULATOR_LDO2] = {
  252. .constraints = {
  253. .min_uV = 3300000,
  254. .max_uV = 3300000,
  255. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  256. .apply_uV = 1,
  257. },
  258. },
  259. [PCF50633_REGULATOR_LDO3] = {
  260. .constraints = {
  261. .min_uV = 3000000,
  262. .max_uV = 3000000,
  263. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  264. .apply_uV = 1,
  265. },
  266. },
  267. [PCF50633_REGULATOR_LDO4] = {
  268. .constraints = {
  269. .min_uV = 3200000,
  270. .max_uV = 3200000,
  271. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  272. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  273. .apply_uV = 1,
  274. },
  275. },
  276. [PCF50633_REGULATOR_LDO5] = {
  277. .constraints = {
  278. .min_uV = 3000000,
  279. .max_uV = 3000000,
  280. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  281. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  282. .apply_uV = 1,
  283. },
  284. },
  285. [PCF50633_REGULATOR_LDO6] = {
  286. .constraints = {
  287. .min_uV = 3000000,
  288. .max_uV = 3000000,
  289. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  290. },
  291. },
  292. [PCF50633_REGULATOR_MEMLDO] = {
  293. .constraints = {
  294. .min_uV = 1800000,
  295. .max_uV = 1800000,
  296. .valid_modes_mask = REGULATOR_MODE_NORMAL,
  297. },
  298. },
  299. },
  300. .mbc_event_callback = gta02_pmu_event_callback,
  301. };
  302. /* NOR Flash. */
  303. #define GTA02_FLASH_BASE 0x18000000 /* GCS3 */
  304. #define GTA02_FLASH_SIZE 0x200000 /* 2MBytes */
  305. static struct physmap_flash_data gta02_nor_flash_data = {
  306. .width = 2,
  307. };
  308. static struct resource gta02_nor_flash_resource =
  309. DEFINE_RES_MEM(GTA02_FLASH_BASE, GTA02_FLASH_SIZE);
  310. static struct platform_device gta02_nor_flash = {
  311. .name = "physmap-flash",
  312. .id = 0,
  313. .dev = {
  314. .platform_data = &gta02_nor_flash_data,
  315. },
  316. .resource = &gta02_nor_flash_resource,
  317. .num_resources = 1,
  318. };
  319. static struct platform_device s3c24xx_pwm_device = {
  320. .name = "s3c24xx_pwm",
  321. .num_resources = 0,
  322. };
  323. static struct platform_device gta02_dfbmcs320_device = {
  324. .name = "dfbmcs320",
  325. };
  326. static struct i2c_board_info gta02_i2c_devs[] __initdata = {
  327. {
  328. I2C_BOARD_INFO("pcf50633", 0x73),
  329. .irq = GTA02_IRQ_PCF50633,
  330. .platform_data = &gta02_pcf_pdata,
  331. },
  332. {
  333. I2C_BOARD_INFO("wm8753", 0x1a),
  334. },
  335. };
  336. static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
  337. [0] = {
  338. /*
  339. * This name is also hard-coded in the boot loaders, so
  340. * changing it would would require all users to upgrade
  341. * their boot loaders, some of which are stored in a NOR
  342. * that is considered to be immutable.
  343. */
  344. .name = "neo1973-nand",
  345. .nr_chips = 1,
  346. .flash_bbt = 1,
  347. },
  348. };
  349. /*
  350. * Choose a set of timings derived from S3C@2442B MCP54
  351. * data sheet (K5D2G13ACM-D075 MCP Memory).
  352. */
  353. static struct s3c2410_platform_nand __initdata gta02_nand_info = {
  354. .tacls = 0,
  355. .twrph0 = 25,
  356. .twrph1 = 15,
  357. .nr_sets = ARRAY_SIZE(gta02_nand_sets),
  358. .sets = gta02_nand_sets,
  359. .engine_type = NAND_ECC_ENGINE_TYPE_SOFT,
  360. };
  361. /* Get PMU to set USB current limit accordingly. */
  362. static struct s3c2410_udc_mach_info gta02_udc_cfg __initdata = {
  363. .vbus_draw = gta02_udc_vbus_draw,
  364. };
  365. static struct gpiod_lookup_table gta02_udc_gpio_table = {
  366. .dev_id = "s3c2410-usbgadget",
  367. .table = {
  368. GPIO_LOOKUP("GPIOB", 9, "pullup", GPIO_ACTIVE_HIGH),
  369. { },
  370. },
  371. };
  372. /* USB */
  373. static struct s3c2410_hcd_info gta02_usb_info __initdata = {
  374. .port[0] = {
  375. .flags = S3C_HCDFLG_USED,
  376. },
  377. .port[1] = {
  378. .flags = 0,
  379. },
  380. };
  381. /* Touchscreen */
  382. static struct s3c2410_ts_mach_info gta02_ts_info = {
  383. .delay = 10000,
  384. .presc = 0xff, /* slow as we can go */
  385. .oversampling_shift = 2,
  386. };
  387. /* Buttons */
  388. static struct gpio_keys_button gta02_buttons[] = {
  389. {
  390. .gpio = GTA02_GPIO_AUX_KEY,
  391. .code = KEY_PHONE,
  392. .desc = "Aux",
  393. .type = EV_KEY,
  394. .debounce_interval = 100,
  395. },
  396. {
  397. .gpio = GTA02_GPIO_HOLD_KEY,
  398. .code = KEY_PAUSE,
  399. .desc = "Hold",
  400. .type = EV_KEY,
  401. .debounce_interval = 100,
  402. },
  403. };
  404. static struct gpio_keys_platform_data gta02_buttons_pdata = {
  405. .buttons = gta02_buttons,
  406. .nbuttons = ARRAY_SIZE(gta02_buttons),
  407. };
  408. static struct platform_device gta02_buttons_device = {
  409. .name = "gpio-keys",
  410. .id = -1,
  411. .dev = {
  412. .platform_data = &gta02_buttons_pdata,
  413. },
  414. };
  415. static struct gpiod_lookup_table gta02_audio_gpio_table = {
  416. .dev_id = "neo1973-audio",
  417. .table = {
  418. GPIO_LOOKUP("GPIOJ", 2, "amp-shut", GPIO_ACTIVE_HIGH),
  419. GPIO_LOOKUP("GPIOJ", 1, "hp", GPIO_ACTIVE_HIGH),
  420. { },
  421. },
  422. };
  423. static struct platform_device gta02_audio = {
  424. .name = "neo1973-audio",
  425. .id = -1,
  426. };
  427. static struct gpiod_lookup_table gta02_mmc_gpio_table = {
  428. .dev_id = "s3c2410-sdi",
  429. .table = {
  430. /* bus pins */
  431. GPIO_LOOKUP_IDX("GPIOE", 5, "bus", 0, GPIO_ACTIVE_HIGH),
  432. GPIO_LOOKUP_IDX("GPIOE", 6, "bus", 1, GPIO_ACTIVE_HIGH),
  433. GPIO_LOOKUP_IDX("GPIOE", 7, "bus", 2, GPIO_ACTIVE_HIGH),
  434. GPIO_LOOKUP_IDX("GPIOE", 8, "bus", 3, GPIO_ACTIVE_HIGH),
  435. GPIO_LOOKUP_IDX("GPIOE", 9, "bus", 4, GPIO_ACTIVE_HIGH),
  436. GPIO_LOOKUP_IDX("GPIOE", 10, "bus", 5, GPIO_ACTIVE_HIGH),
  437. { },
  438. },
  439. };
  440. static void __init gta02_map_io(void)
  441. {
  442. s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
  443. s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
  444. s3c24xx_set_timer_source(S3C24XX_PWM3, S3C24XX_PWM4);
  445. }
  446. /* These are the guys that don't need to be children of PMU. */
  447. static struct platform_device *gta02_devices[] __initdata = {
  448. &s3c_device_ohci,
  449. &s3c_device_wdt,
  450. &s3c_device_sdi,
  451. &s3c_device_usbgadget,
  452. &s3c_device_nand,
  453. &gta02_nor_flash,
  454. &s3c24xx_pwm_device,
  455. &s3c_device_iis,
  456. &s3c_device_i2c0,
  457. &gta02_dfbmcs320_device,
  458. &gta02_buttons_device,
  459. &s3c_device_adc,
  460. &s3c_device_ts,
  461. &gta02_audio,
  462. };
  463. static void gta02_poweroff(void)
  464. {
  465. pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
  466. }
  467. static void __init gta02_machine_init(void)
  468. {
  469. /* Set the panic callback to turn AUX LED on or off. */
  470. panic_blink = gta02_panic_blink;
  471. s3c_pm_init();
  472. #ifdef CONFIG_CHARGER_PCF50633
  473. INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
  474. #endif
  475. s3c24xx_udc_set_platdata(&gta02_udc_cfg);
  476. s3c24xx_ts_set_platdata(&gta02_ts_info);
  477. s3c_ohci_set_platdata(&gta02_usb_info);
  478. s3c_nand_set_platdata(&gta02_nand_info);
  479. s3c_i2c0_set_platdata(NULL);
  480. i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
  481. /* Configure the I2S pins (GPE0...GPE4) in correct mode */
  482. s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
  483. S3C_GPIO_PULL_NONE);
  484. gpiod_add_lookup_table(&gta02_udc_gpio_table);
  485. gpiod_add_lookup_table(&gta02_audio_gpio_table);
  486. gpiod_add_lookup_table(&gta02_mmc_gpio_table);
  487. platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
  488. pm_power_off = gta02_poweroff;
  489. regulator_has_full_constraints();
  490. }
  491. static void __init gta02_init_time(void)
  492. {
  493. s3c2442_init_clocks(12000000);
  494. s3c24xx_timer_init();
  495. }
  496. MACHINE_START(NEO1973_GTA02, "GTA02")
  497. /* Maintainer: Nelson Castillo <[email protected]> */
  498. .atag_offset = 0x100,
  499. .nr_irqs = NR_IRQS_S3C2442,
  500. .map_io = gta02_map_io,
  501. .init_irq = s3c2442_init_irq,
  502. .init_machine = gta02_machine_init,
  503. .init_time = gta02_init_time,
  504. MACHINE_END