blob: cdcd6d6b6d3db64ee88f80ec158ee6ae2897da59 [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>
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040026#include <linux/export.h>
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +010027#include <linux/cpu.h>
Krzysztof Halasa00e1b3a2014-03-23 01:36:48 +010028#include <linux/pci.h>
Stephen Boyd38ff87f2013-06-01 23:39:40 -070029#include <linux/sched_clock.h>
Linus Walleij98ac0cc2018-12-29 14:30:27 +010030#include <linux/bitops.h>
Linus Walleij55ec4652019-01-25 22:58:39 +010031#include <linux/irqchip/irq-ixp4xx.h>
Linus Walleij65af6662019-01-26 00:51:51 +010032#include <linux/platform_data/timer-ixp4xx.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010033#include <mach/udc.h>
34#include <mach/hardware.h>
Rob Herringf4495882012-03-06 15:01:53 -060035#include <mach/io.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080036#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/pgtable.h>
38#include <asm/page.h>
Linus Walleij98ac0cc2018-12-29 14:30:27 +010039#include <asm/exception.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#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#include <asm/mach/map.h>
43#include <asm/mach/irq.h>
44#include <asm/mach/time.h>
45
Linus Walleijdc8ef8cd2018-12-29 15:47:52 +010046#include "irqs.h"
47
Uwe Kleine-Königf0402f92013-11-26 19:25:59 +010048#define IXP4XX_TIMER_FREQ 66666000
Uwe Kleine-Königfb3174e2014-02-03 11:31:19 +010049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/*************************************************************************
51 * IXP4xx chipset I/O mapping
52 *************************************************************************/
53static struct map_desc ixp4xx_io_desc[] __initdata = {
54 { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
Arnd Bergmann13ec32f2012-09-14 20:19:40 +000055 .virtual = (unsigned long)IXP4XX_PERIPHERAL_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010056 .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 .length = IXP4XX_PERIPHERAL_REGION_SIZE,
58 .type = MT_DEVICE
59 }, { /* Expansion Bus Config Registers */
Arnd Bergmann13ec32f2012-09-14 20:19:40 +000060 .virtual = (unsigned long)IXP4XX_EXP_CFG_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010061 .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 .length = IXP4XX_EXP_CFG_REGION_SIZE,
63 .type = MT_DEVICE
64 }, { /* PCI Registers */
Arnd Bergmann13ec32f2012-09-14 20:19:40 +000065 .virtual = (unsigned long)IXP4XX_PCI_CFG_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010066 .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 .length = IXP4XX_PCI_CFG_REGION_SIZE,
68 .type = MT_DEVICE
Krzysztof Hałasaf0cdb152010-03-26 16:38:52 +010069 }, { /* 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,
73 .type = MT_DEVICE
Deepak Saxena5932ae32005-06-24 20:54:35 +010074 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
77void __init ixp4xx_map_io(void)
78{
79 iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
80}
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082void __init ixp4xx_init_irq(void)
83{
Nicolas Pitre12d2b4e2011-08-03 07:25:39 -040084 /*
85 * ixp4xx does not implement the XScale PWRMODE register
86 * so it must not call cpu_do_idle().
87 */
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +010088 cpu_idle_poll_ctrl(true);
Nicolas Pitre12d2b4e2011-08-03 07:25:39 -040089
Linus Walleij55ec4652019-01-25 22:58:39 +010090 ixp4xx_irq_init(IXP4XX_INTC_BASE_PHYS,
91 (cpu_is_ixp46x() || cpu_is_ixp43x()));
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Michael-Luke Jones435c5da2007-05-23 22:38:45 +010094void __init ixp4xx_timer_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Linus Walleij65af6662019-01-26 00:51:51 +010096 return ixp4xx_timer_setup(IXP4XX_TIMER_BASE_PHYS,
97 IRQ_IXP4XX_TIMER1,
98 IXP4XX_TIMER_FREQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
Milan Svobodae520a362006-12-01 11:36:41 +0100101static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
102
103void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
104{
105 memcpy(&ixp4xx_udc_info, info, sizeof *info);
106}
107
108static struct resource ixp4xx_udc_resources[] = {
109 [0] = {
110 .start = 0xc800b000,
111 .end = 0xc800bfff,
112 .flags = IORESOURCE_MEM,
113 },
114 [1] = {
115 .start = IRQ_IXP4XX_USB,
116 .end = IRQ_IXP4XX_USB,
117 .flags = IORESOURCE_IRQ,
118 },
119};
120
Linus Walleij55ec4652019-01-25 22:58:39 +0100121static struct resource ixp4xx_gpio_resource[] = {
122 {
123 .start = IXP4XX_GPIO_BASE_PHYS,
124 .end = IXP4XX_GPIO_BASE_PHYS + 0xfff,
125 .flags = IORESOURCE_MEM,
126 },
127};
128
129static struct platform_device ixp4xx_gpio_device = {
130 .name = "ixp4xx-gpio",
131 .id = -1,
132 .dev = {
133 .coherent_dma_mask = DMA_BIT_MASK(32),
134 },
135 .resource = ixp4xx_gpio_resource,
136 .num_resources = ARRAY_SIZE(ixp4xx_gpio_resource),
137};
138
Milan Svobodae520a362006-12-01 11:36:41 +0100139/*
Philipp Zabel7a857622008-06-22 23:36:39 +0100140 * USB device controller. The IXP4xx uses the same controller as PXA25X,
Milan Svobodae520a362006-12-01 11:36:41 +0100141 * so we just use the same device.
142 */
143static struct platform_device ixp4xx_udc_device = {
Philipp Zabel7a857622008-06-22 23:36:39 +0100144 .name = "pxa25x-udc",
Milan Svobodae520a362006-12-01 11:36:41 +0100145 .id = -1,
146 .num_resources = 2,
147 .resource = ixp4xx_udc_resources,
148 .dev = {
149 .platform_data = &ixp4xx_udc_info,
150 },
151};
152
Linus Walleijbc4d7ea2019-02-10 17:05:29 +0100153static struct platform_device ixp4xx_npe_device = {
154 .name = "ixp4xx-npe",
155 .id = -1,
156};
157
Linus Walleij81bca322019-02-10 17:14:10 +0100158static struct platform_device ixp4xx_qmgr_device = {
159 .name = "ixp4xx-qmgr",
160 .id = -1,
161};
162
Milan Svobodae520a362006-12-01 11:36:41 +0100163static struct platform_device *ixp4xx_devices[] __initdata = {
Linus Walleijbc4d7ea2019-02-10 17:05:29 +0100164 &ixp4xx_npe_device,
Linus Walleij81bca322019-02-10 17:14:10 +0100165 &ixp4xx_qmgr_device,
Linus Walleij55ec4652019-01-25 22:58:39 +0100166 &ixp4xx_gpio_device,
Milan Svobodae520a362006-12-01 11:36:41 +0100167 &ixp4xx_udc_device,
168};
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170static struct resource ixp46x_i2c_resources[] = {
171 [0] = {
172 .start = 0xc8011000,
173 .end = 0xc801101c,
174 .flags = IORESOURCE_MEM,
175 },
176 [1] = {
177 .start = IRQ_IXP4XX_I2C,
178 .end = IRQ_IXP4XX_I2C,
179 .flags = IORESOURCE_IRQ
180 }
181};
182
183/*
184 * I2C controller. The IXP46x uses the same block as the IOP3xx, so
185 * we just use the same device name.
186 */
187static struct platform_device ixp46x_i2c_controller = {
188 .name = "IOP3xx-I2C",
189 .id = 0,
190 .num_resources = 2,
191 .resource = ixp46x_i2c_resources
192};
193
194static struct platform_device *ixp46x_devices[] __initdata = {
195 &ixp46x_i2c_controller
196};
197
Deepak Saxena54e269e2006-01-05 20:59:29 +0000198unsigned long ixp4xx_exp_bus_size;
David Vrabel1e74c892006-01-18 22:46:43 +0000199EXPORT_SYMBOL(ixp4xx_exp_bus_size);
Deepak Saxena54e269e2006-01-05 20:59:29 +0000200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201void __init ixp4xx_sys_init(void)
202{
Deepak Saxena54e269e2006-01-05 20:59:29 +0000203 ixp4xx_exp_bus_size = SZ_16M;
204
Milan Svobodae520a362006-12-01 11:36:41 +0100205 platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if (cpu_is_ixp46x()) {
Deepak Saxena54e269e2006-01-05 20:59:29 +0000208 int region;
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 platform_add_devices(ixp46x_devices,
211 ARRAY_SIZE(ixp46x_devices));
Deepak Saxena54e269e2006-01-05 20:59:29 +0000212
213 for (region = 0; region < 7; region++) {
214 if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
215 ixp4xx_exp_bus_size = SZ_32M;
216 break;
217 }
218 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
Deepak Saxena54e269e2006-01-05 20:59:29 +0000220
David Vrabel1e74c892006-01-18 22:46:43 +0000221 printk("IXP4xx: Using %luMiB expansion bus window size\n",
Deepak Saxena54e269e2006-01-05 20:59:29 +0000222 ixp4xx_exp_bus_size >> 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Ben Hutchingse66a0222010-12-11 20:17:54 +0000225unsigned long ixp4xx_timer_freq = IXP4XX_TIMER_FREQ;
Krzysztof Halasa5dbc4652009-09-05 03:59:49 +0000226EXPORT_SYMBOL(ixp4xx_timer_freq);
Russell Kingd1b860f2011-11-05 12:10:55 +0000227
Robin Holt7b6d8642013-07-08 16:01:40 -0700228void ixp4xx_restart(enum reboot_mode mode, const char *cmd)
Russell Kingd1b860f2011-11-05 12:10:55 +0000229{
Krzysztof Hałasa97e81ac2014-01-02 09:34:10 +0100230 if (mode == REBOOT_SOFT) {
Russell Kingd1b860f2011-11-05 12:10:55 +0000231 /* Jump into ROM at address 0 */
232 soft_restart(0);
233 } else {
234 /* Use on-chip reset capability */
235
236 /* set the "key" register to enable access to
237 * "timer" and "enable" registers
238 */
239 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
240
241 /* write 0 to the timer register for an immediate reset */
242 *IXP4XX_OSWT = 0;
243
244 *IXP4XX_OSWE = IXP4XX_WDT_RESET_ENABLE | IXP4XX_WDT_COUNT_ENABLE;
245 }
246}
Rob Herringf4495882012-03-06 15:01:53 -0600247
Krzysztof Halasa00e1b3a2014-03-23 01:36:48 +0100248#ifdef CONFIG_PCI
249static int ixp4xx_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
250{
251 return (dma_addr + size) > SZ_64M;
252}
253
254static int ixp4xx_platform_notify_remove(struct device *dev)
255{
256 if (dev_is_pci(dev))
257 dmabounce_unregister_dev(dev);
258
259 return 0;
260}
261#endif
262
263/*
264 * Setup DMA mask to 64MB on PCI devices and 4 GB on all other things.
265 */
266static int ixp4xx_platform_notify(struct device *dev)
267{
268 dev->dma_mask = &dev->coherent_dma_mask;
269
270#ifdef CONFIG_PCI
271 if (dev_is_pci(dev)) {
272 dev->coherent_dma_mask = DMA_BIT_MASK(28); /* 64 MB */
273 dmabounce_register_dev(dev, 2048, 4096, ixp4xx_needs_bounce);
274 return 0;
275 }
276#endif
277
278 dev->coherent_dma_mask = DMA_BIT_MASK(32);
279 return 0;
280}
281
282int dma_set_coherent_mask(struct device *dev, u64 mask)
283{
284 if (dev_is_pci(dev))
285 mask &= DMA_BIT_MASK(28); /* 64 MB */
286
287 if ((mask & DMA_BIT_MASK(28)) == DMA_BIT_MASK(28)) {
288 dev->coherent_dma_mask = mask;
289 return 0;
290 }
291
292 return -EIO; /* device wanted sub-64MB mask */
293}
294EXPORT_SYMBOL(dma_set_coherent_mask);
295
Rob Herringf4495882012-03-06 15:01:53 -0600296#ifdef CONFIG_IXP4XX_INDIRECT_PCI
297/*
298 * In the case of using indirect PCI, we simply return the actual PCI
299 * address and our read/write implementation use that to drive the
300 * access registers. If something outside of PCI is ioremap'd, we
301 * fallback to the default.
302 */
303
Laura Abbott9b971732013-05-16 19:40:22 +0100304static void __iomem *ixp4xx_ioremap_caller(phys_addr_t addr, size_t size,
Rob Herringf4495882012-03-06 15:01:53 -0600305 unsigned int mtype, void *caller)
306{
307 if (!is_pci_memory(addr))
308 return __arm_ioremap_caller(addr, size, mtype, caller);
309
310 return (void __iomem *)addr;
311}
312
Arnd Bergmanne43b21c2014-11-10 15:10:32 +0100313static void ixp4xx_iounmap(volatile void __iomem *addr)
Rob Herringf4495882012-03-06 15:01:53 -0600314{
315 if (!is_pci_memory((__force u32)addr))
316 __iounmap(addr);
317}
Krzysztof Halasa00e1b3a2014-03-23 01:36:48 +0100318#endif
Rob Herringf4495882012-03-06 15:01:53 -0600319
320void __init ixp4xx_init_early(void)
321{
Krzysztof Halasa00e1b3a2014-03-23 01:36:48 +0100322 platform_notify = ixp4xx_platform_notify;
323#ifdef CONFIG_PCI
324 platform_notify_remove = ixp4xx_platform_notify_remove;
325#endif
326#ifdef CONFIG_IXP4XX_INDIRECT_PCI
Rob Herringf4495882012-03-06 15:01:53 -0600327 arch_ioremap_caller = ixp4xx_ioremap_caller;
328 arch_iounmap = ixp4xx_iounmap;
Rob Herringf4495882012-03-06 15:01:53 -0600329#endif
Krzysztof Halasa00e1b3a2014-03-23 01:36:48 +0100330}