blob: c8d9257f431b089869bebf951c89289e34acd20a [file] [log] [blame]
Dale Farnsworth52d3aff2007-05-12 10:55:53 +10001/*
2 * Platform device setup for Marvell mv64360/mv64460 host bridges (Discovery)
3 *
4 * Author: Dale Farnsworth <dale@farnsworth.org>
5 *
6 * 2007 (c) MontaVista, Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11
12#include <linux/stddef.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
Mark A. Greer542c98c2007-06-07 10:38:00 +100015#include <linux/console.h>
Dale Farnsworth52d3aff2007-05-12 10:55:53 +100016#include <linux/mv643xx.h>
17#include <linux/platform_device.h>
18
19#include <asm/prom.h>
20
21/*
22 * These functions provide the necessary setup for the mv64x60 drivers.
23 * These drivers are unusual in that they work on both the MIPS and PowerPC
24 * architectures. Because of that, the drivers do not support the normal
25 * PowerPC of_platform_bus_type. They support platform_bus_type instead.
26 */
27
28/*
29 * Create MPSC platform devices
30 */
31static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
32{
33 struct platform_device *pdev;
34 struct resource r[2];
35 struct mpsc_shared_pdata pdata;
36 const phandle *ph;
37 struct device_node *mpscrouting, *mpscintr;
38 int err;
39
40 ph = of_get_property(np, "mpscrouting", NULL);
41 mpscrouting = of_find_node_by_phandle(*ph);
42 if (!mpscrouting)
43 return -ENODEV;
44
45 err = of_address_to_resource(mpscrouting, 0, &r[0]);
46 of_node_put(mpscrouting);
47 if (err)
48 return err;
49
50 ph = of_get_property(np, "mpscintr", NULL);
51 mpscintr = of_find_node_by_phandle(*ph);
52 if (!mpscintr)
53 return -ENODEV;
54
55 err = of_address_to_resource(mpscintr, 0, &r[1]);
56 of_node_put(mpscintr);
57 if (err)
58 return err;
59
60 memset(&pdata, 0, sizeof(pdata));
61
62 pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
63 if (!pdev)
64 return -ENOMEM;
65
66 err = platform_device_add_resources(pdev, r, 2);
67 if (err)
68 goto error;
69
70 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
71 if (err)
72 goto error;
73
74 err = platform_device_add(pdev);
75 if (err)
76 goto error;
77
78 return 0;
79
80error:
81 platform_device_put(pdev);
82 return err;
83}
84
85
86static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
87{
88 struct resource r[5];
89 struct mpsc_pdata pdata;
90 struct platform_device *pdev;
91 const unsigned int *prop;
92 const phandle *ph;
93 struct device_node *sdma, *brg;
94 int err;
95 int port_number;
96
97 /* only register the shared platform device the first time through */
98 if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
99 return err;
100
101 memset(r, 0, sizeof(r));
102
103 err = of_address_to_resource(np, 0, &r[0]);
104 if (err)
105 return err;
106
107 of_irq_to_resource(np, 0, &r[4]);
108
109 ph = of_get_property(np, "sdma", NULL);
110 sdma = of_find_node_by_phandle(*ph);
111 if (!sdma)
112 return -ENODEV;
113
114 of_irq_to_resource(sdma, 0, &r[3]);
115 err = of_address_to_resource(sdma, 0, &r[1]);
116 of_node_put(sdma);
117 if (err)
118 return err;
119
120 ph = of_get_property(np, "brg", NULL);
121 brg = of_find_node_by_phandle(*ph);
122 if (!brg)
123 return -ENODEV;
124
125 err = of_address_to_resource(brg, 0, &r[2]);
126 of_node_put(brg);
127 if (err)
128 return err;
129
Mark A. Greer1791f912008-04-08 08:10:34 +1000130 prop = of_get_property(np, "cell-index", NULL);
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000131 if (!prop)
132 return -ENODEV;
133 port_number = *(int *)prop;
134
135 memset(&pdata, 0, sizeof(pdata));
136
137 pdata.cache_mgmt = 1; /* All current revs need this set */
138
Mark A. Greer1791f912008-04-08 08:10:34 +1000139 pdata.max_idle = 40; /* default */
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000140 prop = of_get_property(np, "max_idle", NULL);
141 if (prop)
142 pdata.max_idle = *prop;
143
144 prop = of_get_property(brg, "current-speed", NULL);
145 if (prop)
146 pdata.default_baud = *prop;
147
148 /* Default is 8 bits, no parity, no flow control */
149 pdata.default_bits = 8;
150 pdata.default_parity = 'n';
151 pdata.default_flow = 'n';
152
153 prop = of_get_property(np, "chr_1", NULL);
154 if (prop)
155 pdata.chr_1_val = *prop;
156
157 prop = of_get_property(np, "chr_2", NULL);
158 if (prop)
159 pdata.chr_2_val = *prop;
160
161 prop = of_get_property(np, "chr_10", NULL);
162 if (prop)
163 pdata.chr_10_val = *prop;
164
165 prop = of_get_property(np, "mpcr", NULL);
166 if (prop)
167 pdata.mpcr_val = *prop;
168
169 prop = of_get_property(brg, "bcr", NULL);
170 if (prop)
171 pdata.bcr_val = *prop;
172
173 pdata.brg_can_tune = 1; /* All current revs need this set */
174
175 prop = of_get_property(brg, "clock-src", NULL);
176 if (prop)
177 pdata.brg_clk_src = *prop;
178
179 prop = of_get_property(brg, "clock-frequency", NULL);
180 if (prop)
181 pdata.brg_clk_freq = *prop;
182
183 pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
184 if (!pdev)
185 return -ENOMEM;
186
187 err = platform_device_add_resources(pdev, r, 5);
188 if (err)
189 goto error;
190
191 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
192 if (err)
193 goto error;
194
195 err = platform_device_add(pdev);
196 if (err)
197 goto error;
198
199 return 0;
200
201error:
202 platform_device_put(pdev);
203 return err;
204}
205
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000206/*
207 * Create mv64x60_eth platform devices
208 */
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000209static struct platform_device * __init mv64x60_eth_register_shared_pdev(
210 struct device_node *np, int id)
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000211{
212 struct platform_device *pdev;
213 struct resource r[1];
214 int err;
215
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000216 err = of_address_to_resource(np, 0, &r[0]);
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000217 if (err)
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000218 return ERR_PTR(err);
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000219
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000220 pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, id,
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000221 r, 1);
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000222 return pdev;
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000223}
224
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000225static int __init mv64x60_eth_device_setup(struct device_node *np, int id,
226 struct platform_device *shared_pdev)
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000227{
228 struct resource r[1];
229 struct mv643xx_eth_platform_data pdata;
230 struct platform_device *pdev;
231 struct device_node *phy;
232 const u8 *mac_addr;
233 const int *prop;
234 const phandle *ph;
235 int err;
236
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000237 memset(r, 0, sizeof(r));
238 of_irq_to_resource(np, 0, &r[0]);
239
240 memset(&pdata, 0, sizeof(pdata));
241
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000242 prop = of_get_property(np, "reg", NULL);
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000243 if (!prop)
244 return -ENODEV;
245 pdata.port_number = *prop;
246
247 mac_addr = of_get_mac_address(np);
248 if (mac_addr)
249 memcpy(pdata.mac_addr, mac_addr, 6);
250
251 prop = of_get_property(np, "speed", NULL);
252 if (prop)
253 pdata.speed = *prop;
254
255 prop = of_get_property(np, "tx_queue_size", NULL);
256 if (prop)
257 pdata.tx_queue_size = *prop;
258
259 prop = of_get_property(np, "rx_queue_size", NULL);
260 if (prop)
261 pdata.rx_queue_size = *prop;
262
263 prop = of_get_property(np, "tx_sram_addr", NULL);
264 if (prop)
265 pdata.tx_sram_addr = *prop;
266
267 prop = of_get_property(np, "tx_sram_size", NULL);
268 if (prop)
269 pdata.tx_sram_size = *prop;
270
271 prop = of_get_property(np, "rx_sram_addr", NULL);
272 if (prop)
273 pdata.rx_sram_addr = *prop;
274
275 prop = of_get_property(np, "rx_sram_size", NULL);
276 if (prop)
277 pdata.rx_sram_size = *prop;
278
279 ph = of_get_property(np, "phy", NULL);
280 if (!ph)
281 return -ENODEV;
282
283 phy = of_find_node_by_phandle(*ph);
284 if (phy == NULL)
285 return -ENODEV;
286
287 prop = of_get_property(phy, "reg", NULL);
288 if (prop) {
289 pdata.force_phy_addr = 1;
290 pdata.phy_addr = *prop;
291 }
292
293 of_node_put(phy);
294
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000295 pdev = platform_device_alloc(MV643XX_ETH_NAME, id);
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000296 if (!pdev)
297 return -ENOMEM;
298
299 err = platform_device_add_resources(pdev, r, 1);
300 if (err)
301 goto error;
302
303 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
304 if (err)
305 goto error;
306
307 err = platform_device_add(pdev);
308 if (err)
309 goto error;
310
311 return 0;
312
313error:
314 platform_device_put(pdev);
315 return err;
316}
317
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000318/*
319 * Create mv64x60_i2c platform devices
320 */
321static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
322{
323 struct resource r[2];
324 struct platform_device *pdev;
325 struct mv64xxx_i2c_pdata pdata;
326 const unsigned int *prop;
327 int err;
328
329 memset(r, 0, sizeof(r));
330
331 err = of_address_to_resource(np, 0, &r[0]);
332 if (err)
333 return err;
334
335 of_irq_to_resource(np, 0, &r[1]);
336
337 memset(&pdata, 0, sizeof(pdata));
338
Mark A. Greer1791f912008-04-08 08:10:34 +1000339 pdata.freq_m = 8; /* default */
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000340 prop = of_get_property(np, "freq_m", NULL);
Remi Machet21dbfd22008-04-22 03:36:48 +1000341 if (prop)
342 pdata.freq_m = *prop;
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000343
Mark A. Greer1791f912008-04-08 08:10:34 +1000344 pdata.freq_m = 3; /* default */
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000345 prop = of_get_property(np, "freq_n", NULL);
Remi Machet21dbfd22008-04-22 03:36:48 +1000346 if (prop)
347 pdata.freq_n = *prop;
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000348
Mark A. Greer1791f912008-04-08 08:10:34 +1000349 pdata.timeout = 1000; /* default: 1 second */
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000350
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000351 pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
352 if (!pdev)
353 return -ENOMEM;
354
355 err = platform_device_add_resources(pdev, r, 2);
356 if (err)
357 goto error;
358
359 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
360 if (err)
361 goto error;
362
363 err = platform_device_add(pdev);
364 if (err)
365 goto error;
366
367 return 0;
368
369error:
370 platform_device_put(pdev);
371 return err;
372}
373
Dale Farnsworth7e07a152007-07-24 11:12:24 -0700374/*
375 * Create mv64x60_wdt platform devices
376 */
377static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
378{
379 struct resource r;
380 struct platform_device *pdev;
381 struct mv64x60_wdt_pdata pdata;
382 const unsigned int *prop;
383 int err;
384
385 err = of_address_to_resource(np, 0, &r);
386 if (err)
387 return err;
388
389 memset(&pdata, 0, sizeof(pdata));
390
Mark A. Greer1791f912008-04-08 08:10:34 +1000391 pdata.timeout = 10; /* Default: 10 seconds */
Dale Farnsworth7e07a152007-07-24 11:12:24 -0700392
393 np = of_get_parent(np);
394 if (!np)
395 return -ENODEV;
396
397 prop = of_get_property(np, "clock-frequency", NULL);
398 of_node_put(np);
399 if (!prop)
400 return -ENODEV;
401 pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
402
403 pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
404 if (!pdev)
405 return -ENOMEM;
406
407 err = platform_device_add_resources(pdev, &r, 1);
408 if (err)
409 goto error;
410
411 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
412 if (err)
413 goto error;
414
415 err = platform_device_add(pdev);
416 if (err)
417 goto error;
418
419 return 0;
420
421error:
422 platform_device_put(pdev);
423 return err;
424}
425
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000426static int __init mv64x60_device_setup(void)
427{
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000428 struct device_node *np, *np2;
429 struct platform_device *pdev;
430 int id, id2;
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000431 int err;
432
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100433 id = 0;
Mark A. Greera1810b42008-04-08 08:09:03 +1000434 for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc")
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100435 if ((err = mv64x60_mpsc_device_setup(np, id++)))
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000436 goto error;
437
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100438 id = 0;
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000439 id2 = 0;
440 for_each_compatible_node(np, NULL, "marvell,mv64360-eth-group") {
441 pdev = mv64x60_eth_register_shared_pdev(np, id++);
442 if (IS_ERR(pdev)) {
443 err = PTR_ERR(pdev);
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000444 goto error;
Dale Farnswortha0916bd2008-04-08 08:11:27 +1000445 }
446 for_each_child_of_node(np, np2) {
447 if (!of_device_is_compatible(np2,
448 "marvell,mv64360-eth"))
449 continue;
450 err = mv64x60_eth_device_setup(np2, id2++, pdev);
451 if (err) {
452 of_node_put(np2);
453 goto error;
454 }
455 }
456 }
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000457
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100458 id = 0;
Mark A. Greera1810b42008-04-08 08:09:03 +1000459 for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c")
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100460 if ((err = mv64x60_i2c_device_setup(np, id++)))
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000461 goto error;
462
Dale Farnsworth7e07a152007-07-24 11:12:24 -0700463 /* support up to one watchdog timer */
Mark A. Greera1810b42008-04-08 08:09:03 +1000464 np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
Dale Farnsworth7e07a152007-07-24 11:12:24 -0700465 if (np) {
466 if ((err = mv64x60_wdt_device_setup(np, id)))
467 goto error;
468 of_node_put(np);
469 }
470
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000471 return 0;
472
473error:
474 of_node_put(np);
475 return err;
476}
477arch_initcall(mv64x60_device_setup);
Mark A. Greer542c98c2007-06-07 10:38:00 +1000478
479static int __init mv64x60_add_mpsc_console(void)
480{
481 struct device_node *np = NULL;
482 const char *prop;
483
484 prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
485 if (prop == NULL)
486 goto not_mpsc;
487
488 np = of_find_node_by_path(prop);
489 if (!np)
490 goto not_mpsc;
491
Mark A. Greera1810b42008-04-08 08:09:03 +1000492 if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
Mark A. Greer542c98c2007-06-07 10:38:00 +1000493 goto not_mpsc;
494
Mark A. Greer1791f912008-04-08 08:10:34 +1000495 prop = of_get_property(np, "cell-index", NULL);
Mark A. Greer542c98c2007-06-07 10:38:00 +1000496 if (!prop)
497 goto not_mpsc;
498
499 add_preferred_console("ttyMM", *(int *)prop, NULL);
500
501not_mpsc:
502 return 0;
503}
504console_initcall(mv64x60_add_mpsc_console);