blob: 9092677f63eb739a529d137b5b1be891b11f53da [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 Sweetend52a26a2008-10-16 23:57:03 +010032#include <linux/i2c.h>
33#include <linux/i2c-gpio.h>
Mika Westerberg4fec9972010-05-11 15:34:54 +010034#include <linux/spi/spi.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000035
Russell Kinga09e64f2008-08-05 16:14:15 +010036#include <mach/hardware.h>
Ryan Mallonc6012182009-09-22 16:47:09 -070037#include <mach/fb.h>
Hartley Sweeten12f56c62009-10-28 21:04:46 +010038#include <mach/ep93xx_keypad.h>
Mika Westerberg4fec9972010-05-11 15:34:54 +010039#include <mach/ep93xx_spi.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000040
41#include <asm/mach/map.h>
42#include <asm/mach/time.h>
Lennert Buytenheke7736d42006-03-20 17:10:13 +000043
44#include <asm/hardware/vic.h>
45
46
47/*************************************************************************
48 * Static I/O mappings that are needed for all EP93xx platforms
49 *************************************************************************/
50static struct map_desc ep93xx_io_desc[] __initdata = {
51 {
52 .virtual = EP93XX_AHB_VIRT_BASE,
53 .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
54 .length = EP93XX_AHB_SIZE,
55 .type = MT_DEVICE,
56 }, {
57 .virtual = EP93XX_APB_VIRT_BASE,
58 .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE),
59 .length = EP93XX_APB_SIZE,
60 .type = MT_DEVICE,
61 },
62};
63
64void __init ep93xx_map_io(void)
65{
66 iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
67}
68
69
70/*************************************************************************
71 * Timer handling for EP93xx
72 *************************************************************************
73 * The ep93xx has four internal timers. Timers 1, 2 (both 16 bit) and
74 * 3 (32 bit) count down at 508 kHz, are self-reloading, and can generate
75 * an interrupt on underflow. Timer 4 (40 bit) counts down at 983.04 kHz,
76 * is free-running, and can't generate interrupts.
77 *
78 * The 508 kHz timers are ideal for use for the timer interrupt, as the
79 * most common values of HZ divide 508 kHz nicely. We pick one of the 16
80 * bit timers (timer 1) since we don't need more than 16 bits of reload
81 * value as long as HZ >= 8.
82 *
83 * The higher clock rate of timer 4 makes it a better choice than the
84 * other timers for use in gettimeoffset(), while the fact that it can't
85 * generate interrupts means we don't have to worry about not being able
86 * to use this timer for something else. We also use timer 4 for keeping
87 * track of lost jiffies.
88 */
Hartley Sweeten1587a372010-02-23 21:45:22 +010089#define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
90#define EP93XX_TIMER1_LOAD EP93XX_TIMER_REG(0x00)
91#define EP93XX_TIMER1_VALUE EP93XX_TIMER_REG(0x04)
92#define EP93XX_TIMER1_CONTROL EP93XX_TIMER_REG(0x08)
93#define EP93XX_TIMER123_CONTROL_ENABLE (1 << 7)
94#define EP93XX_TIMER123_CONTROL_MODE (1 << 6)
95#define EP93XX_TIMER123_CONTROL_CLKSEL (1 << 3)
96#define EP93XX_TIMER1_CLEAR EP93XX_TIMER_REG(0x0c)
97#define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
98#define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
99#define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
100#define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
101#define EP93XX_TIMER4_VALUE_LOW EP93XX_TIMER_REG(0x60)
102#define EP93XX_TIMER4_VALUE_HIGH EP93XX_TIMER_REG(0x64)
103#define EP93XX_TIMER4_VALUE_HIGH_ENABLE (1 << 8)
104#define EP93XX_TIMER3_LOAD EP93XX_TIMER_REG(0x80)
105#define EP93XX_TIMER3_VALUE EP93XX_TIMER_REG(0x84)
106#define EP93XX_TIMER3_CONTROL EP93XX_TIMER_REG(0x88)
107#define EP93XX_TIMER3_CLEAR EP93XX_TIMER_REG(0x8c)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000108
Hartley Sweeten1587a372010-02-23 21:45:22 +0100109#define EP93XX_TIMER123_CLOCK 508469
110#define EP93XX_TIMER4_CLOCK 983040
111
112#define TIMER1_RELOAD ((EP93XX_TIMER123_CLOCK / HZ) - 1)
Julia Lawallaf1057a2009-08-03 11:57:20 +0100113#define TIMER4_TICKS_PER_JIFFY DIV_ROUND_CLOSEST(CLOCK_TICK_RATE, HZ)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000114
Hartley Sweeten1587a372010-02-23 21:45:22 +0100115static unsigned int last_jiffy_time;
116
Hartley Sweetend5565f72009-04-14 21:38:07 +0100117static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000118{
Hartley Sweeten1587a372010-02-23 21:45:22 +0100119 /* Writing any value clears the timer interrupt */
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000120 __raw_writel(1, EP93XX_TIMER1_CLEAR);
Hartley Sweeten1587a372010-02-23 21:45:22 +0100121
122 /* Recover lost jiffies */
Lennert Buytenhekf869afa2006-06-22 10:30:53 +0100123 while ((signed long)
124 (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000125 >= TIMER4_TICKS_PER_JIFFY) {
126 last_jiffy_time += TIMER4_TICKS_PER_JIFFY;
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700127 timer_tick();
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000128 }
129
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000130 return IRQ_HANDLED;
131}
132
133static struct irqaction ep93xx_timer_irq = {
134 .name = "ep93xx timer",
Bernhard Walleb30faba2007-05-08 00:35:39 -0700135 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000136 .handler = ep93xx_timer_interrupt,
137};
138
139static void __init ep93xx_timer_init(void)
140{
Hartley Sweeten1587a372010-02-23 21:45:22 +0100141 u32 tmode = EP93XX_TIMER123_CONTROL_MODE |
142 EP93XX_TIMER123_CONTROL_CLKSEL;
143
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000144 /* Enable periodic HZ timer. */
Hartley Sweeten1587a372010-02-23 21:45:22 +0100145 __raw_writel(tmode, EP93XX_TIMER1_CONTROL);
146 __raw_writel(TIMER1_RELOAD, EP93XX_TIMER1_LOAD);
147 __raw_writel(tmode | EP93XX_TIMER123_CONTROL_ENABLE,
148 EP93XX_TIMER1_CONTROL);
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000149
150 /* Enable lost jiffy timer. */
Hartley Sweeten1587a372010-02-23 21:45:22 +0100151 __raw_writel(EP93XX_TIMER4_VALUE_HIGH_ENABLE,
152 EP93XX_TIMER4_VALUE_HIGH);
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000153
154 setup_irq(IRQ_EP93XX_TIMER1, &ep93xx_timer_irq);
155}
156
157static unsigned long ep93xx_gettimeoffset(void)
158{
159 int offset;
160
161 offset = __raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time;
162
163 /* Calculate (1000000 / 983040) * offset. */
164 return offset + (53 * offset / 3072);
165}
166
167struct sys_timer ep93xx_timer = {
168 .init = ep93xx_timer_init,
169 .offset = ep93xx_gettimeoffset,
170};
171
172
173/*************************************************************************
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000174 * EP93xx IRQ handling
175 *************************************************************************/
Hartley Sweetend056ab72010-02-23 21:41:17 +0100176extern void ep93xx_gpio_init_irq(void);
Lennert Buytenhekbd20ff52006-03-20 21:02:37 +0000177
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000178void __init ep93xx_init_irq(void)
179{
Hartley Sweeten53967302009-07-09 23:22:07 +0100180 vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
181 vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
Lennert Buytenhekbd20ff52006-03-20 21:02:37 +0000182
Hartley Sweetend056ab72010-02-23 21:41:17 +0100183 ep93xx_gpio_init_irq();
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000184}
185
186
187/*************************************************************************
Hartley Sweeten02239f02009-07-08 02:00:49 +0100188 * EP93xx System Controller Software Locked register handling
189 *************************************************************************/
190
191/*
192 * syscon_swlock prevents anything else from writing to the syscon
193 * block while a software locked register is being written.
194 */
195static DEFINE_SPINLOCK(syscon_swlock);
196
Ryan Mallonfbeeea52009-07-15 21:51:59 +0100197void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
Hartley Sweeten02239f02009-07-08 02:00:49 +0100198{
199 unsigned long flags;
200
201 spin_lock_irqsave(&syscon_swlock, flags);
202
203 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
204 __raw_writel(val, reg);
205
206 spin_unlock_irqrestore(&syscon_swlock, flags);
207}
208EXPORT_SYMBOL(ep93xx_syscon_swlocked_write);
209
210void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
211{
212 unsigned long flags;
213 unsigned int val;
214
215 spin_lock_irqsave(&syscon_swlock, flags);
216
217 val = __raw_readl(EP93XX_SYSCON_DEVCFG);
218 val |= set_bits;
219 val &= ~clear_bits;
220 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
221 __raw_writel(val, EP93XX_SYSCON_DEVCFG);
222
223 spin_unlock_irqrestore(&syscon_swlock, flags);
224}
225EXPORT_SYMBOL(ep93xx_devcfg_set_clear);
226
Mika Westerberg99e6a232010-03-27 12:05:14 +0100227/**
228 * ep93xx_chip_revision() - returns the EP93xx chip revision
229 *
230 * See <mach/platform.h> for more information.
231 */
232unsigned int ep93xx_chip_revision(void)
233{
234 unsigned int v;
235
236 v = __raw_readl(EP93XX_SYSCON_SYSCFG);
237 v &= EP93XX_SYSCON_SYSCFG_REV_MASK;
238 v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT;
239 return v;
240}
Hartley Sweeten02239f02009-07-08 02:00:49 +0100241
242/*************************************************************************
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000243 * EP93xx peripheral handling
244 *************************************************************************/
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100245#define EP93XX_UART_MCR_OFFSET (0x0100)
246
247static void ep93xx_uart_set_mctrl(struct amba_device *dev,
248 void __iomem *base, unsigned int mctrl)
249{
250 unsigned int mcr;
251
252 mcr = 0;
253 if (!(mctrl & TIOCM_RTS))
254 mcr |= 2;
255 if (!(mctrl & TIOCM_DTR))
256 mcr |= 1;
257
258 __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
259}
260
261static struct amba_pl010_data ep93xx_uart_data = {
262 .set_mctrl = ep93xx_uart_set_mctrl,
263};
264
265static struct amba_device uart1_device = {
266 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -0800267 .init_name = "apb:uart1",
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100268 .platform_data = &ep93xx_uart_data,
269 },
270 .res = {
271 .start = EP93XX_UART1_PHYS_BASE,
272 .end = EP93XX_UART1_PHYS_BASE + 0x0fff,
273 .flags = IORESOURCE_MEM,
274 },
275 .irq = { IRQ_EP93XX_UART1, NO_IRQ },
276 .periphid = 0x00041010,
277};
278
279static struct amba_device uart2_device = {
280 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -0800281 .init_name = "apb:uart2",
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100282 .platform_data = &ep93xx_uart_data,
283 },
284 .res = {
285 .start = EP93XX_UART2_PHYS_BASE,
286 .end = EP93XX_UART2_PHYS_BASE + 0x0fff,
287 .flags = IORESOURCE_MEM,
288 },
289 .irq = { IRQ_EP93XX_UART2, NO_IRQ },
290 .periphid = 0x00041010,
291};
292
293static struct amba_device uart3_device = {
294 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -0800295 .init_name = "apb:uart3",
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100296 .platform_data = &ep93xx_uart_data,
297 },
298 .res = {
299 .start = EP93XX_UART3_PHYS_BASE,
300 .end = EP93XX_UART3_PHYS_BASE + 0x0fff,
301 .flags = IORESOURCE_MEM,
302 },
303 .irq = { IRQ_EP93XX_UART3, NO_IRQ },
304 .periphid = 0x00041010,
305};
306
Lennert Buytenhek41658132006-04-02 16:17:34 +0100307
Hartley Sweeten38f7b002009-04-15 23:18:26 +0100308static struct resource ep93xx_rtc_resource[] = {
309 {
310 .start = EP93XX_RTC_PHYS_BASE,
311 .end = EP93XX_RTC_PHYS_BASE + 0x10c - 1,
312 .flags = IORESOURCE_MEM,
313 },
314};
315
Lennert Buytenhek41658132006-04-02 16:17:34 +0100316static struct platform_device ep93xx_rtc_device = {
Hartley Sweeten38f7b002009-04-15 23:18:26 +0100317 .name = "ep93xx-rtc",
318 .id = -1,
319 .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
320 .resource = ep93xx_rtc_resource,
Lennert Buytenhek41658132006-04-02 16:17:34 +0100321};
322
323
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100324static struct resource ep93xx_ohci_resources[] = {
325 [0] = {
326 .start = EP93XX_USB_PHYS_BASE,
327 .end = EP93XX_USB_PHYS_BASE + 0x0fff,
328 .flags = IORESOURCE_MEM,
329 },
330 [1] = {
331 .start = IRQ_EP93XX_USB,
332 .end = IRQ_EP93XX_USB,
333 .flags = IORESOURCE_IRQ,
334 },
335};
336
Matthias Kaehlcke63890a02008-10-29 14:14:52 -0700337
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100338static struct platform_device ep93xx_ohci_device = {
339 .name = "ep93xx-ohci",
340 .id = -1,
341 .dev = {
Matthias Kaehlcke63890a02008-10-29 14:14:52 -0700342 .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask,
343 .coherent_dma_mask = DMA_BIT_MASK(32),
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100344 },
345 .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
346 .resource = ep93xx_ohci_resources,
347};
348
Hartley Sweetenb370e082010-03-18 18:04:06 +0100349
350/*************************************************************************
351 * EP93xx ethernet peripheral handling
352 *************************************************************************/
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100353static struct ep93xx_eth_data ep93xx_eth_data;
354
355static struct resource ep93xx_eth_resource[] = {
356 {
357 .start = EP93XX_ETHERNET_PHYS_BASE,
358 .end = EP93XX_ETHERNET_PHYS_BASE + 0xffff,
359 .flags = IORESOURCE_MEM,
360 }, {
361 .start = IRQ_EP93XX_ETHERNET,
362 .end = IRQ_EP93XX_ETHERNET,
363 .flags = IORESOURCE_IRQ,
364 }
365};
366
367static struct platform_device ep93xx_eth_device = {
368 .name = "ep93xx-eth",
369 .id = -1,
370 .dev = {
371 .platform_data = &ep93xx_eth_data,
372 },
373 .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
374 .resource = ep93xx_eth_resource,
375};
376
Hartley Sweetenb370e082010-03-18 18:04:06 +0100377/**
378 * ep93xx_register_eth - Register the built-in ethernet platform device.
379 * @data: platform specific ethernet configuration (__initdata)
380 * @copy_addr: flag indicating that the MAC address should be copied
381 * from the IndAd registers (as programmed by the bootloader)
382 */
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100383void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
384{
Hartley Sweeten5b1c3c82009-07-13 19:50:10 +0100385 if (copy_addr)
386 memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
Hartley Sweetena0a08fd2008-10-04 20:01:49 +0100387
388 ep93xx_eth_data = *data;
389 platform_device_register(&ep93xx_eth_device);
390}
391
Hartley Sweeten6531a992009-10-08 00:45:00 +0100392
393/*************************************************************************
394 * EP93xx i2c peripheral handling
395 *************************************************************************/
396static struct i2c_gpio_platform_data ep93xx_i2c_data;
Hartley Sweetend52a26a2008-10-16 23:57:03 +0100397
398static struct platform_device ep93xx_i2c_device = {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100399 .name = "i2c-gpio",
400 .id = 0,
401 .dev = {
402 .platform_data = &ep93xx_i2c_data,
403 },
Hartley Sweetend52a26a2008-10-16 23:57:03 +0100404};
405
Hartley Sweetenb370e082010-03-18 18:04:06 +0100406/**
407 * ep93xx_register_i2c - Register the i2c platform device.
408 * @data: platform specific i2c-gpio configuration (__initdata)
409 * @devices: platform specific i2c bus device information (__initdata)
410 * @num: the number of devices on the i2c bus
411 */
Hartley Sweeten6531a992009-10-08 00:45:00 +0100412void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
413 struct i2c_board_info *devices, int num)
Hartley Sweetend52a26a2008-10-16 23:57:03 +0100414{
Hartley Sweeten6531a992009-10-08 00:45:00 +0100415 /*
416 * Set the EEPROM interface pin drive type control.
417 * Defines the driver type for the EECLK and EEDAT pins as either
418 * open drain, which will require an external pull-up, or a normal
419 * CMOS driver.
420 */
421 if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT)
Hartley Sweeten64d68822010-01-11 19:33:16 +0100422 pr_warning("sda != EEDAT, open drain has no effect\n");
Hartley Sweeten6531a992009-10-08 00:45:00 +0100423 if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
Hartley Sweeten64d68822010-01-11 19:33:16 +0100424 pr_warning("scl != EECLK, open drain has no effect\n");
Hartley Sweeten6531a992009-10-08 00:45:00 +0100425
426 __raw_writel((data->sda_is_open_drain << 1) |
427 (data->scl_is_open_drain << 0),
428 EP93XX_GPIO_EEDRIVE);
429
430 ep93xx_i2c_data = *data;
Hartley Sweetend52a26a2008-10-16 23:57:03 +0100431 i2c_register_board_info(0, devices, num);
432 platform_device_register(&ep93xx_i2c_device);
433}
434
Mika Westerberg4fec9972010-05-11 15:34:54 +0100435/*************************************************************************
436 * EP93xx SPI peripheral handling
437 *************************************************************************/
438static struct ep93xx_spi_info ep93xx_spi_master_data;
439
440static struct resource ep93xx_spi_resources[] = {
441 {
442 .start = EP93XX_SPI_PHYS_BASE,
443 .end = EP93XX_SPI_PHYS_BASE + 0x18 - 1,
444 .flags = IORESOURCE_MEM,
445 },
446 {
447 .start = IRQ_EP93XX_SSP,
448 .end = IRQ_EP93XX_SSP,
449 .flags = IORESOURCE_IRQ,
450 },
451};
452
453static struct platform_device ep93xx_spi_device = {
454 .name = "ep93xx-spi",
455 .id = 0,
456 .dev = {
457 .platform_data = &ep93xx_spi_master_data,
458 },
459 .num_resources = ARRAY_SIZE(ep93xx_spi_resources),
460 .resource = ep93xx_spi_resources,
461};
462
463/**
464 * ep93xx_register_spi() - registers spi platform device
465 * @info: ep93xx board specific spi master info (__initdata)
466 * @devices: SPI devices to register (__initdata)
467 * @num: number of SPI devices to register
468 *
469 * This function registers platform device for the EP93xx SPI controller and
470 * also makes sure that SPI pins are muxed so that I2S is not using those pins.
471 */
472void __init ep93xx_register_spi(struct ep93xx_spi_info *info,
473 struct spi_board_info *devices, int num)
474{
475 /*
476 * When SPI is used, we need to make sure that I2S is muxed off from
477 * SPI pins.
478 */
479 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
480
481 ep93xx_spi_master_data = *info;
482 spi_register_board_info(devices, num);
483 platform_device_register(&ep93xx_spi_device);
484}
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100485
486/*************************************************************************
487 * EP93xx LEDs
488 *************************************************************************/
489static struct gpio_led ep93xx_led_pins[] = {
490 {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100491 .name = "platform:grled",
492 .gpio = EP93XX_GPIO_LINE_GRLED,
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100493 }, {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100494 .name = "platform:rdled",
495 .gpio = EP93XX_GPIO_LINE_RDLED,
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100496 },
497};
498
499static struct gpio_led_platform_data ep93xx_led_data = {
500 .num_leds = ARRAY_SIZE(ep93xx_led_pins),
501 .leds = ep93xx_led_pins,
502};
503
504static struct platform_device ep93xx_leds = {
505 .name = "leds-gpio",
506 .id = -1,
507 .dev = {
508 .platform_data = &ep93xx_led_data,
509 },
510};
511
512
Hartley Sweetenef123792009-07-29 22:41:06 +0100513/*************************************************************************
514 * EP93xx pwm peripheral handling
515 *************************************************************************/
516static struct resource ep93xx_pwm0_resource[] = {
517 {
518 .start = EP93XX_PWM_PHYS_BASE,
519 .end = EP93XX_PWM_PHYS_BASE + 0x10 - 1,
520 .flags = IORESOURCE_MEM,
521 },
522};
523
524static struct platform_device ep93xx_pwm0_device = {
525 .name = "ep93xx-pwm",
526 .id = 0,
527 .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
528 .resource = ep93xx_pwm0_resource,
529};
530
531static struct resource ep93xx_pwm1_resource[] = {
532 {
533 .start = EP93XX_PWM_PHYS_BASE + 0x20,
534 .end = EP93XX_PWM_PHYS_BASE + 0x30 - 1,
535 .flags = IORESOURCE_MEM,
536 },
537};
538
539static struct platform_device ep93xx_pwm1_device = {
540 .name = "ep93xx-pwm",
541 .id = 1,
542 .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
543 .resource = ep93xx_pwm1_resource,
544};
545
546void __init ep93xx_register_pwm(int pwm0, int pwm1)
547{
548 if (pwm0)
549 platform_device_register(&ep93xx_pwm0_device);
550
551 /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
552 if (pwm1)
553 platform_device_register(&ep93xx_pwm1_device);
554}
555
556int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
557{
558 int err;
559
560 if (pdev->id == 0) {
561 err = 0;
562 } else if (pdev->id == 1) {
563 err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
564 dev_name(&pdev->dev));
565 if (err)
566 return err;
567 err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
568 if (err)
569 goto fail;
570
571 /* PWM 1 output on EGPIO[14] */
572 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
573 } else {
574 err = -ENODEV;
575 }
576
577 return err;
578
579fail:
580 gpio_free(EP93XX_GPIO_LINE_EGPIO14);
581 return err;
582}
583EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
584
585void ep93xx_pwm_release_gpio(struct platform_device *pdev)
586{
587 if (pdev->id == 1) {
588 gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
589 gpio_free(EP93XX_GPIO_LINE_EGPIO14);
590
591 /* EGPIO[14] used for GPIO */
592 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
593 }
594}
595EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
596
597
Ryan Mallonc6012182009-09-22 16:47:09 -0700598/*************************************************************************
599 * EP93xx video peripheral handling
600 *************************************************************************/
601static struct ep93xxfb_mach_info ep93xxfb_data;
602
603static struct resource ep93xx_fb_resource[] = {
604 {
605 .start = EP93XX_RASTER_PHYS_BASE,
606 .end = EP93XX_RASTER_PHYS_BASE + 0x800 - 1,
607 .flags = IORESOURCE_MEM,
608 },
609};
610
611static struct platform_device ep93xx_fb_device = {
612 .name = "ep93xx-fb",
613 .id = -1,
614 .dev = {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100615 .platform_data = &ep93xxfb_data,
Ryan Mallonc6012182009-09-22 16:47:09 -0700616 .coherent_dma_mask = DMA_BIT_MASK(32),
617 .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
618 },
619 .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
620 .resource = ep93xx_fb_resource,
621};
622
Hartley Sweetenb370e082010-03-18 18:04:06 +0100623/**
624 * ep93xx_register_fb - Register the framebuffer platform device.
625 * @data: platform specific framebuffer configuration (__initdata)
626 */
Ryan Mallonc6012182009-09-22 16:47:09 -0700627void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
628{
629 ep93xxfb_data = *data;
630 platform_device_register(&ep93xx_fb_device);
631}
632
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100633
634/*************************************************************************
635 * EP93xx matrix keypad peripheral handling
636 *************************************************************************/
Hartley Sweetenb370e082010-03-18 18:04:06 +0100637static struct ep93xx_keypad_platform_data ep93xx_keypad_data;
638
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100639static struct resource ep93xx_keypad_resource[] = {
640 {
641 .start = EP93XX_KEY_MATRIX_PHYS_BASE,
642 .end = EP93XX_KEY_MATRIX_PHYS_BASE + 0x0c - 1,
643 .flags = IORESOURCE_MEM,
644 }, {
645 .start = IRQ_EP93XX_KEY,
646 .end = IRQ_EP93XX_KEY,
647 .flags = IORESOURCE_IRQ,
648 },
649};
650
651static struct platform_device ep93xx_keypad_device = {
Hartley Sweetenb370e082010-03-18 18:04:06 +0100652 .name = "ep93xx-keypad",
653 .id = -1,
654 .dev = {
655 .platform_data = &ep93xx_keypad_data,
656 },
657 .num_resources = ARRAY_SIZE(ep93xx_keypad_resource),
658 .resource = ep93xx_keypad_resource,
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100659};
660
Hartley Sweetenb370e082010-03-18 18:04:06 +0100661/**
662 * ep93xx_register_keypad - Register the keypad platform device.
663 * @data: platform specific keypad configuration (__initdata)
664 */
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100665void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
666{
Hartley Sweetenb370e082010-03-18 18:04:06 +0100667 ep93xx_keypad_data = *data;
Hartley Sweeten12f56c62009-10-28 21:04:46 +0100668 platform_device_register(&ep93xx_keypad_device);
669}
670
671int ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
672{
673 int err;
674 int i;
675
676 for (i = 0; i < 8; i++) {
677 err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
678 if (err)
679 goto fail_gpio_c;
680 err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
681 if (err)
682 goto fail_gpio_d;
683 }
684
685 /* Enable the keypad controller; GPIO ports C and D used for keypad */
686 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
687 EP93XX_SYSCON_DEVCFG_GONK);
688
689 return 0;
690
691fail_gpio_d:
692 gpio_free(EP93XX_GPIO_LINE_C(i));
693fail_gpio_c:
694 for ( ; i >= 0; --i) {
695 gpio_free(EP93XX_GPIO_LINE_C(i));
696 gpio_free(EP93XX_GPIO_LINE_D(i));
697 }
698 return err;
699}
700EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
701
702void ep93xx_keypad_release_gpio(struct platform_device *pdev)
703{
704 int i;
705
706 for (i = 0; i < 8; i++) {
707 gpio_free(EP93XX_GPIO_LINE_C(i));
708 gpio_free(EP93XX_GPIO_LINE_D(i));
709 }
710
711 /* Disable the keypad controller; GPIO ports C and D used for GPIO */
712 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
713 EP93XX_SYSCON_DEVCFG_GONK);
714}
715EXPORT_SYMBOL(ep93xx_keypad_release_gpio);
716
717
Ryan Mallonb6850042008-04-16 02:56:35 +0100718extern void ep93xx_gpio_init(void);
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100719
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000720void __init ep93xx_init_devices(void)
721{
Hartley Sweeten02239f02009-07-08 02:00:49 +0100722 /* Disallow access to MaverickCrunch initially */
723 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100724
Ryan Mallonb6850042008-04-16 02:56:35 +0100725 ep93xx_gpio_init();
726
Lennert Buytenhekaee85fe2006-03-26 23:16:39 +0100727 amba_device_register(&uart1_device, &iomem_resource);
728 amba_device_register(&uart2_device, &iomem_resource);
729 amba_device_register(&uart3_device, &iomem_resource);
Lennert Buytenhek41658132006-04-02 16:17:34 +0100730
731 platform_device_register(&ep93xx_rtc_device);
Lennert Buytenhek1f64eb32006-06-24 10:33:03 +0100732 platform_device_register(&ep93xx_ohci_device);
Hartley Sweeten3aa7a9a2009-07-20 18:22:36 +0100733 platform_device_register(&ep93xx_leds);
Lennert Buytenheke7736d42006-03-20 17:10:13 +0000734}