Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-integrator/core.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 version 2, as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/device.h> |
Arnd Bergmann | b434f5c | 2012-08-04 10:31:24 +0000 | [diff] [blame] | 14 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/interrupt.h> |
Thomas Gleixner | a03d4d2 | 2006-07-01 22:32:32 +0100 | [diff] [blame] | 17 | #include <linux/irq.h> |
Russell King | 8d717a5 | 2010-05-22 19:47:18 +0100 | [diff] [blame] | 18 | #include <linux/memblock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/sched.h> |
Russell King | 20cf33e | 2005-06-18 10:15:46 +0100 | [diff] [blame] | 20 | #include <linux/smp.h> |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 21 | #include <linux/termios.h> |
Russell King | a62c80e | 2006-01-07 13:52:45 +0000 | [diff] [blame] | 22 | #include <linux/amba/bus.h> |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 23 | #include <linux/amba/serial.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
Linus Walleij | e67ae6b | 2012-11-02 01:31:10 +0100 | [diff] [blame^] | 25 | #include <linux/stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/hardware.h> |
Russell King | a285edc | 2010-01-14 19:59:37 +0000 | [diff] [blame] | 28 | #include <mach/platform.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 29 | #include <mach/cm.h> |
Linus Walleij | 695436e | 2012-02-26 10:46:48 +0100 | [diff] [blame] | 30 | #include <mach/irqs.h> |
| 31 | |
Linus Walleij | ee35887 | 2011-12-20 11:55:19 +0100 | [diff] [blame] | 32 | #include <asm/mach-types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/mach/time.h> |
Russell King | 98c672c | 2010-05-22 18:18:57 +0100 | [diff] [blame] | 34 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 36 | #include "common.h" |
| 37 | |
| 38 | #ifdef CONFIG_ATAGS |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 39 | |
Russell King | 2f64ccd | 2011-12-18 14:50:51 +0000 | [diff] [blame] | 40 | #define INTEGRATOR_RTC_IRQ { IRQ_RTCINT } |
| 41 | #define INTEGRATOR_UART0_IRQ { IRQ_UARTINT0 } |
| 42 | #define INTEGRATOR_UART1_IRQ { IRQ_UARTINT1 } |
| 43 | #define KMI0_IRQ { IRQ_KMIINT0 } |
| 44 | #define KMI1_IRQ { IRQ_KMIINT1 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Linus Walleij | d59fdcfc | 2012-06-11 00:14:15 +0200 | [diff] [blame] | 46 | static AMBA_APB_DEVICE(rtc, "rtc", 0, |
Russell King | 2f64ccd | 2011-12-18 14:50:51 +0000 | [diff] [blame] | 47 | INTEGRATOR_RTC_BASE, INTEGRATOR_RTC_IRQ, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Linus Walleij | d59fdcfc | 2012-06-11 00:14:15 +0200 | [diff] [blame] | 49 | static AMBA_APB_DEVICE(uart0, "uart0", 0, |
Russell King | 2f64ccd | 2011-12-18 14:50:51 +0000 | [diff] [blame] | 50 | INTEGRATOR_UART0_BASE, INTEGRATOR_UART0_IRQ, &integrator_uart_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Linus Walleij | d59fdcfc | 2012-06-11 00:14:15 +0200 | [diff] [blame] | 52 | static AMBA_APB_DEVICE(uart1, "uart1", 0, |
Russell King | 2f64ccd | 2011-12-18 14:50:51 +0000 | [diff] [blame] | 53 | INTEGRATOR_UART1_BASE, INTEGRATOR_UART1_IRQ, &integrator_uart_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Walleij | d59fdcfc | 2012-06-11 00:14:15 +0200 | [diff] [blame] | 55 | static AMBA_APB_DEVICE(kmi0, "kmi0", 0, KMI0_BASE, KMI0_IRQ, NULL); |
| 56 | static AMBA_APB_DEVICE(kmi1, "kmi1", 0, KMI1_BASE, KMI1_IRQ, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | static struct amba_device *amba_devs[] __initdata = { |
| 59 | &rtc_device, |
| 60 | &uart0_device, |
| 61 | &uart1_device, |
| 62 | &kmi0_device, |
| 63 | &kmi1_device, |
| 64 | }; |
| 65 | |
Linus Walleij | 9bf26a1 | 2012-09-06 09:06:52 +0100 | [diff] [blame] | 66 | int __init integrator_init(bool is_cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
| 68 | int i; |
| 69 | |
Linus Walleij | ee35887 | 2011-12-20 11:55:19 +0100 | [diff] [blame] | 70 | /* |
| 71 | * The Integrator/AP lacks necessary AMBA PrimeCell IDs, so we need to |
| 72 | * hard-code them. The Integator/CP and forward have proper cell IDs. |
| 73 | * Else we leave them undefined to the bus driver can autoprobe them. |
| 74 | */ |
Linus Walleij | 9bf26a1 | 2012-09-06 09:06:52 +0100 | [diff] [blame] | 75 | if (!is_cp) { |
Linus Walleij | ee35887 | 2011-12-20 11:55:19 +0100 | [diff] [blame] | 76 | rtc_device.periphid = 0x00041030; |
| 77 | uart0_device.periphid = 0x00041010; |
| 78 | uart1_device.periphid = 0x00041010; |
| 79 | kmi0_device.periphid = 0x00041050; |
| 80 | kmi1_device.periphid = 0x00041050; |
| 81 | } |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { |
| 84 | struct amba_device *d = amba_devs[i]; |
| 85 | amba_device_register(d, &iomem_resource); |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 91 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 93 | /* |
| 94 | * On the Integrator platform, the port RTS and DTR are provided by |
| 95 | * bits in the following SC_CTRLS register bits: |
| 96 | * RTS DTR |
| 97 | * UART0 7 6 |
| 98 | * UART1 5 4 |
| 99 | */ |
Arnd Bergmann | b7a3f8d | 2012-09-14 20:16:39 +0000 | [diff] [blame] | 100 | #define SC_CTRLC __io_address(INTEGRATOR_SC_CTRLC) |
| 101 | #define SC_CTRLS __io_address(INTEGRATOR_SC_CTRLS) |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 102 | |
| 103 | static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl) |
| 104 | { |
| 105 | unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask; |
Linus Walleij | 2c88543 | 2012-09-06 09:07:27 +0100 | [diff] [blame] | 106 | u32 phybase = dev->res.start; |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 107 | |
Linus Walleij | 2c88543 | 2012-09-06 09:07:27 +0100 | [diff] [blame] | 108 | if (phybase == INTEGRATOR_UART0_BASE) { |
| 109 | /* UART0 */ |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 110 | rts_mask = 1 << 4; |
| 111 | dtr_mask = 1 << 5; |
| 112 | } else { |
Linus Walleij | 2c88543 | 2012-09-06 09:07:27 +0100 | [diff] [blame] | 113 | /* UART1 */ |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 114 | rts_mask = 1 << 6; |
| 115 | dtr_mask = 1 << 7; |
| 116 | } |
| 117 | |
| 118 | if (mctrl & TIOCM_RTS) |
| 119 | ctrlc |= rts_mask; |
| 120 | else |
| 121 | ctrls |= rts_mask; |
| 122 | |
| 123 | if (mctrl & TIOCM_DTR) |
| 124 | ctrlc |= dtr_mask; |
| 125 | else |
| 126 | ctrls |= dtr_mask; |
| 127 | |
| 128 | __raw_writel(ctrls, SC_CTRLS); |
| 129 | __raw_writel(ctrlc, SC_CTRLC); |
| 130 | } |
| 131 | |
Linus Walleij | 4672cdd | 2012-09-06 09:08:47 +0100 | [diff] [blame] | 132 | struct amba_pl010_data integrator_uart_data = { |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 133 | .set_mctrl = integrator_uart_set_mctrl, |
| 134 | }; |
| 135 | |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 136 | static DEFINE_RAW_SPINLOCK(cm_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * cm_control - update the CM_CTRL register. |
| 140 | * @mask: bits to change |
| 141 | * @set: bits to set |
| 142 | */ |
| 143 | void cm_control(u32 mask, u32 set) |
| 144 | { |
| 145 | unsigned long flags; |
| 146 | u32 val; |
| 147 | |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 148 | raw_spin_lock_irqsave(&cm_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | val = readl(CM_CTRL) & ~mask; |
| 150 | writel(val | set, CM_CTRL); |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 151 | raw_spin_unlock_irqrestore(&cm_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | EXPORT_SYMBOL(cm_control); |
Russell King | 98c672c | 2010-05-22 18:18:57 +0100 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * We need to stop things allocating the low memory; ideally we need a |
| 158 | * better implementation of GFP_DMA which does not assume that DMA-able |
| 159 | * memory starts at zero. |
| 160 | */ |
| 161 | void __init integrator_reserve(void) |
| 162 | { |
Russell King | 8d717a5 | 2010-05-22 19:47:18 +0100 | [diff] [blame] | 163 | memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET); |
Russell King | 98c672c | 2010-05-22 18:18:57 +0100 | [diff] [blame] | 164 | } |
Russell King | 6338b66 | 2011-11-03 19:54:37 +0000 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * To reset, we hit the on-board reset register in the system FPGA |
| 168 | */ |
| 169 | void integrator_restart(char mode, const char *cmd) |
| 170 | { |
| 171 | cm_control(CM_CTRL_RESET, CM_CTRL_RESET); |
| 172 | } |
Linus Walleij | e67ae6b | 2012-11-02 01:31:10 +0100 | [diff] [blame^] | 173 | |
| 174 | static u32 integrator_id; |
| 175 | |
| 176 | static ssize_t intcp_get_manf(struct device *dev, |
| 177 | struct device_attribute *attr, |
| 178 | char *buf) |
| 179 | { |
| 180 | return sprintf(buf, "%02x\n", integrator_id >> 24); |
| 181 | } |
| 182 | |
| 183 | static struct device_attribute intcp_manf_attr = |
| 184 | __ATTR(manufacturer, S_IRUGO, intcp_get_manf, NULL); |
| 185 | |
| 186 | static ssize_t intcp_get_arch(struct device *dev, |
| 187 | struct device_attribute *attr, |
| 188 | char *buf) |
| 189 | { |
| 190 | const char *arch; |
| 191 | |
| 192 | switch ((integrator_id >> 16) & 0xff) { |
| 193 | case 0x00: |
| 194 | arch = "ASB little-endian"; |
| 195 | break; |
| 196 | case 0x01: |
| 197 | arch = "AHB little-endian"; |
| 198 | break; |
| 199 | case 0x03: |
| 200 | arch = "AHB-Lite system bus, bi-endian"; |
| 201 | break; |
| 202 | case 0x04: |
| 203 | arch = "AHB"; |
| 204 | break; |
| 205 | default: |
| 206 | arch = "Unknown"; |
| 207 | break; |
| 208 | } |
| 209 | |
| 210 | return sprintf(buf, "%s\n", arch); |
| 211 | } |
| 212 | |
| 213 | static struct device_attribute intcp_arch_attr = |
| 214 | __ATTR(architecture, S_IRUGO, intcp_get_arch, NULL); |
| 215 | |
| 216 | static ssize_t intcp_get_fpga(struct device *dev, |
| 217 | struct device_attribute *attr, |
| 218 | char *buf) |
| 219 | { |
| 220 | const char *fpga; |
| 221 | |
| 222 | switch ((integrator_id >> 12) & 0xf) { |
| 223 | case 0x01: |
| 224 | fpga = "XC4062"; |
| 225 | break; |
| 226 | case 0x02: |
| 227 | fpga = "XC4085"; |
| 228 | break; |
| 229 | case 0x04: |
| 230 | fpga = "EPM7256AE (Altera PLD)"; |
| 231 | break; |
| 232 | default: |
| 233 | fpga = "Unknown"; |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | return sprintf(buf, "%s\n", fpga); |
| 238 | } |
| 239 | |
| 240 | static struct device_attribute intcp_fpga_attr = |
| 241 | __ATTR(fpga, S_IRUGO, intcp_get_fpga, NULL); |
| 242 | |
| 243 | static ssize_t intcp_get_build(struct device *dev, |
| 244 | struct device_attribute *attr, |
| 245 | char *buf) |
| 246 | { |
| 247 | return sprintf(buf, "%02x\n", (integrator_id >> 4) & 0xFF); |
| 248 | } |
| 249 | |
| 250 | static struct device_attribute intcp_build_attr = |
| 251 | __ATTR(build, S_IRUGO, intcp_get_build, NULL); |
| 252 | |
| 253 | |
| 254 | |
| 255 | void integrator_init_sysfs(struct device *parent, u32 id) |
| 256 | { |
| 257 | integrator_id = id; |
| 258 | device_create_file(parent, &intcp_manf_attr); |
| 259 | device_create_file(parent, &intcp_arch_attr); |
| 260 | device_create_file(parent, &intcp_fpga_attr); |
| 261 | device_create_file(parent, &intcp_build_attr); |
| 262 | } |