blob: 2afe79d1a273965c3c845eb592fb351fa2ab62c3 [file] [log] [blame]
Andrew Lunn28a2b452011-05-15 13:32:41 +02001/*
2 * arch/arm/plat-orion/common.c
3 *
4 * Marvell Orion SoC common setup code used by multiple mach-/common.c
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>
Andrew Lunn7e3819d2011-05-15 13:32:44 +020014#include <linux/dma-mapping.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020015#include <linux/serial_8250.h>
Andrew Lunn7e3819d2011-05-15 13:32:44 +020016#include <linux/mbus.h>
17#include <linux/mv643xx_eth.h>
Andrew Lunnaac7ffa2011-05-15 13:32:45 +020018#include <linux/mv643xx_i2c.h>
Andrew Lunn7e3819d2011-05-15 13:32:44 +020019#include <net/dsa.h>
Andrew Lunn980f9f62011-05-15 13:32:46 +020020#include <linux/spi/orion_spi.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020021
22/* Fill in the resources structure and link it into the platform
23 device structure. There is always a memory region, and nearly
24 always an interrupt.*/
25static void fill_resources(struct platform_device *device,
26 struct resource *resources,
27 resource_size_t mapbase,
28 resource_size_t size,
29 unsigned int irq)
30{
31 device->resource = resources;
32 device->num_resources = 1;
33 resources[0].flags = IORESOURCE_MEM;
34 resources[0].start = mapbase;
35 resources[0].end = mapbase + size;
36
37 if (irq != NO_IRQ) {
38 device->num_resources++;
39 resources[1].flags = IORESOURCE_IRQ;
40 resources[1].start = irq;
41 resources[1].end = irq;
42 }
43}
44
45/*****************************************************************************
46 * UART
47 ****************************************************************************/
48static void __init uart_complete(
49 struct platform_device *orion_uart,
50 struct plat_serial8250_port *data,
51 struct resource *resources,
52 unsigned int membase,
53 resource_size_t mapbase,
54 unsigned int irq,
55 unsigned int uartclk)
56{
57 data->mapbase = mapbase;
58 data->membase = (void __iomem *)membase;
59 data->irq = irq;
60 data->uartclk = uartclk;
61 orion_uart->dev.platform_data = data;
62
63 fill_resources(orion_uart, resources, mapbase, 0xff, irq);
64 platform_device_register(orion_uart);
65}
66
67/*****************************************************************************
68 * UART0
69 ****************************************************************************/
70static struct plat_serial8250_port orion_uart0_data[] = {
71 {
72 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
73 .iotype = UPIO_MEM,
74 .regshift = 2,
75 }, {
76 },
77};
78
79static struct resource orion_uart0_resources[2];
80
81static struct platform_device orion_uart0 = {
82 .name = "serial8250",
83 .id = PLAT8250_DEV_PLATFORM,
84};
85
86void __init orion_uart0_init(unsigned int membase,
87 resource_size_t mapbase,
88 unsigned int irq,
89 unsigned int uartclk)
90{
91 uart_complete(&orion_uart0, orion_uart0_data, orion_uart0_resources,
92 membase, mapbase, irq, uartclk);
93}
94
95/*****************************************************************************
96 * UART1
97 ****************************************************************************/
98static struct plat_serial8250_port orion_uart1_data[] = {
99 {
100 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
101 .iotype = UPIO_MEM,
102 .regshift = 2,
103 }, {
104 },
105};
106
107static struct resource orion_uart1_resources[2];
108
109static struct platform_device orion_uart1 = {
110 .name = "serial8250",
111 .id = PLAT8250_DEV_PLATFORM1,
112};
113
114void __init orion_uart1_init(unsigned int membase,
115 resource_size_t mapbase,
116 unsigned int irq,
117 unsigned int uartclk)
118{
119 uart_complete(&orion_uart1, orion_uart1_data, orion_uart1_resources,
120 membase, mapbase, irq, uartclk);
121}
122
123/*****************************************************************************
124 * UART2
125 ****************************************************************************/
126static struct plat_serial8250_port orion_uart2_data[] = {
127 {
128 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
129 .iotype = UPIO_MEM,
130 .regshift = 2,
131 }, {
132 },
133};
134
135static struct resource orion_uart2_resources[2];
136
137static struct platform_device orion_uart2 = {
138 .name = "serial8250",
139 .id = PLAT8250_DEV_PLATFORM2,
140};
141
142void __init orion_uart2_init(unsigned int membase,
143 resource_size_t mapbase,
144 unsigned int irq,
145 unsigned int uartclk)
146{
147 uart_complete(&orion_uart2, orion_uart2_data, orion_uart2_resources,
148 membase, mapbase, irq, uartclk);
149}
150
151/*****************************************************************************
152 * UART3
153 ****************************************************************************/
154static struct plat_serial8250_port orion_uart3_data[] = {
155 {
156 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
157 .iotype = UPIO_MEM,
158 .regshift = 2,
159 }, {
160 },
161};
162
163static struct resource orion_uart3_resources[2];
164
165static struct platform_device orion_uart3 = {
166 .name = "serial8250",
167 .id = 3,
168};
169
170void __init orion_uart3_init(unsigned int membase,
171 resource_size_t mapbase,
172 unsigned int irq,
173 unsigned int uartclk)
174{
175 uart_complete(&orion_uart3, orion_uart3_data, orion_uart3_resources,
176 membase, mapbase, irq, uartclk);
177}
Andrew Lunnf6eaccb2011-05-15 13:32:42 +0200178
179/*****************************************************************************
180 * SoC RTC
181 ****************************************************************************/
182static struct resource orion_rtc_resource[2];
183
184void __init orion_rtc_init(unsigned long mapbase,
185 unsigned long irq)
186{
187 orion_rtc_resource[0].start = mapbase;
188 orion_rtc_resource[0].end = mapbase + SZ_32 - 1;
189 orion_rtc_resource[0].flags = IORESOURCE_MEM;
190 orion_rtc_resource[1].start = irq;
191 orion_rtc_resource[1].end = irq;
192 orion_rtc_resource[1].flags = IORESOURCE_IRQ;
193
194 platform_device_register_simple("rtc-mv", -1, orion_rtc_resource, 2);
195}
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200196
197/*****************************************************************************
198 * GE
199 ****************************************************************************/
200static __init void ge_complete(
201 struct mv643xx_eth_shared_platform_data *orion_ge_shared_data,
202 struct mbus_dram_target_info *mbus_dram_info, int tclk,
203 struct resource *orion_ge_resource, unsigned long irq,
204 struct platform_device *orion_ge_shared,
205 struct mv643xx_eth_platform_data *eth_data,
206 struct platform_device *orion_ge)
207{
208 orion_ge_shared_data->dram = mbus_dram_info;
209 orion_ge_shared_data->t_clk = tclk;
210 orion_ge_resource->start = irq;
211 orion_ge_resource->end = irq;
212 eth_data->shared = orion_ge_shared;
213 orion_ge->dev.platform_data = eth_data;
214
215 platform_device_register(orion_ge_shared);
216 platform_device_register(orion_ge);
217}
218
219/*****************************************************************************
220 * GE00
221 ****************************************************************************/
222struct mv643xx_eth_shared_platform_data orion_ge00_shared_data;
223
224static struct resource orion_ge00_shared_resources[] = {
225 {
226 .name = "ge00 base",
227 }, {
228 .name = "ge00 err irq",
229 },
230};
231
232static struct platform_device orion_ge00_shared = {
233 .name = MV643XX_ETH_SHARED_NAME,
234 .id = 0,
235 .dev = {
236 .platform_data = &orion_ge00_shared_data,
237 },
238};
239
240static struct resource orion_ge00_resources[] = {
241 {
242 .name = "ge00 irq",
243 .flags = IORESOURCE_IRQ,
244 },
245};
246
247static struct platform_device orion_ge00 = {
248 .name = MV643XX_ETH_NAME,
249 .id = 0,
250 .num_resources = 1,
251 .resource = orion_ge00_resources,
252 .dev = {
253 .coherent_dma_mask = DMA_BIT_MASK(32),
254 },
255};
256
257void __init orion_ge00_init(struct mv643xx_eth_platform_data *eth_data,
258 struct mbus_dram_target_info *mbus_dram_info,
259 unsigned long mapbase,
260 unsigned long irq,
261 unsigned long irq_err,
262 int tclk)
263{
264 fill_resources(&orion_ge00_shared, orion_ge00_shared_resources,
265 mapbase + 0x2000, SZ_16K - 1, irq_err);
266 ge_complete(&orion_ge00_shared_data, mbus_dram_info, tclk,
267 orion_ge00_resources, irq, &orion_ge00_shared,
268 eth_data, &orion_ge00);
269}
270
271/*****************************************************************************
272 * GE01
273 ****************************************************************************/
274struct mv643xx_eth_shared_platform_data orion_ge01_shared_data = {
275 .shared_smi = &orion_ge00_shared,
276};
277
278static struct resource orion_ge01_shared_resources[] = {
279 {
280 .name = "ge01 base",
281 }, {
282 .name = "ge01 err irq",
283 },
284};
285
286static struct platform_device orion_ge01_shared = {
287 .name = MV643XX_ETH_SHARED_NAME,
288 .id = 1,
289 .dev = {
290 .platform_data = &orion_ge01_shared_data,
291 },
292};
293
294static struct resource orion_ge01_resources[] = {
295 {
296 .name = "ge01 irq",
297 .flags = IORESOURCE_IRQ,
298 },
299};
300
301static struct platform_device orion_ge01 = {
302 .name = MV643XX_ETH_NAME,
303 .id = 1,
304 .num_resources = 1,
305 .resource = orion_ge01_resources,
306 .dev = {
307 .coherent_dma_mask = DMA_BIT_MASK(32),
308 },
309};
310
311void __init orion_ge01_init(struct mv643xx_eth_platform_data *eth_data,
312 struct mbus_dram_target_info *mbus_dram_info,
313 unsigned long mapbase,
314 unsigned long irq,
315 unsigned long irq_err,
316 int tclk)
317{
318 fill_resources(&orion_ge01_shared, orion_ge01_shared_resources,
319 mapbase + 0x2000, SZ_16K - 1, irq_err);
320 ge_complete(&orion_ge01_shared_data, mbus_dram_info, tclk,
321 orion_ge01_resources, irq, &orion_ge01_shared,
322 eth_data, &orion_ge01);
323}
324
325/*****************************************************************************
326 * GE10
327 ****************************************************************************/
328struct mv643xx_eth_shared_platform_data orion_ge10_shared_data = {
329 .shared_smi = &orion_ge00_shared,
330};
331
332static struct resource orion_ge10_shared_resources[] = {
333 {
334 .name = "ge10 base",
335 }, {
336 .name = "ge10 err irq",
337 },
338};
339
340static struct platform_device orion_ge10_shared = {
341 .name = MV643XX_ETH_SHARED_NAME,
342 .id = 1,
343 .dev = {
344 .platform_data = &orion_ge10_shared_data,
345 },
346};
347
348static struct resource orion_ge10_resources[] = {
349 {
350 .name = "ge10 irq",
351 .flags = IORESOURCE_IRQ,
352 },
353};
354
355static struct platform_device orion_ge10 = {
356 .name = MV643XX_ETH_NAME,
357 .id = 1,
358 .num_resources = 2,
359 .resource = orion_ge10_resources,
360 .dev = {
361 .coherent_dma_mask = DMA_BIT_MASK(32),
362 },
363};
364
365void __init orion_ge10_init(struct mv643xx_eth_platform_data *eth_data,
366 struct mbus_dram_target_info *mbus_dram_info,
367 unsigned long mapbase,
368 unsigned long irq,
369 unsigned long irq_err,
370 int tclk)
371{
372 fill_resources(&orion_ge10_shared, orion_ge10_shared_resources,
373 mapbase + 0x2000, SZ_16K - 1, irq_err);
374 ge_complete(&orion_ge10_shared_data, mbus_dram_info, tclk,
375 orion_ge10_resources, irq, &orion_ge10_shared,
376 eth_data, &orion_ge10);
377}
378
379/*****************************************************************************
380 * GE11
381 ****************************************************************************/
382struct mv643xx_eth_shared_platform_data orion_ge11_shared_data = {
383 .shared_smi = &orion_ge00_shared,
384};
385
386static struct resource orion_ge11_shared_resources[] = {
387 {
388 .name = "ge11 base",
389 }, {
390 .name = "ge11 err irq",
391 },
392};
393
394static struct platform_device orion_ge11_shared = {
395 .name = MV643XX_ETH_SHARED_NAME,
396 .id = 1,
397 .dev = {
398 .platform_data = &orion_ge11_shared_data,
399 },
400};
401
402static struct resource orion_ge11_resources[] = {
403 {
404 .name = "ge11 irq",
405 .flags = IORESOURCE_IRQ,
406 },
407};
408
409static struct platform_device orion_ge11 = {
410 .name = MV643XX_ETH_NAME,
411 .id = 1,
412 .num_resources = 2,
413 .resource = orion_ge11_resources,
414 .dev = {
415 .coherent_dma_mask = DMA_BIT_MASK(32),
416 },
417};
418
419void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data,
420 struct mbus_dram_target_info *mbus_dram_info,
421 unsigned long mapbase,
422 unsigned long irq,
423 unsigned long irq_err,
424 int tclk)
425{
426 fill_resources(&orion_ge11_shared, orion_ge11_shared_resources,
427 mapbase + 0x2000, SZ_16K - 1, irq_err);
428 ge_complete(&orion_ge11_shared_data, mbus_dram_info, tclk,
429 orion_ge11_resources, irq, &orion_ge11_shared,
430 eth_data, &orion_ge11);
431}
432
433/*****************************************************************************
434 * Ethernet switch
435 ****************************************************************************/
436static struct resource orion_switch_resources[] = {
437 {
438 .start = 0,
439 .end = 0,
440 .flags = IORESOURCE_IRQ,
441 },
442};
443
444static struct platform_device orion_switch_device = {
445 .name = "dsa",
446 .id = 0,
447 .num_resources = 0,
448 .resource = orion_switch_resources,
449};
450
451void __init orion_ge00_switch_init(struct dsa_platform_data *d, int irq)
452{
453 int i;
454
455 if (irq != NO_IRQ) {
456 orion_switch_resources[0].start = irq;
457 orion_switch_resources[0].end = irq;
458 orion_switch_device.num_resources = 1;
459 }
460
461 d->netdev = &orion_ge00.dev;
462 for (i = 0; i < d->nr_chips; i++)
463 d->chip[i].mii_bus = &orion_ge00_shared.dev;
464 orion_switch_device.dev.platform_data = d;
465
466 platform_device_register(&orion_switch_device);
467}
Andrew Lunnaac7ffa2011-05-15 13:32:45 +0200468
469/*****************************************************************************
470 * I2C
471 ****************************************************************************/
472static struct mv64xxx_i2c_pdata orion_i2c_pdata = {
473 .freq_n = 3,
474 .timeout = 1000, /* Default timeout of 1 second */
475};
476
477static struct resource orion_i2c_resources[2];
478
479static struct platform_device orion_i2c = {
480 .name = MV64XXX_I2C_CTLR_NAME,
481 .id = 0,
482 .dev = {
483 .platform_data = &orion_i2c_pdata,
484 },
485};
486
487static struct mv64xxx_i2c_pdata orion_i2c_1_pdata = {
488 .freq_n = 3,
489 .timeout = 1000, /* Default timeout of 1 second */
490};
491
492static struct resource orion_i2c_1_resources[2];
493
494static struct platform_device orion_i2c_1 = {
495 .name = MV64XXX_I2C_CTLR_NAME,
496 .id = 1,
497 .dev = {
498 .platform_data = &orion_i2c_1_pdata,
499 },
500};
501
502void __init orion_i2c_init(unsigned long mapbase,
503 unsigned long irq,
504 unsigned long freq_m)
505{
506 orion_i2c_pdata.freq_m = freq_m;
507 fill_resources(&orion_i2c, orion_i2c_resources, mapbase,
508 SZ_32 - 1, irq);
509 platform_device_register(&orion_i2c);
510}
511
512void __init orion_i2c_1_init(unsigned long mapbase,
513 unsigned long irq,
514 unsigned long freq_m)
515{
516 orion_i2c_1_pdata.freq_m = freq_m;
517 fill_resources(&orion_i2c_1, orion_i2c_1_resources, mapbase,
518 SZ_32 - 1, irq);
519 platform_device_register(&orion_i2c_1);
520}
Andrew Lunn980f9f62011-05-15 13:32:46 +0200521
522/*****************************************************************************
523 * SPI
524 ****************************************************************************/
525static struct orion_spi_info orion_spi_plat_data;
526static struct resource orion_spi_resources;
527
528static struct platform_device orion_spi = {
529 .name = "orion_spi",
530 .id = 0,
531 .dev = {
532 .platform_data = &orion_spi_plat_data,
533 },
534};
535
536static struct orion_spi_info orion_spi_1_plat_data;
537static struct resource orion_spi_1_resources;
538
539static struct platform_device orion_spi_1 = {
540 .name = "orion_spi",
541 .id = 1,
542 .dev = {
543 .platform_data = &orion_spi_1_plat_data,
544 },
545};
546
547/* Note: The SPI silicon core does have interrupts. However the
548 * current Linux software driver does not use interrupts. */
549
550void __init orion_spi_init(unsigned long mapbase,
551 unsigned long tclk)
552{
553 orion_spi_plat_data.tclk = tclk;
554 fill_resources(&orion_spi, &orion_spi_resources,
555 mapbase, SZ_512 - 1, NO_IRQ);
556 platform_device_register(&orion_spi);
557}
558
559void __init orion_spi_1_init(unsigned long mapbase,
560 unsigned long tclk)
561{
562 orion_spi_1_plat_data.tclk = tclk;
563 fill_resources(&orion_spi_1, &orion_spi_1_resources,
564 mapbase, SZ_512 - 1, NO_IRQ);
565 platform_device_register(&orion_spi_1);
566}