blob: 80bfab5680e2a56ce0853398b7bed311b5b9e33b [file] [log] [blame]
Andrew Victorb2c65612007-02-08 09:42:40 +01001/*
2 * arch/arm/mach-at91/at91sam9263.c
3 *
4 * Copyright (C) 2007 Atmel Corporation.
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 Victorb2c65612007-02-08 09:42:40 +010015
16#include <asm/mach/arch.h>
17#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/at91sam9263.h>
19#include <mach/at91_pmc.h>
20#include <mach/at91_rstc.h>
21#include <mach/at91_shdwc.h>
Andrew Victorb2c65612007-02-08 09:42:40 +010022
23#include "generic.h"
24#include "clock.h"
25
26static struct map_desc at91sam9263_io_desc[] __initdata = {
27 {
28 .virtual = AT91_VA_BASE_SYS,
29 .pfn = __phys_to_pfn(AT91_BASE_SYS),
30 .length = SZ_16K,
31 .type = MT_DEVICE,
32 }, {
33 .virtual = AT91_IO_VIRT_BASE - AT91SAM9263_SRAM0_SIZE,
34 .pfn = __phys_to_pfn(AT91SAM9263_SRAM0_BASE),
35 .length = AT91SAM9263_SRAM0_SIZE,
36 .type = MT_DEVICE,
37 }, {
38 .virtual = AT91_IO_VIRT_BASE - AT91SAM9263_SRAM0_SIZE - AT91SAM9263_SRAM1_SIZE,
39 .pfn = __phys_to_pfn(AT91SAM9263_SRAM1_BASE),
40 .length = AT91SAM9263_SRAM1_SIZE,
41 .type = MT_DEVICE,
42 },
43};
44
45/* --------------------------------------------------------------------
46 * Clocks
47 * -------------------------------------------------------------------- */
48
49/*
50 * The peripheral clocks.
51 */
52static struct clk pioA_clk = {
53 .name = "pioA_clk",
54 .pmc_mask = 1 << AT91SAM9263_ID_PIOA,
55 .type = CLK_TYPE_PERIPHERAL,
56};
57static struct clk pioB_clk = {
58 .name = "pioB_clk",
59 .pmc_mask = 1 << AT91SAM9263_ID_PIOB,
60 .type = CLK_TYPE_PERIPHERAL,
61};
62static struct clk pioCDE_clk = {
63 .name = "pioCDE_clk",
64 .pmc_mask = 1 << AT91SAM9263_ID_PIOCDE,
65 .type = CLK_TYPE_PERIPHERAL,
66};
67static struct clk usart0_clk = {
68 .name = "usart0_clk",
69 .pmc_mask = 1 << AT91SAM9263_ID_US0,
70 .type = CLK_TYPE_PERIPHERAL,
71};
72static struct clk usart1_clk = {
73 .name = "usart1_clk",
74 .pmc_mask = 1 << AT91SAM9263_ID_US1,
75 .type = CLK_TYPE_PERIPHERAL,
76};
77static struct clk usart2_clk = {
78 .name = "usart2_clk",
79 .pmc_mask = 1 << AT91SAM9263_ID_US2,
80 .type = CLK_TYPE_PERIPHERAL,
81};
82static struct clk mmc0_clk = {
83 .name = "mci0_clk",
84 .pmc_mask = 1 << AT91SAM9263_ID_MCI0,
85 .type = CLK_TYPE_PERIPHERAL,
86};
87static struct clk mmc1_clk = {
88 .name = "mci1_clk",
89 .pmc_mask = 1 << AT91SAM9263_ID_MCI1,
90 .type = CLK_TYPE_PERIPHERAL,
91};
Andrew Victore8788ba2007-05-02 17:14:57 +010092static struct clk can_clk = {
93 .name = "can_clk",
94 .pmc_mask = 1 << AT91SAM9263_ID_CAN,
95 .type = CLK_TYPE_PERIPHERAL,
96};
Andrew Victorb2c65612007-02-08 09:42:40 +010097static struct clk twi_clk = {
98 .name = "twi_clk",
99 .pmc_mask = 1 << AT91SAM9263_ID_TWI,
100 .type = CLK_TYPE_PERIPHERAL,
101};
102static struct clk spi0_clk = {
103 .name = "spi0_clk",
104 .pmc_mask = 1 << AT91SAM9263_ID_SPI0,
105 .type = CLK_TYPE_PERIPHERAL,
106};
107static struct clk spi1_clk = {
108 .name = "spi1_clk",
109 .pmc_mask = 1 << AT91SAM9263_ID_SPI1,
110 .type = CLK_TYPE_PERIPHERAL,
111};
Andrew Victore8788ba2007-05-02 17:14:57 +0100112static struct clk ssc0_clk = {
113 .name = "ssc0_clk",
114 .pmc_mask = 1 << AT91SAM9263_ID_SSC0,
115 .type = CLK_TYPE_PERIPHERAL,
116};
117static struct clk ssc1_clk = {
118 .name = "ssc1_clk",
119 .pmc_mask = 1 << AT91SAM9263_ID_SSC1,
120 .type = CLK_TYPE_PERIPHERAL,
121};
122static struct clk ac97_clk = {
123 .name = "ac97_clk",
124 .pmc_mask = 1 << AT91SAM9263_ID_AC97C,
125 .type = CLK_TYPE_PERIPHERAL,
126};
Andrew Victorb2c65612007-02-08 09:42:40 +0100127static struct clk tcb_clk = {
128 .name = "tcb_clk",
129 .pmc_mask = 1 << AT91SAM9263_ID_TCB,
130 .type = CLK_TYPE_PERIPHERAL,
131};
Andrew Victore8788ba2007-05-02 17:14:57 +0100132static struct clk pwmc_clk = {
133 .name = "pwmc_clk",
134 .pmc_mask = 1 << AT91SAM9263_ID_PWMC,
135 .type = CLK_TYPE_PERIPHERAL,
136};
Andrew Victor69b2e992007-02-14 08:44:43 +0100137static struct clk macb_clk = {
138 .name = "macb_clk",
Andrew Victorb2c65612007-02-08 09:42:40 +0100139 .pmc_mask = 1 << AT91SAM9263_ID_EMAC,
140 .type = CLK_TYPE_PERIPHERAL,
141};
Andrew Victore8788ba2007-05-02 17:14:57 +0100142static struct clk dma_clk = {
143 .name = "dma_clk",
144 .pmc_mask = 1 << AT91SAM9263_ID_DMA,
145 .type = CLK_TYPE_PERIPHERAL,
146};
147static struct clk twodge_clk = {
148 .name = "2dge_clk",
149 .pmc_mask = 1 << AT91SAM9263_ID_2DGE,
150 .type = CLK_TYPE_PERIPHERAL,
151};
Andrew Victorb2c65612007-02-08 09:42:40 +0100152static struct clk udc_clk = {
153 .name = "udc_clk",
154 .pmc_mask = 1 << AT91SAM9263_ID_UDP,
155 .type = CLK_TYPE_PERIPHERAL,
156};
157static struct clk isi_clk = {
158 .name = "isi_clk",
159 .pmc_mask = 1 << AT91SAM9263_ID_ISI,
160 .type = CLK_TYPE_PERIPHERAL,
161};
162static struct clk lcdc_clk = {
163 .name = "lcdc_clk",
Andrew Victor7f6e2d92007-02-22 07:34:56 +0100164 .pmc_mask = 1 << AT91SAM9263_ID_LCDC,
Andrew Victorb2c65612007-02-08 09:42:40 +0100165 .type = CLK_TYPE_PERIPHERAL,
166};
167static struct clk ohci_clk = {
168 .name = "ohci_clk",
169 .pmc_mask = 1 << AT91SAM9263_ID_UHP,
170 .type = CLK_TYPE_PERIPHERAL,
171};
172
173static struct clk *periph_clocks[] __initdata = {
174 &pioA_clk,
175 &pioB_clk,
176 &pioCDE_clk,
177 &usart0_clk,
178 &usart1_clk,
179 &usart2_clk,
180 &mmc0_clk,
181 &mmc1_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100182 &can_clk,
Andrew Victorb2c65612007-02-08 09:42:40 +0100183 &twi_clk,
184 &spi0_clk,
185 &spi1_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100186 &ssc0_clk,
187 &ssc1_clk,
188 &ac97_clk,
Andrew Victorb2c65612007-02-08 09:42:40 +0100189 &tcb_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100190 &pwmc_clk,
Andrew Victor69b2e992007-02-14 08:44:43 +0100191 &macb_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100192 &twodge_clk,
Andrew Victorb2c65612007-02-08 09:42:40 +0100193 &udc_clk,
194 &isi_clk,
195 &lcdc_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100196 &dma_clk,
Andrew Victorb2c65612007-02-08 09:42:40 +0100197 &ohci_clk,
198 // irq0 .. irq1
199};
200
201/*
202 * The four programmable clocks.
203 * You must configure pin multiplexing to bring these signals out.
204 */
205static struct clk pck0 = {
206 .name = "pck0",
207 .pmc_mask = AT91_PMC_PCK0,
208 .type = CLK_TYPE_PROGRAMMABLE,
209 .id = 0,
210};
211static struct clk pck1 = {
212 .name = "pck1",
213 .pmc_mask = AT91_PMC_PCK1,
214 .type = CLK_TYPE_PROGRAMMABLE,
215 .id = 1,
216};
217static struct clk pck2 = {
218 .name = "pck2",
219 .pmc_mask = AT91_PMC_PCK2,
220 .type = CLK_TYPE_PROGRAMMABLE,
221 .id = 2,
222};
223static struct clk pck3 = {
224 .name = "pck3",
225 .pmc_mask = AT91_PMC_PCK3,
226 .type = CLK_TYPE_PROGRAMMABLE,
227 .id = 3,
228};
229
230static void __init at91sam9263_register_clocks(void)
231{
232 int i;
233
234 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
235 clk_register(periph_clocks[i]);
236
237 clk_register(&pck0);
238 clk_register(&pck1);
239 clk_register(&pck2);
240 clk_register(&pck3);
241}
242
243/* --------------------------------------------------------------------
244 * GPIO
245 * -------------------------------------------------------------------- */
246
247static struct at91_gpio_bank at91sam9263_gpio[] = {
248 {
249 .id = AT91SAM9263_ID_PIOA,
250 .offset = AT91_PIOA,
251 .clock = &pioA_clk,
252 }, {
253 .id = AT91SAM9263_ID_PIOB,
254 .offset = AT91_PIOB,
255 .clock = &pioB_clk,
256 }, {
257 .id = AT91SAM9263_ID_PIOCDE,
258 .offset = AT91_PIOC,
259 .clock = &pioCDE_clk,
260 }, {
261 .id = AT91SAM9263_ID_PIOCDE,
262 .offset = AT91_PIOD,
263 .clock = &pioCDE_clk,
264 }, {
265 .id = AT91SAM9263_ID_PIOCDE,
266 .offset = AT91_PIOE,
267 .clock = &pioCDE_clk,
268 }
269};
270
271static void at91sam9263_reset(void)
272{
273 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
274}
275
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100276static void at91sam9263_poweroff(void)
277{
278 at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
279}
280
Andrew Victorb2c65612007-02-08 09:42:40 +0100281
282/* --------------------------------------------------------------------
283 * AT91SAM9263 processor initialization
284 * -------------------------------------------------------------------- */
285
286void __init at91sam9263_initialize(unsigned long main_clock)
287{
288 /* Map peripherals */
289 iotable_init(at91sam9263_io_desc, ARRAY_SIZE(at91sam9263_io_desc));
290
291 at91_arch_reset = at91sam9263_reset;
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100292 pm_power_off = at91sam9263_poweroff;
Andrew Victorb2c65612007-02-08 09:42:40 +0100293 at91_extern_irq = (1 << AT91SAM9263_ID_IRQ0) | (1 << AT91SAM9263_ID_IRQ1);
294
295 /* Init clock subsystem */
296 at91_clock_init(main_clock);
297
298 /* Register the processor-specific clocks */
299 at91sam9263_register_clocks();
300
301 /* Register GPIO subsystem */
302 at91_gpio_init(at91sam9263_gpio, 5);
303}
304
305/* --------------------------------------------------------------------
306 * Interrupt initialization
307 * -------------------------------------------------------------------- */
308
309/*
310 * The default interrupt priority levels (0 = lowest, 7 = highest).
311 */
312static unsigned int at91sam9263_default_irq_priority[NR_AIC_IRQS] __initdata = {
313 7, /* Advanced Interrupt Controller (FIQ) */
314 7, /* System Peripherals */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100315 1, /* Parallel IO Controller A */
316 1, /* Parallel IO Controller B */
317 1, /* Parallel IO Controller C, D and E */
Andrew Victorb2c65612007-02-08 09:42:40 +0100318 0,
319 0,
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100320 5, /* USART 0 */
321 5, /* USART 1 */
322 5, /* USART 2 */
Andrew Victorb2c65612007-02-08 09:42:40 +0100323 0, /* Multimedia Card Interface 0 */
324 0, /* Multimedia Card Interface 1 */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100325 3, /* CAN */
326 6, /* Two-Wire Interface */
327 5, /* Serial Peripheral Interface 0 */
328 5, /* Serial Peripheral Interface 1 */
329 4, /* Serial Synchronous Controller 0 */
330 4, /* Serial Synchronous Controller 1 */
331 5, /* AC97 Controller */
Andrew Victorb2c65612007-02-08 09:42:40 +0100332 0, /* Timer Counter 0, 1 and 2 */
333 0, /* Pulse Width Modulation Controller */
334 3, /* Ethernet */
335 0,
336 0, /* 2D Graphic Engine */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100337 2, /* USB Device Port */
Andrew Victorb2c65612007-02-08 09:42:40 +0100338 0, /* Image Sensor Interface */
339 3, /* LDC Controller */
340 0, /* DMA Controller */
341 0,
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100342 2, /* USB Host port */
Andrew Victorb2c65612007-02-08 09:42:40 +0100343 0, /* Advanced Interrupt Controller (IRQ0) */
344 0, /* Advanced Interrupt Controller (IRQ1) */
345};
346
347void __init at91sam9263_init_interrupts(unsigned int priority[NR_AIC_IRQS])
348{
349 if (!priority)
350 priority = at91sam9263_default_irq_priority;
351
352 /* Initialize the AIC interrupt controller */
353 at91_aic_init(priority);
354
355 /* Enable GPIO interrupts */
356 at91_gpio_irq_setup();
357}