blob: 17632b82dd76a810b11781bf7d5345412ffeebc9 [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
Andrew Victor2b3b3512008-01-24 15:10:39 +010032/* --------------------------------------------------------------------
33 * Clocks
34 * -------------------------------------------------------------------- */
35
36/*
37 * The peripheral clocks.
38 */
39static struct clk pioABCD_clk = {
40 .name = "pioABCD_clk",
41 .pmc_mask = 1 << AT91CAP9_ID_PIOABCD,
42 .type = CLK_TYPE_PERIPHERAL,
43};
44static struct clk mpb0_clk = {
45 .name = "mpb0_clk",
46 .pmc_mask = 1 << AT91CAP9_ID_MPB0,
47 .type = CLK_TYPE_PERIPHERAL,
48};
49static struct clk mpb1_clk = {
50 .name = "mpb1_clk",
51 .pmc_mask = 1 << AT91CAP9_ID_MPB1,
52 .type = CLK_TYPE_PERIPHERAL,
53};
54static struct clk mpb2_clk = {
55 .name = "mpb2_clk",
56 .pmc_mask = 1 << AT91CAP9_ID_MPB2,
57 .type = CLK_TYPE_PERIPHERAL,
58};
59static struct clk mpb3_clk = {
60 .name = "mpb3_clk",
61 .pmc_mask = 1 << AT91CAP9_ID_MPB3,
62 .type = CLK_TYPE_PERIPHERAL,
63};
64static struct clk mpb4_clk = {
65 .name = "mpb4_clk",
66 .pmc_mask = 1 << AT91CAP9_ID_MPB4,
67 .type = CLK_TYPE_PERIPHERAL,
68};
69static struct clk usart0_clk = {
70 .name = "usart0_clk",
71 .pmc_mask = 1 << AT91CAP9_ID_US0,
72 .type = CLK_TYPE_PERIPHERAL,
73};
74static struct clk usart1_clk = {
75 .name = "usart1_clk",
76 .pmc_mask = 1 << AT91CAP9_ID_US1,
77 .type = CLK_TYPE_PERIPHERAL,
78};
79static struct clk usart2_clk = {
80 .name = "usart2_clk",
81 .pmc_mask = 1 << AT91CAP9_ID_US2,
82 .type = CLK_TYPE_PERIPHERAL,
83};
84static struct clk mmc0_clk = {
85 .name = "mci0_clk",
86 .pmc_mask = 1 << AT91CAP9_ID_MCI0,
87 .type = CLK_TYPE_PERIPHERAL,
88};
89static struct clk mmc1_clk = {
90 .name = "mci1_clk",
91 .pmc_mask = 1 << AT91CAP9_ID_MCI1,
92 .type = CLK_TYPE_PERIPHERAL,
93};
94static struct clk can_clk = {
95 .name = "can_clk",
96 .pmc_mask = 1 << AT91CAP9_ID_CAN,
97 .type = CLK_TYPE_PERIPHERAL,
98};
99static struct clk twi_clk = {
100 .name = "twi_clk",
101 .pmc_mask = 1 << AT91CAP9_ID_TWI,
102 .type = CLK_TYPE_PERIPHERAL,
103};
104static struct clk spi0_clk = {
105 .name = "spi0_clk",
106 .pmc_mask = 1 << AT91CAP9_ID_SPI0,
107 .type = CLK_TYPE_PERIPHERAL,
108};
109static struct clk spi1_clk = {
110 .name = "spi1_clk",
111 .pmc_mask = 1 << AT91CAP9_ID_SPI1,
112 .type = CLK_TYPE_PERIPHERAL,
113};
114static struct clk ssc0_clk = {
115 .name = "ssc0_clk",
116 .pmc_mask = 1 << AT91CAP9_ID_SSC0,
117 .type = CLK_TYPE_PERIPHERAL,
118};
119static struct clk ssc1_clk = {
120 .name = "ssc1_clk",
121 .pmc_mask = 1 << AT91CAP9_ID_SSC1,
122 .type = CLK_TYPE_PERIPHERAL,
123};
124static struct clk ac97_clk = {
125 .name = "ac97_clk",
126 .pmc_mask = 1 << AT91CAP9_ID_AC97C,
127 .type = CLK_TYPE_PERIPHERAL,
128};
129static struct clk tcb_clk = {
130 .name = "tcb_clk",
131 .pmc_mask = 1 << AT91CAP9_ID_TCB,
132 .type = CLK_TYPE_PERIPHERAL,
133};
Andrew Victorbb1ad682008-09-18 19:42:37 +0100134static struct clk pwm_clk = {
135 .name = "pwm_clk",
Andrew Victor2b3b3512008-01-24 15:10:39 +0100136 .pmc_mask = 1 << AT91CAP9_ID_PWMC,
137 .type = CLK_TYPE_PERIPHERAL,
138};
139static struct clk macb_clk = {
Jamie Iles865d6052011-08-09 16:51:11 +0200140 .name = "pclk",
Andrew Victor2b3b3512008-01-24 15:10:39 +0100141 .pmc_mask = 1 << AT91CAP9_ID_EMAC,
142 .type = CLK_TYPE_PERIPHERAL,
143};
144static struct clk aestdes_clk = {
145 .name = "aestdes_clk",
146 .pmc_mask = 1 << AT91CAP9_ID_AESTDES,
147 .type = CLK_TYPE_PERIPHERAL,
148};
149static struct clk adc_clk = {
150 .name = "adc_clk",
151 .pmc_mask = 1 << AT91CAP9_ID_ADC,
152 .type = CLK_TYPE_PERIPHERAL,
153};
154static struct clk isi_clk = {
155 .name = "isi_clk",
156 .pmc_mask = 1 << AT91CAP9_ID_ISI,
157 .type = CLK_TYPE_PERIPHERAL,
158};
159static struct clk lcdc_clk = {
160 .name = "lcdc_clk",
161 .pmc_mask = 1 << AT91CAP9_ID_LCDC,
162 .type = CLK_TYPE_PERIPHERAL,
163};
164static struct clk dma_clk = {
165 .name = "dma_clk",
166 .pmc_mask = 1 << AT91CAP9_ID_DMA,
167 .type = CLK_TYPE_PERIPHERAL,
168};
169static struct clk udphs_clk = {
170 .name = "udphs_clk",
171 .pmc_mask = 1 << AT91CAP9_ID_UDPHS,
172 .type = CLK_TYPE_PERIPHERAL,
173};
174static struct clk ohci_clk = {
175 .name = "ohci_clk",
176 .pmc_mask = 1 << AT91CAP9_ID_UHP,
177 .type = CLK_TYPE_PERIPHERAL,
178};
179
180static struct clk *periph_clocks[] __initdata = {
181 &pioABCD_clk,
182 &mpb0_clk,
183 &mpb1_clk,
184 &mpb2_clk,
185 &mpb3_clk,
186 &mpb4_clk,
187 &usart0_clk,
188 &usart1_clk,
189 &usart2_clk,
190 &mmc0_clk,
191 &mmc1_clk,
192 &can_clk,
193 &twi_clk,
194 &spi0_clk,
195 &spi1_clk,
196 &ssc0_clk,
197 &ssc1_clk,
198 &ac97_clk,
199 &tcb_clk,
Andrew Victorbb1ad682008-09-18 19:42:37 +0100200 &pwm_clk,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100201 &macb_clk,
202 &aestdes_clk,
203 &adc_clk,
204 &isi_clk,
205 &lcdc_clk,
206 &dma_clk,
207 &udphs_clk,
208 &ohci_clk,
209 // irq0 .. irq1
210};
211
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100212static struct clk_lookup periph_clocks_lookups[] = {
Jamie Iles865d6052011-08-09 16:51:11 +0200213 /* One additional fake clock for macb_hclk */
214 CLKDEV_CON_ID("hclk", &macb_clk),
Jean-Christophe PLAGNIOL-VILLARD9d871592011-06-21 14:24:33 +0800215 CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc", &utmi_clk),
216 CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc", &udphs_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100217 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
218 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
219 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
220 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
221 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
Joachim Eastwoodc5efefa2011-06-02 01:36:09 +0200222 CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
223 CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +0200224 /* fake hclk clock */
225 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100226};
227
228static struct clk_lookup usart_clocks_lookups[] = {
229 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
230 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
231 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
232 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
233};
234
Andrew Victor2b3b3512008-01-24 15:10:39 +0100235/*
236 * The four programmable clocks.
237 * You must configure pin multiplexing to bring these signals out.
238 */
239static struct clk pck0 = {
240 .name = "pck0",
241 .pmc_mask = AT91_PMC_PCK0,
242 .type = CLK_TYPE_PROGRAMMABLE,
243 .id = 0,
244};
245static struct clk pck1 = {
246 .name = "pck1",
247 .pmc_mask = AT91_PMC_PCK1,
248 .type = CLK_TYPE_PROGRAMMABLE,
249 .id = 1,
250};
251static struct clk pck2 = {
252 .name = "pck2",
253 .pmc_mask = AT91_PMC_PCK2,
254 .type = CLK_TYPE_PROGRAMMABLE,
255 .id = 2,
256};
257static struct clk pck3 = {
258 .name = "pck3",
259 .pmc_mask = AT91_PMC_PCK3,
260 .type = CLK_TYPE_PROGRAMMABLE,
261 .id = 3,
262};
263
264static void __init at91cap9_register_clocks(void)
265{
266 int i;
267
268 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
269 clk_register(periph_clocks[i]);
270
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100271 clkdev_add_table(periph_clocks_lookups,
272 ARRAY_SIZE(periph_clocks_lookups));
273 clkdev_add_table(usart_clocks_lookups,
274 ARRAY_SIZE(usart_clocks_lookups));
275
Andrew Victor2b3b3512008-01-24 15:10:39 +0100276 clk_register(&pck0);
277 clk_register(&pck1);
278 clk_register(&pck2);
279 clk_register(&pck3);
280}
281
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100282static struct clk_lookup console_clock_lookup;
283
284void __init at91cap9_set_console_clock(int id)
285{
286 if (id >= ARRAY_SIZE(usart_clocks_lookups))
287 return;
288
289 console_clock_lookup.con_id = "usart";
290 console_clock_lookup.clk = usart_clocks_lookups[id].clk;
291 clkdev_add(&console_clock_lookup);
292}
293
Andrew Victor2b3b3512008-01-24 15:10:39 +0100294/* --------------------------------------------------------------------
295 * GPIO
296 * -------------------------------------------------------------------- */
297
298static struct at91_gpio_bank at91cap9_gpio[] = {
299 {
300 .id = AT91CAP9_ID_PIOABCD,
301 .offset = AT91_PIOA,
302 .clock = &pioABCD_clk,
303 }, {
304 .id = AT91CAP9_ID_PIOABCD,
305 .offset = AT91_PIOB,
306 .clock = &pioABCD_clk,
307 }, {
308 .id = AT91CAP9_ID_PIOABCD,
309 .offset = AT91_PIOC,
310 .clock = &pioABCD_clk,
311 }, {
312 .id = AT91CAP9_ID_PIOABCD,
313 .offset = AT91_PIOD,
314 .clock = &pioABCD_clk,
315 }
316};
317
318static void at91cap9_reset(void)
319{
320 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
321}
322
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100323static void at91cap9_poweroff(void)
324{
325 at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
326}
327
328
Andrew Victor2b3b3512008-01-24 15:10:39 +0100329/* --------------------------------------------------------------------
330 * AT91CAP9 processor initialization
331 * -------------------------------------------------------------------- */
332
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800333static void __init at91cap9_map_io(void)
Andrew Victor2b3b3512008-01-24 15:10:39 +0100334{
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +0800335 at91_init_sram(0, AT91CAP9_SRAM_BASE, AT91CAP9_SRAM_SIZE);
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800336}
Andrew Victor2b3b3512008-01-24 15:10:39 +0100337
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800338static void __init at91cap9_initialize(void)
339{
Andrew Victor2b3b3512008-01-24 15:10:39 +0100340 at91_arch_reset = at91cap9_reset;
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100341 pm_power_off = at91cap9_poweroff;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100342 at91_extern_irq = (1 << AT91CAP9_ID_IRQ0) | (1 << AT91CAP9_ID_IRQ1);
343
Andrew Victor2b3b3512008-01-24 15:10:39 +0100344 /* Register GPIO subsystem */
345 at91_gpio_init(at91cap9_gpio, 4);
Stelian Pop7be90a62008-10-22 13:52:08 +0100346
347 /* Remember the silicon revision */
348 if (cpu_is_at91cap9_revB())
349 system_rev = 0xB;
350 else if (cpu_is_at91cap9_revC())
351 system_rev = 0xC;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100352}
353
354/* --------------------------------------------------------------------
355 * Interrupt initialization
356 * -------------------------------------------------------------------- */
357
358/*
359 * The default interrupt priority levels (0 = lowest, 7 = highest).
360 */
361static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
362 7, /* Advanced Interrupt Controller (FIQ) */
363 7, /* System Peripherals */
364 1, /* Parallel IO Controller A, B, C and D */
365 0, /* MP Block Peripheral 0 */
366 0, /* MP Block Peripheral 1 */
367 0, /* MP Block Peripheral 2 */
368 0, /* MP Block Peripheral 3 */
369 0, /* MP Block Peripheral 4 */
370 5, /* USART 0 */
371 5, /* USART 1 */
372 5, /* USART 2 */
373 0, /* Multimedia Card Interface 0 */
374 0, /* Multimedia Card Interface 1 */
375 3, /* CAN */
376 6, /* Two-Wire Interface */
377 5, /* Serial Peripheral Interface 0 */
378 5, /* Serial Peripheral Interface 1 */
379 4, /* Serial Synchronous Controller 0 */
380 4, /* Serial Synchronous Controller 1 */
381 5, /* AC97 Controller */
382 0, /* Timer Counter 0, 1 and 2 */
383 0, /* Pulse Width Modulation Controller */
384 3, /* Ethernet */
385 0, /* Advanced Encryption Standard, Triple DES*/
386 0, /* Analog-to-Digital Converter */
387 0, /* Image Sensor Interface */
388 3, /* LCD Controller */
389 0, /* DMA Controller */
390 2, /* USB Device Port */
391 2, /* USB Host port */
392 0, /* Advanced Interrupt Controller (IRQ0) */
393 0, /* Advanced Interrupt Controller (IRQ1) */
394};
395
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800396struct at91_init_soc __initdata at91cap9_soc = {
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800397 .map_io = at91cap9_map_io,
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +0800398 .default_irq_priority = at91cap9_default_irq_priority,
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800399 .register_clocks = at91cap9_register_clocks,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800400 .init = at91cap9_initialize,
401};