core.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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 <linux/platform_data/video-ep93xx.h>
  37. #include <linux/platform_data/keypad-ep93xx.h>
  38. #include <linux/platform_data/spi-ep93xx.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. #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. static 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. struct sys_timer ep93xx_timer = {
  154. .init = ep93xx_timer_init,
  155. };
  156. /*************************************************************************
  157. * EP93xx IRQ handling
  158. *************************************************************************/
  159. void __init ep93xx_init_irq(void)
  160. {
  161. vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
  162. vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
  163. }
  164. /*************************************************************************
  165. * EP93xx System Controller Software Locked register handling
  166. *************************************************************************/
  167. /*
  168. * syscon_swlock prevents anything else from writing to the syscon
  169. * block while a software locked register is being written.
  170. */
  171. static DEFINE_SPINLOCK(syscon_swlock);
  172. void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
  173. {
  174. unsigned long flags;
  175. spin_lock_irqsave(&syscon_swlock, flags);
  176. __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
  177. __raw_writel(val, reg);
  178. spin_unlock_irqrestore(&syscon_swlock, flags);
  179. }
  180. void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
  181. {
  182. unsigned long flags;
  183. unsigned int val;
  184. spin_lock_irqsave(&syscon_swlock, flags);
  185. val = __raw_readl(EP93XX_SYSCON_DEVCFG);
  186. val &= ~clear_bits;
  187. val |= set_bits;
  188. __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
  189. __raw_writel(val, EP93XX_SYSCON_DEVCFG);
  190. spin_unlock_irqrestore(&syscon_swlock, flags);
  191. }
  192. /**
  193. * ep93xx_chip_revision() - returns the EP93xx chip revision
  194. *
  195. * See <mach/platform.h> for more information.
  196. */
  197. unsigned int ep93xx_chip_revision(void)
  198. {
  199. unsigned int v;
  200. v = __raw_readl(EP93XX_SYSCON_SYSCFG);
  201. v &= EP93XX_SYSCON_SYSCFG_REV_MASK;
  202. v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT;
  203. return v;
  204. }
  205. /*************************************************************************
  206. * EP93xx GPIO
  207. *************************************************************************/
  208. static struct resource ep93xx_gpio_resource[] = {
  209. DEFINE_RES_MEM(EP93XX_GPIO_PHYS_BASE, 0xcc),
  210. };
  211. static struct platform_device ep93xx_gpio_device = {
  212. .name = "gpio-ep93xx",
  213. .id = -1,
  214. .num_resources = ARRAY_SIZE(ep93xx_gpio_resource),
  215. .resource = ep93xx_gpio_resource,
  216. };
  217. /*************************************************************************
  218. * EP93xx peripheral handling
  219. *************************************************************************/
  220. #define EP93XX_UART_MCR_OFFSET (0x0100)
  221. static void ep93xx_uart_set_mctrl(struct amba_device *dev,
  222. void __iomem *base, unsigned int mctrl)
  223. {
  224. unsigned int mcr;
  225. mcr = 0;
  226. if (mctrl & TIOCM_RTS)
  227. mcr |= 2;
  228. if (mctrl & TIOCM_DTR)
  229. mcr |= 1;
  230. __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
  231. }
  232. static struct amba_pl010_data ep93xx_uart_data = {
  233. .set_mctrl = ep93xx_uart_set_mctrl,
  234. };
  235. static AMBA_APB_DEVICE(uart1, "apb:uart1", 0x00041010, EP93XX_UART1_PHYS_BASE,
  236. { IRQ_EP93XX_UART1 }, &ep93xx_uart_data);
  237. static AMBA_APB_DEVICE(uart2, "apb:uart2", 0x00041010, EP93XX_UART2_PHYS_BASE,
  238. { IRQ_EP93XX_UART2 }, &ep93xx_uart_data);
  239. static AMBA_APB_DEVICE(uart3, "apb:uart3", 0x00041010, EP93XX_UART3_PHYS_BASE,
  240. { IRQ_EP93XX_UART3 }, &ep93xx_uart_data);
  241. static struct resource ep93xx_rtc_resource[] = {
  242. DEFINE_RES_MEM(EP93XX_RTC_PHYS_BASE, 0x10c),
  243. };
  244. static struct platform_device ep93xx_rtc_device = {
  245. .name = "ep93xx-rtc",
  246. .id = -1,
  247. .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
  248. .resource = ep93xx_rtc_resource,
  249. };
  250. static struct resource ep93xx_ohci_resources[] = {
  251. DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000),
  252. DEFINE_RES_IRQ(IRQ_EP93XX_USB),
  253. };
  254. static struct platform_device ep93xx_ohci_device = {
  255. .name = "ep93xx-ohci",
  256. .id = -1,
  257. .dev = {
  258. .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask,
  259. .coherent_dma_mask = DMA_BIT_MASK(32),
  260. },
  261. .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
  262. .resource = ep93xx_ohci_resources,
  263. };
  264. /*************************************************************************
  265. * EP93xx physmap'ed flash
  266. *************************************************************************/
  267. static struct physmap_flash_data ep93xx_flash_data;
  268. static struct resource ep93xx_flash_resource = {
  269. .flags = IORESOURCE_MEM,
  270. };
  271. static struct platform_device ep93xx_flash = {
  272. .name = "physmap-flash",
  273. .id = 0,
  274. .dev = {
  275. .platform_data = &ep93xx_flash_data,
  276. },
  277. .num_resources = 1,
  278. .resource = &ep93xx_flash_resource,
  279. };
  280. /**
  281. * ep93xx_register_flash() - Register the external flash device.
  282. * @width: bank width in octets
  283. * @start: resource start address
  284. * @size: resource size
  285. */
  286. void __init ep93xx_register_flash(unsigned int width,
  287. resource_size_t start, resource_size_t size)
  288. {
  289. ep93xx_flash_data.width = width;
  290. ep93xx_flash_resource.start = start;
  291. ep93xx_flash_resource.end = start + size - 1;
  292. platform_device_register(&ep93xx_flash);
  293. }
  294. /*************************************************************************
  295. * EP93xx ethernet peripheral handling
  296. *************************************************************************/
  297. static struct ep93xx_eth_data ep93xx_eth_data;
  298. static struct resource ep93xx_eth_resource[] = {
  299. DEFINE_RES_MEM(EP93XX_ETHERNET_PHYS_BASE, 0x10000),
  300. DEFINE_RES_IRQ(IRQ_EP93XX_ETHERNET),
  301. };
  302. static u64 ep93xx_eth_dma_mask = DMA_BIT_MASK(32);
  303. static struct platform_device ep93xx_eth_device = {
  304. .name = "ep93xx-eth",
  305. .id = -1,
  306. .dev = {
  307. .platform_data = &ep93xx_eth_data,
  308. .coherent_dma_mask = DMA_BIT_MASK(32),
  309. .dma_mask = &ep93xx_eth_dma_mask,
  310. },
  311. .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
  312. .resource = ep93xx_eth_resource,
  313. };
  314. /**
  315. * ep93xx_register_eth - Register the built-in ethernet platform device.
  316. * @data: platform specific ethernet configuration (__initdata)
  317. * @copy_addr: flag indicating that the MAC address should be copied
  318. * from the IndAd registers (as programmed by the bootloader)
  319. */
  320. void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
  321. {
  322. if (copy_addr)
  323. memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
  324. ep93xx_eth_data = *data;
  325. platform_device_register(&ep93xx_eth_device);
  326. }
  327. /*************************************************************************
  328. * EP93xx i2c peripheral handling
  329. *************************************************************************/
  330. static struct i2c_gpio_platform_data ep93xx_i2c_data;
  331. static struct platform_device ep93xx_i2c_device = {
  332. .name = "i2c-gpio",
  333. .id = 0,
  334. .dev = {
  335. .platform_data = &ep93xx_i2c_data,
  336. },
  337. };
  338. /**
  339. * ep93xx_register_i2c - Register the i2c platform device.
  340. * @data: platform specific i2c-gpio configuration (__initdata)
  341. * @devices: platform specific i2c bus device information (__initdata)
  342. * @num: the number of devices on the i2c bus
  343. */
  344. void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
  345. struct i2c_board_info *devices, int num)
  346. {
  347. /*
  348. * Set the EEPROM interface pin drive type control.
  349. * Defines the driver type for the EECLK and EEDAT pins as either
  350. * open drain, which will require an external pull-up, or a normal
  351. * CMOS driver.
  352. */
  353. if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT)
  354. pr_warning("sda != EEDAT, open drain has no effect\n");
  355. if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
  356. pr_warning("scl != EECLK, open drain has no effect\n");
  357. __raw_writel((data->sda_is_open_drain << 1) |
  358. (data->scl_is_open_drain << 0),
  359. EP93XX_GPIO_EEDRIVE);
  360. ep93xx_i2c_data = *data;
  361. i2c_register_board_info(0, devices, num);
  362. platform_device_register(&ep93xx_i2c_device);
  363. }
  364. /*************************************************************************
  365. * EP93xx SPI peripheral handling
  366. *************************************************************************/
  367. static struct ep93xx_spi_info ep93xx_spi_master_data;
  368. static struct resource ep93xx_spi_resources[] = {
  369. DEFINE_RES_MEM(EP93XX_SPI_PHYS_BASE, 0x18),
  370. DEFINE_RES_IRQ(IRQ_EP93XX_SSP),
  371. };
  372. static u64 ep93xx_spi_dma_mask = DMA_BIT_MASK(32);
  373. static struct platform_device ep93xx_spi_device = {
  374. .name = "ep93xx-spi",
  375. .id = 0,
  376. .dev = {
  377. .platform_data = &ep93xx_spi_master_data,
  378. .coherent_dma_mask = DMA_BIT_MASK(32),
  379. .dma_mask = &ep93xx_spi_dma_mask,
  380. },
  381. .num_resources = ARRAY_SIZE(ep93xx_spi_resources),
  382. .resource = ep93xx_spi_resources,
  383. };
  384. /**
  385. * ep93xx_register_spi() - registers spi platform device
  386. * @info: ep93xx board specific spi master info (__initdata)
  387. * @devices: SPI devices to register (__initdata)
  388. * @num: number of SPI devices to register
  389. *
  390. * This function registers platform device for the EP93xx SPI controller and
  391. * also makes sure that SPI pins are muxed so that I2S is not using those pins.
  392. */
  393. void __init ep93xx_register_spi(struct ep93xx_spi_info *info,
  394. struct spi_board_info *devices, int num)
  395. {
  396. /*
  397. * When SPI is used, we need to make sure that I2S is muxed off from
  398. * SPI pins.
  399. */
  400. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
  401. ep93xx_spi_master_data = *info;
  402. spi_register_board_info(devices, num);
  403. platform_device_register(&ep93xx_spi_device);
  404. }
  405. /*************************************************************************
  406. * EP93xx LEDs
  407. *************************************************************************/
  408. static const struct gpio_led ep93xx_led_pins[] __initconst = {
  409. {
  410. .name = "platform:grled",
  411. .gpio = EP93XX_GPIO_LINE_GRLED,
  412. }, {
  413. .name = "platform:rdled",
  414. .gpio = EP93XX_GPIO_LINE_RDLED,
  415. },
  416. };
  417. static const struct gpio_led_platform_data ep93xx_led_data __initconst = {
  418. .num_leds = ARRAY_SIZE(ep93xx_led_pins),
  419. .leds = ep93xx_led_pins,
  420. };
  421. /*************************************************************************
  422. * EP93xx pwm peripheral handling
  423. *************************************************************************/
  424. static struct resource ep93xx_pwm0_resource[] = {
  425. DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE, 0x10),
  426. };
  427. static struct platform_device ep93xx_pwm0_device = {
  428. .name = "ep93xx-pwm",
  429. .id = 0,
  430. .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
  431. .resource = ep93xx_pwm0_resource,
  432. };
  433. static struct resource ep93xx_pwm1_resource[] = {
  434. DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE + 0x20, 0x10),
  435. };
  436. static struct platform_device ep93xx_pwm1_device = {
  437. .name = "ep93xx-pwm",
  438. .id = 1,
  439. .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
  440. .resource = ep93xx_pwm1_resource,
  441. };
  442. void __init ep93xx_register_pwm(int pwm0, int pwm1)
  443. {
  444. if (pwm0)
  445. platform_device_register(&ep93xx_pwm0_device);
  446. /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
  447. if (pwm1)
  448. platform_device_register(&ep93xx_pwm1_device);
  449. }
  450. int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
  451. {
  452. int err;
  453. if (pdev->id == 0) {
  454. err = 0;
  455. } else if (pdev->id == 1) {
  456. err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
  457. dev_name(&pdev->dev));
  458. if (err)
  459. return err;
  460. err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
  461. if (err)
  462. goto fail;
  463. /* PWM 1 output on EGPIO[14] */
  464. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
  465. } else {
  466. err = -ENODEV;
  467. }
  468. return err;
  469. fail:
  470. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  471. return err;
  472. }
  473. EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
  474. void ep93xx_pwm_release_gpio(struct platform_device *pdev)
  475. {
  476. if (pdev->id == 1) {
  477. gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
  478. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  479. /* EGPIO[14] used for GPIO */
  480. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
  481. }
  482. }
  483. EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
  484. /*************************************************************************
  485. * EP93xx video peripheral handling
  486. *************************************************************************/
  487. static struct ep93xxfb_mach_info ep93xxfb_data;
  488. static struct resource ep93xx_fb_resource[] = {
  489. DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE, 0x800),
  490. };
  491. static struct platform_device ep93xx_fb_device = {
  492. .name = "ep93xx-fb",
  493. .id = -1,
  494. .dev = {
  495. .platform_data = &ep93xxfb_data,
  496. .coherent_dma_mask = DMA_BIT_MASK(32),
  497. .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
  498. },
  499. .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
  500. .resource = ep93xx_fb_resource,
  501. };
  502. /* The backlight use a single register in the framebuffer's register space */
  503. #define EP93XX_RASTER_REG_BRIGHTNESS 0x20
  504. static struct resource ep93xx_bl_resources[] = {
  505. DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE +
  506. EP93XX_RASTER_REG_BRIGHTNESS, 0x04),
  507. };
  508. static struct platform_device ep93xx_bl_device = {
  509. .name = "ep93xx-bl",
  510. .id = -1,
  511. .num_resources = ARRAY_SIZE(ep93xx_bl_resources),
  512. .resource = ep93xx_bl_resources,
  513. };
  514. /**
  515. * ep93xx_register_fb - Register the framebuffer platform device.
  516. * @data: platform specific framebuffer configuration (__initdata)
  517. */
  518. void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
  519. {
  520. ep93xxfb_data = *data;
  521. platform_device_register(&ep93xx_fb_device);
  522. platform_device_register(&ep93xx_bl_device);
  523. }
  524. /*************************************************************************
  525. * EP93xx matrix keypad peripheral handling
  526. *************************************************************************/
  527. static struct ep93xx_keypad_platform_data ep93xx_keypad_data;
  528. static struct resource ep93xx_keypad_resource[] = {
  529. DEFINE_RES_MEM(EP93XX_KEY_MATRIX_PHYS_BASE, 0x0c),
  530. DEFINE_RES_IRQ(IRQ_EP93XX_KEY),
  531. };
  532. static struct platform_device ep93xx_keypad_device = {
  533. .name = "ep93xx-keypad",
  534. .id = -1,
  535. .dev = {
  536. .platform_data = &ep93xx_keypad_data,
  537. },
  538. .num_resources = ARRAY_SIZE(ep93xx_keypad_resource),
  539. .resource = ep93xx_keypad_resource,
  540. };
  541. /**
  542. * ep93xx_register_keypad - Register the keypad platform device.
  543. * @data: platform specific keypad configuration (__initdata)
  544. */
  545. void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
  546. {
  547. ep93xx_keypad_data = *data;
  548. platform_device_register(&ep93xx_keypad_device);
  549. }
  550. int ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
  551. {
  552. int err;
  553. int i;
  554. for (i = 0; i < 8; i++) {
  555. err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
  556. if (err)
  557. goto fail_gpio_c;
  558. err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
  559. if (err)
  560. goto fail_gpio_d;
  561. }
  562. /* Enable the keypad controller; GPIO ports C and D used for keypad */
  563. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  564. EP93XX_SYSCON_DEVCFG_GONK);
  565. return 0;
  566. fail_gpio_d:
  567. gpio_free(EP93XX_GPIO_LINE_C(i));
  568. fail_gpio_c:
  569. for (--i; i >= 0; --i) {
  570. gpio_free(EP93XX_GPIO_LINE_C(i));
  571. gpio_free(EP93XX_GPIO_LINE_D(i));
  572. }
  573. return err;
  574. }
  575. EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
  576. void ep93xx_keypad_release_gpio(struct platform_device *pdev)
  577. {
  578. int i;
  579. for (i = 0; i < 8; i++) {
  580. gpio_free(EP93XX_GPIO_LINE_C(i));
  581. gpio_free(EP93XX_GPIO_LINE_D(i));
  582. }
  583. /* Disable the keypad controller; GPIO ports C and D used for GPIO */
  584. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  585. EP93XX_SYSCON_DEVCFG_GONK);
  586. }
  587. EXPORT_SYMBOL(ep93xx_keypad_release_gpio);
  588. /*************************************************************************
  589. * EP93xx I2S audio peripheral handling
  590. *************************************************************************/
  591. static struct resource ep93xx_i2s_resource[] = {
  592. DEFINE_RES_MEM(EP93XX_I2S_PHYS_BASE, 0x100),
  593. };
  594. static struct platform_device ep93xx_i2s_device = {
  595. .name = "ep93xx-i2s",
  596. .id = -1,
  597. .num_resources = ARRAY_SIZE(ep93xx_i2s_resource),
  598. .resource = ep93xx_i2s_resource,
  599. };
  600. static struct platform_device ep93xx_pcm_device = {
  601. .name = "ep93xx-pcm-audio",
  602. .id = -1,
  603. };
  604. void __init ep93xx_register_i2s(void)
  605. {
  606. platform_device_register(&ep93xx_i2s_device);
  607. platform_device_register(&ep93xx_pcm_device);
  608. }
  609. #define EP93XX_SYSCON_DEVCFG_I2S_MASK (EP93XX_SYSCON_DEVCFG_I2SONSSP | \
  610. EP93XX_SYSCON_DEVCFG_I2SONAC97)
  611. #define EP93XX_I2SCLKDIV_MASK (EP93XX_SYSCON_I2SCLKDIV_ORIDE | \
  612. EP93XX_SYSCON_I2SCLKDIV_SPOL)
  613. int ep93xx_i2s_acquire(void)
  614. {
  615. unsigned val;
  616. ep93xx_devcfg_set_clear(EP93XX_SYSCON_DEVCFG_I2SONAC97,
  617. EP93XX_SYSCON_DEVCFG_I2S_MASK);
  618. /*
  619. * This is potentially racy with the clock api for i2s_mclk, sclk and
  620. * lrclk. Since the i2s driver is the only user of those clocks we
  621. * rely on it to prevent parallel use of this function and the
  622. * clock api for the i2s clocks.
  623. */
  624. val = __raw_readl(EP93XX_SYSCON_I2SCLKDIV);
  625. val &= ~EP93XX_I2SCLKDIV_MASK;
  626. val |= EP93XX_SYSCON_I2SCLKDIV_ORIDE | EP93XX_SYSCON_I2SCLKDIV_SPOL;
  627. ep93xx_syscon_swlocked_write(val, EP93XX_SYSCON_I2SCLKDIV);
  628. return 0;
  629. }
  630. EXPORT_SYMBOL(ep93xx_i2s_acquire);
  631. void ep93xx_i2s_release(void)
  632. {
  633. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK);
  634. }
  635. EXPORT_SYMBOL(ep93xx_i2s_release);
  636. /*************************************************************************
  637. * EP93xx AC97 audio peripheral handling
  638. *************************************************************************/
  639. static struct resource ep93xx_ac97_resources[] = {
  640. DEFINE_RES_MEM(EP93XX_AAC_PHYS_BASE, 0xac),
  641. DEFINE_RES_IRQ(IRQ_EP93XX_AACINTR),
  642. };
  643. static struct platform_device ep93xx_ac97_device = {
  644. .name = "ep93xx-ac97",
  645. .id = -1,
  646. .num_resources = ARRAY_SIZE(ep93xx_ac97_resources),
  647. .resource = ep93xx_ac97_resources,
  648. };
  649. void __init ep93xx_register_ac97(void)
  650. {
  651. /*
  652. * Make sure that the AC97 pins are not used by I2S.
  653. */
  654. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97);
  655. platform_device_register(&ep93xx_ac97_device);
  656. platform_device_register(&ep93xx_pcm_device);
  657. }
  658. /*************************************************************************
  659. * EP93xx Watchdog
  660. *************************************************************************/
  661. static struct resource ep93xx_wdt_resources[] = {
  662. DEFINE_RES_MEM(EP93XX_WATCHDOG_PHYS_BASE, 0x08),
  663. };
  664. static struct platform_device ep93xx_wdt_device = {
  665. .name = "ep93xx-wdt",
  666. .id = -1,
  667. .num_resources = ARRAY_SIZE(ep93xx_wdt_resources),
  668. .resource = ep93xx_wdt_resources,
  669. };
  670. /*************************************************************************
  671. * EP93xx IDE
  672. *************************************************************************/
  673. static struct resource ep93xx_ide_resources[] = {
  674. DEFINE_RES_MEM(EP93XX_IDE_PHYS_BASE, 0x38),
  675. DEFINE_RES_IRQ(IRQ_EP93XX_EXT3),
  676. };
  677. static struct platform_device ep93xx_ide_device = {
  678. .name = "ep93xx-ide",
  679. .id = -1,
  680. .dev = {
  681. .dma_mask = &ep93xx_ide_device.dev.coherent_dma_mask,
  682. .coherent_dma_mask = DMA_BIT_MASK(32),
  683. },
  684. .num_resources = ARRAY_SIZE(ep93xx_ide_resources),
  685. .resource = ep93xx_ide_resources,
  686. };
  687. void __init ep93xx_register_ide(void)
  688. {
  689. platform_device_register(&ep93xx_ide_device);
  690. }
  691. int ep93xx_ide_acquire_gpio(struct platform_device *pdev)
  692. {
  693. int err;
  694. int i;
  695. err = gpio_request(EP93XX_GPIO_LINE_EGPIO2, dev_name(&pdev->dev));
  696. if (err)
  697. return err;
  698. err = gpio_request(EP93XX_GPIO_LINE_EGPIO15, dev_name(&pdev->dev));
  699. if (err)
  700. goto fail_egpio15;
  701. for (i = 2; i < 8; i++) {
  702. err = gpio_request(EP93XX_GPIO_LINE_E(i), dev_name(&pdev->dev));
  703. if (err)
  704. goto fail_gpio_e;
  705. }
  706. for (i = 4; i < 8; i++) {
  707. err = gpio_request(EP93XX_GPIO_LINE_G(i), dev_name(&pdev->dev));
  708. if (err)
  709. goto fail_gpio_g;
  710. }
  711. for (i = 0; i < 8; i++) {
  712. err = gpio_request(EP93XX_GPIO_LINE_H(i), dev_name(&pdev->dev));
  713. if (err)
  714. goto fail_gpio_h;
  715. }
  716. /* GPIO ports E[7:2], G[7:4] and H used by IDE */
  717. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
  718. EP93XX_SYSCON_DEVCFG_GONIDE |
  719. EP93XX_SYSCON_DEVCFG_HONIDE);
  720. return 0;
  721. fail_gpio_h:
  722. for (--i; i >= 0; --i)
  723. gpio_free(EP93XX_GPIO_LINE_H(i));
  724. i = 8;
  725. fail_gpio_g:
  726. for (--i; i >= 4; --i)
  727. gpio_free(EP93XX_GPIO_LINE_G(i));
  728. i = 8;
  729. fail_gpio_e:
  730. for (--i; i >= 2; --i)
  731. gpio_free(EP93XX_GPIO_LINE_E(i));
  732. gpio_free(EP93XX_GPIO_LINE_EGPIO15);
  733. fail_egpio15:
  734. gpio_free(EP93XX_GPIO_LINE_EGPIO2);
  735. return err;
  736. }
  737. EXPORT_SYMBOL(ep93xx_ide_acquire_gpio);
  738. void ep93xx_ide_release_gpio(struct platform_device *pdev)
  739. {
  740. int i;
  741. for (i = 2; i < 8; i++)
  742. gpio_free(EP93XX_GPIO_LINE_E(i));
  743. for (i = 4; i < 8; i++)
  744. gpio_free(EP93XX_GPIO_LINE_G(i));
  745. for (i = 0; i < 8; i++)
  746. gpio_free(EP93XX_GPIO_LINE_H(i));
  747. gpio_free(EP93XX_GPIO_LINE_EGPIO15);
  748. gpio_free(EP93XX_GPIO_LINE_EGPIO2);
  749. /* GPIO ports E[7:2], G[7:4] and H used by GPIO */
  750. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
  751. EP93XX_SYSCON_DEVCFG_GONIDE |
  752. EP93XX_SYSCON_DEVCFG_HONIDE);
  753. }
  754. EXPORT_SYMBOL(ep93xx_ide_release_gpio);
  755. void __init ep93xx_init_devices(void)
  756. {
  757. /* Disallow access to MaverickCrunch initially */
  758. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
  759. /* Default all ports to GPIO */
  760. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  761. EP93XX_SYSCON_DEVCFG_GONK |
  762. EP93XX_SYSCON_DEVCFG_EONIDE |
  763. EP93XX_SYSCON_DEVCFG_GONIDE |
  764. EP93XX_SYSCON_DEVCFG_HONIDE);
  765. /* Get the GPIO working early, other devices need it */
  766. platform_device_register(&ep93xx_gpio_device);
  767. amba_device_register(&uart1_device, &iomem_resource);
  768. amba_device_register(&uart2_device, &iomem_resource);
  769. amba_device_register(&uart3_device, &iomem_resource);
  770. platform_device_register(&ep93xx_rtc_device);
  771. platform_device_register(&ep93xx_ohci_device);
  772. platform_device_register(&ep93xx_wdt_device);
  773. gpio_led_register_device(-1, &ep93xx_led_data);
  774. }
  775. void ep93xx_restart(char mode, const char *cmd)
  776. {
  777. /*
  778. * Set then clear the SWRST bit to initiate a software reset
  779. */
  780. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_SWRST);
  781. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_SWRST);
  782. while (1)
  783. ;
  784. }
  785. void __init ep93xx_init_late(void)
  786. {
  787. crunch_init();
  788. }