blob: c07c821fb6b3c8121d90995b67f06dfb27f7a03a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Bergmannb434f5c2012-08-04 10:31:24 +000014#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/spinlock.h>
16#include <linux/interrupt.h>
Thomas Gleixnera03d4d22006-07-01 22:32:32 +010017#include <linux/irq.h>
Russell King8d717a52010-05-22 19:47:18 +010018#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/sched.h>
Russell King20cf33e2005-06-18 10:15:46 +010020#include <linux/smp.h>
Russell Kinga62c80e2006-01-07 13:52:45 +000021#include <linux/amba/bus.h>
Russell Kingfbb18a22006-03-26 23:13:39 +010022#include <linux/amba/serial.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Linus Walleije67ae6b2012-11-02 01:31:10 +010024#include <linux/stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Russell Kinga285edc2010-01-14 19:59:37 +000027#include <mach/platform.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/cm.h>
Linus Walleij695436e2012-02-26 10:46:48 +010029#include <mach/irqs.h>
30
Linus Walleijee358872011-12-20 11:55:19 +010031#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/mach/time.h>
Russell King98c672c2010-05-22 18:18:57 +010033#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Walleij4672cdd2012-09-06 09:08:47 +010035#include "common.h"
36
37#ifdef CONFIG_ATAGS
Russell Kingfbb18a22006-03-26 23:13:39 +010038
Russell King2f64ccd2011-12-18 14:50:51 +000039#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 Torvalds1da177e2005-04-16 15:20:36 -070044
Linus Walleijd59fdcfc2012-06-11 00:14:15 +020045static AMBA_APB_DEVICE(rtc, "rtc", 0,
Russell King2f64ccd2011-12-18 14:50:51 +000046 INTEGRATOR_RTC_BASE, INTEGRATOR_RTC_IRQ, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Walleijd59fdcfc2012-06-11 00:14:15 +020048static AMBA_APB_DEVICE(uart0, "uart0", 0,
Linus Walleij379df272012-11-17 19:24:23 +010049 INTEGRATOR_UART0_BASE, INTEGRATOR_UART0_IRQ, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Walleijd59fdcfc2012-06-11 00:14:15 +020051static AMBA_APB_DEVICE(uart1, "uart1", 0,
Linus Walleij379df272012-11-17 19:24:23 +010052 INTEGRATOR_UART1_BASE, INTEGRATOR_UART1_IRQ, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Linus Walleijd59fdcfc2012-06-11 00:14:15 +020054static AMBA_APB_DEVICE(kmi0, "kmi0", 0, KMI0_BASE, KMI0_IRQ, NULL);
55static AMBA_APB_DEVICE(kmi1, "kmi1", 0, KMI1_BASE, KMI1_IRQ, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57static struct amba_device *amba_devs[] __initdata = {
58 &rtc_device,
59 &uart0_device,
60 &uart1_device,
61 &kmi0_device,
62 &kmi1_device,
63};
64
Linus Walleij9bf26a12012-09-06 09:06:52 +010065int __init integrator_init(bool is_cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 int i;
68
Linus Walleijee358872011-12-20 11:55:19 +010069 /*
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 Bergmanna02e0a82013-02-14 13:43:29 +010074 if (!is_cp && IS_ENABLED(CONFIG_ARCH_INTEGRATOR_AP)) {
Linus Walleijee358872011-12-20 11:55:19 +010075 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 Walleij379df272012-11-17 19:24:23 +010080 uart0_device.dev.platform_data = &ap_uart_data;
81 uart1_device.dev.platform_data = &ap_uart_data;
Linus Walleijee358872011-12-20 11:55:19 +010082 }
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 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 Walleij4672cdd2012-09-06 09:08:47 +010092#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050094static DEFINE_RAW_SPINLOCK(cm_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/**
Linus Walleijfb61f862013-10-10 14:11:18 +020097 * cm_get - get the value from the CM_CTRL register
98 */
99u32 cm_get(void)
100{
101 return readl(cm_base + INTEGRATOR_HDR_CTRL_OFFSET);
102}
103
104/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 * cm_control - update the CM_CTRL register.
106 * @mask: bits to change
107 * @set: bits to set
108 */
109void cm_control(u32 mask, u32 set)
110{
111 unsigned long flags;
112 u32 val;
113
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500114 raw_spin_lock_irqsave(&cm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 val = readl(CM_CTRL) & ~mask;
116 writel(val | set, CM_CTRL);
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500117 raw_spin_unlock_irqrestore(&cm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
120EXPORT_SYMBOL(cm_control);
Russell King98c672c2010-05-22 18:18:57 +0100121
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 */
127void __init integrator_reserve(void)
128{
Russell King8d717a52010-05-22 19:47:18 +0100129 memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
Russell King98c672c2010-05-22 18:18:57 +0100130}
Russell King6338b662011-11-03 19:54:37 +0000131
132/*
133 * To reset, we hit the on-board reset register in the system FPGA
134 */
Robin Holt7b6d8642013-07-08 16:01:40 -0700135void integrator_restart(enum reboot_mode mode, const char *cmd)
Russell King6338b662011-11-03 19:54:37 +0000136{
137 cm_control(CM_CTRL_RESET, CM_CTRL_RESET);
138}
Linus Walleije67ae6b2012-11-02 01:31:10 +0100139
140static u32 integrator_id;
141
142static 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
149static struct device_attribute intcp_manf_attr =
150 __ATTR(manufacturer, S_IRUGO, intcp_get_manf, NULL);
151
152static 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
179static struct device_attribute intcp_arch_attr =
180 __ATTR(architecture, S_IRUGO, intcp_get_arch, NULL);
181
182static 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
206static struct device_attribute intcp_fpga_attr =
207 __ATTR(fpga, S_IRUGO, intcp_get_fpga, NULL);
208
209static 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
216static struct device_attribute intcp_build_attr =
217 __ATTR(build, S_IRUGO, intcp_get_build, NULL);
218
219
220
221void 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}