core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  2. * arch/arm/mach-ep93xx/core.c
  3. * Core routines for Cirrus EP93xx chips.
  4. *
  5. * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
  6. * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
  7. *
  8. * Thanks go to Michael Burian and Ray Lehtiniemi for their key
  9. * role in the ep93xx linux community.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or (at
  14. * your option) any later version.
  15. */
  16. #define pr_fmt(fmt) "ep93xx " KBUILD_MODNAME ": " fmt
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/timex.h>
  23. #include <linux/irq.h>
  24. #include <linux/io.h>
  25. #include <linux/gpio.h>
  26. #include <linux/leds.h>
  27. #include <linux/termios.h>
  28. #include <linux/amba/bus.h>
  29. #include <linux/amba/serial.h>
  30. #include <linux/i2c.h>
  31. #include <linux/i2c-gpio.h>
  32. #include <mach/hardware.h>
  33. #include <mach/fb.h>
  34. #include <mach/ep93xx_keypad.h>
  35. #include <asm/mach/map.h>
  36. #include <asm/mach/time.h>
  37. #include <asm/hardware/vic.h>
  38. /*************************************************************************
  39. * Static I/O mappings that are needed for all EP93xx platforms
  40. *************************************************************************/
  41. static struct map_desc ep93xx_io_desc[] __initdata = {
  42. {
  43. .virtual = EP93XX_AHB_VIRT_BASE,
  44. .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
  45. .length = EP93XX_AHB_SIZE,
  46. .type = MT_DEVICE,
  47. }, {
  48. .virtual = EP93XX_APB_VIRT_BASE,
  49. .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE),
  50. .length = EP93XX_APB_SIZE,
  51. .type = MT_DEVICE,
  52. },
  53. };
  54. void __init ep93xx_map_io(void)
  55. {
  56. iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
  57. }
  58. /*************************************************************************
  59. * Timer handling for EP93xx
  60. *************************************************************************
  61. * The ep93xx has four internal timers. Timers 1, 2 (both 16 bit) and
  62. * 3 (32 bit) count down at 508 kHz, are self-reloading, and can generate
  63. * an interrupt on underflow. Timer 4 (40 bit) counts down at 983.04 kHz,
  64. * is free-running, and can't generate interrupts.
  65. *
  66. * The 508 kHz timers are ideal for use for the timer interrupt, as the
  67. * most common values of HZ divide 508 kHz nicely. We pick one of the 16
  68. * bit timers (timer 1) since we don't need more than 16 bits of reload
  69. * value as long as HZ >= 8.
  70. *
  71. * The higher clock rate of timer 4 makes it a better choice than the
  72. * other timers for use in gettimeoffset(), while the fact that it can't
  73. * generate interrupts means we don't have to worry about not being able
  74. * to use this timer for something else. We also use timer 4 for keeping
  75. * track of lost jiffies.
  76. */
  77. #define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
  78. #define EP93XX_TIMER1_LOAD EP93XX_TIMER_REG(0x00)
  79. #define EP93XX_TIMER1_VALUE EP93XX_TIMER_REG(0x04)
  80. #define EP93XX_TIMER1_CONTROL EP93XX_TIMER_REG(0x08)
  81. #define EP93XX_TIMER123_CONTROL_ENABLE (1 << 7)
  82. #define EP93XX_TIMER123_CONTROL_MODE (1 << 6)
  83. #define EP93XX_TIMER123_CONTROL_CLKSEL (1 << 3)
  84. #define EP93XX_TIMER1_CLEAR EP93XX_TIMER_REG(0x0c)
  85. #define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
  86. #define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
  87. #define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
  88. #define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
  89. #define EP93XX_TIMER4_VALUE_LOW EP93XX_TIMER_REG(0x60)
  90. #define EP93XX_TIMER4_VALUE_HIGH EP93XX_TIMER_REG(0x64)
  91. #define EP93XX_TIMER4_VALUE_HIGH_ENABLE (1 << 8)
  92. #define EP93XX_TIMER3_LOAD EP93XX_TIMER_REG(0x80)
  93. #define EP93XX_TIMER3_VALUE EP93XX_TIMER_REG(0x84)
  94. #define EP93XX_TIMER3_CONTROL EP93XX_TIMER_REG(0x88)
  95. #define EP93XX_TIMER3_CLEAR EP93XX_TIMER_REG(0x8c)
  96. #define EP93XX_TIMER123_CLOCK 508469
  97. #define EP93XX_TIMER4_CLOCK 983040
  98. #define TIMER1_RELOAD ((EP93XX_TIMER123_CLOCK / HZ) - 1)
  99. #define TIMER4_TICKS_PER_JIFFY DIV_ROUND_CLOSEST(CLOCK_TICK_RATE, HZ)
  100. static unsigned int last_jiffy_time;
  101. static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
  102. {
  103. /* Writing any value clears the timer interrupt */
  104. __raw_writel(1, EP93XX_TIMER1_CLEAR);
  105. /* Recover lost jiffies */
  106. while ((signed long)
  107. (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
  108. >= TIMER4_TICKS_PER_JIFFY) {
  109. last_jiffy_time += TIMER4_TICKS_PER_JIFFY;
  110. timer_tick();
  111. }
  112. return IRQ_HANDLED;
  113. }
  114. static struct irqaction ep93xx_timer_irq = {
  115. .name = "ep93xx timer",
  116. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  117. .handler = ep93xx_timer_interrupt,
  118. };
  119. static void __init ep93xx_timer_init(void)
  120. {
  121. u32 tmode = EP93XX_TIMER123_CONTROL_MODE |
  122. EP93XX_TIMER123_CONTROL_CLKSEL;
  123. /* Enable periodic HZ timer. */
  124. __raw_writel(tmode, EP93XX_TIMER1_CONTROL);
  125. __raw_writel(TIMER1_RELOAD, EP93XX_TIMER1_LOAD);
  126. __raw_writel(tmode | EP93XX_TIMER123_CONTROL_ENABLE,
  127. EP93XX_TIMER1_CONTROL);
  128. /* Enable lost jiffy timer. */
  129. __raw_writel(EP93XX_TIMER4_VALUE_HIGH_ENABLE,
  130. EP93XX_TIMER4_VALUE_HIGH);
  131. setup_irq(IRQ_EP93XX_TIMER1, &ep93xx_timer_irq);
  132. }
  133. static unsigned long ep93xx_gettimeoffset(void)
  134. {
  135. int offset;
  136. offset = __raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time;
  137. /* Calculate (1000000 / 983040) * offset. */
  138. return offset + (53 * offset / 3072);
  139. }
  140. struct sys_timer ep93xx_timer = {
  141. .init = ep93xx_timer_init,
  142. .offset = ep93xx_gettimeoffset,
  143. };
  144. /*************************************************************************
  145. * EP93xx IRQ handling
  146. *************************************************************************/
  147. extern void ep93xx_gpio_init_irq(void);
  148. void __init ep93xx_init_irq(void)
  149. {
  150. vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
  151. vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
  152. ep93xx_gpio_init_irq();
  153. }
  154. /*************************************************************************
  155. * EP93xx System Controller Software Locked register handling
  156. *************************************************************************/
  157. /*
  158. * syscon_swlock prevents anything else from writing to the syscon
  159. * block while a software locked register is being written.
  160. */
  161. static DEFINE_SPINLOCK(syscon_swlock);
  162. void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
  163. {
  164. unsigned long flags;
  165. spin_lock_irqsave(&syscon_swlock, flags);
  166. __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
  167. __raw_writel(val, reg);
  168. spin_unlock_irqrestore(&syscon_swlock, flags);
  169. }
  170. EXPORT_SYMBOL(ep93xx_syscon_swlocked_write);
  171. void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
  172. {
  173. unsigned long flags;
  174. unsigned int val;
  175. spin_lock_irqsave(&syscon_swlock, flags);
  176. val = __raw_readl(EP93XX_SYSCON_DEVCFG);
  177. val |= set_bits;
  178. val &= ~clear_bits;
  179. __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
  180. __raw_writel(val, EP93XX_SYSCON_DEVCFG);
  181. spin_unlock_irqrestore(&syscon_swlock, flags);
  182. }
  183. EXPORT_SYMBOL(ep93xx_devcfg_set_clear);
  184. /*************************************************************************
  185. * EP93xx peripheral handling
  186. *************************************************************************/
  187. #define EP93XX_UART_MCR_OFFSET (0x0100)
  188. static void ep93xx_uart_set_mctrl(struct amba_device *dev,
  189. void __iomem *base, unsigned int mctrl)
  190. {
  191. unsigned int mcr;
  192. mcr = 0;
  193. if (!(mctrl & TIOCM_RTS))
  194. mcr |= 2;
  195. if (!(mctrl & TIOCM_DTR))
  196. mcr |= 1;
  197. __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
  198. }
  199. static struct amba_pl010_data ep93xx_uart_data = {
  200. .set_mctrl = ep93xx_uart_set_mctrl,
  201. };
  202. static struct amba_device uart1_device = {
  203. .dev = {
  204. .init_name = "apb:uart1",
  205. .platform_data = &ep93xx_uart_data,
  206. },
  207. .res = {
  208. .start = EP93XX_UART1_PHYS_BASE,
  209. .end = EP93XX_UART1_PHYS_BASE + 0x0fff,
  210. .flags = IORESOURCE_MEM,
  211. },
  212. .irq = { IRQ_EP93XX_UART1, NO_IRQ },
  213. .periphid = 0x00041010,
  214. };
  215. static struct amba_device uart2_device = {
  216. .dev = {
  217. .init_name = "apb:uart2",
  218. .platform_data = &ep93xx_uart_data,
  219. },
  220. .res = {
  221. .start = EP93XX_UART2_PHYS_BASE,
  222. .end = EP93XX_UART2_PHYS_BASE + 0x0fff,
  223. .flags = IORESOURCE_MEM,
  224. },
  225. .irq = { IRQ_EP93XX_UART2, NO_IRQ },
  226. .periphid = 0x00041010,
  227. };
  228. static struct amba_device uart3_device = {
  229. .dev = {
  230. .init_name = "apb:uart3",
  231. .platform_data = &ep93xx_uart_data,
  232. },
  233. .res = {
  234. .start = EP93XX_UART3_PHYS_BASE,
  235. .end = EP93XX_UART3_PHYS_BASE + 0x0fff,
  236. .flags = IORESOURCE_MEM,
  237. },
  238. .irq = { IRQ_EP93XX_UART3, NO_IRQ },
  239. .periphid = 0x00041010,
  240. };
  241. static struct resource ep93xx_rtc_resource[] = {
  242. {
  243. .start = EP93XX_RTC_PHYS_BASE,
  244. .end = EP93XX_RTC_PHYS_BASE + 0x10c - 1,
  245. .flags = IORESOURCE_MEM,
  246. },
  247. };
  248. static struct platform_device ep93xx_rtc_device = {
  249. .name = "ep93xx-rtc",
  250. .id = -1,
  251. .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
  252. .resource = ep93xx_rtc_resource,
  253. };
  254. static struct resource ep93xx_ohci_resources[] = {
  255. [0] = {
  256. .start = EP93XX_USB_PHYS_BASE,
  257. .end = EP93XX_USB_PHYS_BASE + 0x0fff,
  258. .flags = IORESOURCE_MEM,
  259. },
  260. [1] = {
  261. .start = IRQ_EP93XX_USB,
  262. .end = IRQ_EP93XX_USB,
  263. .flags = IORESOURCE_IRQ,
  264. },
  265. };
  266. static struct platform_device ep93xx_ohci_device = {
  267. .name = "ep93xx-ohci",
  268. .id = -1,
  269. .dev = {
  270. .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask,
  271. .coherent_dma_mask = DMA_BIT_MASK(32),
  272. },
  273. .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
  274. .resource = ep93xx_ohci_resources,
  275. };
  276. static struct ep93xx_eth_data ep93xx_eth_data;
  277. static struct resource ep93xx_eth_resource[] = {
  278. {
  279. .start = EP93XX_ETHERNET_PHYS_BASE,
  280. .end = EP93XX_ETHERNET_PHYS_BASE + 0xffff,
  281. .flags = IORESOURCE_MEM,
  282. }, {
  283. .start = IRQ_EP93XX_ETHERNET,
  284. .end = IRQ_EP93XX_ETHERNET,
  285. .flags = IORESOURCE_IRQ,
  286. }
  287. };
  288. static struct platform_device ep93xx_eth_device = {
  289. .name = "ep93xx-eth",
  290. .id = -1,
  291. .dev = {
  292. .platform_data = &ep93xx_eth_data,
  293. },
  294. .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
  295. .resource = ep93xx_eth_resource,
  296. };
  297. void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
  298. {
  299. if (copy_addr)
  300. memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
  301. ep93xx_eth_data = *data;
  302. platform_device_register(&ep93xx_eth_device);
  303. }
  304. /*************************************************************************
  305. * EP93xx i2c peripheral handling
  306. *************************************************************************/
  307. static struct i2c_gpio_platform_data ep93xx_i2c_data;
  308. static struct platform_device ep93xx_i2c_device = {
  309. .name = "i2c-gpio",
  310. .id = 0,
  311. .dev.platform_data = &ep93xx_i2c_data,
  312. };
  313. void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
  314. struct i2c_board_info *devices, int num)
  315. {
  316. /*
  317. * Set the EEPROM interface pin drive type control.
  318. * Defines the driver type for the EECLK and EEDAT pins as either
  319. * open drain, which will require an external pull-up, or a normal
  320. * CMOS driver.
  321. */
  322. if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT)
  323. pr_warning("sda != EEDAT, open drain has no effect\n");
  324. if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
  325. pr_warning("scl != EECLK, open drain has no effect\n");
  326. __raw_writel((data->sda_is_open_drain << 1) |
  327. (data->scl_is_open_drain << 0),
  328. EP93XX_GPIO_EEDRIVE);
  329. ep93xx_i2c_data = *data;
  330. i2c_register_board_info(0, devices, num);
  331. platform_device_register(&ep93xx_i2c_device);
  332. }
  333. /*************************************************************************
  334. * EP93xx LEDs
  335. *************************************************************************/
  336. static struct gpio_led ep93xx_led_pins[] = {
  337. {
  338. .name = "platform:grled",
  339. .gpio = EP93XX_GPIO_LINE_GRLED,
  340. }, {
  341. .name = "platform:rdled",
  342. .gpio = EP93XX_GPIO_LINE_RDLED,
  343. },
  344. };
  345. static struct gpio_led_platform_data ep93xx_led_data = {
  346. .num_leds = ARRAY_SIZE(ep93xx_led_pins),
  347. .leds = ep93xx_led_pins,
  348. };
  349. static struct platform_device ep93xx_leds = {
  350. .name = "leds-gpio",
  351. .id = -1,
  352. .dev = {
  353. .platform_data = &ep93xx_led_data,
  354. },
  355. };
  356. /*************************************************************************
  357. * EP93xx pwm peripheral handling
  358. *************************************************************************/
  359. static struct resource ep93xx_pwm0_resource[] = {
  360. {
  361. .start = EP93XX_PWM_PHYS_BASE,
  362. .end = EP93XX_PWM_PHYS_BASE + 0x10 - 1,
  363. .flags = IORESOURCE_MEM,
  364. },
  365. };
  366. static struct platform_device ep93xx_pwm0_device = {
  367. .name = "ep93xx-pwm",
  368. .id = 0,
  369. .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
  370. .resource = ep93xx_pwm0_resource,
  371. };
  372. static struct resource ep93xx_pwm1_resource[] = {
  373. {
  374. .start = EP93XX_PWM_PHYS_BASE + 0x20,
  375. .end = EP93XX_PWM_PHYS_BASE + 0x30 - 1,
  376. .flags = IORESOURCE_MEM,
  377. },
  378. };
  379. static struct platform_device ep93xx_pwm1_device = {
  380. .name = "ep93xx-pwm",
  381. .id = 1,
  382. .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
  383. .resource = ep93xx_pwm1_resource,
  384. };
  385. void __init ep93xx_register_pwm(int pwm0, int pwm1)
  386. {
  387. if (pwm0)
  388. platform_device_register(&ep93xx_pwm0_device);
  389. /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
  390. if (pwm1)
  391. platform_device_register(&ep93xx_pwm1_device);
  392. }
  393. int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
  394. {
  395. int err;
  396. if (pdev->id == 0) {
  397. err = 0;
  398. } else if (pdev->id == 1) {
  399. err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
  400. dev_name(&pdev->dev));
  401. if (err)
  402. return err;
  403. err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
  404. if (err)
  405. goto fail;
  406. /* PWM 1 output on EGPIO[14] */
  407. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
  408. } else {
  409. err = -ENODEV;
  410. }
  411. return err;
  412. fail:
  413. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  414. return err;
  415. }
  416. EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
  417. void ep93xx_pwm_release_gpio(struct platform_device *pdev)
  418. {
  419. if (pdev->id == 1) {
  420. gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
  421. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  422. /* EGPIO[14] used for GPIO */
  423. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
  424. }
  425. }
  426. EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
  427. /*************************************************************************
  428. * EP93xx video peripheral handling
  429. *************************************************************************/
  430. static struct ep93xxfb_mach_info ep93xxfb_data;
  431. static struct resource ep93xx_fb_resource[] = {
  432. {
  433. .start = EP93XX_RASTER_PHYS_BASE,
  434. .end = EP93XX_RASTER_PHYS_BASE + 0x800 - 1,
  435. .flags = IORESOURCE_MEM,
  436. },
  437. };
  438. static struct platform_device ep93xx_fb_device = {
  439. .name = "ep93xx-fb",
  440. .id = -1,
  441. .dev = {
  442. .platform_data = &ep93xxfb_data,
  443. .coherent_dma_mask = DMA_BIT_MASK(32),
  444. .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
  445. },
  446. .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
  447. .resource = ep93xx_fb_resource,
  448. };
  449. void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
  450. {
  451. ep93xxfb_data = *data;
  452. platform_device_register(&ep93xx_fb_device);
  453. }
  454. /*************************************************************************
  455. * EP93xx matrix keypad peripheral handling
  456. *************************************************************************/
  457. static struct resource ep93xx_keypad_resource[] = {
  458. {
  459. .start = EP93XX_KEY_MATRIX_PHYS_BASE,
  460. .end = EP93XX_KEY_MATRIX_PHYS_BASE + 0x0c - 1,
  461. .flags = IORESOURCE_MEM,
  462. }, {
  463. .start = IRQ_EP93XX_KEY,
  464. .end = IRQ_EP93XX_KEY,
  465. .flags = IORESOURCE_IRQ,
  466. },
  467. };
  468. static struct platform_device ep93xx_keypad_device = {
  469. .name = "ep93xx-keypad",
  470. .id = -1,
  471. .num_resources = ARRAY_SIZE(ep93xx_keypad_resource),
  472. .resource = ep93xx_keypad_resource,
  473. };
  474. void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
  475. {
  476. ep93xx_keypad_device.dev.platform_data = data;
  477. platform_device_register(&ep93xx_keypad_device);
  478. }
  479. int ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
  480. {
  481. int err;
  482. int i;
  483. for (i = 0; i < 8; i++) {
  484. err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
  485. if (err)
  486. goto fail_gpio_c;
  487. err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
  488. if (err)
  489. goto fail_gpio_d;
  490. }
  491. /* Enable the keypad controller; GPIO ports C and D used for keypad */
  492. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  493. EP93XX_SYSCON_DEVCFG_GONK);
  494. return 0;
  495. fail_gpio_d:
  496. gpio_free(EP93XX_GPIO_LINE_C(i));
  497. fail_gpio_c:
  498. for ( ; i >= 0; --i) {
  499. gpio_free(EP93XX_GPIO_LINE_C(i));
  500. gpio_free(EP93XX_GPIO_LINE_D(i));
  501. }
  502. return err;
  503. }
  504. EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
  505. void ep93xx_keypad_release_gpio(struct platform_device *pdev)
  506. {
  507. int i;
  508. for (i = 0; i < 8; i++) {
  509. gpio_free(EP93XX_GPIO_LINE_C(i));
  510. gpio_free(EP93XX_GPIO_LINE_D(i));
  511. }
  512. /* Disable the keypad controller; GPIO ports C and D used for GPIO */
  513. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  514. EP93XX_SYSCON_DEVCFG_GONK);
  515. }
  516. EXPORT_SYMBOL(ep93xx_keypad_release_gpio);
  517. extern void ep93xx_gpio_init(void);
  518. void __init ep93xx_init_devices(void)
  519. {
  520. /* Disallow access to MaverickCrunch initially */
  521. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
  522. ep93xx_gpio_init();
  523. amba_device_register(&uart1_device, &iomem_resource);
  524. amba_device_register(&uart2_device, &iomem_resource);
  525. amba_device_register(&uart3_device, &iomem_resource);
  526. platform_device_register(&ep93xx_rtc_device);
  527. platform_device_register(&ep93xx_ohci_device);
  528. platform_device_register(&ep93xx_leds);
  529. }