Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 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> |
Herbert Valerio Riedel | 3c9a071 | 2007-11-26 18:49:08 +0100 | [diff] [blame] | 6 | * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org> |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 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 | |
Hartley Sweeten | 64d6882 | 2010-01-11 19:33:16 +0100 | [diff] [blame] | 17 | #define pr_fmt(fmt) "ep93xx " KBUILD_MODNAME ": " fmt |
| 18 | |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/init.h> |
Hartley Sweeten | 583ddaf | 2009-07-06 17:39:50 +0100 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
Matthias Kaehlcke | 63890a0 | 2008-10-29 14:14:52 -0700 | [diff] [blame] | 23 | #include <linux/dma-mapping.h> |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 24 | #include <linux/timex.h> |
Hartley Sweeten | 6bd4b38 | 2010-02-18 18:16:11 +0100 | [diff] [blame] | 25 | #include <linux/irq.h> |
Hartley Sweeten | 583ddaf | 2009-07-06 17:39:50 +0100 | [diff] [blame] | 26 | #include <linux/io.h> |
| 27 | #include <linux/gpio.h> |
Hartley Sweeten | 3aa7a9a | 2009-07-20 18:22:36 +0100 | [diff] [blame] | 28 | #include <linux/leds.h> |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 29 | #include <linux/termios.h> |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 30 | #include <linux/amba/bus.h> |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 31 | #include <linux/amba/serial.h> |
Hartley Sweeten | 16bcf78 | 2010-06-10 16:19:08 +0100 | [diff] [blame] | 32 | #include <linux/mtd/physmap.h> |
Hartley Sweeten | d52a26a | 2008-10-16 23:57:03 +0100 | [diff] [blame] | 33 | #include <linux/i2c.h> |
| 34 | #include <linux/i2c-gpio.h> |
Mika Westerberg | 4fec997 | 2010-05-11 15:34:54 +0100 | [diff] [blame] | 35 | #include <linux/spi/spi.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 36 | #include <linux/export.h> |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 37 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 38 | #include <mach/hardware.h> |
Ryan Mallon | c601218 | 2009-09-22 16:47:09 -0700 | [diff] [blame] | 39 | #include <mach/fb.h> |
Hartley Sweeten | 12f56c6 | 2009-10-28 21:04:46 +0100 | [diff] [blame] | 40 | #include <mach/ep93xx_keypad.h> |
Mika Westerberg | 4fec997 | 2010-05-11 15:34:54 +0100 | [diff] [blame] | 41 | #include <mach/ep93xx_spi.h> |
Linus Walleij | bd5f12a | 2011-09-22 08:07:00 +0100 | [diff] [blame] | 42 | #include <mach/gpio-ep93xx.h> |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 43 | |
| 44 | #include <asm/mach/map.h> |
| 45 | #include <asm/mach/time.h> |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 46 | |
| 47 | #include <asm/hardware/vic.h> |
| 48 | |
| 49 | |
| 50 | /************************************************************************* |
| 51 | * Static I/O mappings that are needed for all EP93xx platforms |
| 52 | *************************************************************************/ |
| 53 | static struct map_desc ep93xx_io_desc[] __initdata = { |
| 54 | { |
| 55 | .virtual = EP93XX_AHB_VIRT_BASE, |
| 56 | .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE), |
| 57 | .length = EP93XX_AHB_SIZE, |
| 58 | .type = MT_DEVICE, |
| 59 | }, { |
| 60 | .virtual = EP93XX_APB_VIRT_BASE, |
| 61 | .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE), |
| 62 | .length = EP93XX_APB_SIZE, |
| 63 | .type = MT_DEVICE, |
| 64 | }, |
| 65 | }; |
| 66 | |
| 67 | void __init ep93xx_map_io(void) |
| 68 | { |
| 69 | iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc)); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /************************************************************************* |
| 74 | * Timer handling for EP93xx |
| 75 | ************************************************************************* |
| 76 | * The ep93xx has four internal timers. Timers 1, 2 (both 16 bit) and |
| 77 | * 3 (32 bit) count down at 508 kHz, are self-reloading, and can generate |
| 78 | * an interrupt on underflow. Timer 4 (40 bit) counts down at 983.04 kHz, |
| 79 | * is free-running, and can't generate interrupts. |
| 80 | * |
| 81 | * The 508 kHz timers are ideal for use for the timer interrupt, as the |
| 82 | * most common values of HZ divide 508 kHz nicely. We pick one of the 16 |
| 83 | * bit timers (timer 1) since we don't need more than 16 bits of reload |
| 84 | * value as long as HZ >= 8. |
| 85 | * |
| 86 | * The higher clock rate of timer 4 makes it a better choice than the |
| 87 | * other timers for use in gettimeoffset(), while the fact that it can't |
| 88 | * generate interrupts means we don't have to worry about not being able |
| 89 | * to use this timer for something else. We also use timer 4 for keeping |
| 90 | * track of lost jiffies. |
| 91 | */ |
Hartley Sweeten | 1587a37 | 2010-02-23 21:45:22 +0100 | [diff] [blame] | 92 | #define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x)) |
| 93 | #define EP93XX_TIMER1_LOAD EP93XX_TIMER_REG(0x00) |
| 94 | #define EP93XX_TIMER1_VALUE EP93XX_TIMER_REG(0x04) |
| 95 | #define EP93XX_TIMER1_CONTROL EP93XX_TIMER_REG(0x08) |
| 96 | #define EP93XX_TIMER123_CONTROL_ENABLE (1 << 7) |
| 97 | #define EP93XX_TIMER123_CONTROL_MODE (1 << 6) |
| 98 | #define EP93XX_TIMER123_CONTROL_CLKSEL (1 << 3) |
| 99 | #define EP93XX_TIMER1_CLEAR EP93XX_TIMER_REG(0x0c) |
| 100 | #define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20) |
| 101 | #define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24) |
| 102 | #define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28) |
| 103 | #define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c) |
| 104 | #define EP93XX_TIMER4_VALUE_LOW EP93XX_TIMER_REG(0x60) |
| 105 | #define EP93XX_TIMER4_VALUE_HIGH EP93XX_TIMER_REG(0x64) |
| 106 | #define EP93XX_TIMER4_VALUE_HIGH_ENABLE (1 << 8) |
| 107 | #define EP93XX_TIMER3_LOAD EP93XX_TIMER_REG(0x80) |
| 108 | #define EP93XX_TIMER3_VALUE EP93XX_TIMER_REG(0x84) |
| 109 | #define EP93XX_TIMER3_CONTROL EP93XX_TIMER_REG(0x88) |
| 110 | #define EP93XX_TIMER3_CLEAR EP93XX_TIMER_REG(0x8c) |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 111 | |
Hartley Sweeten | 1587a37 | 2010-02-23 21:45:22 +0100 | [diff] [blame] | 112 | #define EP93XX_TIMER123_CLOCK 508469 |
| 113 | #define EP93XX_TIMER4_CLOCK 983040 |
| 114 | |
| 115 | #define TIMER1_RELOAD ((EP93XX_TIMER123_CLOCK / HZ) - 1) |
Julia Lawall | af1057a | 2009-08-03 11:57:20 +0100 | [diff] [blame] | 116 | #define TIMER4_TICKS_PER_JIFFY DIV_ROUND_CLOSEST(CLOCK_TICK_RATE, HZ) |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 117 | |
Hartley Sweeten | 1587a37 | 2010-02-23 21:45:22 +0100 | [diff] [blame] | 118 | static unsigned int last_jiffy_time; |
| 119 | |
Hartley Sweeten | d5565f7 | 2009-04-14 21:38:07 +0100 | [diff] [blame] | 120 | static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id) |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 121 | { |
Hartley Sweeten | 1587a37 | 2010-02-23 21:45:22 +0100 | [diff] [blame] | 122 | /* Writing any value clears the timer interrupt */ |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 123 | __raw_writel(1, EP93XX_TIMER1_CLEAR); |
Hartley Sweeten | 1587a37 | 2010-02-23 21:45:22 +0100 | [diff] [blame] | 124 | |
| 125 | /* Recover lost jiffies */ |
Lennert Buytenhek | f869afa | 2006-06-22 10:30:53 +0100 | [diff] [blame] | 126 | while ((signed long) |
| 127 | (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time) |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 128 | >= TIMER4_TICKS_PER_JIFFY) { |
| 129 | last_jiffy_time += TIMER4_TICKS_PER_JIFFY; |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 130 | timer_tick(); |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 133 | return IRQ_HANDLED; |
| 134 | } |
| 135 | |
| 136 | static struct irqaction ep93xx_timer_irq = { |
| 137 | .name = "ep93xx timer", |
Bernhard Walle | b30faba | 2007-05-08 00:35:39 -0700 | [diff] [blame] | 138 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 139 | .handler = ep93xx_timer_interrupt, |
| 140 | }; |
| 141 | |
| 142 | static void __init ep93xx_timer_init(void) |
| 143 | { |
Hartley Sweeten | 1587a37 | 2010-02-23 21:45:22 +0100 | [diff] [blame] | 144 | u32 tmode = EP93XX_TIMER123_CONTROL_MODE | |
| 145 | EP93XX_TIMER123_CONTROL_CLKSEL; |
| 146 | |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 147 | /* Enable periodic HZ timer. */ |
Hartley Sweeten | 1587a37 | 2010-02-23 21:45:22 +0100 | [diff] [blame] | 148 | __raw_writel(tmode, EP93XX_TIMER1_CONTROL); |
| 149 | __raw_writel(TIMER1_RELOAD, EP93XX_TIMER1_LOAD); |
| 150 | __raw_writel(tmode | EP93XX_TIMER123_CONTROL_ENABLE, |
| 151 | EP93XX_TIMER1_CONTROL); |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 152 | |
| 153 | /* Enable lost jiffy timer. */ |
Hartley Sweeten | 1587a37 | 2010-02-23 21:45:22 +0100 | [diff] [blame] | 154 | __raw_writel(EP93XX_TIMER4_VALUE_HIGH_ENABLE, |
| 155 | EP93XX_TIMER4_VALUE_HIGH); |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 156 | |
| 157 | setup_irq(IRQ_EP93XX_TIMER1, &ep93xx_timer_irq); |
| 158 | } |
| 159 | |
| 160 | static unsigned long ep93xx_gettimeoffset(void) |
| 161 | { |
| 162 | int offset; |
| 163 | |
| 164 | offset = __raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time; |
| 165 | |
| 166 | /* Calculate (1000000 / 983040) * offset. */ |
| 167 | return offset + (53 * offset / 3072); |
| 168 | } |
| 169 | |
| 170 | struct sys_timer ep93xx_timer = { |
| 171 | .init = ep93xx_timer_init, |
| 172 | .offset = ep93xx_gettimeoffset, |
| 173 | }; |
| 174 | |
| 175 | |
| 176 | /************************************************************************* |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 177 | * EP93xx IRQ handling |
| 178 | *************************************************************************/ |
| 179 | void __init ep93xx_init_irq(void) |
| 180 | { |
Hartley Sweeten | 5396730 | 2009-07-09 23:22:07 +0100 | [diff] [blame] | 181 | vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0); |
| 182 | vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0); |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
| 186 | /************************************************************************* |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 187 | * EP93xx System Controller Software Locked register handling |
| 188 | *************************************************************************/ |
| 189 | |
| 190 | /* |
| 191 | * syscon_swlock prevents anything else from writing to the syscon |
| 192 | * block while a software locked register is being written. |
| 193 | */ |
| 194 | static DEFINE_SPINLOCK(syscon_swlock); |
| 195 | |
Ryan Mallon | fbeeea5 | 2009-07-15 21:51:59 +0100 | [diff] [blame] | 196 | void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg) |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 197 | { |
| 198 | unsigned long flags; |
| 199 | |
| 200 | spin_lock_irqsave(&syscon_swlock, flags); |
| 201 | |
| 202 | __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK); |
| 203 | __raw_writel(val, reg); |
| 204 | |
| 205 | spin_unlock_irqrestore(&syscon_swlock, flags); |
| 206 | } |
| 207 | EXPORT_SYMBOL(ep93xx_syscon_swlocked_write); |
| 208 | |
| 209 | void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits) |
| 210 | { |
| 211 | unsigned long flags; |
| 212 | unsigned int val; |
| 213 | |
| 214 | spin_lock_irqsave(&syscon_swlock, flags); |
| 215 | |
| 216 | val = __raw_readl(EP93XX_SYSCON_DEVCFG); |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 217 | val &= ~clear_bits; |
Hartley Sweeten | a0fb007 | 2010-06-14 16:54:16 +0100 | [diff] [blame] | 218 | val |= set_bits; |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 219 | __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK); |
| 220 | __raw_writel(val, EP93XX_SYSCON_DEVCFG); |
| 221 | |
| 222 | spin_unlock_irqrestore(&syscon_swlock, flags); |
| 223 | } |
| 224 | EXPORT_SYMBOL(ep93xx_devcfg_set_clear); |
| 225 | |
Mika Westerberg | 99e6a23 | 2010-03-27 12:05:14 +0100 | [diff] [blame] | 226 | /** |
| 227 | * ep93xx_chip_revision() - returns the EP93xx chip revision |
| 228 | * |
| 229 | * See <mach/platform.h> for more information. |
| 230 | */ |
| 231 | unsigned int ep93xx_chip_revision(void) |
| 232 | { |
| 233 | unsigned int v; |
| 234 | |
| 235 | v = __raw_readl(EP93XX_SYSCON_SYSCFG); |
| 236 | v &= EP93XX_SYSCON_SYSCFG_REV_MASK; |
| 237 | v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT; |
| 238 | return v; |
| 239 | } |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 240 | |
| 241 | /************************************************************************* |
H Hartley Sweeten | 1e4c884 | 2011-06-08 14:35:33 -0700 | [diff] [blame] | 242 | * EP93xx GPIO |
| 243 | *************************************************************************/ |
| 244 | static struct resource ep93xx_gpio_resource[] = { |
| 245 | { |
| 246 | .start = EP93XX_GPIO_PHYS_BASE, |
| 247 | .end = EP93XX_GPIO_PHYS_BASE + 0xcc - 1, |
| 248 | .flags = IORESOURCE_MEM, |
| 249 | }, |
| 250 | }; |
| 251 | |
| 252 | static struct platform_device ep93xx_gpio_device = { |
| 253 | .name = "gpio-ep93xx", |
| 254 | .id = -1, |
| 255 | .num_resources = ARRAY_SIZE(ep93xx_gpio_resource), |
| 256 | .resource = ep93xx_gpio_resource, |
| 257 | }; |
| 258 | |
| 259 | /************************************************************************* |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 260 | * EP93xx peripheral handling |
| 261 | *************************************************************************/ |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 262 | #define EP93XX_UART_MCR_OFFSET (0x0100) |
| 263 | |
| 264 | static void ep93xx_uart_set_mctrl(struct amba_device *dev, |
| 265 | void __iomem *base, unsigned int mctrl) |
| 266 | { |
| 267 | unsigned int mcr; |
| 268 | |
| 269 | mcr = 0; |
Petr Å tetiar | 186dcaa | 2011-06-17 11:10:04 +0100 | [diff] [blame] | 270 | if (mctrl & TIOCM_RTS) |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 271 | mcr |= 2; |
Petr Å tetiar | 186dcaa | 2011-06-17 11:10:04 +0100 | [diff] [blame] | 272 | if (mctrl & TIOCM_DTR) |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 273 | mcr |= 1; |
| 274 | |
| 275 | __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET); |
| 276 | } |
| 277 | |
| 278 | static struct amba_pl010_data ep93xx_uart_data = { |
| 279 | .set_mctrl = ep93xx_uart_set_mctrl, |
| 280 | }; |
| 281 | |
Russell King | 0b26051 | 2011-12-18 15:16:40 +0000 | [diff] [blame] | 282 | static AMBA_APB_DEVICE(uart1, "apb:uart1", 0x00041010, EP93XX_UART1_PHYS_BASE, |
| 283 | { IRQ_EP93XX_UART1 }, &ep93xx_uart_data); |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 284 | |
Russell King | 0b26051 | 2011-12-18 15:16:40 +0000 | [diff] [blame] | 285 | static AMBA_APB_DEVICE(uart2, "apb:uart2", 0x00041010, EP93XX_UART2_PHYS_BASE, |
| 286 | { IRQ_EP93XX_UART2 }, &ep93xx_uart_data); |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 287 | |
Russell King | 0b26051 | 2011-12-18 15:16:40 +0000 | [diff] [blame] | 288 | static AMBA_APB_DEVICE(uart3, "apb:uart3", 0x00041010, EP93XX_UART3_PHYS_BASE, |
| 289 | { IRQ_EP93XX_UART3 }, &ep93xx_uart_data); |
Lennert Buytenhek | 4165813 | 2006-04-02 16:17:34 +0100 | [diff] [blame] | 290 | |
Hartley Sweeten | 38f7b00 | 2009-04-15 23:18:26 +0100 | [diff] [blame] | 291 | static struct resource ep93xx_rtc_resource[] = { |
| 292 | { |
| 293 | .start = EP93XX_RTC_PHYS_BASE, |
| 294 | .end = EP93XX_RTC_PHYS_BASE + 0x10c - 1, |
| 295 | .flags = IORESOURCE_MEM, |
| 296 | }, |
| 297 | }; |
| 298 | |
Lennert Buytenhek | 4165813 | 2006-04-02 16:17:34 +0100 | [diff] [blame] | 299 | static struct platform_device ep93xx_rtc_device = { |
Hartley Sweeten | 38f7b00 | 2009-04-15 23:18:26 +0100 | [diff] [blame] | 300 | .name = "ep93xx-rtc", |
| 301 | .id = -1, |
| 302 | .num_resources = ARRAY_SIZE(ep93xx_rtc_resource), |
| 303 | .resource = ep93xx_rtc_resource, |
Lennert Buytenhek | 4165813 | 2006-04-02 16:17:34 +0100 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | |
Lennert Buytenhek | 1f64eb3 | 2006-06-24 10:33:03 +0100 | [diff] [blame] | 307 | static struct resource ep93xx_ohci_resources[] = { |
| 308 | [0] = { |
| 309 | .start = EP93XX_USB_PHYS_BASE, |
| 310 | .end = EP93XX_USB_PHYS_BASE + 0x0fff, |
| 311 | .flags = IORESOURCE_MEM, |
| 312 | }, |
| 313 | [1] = { |
| 314 | .start = IRQ_EP93XX_USB, |
| 315 | .end = IRQ_EP93XX_USB, |
| 316 | .flags = IORESOURCE_IRQ, |
| 317 | }, |
| 318 | }; |
| 319 | |
Matthias Kaehlcke | 63890a0 | 2008-10-29 14:14:52 -0700 | [diff] [blame] | 320 | |
Lennert Buytenhek | 1f64eb3 | 2006-06-24 10:33:03 +0100 | [diff] [blame] | 321 | static struct platform_device ep93xx_ohci_device = { |
| 322 | .name = "ep93xx-ohci", |
| 323 | .id = -1, |
| 324 | .dev = { |
Matthias Kaehlcke | 63890a0 | 2008-10-29 14:14:52 -0700 | [diff] [blame] | 325 | .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask, |
| 326 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Lennert Buytenhek | 1f64eb3 | 2006-06-24 10:33:03 +0100 | [diff] [blame] | 327 | }, |
| 328 | .num_resources = ARRAY_SIZE(ep93xx_ohci_resources), |
| 329 | .resource = ep93xx_ohci_resources, |
| 330 | }; |
| 331 | |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 332 | |
| 333 | /************************************************************************* |
Hartley Sweeten | 16bcf78 | 2010-06-10 16:19:08 +0100 | [diff] [blame] | 334 | * EP93xx physmap'ed flash |
| 335 | *************************************************************************/ |
| 336 | static struct physmap_flash_data ep93xx_flash_data; |
| 337 | |
| 338 | static struct resource ep93xx_flash_resource = { |
| 339 | .flags = IORESOURCE_MEM, |
| 340 | }; |
| 341 | |
| 342 | static struct platform_device ep93xx_flash = { |
| 343 | .name = "physmap-flash", |
| 344 | .id = 0, |
| 345 | .dev = { |
| 346 | .platform_data = &ep93xx_flash_data, |
| 347 | }, |
| 348 | .num_resources = 1, |
| 349 | .resource = &ep93xx_flash_resource, |
| 350 | }; |
| 351 | |
| 352 | /** |
| 353 | * ep93xx_register_flash() - Register the external flash device. |
| 354 | * @width: bank width in octets |
| 355 | * @start: resource start address |
| 356 | * @size: resource size |
| 357 | */ |
| 358 | void __init ep93xx_register_flash(unsigned int width, |
| 359 | resource_size_t start, resource_size_t size) |
| 360 | { |
| 361 | ep93xx_flash_data.width = width; |
| 362 | |
| 363 | ep93xx_flash_resource.start = start; |
| 364 | ep93xx_flash_resource.end = start + size - 1; |
| 365 | |
| 366 | platform_device_register(&ep93xx_flash); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | /************************************************************************* |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 371 | * EP93xx ethernet peripheral handling |
| 372 | *************************************************************************/ |
Hartley Sweeten | a0a08fd | 2008-10-04 20:01:49 +0100 | [diff] [blame] | 373 | static struct ep93xx_eth_data ep93xx_eth_data; |
| 374 | |
| 375 | static struct resource ep93xx_eth_resource[] = { |
| 376 | { |
| 377 | .start = EP93XX_ETHERNET_PHYS_BASE, |
| 378 | .end = EP93XX_ETHERNET_PHYS_BASE + 0xffff, |
| 379 | .flags = IORESOURCE_MEM, |
| 380 | }, { |
| 381 | .start = IRQ_EP93XX_ETHERNET, |
| 382 | .end = IRQ_EP93XX_ETHERNET, |
| 383 | .flags = IORESOURCE_IRQ, |
| 384 | } |
| 385 | }; |
| 386 | |
Mika Westerberg | fa70cf4 | 2011-06-11 08:39:54 +0000 | [diff] [blame] | 387 | static u64 ep93xx_eth_dma_mask = DMA_BIT_MASK(32); |
| 388 | |
Hartley Sweeten | a0a08fd | 2008-10-04 20:01:49 +0100 | [diff] [blame] | 389 | static struct platform_device ep93xx_eth_device = { |
| 390 | .name = "ep93xx-eth", |
| 391 | .id = -1, |
| 392 | .dev = { |
Mika Westerberg | fa70cf4 | 2011-06-11 08:39:54 +0000 | [diff] [blame] | 393 | .platform_data = &ep93xx_eth_data, |
| 394 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 395 | .dma_mask = &ep93xx_eth_dma_mask, |
Hartley Sweeten | a0a08fd | 2008-10-04 20:01:49 +0100 | [diff] [blame] | 396 | }, |
| 397 | .num_resources = ARRAY_SIZE(ep93xx_eth_resource), |
| 398 | .resource = ep93xx_eth_resource, |
| 399 | }; |
| 400 | |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 401 | /** |
| 402 | * ep93xx_register_eth - Register the built-in ethernet platform device. |
| 403 | * @data: platform specific ethernet configuration (__initdata) |
| 404 | * @copy_addr: flag indicating that the MAC address should be copied |
| 405 | * from the IndAd registers (as programmed by the bootloader) |
| 406 | */ |
Hartley Sweeten | a0a08fd | 2008-10-04 20:01:49 +0100 | [diff] [blame] | 407 | void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr) |
| 408 | { |
Hartley Sweeten | 5b1c3c8 | 2009-07-13 19:50:10 +0100 | [diff] [blame] | 409 | if (copy_addr) |
| 410 | memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6); |
Hartley Sweeten | a0a08fd | 2008-10-04 20:01:49 +0100 | [diff] [blame] | 411 | |
| 412 | ep93xx_eth_data = *data; |
| 413 | platform_device_register(&ep93xx_eth_device); |
| 414 | } |
| 415 | |
Hartley Sweeten | 6531a99 | 2009-10-08 00:45:00 +0100 | [diff] [blame] | 416 | |
| 417 | /************************************************************************* |
| 418 | * EP93xx i2c peripheral handling |
| 419 | *************************************************************************/ |
| 420 | static struct i2c_gpio_platform_data ep93xx_i2c_data; |
Hartley Sweeten | d52a26a | 2008-10-16 23:57:03 +0100 | [diff] [blame] | 421 | |
| 422 | static struct platform_device ep93xx_i2c_device = { |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 423 | .name = "i2c-gpio", |
| 424 | .id = 0, |
| 425 | .dev = { |
| 426 | .platform_data = &ep93xx_i2c_data, |
| 427 | }, |
Hartley Sweeten | d52a26a | 2008-10-16 23:57:03 +0100 | [diff] [blame] | 428 | }; |
| 429 | |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 430 | /** |
| 431 | * ep93xx_register_i2c - Register the i2c platform device. |
| 432 | * @data: platform specific i2c-gpio configuration (__initdata) |
| 433 | * @devices: platform specific i2c bus device information (__initdata) |
| 434 | * @num: the number of devices on the i2c bus |
| 435 | */ |
Hartley Sweeten | 6531a99 | 2009-10-08 00:45:00 +0100 | [diff] [blame] | 436 | void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data, |
| 437 | struct i2c_board_info *devices, int num) |
Hartley Sweeten | d52a26a | 2008-10-16 23:57:03 +0100 | [diff] [blame] | 438 | { |
Hartley Sweeten | 6531a99 | 2009-10-08 00:45:00 +0100 | [diff] [blame] | 439 | /* |
| 440 | * Set the EEPROM interface pin drive type control. |
| 441 | * Defines the driver type for the EECLK and EEDAT pins as either |
| 442 | * open drain, which will require an external pull-up, or a normal |
| 443 | * CMOS driver. |
| 444 | */ |
| 445 | if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT) |
Hartley Sweeten | 64d6882 | 2010-01-11 19:33:16 +0100 | [diff] [blame] | 446 | pr_warning("sda != EEDAT, open drain has no effect\n"); |
Hartley Sweeten | 6531a99 | 2009-10-08 00:45:00 +0100 | [diff] [blame] | 447 | if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK) |
Hartley Sweeten | 64d6882 | 2010-01-11 19:33:16 +0100 | [diff] [blame] | 448 | pr_warning("scl != EECLK, open drain has no effect\n"); |
Hartley Sweeten | 6531a99 | 2009-10-08 00:45:00 +0100 | [diff] [blame] | 449 | |
| 450 | __raw_writel((data->sda_is_open_drain << 1) | |
| 451 | (data->scl_is_open_drain << 0), |
| 452 | EP93XX_GPIO_EEDRIVE); |
| 453 | |
| 454 | ep93xx_i2c_data = *data; |
Hartley Sweeten | d52a26a | 2008-10-16 23:57:03 +0100 | [diff] [blame] | 455 | i2c_register_board_info(0, devices, num); |
| 456 | platform_device_register(&ep93xx_i2c_device); |
| 457 | } |
| 458 | |
Mika Westerberg | 4fec997 | 2010-05-11 15:34:54 +0100 | [diff] [blame] | 459 | /************************************************************************* |
| 460 | * EP93xx SPI peripheral handling |
| 461 | *************************************************************************/ |
| 462 | static struct ep93xx_spi_info ep93xx_spi_master_data; |
| 463 | |
| 464 | static struct resource ep93xx_spi_resources[] = { |
| 465 | { |
| 466 | .start = EP93XX_SPI_PHYS_BASE, |
| 467 | .end = EP93XX_SPI_PHYS_BASE + 0x18 - 1, |
| 468 | .flags = IORESOURCE_MEM, |
| 469 | }, |
| 470 | { |
| 471 | .start = IRQ_EP93XX_SSP, |
| 472 | .end = IRQ_EP93XX_SSP, |
| 473 | .flags = IORESOURCE_IRQ, |
| 474 | }, |
| 475 | }; |
| 476 | |
Mika Westerberg | 626a96d | 2011-05-29 13:10:06 +0300 | [diff] [blame] | 477 | static u64 ep93xx_spi_dma_mask = DMA_BIT_MASK(32); |
| 478 | |
Mika Westerberg | 4fec997 | 2010-05-11 15:34:54 +0100 | [diff] [blame] | 479 | static struct platform_device ep93xx_spi_device = { |
| 480 | .name = "ep93xx-spi", |
| 481 | .id = 0, |
| 482 | .dev = { |
Mika Westerberg | 626a96d | 2011-05-29 13:10:06 +0300 | [diff] [blame] | 483 | .platform_data = &ep93xx_spi_master_data, |
| 484 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 485 | .dma_mask = &ep93xx_spi_dma_mask, |
Mika Westerberg | 4fec997 | 2010-05-11 15:34:54 +0100 | [diff] [blame] | 486 | }, |
| 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 | */ |
| 500 | void __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 Sweeten | 3aa7a9a | 2009-07-20 18:22:36 +0100 | [diff] [blame] | 513 | |
| 514 | /************************************************************************* |
| 515 | * EP93xx LEDs |
| 516 | *************************************************************************/ |
| 517 | static struct gpio_led ep93xx_led_pins[] = { |
| 518 | { |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 519 | .name = "platform:grled", |
| 520 | .gpio = EP93XX_GPIO_LINE_GRLED, |
Hartley Sweeten | 3aa7a9a | 2009-07-20 18:22:36 +0100 | [diff] [blame] | 521 | }, { |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 522 | .name = "platform:rdled", |
| 523 | .gpio = EP93XX_GPIO_LINE_RDLED, |
Hartley Sweeten | 3aa7a9a | 2009-07-20 18:22:36 +0100 | [diff] [blame] | 524 | }, |
| 525 | }; |
| 526 | |
| 527 | static struct gpio_led_platform_data ep93xx_led_data = { |
| 528 | .num_leds = ARRAY_SIZE(ep93xx_led_pins), |
| 529 | .leds = ep93xx_led_pins, |
| 530 | }; |
| 531 | |
| 532 | static struct platform_device ep93xx_leds = { |
| 533 | .name = "leds-gpio", |
| 534 | .id = -1, |
| 535 | .dev = { |
| 536 | .platform_data = &ep93xx_led_data, |
| 537 | }, |
| 538 | }; |
| 539 | |
| 540 | |
Hartley Sweeten | ef12379 | 2009-07-29 22:41:06 +0100 | [diff] [blame] | 541 | /************************************************************************* |
| 542 | * EP93xx pwm peripheral handling |
| 543 | *************************************************************************/ |
| 544 | static struct resource ep93xx_pwm0_resource[] = { |
| 545 | { |
| 546 | .start = EP93XX_PWM_PHYS_BASE, |
| 547 | .end = EP93XX_PWM_PHYS_BASE + 0x10 - 1, |
| 548 | .flags = IORESOURCE_MEM, |
| 549 | }, |
| 550 | }; |
| 551 | |
| 552 | static struct platform_device ep93xx_pwm0_device = { |
| 553 | .name = "ep93xx-pwm", |
| 554 | .id = 0, |
| 555 | .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource), |
| 556 | .resource = ep93xx_pwm0_resource, |
| 557 | }; |
| 558 | |
| 559 | static struct resource ep93xx_pwm1_resource[] = { |
| 560 | { |
| 561 | .start = EP93XX_PWM_PHYS_BASE + 0x20, |
| 562 | .end = EP93XX_PWM_PHYS_BASE + 0x30 - 1, |
| 563 | .flags = IORESOURCE_MEM, |
| 564 | }, |
| 565 | }; |
| 566 | |
| 567 | static struct platform_device ep93xx_pwm1_device = { |
| 568 | .name = "ep93xx-pwm", |
| 569 | .id = 1, |
| 570 | .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource), |
| 571 | .resource = ep93xx_pwm1_resource, |
| 572 | }; |
| 573 | |
| 574 | void __init ep93xx_register_pwm(int pwm0, int pwm1) |
| 575 | { |
| 576 | if (pwm0) |
| 577 | platform_device_register(&ep93xx_pwm0_device); |
| 578 | |
| 579 | /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */ |
| 580 | if (pwm1) |
| 581 | platform_device_register(&ep93xx_pwm1_device); |
| 582 | } |
| 583 | |
| 584 | int ep93xx_pwm_acquire_gpio(struct platform_device *pdev) |
| 585 | { |
| 586 | int err; |
| 587 | |
| 588 | if (pdev->id == 0) { |
| 589 | err = 0; |
| 590 | } else if (pdev->id == 1) { |
| 591 | err = gpio_request(EP93XX_GPIO_LINE_EGPIO14, |
| 592 | dev_name(&pdev->dev)); |
| 593 | if (err) |
| 594 | return err; |
| 595 | err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0); |
| 596 | if (err) |
| 597 | goto fail; |
| 598 | |
| 599 | /* PWM 1 output on EGPIO[14] */ |
| 600 | ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG); |
| 601 | } else { |
| 602 | err = -ENODEV; |
| 603 | } |
| 604 | |
| 605 | return err; |
| 606 | |
| 607 | fail: |
| 608 | gpio_free(EP93XX_GPIO_LINE_EGPIO14); |
| 609 | return err; |
| 610 | } |
| 611 | EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio); |
| 612 | |
| 613 | void ep93xx_pwm_release_gpio(struct platform_device *pdev) |
| 614 | { |
| 615 | if (pdev->id == 1) { |
| 616 | gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14); |
| 617 | gpio_free(EP93XX_GPIO_LINE_EGPIO14); |
| 618 | |
| 619 | /* EGPIO[14] used for GPIO */ |
| 620 | ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG); |
| 621 | } |
| 622 | } |
| 623 | EXPORT_SYMBOL(ep93xx_pwm_release_gpio); |
| 624 | |
| 625 | |
Ryan Mallon | c601218 | 2009-09-22 16:47:09 -0700 | [diff] [blame] | 626 | /************************************************************************* |
| 627 | * EP93xx video peripheral handling |
| 628 | *************************************************************************/ |
| 629 | static struct ep93xxfb_mach_info ep93xxfb_data; |
| 630 | |
| 631 | static struct resource ep93xx_fb_resource[] = { |
| 632 | { |
| 633 | .start = EP93XX_RASTER_PHYS_BASE, |
| 634 | .end = EP93XX_RASTER_PHYS_BASE + 0x800 - 1, |
| 635 | .flags = IORESOURCE_MEM, |
| 636 | }, |
| 637 | }; |
| 638 | |
| 639 | static struct platform_device ep93xx_fb_device = { |
| 640 | .name = "ep93xx-fb", |
| 641 | .id = -1, |
| 642 | .dev = { |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 643 | .platform_data = &ep93xxfb_data, |
Ryan Mallon | c601218 | 2009-09-22 16:47:09 -0700 | [diff] [blame] | 644 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 645 | .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask, |
| 646 | }, |
| 647 | .num_resources = ARRAY_SIZE(ep93xx_fb_resource), |
| 648 | .resource = ep93xx_fb_resource, |
| 649 | }; |
| 650 | |
Hartley Sweeten | 6ea4b74 | 2010-06-09 21:15:12 +0100 | [diff] [blame] | 651 | static struct platform_device ep93xx_bl_device = { |
| 652 | .name = "ep93xx-bl", |
| 653 | .id = -1, |
| 654 | }; |
| 655 | |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 656 | /** |
| 657 | * ep93xx_register_fb - Register the framebuffer platform device. |
| 658 | * @data: platform specific framebuffer configuration (__initdata) |
| 659 | */ |
Ryan Mallon | c601218 | 2009-09-22 16:47:09 -0700 | [diff] [blame] | 660 | void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data) |
| 661 | { |
| 662 | ep93xxfb_data = *data; |
| 663 | platform_device_register(&ep93xx_fb_device); |
Hartley Sweeten | 6ea4b74 | 2010-06-09 21:15:12 +0100 | [diff] [blame] | 664 | platform_device_register(&ep93xx_bl_device); |
Ryan Mallon | c601218 | 2009-09-22 16:47:09 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Hartley Sweeten | 12f56c6 | 2009-10-28 21:04:46 +0100 | [diff] [blame] | 667 | |
| 668 | /************************************************************************* |
| 669 | * EP93xx matrix keypad peripheral handling |
| 670 | *************************************************************************/ |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 671 | static struct ep93xx_keypad_platform_data ep93xx_keypad_data; |
| 672 | |
Hartley Sweeten | 12f56c6 | 2009-10-28 21:04:46 +0100 | [diff] [blame] | 673 | static struct resource ep93xx_keypad_resource[] = { |
| 674 | { |
| 675 | .start = EP93XX_KEY_MATRIX_PHYS_BASE, |
| 676 | .end = EP93XX_KEY_MATRIX_PHYS_BASE + 0x0c - 1, |
| 677 | .flags = IORESOURCE_MEM, |
| 678 | }, { |
| 679 | .start = IRQ_EP93XX_KEY, |
| 680 | .end = IRQ_EP93XX_KEY, |
| 681 | .flags = IORESOURCE_IRQ, |
| 682 | }, |
| 683 | }; |
| 684 | |
| 685 | static struct platform_device ep93xx_keypad_device = { |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 686 | .name = "ep93xx-keypad", |
| 687 | .id = -1, |
| 688 | .dev = { |
| 689 | .platform_data = &ep93xx_keypad_data, |
| 690 | }, |
| 691 | .num_resources = ARRAY_SIZE(ep93xx_keypad_resource), |
| 692 | .resource = ep93xx_keypad_resource, |
Hartley Sweeten | 12f56c6 | 2009-10-28 21:04:46 +0100 | [diff] [blame] | 693 | }; |
| 694 | |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 695 | /** |
| 696 | * ep93xx_register_keypad - Register the keypad platform device. |
| 697 | * @data: platform specific keypad configuration (__initdata) |
| 698 | */ |
Hartley Sweeten | 12f56c6 | 2009-10-28 21:04:46 +0100 | [diff] [blame] | 699 | void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data) |
| 700 | { |
Hartley Sweeten | b370e08 | 2010-03-18 18:04:06 +0100 | [diff] [blame] | 701 | ep93xx_keypad_data = *data; |
Hartley Sweeten | 12f56c6 | 2009-10-28 21:04:46 +0100 | [diff] [blame] | 702 | platform_device_register(&ep93xx_keypad_device); |
| 703 | } |
| 704 | |
| 705 | int ep93xx_keypad_acquire_gpio(struct platform_device *pdev) |
| 706 | { |
| 707 | int err; |
| 708 | int i; |
| 709 | |
| 710 | for (i = 0; i < 8; i++) { |
| 711 | err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev)); |
| 712 | if (err) |
| 713 | goto fail_gpio_c; |
| 714 | err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev)); |
| 715 | if (err) |
| 716 | goto fail_gpio_d; |
| 717 | } |
| 718 | |
| 719 | /* Enable the keypad controller; GPIO ports C and D used for keypad */ |
| 720 | ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS | |
| 721 | EP93XX_SYSCON_DEVCFG_GONK); |
| 722 | |
| 723 | return 0; |
| 724 | |
| 725 | fail_gpio_d: |
| 726 | gpio_free(EP93XX_GPIO_LINE_C(i)); |
| 727 | fail_gpio_c: |
| 728 | for ( ; i >= 0; --i) { |
| 729 | gpio_free(EP93XX_GPIO_LINE_C(i)); |
| 730 | gpio_free(EP93XX_GPIO_LINE_D(i)); |
| 731 | } |
| 732 | return err; |
| 733 | } |
| 734 | EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio); |
| 735 | |
| 736 | void ep93xx_keypad_release_gpio(struct platform_device *pdev) |
| 737 | { |
| 738 | int i; |
| 739 | |
| 740 | for (i = 0; i < 8; i++) { |
| 741 | gpio_free(EP93XX_GPIO_LINE_C(i)); |
| 742 | gpio_free(EP93XX_GPIO_LINE_D(i)); |
| 743 | } |
| 744 | |
| 745 | /* Disable the keypad controller; GPIO ports C and D used for GPIO */ |
| 746 | ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS | |
| 747 | EP93XX_SYSCON_DEVCFG_GONK); |
| 748 | } |
| 749 | EXPORT_SYMBOL(ep93xx_keypad_release_gpio); |
| 750 | |
Ryan Mallon | ed67ea8 | 2010-06-08 22:01:10 +1200 | [diff] [blame] | 751 | /************************************************************************* |
| 752 | * EP93xx I2S audio peripheral handling |
| 753 | *************************************************************************/ |
| 754 | static struct resource ep93xx_i2s_resource[] = { |
| 755 | { |
| 756 | .start = EP93XX_I2S_PHYS_BASE, |
| 757 | .end = EP93XX_I2S_PHYS_BASE + 0x100 - 1, |
| 758 | .flags = IORESOURCE_MEM, |
| 759 | }, |
| 760 | }; |
| 761 | |
| 762 | static struct platform_device ep93xx_i2s_device = { |
| 763 | .name = "ep93xx-i2s", |
| 764 | .id = -1, |
| 765 | .num_resources = ARRAY_SIZE(ep93xx_i2s_resource), |
| 766 | .resource = ep93xx_i2s_resource, |
| 767 | }; |
| 768 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 769 | static struct platform_device ep93xx_pcm_device = { |
| 770 | .name = "ep93xx-pcm-audio", |
| 771 | .id = -1, |
| 772 | }; |
| 773 | |
Ryan Mallon | ed67ea8 | 2010-06-08 22:01:10 +1200 | [diff] [blame] | 774 | void __init ep93xx_register_i2s(void) |
| 775 | { |
| 776 | platform_device_register(&ep93xx_i2s_device); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 777 | platform_device_register(&ep93xx_pcm_device); |
Ryan Mallon | ed67ea8 | 2010-06-08 22:01:10 +1200 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | #define EP93XX_SYSCON_DEVCFG_I2S_MASK (EP93XX_SYSCON_DEVCFG_I2SONSSP | \ |
| 781 | EP93XX_SYSCON_DEVCFG_I2SONAC97) |
| 782 | |
| 783 | #define EP93XX_I2SCLKDIV_MASK (EP93XX_SYSCON_I2SCLKDIV_ORIDE | \ |
| 784 | EP93XX_SYSCON_I2SCLKDIV_SPOL) |
| 785 | |
| 786 | int ep93xx_i2s_acquire(unsigned i2s_pins, unsigned i2s_config) |
| 787 | { |
| 788 | unsigned val; |
| 789 | |
| 790 | /* Sanity check */ |
| 791 | if (i2s_pins & ~EP93XX_SYSCON_DEVCFG_I2S_MASK) |
| 792 | return -EINVAL; |
| 793 | if (i2s_config & ~EP93XX_I2SCLKDIV_MASK) |
| 794 | return -EINVAL; |
| 795 | |
| 796 | /* Must have only one of I2SONSSP/I2SONAC97 set */ |
| 797 | if ((i2s_pins & EP93XX_SYSCON_DEVCFG_I2SONSSP) == |
| 798 | (i2s_pins & EP93XX_SYSCON_DEVCFG_I2SONAC97)) |
| 799 | return -EINVAL; |
| 800 | |
| 801 | ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK); |
| 802 | ep93xx_devcfg_set_bits(i2s_pins); |
| 803 | |
| 804 | /* |
| 805 | * This is potentially racy with the clock api for i2s_mclk, sclk and |
| 806 | * lrclk. Since the i2s driver is the only user of those clocks we |
| 807 | * rely on it to prevent parallel use of this function and the |
| 808 | * clock api for the i2s clocks. |
| 809 | */ |
| 810 | val = __raw_readl(EP93XX_SYSCON_I2SCLKDIV); |
| 811 | val &= ~EP93XX_I2SCLKDIV_MASK; |
| 812 | val |= i2s_config; |
| 813 | ep93xx_syscon_swlocked_write(val, EP93XX_SYSCON_I2SCLKDIV); |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | EXPORT_SYMBOL(ep93xx_i2s_acquire); |
| 818 | |
| 819 | void ep93xx_i2s_release(void) |
| 820 | { |
| 821 | ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK); |
| 822 | } |
| 823 | EXPORT_SYMBOL(ep93xx_i2s_release); |
Hartley Sweeten | 12f56c6 | 2009-10-28 21:04:46 +0100 | [diff] [blame] | 824 | |
Mika Westerberg | 534bc7f | 2010-10-14 17:49:07 +0300 | [diff] [blame] | 825 | /************************************************************************* |
| 826 | * EP93xx AC97 audio peripheral handling |
| 827 | *************************************************************************/ |
| 828 | static struct resource ep93xx_ac97_resources[] = { |
| 829 | { |
| 830 | .start = EP93XX_AAC_PHYS_BASE, |
Mika Westerberg | ec11594 | 2011-02-05 09:52:33 +0100 | [diff] [blame] | 831 | .end = EP93XX_AAC_PHYS_BASE + 0xac - 1, |
Mika Westerberg | 534bc7f | 2010-10-14 17:49:07 +0300 | [diff] [blame] | 832 | .flags = IORESOURCE_MEM, |
| 833 | }, |
| 834 | { |
| 835 | .start = IRQ_EP93XX_AACINTR, |
| 836 | .end = IRQ_EP93XX_AACINTR, |
| 837 | .flags = IORESOURCE_IRQ, |
| 838 | }, |
| 839 | }; |
| 840 | |
| 841 | static struct platform_device ep93xx_ac97_device = { |
| 842 | .name = "ep93xx-ac97", |
| 843 | .id = -1, |
| 844 | .num_resources = ARRAY_SIZE(ep93xx_ac97_resources), |
| 845 | .resource = ep93xx_ac97_resources, |
| 846 | }; |
| 847 | |
| 848 | void __init ep93xx_register_ac97(void) |
| 849 | { |
| 850 | /* |
| 851 | * Make sure that the AC97 pins are not used by I2S. |
| 852 | */ |
| 853 | ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97); |
| 854 | |
| 855 | platform_device_register(&ep93xx_ac97_device); |
| 856 | platform_device_register(&ep93xx_pcm_device); |
| 857 | } |
| 858 | |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 859 | void __init ep93xx_init_devices(void) |
| 860 | { |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 861 | /* Disallow access to MaverickCrunch initially */ |
| 862 | ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA); |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 863 | |
H Hartley Sweeten | 1e4c884 | 2011-06-08 14:35:33 -0700 | [diff] [blame] | 864 | /* Get the GPIO working early, other devices need it */ |
| 865 | platform_device_register(&ep93xx_gpio_device); |
Ryan Mallon | b685004 | 2008-04-16 02:56:35 +0100 | [diff] [blame] | 866 | |
Lennert Buytenhek | aee85fe | 2006-03-26 23:16:39 +0100 | [diff] [blame] | 867 | amba_device_register(&uart1_device, &iomem_resource); |
| 868 | amba_device_register(&uart2_device, &iomem_resource); |
| 869 | amba_device_register(&uart3_device, &iomem_resource); |
Lennert Buytenhek | 4165813 | 2006-04-02 16:17:34 +0100 | [diff] [blame] | 870 | |
| 871 | platform_device_register(&ep93xx_rtc_device); |
Lennert Buytenhek | 1f64eb3 | 2006-06-24 10:33:03 +0100 | [diff] [blame] | 872 | platform_device_register(&ep93xx_ohci_device); |
Hartley Sweeten | 3aa7a9a | 2009-07-20 18:22:36 +0100 | [diff] [blame] | 873 | platform_device_register(&ep93xx_leds); |
Lennert Buytenhek | e7736d4 | 2006-03-20 17:10:13 +0000 | [diff] [blame] | 874 | } |
Russell King | 3275166 | 2011-11-05 09:54:14 +0000 | [diff] [blame] | 875 | |
| 876 | void ep93xx_restart(char mode, const char *cmd) |
| 877 | { |
| 878 | /* |
| 879 | * Set then clear the SWRST bit to initiate a software reset |
| 880 | */ |
| 881 | ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_SWRST); |
| 882 | ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_SWRST); |
| 883 | |
| 884 | while (1) |
| 885 | ; |
| 886 | } |