blob: 652dbe1c9cefc01a99933ecee052fd7aea6b3d8b [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>
16
Russell King80b02c12009-01-08 10:01:47 +000017#include <asm/irq.h>
Andrew Victor2b3b3512008-01-24 15:10:39 +010018#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>
Andrew Victor2b3b3512008-01-24 15:10:39 +010025
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080026#include "soc.h"
Andrew Victor2b3b3512008-01-24 15:10:39 +010027#include "generic.h"
28#include "clock.h"
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +080029#include "sam9_smc.h"
Andrew Victor2b3b3512008-01-24 15:10:39 +010030
Andrew Victor2b3b3512008-01-24 15:10:39 +010031/* --------------------------------------------------------------------
32 * Clocks
33 * -------------------------------------------------------------------- */
34
35/*
36 * The peripheral clocks.
37 */
38static struct clk pioABCD_clk = {
39 .name = "pioABCD_clk",
40 .pmc_mask = 1 << AT91CAP9_ID_PIOABCD,
41 .type = CLK_TYPE_PERIPHERAL,
42};
43static struct clk mpb0_clk = {
44 .name = "mpb0_clk",
45 .pmc_mask = 1 << AT91CAP9_ID_MPB0,
46 .type = CLK_TYPE_PERIPHERAL,
47};
48static struct clk mpb1_clk = {
49 .name = "mpb1_clk",
50 .pmc_mask = 1 << AT91CAP9_ID_MPB1,
51 .type = CLK_TYPE_PERIPHERAL,
52};
53static struct clk mpb2_clk = {
54 .name = "mpb2_clk",
55 .pmc_mask = 1 << AT91CAP9_ID_MPB2,
56 .type = CLK_TYPE_PERIPHERAL,
57};
58static struct clk mpb3_clk = {
59 .name = "mpb3_clk",
60 .pmc_mask = 1 << AT91CAP9_ID_MPB3,
61 .type = CLK_TYPE_PERIPHERAL,
62};
63static struct clk mpb4_clk = {
64 .name = "mpb4_clk",
65 .pmc_mask = 1 << AT91CAP9_ID_MPB4,
66 .type = CLK_TYPE_PERIPHERAL,
67};
68static struct clk usart0_clk = {
69 .name = "usart0_clk",
70 .pmc_mask = 1 << AT91CAP9_ID_US0,
71 .type = CLK_TYPE_PERIPHERAL,
72};
73static struct clk usart1_clk = {
74 .name = "usart1_clk",
75 .pmc_mask = 1 << AT91CAP9_ID_US1,
76 .type = CLK_TYPE_PERIPHERAL,
77};
78static struct clk usart2_clk = {
79 .name = "usart2_clk",
80 .pmc_mask = 1 << AT91CAP9_ID_US2,
81 .type = CLK_TYPE_PERIPHERAL,
82};
83static struct clk mmc0_clk = {
84 .name = "mci0_clk",
85 .pmc_mask = 1 << AT91CAP9_ID_MCI0,
86 .type = CLK_TYPE_PERIPHERAL,
87};
88static struct clk mmc1_clk = {
89 .name = "mci1_clk",
90 .pmc_mask = 1 << AT91CAP9_ID_MCI1,
91 .type = CLK_TYPE_PERIPHERAL,
92};
93static struct clk can_clk = {
94 .name = "can_clk",
95 .pmc_mask = 1 << AT91CAP9_ID_CAN,
96 .type = CLK_TYPE_PERIPHERAL,
97};
98static struct clk twi_clk = {
99 .name = "twi_clk",
100 .pmc_mask = 1 << AT91CAP9_ID_TWI,
101 .type = CLK_TYPE_PERIPHERAL,
102};
103static struct clk spi0_clk = {
104 .name = "spi0_clk",
105 .pmc_mask = 1 << AT91CAP9_ID_SPI0,
106 .type = CLK_TYPE_PERIPHERAL,
107};
108static struct clk spi1_clk = {
109 .name = "spi1_clk",
110 .pmc_mask = 1 << AT91CAP9_ID_SPI1,
111 .type = CLK_TYPE_PERIPHERAL,
112};
113static struct clk ssc0_clk = {
114 .name = "ssc0_clk",
115 .pmc_mask = 1 << AT91CAP9_ID_SSC0,
116 .type = CLK_TYPE_PERIPHERAL,
117};
118static struct clk ssc1_clk = {
119 .name = "ssc1_clk",
120 .pmc_mask = 1 << AT91CAP9_ID_SSC1,
121 .type = CLK_TYPE_PERIPHERAL,
122};
123static struct clk ac97_clk = {
124 .name = "ac97_clk",
125 .pmc_mask = 1 << AT91CAP9_ID_AC97C,
126 .type = CLK_TYPE_PERIPHERAL,
127};
128static struct clk tcb_clk = {
129 .name = "tcb_clk",
130 .pmc_mask = 1 << AT91CAP9_ID_TCB,
131 .type = CLK_TYPE_PERIPHERAL,
132};
Andrew Victorbb1ad682008-09-18 19:42:37 +0100133static struct clk pwm_clk = {
134 .name = "pwm_clk",
Andrew Victor2b3b3512008-01-24 15:10:39 +0100135 .pmc_mask = 1 << AT91CAP9_ID_PWMC,
136 .type = CLK_TYPE_PERIPHERAL,
137};
138static struct clk macb_clk = {
139 .name = "macb_clk",
140 .pmc_mask = 1 << AT91CAP9_ID_EMAC,
141 .type = CLK_TYPE_PERIPHERAL,
142};
143static struct clk aestdes_clk = {
144 .name = "aestdes_clk",
145 .pmc_mask = 1 << AT91CAP9_ID_AESTDES,
146 .type = CLK_TYPE_PERIPHERAL,
147};
148static struct clk adc_clk = {
149 .name = "adc_clk",
150 .pmc_mask = 1 << AT91CAP9_ID_ADC,
151 .type = CLK_TYPE_PERIPHERAL,
152};
153static struct clk isi_clk = {
154 .name = "isi_clk",
155 .pmc_mask = 1 << AT91CAP9_ID_ISI,
156 .type = CLK_TYPE_PERIPHERAL,
157};
158static struct clk lcdc_clk = {
159 .name = "lcdc_clk",
160 .pmc_mask = 1 << AT91CAP9_ID_LCDC,
161 .type = CLK_TYPE_PERIPHERAL,
162};
163static struct clk dma_clk = {
164 .name = "dma_clk",
165 .pmc_mask = 1 << AT91CAP9_ID_DMA,
166 .type = CLK_TYPE_PERIPHERAL,
167};
168static struct clk udphs_clk = {
169 .name = "udphs_clk",
170 .pmc_mask = 1 << AT91CAP9_ID_UDPHS,
171 .type = CLK_TYPE_PERIPHERAL,
172};
173static struct clk ohci_clk = {
174 .name = "ohci_clk",
175 .pmc_mask = 1 << AT91CAP9_ID_UHP,
176 .type = CLK_TYPE_PERIPHERAL,
177};
178
179static struct clk *periph_clocks[] __initdata = {
180 &pioABCD_clk,
181 &mpb0_clk,
182 &mpb1_clk,
183 &mpb2_clk,
184 &mpb3_clk,
185 &mpb4_clk,
186 &usart0_clk,
187 &usart1_clk,
188 &usart2_clk,
189 &mmc0_clk,
190 &mmc1_clk,
191 &can_clk,
192 &twi_clk,
193 &spi0_clk,
194 &spi1_clk,
195 &ssc0_clk,
196 &ssc1_clk,
197 &ac97_clk,
198 &tcb_clk,
Andrew Victorbb1ad682008-09-18 19:42:37 +0100199 &pwm_clk,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100200 &macb_clk,
201 &aestdes_clk,
202 &adc_clk,
203 &isi_clk,
204 &lcdc_clk,
205 &dma_clk,
206 &udphs_clk,
207 &ohci_clk,
208 // irq0 .. irq1
209};
210
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100211static struct clk_lookup periph_clocks_lookups[] = {
Jean-Christophe PLAGNIOL-VILLARD9d871592011-06-21 14:24:33 +0800212 CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc", &utmi_clk),
213 CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc", &udphs_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100214 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
215 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
216 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
217 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
218 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
Joachim Eastwoodc5efefa2011-06-02 01:36:09 +0200219 CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
220 CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +0200221 /* fake hclk clock */
222 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100223};
224
225static struct clk_lookup usart_clocks_lookups[] = {
226 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
227 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
228 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
229 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
230};
231
Andrew Victor2b3b3512008-01-24 15:10:39 +0100232/*
233 * The four programmable clocks.
234 * You must configure pin multiplexing to bring these signals out.
235 */
236static struct clk pck0 = {
237 .name = "pck0",
238 .pmc_mask = AT91_PMC_PCK0,
239 .type = CLK_TYPE_PROGRAMMABLE,
240 .id = 0,
241};
242static struct clk pck1 = {
243 .name = "pck1",
244 .pmc_mask = AT91_PMC_PCK1,
245 .type = CLK_TYPE_PROGRAMMABLE,
246 .id = 1,
247};
248static struct clk pck2 = {
249 .name = "pck2",
250 .pmc_mask = AT91_PMC_PCK2,
251 .type = CLK_TYPE_PROGRAMMABLE,
252 .id = 2,
253};
254static struct clk pck3 = {
255 .name = "pck3",
256 .pmc_mask = AT91_PMC_PCK3,
257 .type = CLK_TYPE_PROGRAMMABLE,
258 .id = 3,
259};
260
261static void __init at91cap9_register_clocks(void)
262{
263 int i;
264
265 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
266 clk_register(periph_clocks[i]);
267
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100268 clkdev_add_table(periph_clocks_lookups,
269 ARRAY_SIZE(periph_clocks_lookups));
270 clkdev_add_table(usart_clocks_lookups,
271 ARRAY_SIZE(usart_clocks_lookups));
272
Andrew Victor2b3b3512008-01-24 15:10:39 +0100273 clk_register(&pck0);
274 clk_register(&pck1);
275 clk_register(&pck2);
276 clk_register(&pck3);
277}
278
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100279static struct clk_lookup console_clock_lookup;
280
281void __init at91cap9_set_console_clock(int id)
282{
283 if (id >= ARRAY_SIZE(usart_clocks_lookups))
284 return;
285
286 console_clock_lookup.con_id = "usart";
287 console_clock_lookup.clk = usart_clocks_lookups[id].clk;
288 clkdev_add(&console_clock_lookup);
289}
290
Andrew Victor2b3b3512008-01-24 15:10:39 +0100291/* --------------------------------------------------------------------
292 * GPIO
293 * -------------------------------------------------------------------- */
294
295static struct at91_gpio_bank at91cap9_gpio[] = {
296 {
297 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800298 .regbase = AT91CAP9_BASE_PIOA,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100299 .clock = &pioABCD_clk,
300 }, {
301 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800302 .regbase = AT91CAP9_BASE_PIOB,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100303 .clock = &pioABCD_clk,
304 }, {
305 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800306 .regbase = AT91CAP9_BASE_PIOC,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100307 .clock = &pioABCD_clk,
308 }, {
309 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800310 .regbase = AT91CAP9_BASE_PIOD,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100311 .clock = &pioABCD_clk,
312 }
313};
314
315static void at91cap9_reset(void)
316{
317 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
318}
319
320/* --------------------------------------------------------------------
321 * AT91CAP9 processor initialization
322 * -------------------------------------------------------------------- */
323
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800324static void __init at91cap9_map_io(void)
Andrew Victor2b3b3512008-01-24 15:10:39 +0100325{
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +0800326 at91_init_sram(0, AT91CAP9_SRAM_BASE, AT91CAP9_SRAM_SIZE);
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800327}
Andrew Victor2b3b3512008-01-24 15:10:39 +0100328
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800329static void __init at91cap9_ioremap_registers(void)
330{
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +0800331 at91_ioremap_shdwc(AT91CAP9_BASE_SHDWC);
Jean-Christophe PLAGNIOL-VILLARD4ab0c5992011-09-18 22:29:50 +0800332 at91sam926x_ioremap_pit(AT91CAP9_BASE_PIT);
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +0800333 at91sam9_ioremap_smc(0, AT91CAP9_BASE_SMC);
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800334}
335
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800336static void __init at91cap9_initialize(void)
337{
Andrew Victor2b3b3512008-01-24 15:10:39 +0100338 at91_arch_reset = at91cap9_reset;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100339 at91_extern_irq = (1 << AT91CAP9_ID_IRQ0) | (1 << AT91CAP9_ID_IRQ1);
340
Andrew Victor2b3b3512008-01-24 15:10:39 +0100341 /* Register GPIO subsystem */
342 at91_gpio_init(at91cap9_gpio, 4);
Stelian Pop7be90a62008-10-22 13:52:08 +0100343
344 /* Remember the silicon revision */
345 if (cpu_is_at91cap9_revB())
346 system_rev = 0xB;
347 else if (cpu_is_at91cap9_revC())
348 system_rev = 0xC;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100349}
350
351/* --------------------------------------------------------------------
352 * Interrupt initialization
353 * -------------------------------------------------------------------- */
354
355/*
356 * The default interrupt priority levels (0 = lowest, 7 = highest).
357 */
358static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
359 7, /* Advanced Interrupt Controller (FIQ) */
360 7, /* System Peripherals */
361 1, /* Parallel IO Controller A, B, C and D */
362 0, /* MP Block Peripheral 0 */
363 0, /* MP Block Peripheral 1 */
364 0, /* MP Block Peripheral 2 */
365 0, /* MP Block Peripheral 3 */
366 0, /* MP Block Peripheral 4 */
367 5, /* USART 0 */
368 5, /* USART 1 */
369 5, /* USART 2 */
370 0, /* Multimedia Card Interface 0 */
371 0, /* Multimedia Card Interface 1 */
372 3, /* CAN */
373 6, /* Two-Wire Interface */
374 5, /* Serial Peripheral Interface 0 */
375 5, /* Serial Peripheral Interface 1 */
376 4, /* Serial Synchronous Controller 0 */
377 4, /* Serial Synchronous Controller 1 */
378 5, /* AC97 Controller */
379 0, /* Timer Counter 0, 1 and 2 */
380 0, /* Pulse Width Modulation Controller */
381 3, /* Ethernet */
382 0, /* Advanced Encryption Standard, Triple DES*/
383 0, /* Analog-to-Digital Converter */
384 0, /* Image Sensor Interface */
385 3, /* LCD Controller */
386 0, /* DMA Controller */
387 2, /* USB Device Port */
388 2, /* USB Host port */
389 0, /* Advanced Interrupt Controller (IRQ0) */
390 0, /* Advanced Interrupt Controller (IRQ1) */
391};
392
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800393struct at91_init_soc __initdata at91cap9_soc = {
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800394 .map_io = at91cap9_map_io,
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +0800395 .default_irq_priority = at91cap9_default_irq_priority,
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800396 .ioremap_registers = at91cap9_ioremap_registers,
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800397 .register_clocks = at91cap9_register_clocks,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800398 .init = at91cap9_initialize,
399};