netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: net: phy: mdio-mux: Add support for Generic Mux controls
@ 2019-02-21 13:00 Pankaj Bansal
  2019-02-21 13:42 ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: Pankaj Bansal @ 2019-02-21 13:00 UTC (permalink / raw)
  To: Leo Li, Peter Rosin, Andrew Lunn, Florian Fainelli, Heiner Kallweit
  Cc: netdev, Pankaj Bansal

Add support for Generic Mux controls, when Mdio mux node is a consumer
of mux produced by some other device.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---
 drivers/net/phy/Kconfig    |  1 +
 drivers/net/phy/mdio-mux.c | 81 ++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 3d187cd50eb0..e0e6b2b33d6d 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -47,6 +47,7 @@ config MDIO_BITBANG
 config MDIO_BUS_MUX
 	tristate
 	depends on OF_MDIO
+	select MULTIPLEXER
 	help
 	  This module provides a driver framework for MDIO bus
 	  multiplexers which connect one of several child MDIO busses
diff --git a/drivers/net/phy/mdio-mux.c b/drivers/net/phy/mdio-mux.c
index 0a86f1e4c02f..c49e4ae9c174 100644
--- a/drivers/net/phy/mdio-mux.c
+++ b/drivers/net/phy/mdio-mux.c
@@ -11,6 +11,7 @@
 #include <linux/of_mdio.h>
 #include <linux/device.h>
 #include <linux/module.h>
+#include <linux/mux/consumer.h>
 #include <linux/phy.h>
 
 #define DRV_DESCRIPTION "MDIO bus multiplexer driver"
@@ -35,6 +36,11 @@ struct mdio_mux_child_bus {
 	int bus_number;
 };
 
+struct mdio_mux_state {
+	struct mux_control *muxc;
+	void *mux_handle;
+};
+
 /*
  * The parent bus' lock is used to order access to the switch_fn.
  */
@@ -208,6 +214,81 @@ void mdio_mux_uninit(void *mux_handle)
 }
 EXPORT_SYMBOL_GPL(mdio_mux_uninit);
 
+static int mdio_mux_switch_fn(int current_child, int desired_child, void *data)
+{
+	struct platform_device *pdev;
+	struct mdio_mux_state *s;
+	int ret = 0;
+
+	pdev = (struct platform_device *)data;
+	s = (struct mdio_mux_state *)platform_get_drvdata(pdev);
+	if (current_child ^ desired_child) {
+		if (current_child != -1)
+			ret = mux_control_deselect(s->muxc);
+		if (ret)
+			return ret;
+
+		ret =  mux_control_select(s->muxc, desired_child);
+		if (!ret)
+			dev_dbg(&pdev->dev, "%s %d -> %d\n", __func__,
+				current_child, desired_child);
+	}
+
+	return ret;
+}
+
+static int mdio_mux_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct mdio_mux_state *s;
+	int ret = 0;
+
+	s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
+	if (!s)
+		return -ENOMEM;
+
+	s->muxc = devm_mux_control_get(dev, NULL);
+	if (IS_ERR(s->muxc)) {
+		ret = PTR_ERR(s->muxc);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Failed to get mux: %d\n", ret);
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, s);
+
+	ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node, mdio_mux_switch_fn,
+			    &s->mux_handle, pdev, NULL);
+
+	return ret;
+}
+
+static int mdio_mux_remove(struct platform_device *pdev)
+{
+	struct mdio_mux_state *s = platform_get_drvdata(pdev);
+
+	mdio_mux_uninit(s->mux_handle);
+
+	return 0;
+}
+
+static const struct of_device_id mdio_mux_match[] = {
+	{ .compatible = "mdio-mux", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, mdio_mux_match);
+
+static struct platform_driver mdio_mux_driver = {
+	.driver = {
+		.name		= "mdio-mux",
+		.of_match_table	= mdio_mux_match,
+	},
+	.probe		= mdio_mux_probe,
+	.remove		= mdio_mux_remove,
+};
+
+module_platform_driver(mdio_mux_driver);
+
 MODULE_DESCRIPTION(DRV_DESCRIPTION);
 MODULE_AUTHOR("David Daney");
 MODULE_LICENSE("GPL");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers: net: phy: mdio-mux: Add support for Generic Mux controls
  2019-02-21 13:00 [PATCH] drivers: net: phy: mdio-mux: Add support for Generic Mux controls Pankaj Bansal
@ 2019-02-21 13:42 ` Andrew Lunn
  2019-02-21 14:15   ` Pankaj Bansal
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2019-02-21 13:42 UTC (permalink / raw)
  To: Pankaj Bansal
  Cc: Leo Li, Peter Rosin, Florian Fainelli, Heiner Kallweit, netdev

On Thu, Feb 21, 2019 at 01:00:44PM +0000, Pankaj Bansal wrote:
> Add support for Generic Mux controls, when Mdio mux node is a consumer
> of mux produced by some other device.
> 
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
>  drivers/net/phy/Kconfig    |  1 +
>  drivers/net/phy/mdio-mux.c | 81 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 82 insertions(+)
> 
> diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
> index 3d187cd50eb0..e0e6b2b33d6d 100644
> --- a/drivers/net/phy/Kconfig
> +++ b/drivers/net/phy/Kconfig
> @@ -47,6 +47,7 @@ config MDIO_BITBANG
>  config MDIO_BUS_MUX
>  	tristate
>  	depends on OF_MDIO
> +	select MULTIPLEXER
>  	help
>  	  This module provides a driver framework for MDIO bus
>  	  multiplexers which connect one of several child MDIO busses

Hi Pankaj

Please add a MDIO_BUS_MUX_MULTIPLEXER and put all the code into
mdio-mux-multiplexer.c

> +static const struct of_device_id mdio_mux_match[] = {
> +	{ .compatible = "mdio-mux", },

mdio-mux-multiplexer

Thanks
	Andrew


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] drivers: net: phy: mdio-mux: Add support for Generic Mux controls
  2019-02-21 13:42 ` Andrew Lunn
@ 2019-02-21 14:15   ` Pankaj Bansal
  2019-02-21 15:17     ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: Pankaj Bansal @ 2019-02-21 14:15 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Leo Li, Peter Rosin, Florian Fainelli, Heiner Kallweit, netdev



> -----Original Message-----
> From: Andrew Lunn [mailto:andrew@lunn.ch]
> Sent: Thursday, 21 February, 2019 07:12 PM
> To: Pankaj Bansal <pankaj.bansal@nxp.com>
> Cc: Leo Li <leoyang.li@nxp.com>; Peter Rosin <peda@axentia.se>; Florian
> Fainelli <f.fainelli@gmail.com>; Heiner Kallweit <hkallweit1@gmail.com>;
> netdev@vger.kernel.org
> Subject: Re: [PATCH] drivers: net: phy: mdio-mux: Add support for Generic Mux
> controls
> 
> On Thu, Feb 21, 2019 at 01:00:44PM +0000, Pankaj Bansal wrote:
> > Add support for Generic Mux controls, when Mdio mux node is a consumer
> > of mux produced by some other device.
> >
> > Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> > ---
> >  drivers/net/phy/Kconfig    |  1 +
> >  drivers/net/phy/mdio-mux.c | 81 ++++++++++++++++++++++++++++++++++++
> >  2 files changed, 82 insertions(+)
> >
> > diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index
> > 3d187cd50eb0..e0e6b2b33d6d 100644
> > --- a/drivers/net/phy/Kconfig
> > +++ b/drivers/net/phy/Kconfig
> > @@ -47,6 +47,7 @@ config MDIO_BITBANG
> >  config MDIO_BUS_MUX
> >  	tristate
> >  	depends on OF_MDIO
> > +	select MULTIPLEXER
> >  	help
> >  	  This module provides a driver framework for MDIO bus
> >  	  multiplexers which connect one of several child MDIO busses
> 
> Hi Pankaj
> 
> Please add a MDIO_BUS_MUX_MULTIPLEXER and put all the code into mdio-
> mux-multiplexer.c

Isn't MUX short for MULTIPLEXER ? wouldn't this be more confusing ?
I have kept the mux APIs code unchanged, so as to not disturb the existing drivers that use these APIs.

> 
> > +static const struct of_device_id mdio_mux_match[] = {
> > +	{ .compatible = "mdio-mux", },
> 
> mdio-mux-multiplexer

Again, isn't mux short for multiplexer? wouldn't this be more confusing ?

> 
> Thanks
> 	Andrew


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers: net: phy: mdio-mux: Add support for Generic Mux controls
  2019-02-21 14:15   ` Pankaj Bansal
@ 2019-02-21 15:17     ` Andrew Lunn
  2019-02-21 16:17       ` Peter Rosin
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2019-02-21 15:17 UTC (permalink / raw)
  To: Pankaj Bansal
  Cc: Leo Li, Peter Rosin, Florian Fainelli, Heiner Kallweit, netdev

> > >  config MDIO_BUS_MUX
> > >  	tristate
> > >  	depends on OF_MDIO
> > > +	select MULTIPLEXER
> > >  	help
> > >  	  This module provides a driver framework for MDIO bus
> > >  	  multiplexers which connect one of several child MDIO busses
> > 
> > Hi Pankaj
> > 
> > Please add a MDIO_BUS_MUX_MULTIPLEXER and put all the code into mdio-
> > mux-multiplexer.c
> 
> Isn't MUX short for MULTIPLEXER ? wouldn't this be more confusing ?

Look at the pattern:

config MDIO_BUS_MUX
config MDIO_BUS_MUX_BCM_IPROC
config MDIO_BUS_MUX_GPIO
config MDIO_BUS_MUX_MMIOREG

You are adding another sort of MUX, A Mux that uses a kernel
Multiplexer.  Hence the name should be MDIO_BUS_MUX_MULTIPLEXER.

You can try to avoid confusion by using good help text:

  	help This module provides a driver for MDIO bus multiplexer
	  that is controlled via the kernel multiplexer subsystem. The
	  bus multiplexer connects one of several child MDIO busses to
	  a parent bus.  Child bus selection is under the control of
	  the kernel multiplexer subsystem.

This test basically follows the other MDIO multiplexers.

     Andrew

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers: net: phy: mdio-mux: Add support for Generic Mux controls
  2019-02-21 15:17     ` Andrew Lunn
@ 2019-02-21 16:17       ` Peter Rosin
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Rosin @ 2019-02-21 16:17 UTC (permalink / raw)
  To: Andrew Lunn, Pankaj Bansal
  Cc: Leo Li, Florian Fainelli, Heiner Kallweit, netdev

On 2019-02-21 16:17, Andrew Lunn wrote:
>>>>  config MDIO_BUS_MUX
>>>>  	tristate
>>>>  	depends on OF_MDIO
>>>> +	select MULTIPLEXER
>>>>  	help
>>>>  	  This module provides a driver framework for MDIO bus
>>>>  	  multiplexers which connect one of several child MDIO busses
>>>
>>> Hi Pankaj
>>>
>>> Please add a MDIO_BUS_MUX_MULTIPLEXER and put all the code into mdio-
>>> mux-multiplexer.c
>>
>> Isn't MUX short for MULTIPLEXER ? wouldn't this be more confusing ?
> 
> Look at the pattern:
> 
> config MDIO_BUS_MUX
> config MDIO_BUS_MUX_BCM_IPROC
> config MDIO_BUS_MUX_GPIO
> config MDIO_BUS_MUX_MMIOREG
> 
> You are adding another sort of MUX, A Mux that uses a kernel
> Multiplexer.  Hence the name should be MDIO_BUS_MUX_MULTIPLEXER.
> 
> You can try to avoid confusion by using good help text:
> 
>   	help This module provides a driver for MDIO bus multiplexer
> 	  that is controlled via the kernel multiplexer subsystem. The
> 	  bus multiplexer connects one of several child MDIO busses to
> 	  a parent bus.  Child bus selection is under the control of
> 	  the kernel multiplexer subsystem.
> 
> This test basically follows the other MDIO multiplexers.

The same "problem" happened for I2C muxes, and there the driver
ended up being "i2c-mux-gpmux" with config symbol I2C_MUX_GPMUX, with
GP being short for general purpose.

If that matters...

Cheers,
Peter

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-21 16:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21 13:00 [PATCH] drivers: net: phy: mdio-mux: Add support for Generic Mux controls Pankaj Bansal
2019-02-21 13:42 ` Andrew Lunn
2019-02-21 14:15   ` Pankaj Bansal
2019-02-21 15:17     ` Andrew Lunn
2019-02-21 16:17       ` Peter Rosin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).