2 * arch/arm/mach-ixp4xx/common.c
4 * Generic code shared across all IXP4XX platforms
6 * Maintainer: Deepak Saxena <dsaxena@plexity.net>
8 * Copyright 2002 (c) Intel Corporation
9 * Copyright 2003-2004 (c) MontaVista, Software, Inc.
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.
16 #include <linux/kernel.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>
26 #include <linux/export.h>
27 #include <linux/cpu.h>
28 #include <linux/pci.h>
29 #include <linux/sched_clock.h>
30 #include <linux/bitops.h>
31 #include <linux/irqchip/irq-ixp4xx.h>
32 #include <linux/platform_data/timer-ixp4xx.h>
34 #include <mach/hardware.h>
36 #include <linux/uaccess.h>
37 #include <asm/pgtable.h>
39 #include <asm/exception.h>
41 #include <asm/system_misc.h>
42 #include <asm/mach/map.h>
43 #include <asm/mach/irq.h>
44 #include <asm/mach/time.h>
48 #define IXP4XX_TIMER_FREQ 66666000
50 /*************************************************************************
51 * IXP4xx chipset I/O mapping
52 *************************************************************************/
53 static struct map_desc ixp4xx_io_desc
[] __initdata
= {
54 { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
55 .virtual = (unsigned long)IXP4XX_PERIPHERAL_BASE_VIRT
,
56 .pfn
= __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS
),
57 .length
= IXP4XX_PERIPHERAL_REGION_SIZE
,
59 }, { /* Expansion Bus Config Registers */
60 .virtual = (unsigned long)IXP4XX_EXP_CFG_BASE_VIRT
,
61 .pfn
= __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS
),
62 .length
= IXP4XX_EXP_CFG_REGION_SIZE
,
64 }, { /* PCI Registers */
65 .virtual = (unsigned long)IXP4XX_PCI_CFG_BASE_VIRT
,
66 .pfn
= __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS
),
67 .length
= IXP4XX_PCI_CFG_REGION_SIZE
,
69 }, { /* Queue Manager */
70 .virtual = (unsigned long)IXP4XX_QMGR_BASE_VIRT
,
71 .pfn
= __phys_to_pfn(IXP4XX_QMGR_BASE_PHYS
),
72 .length
= IXP4XX_QMGR_REGION_SIZE
,
77 void __init
ixp4xx_map_io(void)
79 iotable_init(ixp4xx_io_desc
, ARRAY_SIZE(ixp4xx_io_desc
));
82 void __init
ixp4xx_init_irq(void)
85 * ixp4xx does not implement the XScale PWRMODE register
86 * so it must not call cpu_do_idle().
88 cpu_idle_poll_ctrl(true);
90 ixp4xx_irq_init(IXP4XX_INTC_BASE_PHYS
,
91 (cpu_is_ixp46x() || cpu_is_ixp43x()));
94 void __init
ixp4xx_timer_init(void)
96 return ixp4xx_timer_setup(IXP4XX_TIMER_BASE_PHYS
,
101 static struct pxa2xx_udc_mach_info ixp4xx_udc_info
;
103 void __init
ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info
*info
)
105 memcpy(&ixp4xx_udc_info
, info
, sizeof *info
);
108 static struct resource ixp4xx_udc_resources
[] = {
112 .flags
= IORESOURCE_MEM
,
115 .start
= IRQ_IXP4XX_USB
,
116 .end
= IRQ_IXP4XX_USB
,
117 .flags
= IORESOURCE_IRQ
,
121 static struct resource ixp4xx_gpio_resource
[] = {
123 .start
= IXP4XX_GPIO_BASE_PHYS
,
124 .end
= IXP4XX_GPIO_BASE_PHYS
+ 0xfff,
125 .flags
= IORESOURCE_MEM
,
129 static struct platform_device ixp4xx_gpio_device
= {
130 .name
= "ixp4xx-gpio",
133 .coherent_dma_mask
= DMA_BIT_MASK(32),
135 .resource
= ixp4xx_gpio_resource
,
136 .num_resources
= ARRAY_SIZE(ixp4xx_gpio_resource
),
140 * USB device controller. The IXP4xx uses the same controller as PXA25X,
141 * so we just use the same device.
143 static struct platform_device ixp4xx_udc_device
= {
144 .name
= "pxa25x-udc",
147 .resource
= ixp4xx_udc_resources
,
149 .platform_data
= &ixp4xx_udc_info
,
153 static struct resource ixp4xx_npe_resources
[] = {
155 .start
= IXP4XX_NPEA_BASE_PHYS
,
156 .end
= IXP4XX_NPEA_BASE_PHYS
+ 0xfff,
157 .flags
= IORESOURCE_MEM
,
160 .start
= IXP4XX_NPEB_BASE_PHYS
,
161 .end
= IXP4XX_NPEB_BASE_PHYS
+ 0xfff,
162 .flags
= IORESOURCE_MEM
,
165 .start
= IXP4XX_NPEC_BASE_PHYS
,
166 .end
= IXP4XX_NPEC_BASE_PHYS
+ 0xfff,
167 .flags
= IORESOURCE_MEM
,
172 static struct platform_device ixp4xx_npe_device
= {
173 .name
= "ixp4xx-npe",
175 .num_resources
= ARRAY_SIZE(ixp4xx_npe_resources
),
176 .resource
= ixp4xx_npe_resources
,
179 static struct platform_device ixp4xx_qmgr_device
= {
180 .name
= "ixp4xx-qmgr",
184 static struct platform_device
*ixp4xx_devices
[] __initdata
= {
191 static struct resource ixp46x_i2c_resources
[] = {
195 .flags
= IORESOURCE_MEM
,
198 .start
= IRQ_IXP4XX_I2C
,
199 .end
= IRQ_IXP4XX_I2C
,
200 .flags
= IORESOURCE_IRQ
205 * I2C controller. The IXP46x uses the same block as the IOP3xx, so
206 * we just use the same device name.
208 static struct platform_device ixp46x_i2c_controller
= {
209 .name
= "IOP3xx-I2C",
212 .resource
= ixp46x_i2c_resources
215 static struct platform_device
*ixp46x_devices
[] __initdata
= {
216 &ixp46x_i2c_controller
219 unsigned long ixp4xx_exp_bus_size
;
220 EXPORT_SYMBOL(ixp4xx_exp_bus_size
);
222 void __init
ixp4xx_sys_init(void)
224 ixp4xx_exp_bus_size
= SZ_16M
;
226 platform_add_devices(ixp4xx_devices
, ARRAY_SIZE(ixp4xx_devices
));
228 if (cpu_is_ixp46x()) {
231 platform_add_devices(ixp46x_devices
,
232 ARRAY_SIZE(ixp46x_devices
));
234 for (region
= 0; region
< 7; region
++) {
235 if((*(IXP4XX_EXP_REG(0x4 * region
)) & 0x200)) {
236 ixp4xx_exp_bus_size
= SZ_32M
;
242 printk("IXP4xx: Using %luMiB expansion bus window size\n",
243 ixp4xx_exp_bus_size
>> 20);
246 unsigned long ixp4xx_timer_freq
= IXP4XX_TIMER_FREQ
;
247 EXPORT_SYMBOL(ixp4xx_timer_freq
);
249 void ixp4xx_restart(enum reboot_mode mode
, const char *cmd
)
251 if (mode
== REBOOT_SOFT
) {
252 /* Jump into ROM at address 0 */
255 /* Use on-chip reset capability */
257 /* set the "key" register to enable access to
258 * "timer" and "enable" registers
260 *IXP4XX_OSWK
= IXP4XX_WDT_KEY
;
262 /* write 0 to the timer register for an immediate reset */
265 *IXP4XX_OSWE
= IXP4XX_WDT_RESET_ENABLE
| IXP4XX_WDT_COUNT_ENABLE
;
270 static int ixp4xx_needs_bounce(struct device
*dev
, dma_addr_t dma_addr
, size_t size
)
272 return (dma_addr
+ size
) > SZ_64M
;
275 static int ixp4xx_platform_notify_remove(struct device
*dev
)
278 dmabounce_unregister_dev(dev
);
285 * Setup DMA mask to 64MB on PCI devices and 4 GB on all other things.
287 static int ixp4xx_platform_notify(struct device
*dev
)
289 dev
->dma_mask
= &dev
->coherent_dma_mask
;
292 if (dev_is_pci(dev
)) {
293 dev
->coherent_dma_mask
= DMA_BIT_MASK(28); /* 64 MB */
294 dmabounce_register_dev(dev
, 2048, 4096, ixp4xx_needs_bounce
);
299 dev
->coherent_dma_mask
= DMA_BIT_MASK(32);
303 int dma_set_coherent_mask(struct device
*dev
, u64 mask
)
306 mask
&= DMA_BIT_MASK(28); /* 64 MB */
308 if ((mask
& DMA_BIT_MASK(28)) == DMA_BIT_MASK(28)) {
309 dev
->coherent_dma_mask
= mask
;
313 return -EIO
; /* device wanted sub-64MB mask */
315 EXPORT_SYMBOL(dma_set_coherent_mask
);
317 #ifdef CONFIG_IXP4XX_INDIRECT_PCI
319 * In the case of using indirect PCI, we simply return the actual PCI
320 * address and our read/write implementation use that to drive the
321 * access registers. If something outside of PCI is ioremap'd, we
322 * fallback to the default.
325 static void __iomem
*ixp4xx_ioremap_caller(phys_addr_t addr
, size_t size
,
326 unsigned int mtype
, void *caller
)
328 if (!is_pci_memory(addr
))
329 return __arm_ioremap_caller(addr
, size
, mtype
, caller
);
331 return (void __iomem
*)addr
;
334 static void ixp4xx_iounmap(volatile void __iomem
*addr
)
336 if (!is_pci_memory((__force u32
)addr
))
341 void __init
ixp4xx_init_early(void)
343 platform_notify
= ixp4xx_platform_notify
;
345 platform_notify_remove
= ixp4xx_platform_notify_remove
;
347 #ifdef CONFIG_IXP4XX_INDIRECT_PCI
348 arch_ioremap_caller
= ixp4xx_ioremap_caller
;
349 arch_iounmap
= ixp4xx_iounmap
;