blob: 37e6cdac1642e61daff91d972244e7cf0a4b63b0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/arm/mach-ixp4xx/common.c
3 *
4 * Generic code shared across all IXP4XX platforms
5 *
6 * Maintainer: Deepak Saxena <dsaxena@plexity.net>
7 *
8 * Copyright 2002 (c) Intel Corporation
9 * Copyright 2003-2004 (c) MontaVista, Software, Inc.
10 *
11 * This file is licensed under the terms of the GNU General Public
12 * License version 2. This program is licensed "as is" without any
13 * warranty of any kind, whether express or implied.
14 */
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/kernel.h>
17#include <linux/mm.h>
18#include <linux/init.h>
19#include <linux/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/tty.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010021#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/serial_core.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/interrupt.h>
24#include <linux/bitops.h>
25#include <linux/time.h>
Kevin Hilman84904d02006-09-22 00:58:57 +010026#include <linux/clocksource.h>
Kevin Hilmane32f1502007-03-08 20:23:59 +010027#include <linux/clockchips.h>
Russell Kingfced80c2008-09-06 12:10:45 +010028#include <linux/io.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040029#include <linux/export.h>
Richard Cochran9dde0ae2012-05-23 18:19:51 +020030#include <linux/gpio.h>
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +010031#include <linux/cpu.h>
Stephen Boyd38ff87f2013-06-01 23:39:40 -070032#include <linux/sched_clock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Russell Kinga09e64f2008-08-05 16:14:15 +010034#include <mach/udc.h>
35#include <mach/hardware.h>
Rob Herringf4495882012-03-06 15:01:53 -060036#include <mach/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/pgtable.h>
39#include <asm/page.h>
40#include <asm/irq.h>
Olof Johansson86dfe442012-03-29 23:22:44 -070041#include <asm/system_misc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <asm/mach/map.h>
44#include <asm/mach/irq.h>
45#include <asm/mach/time.h>
46
Uwe Kleine-Königf0402f92013-11-26 19:25:59 +010047#define IXP4XX_TIMER_FREQ 66666000
Uwe Kleine-Königfb3174e2014-02-03 11:31:19 +010048
49/*
50 * The timer register doesn't allow to specify the two least significant bits of
51 * the timeout value and assumes them being zero. So make sure IXP4XX_LATCH is
52 * the best value with the two least significant bits unset.
53 */
54#define IXP4XX_LATCH DIV_ROUND_CLOSEST(IXP4XX_TIMER_FREQ, \
55 (IXP4XX_OST_RELOAD_MASK + 1) * HZ) * \
56 (IXP4XX_OST_RELOAD_MASK + 1)
Uwe Kleine-Königf0402f92013-11-26 19:25:59 +010057
Mikael Petterssonceb69a82009-09-11 00:59:07 +020058static void __init ixp4xx_clocksource_init(void);
59static void __init ixp4xx_clockevent_init(void);
Kevin Hilmane32f1502007-03-08 20:23:59 +010060static struct clock_event_device clockevent_ixp4xx;
Kevin Hilmanf9a8ca12006-12-06 00:45:07 +010061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*************************************************************************
63 * IXP4xx chipset I/O mapping
64 *************************************************************************/
65static struct map_desc ixp4xx_io_desc[] __initdata = {
66 { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
Arnd Bergmann13ec32f2012-09-14 20:19:40 +000067 .virtual = (unsigned long)IXP4XX_PERIPHERAL_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010068 .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 .length = IXP4XX_PERIPHERAL_REGION_SIZE,
70 .type = MT_DEVICE
71 }, { /* Expansion Bus Config Registers */
Arnd Bergmann13ec32f2012-09-14 20:19:40 +000072 .virtual = (unsigned long)IXP4XX_EXP_CFG_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010073 .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 .length = IXP4XX_EXP_CFG_REGION_SIZE,
75 .type = MT_DEVICE
76 }, { /* PCI Registers */
Arnd Bergmann13ec32f2012-09-14 20:19:40 +000077 .virtual = (unsigned long)IXP4XX_PCI_CFG_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010078 .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 .length = IXP4XX_PCI_CFG_REGION_SIZE,
80 .type = MT_DEVICE
Krzysztof Hałasaf0cdb152010-03-26 16:38:52 +010081 }, { /* Queue Manager */
82 .virtual = (unsigned long)IXP4XX_QMGR_BASE_VIRT,
83 .pfn = __phys_to_pfn(IXP4XX_QMGR_BASE_PHYS),
84 .length = IXP4XX_QMGR_REGION_SIZE,
85 .type = MT_DEVICE
Deepak Saxena5932ae32005-06-24 20:54:35 +010086 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070087};
88
89void __init ixp4xx_map_io(void)
90{
91 iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
92}
93
Linus Walleij098e30f2013-09-10 14:10:13 +020094/*
95 * GPIO-functions
96 */
97/*
98 * The following converted to the real HW bits the gpio_line_config
99 */
100/* GPIO pin types */
101#define IXP4XX_GPIO_OUT 0x1
102#define IXP4XX_GPIO_IN 0x2
103
104/* GPIO signal types */
105#define IXP4XX_GPIO_LOW 0
106#define IXP4XX_GPIO_HIGH 1
107
108/* GPIO Clocks */
109#define IXP4XX_GPIO_CLK_0 14
110#define IXP4XX_GPIO_CLK_1 15
111
112static void gpio_line_config(u8 line, u32 direction)
113{
114 if (direction == IXP4XX_GPIO_IN)
115 *IXP4XX_GPIO_GPOER |= (1 << line);
116 else
117 *IXP4XX_GPIO_GPOER &= ~(1 << line);
118}
119
120static void gpio_line_get(u8 line, int *value)
121{
122 *value = (*IXP4XX_GPIO_GPINR >> line) & 0x1;
123}
124
125static void gpio_line_set(u8 line, int value)
126{
127 if (value == IXP4XX_GPIO_HIGH)
128 *IXP4XX_GPIO_GPOUTR |= (1 << line);
129 else if (value == IXP4XX_GPIO_LOW)
130 *IXP4XX_GPIO_GPOUTR &= ~(1 << line);
131}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/*************************************************************************
134 * IXP4xx chipset IRQ handling
135 *
136 * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
137 * (be it PCI or something else) configures that GPIO line
138 * as an IRQ.
139 **************************************************************************/
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100140enum ixp4xx_irq_type {
141 IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
142};
143
Kevin Hilman984d1152006-11-03 01:47:20 +0100144/* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
145static unsigned long long ixp4xx_irq_edge = 0;
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100146
147/*
148 * IRQ -> GPIO mapping table
149 */
Lennert Buytenhek6cc1b652006-04-20 21:24:38 +0100150static signed char irq2gpio[32] = {
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100151 -1, -1, -1, -1, -1, -1, 0, 1,
152 -1, -1, -1, -1, -1, -1, -1, -1,
153 -1, -1, -1, 2, 3, 4, 5, 6,
154 7, 8, 9, 10, 11, 12, -1, -1,
155};
156
Richard Cochran9dde0ae2012-05-23 18:19:51 +0200157static int ixp4xx_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
Milan Svoboda25735d12007-03-21 14:04:08 +0100158{
159 int irq;
160
161 for (irq = 0; irq < 32; irq++) {
162 if (irq2gpio[irq] == gpio)
163 return irq;
164 }
165 return -EINVAL;
166}
Milan Svoboda25735d12007-03-21 14:04:08 +0100167
Lennert Buytenhekee040872010-11-29 10:33:49 +0100168static int ixp4xx_set_irq_type(struct irq_data *d, unsigned int type)
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100169{
Lennert Buytenhekee040872010-11-29 10:33:49 +0100170 int line = irq2gpio[d->irq];
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100171 u32 int_style;
172 enum ixp4xx_irq_type irq_type;
173 volatile u32 *int_reg;
174
175 /*
176 * Only for GPIO IRQs
177 */
178 if (line < 0)
179 return -EINVAL;
180
Mårten Wikström06e44792006-02-22 22:27:23 +0000181 switch (type){
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100182 case IRQ_TYPE_EDGE_BOTH:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100183 int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
184 irq_type = IXP4XX_IRQ_EDGE;
Mårten Wikström06e44792006-02-22 22:27:23 +0000185 break;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100186 case IRQ_TYPE_EDGE_RISING:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100187 int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
188 irq_type = IXP4XX_IRQ_EDGE;
Mårten Wikström06e44792006-02-22 22:27:23 +0000189 break;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100190 case IRQ_TYPE_EDGE_FALLING:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100191 int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
192 irq_type = IXP4XX_IRQ_EDGE;
Mårten Wikström06e44792006-02-22 22:27:23 +0000193 break;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100194 case IRQ_TYPE_LEVEL_HIGH:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100195 int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
196 irq_type = IXP4XX_IRQ_LEVEL;
Mårten Wikström06e44792006-02-22 22:27:23 +0000197 break;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100198 case IRQ_TYPE_LEVEL_LOW:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100199 int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
200 irq_type = IXP4XX_IRQ_LEVEL;
Mårten Wikström06e44792006-02-22 22:27:23 +0000201 break;
202 default:
David Vrabel6132f9e2005-09-26 19:52:56 +0100203 return -EINVAL;
Mårten Wikström06e44792006-02-22 22:27:23 +0000204 }
Kevin Hilman984d1152006-11-03 01:47:20 +0100205
206 if (irq_type == IXP4XX_IRQ_EDGE)
Lennert Buytenhekee040872010-11-29 10:33:49 +0100207 ixp4xx_irq_edge |= (1 << d->irq);
Kevin Hilman984d1152006-11-03 01:47:20 +0100208 else
Lennert Buytenhekee040872010-11-29 10:33:49 +0100209 ixp4xx_irq_edge &= ~(1 << d->irq);
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100210
211 if (line >= 8) { /* pins 8-15 */
212 line -= 8;
213 int_reg = IXP4XX_GPIO_GPIT2R;
214 } else { /* pins 0-7 */
215 int_reg = IXP4XX_GPIO_GPIT1R;
216 }
217
218 /* Clear the style for the appropriate pin */
219 *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
220 (line * IXP4XX_GPIO_STYLE_SIZE));
221
Deepak Saxenaf7e8bbb82006-01-04 17:17:10 +0000222 *IXP4XX_GPIO_GPISR = (1 << line);
223
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100224 /* Set the new style */
225 *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
David Vrabel6132f9e2005-09-26 19:52:56 +0100226
Alessandro Zummo73deb7d2006-03-20 17:10:12 +0000227 /* Configure the line as an input */
Lennert Buytenhekee040872010-11-29 10:33:49 +0100228 gpio_line_config(irq2gpio[d->irq], IXP4XX_GPIO_IN);
Alessandro Zummo73deb7d2006-03-20 17:10:12 +0000229
David Vrabel6132f9e2005-09-26 19:52:56 +0100230 return 0;
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100231}
232
Lennert Buytenhekee040872010-11-29 10:33:49 +0100233static void ixp4xx_irq_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Lennert Buytenhekee040872010-11-29 10:33:49 +0100235 if ((cpu_is_ixp46x() || cpu_is_ixp43x()) && d->irq >= 32)
236 *IXP4XX_ICMR2 &= ~(1 << (d->irq - 32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 else
Lennert Buytenhekee040872010-11-29 10:33:49 +0100238 *IXP4XX_ICMR &= ~(1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
240
Lennert Buytenhekee040872010-11-29 10:33:49 +0100241static void ixp4xx_irq_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Lennert Buytenhekee040872010-11-29 10:33:49 +0100243 int line = (d->irq < 32) ? irq2gpio[d->irq] : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 if (line >= 0)
Deepak Saxenaf7e8bbb82006-01-04 17:17:10 +0000246 *IXP4XX_GPIO_GPISR = (1 << line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
249/*
250 * Level triggered interrupts on GPIO lines can only be cleared when the
251 * interrupt condition disappears.
252 */
Lennert Buytenhekee040872010-11-29 10:33:49 +0100253static void ixp4xx_irq_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Lennert Buytenhekee040872010-11-29 10:33:49 +0100255 if (!(ixp4xx_irq_edge & (1 << d->irq)))
256 ixp4xx_irq_ack(d);
Kevin Hilman984d1152006-11-03 01:47:20 +0100257
Lennert Buytenhekee040872010-11-29 10:33:49 +0100258 if ((cpu_is_ixp46x() || cpu_is_ixp43x()) && d->irq >= 32)
259 *IXP4XX_ICMR2 |= (1 << (d->irq - 32));
Kevin Hilman984d1152006-11-03 01:47:20 +0100260 else
Lennert Buytenhekee040872010-11-29 10:33:49 +0100261 *IXP4XX_ICMR |= (1 << d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Russell King10dd5ce2006-11-23 11:41:32 +0000264static struct irq_chip ixp4xx_irq_chip = {
Kevin Hilman984d1152006-11-03 01:47:20 +0100265 .name = "IXP4xx",
Lennert Buytenhekee040872010-11-29 10:33:49 +0100266 .irq_ack = ixp4xx_irq_ack,
267 .irq_mask = ixp4xx_irq_mask,
268 .irq_unmask = ixp4xx_irq_unmask,
269 .irq_set_type = ixp4xx_set_irq_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270};
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272void __init ixp4xx_init_irq(void)
273{
274 int i = 0;
275
Nicolas Pitre12d2b4e2011-08-03 07:25:39 -0400276 /*
277 * ixp4xx does not implement the XScale PWRMODE register
278 * so it must not call cpu_do_idle().
279 */
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +0100280 cpu_idle_poll_ctrl(true);
Nicolas Pitre12d2b4e2011-08-03 07:25:39 -0400281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* Route all sources to IRQ instead of FIQ */
283 *IXP4XX_ICLR = 0x0;
284
285 /* Disable all interrupt */
286 *IXP4XX_ICMR = 0x0;
287
Ruslan V. Sushko45fba082007-04-06 15:00:31 +0100288 if (cpu_is_ixp46x() || cpu_is_ixp43x()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* Route upper 32 sources to IRQ instead of FIQ */
290 *IXP4XX_ICLR2 = 0x00;
291
292 /* Disable upper 32 interrupts */
293 *IXP4XX_ICMR2 = 0x00;
294 }
295
296 /* Default to all level triggered */
Kevin Hilman984d1152006-11-03 01:47:20 +0100297 for(i = 0; i < NR_IRQS; i++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100298 irq_set_chip_and_handler(i, &ixp4xx_irq_chip,
299 handle_level_irq);
Kevin Hilman984d1152006-11-03 01:47:20 +0100300 set_irq_flags(i, IRQF_VALID);
301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
304
305/*************************************************************************
306 * IXP4xx timer tick
307 * We use OS timer1 on the CPU for the timer tick and the timestamp
308 * counter as a source of real clock ticks to account for missed jiffies.
309 *************************************************************************/
310
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700311static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Mikael Petterssonceb69a82009-09-11 00:59:07 +0200313 struct clock_event_device *evt = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 /* Clear Pending Interrupt by writing '1' to it */
316 *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
317
Kevin Hilmane32f1502007-03-08 20:23:59 +0100318 evt->event_handler(evt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 return IRQ_HANDLED;
321}
322
323static struct irqaction ixp4xx_timer_irq = {
Kevin Hilmane32f1502007-03-08 20:23:59 +0100324 .name = "timer1",
Bernhard Walleb30faba2007-05-08 00:35:39 -0700325 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
Russell King09b8b5f2005-06-26 17:06:36 +0100326 .handler = ixp4xx_timer_interrupt,
Mikael Petterssonceb69a82009-09-11 00:59:07 +0200327 .dev_id = &clockevent_ixp4xx,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328};
329
Michael-Luke Jones435c5da2007-05-23 22:38:45 +0100330void __init ixp4xx_timer_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Kevin Hilmane32f1502007-03-08 20:23:59 +0100332 /* Reset/disable counter */
333 *IXP4XX_OSRT1 = 0;
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /* Clear Pending Interrupt by writing '1' to it */
336 *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 /* Reset time-stamp counter */
339 *IXP4XX_OSTS = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 /* Connect the interrupt handler and enable the interrupt */
342 setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
Kevin Hilmanf9a8ca12006-12-06 00:45:07 +0100343
344 ixp4xx_clocksource_init();
Kevin Hilmane32f1502007-03-08 20:23:59 +0100345 ixp4xx_clockevent_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
Milan Svobodae520a362006-12-01 11:36:41 +0100348static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
349
350void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
351{
352 memcpy(&ixp4xx_udc_info, info, sizeof *info);
353}
354
355static struct resource ixp4xx_udc_resources[] = {
356 [0] = {
357 .start = 0xc800b000,
358 .end = 0xc800bfff,
359 .flags = IORESOURCE_MEM,
360 },
361 [1] = {
362 .start = IRQ_IXP4XX_USB,
363 .end = IRQ_IXP4XX_USB,
364 .flags = IORESOURCE_IRQ,
365 },
366};
367
368/*
Philipp Zabel7a857622008-06-22 23:36:39 +0100369 * USB device controller. The IXP4xx uses the same controller as PXA25X,
Milan Svobodae520a362006-12-01 11:36:41 +0100370 * so we just use the same device.
371 */
372static struct platform_device ixp4xx_udc_device = {
Philipp Zabel7a857622008-06-22 23:36:39 +0100373 .name = "pxa25x-udc",
Milan Svobodae520a362006-12-01 11:36:41 +0100374 .id = -1,
375 .num_resources = 2,
376 .resource = ixp4xx_udc_resources,
377 .dev = {
378 .platform_data = &ixp4xx_udc_info,
379 },
380};
381
382static struct platform_device *ixp4xx_devices[] __initdata = {
383 &ixp4xx_udc_device,
384};
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386static struct resource ixp46x_i2c_resources[] = {
387 [0] = {
388 .start = 0xc8011000,
389 .end = 0xc801101c,
390 .flags = IORESOURCE_MEM,
391 },
392 [1] = {
393 .start = IRQ_IXP4XX_I2C,
394 .end = IRQ_IXP4XX_I2C,
395 .flags = IORESOURCE_IRQ
396 }
397};
398
399/*
400 * I2C controller. The IXP46x uses the same block as the IOP3xx, so
401 * we just use the same device name.
402 */
403static struct platform_device ixp46x_i2c_controller = {
404 .name = "IOP3xx-I2C",
405 .id = 0,
406 .num_resources = 2,
407 .resource = ixp46x_i2c_resources
408};
409
410static struct platform_device *ixp46x_devices[] __initdata = {
411 &ixp46x_i2c_controller
412};
413
Deepak Saxena54e269e2006-01-05 20:59:29 +0000414unsigned long ixp4xx_exp_bus_size;
David Vrabel1e74c892006-01-18 22:46:43 +0000415EXPORT_SYMBOL(ixp4xx_exp_bus_size);
Deepak Saxena54e269e2006-01-05 20:59:29 +0000416
Richard Cochran9dde0ae2012-05-23 18:19:51 +0200417static int ixp4xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
418{
419 gpio_line_config(gpio, IXP4XX_GPIO_IN);
420
421 return 0;
422}
423
424static int ixp4xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
425 int level)
426{
427 gpio_line_set(gpio, level);
428 gpio_line_config(gpio, IXP4XX_GPIO_OUT);
429
430 return 0;
431}
432
433static int ixp4xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
434{
435 int value;
436
437 gpio_line_get(gpio, &value);
438
439 return value;
440}
441
442static void ixp4xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio,
443 int value)
444{
445 gpio_line_set(gpio, value);
446}
447
448static struct gpio_chip ixp4xx_gpio_chip = {
449 .label = "IXP4XX_GPIO_CHIP",
450 .direction_input = ixp4xx_gpio_direction_input,
451 .direction_output = ixp4xx_gpio_direction_output,
452 .get = ixp4xx_gpio_get_value,
453 .set = ixp4xx_gpio_set_value,
454 .to_irq = ixp4xx_gpio_to_irq,
455 .base = 0,
456 .ngpio = 16,
457};
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459void __init ixp4xx_sys_init(void)
460{
Deepak Saxena54e269e2006-01-05 20:59:29 +0000461 ixp4xx_exp_bus_size = SZ_16M;
462
Milan Svobodae520a362006-12-01 11:36:41 +0100463 platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
464
Richard Cochran9dde0ae2012-05-23 18:19:51 +0200465 gpiochip_add(&ixp4xx_gpio_chip);
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 if (cpu_is_ixp46x()) {
Deepak Saxena54e269e2006-01-05 20:59:29 +0000468 int region;
469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 platform_add_devices(ixp46x_devices,
471 ARRAY_SIZE(ixp46x_devices));
Deepak Saxena54e269e2006-01-05 20:59:29 +0000472
473 for (region = 0; region < 7; region++) {
474 if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
475 ixp4xx_exp_bus_size = SZ_32M;
476 break;
477 }
478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
Deepak Saxena54e269e2006-01-05 20:59:29 +0000480
David Vrabel1e74c892006-01-18 22:46:43 +0000481 printk("IXP4xx: Using %luMiB expansion bus window size\n",
Deepak Saxena54e269e2006-01-05 20:59:29 +0000482 ixp4xx_exp_bus_size >> 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
484
Kevin Hilmane32f1502007-03-08 20:23:59 +0100485/*
Russell King5b0d4952010-12-15 21:23:13 +0000486 * sched_clock()
487 */
Marc Zyngier2f0778af2011-12-15 12:19:23 +0100488static u32 notrace ixp4xx_read_sched_clock(void)
Russell King5b0d4952010-12-15 21:23:13 +0000489{
Marc Zyngier2f0778af2011-12-15 12:19:23 +0100490 return *IXP4XX_OSTS;
Russell King5b0d4952010-12-15 21:23:13 +0000491}
492
493/*
Kevin Hilmane32f1502007-03-08 20:23:59 +0100494 * clocksource
495 */
Richard Cochran900b1702011-07-15 21:33:12 +0200496
497static cycle_t ixp4xx_clocksource_read(struct clocksource *c)
498{
499 return *IXP4XX_OSTS;
500}
501
Ben Hutchingse66a0222010-12-11 20:17:54 +0000502unsigned long ixp4xx_timer_freq = IXP4XX_TIMER_FREQ;
Krzysztof Halasa5dbc4652009-09-05 03:59:49 +0000503EXPORT_SYMBOL(ixp4xx_timer_freq);
Mikael Petterssonceb69a82009-09-11 00:59:07 +0200504static void __init ixp4xx_clocksource_init(void)
Kevin Hilman84904d02006-09-22 00:58:57 +0100505{
Marc Zyngier2f0778af2011-12-15 12:19:23 +0100506 setup_sched_clock(ixp4xx_read_sched_clock, 32, ixp4xx_timer_freq);
Russell King5b0d4952010-12-15 21:23:13 +0000507
Richard Cochran900b1702011-07-15 21:33:12 +0200508 clocksource_mmio_init(NULL, "OSTS", ixp4xx_timer_freq, 200, 32,
509 ixp4xx_clocksource_read);
Kevin Hilman84904d02006-09-22 00:58:57 +0100510}
Kevin Hilmane32f1502007-03-08 20:23:59 +0100511
512/*
513 * clockevents
514 */
515static int ixp4xx_set_next_event(unsigned long evt,
516 struct clock_event_device *unused)
517{
518 unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
519
520 *IXP4XX_OSRT1 = (evt & ~IXP4XX_OST_RELOAD_MASK) | opts;
521
522 return 0;
523}
524
525static void ixp4xx_set_mode(enum clock_event_mode mode,
526 struct clock_event_device *evt)
527{
Kevin Hilman553876c2007-12-12 00:32:58 +0100528 unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
529 unsigned long osrt = *IXP4XX_OSRT1 & ~IXP4XX_OST_RELOAD_MASK;
Kevin Hilmane32f1502007-03-08 20:23:59 +0100530
531 switch (mode) {
532 case CLOCK_EVT_MODE_PERIODIC:
Uwe Kleine-Königf0402f92013-11-26 19:25:59 +0100533 osrt = IXP4XX_LATCH & ~IXP4XX_OST_RELOAD_MASK;
Kevin Hilmane32f1502007-03-08 20:23:59 +0100534 opts = IXP4XX_OST_ENABLE;
535 break;
536 case CLOCK_EVT_MODE_ONESHOT:
537 /* period set by 'set next_event' */
538 osrt = 0;
539 opts = IXP4XX_OST_ENABLE | IXP4XX_OST_ONE_SHOT;
540 break;
541 case CLOCK_EVT_MODE_SHUTDOWN:
Kevin Hilman553876c2007-12-12 00:32:58 +0100542 opts &= ~IXP4XX_OST_ENABLE;
543 break;
544 case CLOCK_EVT_MODE_RESUME:
545 opts |= IXP4XX_OST_ENABLE;
546 break;
Kevin Hilmane32f1502007-03-08 20:23:59 +0100547 case CLOCK_EVT_MODE_UNUSED:
548 default:
549 osrt = opts = 0;
550 break;
551 }
552
553 *IXP4XX_OSRT1 = osrt | opts;
554}
555
556static struct clock_event_device clockevent_ixp4xx = {
557 .name = "ixp4xx timer1",
558 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
559 .rating = 200,
Kevin Hilmane32f1502007-03-08 20:23:59 +0100560 .set_mode = ixp4xx_set_mode,
561 .set_next_event = ixp4xx_set_next_event,
562};
563
Mikael Petterssonceb69a82009-09-11 00:59:07 +0200564static void __init ixp4xx_clockevent_init(void)
Kevin Hilmane32f1502007-03-08 20:23:59 +0100565{
Rusty Russell320ab2b2008-12-13 21:20:26 +1030566 clockevent_ixp4xx.cpumask = cpumask_of(0);
Shawn Guo838a2ae2013-01-12 11:50:05 +0000567 clockevents_config_and_register(&clockevent_ixp4xx, IXP4XX_TIMER_FREQ,
568 0xf, 0xfffffffe);
Kevin Hilmane32f1502007-03-08 20:23:59 +0100569}
Russell Kingd1b860f2011-11-05 12:10:55 +0000570
Robin Holt7b6d8642013-07-08 16:01:40 -0700571void ixp4xx_restart(enum reboot_mode mode, const char *cmd)
Russell Kingd1b860f2011-11-05 12:10:55 +0000572{
Robin Holt7b6d8642013-07-08 16:01:40 -0700573 if ( 1 && mode == REBOOT_SOFT) {
Russell Kingd1b860f2011-11-05 12:10:55 +0000574 /* Jump into ROM at address 0 */
575 soft_restart(0);
576 } else {
577 /* Use on-chip reset capability */
578
579 /* set the "key" register to enable access to
580 * "timer" and "enable" registers
581 */
582 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
583
584 /* write 0 to the timer register for an immediate reset */
585 *IXP4XX_OSWT = 0;
586
587 *IXP4XX_OSWE = IXP4XX_WDT_RESET_ENABLE | IXP4XX_WDT_COUNT_ENABLE;
588 }
589}
Rob Herringf4495882012-03-06 15:01:53 -0600590
591#ifdef CONFIG_IXP4XX_INDIRECT_PCI
592/*
593 * In the case of using indirect PCI, we simply return the actual PCI
594 * address and our read/write implementation use that to drive the
595 * access registers. If something outside of PCI is ioremap'd, we
596 * fallback to the default.
597 */
598
Laura Abbott9b971732013-05-16 19:40:22 +0100599static void __iomem *ixp4xx_ioremap_caller(phys_addr_t addr, size_t size,
Rob Herringf4495882012-03-06 15:01:53 -0600600 unsigned int mtype, void *caller)
601{
602 if (!is_pci_memory(addr))
603 return __arm_ioremap_caller(addr, size, mtype, caller);
604
605 return (void __iomem *)addr;
606}
607
608static void ixp4xx_iounmap(void __iomem *addr)
609{
610 if (!is_pci_memory((__force u32)addr))
611 __iounmap(addr);
612}
613
614void __init ixp4xx_init_early(void)
615{
616 arch_ioremap_caller = ixp4xx_ioremap_caller;
617 arch_iounmap = ixp4xx_iounmap;
618}
619#else
620void __init ixp4xx_init_early(void) {}
621#endif