summaryrefslogtreecommitdiff
path: root/packages/linux/linux-efika-2.6.20/0023-POWERPC-Make-FEC-work-on-the-lite5200.txt
blob: bdbafcb30d04e66cc0bdc296d3174ba6fe5b0570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
From 3c687b616fee5d7097e965fce80f8f8b2b6e14cf Mon Sep 17 00:00:00 2001
From: Grant Likely <grant.likely@secretlab.ca>
Date: Mon, 4 Dec 2006 22:29:03 -0700
Subject: [PATCH] [POWERPC] Make FEC work on the lite5200

This patch may very well break Eth support on the Efika, and it's not
very pretty.  But is works well enough for an NFS rootfs.  This also
makes major bestcomm changes by removing Efika-specific bestcomm
support and porting the arch/ppc bestcomm support driver which
was posted to linuxppc-embedded about a year ago.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 arch/powerpc/Kconfig                   |    5 +
 arch/powerpc/platforms/52xx/Makefile   |    3 +
 arch/powerpc/platforms/52xx/bestcomm.c |   98 ++++++++++-------------
 arch/powerpc/platforms/52xx/bestcomm.h |   13 ++-
 arch/powerpc/platforms/52xx/fec.c      |    1 -
 arch/powerpc/platforms/52xx/lite5200.c |    9 ++
 drivers/net/fec_mpc52xx/Kconfig        |    2 +-
 drivers/net/fec_mpc52xx/fec.c          |  137 +++++++++++++++++++++++++++----
 drivers/net/fec_mpc52xx/fec_phy.c      |    6 ++
 9 files changed, 196 insertions(+), 78 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 8699dad..23d7d73 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -429,6 +429,11 @@ config PPC_MPC52xx
 	bool
 	default n
 
+config PPC_BESTCOMM
+	bool
+	depends on PPC_MPC52xx
+	default y
+
 config PPC_EFIKA
 	bool "bPlan Efika 5k2. MPC5200B based computer"
 	depends on PPC_MULTIPLATFORM && PPC32
diff --git a/arch/powerpc/platforms/52xx/Makefile b/arch/powerpc/platforms/52xx/Makefile
index a46184a..d85ea04 100644
--- a/arch/powerpc/platforms/52xx/Makefile
+++ b/arch/powerpc/platforms/52xx/Makefile
@@ -3,6 +3,9 @@
 #
 ifeq ($(CONFIG_PPC_MERGE),y)
 obj-y				+= mpc52xx_pic.o mpc52xx_common.o
+obj-$(CONFIG_PCI)		+= mpc52xx_pci.o
+obj-$(CONFIG_PPC_BESTCOMM) 	+= bestcomm.o
+obj-$(CONFIG_FEC_MPC52xx)	+= sdma_fec_rx_task.o sdma_fec_tx_task.o fec.o
 endif
 
 obj-$(CONFIG_PPC_EFIKA)		+= efika-setup.o efika-pci.o
diff --git a/arch/powerpc/platforms/52xx/bestcomm.c b/arch/powerpc/platforms/52xx/bestcomm.c
index ef45e02..9935b01 100644
--- a/arch/powerpc/platforms/52xx/bestcomm.c
+++ b/arch/powerpc/platforms/52xx/bestcomm.c
@@ -16,7 +16,6 @@
  *		Andrey Volkov <avolkov@varma-el.com>, Varma Electronics Oy
  */
 
-#include <linux/config.h>
 #include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -24,17 +23,19 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
-#include <linux/device.h>
 
 #include <asm/bug.h>
 #include <asm/io.h>
 #include <asm/mpc52xx.h>
+#include <asm/of_platform.h>
 
 #include "bestcomm.h"
 
-#define DRIVER_NAME		"mpc52xx-sdma"
+#define DRIVER_NAME "mpc52xx-bestcomm"
 
 struct sdma_io sdma;
+struct device_node *sdma_node;
+struct device_node *sram_node;
 
 static spinlock_t sdma_lock = SPIN_LOCK_UNLOCKED;
 
@@ -42,7 +43,8 @@ static spinlock_t sdma_lock = SPIN_LOCK_UNLOCKED;
 void sdma_dump(void)
 {
 	int i;
-	printk("** SDMA registers: pa = %08x, va = %08x\n", sdma.base_reg_addr, sdma.io);
+	printk("** SDMA registers: pa = %.8lx, va = %p\n",
+	       sdma.base_reg_addr, sdma.io);
 	printk("**  taskBar = %08x\n", sdma.io->taskBar);
 	printk("**  currentPointer = %08x\n", sdma.io->currentPointer);
 	printk("**  endPointer = %08x\n", sdma.io->endPointer);
@@ -254,6 +256,7 @@ struct sdma *sdma_alloc(int queue_size)
 	}
 
 	s->num_bd = queue_size;
+	s->node = sdma_node;
 	return s;
 }
 
@@ -264,29 +267,49 @@ void sdma_free(struct sdma *s)
 	kfree(s);
 }
 
-static int __devinit mpc52xx_sdma_probe(struct device *dev)
+static int __init mpc52xx_sdma_init(void)
 {
-	struct platform_device *pdev = to_platform_device(dev);
 	int task;
 	u32 *context;
 	u32 *fdt;
 	struct sdma_tdt *tdt;
-	struct resource *mem_io, *mem_sram;
-	u32 tdt_pa, var_pa, context_pa, fdt_pa; 
+	struct resource mem_io, mem_sram;
+	u32 tdt_pa, var_pa, context_pa, fdt_pa;
 	int ret = -ENODEV;
 
-	mem_io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	mem_sram = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (!mem_io || !mem_sram)
+	/* Find SDMA registers */
+	sdma_node = of_find_compatible_node(NULL, "dma-controller", "mpc52xx-bestcomm");
+	if (!sdma_node) {
+		printk (KERN_ERR DRIVER_NAME ": could not locate SDRAM controller\n");
 		goto out;
+	}
+
+	if ((ret = of_address_to_resource(sdma_node, 0, &mem_io)) != 0) {
+		printk(KERN_ERR "Could not get address of SDMA controller\n");
+		goto out;
+	}
+
+	/* Find SRAM location */
+	sram_node = of_find_compatible_node(NULL, "sram", "mpc52xx-sram");
+	if (!sram_node) {
+		printk (KERN_ERR DRIVER_NAME ": could not locate SRAM\n");
+		goto out;
+	}
+
+	if ((ret = of_address_to_resource(sram_node, 0, &mem_sram)) != 0) {
+		printk(KERN_ERR "Could not get address of SRAM\n");
+		goto out;
+	}
 
-	if (!request_mem_region(mem_io->start, mem_io->end - mem_io->start + 1, DRIVER_NAME)) {
+	/* Map register regions */
+	if (!request_mem_region(mem_io.start, mem_io.end - mem_io.start + 1,
+	                        DRIVER_NAME)) {
 		printk(KERN_ERR DRIVER_NAME " - resource unavailable\n");
 		goto out;
 	}
-	sdma.base_reg_addr = mem_io->start;
+	sdma.base_reg_addr = mem_io.start;
 
-	sdma.io = ioremap_nocache(mem_io->start, sizeof(struct mpc52xx_sdma));
+	sdma.io = ioremap_nocache(mem_io.start, sizeof(struct mpc52xx_sdma));
 
 	if (!sdma.io ) {
 		printk(KERN_ERR DRIVER_NAME " - failed to map sdma regs\n");
@@ -296,14 +319,14 @@ static int __devinit mpc52xx_sdma_probe(struct device *dev)
 
 	SDMA_DUMP_REGS();
 
-	sdma.sram_size = mem_sram->end - mem_sram->start + 1;
-	if (!request_mem_region(mem_sram->start, sdma.sram_size, DRIVER_NAME)) {
+	sdma.sram_size = mem_sram.end - mem_sram.start + 1;
+	if (!request_mem_region(mem_sram.start, sdma.sram_size, DRIVER_NAME)) {
 		printk(KERN_ERR DRIVER_NAME " - resource unavailable\n");
 		goto req_sram_error;
 	}
 
-	sdma.base_sram_addr = mem_sram->start;
-	sdma.sram = ioremap_nocache(mem_sram->start, sdma.sram_size);
+	sdma.base_sram_addr = mem_sram.start;
+	sdma.sram = ioremap_nocache(mem_sram.start, sdma.sram_size);
 	if (!sdma.sram ) {
 		printk(KERN_ERR DRIVER_NAME " - failed to map sdma sram\n");
 		ret = -ENOMEM;
@@ -350,50 +373,17 @@ static int __devinit mpc52xx_sdma_probe(struct device *dev)
 	return 0;
 
 map_sram_error:
-	release_mem_region(mem_sram->start, sdma.sram_size);
+	release_mem_region(mem_sram.start, sdma.sram_size);
 req_sram_error:
 	iounmap(sdma.io);
 map_io_error:
-	release_mem_region(mem_io->start, mem_io->end - mem_io->start + 1);
+	release_mem_region(mem_io.start, mem_io.end - mem_io.start + 1);
 out:
 	printk(KERN_ERR "DMA: MPC52xx BestComm init FAILED !!!\n");
 	return ret;
 }
 
-
-static struct device_driver mpc52xx_sdma_driver = {
-	.owner	  = THIS_MODULE,
-	.name	  = DRIVER_NAME,
-	.bus	  = &platform_bus_type,
-	.probe 	  = mpc52xx_sdma_probe,
-/*	.remove	  = mpc52xx_sdma_remove,	TODO */
-#ifdef CONFIG_PM
-/*	.suspend	= mpc52xx_sdma_suspend,	TODO */
-/*	.resume		= mpc52xx_sdma_resume,	TODO */
-#endif
-};
-
-static int __init
-mpc52xx_sdma_init(void)
-{
-	printk(KERN_INFO "DMA: MPC52xx BestComm driver\n");
-	return driver_register(&mpc52xx_sdma_driver);
-}
-
-#ifdef MODULE
-static void __exit
-mpc52xx_sdma_exit(void)
-{
-	driver_unregister(&mpc52xx_sdma_driver);
-}
-#endif
-
-#ifndef MODULE
- subsys_initcall(mpc52xx_sdma_init);
-#else
- module_init(mpc52xx_sdma_init);
- module_exit(mpc52xx_sdma_exit);
-#endif
+subsys_initcall(mpc52xx_sdma_init);
 
 
 MODULE_DESCRIPTION("Freescale MPC52xx BestComm DMA");
diff --git a/arch/powerpc/platforms/52xx/bestcomm.h b/arch/powerpc/platforms/52xx/bestcomm.h
index 14bf397..bd2619d 100644
--- a/arch/powerpc/platforms/52xx/bestcomm.h
+++ b/arch/powerpc/platforms/52xx/bestcomm.h
@@ -19,6 +19,8 @@
 #ifndef __BESTCOMM_BESTCOMM_H__
 #define __BESTCOMM_BESTCOMM_H__
 
+#include "mpc52xx_pic.h"
+
 /* Buffer Descriptor definitions */
 struct sdma_bd {
 	u32 status;
@@ -70,6 +72,7 @@ struct sdma {
 	u16 num_bd;
 	s16 tasknum;
 	u32 flags;
+	struct device_node *node;
 };
 
 #define SDMA_FLAGS_NONE		0x0000
@@ -116,7 +119,9 @@ struct sdma_tdt {
 
 static inline void sdma_enable_task(int task)
 {
-	DPRINTK("***DMA enable task (%d): tdt = %08x\n",task, sdma.tdt);
+	u16 reg;
+
+	DPRINTK("***DMA enable task (%d): tdt = %p\n",task, sdma.tdt);
 	DPRINTK("***tdt->start   = %08x\n",sdma.tdt[task].start);
 	DPRINTK("***tdt->stop    = %08x\n",sdma.tdt[task].stop);
 	DPRINTK("***tdt->var     = %08x\n",sdma.tdt[task].var);
@@ -127,8 +132,8 @@ static inline void sdma_enable_task(int task)
 	DPRINTK("***tdt->litbase = %08x\n",sdma.tdt[task].litbase);
 	DPRINTK("***--------------\n");
 
-	u16 reg = in_be16(&sdma.io->tcr[task]);
-	DPRINTK("***enable task: &sdma.io->tcr=%08x, reg = %04x\n", &sdma.io->tcr, reg);
+	reg = in_be16(&sdma.io->tcr[task]);
+	DPRINTK("***enable task: &sdma.io->tcr=%p, reg = %04x\n", &sdma.io->tcr, reg);
 	out_be16(&sdma.io->tcr[task],  reg | TASK_ENABLE);
 }
 
@@ -141,7 +146,7 @@ static inline void sdma_disable_task(int task)
 
 static inline int sdma_irq(struct sdma *s)
 {
-	return MPC52xx_SDMA_IRQ_BASE + s->tasknum;
+	return irq_of_parse_and_map(s->node, s->tasknum);
 }
 
 static inline void sdma_enable(struct sdma *s)
diff --git a/arch/powerpc/platforms/52xx/fec.c b/arch/powerpc/platforms/52xx/fec.c
index 8756856..90df6f4 100644
--- a/arch/powerpc/platforms/52xx/fec.c
+++ b/arch/powerpc/platforms/52xx/fec.c
@@ -16,7 +16,6 @@
  *		Andrey Volkov <avolkov@varma-el.com>, Varma Electronics Oy
  */
 
-#include <linux/config.h>
 #include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/arch/powerpc/platforms/52xx/lite5200.c b/arch/powerpc/platforms/52xx/lite5200.c
index 0f21bab..f1bbe24 100644
--- a/arch/powerpc/platforms/52xx/lite5200.c
+++ b/arch/powerpc/platforms/52xx/lite5200.c
@@ -107,6 +107,15 @@ static void __init lite52xx_setup_arch(void)
 	mpc52xx_setup_cpu();	/* Generic */
 	lite52xx_setup_cpu();	/* Platorm specific */
 
+#ifdef CONFIG_PCI
+	np = of_find_node_by_type(np, "pci");
+	if (np)
+		mpc52xx_add_bridge(np);
+
+	//ppc_md.pci_swizzle = common_swizzle;
+	//ppc_md.pci_exclude_device = mpc52xx_exclude_device;
+#endif
+
 #ifdef CONFIG_BLK_DEV_INITRD
 	if (initrd_start)
 		ROOT_DEV = Root_RAM0;
diff --git a/drivers/net/fec_mpc52xx/Kconfig b/drivers/net/fec_mpc52xx/Kconfig
index 098c3fa..b6bce55 100644
--- a/drivers/net/fec_mpc52xx/Kconfig
+++ b/drivers/net/fec_mpc52xx/Kconfig
@@ -11,7 +11,7 @@ config FEC_MPC52xx
 	  Fast Ethernet Controller
 
 config USE_MDIO
-	bool "  Use external Ethernet MII PHY"
+	bool "Use external Ethernet MII PHY"
 	select MII
 	depends FEC_MPC52xx
 	---help---
diff --git a/drivers/net/fec_mpc52xx/fec.c b/drivers/net/fec_mpc52xx/fec.c
index b5f1559..894da79 100644
--- a/drivers/net/fec_mpc52xx/fec.c
+++ b/drivers/net/fec_mpc52xx/fec.c
@@ -30,17 +30,24 @@
 #include <asm/ppcboot.h>
 #include <asm/mpc52xx.h>
 
+#if defined(CONFIG_PPC_MERGE)
+#include <asm/of_device.h>
+#include <asm/of_platform.h>
+#include <platforms/52xx/bestcomm.h>
+#include <platforms/52xx/fec.h>
+#else
 #include <syslib/bestcomm/bestcomm.h>
 #include <syslib/bestcomm/fec.h>
+#endif
 
 #include "fec_phy.h"
 #include "fec.h"
 
 #define DRIVER_NAME "mpc52xx-fec"
 
-static irqreturn_t fec_interrupt(int, void *, struct pt_regs *);
-static irqreturn_t fec_rx_interrupt(int, void *, struct pt_regs *);
-static irqreturn_t fec_tx_interrupt(int, void *, struct pt_regs *);
+static irqreturn_t fec_interrupt(int, void *);
+static irqreturn_t fec_rx_interrupt(int, void *);
+static irqreturn_t fec_tx_interrupt(int, void *);
 static struct net_device_stats *fec_get_stats(struct net_device *);
 static void fec_set_multicast_list(struct net_device *dev);
 static void fec_reinit(struct net_device *dev);
@@ -233,7 +240,7 @@ static int fec_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 /* This handles BestComm transmit task interrupts
  */
-static irqreturn_t fec_tx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t fec_tx_interrupt(int irq, void *dev_id)
 {
 	struct net_device *dev = dev_id;
 	struct fec_priv *priv = (struct fec_priv *)dev->priv;
@@ -259,7 +266,7 @@ static irqreturn_t fec_tx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 	return IRQ_HANDLED;
 }
 
-static irqreturn_t fec_rx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t fec_rx_interrupt(int irq, void *dev_id)
 {
 	struct net_device *dev = dev_id;
 	struct fec_priv *priv = (struct fec_priv *)dev->priv;
@@ -316,7 +323,7 @@ static irqreturn_t fec_rx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 	return IRQ_HANDLED;
 }
 
-static irqreturn_t fec_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t fec_interrupt(int irq, void *dev_id)
 {
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct fec_priv *priv = (struct fec_priv *)dev->priv;
@@ -324,13 +331,18 @@ static irqreturn_t fec_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 	int ievent;
 
 	ievent = in_be32(&fec->ievent);
+	if (!ievent)
+		return IRQ_NONE;
+
 	out_be32(&fec->ievent, ievent);		/* clear pending events */
 
 	if (ievent & (FEC_IEVENT_RFIFO_ERROR | FEC_IEVENT_XFIFO_ERROR)) {
-		if (ievent & FEC_IEVENT_RFIFO_ERROR)
-			printk(KERN_WARNING "FEC_IEVENT_RFIFO_ERROR\n");
-		if (ievent & FEC_IEVENT_XFIFO_ERROR)
-			printk(KERN_WARNING "FEC_IEVENT_XFIFO_ERROR\n");
+		if (net_ratelimit() && (ievent & FEC_IEVENT_RFIFO_ERROR))
+			printk(KERN_WARNING "FEC_IEVENT_RFIFO_ERROR (%.8x)\n",
+			       ievent);
+		if (net_ratelimit() && (ievent & FEC_IEVENT_XFIFO_ERROR))
+			printk(KERN_WARNING "FEC_IEVENT_XFIFO_ERROR (%.8x)\n",
+			       ievent);
 		fec_reinit(dev);
 	}
 	else if (ievent & FEC_IEVENT_MII)
@@ -495,7 +507,9 @@ static void fec_hw_init(struct net_device *dev)
 {
 	struct fec_priv *priv = (struct fec_priv *)dev->priv;
 	struct mpc52xx_fec *fec = priv->fec;
+#if !defined(CONFIG_PPC_MERGE)
 	bd_t *bd = (bd_t *) &__res;
+#endif
 
 	out_be32(&fec->op_pause, 0x00010020);
 	out_be32(&fec->rfifo_cntrl, 0x0f000000);
@@ -507,7 +521,9 @@ static void fec_hw_init(struct net_device *dev)
 	out_be32(&fec->iaddr1, 0x00000000);	/* No individual filter */
 	out_be32(&fec->iaddr2, 0x00000000);	/* No individual filter */
 
+#if !defined(CONFIG_PPC_MERGE)
 	priv->phy_speed = ((bd->bi_ipbfreq >> 20) / 5) << 1;
+#endif
 
 	fec_restart(dev, 0);	/* always use half duplex mode only */
 	/*
@@ -522,7 +538,6 @@ static void fec_reinit(struct net_device *dev)
 {
 	struct fec_priv *priv = (struct fec_priv *)dev->priv;
 	struct mpc52xx_fec *fec = priv->fec;
-	static void fec_update_stat(struct net_device *);
 
 	netif_stop_queue(dev);
 	out_be32(&fec->imask, 0x0);
@@ -551,19 +566,38 @@ static void fec_reinit(struct net_device *dev)
 /* Platform Driver                                                               */
 /* ======================================================================== */
 
+#if defined(CONFIG_PPC_MERGE)
+static int __devinit
+mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
+#else
 static int __devinit
 mpc52xx_fec_probe(struct device *dev)
+#endif
 {
 	int ret;
+#if defined(CONFIG_PPC_MERGE)
+	int rv;
+	struct resource __mem;
+	struct resource *mem = &__mem;
+#else
 	struct platform_device *pdev = to_platform_device(dev);
+	struct resource *mem;
+#endif
 	struct net_device *ndev;
 	struct fec_priv *priv = NULL;
-	struct resource *mem;
 
 	volatile int dbg=0;
 	while(dbg)
 		__asm("nop");
 	/* Reserve FEC control zone */
+#if defined(CONFIG_PPC_MERGE)
+	rv = of_address_to_resource(op->node, 0, mem);
+	if (rv) {
+		printk(KERN_ERR DRIVER_NAME ": "
+			"Error while parsing device node resource\n" );
+		return rv;
+	}
+#else
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if ((mem->end - mem->start + 1) != sizeof(struct mpc52xx_fec)) {
 		printk(KERN_ERR DRIVER_NAME 
@@ -571,7 +605,8 @@ mpc52xx_fec_probe(struct device *dev)
 									mem->end - mem->start + 1, sizeof(struct mpc52xx_fec));
 		return -EINVAL;
 	}
-	
+#endif
+
 	if (!request_mem_region(mem->start, sizeof(struct mpc52xx_fec),
 	                        DRIVER_NAME))
 		return -EBUSY;
@@ -579,6 +614,8 @@ mpc52xx_fec_probe(struct device *dev)
 	/* Get the ether ndev & it's private zone */
 	ndev = alloc_etherdev(sizeof(struct fec_priv));
 	if (!ndev) {
+		printk(KERN_ERR DRIVER_NAME ": "
+			"Can not allocate the ethernet device\n" );
 		ret = -ENOMEM;
 		goto probe_error;
 	}
@@ -609,6 +646,8 @@ mpc52xx_fec_probe(struct device *dev)
 		ioremap(mem->start, sizeof(struct mpc52xx_fec));
 	
 	if (!priv->fec) {
+		printk(KERN_ERR DRIVER_NAME ": "
+			"Can not remap IO memory at 0x%8.8x\n", mem->start );
 		ret = -ENOMEM;
 		goto probe_error;
 	}
@@ -618,6 +657,8 @@ mpc52xx_fec_probe(struct device *dev)
 	priv->tx_sdma = sdma_alloc(FEC_TX_NUM_BD);
 	
 	if (!priv->rx_sdma || !priv->tx_sdma) {
+		printk(KERN_ERR DRIVER_NAME ": "
+			"Can not init SDMA tasks\n" );
 		ret = -ENOMEM;
 		goto probe_error;
 	}
@@ -631,8 +672,13 @@ mpc52xx_fec_probe(struct device *dev)
 		goto probe_error;
 
 	/* Get the IRQ we need one by one */
-		/* Control */
+	/* Control */
+#if defined(CONFIG_PPC_MERGE)
+	ndev->irq = irq_of_parse_and_map(op->node, 0);
+#else
 	ndev->irq = platform_get_irq(pdev, 0);
+#endif
+
 	if (request_irq(ndev->irq, &fec_interrupt, SA_INTERRUPT,
 	                DRIVER_NAME "_ctrl", ndev)) {
 		printk(KERN_ERR DRIVER_NAME ": ctrl interrupt request failed\n");
@@ -641,26 +687,32 @@ mpc52xx_fec_probe(struct device *dev)
 		goto probe_error;
 	}
 
-		/* RX */
+	/* RX */
 	priv->r_irq = sdma_irq(priv->rx_sdma);
 	if (request_irq(priv->r_irq, &fec_rx_interrupt, SA_INTERRUPT,
 	                DRIVER_NAME "_rx", ndev)) {
-		printk(KERN_ERR DRIVER_NAME ": rx interrupt request failed\n");
+		printk(KERN_ERR DRIVER_NAME ": rx request_irq(0x%x) failed\n",
+		       priv->r_irq);
 		ret = -EBUSY;
 		priv->r_irq = -1;	/* Don't try to free it */
 		goto probe_error;
 	}
 
-		/* TX */
+	/* TX */
 	priv->t_irq = sdma_irq(priv->tx_sdma);
 	if (request_irq(priv->t_irq, &fec_tx_interrupt, SA_INTERRUPT,
 	                DRIVER_NAME "_tx", ndev)) {
-		printk(KERN_ERR DRIVER_NAME ": tx interrupt request failed\n");
+		printk(KERN_ERR DRIVER_NAME ": tx request_irq(0x%x) failed\n",
+		       priv->t_irq);
 		ret = -EBUSY;
 		priv->t_irq = -1;	/* Don't try to free it */
 		goto probe_error;
 	}
 
+#if defined(CONFIG_PPC_MERGE)
+	priv->phy_speed = ((mpc52xx_find_ipb_freq(op->node) >> 20) / 5) << 1;
+#endif
+
 	/* MAC address init */
 	if (memcmp(mpc52xx_fec_mac_addr, null_mac, 6) != 0)
 		memcpy(ndev->dev_addr, mpc52xx_fec_mac_addr, 6);
@@ -679,7 +731,11 @@ mpc52xx_fec_probe(struct device *dev)
 	fec_mii_init(ndev);
 	
 	/* We're done ! */
+#if defined(CONFIG_PPC_MERGE)
+	dev_set_drvdata(&op->dev, ndev);
+#else
 	dev_set_drvdata(dev, ndev);
+#endif
 
 	return 0;
 
@@ -705,13 +761,22 @@ probe_error:
 	return ret;
 }
 
+#if defined(CONFIG_PPC_MERGE)
+static int
+mpc52xx_fec_remove(struct of_device *op)
+#else
 static int
 mpc52xx_fec_remove(struct device *dev)
+#endif
 {
 	struct net_device *ndev;
 	struct fec_priv *priv;
 	
+#if defined(CONFIG_PPC_MERGE)
+	ndev = (struct net_device *) dev_get_drvdata(&op->dev);
+#else
 	ndev = (struct net_device *) dev_get_drvdata(dev);
+#endif
 	if (!ndev)
 		return 0;
 	priv = (struct fec_priv *) ndev->priv;
@@ -728,10 +793,37 @@ mpc52xx_fec_remove(struct device *dev)
 
 	free_netdev(ndev);
 	
+#if defined(CONFIG_PPC_MERGE)
+	dev_set_drvdata(&op->dev, NULL);
+#else
 	dev_set_drvdata(dev, NULL);
+#endif
 	return 0;
 }
 
+#if defined(CONFIG_PPC_MERGE)
+static struct of_device_id mpc52xx_fec_of_match[] = {
+	{ .compatible = "mpc5200-ethernet", },
+	{ .compatible = "mpc52xx-fec", },
+	{},
+};
+
+static struct of_platform_driver mpc52xx_fec_driver = {
+	.name = DRIVER_NAME,
+	.owner = THIS_MODULE,
+	.match_table = mpc52xx_fec_of_match,
+	.probe = mpc52xx_fec_probe,
+	.remove = mpc52xx_fec_remove,
+#ifdef CONFIG_PM
+/*	.suspend = mpc52xx_fec_suspend, TODO */
+/*	.resume = mpc52xx_fec_resume, TODO */
+#endif
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+};
+#else
 static struct device_driver mpc52xx_fec_driver = {
 	.name	  = DRIVER_NAME,
 	.bus		= &platform_bus_type,
@@ -742,6 +834,7 @@ static struct device_driver mpc52xx_fec_driver = {
 /*	.resume		= mpc52xx_fec_resume,	TODO */
 #endif
 };
+#endif
 
 /* ======================================================================== */
 /* Module                                                                   */
@@ -750,13 +843,21 @@ static struct device_driver mpc52xx_fec_driver = {
 static int __init
 mpc52xx_fec_init(void)
 {
+#if defined(CONFIG_PPC_MERGE)
+	return of_register_platform_driver(&mpc52xx_fec_driver);
+#else
 	return driver_register(&mpc52xx_fec_driver);
+#endif
 }
 
 static void __exit
 mpc52xx_fec_exit(void)
 {
+#if defined(CONFIG_PPC_MERGE)
+	of_unregister_platform_driver(&mpc52xx_fec_driver);
+#else
 	driver_unregister(&mpc52xx_fec_driver);
+#endif
 }
 
 
diff --git a/drivers/net/fec_mpc52xx/fec_phy.c b/drivers/net/fec_mpc52xx/fec_phy.c
index 2a287de..25e0409 100644
--- a/drivers/net/fec_mpc52xx/fec_phy.c
+++ b/drivers/net/fec_mpc52xx/fec_phy.c
@@ -20,8 +20,14 @@
 #include <linux/mii.h>
 #include <asm/io.h>
 #include <asm/mpc52xx.h>
+
+#ifdef CONFIG_PPC_MERGE
+#include <platforms/52xx/bestcomm.h>
+#else
 #include <syslib/bestcomm/bestcomm.h>
 #include <syslib/bestcomm/fec.h>
+#endif
+
 #include "fec_phy.h"
 #include "fec.h"
 
-- 
1.4.4.2