blob: 961079250b837c25ca7623563285fc090dd09e00 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +08001/*
2 * Copyright (C) 2007 Atmel Corporation.
3 * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
4 *
5 * Under GPLv2
6 */
7
Maxime Ripard9e8be232014-07-02 12:04:43 +02008#define pr_fmt(fmt) "AT91: " fmt
9
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080010#include <linux/module.h>
11#include <linux/io.h>
Jean-Christophe PLAGNIOL-VILLARDfb149f92011-05-07 11:16:00 +080012#include <linux/mm.h>
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +080013#include <linux/pm.h>
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +080014#include <linux/of_address.h>
Jean-Christophe PLAGNIOL-VILLARD97e5e622012-07-12 23:35:02 +080015#include <linux/pinctrl/machine.h>
Boris BREZILLON2edb90a2013-10-11 09:37:45 +020016#include <linux/clk/at91_pmc.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080017
Olof Johansson86dfe442012-03-29 23:22:44 -070018#include <asm/system_misc.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080019#include <asm/mach/map.h>
20
21#include <mach/hardware.h>
22#include <mach/cpu.h>
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080023#include <mach/at91_dbgu.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080024
25#include "soc.h"
26#include "generic.h"
Jean-Christophe PLAGNIOL-VILLARD6b625892013-10-16 16:24:57 +020027#include "pm.h"
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080028
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080029struct at91_init_soc __initdata at91_boot_soc;
30
31struct at91_socinfo at91_soc_initdata;
32EXPORT_SYMBOL(at91_soc_initdata);
33
34void __init at91rm9200_set_type(int type)
35{
36 if (type == ARCH_REVISON_9200_PQFP)
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080037 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
Nicolas Ferre3e907722011-12-28 13:10:04 +020038 else
39 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
40
Maxime Ripard9e8be232014-07-02 12:04:43 +020041 pr_info("filled in soc subtype: %s\n",
Nicolas Ferre3e907722011-12-28 13:10:04 +020042 at91_get_soc_subtype(&at91_soc_initdata));
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080043}
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080044
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +080045void __init at91_init_irq_default(void)
46{
47 at91_init_interrupts(at91_boot_soc.default_irq_priority);
48}
49
50void __init at91_init_interrupts(unsigned int *priority)
51{
52 /* Initialize the AIC interrupt controller */
Boris BREZILLON07192602014-07-10 19:14:20 +020053 if (IS_ENABLED(CONFIG_OLD_IRQ_AT91))
54 at91_aic_init(priority, at91_boot_soc.extern_irq);
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +080055
56 /* Enable GPIO interrupts */
57 at91_gpio_irq_setup();
58}
59
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +080060void __iomem *at91_ramc_base[2];
Joachim Eastwood9268c6c2012-03-30 23:03:50 +020061EXPORT_SYMBOL_GPL(at91_ramc_base);
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +080062
63void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
64{
65 if (id < 0 || id > 1) {
66 pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
67 BUG();
68 }
69 at91_ramc_base[id] = ioremap(addr, size);
70 if (!at91_ramc_base[id])
Maxime Ripard9e8be232014-07-02 12:04:43 +020071 panic(pr_fmt("Impossible to ioremap ramc.%d 0x%x\n"), id, addr);
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +080072}
73
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080074static struct map_desc sram_desc[2] __initdata;
75
76void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
77{
78 struct map_desc *desc = &sram_desc[bank];
79
Arnd Bergmanndca4ba42012-09-14 20:10:19 +000080 desc->virtual = (unsigned long)AT91_IO_VIRT_BASE - length;
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080081 if (bank > 0)
82 desc->virtual -= sram_desc[bank - 1].length;
83
84 desc->pfn = __phys_to_pfn(base);
85 desc->length = length;
Russell King2e2c9de2013-10-24 10:26:40 +010086 desc->type = MT_MEMORY_RWX_NONCACHED;
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080087
Maxime Ripard9e8be232014-07-02 12:04:43 +020088 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080089 base, length, desc->virtual);
90
91 iotable_init(desc, 1);
92}
93
Arnd Bergmannac092812012-04-30 13:18:53 +000094static struct map_desc at91_io_desc __initdata __maybe_unused = {
Arnd Bergmanndca4ba42012-09-14 20:10:19 +000095 .virtual = (unsigned long)AT91_VA_BASE_SYS,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080096 .pfn = __phys_to_pfn(AT91_BASE_SYS),
97 .length = SZ_16K,
98 .type = MT_DEVICE,
99};
100
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200101static struct map_desc at91_alt_io_desc __initdata __maybe_unused = {
102 .virtual = (unsigned long)AT91_ALT_VA_BASE_SYS,
103 .pfn = __phys_to_pfn(AT91_ALT_BASE_SYS),
104 .length = 24 * SZ_1K,
105 .type = MT_DEVICE,
106};
107
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800108static void __init soc_detect(u32 dbgu_base)
109{
110 u32 cidr, socid;
111
112 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
113 socid = cidr & ~AT91_CIDR_VERSION;
114
115 switch (socid) {
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800116 case ARCH_ID_AT91RM9200:
117 at91_soc_initdata.type = AT91_SOC_RM9200;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200118 if (at91_soc_initdata.subtype == AT91_SOC_SUBTYPE_UNKNOWN)
Jean-Christophe PLAGNIOL-VILLARD36224d02012-12-23 18:07:49 +0000119 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800120 at91_boot_soc = at91rm9200_soc;
121 break;
122
123 case ARCH_ID_AT91SAM9260:
124 at91_soc_initdata.type = AT91_SOC_SAM9260;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200125 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800126 at91_boot_soc = at91sam9260_soc;
127 break;
128
129 case ARCH_ID_AT91SAM9261:
130 at91_soc_initdata.type = AT91_SOC_SAM9261;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200131 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800132 at91_boot_soc = at91sam9261_soc;
133 break;
134
135 case ARCH_ID_AT91SAM9263:
136 at91_soc_initdata.type = AT91_SOC_SAM9263;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200137 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800138 at91_boot_soc = at91sam9263_soc;
139 break;
140
141 case ARCH_ID_AT91SAM9G20:
142 at91_soc_initdata.type = AT91_SOC_SAM9G20;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200143 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800144 at91_boot_soc = at91sam9260_soc;
145 break;
146
147 case ARCH_ID_AT91SAM9G45:
148 at91_soc_initdata.type = AT91_SOC_SAM9G45;
149 if (cidr == ARCH_ID_AT91SAM9G45ES)
150 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
151 at91_boot_soc = at91sam9g45_soc;
152 break;
153
154 case ARCH_ID_AT91SAM9RL64:
155 at91_soc_initdata.type = AT91_SOC_SAM9RL;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200156 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800157 at91_boot_soc = at91sam9rl_soc;
158 break;
159
160 case ARCH_ID_AT91SAM9X5:
161 at91_soc_initdata.type = AT91_SOC_SAM9X5;
162 at91_boot_soc = at91sam9x5_soc;
163 break;
Hong Xu74db4fb2012-04-17 14:26:31 +0800164
165 case ARCH_ID_AT91SAM9N12:
166 at91_soc_initdata.type = AT91_SOC_SAM9N12;
167 at91_boot_soc = at91sam9n12_soc;
168 break;
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000169
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200170 case ARCH_ID_SAMA5:
171 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
172 if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
173 at91_soc_initdata.type = AT91_SOC_SAMA5D3;
174 at91_boot_soc = sama5d3_soc;
175 }
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000176 break;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800177 }
178
179 /* at91sam9g10 */
Ivan Shugov3d9a0182012-10-24 11:02:44 +0200180 if ((socid & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800181 at91_soc_initdata.type = AT91_SOC_SAM9G10;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200182 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800183 at91_boot_soc = at91sam9261_soc;
184 }
185 /* at91sam9xe */
186 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
187 at91_soc_initdata.type = AT91_SOC_SAM9260;
188 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
189 at91_boot_soc = at91sam9260_soc;
190 }
191
192 if (!at91_soc_is_detected())
193 return;
194
195 at91_soc_initdata.cidr = cidr;
196
197 /* sub version of soc */
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200198 if (!at91_soc_initdata.exid)
199 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800200
201 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
202 switch (at91_soc_initdata.exid) {
203 case ARCH_EXID_AT91SAM9M10:
204 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
205 break;
206 case ARCH_EXID_AT91SAM9G46:
207 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
208 break;
209 case ARCH_EXID_AT91SAM9M11:
210 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
211 break;
212 }
213 }
214
215 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
216 switch (at91_soc_initdata.exid) {
217 case ARCH_EXID_AT91SAM9G15:
218 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
219 break;
220 case ARCH_EXID_AT91SAM9G35:
221 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
222 break;
223 case ARCH_EXID_AT91SAM9X35:
224 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
225 break;
226 case ARCH_EXID_AT91SAM9G25:
227 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
228 break;
229 case ARCH_EXID_AT91SAM9X25:
230 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
231 break;
232 }
233 }
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000234
235 if (at91_soc_initdata.type == AT91_SOC_SAMA5D3) {
236 switch (at91_soc_initdata.exid) {
237 case ARCH_EXID_SAMA5D31:
238 at91_soc_initdata.subtype = AT91_SOC_SAMA5D31;
239 break;
240 case ARCH_EXID_SAMA5D33:
241 at91_soc_initdata.subtype = AT91_SOC_SAMA5D33;
242 break;
243 case ARCH_EXID_SAMA5D34:
244 at91_soc_initdata.subtype = AT91_SOC_SAMA5D34;
245 break;
246 case ARCH_EXID_SAMA5D35:
247 at91_soc_initdata.subtype = AT91_SOC_SAMA5D35;
248 break;
Josh Wu7f457162013-11-06 18:01:11 +0800249 case ARCH_EXID_SAMA5D36:
250 at91_soc_initdata.subtype = AT91_SOC_SAMA5D36;
251 break;
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000252 }
253 }
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800254}
255
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200256static void __init alt_soc_detect(u32 dbgu_base)
257{
258 u32 cidr, socid;
259
260 /* SoC ID */
261 cidr = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
262 socid = cidr & ~AT91_CIDR_VERSION;
263
264 switch (socid) {
265 case ARCH_ID_SAMA5:
266 at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
267 if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
268 at91_soc_initdata.type = AT91_SOC_SAMA5D3;
269 at91_boot_soc = sama5d3_soc;
270 } else if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D4) {
271 at91_soc_initdata.type = AT91_SOC_SAMA5D4;
272 at91_boot_soc = sama5d4_soc;
273 }
274 break;
275 }
276
277 if (!at91_soc_is_detected())
278 return;
279
280 at91_soc_initdata.cidr = cidr;
281
282 /* sub version of soc */
283 if (!at91_soc_initdata.exid)
284 at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
285
286 if (at91_soc_initdata.type == AT91_SOC_SAMA5D4) {
287 switch (at91_soc_initdata.exid) {
288 case ARCH_EXID_SAMA5D41:
289 at91_soc_initdata.subtype = AT91_SOC_SAMA5D41;
290 break;
291 case ARCH_EXID_SAMA5D42:
292 at91_soc_initdata.subtype = AT91_SOC_SAMA5D42;
293 break;
294 case ARCH_EXID_SAMA5D43:
295 at91_soc_initdata.subtype = AT91_SOC_SAMA5D43;
296 break;
297 case ARCH_EXID_SAMA5D44:
298 at91_soc_initdata.subtype = AT91_SOC_SAMA5D44;
299 break;
300 }
301 }
302}
303
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800304static const char *soc_name[] = {
305 [AT91_SOC_RM9200] = "at91rm9200",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800306 [AT91_SOC_SAM9260] = "at91sam9260",
307 [AT91_SOC_SAM9261] = "at91sam9261",
308 [AT91_SOC_SAM9263] = "at91sam9263",
309 [AT91_SOC_SAM9G10] = "at91sam9g10",
310 [AT91_SOC_SAM9G20] = "at91sam9g20",
311 [AT91_SOC_SAM9G45] = "at91sam9g45",
312 [AT91_SOC_SAM9RL] = "at91sam9rl",
313 [AT91_SOC_SAM9X5] = "at91sam9x5",
Hong Xu74db4fb2012-04-17 14:26:31 +0800314 [AT91_SOC_SAM9N12] = "at91sam9n12",
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000315 [AT91_SOC_SAMA5D3] = "sama5d3",
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200316 [AT91_SOC_SAMA5D4] = "sama5d4",
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200317 [AT91_SOC_UNKNOWN] = "Unknown",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800318};
319
320const char *at91_get_soc_type(struct at91_socinfo *c)
321{
322 return soc_name[c->type];
323}
324EXPORT_SYMBOL(at91_get_soc_type);
325
326static const char *soc_subtype_name[] = {
327 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
328 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800329 [AT91_SOC_SAM9XE] = "at91sam9xe",
330 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
331 [AT91_SOC_SAM9M10] = "at91sam9m10",
332 [AT91_SOC_SAM9G46] = "at91sam9g46",
333 [AT91_SOC_SAM9M11] = "at91sam9m11",
334 [AT91_SOC_SAM9G15] = "at91sam9g15",
335 [AT91_SOC_SAM9G35] = "at91sam9g35",
336 [AT91_SOC_SAM9X35] = "at91sam9x35",
337 [AT91_SOC_SAM9G25] = "at91sam9g25",
338 [AT91_SOC_SAM9X25] = "at91sam9x25",
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000339 [AT91_SOC_SAMA5D31] = "sama5d31",
340 [AT91_SOC_SAMA5D33] = "sama5d33",
341 [AT91_SOC_SAMA5D34] = "sama5d34",
342 [AT91_SOC_SAMA5D35] = "sama5d35",
Josh Wu7f457162013-11-06 18:01:11 +0800343 [AT91_SOC_SAMA5D36] = "sama5d36",
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200344 [AT91_SOC_SAMA5D41] = "sama5d41",
345 [AT91_SOC_SAMA5D42] = "sama5d42",
346 [AT91_SOC_SAMA5D43] = "sama5d43",
347 [AT91_SOC_SAMA5D44] = "sama5d44",
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200348 [AT91_SOC_SUBTYPE_NONE] = "None",
349 [AT91_SOC_SUBTYPE_UNKNOWN] = "Unknown",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800350};
351
352const char *at91_get_soc_subtype(struct at91_socinfo *c)
353{
354 return soc_subtype_name[c->subtype];
355}
356EXPORT_SYMBOL(at91_get_soc_subtype);
357
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800358void __init at91_map_io(void)
359{
360 /* Map peripherals */
361 iotable_init(&at91_io_desc, 1);
362
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200363 at91_soc_initdata.type = AT91_SOC_UNKNOWN;
364 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800365
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800366 soc_detect(AT91_BASE_DBGU0);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800367 if (!at91_soc_is_detected())
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800368 soc_detect(AT91_BASE_DBGU1);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800369
370 if (!at91_soc_is_detected())
Maxime Ripard9e8be232014-07-02 12:04:43 +0200371 panic(pr_fmt("Impossible to detect the SOC type"));
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800372
Maxime Ripard9e8be232014-07-02 12:04:43 +0200373 pr_info("Detected soc type: %s\n",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800374 at91_get_soc_type(&at91_soc_initdata));
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200375 if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
Maxime Ripard9e8be232014-07-02 12:04:43 +0200376 pr_info("Detected soc subtype: %s\n",
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200377 at91_get_soc_subtype(&at91_soc_initdata));
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800378
379 if (!at91_soc_is_enabled())
Maxime Ripard9e8be232014-07-02 12:04:43 +0200380 panic(pr_fmt("Soc not enabled"));
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800381
382 if (at91_boot_soc.map_io)
383 at91_boot_soc.map_io();
384}
385
Nicolas Ferre726d32b2014-09-15 18:15:55 +0200386void __init at91_alt_map_io(void)
387{
388 /* Map peripherals */
389 iotable_init(&at91_alt_io_desc, 1);
390
391 at91_soc_initdata.type = AT91_SOC_UNKNOWN;
392 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
393
394 alt_soc_detect(AT91_BASE_DBGU2);
395 if (!at91_soc_is_detected())
396 panic("AT91: Impossible to detect the SOC type");
397
398 pr_info("AT91: Detected soc type: %s\n",
399 at91_get_soc_type(&at91_soc_initdata));
400 if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
401 pr_info("AT91: Detected soc subtype: %s\n",
402 at91_get_soc_subtype(&at91_soc_initdata));
403
404 if (!at91_soc_is_enabled())
405 panic("AT91: Soc not enabled");
406
407 if (at91_boot_soc.map_io)
408 at91_boot_soc.map_io();
409}
410
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800411void __iomem *at91_matrix_base;
Joachim Eastwoodac8c4112012-04-07 19:30:23 +0200412EXPORT_SYMBOL_GPL(at91_matrix_base);
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800413
414void __init at91_ioremap_matrix(u32 base_addr)
415{
416 at91_matrix_base = ioremap(base_addr, 512);
417 if (!at91_matrix_base)
Maxime Ripard9e8be232014-07-02 12:04:43 +0200418 panic(pr_fmt("Impossible to ioremap at91_matrix_base\n"));
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800419}
420
Arnd Bergmanndfe36762014-03-13 17:44:55 +0100421#if defined(CONFIG_OF) && !defined(CONFIG_ARCH_AT91X40)
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800422static struct of_device_id ramc_ids[] = {
Jean-Christophe PLAGNIOL-VILLARD6b625892013-10-16 16:24:57 +0200423 { .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby },
424 { .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby },
425 { .compatible = "atmel,at91sam9g45-ddramc", .data = at91_ddr_standby },
Alexandre Belloni017b5522014-07-08 18:21:11 +0200426 { .compatible = "atmel,sama5d3-ddramc", .data = at91_ddr_standby },
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800427 { /*sentinel*/ }
428};
429
430static void at91_dt_ramc(void)
431{
432 struct device_node *np;
Jean-Christophe PLAGNIOL-VILLARD6b625892013-10-16 16:24:57 +0200433 const struct of_device_id *of_id;
Maxime Ripard8d248f02014-07-03 15:58:49 +0200434 int idx = 0;
Alexandre Bellonic8260db2014-08-27 18:06:51 +0200435 const void *standby = NULL;
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800436
Alexandre Bellonic8260db2014-08-27 18:06:51 +0200437 for_each_matching_node_and_match(np, ramc_ids, &of_id) {
Maxime Ripard8d248f02014-07-03 15:58:49 +0200438 at91_ramc_base[idx] = of_iomap(np, 0);
439 if (!at91_ramc_base[idx])
440 panic(pr_fmt("unable to map ramc[%d] cpu registers\n"), idx);
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800441
Alexandre Bellonic8260db2014-08-27 18:06:51 +0200442 if (!standby)
443 standby = of_id->data;
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800444
Maxime Ripard8d248f02014-07-03 15:58:49 +0200445 idx++;
446 }
Jean-Christophe PLAGNIOL-VILLARD6b625892013-10-16 16:24:57 +0200447
Maxime Ripard8d248f02014-07-03 15:58:49 +0200448 if (!idx)
Maxime Ripard9e8be232014-07-02 12:04:43 +0200449 panic(pr_fmt("unable to find compatible ram controller node in dtb\n"));
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800450
Alexandre Bellonic8260db2014-08-27 18:06:51 +0200451 if (!standby) {
Maxime Ripard9e8be232014-07-02 12:04:43 +0200452 pr_warn("ramc no standby function available\n");
Jean-Christophe PLAGNIOL-VILLARD82015c42012-03-02 21:01:00 +0800453 return;
454 }
455
Alexandre Bellonic8260db2014-08-27 18:06:51 +0200456 at91_pm_set_standby(standby);
Jean-Christophe PLAGNIOL-VILLARD82015c42012-03-02 21:01:00 +0800457}
458
Joachim Eastwood397f8c32012-10-28 18:31:09 +0000459void __init at91rm9200_dt_initialize(void)
460{
461 at91_dt_ramc();
462
463 /* Init clock subsystem */
464 at91_dt_clock_init();
465
466 /* Register the processor-specific clocks */
Boris BREZILLONc8a8c632013-10-11 09:37:46 +0200467 if (at91_boot_soc.register_clocks)
468 at91_boot_soc.register_clocks();
Joachim Eastwood397f8c32012-10-28 18:31:09 +0000469
470 at91_boot_soc.init();
471}
472
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800473void __init at91_dt_initialize(void)
474{
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800475 at91_dt_ramc();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800476
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800477 /* Init clock subsystem */
Jean-Christophe PLAGNIOL-VILLARDeb5e76f2012-03-02 20:44:23 +0800478 at91_dt_clock_init();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800479
480 /* Register the processor-specific clocks */
Boris BREZILLONc8a8c632013-10-11 09:37:46 +0200481 if (at91_boot_soc.register_clocks)
482 at91_boot_soc.register_clocks();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800483
Jean-Christophe PLAGNIOL-VILLARD5314ec82012-07-05 16:56:09 +0800484 if (at91_boot_soc.init)
485 at91_boot_soc.init();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800486}
487#endif
488
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800489void __init at91_initialize(unsigned long main_clock)
490{
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800491 at91_boot_soc.ioremap_registers();
492
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800493 /* Init clock subsystem */
494 at91_clock_init(main_clock);
495
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800496 /* Register the processor-specific clocks */
497 at91_boot_soc.register_clocks();
498
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800499 at91_boot_soc.init();
Jean-Christophe PLAGNIOL-VILLARD97e5e622012-07-12 23:35:02 +0800500
501 pinctrl_provide_dummies();
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800502}
Maxime Ripard65f2ce92014-07-02 17:49:28 +0200503
504void __init at91_register_devices(void)
505{
506 at91_boot_soc.register_devices();
507}
Maxime Ripardd2992e52014-09-02 18:05:04 +0200508
509void __init at91_init_time(void)
510{
511 at91_boot_soc.init_time();
512}