blob: 2a42b99d99d1109510aa804dc856781a676b9d04 [file] [log] [blame]
Andrew Victorb2c65612007-02-08 09:42:40 +01001/*
2 * arch/arm/mach-at91/at91sam9263.c
3 *
4 * Copyright (C) 2007 Atmel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12
13#include <linux/module.h>
14
Russell King80b02c12009-01-08 10:01:47 +000015#include <asm/irq.h>
Andrew Victorb2c65612007-02-08 09:42:40 +010016#include <asm/mach/arch.h>
17#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/at91sam9263.h>
19#include <mach/at91_pmc.h>
20#include <mach/at91_rstc.h>
Andrew Victorb2c65612007-02-08 09:42:40 +010021
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080022#include "soc.h"
Andrew Victorb2c65612007-02-08 09:42:40 +010023#include "generic.h"
24#include "clock.h"
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +080025#include "sam9_smc.h"
Andrew Victorb2c65612007-02-08 09:42:40 +010026
Andrew Victorb2c65612007-02-08 09:42:40 +010027/* --------------------------------------------------------------------
28 * Clocks
29 * -------------------------------------------------------------------- */
30
31/*
32 * The peripheral clocks.
33 */
34static struct clk pioA_clk = {
35 .name = "pioA_clk",
36 .pmc_mask = 1 << AT91SAM9263_ID_PIOA,
37 .type = CLK_TYPE_PERIPHERAL,
38};
39static struct clk pioB_clk = {
40 .name = "pioB_clk",
41 .pmc_mask = 1 << AT91SAM9263_ID_PIOB,
42 .type = CLK_TYPE_PERIPHERAL,
43};
44static struct clk pioCDE_clk = {
45 .name = "pioCDE_clk",
46 .pmc_mask = 1 << AT91SAM9263_ID_PIOCDE,
47 .type = CLK_TYPE_PERIPHERAL,
48};
49static struct clk usart0_clk = {
50 .name = "usart0_clk",
51 .pmc_mask = 1 << AT91SAM9263_ID_US0,
52 .type = CLK_TYPE_PERIPHERAL,
53};
54static struct clk usart1_clk = {
55 .name = "usart1_clk",
56 .pmc_mask = 1 << AT91SAM9263_ID_US1,
57 .type = CLK_TYPE_PERIPHERAL,
58};
59static struct clk usart2_clk = {
60 .name = "usart2_clk",
61 .pmc_mask = 1 << AT91SAM9263_ID_US2,
62 .type = CLK_TYPE_PERIPHERAL,
63};
64static struct clk mmc0_clk = {
65 .name = "mci0_clk",
66 .pmc_mask = 1 << AT91SAM9263_ID_MCI0,
67 .type = CLK_TYPE_PERIPHERAL,
68};
69static struct clk mmc1_clk = {
70 .name = "mci1_clk",
71 .pmc_mask = 1 << AT91SAM9263_ID_MCI1,
72 .type = CLK_TYPE_PERIPHERAL,
73};
Andrew Victore8788ba2007-05-02 17:14:57 +010074static struct clk can_clk = {
75 .name = "can_clk",
76 .pmc_mask = 1 << AT91SAM9263_ID_CAN,
77 .type = CLK_TYPE_PERIPHERAL,
78};
Andrew Victorb2c65612007-02-08 09:42:40 +010079static struct clk twi_clk = {
80 .name = "twi_clk",
81 .pmc_mask = 1 << AT91SAM9263_ID_TWI,
82 .type = CLK_TYPE_PERIPHERAL,
83};
84static struct clk spi0_clk = {
85 .name = "spi0_clk",
86 .pmc_mask = 1 << AT91SAM9263_ID_SPI0,
87 .type = CLK_TYPE_PERIPHERAL,
88};
89static struct clk spi1_clk = {
90 .name = "spi1_clk",
91 .pmc_mask = 1 << AT91SAM9263_ID_SPI1,
92 .type = CLK_TYPE_PERIPHERAL,
93};
Andrew Victore8788ba2007-05-02 17:14:57 +010094static struct clk ssc0_clk = {
95 .name = "ssc0_clk",
96 .pmc_mask = 1 << AT91SAM9263_ID_SSC0,
97 .type = CLK_TYPE_PERIPHERAL,
98};
99static struct clk ssc1_clk = {
100 .name = "ssc1_clk",
101 .pmc_mask = 1 << AT91SAM9263_ID_SSC1,
102 .type = CLK_TYPE_PERIPHERAL,
103};
104static struct clk ac97_clk = {
105 .name = "ac97_clk",
106 .pmc_mask = 1 << AT91SAM9263_ID_AC97C,
107 .type = CLK_TYPE_PERIPHERAL,
108};
Andrew Victorb2c65612007-02-08 09:42:40 +0100109static struct clk tcb_clk = {
110 .name = "tcb_clk",
111 .pmc_mask = 1 << AT91SAM9263_ID_TCB,
112 .type = CLK_TYPE_PERIPHERAL,
113};
Andrew Victorbb1ad682008-09-18 19:42:37 +0100114static struct clk pwm_clk = {
115 .name = "pwm_clk",
Andrew Victore8788ba2007-05-02 17:14:57 +0100116 .pmc_mask = 1 << AT91SAM9263_ID_PWMC,
117 .type = CLK_TYPE_PERIPHERAL,
118};
Andrew Victor69b2e992007-02-14 08:44:43 +0100119static struct clk macb_clk = {
120 .name = "macb_clk",
Andrew Victorb2c65612007-02-08 09:42:40 +0100121 .pmc_mask = 1 << AT91SAM9263_ID_EMAC,
122 .type = CLK_TYPE_PERIPHERAL,
123};
Andrew Victore8788ba2007-05-02 17:14:57 +0100124static struct clk dma_clk = {
125 .name = "dma_clk",
126 .pmc_mask = 1 << AT91SAM9263_ID_DMA,
127 .type = CLK_TYPE_PERIPHERAL,
128};
129static struct clk twodge_clk = {
130 .name = "2dge_clk",
131 .pmc_mask = 1 << AT91SAM9263_ID_2DGE,
132 .type = CLK_TYPE_PERIPHERAL,
133};
Andrew Victorb2c65612007-02-08 09:42:40 +0100134static struct clk udc_clk = {
135 .name = "udc_clk",
136 .pmc_mask = 1 << AT91SAM9263_ID_UDP,
137 .type = CLK_TYPE_PERIPHERAL,
138};
139static struct clk isi_clk = {
140 .name = "isi_clk",
141 .pmc_mask = 1 << AT91SAM9263_ID_ISI,
142 .type = CLK_TYPE_PERIPHERAL,
143};
144static struct clk lcdc_clk = {
145 .name = "lcdc_clk",
Andrew Victor7f6e2d92007-02-22 07:34:56 +0100146 .pmc_mask = 1 << AT91SAM9263_ID_LCDC,
Andrew Victorb2c65612007-02-08 09:42:40 +0100147 .type = CLK_TYPE_PERIPHERAL,
148};
149static struct clk ohci_clk = {
150 .name = "ohci_clk",
151 .pmc_mask = 1 << AT91SAM9263_ID_UHP,
152 .type = CLK_TYPE_PERIPHERAL,
153};
154
155static struct clk *periph_clocks[] __initdata = {
156 &pioA_clk,
157 &pioB_clk,
158 &pioCDE_clk,
159 &usart0_clk,
160 &usart1_clk,
161 &usart2_clk,
162 &mmc0_clk,
163 &mmc1_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100164 &can_clk,
Andrew Victorb2c65612007-02-08 09:42:40 +0100165 &twi_clk,
166 &spi0_clk,
167 &spi1_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100168 &ssc0_clk,
169 &ssc1_clk,
170 &ac97_clk,
Andrew Victorb2c65612007-02-08 09:42:40 +0100171 &tcb_clk,
Andrew Victorbb1ad682008-09-18 19:42:37 +0100172 &pwm_clk,
Andrew Victor69b2e992007-02-14 08:44:43 +0100173 &macb_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100174 &twodge_clk,
Andrew Victorb2c65612007-02-08 09:42:40 +0100175 &udc_clk,
176 &isi_clk,
177 &lcdc_clk,
Andrew Victore8788ba2007-05-02 17:14:57 +0100178 &dma_clk,
Andrew Victorb2c65612007-02-08 09:42:40 +0100179 &ohci_clk,
180 // irq0 .. irq1
181};
182
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100183static struct clk_lookup periph_clocks_lookups[] = {
184 CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
185 CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
186 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.0", &mmc0_clk),
187 CLKDEV_CON_DEV_ID("mci_clk", "at91_mci.1", &mmc1_clk),
188 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
189 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
190 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +0200191 /* fake hclk clock */
192 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100193};
194
195static struct clk_lookup usart_clocks_lookups[] = {
196 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
197 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
198 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
199 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
200};
201
Andrew Victorb2c65612007-02-08 09:42:40 +0100202/*
203 * The four programmable clocks.
204 * You must configure pin multiplexing to bring these signals out.
205 */
206static struct clk pck0 = {
207 .name = "pck0",
208 .pmc_mask = AT91_PMC_PCK0,
209 .type = CLK_TYPE_PROGRAMMABLE,
210 .id = 0,
211};
212static struct clk pck1 = {
213 .name = "pck1",
214 .pmc_mask = AT91_PMC_PCK1,
215 .type = CLK_TYPE_PROGRAMMABLE,
216 .id = 1,
217};
218static struct clk pck2 = {
219 .name = "pck2",
220 .pmc_mask = AT91_PMC_PCK2,
221 .type = CLK_TYPE_PROGRAMMABLE,
222 .id = 2,
223};
224static struct clk pck3 = {
225 .name = "pck3",
226 .pmc_mask = AT91_PMC_PCK3,
227 .type = CLK_TYPE_PROGRAMMABLE,
228 .id = 3,
229};
230
231static void __init at91sam9263_register_clocks(void)
232{
233 int i;
234
235 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
236 clk_register(periph_clocks[i]);
237
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100238 clkdev_add_table(periph_clocks_lookups,
239 ARRAY_SIZE(periph_clocks_lookups));
240 clkdev_add_table(usart_clocks_lookups,
241 ARRAY_SIZE(usart_clocks_lookups));
242
Andrew Victorb2c65612007-02-08 09:42:40 +0100243 clk_register(&pck0);
244 clk_register(&pck1);
245 clk_register(&pck2);
246 clk_register(&pck3);
247}
248
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +0100249static struct clk_lookup console_clock_lookup;
250
251void __init at91sam9263_set_console_clock(int id)
252{
253 if (id >= ARRAY_SIZE(usart_clocks_lookups))
254 return;
255
256 console_clock_lookup.con_id = "usart";
257 console_clock_lookup.clk = usart_clocks_lookups[id].clk;
258 clkdev_add(&console_clock_lookup);
259}
260
Andrew Victorb2c65612007-02-08 09:42:40 +0100261/* --------------------------------------------------------------------
262 * GPIO
263 * -------------------------------------------------------------------- */
264
265static struct at91_gpio_bank at91sam9263_gpio[] = {
266 {
267 .id = AT91SAM9263_ID_PIOA,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800268 .regbase = AT91SAM9263_BASE_PIOA,
Andrew Victorb2c65612007-02-08 09:42:40 +0100269 .clock = &pioA_clk,
270 }, {
271 .id = AT91SAM9263_ID_PIOB,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800272 .regbase = AT91SAM9263_BASE_PIOB,
Andrew Victorb2c65612007-02-08 09:42:40 +0100273 .clock = &pioB_clk,
274 }, {
275 .id = AT91SAM9263_ID_PIOCDE,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800276 .regbase = AT91SAM9263_BASE_PIOC,
Andrew Victorb2c65612007-02-08 09:42:40 +0100277 .clock = &pioCDE_clk,
278 }, {
279 .id = AT91SAM9263_ID_PIOCDE,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800280 .regbase = AT91SAM9263_BASE_PIOD,
Andrew Victorb2c65612007-02-08 09:42:40 +0100281 .clock = &pioCDE_clk,
282 }, {
283 .id = AT91SAM9263_ID_PIOCDE,
Jean-Christophe PLAGNIOL-VILLARD80e91cb2011-09-16 23:37:50 +0800284 .regbase = AT91SAM9263_BASE_PIOE,
Andrew Victorb2c65612007-02-08 09:42:40 +0100285 .clock = &pioCDE_clk,
286 }
287};
288
Andrew Victorb2c65612007-02-08 09:42:40 +0100289/* --------------------------------------------------------------------
290 * AT91SAM9263 processor initialization
291 * -------------------------------------------------------------------- */
292
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800293static void __init at91sam9263_map_io(void)
Andrew Victorb2c65612007-02-08 09:42:40 +0100294{
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +0800295 at91_init_sram(0, AT91SAM9263_SRAM0_BASE, AT91SAM9263_SRAM0_SIZE);
296 at91_init_sram(1, AT91SAM9263_SRAM1_BASE, AT91SAM9263_SRAM1_SIZE);
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800297}
Andrew Victorb2c65612007-02-08 09:42:40 +0100298
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800299static void __init at91sam9263_ioremap_registers(void)
300{
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +0800301 at91_ioremap_shdwc(AT91SAM9263_BASE_SHDWC);
Jean-Christophe PLAGNIOL-VILLARD4ab0c5992011-09-18 22:29:50 +0800302 at91sam926x_ioremap_pit(AT91SAM9263_BASE_PIT);
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +0800303 at91sam9_ioremap_smc(0, AT91SAM9263_BASE_SMC0);
304 at91sam9_ioremap_smc(1, AT91SAM9263_BASE_SMC1);
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800305}
306
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800307static void __init at91sam9263_initialize(void)
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800308{
Nicolas Ferrebb413db2010-10-14 19:14:00 +0200309 at91_arch_reset = at91sam9_alt_reset;
Andrew Victorb2c65612007-02-08 09:42:40 +0100310 at91_extern_irq = (1 << AT91SAM9263_ID_IRQ0) | (1 << AT91SAM9263_ID_IRQ1);
311
Andrew Victorb2c65612007-02-08 09:42:40 +0100312 /* Register GPIO subsystem */
313 at91_gpio_init(at91sam9263_gpio, 5);
314}
315
316/* --------------------------------------------------------------------
317 * Interrupt initialization
318 * -------------------------------------------------------------------- */
319
320/*
321 * The default interrupt priority levels (0 = lowest, 7 = highest).
322 */
323static unsigned int at91sam9263_default_irq_priority[NR_AIC_IRQS] __initdata = {
324 7, /* Advanced Interrupt Controller (FIQ) */
325 7, /* System Peripherals */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100326 1, /* Parallel IO Controller A */
327 1, /* Parallel IO Controller B */
328 1, /* Parallel IO Controller C, D and E */
Andrew Victorb2c65612007-02-08 09:42:40 +0100329 0,
330 0,
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100331 5, /* USART 0 */
332 5, /* USART 1 */
333 5, /* USART 2 */
Andrew Victorb2c65612007-02-08 09:42:40 +0100334 0, /* Multimedia Card Interface 0 */
335 0, /* Multimedia Card Interface 1 */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100336 3, /* CAN */
337 6, /* Two-Wire Interface */
338 5, /* Serial Peripheral Interface 0 */
339 5, /* Serial Peripheral Interface 1 */
340 4, /* Serial Synchronous Controller 0 */
341 4, /* Serial Synchronous Controller 1 */
342 5, /* AC97 Controller */
Andrew Victorb2c65612007-02-08 09:42:40 +0100343 0, /* Timer Counter 0, 1 and 2 */
344 0, /* Pulse Width Modulation Controller */
345 3, /* Ethernet */
346 0,
347 0, /* 2D Graphic Engine */
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100348 2, /* USB Device Port */
Andrew Victorb2c65612007-02-08 09:42:40 +0100349 0, /* Image Sensor Interface */
350 3, /* LDC Controller */
351 0, /* DMA Controller */
352 0,
Andrew Victor7cbed2b2007-11-20 08:46:53 +0100353 2, /* USB Host port */
Andrew Victorb2c65612007-02-08 09:42:40 +0100354 0, /* Advanced Interrupt Controller (IRQ0) */
355 0, /* Advanced Interrupt Controller (IRQ1) */
356};
357
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800358struct at91_init_soc __initdata at91sam9263_soc = {
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800359 .map_io = at91sam9263_map_io,
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +0800360 .default_irq_priority = at91sam9263_default_irq_priority,
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800361 .ioremap_registers = at91sam9263_ioremap_registers,
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800362 .register_clocks = at91sam9263_register_clocks,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800363 .init = at91sam9263_initialize,
364};