core.c 20 KB

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