2 * linux/arch/arm/mach-integrator/integrator_ap.c
4 * Copyright (C) 2000-2003 Deep Blue Solutions Ltd
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/types.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/list.h>
24 #include <linux/platform_device.h>
25 #include <linux/slab.h>
26 #include <linux/string.h>
27 #include <linux/sysdev.h>
28 #include <linux/amba/bus.h>
29 #include <linux/amba/kmi.h>
31 #include <asm/hardware.h>
34 #include <asm/setup.h>
35 #include <asm/param.h> /* HZ */
36 #include <asm/mach-types.h>
38 #include <asm/arch/lm.h>
40 #include <asm/mach/arch.h>
41 #include <asm/mach/flash.h>
42 #include <asm/mach/irq.h>
43 #include <asm/mach/map.h>
44 #include <asm/mach/time.h>
49 * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
52 * Setup a VA for the Integrator interrupt controller (for header #0,
55 #define VA_IC_BASE IO_ADDRESS(INTEGRATOR_IC_BASE)
56 #define VA_SC_BASE IO_ADDRESS(INTEGRATOR_SC_BASE)
57 #define VA_EBI_BASE IO_ADDRESS(INTEGRATOR_EBI_BASE)
58 #define VA_CMIC_BASE IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_IC_OFFSET
62 * e8000000 40000000 PCI memory PHYS_PCI_MEM_BASE (max 512M)
63 * ec000000 61000000 PCI config space PHYS_PCI_CONFIG_BASE (max 16M)
64 * ed000000 62000000 PCI V3 regs PHYS_PCI_V3_BASE (max 64k)
65 * ee000000 60000000 PCI IO PHYS_PCI_IO_BASE (max 16M)
66 * ef000000 Cache flush
67 * f1000000 10000000 Core module registers
68 * f1100000 11000000 System controller registers
69 * f1200000 12000000 EBI registers
70 * f1300000 13000000 Counter/Timer
71 * f1400000 14000000 Interrupt controller
72 * f1600000 16000000 UART 0
73 * f1700000 17000000 UART 1
74 * f1a00000 1a000000 Debug LEDs
75 * f1b00000 1b000000 GPIO
78 static struct map_desc ap_io_desc
[] __initdata
= {
80 .virtual = IO_ADDRESS(INTEGRATOR_HDR_BASE
),
81 .pfn
= __phys_to_pfn(INTEGRATOR_HDR_BASE
),
85 .virtual = IO_ADDRESS(INTEGRATOR_SC_BASE
),
86 .pfn
= __phys_to_pfn(INTEGRATOR_SC_BASE
),
90 .virtual = IO_ADDRESS(INTEGRATOR_EBI_BASE
),
91 .pfn
= __phys_to_pfn(INTEGRATOR_EBI_BASE
),
95 .virtual = IO_ADDRESS(INTEGRATOR_CT_BASE
),
96 .pfn
= __phys_to_pfn(INTEGRATOR_CT_BASE
),
100 .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE
),
101 .pfn
= __phys_to_pfn(INTEGRATOR_IC_BASE
),
105 .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE
),
106 .pfn
= __phys_to_pfn(INTEGRATOR_UART0_BASE
),
110 .virtual = IO_ADDRESS(INTEGRATOR_UART1_BASE
),
111 .pfn
= __phys_to_pfn(INTEGRATOR_UART1_BASE
),
115 .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE
),
116 .pfn
= __phys_to_pfn(INTEGRATOR_DBG_BASE
),
120 .virtual = IO_ADDRESS(INTEGRATOR_GPIO_BASE
),
121 .pfn
= __phys_to_pfn(INTEGRATOR_GPIO_BASE
),
125 .virtual = PCI_MEMORY_VADDR
,
126 .pfn
= __phys_to_pfn(PHYS_PCI_MEM_BASE
),
130 .virtual = PCI_CONFIG_VADDR
,
131 .pfn
= __phys_to_pfn(PHYS_PCI_CONFIG_BASE
),
135 .virtual = PCI_V3_VADDR
,
136 .pfn
= __phys_to_pfn(PHYS_PCI_V3_BASE
),
140 .virtual = PCI_IO_VADDR
,
141 .pfn
= __phys_to_pfn(PHYS_PCI_IO_BASE
),
147 static void __init
ap_map_io(void)
149 iotable_init(ap_io_desc
, ARRAY_SIZE(ap_io_desc
));
152 #define INTEGRATOR_SC_VALID_INT 0x003fffff
154 static void sc_mask_irq(unsigned int irq
)
156 writel(1 << irq
, VA_IC_BASE
+ IRQ_ENABLE_CLEAR
);
159 static void sc_unmask_irq(unsigned int irq
)
161 writel(1 << irq
, VA_IC_BASE
+ IRQ_ENABLE_SET
);
164 static struct irq_chip sc_chip
= {
168 .unmask
= sc_unmask_irq
,
171 static void __init
ap_init_irq(void)
175 /* Disable all interrupts initially. */
176 /* Do the core module ones */
177 writel(-1, VA_CMIC_BASE
+ IRQ_ENABLE_CLEAR
);
179 /* do the header card stuff next */
180 writel(-1, VA_IC_BASE
+ IRQ_ENABLE_CLEAR
);
181 writel(-1, VA_IC_BASE
+ FIQ_ENABLE_CLEAR
);
183 for (i
= 0; i
< NR_IRQS
; i
++) {
184 if (((1 << i
) & INTEGRATOR_SC_VALID_INT
) != 0) {
185 set_irq_chip(i
, &sc_chip
);
186 set_irq_handler(i
, handle_level_irq
);
187 set_irq_flags(i
, IRQF_VALID
| IRQF_PROBE
);
193 static unsigned long ic_irq_enable
;
195 static int irq_suspend(struct sys_device
*dev
, pm_message_t state
)
197 ic_irq_enable
= readl(VA_IC_BASE
+ IRQ_ENABLE
);
201 static int irq_resume(struct sys_device
*dev
)
203 /* disable all irq sources */
204 writel(-1, VA_CMIC_BASE
+ IRQ_ENABLE_CLEAR
);
205 writel(-1, VA_IC_BASE
+ IRQ_ENABLE_CLEAR
);
206 writel(-1, VA_IC_BASE
+ FIQ_ENABLE_CLEAR
);
208 writel(ic_irq_enable
, VA_IC_BASE
+ IRQ_ENABLE_SET
);
212 #define irq_suspend NULL
213 #define irq_resume NULL
216 static struct sysdev_class irq_class
= {
218 .suspend
= irq_suspend
,
219 .resume
= irq_resume
,
222 static struct sys_device irq_device
= {
227 static int __init
irq_init_sysfs(void)
229 int ret
= sysdev_class_register(&irq_class
);
231 ret
= sysdev_register(&irq_device
);
235 device_initcall(irq_init_sysfs
);
240 #define SC_CTRLC (VA_SC_BASE + INTEGRATOR_SC_CTRLC_OFFSET)
241 #define SC_CTRLS (VA_SC_BASE + INTEGRATOR_SC_CTRLS_OFFSET)
242 #define EBI_CSR1 (VA_EBI_BASE + INTEGRATOR_EBI_CSR1_OFFSET)
243 #define EBI_LOCK (VA_EBI_BASE + INTEGRATOR_EBI_LOCK_OFFSET)
245 static int ap_flash_init(void)
249 writel(INTEGRATOR_SC_CTRL_nFLVPPEN
| INTEGRATOR_SC_CTRL_nFLWP
, SC_CTRLC
);
251 tmp
= readl(EBI_CSR1
) | INTEGRATOR_EBI_WRITE_ENABLE
;
252 writel(tmp
, EBI_CSR1
);
254 if (!(readl(EBI_CSR1
) & INTEGRATOR_EBI_WRITE_ENABLE
)) {
255 writel(0xa05f, EBI_LOCK
);
256 writel(tmp
, EBI_CSR1
);
262 static void ap_flash_exit(void)
266 writel(INTEGRATOR_SC_CTRL_nFLVPPEN
| INTEGRATOR_SC_CTRL_nFLWP
, SC_CTRLC
);
268 tmp
= readl(EBI_CSR1
) & ~INTEGRATOR_EBI_WRITE_ENABLE
;
269 writel(tmp
, EBI_CSR1
);
271 if (readl(EBI_CSR1
) & INTEGRATOR_EBI_WRITE_ENABLE
) {
272 writel(0xa05f, EBI_LOCK
);
273 writel(tmp
, EBI_CSR1
);
278 static void ap_flash_set_vpp(int on
)
280 unsigned long reg
= on
? SC_CTRLS
: SC_CTRLC
;
282 writel(INTEGRATOR_SC_CTRL_nFLVPPEN
, reg
);
285 static struct flash_platform_data ap_flash_data
= {
286 .map_name
= "cfi_probe",
288 .init
= ap_flash_init
,
289 .exit
= ap_flash_exit
,
290 .set_vpp
= ap_flash_set_vpp
,
293 static struct resource cfi_flash_resource
= {
294 .start
= INTEGRATOR_FLASH_BASE
,
295 .end
= INTEGRATOR_FLASH_BASE
+ INTEGRATOR_FLASH_SIZE
- 1,
296 .flags
= IORESOURCE_MEM
,
299 static struct platform_device cfi_flash_device
= {
303 .platform_data
= &ap_flash_data
,
306 .resource
= &cfi_flash_resource
,
309 static void __init
ap_init(void)
311 unsigned long sc_dec
;
314 platform_device_register(&cfi_flash_device
);
316 sc_dec
= readl(VA_SC_BASE
+ INTEGRATOR_SC_DEC_OFFSET
);
317 for (i
= 0; i
< 4; i
++) {
318 struct lm_device
*lmdev
;
320 if ((sc_dec
& (16 << i
)) == 0)
323 lmdev
= kzalloc(sizeof(struct lm_device
), GFP_KERNEL
);
327 lmdev
->resource
.start
= 0xc0000000 + 0x10000000 * i
;
328 lmdev
->resource
.end
= lmdev
->resource
.start
+ 0x0fffffff;
329 lmdev
->resource
.flags
= IORESOURCE_MEM
;
330 lmdev
->irq
= IRQ_AP_EXPINT0
+ i
;
333 lm_device_register(lmdev
);
337 static void __init
ap_init_timer(void)
339 integrator_time_init(1000000 * TICKS_PER_uSEC
/ HZ
, 0);
342 static struct sys_timer ap_timer
= {
343 .init
= ap_init_timer
,
344 .offset
= integrator_gettimeoffset
,
347 MACHINE_START(INTEGRATOR
, "ARM-Integrator")
348 /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
349 .phys_io
= 0x16000000,
350 .io_pg_offst
= ((0xf1600000) >> 18) & 0xfffc,
351 .boot_params
= 0x00000100,
353 .init_irq
= ap_init_irq
,
355 .init_machine
= ap_init
,