blob: bdf50974ef4c8d71428fc1aaec4099d0f3078309 [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
Russell King80b02c12009-01-08 10:01:47 +000018#include <asm/irq.h>
Andrew Victor2b3b3512008-01-24 15:10:39 +010019#include <asm/mach/arch.h>
20#include <asm/mach/map.h>
Stelian Pop7be90a62008-10-22 13:52:08 +010021
22#include <mach/cpu.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/at91cap9.h>
24#include <mach/at91_pmc.h>
25#include <mach/at91_rstc.h>
26#include <mach/at91_shdwc.h>
Andrew Victor2b3b3512008-01-24 15:10:39 +010027
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080028#include "soc.h"
Andrew Victor2b3b3512008-01-24 15:10:39 +010029#include "generic.h"
30#include "clock.h"
31
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080032static struct map_desc at91cap9_sram_desc[] __initdata = {
Andrew Victor2b3b3512008-01-24 15:10:39 +010033 {
Andrew Victor2b3b3512008-01-24 15:10:39 +010034 .virtual = AT91_IO_VIRT_BASE - AT91CAP9_SRAM_SIZE,
35 .pfn = __phys_to_pfn(AT91CAP9_SRAM_BASE),
36 .length = AT91CAP9_SRAM_SIZE,
37 .type = MT_DEVICE,
38 },
39};
40
41/* --------------------------------------------------------------------
42 * Clocks
43 * -------------------------------------------------------------------- */
44
45/*
46 * The peripheral clocks.
47 */
48static struct clk pioABCD_clk = {
49 .name = "pioABCD_clk",
50 .pmc_mask = 1 << AT91CAP9_ID_PIOABCD,
51 .type = CLK_TYPE_PERIPHERAL,
52};
53static struct clk mpb0_clk = {
54 .name = "mpb0_clk",
55 .pmc_mask = 1 << AT91CAP9_ID_MPB0,
56 .type = CLK_TYPE_PERIPHERAL,
57};
58static struct clk mpb1_clk = {
59 .name = "mpb1_clk",
60 .pmc_mask = 1 << AT91CAP9_ID_MPB1,
61 .type = CLK_TYPE_PERIPHERAL,
62};
63static struct clk mpb2_clk = {
64 .name = "mpb2_clk",
65 .pmc_mask = 1 << AT91CAP9_ID_MPB2,
66 .type = CLK_TYPE_PERIPHERAL,
67};
68static struct clk mpb3_clk = {
69 .name = "mpb3_clk",
70 .pmc_mask = 1 << AT91CAP9_ID_MPB3,
71 .type = CLK_TYPE_PERIPHERAL,
72};
73static struct clk mpb4_clk = {
74 .name = "mpb4_clk",
75 .pmc_mask = 1 << AT91CAP9_ID_MPB4,
76 .type = CLK_TYPE_PERIPHERAL,
77};
78static struct clk usart0_clk = {
79 .name = "usart0_clk",
80 .pmc_mask = 1 << AT91CAP9_ID_US0,
81 .type = CLK_TYPE_PERIPHERAL,
82};
83static struct clk usart1_clk = {
84 .name = "usart1_clk",
85 .pmc_mask = 1 << AT91CAP9_ID_US1,
86 .type = CLK_TYPE_PERIPHERAL,
87};
88static struct clk usart2_clk = {
89 .name = "usart2_clk",
90 .pmc_mask = 1 << AT91CAP9_ID_US2,
91 .type = CLK_TYPE_PERIPHERAL,
92};
93static struct clk mmc0_clk = {
94 .name = "mci0_clk",
95 .pmc_mask = 1 << AT91CAP9_ID_MCI0,
96 .type = CLK_TYPE_PERIPHERAL,
97};
98static struct clk mmc1_clk = {
99 .name = "mci1_clk",
100 .pmc_mask = 1 << AT91CAP9_ID_MCI1,
101 .type = CLK_TYPE_PERIPHERAL,
102};
103static struct clk can_clk = {
104 .name = "can_clk",
105 .pmc_mask = 1 << AT91CAP9_ID_CAN,
106 .type = CLK_TYPE_PERIPHERAL,
107};
108static struct clk twi_clk = {
109 .name = "twi_clk",
110 .pmc_mask = 1 << AT91CAP9_ID_TWI,
111 .type = CLK_TYPE_PERIPHERAL,
112};
113static struct clk spi0_clk = {
114 .name = "spi0_clk",
115 .pmc_mask = 1 << AT91CAP9_ID_SPI0,
116 .type = CLK_TYPE_PERIPHERAL,
117};
118static struct clk spi1_clk = {
119 .name = "spi1_clk",
120 .pmc_mask = 1 << AT91CAP9_ID_SPI1,
121 .type = CLK_TYPE_PERIPHERAL,
122};
123static struct clk ssc0_clk = {
124 .name = "ssc0_clk",
125 .pmc_mask = 1 << AT91CAP9_ID_SSC0,
126 .type = CLK_TYPE_PERIPHERAL,
127};
128static struct clk ssc1_clk = {
129 .name = "ssc1_clk",
130 .pmc_mask = 1 << AT91CAP9_ID_SSC1,
131 .type = CLK_TYPE_PERIPHERAL,
132};
133static struct clk ac97_clk = {
134 .name = "ac97_clk",
135 .pmc_mask = 1 << AT91CAP9_ID_AC97C,
136 .type = CLK_TYPE_PERIPHERAL,
137};
138static struct clk tcb_clk = {
139 .name = "tcb_clk",
140 .pmc_mask = 1 << AT91CAP9_ID_TCB,
141 .type = CLK_TYPE_PERIPHERAL,
142};
Andrew Victorbb1ad682008-09-18 19:42:37 +0100143static struct clk pwm_clk = {
144 .name = "pwm_clk",
Andrew Victor2b3b3512008-01-24 15:10:39 +0100145 .pmc_mask = 1 << AT91CAP9_ID_PWMC,
146 .type = CLK_TYPE_PERIPHERAL,
147};
148static struct clk macb_clk = {
149 .name = "macb_clk",
150 .pmc_mask = 1 << AT91CAP9_ID_EMAC,
151 .type = CLK_TYPE_PERIPHERAL,
152};
153static struct clk aestdes_clk = {
154 .name = "aestdes_clk",
155 .pmc_mask = 1 << AT91CAP9_ID_AESTDES,
156 .type = CLK_TYPE_PERIPHERAL,
157};
158static struct clk adc_clk = {
159 .name = "adc_clk",
160 .pmc_mask = 1 << AT91CAP9_ID_ADC,
161 .type = CLK_TYPE_PERIPHERAL,
162};
163static struct clk isi_clk = {
164 .name = "isi_clk",
165 .pmc_mask = 1 << AT91CAP9_ID_ISI,
166 .type = CLK_TYPE_PERIPHERAL,
167};
168static struct clk lcdc_clk = {
169 .name = "lcdc_clk",
170 .pmc_mask = 1 << AT91CAP9_ID_LCDC,
171 .type = CLK_TYPE_PERIPHERAL,
172};
173static struct clk dma_clk = {
174 .name = "dma_clk",
175 .pmc_mask = 1 << AT91CAP9_ID_DMA,
176 .type = CLK_TYPE_PERIPHERAL,
177};
178static struct clk udphs_clk = {
179 .name = "udphs_clk",
180 .pmc_mask = 1 << AT91CAP9_ID_UDPHS,
181 .type = CLK_TYPE_PERIPHERAL,
182};
183static struct clk ohci_clk = {
184 .name = "ohci_clk",
185 .pmc_mask = 1 << AT91CAP9_ID_UHP,
186 .type = CLK_TYPE_PERIPHERAL,
187};
188
189static struct clk *periph_clocks[] __initdata = {
190 &pioABCD_clk,
191 &mpb0_clk,
192 &mpb1_clk,
193 &mpb2_clk,
194 &mpb3_clk,
195 &mpb4_clk,
196 &usart0_clk,
197 &usart1_clk,
198 &usart2_clk,
199 &mmc0_clk,
200 &mmc1_clk,
201 &can_clk,
202 &twi_clk,
203 &spi0_clk,
204 &spi1_clk,
205 &ssc0_clk,
206 &ssc1_clk,
207 &ac97_clk,
208 &tcb_clk,
Andrew Victorbb1ad682008-09-18 19:42:37 +0100209 &pwm_clk,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100210 &macb_clk,
211 &aestdes_clk,
212 &adc_clk,
213 &isi_clk,
214 &lcdc_clk,
215 &dma_clk,
216 &udphs_clk,
217 &ohci_clk,
218 // irq0 .. irq1
219};
220
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100221static struct clk_lookup periph_clocks_lookups[] = {
Jean-Christophe PLAGNIOL-VILLARD9d871592011-06-21 14:24:33 +0800222 CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc", &utmi_clk),
223 CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc", &udphs_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100224 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
225 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
226 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
227 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
228 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
Joachim Eastwoodc5efefa2011-06-02 01:36:09 +0200229 CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
230 CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100231};
232
233static struct clk_lookup usart_clocks_lookups[] = {
234 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
235 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
236 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
237 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
238};
239
Andrew Victor2b3b3512008-01-24 15:10:39 +0100240/*
241 * The four programmable clocks.
242 * You must configure pin multiplexing to bring these signals out.
243 */
244static struct clk pck0 = {
245 .name = "pck0",
246 .pmc_mask = AT91_PMC_PCK0,
247 .type = CLK_TYPE_PROGRAMMABLE,
248 .id = 0,
249};
250static struct clk pck1 = {
251 .name = "pck1",
252 .pmc_mask = AT91_PMC_PCK1,
253 .type = CLK_TYPE_PROGRAMMABLE,
254 .id = 1,
255};
256static struct clk pck2 = {
257 .name = "pck2",
258 .pmc_mask = AT91_PMC_PCK2,
259 .type = CLK_TYPE_PROGRAMMABLE,
260 .id = 2,
261};
262static struct clk pck3 = {
263 .name = "pck3",
264 .pmc_mask = AT91_PMC_PCK3,
265 .type = CLK_TYPE_PROGRAMMABLE,
266 .id = 3,
267};
268
269static void __init at91cap9_register_clocks(void)
270{
271 int i;
272
273 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
274 clk_register(periph_clocks[i]);
275
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100276 clkdev_add_table(periph_clocks_lookups,
277 ARRAY_SIZE(periph_clocks_lookups));
278 clkdev_add_table(usart_clocks_lookups,
279 ARRAY_SIZE(usart_clocks_lookups));
280
Andrew Victor2b3b3512008-01-24 15:10:39 +0100281 clk_register(&pck0);
282 clk_register(&pck1);
283 clk_register(&pck2);
284 clk_register(&pck3);
285}
286
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100287static struct clk_lookup console_clock_lookup;
288
289void __init at91cap9_set_console_clock(int id)
290{
291 if (id >= ARRAY_SIZE(usart_clocks_lookups))
292 return;
293
294 console_clock_lookup.con_id = "usart";
295 console_clock_lookup.clk = usart_clocks_lookups[id].clk;
296 clkdev_add(&console_clock_lookup);
297}
298
Andrew Victor2b3b3512008-01-24 15:10:39 +0100299/* --------------------------------------------------------------------
300 * GPIO
301 * -------------------------------------------------------------------- */
302
303static struct at91_gpio_bank at91cap9_gpio[] = {
304 {
305 .id = AT91CAP9_ID_PIOABCD,
306 .offset = AT91_PIOA,
307 .clock = &pioABCD_clk,
308 }, {
309 .id = AT91CAP9_ID_PIOABCD,
310 .offset = AT91_PIOB,
311 .clock = &pioABCD_clk,
312 }, {
313 .id = AT91CAP9_ID_PIOABCD,
314 .offset = AT91_PIOC,
315 .clock = &pioABCD_clk,
316 }, {
317 .id = AT91CAP9_ID_PIOABCD,
318 .offset = AT91_PIOD,
319 .clock = &pioABCD_clk,
320 }
321};
322
323static void at91cap9_reset(void)
324{
325 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
326}
327
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100328static void at91cap9_poweroff(void)
329{
330 at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
331}
332
333
Andrew Victor2b3b3512008-01-24 15:10:39 +0100334/* --------------------------------------------------------------------
335 * AT91CAP9 processor initialization
336 * -------------------------------------------------------------------- */
337
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800338static void __init at91cap9_map_io(void)
Andrew Victor2b3b3512008-01-24 15:10:39 +0100339{
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800340 iotable_init(at91cap9_sram_desc, ARRAY_SIZE(at91cap9_sram_desc));
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800341}
Andrew Victor2b3b3512008-01-24 15:10:39 +0100342
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800343static void __init at91cap9_initialize(void)
344{
Andrew Victor2b3b3512008-01-24 15:10:39 +0100345 at91_arch_reset = at91cap9_reset;
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100346 pm_power_off = at91cap9_poweroff;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100347 at91_extern_irq = (1 << AT91CAP9_ID_IRQ0) | (1 << AT91CAP9_ID_IRQ1);
348
Andrew Victor2b3b3512008-01-24 15:10:39 +0100349 /* Register the processor-specific clocks */
350 at91cap9_register_clocks();
351
352 /* Register GPIO subsystem */
353 at91_gpio_init(at91cap9_gpio, 4);
Stelian Pop7be90a62008-10-22 13:52:08 +0100354
355 /* Remember the silicon revision */
356 if (cpu_is_at91cap9_revB())
357 system_rev = 0xB;
358 else if (cpu_is_at91cap9_revC())
359 system_rev = 0xC;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100360}
361
362/* --------------------------------------------------------------------
363 * Interrupt initialization
364 * -------------------------------------------------------------------- */
365
366/*
367 * The default interrupt priority levels (0 = lowest, 7 = highest).
368 */
369static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
370 7, /* Advanced Interrupt Controller (FIQ) */
371 7, /* System Peripherals */
372 1, /* Parallel IO Controller A, B, C and D */
373 0, /* MP Block Peripheral 0 */
374 0, /* MP Block Peripheral 1 */
375 0, /* MP Block Peripheral 2 */
376 0, /* MP Block Peripheral 3 */
377 0, /* MP Block Peripheral 4 */
378 5, /* USART 0 */
379 5, /* USART 1 */
380 5, /* USART 2 */
381 0, /* Multimedia Card Interface 0 */
382 0, /* Multimedia Card Interface 1 */
383 3, /* CAN */
384 6, /* Two-Wire Interface */
385 5, /* Serial Peripheral Interface 0 */
386 5, /* Serial Peripheral Interface 1 */
387 4, /* Serial Synchronous Controller 0 */
388 4, /* Serial Synchronous Controller 1 */
389 5, /* AC97 Controller */
390 0, /* Timer Counter 0, 1 and 2 */
391 0, /* Pulse Width Modulation Controller */
392 3, /* Ethernet */
393 0, /* Advanced Encryption Standard, Triple DES*/
394 0, /* Analog-to-Digital Converter */
395 0, /* Image Sensor Interface */
396 3, /* LCD Controller */
397 0, /* DMA Controller */
398 2, /* USB Device Port */
399 2, /* USB Host port */
400 0, /* Advanced Interrupt Controller (IRQ0) */
401 0, /* Advanced Interrupt Controller (IRQ1) */
402};
403
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800404struct at91_init_soc __initdata at91cap9_soc = {
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800405 .map_io = at91cap9_map_io,
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +0800406 .default_irq_priority = at91cap9_default_irq_priority,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800407 .init = at91cap9_initialize,
408};