blob: 242c26b2368d6b5549f18c7f19d995884084b68f [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-VILLARD21d08b92011-04-23 15:28:34 +080012
13#include <asm/mach/map.h>
14
15#include <mach/hardware.h>
16#include <mach/cpu.h>
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080017#include <mach/at91_dbgu.h>
18#include <mach/at91_pmc.h>
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +080019#include <mach/at91_shdwc.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080020
21#include "soc.h"
22#include "generic.h"
23
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080024struct at91_init_soc __initdata at91_boot_soc;
25
26struct at91_socinfo at91_soc_initdata;
27EXPORT_SYMBOL(at91_soc_initdata);
28
29void __init at91rm9200_set_type(int type)
30{
31 if (type == ARCH_REVISON_9200_PQFP)
32 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
33 else
34 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
35}
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080036
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +080037void __init at91_init_irq_default(void)
38{
39 at91_init_interrupts(at91_boot_soc.default_irq_priority);
40}
41
42void __init at91_init_interrupts(unsigned int *priority)
43{
44 /* Initialize the AIC interrupt controller */
45 at91_aic_init(priority);
46
47 /* Enable GPIO interrupts */
48 at91_gpio_irq_setup();
49}
50
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080051static struct map_desc sram_desc[2] __initdata;
52
53void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
54{
55 struct map_desc *desc = &sram_desc[bank];
56
57 desc->virtual = AT91_IO_VIRT_BASE - length;
58 if (bank > 0)
59 desc->virtual -= sram_desc[bank - 1].length;
60
61 desc->pfn = __phys_to_pfn(base);
62 desc->length = length;
63 desc->type = MT_DEVICE;
64
65 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
66 base, length, desc->virtual);
67
68 iotable_init(desc, 1);
69}
70
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080071static struct map_desc at91_io_desc __initdata = {
72 .virtual = AT91_VA_BASE_SYS,
73 .pfn = __phys_to_pfn(AT91_BASE_SYS),
74 .length = SZ_16K,
75 .type = MT_DEVICE,
76};
77
Jean-Christophe PLAGNIOL-VILLARDfb149f92011-05-07 11:16:00 +080078void __iomem *at91_ioremap(unsigned long p, size_t size, unsigned int type)
79{
80 if (p >= AT91_BASE_SYS && p <= (AT91_BASE_SYS + SZ_16K - 1))
81 return (void __iomem *)AT91_IO_P2V(p);
82
83 return __arm_ioremap_caller(p, size, type, __builtin_return_address(0));
84}
85EXPORT_SYMBOL(at91_ioremap);
86
87void at91_iounmap(volatile void __iomem *addr)
88{
89 unsigned long virt = (unsigned long)addr;
90
91 if (virt >= VMALLOC_START && virt < VMALLOC_END)
92 __iounmap(addr);
93}
94EXPORT_SYMBOL(at91_iounmap);
95
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080096static void __init soc_detect(u32 dbgu_base)
97{
98 u32 cidr, socid;
99
100 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
101 socid = cidr & ~AT91_CIDR_VERSION;
102
103 switch (socid) {
104 case ARCH_ID_AT91CAP9: {
105#ifdef CONFIG_AT91_PMC_UNIT
106 u32 pmc_ver = at91_sys_read(AT91_PMC_VER);
107
108 if (pmc_ver == ARCH_REVISION_CAP9_B)
109 at91_soc_initdata.subtype = AT91_SOC_CAP9_REV_B;
110 else if (pmc_ver == ARCH_REVISION_CAP9_C)
111 at91_soc_initdata.subtype = AT91_SOC_CAP9_REV_C;
112#endif
113 at91_soc_initdata.type = AT91_SOC_CAP9;
114 at91_boot_soc = at91cap9_soc;
115 break;
116 }
117
118 case ARCH_ID_AT91RM9200:
119 at91_soc_initdata.type = AT91_SOC_RM9200;
120 at91_boot_soc = at91rm9200_soc;
121 break;
122
123 case ARCH_ID_AT91SAM9260:
124 at91_soc_initdata.type = AT91_SOC_SAM9260;
125 at91_boot_soc = at91sam9260_soc;
126 break;
127
128 case ARCH_ID_AT91SAM9261:
129 at91_soc_initdata.type = AT91_SOC_SAM9261;
130 at91_boot_soc = at91sam9261_soc;
131 break;
132
133 case ARCH_ID_AT91SAM9263:
134 at91_soc_initdata.type = AT91_SOC_SAM9263;
135 at91_boot_soc = at91sam9263_soc;
136 break;
137
138 case ARCH_ID_AT91SAM9G20:
139 at91_soc_initdata.type = AT91_SOC_SAM9G20;
140 at91_boot_soc = at91sam9260_soc;
141 break;
142
143 case ARCH_ID_AT91SAM9G45:
144 at91_soc_initdata.type = AT91_SOC_SAM9G45;
145 if (cidr == ARCH_ID_AT91SAM9G45ES)
146 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
147 at91_boot_soc = at91sam9g45_soc;
148 break;
149
150 case ARCH_ID_AT91SAM9RL64:
151 at91_soc_initdata.type = AT91_SOC_SAM9RL;
152 at91_boot_soc = at91sam9rl_soc;
153 break;
154
155 case ARCH_ID_AT91SAM9X5:
156 at91_soc_initdata.type = AT91_SOC_SAM9X5;
157 at91_boot_soc = at91sam9x5_soc;
158 break;
159 }
160
161 /* at91sam9g10 */
162 if ((cidr & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
163 at91_soc_initdata.type = AT91_SOC_SAM9G10;
164 at91_boot_soc = at91sam9261_soc;
165 }
166 /* at91sam9xe */
167 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
168 at91_soc_initdata.type = AT91_SOC_SAM9260;
169 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
170 at91_boot_soc = at91sam9260_soc;
171 }
172
173 if (!at91_soc_is_detected())
174 return;
175
176 at91_soc_initdata.cidr = cidr;
177
178 /* sub version of soc */
179 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
180
181 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
182 switch (at91_soc_initdata.exid) {
183 case ARCH_EXID_AT91SAM9M10:
184 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
185 break;
186 case ARCH_EXID_AT91SAM9G46:
187 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
188 break;
189 case ARCH_EXID_AT91SAM9M11:
190 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
191 break;
192 }
193 }
194
195 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
196 switch (at91_soc_initdata.exid) {
197 case ARCH_EXID_AT91SAM9G15:
198 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
199 break;
200 case ARCH_EXID_AT91SAM9G35:
201 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
202 break;
203 case ARCH_EXID_AT91SAM9X35:
204 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
205 break;
206 case ARCH_EXID_AT91SAM9G25:
207 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
208 break;
209 case ARCH_EXID_AT91SAM9X25:
210 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
211 break;
212 }
213 }
214}
215
216static const char *soc_name[] = {
217 [AT91_SOC_RM9200] = "at91rm9200",
218 [AT91_SOC_CAP9] = "at91cap9",
219 [AT91_SOC_SAM9260] = "at91sam9260",
220 [AT91_SOC_SAM9261] = "at91sam9261",
221 [AT91_SOC_SAM9263] = "at91sam9263",
222 [AT91_SOC_SAM9G10] = "at91sam9g10",
223 [AT91_SOC_SAM9G20] = "at91sam9g20",
224 [AT91_SOC_SAM9G45] = "at91sam9g45",
225 [AT91_SOC_SAM9RL] = "at91sam9rl",
226 [AT91_SOC_SAM9X5] = "at91sam9x5",
227 [AT91_SOC_NONE] = "Unknown"
228};
229
230const char *at91_get_soc_type(struct at91_socinfo *c)
231{
232 return soc_name[c->type];
233}
234EXPORT_SYMBOL(at91_get_soc_type);
235
236static const char *soc_subtype_name[] = {
237 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
238 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
239 [AT91_SOC_CAP9_REV_B] = "at91cap9 revB",
240 [AT91_SOC_CAP9_REV_C] = "at91cap9 revC",
241 [AT91_SOC_SAM9XE] = "at91sam9xe",
242 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
243 [AT91_SOC_SAM9M10] = "at91sam9m10",
244 [AT91_SOC_SAM9G46] = "at91sam9g46",
245 [AT91_SOC_SAM9M11] = "at91sam9m11",
246 [AT91_SOC_SAM9G15] = "at91sam9g15",
247 [AT91_SOC_SAM9G35] = "at91sam9g35",
248 [AT91_SOC_SAM9X35] = "at91sam9x35",
249 [AT91_SOC_SAM9G25] = "at91sam9g25",
250 [AT91_SOC_SAM9X25] = "at91sam9x25",
251 [AT91_SOC_SUBTYPE_NONE] = "Unknown"
252};
253
254const char *at91_get_soc_subtype(struct at91_socinfo *c)
255{
256 return soc_subtype_name[c->subtype];
257}
258EXPORT_SYMBOL(at91_get_soc_subtype);
259
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800260void __init at91_map_io(void)
261{
262 /* Map peripherals */
263 iotable_init(&at91_io_desc, 1);
264
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800265 at91_soc_initdata.type = AT91_SOC_NONE;
266 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
267
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800268 soc_detect(AT91_BASE_DBGU0);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800269 if (!at91_soc_is_detected())
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800270 soc_detect(AT91_BASE_DBGU1);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800271
272 if (!at91_soc_is_detected())
273 panic("AT91: Impossible to detect the SOC type");
274
275 pr_info("AT91: Detected soc type: %s\n",
276 at91_get_soc_type(&at91_soc_initdata));
277 pr_info("AT91: Detected soc subtype: %s\n",
278 at91_get_soc_subtype(&at91_soc_initdata));
279
280 if (!at91_soc_is_enabled())
281 panic("AT91: Soc not enabled");
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800282
283 if (at91_boot_soc.map_io)
284 at91_boot_soc.map_io();
285}
286
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +0800287void __iomem *at91_shdwc_base = NULL;
288
289static void at91sam9_poweroff(void)
290{
291 at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
292}
293
294void __init at91_ioremap_shdwc(u32 base_addr)
295{
296 at91_shdwc_base = ioremap(base_addr, 16);
297 if (!at91_shdwc_base)
298 panic("Impossible to ioremap at91_shdwc_base\n");
299 pm_power_off = at91sam9_poweroff;
300}
301
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800302void __init at91_initialize(unsigned long main_clock)
303{
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800304 at91_boot_soc.ioremap_registers();
305
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800306 /* Init clock subsystem */
307 at91_clock_init(main_clock);
308
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800309 /* Register the processor-specific clocks */
310 at91_boot_soc.register_clocks();
311
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800312 at91_boot_soc.init();
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800313}