blob: 0a38c69fdbc450f3d09ed7545ef60af14e45fb50 [file] [log] [blame]
Andrew Victor2b3b3512008-01-24 15:10:39 +01001/*
2 * arch/arm/mach-at91/at91cap9.c
3 *
4 * Copyright (C) 2007 Stelian Pop <stelian.pop@leadtechdesign.com>
5 * Copyright (C) 2007 Lead Tech Design <www.leadtechdesign.com>
6 * Copyright (C) 2007 Atmel Corporation.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 */
14
15#include <linux/module.h>
Andrew Victor3ef2fb42008-04-02 21:36:06 +010016#include <linux/pm.h>
Andrew Victor2b3b3512008-01-24 15:10:39 +010017
18#include <asm/mach/arch.h>
19#include <asm/mach/map.h>
Stelian Pop7be90a62008-10-22 13:52:08 +010020
21#include <mach/cpu.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010022#include <mach/at91cap9.h>
23#include <mach/at91_pmc.h>
24#include <mach/at91_rstc.h>
25#include <mach/at91_shdwc.h>
Andrew Victor2b3b3512008-01-24 15:10:39 +010026
27#include "generic.h"
28#include "clock.h"
29
30static struct map_desc at91cap9_io_desc[] __initdata = {
31 {
32 .virtual = AT91_VA_BASE_SYS,
33 .pfn = __phys_to_pfn(AT91_BASE_SYS),
34 .length = SZ_16K,
35 .type = MT_DEVICE,
36 }, {
37 .virtual = AT91_IO_VIRT_BASE - AT91CAP9_SRAM_SIZE,
38 .pfn = __phys_to_pfn(AT91CAP9_SRAM_BASE),
39 .length = AT91CAP9_SRAM_SIZE,
40 .type = MT_DEVICE,
41 },
42};
43
44/* --------------------------------------------------------------------
45 * Clocks
46 * -------------------------------------------------------------------- */
47
48/*
49 * The peripheral clocks.
50 */
51static struct clk pioABCD_clk = {
52 .name = "pioABCD_clk",
53 .pmc_mask = 1 << AT91CAP9_ID_PIOABCD,
54 .type = CLK_TYPE_PERIPHERAL,
55};
56static struct clk mpb0_clk = {
57 .name = "mpb0_clk",
58 .pmc_mask = 1 << AT91CAP9_ID_MPB0,
59 .type = CLK_TYPE_PERIPHERAL,
60};
61static struct clk mpb1_clk = {
62 .name = "mpb1_clk",
63 .pmc_mask = 1 << AT91CAP9_ID_MPB1,
64 .type = CLK_TYPE_PERIPHERAL,
65};
66static struct clk mpb2_clk = {
67 .name = "mpb2_clk",
68 .pmc_mask = 1 << AT91CAP9_ID_MPB2,
69 .type = CLK_TYPE_PERIPHERAL,
70};
71static struct clk mpb3_clk = {
72 .name = "mpb3_clk",
73 .pmc_mask = 1 << AT91CAP9_ID_MPB3,
74 .type = CLK_TYPE_PERIPHERAL,
75};
76static struct clk mpb4_clk = {
77 .name = "mpb4_clk",
78 .pmc_mask = 1 << AT91CAP9_ID_MPB4,
79 .type = CLK_TYPE_PERIPHERAL,
80};
81static struct clk usart0_clk = {
82 .name = "usart0_clk",
83 .pmc_mask = 1 << AT91CAP9_ID_US0,
84 .type = CLK_TYPE_PERIPHERAL,
85};
86static struct clk usart1_clk = {
87 .name = "usart1_clk",
88 .pmc_mask = 1 << AT91CAP9_ID_US1,
89 .type = CLK_TYPE_PERIPHERAL,
90};
91static struct clk usart2_clk = {
92 .name = "usart2_clk",
93 .pmc_mask = 1 << AT91CAP9_ID_US2,
94 .type = CLK_TYPE_PERIPHERAL,
95};
96static struct clk mmc0_clk = {
97 .name = "mci0_clk",
98 .pmc_mask = 1 << AT91CAP9_ID_MCI0,
99 .type = CLK_TYPE_PERIPHERAL,
100};
101static struct clk mmc1_clk = {
102 .name = "mci1_clk",
103 .pmc_mask = 1 << AT91CAP9_ID_MCI1,
104 .type = CLK_TYPE_PERIPHERAL,
105};
106static struct clk can_clk = {
107 .name = "can_clk",
108 .pmc_mask = 1 << AT91CAP9_ID_CAN,
109 .type = CLK_TYPE_PERIPHERAL,
110};
111static struct clk twi_clk = {
112 .name = "twi_clk",
113 .pmc_mask = 1 << AT91CAP9_ID_TWI,
114 .type = CLK_TYPE_PERIPHERAL,
115};
116static struct clk spi0_clk = {
117 .name = "spi0_clk",
118 .pmc_mask = 1 << AT91CAP9_ID_SPI0,
119 .type = CLK_TYPE_PERIPHERAL,
120};
121static struct clk spi1_clk = {
122 .name = "spi1_clk",
123 .pmc_mask = 1 << AT91CAP9_ID_SPI1,
124 .type = CLK_TYPE_PERIPHERAL,
125};
126static struct clk ssc0_clk = {
127 .name = "ssc0_clk",
128 .pmc_mask = 1 << AT91CAP9_ID_SSC0,
129 .type = CLK_TYPE_PERIPHERAL,
130};
131static struct clk ssc1_clk = {
132 .name = "ssc1_clk",
133 .pmc_mask = 1 << AT91CAP9_ID_SSC1,
134 .type = CLK_TYPE_PERIPHERAL,
135};
136static struct clk ac97_clk = {
137 .name = "ac97_clk",
138 .pmc_mask = 1 << AT91CAP9_ID_AC97C,
139 .type = CLK_TYPE_PERIPHERAL,
140};
141static struct clk tcb_clk = {
142 .name = "tcb_clk",
143 .pmc_mask = 1 << AT91CAP9_ID_TCB,
144 .type = CLK_TYPE_PERIPHERAL,
145};
Andrew Victorbb1ad682008-09-18 19:42:37 +0100146static struct clk pwm_clk = {
147 .name = "pwm_clk",
Andrew Victor2b3b3512008-01-24 15:10:39 +0100148 .pmc_mask = 1 << AT91CAP9_ID_PWMC,
149 .type = CLK_TYPE_PERIPHERAL,
150};
151static struct clk macb_clk = {
152 .name = "macb_clk",
153 .pmc_mask = 1 << AT91CAP9_ID_EMAC,
154 .type = CLK_TYPE_PERIPHERAL,
155};
156static struct clk aestdes_clk = {
157 .name = "aestdes_clk",
158 .pmc_mask = 1 << AT91CAP9_ID_AESTDES,
159 .type = CLK_TYPE_PERIPHERAL,
160};
161static struct clk adc_clk = {
162 .name = "adc_clk",
163 .pmc_mask = 1 << AT91CAP9_ID_ADC,
164 .type = CLK_TYPE_PERIPHERAL,
165};
166static struct clk isi_clk = {
167 .name = "isi_clk",
168 .pmc_mask = 1 << AT91CAP9_ID_ISI,
169 .type = CLK_TYPE_PERIPHERAL,
170};
171static struct clk lcdc_clk = {
172 .name = "lcdc_clk",
173 .pmc_mask = 1 << AT91CAP9_ID_LCDC,
174 .type = CLK_TYPE_PERIPHERAL,
175};
176static struct clk dma_clk = {
177 .name = "dma_clk",
178 .pmc_mask = 1 << AT91CAP9_ID_DMA,
179 .type = CLK_TYPE_PERIPHERAL,
180};
181static struct clk udphs_clk = {
182 .name = "udphs_clk",
183 .pmc_mask = 1 << AT91CAP9_ID_UDPHS,
184 .type = CLK_TYPE_PERIPHERAL,
185};
186static struct clk ohci_clk = {
187 .name = "ohci_clk",
188 .pmc_mask = 1 << AT91CAP9_ID_UHP,
189 .type = CLK_TYPE_PERIPHERAL,
190};
191
192static struct clk *periph_clocks[] __initdata = {
193 &pioABCD_clk,
194 &mpb0_clk,
195 &mpb1_clk,
196 &mpb2_clk,
197 &mpb3_clk,
198 &mpb4_clk,
199 &usart0_clk,
200 &usart1_clk,
201 &usart2_clk,
202 &mmc0_clk,
203 &mmc1_clk,
204 &can_clk,
205 &twi_clk,
206 &spi0_clk,
207 &spi1_clk,
208 &ssc0_clk,
209 &ssc1_clk,
210 &ac97_clk,
211 &tcb_clk,
Andrew Victorbb1ad682008-09-18 19:42:37 +0100212 &pwm_clk,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100213 &macb_clk,
214 &aestdes_clk,
215 &adc_clk,
216 &isi_clk,
217 &lcdc_clk,
218 &dma_clk,
219 &udphs_clk,
220 &ohci_clk,
221 // irq0 .. irq1
222};
223
224/*
225 * The four programmable clocks.
226 * You must configure pin multiplexing to bring these signals out.
227 */
228static struct clk pck0 = {
229 .name = "pck0",
230 .pmc_mask = AT91_PMC_PCK0,
231 .type = CLK_TYPE_PROGRAMMABLE,
232 .id = 0,
233};
234static struct clk pck1 = {
235 .name = "pck1",
236 .pmc_mask = AT91_PMC_PCK1,
237 .type = CLK_TYPE_PROGRAMMABLE,
238 .id = 1,
239};
240static struct clk pck2 = {
241 .name = "pck2",
242 .pmc_mask = AT91_PMC_PCK2,
243 .type = CLK_TYPE_PROGRAMMABLE,
244 .id = 2,
245};
246static struct clk pck3 = {
247 .name = "pck3",
248 .pmc_mask = AT91_PMC_PCK3,
249 .type = CLK_TYPE_PROGRAMMABLE,
250 .id = 3,
251};
252
253static void __init at91cap9_register_clocks(void)
254{
255 int i;
256
257 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
258 clk_register(periph_clocks[i]);
259
260 clk_register(&pck0);
261 clk_register(&pck1);
262 clk_register(&pck2);
263 clk_register(&pck3);
264}
265
266/* --------------------------------------------------------------------
267 * GPIO
268 * -------------------------------------------------------------------- */
269
270static struct at91_gpio_bank at91cap9_gpio[] = {
271 {
272 .id = AT91CAP9_ID_PIOABCD,
273 .offset = AT91_PIOA,
274 .clock = &pioABCD_clk,
275 }, {
276 .id = AT91CAP9_ID_PIOABCD,
277 .offset = AT91_PIOB,
278 .clock = &pioABCD_clk,
279 }, {
280 .id = AT91CAP9_ID_PIOABCD,
281 .offset = AT91_PIOC,
282 .clock = &pioABCD_clk,
283 }, {
284 .id = AT91CAP9_ID_PIOABCD,
285 .offset = AT91_PIOD,
286 .clock = &pioABCD_clk,
287 }
288};
289
290static void at91cap9_reset(void)
291{
292 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
293}
294
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100295static void at91cap9_poweroff(void)
296{
297 at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
298}
299
300
Andrew Victor2b3b3512008-01-24 15:10:39 +0100301/* --------------------------------------------------------------------
302 * AT91CAP9 processor initialization
303 * -------------------------------------------------------------------- */
304
305void __init at91cap9_initialize(unsigned long main_clock)
306{
307 /* Map peripherals */
308 iotable_init(at91cap9_io_desc, ARRAY_SIZE(at91cap9_io_desc));
309
310 at91_arch_reset = at91cap9_reset;
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100311 pm_power_off = at91cap9_poweroff;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100312 at91_extern_irq = (1 << AT91CAP9_ID_IRQ0) | (1 << AT91CAP9_ID_IRQ1);
313
314 /* Init clock subsystem */
315 at91_clock_init(main_clock);
316
317 /* Register the processor-specific clocks */
318 at91cap9_register_clocks();
319
320 /* Register GPIO subsystem */
321 at91_gpio_init(at91cap9_gpio, 4);
Stelian Pop7be90a62008-10-22 13:52:08 +0100322
323 /* Remember the silicon revision */
324 if (cpu_is_at91cap9_revB())
325 system_rev = 0xB;
326 else if (cpu_is_at91cap9_revC())
327 system_rev = 0xC;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100328}
329
330/* --------------------------------------------------------------------
331 * Interrupt initialization
332 * -------------------------------------------------------------------- */
333
334/*
335 * The default interrupt priority levels (0 = lowest, 7 = highest).
336 */
337static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
338 7, /* Advanced Interrupt Controller (FIQ) */
339 7, /* System Peripherals */
340 1, /* Parallel IO Controller A, B, C and D */
341 0, /* MP Block Peripheral 0 */
342 0, /* MP Block Peripheral 1 */
343 0, /* MP Block Peripheral 2 */
344 0, /* MP Block Peripheral 3 */
345 0, /* MP Block Peripheral 4 */
346 5, /* USART 0 */
347 5, /* USART 1 */
348 5, /* USART 2 */
349 0, /* Multimedia Card Interface 0 */
350 0, /* Multimedia Card Interface 1 */
351 3, /* CAN */
352 6, /* Two-Wire Interface */
353 5, /* Serial Peripheral Interface 0 */
354 5, /* Serial Peripheral Interface 1 */
355 4, /* Serial Synchronous Controller 0 */
356 4, /* Serial Synchronous Controller 1 */
357 5, /* AC97 Controller */
358 0, /* Timer Counter 0, 1 and 2 */
359 0, /* Pulse Width Modulation Controller */
360 3, /* Ethernet */
361 0, /* Advanced Encryption Standard, Triple DES*/
362 0, /* Analog-to-Digital Converter */
363 0, /* Image Sensor Interface */
364 3, /* LCD Controller */
365 0, /* DMA Controller */
366 2, /* USB Device Port */
367 2, /* USB Host port */
368 0, /* Advanced Interrupt Controller (IRQ0) */
369 0, /* Advanced Interrupt Controller (IRQ1) */
370};
371
372void __init at91cap9_init_interrupts(unsigned int priority[NR_AIC_IRQS])
373{
374 if (!priority)
375 priority = at91cap9_default_irq_priority;
376
377 /* Initialize the AIC interrupt controller */
378 at91_aic_init(priority);
379
380 /* Enable GPIO interrupts */
381 at91_gpio_irq_setup();
382}