blob: 5b0e363fe5ba525dcf05af4a2cf28d8a20d62c8d [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/setup.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080041#include <asm/param.h> /* HZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/mach/arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/mach/irq.h>
46#include <asm/mach/map.h>
47#include <asm/mach/time.h>
48
Linus Walleij1b1ef752014-02-13 21:26:24 +010049#include "hardware.h"
Linus Walleijbb4dbef2013-06-16 02:44:27 +020050#include "cm.h"
Russell King98c672c2010-05-22 18:18:57 +010051#include "common.h"
Linus Walleijae9daf22013-03-19 19:58:49 +010052#include "pci_v3.h"
Linus Walleijc36928a2014-02-13 20:01:41 +010053#include "lm.h"
Russell King98c672c2010-05-22 18:18:57 +010054
Linus Walleij83feba52012-11-04 20:49:15 +010055/* Base address to the AP system controller */
Linus Walleij379df272012-11-17 19:24:23 +010056void __iomem *ap_syscon_base;
Linus Walleij307b9662013-06-17 23:58:25 +020057/* Base address to the external bus interface */
58static void __iomem *ebi_base;
Linus Walleij83feba52012-11-04 20:49:15 +010059
Linus Walleij83feba52012-11-04 20:49:15 +010060
61/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
63 * is the (PA >> 12).
64 *
65 * Setup a VA for the Integrator interrupt controller (for header #0,
66 * just for now).
67 */
Russell Kingc41b16f2011-01-19 15:32:15 +000068#define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/*
71 * Logical Physical
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * ef000000 Cache flush
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 * f1100000 11000000 System controller registers
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 * 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
80 */
81
Arnd Bergmann060fd1b2013-02-14 13:50:57 +010082static struct map_desc ap_io_desc[] __initdata __maybe_unused = {
Deepak Saxenac8d27292005-10-28 15:19:10 +010083 {
Deepak Saxenac8d27292005-10-28 15:19:10 +010084 .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
85 .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
86 .length = SZ_4K,
87 .type = MT_DEVICE
88 }, {
89 .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
90 .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
91 .length = SZ_4K,
92 .type = MT_DEVICE
93 }, {
Deepak Saxenac8d27292005-10-28 15:19:10 +010094 .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
95 .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
96 .length = SZ_4K,
97 .type = MT_DEVICE
98 }, {
Russell Kingda7ba952010-01-17 19:59:58 +000099 .virtual = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE),
100 .pfn = __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE),
Deepak Saxenac8d27292005-10-28 15:19:10 +0100101 .length = SZ_4K,
102 .type = MT_DEVICE
Deepak Saxenac8d27292005-10-28 15:19:10 +0100103 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104};
105
106static void __init ap_map_io(void)
107{
108 iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
Linus Walleijae9daf22013-03-19 19:58:49 +0100109 pci_v3_early_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#ifdef CONFIG_PM
113static unsigned long ic_irq_enable;
114
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200115static int irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
118 return 0;
119}
120
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200121static void irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 /* disable all irq sources */
Linus Walleijbb4dbef2013-06-16 02:44:27 +0200124 cm_clear_irqs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
126 writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
127
128 writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130#else
131#define irq_suspend NULL
132#define irq_resume NULL
133#endif
134
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200135static struct syscore_ops irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .suspend = irq_suspend,
137 .resume = irq_resume,
138};
139
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200140static int __init irq_syscore_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200142 register_syscore_ops(&irq_syscore_ops);
143
144 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200147device_initcall(irq_syscore_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149/*
150 * Flash handling.
151 */
Marc Zyngierf07e7622011-05-18 10:51:52 +0100152static int ap_flash_init(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 u32 tmp;
155
Linus Walleij83feba52012-11-04 20:49:15 +0100156 writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP,
157 ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Linus Walleij307b9662013-06-17 23:58:25 +0200159 tmp = readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET) |
160 INTEGRATOR_EBI_WRITE_ENABLE;
161 writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Linus Walleij307b9662013-06-17 23:58:25 +0200163 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169 return 0;
170}
171
Marc Zyngierf07e7622011-05-18 10:51:52 +0100172static void ap_flash_exit(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 u32 tmp;
175
Linus Walleij83feba52012-11-04 20:49:15 +0100176 writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP,
177 ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Linus Walleij307b9662013-06-17 23:58:25 +0200179 tmp = readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET) &
180 ~INTEGRATOR_EBI_WRITE_ENABLE;
181 writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Linus Walleij307b9662013-06-17 23:58:25 +0200183 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189}
190
Marc Zyngier667f3902011-05-18 10:51:55 +0100191static void ap_flash_set_vpp(struct platform_device *pdev, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Linus Walleij83feba52012-11-04 20:49:15 +0100193 if (on)
194 writel(INTEGRATOR_SC_CTRL_nFLVPPEN,
195 ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
196 else
197 writel(INTEGRATOR_SC_CTRL_nFLVPPEN,
198 ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
Marc Zyngierf07e7622011-05-18 10:51:52 +0100201static struct physmap_flash_data ap_flash_data = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 .width = 4,
203 .init = ap_flash_init,
204 .exit = ap_flash_exit,
205 .set_vpp = ap_flash_set_vpp,
206};
207
Russell King6be48262010-01-17 16:20:56 +0000208/*
Linus Walleij379df272012-11-17 19:24:23 +0100209 * 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
211 * from the driver.
212 */
213static void integrator_uart_set_mctrl(struct amba_device *dev,
214 void __iomem *base, unsigned int mctrl)
215{
216 unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
217 u32 phybase = dev->res.start;
218
219 if (phybase == INTEGRATOR_UART0_BASE) {
220 /* UART0 */
221 rts_mask = 1 << 4;
222 dtr_mask = 1 << 5;
223 } else {
224 /* UART1 */
225 rts_mask = 1 << 6;
226 dtr_mask = 1 << 7;
227 }
228
229 if (mctrl & TIOCM_RTS)
230 ctrlc |= rts_mask;
231 else
232 ctrls |= rts_mask;
233
234 if (mctrl & TIOCM_DTR)
235 ctrlc |= dtr_mask;
236 else
237 ctrls |= dtr_mask;
238
239 __raw_writel(ctrls, ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
240 __raw_writel(ctrlc, ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
241}
242
243struct amba_pl010_data ap_uart_data = {
244 .set_mctrl = integrator_uart_set_mctrl,
245};
246
Linus Walleija6131632012-06-11 17:33:12 +0200247void __init ap_init_early(void)
248{
249}
250
Linus Walleij4980f9b2012-09-06 09:08:24 +0100251static void __init ap_init_irq_of(void)
252{
Linus Walleijbb4dbef2013-06-16 02:44:27 +0200253 cm_init();
Rob Herring44fa72d2014-05-29 16:44:27 -0500254 irqchip_init();
Linus Walleij4980f9b2012-09-06 09:08:24 +0100255}
256
Linus Walleij4672cdd2012-09-06 09:08:47 +0100257/* For the Device Tree, add in the UART callbacks as AUXDATA */
258static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = {
259 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_RTC_BASE,
260 "rtc", NULL),
261 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE,
Linus Walleij379df272012-11-17 19:24:23 +0100262 "uart0", &ap_uart_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100263 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE,
Linus Walleij379df272012-11-17 19:24:23 +0100264 "uart1", &ap_uart_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100265 OF_DEV_AUXDATA("arm,primecell", KMI0_BASE,
266 "kmi0", NULL),
267 OF_DEV_AUXDATA("arm,primecell", KMI1_BASE,
268 "kmi1", NULL),
Linus Walleij73efd532012-09-06 09:09:11 +0100269 OF_DEV_AUXDATA("cfi-flash", INTEGRATOR_FLASH_BASE,
270 "physmap-flash", &ap_flash_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100271 { /* sentinel */ },
272};
273
Linus Walleijdf366802013-10-10 18:24:58 +0200274static const struct of_device_id ap_syscon_match[] = {
275 { .compatible = "arm,integrator-ap-syscon"},
276 { },
277};
278
Linus Walleij307b9662013-06-17 23:58:25 +0200279static const struct of_device_id ebi_match[] = {
280 { .compatible = "arm,external-bus-interface"},
281 { },
282};
283
Linus Walleij4672cdd2012-09-06 09:08:47 +0100284static void __init ap_init_of(void)
285{
286 unsigned long sc_dec;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100287 struct device_node *syscon;
Linus Walleij307b9662013-06-17 23:58:25 +0200288 struct device_node *ebi;
Linus Walleij4672cdd2012-09-06 09:08:47 +0100289 int i;
290
Linus Walleij11f93232014-06-24 14:08:07 +0200291 syscon = of_find_matching_node(NULL, ap_syscon_match);
Linus Walleije67ae6b2012-11-02 01:31:10 +0100292 if (!syscon)
293 return;
Linus Walleij11f93232014-06-24 14:08:07 +0200294 ebi = of_find_matching_node(NULL, ebi_match);
Linus Walleij307b9662013-06-17 23:58:25 +0200295 if (!ebi)
296 return;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100297
298 ap_syscon_base = of_iomap(syscon, 0);
299 if (!ap_syscon_base)
300 return;
Linus Walleij307b9662013-06-17 23:58:25 +0200301 ebi_base = of_iomap(ebi, 0);
302 if (!ebi_base)
303 return;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100304
Linus Walleij11f93232014-06-24 14:08:07 +0200305 of_platform_populate(NULL, of_default_bus_match_table,
306 ap_auxdata_lookup, NULL);
307
Linus Walleij83feba52012-11-04 20:49:15 +0100308 sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET);
Linus Walleij4672cdd2012-09-06 09:08:47 +0100309 for (i = 0; i < 4; i++) {
310 struct lm_device *lmdev;
311
312 if ((sc_dec & (16 << i)) == 0)
313 continue;
314
315 lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
316 if (!lmdev)
317 continue;
318
319 lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
320 lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
321 lmdev->resource.flags = IORESOURCE_MEM;
Linus Walleija6720252013-06-15 23:56:32 +0200322 lmdev->irq = irq_of_parse_and_map(syscon, i);
Linus Walleij4672cdd2012-09-06 09:08:47 +0100323 lmdev->id = i;
324
325 lm_device_register(lmdev);
326 }
327}
328
Linus Walleij4980f9b2012-09-06 09:08:24 +0100329static const char * ap_dt_board_compat[] = {
330 "arm,integrator-ap",
331 NULL,
332};
333
334DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
335 .reserve = integrator_reserve,
336 .map_io = ap_map_io,
Linus Walleij4980f9b2012-09-06 09:08:24 +0100337 .init_early = ap_init_early,
338 .init_irq = ap_init_irq_of,
Linus Walleij4672cdd2012-09-06 09:08:47 +0100339 .init_machine = ap_init_of,
Linus Walleij4980f9b2012-09-06 09:08:24 +0100340 .dt_compat = ap_dt_board_compat,
341MACHINE_END