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/syscore_ops.h>
28 #include <linux/amba/bus.h>
29 #include <linux/amba/kmi.h>
31 #include <linux/irqchip.h>
32 #include <linux/mtd/physmap.h>
33 #include <linux/platform_data/clk-integrator.h>
34 #include <linux/of_irq.h>
35 #include <linux/of_address.h>
36 #include <linux/of_platform.h>
37 #include <linux/stat.h>
38 #include <linux/termios.h>
40 #include <asm/setup.h>
41 #include <asm/param.h> /* HZ */
42 #include <asm/mach-types.h>
44 #include <asm/mach/arch.h>
45 #include <asm/mach/irq.h>
46 #include <asm/mach/map.h>
47 #include <asm/mach/time.h>
55 /* Base address to the AP system controller */
56 void __iomem
*ap_syscon_base
;
57 /* Base address to the external bus interface */
58 static void __iomem
*ebi_base
;
62 * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
65 * Setup a VA for the Integrator interrupt controller (for header #0,
68 #define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE)
72 * ef000000 Cache flush
73 * f1100000 11000000 System controller registers
74 * f1300000 13000000 Counter/Timer
75 * f1400000 14000000 Interrupt controller
76 * f1600000 16000000 UART 0
77 * f1700000 17000000 UART 1
78 * f1a00000 1a000000 Debug LEDs
79 * f1b00000 1b000000 GPIO
82 static struct map_desc ap_io_desc
[] __initdata __maybe_unused
= {
84 .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE
),
85 .pfn
= __phys_to_pfn(INTEGRATOR_IC_BASE
),
89 .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE
),
90 .pfn
= __phys_to_pfn(INTEGRATOR_UART0_BASE
),
94 .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE
),
95 .pfn
= __phys_to_pfn(INTEGRATOR_DBG_BASE
),
99 .virtual = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE
),
100 .pfn
= __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE
),
106 static void __init
ap_map_io(void)
108 iotable_init(ap_io_desc
, ARRAY_SIZE(ap_io_desc
));
113 static unsigned long ic_irq_enable
;
115 static int irq_suspend(void)
117 ic_irq_enable
= readl(VA_IC_BASE
+ IRQ_ENABLE
);
121 static void irq_resume(void)
123 /* disable all irq sources */
125 writel(-1, VA_IC_BASE
+ IRQ_ENABLE_CLEAR
);
126 writel(-1, VA_IC_BASE
+ FIQ_ENABLE_CLEAR
);
128 writel(ic_irq_enable
, VA_IC_BASE
+ IRQ_ENABLE_SET
);
131 #define irq_suspend NULL
132 #define irq_resume NULL
135 static struct syscore_ops irq_syscore_ops
= {
136 .suspend
= irq_suspend
,
137 .resume
= irq_resume
,
140 static int __init
irq_syscore_init(void)
142 register_syscore_ops(&irq_syscore_ops
);
147 device_initcall(irq_syscore_init
);
152 static int ap_flash_init(struct platform_device
*dev
)
156 writel(INTEGRATOR_SC_CTRL_nFLVPPEN
| INTEGRATOR_SC_CTRL_nFLWP
,
157 ap_syscon_base
+ INTEGRATOR_SC_CTRLC_OFFSET
);
159 tmp
= readl(ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
) |
160 INTEGRATOR_EBI_WRITE_ENABLE
;
161 writel(tmp
, ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
);
163 if (!(readl(ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
)
164 & INTEGRATOR_EBI_WRITE_ENABLE
)) {
165 writel(0xa05f, ebi_base
+ INTEGRATOR_EBI_LOCK_OFFSET
);
166 writel(tmp
, ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
);
167 writel(0, ebi_base
+ INTEGRATOR_EBI_LOCK_OFFSET
);
172 static void ap_flash_exit(struct platform_device
*dev
)
176 writel(INTEGRATOR_SC_CTRL_nFLVPPEN
| INTEGRATOR_SC_CTRL_nFLWP
,
177 ap_syscon_base
+ INTEGRATOR_SC_CTRLC_OFFSET
);
179 tmp
= readl(ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
) &
180 ~INTEGRATOR_EBI_WRITE_ENABLE
;
181 writel(tmp
, ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
);
183 if (readl(ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
) &
184 INTEGRATOR_EBI_WRITE_ENABLE
) {
185 writel(0xa05f, ebi_base
+ INTEGRATOR_EBI_LOCK_OFFSET
);
186 writel(tmp
, ebi_base
+ INTEGRATOR_EBI_CSR1_OFFSET
);
187 writel(0, ebi_base
+ INTEGRATOR_EBI_LOCK_OFFSET
);
191 static void ap_flash_set_vpp(struct platform_device
*pdev
, int on
)
194 writel(INTEGRATOR_SC_CTRL_nFLVPPEN
,
195 ap_syscon_base
+ INTEGRATOR_SC_CTRLS_OFFSET
);
197 writel(INTEGRATOR_SC_CTRL_nFLVPPEN
,
198 ap_syscon_base
+ INTEGRATOR_SC_CTRLC_OFFSET
);
201 static struct physmap_flash_data ap_flash_data
= {
203 .init
= ap_flash_init
,
204 .exit
= ap_flash_exit
,
205 .set_vpp
= ap_flash_set_vpp
,
209 * For the PL010 found in the Integrator/AP some of the UART control is
210 * implemented in the system controller and accessed using a callback
213 static void integrator_uart_set_mctrl(struct amba_device
*dev
,
214 void __iomem
*base
, unsigned int mctrl
)
216 unsigned int ctrls
= 0, ctrlc
= 0, rts_mask
, dtr_mask
;
217 u32 phybase
= dev
->res
.start
;
219 if (phybase
== INTEGRATOR_UART0_BASE
) {
229 if (mctrl
& TIOCM_RTS
)
234 if (mctrl
& TIOCM_DTR
)
239 __raw_writel(ctrls
, ap_syscon_base
+ INTEGRATOR_SC_CTRLS_OFFSET
);
240 __raw_writel(ctrlc
, ap_syscon_base
+ INTEGRATOR_SC_CTRLC_OFFSET
);
243 struct amba_pl010_data ap_uart_data
= {
244 .set_mctrl
= integrator_uart_set_mctrl
,
247 void __init
ap_init_early(void)
251 static void __init
ap_init_irq_of(void)
257 /* For the Device Tree, add in the UART callbacks as AUXDATA */
258 static struct of_dev_auxdata ap_auxdata_lookup
[] __initdata
= {
259 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_RTC_BASE
,
261 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE
,
262 "uart0", &ap_uart_data
),
263 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE
,
264 "uart1", &ap_uart_data
),
265 OF_DEV_AUXDATA("arm,primecell", KMI0_BASE
,
267 OF_DEV_AUXDATA("arm,primecell", KMI1_BASE
,
269 OF_DEV_AUXDATA("cfi-flash", INTEGRATOR_FLASH_BASE
,
270 "physmap-flash", &ap_flash_data
),
274 static const struct of_device_id ap_syscon_match
[] = {
275 { .compatible
= "arm,integrator-ap-syscon"},
279 static const struct of_device_id ebi_match
[] = {
280 { .compatible
= "arm,external-bus-interface"},
284 static void __init
ap_init_of(void)
286 unsigned long sc_dec
;
287 struct device_node
*syscon
;
288 struct device_node
*ebi
;
291 syscon
= of_find_matching_node(NULL
, ap_syscon_match
);
294 ebi
= of_find_matching_node(NULL
, ebi_match
);
298 ap_syscon_base
= of_iomap(syscon
, 0);
301 ebi_base
= of_iomap(ebi
, 0);
305 of_platform_populate(NULL
, of_default_bus_match_table
,
306 ap_auxdata_lookup
, NULL
);
308 sc_dec
= readl(ap_syscon_base
+ INTEGRATOR_SC_DEC_OFFSET
);
309 for (i
= 0; i
< 4; i
++) {
310 struct lm_device
*lmdev
;
312 if ((sc_dec
& (16 << i
)) == 0)
315 lmdev
= kzalloc(sizeof(struct lm_device
), GFP_KERNEL
);
319 lmdev
->resource
.start
= 0xc0000000 + 0x10000000 * i
;
320 lmdev
->resource
.end
= lmdev
->resource
.start
+ 0x0fffffff;
321 lmdev
->resource
.flags
= IORESOURCE_MEM
;
322 lmdev
->irq
= irq_of_parse_and_map(syscon
, i
);
325 lm_device_register(lmdev
);
329 static const char * ap_dt_board_compat
[] = {
334 DT_MACHINE_START(INTEGRATOR_AP_DT
, "ARM Integrator/AP (Device Tree)")
335 .reserve
= integrator_reserve
,
337 .init_early
= ap_init_early
,
338 .init_irq
= ap_init_irq_of
,
339 .init_machine
= ap_init_of
,
340 .dt_compat
= ap_dt_board_compat
,