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