blob: 485f3b9ba4e29bec31abcb85a750a03928960636 [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>
Martin Michlmayr6574e002009-03-23 19:13:21 +010016#include <linux/mv643xx_i2c.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020017#include <linux/ata_platform.h>
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -040018#include <linux/mtd/nand.h>
Lennert Buytenhek18365d12008-08-09 15:38:18 +020019#include <linux/spi/orion_spi.h>
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +020020#include <net/dsa.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020021#include <asm/page.h>
22#include <asm/timex.h>
Eric Cooper9c153642011-02-02 17:16:11 -050023#include <asm/kexec.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020024#include <asm/mach/map.h>
25#include <asm/mach/time.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/kirkwood.h>
Nicolas Pitrefdd8b072009-04-22 20:08:17 +010027#include <mach/bridge-regs.h>
apatard@mandriva.com49106c72010-05-31 13:49:12 +020028#include <plat/audio.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020029#include <plat/cache-feroceon-l2.h>
30#include <plat/ehci-orion.h>
Nicolas Pitre8235ee02009-02-14 03:15:55 -050031#include <plat/mvsdio.h>
Saeed Bishara09c0ed22008-06-23 04:26:07 -110032#include <plat/mv_xor.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020033#include <plat/orion_nand.h>
Nicolas Pitre3b937a72009-06-01 13:56:02 -040034#include <plat/orion_wdt.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020035#include <plat/common.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020036#include <plat/time.h>
Saeed Bishara651c74c2008-06-22 22:45:06 +020037#include "common.h"
38
39/*****************************************************************************
40 * I/O Address Mapping
41 ****************************************************************************/
42static struct map_desc kirkwood_io_desc[] __initdata = {
43 {
44 .virtual = KIRKWOOD_PCIE_IO_VIRT_BASE,
45 .pfn = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
46 .length = KIRKWOOD_PCIE_IO_SIZE,
47 .type = MT_DEVICE,
48 }, {
Saeed Bisharaffd58bd2010-06-08 14:21:34 +030049 .virtual = KIRKWOOD_PCIE1_IO_VIRT_BASE,
50 .pfn = __phys_to_pfn(KIRKWOOD_PCIE1_IO_PHYS_BASE),
51 .length = KIRKWOOD_PCIE1_IO_SIZE,
52 .type = MT_DEVICE,
53 }, {
Saeed Bishara651c74c2008-06-22 22:45:06 +020054 .virtual = KIRKWOOD_REGS_VIRT_BASE,
55 .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
56 .length = KIRKWOOD_REGS_SIZE,
57 .type = MT_DEVICE,
58 },
59};
60
61void __init kirkwood_map_io(void)
62{
63 iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
64}
65
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +020066/*
67 * Default clock control bits. Any bit _not_ set in this variable
68 * will be cleared from the hardware after platform devices have been
69 * registered. Some reserved bits must be set to 1.
70 */
71unsigned int kirkwood_clk_ctrl = CGC_DUNIT | CGC_RESERVED;
Andrew Lunn7e3819d2011-05-15 13:32:44 +020072
Saeed Bishara651c74c2008-06-22 22:45:06 +020073
74/*****************************************************************************
75 * EHCI
76 ****************************************************************************/
77static struct orion_ehci_data kirkwood_ehci_data = {
78 .dram = &kirkwood_mbus_dram_info,
Ronen Shitritfb6f5522008-09-17 10:08:05 +030079 .phy_version = EHCI_PHY_NA,
Saeed Bishara651c74c2008-06-22 22:45:06 +020080};
81
Andrew Lunn5c602552011-05-15 13:32:40 +020082static u64 ehci_dmamask = DMA_BIT_MASK(32);
Saeed Bishara651c74c2008-06-22 22:45:06 +020083
84
85/*****************************************************************************
86 * EHCI0
87 ****************************************************************************/
88static struct resource kirkwood_ehci_resources[] = {
89 {
90 .start = USB_PHYS_BASE,
Andrew Lunn5c602552011-05-15 13:32:40 +020091 .end = USB_PHYS_BASE + SZ_4K - 1,
Saeed Bishara651c74c2008-06-22 22:45:06 +020092 .flags = IORESOURCE_MEM,
93 }, {
94 .start = IRQ_KIRKWOOD_USB,
95 .end = IRQ_KIRKWOOD_USB,
96 .flags = IORESOURCE_IRQ,
97 },
98};
99
100static struct platform_device kirkwood_ehci = {
101 .name = "orion-ehci",
102 .id = 0,
103 .dev = {
104 .dma_mask = &ehci_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200105 .coherent_dma_mask = DMA_BIT_MASK(32),
Saeed Bishara651c74c2008-06-22 22:45:06 +0200106 .platform_data = &kirkwood_ehci_data,
107 },
108 .resource = kirkwood_ehci_resources,
109 .num_resources = ARRAY_SIZE(kirkwood_ehci_resources),
110};
111
112void __init kirkwood_ehci_init(void)
113{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200114 kirkwood_clk_ctrl |= CGC_USB0;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200115 platform_device_register(&kirkwood_ehci);
116}
117
118
119/*****************************************************************************
120 * GE00
121 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200122void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
123{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200124 kirkwood_clk_ctrl |= CGC_GE0;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200125
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200126 orion_ge00_init(eth_data, &kirkwood_mbus_dram_info,
127 GE00_PHYS_BASE, IRQ_KIRKWOOD_GE00_SUM,
128 IRQ_KIRKWOOD_GE00_ERR, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200129}
130
131
132/*****************************************************************************
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200133 * GE01
134 ****************************************************************************/
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200135void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data)
136{
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200137
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200138 kirkwood_clk_ctrl |= CGC_GE1;
139
140 orion_ge01_init(eth_data, &kirkwood_mbus_dram_info,
141 GE01_PHYS_BASE, IRQ_KIRKWOOD_GE01_SUM,
142 IRQ_KIRKWOOD_GE01_ERR, kirkwood_tclk);
Ronen Shitritd15fb9e2008-10-19 23:10:14 +0200143}
144
145
146/*****************************************************************************
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200147 * Ethernet switch
148 ****************************************************************************/
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200149void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
150{
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200151 orion_ge00_switch_init(d, irq);
Lennert Buytenhekdcf1cec2008-09-25 16:23:48 +0200152}
153
154
155/*****************************************************************************
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400156 * NAND flash
157 ****************************************************************************/
158static struct resource kirkwood_nand_resource = {
159 .flags = IORESOURCE_MEM,
160 .start = KIRKWOOD_NAND_MEM_PHYS_BASE,
161 .end = KIRKWOOD_NAND_MEM_PHYS_BASE +
162 KIRKWOOD_NAND_MEM_SIZE - 1,
163};
164
165static struct orion_nand_data kirkwood_nand_data = {
166 .cle = 0,
167 .ale = 1,
168 .width = 8,
169};
170
171static struct platform_device kirkwood_nand_flash = {
172 .name = "orion_nand",
173 .id = -1,
174 .dev = {
175 .platform_data = &kirkwood_nand_data,
176 },
177 .resource = &kirkwood_nand_resource,
178 .num_resources = 1,
179};
180
181void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
182 int chip_delay)
183{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200184 kirkwood_clk_ctrl |= CGC_RUNIT;
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400185 kirkwood_nand_data.parts = parts;
186 kirkwood_nand_data.nr_parts = nr_parts;
187 kirkwood_nand_data.chip_delay = chip_delay;
188 platform_device_register(&kirkwood_nand_flash);
189}
190
Ben Dooks010937e2010-04-20 10:26:19 +0100191void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
192 int (*dev_ready)(struct mtd_info *))
193{
194 kirkwood_clk_ctrl |= CGC_RUNIT;
195 kirkwood_nand_data.parts = parts;
196 kirkwood_nand_data.nr_parts = nr_parts;
197 kirkwood_nand_data.dev_ready = dev_ready;
198 platform_device_register(&kirkwood_nand_flash);
199}
Nicolas Pitrefb7b2d32009-06-01 15:36:36 -0400200
201/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200202 * SoC RTC
203 ****************************************************************************/
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500204static void __init kirkwood_rtc_init(void)
Saeed Bishara651c74c2008-06-22 22:45:06 +0200205{
Andrew Lunn47480582011-05-15 13:32:43 +0200206 orion_rtc_init(RTC_PHYS_BASE, IRQ_KIRKWOOD_RTC);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200207}
208
209
210/*****************************************************************************
211 * SATA
212 ****************************************************************************/
213static struct resource kirkwood_sata_resources[] = {
214 {
215 .name = "sata base",
216 .start = SATA_PHYS_BASE,
217 .end = SATA_PHYS_BASE + 0x5000 - 1,
218 .flags = IORESOURCE_MEM,
219 }, {
220 .name = "sata irq",
221 .start = IRQ_KIRKWOOD_SATA,
222 .end = IRQ_KIRKWOOD_SATA,
223 .flags = IORESOURCE_IRQ,
224 },
225};
226
227static struct platform_device kirkwood_sata = {
228 .name = "sata_mv",
229 .id = 0,
230 .dev = {
Andrew Lunn5c602552011-05-15 13:32:40 +0200231 .coherent_dma_mask = DMA_BIT_MASK(32),
Saeed Bishara651c74c2008-06-22 22:45:06 +0200232 },
233 .num_resources = ARRAY_SIZE(kirkwood_sata_resources),
234 .resource = kirkwood_sata_resources,
235};
236
237void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
238{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200239 kirkwood_clk_ctrl |= CGC_SATA0;
240 if (sata_data->n_ports > 1)
241 kirkwood_clk_ctrl |= CGC_SATA1;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200242 sata_data->dram = &kirkwood_mbus_dram_info;
243 kirkwood_sata.dev.platform_data = sata_data;
244 platform_device_register(&kirkwood_sata);
245}
246
247
248/*****************************************************************************
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500249 * SD/SDIO/MMC
250 ****************************************************************************/
251static struct resource mvsdio_resources[] = {
252 [0] = {
253 .start = SDIO_PHYS_BASE,
254 .end = SDIO_PHYS_BASE + SZ_1K - 1,
255 .flags = IORESOURCE_MEM,
256 },
257 [1] = {
258 .start = IRQ_KIRKWOOD_SDIO,
259 .end = IRQ_KIRKWOOD_SDIO,
260 .flags = IORESOURCE_IRQ,
261 },
262};
263
Andrew Lunn5c602552011-05-15 13:32:40 +0200264static u64 mvsdio_dmamask = DMA_BIT_MASK(32);
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500265
266static struct platform_device kirkwood_sdio = {
267 .name = "mvsdio",
268 .id = -1,
269 .dev = {
270 .dma_mask = &mvsdio_dmamask,
Andrew Lunn5c602552011-05-15 13:32:40 +0200271 .coherent_dma_mask = DMA_BIT_MASK(32),
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500272 },
273 .num_resources = ARRAY_SIZE(mvsdio_resources),
274 .resource = mvsdio_resources,
275};
276
277void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
278{
279 u32 dev, rev;
280
281 kirkwood_pcie_id(&dev, &rev);
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300282 if (rev == 0 && dev != MV88F6282_DEV_ID) /* catch all Kirkwood Z0's */
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500283 mvsdio_data->clock = 100000000;
284 else
285 mvsdio_data->clock = 200000000;
286 mvsdio_data->dram = &kirkwood_mbus_dram_info;
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200287 kirkwood_clk_ctrl |= CGC_SDIO;
Nicolas Pitre8235ee02009-02-14 03:15:55 -0500288 kirkwood_sdio.dev.platform_data = mvsdio_data;
289 platform_device_register(&kirkwood_sdio);
290}
291
292
293/*****************************************************************************
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200294 * SPI
295 ****************************************************************************/
296static struct orion_spi_info kirkwood_spi_plat_data = {
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200297};
298
299static struct resource kirkwood_spi_resources[] = {
300 {
301 .start = SPI_PHYS_BASE,
302 .end = SPI_PHYS_BASE + SZ_512 - 1,
303 .flags = IORESOURCE_MEM,
304 },
305};
306
307static struct platform_device kirkwood_spi = {
308 .name = "orion_spi",
309 .id = 0,
310 .resource = kirkwood_spi_resources,
311 .dev = {
312 .platform_data = &kirkwood_spi_plat_data,
313 },
314 .num_resources = ARRAY_SIZE(kirkwood_spi_resources),
315};
316
317void __init kirkwood_spi_init()
318{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200319 kirkwood_clk_ctrl |= CGC_RUNIT;
Lennert Buytenhek18365d12008-08-09 15:38:18 +0200320 platform_device_register(&kirkwood_spi);
321}
322
323
324/*****************************************************************************
Martin Michlmayr6574e002009-03-23 19:13:21 +0100325 * I2C
326 ****************************************************************************/
327static struct mv64xxx_i2c_pdata kirkwood_i2c_pdata = {
328 .freq_m = 8, /* assumes 166 MHz TCLK */
329 .freq_n = 3,
330 .timeout = 1000, /* Default timeout of 1 second */
331};
332
333static struct resource kirkwood_i2c_resources[] = {
334 {
Martin Michlmayr6574e002009-03-23 19:13:21 +0100335 .start = I2C_PHYS_BASE,
336 .end = I2C_PHYS_BASE + 0x1f,
337 .flags = IORESOURCE_MEM,
338 }, {
Martin Michlmayr6574e002009-03-23 19:13:21 +0100339 .start = IRQ_KIRKWOOD_TWSI,
340 .end = IRQ_KIRKWOOD_TWSI,
341 .flags = IORESOURCE_IRQ,
342 },
343};
344
345static struct platform_device kirkwood_i2c = {
346 .name = MV64XXX_I2C_CTLR_NAME,
347 .id = 0,
348 .num_resources = ARRAY_SIZE(kirkwood_i2c_resources),
349 .resource = kirkwood_i2c_resources,
350 .dev = {
351 .platform_data = &kirkwood_i2c_pdata,
352 },
353};
354
355void __init kirkwood_i2c_init(void)
356{
357 platform_device_register(&kirkwood_i2c);
358}
359
360
361/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200362 * UART0
363 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200364
365void __init kirkwood_uart0_init(void)
366{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200367 orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
368 IRQ_KIRKWOOD_UART_0, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200369}
370
371
372/*****************************************************************************
373 * UART1
374 ****************************************************************************/
Saeed Bishara651c74c2008-06-22 22:45:06 +0200375void __init kirkwood_uart1_init(void)
376{
Andrew Lunn28a2b452011-05-15 13:32:41 +0200377 orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
378 IRQ_KIRKWOOD_UART_1, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200379}
380
Saeed Bishara651c74c2008-06-22 22:45:06 +0200381/*****************************************************************************
Nicolas Pitreae5c8c82009-06-03 15:24:36 -0400382 * Cryptographic Engines and Security Accelerator (CESA)
383 ****************************************************************************/
384
385static struct resource kirkwood_crypto_res[] = {
386 {
387 .name = "regs",
388 .start = CRYPTO_PHYS_BASE,
389 .end = CRYPTO_PHYS_BASE + 0xffff,
390 .flags = IORESOURCE_MEM,
391 }, {
392 .name = "sram",
393 .start = KIRKWOOD_SRAM_PHYS_BASE,
394 .end = KIRKWOOD_SRAM_PHYS_BASE + KIRKWOOD_SRAM_SIZE - 1,
395 .flags = IORESOURCE_MEM,
396 }, {
397 .name = "crypto interrupt",
398 .start = IRQ_KIRKWOOD_CRYPTO,
399 .end = IRQ_KIRKWOOD_CRYPTO,
400 .flags = IORESOURCE_IRQ,
401 },
402};
403
404static struct platform_device kirkwood_crypto_device = {
405 .name = "mv_crypto",
406 .id = -1,
407 .num_resources = ARRAY_SIZE(kirkwood_crypto_res),
408 .resource = kirkwood_crypto_res,
409};
410
411void __init kirkwood_crypto_init(void)
412{
413 kirkwood_clk_ctrl |= CGC_CRYPTO;
414 platform_device_register(&kirkwood_crypto_device);
415}
416
417
418/*****************************************************************************
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100419 * XOR
420 ****************************************************************************/
421static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
422 .dram = &kirkwood_mbus_dram_info,
423};
424
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100425
426/*****************************************************************************
427 * XOR0
428 ****************************************************************************/
429static struct resource kirkwood_xor0_shared_resources[] = {
430 {
431 .name = "xor 0 low",
432 .start = XOR0_PHYS_BASE,
433 .end = XOR0_PHYS_BASE + 0xff,
434 .flags = IORESOURCE_MEM,
435 }, {
436 .name = "xor 0 high",
437 .start = XOR0_HIGH_PHYS_BASE,
438 .end = XOR0_HIGH_PHYS_BASE + 0xff,
439 .flags = IORESOURCE_MEM,
440 },
441};
442
443static struct platform_device kirkwood_xor0_shared = {
444 .name = MV_XOR_SHARED_NAME,
445 .id = 0,
446 .dev = {
447 .platform_data = &kirkwood_xor_shared_data,
448 },
449 .num_resources = ARRAY_SIZE(kirkwood_xor0_shared_resources),
450 .resource = kirkwood_xor0_shared_resources,
451};
452
Andrew Lunn5c602552011-05-15 13:32:40 +0200453static u64 kirkwood_xor_dmamask = DMA_BIT_MASK(32);
454
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100455static struct resource kirkwood_xor00_resources[] = {
456 [0] = {
457 .start = IRQ_KIRKWOOD_XOR_00,
458 .end = IRQ_KIRKWOOD_XOR_00,
459 .flags = IORESOURCE_IRQ,
460 },
461};
462
463static struct mv_xor_platform_data kirkwood_xor00_data = {
464 .shared = &kirkwood_xor0_shared,
465 .hw_id = 0,
466 .pool_size = PAGE_SIZE,
467};
468
469static struct platform_device kirkwood_xor00_channel = {
470 .name = MV_XOR_NAME,
471 .id = 0,
472 .num_resources = ARRAY_SIZE(kirkwood_xor00_resources),
473 .resource = kirkwood_xor00_resources,
474 .dev = {
475 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700476 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800477 .platform_data = &kirkwood_xor00_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100478 },
479};
480
481static struct resource kirkwood_xor01_resources[] = {
482 [0] = {
483 .start = IRQ_KIRKWOOD_XOR_01,
484 .end = IRQ_KIRKWOOD_XOR_01,
485 .flags = IORESOURCE_IRQ,
486 },
487};
488
489static struct mv_xor_platform_data kirkwood_xor01_data = {
490 .shared = &kirkwood_xor0_shared,
491 .hw_id = 1,
492 .pool_size = PAGE_SIZE,
493};
494
495static struct platform_device kirkwood_xor01_channel = {
496 .name = MV_XOR_NAME,
497 .id = 1,
498 .num_resources = ARRAY_SIZE(kirkwood_xor01_resources),
499 .resource = kirkwood_xor01_resources,
500 .dev = {
501 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700502 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800503 .platform_data = &kirkwood_xor01_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100504 },
505};
506
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500507static void __init kirkwood_xor0_init(void)
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100508{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200509 kirkwood_clk_ctrl |= CGC_XOR0;
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100510 platform_device_register(&kirkwood_xor0_shared);
511
512 /*
513 * two engines can't do memset simultaneously, this limitation
514 * satisfied by removing memset support from one of the engines.
515 */
516 dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
517 dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
518 platform_device_register(&kirkwood_xor00_channel);
519
520 dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
521 dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
522 dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
523 platform_device_register(&kirkwood_xor01_channel);
524}
525
526
527/*****************************************************************************
528 * XOR1
529 ****************************************************************************/
530static struct resource kirkwood_xor1_shared_resources[] = {
531 {
532 .name = "xor 1 low",
533 .start = XOR1_PHYS_BASE,
534 .end = XOR1_PHYS_BASE + 0xff,
535 .flags = IORESOURCE_MEM,
536 }, {
537 .name = "xor 1 high",
538 .start = XOR1_HIGH_PHYS_BASE,
539 .end = XOR1_HIGH_PHYS_BASE + 0xff,
540 .flags = IORESOURCE_MEM,
541 },
542};
543
544static struct platform_device kirkwood_xor1_shared = {
545 .name = MV_XOR_SHARED_NAME,
546 .id = 1,
547 .dev = {
548 .platform_data = &kirkwood_xor_shared_data,
549 },
550 .num_resources = ARRAY_SIZE(kirkwood_xor1_shared_resources),
551 .resource = kirkwood_xor1_shared_resources,
552};
553
554static struct resource kirkwood_xor10_resources[] = {
555 [0] = {
556 .start = IRQ_KIRKWOOD_XOR_10,
557 .end = IRQ_KIRKWOOD_XOR_10,
558 .flags = IORESOURCE_IRQ,
559 },
560};
561
562static struct mv_xor_platform_data kirkwood_xor10_data = {
563 .shared = &kirkwood_xor1_shared,
564 .hw_id = 0,
565 .pool_size = PAGE_SIZE,
566};
567
568static struct platform_device kirkwood_xor10_channel = {
569 .name = MV_XOR_NAME,
570 .id = 2,
571 .num_resources = ARRAY_SIZE(kirkwood_xor10_resources),
572 .resource = kirkwood_xor10_resources,
573 .dev = {
574 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700575 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800576 .platform_data = &kirkwood_xor10_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100577 },
578};
579
580static struct resource kirkwood_xor11_resources[] = {
581 [0] = {
582 .start = IRQ_KIRKWOOD_XOR_11,
583 .end = IRQ_KIRKWOOD_XOR_11,
584 .flags = IORESOURCE_IRQ,
585 },
586};
587
588static struct mv_xor_platform_data kirkwood_xor11_data = {
589 .shared = &kirkwood_xor1_shared,
590 .hw_id = 1,
591 .pool_size = PAGE_SIZE,
592};
593
594static struct platform_device kirkwood_xor11_channel = {
595 .name = MV_XOR_NAME,
596 .id = 3,
597 .num_resources = ARRAY_SIZE(kirkwood_xor11_resources),
598 .resource = kirkwood_xor11_resources,
599 .dev = {
600 .dma_mask = &kirkwood_xor_dmamask,
Yang Hongyang6a355282009-04-06 19:01:13 -0700601 .coherent_dma_mask = DMA_BIT_MASK(64),
H Hartley Sweeten3e3e65f2010-01-29 14:43:52 -0800602 .platform_data = &kirkwood_xor11_data,
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100603 },
604};
605
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500606static void __init kirkwood_xor1_init(void)
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100607{
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200608 kirkwood_clk_ctrl |= CGC_XOR1;
Saeed Bishara09c0ed22008-06-23 04:26:07 -1100609 platform_device_register(&kirkwood_xor1_shared);
610
611 /*
612 * two engines can't do memset simultaneously, this limitation
613 * satisfied by removing memset support from one of the engines.
614 */
615 dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
616 dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
617 platform_device_register(&kirkwood_xor10_channel);
618
619 dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
620 dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
621 dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
622 platform_device_register(&kirkwood_xor11_channel);
623}
624
625
626/*****************************************************************************
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200627 * Watchdog
628 ****************************************************************************/
Nicolas Pitre3b937a72009-06-01 13:56:02 -0400629static struct orion_wdt_platform_data kirkwood_wdt_data = {
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200630 .tclk = 0,
631};
632
633static struct platform_device kirkwood_wdt_device = {
Nicolas Pitre3b937a72009-06-01 13:56:02 -0400634 .name = "orion_wdt",
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200635 .id = -1,
636 .dev = {
637 .platform_data = &kirkwood_wdt_data,
638 },
639 .num_resources = 0,
640};
641
642static void __init kirkwood_wdt_init(void)
643{
644 kirkwood_wdt_data.tclk = kirkwood_tclk;
645 platform_device_register(&kirkwood_wdt_device);
646}
647
648
649/*****************************************************************************
Saeed Bishara651c74c2008-06-22 22:45:06 +0200650 * Time handling
651 ****************************************************************************/
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200652void __init kirkwood_init_early(void)
653{
654 orion_time_set_base(TIMER_VIRT_BASE);
655}
656
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200657int kirkwood_tclk;
658
Nicolas Pitre9b8ebfe2011-03-03 15:08:53 -0500659static int __init kirkwood_find_tclk(void)
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200660{
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300661 u32 dev, rev;
662
663 kirkwood_pcie_id(&dev, &rev);
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300664
Simon Guinot2fa0f932010-10-21 11:42:28 +0200665 if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
666 if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
667 return 200000000;
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300668
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200669 return 166666667;
670}
671
Li Jie6de95c12009-11-05 07:29:54 -0800672static void __init kirkwood_timer_init(void)
Saeed Bishara651c74c2008-06-22 22:45:06 +0200673{
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200674 kirkwood_tclk = kirkwood_find_tclk();
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200675
676 orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
677 IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
Saeed Bishara651c74c2008-06-22 22:45:06 +0200678}
679
680struct sys_timer kirkwood_timer = {
681 .init = kirkwood_timer_init,
682};
683
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200684/*****************************************************************************
685 * Audio
686 ****************************************************************************/
687static struct resource kirkwood_i2s_resources[] = {
688 [0] = {
689 .start = AUDIO_PHYS_BASE,
690 .end = AUDIO_PHYS_BASE + SZ_16K - 1,
691 .flags = IORESOURCE_MEM,
692 },
693 [1] = {
694 .start = IRQ_KIRKWOOD_I2S,
695 .end = IRQ_KIRKWOOD_I2S,
696 .flags = IORESOURCE_IRQ,
697 },
698};
699
700static struct kirkwood_asoc_platform_data kirkwood_i2s_data = {
701 .dram = &kirkwood_mbus_dram_info,
702 .burst = 128,
703};
704
705static struct platform_device kirkwood_i2s_device = {
706 .name = "kirkwood-i2s",
707 .id = -1,
708 .num_resources = ARRAY_SIZE(kirkwood_i2s_resources),
709 .resource = kirkwood_i2s_resources,
710 .dev = {
711 .platform_data = &kirkwood_i2s_data,
712 },
713};
714
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000715static struct platform_device kirkwood_pcm_device = {
Arnaud Patard (Rtp)c88e7b92010-08-30 16:00:05 +0200716 .name = "kirkwood-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000717 .id = -1,
718};
719
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200720void __init kirkwood_audio_init(void)
721{
722 kirkwood_clk_ctrl |= CGC_AUDIO;
723 platform_device_register(&kirkwood_i2s_device);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000724 platform_device_register(&kirkwood_pcm_device);
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200725}
Saeed Bishara651c74c2008-06-22 22:45:06 +0200726
727/*****************************************************************************
728 * General
729 ****************************************************************************/
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300730/*
731 * Identify device ID and revision.
732 */
Saeed Bishara651c74c2008-06-22 22:45:06 +0200733static char * __init kirkwood_id(void)
734{
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300735 u32 dev, rev;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200736
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300737 kirkwood_pcie_id(&dev, &rev);
738
739 if (dev == MV88F6281_DEV_ID) {
740 if (rev == MV88F6281_REV_Z0)
741 return "MV88F6281-Z0";
742 else if (rev == MV88F6281_REV_A0)
743 return "MV88F6281-A0";
Siddarth Goreaec1bad2009-06-09 14:41:02 +0530744 else if (rev == MV88F6281_REV_A1)
745 return "MV88F6281-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300746 else
747 return "MV88F6281-Rev-Unsupported";
748 } else if (dev == MV88F6192_DEV_ID) {
749 if (rev == MV88F6192_REV_Z0)
750 return "MV88F6192-Z0";
751 else if (rev == MV88F6192_REV_A0)
752 return "MV88F6192-A0";
Saeed Bishara1c2003a2010-06-01 18:09:26 +0300753 else if (rev == MV88F6192_REV_A1)
754 return "MV88F6192-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300755 else
756 return "MV88F6192-Rev-Unsupported";
757 } else if (dev == MV88F6180_DEV_ID) {
758 if (rev == MV88F6180_REV_A0)
759 return "MV88F6180-Rev-A0";
Saeed Bishara1c2003a2010-06-01 18:09:26 +0300760 else if (rev == MV88F6180_REV_A1)
761 return "MV88F6180-Rev-A1";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300762 else
763 return "MV88F6180-Rev-Unsupported";
Saeed Bishara1e4d2d32010-06-01 18:09:27 +0300764 } else if (dev == MV88F6282_DEV_ID) {
765 if (rev == MV88F6282_REV_A0)
766 return "MV88F6282-Rev-A0";
767 else
768 return "MV88F6282-Rev-Unsupported";
Ronen Shitritb2b3dc22008-09-15 10:40:35 +0300769 } else {
770 return "Device-Unknown";
771 }
Saeed Bishara651c74c2008-06-22 22:45:06 +0200772}
773
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300774static void __init kirkwood_l2_init(void)
Saeed Bishara13387602008-06-23 01:05:08 -1100775{
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300776#ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
777 writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
778 feroceon_l2_init(1);
779#else
780 writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
781 feroceon_l2_init(0);
782#endif
Saeed Bishara13387602008-06-23 01:05:08 -1100783}
784
Saeed Bishara651c74c2008-06-22 22:45:06 +0200785void __init kirkwood_init(void)
786{
787 printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200788 kirkwood_id(), kirkwood_tclk);
Ronen Shitrit79d4dd72008-09-15 00:56:38 +0200789 kirkwood_spi_plat_data.tclk = kirkwood_tclk;
apatard@mandriva.com49106c72010-05-31 13:49:12 +0200790 kirkwood_i2s_data.tclk = kirkwood_tclk;
Saeed Bishara651c74c2008-06-22 22:45:06 +0200791
Lennert Buytenhek2bf30102009-11-12 20:31:14 +0100792 /*
793 * Disable propagation of mbus errors to the CPU local bus,
794 * as this causes mbus errors (which can occur for example
795 * for PCI aborts) to throw CPU aborts, which we're not set
796 * up to deal with.
797 */
798 writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
799
Saeed Bishara651c74c2008-06-22 22:45:06 +0200800 kirkwood_setup_cpu_mbus();
801
802#ifdef CONFIG_CACHE_FEROCEON_L2
Ronen Shitrit4360bb42008-09-23 15:28:10 +0300803 kirkwood_l2_init();
Saeed Bishara651c74c2008-06-22 22:45:06 +0200804#endif
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500805
806 /* internal devices that every board has */
807 kirkwood_rtc_init();
Thomas Reitmayr054bd3f02009-06-01 13:38:34 +0200808 kirkwood_wdt_init();
Nicolas Pitre5b99d532009-02-26 22:55:59 -0500809 kirkwood_xor0_init();
810 kirkwood_xor1_init();
Nicolas Pitreae5c8c82009-06-03 15:24:36 -0400811 kirkwood_crypto_init();
Eric Cooper9c153642011-02-02 17:16:11 -0500812
813#ifdef CONFIG_KEXEC
814 kexec_reinit = kirkwood_enable_pcie;
815#endif
Saeed Bishara651c74c2008-06-22 22:45:06 +0200816}
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200817
818static int __init kirkwood_clock_gate(void)
819{
820 unsigned int curr = readl(CLOCK_GATING_CTRL);
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300821 u32 dev, rev;
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200822
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300823 kirkwood_pcie_id(&dev, &rev);
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200824 printk(KERN_DEBUG "Gating clock of unused units\n");
825 printk(KERN_DEBUG "before: 0x%08x\n", curr);
826
827 /* Make sure those units are accessible */
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300828 writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL);
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200829
830 /* For SATA: first shutdown the phy */
831 if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
832 /* Disable PLL and IVREF */
833 writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
834 /* Disable PHY */
835 writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
836 }
837 if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
838 /* Disable PLL and IVREF */
839 writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
840 /* Disable PHY */
841 writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
842 }
843
844 /* For PCIe: first shutdown the phy */
845 if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
846 writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
847 while (1)
848 if (readl(PCIE_STATUS) & 0x1)
849 break;
850 writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
851 }
852
Saeed Bisharaffd58bd2010-06-08 14:21:34 +0300853 /* For PCIe 1: first shutdown the phy */
854 if (dev == MV88F6282_DEV_ID) {
855 if (!(kirkwood_clk_ctrl & CGC_PEX1)) {
856 writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
857 while (1)
858 if (readl(PCIE1_STATUS) & 0x1)
859 break;
860 writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
861 }
862 } else /* keep this bit set for devices that don't have PCIe1 */
863 kirkwood_clk_ctrl |= CGC_PEX1;
864
Rabeeh Khourye8b2b7b2009-03-22 17:30:32 +0200865 /* Now gate clock the required units */
866 writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
867 printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
868
869 return 0;
870}
871late_initcall(kirkwood_clock_gate);