blob: d95ee28a616a3ed53c776dda2df2fa5da6f229f1 [file] [log] [blame]
Lennert Buytenheke7736d42006-03-20 17:10:13 +00001/*
2 * arch/arm/mach-ep93xx/core.c
3 * Core routines for Cirrus EP93xx chips.
4 *
5 * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
Herbert Valerio Riedel3c9a0712007-11-26 18:49:08 +01006 * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
Lennert Buytenheke7736d42006-03-20 17:10:13 +00007 *
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
Hartley Sweeten64d68822010-01-11 19:33:16 +010017#define pr_fmt(fmt) "ep93xx " KBUILD_MODNAME ": " fmt
18
Lennert Buytenheke7736d42006-03-20 17:10:13 +000019#include <linux/kernel.h>
20#include <linux/init.h>
Hartley Sweeten583ddaf2009-07-06 17:39:50 +010021#include <linux/platform_device.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000022#include <linux/interrupt.h>
Matthias Kaehlcke63890a02008-10-29 14:14:52 -070023#include <linux/dma-mapping.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000024#include <linux/timex.h>
Hartley Sweeten6bd4b382010-02-18 18:16:11 +010025#include <linux/irq.h>
Hartley Sweeten583ddaf2009-07-06 17:39:50 +010026#include <linux/io.h>
27#include <linux/gpio.h>
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +010028#include <linux/leds.h>
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +010029#include <linux/termios.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000030#include <linux/amba/bus.h>
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +010031#include <linux/amba/serial.h>
Hartley Sweeten16bcf782010-06-10 16:19:08 +010032#include <linux/mtd/physmap.h>
Hartley Sweetend52a26a2008-10-16 23:57:03 +010033#include <linux/i2c.h>
34#include <linux/i2c-gpio.h>
Mika Westerberg4fec9972010-05-11 15:34:54 +010035#include <linux/spi/spi.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040036#include <linux/export.h>
Rob Herring9e47b8b2013-01-07 09:45:59 -060037#include <linux/irqchip/arm-vic.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070038#include <linux/reboot.h>
H Hartley Sweetene55f7cd2013-10-21 13:39:04 -070039#include <linux/usb/ohci_pdriver.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000040
Russell Kinga09e64f2008-08-05 16:14:15 +010041#include <mach/hardware.h>
Arnd Bergmanna3b29242012-08-24 15:12:11 +020042#include <linux/platform_data/video-ep93xx.h>
43#include <linux/platform_data/keypad-ep93xx.h>
44#include <linux/platform_data/spi-ep93xx.h>
Linus Walleijbd5f12a2011-09-22 08:07:00 +010045#include <mach/gpio-ep93xx.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000046
47#include <asm/mach/map.h>
48#include <asm/mach/time.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000049
Ryan Mallona05baf32012-01-11 09:29:26 +110050#include "soc.h"
Lennert Buytenheke7736d42006-03-20 17:10:13 +000051
52/*************************************************************************
53 * Static I/O mappings that are needed for all EP93xx platforms
54 *************************************************************************/
55static struct map_desc ep93xx_io_desc[] __initdata = {
56 {
57 .virtual = EP93XX_AHB_VIRT_BASE,
58 .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
59 .length = EP93XX_AHB_SIZE,
60 .type = MT_DEVICE,
61 }, {
62 .virtual = EP93XX_APB_VIRT_BASE,
63 .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE),
64 .length = EP93XX_APB_SIZE,
65 .type = MT_DEVICE,
66 },
67};
68
69void __init ep93xx_map_io(void)
70{
71 iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
72}
73
74
75/*************************************************************************
76 * Timer handling for EP93xx
77 *************************************************************************
78 * The ep93xx has four internal timers. Timers 1, 2 (both 16 bit) and
79 * 3 (32 bit) count down at 508 kHz, are self-reloading, and can generate
80 * an interrupt on underflow. Timer 4 (40 bit) counts down at 983.04 kHz,
81 * is free-running, and can't generate interrupts.
82 *
83 * The 508 kHz timers are ideal for use for the timer interrupt, as the
84 * most common values of HZ divide 508 kHz nicely. We pick one of the 16
85 * bit timers (timer 1) since we don't need more than 16 bits of reload
86 * value as long as HZ >= 8.
87 *
88 * The higher clock rate of timer 4 makes it a better choice than the
89 * other timers for use in gettimeoffset(), while the fact that it can't
90 * generate interrupts means we don't have to worry about not being able
91 * to use this timer for something else. We also use timer 4 for keeping
92 * track of lost jiffies.
93 */
Hartley Sweeten1587a372010-02-23 21:45:22 +010094#define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
95#define EP93XX_TIMER1_LOAD EP93XX_TIMER_REG(0x00)
96#define EP93XX_TIMER1_VALUE EP93XX_TIMER_REG(0x04)
97#define EP93XX_TIMER1_CONTROL EP93XX_TIMER_REG(0x08)
98#define EP93XX_TIMER123_CONTROL_ENABLE (1 << 7)
99#define EP93XX_TIMER123_CONTROL_MODE (1 << 6)
100#define EP93XX_TIMER123_CONTROL_CLKSEL (1 << 3)
101#define EP93XX_TIMER1_CLEAR EP93XX_TIMER_REG(0x0c)
102#define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
103#define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
104#define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
105#define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
106#define EP93XX_TIMER4_VALUE_LOW EP93XX_TIMER_REG(0x60)
107#define EP93XX_TIMER4_VALUE_HIGH EP93XX_TIMER_REG(0x64)
108#define EP93XX_TIMER4_VALUE_HIGH_ENABLE (1 << 8)
109#define EP93XX_TIMER3_LOAD EP93XX_TIMER_REG(0x80)
110#define EP93XX_TIMER3_VALUE EP93XX_TIMER_REG(0x84)
111#define EP93XX_TIMER3_CONTROL EP93XX_TIMER_REG(0x88)
112#define EP93XX_TIMER3_CLEAR EP93XX_TIMER_REG(0x8c)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000113
Hartley Sweeten1587a372010-02-23 21:45:22 +0100114#define EP93XX_TIMER123_CLOCK 508469
115#define EP93XX_TIMER4_CLOCK 983040
116
117#define TIMER1_RELOAD ((EP93XX_TIMER123_CLOCK / HZ) - 1)
Julia Lawallaf1057a2009-08-03 11:57:20 +0100118#define TIMER4_TICKS_PER_JIFFY DIV_ROUND_CLOSEST(CLOCK_TICK_RATE, HZ)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000119
Hartley Sweeten1587a372010-02-23 21:45:22 +0100120static unsigned int last_jiffy_time;
121
Hartley Sweetend5565f72009-04-14 21:38:07 +0100122static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000123{
Hartley Sweeten1587a372010-02-23 21:45:22 +0100124 /* Writing any value clears the timer interrupt */
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000125 __raw_writel(1, EP93XX_TIMER1_CLEAR);
Hartley Sweeten1587a372010-02-23 21:45:22 +0100126
127 /* Recover lost jiffies */
Lennert Buytenhekf869afa2006-06-22 10:30:53 +0100128 while ((signed long)
129 (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000130 >= TIMER4_TICKS_PER_JIFFY) {
131 last_jiffy_time += TIMER4_TICKS_PER_JIFFY;
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700132 timer_tick();
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000133 }
134
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000135 return IRQ_HANDLED;
136}
137
138static struct irqaction ep93xx_timer_irq = {
139 .name = "ep93xx timer",
Bernhard Walleb30faba2007-05-08 00:35:39 -0700140 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000141 .handler = ep93xx_timer_interrupt,
142};
143
Stephen Warren23c197b2012-11-08 11:51:58 -0700144static u32 ep93xx_gettimeoffset(void)
145{
146 int offset;
147
148 offset = __raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time;
149
150 /*
151 * Timer 4 is based on a 983.04 kHz reference clock,
152 * so dividing by 983040 gives the fraction of a second,
153 * so dividing by 0.983040 converts to uS.
154 * Refactor the calculation to avoid overflow.
155 * Finally, multiply by 1000 to give nS.
156 */
157 return (offset + (53 * offset / 3072)) * 1000;
158}
159
Stephen Warren6bb27d72012-11-08 12:40:59 -0700160void __init ep93xx_timer_init(void)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000161{
Hartley Sweeten1587a372010-02-23 21:45:22 +0100162 u32 tmode = EP93XX_TIMER123_CONTROL_MODE |
163 EP93XX_TIMER123_CONTROL_CLKSEL;
164
Stephen Warren23c197b2012-11-08 11:51:58 -0700165 arch_gettimeoffset = ep93xx_gettimeoffset;
166
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000167 /* Enable periodic HZ timer. */
Hartley Sweeten1587a372010-02-23 21:45:22 +0100168 __raw_writel(tmode, EP93XX_TIMER1_CONTROL);
169 __raw_writel(TIMER1_RELOAD, EP93XX_TIMER1_LOAD);
170 __raw_writel(tmode | EP93XX_TIMER123_CONTROL_ENABLE,
171 EP93XX_TIMER1_CONTROL);
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000172
173 /* Enable lost jiffy timer. */
Hartley Sweeten1587a372010-02-23 21:45:22 +0100174 __raw_writel(EP93XX_TIMER4_VALUE_HIGH_ENABLE,
175 EP93XX_TIMER4_VALUE_HIGH);
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000176
177 setup_irq(IRQ_EP93XX_TIMER1, &ep93xx_timer_irq);
178}
179
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000180
181/*************************************************************************
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000182 * EP93xx IRQ handling
183 *************************************************************************/
184void __init ep93xx_init_irq(void)
185{
Hartley Sweeten53967302009-07-09 23:22:07 +0100186 vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
187 vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000188}
189
190
191/*************************************************************************
Hartley Sweeten02239f02009-07-08 02:00:49 +0100192 * EP93xx System Controller Software Locked register handling
193 *************************************************************************/
194
195/*
196 * syscon_swlock prevents anything else from writing to the syscon
197 * block while a software locked register is being written.
198 */
199static DEFINE_SPINLOCK(syscon_swlock);
200
Ryan Mallonfbeeea52009-07-15 21:51:59 +0100201void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
Hartley Sweeten02239f02009-07-08 02:00:49 +0100202{
203 unsigned long flags;
204
205 spin_lock_irqsave(&syscon_swlock, flags);
206
207 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
208 __raw_writel(val, reg);
209
210 spin_unlock_irqrestore(&syscon_swlock, flags);
211}
Hartley Sweeten02239f02009-07-08 02:00:49 +0100212
213void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
214{
215 unsigned long flags;
216 unsigned int val;
217
218 spin_lock_irqsave(&syscon_swlock, flags);
219
220 val = __raw_readl(EP93XX_SYSCON_DEVCFG);
Hartley Sweeten02239f02009-07-08 02:00:49 +0100221 val &= ~clear_bits;
Hartley Sweetena0fb0072010-06-14 16:54:16 +0100222 val |= set_bits;
Hartley Sweeten02239f02009-07-08 02:00:49 +0100223 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
224 __raw_writel(val, EP93XX_SYSCON_DEVCFG);
225
226 spin_unlock_irqrestore(&syscon_swlock, flags);
227}
Hartley Sweeten02239f02009-07-08 02:00:49 +0100228
Mika Westerberg99e6a232010-03-27 12:05:14 +0100229/**
230 * ep93xx_chip_revision() - returns the EP93xx chip revision
231 *
232 * See <mach/platform.h> for more information.
233 */
234unsigned int ep93xx_chip_revision(void)
235{
236 unsigned int v;
237
238 v = __raw_readl(EP93XX_SYSCON_SYSCFG);
239 v &= EP93XX_SYSCON_SYSCFG_REV_MASK;
240 v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT;
241 return v;
242}
Hartley Sweeten02239f02009-07-08 02:00:49 +0100243
244/*************************************************************************
H Hartley Sweeten1e4c8842011-06-08 14:35:33 -0700245 * EP93xx GPIO
246 *************************************************************************/
247static struct resource ep93xx_gpio_resource[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700248 DEFINE_RES_MEM(EP93XX_GPIO_PHYS_BASE, 0xcc),
H Hartley Sweeten1e4c8842011-06-08 14:35:33 -0700249};
250
251static struct platform_device ep93xx_gpio_device = {
252 .name = "gpio-ep93xx",
253 .id = -1,
254 .num_resources = ARRAY_SIZE(ep93xx_gpio_resource),
255 .resource = ep93xx_gpio_resource,
256};
257
258/*************************************************************************
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000259 * EP93xx peripheral handling
260 *************************************************************************/
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100261#define EP93XX_UART_MCR_OFFSET (0x0100)
262
263static void ep93xx_uart_set_mctrl(struct amba_device *dev,
264 void __iomem *base, unsigned int mctrl)
265{
266 unsigned int mcr;
267
268 mcr = 0;
Petr Å tetiar186dcaa2011-06-17 11:10:04 +0100269 if (mctrl & TIOCM_RTS)
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100270 mcr |= 2;
Petr Å tetiar186dcaa2011-06-17 11:10:04 +0100271 if (mctrl & TIOCM_DTR)
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100272 mcr |= 1;
273
274 __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
275}
276
277static struct amba_pl010_data ep93xx_uart_data = {
278 .set_mctrl = ep93xx_uart_set_mctrl,
279};
280
Russell King0b260512011-12-18 15:16:40 +0000281static AMBA_APB_DEVICE(uart1, "apb:uart1", 0x00041010, EP93XX_UART1_PHYS_BASE,
282 { IRQ_EP93XX_UART1 }, &ep93xx_uart_data);
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100283
Russell King0b260512011-12-18 15:16:40 +0000284static AMBA_APB_DEVICE(uart2, "apb:uart2", 0x00041010, EP93XX_UART2_PHYS_BASE,
Petr Å tetiarcc3874f2013-08-29 16:28:11 +0200285 { IRQ_EP93XX_UART2 }, NULL);
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100286
Russell King0b260512011-12-18 15:16:40 +0000287static AMBA_APB_DEVICE(uart3, "apb:uart3", 0x00041010, EP93XX_UART3_PHYS_BASE,
288 { IRQ_EP93XX_UART3 }, &ep93xx_uart_data);
Lennert Buytenhek41658132006-04-02 16:17:34 +0100289
Hartley Sweeten38f7b002009-04-15 23:18:26 +0100290static struct resource ep93xx_rtc_resource[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700291 DEFINE_RES_MEM(EP93XX_RTC_PHYS_BASE, 0x10c),
Hartley Sweeten38f7b002009-04-15 23:18:26 +0100292};
293
Lennert Buytenhek41658132006-04-02 16:17:34 +0100294static struct platform_device ep93xx_rtc_device = {
Hartley Sweeten38f7b002009-04-15 23:18:26 +0100295 .name = "ep93xx-rtc",
296 .id = -1,
297 .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
298 .resource = ep93xx_rtc_resource,
Lennert Buytenhek41658132006-04-02 16:17:34 +0100299};
300
H Hartley Sweetene55f7cd2013-10-21 13:39:04 -0700301/*************************************************************************
302 * EP93xx OHCI USB Host
303 *************************************************************************/
304
305static struct clk *ep93xx_ohci_host_clock;
306
307static int ep93xx_ohci_power_on(struct platform_device *pdev)
308{
309 if (!ep93xx_ohci_host_clock) {
310 ep93xx_ohci_host_clock = devm_clk_get(&pdev->dev, NULL);
311 if (IS_ERR(ep93xx_ohci_host_clock))
312 return PTR_ERR(ep93xx_ohci_host_clock);
313 }
314
315 return clk_enable(ep93xx_ohci_host_clock);
316}
317
318static void ep93xx_ohci_power_off(struct platform_device *pdev)
319{
320 clk_disable(ep93xx_ohci_host_clock);
321}
322
323static struct usb_ohci_pdata ep93xx_ohci_pdata = {
324 .power_on = ep93xx_ohci_power_on,
325 .power_off = ep93xx_ohci_power_off,
326 .power_suspend = ep93xx_ohci_power_off,
327};
Lennert Buytenhek41658132006-04-02 16:17:34 +0100328
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100329static struct resource ep93xx_ohci_resources[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700330 DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000),
331 DEFINE_RES_IRQ(IRQ_EP93XX_USB),
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100332};
333
H Hartley Sweetene55f7cd2013-10-21 13:39:04 -0700334static u64 ep93xx_ohci_dma_mask = DMA_BIT_MASK(32);
Matthias Kaehlcke63890a02008-10-29 14:14:52 -0700335
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100336static struct platform_device ep93xx_ohci_device = {
H Hartley Sweetene55f7cd2013-10-21 13:39:04 -0700337 .name = "ohci-platform",
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100338 .id = -1,
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100339 .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
340 .resource = ep93xx_ohci_resources,
H Hartley Sweetene55f7cd2013-10-21 13:39:04 -0700341 .dev = {
342 .dma_mask = &ep93xx_ohci_dma_mask,
343 .coherent_dma_mask = DMA_BIT_MASK(32),
344 .platform_data = &ep93xx_ohci_pdata,
345 },
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100346};
347
Hartley Sweetenb370e082010-03-18 18:04:06 +0100348/*************************************************************************
Hartley Sweeten16bcf782010-06-10 16:19:08 +0100349 * EP93xx physmap'ed flash
350 *************************************************************************/
351static struct physmap_flash_data ep93xx_flash_data;
352
353static struct resource ep93xx_flash_resource = {
354 .flags = IORESOURCE_MEM,
355};
356
357static struct platform_device ep93xx_flash = {
358 .name = "physmap-flash",
359 .id = 0,
360 .dev = {
361 .platform_data = &ep93xx_flash_data,
362 },
363 .num_resources = 1,
364 .resource = &ep93xx_flash_resource,
365};
366
367/**
368 * ep93xx_register_flash() - Register the external flash device.
369 * @width: bank width in octets
370 * @start: resource start address
371 * @size: resource size
372 */
373void __init ep93xx_register_flash(unsigned int width,
374 resource_size_t start, resource_size_t size)
375{
376 ep93xx_flash_data.width = width;
377
378 ep93xx_flash_resource.start = start;
379 ep93xx_flash_resource.end = start + size - 1;
380
381 platform_device_register(&ep93xx_flash);
382}
383
384
385/*************************************************************************
Hartley Sweetenb370e082010-03-18 18:04:06 +0100386 * EP93xx ethernet peripheral handling
387 *************************************************************************/
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100388static struct ep93xx_eth_data ep93xx_eth_data;
389
390static struct resource ep93xx_eth_resource[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700391 DEFINE_RES_MEM(EP93XX_ETHERNET_PHYS_BASE, 0x10000),
Ryan Mallon011b2e82012-04-12 09:11:55 +1000392 DEFINE_RES_IRQ(IRQ_EP93XX_ETHERNET),
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100393};
394
Mika Westerbergfa70cf42011-06-11 08:39:54 +0000395static u64 ep93xx_eth_dma_mask = DMA_BIT_MASK(32);
396
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100397static struct platform_device ep93xx_eth_device = {
398 .name = "ep93xx-eth",
399 .id = -1,
400 .dev = {
Mika Westerbergfa70cf42011-06-11 08:39:54 +0000401 .platform_data = &ep93xx_eth_data,
402 .coherent_dma_mask = DMA_BIT_MASK(32),
403 .dma_mask = &ep93xx_eth_dma_mask,
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100404 },
405 .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
406 .resource = ep93xx_eth_resource,
407};
408
Hartley Sweetenb370e082010-03-18 18:04:06 +0100409/**
410 * ep93xx_register_eth - Register the built-in ethernet platform device.
411 * @data: platform specific ethernet configuration (__initdata)
412 * @copy_addr: flag indicating that the MAC address should be copied
413 * from the IndAd registers (as programmed by the bootloader)
414 */
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100415void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
416{
Hartley Sweeten5b1c3c82009-07-13 19:50:10 +0100417 if (copy_addr)
418 memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100419
420 ep93xx_eth_data = *data;
421 platform_device_register(&ep93xx_eth_device);
422}
423
Hartley Sweeten6531a992009-10-08 00:45:00 +0100424
425/*************************************************************************
426 * EP93xx i2c peripheral handling
427 *************************************************************************/
428static struct i2c_gpio_platform_data ep93xx_i2c_data;
Hartley Sweetend52a26a2008-10-16 23:57:03 +0100429
430static struct platform_device ep93xx_i2c_device = {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100431 .name = "i2c-gpio",
432 .id = 0,
433 .dev = {
434 .platform_data = &ep93xx_i2c_data,
435 },
Hartley Sweetend52a26a2008-10-16 23:57:03 +0100436};
437
Hartley Sweetenb370e082010-03-18 18:04:06 +0100438/**
439 * ep93xx_register_i2c - Register the i2c platform device.
440 * @data: platform specific i2c-gpio configuration (__initdata)
441 * @devices: platform specific i2c bus device information (__initdata)
442 * @num: the number of devices on the i2c bus
443 */
Hartley Sweeten6531a992009-10-08 00:45:00 +0100444void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
445 struct i2c_board_info *devices, int num)
Hartley Sweetend52a26a2008-10-16 23:57:03 +0100446{
Hartley Sweeten6531a992009-10-08 00:45:00 +0100447 /*
448 * Set the EEPROM interface pin drive type control.
449 * Defines the driver type for the EECLK and EEDAT pins as either
450 * open drain, which will require an external pull-up, or a normal
451 * CMOS driver.
452 */
453 if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT)
Hartley Sweeten64d68822010-01-11 19:33:16 +0100454 pr_warning("sda != EEDAT, open drain has no effect\n");
Hartley Sweeten6531a992009-10-08 00:45:00 +0100455 if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
Hartley Sweeten64d68822010-01-11 19:33:16 +0100456 pr_warning("scl != EECLK, open drain has no effect\n");
Hartley Sweeten6531a992009-10-08 00:45:00 +0100457
458 __raw_writel((data->sda_is_open_drain << 1) |
459 (data->scl_is_open_drain << 0),
460 EP93XX_GPIO_EEDRIVE);
461
462 ep93xx_i2c_data = *data;
Hartley Sweetend52a26a2008-10-16 23:57:03 +0100463 i2c_register_board_info(0, devices, num);
464 platform_device_register(&ep93xx_i2c_device);
465}
466
Mika Westerberg4fec9972010-05-11 15:34:54 +0100467/*************************************************************************
468 * EP93xx SPI peripheral handling
469 *************************************************************************/
470static struct ep93xx_spi_info ep93xx_spi_master_data;
471
472static struct resource ep93xx_spi_resources[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700473 DEFINE_RES_MEM(EP93XX_SPI_PHYS_BASE, 0x18),
474 DEFINE_RES_IRQ(IRQ_EP93XX_SSP),
Mika Westerberg4fec9972010-05-11 15:34:54 +0100475};
476
Mika Westerberg626a96d2011-05-29 13:10:06 +0300477static u64 ep93xx_spi_dma_mask = DMA_BIT_MASK(32);
478
Mika Westerberg4fec9972010-05-11 15:34:54 +0100479static struct platform_device ep93xx_spi_device = {
480 .name = "ep93xx-spi",
481 .id = 0,
482 .dev = {
Mika Westerberg626a96d2011-05-29 13:10:06 +0300483 .platform_data = &ep93xx_spi_master_data,
484 .coherent_dma_mask = DMA_BIT_MASK(32),
485 .dma_mask = &ep93xx_spi_dma_mask,
Mika Westerberg4fec9972010-05-11 15:34:54 +0100486 },
487 .num_resources = ARRAY_SIZE(ep93xx_spi_resources),
488 .resource = ep93xx_spi_resources,
489};
490
491/**
492 * ep93xx_register_spi() - registers spi platform device
493 * @info: ep93xx board specific spi master info (__initdata)
494 * @devices: SPI devices to register (__initdata)
495 * @num: number of SPI devices to register
496 *
497 * This function registers platform device for the EP93xx SPI controller and
498 * also makes sure that SPI pins are muxed so that I2S is not using those pins.
499 */
500void __init ep93xx_register_spi(struct ep93xx_spi_info *info,
501 struct spi_board_info *devices, int num)
502{
503 /*
504 * When SPI is used, we need to make sure that I2S is muxed off from
505 * SPI pins.
506 */
507 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
508
509 ep93xx_spi_master_data = *info;
510 spi_register_board_info(devices, num);
511 platform_device_register(&ep93xx_spi_device);
512}
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100513
514/*************************************************************************
515 * EP93xx LEDs
516 *************************************************************************/
H Hartley Sweetena1eacd72012-04-11 15:44:42 -0700517static const struct gpio_led ep93xx_led_pins[] __initconst = {
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100518 {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100519 .name = "platform:grled",
520 .gpio = EP93XX_GPIO_LINE_GRLED,
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100521 }, {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100522 .name = "platform:rdled",
523 .gpio = EP93XX_GPIO_LINE_RDLED,
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100524 },
525};
526
H Hartley Sweetena1eacd72012-04-11 15:44:42 -0700527static const struct gpio_led_platform_data ep93xx_led_data __initconst = {
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100528 .num_leds = ARRAY_SIZE(ep93xx_led_pins),
529 .leds = ep93xx_led_pins,
530};
531
Hartley Sweetenef123792009-07-29 22:41:06 +0100532/*************************************************************************
533 * EP93xx pwm peripheral handling
534 *************************************************************************/
535static struct resource ep93xx_pwm0_resource[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700536 DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE, 0x10),
Hartley Sweetenef123792009-07-29 22:41:06 +0100537};
538
539static struct platform_device ep93xx_pwm0_device = {
540 .name = "ep93xx-pwm",
541 .id = 0,
542 .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
543 .resource = ep93xx_pwm0_resource,
544};
545
546static struct resource ep93xx_pwm1_resource[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700547 DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE + 0x20, 0x10),
Hartley Sweetenef123792009-07-29 22:41:06 +0100548};
549
550static struct platform_device ep93xx_pwm1_device = {
551 .name = "ep93xx-pwm",
552 .id = 1,
553 .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
554 .resource = ep93xx_pwm1_resource,
555};
556
557void __init ep93xx_register_pwm(int pwm0, int pwm1)
558{
559 if (pwm0)
560 platform_device_register(&ep93xx_pwm0_device);
561
562 /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
563 if (pwm1)
564 platform_device_register(&ep93xx_pwm1_device);
565}
566
567int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
568{
569 int err;
570
571 if (pdev->id == 0) {
572 err = 0;
573 } else if (pdev->id == 1) {
574 err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
575 dev_name(&pdev->dev));
576 if (err)
577 return err;
578 err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
579 if (err)
580 goto fail;
581
582 /* PWM 1 output on EGPIO[14] */
583 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
584 } else {
585 err = -ENODEV;
586 }
587
588 return err;
589
590fail:
591 gpio_free(EP93XX_GPIO_LINE_EGPIO14);
592 return err;
593}
594EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
595
596void ep93xx_pwm_release_gpio(struct platform_device *pdev)
597{
598 if (pdev->id == 1) {
599 gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
600 gpio_free(EP93XX_GPIO_LINE_EGPIO14);
601
602 /* EGPIO[14] used for GPIO */
603 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
604 }
605}
606EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
607
608
Ryan Mallonc6012182009-09-22 16:47:09 -0700609/*************************************************************************
610 * EP93xx video peripheral handling
611 *************************************************************************/
612static struct ep93xxfb_mach_info ep93xxfb_data;
613
614static struct resource ep93xx_fb_resource[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700615 DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE, 0x800),
Ryan Mallonc6012182009-09-22 16:47:09 -0700616};
617
618static struct platform_device ep93xx_fb_device = {
619 .name = "ep93xx-fb",
620 .id = -1,
621 .dev = {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100622 .platform_data = &ep93xxfb_data,
Ryan Mallonc6012182009-09-22 16:47:09 -0700623 .coherent_dma_mask = DMA_BIT_MASK(32),
624 .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
625 },
626 .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
627 .resource = ep93xx_fb_resource,
628};
629
Ryan Mallon0fd19582012-01-22 20:31:32 +1100630/* The backlight use a single register in the framebuffer's register space */
631#define EP93XX_RASTER_REG_BRIGHTNESS 0x20
632
633static struct resource ep93xx_bl_resources[] = {
634 DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE +
635 EP93XX_RASTER_REG_BRIGHTNESS, 0x04),
636};
637
Hartley Sweeten6ea4b742010-06-09 21:15:12 +0100638static struct platform_device ep93xx_bl_device = {
639 .name = "ep93xx-bl",
640 .id = -1,
Ryan Mallon0fd19582012-01-22 20:31:32 +1100641 .num_resources = ARRAY_SIZE(ep93xx_bl_resources),
642 .resource = ep93xx_bl_resources,
Hartley Sweeten6ea4b742010-06-09 21:15:12 +0100643};
644
Hartley Sweetenb370e082010-03-18 18:04:06 +0100645/**
646 * ep93xx_register_fb - Register the framebuffer platform device.
647 * @data: platform specific framebuffer configuration (__initdata)
648 */
Ryan Mallonc6012182009-09-22 16:47:09 -0700649void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
650{
651 ep93xxfb_data = *data;
652 platform_device_register(&ep93xx_fb_device);
Hartley Sweeten6ea4b742010-06-09 21:15:12 +0100653 platform_device_register(&ep93xx_bl_device);
Ryan Mallonc6012182009-09-22 16:47:09 -0700654}
655
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100656
657/*************************************************************************
658 * EP93xx matrix keypad peripheral handling
659 *************************************************************************/
Hartley Sweetenb370e082010-03-18 18:04:06 +0100660static struct ep93xx_keypad_platform_data ep93xx_keypad_data;
661
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100662static struct resource ep93xx_keypad_resource[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700663 DEFINE_RES_MEM(EP93XX_KEY_MATRIX_PHYS_BASE, 0x0c),
664 DEFINE_RES_IRQ(IRQ_EP93XX_KEY),
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100665};
666
667static struct platform_device ep93xx_keypad_device = {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100668 .name = "ep93xx-keypad",
669 .id = -1,
670 .dev = {
671 .platform_data = &ep93xx_keypad_data,
672 },
673 .num_resources = ARRAY_SIZE(ep93xx_keypad_resource),
674 .resource = ep93xx_keypad_resource,
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100675};
676
Hartley Sweetenb370e082010-03-18 18:04:06 +0100677/**
678 * ep93xx_register_keypad - Register the keypad platform device.
679 * @data: platform specific keypad configuration (__initdata)
680 */
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100681void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
682{
Hartley Sweetenb370e082010-03-18 18:04:06 +0100683 ep93xx_keypad_data = *data;
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100684 platform_device_register(&ep93xx_keypad_device);
685}
686
687int ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
688{
689 int err;
690 int i;
691
692 for (i = 0; i < 8; i++) {
693 err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
694 if (err)
695 goto fail_gpio_c;
696 err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
697 if (err)
698 goto fail_gpio_d;
699 }
700
701 /* Enable the keypad controller; GPIO ports C and D used for keypad */
702 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
703 EP93XX_SYSCON_DEVCFG_GONK);
704
705 return 0;
706
707fail_gpio_d:
708 gpio_free(EP93XX_GPIO_LINE_C(i));
709fail_gpio_c:
Rafal Prylowski5528a842012-04-05 13:44:07 +0200710 for (--i; i >= 0; --i) {
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100711 gpio_free(EP93XX_GPIO_LINE_C(i));
712 gpio_free(EP93XX_GPIO_LINE_D(i));
713 }
714 return err;
715}
716EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
717
718void ep93xx_keypad_release_gpio(struct platform_device *pdev)
719{
720 int i;
721
722 for (i = 0; i < 8; i++) {
723 gpio_free(EP93XX_GPIO_LINE_C(i));
724 gpio_free(EP93XX_GPIO_LINE_D(i));
725 }
726
727 /* Disable the keypad controller; GPIO ports C and D used for GPIO */
728 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
729 EP93XX_SYSCON_DEVCFG_GONK);
730}
731EXPORT_SYMBOL(ep93xx_keypad_release_gpio);
732
Ryan Malloned67ea82010-06-08 22:01:10 +1200733/*************************************************************************
734 * EP93xx I2S audio peripheral handling
735 *************************************************************************/
736static struct resource ep93xx_i2s_resource[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700737 DEFINE_RES_MEM(EP93XX_I2S_PHYS_BASE, 0x100),
Ryan Malloned67ea82010-06-08 22:01:10 +1200738};
739
740static struct platform_device ep93xx_i2s_device = {
741 .name = "ep93xx-i2s",
742 .id = -1,
743 .num_resources = ARRAY_SIZE(ep93xx_i2s_resource),
744 .resource = ep93xx_i2s_resource,
745};
746
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000747static struct platform_device ep93xx_pcm_device = {
748 .name = "ep93xx-pcm-audio",
749 .id = -1,
750};
751
Ryan Malloned67ea82010-06-08 22:01:10 +1200752void __init ep93xx_register_i2s(void)
753{
754 platform_device_register(&ep93xx_i2s_device);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000755 platform_device_register(&ep93xx_pcm_device);
Ryan Malloned67ea82010-06-08 22:01:10 +1200756}
757
758#define EP93XX_SYSCON_DEVCFG_I2S_MASK (EP93XX_SYSCON_DEVCFG_I2SONSSP | \
759 EP93XX_SYSCON_DEVCFG_I2SONAC97)
760
761#define EP93XX_I2SCLKDIV_MASK (EP93XX_SYSCON_I2SCLKDIV_ORIDE | \
762 EP93XX_SYSCON_I2SCLKDIV_SPOL)
763
Ryan Mallonf15855b2012-01-11 11:04:42 +1100764int ep93xx_i2s_acquire(void)
Ryan Malloned67ea82010-06-08 22:01:10 +1200765{
766 unsigned val;
767
Ryan Mallonf15855b2012-01-11 11:04:42 +1100768 ep93xx_devcfg_set_clear(EP93XX_SYSCON_DEVCFG_I2SONAC97,
769 EP93XX_SYSCON_DEVCFG_I2S_MASK);
Ryan Malloned67ea82010-06-08 22:01:10 +1200770
771 /*
772 * This is potentially racy with the clock api for i2s_mclk, sclk and
773 * lrclk. Since the i2s driver is the only user of those clocks we
774 * rely on it to prevent parallel use of this function and the
775 * clock api for the i2s clocks.
776 */
777 val = __raw_readl(EP93XX_SYSCON_I2SCLKDIV);
778 val &= ~EP93XX_I2SCLKDIV_MASK;
Ryan Mallonf15855b2012-01-11 11:04:42 +1100779 val |= EP93XX_SYSCON_I2SCLKDIV_ORIDE | EP93XX_SYSCON_I2SCLKDIV_SPOL;
Ryan Malloned67ea82010-06-08 22:01:10 +1200780 ep93xx_syscon_swlocked_write(val, EP93XX_SYSCON_I2SCLKDIV);
781
782 return 0;
783}
784EXPORT_SYMBOL(ep93xx_i2s_acquire);
785
786void ep93xx_i2s_release(void)
787{
788 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK);
789}
790EXPORT_SYMBOL(ep93xx_i2s_release);
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100791
Mika Westerberg534bc7f2010-10-14 17:49:07 +0300792/*************************************************************************
793 * EP93xx AC97 audio peripheral handling
794 *************************************************************************/
795static struct resource ep93xx_ac97_resources[] = {
H Hartley Sweetenede55aa2012-03-21 11:35:49 -0700796 DEFINE_RES_MEM(EP93XX_AAC_PHYS_BASE, 0xac),
797 DEFINE_RES_IRQ(IRQ_EP93XX_AACINTR),
Mika Westerberg534bc7f2010-10-14 17:49:07 +0300798};
799
800static struct platform_device ep93xx_ac97_device = {
801 .name = "ep93xx-ac97",
802 .id = -1,
803 .num_resources = ARRAY_SIZE(ep93xx_ac97_resources),
804 .resource = ep93xx_ac97_resources,
805};
806
807void __init ep93xx_register_ac97(void)
808{
809 /*
810 * Make sure that the AC97 pins are not used by I2S.
811 */
812 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97);
813
814 platform_device_register(&ep93xx_ac97_device);
815 platform_device_register(&ep93xx_pcm_device);
816}
817
H Hartley Sweeten73303d12012-01-22 20:01:16 +1100818/*************************************************************************
819 * EP93xx Watchdog
820 *************************************************************************/
821static struct resource ep93xx_wdt_resources[] = {
822 DEFINE_RES_MEM(EP93XX_WATCHDOG_PHYS_BASE, 0x08),
823};
824
825static struct platform_device ep93xx_wdt_device = {
826 .name = "ep93xx-wdt",
827 .id = -1,
828 .num_resources = ARRAY_SIZE(ep93xx_wdt_resources),
829 .resource = ep93xx_wdt_resources,
830};
831
Rafal Prylowskieb774a02012-04-12 14:14:12 +0200832/*************************************************************************
833 * EP93xx IDE
834 *************************************************************************/
835static struct resource ep93xx_ide_resources[] = {
836 DEFINE_RES_MEM(EP93XX_IDE_PHYS_BASE, 0x38),
837 DEFINE_RES_IRQ(IRQ_EP93XX_EXT3),
838};
839
840static struct platform_device ep93xx_ide_device = {
841 .name = "ep93xx-ide",
842 .id = -1,
843 .dev = {
844 .dma_mask = &ep93xx_ide_device.dev.coherent_dma_mask,
845 .coherent_dma_mask = DMA_BIT_MASK(32),
846 },
847 .num_resources = ARRAY_SIZE(ep93xx_ide_resources),
848 .resource = ep93xx_ide_resources,
849};
850
851void __init ep93xx_register_ide(void)
852{
853 platform_device_register(&ep93xx_ide_device);
854}
855
856int ep93xx_ide_acquire_gpio(struct platform_device *pdev)
857{
858 int err;
859 int i;
860
861 err = gpio_request(EP93XX_GPIO_LINE_EGPIO2, dev_name(&pdev->dev));
862 if (err)
863 return err;
864 err = gpio_request(EP93XX_GPIO_LINE_EGPIO15, dev_name(&pdev->dev));
865 if (err)
866 goto fail_egpio15;
867 for (i = 2; i < 8; i++) {
868 err = gpio_request(EP93XX_GPIO_LINE_E(i), dev_name(&pdev->dev));
869 if (err)
870 goto fail_gpio_e;
871 }
872 for (i = 4; i < 8; i++) {
873 err = gpio_request(EP93XX_GPIO_LINE_G(i), dev_name(&pdev->dev));
874 if (err)
875 goto fail_gpio_g;
876 }
877 for (i = 0; i < 8; i++) {
878 err = gpio_request(EP93XX_GPIO_LINE_H(i), dev_name(&pdev->dev));
879 if (err)
880 goto fail_gpio_h;
881 }
882
883 /* GPIO ports E[7:2], G[7:4] and H used by IDE */
884 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
885 EP93XX_SYSCON_DEVCFG_GONIDE |
886 EP93XX_SYSCON_DEVCFG_HONIDE);
887 return 0;
888
889fail_gpio_h:
890 for (--i; i >= 0; --i)
891 gpio_free(EP93XX_GPIO_LINE_H(i));
892 i = 8;
893fail_gpio_g:
894 for (--i; i >= 4; --i)
895 gpio_free(EP93XX_GPIO_LINE_G(i));
896 i = 8;
897fail_gpio_e:
898 for (--i; i >= 2; --i)
899 gpio_free(EP93XX_GPIO_LINE_E(i));
900 gpio_free(EP93XX_GPIO_LINE_EGPIO15);
901fail_egpio15:
902 gpio_free(EP93XX_GPIO_LINE_EGPIO2);
903 return err;
904}
905EXPORT_SYMBOL(ep93xx_ide_acquire_gpio);
906
907void ep93xx_ide_release_gpio(struct platform_device *pdev)
908{
909 int i;
910
911 for (i = 2; i < 8; i++)
912 gpio_free(EP93XX_GPIO_LINE_E(i));
913 for (i = 4; i < 8; i++)
914 gpio_free(EP93XX_GPIO_LINE_G(i));
915 for (i = 0; i < 8; i++)
916 gpio_free(EP93XX_GPIO_LINE_H(i));
917 gpio_free(EP93XX_GPIO_LINE_EGPIO15);
918 gpio_free(EP93XX_GPIO_LINE_EGPIO2);
919
920
921 /* GPIO ports E[7:2], G[7:4] and H used by GPIO */
922 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
923 EP93XX_SYSCON_DEVCFG_GONIDE |
924 EP93XX_SYSCON_DEVCFG_HONIDE);
925}
926EXPORT_SYMBOL(ep93xx_ide_release_gpio);
927
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000928void __init ep93xx_init_devices(void)
929{
Hartley Sweeten02239f02009-07-08 02:00:49 +0100930 /* Disallow access to MaverickCrunch initially */
931 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100932
Ryan Mallon08932d82012-01-11 09:58:30 +1100933 /* Default all ports to GPIO */
934 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
935 EP93XX_SYSCON_DEVCFG_GONK |
936 EP93XX_SYSCON_DEVCFG_EONIDE |
937 EP93XX_SYSCON_DEVCFG_GONIDE |
938 EP93XX_SYSCON_DEVCFG_HONIDE);
939
H Hartley Sweeten1e4c8842011-06-08 14:35:33 -0700940 /* Get the GPIO working early, other devices need it */
941 platform_device_register(&ep93xx_gpio_device);
Ryan Mallonb6850042008-04-16 02:56:35 +0100942
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100943 amba_device_register(&uart1_device, &iomem_resource);
944 amba_device_register(&uart2_device, &iomem_resource);
945 amba_device_register(&uart3_device, &iomem_resource);
Lennert Buytenhek41658132006-04-02 16:17:34 +0100946
947 platform_device_register(&ep93xx_rtc_device);
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100948 platform_device_register(&ep93xx_ohci_device);
H Hartley Sweeten73303d12012-01-22 20:01:16 +1100949 platform_device_register(&ep93xx_wdt_device);
H Hartley Sweetena1eacd72012-04-11 15:44:42 -0700950
951 gpio_led_register_device(-1, &ep93xx_led_data);
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000952}
Russell King32751662011-11-05 09:54:14 +0000953
Robin Holt7b6d8642013-07-08 16:01:40 -0700954void ep93xx_restart(enum reboot_mode mode, const char *cmd)
Russell King32751662011-11-05 09:54:14 +0000955{
956 /*
957 * Set then clear the SWRST bit to initiate a software reset
958 */
959 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_SWRST);
960 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_SWRST);
961
962 while (1)
963 ;
964}
Shawn Guoc9142832012-04-26 10:05:15 +0800965
966void __init ep93xx_init_late(void)
967{
968 crunch_init();
969}