blob: 1ea931274bac1d9397a734dd13a8fc01504951b1 [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"
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +080031#include "sam9_smc.h"
Andrew Victor2b3b3512008-01-24 15:10:39 +010032
Andrew Victor2b3b3512008-01-24 15:10:39 +010033/* --------------------------------------------------------------------
34 * Clocks
35 * -------------------------------------------------------------------- */
36
37/*
38 * The peripheral clocks.
39 */
40static struct clk pioABCD_clk = {
41 .name = "pioABCD_clk",
42 .pmc_mask = 1 << AT91CAP9_ID_PIOABCD,
43 .type = CLK_TYPE_PERIPHERAL,
44};
45static struct clk mpb0_clk = {
46 .name = "mpb0_clk",
47 .pmc_mask = 1 << AT91CAP9_ID_MPB0,
48 .type = CLK_TYPE_PERIPHERAL,
49};
50static struct clk mpb1_clk = {
51 .name = "mpb1_clk",
52 .pmc_mask = 1 << AT91CAP9_ID_MPB1,
53 .type = CLK_TYPE_PERIPHERAL,
54};
55static struct clk mpb2_clk = {
56 .name = "mpb2_clk",
57 .pmc_mask = 1 << AT91CAP9_ID_MPB2,
58 .type = CLK_TYPE_PERIPHERAL,
59};
60static struct clk mpb3_clk = {
61 .name = "mpb3_clk",
62 .pmc_mask = 1 << AT91CAP9_ID_MPB3,
63 .type = CLK_TYPE_PERIPHERAL,
64};
65static struct clk mpb4_clk = {
66 .name = "mpb4_clk",
67 .pmc_mask = 1 << AT91CAP9_ID_MPB4,
68 .type = CLK_TYPE_PERIPHERAL,
69};
70static struct clk usart0_clk = {
71 .name = "usart0_clk",
72 .pmc_mask = 1 << AT91CAP9_ID_US0,
73 .type = CLK_TYPE_PERIPHERAL,
74};
75static struct clk usart1_clk = {
76 .name = "usart1_clk",
77 .pmc_mask = 1 << AT91CAP9_ID_US1,
78 .type = CLK_TYPE_PERIPHERAL,
79};
80static struct clk usart2_clk = {
81 .name = "usart2_clk",
82 .pmc_mask = 1 << AT91CAP9_ID_US2,
83 .type = CLK_TYPE_PERIPHERAL,
84};
85static struct clk mmc0_clk = {
86 .name = "mci0_clk",
87 .pmc_mask = 1 << AT91CAP9_ID_MCI0,
88 .type = CLK_TYPE_PERIPHERAL,
89};
90static struct clk mmc1_clk = {
91 .name = "mci1_clk",
92 .pmc_mask = 1 << AT91CAP9_ID_MCI1,
93 .type = CLK_TYPE_PERIPHERAL,
94};
95static struct clk can_clk = {
96 .name = "can_clk",
97 .pmc_mask = 1 << AT91CAP9_ID_CAN,
98 .type = CLK_TYPE_PERIPHERAL,
99};
100static struct clk twi_clk = {
101 .name = "twi_clk",
102 .pmc_mask = 1 << AT91CAP9_ID_TWI,
103 .type = CLK_TYPE_PERIPHERAL,
104};
105static struct clk spi0_clk = {
106 .name = "spi0_clk",
107 .pmc_mask = 1 << AT91CAP9_ID_SPI0,
108 .type = CLK_TYPE_PERIPHERAL,
109};
110static struct clk spi1_clk = {
111 .name = "spi1_clk",
112 .pmc_mask = 1 << AT91CAP9_ID_SPI1,
113 .type = CLK_TYPE_PERIPHERAL,
114};
115static struct clk ssc0_clk = {
116 .name = "ssc0_clk",
117 .pmc_mask = 1 << AT91CAP9_ID_SSC0,
118 .type = CLK_TYPE_PERIPHERAL,
119};
120static struct clk ssc1_clk = {
121 .name = "ssc1_clk",
122 .pmc_mask = 1 << AT91CAP9_ID_SSC1,
123 .type = CLK_TYPE_PERIPHERAL,
124};
125static struct clk ac97_clk = {
126 .name = "ac97_clk",
127 .pmc_mask = 1 << AT91CAP9_ID_AC97C,
128 .type = CLK_TYPE_PERIPHERAL,
129};
130static struct clk tcb_clk = {
131 .name = "tcb_clk",
132 .pmc_mask = 1 << AT91CAP9_ID_TCB,
133 .type = CLK_TYPE_PERIPHERAL,
134};
Andrew Victorbb1ad682008-09-18 19:42:37 +0100135static struct clk pwm_clk = {
136 .name = "pwm_clk",
Andrew Victor2b3b3512008-01-24 15:10:39 +0100137 .pmc_mask = 1 << AT91CAP9_ID_PWMC,
138 .type = CLK_TYPE_PERIPHERAL,
139};
140static struct clk macb_clk = {
141 .name = "macb_clk",
142 .pmc_mask = 1 << AT91CAP9_ID_EMAC,
143 .type = CLK_TYPE_PERIPHERAL,
144};
145static struct clk aestdes_clk = {
146 .name = "aestdes_clk",
147 .pmc_mask = 1 << AT91CAP9_ID_AESTDES,
148 .type = CLK_TYPE_PERIPHERAL,
149};
150static struct clk adc_clk = {
151 .name = "adc_clk",
152 .pmc_mask = 1 << AT91CAP9_ID_ADC,
153 .type = CLK_TYPE_PERIPHERAL,
154};
155static struct clk isi_clk = {
156 .name = "isi_clk",
157 .pmc_mask = 1 << AT91CAP9_ID_ISI,
158 .type = CLK_TYPE_PERIPHERAL,
159};
160static struct clk lcdc_clk = {
161 .name = "lcdc_clk",
162 .pmc_mask = 1 << AT91CAP9_ID_LCDC,
163 .type = CLK_TYPE_PERIPHERAL,
164};
165static struct clk dma_clk = {
166 .name = "dma_clk",
167 .pmc_mask = 1 << AT91CAP9_ID_DMA,
168 .type = CLK_TYPE_PERIPHERAL,
169};
170static struct clk udphs_clk = {
171 .name = "udphs_clk",
172 .pmc_mask = 1 << AT91CAP9_ID_UDPHS,
173 .type = CLK_TYPE_PERIPHERAL,
174};
175static struct clk ohci_clk = {
176 .name = "ohci_clk",
177 .pmc_mask = 1 << AT91CAP9_ID_UHP,
178 .type = CLK_TYPE_PERIPHERAL,
179};
180
181static struct clk *periph_clocks[] __initdata = {
182 &pioABCD_clk,
183 &mpb0_clk,
184 &mpb1_clk,
185 &mpb2_clk,
186 &mpb3_clk,
187 &mpb4_clk,
188 &usart0_clk,
189 &usart1_clk,
190 &usart2_clk,
191 &mmc0_clk,
192 &mmc1_clk,
193 &can_clk,
194 &twi_clk,
195 &spi0_clk,
196 &spi1_clk,
197 &ssc0_clk,
198 &ssc1_clk,
199 &ac97_clk,
200 &tcb_clk,
Andrew Victorbb1ad682008-09-18 19:42:37 +0100201 &pwm_clk,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100202 &macb_clk,
203 &aestdes_clk,
204 &adc_clk,
205 &isi_clk,
206 &lcdc_clk,
207 &dma_clk,
208 &udphs_clk,
209 &ohci_clk,
210 // irq0 .. irq1
211};
212
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100213static struct clk_lookup periph_clocks_lookups[] = {
Jean-Christophe PLAGNIOL-VILLARD9d871592011-06-21 14:24:33 +0800214 CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc", &utmi_clk),
215 CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc", &udphs_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100216 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
217 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
218 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
219 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
220 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
Joachim Eastwoodc5efefa2011-06-02 01:36:09 +0200221 CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
222 CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +0200223 /* fake hclk clock */
224 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100225};
226
227static struct clk_lookup usart_clocks_lookups[] = {
228 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
229 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
230 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
231 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
232};
233
Andrew Victor2b3b3512008-01-24 15:10:39 +0100234/*
235 * The four programmable clocks.
236 * You must configure pin multiplexing to bring these signals out.
237 */
238static struct clk pck0 = {
239 .name = "pck0",
240 .pmc_mask = AT91_PMC_PCK0,
241 .type = CLK_TYPE_PROGRAMMABLE,
242 .id = 0,
243};
244static struct clk pck1 = {
245 .name = "pck1",
246 .pmc_mask = AT91_PMC_PCK1,
247 .type = CLK_TYPE_PROGRAMMABLE,
248 .id = 1,
249};
250static struct clk pck2 = {
251 .name = "pck2",
252 .pmc_mask = AT91_PMC_PCK2,
253 .type = CLK_TYPE_PROGRAMMABLE,
254 .id = 2,
255};
256static struct clk pck3 = {
257 .name = "pck3",
258 .pmc_mask = AT91_PMC_PCK3,
259 .type = CLK_TYPE_PROGRAMMABLE,
260 .id = 3,
261};
262
263static void __init at91cap9_register_clocks(void)
264{
265 int i;
266
267 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
268 clk_register(periph_clocks[i]);
269
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100270 clkdev_add_table(periph_clocks_lookups,
271 ARRAY_SIZE(periph_clocks_lookups));
272 clkdev_add_table(usart_clocks_lookups,
273 ARRAY_SIZE(usart_clocks_lookups));
274
Andrew Victor2b3b3512008-01-24 15:10:39 +0100275 clk_register(&pck0);
276 clk_register(&pck1);
277 clk_register(&pck2);
278 clk_register(&pck3);
279}
280
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100281static struct clk_lookup console_clock_lookup;
282
283void __init at91cap9_set_console_clock(int id)
284{
285 if (id >= ARRAY_SIZE(usart_clocks_lookups))
286 return;
287
288 console_clock_lookup.con_id = "usart";
289 console_clock_lookup.clk = usart_clocks_lookups[id].clk;
290 clkdev_add(&console_clock_lookup);
291}
292
Andrew Victor2b3b3512008-01-24 15:10:39 +0100293/* --------------------------------------------------------------------
294 * GPIO
295 * -------------------------------------------------------------------- */
296
297static struct at91_gpio_bank at91cap9_gpio[] = {
298 {
299 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800300 .regbase = AT91CAP9_BASE_PIOA,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100301 .clock = &pioABCD_clk,
302 }, {
303 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800304 .regbase = AT91CAP9_BASE_PIOB,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100305 .clock = &pioABCD_clk,
306 }, {
307 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800308 .regbase = AT91CAP9_BASE_PIOC,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100309 .clock = &pioABCD_clk,
310 }, {
311 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800312 .regbase = AT91CAP9_BASE_PIOD,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100313 .clock = &pioABCD_clk,
314 }
315};
316
317static void at91cap9_reset(void)
318{
319 at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
320}
321
Andrew Victor3ef2fb42008-04-02 21:36:06 +0100322static void at91cap9_poweroff(void)
323{
324 at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
325}
326
327
Andrew Victor2b3b3512008-01-24 15:10:39 +0100328/* --------------------------------------------------------------------
329 * AT91CAP9 processor initialization
330 * -------------------------------------------------------------------- */
331
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800332static void __init at91cap9_map_io(void)
Andrew Victor2b3b3512008-01-24 15:10:39 +0100333{
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +0800334 at91_init_sram(0, AT91CAP9_SRAM_BASE, AT91CAP9_SRAM_SIZE);
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800335}
Andrew Victor2b3b3512008-01-24 15:10:39 +0100336
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800337static void __init at91cap9_ioremap_registers(void)
338{
Jean-Christophe PLAGNIOL-VILLARD4ab0c592011-09-18 22:29:50 +0800339 at91sam926x_ioremap_pit(AT91CAP9_BASE_PIT);
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +0800340 at91sam9_ioremap_smc(0, AT91CAP9_BASE_SMC);
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800341}
342
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 GPIO subsystem */
350 at91_gpio_init(at91cap9_gpio, 4);
Stelian Pop7be90a62008-10-22 13:52:08 +0100351
352 /* Remember the silicon revision */
353 if (cpu_is_at91cap9_revB())
354 system_rev = 0xB;
355 else if (cpu_is_at91cap9_revC())
356 system_rev = 0xC;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100357}
358
359/* --------------------------------------------------------------------
360 * Interrupt initialization
361 * -------------------------------------------------------------------- */
362
363/*
364 * The default interrupt priority levels (0 = lowest, 7 = highest).
365 */
366static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
367 7, /* Advanced Interrupt Controller (FIQ) */
368 7, /* System Peripherals */
369 1, /* Parallel IO Controller A, B, C and D */
370 0, /* MP Block Peripheral 0 */
371 0, /* MP Block Peripheral 1 */
372 0, /* MP Block Peripheral 2 */
373 0, /* MP Block Peripheral 3 */
374 0, /* MP Block Peripheral 4 */
375 5, /* USART 0 */
376 5, /* USART 1 */
377 5, /* USART 2 */
378 0, /* Multimedia Card Interface 0 */
379 0, /* Multimedia Card Interface 1 */
380 3, /* CAN */
381 6, /* Two-Wire Interface */
382 5, /* Serial Peripheral Interface 0 */
383 5, /* Serial Peripheral Interface 1 */
384 4, /* Serial Synchronous Controller 0 */
385 4, /* Serial Synchronous Controller 1 */
386 5, /* AC97 Controller */
387 0, /* Timer Counter 0, 1 and 2 */
388 0, /* Pulse Width Modulation Controller */
389 3, /* Ethernet */
390 0, /* Advanced Encryption Standard, Triple DES*/
391 0, /* Analog-to-Digital Converter */
392 0, /* Image Sensor Interface */
393 3, /* LCD Controller */
394 0, /* DMA Controller */
395 2, /* USB Device Port */
396 2, /* USB Host port */
397 0, /* Advanced Interrupt Controller (IRQ0) */
398 0, /* Advanced Interrupt Controller (IRQ1) */
399};
400
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800401struct at91_init_soc __initdata at91cap9_soc = {
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800402 .map_io = at91cap9_map_io,
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +0800403 .default_irq_priority = at91cap9_default_irq_priority,
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800404 .ioremap_registers = at91cap9_ioremap_registers,
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800405 .register_clocks = at91cap9_register_clocks,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800406 .init = at91cap9_initialize,
407};