core.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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/mtd/physmap.h>
  31. #include <linux/i2c.h>
  32. #include <linux/i2c-gpio.h>
  33. #include <linux/spi/spi.h>
  34. #include <mach/hardware.h>
  35. #include <mach/fb.h>
  36. #include <mach/ep93xx_keypad.h>
  37. #include <mach/ep93xx_spi.h>
  38. #include <mach/gpio-ep93xx.h>
  39. #include <asm/mach/map.h>
  40. #include <asm/mach/time.h>
  41. #include <asm/hardware/vic.h>
  42. /*************************************************************************
  43. * Static I/O mappings that are needed for all EP93xx platforms
  44. *************************************************************************/
  45. static struct map_desc ep93xx_io_desc[] __initdata = {
  46. {
  47. .virtual = EP93XX_AHB_VIRT_BASE,
  48. .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
  49. .length = EP93XX_AHB_SIZE,
  50. .type = MT_DEVICE,
  51. }, {
  52. .virtual = EP93XX_APB_VIRT_BASE,
  53. .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE),
  54. .length = EP93XX_APB_SIZE,
  55. .type = MT_DEVICE,
  56. },
  57. };
  58. void __init ep93xx_map_io(void)
  59. {
  60. iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
  61. }
  62. /*************************************************************************
  63. * Timer handling for EP93xx
  64. *************************************************************************
  65. * The ep93xx has four internal timers. Timers 1, 2 (both 16 bit) and
  66. * 3 (32 bit) count down at 508 kHz, are self-reloading, and can generate
  67. * an interrupt on underflow. Timer 4 (40 bit) counts down at 983.04 kHz,
  68. * is free-running, and can't generate interrupts.
  69. *
  70. * The 508 kHz timers are ideal for use for the timer interrupt, as the
  71. * most common values of HZ divide 508 kHz nicely. We pick one of the 16
  72. * bit timers (timer 1) since we don't need more than 16 bits of reload
  73. * value as long as HZ >= 8.
  74. *
  75. * The higher clock rate of timer 4 makes it a better choice than the
  76. * other timers for use in gettimeoffset(), while the fact that it can't
  77. * generate interrupts means we don't have to worry about not being able
  78. * to use this timer for something else. We also use timer 4 for keeping
  79. * track of lost jiffies.
  80. */
  81. #define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
  82. #define EP93XX_TIMER1_LOAD EP93XX_TIMER_REG(0x00)
  83. #define EP93XX_TIMER1_VALUE EP93XX_TIMER_REG(0x04)
  84. #define EP93XX_TIMER1_CONTROL EP93XX_TIMER_REG(0x08)
  85. #define EP93XX_TIMER123_CONTROL_ENABLE (1 << 7)
  86. #define EP93XX_TIMER123_CONTROL_MODE (1 << 6)
  87. #define EP93XX_TIMER123_CONTROL_CLKSEL (1 << 3)
  88. #define EP93XX_TIMER1_CLEAR EP93XX_TIMER_REG(0x0c)
  89. #define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
  90. #define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
  91. #define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
  92. #define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
  93. #define EP93XX_TIMER4_VALUE_LOW EP93XX_TIMER_REG(0x60)
  94. #define EP93XX_TIMER4_VALUE_HIGH EP93XX_TIMER_REG(0x64)
  95. #define EP93XX_TIMER4_VALUE_HIGH_ENABLE (1 << 8)
  96. #define EP93XX_TIMER3_LOAD EP93XX_TIMER_REG(0x80)
  97. #define EP93XX_TIMER3_VALUE EP93XX_TIMER_REG(0x84)
  98. #define EP93XX_TIMER3_CONTROL EP93XX_TIMER_REG(0x88)
  99. #define EP93XX_TIMER3_CLEAR EP93XX_TIMER_REG(0x8c)
  100. #define EP93XX_TIMER123_CLOCK 508469
  101. #define EP93XX_TIMER4_CLOCK 983040
  102. #define TIMER1_RELOAD ((EP93XX_TIMER123_CLOCK / HZ) - 1)
  103. #define TIMER4_TICKS_PER_JIFFY DIV_ROUND_CLOSEST(CLOCK_TICK_RATE, HZ)
  104. static unsigned int last_jiffy_time;
  105. static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
  106. {
  107. /* Writing any value clears the timer interrupt */
  108. __raw_writel(1, EP93XX_TIMER1_CLEAR);
  109. /* Recover lost jiffies */
  110. while ((signed long)
  111. (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
  112. >= TIMER4_TICKS_PER_JIFFY) {
  113. last_jiffy_time += TIMER4_TICKS_PER_JIFFY;
  114. timer_tick();
  115. }
  116. return IRQ_HANDLED;
  117. }
  118. static struct irqaction ep93xx_timer_irq = {
  119. .name = "ep93xx timer",
  120. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  121. .handler = ep93xx_timer_interrupt,
  122. };
  123. static void __init ep93xx_timer_init(void)
  124. {
  125. u32 tmode = EP93XX_TIMER123_CONTROL_MODE |
  126. EP93XX_TIMER123_CONTROL_CLKSEL;
  127. /* Enable periodic HZ timer. */
  128. __raw_writel(tmode, EP93XX_TIMER1_CONTROL);
  129. __raw_writel(TIMER1_RELOAD, EP93XX_TIMER1_LOAD);
  130. __raw_writel(tmode | EP93XX_TIMER123_CONTROL_ENABLE,
  131. EP93XX_TIMER1_CONTROL);
  132. /* Enable lost jiffy timer. */
  133. __raw_writel(EP93XX_TIMER4_VALUE_HIGH_ENABLE,
  134. EP93XX_TIMER4_VALUE_HIGH);
  135. setup_irq(IRQ_EP93XX_TIMER1, &ep93xx_timer_irq);
  136. }
  137. static unsigned long ep93xx_gettimeoffset(void)
  138. {
  139. int offset;
  140. offset = __raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time;
  141. /* Calculate (1000000 / 983040) * offset. */
  142. return offset + (53 * offset / 3072);
  143. }
  144. struct sys_timer ep93xx_timer = {
  145. .init = ep93xx_timer_init,
  146. .offset = ep93xx_gettimeoffset,
  147. };
  148. /*************************************************************************
  149. * EP93xx IRQ handling
  150. *************************************************************************/
  151. void __init ep93xx_init_irq(void)
  152. {
  153. vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
  154. vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
  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 &= ~clear_bits;
  180. val |= set_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 GPIO
  201. *************************************************************************/
  202. static struct resource ep93xx_gpio_resource[] = {
  203. {
  204. .start = EP93XX_GPIO_PHYS_BASE,
  205. .end = EP93XX_GPIO_PHYS_BASE + 0xcc - 1,
  206. .flags = IORESOURCE_MEM,
  207. },
  208. };
  209. static struct platform_device ep93xx_gpio_device = {
  210. .name = "gpio-ep93xx",
  211. .id = -1,
  212. .num_resources = ARRAY_SIZE(ep93xx_gpio_resource),
  213. .resource = ep93xx_gpio_resource,
  214. };
  215. /*************************************************************************
  216. * EP93xx peripheral handling
  217. *************************************************************************/
  218. #define EP93XX_UART_MCR_OFFSET (0x0100)
  219. static void ep93xx_uart_set_mctrl(struct amba_device *dev,
  220. void __iomem *base, unsigned int mctrl)
  221. {
  222. unsigned int mcr;
  223. mcr = 0;
  224. if (mctrl & TIOCM_RTS)
  225. mcr |= 2;
  226. if (mctrl & TIOCM_DTR)
  227. mcr |= 1;
  228. __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
  229. }
  230. static struct amba_pl010_data ep93xx_uart_data = {
  231. .set_mctrl = ep93xx_uart_set_mctrl,
  232. };
  233. static struct amba_device uart1_device = {
  234. .dev = {
  235. .init_name = "apb:uart1",
  236. .platform_data = &ep93xx_uart_data,
  237. },
  238. .res = {
  239. .start = EP93XX_UART1_PHYS_BASE,
  240. .end = EP93XX_UART1_PHYS_BASE + 0x0fff,
  241. .flags = IORESOURCE_MEM,
  242. },
  243. .irq = { IRQ_EP93XX_UART1, NO_IRQ },
  244. .periphid = 0x00041010,
  245. };
  246. static struct amba_device uart2_device = {
  247. .dev = {
  248. .init_name = "apb:uart2",
  249. .platform_data = &ep93xx_uart_data,
  250. },
  251. .res = {
  252. .start = EP93XX_UART2_PHYS_BASE,
  253. .end = EP93XX_UART2_PHYS_BASE + 0x0fff,
  254. .flags = IORESOURCE_MEM,
  255. },
  256. .irq = { IRQ_EP93XX_UART2, NO_IRQ },
  257. .periphid = 0x00041010,
  258. };
  259. static struct amba_device uart3_device = {
  260. .dev = {
  261. .init_name = "apb:uart3",
  262. .platform_data = &ep93xx_uart_data,
  263. },
  264. .res = {
  265. .start = EP93XX_UART3_PHYS_BASE,
  266. .end = EP93XX_UART3_PHYS_BASE + 0x0fff,
  267. .flags = IORESOURCE_MEM,
  268. },
  269. .irq = { IRQ_EP93XX_UART3, NO_IRQ },
  270. .periphid = 0x00041010,
  271. };
  272. static struct resource ep93xx_rtc_resource[] = {
  273. {
  274. .start = EP93XX_RTC_PHYS_BASE,
  275. .end = EP93XX_RTC_PHYS_BASE + 0x10c - 1,
  276. .flags = IORESOURCE_MEM,
  277. },
  278. };
  279. static struct platform_device ep93xx_rtc_device = {
  280. .name = "ep93xx-rtc",
  281. .id = -1,
  282. .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
  283. .resource = ep93xx_rtc_resource,
  284. };
  285. static struct resource ep93xx_ohci_resources[] = {
  286. [0] = {
  287. .start = EP93XX_USB_PHYS_BASE,
  288. .end = EP93XX_USB_PHYS_BASE + 0x0fff,
  289. .flags = IORESOURCE_MEM,
  290. },
  291. [1] = {
  292. .start = IRQ_EP93XX_USB,
  293. .end = IRQ_EP93XX_USB,
  294. .flags = IORESOURCE_IRQ,
  295. },
  296. };
  297. static struct platform_device ep93xx_ohci_device = {
  298. .name = "ep93xx-ohci",
  299. .id = -1,
  300. .dev = {
  301. .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask,
  302. .coherent_dma_mask = DMA_BIT_MASK(32),
  303. },
  304. .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
  305. .resource = ep93xx_ohci_resources,
  306. };
  307. /*************************************************************************
  308. * EP93xx physmap'ed flash
  309. *************************************************************************/
  310. static struct physmap_flash_data ep93xx_flash_data;
  311. static struct resource ep93xx_flash_resource = {
  312. .flags = IORESOURCE_MEM,
  313. };
  314. static struct platform_device ep93xx_flash = {
  315. .name = "physmap-flash",
  316. .id = 0,
  317. .dev = {
  318. .platform_data = &ep93xx_flash_data,
  319. },
  320. .num_resources = 1,
  321. .resource = &ep93xx_flash_resource,
  322. };
  323. /**
  324. * ep93xx_register_flash() - Register the external flash device.
  325. * @width: bank width in octets
  326. * @start: resource start address
  327. * @size: resource size
  328. */
  329. void __init ep93xx_register_flash(unsigned int width,
  330. resource_size_t start, resource_size_t size)
  331. {
  332. ep93xx_flash_data.width = width;
  333. ep93xx_flash_resource.start = start;
  334. ep93xx_flash_resource.end = start + size - 1;
  335. platform_device_register(&ep93xx_flash);
  336. }
  337. /*************************************************************************
  338. * EP93xx ethernet peripheral handling
  339. *************************************************************************/
  340. static struct ep93xx_eth_data ep93xx_eth_data;
  341. static struct resource ep93xx_eth_resource[] = {
  342. {
  343. .start = EP93XX_ETHERNET_PHYS_BASE,
  344. .end = EP93XX_ETHERNET_PHYS_BASE + 0xffff,
  345. .flags = IORESOURCE_MEM,
  346. }, {
  347. .start = IRQ_EP93XX_ETHERNET,
  348. .end = IRQ_EP93XX_ETHERNET,
  349. .flags = IORESOURCE_IRQ,
  350. }
  351. };
  352. static u64 ep93xx_eth_dma_mask = DMA_BIT_MASK(32);
  353. static struct platform_device ep93xx_eth_device = {
  354. .name = "ep93xx-eth",
  355. .id = -1,
  356. .dev = {
  357. .platform_data = &ep93xx_eth_data,
  358. .coherent_dma_mask = DMA_BIT_MASK(32),
  359. .dma_mask = &ep93xx_eth_dma_mask,
  360. },
  361. .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
  362. .resource = ep93xx_eth_resource,
  363. };
  364. /**
  365. * ep93xx_register_eth - Register the built-in ethernet platform device.
  366. * @data: platform specific ethernet configuration (__initdata)
  367. * @copy_addr: flag indicating that the MAC address should be copied
  368. * from the IndAd registers (as programmed by the bootloader)
  369. */
  370. void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
  371. {
  372. if (copy_addr)
  373. memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
  374. ep93xx_eth_data = *data;
  375. platform_device_register(&ep93xx_eth_device);
  376. }
  377. /*************************************************************************
  378. * EP93xx i2c peripheral handling
  379. *************************************************************************/
  380. static struct i2c_gpio_platform_data ep93xx_i2c_data;
  381. static struct platform_device ep93xx_i2c_device = {
  382. .name = "i2c-gpio",
  383. .id = 0,
  384. .dev = {
  385. .platform_data = &ep93xx_i2c_data,
  386. },
  387. };
  388. /**
  389. * ep93xx_register_i2c - Register the i2c platform device.
  390. * @data: platform specific i2c-gpio configuration (__initdata)
  391. * @devices: platform specific i2c bus device information (__initdata)
  392. * @num: the number of devices on the i2c bus
  393. */
  394. void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
  395. struct i2c_board_info *devices, int num)
  396. {
  397. /*
  398. * Set the EEPROM interface pin drive type control.
  399. * Defines the driver type for the EECLK and EEDAT pins as either
  400. * open drain, which will require an external pull-up, or a normal
  401. * CMOS driver.
  402. */
  403. if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT)
  404. pr_warning("sda != EEDAT, open drain has no effect\n");
  405. if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
  406. pr_warning("scl != EECLK, open drain has no effect\n");
  407. __raw_writel((data->sda_is_open_drain << 1) |
  408. (data->scl_is_open_drain << 0),
  409. EP93XX_GPIO_EEDRIVE);
  410. ep93xx_i2c_data = *data;
  411. i2c_register_board_info(0, devices, num);
  412. platform_device_register(&ep93xx_i2c_device);
  413. }
  414. /*************************************************************************
  415. * EP93xx SPI peripheral handling
  416. *************************************************************************/
  417. static struct ep93xx_spi_info ep93xx_spi_master_data;
  418. static struct resource ep93xx_spi_resources[] = {
  419. {
  420. .start = EP93XX_SPI_PHYS_BASE,
  421. .end = EP93XX_SPI_PHYS_BASE + 0x18 - 1,
  422. .flags = IORESOURCE_MEM,
  423. },
  424. {
  425. .start = IRQ_EP93XX_SSP,
  426. .end = IRQ_EP93XX_SSP,
  427. .flags = IORESOURCE_IRQ,
  428. },
  429. };
  430. static u64 ep93xx_spi_dma_mask = DMA_BIT_MASK(32);
  431. static struct platform_device ep93xx_spi_device = {
  432. .name = "ep93xx-spi",
  433. .id = 0,
  434. .dev = {
  435. .platform_data = &ep93xx_spi_master_data,
  436. .coherent_dma_mask = DMA_BIT_MASK(32),
  437. .dma_mask = &ep93xx_spi_dma_mask,
  438. },
  439. .num_resources = ARRAY_SIZE(ep93xx_spi_resources),
  440. .resource = ep93xx_spi_resources,
  441. };
  442. /**
  443. * ep93xx_register_spi() - registers spi platform device
  444. * @info: ep93xx board specific spi master info (__initdata)
  445. * @devices: SPI devices to register (__initdata)
  446. * @num: number of SPI devices to register
  447. *
  448. * This function registers platform device for the EP93xx SPI controller and
  449. * also makes sure that SPI pins are muxed so that I2S is not using those pins.
  450. */
  451. void __init ep93xx_register_spi(struct ep93xx_spi_info *info,
  452. struct spi_board_info *devices, int num)
  453. {
  454. /*
  455. * When SPI is used, we need to make sure that I2S is muxed off from
  456. * SPI pins.
  457. */
  458. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
  459. ep93xx_spi_master_data = *info;
  460. spi_register_board_info(devices, num);
  461. platform_device_register(&ep93xx_spi_device);
  462. }
  463. /*************************************************************************
  464. * EP93xx LEDs
  465. *************************************************************************/
  466. static struct gpio_led ep93xx_led_pins[] = {
  467. {
  468. .name = "platform:grled",
  469. .gpio = EP93XX_GPIO_LINE_GRLED,
  470. }, {
  471. .name = "platform:rdled",
  472. .gpio = EP93XX_GPIO_LINE_RDLED,
  473. },
  474. };
  475. static struct gpio_led_platform_data ep93xx_led_data = {
  476. .num_leds = ARRAY_SIZE(ep93xx_led_pins),
  477. .leds = ep93xx_led_pins,
  478. };
  479. static struct platform_device ep93xx_leds = {
  480. .name = "leds-gpio",
  481. .id = -1,
  482. .dev = {
  483. .platform_data = &ep93xx_led_data,
  484. },
  485. };
  486. /*************************************************************************
  487. * EP93xx pwm peripheral handling
  488. *************************************************************************/
  489. static struct resource ep93xx_pwm0_resource[] = {
  490. {
  491. .start = EP93XX_PWM_PHYS_BASE,
  492. .end = EP93XX_PWM_PHYS_BASE + 0x10 - 1,
  493. .flags = IORESOURCE_MEM,
  494. },
  495. };
  496. static struct platform_device ep93xx_pwm0_device = {
  497. .name = "ep93xx-pwm",
  498. .id = 0,
  499. .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
  500. .resource = ep93xx_pwm0_resource,
  501. };
  502. static struct resource ep93xx_pwm1_resource[] = {
  503. {
  504. .start = EP93XX_PWM_PHYS_BASE + 0x20,
  505. .end = EP93XX_PWM_PHYS_BASE + 0x30 - 1,
  506. .flags = IORESOURCE_MEM,
  507. },
  508. };
  509. static struct platform_device ep93xx_pwm1_device = {
  510. .name = "ep93xx-pwm",
  511. .id = 1,
  512. .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
  513. .resource = ep93xx_pwm1_resource,
  514. };
  515. void __init ep93xx_register_pwm(int pwm0, int pwm1)
  516. {
  517. if (pwm0)
  518. platform_device_register(&ep93xx_pwm0_device);
  519. /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
  520. if (pwm1)
  521. platform_device_register(&ep93xx_pwm1_device);
  522. }
  523. int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
  524. {
  525. int err;
  526. if (pdev->id == 0) {
  527. err = 0;
  528. } else if (pdev->id == 1) {
  529. err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
  530. dev_name(&pdev->dev));
  531. if (err)
  532. return err;
  533. err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
  534. if (err)
  535. goto fail;
  536. /* PWM 1 output on EGPIO[14] */
  537. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
  538. } else {
  539. err = -ENODEV;
  540. }
  541. return err;
  542. fail:
  543. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  544. return err;
  545. }
  546. EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
  547. void ep93xx_pwm_release_gpio(struct platform_device *pdev)
  548. {
  549. if (pdev->id == 1) {
  550. gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
  551. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  552. /* EGPIO[14] used for GPIO */
  553. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
  554. }
  555. }
  556. EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
  557. /*************************************************************************
  558. * EP93xx video peripheral handling
  559. *************************************************************************/
  560. static struct ep93xxfb_mach_info ep93xxfb_data;
  561. static struct resource ep93xx_fb_resource[] = {
  562. {
  563. .start = EP93XX_RASTER_PHYS_BASE,
  564. .end = EP93XX_RASTER_PHYS_BASE + 0x800 - 1,
  565. .flags = IORESOURCE_MEM,
  566. },
  567. };
  568. static struct platform_device ep93xx_fb_device = {
  569. .name = "ep93xx-fb",
  570. .id = -1,
  571. .dev = {
  572. .platform_data = &ep93xxfb_data,
  573. .coherent_dma_mask = DMA_BIT_MASK(32),
  574. .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
  575. },
  576. .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
  577. .resource = ep93xx_fb_resource,
  578. };
  579. static struct platform_device ep93xx_bl_device = {
  580. .name = "ep93xx-bl",
  581. .id = -1,
  582. };
  583. /**
  584. * ep93xx_register_fb - Register the framebuffer platform device.
  585. * @data: platform specific framebuffer configuration (__initdata)
  586. */
  587. void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
  588. {
  589. ep93xxfb_data = *data;
  590. platform_device_register(&ep93xx_fb_device);
  591. platform_device_register(&ep93xx_bl_device);
  592. }
  593. /*************************************************************************
  594. * EP93xx matrix keypad peripheral handling
  595. *************************************************************************/
  596. static struct ep93xx_keypad_platform_data ep93xx_keypad_data;
  597. static struct resource ep93xx_keypad_resource[] = {
  598. {
  599. .start = EP93XX_KEY_MATRIX_PHYS_BASE,
  600. .end = EP93XX_KEY_MATRIX_PHYS_BASE + 0x0c - 1,
  601. .flags = IORESOURCE_MEM,
  602. }, {
  603. .start = IRQ_EP93XX_KEY,
  604. .end = IRQ_EP93XX_KEY,
  605. .flags = IORESOURCE_IRQ,
  606. },
  607. };
  608. static struct platform_device ep93xx_keypad_device = {
  609. .name = "ep93xx-keypad",
  610. .id = -1,
  611. .dev = {
  612. .platform_data = &ep93xx_keypad_data,
  613. },
  614. .num_resources = ARRAY_SIZE(ep93xx_keypad_resource),
  615. .resource = ep93xx_keypad_resource,
  616. };
  617. /**
  618. * ep93xx_register_keypad - Register the keypad platform device.
  619. * @data: platform specific keypad configuration (__initdata)
  620. */
  621. void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
  622. {
  623. ep93xx_keypad_data = *data;
  624. platform_device_register(&ep93xx_keypad_device);
  625. }
  626. int ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
  627. {
  628. int err;
  629. int i;
  630. for (i = 0; i < 8; i++) {
  631. err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
  632. if (err)
  633. goto fail_gpio_c;
  634. err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
  635. if (err)
  636. goto fail_gpio_d;
  637. }
  638. /* Enable the keypad controller; GPIO ports C and D used for keypad */
  639. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  640. EP93XX_SYSCON_DEVCFG_GONK);
  641. return 0;
  642. fail_gpio_d:
  643. gpio_free(EP93XX_GPIO_LINE_C(i));
  644. fail_gpio_c:
  645. for ( ; i >= 0; --i) {
  646. gpio_free(EP93XX_GPIO_LINE_C(i));
  647. gpio_free(EP93XX_GPIO_LINE_D(i));
  648. }
  649. return err;
  650. }
  651. EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
  652. void ep93xx_keypad_release_gpio(struct platform_device *pdev)
  653. {
  654. int i;
  655. for (i = 0; i < 8; i++) {
  656. gpio_free(EP93XX_GPIO_LINE_C(i));
  657. gpio_free(EP93XX_GPIO_LINE_D(i));
  658. }
  659. /* Disable the keypad controller; GPIO ports C and D used for GPIO */
  660. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  661. EP93XX_SYSCON_DEVCFG_GONK);
  662. }
  663. EXPORT_SYMBOL(ep93xx_keypad_release_gpio);
  664. /*************************************************************************
  665. * EP93xx I2S audio peripheral handling
  666. *************************************************************************/
  667. static struct resource ep93xx_i2s_resource[] = {
  668. {
  669. .start = EP93XX_I2S_PHYS_BASE,
  670. .end = EP93XX_I2S_PHYS_BASE + 0x100 - 1,
  671. .flags = IORESOURCE_MEM,
  672. },
  673. };
  674. static struct platform_device ep93xx_i2s_device = {
  675. .name = "ep93xx-i2s",
  676. .id = -1,
  677. .num_resources = ARRAY_SIZE(ep93xx_i2s_resource),
  678. .resource = ep93xx_i2s_resource,
  679. };
  680. static struct platform_device ep93xx_pcm_device = {
  681. .name = "ep93xx-pcm-audio",
  682. .id = -1,
  683. };
  684. void __init ep93xx_register_i2s(void)
  685. {
  686. platform_device_register(&ep93xx_i2s_device);
  687. platform_device_register(&ep93xx_pcm_device);
  688. }
  689. #define EP93XX_SYSCON_DEVCFG_I2S_MASK (EP93XX_SYSCON_DEVCFG_I2SONSSP | \
  690. EP93XX_SYSCON_DEVCFG_I2SONAC97)
  691. #define EP93XX_I2SCLKDIV_MASK (EP93XX_SYSCON_I2SCLKDIV_ORIDE | \
  692. EP93XX_SYSCON_I2SCLKDIV_SPOL)
  693. int ep93xx_i2s_acquire(unsigned i2s_pins, unsigned i2s_config)
  694. {
  695. unsigned val;
  696. /* Sanity check */
  697. if (i2s_pins & ~EP93XX_SYSCON_DEVCFG_I2S_MASK)
  698. return -EINVAL;
  699. if (i2s_config & ~EP93XX_I2SCLKDIV_MASK)
  700. return -EINVAL;
  701. /* Must have only one of I2SONSSP/I2SONAC97 set */
  702. if ((i2s_pins & EP93XX_SYSCON_DEVCFG_I2SONSSP) ==
  703. (i2s_pins & EP93XX_SYSCON_DEVCFG_I2SONAC97))
  704. return -EINVAL;
  705. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK);
  706. ep93xx_devcfg_set_bits(i2s_pins);
  707. /*
  708. * This is potentially racy with the clock api for i2s_mclk, sclk and
  709. * lrclk. Since the i2s driver is the only user of those clocks we
  710. * rely on it to prevent parallel use of this function and the
  711. * clock api for the i2s clocks.
  712. */
  713. val = __raw_readl(EP93XX_SYSCON_I2SCLKDIV);
  714. val &= ~EP93XX_I2SCLKDIV_MASK;
  715. val |= i2s_config;
  716. ep93xx_syscon_swlocked_write(val, EP93XX_SYSCON_I2SCLKDIV);
  717. return 0;
  718. }
  719. EXPORT_SYMBOL(ep93xx_i2s_acquire);
  720. void ep93xx_i2s_release(void)
  721. {
  722. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK);
  723. }
  724. EXPORT_SYMBOL(ep93xx_i2s_release);
  725. /*************************************************************************
  726. * EP93xx AC97 audio peripheral handling
  727. *************************************************************************/
  728. static struct resource ep93xx_ac97_resources[] = {
  729. {
  730. .start = EP93XX_AAC_PHYS_BASE,
  731. .end = EP93XX_AAC_PHYS_BASE + 0xac - 1,
  732. .flags = IORESOURCE_MEM,
  733. },
  734. {
  735. .start = IRQ_EP93XX_AACINTR,
  736. .end = IRQ_EP93XX_AACINTR,
  737. .flags = IORESOURCE_IRQ,
  738. },
  739. };
  740. static struct platform_device ep93xx_ac97_device = {
  741. .name = "ep93xx-ac97",
  742. .id = -1,
  743. .num_resources = ARRAY_SIZE(ep93xx_ac97_resources),
  744. .resource = ep93xx_ac97_resources,
  745. };
  746. void __init ep93xx_register_ac97(void)
  747. {
  748. /*
  749. * Make sure that the AC97 pins are not used by I2S.
  750. */
  751. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97);
  752. platform_device_register(&ep93xx_ac97_device);
  753. platform_device_register(&ep93xx_pcm_device);
  754. }
  755. void __init ep93xx_init_devices(void)
  756. {
  757. /* Disallow access to MaverickCrunch initially */
  758. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
  759. /* Get the GPIO working early, other devices need it */
  760. platform_device_register(&ep93xx_gpio_device);
  761. amba_device_register(&uart1_device, &iomem_resource);
  762. amba_device_register(&uart2_device, &iomem_resource);
  763. amba_device_register(&uart3_device, &iomem_resource);
  764. platform_device_register(&ep93xx_rtc_device);
  765. platform_device_register(&ep93xx_ohci_device);
  766. platform_device_register(&ep93xx_leds);
  767. }