blob: 90f2c14d5b6099d44ba9405bea58df8d01c6dc6c [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 */
209static int __init eth_register_shared_pdev(struct device_node *np)
210{
211 struct platform_device *pdev;
212 struct resource r[1];
213 int err;
214
215 np = of_get_parent(np);
216 if (!np)
217 return -ENODEV;
218
219 err = of_address_to_resource(np, 0, &r[0]);
220 of_node_put(np);
221 if (err)
222 return err;
223
224 pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, 0,
225 r, 1);
226 if (IS_ERR(pdev))
227 return PTR_ERR(pdev);
228
229 return 0;
230}
231
232static int __init mv64x60_eth_device_setup(struct device_node *np, int id)
233{
234 struct resource r[1];
235 struct mv643xx_eth_platform_data pdata;
236 struct platform_device *pdev;
237 struct device_node *phy;
238 const u8 *mac_addr;
239 const int *prop;
240 const phandle *ph;
241 int err;
242
243 /* only register the shared platform device the first time through */
244 if (id == 0 && (err = eth_register_shared_pdev(np)))
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100245 return err;
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000246
247 memset(r, 0, sizeof(r));
248 of_irq_to_resource(np, 0, &r[0]);
249
250 memset(&pdata, 0, sizeof(pdata));
251
252 prop = of_get_property(np, "block-index", NULL);
253 if (!prop)
254 return -ENODEV;
255 pdata.port_number = *prop;
256
257 mac_addr = of_get_mac_address(np);
258 if (mac_addr)
259 memcpy(pdata.mac_addr, mac_addr, 6);
260
261 prop = of_get_property(np, "speed", NULL);
262 if (prop)
263 pdata.speed = *prop;
264
265 prop = of_get_property(np, "tx_queue_size", NULL);
266 if (prop)
267 pdata.tx_queue_size = *prop;
268
269 prop = of_get_property(np, "rx_queue_size", NULL);
270 if (prop)
271 pdata.rx_queue_size = *prop;
272
273 prop = of_get_property(np, "tx_sram_addr", NULL);
274 if (prop)
275 pdata.tx_sram_addr = *prop;
276
277 prop = of_get_property(np, "tx_sram_size", NULL);
278 if (prop)
279 pdata.tx_sram_size = *prop;
280
281 prop = of_get_property(np, "rx_sram_addr", NULL);
282 if (prop)
283 pdata.rx_sram_addr = *prop;
284
285 prop = of_get_property(np, "rx_sram_size", NULL);
286 if (prop)
287 pdata.rx_sram_size = *prop;
288
289 ph = of_get_property(np, "phy", NULL);
290 if (!ph)
291 return -ENODEV;
292
293 phy = of_find_node_by_phandle(*ph);
294 if (phy == NULL)
295 return -ENODEV;
296
297 prop = of_get_property(phy, "reg", NULL);
298 if (prop) {
299 pdata.force_phy_addr = 1;
300 pdata.phy_addr = *prop;
301 }
302
303 of_node_put(phy);
304
305 pdev = platform_device_alloc(MV643XX_ETH_NAME, pdata.port_number);
306 if (!pdev)
307 return -ENOMEM;
308
309 err = platform_device_add_resources(pdev, r, 1);
310 if (err)
311 goto error;
312
313 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
314 if (err)
315 goto error;
316
317 err = platform_device_add(pdev);
318 if (err)
319 goto error;
320
321 return 0;
322
323error:
324 platform_device_put(pdev);
325 return err;
326}
327
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000328/*
329 * Create mv64x60_i2c platform devices
330 */
331static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
332{
333 struct resource r[2];
334 struct platform_device *pdev;
335 struct mv64xxx_i2c_pdata pdata;
336 const unsigned int *prop;
337 int err;
338
339 memset(r, 0, sizeof(r));
340
341 err = of_address_to_resource(np, 0, &r[0]);
342 if (err)
343 return err;
344
345 of_irq_to_resource(np, 0, &r[1]);
346
347 memset(&pdata, 0, sizeof(pdata));
348
Mark A. Greer1791f912008-04-08 08:10:34 +1000349 pdata.freq_m = 8; /* default */
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000350 prop = of_get_property(np, "freq_m", NULL);
351 if (!prop)
352 return -ENODEV;
353 pdata.freq_m = *prop;
354
Mark A. Greer1791f912008-04-08 08:10:34 +1000355 pdata.freq_m = 3; /* default */
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000356 prop = of_get_property(np, "freq_n", NULL);
357 if (!prop)
358 return -ENODEV;
359 pdata.freq_n = *prop;
360
Mark A. Greer1791f912008-04-08 08:10:34 +1000361 pdata.timeout = 1000; /* default: 1 second */
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000362
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000363 pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
364 if (!pdev)
365 return -ENOMEM;
366
367 err = platform_device_add_resources(pdev, r, 2);
368 if (err)
369 goto error;
370
371 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
372 if (err)
373 goto error;
374
375 err = platform_device_add(pdev);
376 if (err)
377 goto error;
378
379 return 0;
380
381error:
382 platform_device_put(pdev);
383 return err;
384}
385
Dale Farnsworth7e07a152007-07-24 11:12:24 -0700386/*
387 * Create mv64x60_wdt platform devices
388 */
389static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
390{
391 struct resource r;
392 struct platform_device *pdev;
393 struct mv64x60_wdt_pdata pdata;
394 const unsigned int *prop;
395 int err;
396
397 err = of_address_to_resource(np, 0, &r);
398 if (err)
399 return err;
400
401 memset(&pdata, 0, sizeof(pdata));
402
Mark A. Greer1791f912008-04-08 08:10:34 +1000403 pdata.timeout = 10; /* Default: 10 seconds */
Dale Farnsworth7e07a152007-07-24 11:12:24 -0700404
405 np = of_get_parent(np);
406 if (!np)
407 return -ENODEV;
408
409 prop = of_get_property(np, "clock-frequency", NULL);
410 of_node_put(np);
411 if (!prop)
412 return -ENODEV;
413 pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
414
415 pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
416 if (!pdev)
417 return -ENOMEM;
418
419 err = platform_device_add_resources(pdev, &r, 1);
420 if (err)
421 goto error;
422
423 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
424 if (err)
425 goto error;
426
427 err = platform_device_add(pdev);
428 if (err)
429 goto error;
430
431 return 0;
432
433error:
434 platform_device_put(pdev);
435 return err;
436}
437
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000438static int __init mv64x60_device_setup(void)
439{
440 struct device_node *np = NULL;
441 int id;
442 int err;
443
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100444 id = 0;
Mark A. Greera1810b42008-04-08 08:09:03 +1000445 for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc")
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100446 if ((err = mv64x60_mpsc_device_setup(np, id++)))
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000447 goto error;
448
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100449 id = 0;
Mark A. Greera1810b42008-04-08 08:09:03 +1000450 for_each_compatible_node(np, "network", "marvell,mv64360-eth")
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100451 if ((err = mv64x60_eth_device_setup(np, id++)))
Dale Farnsworth649c8e02007-05-12 10:56:24 +1000452 goto error;
453
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100454 id = 0;
Mark A. Greera1810b42008-04-08 08:09:03 +1000455 for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c")
Cyrill Gorcunov26cb7d82007-11-30 06:44:36 +1100456 if ((err = mv64x60_i2c_device_setup(np, id++)))
Dale Farnsworth01f0e782007-05-12 10:56:47 +1000457 goto error;
458
Dale Farnsworth7e07a152007-07-24 11:12:24 -0700459 /* support up to one watchdog timer */
Mark A. Greera1810b42008-04-08 08:09:03 +1000460 np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
Dale Farnsworth7e07a152007-07-24 11:12:24 -0700461 if (np) {
462 if ((err = mv64x60_wdt_device_setup(np, id)))
463 goto error;
464 of_node_put(np);
465 }
466
Dale Farnsworth52d3aff2007-05-12 10:55:53 +1000467 return 0;
468
469error:
470 of_node_put(np);
471 return err;
472}
473arch_initcall(mv64x60_device_setup);
Mark A. Greer542c98c2007-06-07 10:38:00 +1000474
475static int __init mv64x60_add_mpsc_console(void)
476{
477 struct device_node *np = NULL;
478 const char *prop;
479
480 prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
481 if (prop == NULL)
482 goto not_mpsc;
483
484 np = of_find_node_by_path(prop);
485 if (!np)
486 goto not_mpsc;
487
Mark A. Greera1810b42008-04-08 08:09:03 +1000488 if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
Mark A. Greer542c98c2007-06-07 10:38:00 +1000489 goto not_mpsc;
490
Mark A. Greer1791f912008-04-08 08:10:34 +1000491 prop = of_get_property(np, "cell-index", NULL);
Mark A. Greer542c98c2007-06-07 10:38:00 +1000492 if (!prop)
493 goto not_mpsc;
494
495 add_preferred_console("ttyMM", *(int *)prop, NULL);
496
497not_mpsc:
498 return 0;
499}
500console_initcall(mv64x60_add_mpsc_console);