core.c 24 KB

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