core.c 27 KB

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