blob: 15c3f353a9b561c3750ad5b92dca76fac60efcf9 [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>
18#include <net/dsa.h>
Andrew Lunn28a2b452011-05-15 13:32:41 +020019
20/* Fill in the resources structure and link it into the platform
21 device structure. There is always a memory region, and nearly
22 always an interrupt.*/
23static void fill_resources(struct platform_device *device,
24 struct resource *resources,
25 resource_size_t mapbase,
26 resource_size_t size,
27 unsigned int irq)
28{
29 device->resource = resources;
30 device->num_resources = 1;
31 resources[0].flags = IORESOURCE_MEM;
32 resources[0].start = mapbase;
33 resources[0].end = mapbase + size;
34
35 if (irq != NO_IRQ) {
36 device->num_resources++;
37 resources[1].flags = IORESOURCE_IRQ;
38 resources[1].start = irq;
39 resources[1].end = irq;
40 }
41}
42
43/*****************************************************************************
44 * UART
45 ****************************************************************************/
46static void __init uart_complete(
47 struct platform_device *orion_uart,
48 struct plat_serial8250_port *data,
49 struct resource *resources,
50 unsigned int membase,
51 resource_size_t mapbase,
52 unsigned int irq,
53 unsigned int uartclk)
54{
55 data->mapbase = mapbase;
56 data->membase = (void __iomem *)membase;
57 data->irq = irq;
58 data->uartclk = uartclk;
59 orion_uart->dev.platform_data = data;
60
61 fill_resources(orion_uart, resources, mapbase, 0xff, irq);
62 platform_device_register(orion_uart);
63}
64
65/*****************************************************************************
66 * UART0
67 ****************************************************************************/
68static struct plat_serial8250_port orion_uart0_data[] = {
69 {
70 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
71 .iotype = UPIO_MEM,
72 .regshift = 2,
73 }, {
74 },
75};
76
77static struct resource orion_uart0_resources[2];
78
79static struct platform_device orion_uart0 = {
80 .name = "serial8250",
81 .id = PLAT8250_DEV_PLATFORM,
82};
83
84void __init orion_uart0_init(unsigned int membase,
85 resource_size_t mapbase,
86 unsigned int irq,
87 unsigned int uartclk)
88{
89 uart_complete(&orion_uart0, orion_uart0_data, orion_uart0_resources,
90 membase, mapbase, irq, uartclk);
91}
92
93/*****************************************************************************
94 * UART1
95 ****************************************************************************/
96static struct plat_serial8250_port orion_uart1_data[] = {
97 {
98 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
99 .iotype = UPIO_MEM,
100 .regshift = 2,
101 }, {
102 },
103};
104
105static struct resource orion_uart1_resources[2];
106
107static struct platform_device orion_uart1 = {
108 .name = "serial8250",
109 .id = PLAT8250_DEV_PLATFORM1,
110};
111
112void __init orion_uart1_init(unsigned int membase,
113 resource_size_t mapbase,
114 unsigned int irq,
115 unsigned int uartclk)
116{
117 uart_complete(&orion_uart1, orion_uart1_data, orion_uart1_resources,
118 membase, mapbase, irq, uartclk);
119}
120
121/*****************************************************************************
122 * UART2
123 ****************************************************************************/
124static struct plat_serial8250_port orion_uart2_data[] = {
125 {
126 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
127 .iotype = UPIO_MEM,
128 .regshift = 2,
129 }, {
130 },
131};
132
133static struct resource orion_uart2_resources[2];
134
135static struct platform_device orion_uart2 = {
136 .name = "serial8250",
137 .id = PLAT8250_DEV_PLATFORM2,
138};
139
140void __init orion_uart2_init(unsigned int membase,
141 resource_size_t mapbase,
142 unsigned int irq,
143 unsigned int uartclk)
144{
145 uart_complete(&orion_uart2, orion_uart2_data, orion_uart2_resources,
146 membase, mapbase, irq, uartclk);
147}
148
149/*****************************************************************************
150 * UART3
151 ****************************************************************************/
152static struct plat_serial8250_port orion_uart3_data[] = {
153 {
154 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
155 .iotype = UPIO_MEM,
156 .regshift = 2,
157 }, {
158 },
159};
160
161static struct resource orion_uart3_resources[2];
162
163static struct platform_device orion_uart3 = {
164 .name = "serial8250",
165 .id = 3,
166};
167
168void __init orion_uart3_init(unsigned int membase,
169 resource_size_t mapbase,
170 unsigned int irq,
171 unsigned int uartclk)
172{
173 uart_complete(&orion_uart3, orion_uart3_data, orion_uart3_resources,
174 membase, mapbase, irq, uartclk);
175}
Andrew Lunnf6eaccb2011-05-15 13:32:42 +0200176
177/*****************************************************************************
178 * SoC RTC
179 ****************************************************************************/
180static struct resource orion_rtc_resource[2];
181
182void __init orion_rtc_init(unsigned long mapbase,
183 unsigned long irq)
184{
185 orion_rtc_resource[0].start = mapbase;
186 orion_rtc_resource[0].end = mapbase + SZ_32 - 1;
187 orion_rtc_resource[0].flags = IORESOURCE_MEM;
188 orion_rtc_resource[1].start = irq;
189 orion_rtc_resource[1].end = irq;
190 orion_rtc_resource[1].flags = IORESOURCE_IRQ;
191
192 platform_device_register_simple("rtc-mv", -1, orion_rtc_resource, 2);
193}
Andrew Lunn7e3819d2011-05-15 13:32:44 +0200194
195/*****************************************************************************
196 * GE
197 ****************************************************************************/
198static __init void ge_complete(
199 struct mv643xx_eth_shared_platform_data *orion_ge_shared_data,
200 struct mbus_dram_target_info *mbus_dram_info, int tclk,
201 struct resource *orion_ge_resource, unsigned long irq,
202 struct platform_device *orion_ge_shared,
203 struct mv643xx_eth_platform_data *eth_data,
204 struct platform_device *orion_ge)
205{
206 orion_ge_shared_data->dram = mbus_dram_info;
207 orion_ge_shared_data->t_clk = tclk;
208 orion_ge_resource->start = irq;
209 orion_ge_resource->end = irq;
210 eth_data->shared = orion_ge_shared;
211 orion_ge->dev.platform_data = eth_data;
212
213 platform_device_register(orion_ge_shared);
214 platform_device_register(orion_ge);
215}
216
217/*****************************************************************************
218 * GE00
219 ****************************************************************************/
220struct mv643xx_eth_shared_platform_data orion_ge00_shared_data;
221
222static struct resource orion_ge00_shared_resources[] = {
223 {
224 .name = "ge00 base",
225 }, {
226 .name = "ge00 err irq",
227 },
228};
229
230static struct platform_device orion_ge00_shared = {
231 .name = MV643XX_ETH_SHARED_NAME,
232 .id = 0,
233 .dev = {
234 .platform_data = &orion_ge00_shared_data,
235 },
236};
237
238static struct resource orion_ge00_resources[] = {
239 {
240 .name = "ge00 irq",
241 .flags = IORESOURCE_IRQ,
242 },
243};
244
245static struct platform_device orion_ge00 = {
246 .name = MV643XX_ETH_NAME,
247 .id = 0,
248 .num_resources = 1,
249 .resource = orion_ge00_resources,
250 .dev = {
251 .coherent_dma_mask = DMA_BIT_MASK(32),
252 },
253};
254
255void __init orion_ge00_init(struct mv643xx_eth_platform_data *eth_data,
256 struct mbus_dram_target_info *mbus_dram_info,
257 unsigned long mapbase,
258 unsigned long irq,
259 unsigned long irq_err,
260 int tclk)
261{
262 fill_resources(&orion_ge00_shared, orion_ge00_shared_resources,
263 mapbase + 0x2000, SZ_16K - 1, irq_err);
264 ge_complete(&orion_ge00_shared_data, mbus_dram_info, tclk,
265 orion_ge00_resources, irq, &orion_ge00_shared,
266 eth_data, &orion_ge00);
267}
268
269/*****************************************************************************
270 * GE01
271 ****************************************************************************/
272struct mv643xx_eth_shared_platform_data orion_ge01_shared_data = {
273 .shared_smi = &orion_ge00_shared,
274};
275
276static struct resource orion_ge01_shared_resources[] = {
277 {
278 .name = "ge01 base",
279 }, {
280 .name = "ge01 err irq",
281 },
282};
283
284static struct platform_device orion_ge01_shared = {
285 .name = MV643XX_ETH_SHARED_NAME,
286 .id = 1,
287 .dev = {
288 .platform_data = &orion_ge01_shared_data,
289 },
290};
291
292static struct resource orion_ge01_resources[] = {
293 {
294 .name = "ge01 irq",
295 .flags = IORESOURCE_IRQ,
296 },
297};
298
299static struct platform_device orion_ge01 = {
300 .name = MV643XX_ETH_NAME,
301 .id = 1,
302 .num_resources = 1,
303 .resource = orion_ge01_resources,
304 .dev = {
305 .coherent_dma_mask = DMA_BIT_MASK(32),
306 },
307};
308
309void __init orion_ge01_init(struct mv643xx_eth_platform_data *eth_data,
310 struct mbus_dram_target_info *mbus_dram_info,
311 unsigned long mapbase,
312 unsigned long irq,
313 unsigned long irq_err,
314 int tclk)
315{
316 fill_resources(&orion_ge01_shared, orion_ge01_shared_resources,
317 mapbase + 0x2000, SZ_16K - 1, irq_err);
318 ge_complete(&orion_ge01_shared_data, mbus_dram_info, tclk,
319 orion_ge01_resources, irq, &orion_ge01_shared,
320 eth_data, &orion_ge01);
321}
322
323/*****************************************************************************
324 * GE10
325 ****************************************************************************/
326struct mv643xx_eth_shared_platform_data orion_ge10_shared_data = {
327 .shared_smi = &orion_ge00_shared,
328};
329
330static struct resource orion_ge10_shared_resources[] = {
331 {
332 .name = "ge10 base",
333 }, {
334 .name = "ge10 err irq",
335 },
336};
337
338static struct platform_device orion_ge10_shared = {
339 .name = MV643XX_ETH_SHARED_NAME,
340 .id = 1,
341 .dev = {
342 .platform_data = &orion_ge10_shared_data,
343 },
344};
345
346static struct resource orion_ge10_resources[] = {
347 {
348 .name = "ge10 irq",
349 .flags = IORESOURCE_IRQ,
350 },
351};
352
353static struct platform_device orion_ge10 = {
354 .name = MV643XX_ETH_NAME,
355 .id = 1,
356 .num_resources = 2,
357 .resource = orion_ge10_resources,
358 .dev = {
359 .coherent_dma_mask = DMA_BIT_MASK(32),
360 },
361};
362
363void __init orion_ge10_init(struct mv643xx_eth_platform_data *eth_data,
364 struct mbus_dram_target_info *mbus_dram_info,
365 unsigned long mapbase,
366 unsigned long irq,
367 unsigned long irq_err,
368 int tclk)
369{
370 fill_resources(&orion_ge10_shared, orion_ge10_shared_resources,
371 mapbase + 0x2000, SZ_16K - 1, irq_err);
372 ge_complete(&orion_ge10_shared_data, mbus_dram_info, tclk,
373 orion_ge10_resources, irq, &orion_ge10_shared,
374 eth_data, &orion_ge10);
375}
376
377/*****************************************************************************
378 * GE11
379 ****************************************************************************/
380struct mv643xx_eth_shared_platform_data orion_ge11_shared_data = {
381 .shared_smi = &orion_ge00_shared,
382};
383
384static struct resource orion_ge11_shared_resources[] = {
385 {
386 .name = "ge11 base",
387 }, {
388 .name = "ge11 err irq",
389 },
390};
391
392static struct platform_device orion_ge11_shared = {
393 .name = MV643XX_ETH_SHARED_NAME,
394 .id = 1,
395 .dev = {
396 .platform_data = &orion_ge11_shared_data,
397 },
398};
399
400static struct resource orion_ge11_resources[] = {
401 {
402 .name = "ge11 irq",
403 .flags = IORESOURCE_IRQ,
404 },
405};
406
407static struct platform_device orion_ge11 = {
408 .name = MV643XX_ETH_NAME,
409 .id = 1,
410 .num_resources = 2,
411 .resource = orion_ge11_resources,
412 .dev = {
413 .coherent_dma_mask = DMA_BIT_MASK(32),
414 },
415};
416
417void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data,
418 struct mbus_dram_target_info *mbus_dram_info,
419 unsigned long mapbase,
420 unsigned long irq,
421 unsigned long irq_err,
422 int tclk)
423{
424 fill_resources(&orion_ge11_shared, orion_ge11_shared_resources,
425 mapbase + 0x2000, SZ_16K - 1, irq_err);
426 ge_complete(&orion_ge11_shared_data, mbus_dram_info, tclk,
427 orion_ge11_resources, irq, &orion_ge11_shared,
428 eth_data, &orion_ge11);
429}
430
431/*****************************************************************************
432 * Ethernet switch
433 ****************************************************************************/
434static struct resource orion_switch_resources[] = {
435 {
436 .start = 0,
437 .end = 0,
438 .flags = IORESOURCE_IRQ,
439 },
440};
441
442static struct platform_device orion_switch_device = {
443 .name = "dsa",
444 .id = 0,
445 .num_resources = 0,
446 .resource = orion_switch_resources,
447};
448
449void __init orion_ge00_switch_init(struct dsa_platform_data *d, int irq)
450{
451 int i;
452
453 if (irq != NO_IRQ) {
454 orion_switch_resources[0].start = irq;
455 orion_switch_resources[0].end = irq;
456 orion_switch_device.num_resources = 1;
457 }
458
459 d->netdev = &orion_ge00.dev;
460 for (i = 0; i < d->nr_chips; i++)
461 d->chip[i].mii_bus = &orion_ge00_shared.dev;
462 orion_switch_device.dev.platform_data = d;
463
464 platform_device_register(&orion_switch_device);
465}