board-ams-delta.c 23 KB

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