blob: fc86a80ef565cd4cb0aba32dc839ed4e665a9a48 [file] [log] [blame]
Saeed Bishara651c74c2008-06-22 22:45:06 +02001/*
2 * arch/arm/mach-kirkwood/common.c
3 *
4 * Core functions for Marvell Kirkwood SoCs
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/platform_device.h>
14#include <linux/serial_8250.h>
15#include <linux/mbus.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020016#include <linux/ata_platform.h>
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -040017#include <linux/mtd/nand.h>
Lennert Buytenhek18365d12008-08-09 15:38:18 +020018#include <linux/spi/orion_spi.h>
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +020019#include <net/dsa.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020020#include <asm/page.h>
21#include <asm/timex.h>
Eric Cooper9c153642011-02-02 17:16:11 -050022#include <asm/kexec.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020023#include <asm/mach/map.h>
24#include <asm/mach/time.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/kirkwood.h>
Nicolas Pitrefdd8b072009-04-22 20:08:17 +010026#include <mach/bridge-regs.h>
apatard@mandriva.com49106c72010-05-31 13:49:12 +020027#include <plat/audio.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020028#include <plat/cache-feroceon-l2.h>
29#include <plat/ehci-orion.h>
Nicolas Pitre8235ee02009-02-14 03:15:55 -050030#include <plat/mvsdio.h>
Saeed Bishara09c0ed22008-06-23 04:26:07 -110031#include <plat/mv_xor.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020032#include <plat/orion_nand.h>
Nicolas Pitre3b937a72009-06-01 13:56:02 -040033#include <plat/orion_wdt.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020034#include <plat/common.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020035#include <plat/time.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020036#include "common.h"
37
38/*****************************************************************************
39 * I/O Address Mapping
40 ****************************************************************************/
41static struct map_desc kirkwood_io_desc[] __initdata = {
42 {
43 .virtual = KIRKWOOD_PCIE_IO_VIRT_BASE,
44 .pfn = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
45 .length = KIRKWOOD_PCIE_IO_SIZE,
46 .type = MT_DEVICE,
47 }, {
Saeed Bisharaffd58bd2010-06-08 14:21:34 +030048 .virtual = KIRKWOOD_PCIE1_IO_VIRT_BASE,
49 .pfn = __phys_to_pfn(KIRKWOOD_PCIE1_IO_PHYS_BASE),
50 .length = KIRKWOOD_PCIE1_IO_SIZE,
51 .type = MT_DEVICE,
52 }, {
Saeed Bishara651c74c2008-06-22 22:45:06 +020053 .virtual = KIRKWOOD_REGS_VIRT_BASE,
54 .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
55 .length = KIRKWOOD_REGS_SIZE,
56 .type = MT_DEVICE,
57 },
58};
59
60void __init kirkwood_map_io(void)
61{
62 iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
63}
64
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +020065/*
66 * Default clock control bits. Any bit _not_ set in this variable
67 * will be cleared from the hardware after platform devices have been
68 * registered. Some reserved bits must be set to 1.
69 */
70unsigned int kirkwood_clk_ctrl = CGC_DUNIT | CGC_RESERVED;
Andrew Lunn7e3819d2011-05-15 13:32:44 +020071
Saeed Bishara651c74c2008-06-22 22:45:06 +020072
73/*****************************************************************************
74 * EHCI
75 ****************************************************************************/
76static struct orion_ehci_data kirkwood_ehci_data = {
77 .dram = &kirkwood_mbus_dram_info,
Ronen Shitritfb6f5522008-09-17 10:08:05 +030078 .phy_version = EHCI_PHY_NA,
Saeed Bishara651c74c2008-06-22 22:45:06 +020079};
80
Andrew Lunn5c602552011-05-15 13:32:40 +020081static u64 ehci_dmamask = DMA_BIT_MASK(32);
Saeed Bishara651c74c2008-06-22 22:45:06 +020082
83
84/*****************************************************************************
85 * EHCI0
86 ****************************************************************************/
87static struct resource kirkwood_ehci_resources[] = {
88 {
89 .start = USB_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +020090 .end = USB_PHYS_BASE + SZ_4K - 1,
Saeed Bishara651c74c2008-06-22 22:45:06 +020091 .flags = IORESOURCE_MEM,
92 }, {
93 .start = IRQ_KIRKWOOD_USB,
94 .end = IRQ_KIRKWOOD_USB,
95 .flags = IORESOURCE_IRQ,
96 },
97};
98
99static struct platform_device kirkwood_ehci = {
100 .name = "orion-ehci",
101 .id = 0,
102 .dev = {
103 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200104 .coherent_dma_mask = DMA_BIT_MASK(32),
Saeed Bishara651c74c2008-06-22 22:45:06 +0200105 .platform_data = &kirkwood_ehci_data,
106 },
107 .resource = kirkwood_ehci_resources,
108 .num_resources = ARRAY_SIZE(kirkwood_ehci_resources),
109};
110
111void __init kirkwood_ehci_init(void)
112{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200113 kirkwood_clk_ctrl |= CGC_USB0;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200114 platform_device_register(&kirkwood_ehci);
115}
116
117
118/*****************************************************************************
119 * GE00
120 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200121void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
122{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200123 kirkwood_clk_ctrl |= CGC_GE0;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200124
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200125 orion_ge00_init(eth_data, &kirkwood_mbus_dram_info,
126 GE00_PHYS_BASE, IRQ_KIRKWOOD_GE00_SUM,
127 IRQ_KIRKWOOD_GE00_ERR, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200128}
129
130
131/*****************************************************************************
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200132 * GE01
133 ****************************************************************************/
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200134void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data)
135{
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200136
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200137 kirkwood_clk_ctrl |= CGC_GE1;
138
139 orion_ge01_init(eth_data, &kirkwood_mbus_dram_info,
140 GE01_PHYS_BASE, IRQ_KIRKWOOD_GE01_SUM,
141 IRQ_KIRKWOOD_GE01_ERR, kirkwood_tclk);
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200142}
143
144
145/*****************************************************************************
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200146 * Ethernet switch
147 ****************************************************************************/
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200148void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
149{
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200150 orion_ge00_switch_init(d, irq);
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200151}
152
153
154/*****************************************************************************
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400155 * NAND flash
156 ****************************************************************************/
157static struct resource kirkwood_nand_resource = {
158 .flags = IORESOURCE_MEM,
159 .start = KIRKWOOD_NAND_MEM_PHYS_BASE,
160 .end = KIRKWOOD_NAND_MEM_PHYS_BASE +
161 KIRKWOOD_NAND_MEM_SIZE - 1,
162};
163
164static struct orion_nand_data kirkwood_nand_data = {
165 .cle = 0,
166 .ale = 1,
167 .width = 8,
168};
169
170static struct platform_device kirkwood_nand_flash = {
171 .name = "orion_nand",
172 .id = -1,
173 .dev = {
174 .platform_data = &kirkwood_nand_data,
175 },
176 .resource = &kirkwood_nand_resource,
177 .num_resources = 1,
178};
179
180void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
181 int chip_delay)
182{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200183 kirkwood_clk_ctrl |= CGC_RUNIT;
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400184 kirkwood_nand_data.parts = parts;
185 kirkwood_nand_data.nr_parts = nr_parts;
186 kirkwood_nand_data.chip_delay = chip_delay;
187 platform_device_register(&kirkwood_nand_flash);
188}
189
Ben Dooks010937e2010-04-20 10:26:19 +0100190void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
191 int (*dev_ready)(struct mtd_info *))
192{
193 kirkwood_clk_ctrl |= CGC_RUNIT;
194 kirkwood_nand_data.parts = parts;
195 kirkwood_nand_data.nr_parts = nr_parts;
196 kirkwood_nand_data.dev_ready = dev_ready;
197 platform_device_register(&kirkwood_nand_flash);
198}
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400199
200/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200201 * SoC RTC
202 ****************************************************************************/
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500203static void __init kirkwood_rtc_init(void)
Saeed Bishara651c74c2008-06-22 22:45:06 +0200204{
Andrew Lunn47480582011-05-15 13:32:43 +0200205 orion_rtc_init(RTC_PHYS_BASE, IRQ_KIRKWOOD_RTC);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200206}
207
208
209/*****************************************************************************
210 * SATA
211 ****************************************************************************/
212static struct resource kirkwood_sata_resources[] = {
213 {
214 .name = "sata base",
215 .start = SATA_PHYS_BASE,
216 .end = SATA_PHYS_BASE + 0x5000 - 1,
217 .flags = IORESOURCE_MEM,
218 }, {
219 .name = "sata irq",
220 .start = IRQ_KIRKWOOD_SATA,
221 .end = IRQ_KIRKWOOD_SATA,
222 .flags = IORESOURCE_IRQ,
223 },
224};
225
226static struct platform_device kirkwood_sata = {
227 .name = "sata_mv",
228 .id = 0,
229 .dev = {
Andrew Lunn5c602552011-05-15 13:32:40 +0200230 .coherent_dma_mask = DMA_BIT_MASK(32),
Saeed Bishara651c74c2008-06-22 22:45:06 +0200231 },
232 .num_resources = ARRAY_SIZE(kirkwood_sata_resources),
233 .resource = kirkwood_sata_resources,
234};
235
236void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
237{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200238 kirkwood_clk_ctrl |= CGC_SATA0;
239 if (sata_data->n_ports > 1)
240 kirkwood_clk_ctrl |= CGC_SATA1;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200241 sata_data->dram = &kirkwood_mbus_dram_info;
242 kirkwood_sata.dev.platform_data = sata_data;
243 platform_device_register(&kirkwood_sata);
244}
245
246
247/*****************************************************************************
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500248 * SD/SDIO/MMC
249 ****************************************************************************/
250static struct resource mvsdio_resources[] = {
251 [0] = {
252 .start = SDIO_PHYS_BASE,
253 .end = SDIO_PHYS_BASE + SZ_1K - 1,
254 .flags = IORESOURCE_MEM,
255 },
256 [1] = {
257 .start = IRQ_KIRKWOOD_SDIO,
258 .end = IRQ_KIRKWOOD_SDIO,
259 .flags = IORESOURCE_IRQ,
260 },
261};
262
Andrew Lunn5c602552011-05-15 13:32:40 +0200263static u64 mvsdio_dmamask = DMA_BIT_MASK(32);
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500264
265static struct platform_device kirkwood_sdio = {
266 .name = "mvsdio",
267 .id = -1,
268 .dev = {
269 .dma_mask = &mvsdio_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200270 .coherent_dma_mask = DMA_BIT_MASK(32),
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500271 },
272 .num_resources = ARRAY_SIZE(mvsdio_resources),
273 .resource = mvsdio_resources,
274};
275
276void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
277{
278 u32 dev, rev;
279
280 kirkwood_pcie_id(&dev, &rev);
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300281 if (rev == 0 && dev != MV88F6282_DEV_ID) /* catch all Kirkwood Z0's */
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500282 mvsdio_data->clock = 100000000;
283 else
284 mvsdio_data->clock = 200000000;
285 mvsdio_data->dram = &kirkwood_mbus_dram_info;
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200286 kirkwood_clk_ctrl |= CGC_SDIO;
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500287 kirkwood_sdio.dev.platform_data = mvsdio_data;
288 platform_device_register(&kirkwood_sdio);
289}
290
291
292/*****************************************************************************
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200293 * SPI
294 ****************************************************************************/
295static struct orion_spi_info kirkwood_spi_plat_data = {
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200296};
297
298static struct resource kirkwood_spi_resources[] = {
299 {
300 .start = SPI_PHYS_BASE,
301 .end = SPI_PHYS_BASE + SZ_512 - 1,
302 .flags = IORESOURCE_MEM,
303 },
304};
305
306static struct platform_device kirkwood_spi = {
307 .name = "orion_spi",
308 .id = 0,
309 .resource = kirkwood_spi_resources,
310 .dev = {
311 .platform_data = &kirkwood_spi_plat_data,
312 },
313 .num_resources = ARRAY_SIZE(kirkwood_spi_resources),
314};
315
316void __init kirkwood_spi_init()
317{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200318 kirkwood_clk_ctrl |= CGC_RUNIT;
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200319 platform_device_register(&kirkwood_spi);
320}
321
322
323/*****************************************************************************
Martin Michlmayr6574e002009-03-23 19:13:21 +0100324 * I2C
325 ****************************************************************************/
Martin Michlmayr6574e002009-03-23 19:13:21 +0100326void __init kirkwood_i2c_init(void)
327{
Andrew Lunnaac7ffa2011-05-15 13:32:45 +0200328 orion_i2c_init(I2C_PHYS_BASE, IRQ_KIRKWOOD_TWSI, 8);
Martin Michlmayr6574e002009-03-23 19:13:21 +0100329}
330
331
332/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200333 * UART0
334 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200335
336void __init kirkwood_uart0_init(void)
337{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200338 orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
339 IRQ_KIRKWOOD_UART_0, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200340}
341
342
343/*****************************************************************************
344 * UART1
345 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200346void __init kirkwood_uart1_init(void)
347{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200348 orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
349 IRQ_KIRKWOOD_UART_1, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200350}
351
Saeed Bishara651c74c2008-06-22 22:45:06 +0200352/*****************************************************************************
Nicolas Pitreae5c8c82009-06-03 15:24:36 -0400353 * Cryptographic Engines and Security Accelerator (CESA)
354 ****************************************************************************/
355
356static struct resource kirkwood_crypto_res[] = {
357 {
358 .name = "regs",
359 .start = CRYPTO_PHYS_BASE,
360 .end = CRYPTO_PHYS_BASE + 0xffff,
361 .flags = IORESOURCE_MEM,
362 }, {
363 .name = "sram",
364 .start = KIRKWOOD_SRAM_PHYS_BASE,
365 .end = KIRKWOOD_SRAM_PHYS_BASE + KIRKWOOD_SRAM_SIZE - 1,
366 .flags = IORESOURCE_MEM,
367 }, {
368 .name = "crypto interrupt",
369 .start = IRQ_KIRKWOOD_CRYPTO,
370 .end = IRQ_KIRKWOOD_CRYPTO,
371 .flags = IORESOURCE_IRQ,
372 },
373};
374
375static struct platform_device kirkwood_crypto_device = {
376 .name = "mv_crypto",
377 .id = -1,
378 .num_resources = ARRAY_SIZE(kirkwood_crypto_res),
379 .resource = kirkwood_crypto_res,
380};
381
382void __init kirkwood_crypto_init(void)
383{
384 kirkwood_clk_ctrl |= CGC_CRYPTO;
385 platform_device_register(&kirkwood_crypto_device);
386}
387
388
389/*****************************************************************************
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100390 * XOR
391 ****************************************************************************/
392static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
393 .dram = &kirkwood_mbus_dram_info,
394};
395
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100396
397/*****************************************************************************
398 * XOR0
399 ****************************************************************************/
400static struct resource kirkwood_xor0_shared_resources[] = {
401 {
402 .name = "xor 0 low",
403 .start = XOR0_PHYS_BASE,
404 .end = XOR0_PHYS_BASE + 0xff,
405 .flags = IORESOURCE_MEM,
406 }, {
407 .name = "xor 0 high",
408 .start = XOR0_HIGH_PHYS_BASE,
409 .end = XOR0_HIGH_PHYS_BASE + 0xff,
410 .flags = IORESOURCE_MEM,
411 },
412};
413
414static struct platform_device kirkwood_xor0_shared = {
415 .name = MV_XOR_SHARED_NAME,
416 .id = 0,
417 .dev = {
418 .platform_data = &kirkwood_xor_shared_data,
419 },
420 .num_resources = ARRAY_SIZE(kirkwood_xor0_shared_resources),
421 .resource = kirkwood_xor0_shared_resources,
422};
423
Andrew Lunn5c602552011-05-15 13:32:40 +0200424static u64 kirkwood_xor_dmamask = DMA_BIT_MASK(32);
425
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100426static struct resource kirkwood_xor00_resources[] = {
427 [0] = {
428 .start = IRQ_KIRKWOOD_XOR_00,
429 .end = IRQ_KIRKWOOD_XOR_00,
430 .flags = IORESOURCE_IRQ,
431 },
432};
433
434static struct mv_xor_platform_data kirkwood_xor00_data = {
435 .shared = &kirkwood_xor0_shared,
436 .hw_id = 0,
437 .pool_size = PAGE_SIZE,
438};
439
440static struct platform_device kirkwood_xor00_channel = {
441 .name = MV_XOR_NAME,
442 .id = 0,
443 .num_resources = ARRAY_SIZE(kirkwood_xor00_resources),
444 .resource = kirkwood_xor00_resources,
445 .dev = {
446 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700447 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800448 .platform_data = &kirkwood_xor00_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100449 },
450};
451
452static struct resource kirkwood_xor01_resources[] = {
453 [0] = {
454 .start = IRQ_KIRKWOOD_XOR_01,
455 .end = IRQ_KIRKWOOD_XOR_01,
456 .flags = IORESOURCE_IRQ,
457 },
458};
459
460static struct mv_xor_platform_data kirkwood_xor01_data = {
461 .shared = &kirkwood_xor0_shared,
462 .hw_id = 1,
463 .pool_size = PAGE_SIZE,
464};
465
466static struct platform_device kirkwood_xor01_channel = {
467 .name = MV_XOR_NAME,
468 .id = 1,
469 .num_resources = ARRAY_SIZE(kirkwood_xor01_resources),
470 .resource = kirkwood_xor01_resources,
471 .dev = {
472 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700473 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800474 .platform_data = &kirkwood_xor01_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100475 },
476};
477
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500478static void __init kirkwood_xor0_init(void)
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100479{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200480 kirkwood_clk_ctrl |= CGC_XOR0;
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100481 platform_device_register(&kirkwood_xor0_shared);
482
483 /*
484 * two engines can't do memset simultaneously, this limitation
485 * satisfied by removing memset support from one of the engines.
486 */
487 dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
488 dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
489 platform_device_register(&kirkwood_xor00_channel);
490
491 dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
492 dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
493 dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
494 platform_device_register(&kirkwood_xor01_channel);
495}
496
497
498/*****************************************************************************
499 * XOR1
500 ****************************************************************************/
501static struct resource kirkwood_xor1_shared_resources[] = {
502 {
503 .name = "xor 1 low",
504 .start = XOR1_PHYS_BASE,
505 .end = XOR1_PHYS_BASE + 0xff,
506 .flags = IORESOURCE_MEM,
507 }, {
508 .name = "xor 1 high",
509 .start = XOR1_HIGH_PHYS_BASE,
510 .end = XOR1_HIGH_PHYS_BASE + 0xff,
511 .flags = IORESOURCE_MEM,
512 },
513};
514
515static struct platform_device kirkwood_xor1_shared = {
516 .name = MV_XOR_SHARED_NAME,
517 .id = 1,
518 .dev = {
519 .platform_data = &kirkwood_xor_shared_data,
520 },
521 .num_resources = ARRAY_SIZE(kirkwood_xor1_shared_resources),
522 .resource = kirkwood_xor1_shared_resources,
523};
524
525static struct resource kirkwood_xor10_resources[] = {
526 [0] = {
527 .start = IRQ_KIRKWOOD_XOR_10,
528 .end = IRQ_KIRKWOOD_XOR_10,
529 .flags = IORESOURCE_IRQ,
530 },
531};
532
533static struct mv_xor_platform_data kirkwood_xor10_data = {
534 .shared = &kirkwood_xor1_shared,
535 .hw_id = 0,
536 .pool_size = PAGE_SIZE,
537};
538
539static struct platform_device kirkwood_xor10_channel = {
540 .name = MV_XOR_NAME,
541 .id = 2,
542 .num_resources = ARRAY_SIZE(kirkwood_xor10_resources),
543 .resource = kirkwood_xor10_resources,
544 .dev = {
545 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700546 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800547 .platform_data = &kirkwood_xor10_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100548 },
549};
550
551static struct resource kirkwood_xor11_resources[] = {
552 [0] = {
553 .start = IRQ_KIRKWOOD_XOR_11,
554 .end = IRQ_KIRKWOOD_XOR_11,
555 .flags = IORESOURCE_IRQ,
556 },
557};
558
559static struct mv_xor_platform_data kirkwood_xor11_data = {
560 .shared = &kirkwood_xor1_shared,
561 .hw_id = 1,
562 .pool_size = PAGE_SIZE,
563};
564
565static struct platform_device kirkwood_xor11_channel = {
566 .name = MV_XOR_NAME,
567 .id = 3,
568 .num_resources = ARRAY_SIZE(kirkwood_xor11_resources),
569 .resource = kirkwood_xor11_resources,
570 .dev = {
571 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700572 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800573 .platform_data = &kirkwood_xor11_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100574 },
575};
576
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500577static void __init kirkwood_xor1_init(void)
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100578{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200579 kirkwood_clk_ctrl |= CGC_XOR1;
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100580 platform_device_register(&kirkwood_xor1_shared);
581
582 /*
583 * two engines can't do memset simultaneously, this limitation
584 * satisfied by removing memset support from one of the engines.
585 */
586 dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
587 dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
588 platform_device_register(&kirkwood_xor10_channel);
589
590 dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
591 dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
592 dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
593 platform_device_register(&kirkwood_xor11_channel);
594}
595
596
597/*****************************************************************************
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200598 * Watchdog
599 ****************************************************************************/
Nicolas Pitre3b937a72009-06-01 13:56:02 -0400600static struct orion_wdt_platform_data kirkwood_wdt_data = {
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200601 .tclk = 0,
602};
603
604static struct platform_device kirkwood_wdt_device = {
Nicolas Pitre3b937a72009-06-01 13:56:02 -0400605 .name = "orion_wdt",
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200606 .id = -1,
607 .dev = {
608 .platform_data = &kirkwood_wdt_data,
609 },
610 .num_resources = 0,
611};
612
613static void __init kirkwood_wdt_init(void)
614{
615 kirkwood_wdt_data.tclk = kirkwood_tclk;
616 platform_device_register(&kirkwood_wdt_device);
617}
618
619
620/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200621 * Time handling
622 ****************************************************************************/
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200623void __init kirkwood_init_early(void)
624{
625 orion_time_set_base(TIMER_VIRT_BASE);
626}
627
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200628int kirkwood_tclk;
629
Nicolas Pitre9b8ebfe2011-03-03 15:08:53 -0500630static int __init kirkwood_find_tclk(void)
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200631{
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300632 u32 dev, rev;
633
634 kirkwood_pcie_id(&dev, &rev);
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300635
Simon Guinot2fa0f932010-10-21 11:42:28 +0200636 if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
637 if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
638 return 200000000;
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300639
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200640 return 166666667;
641}
642
Li Jie6de95c12009-11-05 07:29:54 -0800643static void __init kirkwood_timer_init(void)
Saeed Bishara651c74c2008-06-22 22:45:06 +0200644{
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200645 kirkwood_tclk = kirkwood_find_tclk();
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200646
647 orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
648 IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200649}
650
651struct sys_timer kirkwood_timer = {
652 .init = kirkwood_timer_init,
653};
654
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200655/*****************************************************************************
656 * Audio
657 ****************************************************************************/
658static struct resource kirkwood_i2s_resources[] = {
659 [0] = {
660 .start = AUDIO_PHYS_BASE,
661 .end = AUDIO_PHYS_BASE + SZ_16K - 1,
662 .flags = IORESOURCE_MEM,
663 },
664 [1] = {
665 .start = IRQ_KIRKWOOD_I2S,
666 .end = IRQ_KIRKWOOD_I2S,
667 .flags = IORESOURCE_IRQ,
668 },
669};
670
671static struct kirkwood_asoc_platform_data kirkwood_i2s_data = {
672 .dram = &kirkwood_mbus_dram_info,
673 .burst = 128,
674};
675
676static struct platform_device kirkwood_i2s_device = {
677 .name = "kirkwood-i2s",
678 .id = -1,
679 .num_resources = ARRAY_SIZE(kirkwood_i2s_resources),
680 .resource = kirkwood_i2s_resources,
681 .dev = {
682 .platform_data = &kirkwood_i2s_data,
683 },
684};
685
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000686static struct platform_device kirkwood_pcm_device = {
Arnaud Patard (Rtp)c88e7b92010-08-30 16:00:05 +0200687 .name = "kirkwood-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000688 .id = -1,
689};
690
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200691void __init kirkwood_audio_init(void)
692{
693 kirkwood_clk_ctrl |= CGC_AUDIO;
694 platform_device_register(&kirkwood_i2s_device);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000695 platform_device_register(&kirkwood_pcm_device);
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200696}
Saeed Bishara651c74c2008-06-22 22:45:06 +0200697
698/*****************************************************************************
699 * General
700 ****************************************************************************/
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300701/*
702 * Identify device ID and revision.
703 */
Saeed Bishara651c74c2008-06-22 22:45:06 +0200704static char * __init kirkwood_id(void)
705{
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300706 u32 dev, rev;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200707
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300708 kirkwood_pcie_id(&dev, &rev);
709
710 if (dev == MV88F6281_DEV_ID) {
711 if (rev == MV88F6281_REV_Z0)
712 return "MV88F6281-Z0";
713 else if (rev == MV88F6281_REV_A0)
714 return "MV88F6281-A0";
Siddarth Goreaec1bad2009-06-09 14:41:02 +0530715 else if (rev == MV88F6281_REV_A1)
716 return "MV88F6281-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300717 else
718 return "MV88F6281-Rev-Unsupported";
719 } else if (dev == MV88F6192_DEV_ID) {
720 if (rev == MV88F6192_REV_Z0)
721 return "MV88F6192-Z0";
722 else if (rev == MV88F6192_REV_A0)
723 return "MV88F6192-A0";
Saeed Bishara1c2003a2010-06-01 18:09:26 +0300724 else if (rev == MV88F6192_REV_A1)
725 return "MV88F6192-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300726 else
727 return "MV88F6192-Rev-Unsupported";
728 } else if (dev == MV88F6180_DEV_ID) {
729 if (rev == MV88F6180_REV_A0)
730 return "MV88F6180-Rev-A0";
Saeed Bishara1c2003a2010-06-01 18:09:26 +0300731 else if (rev == MV88F6180_REV_A1)
732 return "MV88F6180-Rev-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300733 else
734 return "MV88F6180-Rev-Unsupported";
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300735 } else if (dev == MV88F6282_DEV_ID) {
736 if (rev == MV88F6282_REV_A0)
737 return "MV88F6282-Rev-A0";
738 else
739 return "MV88F6282-Rev-Unsupported";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300740 } else {
741 return "Device-Unknown";
742 }
Saeed Bishara651c74c2008-06-22 22:45:06 +0200743}
744
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300745static void __init kirkwood_l2_init(void)
Saeed Bishara13387602008-06-23 01:05:08 -1100746{
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300747#ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
748 writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
749 feroceon_l2_init(1);
750#else
751 writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
752 feroceon_l2_init(0);
753#endif
Saeed Bishara13387602008-06-23 01:05:08 -1100754}
755
Saeed Bishara651c74c2008-06-22 22:45:06 +0200756void __init kirkwood_init(void)
757{
758 printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200759 kirkwood_id(), kirkwood_tclk);
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200760 kirkwood_spi_plat_data.tclk = kirkwood_tclk;
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200761 kirkwood_i2s_data.tclk = kirkwood_tclk;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200762
Lennert Buytenhek2bf30102009-11-12 20:31:14 +0100763 /*
764 * Disable propagation of mbus errors to the CPU local bus,
765 * as this causes mbus errors (which can occur for example
766 * for PCI aborts) to throw CPU aborts, which we're not set
767 * up to deal with.
768 */
769 writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
770
Saeed Bishara651c74c2008-06-22 22:45:06 +0200771 kirkwood_setup_cpu_mbus();
772
773#ifdef CONFIG_CACHE_FEROCEON_L2
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300774 kirkwood_l2_init();
Saeed Bishara651c74c2008-06-22 22:45:06 +0200775#endif
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500776
777 /* internal devices that every board has */
778 kirkwood_rtc_init();
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200779 kirkwood_wdt_init();
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500780 kirkwood_xor0_init();
781 kirkwood_xor1_init();
Nicolas Pitreae5c8c82009-06-03 15:24:36 -0400782 kirkwood_crypto_init();
Eric Cooper9c153642011-02-02 17:16:11 -0500783
784#ifdef CONFIG_KEXEC
785 kexec_reinit = kirkwood_enable_pcie;
786#endif
Saeed Bishara651c74c2008-06-22 22:45:06 +0200787}
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200788
789static int __init kirkwood_clock_gate(void)
790{
791 unsigned int curr = readl(CLOCK_GATING_CTRL);
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300792 u32 dev, rev;
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200793
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300794 kirkwood_pcie_id(&dev, &rev);
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200795 printk(KERN_DEBUG "Gating clock of unused units\n");
796 printk(KERN_DEBUG "before: 0x%08x\n", curr);
797
798 /* Make sure those units are accessible */
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300799 writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL);
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200800
801 /* For SATA: first shutdown the phy */
802 if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
803 /* Disable PLL and IVREF */
804 writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
805 /* Disable PHY */
806 writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
807 }
808 if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
809 /* Disable PLL and IVREF */
810 writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
811 /* Disable PHY */
812 writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
813 }
814
815 /* For PCIe: first shutdown the phy */
816 if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
817 writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
818 while (1)
819 if (readl(PCIE_STATUS) & 0x1)
820 break;
821 writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
822 }
823
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300824 /* For PCIe 1: first shutdown the phy */
825 if (dev == MV88F6282_DEV_ID) {
826 if (!(kirkwood_clk_ctrl & CGC_PEX1)) {
827 writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
828 while (1)
829 if (readl(PCIE1_STATUS) & 0x1)
830 break;
831 writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
832 }
833 } else /* keep this bit set for devices that don't have PCIe1 */
834 kirkwood_clk_ctrl |= CGC_PEX1;
835
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200836 /* Now gate clock the required units */
837 writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
838 printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
839
840 return 0;
841}
842late_initcall(kirkwood_clock_gate);