core.c 26 KB

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