blob: 00ddf20ed91b384d892248238afe6f008758e303 [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 Walleijbb4dbef2013-06-16 02:44:27 +020025#include <linux/of.h>
26#include <linux/of_address.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/hardware.h>
Russell Kinga285edc2010-01-14 19:59:37 +000029#include <mach/platform.h>
Linus Walleij695436e2012-02-26 10:46:48 +010030
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 Walleijbb4dbef2013-06-16 02:44:27 +020035#include "cm.h"
Linus Walleij4672cdd2012-09-06 09:08:47 +010036#include "common.h"
37
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050038static DEFINE_RAW_SPINLOCK(cm_lock);
Linus Walleijbb4dbef2013-06-16 02:44:27 +020039static void __iomem *cm_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/**
Linus Walleijfb61f862013-10-10 14:11:18 +020042 * cm_get - get the value from the CM_CTRL register
43 */
44u32 cm_get(void)
45{
46 return readl(cm_base + INTEGRATOR_HDR_CTRL_OFFSET);
47}
48
49/**
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * cm_control - update the CM_CTRL register.
51 * @mask: bits to change
52 * @set: bits to set
53 */
54void cm_control(u32 mask, u32 set)
55{
56 unsigned long flags;
57 u32 val;
58
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050059 raw_spin_lock_irqsave(&cm_lock, flags);
Linus Walleijbb4dbef2013-06-16 02:44:27 +020060 val = readl(cm_base + INTEGRATOR_HDR_CTRL_OFFSET) & ~mask;
61 writel(val | set, cm_base + INTEGRATOR_HDR_CTRL_OFFSET);
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050062 raw_spin_unlock_irqrestore(&cm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Linus Walleijbb4dbef2013-06-16 02:44:27 +020065static const char *integrator_arch_str(u32 id)
66{
67 switch ((id >> 16) & 0xff) {
68 case 0x00:
69 return "ASB little-endian";
70 case 0x01:
71 return "AHB little-endian";
72 case 0x03:
73 return "AHB-Lite system bus, bi-endian";
74 case 0x04:
75 return "AHB";
76 case 0x08:
77 return "AHB system bus, ASB processor bus";
78 default:
79 return "Unknown";
80 }
81}
82
83static const char *integrator_fpga_str(u32 id)
84{
85 switch ((id >> 12) & 0xf) {
86 case 0x01:
87 return "XC4062";
88 case 0x02:
89 return "XC4085";
90 case 0x03:
91 return "XVC600";
92 case 0x04:
93 return "EPM7256AE (Altera PLD)";
94 default:
95 return "Unknown";
96 }
97}
98
99void cm_clear_irqs(void)
100{
101 /* disable core module IRQs */
102 writel(0xffffffffU, cm_base + INTEGRATOR_HDR_IC_OFFSET +
103 IRQ_ENABLE_CLEAR);
104}
105
106static const struct of_device_id cm_match[] = {
107 { .compatible = "arm,core-module-integrator"},
108 { },
109};
110
111void cm_init(void)
112{
113 struct device_node *cm = of_find_matching_node(NULL, cm_match);
114 u32 val;
115
116 if (!cm) {
117 pr_crit("no core module node found in device tree\n");
118 return;
119 }
120 cm_base = of_iomap(cm, 0);
121 if (!cm_base) {
122 pr_crit("could not remap core module\n");
123 return;
124 }
125 cm_clear_irqs();
126 val = readl(cm_base + INTEGRATOR_HDR_ID_OFFSET);
127 pr_info("Detected ARM core module:\n");
128 pr_info(" Manufacturer: %02x\n", (val >> 24));
129 pr_info(" Architecture: %s\n", integrator_arch_str(val));
130 pr_info(" FPGA: %s\n", integrator_fpga_str(val));
131 pr_info(" Build: %02x\n", (val >> 4) & 0xFF);
132 pr_info(" Rev: %c\n", ('A' + (val & 0x03)));
133}
Russell King98c672c2010-05-22 18:18:57 +0100134
135/*
136 * We need to stop things allocating the low memory; ideally we need a
137 * better implementation of GFP_DMA which does not assume that DMA-able
138 * memory starts at zero.
139 */
140void __init integrator_reserve(void)
141{
Russell King8d717a52010-05-22 19:47:18 +0100142 memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
Russell King98c672c2010-05-22 18:18:57 +0100143}
Russell King6338b662011-11-03 19:54:37 +0000144
145/*
146 * To reset, we hit the on-board reset register in the system FPGA
147 */
Robin Holt7b6d8642013-07-08 16:01:40 -0700148void integrator_restart(enum reboot_mode mode, const char *cmd)
Russell King6338b662011-11-03 19:54:37 +0000149{
150 cm_control(CM_CTRL_RESET, CM_CTRL_RESET);
151}
Linus Walleije67ae6b2012-11-02 01:31:10 +0100152
153static u32 integrator_id;
154
155static ssize_t intcp_get_manf(struct device *dev,
156 struct device_attribute *attr,
157 char *buf)
158{
159 return sprintf(buf, "%02x\n", integrator_id >> 24);
160}
161
162static struct device_attribute intcp_manf_attr =
163 __ATTR(manufacturer, S_IRUGO, intcp_get_manf, NULL);
164
165static ssize_t intcp_get_arch(struct device *dev,
166 struct device_attribute *attr,
167 char *buf)
168{
Linus Walleijbb4dbef2013-06-16 02:44:27 +0200169 return sprintf(buf, "%s\n", integrator_arch_str(integrator_id));
Linus Walleije67ae6b2012-11-02 01:31:10 +0100170}
171
172static struct device_attribute intcp_arch_attr =
173 __ATTR(architecture, S_IRUGO, intcp_get_arch, NULL);
174
175static ssize_t intcp_get_fpga(struct device *dev,
176 struct device_attribute *attr,
177 char *buf)
178{
Linus Walleijbb4dbef2013-06-16 02:44:27 +0200179 return sprintf(buf, "%s\n", integrator_fpga_str(integrator_id));
Linus Walleije67ae6b2012-11-02 01:31:10 +0100180}
181
182static struct device_attribute intcp_fpga_attr =
183 __ATTR(fpga, S_IRUGO, intcp_get_fpga, NULL);
184
185static ssize_t intcp_get_build(struct device *dev,
186 struct device_attribute *attr,
187 char *buf)
188{
189 return sprintf(buf, "%02x\n", (integrator_id >> 4) & 0xFF);
190}
191
192static struct device_attribute intcp_build_attr =
193 __ATTR(build, S_IRUGO, intcp_get_build, NULL);
194
195
196
197void integrator_init_sysfs(struct device *parent, u32 id)
198{
199 integrator_id = id;
200 device_create_file(parent, &intcp_manf_attr);
201 device_create_file(parent, &intcp_arch_attr);
202 device_create_file(parent, &intcp_fpga_attr);
203 device_create_file(parent, &intcp_build_attr);
204}