board-ams-delta.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/mach-omap1/board-ams-delta.c
  4. *
  5. * Modified from board-generic.c
  6. *
  7. * Board specific inits for the Amstrad E3 (codename Delta) videophone
  8. *
  9. * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
  10. */
  11. #include <linux/gpio/driver.h>
  12. #include <linux/gpio/machine.h>
  13. #include <linux/gpio/consumer.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/input.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/leds.h>
  19. #include <linux/mtd/nand-gpio.h>
  20. #include <linux/mtd/partitions.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regulator/consumer.h>
  23. #include <linux/regulator/fixed.h>
  24. #include <linux/regulator/machine.h>
  25. #include <linux/serial_8250.h>
  26. #include <linux/export.h>
  27. #include <linux/omapfb.h>
  28. #include <linux/io.h>
  29. #include <linux/platform_data/gpio-omap.h>
  30. #include <linux/soc/ti/omap1-mux.h>
  31. #include <asm/serial.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/map.h>
  35. #include <linux/platform_data/keypad-omap.h>
  36. #include "hardware.h"
  37. #include "usb.h"
  38. #include "ams-delta-fiq.h"
  39. #include "board-ams-delta.h"
  40. #include "iomap.h"
  41. #include "common.h"
  42. static const unsigned int ams_delta_keymap[] = {
  43. KEY(0, 0, KEY_F1), /* Advert */
  44. KEY(0, 3, KEY_COFFEE), /* Games */
  45. KEY(0, 2, KEY_QUESTION), /* Directory */
  46. KEY(2, 3, KEY_CONNECT), /* Internet */
  47. KEY(1, 2, KEY_SHOP), /* Services */
  48. KEY(1, 1, KEY_PHONE), /* VoiceMail */
  49. KEY(0, 1, KEY_DELETE), /* Delete */
  50. KEY(2, 2, KEY_PLAY), /* Play */
  51. KEY(1, 0, KEY_PAGEUP), /* Up */
  52. KEY(1, 3, KEY_PAGEDOWN), /* Down */
  53. KEY(2, 0, KEY_EMAIL), /* ReadEmail */
  54. KEY(2, 1, KEY_STOP), /* Stop */
  55. /* Numeric keypad portion */
  56. KEY(0, 7, KEY_KP1),
  57. KEY(0, 6, KEY_KP2),
  58. KEY(0, 5, KEY_KP3),
  59. KEY(1, 7, KEY_KP4),
  60. KEY(1, 6, KEY_KP5),
  61. KEY(1, 5, KEY_KP6),
  62. KEY(2, 7, KEY_KP7),
  63. KEY(2, 6, KEY_KP8),
  64. KEY(2, 5, KEY_KP9),
  65. KEY(3, 6, KEY_KP0),
  66. KEY(3, 7, KEY_KPASTERISK),
  67. KEY(3, 5, KEY_KPDOT), /* # key */
  68. KEY(7, 2, KEY_NUMLOCK), /* Mute */
  69. KEY(7, 1, KEY_KPMINUS), /* Recall */
  70. KEY(6, 1, KEY_KPPLUS), /* Redial */
  71. KEY(7, 6, KEY_KPSLASH), /* Handsfree */
  72. KEY(6, 0, KEY_ENTER), /* Video */
  73. KEY(7, 4, KEY_CAMERA), /* Photo */
  74. KEY(0, 4, KEY_F2), /* Home */
  75. KEY(1, 4, KEY_F3), /* Office */
  76. KEY(2, 4, KEY_F4), /* Mobile */
  77. KEY(7, 7, KEY_F5), /* SMS */
  78. KEY(7, 5, KEY_F6), /* Email */
  79. /* QWERTY portion of keypad */
  80. KEY(3, 4, KEY_Q),
  81. KEY(3, 3, KEY_W),
  82. KEY(3, 2, KEY_E),
  83. KEY(3, 1, KEY_R),
  84. KEY(3, 0, KEY_T),
  85. KEY(4, 7, KEY_Y),
  86. KEY(4, 6, KEY_U),
  87. KEY(4, 5, KEY_I),
  88. KEY(4, 4, KEY_O),
  89. KEY(4, 3, KEY_P),
  90. KEY(4, 2, KEY_A),
  91. KEY(4, 1, KEY_S),
  92. KEY(4, 0, KEY_D),
  93. KEY(5, 7, KEY_F),
  94. KEY(5, 6, KEY_G),
  95. KEY(5, 5, KEY_H),
  96. KEY(5, 4, KEY_J),
  97. KEY(5, 3, KEY_K),
  98. KEY(5, 2, KEY_L),
  99. KEY(5, 1, KEY_Z),
  100. KEY(5, 0, KEY_X),
  101. KEY(6, 7, KEY_C),
  102. KEY(6, 6, KEY_V),
  103. KEY(6, 5, KEY_B),
  104. KEY(6, 4, KEY_N),
  105. KEY(6, 3, KEY_M),
  106. KEY(6, 2, KEY_SPACE),
  107. KEY(7, 0, KEY_LEFTSHIFT), /* Vol up */
  108. KEY(7, 3, KEY_LEFTCTRL), /* Vol down */
  109. };
  110. #define LATCH1_PHYS 0x01000000
  111. #define LATCH1_VIRT 0xEA000000
  112. #define MODEM_PHYS 0x04000000
  113. #define MODEM_VIRT 0xEB000000
  114. #define LATCH2_PHYS 0x08000000
  115. #define LATCH2_VIRT 0xEC000000
  116. static struct map_desc ams_delta_io_desc[] __initdata = {
  117. /* AMS_DELTA_LATCH1 */
  118. {
  119. .virtual = LATCH1_VIRT,
  120. .pfn = __phys_to_pfn(LATCH1_PHYS),
  121. .length = 0x01000000,
  122. .type = MT_DEVICE
  123. },
  124. /* AMS_DELTA_LATCH2 */
  125. {
  126. .virtual = LATCH2_VIRT,
  127. .pfn = __phys_to_pfn(LATCH2_PHYS),
  128. .length = 0x01000000,
  129. .type = MT_DEVICE
  130. },
  131. /* AMS_DELTA_MODEM */
  132. {
  133. .virtual = MODEM_VIRT,
  134. .pfn = __phys_to_pfn(MODEM_PHYS),
  135. .length = 0x01000000,
  136. .type = MT_DEVICE
  137. }
  138. };
  139. static const struct omap_lcd_config ams_delta_lcd_config __initconst = {
  140. .ctrl_name = "internal",
  141. };
  142. static struct omap_usb_config ams_delta_usb_config __initdata = {
  143. .register_host = 1,
  144. .hmc_mode = 16,
  145. .pins[0] = 2,
  146. };
  147. #define LATCH1_NGPIO 8
  148. static struct resource latch1_resources[] = {
  149. [0] = {
  150. .name = "dat",
  151. .start = LATCH1_PHYS,
  152. .end = LATCH1_PHYS + (LATCH1_NGPIO - 1) / 8,
  153. .flags = IORESOURCE_MEM,
  154. },
  155. };
  156. #define LATCH1_LABEL "latch1"
  157. static struct bgpio_pdata latch1_pdata = {
  158. .label = LATCH1_LABEL,
  159. .base = -1,
  160. .ngpio = LATCH1_NGPIO,
  161. };
  162. static struct platform_device latch1_gpio_device = {
  163. .name = "basic-mmio-gpio",
  164. .id = 0,
  165. .resource = latch1_resources,
  166. .num_resources = ARRAY_SIZE(latch1_resources),
  167. .dev = {
  168. .platform_data = &latch1_pdata,
  169. },
  170. };
  171. #define LATCH1_PIN_LED_CAMERA 0
  172. #define LATCH1_PIN_LED_ADVERT 1
  173. #define LATCH1_PIN_LED_MAIL 2
  174. #define LATCH1_PIN_LED_HANDSFREE 3
  175. #define LATCH1_PIN_LED_VOICEMAIL 4
  176. #define LATCH1_PIN_LED_VOICE 5
  177. #define LATCH1_PIN_DOCKIT1 6
  178. #define LATCH1_PIN_DOCKIT2 7
  179. #define LATCH2_NGPIO 16
  180. static struct resource latch2_resources[] = {
  181. [0] = {
  182. .name = "dat",
  183. .start = LATCH2_PHYS,
  184. .end = LATCH2_PHYS + (LATCH2_NGPIO - 1) / 8,
  185. .flags = IORESOURCE_MEM,
  186. },
  187. };
  188. #define LATCH2_LABEL "latch2"
  189. static struct bgpio_pdata latch2_pdata = {
  190. .label = LATCH2_LABEL,
  191. .base = -1,
  192. .ngpio = LATCH2_NGPIO,
  193. };
  194. static struct platform_device latch2_gpio_device = {
  195. .name = "basic-mmio-gpio",
  196. .id = 1,
  197. .resource = latch2_resources,
  198. .num_resources = ARRAY_SIZE(latch2_resources),
  199. .dev = {
  200. .platform_data = &latch2_pdata,
  201. },
  202. };
  203. #define LATCH2_PIN_LCD_VBLEN 0
  204. #define LATCH2_PIN_LCD_NDISP 1
  205. #define LATCH2_PIN_NAND_NCE 2
  206. #define LATCH2_PIN_NAND_NRE 3
  207. #define LATCH2_PIN_NAND_NWP 4
  208. #define LATCH2_PIN_NAND_NWE 5
  209. #define LATCH2_PIN_NAND_ALE 6
  210. #define LATCH2_PIN_NAND_CLE 7
  211. #define LATCH2_PIN_KEYBRD_PWR 8
  212. #define LATCH2_PIN_KEYBRD_DATAOUT 9
  213. #define LATCH2_PIN_SCARD_RSTIN 10
  214. #define LATCH2_PIN_SCARD_CMDVCC 11
  215. #define LATCH2_PIN_MODEM_NRESET 12
  216. #define LATCH2_PIN_MODEM_CODEC 13
  217. #define LATCH2_PIN_HANDSFREE_MUTE 14
  218. #define LATCH2_PIN_HANDSET_MUTE 15
  219. static struct regulator_consumer_supply modem_nreset_consumers[] = {
  220. REGULATOR_SUPPLY("RESET#", "serial8250.1"),
  221. REGULATOR_SUPPLY("POR", "cx20442-codec"),
  222. };
  223. static struct regulator_init_data modem_nreset_data = {
  224. .constraints = {
  225. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  226. .boot_on = 1,
  227. },
  228. .num_consumer_supplies = ARRAY_SIZE(modem_nreset_consumers),
  229. .consumer_supplies = modem_nreset_consumers,
  230. };
  231. static struct fixed_voltage_config modem_nreset_config = {
  232. .supply_name = "modem_nreset",
  233. .microvolts = 3300000,
  234. .startup_delay = 25000,
  235. .enabled_at_boot = 1,
  236. .init_data = &modem_nreset_data,
  237. };
  238. static struct platform_device modem_nreset_device = {
  239. .name = "reg-fixed-voltage",
  240. .id = -1,
  241. .dev = {
  242. .platform_data = &modem_nreset_config,
  243. },
  244. };
  245. static struct gpiod_lookup_table ams_delta_nreset_gpiod_table = {
  246. .dev_id = "reg-fixed-voltage",
  247. .table = {
  248. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_MODEM_NRESET,
  249. NULL, GPIO_ACTIVE_HIGH),
  250. { },
  251. },
  252. };
  253. struct modem_private_data {
  254. struct regulator *regulator;
  255. };
  256. static struct modem_private_data modem_priv;
  257. /*
  258. * Define partitions for flash device
  259. */
  260. static struct mtd_partition partition_info[] = {
  261. { .name = "Kernel",
  262. .offset = 0,
  263. .size = 3 * SZ_1M + SZ_512K },
  264. { .name = "u-boot",
  265. .offset = 3 * SZ_1M + SZ_512K,
  266. .size = SZ_256K },
  267. { .name = "u-boot params",
  268. .offset = 3 * SZ_1M + SZ_512K + SZ_256K,
  269. .size = SZ_256K },
  270. { .name = "Amstrad LDR",
  271. .offset = 4 * SZ_1M,
  272. .size = SZ_256K },
  273. { .name = "File system",
  274. .offset = 4 * SZ_1M + 1 * SZ_256K,
  275. .size = 27 * SZ_1M },
  276. { .name = "PBL reserved",
  277. .offset = 32 * SZ_1M - 3 * SZ_256K,
  278. .size = 3 * SZ_256K },
  279. };
  280. static struct gpio_nand_platdata nand_platdata = {
  281. .parts = partition_info,
  282. .num_parts = ARRAY_SIZE(partition_info),
  283. };
  284. static struct platform_device ams_delta_nand_device = {
  285. .name = "ams-delta-nand",
  286. .id = -1,
  287. .dev = {
  288. .platform_data = &nand_platdata,
  289. },
  290. };
  291. #define OMAP_GPIO_LABEL "gpio-0-15"
  292. #define OMAP_MPUIO_LABEL "mpuio"
  293. static struct gpiod_lookup_table ams_delta_nand_gpio_table = {
  294. .table = {
  295. GPIO_LOOKUP(OMAP_GPIO_LABEL, AMS_DELTA_GPIO_PIN_NAND_RB, "rdy",
  296. 0),
  297. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NCE, "nce",
  298. GPIO_ACTIVE_LOW),
  299. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NRE, "nre",
  300. GPIO_ACTIVE_LOW),
  301. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NWP, "nwp",
  302. GPIO_ACTIVE_LOW),
  303. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NWE, "nwe",
  304. GPIO_ACTIVE_LOW),
  305. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_ALE, "ale", 0),
  306. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_CLE, "cle", 0),
  307. GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 0, "data", 0, 0),
  308. GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 1, "data", 1, 0),
  309. GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 2, "data", 2, 0),
  310. GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 3, "data", 3, 0),
  311. GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 4, "data", 4, 0),
  312. GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 5, "data", 5, 0),
  313. GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 6, "data", 6, 0),
  314. GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 7, "data", 7, 0),
  315. { },
  316. },
  317. };
  318. static struct resource ams_delta_kp_resources[] = {
  319. [0] = {
  320. .start = INT_KEYBOARD,
  321. .end = INT_KEYBOARD,
  322. .flags = IORESOURCE_IRQ,
  323. },
  324. };
  325. static const struct matrix_keymap_data ams_delta_keymap_data = {
  326. .keymap = ams_delta_keymap,
  327. .keymap_size = ARRAY_SIZE(ams_delta_keymap),
  328. };
  329. static struct omap_kp_platform_data ams_delta_kp_data = {
  330. .rows = 8,
  331. .cols = 8,
  332. .keymap_data = &ams_delta_keymap_data,
  333. .delay = 9,
  334. };
  335. static struct platform_device ams_delta_kp_device = {
  336. .name = "omap-keypad",
  337. .id = -1,
  338. .dev = {
  339. .platform_data = &ams_delta_kp_data,
  340. },
  341. .num_resources = ARRAY_SIZE(ams_delta_kp_resources),
  342. .resource = ams_delta_kp_resources,
  343. };
  344. static struct platform_device ams_delta_lcd_device = {
  345. .name = "lcd_ams_delta",
  346. .id = -1,
  347. };
  348. static struct gpiod_lookup_table ams_delta_lcd_gpio_table = {
  349. .table = {
  350. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_LCD_VBLEN, "vblen", 0),
  351. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_LCD_NDISP, "ndisp", 0),
  352. { },
  353. },
  354. };
  355. static struct gpio_led gpio_leds[] __initdata = {
  356. [LATCH1_PIN_LED_CAMERA] = {
  357. .name = "camera",
  358. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  359. },
  360. [LATCH1_PIN_LED_ADVERT] = {
  361. .name = "advert",
  362. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  363. },
  364. [LATCH1_PIN_LED_MAIL] = {
  365. .name = "email",
  366. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  367. },
  368. [LATCH1_PIN_LED_HANDSFREE] = {
  369. .name = "handsfree",
  370. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  371. },
  372. [LATCH1_PIN_LED_VOICEMAIL] = {
  373. .name = "voicemail",
  374. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  375. },
  376. [LATCH1_PIN_LED_VOICE] = {
  377. .name = "voice",
  378. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  379. },
  380. };
  381. static const struct gpio_led_platform_data leds_pdata __initconst = {
  382. .leds = gpio_leds,
  383. .num_leds = ARRAY_SIZE(gpio_leds),
  384. };
  385. static struct gpiod_lookup_table leds_gpio_table = {
  386. .table = {
  387. GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_CAMERA, NULL,
  388. LATCH1_PIN_LED_CAMERA, 0),
  389. GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_ADVERT, NULL,
  390. LATCH1_PIN_LED_ADVERT, 0),
  391. GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_MAIL, NULL,
  392. LATCH1_PIN_LED_MAIL, 0),
  393. GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_HANDSFREE, NULL,
  394. LATCH1_PIN_LED_HANDSFREE, 0),
  395. GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_VOICEMAIL, NULL,
  396. LATCH1_PIN_LED_VOICEMAIL, 0),
  397. GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_VOICE, NULL,
  398. LATCH1_PIN_LED_VOICE, 0),
  399. { },
  400. },
  401. };
  402. static struct platform_device ams_delta_audio_device = {
  403. .name = "ams-delta-audio",
  404. .id = -1,
  405. };
  406. static struct gpiod_lookup_table ams_delta_audio_gpio_table = {
  407. .table = {
  408. GPIO_LOOKUP(OMAP_GPIO_LABEL, AMS_DELTA_GPIO_PIN_HOOK_SWITCH,
  409. "hook_switch", 0),
  410. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_MODEM_CODEC,
  411. "modem_codec", 0),
  412. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_HANDSFREE_MUTE,
  413. "handsfree_mute", 0),
  414. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_HANDSET_MUTE,
  415. "handset_mute", 0),
  416. { },
  417. },
  418. };
  419. static struct platform_device cx20442_codec_device = {
  420. .name = "cx20442-codec",
  421. .id = -1,
  422. };
  423. static struct resource ams_delta_serio_resources[] = {
  424. {
  425. .flags = IORESOURCE_IRQ,
  426. /*
  427. * Initialize IRQ resource with invalid IRQ number.
  428. * It will be replaced with dynamically allocated GPIO IRQ
  429. * obtained from GPIO chip as soon as the chip is available.
  430. */
  431. .start = -EINVAL,
  432. .end = -EINVAL,
  433. },
  434. };
  435. static struct platform_device ams_delta_serio_device = {
  436. .name = "ams-delta-serio",
  437. .id = PLATFORM_DEVID_NONE,
  438. .dev = {
  439. /*
  440. * Initialize .platform_data explicitly with NULL to
  441. * indicate it is going to be used. It will be replaced
  442. * with FIQ buffer address as soon as FIQ is initialized.
  443. */
  444. .platform_data = NULL,
  445. },
  446. .num_resources = ARRAY_SIZE(ams_delta_serio_resources),
  447. .resource = ams_delta_serio_resources,
  448. };
  449. static struct regulator_consumer_supply keybrd_pwr_consumers[] = {
  450. /*
  451. * Initialize supply .dev_name with NULL. It will be replaced
  452. * with serio dev_name() as soon as the serio device is registered.
  453. */
  454. REGULATOR_SUPPLY("vcc", NULL),
  455. };
  456. static struct regulator_init_data keybrd_pwr_initdata = {
  457. .constraints = {
  458. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  459. },
  460. .num_consumer_supplies = ARRAY_SIZE(keybrd_pwr_consumers),
  461. .consumer_supplies = keybrd_pwr_consumers,
  462. };
  463. static struct fixed_voltage_config keybrd_pwr_config = {
  464. .supply_name = "keybrd_pwr",
  465. .microvolts = 5000000,
  466. .init_data = &keybrd_pwr_initdata,
  467. };
  468. static struct platform_device keybrd_pwr_device = {
  469. .name = "reg-fixed-voltage",
  470. .id = PLATFORM_DEVID_AUTO,
  471. .dev = {
  472. .platform_data = &keybrd_pwr_config,
  473. },
  474. };
  475. static struct gpiod_lookup_table keybrd_pwr_gpio_table = {
  476. .table = {
  477. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_KEYBRD_PWR, NULL,
  478. GPIO_ACTIVE_HIGH),
  479. { },
  480. },
  481. };
  482. static struct platform_device *ams_delta_devices[] __initdata = {
  483. &latch1_gpio_device,
  484. &latch2_gpio_device,
  485. &ams_delta_kp_device,
  486. &ams_delta_audio_device,
  487. &ams_delta_serio_device,
  488. &ams_delta_nand_device,
  489. &ams_delta_lcd_device,
  490. &cx20442_codec_device,
  491. &modem_nreset_device,
  492. };
  493. static struct gpiod_lookup_table *ams_delta_gpio_tables[] __initdata = {
  494. &ams_delta_nreset_gpiod_table,
  495. &ams_delta_audio_gpio_table,
  496. &keybrd_pwr_gpio_table,
  497. &ams_delta_lcd_gpio_table,
  498. &ams_delta_nand_gpio_table,
  499. };
  500. static struct gpiod_hog ams_delta_gpio_hogs[] = {
  501. GPIO_HOG(LATCH2_LABEL, LATCH2_PIN_KEYBRD_DATAOUT, "keybrd_dataout",
  502. GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW),
  503. {},
  504. };
  505. static struct plat_serial8250_port ams_delta_modem_ports[];
  506. /*
  507. * Obtain MODEM IRQ GPIO descriptor using its hardware pin
  508. * number and assign related IRQ number to the MODEM port.
  509. * Keep the GPIO descriptor open so nobody steps in.
  510. */
  511. static void __init modem_assign_irq(struct gpio_chip *chip)
  512. {
  513. struct gpio_desc *gpiod;
  514. gpiod = gpiochip_request_own_desc(chip, AMS_DELTA_GPIO_PIN_MODEM_IRQ,
  515. "modem_irq", GPIO_ACTIVE_HIGH,
  516. GPIOD_IN);
  517. if (IS_ERR(gpiod)) {
  518. pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__,
  519. PTR_ERR(gpiod));
  520. } else {
  521. ams_delta_modem_ports[0].irq = gpiod_to_irq(gpiod);
  522. }
  523. }
  524. /*
  525. * The purpose of this function is to take care of proper initialization of
  526. * devices and data structures which depend on GPIO lines provided by OMAP GPIO
  527. * banks but their drivers don't use GPIO lookup tables or GPIO layer at all.
  528. * The function may be called as soon as OMAP GPIO devices are probed.
  529. * Since that happens at postcore_initcall, it can be called successfully
  530. * from init_machine or later.
  531. * Dependent devices may be registered from within this function or later.
  532. */
  533. static void __init omap_gpio_deps_init(void)
  534. {
  535. struct gpio_device *gdev;
  536. struct gpio_chip *chip;
  537. /*
  538. * Some drivers may not use GPIO lookup tables but need to be provided
  539. * with GPIO numbers. The same applies to GPIO based IRQ lines - some
  540. * drivers may even not use GPIO layer but expect just IRQ numbers.
  541. * We could either define GPIO lookup tables then use them on behalf
  542. * of those devices, or we can use GPIO driver level methods for
  543. * identification of GPIO and IRQ numbers.
  544. *
  545. * This reference will be leaked but that's alright as this device
  546. * never goes down.
  547. */
  548. gdev = gpio_device_find_by_label(OMAP_GPIO_LABEL);
  549. if (!gdev) {
  550. pr_err("%s: OMAP GPIO device not found\n", __func__);
  551. return;
  552. }
  553. chip = gpio_device_get_chip(gdev);
  554. /*
  555. * Start with FIQ initialization as it may have to request
  556. * and release successfully each OMAP GPIO pin in turn.
  557. */
  558. ams_delta_init_fiq(chip, &ams_delta_serio_device);
  559. modem_assign_irq(chip);
  560. }
  561. /*
  562. * Initialize latch2 pins with values which are safe for dependent on-board
  563. * devices or useful for their successull initialization even before GPIO
  564. * driver takes control over the latch pins:
  565. * - LATCH2_PIN_LCD_VBLEN = 0
  566. * - LATCH2_PIN_LCD_NDISP = 0 Keep LCD device powered off before its
  567. * driver takes control over it.
  568. * - LATCH2_PIN_NAND_NCE = 0
  569. * - LATCH2_PIN_NAND_NWP = 0 Keep NAND device down and write-
  570. * protected before its driver takes
  571. * control over it.
  572. * - LATCH2_PIN_KEYBRD_PWR = 0 Keep keyboard powered off before serio
  573. * driver takes control over it.
  574. * - LATCH2_PIN_KEYBRD_DATAOUT = 0 Keep low to avoid corruption of first
  575. * byte of data received from attached
  576. * keyboard when serio device is probed;
  577. * the pin is also hogged low by the latch2
  578. * GPIO driver as soon as it is ready.
  579. * - LATCH2_PIN_MODEM_NRESET = 1 Enable voice MODEM device, allowing for
  580. * its successful probe even before a
  581. * regulator it depends on, which in turn
  582. * takes control over the pin, is set up.
  583. * - LATCH2_PIN_MODEM_CODEC = 1 Attach voice MODEM CODEC data port
  584. * to the MODEM so the CODEC is under
  585. * control even if audio driver doesn't
  586. * take it over.
  587. */
  588. static void __init ams_delta_latch2_init(void)
  589. {
  590. u16 latch2 = 1 << LATCH2_PIN_MODEM_NRESET | 1 << LATCH2_PIN_MODEM_CODEC;
  591. __raw_writew(latch2, IOMEM(LATCH2_VIRT));
  592. }
  593. static void __init ams_delta_init(void)
  594. {
  595. struct platform_device *leds_pdev;
  596. /* mux pins for uarts */
  597. omap_cfg_reg(UART1_TX);
  598. omap_cfg_reg(UART1_RTS);
  599. /* parallel camera interface */
  600. omap_cfg_reg(H19_1610_CAM_EXCLK);
  601. omap_cfg_reg(J15_1610_CAM_LCLK);
  602. omap_cfg_reg(L18_1610_CAM_VS);
  603. omap_cfg_reg(L15_1610_CAM_HS);
  604. omap_cfg_reg(L19_1610_CAM_D0);
  605. omap_cfg_reg(K14_1610_CAM_D1);
  606. omap_cfg_reg(K15_1610_CAM_D2);
  607. omap_cfg_reg(K19_1610_CAM_D3);
  608. omap_cfg_reg(K18_1610_CAM_D4);
  609. omap_cfg_reg(J14_1610_CAM_D5);
  610. omap_cfg_reg(J19_1610_CAM_D6);
  611. omap_cfg_reg(J18_1610_CAM_D7);
  612. omap_gpio_deps_init();
  613. ams_delta_latch2_init();
  614. gpiod_add_hogs(ams_delta_gpio_hogs);
  615. omap_serial_init();
  616. omap_register_i2c_bus(1, 100, NULL, 0);
  617. omap1_usb_init(&ams_delta_usb_config);
  618. platform_add_devices(ams_delta_devices, ARRAY_SIZE(ams_delta_devices));
  619. /*
  620. * As soon as regulator consumers have been registered, assign their
  621. * dev_names to consumer supply entries of respective regulators.
  622. */
  623. keybrd_pwr_consumers[0].dev_name =
  624. dev_name(&ams_delta_serio_device.dev);
  625. /*
  626. * Once consumer supply entries are populated with dev_names,
  627. * register regulator devices. At this stage only the keyboard
  628. * power regulator has its consumer supply table fully populated.
  629. */
  630. platform_device_register(&keybrd_pwr_device);
  631. /*
  632. * As soon as GPIO consumers have been registered, assign
  633. * their dev_names to respective GPIO lookup tables.
  634. */
  635. ams_delta_audio_gpio_table.dev_id =
  636. dev_name(&ams_delta_audio_device.dev);
  637. keybrd_pwr_gpio_table.dev_id = dev_name(&keybrd_pwr_device.dev);
  638. ams_delta_nand_gpio_table.dev_id = dev_name(&ams_delta_nand_device.dev);
  639. ams_delta_lcd_gpio_table.dev_id = dev_name(&ams_delta_lcd_device.dev);
  640. /*
  641. * Once GPIO lookup tables are populated with dev_names, register them.
  642. */
  643. gpiod_add_lookup_tables(ams_delta_gpio_tables,
  644. ARRAY_SIZE(ams_delta_gpio_tables));
  645. leds_pdev = gpio_led_register_device(PLATFORM_DEVID_NONE, &leds_pdata);
  646. if (!IS_ERR_OR_NULL(leds_pdev)) {
  647. leds_gpio_table.dev_id = dev_name(&leds_pdev->dev);
  648. gpiod_add_lookup_table(&leds_gpio_table);
  649. }
  650. omap_writew(omap_readw(ARM_RSTCT1) | 0x0004, ARM_RSTCT1);
  651. omapfb_set_lcd_config(&ams_delta_lcd_config);
  652. }
  653. static void modem_pm(struct uart_port *port, unsigned int state, unsigned old)
  654. {
  655. struct modem_private_data *priv = port->private_data;
  656. int ret;
  657. if (!priv)
  658. return;
  659. if (IS_ERR(priv->regulator))
  660. return;
  661. if (state == old)
  662. return;
  663. if (state == 0)
  664. ret = regulator_enable(priv->regulator);
  665. else if (old == 0)
  666. ret = regulator_disable(priv->regulator);
  667. else
  668. ret = 0;
  669. if (ret)
  670. dev_warn(port->dev,
  671. "ams_delta modem_pm: failed to %sable regulator: %d\n",
  672. state ? "dis" : "en", ret);
  673. }
  674. static struct plat_serial8250_port ams_delta_modem_ports[] = {
  675. {
  676. .membase = IOMEM(MODEM_VIRT),
  677. .mapbase = MODEM_PHYS,
  678. .irq = IRQ_NOTCONNECTED, /* changed later */
  679. .flags = UPF_BOOT_AUTOCONF,
  680. .irqflags = IRQF_TRIGGER_RISING,
  681. .iotype = UPIO_MEM,
  682. .regshift = 1,
  683. .uartclk = BASE_BAUD * 16,
  684. .pm = modem_pm,
  685. .private_data = &modem_priv,
  686. },
  687. { },
  688. };
  689. static int ams_delta_modem_pm_activate(struct device *dev)
  690. {
  691. modem_priv.regulator = regulator_get(dev, "RESET#");
  692. if (IS_ERR(modem_priv.regulator))
  693. return -EPROBE_DEFER;
  694. return 0;
  695. }
  696. static struct dev_pm_domain ams_delta_modem_pm_domain = {
  697. .activate = ams_delta_modem_pm_activate,
  698. };
  699. static struct platform_device ams_delta_modem_device = {
  700. .name = "serial8250",
  701. .id = PLAT8250_DEV_PLATFORM1,
  702. .dev = {
  703. .platform_data = ams_delta_modem_ports,
  704. .pm_domain = &ams_delta_modem_pm_domain,
  705. },
  706. };
  707. /*
  708. * This function expects MODEM IRQ number already assigned to the port.
  709. * The MODEM device requires its RESET# pin kept high during probe.
  710. * That requirement can be fulfilled in several ways:
  711. * - with a descriptor of already functional modem_nreset regulator
  712. * assigned to the MODEM private data,
  713. * - with the regulator not yet controlled by modem_pm function but
  714. * already enabled by default on probe,
  715. * - before the modem_nreset regulator is probed, with the pin already
  716. * set high explicitly.
  717. * The last one is already guaranteed by ams_delta_latch2_init() called
  718. * from machine_init.
  719. * In order to avoid taking over ttyS0 device slot, the MODEM device
  720. * should be registered after OMAP serial ports. Since those ports
  721. * are registered at arch_initcall, this function can be called safely
  722. * at arch_initcall_sync earliest.
  723. */
  724. static int __init ams_delta_modem_init(void)
  725. {
  726. if (!machine_is_ams_delta())
  727. return -ENODEV;
  728. omap_cfg_reg(M14_1510_GPIO2);
  729. /* Initialize the modem_nreset regulator consumer before use */
  730. modem_priv.regulator = ERR_PTR(-ENODEV);
  731. return platform_device_register(&ams_delta_modem_device);
  732. }
  733. arch_initcall_sync(ams_delta_modem_init);
  734. static void __init ams_delta_map_io(void)
  735. {
  736. omap1_map_io();
  737. iotable_init(ams_delta_io_desc, ARRAY_SIZE(ams_delta_io_desc));
  738. }
  739. MACHINE_START(AMS_DELTA, "Amstrad E3 (Delta)")
  740. /* Maintainer: Jonathan McDowell <noodles@earth.li> */
  741. .atag_offset = 0x100,
  742. .map_io = ams_delta_map_io,
  743. .init_early = omap1_init_early,
  744. .init_irq = omap1_init_irq,
  745. .init_machine = ams_delta_init,
  746. .init_late = omap1_init_late,
  747. .init_time = omap1_timer_init,
  748. .restart = omap1_restart,
  749. MACHINE_END