blob: 8967d75c2ea3d4c4570efa8c77709b97d623eada [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
Nicolas Pitrec9dfafb2011-08-02 10:21:36 -040017#include <asm/proc-fns.h>
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>
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 = {
Jamie Iles865d6052011-08-09 16:51:11 +0200139 .name = "pclk",
Andrew Victor2b3b3512008-01-24 15:10:39 +0100140 .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[] = {
Jamie Iles865d6052011-08-09 16:51:11 +0200212 /* One additional fake clock for macb_hclk */
213 CLKDEV_CON_ID("hclk", &macb_clk),
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-VILLARD619d4a42011-11-13 13:00:58 +0800225 CLKDEV_CON_ID("pioA", &pioABCD_clk),
226 CLKDEV_CON_ID("pioB", &pioABCD_clk),
227 CLKDEV_CON_ID("pioC", &pioABCD_clk),
228 CLKDEV_CON_ID("pioD", &pioABCD_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100229};
230
231static struct clk_lookup usart_clocks_lookups[] = {
232 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
233 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
234 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
235 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
236};
237
Andrew Victor2b3b3512008-01-24 15:10:39 +0100238/*
239 * The four programmable clocks.
240 * You must configure pin multiplexing to bring these signals out.
241 */
242static struct clk pck0 = {
243 .name = "pck0",
244 .pmc_mask = AT91_PMC_PCK0,
245 .type = CLK_TYPE_PROGRAMMABLE,
246 .id = 0,
247};
248static struct clk pck1 = {
249 .name = "pck1",
250 .pmc_mask = AT91_PMC_PCK1,
251 .type = CLK_TYPE_PROGRAMMABLE,
252 .id = 1,
253};
254static struct clk pck2 = {
255 .name = "pck2",
256 .pmc_mask = AT91_PMC_PCK2,
257 .type = CLK_TYPE_PROGRAMMABLE,
258 .id = 2,
259};
260static struct clk pck3 = {
261 .name = "pck3",
262 .pmc_mask = AT91_PMC_PCK3,
263 .type = CLK_TYPE_PROGRAMMABLE,
264 .id = 3,
265};
266
267static void __init at91cap9_register_clocks(void)
268{
269 int i;
270
271 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
272 clk_register(periph_clocks[i]);
273
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100274 clkdev_add_table(periph_clocks_lookups,
275 ARRAY_SIZE(periph_clocks_lookups));
276 clkdev_add_table(usart_clocks_lookups,
277 ARRAY_SIZE(usart_clocks_lookups));
278
Andrew Victor2b3b3512008-01-24 15:10:39 +0100279 clk_register(&pck0);
280 clk_register(&pck1);
281 clk_register(&pck2);
282 clk_register(&pck3);
283}
284
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100285static struct clk_lookup console_clock_lookup;
286
287void __init at91cap9_set_console_clock(int id)
288{
289 if (id >= ARRAY_SIZE(usart_clocks_lookups))
290 return;
291
292 console_clock_lookup.con_id = "usart";
293 console_clock_lookup.clk = usart_clocks_lookups[id].clk;
294 clkdev_add(&console_clock_lookup);
295}
296
Andrew Victor2b3b3512008-01-24 15:10:39 +0100297/* --------------------------------------------------------------------
298 * GPIO
299 * -------------------------------------------------------------------- */
300
Jean-Christophe PLAGNIOL-VILLARD1a2d9152011-10-17 14:28:38 +0800301static struct at91_gpio_bank at91cap9_gpio[] __initdata = {
Andrew Victor2b3b3512008-01-24 15:10:39 +0100302 {
303 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800304 .regbase = AT91CAP9_BASE_PIOA,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100305 }, {
306 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800307 .regbase = AT91CAP9_BASE_PIOB,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100308 }, {
309 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800310 .regbase = AT91CAP9_BASE_PIOC,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100311 }, {
312 .id = AT91CAP9_ID_PIOABCD,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800313 .regbase = AT91CAP9_BASE_PIOD,
Andrew Victor2b3b3512008-01-24 15:10:39 +0100314 }
315};
316
Nicolas Pitrec9dfafb2011-08-02 10:21:36 -0400317static void at91cap9_idle(void)
318{
319 at91_sys_write(AT91_PMC_SCDR, AT91_PMC_PCK);
320 cpu_do_idle();
321}
322
Andrew Victor2b3b3512008-01-24 15:10:39 +0100323/* --------------------------------------------------------------------
324 * AT91CAP9 processor initialization
325 * -------------------------------------------------------------------- */
326
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800327static void __init at91cap9_map_io(void)
Andrew Victor2b3b3512008-01-24 15:10:39 +0100328{
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +0800329 at91_init_sram(0, AT91CAP9_SRAM_BASE, AT91CAP9_SRAM_SIZE);
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800330}
Andrew Victor2b3b3512008-01-24 15:10:39 +0100331
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800332static void __init at91cap9_ioremap_registers(void)
333{
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +0800334 at91_ioremap_shdwc(AT91CAP9_BASE_SHDWC);
Jean-Christophe PLAGNIOL-VILLARDe9f68b52011-11-18 01:25:52 +0800335 at91_ioremap_rstc(AT91CAP9_BASE_RSTC);
Jean-Christophe PLAGNIOL-VILLARD4ab0c5992011-09-18 22:29:50 +0800336 at91sam926x_ioremap_pit(AT91CAP9_BASE_PIT);
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +0800337 at91sam9_ioremap_smc(0, AT91CAP9_BASE_SMC);
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800338}
339
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800340static void __init at91cap9_initialize(void)
341{
Nicolas Pitrec9dfafb2011-08-02 10:21:36 -0400342 arm_pm_idle = at91cap9_idle;
Jean-Christophe PLAGNIOL-VILLARD14f991a2011-11-18 01:41:28 +0800343 arm_pm_restart = at91sam9g45_restart;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100344 at91_extern_irq = (1 << AT91CAP9_ID_IRQ0) | (1 << AT91CAP9_ID_IRQ1);
345
Andrew Victor2b3b3512008-01-24 15:10:39 +0100346 /* Register GPIO subsystem */
347 at91_gpio_init(at91cap9_gpio, 4);
Stelian Pop7be90a62008-10-22 13:52:08 +0100348
349 /* Remember the silicon revision */
350 if (cpu_is_at91cap9_revB())
351 system_rev = 0xB;
352 else if (cpu_is_at91cap9_revC())
353 system_rev = 0xC;
Andrew Victor2b3b3512008-01-24 15:10:39 +0100354}
355
356/* --------------------------------------------------------------------
357 * Interrupt initialization
358 * -------------------------------------------------------------------- */
359
360/*
361 * The default interrupt priority levels (0 = lowest, 7 = highest).
362 */
363static unsigned int at91cap9_default_irq_priority[NR_AIC_IRQS] __initdata = {
364 7, /* Advanced Interrupt Controller (FIQ) */
365 7, /* System Peripherals */
366 1, /* Parallel IO Controller A, B, C and D */
367 0, /* MP Block Peripheral 0 */
368 0, /* MP Block Peripheral 1 */
369 0, /* MP Block Peripheral 2 */
370 0, /* MP Block Peripheral 3 */
371 0, /* MP Block Peripheral 4 */
372 5, /* USART 0 */
373 5, /* USART 1 */
374 5, /* USART 2 */
375 0, /* Multimedia Card Interface 0 */
376 0, /* Multimedia Card Interface 1 */
377 3, /* CAN */
378 6, /* Two-Wire Interface */
379 5, /* Serial Peripheral Interface 0 */
380 5, /* Serial Peripheral Interface 1 */
381 4, /* Serial Synchronous Controller 0 */
382 4, /* Serial Synchronous Controller 1 */
383 5, /* AC97 Controller */
384 0, /* Timer Counter 0, 1 and 2 */
385 0, /* Pulse Width Modulation Controller */
386 3, /* Ethernet */
387 0, /* Advanced Encryption Standard, Triple DES*/
388 0, /* Analog-to-Digital Converter */
389 0, /* Image Sensor Interface */
390 3, /* LCD Controller */
391 0, /* DMA Controller */
392 2, /* USB Device Port */
393 2, /* USB Host port */
394 0, /* Advanced Interrupt Controller (IRQ0) */
395 0, /* Advanced Interrupt Controller (IRQ1) */
396};
397
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800398struct at91_init_soc __initdata at91cap9_soc = {
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800399 .map_io = at91cap9_map_io,
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +0800400 .default_irq_priority = at91cap9_default_irq_priority,
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800401 .ioremap_registers = at91cap9_ioremap_registers,
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800402 .register_clocks = at91cap9_register_clocks,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800403 .init = at91cap9_initialize,
404};