Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/kernel.h> |
| 21 | #include <linux/init.h> |
Rafael J. Wysocki | b780805 | 2011-04-22 22:02:55 +0200 | [diff] [blame] | 22 | #include <linux/syscore_ops.h> |
Russell King | a62c80e | 2006-01-07 13:52:45 +0000 | [diff] [blame] | 23 | #include <linux/amba/bus.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
Rob Herring | 44fa72d | 2014-05-29 16:44:27 -0500 | [diff] [blame] | 25 | #include <linux/irqchip.h> |
Linus Walleij | 4980f9b | 2012-09-06 09:08:24 +0100 | [diff] [blame] | 26 | #include <linux/of_irq.h> |
| 27 | #include <linux/of_address.h> |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 28 | #include <linux/of_platform.h> |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 29 | #include <linux/termios.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/mach/arch.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/mach/map.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Walleij | 1b1ef75 | 2014-02-13 21:26:24 +0100 | [diff] [blame] | 34 | #include "hardware.h" |
Linus Walleij | bb4dbef | 2013-06-16 02:44:27 +0200 | [diff] [blame] | 35 | #include "cm.h" |
Russell King | 98c672c | 2010-05-22 18:18:57 +0100 | [diff] [blame] | 36 | #include "common.h" |
Linus Walleij | ae9daf2 | 2013-03-19 19:58:49 +0100 | [diff] [blame] | 37 | #include "pci_v3.h" |
Linus Walleij | c36928a | 2014-02-13 20:01:41 +0100 | [diff] [blame] | 38 | #include "lm.h" |
Russell King | 98c672c | 2010-05-22 18:18:57 +0100 | [diff] [blame] | 39 | |
Linus Walleij | 83feba5 | 2012-11-04 20:49:15 +0100 | [diff] [blame] | 40 | /* Base address to the AP system controller */ |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 41 | void __iomem *ap_syscon_base; |
Linus Walleij | 307b966 | 2013-06-17 23:58:25 +0200 | [diff] [blame] | 42 | /* Base address to the external bus interface */ |
| 43 | static void __iomem *ebi_base; |
Linus Walleij | 83feba5 | 2012-11-04 20:49:15 +0100 | [diff] [blame] | 44 | |
Linus Walleij | 83feba5 | 2012-11-04 20:49:15 +0100 | [diff] [blame] | 45 | |
| 46 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | * 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 King | c41b16f | 2011-01-19 15:32:15 +0000 | [diff] [blame] | 53 | #define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Logical Physical |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * f1400000 14000000 Interrupt controller |
| 58 | * f1600000 16000000 UART 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | */ |
| 60 | |
Arnd Bergmann | 060fd1b | 2013-02-14 13:50:57 +0100 | [diff] [blame] | 61 | static struct map_desc ap_io_desc[] __initdata __maybe_unused = { |
Deepak Saxena | c8d2729 | 2005-10-28 15:19:10 +0100 | [diff] [blame] | 62 | { |
Deepak Saxena | c8d2729 | 2005-10-28 15:19:10 +0100 | [diff] [blame] | 63 | .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 Saxena | c8d2729 | 2005-10-28 15:19:10 +0100 | [diff] [blame] | 72 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | static void __init ap_map_io(void) |
| 76 | { |
| 77 | iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc)); |
Linus Walleij | ae9daf2 | 2013-03-19 19:58:49 +0100 | [diff] [blame] | 78 | pci_v3_early_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #ifdef CONFIG_PM |
| 82 | static unsigned long ic_irq_enable; |
| 83 | |
Rafael J. Wysocki | b780805 | 2011-04-22 22:02:55 +0200 | [diff] [blame] | 84 | static int irq_suspend(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
| 86 | ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE); |
| 87 | return 0; |
| 88 | } |
| 89 | |
Rafael J. Wysocki | b780805 | 2011-04-22 22:02:55 +0200 | [diff] [blame] | 90 | static void irq_resume(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | /* disable all irq sources */ |
Linus Walleij | bb4dbef | 2013-06-16 02:44:27 +0200 | [diff] [blame] | 93 | cm_clear_irqs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | #else |
| 100 | #define irq_suspend NULL |
| 101 | #define irq_resume NULL |
| 102 | #endif |
| 103 | |
Rafael J. Wysocki | b780805 | 2011-04-22 22:02:55 +0200 | [diff] [blame] | 104 | static struct syscore_ops irq_syscore_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | .suspend = irq_suspend, |
| 106 | .resume = irq_resume, |
| 107 | }; |
| 108 | |
Rafael J. Wysocki | b780805 | 2011-04-22 22:02:55 +0200 | [diff] [blame] | 109 | static int __init irq_syscore_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Rafael J. Wysocki | b780805 | 2011-04-22 22:02:55 +0200 | [diff] [blame] | 111 | register_syscore_ops(&irq_syscore_ops); |
| 112 | |
| 113 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Rafael J. Wysocki | b780805 | 2011-04-22 22:02:55 +0200 | [diff] [blame] | 116 | device_initcall(irq_syscore_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | /* |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 119 | * 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 | */ |
| 123 | static 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 | |
| 153 | struct amba_pl010_data ap_uart_data = { |
| 154 | .set_mctrl = integrator_uart_set_mctrl, |
| 155 | }; |
| 156 | |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 157 | void __init ap_init_early(void) |
| 158 | { |
| 159 | } |
| 160 | |
Linus Walleij | 4980f9b | 2012-09-06 09:08:24 +0100 | [diff] [blame] | 161 | static void __init ap_init_irq_of(void) |
| 162 | { |
Linus Walleij | bb4dbef | 2013-06-16 02:44:27 +0200 | [diff] [blame] | 163 | cm_init(); |
Rob Herring | 44fa72d | 2014-05-29 16:44:27 -0500 | [diff] [blame] | 164 | irqchip_init(); |
Linus Walleij | 4980f9b | 2012-09-06 09:08:24 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 167 | /* For the Device Tree, add in the UART callbacks as AUXDATA */ |
| 168 | static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = { |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 169 | OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE, |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 170 | "uart0", &ap_uart_data), |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 171 | OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE, |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 172 | "uart1", &ap_uart_data), |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 173 | { /* sentinel */ }, |
| 174 | }; |
| 175 | |
Linus Walleij | df36680 | 2013-10-10 18:24:58 +0200 | [diff] [blame] | 176 | static const struct of_device_id ap_syscon_match[] = { |
| 177 | { .compatible = "arm,integrator-ap-syscon"}, |
| 178 | { }, |
| 179 | }; |
| 180 | |
Linus Walleij | 307b966 | 2013-06-17 23:58:25 +0200 | [diff] [blame] | 181 | static const struct of_device_id ebi_match[] = { |
| 182 | { .compatible = "arm,external-bus-interface"}, |
| 183 | { }, |
| 184 | }; |
| 185 | |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 186 | static void __init ap_init_of(void) |
| 187 | { |
| 188 | unsigned long sc_dec; |
Linus Walleij | e67ae6b | 2012-11-02 01:31:10 +0100 | [diff] [blame] | 189 | struct device_node *syscon; |
Linus Walleij | 307b966 | 2013-06-17 23:58:25 +0200 | [diff] [blame] | 190 | struct device_node *ebi; |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 191 | int i; |
| 192 | |
Linus Walleij | 11f9323 | 2014-06-24 14:08:07 +0200 | [diff] [blame] | 193 | syscon = of_find_matching_node(NULL, ap_syscon_match); |
Linus Walleij | e67ae6b | 2012-11-02 01:31:10 +0100 | [diff] [blame] | 194 | if (!syscon) |
| 195 | return; |
Linus Walleij | 11f9323 | 2014-06-24 14:08:07 +0200 | [diff] [blame] | 196 | ebi = of_find_matching_node(NULL, ebi_match); |
Linus Walleij | 307b966 | 2013-06-17 23:58:25 +0200 | [diff] [blame] | 197 | if (!ebi) |
| 198 | return; |
Linus Walleij | e67ae6b | 2012-11-02 01:31:10 +0100 | [diff] [blame] | 199 | |
| 200 | ap_syscon_base = of_iomap(syscon, 0); |
| 201 | if (!ap_syscon_base) |
| 202 | return; |
Linus Walleij | 307b966 | 2013-06-17 23:58:25 +0200 | [diff] [blame] | 203 | ebi_base = of_iomap(ebi, 0); |
| 204 | if (!ebi_base) |
| 205 | return; |
Linus Walleij | e67ae6b | 2012-11-02 01:31:10 +0100 | [diff] [blame] | 206 | |
Kefeng Wang | 435ebcb | 2016-06-01 14:53:05 +0800 | [diff] [blame] | 207 | of_platform_default_populate(NULL, ap_auxdata_lookup, NULL); |
Linus Walleij | 11f9323 | 2014-06-24 14:08:07 +0200 | [diff] [blame] | 208 | |
Linus Walleij | 83feba5 | 2012-11-04 20:49:15 +0100 | [diff] [blame] | 209 | sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET); |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 210 | 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 Walleij | a672025 | 2013-06-15 23:56:32 +0200 | [diff] [blame] | 223 | lmdev->irq = irq_of_parse_and_map(syscon, i); |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 224 | lmdev->id = i; |
| 225 | |
| 226 | lm_device_register(lmdev); |
| 227 | } |
| 228 | } |
| 229 | |
Linus Walleij | 4980f9b | 2012-09-06 09:08:24 +0100 | [diff] [blame] | 230 | static const char * ap_dt_board_compat[] = { |
| 231 | "arm,integrator-ap", |
| 232 | NULL, |
| 233 | }; |
| 234 | |
| 235 | DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)") |
| 236 | .reserve = integrator_reserve, |
| 237 | .map_io = ap_map_io, |
Linus Walleij | 4980f9b | 2012-09-06 09:08:24 +0100 | [diff] [blame] | 238 | .init_early = ap_init_early, |
| 239 | .init_irq = ap_init_irq_of, |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 240 | .init_machine = ap_init_of, |
Linus Walleij | 4980f9b | 2012-09-06 09:08:24 +0100 | [diff] [blame] | 241 | .dt_compat = ap_dt_board_compat, |
| 242 | MACHINE_END |