2 * Copyright (C) 2007 Atmel Corporation.
3 * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
8 #define pr_fmt(fmt) "AT91: " fmt
10 #include <linux/module.h>
14 #include <linux/of_address.h>
15 #include <linux/pinctrl/machine.h>
16 #include <linux/clk/at91_pmc.h>
18 #include <asm/system_misc.h>
19 #include <asm/mach/map.h>
21 #include <mach/hardware.h>
23 #include <mach/at91_dbgu.h>
29 struct at91_init_soc __initdata at91_boot_soc;
31 struct at91_socinfo at91_soc_initdata;
32 EXPORT_SYMBOL(at91_soc_initdata);
34 void __init at91rm9200_set_type(int type)
36 if (type == ARCH_REVISON_9200_PQFP)
37 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
39 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
41 pr_info("filled in soc subtype: %s\n",
42 at91_get_soc_subtype(&at91_soc_initdata));
45 void __init at91_init_irq_default(void)
47 at91_init_interrupts(at91_boot_soc.default_irq_priority);
50 void __init at91_init_interrupts(unsigned int *priority)
52 /* Initialize the AIC interrupt controller */
53 if (IS_ENABLED(CONFIG_OLD_IRQ_AT91))
54 at91_aic_init(priority, at91_boot_soc.extern_irq);
56 /* Enable GPIO interrupts */
57 at91_gpio_irq_setup();
60 void __iomem *at91_ramc_base[2];
61 EXPORT_SYMBOL_GPL(at91_ramc_base);
63 void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
65 if (id < 0 || id > 1) {
66 pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
69 at91_ramc_base[id] = ioremap(addr, size);
70 if (!at91_ramc_base[id])
71 panic(pr_fmt("Impossible to ioremap ramc.%d 0x%x\n"), id, addr);
74 static struct map_desc sram_desc[2] __initdata;
76 void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
78 struct map_desc *desc = &sram_desc[bank];
80 desc->virtual = (unsigned long)AT91_IO_VIRT_BASE - length;
82 desc->virtual -= sram_desc[bank - 1].length;
84 desc->pfn = __phys_to_pfn(base);
85 desc->length = length;
86 desc->type = MT_MEMORY_RWX_NONCACHED;
88 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
89 base, length, desc->virtual);
91 iotable_init(desc, 1);
94 static struct map_desc at91_io_desc __initdata __maybe_unused = {
95 .virtual = (unsigned long)AT91_VA_BASE_SYS,
96 .pfn = __phys_to_pfn(AT91_BASE_SYS),
101 static void __init soc_detect(u32 dbgu_base)
105 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
106 socid = cidr & ~AT91_CIDR_VERSION;
109 case ARCH_ID_AT91RM9200:
110 at91_soc_initdata.type = AT91_SOC_RM9200;
111 if (at91_soc_initdata.subtype == AT91_SOC_SUBTYPE_UNKNOWN)
112 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
113 at91_boot_soc = at91rm9200_soc;
116 case ARCH_ID_AT91SAM9260:
117 at91_soc_initdata.type = AT91_SOC_SAM9260;
118 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
119 at91_boot_soc = at91sam9260_soc;
122 case ARCH_ID_AT91SAM9261:
123 at91_soc_initdata.type = AT91_SOC_SAM9261;
124 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
125 at91_boot_soc = at91sam9261_soc;
128 case ARCH_ID_AT91SAM9263:
129 at91_soc_initdata.type = AT91_SOC_SAM9263;
130 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
131 at91_boot_soc = at91sam9263_soc;
134 case ARCH_ID_AT91SAM9G20:
135 at91_soc_initdata.type = AT91_SOC_SAM9G20;
136 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
137 at91_boot_soc = at91sam9260_soc;
140 case ARCH_ID_AT91SAM9G45:
141 at91_soc_initdata.type = AT91_SOC_SAM9G45;
142 if (cidr == ARCH_ID_AT91SAM9G45ES)
143 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
144 at91_boot_soc = at91sam9g45_soc;
147 case ARCH_ID_AT91SAM9RL64:
148 at91_soc_initdata.type = AT91_SOC_SAM9RL;
149 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
150 at91_boot_soc = at91sam9rl_soc;
153 case ARCH_ID_AT91SAM9X5:
154 at91_soc_initdata.type = AT91_SOC_SAM9X5;
155 at91_boot_soc = at91sam9x5_soc;
158 case ARCH_ID_AT91SAM9N12:
159 at91_soc_initdata.type = AT91_SOC_SAM9N12;
160 at91_boot_soc = at91sam9n12_soc;
163 case ARCH_ID_SAMA5D3:
164 at91_soc_initdata.type = AT91_SOC_SAMA5D3;
165 at91_boot_soc = sama5d3_soc;
170 if ((socid & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
171 at91_soc_initdata.type = AT91_SOC_SAM9G10;
172 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
173 at91_boot_soc = at91sam9261_soc;
176 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
177 at91_soc_initdata.type = AT91_SOC_SAM9260;
178 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
179 at91_boot_soc = at91sam9260_soc;
182 if (!at91_soc_is_detected())
185 at91_soc_initdata.cidr = cidr;
187 /* sub version of soc */
188 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
190 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
191 switch (at91_soc_initdata.exid) {
192 case ARCH_EXID_AT91SAM9M10:
193 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
195 case ARCH_EXID_AT91SAM9G46:
196 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
198 case ARCH_EXID_AT91SAM9M11:
199 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
204 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
205 switch (at91_soc_initdata.exid) {
206 case ARCH_EXID_AT91SAM9G15:
207 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
209 case ARCH_EXID_AT91SAM9G35:
210 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
212 case ARCH_EXID_AT91SAM9X35:
213 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
215 case ARCH_EXID_AT91SAM9G25:
216 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
218 case ARCH_EXID_AT91SAM9X25:
219 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
224 if (at91_soc_initdata.type == AT91_SOC_SAMA5D3) {
225 switch (at91_soc_initdata.exid) {
226 case ARCH_EXID_SAMA5D31:
227 at91_soc_initdata.subtype = AT91_SOC_SAMA5D31;
229 case ARCH_EXID_SAMA5D33:
230 at91_soc_initdata.subtype = AT91_SOC_SAMA5D33;
232 case ARCH_EXID_SAMA5D34:
233 at91_soc_initdata.subtype = AT91_SOC_SAMA5D34;
235 case ARCH_EXID_SAMA5D35:
236 at91_soc_initdata.subtype = AT91_SOC_SAMA5D35;
238 case ARCH_EXID_SAMA5D36:
239 at91_soc_initdata.subtype = AT91_SOC_SAMA5D36;
245 static const char *soc_name[] = {
246 [AT91_SOC_RM9200] = "at91rm9200",
247 [AT91_SOC_SAM9260] = "at91sam9260",
248 [AT91_SOC_SAM9261] = "at91sam9261",
249 [AT91_SOC_SAM9263] = "at91sam9263",
250 [AT91_SOC_SAM9G10] = "at91sam9g10",
251 [AT91_SOC_SAM9G20] = "at91sam9g20",
252 [AT91_SOC_SAM9G45] = "at91sam9g45",
253 [AT91_SOC_SAM9RL] = "at91sam9rl",
254 [AT91_SOC_SAM9X5] = "at91sam9x5",
255 [AT91_SOC_SAM9N12] = "at91sam9n12",
256 [AT91_SOC_SAMA5D3] = "sama5d3",
257 [AT91_SOC_UNKNOWN] = "Unknown",
260 const char *at91_get_soc_type(struct at91_socinfo *c)
262 return soc_name[c->type];
264 EXPORT_SYMBOL(at91_get_soc_type);
266 static const char *soc_subtype_name[] = {
267 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
268 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
269 [AT91_SOC_SAM9XE] = "at91sam9xe",
270 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
271 [AT91_SOC_SAM9M10] = "at91sam9m10",
272 [AT91_SOC_SAM9G46] = "at91sam9g46",
273 [AT91_SOC_SAM9M11] = "at91sam9m11",
274 [AT91_SOC_SAM9G15] = "at91sam9g15",
275 [AT91_SOC_SAM9G35] = "at91sam9g35",
276 [AT91_SOC_SAM9X35] = "at91sam9x35",
277 [AT91_SOC_SAM9G25] = "at91sam9g25",
278 [AT91_SOC_SAM9X25] = "at91sam9x25",
279 [AT91_SOC_SAMA5D31] = "sama5d31",
280 [AT91_SOC_SAMA5D33] = "sama5d33",
281 [AT91_SOC_SAMA5D34] = "sama5d34",
282 [AT91_SOC_SAMA5D35] = "sama5d35",
283 [AT91_SOC_SAMA5D36] = "sama5d36",
284 [AT91_SOC_SUBTYPE_NONE] = "None",
285 [AT91_SOC_SUBTYPE_UNKNOWN] = "Unknown",
288 const char *at91_get_soc_subtype(struct at91_socinfo *c)
290 return soc_subtype_name[c->subtype];
292 EXPORT_SYMBOL(at91_get_soc_subtype);
294 void __init at91_map_io(void)
296 /* Map peripherals */
297 iotable_init(&at91_io_desc, 1);
299 at91_soc_initdata.type = AT91_SOC_UNKNOWN;
300 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
302 soc_detect(AT91_BASE_DBGU0);
303 if (!at91_soc_is_detected())
304 soc_detect(AT91_BASE_DBGU1);
306 if (!at91_soc_is_detected())
307 panic(pr_fmt("Impossible to detect the SOC type"));
309 pr_info("Detected soc type: %s\n",
310 at91_get_soc_type(&at91_soc_initdata));
311 if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
312 pr_info("Detected soc subtype: %s\n",
313 at91_get_soc_subtype(&at91_soc_initdata));
315 if (!at91_soc_is_enabled())
316 panic(pr_fmt("Soc not enabled"));
318 if (at91_boot_soc.map_io)
319 at91_boot_soc.map_io();
322 void __iomem *at91_matrix_base;
323 EXPORT_SYMBOL_GPL(at91_matrix_base);
325 void __init at91_ioremap_matrix(u32 base_addr)
327 at91_matrix_base = ioremap(base_addr, 512);
328 if (!at91_matrix_base)
329 panic(pr_fmt("Impossible to ioremap at91_matrix_base\n"));
332 #if defined(CONFIG_OF) && !defined(CONFIG_ARCH_AT91X40)
333 static struct of_device_id ramc_ids[] = {
334 { .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby },
335 { .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby },
336 { .compatible = "atmel,at91sam9g45-ddramc", .data = at91_ddr_standby },
337 { .compatible = "atmel,sama5d3-ddramc", .data = at91_ddr_standby },
341 static void at91_dt_ramc(void)
343 struct device_node *np;
344 const struct of_device_id *of_id;
347 for_each_matching_node(np, ramc_ids) {
348 at91_ramc_base[idx] = of_iomap(np, 0);
349 if (!at91_ramc_base[idx])
350 panic(pr_fmt("unable to map ramc[%d] cpu registers\n"), idx);
356 panic(pr_fmt("unable to find compatible ram controller node in dtb\n"));
358 of_id = of_match_node(ramc_ids, np);
360 pr_warn("ramc no standby function available\n");
364 at91_pm_set_standby(of_id->data);
367 void __init at91rm9200_dt_initialize(void)
371 /* Init clock subsystem */
372 at91_dt_clock_init();
374 /* Register the processor-specific clocks */
375 if (at91_boot_soc.register_clocks)
376 at91_boot_soc.register_clocks();
378 at91_boot_soc.init();
381 void __init at91_dt_initialize(void)
385 /* Init clock subsystem */
386 at91_dt_clock_init();
388 /* Register the processor-specific clocks */
389 if (at91_boot_soc.register_clocks)
390 at91_boot_soc.register_clocks();
392 if (at91_boot_soc.init)
393 at91_boot_soc.init();
397 void __init at91_initialize(unsigned long main_clock)
399 at91_boot_soc.ioremap_registers();
401 /* Init clock subsystem */
402 at91_clock_init(main_clock);
404 /* Register the processor-specific clocks */
405 at91_boot_soc.register_clocks();
407 at91_boot_soc.init();
409 pinctrl_provide_dummies();
412 void __init at91_register_devices(void)
414 at91_boot_soc.register_devices();