diff options
author | Dale Farnsworth <dale@farnsworth.org> | 2007-05-11 20:56:24 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-05-11 21:32:49 -0400 |
commit | 649c8e0289eeee2ab3d4c6c6e062df24dd602233 (patch) | |
tree | b4c0a6de487151e3d137714cee6621e6c1b2d161 /arch/powerpc/sysdev | |
parent | 52d3aff903171af13b56c5a4d6fb828461406c65 (diff) |
[POWERPC] Create Marvell mv64x60 ethernet platform_data
This patch creates platform_device entries for the Marvell mv64x60
ethernet controller ports, based on information contained in the
device tree.
This driver (like the other mv64x60 drivers) are unusual in that it
works on both the MIPS and PowerPC architectures. Because of that,
the drivers do not support the normal PowerPC of_platform_bus_type.
They support platform_bus_type instead.
Signed-off-by: Dale Farnsworth <dale@farnsworth.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/sysdev')
-rw-r--r-- | arch/powerpc/sysdev/mv64x60_dev.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/arch/powerpc/sysdev/mv64x60_dev.c b/arch/powerpc/sysdev/mv64x60_dev.c index 735d20fa586b..0ccc495340bb 100644 --- a/arch/powerpc/sysdev/mv64x60_dev.c +++ b/arch/powerpc/sysdev/mv64x60_dev.c | |||
@@ -201,6 +201,128 @@ error: | |||
201 | return err; | 201 | return err; |
202 | } | 202 | } |
203 | 203 | ||
204 | /* | ||
205 | * Create mv64x60_eth platform devices | ||
206 | */ | ||
207 | static int __init eth_register_shared_pdev(struct device_node *np) | ||
208 | { | ||
209 | struct platform_device *pdev; | ||
210 | struct resource r[1]; | ||
211 | int err; | ||
212 | |||
213 | np = of_get_parent(np); | ||
214 | if (!np) | ||
215 | return -ENODEV; | ||
216 | |||
217 | err = of_address_to_resource(np, 0, &r[0]); | ||
218 | of_node_put(np); | ||
219 | if (err) | ||
220 | return err; | ||
221 | |||
222 | pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, 0, | ||
223 | r, 1); | ||
224 | if (IS_ERR(pdev)) | ||
225 | return PTR_ERR(pdev); | ||
226 | |||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | static int __init mv64x60_eth_device_setup(struct device_node *np, int id) | ||
231 | { | ||
232 | struct resource r[1]; | ||
233 | struct mv643xx_eth_platform_data pdata; | ||
234 | struct platform_device *pdev; | ||
235 | struct device_node *phy; | ||
236 | const u8 *mac_addr; | ||
237 | const int *prop; | ||
238 | const phandle *ph; | ||
239 | int err; | ||
240 | |||
241 | /* only register the shared platform device the first time through */ | ||
242 | if (id == 0 && (err = eth_register_shared_pdev(np))) | ||
243 | return err;; | ||
244 | |||
245 | memset(r, 0, sizeof(r)); | ||
246 | of_irq_to_resource(np, 0, &r[0]); | ||
247 | |||
248 | memset(&pdata, 0, sizeof(pdata)); | ||
249 | |||
250 | prop = of_get_property(np, "block-index", NULL); | ||
251 | if (!prop) | ||
252 | return -ENODEV; | ||
253 | pdata.port_number = *prop; | ||
254 | |||
255 | mac_addr = of_get_mac_address(np); | ||
256 | if (mac_addr) | ||
257 | memcpy(pdata.mac_addr, mac_addr, 6); | ||
258 | |||
259 | prop = of_get_property(np, "speed", NULL); | ||
260 | if (prop) | ||
261 | pdata.speed = *prop; | ||
262 | |||
263 | prop = of_get_property(np, "tx_queue_size", NULL); | ||
264 | if (prop) | ||
265 | pdata.tx_queue_size = *prop; | ||
266 | |||
267 | prop = of_get_property(np, "rx_queue_size", NULL); | ||
268 | if (prop) | ||
269 | pdata.rx_queue_size = *prop; | ||
270 | |||
271 | prop = of_get_property(np, "tx_sram_addr", NULL); | ||
272 | if (prop) | ||
273 | pdata.tx_sram_addr = *prop; | ||
274 | |||
275 | prop = of_get_property(np, "tx_sram_size", NULL); | ||
276 | if (prop) | ||
277 | pdata.tx_sram_size = *prop; | ||
278 | |||
279 | prop = of_get_property(np, "rx_sram_addr", NULL); | ||
280 | if (prop) | ||
281 | pdata.rx_sram_addr = *prop; | ||
282 | |||
283 | prop = of_get_property(np, "rx_sram_size", NULL); | ||
284 | if (prop) | ||
285 | pdata.rx_sram_size = *prop; | ||
286 | |||
287 | ph = of_get_property(np, "phy", NULL); | ||
288 | if (!ph) | ||
289 | return -ENODEV; | ||
290 | |||
291 | phy = of_find_node_by_phandle(*ph); | ||
292 | if (phy == NULL) | ||
293 | return -ENODEV; | ||
294 | |||
295 | prop = of_get_property(phy, "reg", NULL); | ||
296 | if (prop) { | ||
297 | pdata.force_phy_addr = 1; | ||
298 | pdata.phy_addr = *prop; | ||
299 | } | ||
300 | |||
301 | of_node_put(phy); | ||
302 | |||
303 | pdev = platform_device_alloc(MV643XX_ETH_NAME, pdata.port_number); | ||
304 | if (!pdev) | ||
305 | return -ENOMEM; | ||
306 | |||
307 | err = platform_device_add_resources(pdev, r, 1); | ||
308 | if (err) | ||
309 | goto error; | ||
310 | |||
311 | err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); | ||
312 | if (err) | ||
313 | goto error; | ||
314 | |||
315 | err = platform_device_add(pdev); | ||
316 | if (err) | ||
317 | goto error; | ||
318 | |||
319 | return 0; | ||
320 | |||
321 | error: | ||
322 | platform_device_put(pdev); | ||
323 | return err; | ||
324 | } | ||
325 | |||
204 | static int __init mv64x60_device_setup(void) | 326 | static int __init mv64x60_device_setup(void) |
205 | { | 327 | { |
206 | struct device_node *np = NULL; | 328 | struct device_node *np = NULL; |
@@ -212,6 +334,13 @@ static int __init mv64x60_device_setup(void) | |||
212 | if ((err = mv64x60_mpsc_device_setup(np, id))) | 334 | if ((err = mv64x60_mpsc_device_setup(np, id))) |
213 | goto error; | 335 | goto error; |
214 | 336 | ||
337 | for (id = 0; | ||
338 | (np = of_find_compatible_node(np, "network", | ||
339 | "marvell,mv64x60-eth")); | ||
340 | id++) | ||
341 | if ((err = mv64x60_eth_device_setup(np, id))) | ||
342 | goto error; | ||
343 | |||
215 | return 0; | 344 | return 0; |
216 | 345 | ||
217 | error: | 346 | error: |