blob: 30003ba447a580563428a644ca93d22c9865ea2e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-integrator/integrator_ap.c
3 *
4 * Copyright (C) 2000-2003 Deep Blue Solutions Ltd
5 *
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.
10 *
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.
15 *
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
19 */
20#include <linux/types.h>
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/list.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010024#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/slab.h>
26#include <linux/string.h>
Rafael J. Wysockib7808052011-04-22 22:02:55 +020027#include <linux/syscore_ops.h>
Russell Kinga62c80e2006-01-07 13:52:45 +000028#include <linux/amba/bus.h>
29#include <linux/amba/kmi.h>
Russell Kingfced80c2008-09-06 12:10:45 +010030#include <linux/io.h>
Rob Herring44fa72d2014-05-29 16:44:27 -050031#include <linux/irqchip.h>
Marc Zyngierf07e7622011-05-18 10:51:52 +010032#include <linux/mtd/physmap.h>
Linus Walleija6131632012-06-11 17:33:12 +020033#include <linux/platform_data/clk-integrator.h>
Linus Walleij4980f9b2012-09-06 09:08:24 +010034#include <linux/of_irq.h>
35#include <linux/of_address.h>
Linus Walleij4672cdd2012-09-06 09:08:47 +010036#include <linux/of_platform.h>
Linus Walleije67ae6b2012-11-02 01:31:10 +010037#include <linux/stat.h>
Linus Walleij379df272012-11-17 19:24:23 +010038#include <linux/termios.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Russell King6be48262010-01-17 16:20:56 +000040#include <asm/hardware/arm_timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/setup.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080042#include <asm/param.h> /* HZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/mach/arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/mach/irq.h>
47#include <asm/mach/map.h>
48#include <asm/mach/time.h>
49
Linus Walleij1b1ef752014-02-13 21:26:24 +010050#include "hardware.h"
Linus Walleijbb4dbef2013-06-16 02:44:27 +020051#include "cm.h"
Russell King98c672c2010-05-22 18:18:57 +010052#include "common.h"
Linus Walleijae9daf22013-03-19 19:58:49 +010053#include "pci_v3.h"
Linus Walleijc36928a2014-02-13 20:01:41 +010054#include "lm.h"
Russell King98c672c2010-05-22 18:18:57 +010055
Linus Walleij83feba52012-11-04 20:49:15 +010056/* Base address to the AP system controller */
Linus Walleij379df272012-11-17 19:24:23 +010057void __iomem *ap_syscon_base;
Linus Walleij307b9662013-06-17 23:58:25 +020058/* Base address to the external bus interface */
59static void __iomem *ebi_base;
Linus Walleij83feba52012-11-04 20:49:15 +010060
Linus Walleij83feba52012-11-04 20:49:15 +010061
62/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
64 * is the (PA >> 12).
65 *
66 * Setup a VA for the Integrator interrupt controller (for header #0,
67 * just for now).
68 */
Russell Kingc41b16f2011-01-19 15:32:15 +000069#define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/*
72 * Logical Physical
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 * ef000000 Cache flush
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 * f1100000 11000000 System controller registers
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 * f1300000 13000000 Counter/Timer
76 * f1400000 14000000 Interrupt controller
77 * f1600000 16000000 UART 0
78 * f1700000 17000000 UART 1
79 * f1a00000 1a000000 Debug LEDs
80 * f1b00000 1b000000 GPIO
81 */
82
Arnd Bergmann060fd1b2013-02-14 13:50:57 +010083static struct map_desc ap_io_desc[] __initdata __maybe_unused = {
Deepak Saxenac8d27292005-10-28 15:19:10 +010084 {
Deepak Saxenac8d27292005-10-28 15:19:10 +010085 .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
86 .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
87 .length = SZ_4K,
88 .type = MT_DEVICE
89 }, {
90 .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
91 .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
92 .length = SZ_4K,
93 .type = MT_DEVICE
94 }, {
Deepak Saxenac8d27292005-10-28 15:19:10 +010095 .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
96 .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
97 .length = SZ_4K,
98 .type = MT_DEVICE
99 }, {
Russell Kingda7ba952010-01-17 19:59:58 +0000100 .virtual = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE),
101 .pfn = __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE),
Deepak Saxenac8d27292005-10-28 15:19:10 +0100102 .length = SZ_4K,
103 .type = MT_DEVICE
Deepak Saxenac8d27292005-10-28 15:19:10 +0100104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
107static void __init ap_map_io(void)
108{
109 iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
Linus Walleijae9daf22013-03-19 19:58:49 +0100110 pci_v3_early_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#ifdef CONFIG_PM
114static unsigned long ic_irq_enable;
115
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200116static int irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118 ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
119 return 0;
120}
121
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200122static void irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 /* disable all irq sources */
Linus Walleijbb4dbef2013-06-16 02:44:27 +0200125 cm_clear_irqs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
127 writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
128
129 writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131#else
132#define irq_suspend NULL
133#define irq_resume NULL
134#endif
135
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200136static struct syscore_ops irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 .suspend = irq_suspend,
138 .resume = irq_resume,
139};
140
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200141static int __init irq_syscore_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200143 register_syscore_ops(&irq_syscore_ops);
144
145 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200148device_initcall(irq_syscore_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150/*
151 * Flash handling.
152 */
Marc Zyngierf07e7622011-05-18 10:51:52 +0100153static int ap_flash_init(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 u32 tmp;
156
Linus Walleij83feba52012-11-04 20:49:15 +0100157 writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP,
158 ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Linus Walleij307b9662013-06-17 23:58:25 +0200160 tmp = readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET) |
161 INTEGRATOR_EBI_WRITE_ENABLE;
162 writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Linus Walleij307b9662013-06-17 23:58:25 +0200164 if (!(readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET)
165 & INTEGRATOR_EBI_WRITE_ENABLE)) {
166 writel(0xa05f, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET);
167 writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
168 writel(0, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 }
170 return 0;
171}
172
Marc Zyngierf07e7622011-05-18 10:51:52 +0100173static void ap_flash_exit(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
175 u32 tmp;
176
Linus Walleij83feba52012-11-04 20:49:15 +0100177 writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP,
178 ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Walleij307b9662013-06-17 23:58:25 +0200180 tmp = readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET) &
181 ~INTEGRATOR_EBI_WRITE_ENABLE;
182 writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Linus Walleij307b9662013-06-17 23:58:25 +0200184 if (readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET) &
185 INTEGRATOR_EBI_WRITE_ENABLE) {
186 writel(0xa05f, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET);
187 writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
188 writel(0, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190}
191
Marc Zyngier667f3902011-05-18 10:51:55 +0100192static void ap_flash_set_vpp(struct platform_device *pdev, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
Linus Walleij83feba52012-11-04 20:49:15 +0100194 if (on)
195 writel(INTEGRATOR_SC_CTRL_nFLVPPEN,
196 ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
197 else
198 writel(INTEGRATOR_SC_CTRL_nFLVPPEN,
199 ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
Marc Zyngierf07e7622011-05-18 10:51:52 +0100202static struct physmap_flash_data ap_flash_data = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .width = 4,
204 .init = ap_flash_init,
205 .exit = ap_flash_exit,
206 .set_vpp = ap_flash_set_vpp,
207};
208
Russell King6be48262010-01-17 16:20:56 +0000209/*
Linus Walleij379df272012-11-17 19:24:23 +0100210 * For the PL010 found in the Integrator/AP some of the UART control is
211 * implemented in the system controller and accessed using a callback
212 * from the driver.
213 */
214static void integrator_uart_set_mctrl(struct amba_device *dev,
215 void __iomem *base, unsigned int mctrl)
216{
217 unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
218 u32 phybase = dev->res.start;
219
220 if (phybase == INTEGRATOR_UART0_BASE) {
221 /* UART0 */
222 rts_mask = 1 << 4;
223 dtr_mask = 1 << 5;
224 } else {
225 /* UART1 */
226 rts_mask = 1 << 6;
227 dtr_mask = 1 << 7;
228 }
229
230 if (mctrl & TIOCM_RTS)
231 ctrlc |= rts_mask;
232 else
233 ctrls |= rts_mask;
234
235 if (mctrl & TIOCM_DTR)
236 ctrlc |= dtr_mask;
237 else
238 ctrls |= dtr_mask;
239
240 __raw_writel(ctrls, ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
241 __raw_writel(ctrlc, ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
242}
243
244struct amba_pl010_data ap_uart_data = {
245 .set_mctrl = integrator_uart_set_mctrl,
246};
247
Linus Walleija6131632012-06-11 17:33:12 +0200248void __init ap_init_early(void)
249{
250}
251
Linus Walleij4980f9b2012-09-06 09:08:24 +0100252static void __init ap_init_irq_of(void)
253{
Linus Walleijbb4dbef2013-06-16 02:44:27 +0200254 cm_init();
Rob Herring44fa72d2014-05-29 16:44:27 -0500255 irqchip_init();
Linus Walleij4980f9b2012-09-06 09:08:24 +0100256}
257
Linus Walleij4672cdd2012-09-06 09:08:47 +0100258/* For the Device Tree, add in the UART callbacks as AUXDATA */
259static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = {
260 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_RTC_BASE,
261 "rtc", NULL),
262 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE,
Linus Walleij379df272012-11-17 19:24:23 +0100263 "uart0", &ap_uart_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100264 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE,
Linus Walleij379df272012-11-17 19:24:23 +0100265 "uart1", &ap_uart_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100266 OF_DEV_AUXDATA("arm,primecell", KMI0_BASE,
267 "kmi0", NULL),
268 OF_DEV_AUXDATA("arm,primecell", KMI1_BASE,
269 "kmi1", NULL),
Linus Walleij73efd532012-09-06 09:09:11 +0100270 OF_DEV_AUXDATA("cfi-flash", INTEGRATOR_FLASH_BASE,
271 "physmap-flash", &ap_flash_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100272 { /* sentinel */ },
273};
274
Linus Walleijdf366802013-10-10 18:24:58 +0200275static const struct of_device_id ap_syscon_match[] = {
276 { .compatible = "arm,integrator-ap-syscon"},
277 { },
278};
279
Linus Walleij307b9662013-06-17 23:58:25 +0200280static const struct of_device_id ebi_match[] = {
281 { .compatible = "arm,external-bus-interface"},
282 { },
283};
284
Linus Walleij4672cdd2012-09-06 09:08:47 +0100285static void __init ap_init_of(void)
286{
287 unsigned long sc_dec;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100288 struct device_node *syscon;
Linus Walleij307b9662013-06-17 23:58:25 +0200289 struct device_node *ebi;
Linus Walleij4672cdd2012-09-06 09:08:47 +0100290 int i;
291
Linus Walleij11f93232014-06-24 14:08:07 +0200292 syscon = of_find_matching_node(NULL, ap_syscon_match);
Linus Walleije67ae6b2012-11-02 01:31:10 +0100293 if (!syscon)
294 return;
Linus Walleij11f93232014-06-24 14:08:07 +0200295 ebi = of_find_matching_node(NULL, ebi_match);
Linus Walleij307b9662013-06-17 23:58:25 +0200296 if (!ebi)
297 return;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100298
299 ap_syscon_base = of_iomap(syscon, 0);
300 if (!ap_syscon_base)
301 return;
Linus Walleij307b9662013-06-17 23:58:25 +0200302 ebi_base = of_iomap(ebi, 0);
303 if (!ebi_base)
304 return;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100305
Linus Walleij11f93232014-06-24 14:08:07 +0200306 of_platform_populate(NULL, of_default_bus_match_table,
307 ap_auxdata_lookup, NULL);
308
Linus Walleij83feba52012-11-04 20:49:15 +0100309 sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET);
Linus Walleij4672cdd2012-09-06 09:08:47 +0100310 for (i = 0; i < 4; i++) {
311 struct lm_device *lmdev;
312
313 if ((sc_dec & (16 << i)) == 0)
314 continue;
315
316 lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
317 if (!lmdev)
318 continue;
319
320 lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
321 lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
322 lmdev->resource.flags = IORESOURCE_MEM;
Linus Walleija6720252013-06-15 23:56:32 +0200323 lmdev->irq = irq_of_parse_and_map(syscon, i);
Linus Walleij4672cdd2012-09-06 09:08:47 +0100324 lmdev->id = i;
325
326 lm_device_register(lmdev);
327 }
328}
329
Linus Walleij4980f9b2012-09-06 09:08:24 +0100330static const char * ap_dt_board_compat[] = {
331 "arm,integrator-ap",
332 NULL,
333};
334
335DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
336 .reserve = integrator_reserve,
337 .map_io = ap_map_io,
Linus Walleij4980f9b2012-09-06 09:08:24 +0100338 .init_early = ap_init_early,
339 .init_irq = ap_init_irq_of,
Linus Walleij4672cdd2012-09-06 09:08:47 +0100340 .init_machine = ap_init_of,
Linus Walleij4980f9b2012-09-06 09:08:24 +0100341 .dt_compat = ap_dt_board_compat,
342MACHINE_END