blob: 8cfca45d3650f8c3d77608948193749b2e370b78 [file] [log] [blame]
Linus Walleijbb3cee22009-04-23 10:22:13 +01001/*
2 *
3 * arch/arm/mach-u300/core.c
4 *
5 *
Linus Walleijfcb28d22012-08-13 10:11:15 +02006 * Copyright (C) 2007-2012 ST-Ericsson SA
Linus Walleijbb3cee22009-04-23 10:22:13 +01007 * License terms: GNU General Public License (GPL) version 2
8 * Core platform support, IRQ handling and device definitions.
9 * Author: Linus Walleij <linus.walleij@stericsson.com>
10 */
11#include <linux/kernel.h>
Linus Walleij98da3522011-05-02 20:54:38 +020012#include <linux/pinctrl/machine.h>
Linus Walleij51dddfe2012-01-20 17:53:15 +010013#include <linux/pinctrl/pinconf-generic.h>
Linus Walleij50667d62012-06-19 23:44:25 +020014#include <linux/platform_data/clk-u300.h>
Linus Walleij65172852012-08-13 10:56:43 +020015#include <linux/platform_data/pinctrl-coh901.h>
Linus Walleij978577e2013-04-08 11:38:50 +020016#include <linux/irqchip.h>
Linus Walleijcf0ce092013-05-22 16:15:13 +020017#include <linux/of_address.h>
Linus Walleij978577e2013-04-08 11:38:50 +020018#include <linux/of_platform.h>
19#include <linux/clocksource.h>
Linus Walleij75a7f3f2013-04-22 11:29:30 +020020#include <linux/clk.h>
Linus Walleijbb3cee22009-04-23 10:22:13 +010021
Linus Walleijbb3cee22009-04-23 10:22:13 +010022#include <asm/mach/map.h>
Linus Walleij234323b2012-08-13 11:35:55 +020023#include <asm/mach/arch.h>
Linus Walleijbb3cee22009-04-23 10:22:13 +010024
Linus Walleijb0bdd8b2013-05-02 17:12:33 +020025#include "u300-regs.h"
Linus Walleij0004b012013-05-02 16:56:15 +020026
27/*
28 * SYSCON addresses applicable to the core machine.
29 */
30
31/* Chip ID register 16bit (R/-) */
32#define U300_SYSCON_CIDR (0x400)
33/* SMCR */
34#define U300_SYSCON_SMCR (0x4d0)
35#define U300_SYSCON_SMCR_FIELD_MASK (0x000e)
36#define U300_SYSCON_SMCR_SEMI_SREFACK_IND (0x0008)
37#define U300_SYSCON_SMCR_SEMI_SREFREQ_ENABLE (0x0004)
38#define U300_SYSCON_SMCR_SEMI_EXT_BOOT_MODE_ENABLE (0x0002)
39/* CPU_SW_DBGEN Software Debug Enable 16bit (R/W) */
40#define U300_SYSCON_CSDR (0x4f0)
41#define U300_SYSCON_CSDR_SW_DEBUG_ENABLE (0x0001)
42/* PRINT_CONTROL Print Control 16bit (R/-) */
43#define U300_SYSCON_PCR (0x4f8)
44#define U300_SYSCON_PCR_SERV_IND (0x0001)
45/* BOOT_CONTROL 16bit (R/-) */
46#define U300_SYSCON_BCR (0x4fc)
47#define U300_SYSCON_BCR_ACC_CPU_SUBSYS_VINITHI_IND (0x0400)
48#define U300_SYSCON_BCR_APP_CPU_SUBSYS_VINITHI_IND (0x0200)
49#define U300_SYSCON_BCR_EXTRA_BOOT_OPTION_MASK (0x01FC)
50#define U300_SYSCON_BCR_APP_BOOT_SERV_MASK (0x0003)
Linus Walleijbb3cee22009-04-23 10:22:13 +010051
Linus Walleijcf0ce092013-05-22 16:15:13 +020052static void __iomem *syscon_base;
53
Linus Walleijbb3cee22009-04-23 10:22:13 +010054/*
55 * Static I/O mappings that are needed for booting the U300 platforms. The
56 * only things we need are the areas where we find the timer, syscon and
57 * intcon, since the remaining device drivers will map their own memory
58 * physical to virtual as the need arise.
59 */
60static struct map_desc u300_io_desc[] __initdata = {
61 {
62 .virtual = U300_SLOW_PER_VIRT_BASE,
63 .pfn = __phys_to_pfn(U300_SLOW_PER_PHYS_BASE),
64 .length = SZ_64K,
65 .type = MT_DEVICE,
66 },
67 {
68 .virtual = U300_AHB_PER_VIRT_BASE,
69 .pfn = __phys_to_pfn(U300_AHB_PER_PHYS_BASE),
70 .length = SZ_32K,
71 .type = MT_DEVICE,
72 },
73 {
74 .virtual = U300_FAST_PER_VIRT_BASE,
75 .pfn = __phys_to_pfn(U300_FAST_PER_PHYS_BASE),
76 .length = SZ_32K,
77 .type = MT_DEVICE,
78 },
Linus Walleijbb3cee22009-04-23 10:22:13 +010079};
80
Linus Walleij234323b2012-08-13 11:35:55 +020081static void __init u300_map_io(void)
Linus Walleijbb3cee22009-04-23 10:22:13 +010082{
83 iotable_init(u300_io_desc, ARRAY_SIZE(u300_io_desc));
84}
85
86/*
Linus Walleijcc890cd2011-09-08 09:04:51 +010087 * The different variants have a few different versions of the
88 * GPIO block, with different number of ports.
89 */
90static struct u300_gpio_platform u300_gpio_plat = {
Linus Walleijcc890cd2011-09-08 09:04:51 +010091 .ports = 7,
Linus Walleijcc890cd2011-09-08 09:04:51 +010092 .gpio_base = 0,
Linus Walleijcc890cd2011-09-08 09:04:51 +010093};
94
Linus Walleij51dddfe2012-01-20 17:53:15 +010095static unsigned long pin_pullup_conf[] = {
96 PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_UP, 1),
97};
98
99static unsigned long pin_highz_conf[] = {
100 PIN_CONF_PACKED(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0),
101};
102
103/* Pin control settings */
Linus Walleije93bcee2012-02-09 07:23:28 +0100104static struct pinctrl_map __initdata u300_pinmux_map[] = {
Linus Walleij98da3522011-05-02 20:54:38 +0200105 /* anonymous maps for chip power and EMIFs */
Stephen Warren1e2082b2012-03-02 13:05:48 -0700106 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "power"),
107 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "emif0"),
108 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "emif1"),
Linus Walleij98da3522011-05-02 20:54:38 +0200109 /* per-device maps for MMC/SD, SPI and UART */
Stephen Warren1e2082b2012-03-02 13:05:48 -0700110 PIN_MAP_MUX_GROUP_DEFAULT("mmci", "pinctrl-u300", NULL, "mmc0"),
111 PIN_MAP_MUX_GROUP_DEFAULT("pl022", "pinctrl-u300", NULL, "spi0"),
112 PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-u300", NULL, "uart0"),
Linus Walleij51dddfe2012-01-20 17:53:15 +0100113 /* This pin is used for clock return rather than GPIO */
114 PIN_MAP_CONFIGS_PIN_DEFAULT("mmci", "pinctrl-u300", "PIO APP GPIO 11",
115 pin_pullup_conf),
116 /* This pin is used for card detect */
117 PIN_MAP_CONFIGS_PIN_DEFAULT("mmci", "pinctrl-u300", "PIO MS INS",
118 pin_highz_conf),
Linus Walleij98da3522011-05-02 20:54:38 +0200119};
120
Linus Walleijbb3cee22009-04-23 10:22:13 +0100121struct db_chip {
122 u16 chipid;
123 const char *name;
124};
125
126/*
127 * This is a list of the Digital Baseband chips used in the U300 platform.
128 */
129static struct db_chip db_chips[] __initdata = {
130 {
131 .chipid = 0xb800,
132 .name = "DB3000",
133 },
134 {
135 .chipid = 0xc000,
136 .name = "DB3100",
137 },
138 {
139 .chipid = 0xc800,
140 .name = "DB3150",
141 },
142 {
143 .chipid = 0xd800,
144 .name = "DB3200",
145 },
146 {
147 .chipid = 0xe000,
148 .name = "DB3250",
149 },
150 {
151 .chipid = 0xe800,
152 .name = "DB3210",
153 },
154 {
155 .chipid = 0xf000,
156 .name = "DB3350 P1x",
157 },
158 {
159 .chipid = 0xf100,
160 .name = "DB3350 P2x",
161 },
162 {
163 .chipid = 0x0000, /* List terminator */
164 .name = NULL,
165 }
166};
167
Linus Walleija2bb9f42009-08-13 21:57:22 +0100168static void __init u300_init_check_chip(void)
Linus Walleijbb3cee22009-04-23 10:22:13 +0100169{
170
171 u16 val;
172 struct db_chip *chip;
173 const char *chipname;
174 const char unknown[] = "UNKNOWN";
175
176 /* Read out and print chip ID */
Linus Walleijcf0ce092013-05-22 16:15:13 +0200177 val = readw(syscon_base + U300_SYSCON_CIDR);
Linus Walleijbb3cee22009-04-23 10:22:13 +0100178 /* This is in funky bigendian order... */
179 val = (val & 0xFFU) << 8 | (val >> 8);
180 chip = db_chips;
181 chipname = unknown;
182
183 for ( ; chip->chipid; chip++) {
184 if (chip->chipid == (val & 0xFF00U)) {
185 chipname = chip->name;
186 break;
187 }
188 }
189 printk(KERN_INFO "Initializing U300 system on %s baseband chip " \
190 "(chip ID 0x%04x)\n", chipname, val);
191
Linus Walleijbb3cee22009-04-23 10:22:13 +0100192 if ((val & 0xFF00U) != 0xf000 && (val & 0xFF00U) != 0xf100) {
Linus Walleijec8f1252010-08-13 11:31:59 +0200193 printk(KERN_ERR "Platform configured for BS335 " \
Linus Walleijbb3cee22009-04-23 10:22:13 +0100194 " with DB3350 but %s detected, expect problems!",
195 chipname);
196 }
Linus Walleijbb3cee22009-04-23 10:22:13 +0100197}
198
Russell King7e3974b2011-11-05 15:51:25 +0000199/* Forward declare this function from the watchdog */
200void coh901327_watchdog_reset(void);
201
Linus Walleij234323b2012-08-13 11:35:55 +0200202static void u300_restart(char mode, const char *cmd)
Russell King7e3974b2011-11-05 15:51:25 +0000203{
204 switch (mode) {
205 case 's':
206 case 'h':
Russell King7e3974b2011-11-05 15:51:25 +0000207#ifdef CONFIG_COH901327_WATCHDOG
208 coh901327_watchdog_reset();
209#endif
210 break;
211 default:
212 /* Do nothing */
213 break;
214 }
215 /* Wait for system do die/reset. */
216 while (1);
217}
Linus Walleij234323b2012-08-13 11:35:55 +0200218
Linus Walleij978577e2013-04-08 11:38:50 +0200219/* These are mostly to get the right device names for the clock lookups */
220static struct of_dev_auxdata u300_auxdata_lookup[] __initdata = {
221 OF_DEV_AUXDATA("stericsson,pinctrl-u300", U300_SYSCON_BASE,
222 "pinctrl-u300", NULL),
223 OF_DEV_AUXDATA("stericsson,gpio-coh901", U300_GPIO_BASE,
224 "u300-gpio", &u300_gpio_plat),
Linus Walleij63a62ec2013-04-19 12:59:59 +0200225 OF_DEV_AUXDATA("stericsson,coh901327", U300_WDOG_BASE,
226 "coh901327_wdog", NULL),
Linus Walleijae87bb82013-04-19 13:22:57 +0200227 OF_DEV_AUXDATA("stericsson,coh901331", U300_RTC_BASE,
228 "rtc-coh901331", NULL),
Linus Walleij39738cc2013-04-19 13:44:25 +0200229 OF_DEV_AUXDATA("stericsson,coh901318", U300_DMAC_BASE,
230 "coh901318", NULL),
Linus Walleijd1346362013-04-22 11:00:02 +0200231 OF_DEV_AUXDATA("stericsson,fsmc-nand", U300_NAND_IF_PHYS_BASE,
232 "fsmc-nand", NULL),
Linus Walleij978577e2013-04-08 11:38:50 +0200233 OF_DEV_AUXDATA("arm,primecell", U300_UART0_BASE,
Linus Walleij75a7f3f2013-04-22 11:29:30 +0200234 "uart0", NULL),
Linus Walleij978577e2013-04-08 11:38:50 +0200235 OF_DEV_AUXDATA("arm,primecell", U300_UART1_BASE,
Linus Walleij75a7f3f2013-04-22 11:29:30 +0200236 "uart1", NULL),
Linus Walleijcf4af862013-04-19 14:56:46 +0200237 OF_DEV_AUXDATA("arm,primecell", U300_SPI_BASE,
Linus Walleij75a7f3f2013-04-22 11:29:30 +0200238 "pl022", NULL),
Linus Walleijc023b8b2013-04-11 15:13:39 +0200239 OF_DEV_AUXDATA("st,ddci2c", U300_I2C0_BASE,
240 "stu300.0", NULL),
241 OF_DEV_AUXDATA("st,ddci2c", U300_I2C1_BASE,
242 "stu300.1", NULL),
Linus Walleij978577e2013-04-08 11:38:50 +0200243 OF_DEV_AUXDATA("arm,primecell", U300_MMCSD_BASE,
Linus Walleij75a7f3f2013-04-22 11:29:30 +0200244 "mmci", NULL),
Linus Walleij978577e2013-04-08 11:38:50 +0200245 { /* sentinel */ },
246};
247
248static void __init u300_init_irq_dt(void)
249{
Linus Walleijcf0ce092013-05-22 16:15:13 +0200250 struct device_node *syscon;
Linus Walleij978577e2013-04-08 11:38:50 +0200251 struct clk *clk;
252
Linus Walleijcf0ce092013-05-22 16:15:13 +0200253 syscon = of_find_node_by_path("/syscon@c0011000");
254 if (!syscon) {
255 pr_crit("could not find syscon node\n");
256 return;
257 }
258 syscon_base = of_iomap(syscon, 0);
259 if (!syscon_base) {
260 pr_crit("could not remap syscon\n");
261 return;
262 }
Linus Walleij978577e2013-04-08 11:38:50 +0200263 /* initialize clocking early, we want to clock the INTCON */
Linus Walleijcf0ce092013-05-22 16:15:13 +0200264 u300_clk_init(syscon_base);
Linus Walleij978577e2013-04-08 11:38:50 +0200265
266 /* Bootstrap EMIF and SEMI clocks */
267 clk = clk_get_sys("pl172", NULL);
268 BUG_ON(IS_ERR(clk));
269 clk_prepare_enable(clk);
270 clk = clk_get_sys("semi", NULL);
271 BUG_ON(IS_ERR(clk));
272 clk_prepare_enable(clk);
273
274 /* Clock the interrupt controller */
275 clk = clk_get_sys("intcon", NULL);
276 BUG_ON(IS_ERR(clk));
277 clk_prepare_enable(clk);
278
279 irqchip_init();
280}
281
282static void __init u300_init_machine_dt(void)
283{
284 u16 val;
285
286 /* Check what platform we run and print some status information */
287 u300_init_check_chip();
288
Linus Walleij978577e2013-04-08 11:38:50 +0200289 /* Initialize pinmuxing */
290 pinctrl_register_mappings(u300_pinmux_map,
291 ARRAY_SIZE(u300_pinmux_map));
292
293 of_platform_populate(NULL, of_default_bus_match_table,
294 u300_auxdata_lookup, NULL);
295
296 /* Enable SEMI self refresh */
Linus Walleijcf0ce092013-05-22 16:15:13 +0200297 val = readw(syscon_base + U300_SYSCON_SMCR) |
Linus Walleij978577e2013-04-08 11:38:50 +0200298 U300_SYSCON_SMCR_SEMI_SREFREQ_ENABLE;
Linus Walleijcf0ce092013-05-22 16:15:13 +0200299 writew(val, syscon_base + U300_SYSCON_SMCR);
Linus Walleij978577e2013-04-08 11:38:50 +0200300}
301
302static const char * u300_board_compat[] = {
303 "stericsson,u300",
304 NULL,
305};
306
307DT_MACHINE_START(U300_DT, "U300 S335/B335 (Device Tree)")
308 .map_io = u300_map_io,
309 .init_irq = u300_init_irq_dt,
310 .init_time = clocksource_of_init,
311 .init_machine = u300_init_machine_dt,
312 .restart = u300_restart,
313 .dt_compat = u300_board_compat,
314MACHINE_END