board-ams-delta.c 25 KB

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