board-ams-delta.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  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 const struct gpio latch_gpios[] __initconst = {
  223. {
  224. .gpio = LATCH1_GPIO_BASE + 6,
  225. .flags = GPIOF_OUT_INIT_LOW,
  226. .label = "dockit1",
  227. },
  228. {
  229. .gpio = LATCH1_GPIO_BASE + 7,
  230. .flags = GPIOF_OUT_INIT_LOW,
  231. .label = "dockit2",
  232. },
  233. {
  234. .gpio = AMS_DELTA_GPIO_PIN_SCARD_RSTIN,
  235. .flags = GPIOF_OUT_INIT_LOW,
  236. .label = "scard_rstin",
  237. },
  238. {
  239. .gpio = AMS_DELTA_GPIO_PIN_SCARD_CMDVCC,
  240. .flags = GPIOF_OUT_INIT_LOW,
  241. .label = "scard_cmdvcc",
  242. },
  243. {
  244. .gpio = AMS_DELTA_LATCH2_GPIO_BASE + 14,
  245. .flags = GPIOF_OUT_INIT_LOW,
  246. .label = "hookflash1",
  247. },
  248. {
  249. .gpio = AMS_DELTA_LATCH2_GPIO_BASE + 15,
  250. .flags = GPIOF_OUT_INIT_LOW,
  251. .label = "hookflash2",
  252. },
  253. };
  254. static struct regulator_consumer_supply modem_nreset_consumers[] = {
  255. REGULATOR_SUPPLY("RESET#", "serial8250.1"),
  256. REGULATOR_SUPPLY("POR", "cx20442-codec"),
  257. };
  258. static struct regulator_init_data modem_nreset_data = {
  259. .constraints = {
  260. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  261. .boot_on = 1,
  262. },
  263. .num_consumer_supplies = ARRAY_SIZE(modem_nreset_consumers),
  264. .consumer_supplies = modem_nreset_consumers,
  265. };
  266. static struct fixed_voltage_config modem_nreset_config = {
  267. .supply_name = "modem_nreset",
  268. .microvolts = 3300000,
  269. .gpio = AMS_DELTA_GPIO_PIN_MODEM_NRESET,
  270. .startup_delay = 25000,
  271. .enable_high = 1,
  272. .enabled_at_boot = 1,
  273. .init_data = &modem_nreset_data,
  274. };
  275. static struct platform_device modem_nreset_device = {
  276. .name = "reg-fixed-voltage",
  277. .id = -1,
  278. .dev = {
  279. .platform_data = &modem_nreset_config,
  280. },
  281. };
  282. struct modem_private_data {
  283. struct regulator *regulator;
  284. };
  285. static struct modem_private_data modem_priv;
  286. void ams_delta_latch_write(int base, int ngpio, u16 mask, u16 value)
  287. {
  288. int bit = 0;
  289. u16 bitpos = 1 << bit;
  290. for (; bit < ngpio; bit++, bitpos = bitpos << 1) {
  291. if (!(mask & bitpos))
  292. continue;
  293. else
  294. gpio_set_value(base + bit, (value & bitpos) != 0);
  295. }
  296. }
  297. EXPORT_SYMBOL(ams_delta_latch_write);
  298. static struct resource ams_delta_nand_resources[] = {
  299. [0] = {
  300. .start = OMAP1_MPUIO_BASE,
  301. .end = OMAP1_MPUIO_BASE +
  302. OMAP_MPUIO_IO_CNTL + sizeof(u32) - 1,
  303. .flags = IORESOURCE_MEM,
  304. },
  305. };
  306. static struct platform_device ams_delta_nand_device = {
  307. .name = "ams-delta-nand",
  308. .id = -1,
  309. .num_resources = ARRAY_SIZE(ams_delta_nand_resources),
  310. .resource = ams_delta_nand_resources,
  311. };
  312. #define OMAP_GPIO_LABEL "gpio-0-15"
  313. static struct gpiod_lookup_table ams_delta_nand_gpio_table = {
  314. .table = {
  315. GPIO_LOOKUP(OMAP_GPIO_LABEL, AMS_DELTA_GPIO_PIN_NAND_RB, "rdy",
  316. 0),
  317. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NCE, "nce", 0),
  318. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NRE, "nre", 0),
  319. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NWP, "nwp", 0),
  320. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NWE, "nwe", 0),
  321. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_ALE, "ale", 0),
  322. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_CLE, "cle", 0),
  323. { },
  324. },
  325. };
  326. static struct resource ams_delta_kp_resources[] = {
  327. [0] = {
  328. .start = INT_KEYBOARD,
  329. .end = INT_KEYBOARD,
  330. .flags = IORESOURCE_IRQ,
  331. },
  332. };
  333. static const struct matrix_keymap_data ams_delta_keymap_data = {
  334. .keymap = ams_delta_keymap,
  335. .keymap_size = ARRAY_SIZE(ams_delta_keymap),
  336. };
  337. static struct omap_kp_platform_data ams_delta_kp_data = {
  338. .rows = 8,
  339. .cols = 8,
  340. .keymap_data = &ams_delta_keymap_data,
  341. .delay = 9,
  342. };
  343. static struct platform_device ams_delta_kp_device = {
  344. .name = "omap-keypad",
  345. .id = -1,
  346. .dev = {
  347. .platform_data = &ams_delta_kp_data,
  348. },
  349. .num_resources = ARRAY_SIZE(ams_delta_kp_resources),
  350. .resource = ams_delta_kp_resources,
  351. };
  352. static struct platform_device ams_delta_lcd_device = {
  353. .name = "lcd_ams_delta",
  354. .id = -1,
  355. };
  356. static struct gpiod_lookup_table ams_delta_lcd_gpio_table = {
  357. .table = {
  358. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_LCD_VBLEN, "vblen", 0),
  359. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_LCD_NDISP, "ndisp", 0),
  360. { },
  361. },
  362. };
  363. /*
  364. * Dynamically allocated GPIO numbers must be obtained fromm GPIO device
  365. * before they can be put in the gpio_led table. Before that happens,
  366. * initialize the table with invalid GPIO numbers, not 0.
  367. */
  368. static struct gpio_led gpio_leds[] __initdata = {
  369. [LATCH1_PIN_LED_CAMERA] = {
  370. .name = "camera",
  371. .gpio = -EINVAL,
  372. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  373. #ifdef CONFIG_LEDS_TRIGGERS
  374. .default_trigger = "ams_delta_camera",
  375. #endif
  376. },
  377. [LATCH1_PIN_LED_ADVERT] = {
  378. .name = "advert",
  379. .gpio = -EINVAL,
  380. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  381. },
  382. [LATCH1_PIN_LED_MAIL] = {
  383. .name = "email",
  384. .gpio = -EINVAL,
  385. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  386. },
  387. [LATCH1_PIN_LED_HANDSFREE] = {
  388. .name = "handsfree",
  389. .gpio = -EINVAL,
  390. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  391. },
  392. [LATCH1_PIN_LED_VOICEMAIL] = {
  393. .name = "voicemail",
  394. .gpio = -EINVAL,
  395. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  396. },
  397. [LATCH1_PIN_LED_VOICE] = {
  398. .name = "voice",
  399. .gpio = -EINVAL,
  400. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  401. },
  402. };
  403. static const struct gpio_led_platform_data leds_pdata __initconst = {
  404. .leds = gpio_leds,
  405. .num_leds = ARRAY_SIZE(gpio_leds),
  406. };
  407. static struct i2c_board_info ams_delta_camera_board_info[] = {
  408. {
  409. I2C_BOARD_INFO("ov6650", 0x60),
  410. },
  411. };
  412. #ifdef CONFIG_LEDS_TRIGGERS
  413. DEFINE_LED_TRIGGER(ams_delta_camera_led_trigger);
  414. static int ams_delta_camera_power(struct device *dev, int power)
  415. {
  416. /*
  417. * turn on camera LED
  418. */
  419. if (power)
  420. led_trigger_event(ams_delta_camera_led_trigger, LED_FULL);
  421. else
  422. led_trigger_event(ams_delta_camera_led_trigger, LED_OFF);
  423. return 0;
  424. }
  425. #else
  426. #define ams_delta_camera_power NULL
  427. #endif
  428. static struct soc_camera_link ams_delta_iclink = {
  429. .bus_id = 0, /* OMAP1 SoC camera bus */
  430. .i2c_adapter_id = 1,
  431. .board_info = &ams_delta_camera_board_info[0],
  432. .module_name = "ov6650",
  433. .power = ams_delta_camera_power,
  434. };
  435. static struct platform_device ams_delta_camera_device = {
  436. .name = "soc-camera-pdrv",
  437. .id = 0,
  438. .dev = {
  439. .platform_data = &ams_delta_iclink,
  440. },
  441. };
  442. static struct omap1_cam_platform_data ams_delta_camera_platform_data = {
  443. .camexclk_khz = 12000, /* default 12MHz clock, no extra DPLL */
  444. .lclk_khz_max = 1334, /* results in 5fps CIF, 10fps QCIF */
  445. };
  446. static struct platform_device ams_delta_audio_device = {
  447. .name = "ams-delta-audio",
  448. .id = -1,
  449. };
  450. static struct gpiod_lookup_table ams_delta_audio_gpio_table = {
  451. .table = {
  452. GPIO_LOOKUP(OMAP_GPIO_LABEL, AMS_DELTA_GPIO_PIN_HOOK_SWITCH,
  453. "hook_switch", 0),
  454. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_MODEM_CODEC,
  455. "modem_codec", 0),
  456. { },
  457. },
  458. };
  459. static struct platform_device cx20442_codec_device = {
  460. .name = "cx20442-codec",
  461. .id = -1,
  462. };
  463. static struct resource ams_delta_serio_resources[] = {
  464. {
  465. .flags = IORESOURCE_IRQ,
  466. /*
  467. * Initialize IRQ resource with invalid IRQ number.
  468. * It will be replaced with dynamically allocated GPIO IRQ
  469. * obtained from GPIO chip as soon as the chip is available.
  470. */
  471. .start = -EINVAL,
  472. .end = -EINVAL,
  473. },
  474. };
  475. static struct platform_device ams_delta_serio_device = {
  476. .name = "ams-delta-serio",
  477. .id = PLATFORM_DEVID_NONE,
  478. .dev = {
  479. /*
  480. * Initialize .platform_data explicitly with NULL to
  481. * indicate it is going to be used. It will be replaced
  482. * with FIQ buffer address as soon as FIQ is initialized.
  483. */
  484. .platform_data = NULL,
  485. },
  486. .num_resources = ARRAY_SIZE(ams_delta_serio_resources),
  487. .resource = ams_delta_serio_resources,
  488. };
  489. static struct regulator_consumer_supply keybrd_pwr_consumers[] = {
  490. /*
  491. * Initialize supply .dev_name with NULL. It will be replaced
  492. * with serio dev_name() as soon as the serio device is registered.
  493. */
  494. REGULATOR_SUPPLY("vcc", NULL),
  495. };
  496. static struct regulator_init_data keybrd_pwr_initdata = {
  497. .constraints = {
  498. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  499. },
  500. .num_consumer_supplies = ARRAY_SIZE(keybrd_pwr_consumers),
  501. .consumer_supplies = keybrd_pwr_consumers,
  502. };
  503. static struct fixed_voltage_config keybrd_pwr_config = {
  504. .supply_name = "keybrd_pwr",
  505. .microvolts = 5000000,
  506. .gpio = AMS_DELTA_GPIO_PIN_KEYBRD_PWR,
  507. .enable_high = 1,
  508. .init_data = &keybrd_pwr_initdata,
  509. };
  510. static struct platform_device keybrd_pwr_device = {
  511. .name = "reg-fixed-voltage",
  512. .id = PLATFORM_DEVID_AUTO,
  513. .dev = {
  514. .platform_data = &keybrd_pwr_config,
  515. },
  516. };
  517. static struct gpiod_lookup_table keybrd_pwr_gpio_table = {
  518. .table = {
  519. GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_KEYBRD_PWR, NULL,
  520. GPIO_ACTIVE_HIGH),
  521. { },
  522. },
  523. };
  524. static struct platform_device *ams_delta_devices[] __initdata = {
  525. &latch1_gpio_device,
  526. &latch2_gpio_device,
  527. &ams_delta_kp_device,
  528. &ams_delta_camera_device,
  529. &ams_delta_audio_device,
  530. &ams_delta_serio_device,
  531. &ams_delta_nand_device,
  532. &ams_delta_lcd_device,
  533. &cx20442_codec_device,
  534. };
  535. static struct gpiod_lookup_table *ams_delta_gpio_tables[] __initdata = {
  536. &ams_delta_audio_gpio_table,
  537. &keybrd_pwr_gpio_table,
  538. &ams_delta_lcd_gpio_table,
  539. &ams_delta_nand_gpio_table,
  540. };
  541. /*
  542. * Some drivers may not use GPIO lookup tables but need to be provided
  543. * with GPIO numbers. The same applies to GPIO based IRQ lines - some
  544. * drivers may even not use GPIO layer but expect just IRQ numbers.
  545. * We could either define GPIO lookup tables then use them on behalf
  546. * of those devices, or we can use GPIO driver level methods for
  547. * identification of GPIO and IRQ numbers. For the purpose of the latter,
  548. * defina a helper function which identifies GPIO chips by their labels.
  549. */
  550. static int gpiochip_match_by_label(struct gpio_chip *chip, void *data)
  551. {
  552. char *label = data;
  553. return !strcmp(label, chip->label);
  554. }
  555. static struct gpiod_hog ams_delta_gpio_hogs[] = {
  556. GPIO_HOG(LATCH2_LABEL, LATCH2_PIN_KEYBRD_DATAOUT, "keybrd_dataout",
  557. GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW),
  558. {},
  559. };
  560. /*
  561. * The purpose of this function is to take care of proper initialization of
  562. * devices and data structures which depend on GPIO lines provided by OMAP GPIO
  563. * banks but their drivers don't use GPIO lookup tables or GPIO layer at all.
  564. * The function may be called as soon as OMAP GPIO devices are probed.
  565. * Since that happens at postcore_initcall, it can be called successfully
  566. * from init_machine or later.
  567. * Dependent devices may be registered from within this function or later.
  568. */
  569. static void __init omap_gpio_deps_init(void)
  570. {
  571. struct gpio_chip *chip;
  572. chip = gpiochip_find(OMAP_GPIO_LABEL, gpiochip_match_by_label);
  573. if (!chip) {
  574. pr_err("%s: OMAP GPIO chip not found\n", __func__);
  575. return;
  576. }
  577. ams_delta_init_fiq(chip, &ams_delta_serio_device);
  578. }
  579. static void __init ams_delta_init(void)
  580. {
  581. /* mux pins for uarts */
  582. omap_cfg_reg(UART1_TX);
  583. omap_cfg_reg(UART1_RTS);
  584. /* parallel camera interface */
  585. omap_cfg_reg(H19_1610_CAM_EXCLK);
  586. omap_cfg_reg(J15_1610_CAM_LCLK);
  587. omap_cfg_reg(L18_1610_CAM_VS);
  588. omap_cfg_reg(L15_1610_CAM_HS);
  589. omap_cfg_reg(L19_1610_CAM_D0);
  590. omap_cfg_reg(K14_1610_CAM_D1);
  591. omap_cfg_reg(K15_1610_CAM_D2);
  592. omap_cfg_reg(K19_1610_CAM_D3);
  593. omap_cfg_reg(K18_1610_CAM_D4);
  594. omap_cfg_reg(J14_1610_CAM_D5);
  595. omap_cfg_reg(J19_1610_CAM_D6);
  596. omap_cfg_reg(J18_1610_CAM_D7);
  597. omap_gpio_deps_init();
  598. gpiod_add_hogs(ams_delta_gpio_hogs);
  599. omap_serial_init();
  600. omap_register_i2c_bus(1, 100, NULL, 0);
  601. omap1_usb_init(&ams_delta_usb_config);
  602. omap1_set_camera_info(&ams_delta_camera_platform_data);
  603. #ifdef CONFIG_LEDS_TRIGGERS
  604. led_trigger_register_simple("ams_delta_camera",
  605. &ams_delta_camera_led_trigger);
  606. #endif
  607. platform_add_devices(ams_delta_devices, ARRAY_SIZE(ams_delta_devices));
  608. /*
  609. * As soon as regulator consumers have been registered, assign their
  610. * dev_names to consumer supply entries of respective regulators.
  611. */
  612. keybrd_pwr_consumers[0].dev_name =
  613. dev_name(&ams_delta_serio_device.dev);
  614. /*
  615. * Once consumer supply entries are populated with dev_names,
  616. * register regulator devices. At this stage only the keyboard
  617. * power regulator has its consumer supply table fully populated.
  618. */
  619. platform_device_register(&keybrd_pwr_device);
  620. /*
  621. * As soon as GPIO consumers have been registered, assign
  622. * their dev_names to respective GPIO lookup tables.
  623. */
  624. ams_delta_audio_gpio_table.dev_id =
  625. dev_name(&ams_delta_audio_device.dev);
  626. keybrd_pwr_gpio_table.dev_id = dev_name(&keybrd_pwr_device.dev);
  627. ams_delta_nand_gpio_table.dev_id = dev_name(&ams_delta_nand_device.dev);
  628. ams_delta_lcd_gpio_table.dev_id = dev_name(&ams_delta_lcd_device.dev);
  629. /*
  630. * Once GPIO lookup tables are populated with dev_names, register them.
  631. */
  632. gpiod_add_lookup_tables(ams_delta_gpio_tables,
  633. ARRAY_SIZE(ams_delta_gpio_tables));
  634. omap_writew(omap_readw(ARM_RSTCT1) | 0x0004, ARM_RSTCT1);
  635. omapfb_set_lcd_config(&ams_delta_lcd_config);
  636. }
  637. static void modem_pm(struct uart_port *port, unsigned int state, unsigned old)
  638. {
  639. struct modem_private_data *priv = port->private_data;
  640. int ret;
  641. if (!priv)
  642. return;
  643. if (IS_ERR(priv->regulator))
  644. return;
  645. if (state == old)
  646. return;
  647. if (state == 0)
  648. ret = regulator_enable(priv->regulator);
  649. else if (old == 0)
  650. ret = regulator_disable(priv->regulator);
  651. else
  652. ret = 0;
  653. if (ret)
  654. dev_warn(port->dev,
  655. "ams_delta modem_pm: failed to %sable regulator: %d\n",
  656. state ? "dis" : "en", ret);
  657. }
  658. static struct plat_serial8250_port ams_delta_modem_ports[] = {
  659. {
  660. .membase = IOMEM(MODEM_VIRT),
  661. .mapbase = MODEM_PHYS,
  662. .irq = -EINVAL, /* changed later */
  663. .flags = UPF_BOOT_AUTOCONF,
  664. .irqflags = IRQF_TRIGGER_RISING,
  665. .iotype = UPIO_MEM,
  666. .regshift = 1,
  667. .uartclk = BASE_BAUD * 16,
  668. .pm = modem_pm,
  669. .private_data = &modem_priv,
  670. },
  671. { },
  672. };
  673. static struct platform_device ams_delta_modem_device = {
  674. .name = "serial8250",
  675. .id = PLAT8250_DEV_PLATFORM1,
  676. .dev = {
  677. .platform_data = ams_delta_modem_ports,
  678. },
  679. };
  680. /*
  681. * leds-gpio driver doesn't make use of GPIO lookup tables,
  682. * it has to be provided with GPIO numbers over platform data
  683. * if GPIO descriptor info can't be obtained from device tree.
  684. * We could either define GPIO lookup tables and use them on behalf
  685. * of the leds-gpio device, or we can use GPIO driver level methods
  686. * for identification of GPIO numbers as long as we don't support
  687. * device tree. Let's do the latter.
  688. */
  689. static void __init ams_delta_led_init(struct gpio_chip *chip)
  690. {
  691. struct gpio_desc *gpiod;
  692. int i;
  693. for (i = LATCH1_PIN_LED_CAMERA; i < LATCH1_PIN_DOCKIT1; i++) {
  694. gpiod = gpiochip_request_own_desc(chip, i, NULL);
  695. if (IS_ERR(gpiod)) {
  696. pr_warn("%s: %s GPIO %d request failed (%ld)\n",
  697. __func__, LATCH1_LABEL, i, PTR_ERR(gpiod));
  698. continue;
  699. }
  700. /* Assign GPIO numbers to LED device. */
  701. gpio_leds[i].gpio = desc_to_gpio(gpiod);
  702. gpiochip_free_own_desc(gpiod);
  703. }
  704. gpio_led_register_device(PLATFORM_DEVID_NONE, &leds_pdata);
  705. }
  706. /*
  707. * The purpose of this function is to take care of assignment of GPIO numbers
  708. * to platform devices which depend on GPIO lines provided by Amstrad Delta
  709. * latch1 and/or latch2 GPIO devices but don't use GPIO lookup tables.
  710. * The function may be called as soon as latch1/latch2 GPIO devices are
  711. * initilized. Since basic-mmio-gpio driver is not registered before
  712. * device_initcall, this may happen at erliest during device_initcall_sync.
  713. * Dependent devices shouldn't be registered before that, their
  714. * registration may be performed from within this function or later.
  715. */
  716. static int __init ams_delta_gpio_init(void)
  717. {
  718. struct gpio_chip *chip;
  719. int err;
  720. if (!machine_is_ams_delta())
  721. return -ENODEV;
  722. chip = gpiochip_find(LATCH1_LABEL, gpiochip_match_by_label);
  723. if (!chip)
  724. pr_err("%s: latch1 GPIO chip not found\n", __func__);
  725. else
  726. ams_delta_led_init(chip);
  727. err = gpio_request_array(latch_gpios, ARRAY_SIZE(latch_gpios));
  728. if (err)
  729. pr_err("Couldn't take over latch1/latch2 GPIO pins\n");
  730. return err;
  731. }
  732. device_initcall_sync(ams_delta_gpio_init);
  733. static int __init modem_nreset_init(void)
  734. {
  735. int err;
  736. err = platform_device_register(&modem_nreset_device);
  737. if (err)
  738. pr_err("Couldn't register the modem regulator device\n");
  739. return err;
  740. }
  741. static int __init ams_delta_modem_init(void)
  742. {
  743. int err;
  744. omap_cfg_reg(M14_1510_GPIO2);
  745. ams_delta_modem_ports[0].irq =
  746. gpio_to_irq(AMS_DELTA_GPIO_PIN_MODEM_IRQ);
  747. err = gpio_request(AMS_DELTA_GPIO_PIN_MODEM_IRQ, "modem");
  748. if (err) {
  749. pr_err("Couldn't request gpio pin for modem\n");
  750. return err;
  751. }
  752. gpio_direction_input(AMS_DELTA_GPIO_PIN_MODEM_IRQ);
  753. /* Initialize the modem_nreset regulator consumer before use */
  754. modem_priv.regulator = ERR_PTR(-ENODEV);
  755. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC,
  756. AMS_DELTA_LATCH2_MODEM_CODEC);
  757. err = platform_device_register(&ams_delta_modem_device);
  758. if (err)
  759. gpio_free(AMS_DELTA_GPIO_PIN_MODEM_IRQ);
  760. return err;
  761. }
  762. static int __init late_init(void)
  763. {
  764. int err;
  765. err = modem_nreset_init();
  766. if (err)
  767. return err;
  768. err = ams_delta_modem_init();
  769. if (err)
  770. return err;
  771. /*
  772. * Once the modem device is registered, the modem_nreset
  773. * regulator can be requested on behalf of that device.
  774. */
  775. modem_priv.regulator = regulator_get(&ams_delta_modem_device.dev,
  776. "RESET#");
  777. if (IS_ERR(modem_priv.regulator)) {
  778. err = PTR_ERR(modem_priv.regulator);
  779. goto unregister;
  780. }
  781. return 0;
  782. unregister:
  783. platform_device_unregister(&ams_delta_modem_device);
  784. gpio_free(AMS_DELTA_GPIO_PIN_MODEM_IRQ);
  785. return err;
  786. }
  787. static void __init ams_delta_init_late(void)
  788. {
  789. omap1_init_late();
  790. late_init();
  791. }
  792. static void __init ams_delta_map_io(void)
  793. {
  794. omap15xx_map_io();
  795. iotable_init(ams_delta_io_desc, ARRAY_SIZE(ams_delta_io_desc));
  796. }
  797. MACHINE_START(AMS_DELTA, "Amstrad E3 (Delta)")
  798. /* Maintainer: Jonathan McDowell <noodles@earth.li> */
  799. .atag_offset = 0x100,
  800. .map_io = ams_delta_map_io,
  801. .init_early = omap1_init_early,
  802. .init_irq = omap1_init_irq,
  803. .handle_irq = omap1_handle_irq,
  804. .init_machine = ams_delta_init,
  805. .init_late = ams_delta_init_late,
  806. .init_time = omap1_timer_init,
  807. .restart = omap1_restart,
  808. MACHINE_END