core.c 27 KB

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