Re: [PATCH v4 1/7] mdio: mux: Enhanced MDIO mux framework for integrated multiplexers

2016-06-06 Thread Florian Fainelli
On 06/06/2016 05:41 AM, Pramod Kumar wrote:
> An integrated multiplexer uses same address space for
> "muxed bus selection" and "generation of mdio transaction"
> hence its good to register parent bus from mux driver.
> 
> Hence added a mechanism where mux driver could register a
> parent bus and pass it down to framework via mdio_mux_init api.
> 
> Signed-off-by: Pramod Kumar 

Reviewed-by: Florian Fainelli 


> diff --git a/include/linux/mdio-mux.h b/include/linux/mdio-mux.h
> index a243dbb..61f5b21 100644
> --- a/include/linux/mdio-mux.h
> +++ b/include/linux/mdio-mux.h
> @@ -10,11 +10,13 @@
>  #ifndef __LINUX_MDIO_MUX_H
>  #define __LINUX_MDIO_MUX_H
>  #include 
> +#include 

You could have added just a forward declaration, this is a pointer to
the structure so you don't need the compiler to have full knowledge of
the storage type. Not a biggie.
-- 
Florian


Re: [PATCH v4 1/7] mdio: mux: Enhanced MDIO mux framework for integrated multiplexers

2016-06-06 Thread Andrew Lunn
On Mon, Jun 06, 2016 at 06:11:34PM +0530, Pramod Kumar wrote:
> An integrated multiplexer uses same address space for
> "muxed bus selection" and "generation of mdio transaction"
> hence its good to register parent bus from mux driver.
> 
> Hence added a mechanism where mux driver could register a
> parent bus and pass it down to framework via mdio_mux_init api.
> 
> Signed-off-by: Pramod Kumar 

Reviewed-by: Andrew Lunn 

 Andrew


[PATCH v4 1/7] mdio: mux: Enhanced MDIO mux framework for integrated multiplexers

2016-06-06 Thread Pramod Kumar
An integrated multiplexer uses same address space for
"muxed bus selection" and "generation of mdio transaction"
hence its good to register parent bus from mux driver.

Hence added a mechanism where mux driver could register a
parent bus and pass it down to framework via mdio_mux_init api.

Signed-off-by: Pramod Kumar 
---
 drivers/net/phy/mdio-mux-gpio.c|  2 +-
 drivers/net/phy/mdio-mux-mmioreg.c |  2 +-
 drivers/net/phy/mdio-mux.c | 28 ++--
 include/linux/mdio-mux.h   |  4 +++-
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
index 7ddb1ab..9199499 100644
--- a/drivers/net/phy/mdio-mux-gpio.c
+++ b/drivers/net/phy/mdio-mux-gpio.c
@@ -55,7 +55,7 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
return PTR_ERR(s->gpios);
 
r = mdio_mux_init(>dev,
- mdio_mux_gpio_switch_fn, >mux_handle, s);
+ mdio_mux_gpio_switch_fn, >mux_handle, s, NULL);
 
if (r != 0) {
gpiod_put_array(s->gpios);
diff --git a/drivers/net/phy/mdio-mux-mmioreg.c 
b/drivers/net/phy/mdio-mux-mmioreg.c
index 7fde454..d0bed52 100644
--- a/drivers/net/phy/mdio-mux-mmioreg.c
+++ b/drivers/net/phy/mdio-mux-mmioreg.c
@@ -126,7 +126,7 @@ static int mdio_mux_mmioreg_probe(struct platform_device 
*pdev)
}
 
ret = mdio_mux_init(>dev, mdio_mux_mmioreg_switch_fn,
-   >mux_handle, s);
+   >mux_handle, s, NULL);
if (ret) {
dev_err(>dev, "failed to register mdio-mux bus %s\n",
np->full_name);
diff --git a/drivers/net/phy/mdio-mux.c b/drivers/net/phy/mdio-mux.c
index 5c81d6f..dbd4ecc 100644
--- a/drivers/net/phy/mdio-mux.c
+++ b/drivers/net/phy/mdio-mux.c
@@ -89,7 +89,8 @@ static int parent_count;
 int mdio_mux_init(struct device *dev,
  int (*switch_fn)(int cur, int desired, void *data),
  void **mux_handle,
- void *data)
+ void *data,
+ struct mii_bus *mux_bus)
 {
struct device_node *parent_bus_node;
struct device_node *child_bus_node;
@@ -101,10 +102,21 @@ int mdio_mux_init(struct device *dev,
if (!dev->of_node)
return -ENODEV;
 
-   parent_bus_node = of_parse_phandle(dev->of_node, "mdio-parent-bus", 0);
+   if (!mux_bus) {
+   parent_bus_node = of_parse_phandle(dev->of_node,
+  "mdio-parent-bus", 0);
 
-   if (!parent_bus_node)
-   return -ENODEV;
+   if (!parent_bus_node)
+   return -ENODEV;
+
+   parent_bus = of_mdio_find_bus(parent_bus_node);
+   if (!parent_bus) {
+   ret_val = -EPROBE_DEFER;
+   goto err_parent_bus;
+   }
+   } else {
+   parent_bus = mux_bus;
+   }
 
pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL);
if (pb == NULL) {
@@ -112,11 +124,6 @@ int mdio_mux_init(struct device *dev,
goto err_parent_bus;
}
 
-   parent_bus = of_mdio_find_bus(parent_bus_node);
-   if (parent_bus == NULL) {
-   ret_val = -EPROBE_DEFER;
-   goto err_parent_bus;
-   }
 
pb->switch_data = data;
pb->switch_fn = switch_fn;
@@ -177,7 +184,8 @@ int mdio_mux_init(struct device *dev,
put_device(>mii_bus->dev);
 
 err_parent_bus:
-   of_node_put(parent_bus_node);
+   if (!mux_bus)
+   of_node_put(parent_bus_node);
return ret_val;
 }
 EXPORT_SYMBOL_GPL(mdio_mux_init);
diff --git a/include/linux/mdio-mux.h b/include/linux/mdio-mux.h
index a243dbb..61f5b21 100644
--- a/include/linux/mdio-mux.h
+++ b/include/linux/mdio-mux.h
@@ -10,11 +10,13 @@
 #ifndef __LINUX_MDIO_MUX_H
 #define __LINUX_MDIO_MUX_H
 #include 
+#include 
 
 int mdio_mux_init(struct device *dev,
  int (*switch_fn) (int cur, int desired, void *data),
  void **mux_handle,
- void *data);
+ void *data,
+ struct mii_bus *mux_bus);
 
 void mdio_mux_uninit(void *mux_handle);
 
-- 
1.9.1