blob: af864fc7883b656fa6a3db59e99bd5ab19fabb31 [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 Buytenhekdcf1cec2008-09-25 16:23:48 +020018#include <net/dsa.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020019#include <asm/page.h>
20#include <asm/timex.h>
Eric Cooper9c153642011-02-02 17:16:11 -050021#include <asm/kexec.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020022#include <asm/mach/map.h>
23#include <asm/mach/time.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/kirkwood.h>
Nicolas Pitrefdd8b072009-04-22 20:08:17 +010025#include <mach/bridge-regs.h>
apatard@mandriva.com49106c72010-05-31 13:49:12 +020026#include <plat/audio.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020027#include <plat/cache-feroceon-l2.h>
28#include <plat/ehci-orion.h>
Nicolas Pitre8235ee02009-02-14 03:15:55 -050029#include <plat/mvsdio.h>
Saeed Bishara09c0ed22008-06-23 04:26:07 -110030#include <plat/mv_xor.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020031#include <plat/orion_nand.h>
Nicolas Pitre3b937a72009-06-01 13:56:02 -040032#include <plat/orion_wdt.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020033#include <plat/common.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020034#include <plat/time.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020035#include "common.h"
36
37/*****************************************************************************
38 * I/O Address Mapping
39 ****************************************************************************/
40static struct map_desc kirkwood_io_desc[] __initdata = {
41 {
42 .virtual = KIRKWOOD_PCIE_IO_VIRT_BASE,
43 .pfn = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
44 .length = KIRKWOOD_PCIE_IO_SIZE,
45 .type = MT_DEVICE,
46 }, {
Saeed Bisharaffd58bd2010-06-08 14:21:34 +030047 .virtual = KIRKWOOD_PCIE1_IO_VIRT_BASE,
48 .pfn = __phys_to_pfn(KIRKWOOD_PCIE1_IO_PHYS_BASE),
49 .length = KIRKWOOD_PCIE1_IO_SIZE,
50 .type = MT_DEVICE,
51 }, {
Saeed Bishara651c74c2008-06-22 22:45:06 +020052 .virtual = KIRKWOOD_REGS_VIRT_BASE,
53 .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
54 .length = KIRKWOOD_REGS_SIZE,
55 .type = MT_DEVICE,
56 },
57};
58
59void __init kirkwood_map_io(void)
60{
61 iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
62}
63
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +020064/*
65 * Default clock control bits. Any bit _not_ set in this variable
66 * will be cleared from the hardware after platform devices have been
67 * registered. Some reserved bits must be set to 1.
68 */
69unsigned int kirkwood_clk_ctrl = CGC_DUNIT | CGC_RESERVED;
Andrew Lunn7e3819d2011-05-15 13:32:44 +020070
Saeed Bishara651c74c2008-06-22 22:45:06 +020071
72/*****************************************************************************
73 * EHCI
74 ****************************************************************************/
75static struct orion_ehci_data kirkwood_ehci_data = {
76 .dram = &kirkwood_mbus_dram_info,
Ronen Shitritfb6f5522008-09-17 10:08:05 +030077 .phy_version = EHCI_PHY_NA,
Saeed Bishara651c74c2008-06-22 22:45:06 +020078};
79
Andrew Lunn5c602552011-05-15 13:32:40 +020080static u64 ehci_dmamask = DMA_BIT_MASK(32);
Saeed Bishara651c74c2008-06-22 22:45:06 +020081
82
83/*****************************************************************************
84 * EHCI0
85 ****************************************************************************/
86static struct resource kirkwood_ehci_resources[] = {
87 {
88 .start = USB_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +020089 .end = USB_PHYS_BASE + SZ_4K - 1,
Saeed Bishara651c74c2008-06-22 22:45:06 +020090 .flags = IORESOURCE_MEM,
91 }, {
92 .start = IRQ_KIRKWOOD_USB,
93 .end = IRQ_KIRKWOOD_USB,
94 .flags = IORESOURCE_IRQ,
95 },
96};
97
98static struct platform_device kirkwood_ehci = {
99 .name = "orion-ehci",
100 .id = 0,
101 .dev = {
102 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200103 .coherent_dma_mask = DMA_BIT_MASK(32),
Saeed Bishara651c74c2008-06-22 22:45:06 +0200104 .platform_data = &kirkwood_ehci_data,
105 },
106 .resource = kirkwood_ehci_resources,
107 .num_resources = ARRAY_SIZE(kirkwood_ehci_resources),
108};
109
110void __init kirkwood_ehci_init(void)
111{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200112 kirkwood_clk_ctrl |= CGC_USB0;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200113 platform_device_register(&kirkwood_ehci);
114}
115
116
117/*****************************************************************************
118 * GE00
119 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200120void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
121{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200122 kirkwood_clk_ctrl |= CGC_GE0;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200123
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200124 orion_ge00_init(eth_data, &kirkwood_mbus_dram_info,
125 GE00_PHYS_BASE, IRQ_KIRKWOOD_GE00_SUM,
126 IRQ_KIRKWOOD_GE00_ERR, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200127}
128
129
130/*****************************************************************************
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200131 * GE01
132 ****************************************************************************/
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200133void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data)
134{
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200135
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200136 kirkwood_clk_ctrl |= CGC_GE1;
137
138 orion_ge01_init(eth_data, &kirkwood_mbus_dram_info,
139 GE01_PHYS_BASE, IRQ_KIRKWOOD_GE01_SUM,
140 IRQ_KIRKWOOD_GE01_ERR, kirkwood_tclk);
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200141}
142
143
144/*****************************************************************************
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200145 * Ethernet switch
146 ****************************************************************************/
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200147void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
148{
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200149 orion_ge00_switch_init(d, irq);
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200150}
151
152
153/*****************************************************************************
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400154 * NAND flash
155 ****************************************************************************/
156static struct resource kirkwood_nand_resource = {
157 .flags = IORESOURCE_MEM,
158 .start = KIRKWOOD_NAND_MEM_PHYS_BASE,
159 .end = KIRKWOOD_NAND_MEM_PHYS_BASE +
160 KIRKWOOD_NAND_MEM_SIZE - 1,
161};
162
163static struct orion_nand_data kirkwood_nand_data = {
164 .cle = 0,
165 .ale = 1,
166 .width = 8,
167};
168
169static struct platform_device kirkwood_nand_flash = {
170 .name = "orion_nand",
171 .id = -1,
172 .dev = {
173 .platform_data = &kirkwood_nand_data,
174 },
175 .resource = &kirkwood_nand_resource,
176 .num_resources = 1,
177};
178
179void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
180 int chip_delay)
181{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200182 kirkwood_clk_ctrl |= CGC_RUNIT;
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400183 kirkwood_nand_data.parts = parts;
184 kirkwood_nand_data.nr_parts = nr_parts;
185 kirkwood_nand_data.chip_delay = chip_delay;
186 platform_device_register(&kirkwood_nand_flash);
187}
188
Ben Dooks010937e2010-04-20 10:26:19 +0100189void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
190 int (*dev_ready)(struct mtd_info *))
191{
192 kirkwood_clk_ctrl |= CGC_RUNIT;
193 kirkwood_nand_data.parts = parts;
194 kirkwood_nand_data.nr_parts = nr_parts;
195 kirkwood_nand_data.dev_ready = dev_ready;
196 platform_device_register(&kirkwood_nand_flash);
197}
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400198
199/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200200 * SoC RTC
201 ****************************************************************************/
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500202static void __init kirkwood_rtc_init(void)
Saeed Bishara651c74c2008-06-22 22:45:06 +0200203{
Andrew Lunn47480582011-05-15 13:32:43 +0200204 orion_rtc_init(RTC_PHYS_BASE, IRQ_KIRKWOOD_RTC);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200205}
206
207
208/*****************************************************************************
209 * SATA
210 ****************************************************************************/
211static struct resource kirkwood_sata_resources[] = {
212 {
213 .name = "sata base",
214 .start = SATA_PHYS_BASE,
215 .end = SATA_PHYS_BASE + 0x5000 - 1,
216 .flags = IORESOURCE_MEM,
217 }, {
218 .name = "sata irq",
219 .start = IRQ_KIRKWOOD_SATA,
220 .end = IRQ_KIRKWOOD_SATA,
221 .flags = IORESOURCE_IRQ,
222 },
223};
224
225static struct platform_device kirkwood_sata = {
226 .name = "sata_mv",
227 .id = 0,
228 .dev = {
Andrew Lunn5c602552011-05-15 13:32:40 +0200229 .coherent_dma_mask = DMA_BIT_MASK(32),
Saeed Bishara651c74c2008-06-22 22:45:06 +0200230 },
231 .num_resources = ARRAY_SIZE(kirkwood_sata_resources),
232 .resource = kirkwood_sata_resources,
233};
234
235void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
236{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200237 kirkwood_clk_ctrl |= CGC_SATA0;
238 if (sata_data->n_ports > 1)
239 kirkwood_clk_ctrl |= CGC_SATA1;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200240 sata_data->dram = &kirkwood_mbus_dram_info;
241 kirkwood_sata.dev.platform_data = sata_data;
242 platform_device_register(&kirkwood_sata);
243}
244
245
246/*****************************************************************************
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500247 * SD/SDIO/MMC
248 ****************************************************************************/
249static struct resource mvsdio_resources[] = {
250 [0] = {
251 .start = SDIO_PHYS_BASE,
252 .end = SDIO_PHYS_BASE + SZ_1K - 1,
253 .flags = IORESOURCE_MEM,
254 },
255 [1] = {
256 .start = IRQ_KIRKWOOD_SDIO,
257 .end = IRQ_KIRKWOOD_SDIO,
258 .flags = IORESOURCE_IRQ,
259 },
260};
261
Andrew Lunn5c602552011-05-15 13:32:40 +0200262static u64 mvsdio_dmamask = DMA_BIT_MASK(32);
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500263
264static struct platform_device kirkwood_sdio = {
265 .name = "mvsdio",
266 .id = -1,
267 .dev = {
268 .dma_mask = &mvsdio_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200269 .coherent_dma_mask = DMA_BIT_MASK(32),
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500270 },
271 .num_resources = ARRAY_SIZE(mvsdio_resources),
272 .resource = mvsdio_resources,
273};
274
275void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
276{
277 u32 dev, rev;
278
279 kirkwood_pcie_id(&dev, &rev);
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300280 if (rev == 0 && dev != MV88F6282_DEV_ID) /* catch all Kirkwood Z0's */
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500281 mvsdio_data->clock = 100000000;
282 else
283 mvsdio_data->clock = 200000000;
284 mvsdio_data->dram = &kirkwood_mbus_dram_info;
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200285 kirkwood_clk_ctrl |= CGC_SDIO;
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500286 kirkwood_sdio.dev.platform_data = mvsdio_data;
287 platform_device_register(&kirkwood_sdio);
288}
289
290
291/*****************************************************************************
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200292 * SPI
293 ****************************************************************************/
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200294void __init kirkwood_spi_init()
295{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200296 kirkwood_clk_ctrl |= CGC_RUNIT;
Andrew Lunn980f9f62011-05-15 13:32:46 +0200297 orion_spi_init(SPI_PHYS_BASE, kirkwood_tclk);
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200298}
299
300
301/*****************************************************************************
Martin Michlmayr6574e002009-03-23 19:13:21 +0100302 * I2C
303 ****************************************************************************/
Martin Michlmayr6574e002009-03-23 19:13:21 +0100304void __init kirkwood_i2c_init(void)
305{
Andrew Lunnaac7ffa2011-05-15 13:32:45 +0200306 orion_i2c_init(I2C_PHYS_BASE, IRQ_KIRKWOOD_TWSI, 8);
Martin Michlmayr6574e002009-03-23 19:13:21 +0100307}
308
309
310/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200311 * UART0
312 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200313
314void __init kirkwood_uart0_init(void)
315{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200316 orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
317 IRQ_KIRKWOOD_UART_0, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200318}
319
320
321/*****************************************************************************
322 * UART1
323 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200324void __init kirkwood_uart1_init(void)
325{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200326 orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
327 IRQ_KIRKWOOD_UART_1, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200328}
329
Saeed Bishara651c74c2008-06-22 22:45:06 +0200330/*****************************************************************************
Nicolas Pitreae5c8c82009-06-03 15:24:36 -0400331 * Cryptographic Engines and Security Accelerator (CESA)
332 ****************************************************************************/
333
334static struct resource kirkwood_crypto_res[] = {
335 {
336 .name = "regs",
337 .start = CRYPTO_PHYS_BASE,
338 .end = CRYPTO_PHYS_BASE + 0xffff,
339 .flags = IORESOURCE_MEM,
340 }, {
341 .name = "sram",
342 .start = KIRKWOOD_SRAM_PHYS_BASE,
343 .end = KIRKWOOD_SRAM_PHYS_BASE + KIRKWOOD_SRAM_SIZE - 1,
344 .flags = IORESOURCE_MEM,
345 }, {
346 .name = "crypto interrupt",
347 .start = IRQ_KIRKWOOD_CRYPTO,
348 .end = IRQ_KIRKWOOD_CRYPTO,
349 .flags = IORESOURCE_IRQ,
350 },
351};
352
353static struct platform_device kirkwood_crypto_device = {
354 .name = "mv_crypto",
355 .id = -1,
356 .num_resources = ARRAY_SIZE(kirkwood_crypto_res),
357 .resource = kirkwood_crypto_res,
358};
359
360void __init kirkwood_crypto_init(void)
361{
362 kirkwood_clk_ctrl |= CGC_CRYPTO;
363 platform_device_register(&kirkwood_crypto_device);
364}
365
366
367/*****************************************************************************
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100368 * XOR
369 ****************************************************************************/
370static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
371 .dram = &kirkwood_mbus_dram_info,
372};
373
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100374
375/*****************************************************************************
376 * XOR0
377 ****************************************************************************/
378static struct resource kirkwood_xor0_shared_resources[] = {
379 {
380 .name = "xor 0 low",
381 .start = XOR0_PHYS_BASE,
382 .end = XOR0_PHYS_BASE + 0xff,
383 .flags = IORESOURCE_MEM,
384 }, {
385 .name = "xor 0 high",
386 .start = XOR0_HIGH_PHYS_BASE,
387 .end = XOR0_HIGH_PHYS_BASE + 0xff,
388 .flags = IORESOURCE_MEM,
389 },
390};
391
392static struct platform_device kirkwood_xor0_shared = {
393 .name = MV_XOR_SHARED_NAME,
394 .id = 0,
395 .dev = {
396 .platform_data = &kirkwood_xor_shared_data,
397 },
398 .num_resources = ARRAY_SIZE(kirkwood_xor0_shared_resources),
399 .resource = kirkwood_xor0_shared_resources,
400};
401
Andrew Lunn5c602552011-05-15 13:32:40 +0200402static u64 kirkwood_xor_dmamask = DMA_BIT_MASK(32);
403
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100404static struct resource kirkwood_xor00_resources[] = {
405 [0] = {
406 .start = IRQ_KIRKWOOD_XOR_00,
407 .end = IRQ_KIRKWOOD_XOR_00,
408 .flags = IORESOURCE_IRQ,
409 },
410};
411
412static struct mv_xor_platform_data kirkwood_xor00_data = {
413 .shared = &kirkwood_xor0_shared,
414 .hw_id = 0,
415 .pool_size = PAGE_SIZE,
416};
417
418static struct platform_device kirkwood_xor00_channel = {
419 .name = MV_XOR_NAME,
420 .id = 0,
421 .num_resources = ARRAY_SIZE(kirkwood_xor00_resources),
422 .resource = kirkwood_xor00_resources,
423 .dev = {
424 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700425 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800426 .platform_data = &kirkwood_xor00_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100427 },
428};
429
430static struct resource kirkwood_xor01_resources[] = {
431 [0] = {
432 .start = IRQ_KIRKWOOD_XOR_01,
433 .end = IRQ_KIRKWOOD_XOR_01,
434 .flags = IORESOURCE_IRQ,
435 },
436};
437
438static struct mv_xor_platform_data kirkwood_xor01_data = {
439 .shared = &kirkwood_xor0_shared,
440 .hw_id = 1,
441 .pool_size = PAGE_SIZE,
442};
443
444static struct platform_device kirkwood_xor01_channel = {
445 .name = MV_XOR_NAME,
446 .id = 1,
447 .num_resources = ARRAY_SIZE(kirkwood_xor01_resources),
448 .resource = kirkwood_xor01_resources,
449 .dev = {
450 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700451 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800452 .platform_data = &kirkwood_xor01_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100453 },
454};
455
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500456static void __init kirkwood_xor0_init(void)
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100457{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200458 kirkwood_clk_ctrl |= CGC_XOR0;
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100459 platform_device_register(&kirkwood_xor0_shared);
460
461 /*
462 * two engines can't do memset simultaneously, this limitation
463 * satisfied by removing memset support from one of the engines.
464 */
465 dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
466 dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
467 platform_device_register(&kirkwood_xor00_channel);
468
469 dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
470 dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
471 dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
472 platform_device_register(&kirkwood_xor01_channel);
473}
474
475
476/*****************************************************************************
477 * XOR1
478 ****************************************************************************/
479static struct resource kirkwood_xor1_shared_resources[] = {
480 {
481 .name = "xor 1 low",
482 .start = XOR1_PHYS_BASE,
483 .end = XOR1_PHYS_BASE + 0xff,
484 .flags = IORESOURCE_MEM,
485 }, {
486 .name = "xor 1 high",
487 .start = XOR1_HIGH_PHYS_BASE,
488 .end = XOR1_HIGH_PHYS_BASE + 0xff,
489 .flags = IORESOURCE_MEM,
490 },
491};
492
493static struct platform_device kirkwood_xor1_shared = {
494 .name = MV_XOR_SHARED_NAME,
495 .id = 1,
496 .dev = {
497 .platform_data = &kirkwood_xor_shared_data,
498 },
499 .num_resources = ARRAY_SIZE(kirkwood_xor1_shared_resources),
500 .resource = kirkwood_xor1_shared_resources,
501};
502
503static struct resource kirkwood_xor10_resources[] = {
504 [0] = {
505 .start = IRQ_KIRKWOOD_XOR_10,
506 .end = IRQ_KIRKWOOD_XOR_10,
507 .flags = IORESOURCE_IRQ,
508 },
509};
510
511static struct mv_xor_platform_data kirkwood_xor10_data = {
512 .shared = &kirkwood_xor1_shared,
513 .hw_id = 0,
514 .pool_size = PAGE_SIZE,
515};
516
517static struct platform_device kirkwood_xor10_channel = {
518 .name = MV_XOR_NAME,
519 .id = 2,
520 .num_resources = ARRAY_SIZE(kirkwood_xor10_resources),
521 .resource = kirkwood_xor10_resources,
522 .dev = {
523 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700524 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800525 .platform_data = &kirkwood_xor10_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100526 },
527};
528
529static struct resource kirkwood_xor11_resources[] = {
530 [0] = {
531 .start = IRQ_KIRKWOOD_XOR_11,
532 .end = IRQ_KIRKWOOD_XOR_11,
533 .flags = IORESOURCE_IRQ,
534 },
535};
536
537static struct mv_xor_platform_data kirkwood_xor11_data = {
538 .shared = &kirkwood_xor1_shared,
539 .hw_id = 1,
540 .pool_size = PAGE_SIZE,
541};
542
543static struct platform_device kirkwood_xor11_channel = {
544 .name = MV_XOR_NAME,
545 .id = 3,
546 .num_resources = ARRAY_SIZE(kirkwood_xor11_resources),
547 .resource = kirkwood_xor11_resources,
548 .dev = {
549 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700550 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800551 .platform_data = &kirkwood_xor11_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100552 },
553};
554
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500555static void __init kirkwood_xor1_init(void)
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100556{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200557 kirkwood_clk_ctrl |= CGC_XOR1;
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100558 platform_device_register(&kirkwood_xor1_shared);
559
560 /*
561 * two engines can't do memset simultaneously, this limitation
562 * satisfied by removing memset support from one of the engines.
563 */
564 dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
565 dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
566 platform_device_register(&kirkwood_xor10_channel);
567
568 dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
569 dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
570 dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
571 platform_device_register(&kirkwood_xor11_channel);
572}
573
574
575/*****************************************************************************
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200576 * Watchdog
577 ****************************************************************************/
Nicolas Pitre3b937a72009-06-01 13:56:02 -0400578static struct orion_wdt_platform_data kirkwood_wdt_data = {
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200579 .tclk = 0,
580};
581
582static struct platform_device kirkwood_wdt_device = {
Nicolas Pitre3b937a72009-06-01 13:56:02 -0400583 .name = "orion_wdt",
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200584 .id = -1,
585 .dev = {
586 .platform_data = &kirkwood_wdt_data,
587 },
588 .num_resources = 0,
589};
590
591static void __init kirkwood_wdt_init(void)
592{
593 kirkwood_wdt_data.tclk = kirkwood_tclk;
594 platform_device_register(&kirkwood_wdt_device);
595}
596
597
598/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200599 * Time handling
600 ****************************************************************************/
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200601void __init kirkwood_init_early(void)
602{
603 orion_time_set_base(TIMER_VIRT_BASE);
604}
605
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200606int kirkwood_tclk;
607
Nicolas Pitre9b8ebfe2011-03-03 15:08:53 -0500608static int __init kirkwood_find_tclk(void)
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200609{
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300610 u32 dev, rev;
611
612 kirkwood_pcie_id(&dev, &rev);
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300613
Simon Guinot2fa0f932010-10-21 11:42:28 +0200614 if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
615 if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
616 return 200000000;
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300617
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200618 return 166666667;
619}
620
Li Jie6de95c12009-11-05 07:29:54 -0800621static void __init kirkwood_timer_init(void)
Saeed Bishara651c74c2008-06-22 22:45:06 +0200622{
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200623 kirkwood_tclk = kirkwood_find_tclk();
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200624
625 orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
626 IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200627}
628
629struct sys_timer kirkwood_timer = {
630 .init = kirkwood_timer_init,
631};
632
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200633/*****************************************************************************
634 * Audio
635 ****************************************************************************/
636static struct resource kirkwood_i2s_resources[] = {
637 [0] = {
638 .start = AUDIO_PHYS_BASE,
639 .end = AUDIO_PHYS_BASE + SZ_16K - 1,
640 .flags = IORESOURCE_MEM,
641 },
642 [1] = {
643 .start = IRQ_KIRKWOOD_I2S,
644 .end = IRQ_KIRKWOOD_I2S,
645 .flags = IORESOURCE_IRQ,
646 },
647};
648
649static struct kirkwood_asoc_platform_data kirkwood_i2s_data = {
650 .dram = &kirkwood_mbus_dram_info,
651 .burst = 128,
652};
653
654static struct platform_device kirkwood_i2s_device = {
655 .name = "kirkwood-i2s",
656 .id = -1,
657 .num_resources = ARRAY_SIZE(kirkwood_i2s_resources),
658 .resource = kirkwood_i2s_resources,
659 .dev = {
660 .platform_data = &kirkwood_i2s_data,
661 },
662};
663
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000664static struct platform_device kirkwood_pcm_device = {
Arnaud Patard (Rtp)c88e7b92010-08-30 16:00:05 +0200665 .name = "kirkwood-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000666 .id = -1,
667};
668
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200669void __init kirkwood_audio_init(void)
670{
671 kirkwood_clk_ctrl |= CGC_AUDIO;
672 platform_device_register(&kirkwood_i2s_device);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000673 platform_device_register(&kirkwood_pcm_device);
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200674}
Saeed Bishara651c74c2008-06-22 22:45:06 +0200675
676/*****************************************************************************
677 * General
678 ****************************************************************************/
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300679/*
680 * Identify device ID and revision.
681 */
Saeed Bishara651c74c2008-06-22 22:45:06 +0200682static char * __init kirkwood_id(void)
683{
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300684 u32 dev, rev;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200685
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300686 kirkwood_pcie_id(&dev, &rev);
687
688 if (dev == MV88F6281_DEV_ID) {
689 if (rev == MV88F6281_REV_Z0)
690 return "MV88F6281-Z0";
691 else if (rev == MV88F6281_REV_A0)
692 return "MV88F6281-A0";
Siddarth Goreaec1bad2009-06-09 14:41:02 +0530693 else if (rev == MV88F6281_REV_A1)
694 return "MV88F6281-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300695 else
696 return "MV88F6281-Rev-Unsupported";
697 } else if (dev == MV88F6192_DEV_ID) {
698 if (rev == MV88F6192_REV_Z0)
699 return "MV88F6192-Z0";
700 else if (rev == MV88F6192_REV_A0)
701 return "MV88F6192-A0";
Saeed Bishara1c2003a2010-06-01 18:09:26 +0300702 else if (rev == MV88F6192_REV_A1)
703 return "MV88F6192-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300704 else
705 return "MV88F6192-Rev-Unsupported";
706 } else if (dev == MV88F6180_DEV_ID) {
707 if (rev == MV88F6180_REV_A0)
708 return "MV88F6180-Rev-A0";
Saeed Bishara1c2003a2010-06-01 18:09:26 +0300709 else if (rev == MV88F6180_REV_A1)
710 return "MV88F6180-Rev-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300711 else
712 return "MV88F6180-Rev-Unsupported";
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300713 } else if (dev == MV88F6282_DEV_ID) {
714 if (rev == MV88F6282_REV_A0)
715 return "MV88F6282-Rev-A0";
716 else
717 return "MV88F6282-Rev-Unsupported";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300718 } else {
719 return "Device-Unknown";
720 }
Saeed Bishara651c74c2008-06-22 22:45:06 +0200721}
722
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300723static void __init kirkwood_l2_init(void)
Saeed Bishara13387602008-06-23 01:05:08 -1100724{
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300725#ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
726 writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
727 feroceon_l2_init(1);
728#else
729 writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
730 feroceon_l2_init(0);
731#endif
Saeed Bishara13387602008-06-23 01:05:08 -1100732}
733
Saeed Bishara651c74c2008-06-22 22:45:06 +0200734void __init kirkwood_init(void)
735{
736 printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200737 kirkwood_id(), kirkwood_tclk);
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200738 kirkwood_i2s_data.tclk = kirkwood_tclk;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200739
Lennert Buytenhek2bf30102009-11-12 20:31:14 +0100740 /*
741 * Disable propagation of mbus errors to the CPU local bus,
742 * as this causes mbus errors (which can occur for example
743 * for PCI aborts) to throw CPU aborts, which we're not set
744 * up to deal with.
745 */
746 writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
747
Saeed Bishara651c74c2008-06-22 22:45:06 +0200748 kirkwood_setup_cpu_mbus();
749
750#ifdef CONFIG_CACHE_FEROCEON_L2
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300751 kirkwood_l2_init();
Saeed Bishara651c74c2008-06-22 22:45:06 +0200752#endif
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500753
754 /* internal devices that every board has */
755 kirkwood_rtc_init();
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200756 kirkwood_wdt_init();
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500757 kirkwood_xor0_init();
758 kirkwood_xor1_init();
Nicolas Pitreae5c8c82009-06-03 15:24:36 -0400759 kirkwood_crypto_init();
Eric Cooper9c153642011-02-02 17:16:11 -0500760
761#ifdef CONFIG_KEXEC
762 kexec_reinit = kirkwood_enable_pcie;
763#endif
Saeed Bishara651c74c2008-06-22 22:45:06 +0200764}
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200765
766static int __init kirkwood_clock_gate(void)
767{
768 unsigned int curr = readl(CLOCK_GATING_CTRL);
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300769 u32 dev, rev;
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200770
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300771 kirkwood_pcie_id(&dev, &rev);
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200772 printk(KERN_DEBUG "Gating clock of unused units\n");
773 printk(KERN_DEBUG "before: 0x%08x\n", curr);
774
775 /* Make sure those units are accessible */
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300776 writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL);
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200777
778 /* For SATA: first shutdown the phy */
779 if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
780 /* Disable PLL and IVREF */
781 writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
782 /* Disable PHY */
783 writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
784 }
785 if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
786 /* Disable PLL and IVREF */
787 writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
788 /* Disable PHY */
789 writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
790 }
791
792 /* For PCIe: first shutdown the phy */
793 if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
794 writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
795 while (1)
796 if (readl(PCIE_STATUS) & 0x1)
797 break;
798 writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
799 }
800
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300801 /* For PCIe 1: first shutdown the phy */
802 if (dev == MV88F6282_DEV_ID) {
803 if (!(kirkwood_clk_ctrl & CGC_PEX1)) {
804 writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
805 while (1)
806 if (readl(PCIE1_STATUS) & 0x1)
807 break;
808 writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
809 }
810 } else /* keep this bit set for devices that don't have PCIe1 */
811 kirkwood_clk_ctrl |= CGC_PEX1;
812
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200813 /* Now gate clock the required units */
814 writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
815 printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
816
817 return 0;
818}
819late_initcall(kirkwood_clock_gate);