ARM: ixp4xx: Convert to SPARSE_IRQ
[sfrench/cifs-2.6.git] / arch / arm / mach-ixp4xx / common.c
1 /*
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
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/init.h>
19 #include <linux/serial.h>
20 #include <linux/tty.h>
21 #include <linux/platform_device.h>
22 #include <linux/serial_core.h>
23 #include <linux/interrupt.h>
24 #include <linux/bitops.h>
25 #include <linux/time.h>
26 #include <linux/clocksource.h>
27 #include <linux/clockchips.h>
28 #include <linux/io.h>
29 #include <linux/export.h>
30 #include <linux/gpio/driver.h>
31 #include <linux/cpu.h>
32 #include <linux/pci.h>
33 #include <linux/sched_clock.h>
34 #include <linux/bitops.h>
35 #include <mach/udc.h>
36 #include <mach/hardware.h>
37 #include <mach/io.h>
38 #include <linux/uaccess.h>
39 #include <asm/pgtable.h>
40 #include <asm/page.h>
41 #include <asm/exception.h>
42 #include <asm/irq.h>
43 #include <asm/system_misc.h>
44 #include <asm/mach/map.h>
45 #include <asm/mach/irq.h>
46 #include <asm/mach/time.h>
47
48 #include "irqs.h"
49
50 #define IXP4XX_TIMER_FREQ 66666000
51
52 /*
53  * The timer register doesn't allow to specify the two least significant bits of
54  * the timeout value and assumes them being zero. So make sure IXP4XX_LATCH is
55  * the best value with the two least significant bits unset.
56  */
57 #define IXP4XX_LATCH DIV_ROUND_CLOSEST(IXP4XX_TIMER_FREQ, \
58                                        (IXP4XX_OST_RELOAD_MASK + 1) * HZ) * \
59                         (IXP4XX_OST_RELOAD_MASK + 1)
60
61 static struct irq_domain *ixp4xx_irqdomain;
62 static void __init ixp4xx_clocksource_init(void);
63 static void __init ixp4xx_clockevent_init(void);
64 static struct clock_event_device clockevent_ixp4xx;
65
66 /*************************************************************************
67  * IXP4xx chipset I/O mapping
68  *************************************************************************/
69 static struct map_desc ixp4xx_io_desc[] __initdata = {
70         {       /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
71                 .virtual        = (unsigned long)IXP4XX_PERIPHERAL_BASE_VIRT,
72                 .pfn            = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
73                 .length         = IXP4XX_PERIPHERAL_REGION_SIZE,
74                 .type           = MT_DEVICE
75         }, {    /* Expansion Bus Config Registers */
76                 .virtual        = (unsigned long)IXP4XX_EXP_CFG_BASE_VIRT,
77                 .pfn            = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
78                 .length         = IXP4XX_EXP_CFG_REGION_SIZE,
79                 .type           = MT_DEVICE
80         }, {    /* PCI Registers */
81                 .virtual        = (unsigned long)IXP4XX_PCI_CFG_BASE_VIRT,
82                 .pfn            = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
83                 .length         = IXP4XX_PCI_CFG_REGION_SIZE,
84                 .type           = MT_DEVICE
85         }, {    /* Queue Manager */
86                 .virtual        = (unsigned long)IXP4XX_QMGR_BASE_VIRT,
87                 .pfn            = __phys_to_pfn(IXP4XX_QMGR_BASE_PHYS),
88                 .length         = IXP4XX_QMGR_REGION_SIZE,
89                 .type           = MT_DEVICE
90         },
91 };
92
93 void __init ixp4xx_map_io(void)
94 {
95         iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
96 }
97
98 /*
99  * GPIO-functions
100  */
101 /*
102  * The following converted to the real HW bits the gpio_line_config
103  */
104 /* GPIO pin types */
105 #define IXP4XX_GPIO_OUT                 0x1
106 #define IXP4XX_GPIO_IN                  0x2
107
108 /* GPIO signal types */
109 #define IXP4XX_GPIO_LOW                 0
110 #define IXP4XX_GPIO_HIGH                1
111
112 /* GPIO Clocks */
113 #define IXP4XX_GPIO_CLK_0               14
114 #define IXP4XX_GPIO_CLK_1               15
115
116 static void gpio_line_config(u8 line, u32 direction)
117 {
118         if (direction == IXP4XX_GPIO_IN)
119                 *IXP4XX_GPIO_GPOER |= (1 << line);
120         else
121                 *IXP4XX_GPIO_GPOER &= ~(1 << line);
122 }
123
124 static void gpio_line_get(u8 line, int *value)
125 {
126         *value = (*IXP4XX_GPIO_GPINR >> line) & 0x1;
127 }
128
129 static void gpio_line_set(u8 line, int value)
130 {
131         if (value == IXP4XX_GPIO_HIGH)
132             *IXP4XX_GPIO_GPOUTR |= (1 << line);
133         else if (value == IXP4XX_GPIO_LOW)
134             *IXP4XX_GPIO_GPOUTR &= ~(1 << line);
135 }
136
137 /*************************************************************************
138  * IXP4xx chipset IRQ handling
139  *
140  * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
141  *       (be it PCI or something else) configures that GPIO line
142  *       as an IRQ.
143  **************************************************************************/
144 enum ixp4xx_irq_type {
145         IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
146 };
147
148 /* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
149 static unsigned long long ixp4xx_irq_edge = 0;
150
151 /*
152  * IRQ -> GPIO mapping table
153  */
154 static signed char irq2gpio[32] = {
155         -1, -1, -1, -1, -1, -1,  0,  1,
156         -1, -1, -1, -1, -1, -1, -1, -1,
157         -1, -1, -1,  2,  3,  4,  5,  6,
158          7,  8,  9, 10, 11, 12, -1, -1,
159 };
160
161 static int ixp4xx_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
162 {
163         int irq;
164
165         for (irq = 0; irq < 32; irq++) {
166                 if (irq2gpio[irq] == gpio)
167                         return irq;
168         }
169         return -EINVAL;
170 }
171
172 static int ixp4xx_set_irq_type(struct irq_data *d, unsigned int type)
173 {
174         int line = irq2gpio[d->hwirq];
175         u32 int_style;
176         enum ixp4xx_irq_type irq_type;
177         volatile u32 *int_reg;
178
179         /*
180          * Only for GPIO IRQs
181          * all other IRQs are simply active low
182          */
183         if (line < 0)
184                 return 0;
185
186         switch (type){
187         case IRQ_TYPE_EDGE_BOTH:
188                 int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
189                 irq_type = IXP4XX_IRQ_EDGE;
190                 break;
191         case IRQ_TYPE_EDGE_RISING:
192                 int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
193                 irq_type = IXP4XX_IRQ_EDGE;
194                 break;
195         case IRQ_TYPE_EDGE_FALLING:
196                 int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
197                 irq_type = IXP4XX_IRQ_EDGE;
198                 break;
199         case IRQ_TYPE_LEVEL_HIGH:
200                 int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
201                 irq_type = IXP4XX_IRQ_LEVEL;
202                 break;
203         case IRQ_TYPE_LEVEL_LOW:
204                 int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
205                 irq_type = IXP4XX_IRQ_LEVEL;
206                 break;
207         default:
208                 return -EINVAL;
209         }
210
211         if (irq_type == IXP4XX_IRQ_EDGE)
212                 ixp4xx_irq_edge |= (1 << d->hwirq);
213         else
214                 ixp4xx_irq_edge &= ~(1 << d->hwirq);
215
216         if (line >= 8) {        /* pins 8-15 */
217                 line -= 8;
218                 int_reg = IXP4XX_GPIO_GPIT2R;
219         } else {                /* pins 0-7 */
220                 int_reg = IXP4XX_GPIO_GPIT1R;
221         }
222
223         /* Clear the style for the appropriate pin */
224         *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
225                         (line * IXP4XX_GPIO_STYLE_SIZE));
226
227         *IXP4XX_GPIO_GPISR = (1 << line);
228
229         /* Set the new style */
230         *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
231
232         /* Configure the line as an input */
233         gpio_line_config(irq2gpio[d->hwirq], IXP4XX_GPIO_IN);
234
235         return 0;
236 }
237
238 static void ixp4xx_irq_mask(struct irq_data *d)
239 {
240         if ((cpu_is_ixp46x() || cpu_is_ixp43x()) && d->hwirq >= 32)
241                 *IXP4XX_ICMR2 &= ~(1 << (d->hwirq - 32));
242         else
243                 *IXP4XX_ICMR &= ~(1 << d->hwirq);
244 }
245
246 static void ixp4xx_irq_ack(struct irq_data *d)
247 {
248         int line = (d->hwirq < 32) ? irq2gpio[d->hwirq] : -1;
249
250         if (line >= 0)
251                 *IXP4XX_GPIO_GPISR = (1 << line);
252 }
253
254 /*
255  * Level triggered interrupts on GPIO lines can only be cleared when the
256  * interrupt condition disappears.
257  */
258 static void ixp4xx_irq_unmask(struct irq_data *d)
259 {
260         if (!(ixp4xx_irq_edge & (1 << d->hwirq)))
261                 ixp4xx_irq_ack(d);
262
263         if ((cpu_is_ixp46x() || cpu_is_ixp43x()) && d->hwirq >= 32)
264                 *IXP4XX_ICMR2 |= (1 << (d->hwirq - 32));
265         else
266                 *IXP4XX_ICMR |= (1 << d->hwirq);
267 }
268
269 static struct irq_chip ixp4xx_irq_chip = {
270         .name           = "IXP4xx",
271         .irq_ack        = ixp4xx_irq_ack,
272         .irq_mask       = ixp4xx_irq_mask,
273         .irq_unmask     = ixp4xx_irq_unmask,
274         .irq_set_type   = ixp4xx_set_irq_type,
275 };
276
277 asmlinkage void __exception_irq_entry ixp4xx_handle_irq(struct pt_regs *regs)
278 {
279         unsigned long status;
280         int i;
281
282         status = *IXP4XX_ICIP;
283
284         for_each_set_bit(i, &status, 32)
285                 handle_domain_irq(ixp4xx_irqdomain, i, regs);
286
287         /*
288          * IXP465/IXP435 has an upper IRQ status register
289          */
290         if ((cpu_is_ixp46x() || cpu_is_ixp43x())) {
291                 status = *IXP4XX_ICIP2;
292                 for_each_set_bit(i, &status, 32)
293                         handle_domain_irq(ixp4xx_irqdomain, i + 32, regs);
294         }
295 }
296
297 static int ixp4xx_irqdomain_map(struct irq_domain *d, unsigned int irq,
298                                 irq_hw_number_t hwirq)
299 {
300         irq_set_chip_data(irq, &ixp4xx_irq_chip);
301         irq_set_chip_and_handler(irq, &ixp4xx_irq_chip, handle_level_irq);
302         irq_set_probe(irq);
303
304         return 0;
305 }
306
307 static void ixp4xx_irqdomain_unmap(struct irq_domain *d, unsigned int irq)
308 {
309         irq_set_chip_and_handler(irq, NULL, NULL);
310         irq_set_chip_data(irq, NULL);
311 }
312
313 static const struct irq_domain_ops ixp4xx_irqdomain_ops = {
314         .map = ixp4xx_irqdomain_map,
315         .unmap = ixp4xx_irqdomain_unmap,
316 };
317
318 void __init ixp4xx_init_irq(void)
319 {
320         int nr_irqs;
321
322         /*
323          * ixp4xx does not implement the XScale PWRMODE register
324          * so it must not call cpu_do_idle().
325          */
326         cpu_idle_poll_ctrl(true);
327
328         /* Route all sources to IRQ instead of FIQ */
329         *IXP4XX_ICLR = 0x0;
330
331         /* Disable all interrupt */
332         *IXP4XX_ICMR = 0x0; 
333
334         if (cpu_is_ixp46x() || cpu_is_ixp43x()) {
335                 /* Route upper 32 sources to IRQ instead of FIQ */
336                 *IXP4XX_ICLR2 = 0x00;
337
338                 /* Disable upper 32 interrupts */
339                 *IXP4XX_ICMR2 = 0x00;
340
341                 nr_irqs = 64;
342         } else {
343                 nr_irqs = 32;
344         }
345
346         ixp4xx_irqdomain = irq_domain_add_simple(NULL, nr_irqs, IRQ_IXP4XX_BASE,
347                                                  &ixp4xx_irqdomain_ops,
348                                                  NULL);
349         if (!ixp4xx_irqdomain) {
350                 pr_crit("can not add primary irqdomain\n");
351                 return;
352         }
353
354         set_handle_irq(ixp4xx_handle_irq);
355 }
356
357
358 /*************************************************************************
359  * IXP4xx timer tick
360  * We use OS timer1 on the CPU for the timer tick and the timestamp 
361  * counter as a source of real clock ticks to account for missed jiffies.
362  *************************************************************************/
363
364 static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id)
365 {
366         struct clock_event_device *evt = dev_id;
367
368         /* Clear Pending Interrupt by writing '1' to it */
369         *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
370
371         evt->event_handler(evt);
372
373         return IRQ_HANDLED;
374 }
375
376 void __init ixp4xx_timer_init(void)
377 {
378         /* Reset/disable counter */
379         *IXP4XX_OSRT1 = 0;
380
381         /* Clear Pending Interrupt by writing '1' to it */
382         *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
383
384         /* Reset time-stamp counter */
385         *IXP4XX_OSTS = 0;
386
387         ixp4xx_clocksource_init();
388         ixp4xx_clockevent_init();
389 }
390
391 static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
392
393 void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
394 {
395         memcpy(&ixp4xx_udc_info, info, sizeof *info);
396 }
397
398 static struct resource ixp4xx_udc_resources[] = {
399         [0] = {
400                 .start  = 0xc800b000,
401                 .end    = 0xc800bfff,
402                 .flags  = IORESOURCE_MEM,
403         },
404         [1] = {
405                 .start  = IRQ_IXP4XX_USB,
406                 .end    = IRQ_IXP4XX_USB,
407                 .flags  = IORESOURCE_IRQ,
408         },
409 };
410
411 /*
412  * USB device controller. The IXP4xx uses the same controller as PXA25X,
413  * so we just use the same device.
414  */
415 static struct platform_device ixp4xx_udc_device = {
416         .name           = "pxa25x-udc",
417         .id             = -1,
418         .num_resources  = 2,
419         .resource       = ixp4xx_udc_resources,
420         .dev            = {
421                 .platform_data = &ixp4xx_udc_info,
422         },
423 };
424
425 static struct platform_device *ixp4xx_devices[] __initdata = {
426         &ixp4xx_udc_device,
427 };
428
429 static struct resource ixp46x_i2c_resources[] = {
430         [0] = {
431                 .start  = 0xc8011000,
432                 .end    = 0xc801101c,
433                 .flags  = IORESOURCE_MEM,
434         },
435         [1] = {
436                 .start  = IRQ_IXP4XX_I2C,
437                 .end    = IRQ_IXP4XX_I2C,
438                 .flags  = IORESOURCE_IRQ
439         }
440 };
441
442 /*
443  * I2C controller. The IXP46x uses the same block as the IOP3xx, so
444  * we just use the same device name.
445  */
446 static struct platform_device ixp46x_i2c_controller = {
447         .name           = "IOP3xx-I2C",
448         .id             = 0,
449         .num_resources  = 2,
450         .resource       = ixp46x_i2c_resources
451 };
452
453 static struct platform_device *ixp46x_devices[] __initdata = {
454         &ixp46x_i2c_controller
455 };
456
457 unsigned long ixp4xx_exp_bus_size;
458 EXPORT_SYMBOL(ixp4xx_exp_bus_size);
459
460 static int ixp4xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
461 {
462         gpio_line_config(gpio, IXP4XX_GPIO_IN);
463
464         return 0;
465 }
466
467 static int ixp4xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
468                                         int level)
469 {
470         gpio_line_set(gpio, level);
471         gpio_line_config(gpio, IXP4XX_GPIO_OUT);
472
473         return 0;
474 }
475
476 static int ixp4xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
477 {
478         int value;
479
480         gpio_line_get(gpio, &value);
481
482         return value;
483 }
484
485 static void ixp4xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio,
486                                   int value)
487 {
488         gpio_line_set(gpio, value);
489 }
490
491 static struct gpio_chip ixp4xx_gpio_chip = {
492         .label                  = "IXP4XX_GPIO_CHIP",
493         .direction_input        = ixp4xx_gpio_direction_input,
494         .direction_output       = ixp4xx_gpio_direction_output,
495         .get                    = ixp4xx_gpio_get_value,
496         .set                    = ixp4xx_gpio_set_value,
497         .to_irq                 = ixp4xx_gpio_to_irq,
498         .base                   = 0,
499         .ngpio                  = 16,
500 };
501
502 void __init ixp4xx_sys_init(void)
503 {
504         ixp4xx_exp_bus_size = SZ_16M;
505
506         platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
507
508         gpiochip_add_data(&ixp4xx_gpio_chip, NULL);
509
510         if (cpu_is_ixp46x()) {
511                 int region;
512
513                 platform_add_devices(ixp46x_devices,
514                                 ARRAY_SIZE(ixp46x_devices));
515
516                 for (region = 0; region < 7; region++) {
517                         if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
518                                 ixp4xx_exp_bus_size = SZ_32M;
519                                 break;
520                         }
521                 }
522         }
523
524         printk("IXP4xx: Using %luMiB expansion bus window size\n",
525                         ixp4xx_exp_bus_size >> 20);
526 }
527
528 /*
529  * sched_clock()
530  */
531 static u64 notrace ixp4xx_read_sched_clock(void)
532 {
533         return *IXP4XX_OSTS;
534 }
535
536 /*
537  * clocksource
538  */
539
540 static u64 ixp4xx_clocksource_read(struct clocksource *c)
541 {
542         return *IXP4XX_OSTS;
543 }
544
545 unsigned long ixp4xx_timer_freq = IXP4XX_TIMER_FREQ;
546 EXPORT_SYMBOL(ixp4xx_timer_freq);
547 static void __init ixp4xx_clocksource_init(void)
548 {
549         sched_clock_register(ixp4xx_read_sched_clock, 32, ixp4xx_timer_freq);
550
551         clocksource_mmio_init(NULL, "OSTS", ixp4xx_timer_freq, 200, 32,
552                         ixp4xx_clocksource_read);
553 }
554
555 /*
556  * clockevents
557  */
558 static int ixp4xx_set_next_event(unsigned long evt,
559                                  struct clock_event_device *unused)
560 {
561         unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
562
563         *IXP4XX_OSRT1 = (evt & ~IXP4XX_OST_RELOAD_MASK) | opts;
564
565         return 0;
566 }
567
568 static int ixp4xx_shutdown(struct clock_event_device *evt)
569 {
570         unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
571         unsigned long osrt = *IXP4XX_OSRT1 & ~IXP4XX_OST_RELOAD_MASK;
572
573         opts &= ~IXP4XX_OST_ENABLE;
574         *IXP4XX_OSRT1 = osrt | opts;
575         return 0;
576 }
577
578 static int ixp4xx_set_oneshot(struct clock_event_device *evt)
579 {
580         unsigned long opts = IXP4XX_OST_ENABLE | IXP4XX_OST_ONE_SHOT;
581         unsigned long osrt = 0;
582
583         /* period set by 'set next_event' */
584         *IXP4XX_OSRT1 = osrt | opts;
585         return 0;
586 }
587
588 static int ixp4xx_set_periodic(struct clock_event_device *evt)
589 {
590         unsigned long opts = IXP4XX_OST_ENABLE;
591         unsigned long osrt = IXP4XX_LATCH & ~IXP4XX_OST_RELOAD_MASK;
592
593         *IXP4XX_OSRT1 = osrt | opts;
594         return 0;
595 }
596
597 static int ixp4xx_resume(struct clock_event_device *evt)
598 {
599         unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
600         unsigned long osrt = *IXP4XX_OSRT1 & ~IXP4XX_OST_RELOAD_MASK;
601
602         opts |= IXP4XX_OST_ENABLE;
603         *IXP4XX_OSRT1 = osrt | opts;
604         return 0;
605 }
606
607 static struct clock_event_device clockevent_ixp4xx = {
608         .name                   = "ixp4xx timer1",
609         .features               = CLOCK_EVT_FEAT_PERIODIC |
610                                   CLOCK_EVT_FEAT_ONESHOT,
611         .rating                 = 200,
612         .set_state_shutdown     = ixp4xx_shutdown,
613         .set_state_periodic     = ixp4xx_set_periodic,
614         .set_state_oneshot      = ixp4xx_set_oneshot,
615         .tick_resume            = ixp4xx_resume,
616         .set_next_event         = ixp4xx_set_next_event,
617 };
618
619 static void __init ixp4xx_clockevent_init(void)
620 {
621         int ret;
622
623         clockevent_ixp4xx.cpumask = cpumask_of(0);
624         clockevent_ixp4xx.irq = IRQ_IXP4XX_TIMER1;
625         ret = request_irq(IRQ_IXP4XX_TIMER1, ixp4xx_timer_interrupt,
626                           IRQF_TIMER, "IXP4XX-TIMER1", &clockevent_ixp4xx);
627         if (ret) {
628                 pr_crit("no timer IRQ\n");
629                 return;
630         }
631         clockevents_config_and_register(&clockevent_ixp4xx, IXP4XX_TIMER_FREQ,
632                                         0xf, 0xfffffffe);
633 }
634
635 void ixp4xx_restart(enum reboot_mode mode, const char *cmd)
636 {
637         if (mode == REBOOT_SOFT) {
638                 /* Jump into ROM at address 0 */
639                 soft_restart(0);
640         } else {
641                 /* Use on-chip reset capability */
642
643                 /* set the "key" register to enable access to
644                  * "timer" and "enable" registers
645                  */
646                 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
647
648                 /* write 0 to the timer register for an immediate reset */
649                 *IXP4XX_OSWT = 0;
650
651                 *IXP4XX_OSWE = IXP4XX_WDT_RESET_ENABLE | IXP4XX_WDT_COUNT_ENABLE;
652         }
653 }
654
655 #ifdef CONFIG_PCI
656 static int ixp4xx_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
657 {
658         return (dma_addr + size) > SZ_64M;
659 }
660
661 static int ixp4xx_platform_notify_remove(struct device *dev)
662 {
663         if (dev_is_pci(dev))
664                 dmabounce_unregister_dev(dev);
665
666         return 0;
667 }
668 #endif
669
670 /*
671  * Setup DMA mask to 64MB on PCI devices and 4 GB on all other things.
672  */
673 static int ixp4xx_platform_notify(struct device *dev)
674 {
675         dev->dma_mask = &dev->coherent_dma_mask;
676
677 #ifdef CONFIG_PCI
678         if (dev_is_pci(dev)) {
679                 dev->coherent_dma_mask = DMA_BIT_MASK(28); /* 64 MB */
680                 dmabounce_register_dev(dev, 2048, 4096, ixp4xx_needs_bounce);
681                 return 0;
682         }
683 #endif
684
685         dev->coherent_dma_mask = DMA_BIT_MASK(32);
686         return 0;
687 }
688
689 int dma_set_coherent_mask(struct device *dev, u64 mask)
690 {
691         if (dev_is_pci(dev))
692                 mask &= DMA_BIT_MASK(28); /* 64 MB */
693
694         if ((mask & DMA_BIT_MASK(28)) == DMA_BIT_MASK(28)) {
695                 dev->coherent_dma_mask = mask;
696                 return 0;
697         }
698
699         return -EIO;            /* device wanted sub-64MB mask */
700 }
701 EXPORT_SYMBOL(dma_set_coherent_mask);
702
703 #ifdef CONFIG_IXP4XX_INDIRECT_PCI
704 /*
705  * In the case of using indirect PCI, we simply return the actual PCI
706  * address and our read/write implementation use that to drive the
707  * access registers. If something outside of PCI is ioremap'd, we
708  * fallback to the default.
709  */
710
711 static void __iomem *ixp4xx_ioremap_caller(phys_addr_t addr, size_t size,
712                                            unsigned int mtype, void *caller)
713 {
714         if (!is_pci_memory(addr))
715                 return __arm_ioremap_caller(addr, size, mtype, caller);
716
717         return (void __iomem *)addr;
718 }
719
720 static void ixp4xx_iounmap(volatile void __iomem *addr)
721 {
722         if (!is_pci_memory((__force u32)addr))
723                 __iounmap(addr);
724 }
725 #endif
726
727 void __init ixp4xx_init_early(void)
728 {
729         platform_notify = ixp4xx_platform_notify;
730 #ifdef CONFIG_PCI
731         platform_notify_remove = ixp4xx_platform_notify_remove;
732 #endif
733 #ifdef CONFIG_IXP4XX_INDIRECT_PCI
734         arch_ioremap_caller = ixp4xx_ioremap_caller;
735         arch_iounmap = ixp4xx_iounmap;
736 #endif
737 }