blob: 08847a6f7d10ec9641ff380da12b27c630326650 [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>
Andrew Lunn28a2b452011-05-15 13:32:41 +020032#include <plat/common.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020033#include <plat/time.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020034#include "common.h"
35
36/*****************************************************************************
37 * I/O Address Mapping
38 ****************************************************************************/
39static struct map_desc kirkwood_io_desc[] __initdata = {
40 {
41 .virtual = KIRKWOOD_PCIE_IO_VIRT_BASE,
42 .pfn = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
43 .length = KIRKWOOD_PCIE_IO_SIZE,
44 .type = MT_DEVICE,
45 }, {
Saeed Bisharaffd58bd2010-06-08 14:21:34 +030046 .virtual = KIRKWOOD_PCIE1_IO_VIRT_BASE,
47 .pfn = __phys_to_pfn(KIRKWOOD_PCIE1_IO_PHYS_BASE),
48 .length = KIRKWOOD_PCIE1_IO_SIZE,
49 .type = MT_DEVICE,
50 }, {
Saeed Bishara651c74c2008-06-22 22:45:06 +020051 .virtual = KIRKWOOD_REGS_VIRT_BASE,
52 .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
53 .length = KIRKWOOD_REGS_SIZE,
54 .type = MT_DEVICE,
55 },
56};
57
58void __init kirkwood_map_io(void)
59{
60 iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
61}
62
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +020063/*
64 * Default clock control bits. Any bit _not_ set in this variable
65 * will be cleared from the hardware after platform devices have been
66 * registered. Some reserved bits must be set to 1.
67 */
68unsigned int kirkwood_clk_ctrl = CGC_DUNIT | CGC_RESERVED;
Andrew Lunn7e3819d2011-05-15 13:32:44 +020069
Saeed Bishara651c74c2008-06-22 22:45:06 +020070
71/*****************************************************************************
72 * EHCI
73 ****************************************************************************/
74static struct orion_ehci_data kirkwood_ehci_data = {
75 .dram = &kirkwood_mbus_dram_info,
Ronen Shitritfb6f5522008-09-17 10:08:05 +030076 .phy_version = EHCI_PHY_NA,
Saeed Bishara651c74c2008-06-22 22:45:06 +020077};
78
Andrew Lunn5c602552011-05-15 13:32:40 +020079static u64 ehci_dmamask = DMA_BIT_MASK(32);
Saeed Bishara651c74c2008-06-22 22:45:06 +020080
81
82/*****************************************************************************
83 * EHCI0
84 ****************************************************************************/
85static struct resource kirkwood_ehci_resources[] = {
86 {
87 .start = USB_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +020088 .end = USB_PHYS_BASE + SZ_4K - 1,
Saeed Bishara651c74c2008-06-22 22:45:06 +020089 .flags = IORESOURCE_MEM,
90 }, {
91 .start = IRQ_KIRKWOOD_USB,
92 .end = IRQ_KIRKWOOD_USB,
93 .flags = IORESOURCE_IRQ,
94 },
95};
96
97static struct platform_device kirkwood_ehci = {
98 .name = "orion-ehci",
99 .id = 0,
100 .dev = {
101 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200102 .coherent_dma_mask = DMA_BIT_MASK(32),
Saeed Bishara651c74c2008-06-22 22:45:06 +0200103 .platform_data = &kirkwood_ehci_data,
104 },
105 .resource = kirkwood_ehci_resources,
106 .num_resources = ARRAY_SIZE(kirkwood_ehci_resources),
107};
108
109void __init kirkwood_ehci_init(void)
110{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200111 kirkwood_clk_ctrl |= CGC_USB0;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200112 platform_device_register(&kirkwood_ehci);
113}
114
115
116/*****************************************************************************
117 * GE00
118 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200119void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
120{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200121 kirkwood_clk_ctrl |= CGC_GE0;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200122
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200123 orion_ge00_init(eth_data, &kirkwood_mbus_dram_info,
124 GE00_PHYS_BASE, IRQ_KIRKWOOD_GE00_SUM,
125 IRQ_KIRKWOOD_GE00_ERR, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200126}
127
128
129/*****************************************************************************
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200130 * GE01
131 ****************************************************************************/
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200132void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data)
133{
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200134
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200135 kirkwood_clk_ctrl |= CGC_GE1;
136
137 orion_ge01_init(eth_data, &kirkwood_mbus_dram_info,
138 GE01_PHYS_BASE, IRQ_KIRKWOOD_GE01_SUM,
139 IRQ_KIRKWOOD_GE01_ERR, kirkwood_tclk);
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200140}
141
142
143/*****************************************************************************
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200144 * Ethernet switch
145 ****************************************************************************/
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200146void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
147{
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200148 orion_ge00_switch_init(d, irq);
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200149}
150
151
152/*****************************************************************************
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400153 * NAND flash
154 ****************************************************************************/
155static struct resource kirkwood_nand_resource = {
156 .flags = IORESOURCE_MEM,
157 .start = KIRKWOOD_NAND_MEM_PHYS_BASE,
158 .end = KIRKWOOD_NAND_MEM_PHYS_BASE +
159 KIRKWOOD_NAND_MEM_SIZE - 1,
160};
161
162static struct orion_nand_data kirkwood_nand_data = {
163 .cle = 0,
164 .ale = 1,
165 .width = 8,
166};
167
168static struct platform_device kirkwood_nand_flash = {
169 .name = "orion_nand",
170 .id = -1,
171 .dev = {
172 .platform_data = &kirkwood_nand_data,
173 },
174 .resource = &kirkwood_nand_resource,
175 .num_resources = 1,
176};
177
178void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
179 int chip_delay)
180{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200181 kirkwood_clk_ctrl |= CGC_RUNIT;
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400182 kirkwood_nand_data.parts = parts;
183 kirkwood_nand_data.nr_parts = nr_parts;
184 kirkwood_nand_data.chip_delay = chip_delay;
185 platform_device_register(&kirkwood_nand_flash);
186}
187
Ben Dooks010937e2010-04-20 10:26:19 +0100188void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
189 int (*dev_ready)(struct mtd_info *))
190{
191 kirkwood_clk_ctrl |= CGC_RUNIT;
192 kirkwood_nand_data.parts = parts;
193 kirkwood_nand_data.nr_parts = nr_parts;
194 kirkwood_nand_data.dev_ready = dev_ready;
195 platform_device_register(&kirkwood_nand_flash);
196}
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400197
198/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200199 * SoC RTC
200 ****************************************************************************/
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500201static void __init kirkwood_rtc_init(void)
Saeed Bishara651c74c2008-06-22 22:45:06 +0200202{
Andrew Lunn47480582011-05-15 13:32:43 +0200203 orion_rtc_init(RTC_PHYS_BASE, IRQ_KIRKWOOD_RTC);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200204}
205
206
207/*****************************************************************************
208 * SATA
209 ****************************************************************************/
210static struct resource kirkwood_sata_resources[] = {
211 {
212 .name = "sata base",
213 .start = SATA_PHYS_BASE,
214 .end = SATA_PHYS_BASE + 0x5000 - 1,
215 .flags = IORESOURCE_MEM,
216 }, {
217 .name = "sata irq",
218 .start = IRQ_KIRKWOOD_SATA,
219 .end = IRQ_KIRKWOOD_SATA,
220 .flags = IORESOURCE_IRQ,
221 },
222};
223
224static struct platform_device kirkwood_sata = {
225 .name = "sata_mv",
226 .id = 0,
227 .dev = {
Andrew Lunn5c602552011-05-15 13:32:40 +0200228 .coherent_dma_mask = DMA_BIT_MASK(32),
Saeed Bishara651c74c2008-06-22 22:45:06 +0200229 },
230 .num_resources = ARRAY_SIZE(kirkwood_sata_resources),
231 .resource = kirkwood_sata_resources,
232};
233
234void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
235{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200236 kirkwood_clk_ctrl |= CGC_SATA0;
237 if (sata_data->n_ports > 1)
238 kirkwood_clk_ctrl |= CGC_SATA1;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200239 sata_data->dram = &kirkwood_mbus_dram_info;
240 kirkwood_sata.dev.platform_data = sata_data;
241 platform_device_register(&kirkwood_sata);
242}
243
244
245/*****************************************************************************
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500246 * SD/SDIO/MMC
247 ****************************************************************************/
248static struct resource mvsdio_resources[] = {
249 [0] = {
250 .start = SDIO_PHYS_BASE,
251 .end = SDIO_PHYS_BASE + SZ_1K - 1,
252 .flags = IORESOURCE_MEM,
253 },
254 [1] = {
255 .start = IRQ_KIRKWOOD_SDIO,
256 .end = IRQ_KIRKWOOD_SDIO,
257 .flags = IORESOURCE_IRQ,
258 },
259};
260
Andrew Lunn5c602552011-05-15 13:32:40 +0200261static u64 mvsdio_dmamask = DMA_BIT_MASK(32);
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500262
263static struct platform_device kirkwood_sdio = {
264 .name = "mvsdio",
265 .id = -1,
266 .dev = {
267 .dma_mask = &mvsdio_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200268 .coherent_dma_mask = DMA_BIT_MASK(32),
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500269 },
270 .num_resources = ARRAY_SIZE(mvsdio_resources),
271 .resource = mvsdio_resources,
272};
273
274void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
275{
276 u32 dev, rev;
277
278 kirkwood_pcie_id(&dev, &rev);
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300279 if (rev == 0 && dev != MV88F6282_DEV_ID) /* catch all Kirkwood Z0's */
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500280 mvsdio_data->clock = 100000000;
281 else
282 mvsdio_data->clock = 200000000;
283 mvsdio_data->dram = &kirkwood_mbus_dram_info;
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200284 kirkwood_clk_ctrl |= CGC_SDIO;
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500285 kirkwood_sdio.dev.platform_data = mvsdio_data;
286 platform_device_register(&kirkwood_sdio);
287}
288
289
290/*****************************************************************************
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200291 * SPI
292 ****************************************************************************/
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200293void __init kirkwood_spi_init()
294{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200295 kirkwood_clk_ctrl |= CGC_RUNIT;
Andrew Lunn980f9f62011-05-15 13:32:46 +0200296 orion_spi_init(SPI_PHYS_BASE, kirkwood_tclk);
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200297}
298
299
300/*****************************************************************************
Martin Michlmayr6574e002009-03-23 19:13:21 +0100301 * I2C
302 ****************************************************************************/
Martin Michlmayr6574e002009-03-23 19:13:21 +0100303void __init kirkwood_i2c_init(void)
304{
Andrew Lunnaac7ffa2011-05-15 13:32:45 +0200305 orion_i2c_init(I2C_PHYS_BASE, IRQ_KIRKWOOD_TWSI, 8);
Martin Michlmayr6574e002009-03-23 19:13:21 +0100306}
307
308
309/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200310 * UART0
311 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200312
313void __init kirkwood_uart0_init(void)
314{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200315 orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
316 IRQ_KIRKWOOD_UART_0, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200317}
318
319
320/*****************************************************************************
321 * UART1
322 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200323void __init kirkwood_uart1_init(void)
324{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200325 orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
326 IRQ_KIRKWOOD_UART_1, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200327}
328
Saeed Bishara651c74c2008-06-22 22:45:06 +0200329/*****************************************************************************
Nicolas Pitreae5c8c82009-06-03 15:24:36 -0400330 * Cryptographic Engines and Security Accelerator (CESA)
331 ****************************************************************************/
332
333static struct resource kirkwood_crypto_res[] = {
334 {
335 .name = "regs",
336 .start = CRYPTO_PHYS_BASE,
337 .end = CRYPTO_PHYS_BASE + 0xffff,
338 .flags = IORESOURCE_MEM,
339 }, {
340 .name = "sram",
341 .start = KIRKWOOD_SRAM_PHYS_BASE,
342 .end = KIRKWOOD_SRAM_PHYS_BASE + KIRKWOOD_SRAM_SIZE - 1,
343 .flags = IORESOURCE_MEM,
344 }, {
345 .name = "crypto interrupt",
346 .start = IRQ_KIRKWOOD_CRYPTO,
347 .end = IRQ_KIRKWOOD_CRYPTO,
348 .flags = IORESOURCE_IRQ,
349 },
350};
351
352static struct platform_device kirkwood_crypto_device = {
353 .name = "mv_crypto",
354 .id = -1,
355 .num_resources = ARRAY_SIZE(kirkwood_crypto_res),
356 .resource = kirkwood_crypto_res,
357};
358
359void __init kirkwood_crypto_init(void)
360{
361 kirkwood_clk_ctrl |= CGC_CRYPTO;
362 platform_device_register(&kirkwood_crypto_device);
363}
364
365
366/*****************************************************************************
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100367 * XOR
368 ****************************************************************************/
369static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
370 .dram = &kirkwood_mbus_dram_info,
371};
372
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100373
374/*****************************************************************************
375 * XOR0
376 ****************************************************************************/
377static struct resource kirkwood_xor0_shared_resources[] = {
378 {
379 .name = "xor 0 low",
380 .start = XOR0_PHYS_BASE,
381 .end = XOR0_PHYS_BASE + 0xff,
382 .flags = IORESOURCE_MEM,
383 }, {
384 .name = "xor 0 high",
385 .start = XOR0_HIGH_PHYS_BASE,
386 .end = XOR0_HIGH_PHYS_BASE + 0xff,
387 .flags = IORESOURCE_MEM,
388 },
389};
390
391static struct platform_device kirkwood_xor0_shared = {
392 .name = MV_XOR_SHARED_NAME,
393 .id = 0,
394 .dev = {
395 .platform_data = &kirkwood_xor_shared_data,
396 },
397 .num_resources = ARRAY_SIZE(kirkwood_xor0_shared_resources),
398 .resource = kirkwood_xor0_shared_resources,
399};
400
Andrew Lunn5c602552011-05-15 13:32:40 +0200401static u64 kirkwood_xor_dmamask = DMA_BIT_MASK(32);
402
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100403static struct resource kirkwood_xor00_resources[] = {
404 [0] = {
405 .start = IRQ_KIRKWOOD_XOR_00,
406 .end = IRQ_KIRKWOOD_XOR_00,
407 .flags = IORESOURCE_IRQ,
408 },
409};
410
411static struct mv_xor_platform_data kirkwood_xor00_data = {
412 .shared = &kirkwood_xor0_shared,
413 .hw_id = 0,
414 .pool_size = PAGE_SIZE,
415};
416
417static struct platform_device kirkwood_xor00_channel = {
418 .name = MV_XOR_NAME,
419 .id = 0,
420 .num_resources = ARRAY_SIZE(kirkwood_xor00_resources),
421 .resource = kirkwood_xor00_resources,
422 .dev = {
423 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700424 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800425 .platform_data = &kirkwood_xor00_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100426 },
427};
428
429static struct resource kirkwood_xor01_resources[] = {
430 [0] = {
431 .start = IRQ_KIRKWOOD_XOR_01,
432 .end = IRQ_KIRKWOOD_XOR_01,
433 .flags = IORESOURCE_IRQ,
434 },
435};
436
437static struct mv_xor_platform_data kirkwood_xor01_data = {
438 .shared = &kirkwood_xor0_shared,
439 .hw_id = 1,
440 .pool_size = PAGE_SIZE,
441};
442
443static struct platform_device kirkwood_xor01_channel = {
444 .name = MV_XOR_NAME,
445 .id = 1,
446 .num_resources = ARRAY_SIZE(kirkwood_xor01_resources),
447 .resource = kirkwood_xor01_resources,
448 .dev = {
449 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700450 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800451 .platform_data = &kirkwood_xor01_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100452 },
453};
454
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500455static void __init kirkwood_xor0_init(void)
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100456{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200457 kirkwood_clk_ctrl |= CGC_XOR0;
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100458 platform_device_register(&kirkwood_xor0_shared);
459
460 /*
461 * two engines can't do memset simultaneously, this limitation
462 * satisfied by removing memset support from one of the engines.
463 */
464 dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
465 dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
466 platform_device_register(&kirkwood_xor00_channel);
467
468 dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
469 dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
470 dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
471 platform_device_register(&kirkwood_xor01_channel);
472}
473
474
475/*****************************************************************************
476 * XOR1
477 ****************************************************************************/
478static struct resource kirkwood_xor1_shared_resources[] = {
479 {
480 .name = "xor 1 low",
481 .start = XOR1_PHYS_BASE,
482 .end = XOR1_PHYS_BASE + 0xff,
483 .flags = IORESOURCE_MEM,
484 }, {
485 .name = "xor 1 high",
486 .start = XOR1_HIGH_PHYS_BASE,
487 .end = XOR1_HIGH_PHYS_BASE + 0xff,
488 .flags = IORESOURCE_MEM,
489 },
490};
491
492static struct platform_device kirkwood_xor1_shared = {
493 .name = MV_XOR_SHARED_NAME,
494 .id = 1,
495 .dev = {
496 .platform_data = &kirkwood_xor_shared_data,
497 },
498 .num_resources = ARRAY_SIZE(kirkwood_xor1_shared_resources),
499 .resource = kirkwood_xor1_shared_resources,
500};
501
502static struct resource kirkwood_xor10_resources[] = {
503 [0] = {
504 .start = IRQ_KIRKWOOD_XOR_10,
505 .end = IRQ_KIRKWOOD_XOR_10,
506 .flags = IORESOURCE_IRQ,
507 },
508};
509
510static struct mv_xor_platform_data kirkwood_xor10_data = {
511 .shared = &kirkwood_xor1_shared,
512 .hw_id = 0,
513 .pool_size = PAGE_SIZE,
514};
515
516static struct platform_device kirkwood_xor10_channel = {
517 .name = MV_XOR_NAME,
518 .id = 2,
519 .num_resources = ARRAY_SIZE(kirkwood_xor10_resources),
520 .resource = kirkwood_xor10_resources,
521 .dev = {
522 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700523 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800524 .platform_data = &kirkwood_xor10_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100525 },
526};
527
528static struct resource kirkwood_xor11_resources[] = {
529 [0] = {
530 .start = IRQ_KIRKWOOD_XOR_11,
531 .end = IRQ_KIRKWOOD_XOR_11,
532 .flags = IORESOURCE_IRQ,
533 },
534};
535
536static struct mv_xor_platform_data kirkwood_xor11_data = {
537 .shared = &kirkwood_xor1_shared,
538 .hw_id = 1,
539 .pool_size = PAGE_SIZE,
540};
541
542static struct platform_device kirkwood_xor11_channel = {
543 .name = MV_XOR_NAME,
544 .id = 3,
545 .num_resources = ARRAY_SIZE(kirkwood_xor11_resources),
546 .resource = kirkwood_xor11_resources,
547 .dev = {
548 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700549 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800550 .platform_data = &kirkwood_xor11_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100551 },
552};
553
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500554static void __init kirkwood_xor1_init(void)
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100555{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200556 kirkwood_clk_ctrl |= CGC_XOR1;
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100557 platform_device_register(&kirkwood_xor1_shared);
558
559 /*
560 * two engines can't do memset simultaneously, this limitation
561 * satisfied by removing memset support from one of the engines.
562 */
563 dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
564 dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
565 platform_device_register(&kirkwood_xor10_channel);
566
567 dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
568 dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
569 dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
570 platform_device_register(&kirkwood_xor11_channel);
571}
572
573
574/*****************************************************************************
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200575 * Watchdog
576 ****************************************************************************/
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200577static void __init kirkwood_wdt_init(void)
578{
Andrew Lunn5e00d372011-05-15 13:32:47 +0200579 orion_wdt_init(kirkwood_tclk);
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200580}
581
582
583/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200584 * Time handling
585 ****************************************************************************/
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200586void __init kirkwood_init_early(void)
587{
588 orion_time_set_base(TIMER_VIRT_BASE);
589}
590
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200591int kirkwood_tclk;
592
Nicolas Pitre9b8ebfe2011-03-03 15:08:53 -0500593static int __init kirkwood_find_tclk(void)
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200594{
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300595 u32 dev, rev;
596
597 kirkwood_pcie_id(&dev, &rev);
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300598
Simon Guinot2fa0f932010-10-21 11:42:28 +0200599 if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
600 if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
601 return 200000000;
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300602
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200603 return 166666667;
604}
605
Li Jie6de95c12009-11-05 07:29:54 -0800606static void __init kirkwood_timer_init(void)
Saeed Bishara651c74c2008-06-22 22:45:06 +0200607{
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200608 kirkwood_tclk = kirkwood_find_tclk();
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200609
610 orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
611 IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200612}
613
614struct sys_timer kirkwood_timer = {
615 .init = kirkwood_timer_init,
616};
617
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200618/*****************************************************************************
619 * Audio
620 ****************************************************************************/
621static struct resource kirkwood_i2s_resources[] = {
622 [0] = {
623 .start = AUDIO_PHYS_BASE,
624 .end = AUDIO_PHYS_BASE + SZ_16K - 1,
625 .flags = IORESOURCE_MEM,
626 },
627 [1] = {
628 .start = IRQ_KIRKWOOD_I2S,
629 .end = IRQ_KIRKWOOD_I2S,
630 .flags = IORESOURCE_IRQ,
631 },
632};
633
634static struct kirkwood_asoc_platform_data kirkwood_i2s_data = {
635 .dram = &kirkwood_mbus_dram_info,
636 .burst = 128,
637};
638
639static struct platform_device kirkwood_i2s_device = {
640 .name = "kirkwood-i2s",
641 .id = -1,
642 .num_resources = ARRAY_SIZE(kirkwood_i2s_resources),
643 .resource = kirkwood_i2s_resources,
644 .dev = {
645 .platform_data = &kirkwood_i2s_data,
646 },
647};
648
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000649static struct platform_device kirkwood_pcm_device = {
Arnaud Patard (Rtp)c88e7b92010-08-30 16:00:05 +0200650 .name = "kirkwood-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000651 .id = -1,
652};
653
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200654void __init kirkwood_audio_init(void)
655{
656 kirkwood_clk_ctrl |= CGC_AUDIO;
657 platform_device_register(&kirkwood_i2s_device);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000658 platform_device_register(&kirkwood_pcm_device);
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200659}
Saeed Bishara651c74c2008-06-22 22:45:06 +0200660
661/*****************************************************************************
662 * General
663 ****************************************************************************/
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300664/*
665 * Identify device ID and revision.
666 */
Saeed Bishara651c74c2008-06-22 22:45:06 +0200667static char * __init kirkwood_id(void)
668{
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300669 u32 dev, rev;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200670
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300671 kirkwood_pcie_id(&dev, &rev);
672
673 if (dev == MV88F6281_DEV_ID) {
674 if (rev == MV88F6281_REV_Z0)
675 return "MV88F6281-Z0";
676 else if (rev == MV88F6281_REV_A0)
677 return "MV88F6281-A0";
Siddarth Goreaec1bad2009-06-09 14:41:02 +0530678 else if (rev == MV88F6281_REV_A1)
679 return "MV88F6281-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300680 else
681 return "MV88F6281-Rev-Unsupported";
682 } else if (dev == MV88F6192_DEV_ID) {
683 if (rev == MV88F6192_REV_Z0)
684 return "MV88F6192-Z0";
685 else if (rev == MV88F6192_REV_A0)
686 return "MV88F6192-A0";
Saeed Bishara1c2003a2010-06-01 18:09:26 +0300687 else if (rev == MV88F6192_REV_A1)
688 return "MV88F6192-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300689 else
690 return "MV88F6192-Rev-Unsupported";
691 } else if (dev == MV88F6180_DEV_ID) {
692 if (rev == MV88F6180_REV_A0)
693 return "MV88F6180-Rev-A0";
Saeed Bishara1c2003a2010-06-01 18:09:26 +0300694 else if (rev == MV88F6180_REV_A1)
695 return "MV88F6180-Rev-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300696 else
697 return "MV88F6180-Rev-Unsupported";
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300698 } else if (dev == MV88F6282_DEV_ID) {
699 if (rev == MV88F6282_REV_A0)
700 return "MV88F6282-Rev-A0";
701 else
702 return "MV88F6282-Rev-Unsupported";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300703 } else {
704 return "Device-Unknown";
705 }
Saeed Bishara651c74c2008-06-22 22:45:06 +0200706}
707
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300708static void __init kirkwood_l2_init(void)
Saeed Bishara13387602008-06-23 01:05:08 -1100709{
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300710#ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
711 writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
712 feroceon_l2_init(1);
713#else
714 writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
715 feroceon_l2_init(0);
716#endif
Saeed Bishara13387602008-06-23 01:05:08 -1100717}
718
Saeed Bishara651c74c2008-06-22 22:45:06 +0200719void __init kirkwood_init(void)
720{
721 printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200722 kirkwood_id(), kirkwood_tclk);
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200723 kirkwood_i2s_data.tclk = kirkwood_tclk;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200724
Lennert Buytenhek2bf30102009-11-12 20:31:14 +0100725 /*
726 * Disable propagation of mbus errors to the CPU local bus,
727 * as this causes mbus errors (which can occur for example
728 * for PCI aborts) to throw CPU aborts, which we're not set
729 * up to deal with.
730 */
731 writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
732
Saeed Bishara651c74c2008-06-22 22:45:06 +0200733 kirkwood_setup_cpu_mbus();
734
735#ifdef CONFIG_CACHE_FEROCEON_L2
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300736 kirkwood_l2_init();
Saeed Bishara651c74c2008-06-22 22:45:06 +0200737#endif
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500738
739 /* internal devices that every board has */
740 kirkwood_rtc_init();
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200741 kirkwood_wdt_init();
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500742 kirkwood_xor0_init();
743 kirkwood_xor1_init();
Nicolas Pitreae5c8c82009-06-03 15:24:36 -0400744 kirkwood_crypto_init();
Eric Cooper9c153642011-02-02 17:16:11 -0500745
746#ifdef CONFIG_KEXEC
747 kexec_reinit = kirkwood_enable_pcie;
748#endif
Saeed Bishara651c74c2008-06-22 22:45:06 +0200749}
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200750
751static int __init kirkwood_clock_gate(void)
752{
753 unsigned int curr = readl(CLOCK_GATING_CTRL);
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300754 u32 dev, rev;
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200755
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300756 kirkwood_pcie_id(&dev, &rev);
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200757 printk(KERN_DEBUG "Gating clock of unused units\n");
758 printk(KERN_DEBUG "before: 0x%08x\n", curr);
759
760 /* Make sure those units are accessible */
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300761 writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL);
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200762
763 /* For SATA: first shutdown the phy */
764 if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
765 /* Disable PLL and IVREF */
766 writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
767 /* Disable PHY */
768 writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
769 }
770 if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
771 /* Disable PLL and IVREF */
772 writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
773 /* Disable PHY */
774 writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
775 }
776
777 /* For PCIe: first shutdown the phy */
778 if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
779 writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
780 while (1)
781 if (readl(PCIE_STATUS) & 0x1)
782 break;
783 writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
784 }
785
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300786 /* For PCIe 1: first shutdown the phy */
787 if (dev == MV88F6282_DEV_ID) {
788 if (!(kirkwood_clk_ctrl & CGC_PEX1)) {
789 writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
790 while (1)
791 if (readl(PCIE1_STATUS) & 0x1)
792 break;
793 writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
794 }
795 } else /* keep this bit set for devices that don't have PCIe1 */
796 kirkwood_clk_ctrl |= CGC_PEX1;
797
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200798 /* Now gate clock the required units */
799 writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
800 printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
801
802 return 0;
803}
804late_initcall(kirkwood_clock_gate);