blob: b17fbcf4d9e8f34dbd876ea96af334dae4780efc [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
8#include <linux/module.h>
9#include <linux/io.h>
Jean-Christophe PLAGNIOL-VILLARDfb149f92011-05-07 11:16:00 +080010#include <linux/mm.h>
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +080011#include <linux/pm.h>
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +080012#include <linux/of_address.h>
Jean-Christophe PLAGNIOL-VILLARD97e5e622012-07-12 23:35:02 +080013#include <linux/pinctrl/machine.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080014
Olof Johansson86dfe442012-03-29 23:22:44 -070015#include <asm/system_misc.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080016#include <asm/mach/map.h>
17
18#include <mach/hardware.h>
19#include <mach/cpu.h>
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080020#include <mach/at91_dbgu.h>
21#include <mach/at91_pmc.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080022
Jean-Christophe PLAGNIOL-VILLARD176bdd22012-10-30 08:07:11 +080023#include "at91_shdwc.h"
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080024#include "soc.h"
25#include "generic.h"
26
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080027struct at91_init_soc __initdata at91_boot_soc;
28
29struct at91_socinfo at91_soc_initdata;
30EXPORT_SYMBOL(at91_soc_initdata);
31
32void __init at91rm9200_set_type(int type)
33{
34 if (type == ARCH_REVISON_9200_PQFP)
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080035 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
Nicolas Ferre3e907722011-12-28 13:10:04 +020036 else
37 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
38
39 pr_info("AT91: filled in soc subtype: %s\n",
40 at91_get_soc_subtype(&at91_soc_initdata));
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080041}
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080042
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +080043void __init at91_init_irq_default(void)
44{
45 at91_init_interrupts(at91_boot_soc.default_irq_priority);
46}
47
48void __init at91_init_interrupts(unsigned int *priority)
49{
50 /* Initialize the AIC interrupt controller */
Jean-Christophe PLAGNIOL-VILLARD546c8302013-06-01 16:40:11 +020051 at91_aic_init(priority, at91_boot_soc.extern_irq);
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +080052
53 /* Enable GPIO interrupts */
54 at91_gpio_irq_setup();
55}
56
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +080057void __iomem *at91_ramc_base[2];
Joachim Eastwood9268c6c2012-03-30 23:03:50 +020058EXPORT_SYMBOL_GPL(at91_ramc_base);
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +080059
60void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
61{
62 if (id < 0 || id > 1) {
63 pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
64 BUG();
65 }
66 at91_ramc_base[id] = ioremap(addr, size);
67 if (!at91_ramc_base[id])
68 panic("Impossible to ioremap ramc.%d 0x%x\n", id, addr);
69}
70
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080071static struct map_desc sram_desc[2] __initdata;
72
73void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
74{
75 struct map_desc *desc = &sram_desc[bank];
76
Arnd Bergmanndca4ba42012-09-14 20:10:19 +000077 desc->virtual = (unsigned long)AT91_IO_VIRT_BASE - length;
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080078 if (bank > 0)
79 desc->virtual -= sram_desc[bank - 1].length;
80
81 desc->pfn = __phys_to_pfn(base);
82 desc->length = length;
Wenyou Yang133e0012013-06-08 02:17:43 +000083 desc->type = MT_MEMORY_NONCACHED;
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080084
85 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
86 base, length, desc->virtual);
87
88 iotable_init(desc, 1);
89}
90
Arnd Bergmannac092812012-04-30 13:18:53 +000091static struct map_desc at91_io_desc __initdata __maybe_unused = {
Arnd Bergmanndca4ba42012-09-14 20:10:19 +000092 .virtual = (unsigned long)AT91_VA_BASE_SYS,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080093 .pfn = __phys_to_pfn(AT91_BASE_SYS),
94 .length = SZ_16K,
95 .type = MT_DEVICE,
96};
97
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080098static void __init soc_detect(u32 dbgu_base)
99{
100 u32 cidr, socid;
101
102 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
103 socid = cidr & ~AT91_CIDR_VERSION;
104
105 switch (socid) {
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800106 case ARCH_ID_AT91RM9200:
107 at91_soc_initdata.type = AT91_SOC_RM9200;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200108 if (at91_soc_initdata.subtype == AT91_SOC_SUBTYPE_UNKNOWN)
Jean-Christophe PLAGNIOL-VILLARD36224d02012-12-23 18:07:49 +0000109 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800110 at91_boot_soc = at91rm9200_soc;
111 break;
112
113 case ARCH_ID_AT91SAM9260:
114 at91_soc_initdata.type = AT91_SOC_SAM9260;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200115 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800116 at91_boot_soc = at91sam9260_soc;
117 break;
118
119 case ARCH_ID_AT91SAM9261:
120 at91_soc_initdata.type = AT91_SOC_SAM9261;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200121 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800122 at91_boot_soc = at91sam9261_soc;
123 break;
124
125 case ARCH_ID_AT91SAM9263:
126 at91_soc_initdata.type = AT91_SOC_SAM9263;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200127 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800128 at91_boot_soc = at91sam9263_soc;
129 break;
130
131 case ARCH_ID_AT91SAM9G20:
132 at91_soc_initdata.type = AT91_SOC_SAM9G20;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200133 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800134 at91_boot_soc = at91sam9260_soc;
135 break;
136
137 case ARCH_ID_AT91SAM9G45:
138 at91_soc_initdata.type = AT91_SOC_SAM9G45;
139 if (cidr == ARCH_ID_AT91SAM9G45ES)
140 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
141 at91_boot_soc = at91sam9g45_soc;
142 break;
143
144 case ARCH_ID_AT91SAM9RL64:
145 at91_soc_initdata.type = AT91_SOC_SAM9RL;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200146 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800147 at91_boot_soc = at91sam9rl_soc;
148 break;
149
150 case ARCH_ID_AT91SAM9X5:
151 at91_soc_initdata.type = AT91_SOC_SAM9X5;
152 at91_boot_soc = at91sam9x5_soc;
153 break;
Hong Xu74db4fb2012-04-17 14:26:31 +0800154
155 case ARCH_ID_AT91SAM9N12:
156 at91_soc_initdata.type = AT91_SOC_SAM9N12;
157 at91_boot_soc = at91sam9n12_soc;
158 break;
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000159
160 case ARCH_ID_SAMA5D3:
161 at91_soc_initdata.type = AT91_SOC_SAMA5D3;
162 at91_boot_soc = sama5d3_soc;
163 break;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800164 }
165
166 /* at91sam9g10 */
Ivan Shugov3d9a0182012-10-24 11:02:44 +0200167 if ((socid & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800168 at91_soc_initdata.type = AT91_SOC_SAM9G10;
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200169 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800170 at91_boot_soc = at91sam9261_soc;
171 }
172 /* at91sam9xe */
173 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
174 at91_soc_initdata.type = AT91_SOC_SAM9260;
175 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
176 at91_boot_soc = at91sam9260_soc;
177 }
178
179 if (!at91_soc_is_detected())
180 return;
181
182 at91_soc_initdata.cidr = cidr;
183
184 /* sub version of soc */
185 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
186
187 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
188 switch (at91_soc_initdata.exid) {
189 case ARCH_EXID_AT91SAM9M10:
190 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
191 break;
192 case ARCH_EXID_AT91SAM9G46:
193 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
194 break;
195 case ARCH_EXID_AT91SAM9M11:
196 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
197 break;
198 }
199 }
200
201 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
202 switch (at91_soc_initdata.exid) {
203 case ARCH_EXID_AT91SAM9G15:
204 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
205 break;
206 case ARCH_EXID_AT91SAM9G35:
207 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
208 break;
209 case ARCH_EXID_AT91SAM9X35:
210 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
211 break;
212 case ARCH_EXID_AT91SAM9G25:
213 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
214 break;
215 case ARCH_EXID_AT91SAM9X25:
216 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
217 break;
218 }
219 }
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000220
221 if (at91_soc_initdata.type == AT91_SOC_SAMA5D3) {
222 switch (at91_soc_initdata.exid) {
223 case ARCH_EXID_SAMA5D31:
224 at91_soc_initdata.subtype = AT91_SOC_SAMA5D31;
225 break;
226 case ARCH_EXID_SAMA5D33:
227 at91_soc_initdata.subtype = AT91_SOC_SAMA5D33;
228 break;
229 case ARCH_EXID_SAMA5D34:
230 at91_soc_initdata.subtype = AT91_SOC_SAMA5D34;
231 break;
232 case ARCH_EXID_SAMA5D35:
233 at91_soc_initdata.subtype = AT91_SOC_SAMA5D35;
234 break;
235 }
236 }
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800237}
238
239static const char *soc_name[] = {
240 [AT91_SOC_RM9200] = "at91rm9200",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800241 [AT91_SOC_SAM9260] = "at91sam9260",
242 [AT91_SOC_SAM9261] = "at91sam9261",
243 [AT91_SOC_SAM9263] = "at91sam9263",
244 [AT91_SOC_SAM9G10] = "at91sam9g10",
245 [AT91_SOC_SAM9G20] = "at91sam9g20",
246 [AT91_SOC_SAM9G45] = "at91sam9g45",
247 [AT91_SOC_SAM9RL] = "at91sam9rl",
248 [AT91_SOC_SAM9X5] = "at91sam9x5",
Hong Xu74db4fb2012-04-17 14:26:31 +0800249 [AT91_SOC_SAM9N12] = "at91sam9n12",
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000250 [AT91_SOC_SAMA5D3] = "sama5d3",
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200251 [AT91_SOC_UNKNOWN] = "Unknown",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800252};
253
254const char *at91_get_soc_type(struct at91_socinfo *c)
255{
256 return soc_name[c->type];
257}
258EXPORT_SYMBOL(at91_get_soc_type);
259
260static const char *soc_subtype_name[] = {
261 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
262 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800263 [AT91_SOC_SAM9XE] = "at91sam9xe",
264 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
265 [AT91_SOC_SAM9M10] = "at91sam9m10",
266 [AT91_SOC_SAM9G46] = "at91sam9g46",
267 [AT91_SOC_SAM9M11] = "at91sam9m11",
268 [AT91_SOC_SAM9G15] = "at91sam9g15",
269 [AT91_SOC_SAM9G35] = "at91sam9g35",
270 [AT91_SOC_SAM9X35] = "at91sam9x35",
271 [AT91_SOC_SAM9G25] = "at91sam9g25",
272 [AT91_SOC_SAM9X25] = "at91sam9x25",
Ludovic Desroches8f4b4792013-03-22 13:24:12 +0000273 [AT91_SOC_SAMA5D31] = "sama5d31",
274 [AT91_SOC_SAMA5D33] = "sama5d33",
275 [AT91_SOC_SAMA5D34] = "sama5d34",
276 [AT91_SOC_SAMA5D35] = "sama5d35",
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200277 [AT91_SOC_SUBTYPE_NONE] = "None",
278 [AT91_SOC_SUBTYPE_UNKNOWN] = "Unknown",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800279};
280
281const char *at91_get_soc_subtype(struct at91_socinfo *c)
282{
283 return soc_subtype_name[c->subtype];
284}
285EXPORT_SYMBOL(at91_get_soc_subtype);
286
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800287void __init at91_map_io(void)
288{
289 /* Map peripherals */
290 iotable_init(&at91_io_desc, 1);
291
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200292 at91_soc_initdata.type = AT91_SOC_UNKNOWN;
293 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800294
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800295 soc_detect(AT91_BASE_DBGU0);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800296 if (!at91_soc_is_detected())
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800297 soc_detect(AT91_BASE_DBGU1);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800298
299 if (!at91_soc_is_detected())
300 panic("AT91: Impossible to detect the SOC type");
301
302 pr_info("AT91: Detected soc type: %s\n",
303 at91_get_soc_type(&at91_soc_initdata));
Nicolas Ferre13ab6ae2013-04-09 12:56:21 +0200304 if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
305 pr_info("AT91: Detected soc subtype: %s\n",
306 at91_get_soc_subtype(&at91_soc_initdata));
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800307
308 if (!at91_soc_is_enabled())
309 panic("AT91: Soc not enabled");
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800310
311 if (at91_boot_soc.map_io)
312 at91_boot_soc.map_io();
313}
314
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +0800315void __iomem *at91_shdwc_base = NULL;
316
317static void at91sam9_poweroff(void)
318{
319 at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
320}
321
322void __init at91_ioremap_shdwc(u32 base_addr)
323{
324 at91_shdwc_base = ioremap(base_addr, 16);
325 if (!at91_shdwc_base)
326 panic("Impossible to ioremap at91_shdwc_base\n");
327 pm_power_off = at91sam9_poweroff;
328}
329
Jean-Christophe PLAGNIOL-VILLARDe9f68b52011-11-18 01:25:52 +0800330void __iomem *at91_rstc_base;
331
332void __init at91_ioremap_rstc(u32 base_addr)
333{
334 at91_rstc_base = ioremap(base_addr, 16);
335 if (!at91_rstc_base)
336 panic("Impossible to ioremap at91_rstc_base\n");
337}
338
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800339void __iomem *at91_matrix_base;
Joachim Eastwoodac8c4112012-04-07 19:30:23 +0200340EXPORT_SYMBOL_GPL(at91_matrix_base);
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800341
342void __init at91_ioremap_matrix(u32 base_addr)
343{
344 at91_matrix_base = ioremap(base_addr, 512);
345 if (!at91_matrix_base)
346 panic("Impossible to ioremap at91_matrix_base\n");
347}
348
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800349#if defined(CONFIG_OF)
Jean-Christophe PLAGNIOL-VILLARDc8082d32012-03-03 03:16:27 +0800350static struct of_device_id rstc_ids[] = {
351 { .compatible = "atmel,at91sam9260-rstc", .data = at91sam9_alt_restart },
352 { .compatible = "atmel,at91sam9g45-rstc", .data = at91sam9g45_restart },
353 { /*sentinel*/ }
354};
355
356static void at91_dt_rstc(void)
357{
358 struct device_node *np;
359 const struct of_device_id *of_id;
360
361 np = of_find_matching_node(NULL, rstc_ids);
362 if (!np)
363 panic("unable to find compatible rstc node in dtb\n");
364
365 at91_rstc_base = of_iomap(np, 0);
366 if (!at91_rstc_base)
367 panic("unable to map rstc cpu registers\n");
368
369 of_id = of_match_node(rstc_ids, np);
370 if (!of_id)
Maxime Riparde7619452013-03-23 10:58:57 +0100371 panic("AT91: rtsc no restart function available\n");
Jean-Christophe PLAGNIOL-VILLARDc8082d32012-03-03 03:16:27 +0800372
373 arm_pm_restart = of_id->data;
374
375 of_node_put(np);
376}
377
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800378static struct of_device_id ramc_ids[] = {
Joachim Eastwood397f8c32012-10-28 18:31:09 +0000379 { .compatible = "atmel,at91rm9200-sdramc" },
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800380 { .compatible = "atmel,at91sam9260-sdramc" },
381 { .compatible = "atmel,at91sam9g45-ddramc" },
382 { /*sentinel*/ }
383};
384
385static void at91_dt_ramc(void)
386{
387 struct device_node *np;
388
389 np = of_find_matching_node(NULL, ramc_ids);
390 if (!np)
Johan Hovold95f287e2013-04-07 16:49:58 +0200391 panic("unable to find compatible ram controller node in dtb\n");
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800392
393 at91_ramc_base[0] = of_iomap(np, 0);
394 if (!at91_ramc_base[0])
395 panic("unable to map ramc[0] cpu registers\n");
396 /* the controller may have 2 banks */
397 at91_ramc_base[1] = of_iomap(np, 1);
398
399 of_node_put(np);
400}
401
Jean-Christophe PLAGNIOL-VILLARD82015c42012-03-02 21:01:00 +0800402static struct of_device_id shdwc_ids[] = {
403 { .compatible = "atmel,at91sam9260-shdwc", },
404 { .compatible = "atmel,at91sam9rl-shdwc", },
405 { .compatible = "atmel,at91sam9x5-shdwc", },
406 { /*sentinel*/ }
407};
408
409static const char *shdwc_wakeup_modes[] = {
410 [AT91_SHDW_WKMODE0_NONE] = "none",
411 [AT91_SHDW_WKMODE0_HIGH] = "high",
412 [AT91_SHDW_WKMODE0_LOW] = "low",
413 [AT91_SHDW_WKMODE0_ANYLEVEL] = "any",
414};
415
416const int at91_dtget_shdwc_wakeup_mode(struct device_node *np)
417{
418 const char *pm;
419 int err, i;
420
421 err = of_property_read_string(np, "atmel,wakeup-mode", &pm);
422 if (err < 0)
423 return AT91_SHDW_WKMODE0_ANYLEVEL;
424
425 for (i = 0; i < ARRAY_SIZE(shdwc_wakeup_modes); i++)
426 if (!strcasecmp(pm, shdwc_wakeup_modes[i]))
427 return i;
428
429 return -ENODEV;
430}
431
432static void at91_dt_shdwc(void)
433{
434 struct device_node *np;
435 int wakeup_mode;
436 u32 reg;
437 u32 mode = 0;
438
439 np = of_find_matching_node(NULL, shdwc_ids);
440 if (!np) {
Johan Hovold95f287e2013-04-07 16:49:58 +0200441 pr_debug("AT91: unable to find compatible shutdown (shdwc) controller node in dtb\n");
Jean-Christophe PLAGNIOL-VILLARD82015c42012-03-02 21:01:00 +0800442 return;
443 }
444
445 at91_shdwc_base = of_iomap(np, 0);
446 if (!at91_shdwc_base)
447 panic("AT91: unable to map shdwc cpu registers\n");
448
449 wakeup_mode = at91_dtget_shdwc_wakeup_mode(np);
450 if (wakeup_mode < 0) {
451 pr_warn("AT91: shdwc unknown wakeup mode\n");
452 goto end;
453 }
454
455 if (!of_property_read_u32(np, "atmel,wakeup-counter", &reg)) {
456 if (reg > AT91_SHDW_CPTWK0_MAX) {
Johan Hovold95f287e2013-04-07 16:49:58 +0200457 pr_warn("AT91: shdwc wakeup counter 0x%x > 0x%x reduce it to 0x%x\n",
Jean-Christophe PLAGNIOL-VILLARD82015c42012-03-02 21:01:00 +0800458 reg, AT91_SHDW_CPTWK0_MAX, AT91_SHDW_CPTWK0_MAX);
459 reg = AT91_SHDW_CPTWK0_MAX;
460 }
461 mode |= AT91_SHDW_CPTWK0_(reg);
462 }
463
464 if (of_property_read_bool(np, "atmel,wakeup-rtc-timer"))
465 mode |= AT91_SHDW_RTCWKEN;
466
467 if (of_property_read_bool(np, "atmel,wakeup-rtt-timer"))
468 mode |= AT91_SHDW_RTTWKEN;
469
470 at91_shdwc_write(AT91_SHDW_MR, wakeup_mode | mode);
471
472end:
473 pm_power_off = at91sam9_poweroff;
474
475 of_node_put(np);
476}
477
Joachim Eastwood397f8c32012-10-28 18:31:09 +0000478void __init at91rm9200_dt_initialize(void)
479{
480 at91_dt_ramc();
481
482 /* Init clock subsystem */
483 at91_dt_clock_init();
484
485 /* Register the processor-specific clocks */
486 at91_boot_soc.register_clocks();
487
488 at91_boot_soc.init();
489}
490
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800491void __init at91_dt_initialize(void)
492{
Jean-Christophe PLAGNIOL-VILLARDc8082d32012-03-03 03:16:27 +0800493 at91_dt_rstc();
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800494 at91_dt_ramc();
Jean-Christophe PLAGNIOL-VILLARD82015c42012-03-02 21:01:00 +0800495 at91_dt_shdwc();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800496
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800497 /* Init clock subsystem */
Jean-Christophe PLAGNIOL-VILLARDeb5e76f2012-03-02 20:44:23 +0800498 at91_dt_clock_init();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800499
500 /* Register the processor-specific clocks */
501 at91_boot_soc.register_clocks();
502
Jean-Christophe PLAGNIOL-VILLARD5314ec82012-07-05 16:56:09 +0800503 if (at91_boot_soc.init)
504 at91_boot_soc.init();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800505}
506#endif
507
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800508void __init at91_initialize(unsigned long main_clock)
509{
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800510 at91_boot_soc.ioremap_registers();
511
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800512 /* Init clock subsystem */
513 at91_clock_init(main_clock);
514
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800515 /* Register the processor-specific clocks */
516 at91_boot_soc.register_clocks();
517
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800518 at91_boot_soc.init();
Jean-Christophe PLAGNIOL-VILLARD97e5e622012-07-12 23:35:02 +0800519
520 pinctrl_provide_dummies();
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800521}