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/soc/ixp4xx/cpu.h>
31 #include <linux/irqchip/irq-ixp4xx.h>
32 #include <linux/platform_data/timer-ixp4xx.h>
33 #include <linux/dma-map-ops.h>
35 #include <mach/hardware.h>
36 #include <linux/uaccess.h>
38 #include <asm/exception.h>
40 #include <asm/system_misc.h>
41 #include <asm/mach/map.h>
42 #include <asm/mach/irq.h>
43 #include <asm/mach/time.h>
47 u32 ixp4xx_read_feature_bits(void)
49 u32 val = ~__raw_readl(IXP4XX_EXP_CFG2);
51 if (cpu_is_ixp42x_rev_a0())
52 return IXP42X_FEATURE_MASK & ~(IXP4XX_FEATURE_RCOMP |
55 return val & IXP42X_FEATURE_MASK;
57 return val & IXP43X_FEATURE_MASK;
58 return val & IXP46X_FEATURE_MASK;
60 EXPORT_SYMBOL(ixp4xx_read_feature_bits);
62 void ixp4xx_write_feature_bits(u32 value)
64 __raw_writel(~value, IXP4XX_EXP_CFG2);
66 EXPORT_SYMBOL(ixp4xx_write_feature_bits);
68 #define IXP4XX_TIMER_FREQ 66666000
70 /*************************************************************************
71 * IXP4xx chipset I/O mapping
72 *************************************************************************/
73 static struct map_desc ixp4xx_io_desc[] __initdata = {
74 { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
75 .virtual = (unsigned long)IXP4XX_PERIPHERAL_BASE_VIRT,
76 .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
77 .length = IXP4XX_PERIPHERAL_REGION_SIZE,
79 }, { /* Expansion Bus Config Registers */
80 .virtual = (unsigned long)IXP4XX_EXP_CFG_BASE_VIRT,
81 .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
82 .length = IXP4XX_EXP_CFG_REGION_SIZE,
84 }, { /* PCI Registers */
85 .virtual = (unsigned long)IXP4XX_PCI_CFG_BASE_VIRT,
86 .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
87 .length = IXP4XX_PCI_CFG_REGION_SIZE,
92 void __init ixp4xx_map_io(void)
94 iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
97 void __init ixp4xx_init_irq(void)
100 * ixp4xx does not implement the XScale PWRMODE register
101 * so it must not call cpu_do_idle().
103 cpu_idle_poll_ctrl(true);
105 ixp4xx_irq_init(IXP4XX_INTC_BASE_PHYS,
106 (cpu_is_ixp46x() || cpu_is_ixp43x()));
109 void __init ixp4xx_timer_init(void)
111 return ixp4xx_timer_setup(IXP4XX_TIMER_BASE_PHYS,
116 static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
118 void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
120 memcpy(&ixp4xx_udc_info, info, sizeof *info);
123 static struct resource ixp4xx_udc_resources[] = {
127 .flags = IORESOURCE_MEM,
130 .start = IRQ_IXP4XX_USB,
131 .end = IRQ_IXP4XX_USB,
132 .flags = IORESOURCE_IRQ,
136 static struct resource ixp4xx_gpio_resource[] = {
138 .start = IXP4XX_GPIO_BASE_PHYS,
139 .end = IXP4XX_GPIO_BASE_PHYS + 0xfff,
140 .flags = IORESOURCE_MEM,
144 static struct platform_device ixp4xx_gpio_device = {
145 .name = "ixp4xx-gpio",
148 .coherent_dma_mask = DMA_BIT_MASK(32),
150 .resource = ixp4xx_gpio_resource,
151 .num_resources = ARRAY_SIZE(ixp4xx_gpio_resource),
155 * USB device controller. The IXP4xx uses the same controller as PXA25X,
156 * so we just use the same device.
158 static struct platform_device ixp4xx_udc_device = {
159 .name = "pxa25x-udc",
162 .resource = ixp4xx_udc_resources,
164 .platform_data = &ixp4xx_udc_info,
168 static struct resource ixp4xx_npe_resources[] = {
170 .start = IXP4XX_NPEA_BASE_PHYS,
171 .end = IXP4XX_NPEA_BASE_PHYS + 0xfff,
172 .flags = IORESOURCE_MEM,
175 .start = IXP4XX_NPEB_BASE_PHYS,
176 .end = IXP4XX_NPEB_BASE_PHYS + 0xfff,
177 .flags = IORESOURCE_MEM,
180 .start = IXP4XX_NPEC_BASE_PHYS,
181 .end = IXP4XX_NPEC_BASE_PHYS + 0xfff,
182 .flags = IORESOURCE_MEM,
187 static struct platform_device ixp4xx_npe_device = {
188 .name = "ixp4xx-npe",
190 .num_resources = ARRAY_SIZE(ixp4xx_npe_resources),
191 .resource = ixp4xx_npe_resources,
194 static struct resource ixp4xx_qmgr_resources[] = {
196 .start = IXP4XX_QMGR_BASE_PHYS,
197 .end = IXP4XX_QMGR_BASE_PHYS + 0x3fff,
198 .flags = IORESOURCE_MEM,
201 .start = IRQ_IXP4XX_QM1,
202 .end = IRQ_IXP4XX_QM1,
203 .flags = IORESOURCE_IRQ,
206 .start = IRQ_IXP4XX_QM2,
207 .end = IRQ_IXP4XX_QM2,
208 .flags = IORESOURCE_IRQ,
212 static struct platform_device ixp4xx_qmgr_device = {
213 .name = "ixp4xx-qmgr",
215 .num_resources = ARRAY_SIZE(ixp4xx_qmgr_resources),
216 .resource = ixp4xx_qmgr_resources,
219 static struct platform_device *ixp4xx_devices[] __initdata = {
226 static struct resource ixp46x_i2c_resources[] = {
230 .flags = IORESOURCE_MEM,
233 .start = IRQ_IXP4XX_I2C,
234 .end = IRQ_IXP4XX_I2C,
235 .flags = IORESOURCE_IRQ
239 /* A single 32-bit register on IXP46x */
240 #define IXP4XX_HWRANDOM_BASE_PHYS 0x70002100
242 static struct resource ixp46x_hwrandom_resource[] = {
244 .start = IXP4XX_HWRANDOM_BASE_PHYS,
245 .end = IXP4XX_HWRANDOM_BASE_PHYS + 0x3,
246 .flags = IORESOURCE_MEM,
250 static struct platform_device ixp46x_hwrandom_device = {
251 .name = "ixp4xx-hwrandom",
254 .coherent_dma_mask = DMA_BIT_MASK(32),
256 .resource = ixp46x_hwrandom_resource,
257 .num_resources = ARRAY_SIZE(ixp46x_hwrandom_resource),
261 * I2C controller. The IXP46x uses the same block as the IOP3xx, so
262 * we just use the same device name.
264 static struct platform_device ixp46x_i2c_controller = {
265 .name = "IOP3xx-I2C",
268 .resource = ixp46x_i2c_resources
271 static struct platform_device *ixp46x_devices[] __initdata = {
272 &ixp46x_hwrandom_device,
273 &ixp46x_i2c_controller,
276 unsigned long ixp4xx_exp_bus_size;
277 EXPORT_SYMBOL(ixp4xx_exp_bus_size);
279 static struct platform_device_info ixp_dev_info __initdata = {
280 .name = "ixp4xx_crypto",
282 .dma_mask = DMA_BIT_MASK(32),
285 static int __init ixp_crypto_register(void)
287 struct platform_device *pdev;
289 if (!(~(*IXP4XX_EXP_CFG2) & (IXP4XX_FEATURE_HASH |
290 IXP4XX_FEATURE_AES | IXP4XX_FEATURE_DES))) {
291 printk(KERN_ERR "ixp_crypto: No HW crypto available\n");
295 pdev = platform_device_register_full(&ixp_dev_info);
297 return PTR_ERR(pdev);
302 void __init ixp4xx_sys_init(void)
304 ixp4xx_exp_bus_size = SZ_16M;
306 platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
308 if (IS_ENABLED(CONFIG_CRYPTO_DEV_IXP4XX))
309 ixp_crypto_register();
311 if (cpu_is_ixp46x()) {
314 platform_add_devices(ixp46x_devices,
315 ARRAY_SIZE(ixp46x_devices));
317 for (region = 0; region < 7; region++) {
318 if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
319 ixp4xx_exp_bus_size = SZ_32M;
325 printk("IXP4xx: Using %luMiB expansion bus window size\n",
326 ixp4xx_exp_bus_size >> 20);
329 unsigned long ixp4xx_timer_freq = IXP4XX_TIMER_FREQ;
330 EXPORT_SYMBOL(ixp4xx_timer_freq);
332 void ixp4xx_restart(enum reboot_mode mode, const char *cmd)
334 if (mode == REBOOT_SOFT) {
335 /* Jump into ROM at address 0 */
338 /* Use on-chip reset capability */
340 /* set the "key" register to enable access to
341 * "timer" and "enable" registers
343 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
345 /* write 0 to the timer register for an immediate reset */
348 *IXP4XX_OSWE = IXP4XX_WDT_RESET_ENABLE | IXP4XX_WDT_COUNT_ENABLE;
353 static int ixp4xx_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
355 return (dma_addr + size) > SZ_64M;
358 static int ixp4xx_platform_notify_remove(struct device *dev)
361 dmabounce_unregister_dev(dev);
368 * Setup DMA mask to 64MB on PCI devices and 4 GB on all other things.
370 static int ixp4xx_platform_notify(struct device *dev)
372 dev->dma_mask = &dev->coherent_dma_mask;
375 if (dev_is_pci(dev)) {
376 dev->coherent_dma_mask = DMA_BIT_MASK(28); /* 64 MB */
377 dmabounce_register_dev(dev, 2048, 4096, ixp4xx_needs_bounce);
382 dev->coherent_dma_mask = DMA_BIT_MASK(32);
386 int dma_set_coherent_mask(struct device *dev, u64 mask)
389 mask &= DMA_BIT_MASK(28); /* 64 MB */
391 if ((mask & DMA_BIT_MASK(28)) == DMA_BIT_MASK(28)) {
392 dev->coherent_dma_mask = mask;
396 return -EIO; /* device wanted sub-64MB mask */
398 EXPORT_SYMBOL(dma_set_coherent_mask);
400 #ifdef CONFIG_IXP4XX_INDIRECT_PCI
402 * In the case of using indirect PCI, we simply return the actual PCI
403 * address and our read/write implementation use that to drive the
404 * access registers. If something outside of PCI is ioremap'd, we
405 * fallback to the default.
408 static void __iomem *ixp4xx_ioremap_caller(phys_addr_t addr, size_t size,
409 unsigned int mtype, void *caller)
411 if (!is_pci_memory(addr))
412 return __arm_ioremap_caller(addr, size, mtype, caller);
414 return (void __iomem *)addr;
417 static void ixp4xx_iounmap(volatile void __iomem *addr)
419 if (!is_pci_memory((__force u32)addr))
424 void __init ixp4xx_init_early(void)
426 platform_notify = ixp4xx_platform_notify;
428 platform_notify_remove = ixp4xx_platform_notify_remove;
430 #ifdef CONFIG_IXP4XX_INDIRECT_PCI
431 arch_ioremap_caller = ixp4xx_ioremap_caller;
432 arch_iounmap = ixp4xx_iounmap;