core.c 27 KB

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