blob: d3638bd994da74dccf74cd8b2a44c7cd8cbd5bd4 [file] [log] [blame]
SAN People73a59c12006-01-09 17:05:41 +00001/*
Andrew Victor9d041262007-02-05 11:42:07 +01002 * arch/arm/mach-at91/at91rm9200.c
SAN People73a59c12006-01-09 17:05:41 +00003 *
4 * Copyright (C) 2005 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
SAN People73a59c12006-01-09 17:05:41 +000013#include <linux/module.h>
14
Russell King80b02c12009-01-08 10:01:47 +000015#include <asm/irq.h>
SAN People73a59c12006-01-09 17:05:41 +000016#include <asm/mach/arch.h>
17#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/at91rm9200.h>
19#include <mach/at91_pmc.h>
20#include <mach/at91_st.h>
SAN People73a59c12006-01-09 17:05:41 +000021
Andrew Victor10e8e1f2006-06-19 15:26:51 +010022#include "generic.h"
Andrew Victor2eeaaa22006-09-27 10:50:59 +010023#include "clock.h"
SAN People73a59c12006-01-09 17:05:41 +000024
25static struct map_desc at91rm9200_io_desc[] __initdata = {
26 {
27 .virtual = AT91_VA_BASE_SYS,
28 .pfn = __phys_to_pfn(AT91_BASE_SYS),
29 .length = SZ_4K,
30 .type = MT_DEVICE,
31 }, {
SAN People73a59c12006-01-09 17:05:41 +000032 .virtual = AT91_VA_BASE_EMAC,
Andrew Victor72729912006-09-27 09:44:11 +010033 .pfn = __phys_to_pfn(AT91RM9200_BASE_EMAC),
SAN People73a59c12006-01-09 17:05:41 +000034 .length = SZ_16K,
35 .type = MT_DEVICE,
36 }, {
Andrew Victor05043d02006-12-01 11:51:19 +010037 .virtual = AT91_IO_VIRT_BASE - AT91RM9200_SRAM_SIZE,
Andrew Victor72729912006-09-27 09:44:11 +010038 .pfn = __phys_to_pfn(AT91RM9200_SRAM_BASE),
39 .length = AT91RM9200_SRAM_SIZE,
Andrew Victor10e8e1f2006-06-19 15:26:51 +010040 .type = MT_DEVICE,
SAN People73a59c12006-01-09 17:05:41 +000041 },
42};
43
Andrew Victor2eeaaa22006-09-27 10:50:59 +010044/* --------------------------------------------------------------------
45 * Clocks
46 * -------------------------------------------------------------------- */
47
48/*
49 * The peripheral clocks.
50 */
51static struct clk udc_clk = {
52 .name = "udc_clk",
53 .pmc_mask = 1 << AT91RM9200_ID_UDP,
54 .type = CLK_TYPE_PERIPHERAL,
55};
56static struct clk ohci_clk = {
57 .name = "ohci_clk",
58 .pmc_mask = 1 << AT91RM9200_ID_UHP,
59 .type = CLK_TYPE_PERIPHERAL,
60};
61static struct clk ether_clk = {
62 .name = "ether_clk",
63 .pmc_mask = 1 << AT91RM9200_ID_EMAC,
64 .type = CLK_TYPE_PERIPHERAL,
65};
66static struct clk mmc_clk = {
67 .name = "mci_clk",
68 .pmc_mask = 1 << AT91RM9200_ID_MCI,
69 .type = CLK_TYPE_PERIPHERAL,
70};
71static struct clk twi_clk = {
72 .name = "twi_clk",
73 .pmc_mask = 1 << AT91RM9200_ID_TWI,
74 .type = CLK_TYPE_PERIPHERAL,
75};
76static struct clk usart0_clk = {
77 .name = "usart0_clk",
78 .pmc_mask = 1 << AT91RM9200_ID_US0,
79 .type = CLK_TYPE_PERIPHERAL,
80};
81static struct clk usart1_clk = {
82 .name = "usart1_clk",
83 .pmc_mask = 1 << AT91RM9200_ID_US1,
84 .type = CLK_TYPE_PERIPHERAL,
85};
86static struct clk usart2_clk = {
87 .name = "usart2_clk",
88 .pmc_mask = 1 << AT91RM9200_ID_US2,
89 .type = CLK_TYPE_PERIPHERAL,
90};
91static struct clk usart3_clk = {
92 .name = "usart3_clk",
93 .pmc_mask = 1 << AT91RM9200_ID_US3,
94 .type = CLK_TYPE_PERIPHERAL,
95};
96static struct clk spi_clk = {
97 .name = "spi_clk",
98 .pmc_mask = 1 << AT91RM9200_ID_SPI,
99 .type = CLK_TYPE_PERIPHERAL,
100};
101static struct clk pioA_clk = {
102 .name = "pioA_clk",
103 .pmc_mask = 1 << AT91RM9200_ID_PIOA,
104 .type = CLK_TYPE_PERIPHERAL,
105};
106static struct clk pioB_clk = {
107 .name = "pioB_clk",
108 .pmc_mask = 1 << AT91RM9200_ID_PIOB,
109 .type = CLK_TYPE_PERIPHERAL,
110};
111static struct clk pioC_clk = {
112 .name = "pioC_clk",
113 .pmc_mask = 1 << AT91RM9200_ID_PIOC,
114 .type = CLK_TYPE_PERIPHERAL,
115};
116static struct clk pioD_clk = {
117 .name = "pioD_clk",
118 .pmc_mask = 1 << AT91RM9200_ID_PIOD,
119 .type = CLK_TYPE_PERIPHERAL,
120};
Andrew Victore8788ba2007-05-02 17:14:57 +0100121static struct clk ssc0_clk = {
122 .name = "ssc0_clk",
123 .pmc_mask = 1 << AT91RM9200_ID_SSC0,
124 .type = CLK_TYPE_PERIPHERAL,
125};
126static struct clk ssc1_clk = {
127 .name = "ssc1_clk",
128 .pmc_mask = 1 << AT91RM9200_ID_SSC1,
129 .type = CLK_TYPE_PERIPHERAL,
130};
131static struct clk ssc2_clk = {
132 .name = "ssc2_clk",
133 .pmc_mask = 1 << AT91RM9200_ID_SSC2,
134 .type = CLK_TYPE_PERIPHERAL,
135};
Andrew Victorc177a1e2007-02-08 10:25:38 +0100136static struct clk tc0_clk = {
137 .name = "tc0_clk",
138 .pmc_mask = 1 << AT91RM9200_ID_TC0,
139 .type = CLK_TYPE_PERIPHERAL,
140};
141static struct clk tc1_clk = {
142 .name = "tc1_clk",
143 .pmc_mask = 1 << AT91RM9200_ID_TC1,
144 .type = CLK_TYPE_PERIPHERAL,
145};
146static struct clk tc2_clk = {
147 .name = "tc2_clk",
148 .pmc_mask = 1 << AT91RM9200_ID_TC2,
149 .type = CLK_TYPE_PERIPHERAL,
150};
151static struct clk tc3_clk = {
152 .name = "tc3_clk",
153 .pmc_mask = 1 << AT91RM9200_ID_TC3,
154 .type = CLK_TYPE_PERIPHERAL,
155};
156static struct clk tc4_clk = {
157 .name = "tc4_clk",
158 .pmc_mask = 1 << AT91RM9200_ID_TC4,
159 .type = CLK_TYPE_PERIPHERAL,
160};
161static struct clk tc5_clk = {
162 .name = "tc5_clk",
163 .pmc_mask = 1 << AT91RM9200_ID_TC5,
164 .type = CLK_TYPE_PERIPHERAL,
165};
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100166
167static struct clk *periph_clocks[] __initdata = {
168 &pioA_clk,
169 &pioB_clk,
170 &pioC_clk,
171 &pioD_clk,
172 &usart0_clk,
173 &usart1_clk,
174 &usart2_clk,
175 &usart3_clk,
176 &mmc_clk,
177 &udc_clk,
178 &twi_clk,
179 &spi_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100180 &ssc0_clk,
181 &ssc1_clk,
182 &ssc2_clk,
Andrew Victorc177a1e2007-02-08 10:25:38 +0100183 &tc0_clk,
184 &tc1_clk,
185 &tc2_clk,
186 &tc3_clk,
187 &tc4_clk,
188 &tc5_clk,
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100189 &ohci_clk,
190 &ether_clk,
191 // irq0 .. irq6
192};
193
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100194static struct clk_lookup periph_clocks_lookups[] = {
195 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
196 CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
197 CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
198 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.1", &tc3_clk),
199 CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.1", &tc4_clk),
200 CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.1", &tc5_clk),
201 CLKDEV_CON_DEV_ID("ssc", "ssc.0", &ssc0_clk),
202 CLKDEV_CON_DEV_ID("ssc", "ssc.1", &ssc1_clk),
203 CLKDEV_CON_DEV_ID("ssc", "ssc.2", &ssc2_clk),
204};
205
206static struct clk_lookup usart_clocks_lookups[] = {
207 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
208 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
209 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
210 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
211 CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),
212};
213
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100214/*
215 * The four programmable clocks.
216 * You must configure pin multiplexing to bring these signals out.
217 */
218static struct clk pck0 = {
219 .name = "pck0",
220 .pmc_mask = AT91_PMC_PCK0,
221 .type = CLK_TYPE_PROGRAMMABLE,
222 .id = 0,
223};
224static struct clk pck1 = {
225 .name = "pck1",
226 .pmc_mask = AT91_PMC_PCK1,
227 .type = CLK_TYPE_PROGRAMMABLE,
228 .id = 1,
229};
230static struct clk pck2 = {
231 .name = "pck2",
232 .pmc_mask = AT91_PMC_PCK2,
233 .type = CLK_TYPE_PROGRAMMABLE,
234 .id = 2,
235};
236static struct clk pck3 = {
237 .name = "pck3",
238 .pmc_mask = AT91_PMC_PCK3,
239 .type = CLK_TYPE_PROGRAMMABLE,
240 .id = 3,
241};
242
243static void __init at91rm9200_register_clocks(void)
SAN People73a59c12006-01-09 17:05:41 +0000244{
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100245 int i;
246
247 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
248 clk_register(periph_clocks[i]);
249
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100250 clkdev_add_table(periph_clocks_lookups,
251 ARRAY_SIZE(periph_clocks_lookups));
252 clkdev_add_table(usart_clocks_lookups,
253 ARRAY_SIZE(usart_clocks_lookups));
254
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100255 clk_register(&pck0);
256 clk_register(&pck1);
257 clk_register(&pck2);
258 clk_register(&pck3);
259}
260
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100261static struct clk_lookup console_clock_lookup;
262
263void __init at91rm9200_set_console_clock(int id)
264{
265 if (id >= ARRAY_SIZE(usart_clocks_lookups))
266 return;
267
268 console_clock_lookup.con_id = "usart";
269 console_clock_lookup.clk = usart_clocks_lookups[id].clk;
270 clkdev_add(&console_clock_lookup);
271}
272
Andrew Victorf2173832006-09-27 13:23:00 +0100273/* --------------------------------------------------------------------
274 * GPIO
275 * -------------------------------------------------------------------- */
276
277static struct at91_gpio_bank at91rm9200_gpio[] = {
278 {
279 .id = AT91RM9200_ID_PIOA,
280 .offset = AT91_PIOA,
281 .clock = &pioA_clk,
282 }, {
283 .id = AT91RM9200_ID_PIOB,
284 .offset = AT91_PIOB,
285 .clock = &pioB_clk,
286 }, {
287 .id = AT91RM9200_ID_PIOC,
288 .offset = AT91_PIOC,
289 .clock = &pioC_clk,
290 }, {
291 .id = AT91RM9200_ID_PIOD,
292 .offset = AT91_PIOD,
293 .clock = &pioD_clk,
294 }
295};
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100296
Andrew Victor1f4fd0a2006-11-30 10:01:47 +0100297static void at91rm9200_reset(void)
298{
299 /*
300 * Perform a hardware reset with the use of the Watchdog timer.
301 */
302 at91_sys_write(AT91_ST_WDMR, AT91_ST_RSTEN | AT91_ST_EXTEN | 1);
303 at91_sys_write(AT91_ST_CR, AT91_ST_WDRST);
304}
305
306
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100307/* --------------------------------------------------------------------
308 * AT91RM9200 processor initialization
309 * -------------------------------------------------------------------- */
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800310void __init at91rm9200_map_io(void)
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100311{
312 /* Map peripherals */
SAN People73a59c12006-01-09 17:05:41 +0000313 iotable_init(at91rm9200_io_desc, ARRAY_SIZE(at91rm9200_io_desc));
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800314}
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100315
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800316void __init at91rm9200_initialize(unsigned long main_clock, unsigned short banks)
317{
Andrew Victor1f4fd0a2006-11-30 10:01:47 +0100318 at91_arch_reset = at91rm9200_reset;
319 at91_extern_irq = (1 << AT91RM9200_ID_IRQ0) | (1 << AT91RM9200_ID_IRQ1)
320 | (1 << AT91RM9200_ID_IRQ2) | (1 << AT91RM9200_ID_IRQ3)
321 | (1 << AT91RM9200_ID_IRQ4) | (1 << AT91RM9200_ID_IRQ5)
322 | (1 << AT91RM9200_ID_IRQ6);
323
Andrew Victor2eeaaa22006-09-27 10:50:59 +0100324 /* Init clock subsystem */
325 at91_clock_init(main_clock);
326
327 /* Register the processor-specific clocks */
328 at91rm9200_register_clocks();
Andrew Victorf2173832006-09-27 13:23:00 +0100329
330 /* Initialize GPIO subsystem */
331 at91_gpio_init(at91rm9200_gpio, banks);
SAN People73a59c12006-01-09 17:05:41 +0000332}
333
Andrew Victorf2173832006-09-27 13:23:00 +0100334
335/* --------------------------------------------------------------------
336 * Interrupt initialization
337 * -------------------------------------------------------------------- */
338
Andrew Victorba854e12006-07-05 17:22:52 +0100339/*
340 * The default interrupt priority levels (0 = lowest, 7 = highest).
341 */
342static unsigned int at91rm9200_default_irq_priority[NR_AIC_IRQS] __initdata = {
343 7, /* Advanced Interrupt Controller (FIQ) */
344 7, /* System Peripherals */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100345 1, /* Parallel IO Controller A */
346 1, /* Parallel IO Controller B */
347 1, /* Parallel IO Controller C */
348 1, /* Parallel IO Controller D */
349 5, /* USART 0 */
350 5, /* USART 1 */
351 5, /* USART 2 */
352 5, /* USART 3 */
Andrew Victorba854e12006-07-05 17:22:52 +0100353 0, /* Multimedia Card Interface */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100354 2, /* USB Device Port */
355 6, /* Two-Wire Interface */
356 5, /* Serial Peripheral Interface */
357 4, /* Serial Synchronous Controller 0 */
358 4, /* Serial Synchronous Controller 1 */
359 4, /* Serial Synchronous Controller 2 */
Andrew Victorba854e12006-07-05 17:22:52 +0100360 0, /* Timer Counter 0 */
361 0, /* Timer Counter 1 */
362 0, /* Timer Counter 2 */
363 0, /* Timer Counter 3 */
364 0, /* Timer Counter 4 */
365 0, /* Timer Counter 5 */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100366 2, /* USB Host port */
Andrew Victorba854e12006-07-05 17:22:52 +0100367 3, /* Ethernet MAC */
368 0, /* Advanced Interrupt Controller (IRQ0) */
369 0, /* Advanced Interrupt Controller (IRQ1) */
370 0, /* Advanced Interrupt Controller (IRQ2) */
371 0, /* Advanced Interrupt Controller (IRQ3) */
372 0, /* Advanced Interrupt Controller (IRQ4) */
373 0, /* Advanced Interrupt Controller (IRQ5) */
374 0 /* Advanced Interrupt Controller (IRQ6) */
375};
376
Andrew Victorf2173832006-09-27 13:23:00 +0100377void __init at91rm9200_init_interrupts(unsigned int priority[NR_AIC_IRQS])
Andrew Victorba854e12006-07-05 17:22:52 +0100378{
379 if (!priority)
380 priority = at91rm9200_default_irq_priority;
381
Andrew Victorf2173832006-09-27 13:23:00 +0100382 /* Initialize the AIC interrupt controller */
Andrew Victorba854e12006-07-05 17:22:52 +0100383 at91_aic_init(priority);
Andrew Victorf2173832006-09-27 13:23:00 +0100384
385 /* Enable GPIO interrupts */
386 at91_gpio_irq_setup();
Andrew Victorba854e12006-07-05 17:22:52 +0100387}