Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-05 Thread David Brownell
On Wednesday 05 November 2008, Grant Likely wrote:
> >  Maybe the best solution is
> > to write separate driver for OF which will be just wrapper for platform
> > driver... Just like you suggested.

I'd certainly prefer that:  packaging all the OF glue in
a small bit of OF glue code, which doesn't need to affect
the majority of platforms (which don't and won't use OF).


> More complex than necessary.  Just give the driver 2 blocks of binding
> code; one for OF, one for non-OF.  No need to split up the driver.

The preceding discussion pointed out ways the "2 blocks"
approach doesn't currently work well ... minimally, there
is currently no way to do that without much ugly #ifdeffing.

And clearly, you and I view this a bit differently.  I'm
happier to think of these kinds of configuration as one
driver plus *separate* platform glue, while you want to be
modifying every driver to accomodate OF.  Or, by extension,
ACPI and any other hardware abstraction layer that comes
along.

- Dave

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-05 Thread David Brownell
On Wednesday 05 November 2008, Marc Pignat wrote:
> This is why I proposed to split the driver in two parts (gpio only mdio
> driver + OF platform device). Just treating OF GPIO as any other GPIO.

I think that's overall a much cleaner approach too.  Keeps
OF's hardware abstraction layer out of drivers.

But for some reason the OF folk don't like that model.
It comes up repeatedly, with lots of frameworks and their
drivers.

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-05 Thread Grant Likely
On Wed, Nov 5, 2008 at 1:57 AM, Paulius Zaleckas
<[EMAIL PROTECTED]> wrote:
> Mike Frysinger wrote:
>> On Wed, Nov 5, 2008 at 03:11, David Brownell wrote:
>>> On Tuesday 04 November 2008, Mike Frysinger wrote:
> If indeed OF functions don't have declarations which are
> available on all platforms, that might be worth fixing
> to enable this approach to #ifdef elimination.
 OF is open firmware right ?  no way there's going to be OF for every
 port that supports GPIO, so filling out the stubs in linux/of_gpio.h
 will need to be done.
>>> In which case the boolean "we don't have OF" would be "false" and
>>> any code referencing the declared functions would be compiled out
>>> (being dead code/data).  So there would be no link-time references
>>> to any OF routines... standard technique.
>>
>> i understand the compiler side just fine.  my point is that the
>> current linux/of_gpio.h only defines the OF structure and related
>> prototypes when CONFIG_OF_GPIO is defined.  so it needs updating
>> first.
>
> This is small problem compared to what you will find in linux/of_device.h
> It includes  which contains main of_device structure
> and this won't work with any non OF platform.  Maybe the best solution is
> to write separate driver for OF which will be just wrapper for platform
> driver... Just like you suggested.

More complex than necessary.  Just give the driver 2 blocks of binding
code; one for OF, one for non-OF.  No need to split up the driver.

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-05 Thread Paulius Zaleckas
Paulius Zaleckas wrote:
> Mike Frysinger wrote:
>> On Wed, Nov 5, 2008 at 03:11, David Brownell wrote:
>>> On Tuesday 04 November 2008, Mike Frysinger wrote:
> If indeed OF functions don't have declarations which are
> available on all platforms, that might be worth fixing
> to enable this approach to #ifdef elimination.
 OF is open firmware right ?  no way there's going to be OF for every
 port that supports GPIO, so filling out the stubs in linux/of_gpio.h
 will need to be done.
>>> In which case the boolean "we don't have OF" would be "false" and
>>> any code referencing the declared functions would be compiled out
>>> (being dead code/data).  So there would be no link-time references
>>> to any OF routines... standard technique.
>> i understand the compiler side just fine.  my point is that the
>> current linux/of_gpio.h only defines the OF structure and related
>> prototypes when CONFIG_OF_GPIO is defined.  so it needs updating
>> first.
> 
> This is small problem compared to what you will find in linux/of_device.h
> It includes  which contains main of_device structure
> and this won't work with any non OF platform. Maybe the best solution is
> to write separate driver for OF which will be just wrapper for platform
> driver... Just like you suggested.

Oops... Not you, but Marc Pignat suggested.
 
>> -mike
>>
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-05 Thread Paulius Zaleckas
Mike Frysinger wrote:
> On Wed, Nov 5, 2008 at 03:11, David Brownell wrote:
>> On Tuesday 04 November 2008, Mike Frysinger wrote:
 If indeed OF functions don't have declarations which are
 available on all platforms, that might be worth fixing
 to enable this approach to #ifdef elimination.
>>> OF is open firmware right ?  no way there's going to be OF for every
>>> port that supports GPIO, so filling out the stubs in linux/of_gpio.h
>>> will need to be done.
>> In which case the boolean "we don't have OF" would be "false" and
>> any code referencing the declared functions would be compiled out
>> (being dead code/data).  So there would be no link-time references
>> to any OF routines... standard technique.
> 
> i understand the compiler side just fine.  my point is that the
> current linux/of_gpio.h only defines the OF structure and related
> prototypes when CONFIG_OF_GPIO is defined.  so it needs updating
> first.

This is small problem compared to what you will find in linux/of_device.h
It includes  which contains main of_device structure
and this won't work with any non OF platform. Maybe the best solution is
to write separate driver for OF which will be just wrapper for platform
driver... Just like you suggested.

> -mike
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-05 Thread Marc Pignat
On Wednesday 05 November 2008, Mike Frysinger wrote:
...

> i understand the compiler side just fine.  my point is that the
> current linux/of_gpio.h only defines the OF structure and related
> prototypes when CONFIG_OF_GPIO is defined.  so it needs updating
> first.

This is why I proposed to split the driver in two parts (gpio only mdio
driver + OF platform device). Just treating OF GPIO as any other GPIO.

This will remove all #ifdefs, the same code will be used for OF and non-OF
platforms and defining a platform device is not so complicated.



Best regards

Marc
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-05 Thread Mike Frysinger
On Wed, Nov 5, 2008 at 03:11, David Brownell wrote:
> On Tuesday 04 November 2008, Mike Frysinger wrote:
>> > If indeed OF functions don't have declarations which are
>> > available on all platforms, that might be worth fixing
>> > to enable this approach to #ifdef elimination.
>>
>> OF is open firmware right ?  no way there's going to be OF for every
>> port that supports GPIO, so filling out the stubs in linux/of_gpio.h
>> will need to be done.
>
> In which case the boolean "we don't have OF" would be "false" and
> any code referencing the declared functions would be compiled out
> (being dead code/data).  So there would be no link-time references
> to any OF routines... standard technique.

i understand the compiler side just fine.  my point is that the
current linux/of_gpio.h only defines the OF structure and related
prototypes when CONFIG_OF_GPIO is defined.  so it needs updating
first.
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-05 Thread David Brownell
On Tuesday 04 November 2008, Mike Frysinger wrote:
> > If indeed OF functions don't have declarations which are
> > available on all platforms, that might be worth fixing
> > to enable this approach to #ifdef elimination.
> 
> OF is open firmware right ?  no way there's going to be OF for every
> port that supports GPIO, so filling out the stubs in linux/of_gpio.h
> will need to be done.

In which case the boolean "we don't have OF" would be "false" and
any code referencing the declared functions would be compiled out
(being dead code/data).  So there would be no link-time references
to any OF routines... standard technique.


--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-04 Thread Mike Frysinger
On Tue, Nov 4, 2008 at 23:45, David Brownell wrote:
> On Tuesday 04 November 2008, Mike Frysinger wrote:
>> > That's generally the preferred way to handle #ifdeffery.
>> > But I could imagine OF isn't (yet?) set up to handle it.
>>
>> i agree completely with the inclination to do it all in C as you've
>> suggested and let the compiler do dead code elimination, but that only
>> works if the functions in question are defined everywhere (in other
>> words, there's a linux/ api for it).  i dont think that's the case for
>> OF (which is what you were implying?) ...
>
> Only works if the functions are "declared" everywhere;
> the stuff that's included in header files.
>
> A "definition" would be available at link time (except
> for inlined functions, in headers).  Actual C functions.
>
> If indeed OF functions don't have declarations which are
> available on all platforms, that might be worth fixing
> to enable this approach to #ifdef elimination.

OF is open firmware right ?  no way there's going to be OF for every
port that supports GPIO, so filling out the stubs in linux/of_gpio.h
will need to be done.
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-04 Thread David Brownell
On Tuesday 04 November 2008, Mike Frysinger wrote:
> > That's generally the preferred way to handle #ifdeffery.
> > But I could imagine OF isn't (yet?) set up to handle it.
> 
> i agree completely with the inclination to do it all in C as you've
> suggested and let the compiler do dead code elimination, but that only
> works if the functions in question are defined everywhere (in other
> words, there's a linux/ api for it).  i dont think that's the case for
> OF (which is what you were implying?) ...

Only works if the functions are "declared" everywhere;
the stuff that's included in header files.

A "definition" would be available at link time (except
for inlined functions, in headers).  Actual C functions.

If indeed OF functions don't have declarations which are
available on all platforms, that might be worth fixing
to enable this approach to #ifdef elimination.

- Dave


--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-04 Thread Mike Frysinger
On Tue, Nov 4, 2008 at 19:04, David Brownell wrote:
> On Tuesday 04 November 2008, Grant Likely wrote:
>> At this point, instead of #ifdeffing the function signature, I would
>> much rather see this generalized as something like
>> 'mdio_gpio_setup()'.  Then move the OF and non-OF specific bits into
>> two new functions; mdio_ofgpio_probe() and mdio_gpio_probe().  The two
>> new functions should be placed with the appropriate bus binding in the
>> #ifdef/#else block at the bottom of the file.
>
> Or if possible something that creates a single #ifdef that
> ensures dead code elimination will remove the "other" branch,
> but ensures all platforms will build both versions:
>
>#ifdef OF
>#define using_oftrue
>#else
>#define using_offalse
>#endif
>
>...
>
>static int __init mdio_gpio_init(void)
>{
>if (using_of)
>return register mdio_ofgpio driver;
>else
>return register mdio_gpio driver;
>}
>subsys_initcall(mdio_gpio_init);
>
>...
>
> That's generally the preferred way to handle #ifdeffery.
> But I could imagine OF isn't (yet?) set up to handle it.

i agree completely with the inclination to do it all in C as you've
suggested and let the compiler do dead code elimination, but that only
works if the functions in question are defined everywhere (in other
words, there's a linux/ api for it).  i dont think that's the case for
OF (which is what you were implying?) ...
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-04 Thread David Brownell
On Tuesday 04 November 2008, Grant Likely wrote:
> At this point, instead of #ifdeffing the function signature, I would
> much rather see this generalized as something like
> 'mdio_gpio_setup()'.  Then move the OF and non-OF specific bits into
> two new functions; mdio_ofgpio_probe() and mdio_gpio_probe().  The two
> new functions should be placed with the appropriate bus binding in the
> #ifdef/#else block at the bottom of the file.

Or if possible something that creates a single #ifdef that
ensures dead code elimination will remove the "other" branch,
but ensures all platforms will build both versions:

#ifdef OF
#define using_oftrue
#else
#define using_offalse
#endif

...

static int __init mdio_gpio_init(void)
{
if (using_of)
return register mdio_ofgpio driver;
else
return register mdio_gpio driver;
}
subsys_initcall(mdio_gpio_init);

...

That's generally the preferred way to handle #ifdeffery.
But I could imagine OF isn't (yet?) set up to handle it.

- Dave
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-04 Thread Grant Likely
On Tue, Nov 4, 2008 at 7:45 AM, Paulius Zaleckas
<[EMAIL PROTECTED]> wrote:
> make mdio-gpio work with non OpenFirmware gpio implementation.
>
> Aditional changes to mdio-gpio:
> - use gpio_request() and gpio_free()
> - place irq[] array in struct mdio_gpio_info
> - add module description, author and license
> - add note about compiling this driver as module
> - rename mdc and mdio function (were ugly names)
> - change MII to MDIO in bus name
> - add __init __exit to module (un)loading functions
> - probe fails if no phys added to the bus
> - kzalloc bitbang with sizeof(*bitbang)
>
> Changes since v1:
> - removed NO_IRQ
> - reduced #idefs

I like this better, but I have a few more comments below.  I'd like to
see the #ifdefs reduced even more.

> +#ifdef CONFIG_OF_GPIO
>  static int __devinit mdio_ofgpio_probe(struct of_device *ofdev,
> const struct of_device_id *match)
>  {
>struct device_node *np = NULL;
> +   struct device *dev = &ofdev->dev;
> +#else
> +static int __devinit mdio_gpio_probe(struct platform_device *pdev)
> +{
> +   struct mdio_gpio_platform_data *pdata;
> +   struct device *dev = &pdev->dev;
> +#endif

At this point, instead of #ifdeffing the function signature, I would
much rather see this generalized as something like
'mdio_gpio_setup()'.  Then move the OF and non-OF specific bits into
two new functions; mdio_ofgpio_probe() and mdio_gpio_probe().  The two
new functions should be placed with the appropriate bus binding in the
#ifdef/#else block at the bottom of the file.

Separating it in this way will keep the two separate binding code
paths easier to read and understand.

> +#ifdef CONFIG_OF_GPIO
> +   bitbang->mdc = of_get_gpio(ofdev->node, 0);
> +   bitbang->mdio = of_get_gpio(ofdev->node, 1);
> +
> +   if (bitbang->mdc < 0 || bitbang->mdio < 0)
> +   goto out_free_bus;
> +
> +   snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", bitbang->mdc);
>
>while ((np = of_get_next_child(ofdev->node, np)))
> -   if (!strcmp(np->type, "ethernet-phy"))
> -   add_phy(new_bus, np);
> +   if (!strcmp(np->type, "ethernet-phy")) {
> +   const u32 *data;
> +   int len;
> +
> +   data = of_get_property(np, "reg", &len);
> +   if (!data || len != 4)
> +   continue;
> +
> +   add_phy(new_bus, *data,
> +   of_irq_to_resource(np, 0, NULL));
> +   }
> +#else
> +   pdata = dev->platform_data;
> +   if (pdata == NULL)
> +   goto out_free_bus;
> +
> +   bitbang->mdc = pdata->mdc;
> +   bitbang->mdio = pdata->mdio;
>
> -   new_bus->parent = &ofdev->dev;
> -   dev_set_drvdata(&ofdev->dev, new_bus);
> +   snprintf(new_bus->id, MII_BUS_ID_SIZE, "phy%i", pdev->id);
> +
> +   for (i = 0; i < pdata->nr_phys; i++)
> +   add_phy(new_bus, pdata->phys[i].addr, pdata->phys[i].irq);
> +#endif

These are the bits to factor out into binding specific probe()
functions.  I want to see the data interpretation code (probe)
separated from the driver setup code.

Otherwise, this looks good to me.

g.

> +
> +   if (new_bus->phy_mask == ~0)
> +   goto out_free_bus;
> +
> +   if (gpio_request(bitbang->mdc, "mdc"))
> +   goto out_free_bus;
> +
> +   if (gpio_request(bitbang->mdio, "mdio"))
> +   goto out_free_mdc;
> +
> +   dev_set_drvdata(dev, new_bus);
>
>ret = mdiobus_register(new_bus);
>if (ret)
> -   goto out_free_irqs;
> +   goto out_free_all;
>
>return 0;
>
> -out_free_irqs:
> -   dev_set_drvdata(&ofdev->dev, NULL);
> -   kfree(new_bus->irq);
> +out_free_all:
> +   dev_set_drvdata(dev, NULL);
> +   gpio_free(bitbang->mdio);
> +out_free_mdc:
> +   gpio_free(bitbang->mdc);
>  out_free_bus:
>free_mdio_bitbang(new_bus);
>  out_free_bitbang:
> @@ -162,20 +202,29 @@ out:
>return ret;
>  }
>
> +#ifdef CONFIG_OF_GPIO
>  static int mdio_ofgpio_remove(struct of_device *ofdev)
>  {
> -   struct mii_bus *bus = dev_get_drvdata(&ofdev->dev);
> +   struct device *dev = &ofdev->dev;
> +#else
> +static int __devexit mdio_gpio_remove(struct platform_device *pdev)
> +{
> +   struct device *dev = &pdev->dev;
> +#endif

Ditto here my comments on the probe functions; create binding specific
*_remove() functions and refactor this into a common
mdio_gpio_teardown() function.

> +   struct mii_bus *bus = dev_get_drvdata(dev);
>struct mdio_gpio_info *bitbang = bus->priv;
>
>mdiobus_unregister(bus);
> -   kfree(bus->irq);
>free_mdio_bitbang(bus);
> -   dev_set_drvdata(&ofdev->dev, NULL);
> +   dev_set_drvdata(dev, NULL);
> +   gpio_free(bitbang->mdc);
> +   gpio_free(bitbang->mdio);
>kfree(bitbang);
>

Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-04 Thread Grant Likely
On Tue, Nov 4, 2008 at 8:45 AM, Marc Pignat <[EMAIL PROTECTED]> wrote:
> Hiü
>
> On Tuesday 04 November 2008, Paulius Zaleckas wrote:
>> make mdio-gpio work with non OpenFirmware gpio implementation.
>
> of_gpio.c provides generic gpio compatible gpios.
>
> Why not remove all OF specific code from this file and add another one
> creating the struct mdio_gpio_platform_data using OF specific functions?

This is a very simple driver.  There is no need to split it into two
files.  Have two sections of bus binding (OF and non-OF) is just fine.

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-04 Thread Marc Pignat
Hiü

On Tuesday 04 November 2008, Paulius Zaleckas wrote:
> make mdio-gpio work with non OpenFirmware gpio implementation.

of_gpio.c provides generic gpio compatible gpios.

Why not remove all OF specific code from this file and add another one
creating the struct mdio_gpio_platform_data using OF specific functions?

Best regards

Marc
--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] phylib: make mdio-gpio work without OF (v2)

2008-11-04 Thread Paulius Zaleckas
make mdio-gpio work with non OpenFirmware gpio implementation.

Aditional changes to mdio-gpio:
- use gpio_request() and gpio_free()
- place irq[] array in struct mdio_gpio_info
- add module description, author and license
- add note about compiling this driver as module
- rename mdc and mdio function (were ugly names)
- change MII to MDIO in bus name
- add __init __exit to module (un)loading functions
- probe fails if no phys added to the bus
- kzalloc bitbang with sizeof(*bitbang)

Changes since v1:
- removed NO_IRQ
- reduced #idefs

Laurent, please test this driver under OF.

Signed-off-by: Paulius Zaleckas <[EMAIL PROTECTED]>
Cc: Laurent Pinchart <[EMAIL PROTECTED]>
Cc: Grant Likely <[EMAIL PROTECTED]>
Cc: Mike Frysinger <[EMAIL PROTECTED]>
---

 drivers/net/phy/Kconfig |5 +
 drivers/net/phy/mdio-gpio.c |  194 ++-
 include/linux/mdio-gpio.h   |   30 +++
 3 files changed, 169 insertions(+), 60 deletions(-)
 create mode 100644 include/linux/mdio-gpio.h


diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 0318077..c4c5a2f 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -86,8 +86,11 @@ config MDIO_BITBANG
 
 config MDIO_GPIO
tristate "Support for GPIO lib-based bitbanged MDIO buses"
-   depends on MDIO_BITBANG && OF_GPIO
+   depends on MDIO_BITBANG && GENERIC_GPIO
---help---
  Supports GPIO lib-based MDIO busses.
 
+ To compile this driver as a module, choose M here: the module
+ will be called mdio-gpio.
+
 endif # PHYLIB
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index 2ff9775..bcc2cb7 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -1,9 +1,12 @@
 /*
- * OpenFirmware GPIO based MDIO bitbang driver.
+ * GPIO based MDIO bitbang driver.
+ * Supports OpenFirmware.
  *
  * Copyright (c) 2008 CSE Semaphore Belgium.
  *  by Laurent Pinchart <[EMAIL PROTECTED]>
  *
+ * Copyright (C) 2008, Paulius Zaleckas <[EMAIL PROTECTED]>
+ *
  * Based on earlier work by
  *
  * Copyright (c) 2003 Intracom S.A.
@@ -22,12 +25,19 @@
 #include 
 #include 
 #include 
-#include 
-#include 
+#ifdef CONFIG_OF_GPIO
+# include 
+# include 
+#else
+# include 
+# include 
+# include 
+#endif
 
 struct mdio_gpio_info {
struct mdiobb_ctrl ctrl;
int mdc, mdio;
+   int irq[PHY_MAX_ADDR];
 };
 
 static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
@@ -41,7 +51,7 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
gpio_direction_input(bitbang->mdio);
 }
 
-static int mdio_read(struct mdiobb_ctrl *ctrl)
+static int mdio_get(struct mdiobb_ctrl *ctrl)
 {
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
@@ -49,7 +59,7 @@ static int mdio_read(struct mdiobb_ctrl *ctrl)
return gpio_get_value(bitbang->mdio);
 }
 
-static void mdio(struct mdiobb_ctrl *ctrl, int what)
+static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
 {
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
@@ -57,7 +67,7 @@ static void mdio(struct mdiobb_ctrl *ctrl, int what)
gpio_set_value(bitbang->mdio, what);
 }
 
-static void mdc(struct mdiobb_ctrl *ctrl, int what)
+static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
 {
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
@@ -67,54 +77,46 @@ static void mdc(struct mdiobb_ctrl *ctrl, int what)
 
 static struct mdiobb_ops mdio_gpio_ops = {
.owner = THIS_MODULE,
-   .set_mdc = mdc,
+   .set_mdc = mdc_set,
.set_mdio_dir = mdio_dir,
-   .set_mdio_data = mdio,
-   .get_mdio_data = mdio_read,
+   .set_mdio_data = mdio_set,
+   .get_mdio_data = mdio_get,
 };
 
-static int __devinit mdio_ofgpio_bitbang_init(struct mii_bus *bus,
- struct device_node *np)
+static void __devinit add_phy(struct mii_bus *bus, unsigned int phy_addr,
+ int phy_irq)
 {
-   struct mdio_gpio_info *bitbang = bus->priv;
-
-   bitbang->mdc = of_get_gpio(np, 0);
-   bitbang->mdio = of_get_gpio(np, 1);
-
-   if (bitbang->mdc < 0 || bitbang->mdio < 0)
-   return -ENODEV;
-
-   snprintf(bus->id, MII_BUS_ID_SIZE, "%x", bitbang->mdc);
-   return 0;
-}
-
-static void __devinit add_phy(struct mii_bus *bus, struct device_node *np)
-{
-   const u32 *data;
-   int len, id, irq;
-
-   data = of_get_property(np, "reg", &len);
-   if (!data || len != 4)
+   if (phy_addr >= PHY_MAX_ADDR) {
+   dev_err(bus->parent,
+   "Failed to add phy with invalid address: 0x%x",
+   phy_addr);
return;
+   }
 
-   id = *data;
-   bus->phy_mask &= ~(1 << id);
+   bus->phy_mask &= ~(1 << phy_addr);
 
-   irq = of_irq_to_resource