blob: accb69ec478e53aca7bffb3e0aedefae89a167b5 [file] [log] [blame]
Andrew Victor62c16602006-11-30 12:27:38 +01001/*
Andrew Victor9d041262007-02-05 11:42:07 +01002 * arch/arm/mach-at91/at91sam9260.c
Andrew Victor62c16602006-11-30 12:27:38 +01003 *
4 * Copyright (C) 2006 SAN People
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12
13#include <linux/module.h>
Andrew Victor3ef2fb42008-04-02 21:36:06 +010014#include <linux/pm.h>
Andrew Victor62c16602006-11-30 12:27:38 +010015
16#include <asm/mach/arch.h>
17#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/cpu.h>
19#include <mach/at91sam9260.h>
20#include <mach/at91_pmc.h>
21#include <mach/at91_rstc.h>
22#include <mach/at91_shdwc.h>
Andrew Victor62c16602006-11-30 12:27:38 +010023
24#include "generic.h"
25#include "clock.h"
26
27static struct map_desc at91sam9260_io_desc[] __initdata = {
28 {
29 .virtual = AT91_VA_BASE_SYS,
30 .pfn = __phys_to_pfn(AT91_BASE_SYS),
31 .length = SZ_16K,
32 .type = MT_DEVICE,
Andrew Victorf7eee892007-02-15 08:17:38 +010033 }
34};
35
36static struct map_desc at91sam9260_sram_desc[] __initdata = {
37 {
Andrew Victor62c16602006-11-30 12:27:38 +010038 .virtual = AT91_IO_VIRT_BASE - AT91SAM9260_SRAM0_SIZE,
39 .pfn = __phys_to_pfn(AT91SAM9260_SRAM0_BASE),
40 .length = AT91SAM9260_SRAM0_SIZE,
41 .type = MT_DEVICE,
42 }, {
43 .virtual = AT91_IO_VIRT_BASE - AT91SAM9260_SRAM0_SIZE - AT91SAM9260_SRAM1_SIZE,
44 .pfn = __phys_to_pfn(AT91SAM9260_SRAM1_BASE),
45 .length = AT91SAM9260_SRAM1_SIZE,
46 .type = MT_DEVICE,
Andrew Victorf7eee892007-02-15 08:17:38 +010047 }
48};
49
sedji gaouaou61352662008-07-10 10:15:35 +010050static struct map_desc at91sam9g20_sram_desc[] __initdata = {
51 {
52 .virtual = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE,
53 .pfn = __phys_to_pfn(AT91SAM9G20_SRAM0_BASE),
54 .length = AT91SAM9G20_SRAM0_SIZE,
55 .type = MT_DEVICE,
56 }, {
57 .virtual = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE - AT91SAM9G20_SRAM1_SIZE,
58 .pfn = __phys_to_pfn(AT91SAM9G20_SRAM1_BASE),
59 .length = AT91SAM9G20_SRAM1_SIZE,
60 .type = MT_DEVICE,
61 }
62};
63
Andrew Victorf7eee892007-02-15 08:17:38 +010064static struct map_desc at91sam9xe_sram_desc[] __initdata = {
65 {
66 .pfn = __phys_to_pfn(AT91SAM9XE_SRAM_BASE),
67 .type = MT_DEVICE,
68 }
Andrew Victor62c16602006-11-30 12:27:38 +010069};
70
71/* --------------------------------------------------------------------
72 * Clocks
73 * -------------------------------------------------------------------- */
74
75/*
76 * The peripheral clocks.
77 */
78static struct clk pioA_clk = {
79 .name = "pioA_clk",
80 .pmc_mask = 1 << AT91SAM9260_ID_PIOA,
81 .type = CLK_TYPE_PERIPHERAL,
82};
83static struct clk pioB_clk = {
84 .name = "pioB_clk",
85 .pmc_mask = 1 << AT91SAM9260_ID_PIOB,
86 .type = CLK_TYPE_PERIPHERAL,
87};
88static struct clk pioC_clk = {
89 .name = "pioC_clk",
90 .pmc_mask = 1 << AT91SAM9260_ID_PIOC,
91 .type = CLK_TYPE_PERIPHERAL,
92};
93static struct clk adc_clk = {
94 .name = "adc_clk",
95 .pmc_mask = 1 << AT91SAM9260_ID_ADC,
96 .type = CLK_TYPE_PERIPHERAL,
97};
98static struct clk usart0_clk = {
99 .name = "usart0_clk",
100 .pmc_mask = 1 << AT91SAM9260_ID_US0,
101 .type = CLK_TYPE_PERIPHERAL,
102};
103static struct clk usart1_clk = {
104 .name = "usart1_clk",
105 .pmc_mask = 1 << AT91SAM9260_ID_US1,
106 .type = CLK_TYPE_PERIPHERAL,
107};
108static struct clk usart2_clk = {
109 .name = "usart2_clk",
110 .pmc_mask = 1 << AT91SAM9260_ID_US2,
111 .type = CLK_TYPE_PERIPHERAL,
112};
113static struct clk mmc_clk = {
114 .name = "mci_clk",
115 .pmc_mask = 1 << AT91SAM9260_ID_MCI,
116 .type = CLK_TYPE_PERIPHERAL,
117};
118static struct clk udc_clk = {
119 .name = "udc_clk",
120 .pmc_mask = 1 << AT91SAM9260_ID_UDP,
121 .type = CLK_TYPE_PERIPHERAL,
122};
123static struct clk twi_clk = {
124 .name = "twi_clk",
125 .pmc_mask = 1 << AT91SAM9260_ID_TWI,
126 .type = CLK_TYPE_PERIPHERAL,
127};
128static struct clk spi0_clk = {
129 .name = "spi0_clk",
130 .pmc_mask = 1 << AT91SAM9260_ID_SPI0,
131 .type = CLK_TYPE_PERIPHERAL,
132};
133static struct clk spi1_clk = {
134 .name = "spi1_clk",
135 .pmc_mask = 1 << AT91SAM9260_ID_SPI1,
136 .type = CLK_TYPE_PERIPHERAL,
137};
Andrew Victore8788ba2007-05-02 17:14:57 +0100138static struct clk ssc_clk = {
139 .name = "ssc_clk",
140 .pmc_mask = 1 << AT91SAM9260_ID_SSC,
141 .type = CLK_TYPE_PERIPHERAL,
142};
Andrew Victorc177a1e2007-02-08 10:25:38 +0100143static struct clk tc0_clk = {
144 .name = "tc0_clk",
145 .pmc_mask = 1 << AT91SAM9260_ID_TC0,
146 .type = CLK_TYPE_PERIPHERAL,
147};
148static struct clk tc1_clk = {
149 .name = "tc1_clk",
150 .pmc_mask = 1 << AT91SAM9260_ID_TC1,
151 .type = CLK_TYPE_PERIPHERAL,
152};
153static struct clk tc2_clk = {
154 .name = "tc2_clk",
155 .pmc_mask = 1 << AT91SAM9260_ID_TC2,
156 .type = CLK_TYPE_PERIPHERAL,
157};
Andrew Victor62c16602006-11-30 12:27:38 +0100158static struct clk ohci_clk = {
159 .name = "ohci_clk",
160 .pmc_mask = 1 << AT91SAM9260_ID_UHP,
161 .type = CLK_TYPE_PERIPHERAL,
162};
Andrew Victor69b2e992007-02-14 08:44:43 +0100163static struct clk macb_clk = {
164 .name = "macb_clk",
Andrew Victor62c16602006-11-30 12:27:38 +0100165 .pmc_mask = 1 << AT91SAM9260_ID_EMAC,
166 .type = CLK_TYPE_PERIPHERAL,
167};
168static struct clk isi_clk = {
169 .name = "isi_clk",
170 .pmc_mask = 1 << AT91SAM9260_ID_ISI,
171 .type = CLK_TYPE_PERIPHERAL,
172};
173static struct clk usart3_clk = {
174 .name = "usart3_clk",
175 .pmc_mask = 1 << AT91SAM9260_ID_US3,
176 .type = CLK_TYPE_PERIPHERAL,
177};
178static struct clk usart4_clk = {
179 .name = "usart4_clk",
180 .pmc_mask = 1 << AT91SAM9260_ID_US4,
181 .type = CLK_TYPE_PERIPHERAL,
182};
183static struct clk usart5_clk = {
184 .name = "usart5_clk",
185 .pmc_mask = 1 << AT91SAM9260_ID_US5,
186 .type = CLK_TYPE_PERIPHERAL,
187};
Andrew Victorc177a1e2007-02-08 10:25:38 +0100188static struct clk tc3_clk = {
189 .name = "tc3_clk",
190 .pmc_mask = 1 << AT91SAM9260_ID_TC3,
191 .type = CLK_TYPE_PERIPHERAL,
192};
193static struct clk tc4_clk = {
194 .name = "tc4_clk",
195 .pmc_mask = 1 << AT91SAM9260_ID_TC4,
196 .type = CLK_TYPE_PERIPHERAL,
197};
198static struct clk tc5_clk = {
199 .name = "tc5_clk",
200 .pmc_mask = 1 << AT91SAM9260_ID_TC5,
201 .type = CLK_TYPE_PERIPHERAL,
202};
Andrew Victor62c16602006-11-30 12:27:38 +0100203
204static struct clk *periph_clocks[] __initdata = {
205 &pioA_clk,
206 &pioB_clk,
207 &pioC_clk,
208 &adc_clk,
209 &usart0_clk,
210 &usart1_clk,
211 &usart2_clk,
212 &mmc_clk,
213 &udc_clk,
214 &twi_clk,
215 &spi0_clk,
216 &spi1_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100217 &ssc_clk,
Andrew Victorc177a1e2007-02-08 10:25:38 +0100218 &tc0_clk,
219 &tc1_clk,
220 &tc2_clk,
Andrew Victor62c16602006-11-30 12:27:38 +0100221 &ohci_clk,
Andrew Victor69b2e992007-02-14 08:44:43 +0100222 &macb_clk,
Andrew Victor62c16602006-11-30 12:27:38 +0100223 &isi_clk,
224 &usart3_clk,
225 &usart4_clk,
226 &usart5_clk,
Andrew Victorc177a1e2007-02-08 10:25:38 +0100227 &tc3_clk,
228 &tc4_clk,
229 &tc5_clk,
Andrew Victor62c16602006-11-30 12:27:38 +0100230 // irq0 .. irq2
231};
232
233/*
234 * The two programmable clocks.
235 * You must configure pin multiplexing to bring these signals out.
236 */
237static struct clk pck0 = {
238 .name = "pck0",
239 .pmc_mask = AT91_PMC_PCK0,
240 .type = CLK_TYPE_PROGRAMMABLE,
241 .id = 0,
242};
243static struct clk pck1 = {
244 .name = "pck1",
245 .pmc_mask = AT91_PMC_PCK1,
246 .type = CLK_TYPE_PROGRAMMABLE,
247 .id = 1,
248};
249
250static void __init at91sam9260_register_clocks(void)
251{
252 int i;
253
254 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
255 clk_register(periph_clocks[i]);
256
257 clk_register(&pck0);
258 clk_register(&pck1);
259}
260
261/* --------------------------------------------------------------------
262 * GPIO
263 * -------------------------------------------------------------------- */
264
265static struct at91_gpio_bank at91sam9260_gpio[] = {
266 {
267 .id = AT91SAM9260_ID_PIOA,
268 .offset = AT91_PIOA,
269 .clock = &pioA_clk,
270 }, {
271 .id = AT91SAM9260_ID_PIOB,
272 .offset = AT91_PIOB,
273 .clock = &pioB_clk,
274 }, {
275 .id = AT91SAM9260_ID_PIOC,
276 .offset = AT91_PIOC,
277 .clock = &pioC_clk,
278 }
279};
280
281static void at91sam9260_reset(void)
282{
Jan Altenbergdd1d2f42007-02-16 01:37:10 -0800283 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
Andrew Victor62c16602006-11-30 12:27:38 +0100284}
285
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100286static void at91sam9260_poweroff(void)
287{
288 at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
289}
290
Andrew Victor62c16602006-11-30 12:27:38 +0100291
292/* --------------------------------------------------------------------
293 * AT91SAM9260 processor initialization
294 * -------------------------------------------------------------------- */
295
Andrew Victorf7eee892007-02-15 08:17:38 +0100296static void __init at91sam9xe_initialize(void)
297{
298 unsigned long cidr, sram_size;
299
300 cidr = at91_sys_read(AT91_DBGU_CIDR);
301
302 switch (cidr & AT91_CIDR_SRAMSIZ) {
303 case AT91_CIDR_SRAMSIZ_32K:
304 sram_size = 2 * SZ_16K;
305 break;
306 case AT91_CIDR_SRAMSIZ_16K:
307 default:
308 sram_size = SZ_16K;
309 }
310
311 at91sam9xe_sram_desc->virtual = AT91_IO_VIRT_BASE - sram_size;
312 at91sam9xe_sram_desc->length = sram_size;
313
314 iotable_init(at91sam9xe_sram_desc, ARRAY_SIZE(at91sam9xe_sram_desc));
315}
316
Andrew Victor62c16602006-11-30 12:27:38 +0100317void __init at91sam9260_initialize(unsigned long main_clock)
318{
319 /* Map peripherals */
320 iotable_init(at91sam9260_io_desc, ARRAY_SIZE(at91sam9260_io_desc));
321
Andrew Victorf7eee892007-02-15 08:17:38 +0100322 if (cpu_is_at91sam9xe())
323 at91sam9xe_initialize();
sedji gaouaou61352662008-07-10 10:15:35 +0100324 else if (cpu_is_at91sam9g20())
325 iotable_init(at91sam9g20_sram_desc, ARRAY_SIZE(at91sam9g20_sram_desc));
Andrew Victorf7eee892007-02-15 08:17:38 +0100326 else
327 iotable_init(at91sam9260_sram_desc, ARRAY_SIZE(at91sam9260_sram_desc));
328
Andrew Victor62c16602006-11-30 12:27:38 +0100329 at91_arch_reset = at91sam9260_reset;
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100330 pm_power_off = at91sam9260_poweroff;
Andrew Victor62c16602006-11-30 12:27:38 +0100331 at91_extern_irq = (1 << AT91SAM9260_ID_IRQ0) | (1 << AT91SAM9260_ID_IRQ1)
332 | (1 << AT91SAM9260_ID_IRQ2);
333
334 /* Init clock subsystem */
335 at91_clock_init(main_clock);
336
337 /* Register the processor-specific clocks */
338 at91sam9260_register_clocks();
339
340 /* Register GPIO subsystem */
341 at91_gpio_init(at91sam9260_gpio, 3);
342}
343
344/* --------------------------------------------------------------------
345 * Interrupt initialization
346 * -------------------------------------------------------------------- */
347
348/*
349 * The default interrupt priority levels (0 = lowest, 7 = highest).
350 */
351static unsigned int at91sam9260_default_irq_priority[NR_AIC_IRQS] __initdata = {
352 7, /* Advanced Interrupt Controller */
353 7, /* System Peripherals */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100354 1, /* Parallel IO Controller A */
355 1, /* Parallel IO Controller B */
356 1, /* Parallel IO Controller C */
Andrew Victor62c16602006-11-30 12:27:38 +0100357 0, /* Analog-to-Digital Converter */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100358 5, /* USART 0 */
359 5, /* USART 1 */
360 5, /* USART 2 */
Andrew Victor62c16602006-11-30 12:27:38 +0100361 0, /* Multimedia Card Interface */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100362 2, /* USB Device Port */
363 6, /* Two-Wire Interface */
364 5, /* Serial Peripheral Interface 0 */
365 5, /* Serial Peripheral Interface 1 */
Andrew Victor62c16602006-11-30 12:27:38 +0100366 5, /* Serial Synchronous Controller */
367 0,
368 0,
369 0, /* Timer Counter 0 */
370 0, /* Timer Counter 1 */
371 0, /* Timer Counter 2 */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100372 2, /* USB Host port */
Andrew Victor62c16602006-11-30 12:27:38 +0100373 3, /* Ethernet */
374 0, /* Image Sensor Interface */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100375 5, /* USART 3 */
376 5, /* USART 4 */
377 5, /* USART 5 */
Andrew Victor62c16602006-11-30 12:27:38 +0100378 0, /* Timer Counter 3 */
379 0, /* Timer Counter 4 */
380 0, /* Timer Counter 5 */
381 0, /* Advanced Interrupt Controller */
382 0, /* Advanced Interrupt Controller */
383 0, /* Advanced Interrupt Controller */
384};
385
386void __init at91sam9260_init_interrupts(unsigned int priority[NR_AIC_IRQS])
387{
388 if (!priority)
389 priority = at91sam9260_default_irq_priority;
390
391 /* Initialize the AIC interrupt controller */
392 at91_aic_init(priority);
393
394 /* Enable GPIO interrupts */
395 at91_gpio_irq_setup();
396}