blob: 23b98fd414bf81f7f9acff6a18974a237eccf19b [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/kernel.h>
21#include <linux/init.h>
Rafael J. Wysockib7808052011-04-22 22:02:55 +020022#include <linux/syscore_ops.h>
Russell Kinga62c80e2006-01-07 13:52:45 +000023#include <linux/amba/bus.h>
Russell Kingfced80c2008-09-06 12:10:45 +010024#include <linux/io.h>
Rob Herring44fa72d2014-05-29 16:44:27 -050025#include <linux/irqchip.h>
Linus Walleij4980f9b2012-09-06 09:08:24 +010026#include <linux/of_irq.h>
27#include <linux/of_address.h>
Linus Walleij4672cdd2012-09-06 09:08:47 +010028#include <linux/of_platform.h>
Linus Walleij379df272012-11-17 19:24:23 +010029#include <linux/termios.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/mach/arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/mach/map.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Linus Walleij1b1ef752014-02-13 21:26:24 +010034#include "hardware.h"
Linus Walleijbb4dbef2013-06-16 02:44:27 +020035#include "cm.h"
Russell King98c672c2010-05-22 18:18:57 +010036#include "common.h"
Linus Walleijae9daf22013-03-19 19:58:49 +010037#include "pci_v3.h"
Linus Walleijc36928a2014-02-13 20:01:41 +010038#include "lm.h"
Russell King98c672c2010-05-22 18:18:57 +010039
Linus Walleij83feba52012-11-04 20:49:15 +010040/* Base address to the AP system controller */
Linus Walleij379df272012-11-17 19:24:23 +010041void __iomem *ap_syscon_base;
Linus Walleij307b9662013-06-17 23:58:25 +020042/* Base address to the external bus interface */
43static void __iomem *ebi_base;
Linus Walleij83feba52012-11-04 20:49:15 +010044
Linus Walleij83feba52012-11-04 20:49:15 +010045
46/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
48 * is the (PA >> 12).
49 *
50 * Setup a VA for the Integrator interrupt controller (for header #0,
51 * just for now).
52 */
Russell Kingc41b16f2011-01-19 15:32:15 +000053#define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/*
56 * Logical Physical
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 * f1400000 14000000 Interrupt controller
58 * f1600000 16000000 UART 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 */
60
Arnd Bergmann060fd1b2013-02-14 13:50:57 +010061static struct map_desc ap_io_desc[] __initdata __maybe_unused = {
Deepak Saxenac8d27292005-10-28 15:19:10 +010062 {
Deepak Saxenac8d27292005-10-28 15:19:10 +010063 .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
64 .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
65 .length = SZ_4K,
66 .type = MT_DEVICE
67 }, {
68 .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
69 .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
70 .length = SZ_4K,
71 .type = MT_DEVICE
Deepak Saxenac8d27292005-10-28 15:19:10 +010072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
74
75static void __init ap_map_io(void)
76{
77 iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
Linus Walleijae9daf22013-03-19 19:58:49 +010078 pci_v3_early_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#ifdef CONFIG_PM
82static unsigned long ic_irq_enable;
83
Rafael J. Wysockib7808052011-04-22 22:02:55 +020084static int irq_suspend(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
87 return 0;
88}
89
Rafael J. Wysockib7808052011-04-22 22:02:55 +020090static void irq_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 /* disable all irq sources */
Linus Walleijbb4dbef2013-06-16 02:44:27 +020093 cm_clear_irqs();
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
95 writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
96
97 writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99#else
100#define irq_suspend NULL
101#define irq_resume NULL
102#endif
103
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200104static struct syscore_ops irq_syscore_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .suspend = irq_suspend,
106 .resume = irq_resume,
107};
108
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200109static int __init irq_syscore_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200111 register_syscore_ops(&irq_syscore_ops);
112
113 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Rafael J. Wysockib7808052011-04-22 22:02:55 +0200116device_initcall(irq_syscore_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/*
Linus Walleij379df272012-11-17 19:24:23 +0100119 * For the PL010 found in the Integrator/AP some of the UART control is
120 * implemented in the system controller and accessed using a callback
121 * from the driver.
122 */
123static void integrator_uart_set_mctrl(struct amba_device *dev,
124 void __iomem *base, unsigned int mctrl)
125{
126 unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
127 u32 phybase = dev->res.start;
128
129 if (phybase == INTEGRATOR_UART0_BASE) {
130 /* UART0 */
131 rts_mask = 1 << 4;
132 dtr_mask = 1 << 5;
133 } else {
134 /* UART1 */
135 rts_mask = 1 << 6;
136 dtr_mask = 1 << 7;
137 }
138
139 if (mctrl & TIOCM_RTS)
140 ctrlc |= rts_mask;
141 else
142 ctrls |= rts_mask;
143
144 if (mctrl & TIOCM_DTR)
145 ctrlc |= dtr_mask;
146 else
147 ctrls |= dtr_mask;
148
149 __raw_writel(ctrls, ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
150 __raw_writel(ctrlc, ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
151}
152
153struct amba_pl010_data ap_uart_data = {
154 .set_mctrl = integrator_uart_set_mctrl,
155};
156
Linus Walleija6131632012-06-11 17:33:12 +0200157void __init ap_init_early(void)
158{
159}
160
Linus Walleij4980f9b2012-09-06 09:08:24 +0100161static void __init ap_init_irq_of(void)
162{
Linus Walleijbb4dbef2013-06-16 02:44:27 +0200163 cm_init();
Rob Herring44fa72d2014-05-29 16:44:27 -0500164 irqchip_init();
Linus Walleij4980f9b2012-09-06 09:08:24 +0100165}
166
Linus Walleij4672cdd2012-09-06 09:08:47 +0100167/* For the Device Tree, add in the UART callbacks as AUXDATA */
168static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = {
Linus Walleij4672cdd2012-09-06 09:08:47 +0100169 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE,
Linus Walleij379df272012-11-17 19:24:23 +0100170 "uart0", &ap_uart_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100171 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE,
Linus Walleij379df272012-11-17 19:24:23 +0100172 "uart1", &ap_uart_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100173 { /* sentinel */ },
174};
175
Linus Walleijdf366802013-10-10 18:24:58 +0200176static const struct of_device_id ap_syscon_match[] = {
177 { .compatible = "arm,integrator-ap-syscon"},
178 { },
179};
180
Linus Walleij307b9662013-06-17 23:58:25 +0200181static const struct of_device_id ebi_match[] = {
182 { .compatible = "arm,external-bus-interface"},
183 { },
184};
185
Linus Walleij4672cdd2012-09-06 09:08:47 +0100186static void __init ap_init_of(void)
187{
188 unsigned long sc_dec;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100189 struct device_node *syscon;
Linus Walleij307b9662013-06-17 23:58:25 +0200190 struct device_node *ebi;
Linus Walleij4672cdd2012-09-06 09:08:47 +0100191 int i;
192
Linus Walleij11f93232014-06-24 14:08:07 +0200193 syscon = of_find_matching_node(NULL, ap_syscon_match);
Linus Walleije67ae6b2012-11-02 01:31:10 +0100194 if (!syscon)
195 return;
Linus Walleij11f93232014-06-24 14:08:07 +0200196 ebi = of_find_matching_node(NULL, ebi_match);
Linus Walleij307b9662013-06-17 23:58:25 +0200197 if (!ebi)
198 return;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100199
200 ap_syscon_base = of_iomap(syscon, 0);
201 if (!ap_syscon_base)
202 return;
Linus Walleij307b9662013-06-17 23:58:25 +0200203 ebi_base = of_iomap(ebi, 0);
204 if (!ebi_base)
205 return;
Linus Walleije67ae6b2012-11-02 01:31:10 +0100206
Kefeng Wang435ebcb2016-06-01 14:53:05 +0800207 of_platform_default_populate(NULL, ap_auxdata_lookup, NULL);
Linus Walleij11f93232014-06-24 14:08:07 +0200208
Linus Walleij83feba52012-11-04 20:49:15 +0100209 sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET);
Linus Walleij4672cdd2012-09-06 09:08:47 +0100210 for (i = 0; i < 4; i++) {
211 struct lm_device *lmdev;
212
213 if ((sc_dec & (16 << i)) == 0)
214 continue;
215
216 lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
217 if (!lmdev)
218 continue;
219
220 lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
221 lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
222 lmdev->resource.flags = IORESOURCE_MEM;
Linus Walleija6720252013-06-15 23:56:32 +0200223 lmdev->irq = irq_of_parse_and_map(syscon, i);
Linus Walleij4672cdd2012-09-06 09:08:47 +0100224 lmdev->id = i;
225
226 lm_device_register(lmdev);
227 }
228}
229
Linus Walleij4980f9b2012-09-06 09:08:24 +0100230static const char * ap_dt_board_compat[] = {
231 "arm,integrator-ap",
232 NULL,
233};
234
235DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
236 .reserve = integrator_reserve,
237 .map_io = ap_map_io,
Linus Walleij4980f9b2012-09-06 09:08:24 +0100238 .init_early = ap_init_early,
239 .init_irq = ap_init_irq_of,
Linus Walleij4672cdd2012-09-06 09:08:47 +0100240 .init_machine = ap_init_of,
Linus Walleij4980f9b2012-09-06 09:08:24 +0100241 .dt_compat = ap_dt_board_compat,
242MACHINE_END