All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] net: mdio-gpio enhancements
@ 2014-04-16  2:16 Guenter Roeck
  2014-04-16  2:16 ` [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible Guenter Roeck
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Guenter Roeck @ 2014-04-16  2:16 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Chris Healy, linux-kernel, netdev, Guenter Roeck

The following series of patches adds support for active-low gpio pins
as well as for systems with separate MDI and MDO pins to the mdio-gpio
driver.

A board using those features is based on a COM Express CPU board.
The COM Express standard supports GPIO pins on its connector,
with one caveat: The pins on the connector have fixed direction
and are hard configured either as input or output pins.
The COM Express Design Guide [1] provides additional details.

The hardware uses three of the GPO/GPI pins from the COM Express board
to drive an MDIO bus. Connectivity between GPI/GPO pins and the MDIO bus
is as follows.

GPI2 --------------------+------------ MDIO
                         |
            +--------+   |
GPO2 ---+---G        |   |
        |   |        |   |
       4.7k | 2N7002 D---+
	|   |        |
	+---S        |
	|   +--------+
       GND

GPO1 --------------------------------- MDC

To support this hardware, two extensions to the driver were necessary.

- Due to the FET in the MDO path (GPO2), the MDO signal is inverted.
  The driver therefore has to support active-low GPIO pins.

- The MDIO signal must be separated into MDI and MDO.

Those changes are implemented in patch 2/3 and 3/3.
Patch 1/3 simplifies the error path and thus the subsequent
patches.


[1] http://www.picmg.org/pdf/picmg_comdg_100.pdf

----------------------------------------------------------------
Guenter Roeck (3):
      net: mdio-gpio: Use devm_ functions where possible
      net: mdio-gpio: Add support for active low gpio pins
      net: mdio-gpio: Add support for separate MDI and MDO gpio pins

 drivers/net/phy/mdio-gpio.c |   68 ++++++++++++++++++++++++++++++-------------
 include/linux/mdio-gpio.h   |    5 ++++
 2 files changed, 52 insertions(+), 21 deletions(-)

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

* [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible
  2014-04-16  2:16 [PATCH 0/3] net: mdio-gpio enhancements Guenter Roeck
@ 2014-04-16  2:16 ` Guenter Roeck
  2014-04-16  2:50   ` Chris Healy
                     ` (2 more replies)
  2014-04-16  2:16 ` [PATCH 2/3] net: mdio-gpio: Add support for active low gpio pins Guenter Roeck
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 13+ messages in thread
From: Guenter Roeck @ 2014-04-16  2:16 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Chris Healy, linux-kernel, netdev, Guenter Roeck

This simplifies error path and deinit/removal functions.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/net/phy/mdio-gpio.c |   19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index e701433..e853066 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -110,7 +110,7 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
 	struct mdio_gpio_info *bitbang;
 	int i;
 
-	bitbang = kzalloc(sizeof(*bitbang), GFP_KERNEL);
+	bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL);
 	if (!bitbang)
 		goto out;
 
@@ -121,7 +121,7 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
 
 	new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
 	if (!new_bus)
-		goto out_free_bitbang;
+		goto out;
 
 	new_bus->name = "GPIO Bitbanged MDIO",
 
@@ -138,11 +138,11 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
 
 	snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id);
 
-	if (gpio_request(bitbang->mdc, "mdc"))
+	if (devm_gpio_request(dev, bitbang->mdc, "mdc"))
 		goto out_free_bus;
 
-	if (gpio_request(bitbang->mdio, "mdio"))
-		goto out_free_mdc;
+	if (devm_gpio_request(dev, bitbang->mdio, "mdio"))
+		goto out_free_bus;
 
 	gpio_direction_output(bitbang->mdc, 0);
 
@@ -150,12 +150,8 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
 
 	return new_bus;
 
-out_free_mdc:
-	gpio_free(bitbang->mdc);
 out_free_bus:
 	free_mdio_bitbang(new_bus);
-out_free_bitbang:
-	kfree(bitbang);
 out:
 	return NULL;
 }
@@ -163,13 +159,8 @@ out:
 static void mdio_gpio_bus_deinit(struct device *dev)
 {
 	struct mii_bus *bus = dev_get_drvdata(dev);
-	struct mdio_gpio_info *bitbang = bus->priv;
 
-	dev_set_drvdata(dev, NULL);
-	gpio_free(bitbang->mdio);
-	gpio_free(bitbang->mdc);
 	free_mdio_bitbang(bus);
-	kfree(bitbang);
 }
 
 static void mdio_gpio_bus_destroy(struct device *dev)
-- 
1.7.9.7


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

* [PATCH 2/3] net: mdio-gpio: Add support for active low gpio pins
  2014-04-16  2:16 [PATCH 0/3] net: mdio-gpio enhancements Guenter Roeck
  2014-04-16  2:16 ` [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible Guenter Roeck
@ 2014-04-16  2:16 ` Guenter Roeck
  2014-04-16  2:44   ` Chris Healy
  2014-04-16  2:16 ` [PATCH 3/3] net: mdio-gpio: Add support for separate MDI and MDO " Guenter Roeck
  2014-04-16 19:10 ` [PATCH 0/3] net: mdio-gpio enhancements David Miller
  3 siblings, 1 reply; 13+ messages in thread
From: Guenter Roeck @ 2014-04-16  2:16 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Chris Healy, linux-kernel, netdev, Guenter Roeck

Some systems using mdio-gpio may use active-low gpio pins
(eg with inverters or FETs connected to all or some of the
gpio pins).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/net/phy/mdio-gpio.c |   19 +++++++++++++------
 include/linux/mdio-gpio.h   |    3 +++
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index e853066..fac211a 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -33,28 +33,32 @@
 struct mdio_gpio_info {
 	struct mdiobb_ctrl ctrl;
 	int mdc, mdio;
+	int mdc_active_low, mdio_active_low;
 };
 
 static void *mdio_gpio_of_get_data(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
 	struct mdio_gpio_platform_data *pdata;
+	enum of_gpio_flags flags;
 	int ret;
 
 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return NULL;
 
-	ret = of_get_gpio(np, 0);
+	ret = of_get_gpio_flags(np, 0, &flags);
 	if (ret < 0)
 		return NULL;
 
 	pdata->mdc = ret;
+	pdata->mdc_active_low = flags & OF_GPIO_ACTIVE_LOW;
 
-	ret = of_get_gpio(np, 1);
+	ret = of_get_gpio_flags(np, 1, &flags);
 	if (ret < 0)
 		return NULL;
 	pdata->mdio = ret;
+	pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW;
 
 	return pdata;
 }
@@ -65,7 +69,8 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
 		container_of(ctrl, struct mdio_gpio_info, ctrl);
 
 	if (dir)
-		gpio_direction_output(bitbang->mdio, 1);
+		gpio_direction_output(bitbang->mdio,
+				      1 ^ bitbang->mdio_active_low);
 	else
 		gpio_direction_input(bitbang->mdio);
 }
@@ -75,7 +80,7 @@ static int mdio_get(struct mdiobb_ctrl *ctrl)
 	struct mdio_gpio_info *bitbang =
 		container_of(ctrl, struct mdio_gpio_info, ctrl);
 
-	return gpio_get_value(bitbang->mdio);
+	return gpio_get_value(bitbang->mdio) ^ bitbang->mdio_active_low;
 }
 
 static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
@@ -83,7 +88,7 @@ static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
 	struct mdio_gpio_info *bitbang =
 		container_of(ctrl, struct mdio_gpio_info, ctrl);
 
-	gpio_set_value(bitbang->mdio, what);
+	gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low);
 }
 
 static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
@@ -91,7 +96,7 @@ static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
 	struct mdio_gpio_info *bitbang =
 		container_of(ctrl, struct mdio_gpio_info, ctrl);
 
-	gpio_set_value(bitbang->mdc, what);
+	gpio_set_value(bitbang->mdc, what ^ bitbang->mdc_active_low);
 }
 
 static struct mdiobb_ops mdio_gpio_ops = {
@@ -117,7 +122,9 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
 	bitbang->ctrl.ops = &mdio_gpio_ops;
 	bitbang->ctrl.reset = pdata->reset;
 	bitbang->mdc = pdata->mdc;
+	bitbang->mdc_active_low = pdata->mdc_active_low;
 	bitbang->mdio = pdata->mdio;
+	bitbang->mdio_active_low = pdata->mdio_active_low;
 
 	new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
 	if (!new_bus)
diff --git a/include/linux/mdio-gpio.h b/include/linux/mdio-gpio.h
index 7c9fe3c..57e57fe 100644
--- a/include/linux/mdio-gpio.h
+++ b/include/linux/mdio-gpio.h
@@ -18,6 +18,9 @@ struct mdio_gpio_platform_data {
 	unsigned int mdc;
 	unsigned int mdio;
 
+	bool mdc_active_low;
+	bool mdio_active_low;
+
 	unsigned int phy_mask;
 	int irqs[PHY_MAX_ADDR];
 	/* reset callback */
-- 
1.7.9.7


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

* [PATCH 3/3] net: mdio-gpio: Add support for separate MDI and MDO gpio pins
  2014-04-16  2:16 [PATCH 0/3] net: mdio-gpio enhancements Guenter Roeck
  2014-04-16  2:16 ` [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible Guenter Roeck
  2014-04-16  2:16 ` [PATCH 2/3] net: mdio-gpio: Add support for active low gpio pins Guenter Roeck
@ 2014-04-16  2:16 ` Guenter Roeck
  2014-04-16  2:45   ` Chris Healy
  2014-04-16 19:10 ` [PATCH 0/3] net: mdio-gpio enhancements David Miller
  3 siblings, 1 reply; 13+ messages in thread
From: Guenter Roeck @ 2014-04-16  2:16 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Chris Healy, linux-kernel, netdev, Guenter Roeck

This is for a system with fixed assignments of input and output pins
(various variants of Kontron COMe).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/net/phy/mdio-gpio.c |   34 +++++++++++++++++++++++++++++++---
 include/linux/mdio-gpio.h   |    2 ++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index fac211a..9c4defd 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -32,8 +32,8 @@
 
 struct mdio_gpio_info {
 	struct mdiobb_ctrl ctrl;
-	int mdc, mdio;
-	int mdc_active_low, mdio_active_low;
+	int mdc, mdio, mdo;
+	int mdc_active_low, mdio_active_low, mdo_active_low;
 };
 
 static void *mdio_gpio_of_get_data(struct platform_device *pdev)
@@ -60,6 +60,12 @@ static void *mdio_gpio_of_get_data(struct platform_device *pdev)
 	pdata->mdio = ret;
 	pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW;
 
+	ret = of_get_gpio_flags(np, 2, &flags);
+	if (ret > 0) {
+		pdata->mdo = ret;
+		pdata->mdo_active_low = flags & OF_GPIO_ACTIVE_LOW;
+	}
+
 	return pdata;
 }
 
@@ -68,6 +74,16 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
 	struct mdio_gpio_info *bitbang =
 		container_of(ctrl, struct mdio_gpio_info, ctrl);
 
+	if (bitbang->mdo) {
+		/* Separate output pin. Always set its value to high
+		 * when changing direction. If direction is input,
+		 * assume the pin serves as pull-up. If direction is
+		 * output, the default value is high.
+		 */
+		gpio_set_value(bitbang->mdo, 1 ^ bitbang->mdo_active_low);
+		return;
+	}
+
 	if (dir)
 		gpio_direction_output(bitbang->mdio,
 				      1 ^ bitbang->mdio_active_low);
@@ -88,7 +104,10 @@ static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
 	struct mdio_gpio_info *bitbang =
 		container_of(ctrl, struct mdio_gpio_info, ctrl);
 
-	gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low);
+	if (bitbang->mdo)
+		gpio_set_value(bitbang->mdo, what ^ bitbang->mdo_active_low);
+	else
+		gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low);
 }
 
 static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
@@ -125,6 +144,8 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
 	bitbang->mdc_active_low = pdata->mdc_active_low;
 	bitbang->mdio = pdata->mdio;
 	bitbang->mdio_active_low = pdata->mdio_active_low;
+	bitbang->mdo = pdata->mdo;
+	bitbang->mdo_active_low = pdata->mdo_active_low;
 
 	new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
 	if (!new_bus)
@@ -151,6 +172,13 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
 	if (devm_gpio_request(dev, bitbang->mdio, "mdio"))
 		goto out_free_bus;
 
+	if (bitbang->mdo) {
+		if (devm_gpio_request(dev, bitbang->mdo, "mdo"))
+			goto out_free_bus;
+		gpio_direction_output(bitbang->mdo, 1);
+		gpio_direction_input(bitbang->mdio);
+	}
+
 	gpio_direction_output(bitbang->mdc, 0);
 
 	dev_set_drvdata(dev, new_bus);
diff --git a/include/linux/mdio-gpio.h b/include/linux/mdio-gpio.h
index 57e57fe..66c30a7 100644
--- a/include/linux/mdio-gpio.h
+++ b/include/linux/mdio-gpio.h
@@ -17,9 +17,11 @@ struct mdio_gpio_platform_data {
 	/* GPIO numbers for bus pins */
 	unsigned int mdc;
 	unsigned int mdio;
+	unsigned int mdo;
 
 	bool mdc_active_low;
 	bool mdio_active_low;
+	bool mdo_active_low;
 
 	unsigned int phy_mask;
 	int irqs[PHY_MAX_ADDR];
-- 
1.7.9.7


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

* RE: [PATCH 2/3] net: mdio-gpio: Add support for active low gpio pins
  2014-04-16  2:16 ` [PATCH 2/3] net: mdio-gpio: Add support for active low gpio pins Guenter Roeck
@ 2014-04-16  2:44   ` Chris Healy
  0 siblings, 0 replies; 13+ messages in thread
From: Chris Healy @ 2014-04-16  2:44 UTC (permalink / raw)
  To: Guenter Roeck, Florian Fainelli; +Cc: linux-kernel, netdev, cphealy

Some systems using mdio-gpio may use active-low gpio pins
(eg with inverters or FETs connected to all or some of the
gpio pins).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Chris Healy <cphealy@gmail.com>
---
 drivers/net/phy/mdio-gpio.c |   19 +++++++++++++------
 include/linux/mdio-gpio.h   |    3 +++
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index e853066..fac211a 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -33,28 +33,32 @@
 struct mdio_gpio_info {
        struct mdiobb_ctrl ctrl;
        int mdc, mdio;
+       int mdc_active_low, mdio_active_low;
 };

 static void *mdio_gpio_of_get_data(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
        struct mdio_gpio_platform_data *pdata;
+       enum of_gpio_flags flags;
        int ret;

        pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
        if (!pdata)
                return NULL;

-       ret = of_get_gpio(np, 0);
+       ret = of_get_gpio_flags(np, 0, &flags);
        if (ret < 0)
                return NULL;

        pdata->mdc = ret;
+       pdata->mdc_active_low = flags & OF_GPIO_ACTIVE_LOW;

-       ret = of_get_gpio(np, 1);
+       ret = of_get_gpio_flags(np, 1, &flags);
        if (ret < 0)
                return NULL;
        pdata->mdio = ret;
+       pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW;

        return pdata;
 }
@@ -65,7 +69,8 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
                container_of(ctrl, struct mdio_gpio_info, ctrl);

        if (dir)
-               gpio_direction_output(bitbang->mdio, 1);
+               gpio_direction_output(bitbang->mdio,
+                                     1 ^ bitbang->mdio_active_low);
        else
                gpio_direction_input(bitbang->mdio);
 }
@@ -75,7 +80,7 @@ static int mdio_get(struct mdiobb_ctrl *ctrl)
        struct mdio_gpio_info *bitbang =
                container_of(ctrl, struct mdio_gpio_info, ctrl);

-       return gpio_get_value(bitbang->mdio);
+       return gpio_get_value(bitbang->mdio) ^ bitbang->mdio_active_low;
 }

 static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
@@ -83,7 +88,7 @@ static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
        struct mdio_gpio_info *bitbang =
                container_of(ctrl, struct mdio_gpio_info, ctrl);

-       gpio_set_value(bitbang->mdio, what);
+       gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low);
 }

 static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
@@ -91,7 +96,7 @@ static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
        struct mdio_gpio_info *bitbang =
                container_of(ctrl, struct mdio_gpio_info, ctrl);

-       gpio_set_value(bitbang->mdc, what);
+       gpio_set_value(bitbang->mdc, what ^ bitbang->mdc_active_low);
 }

 static struct mdiobb_ops mdio_gpio_ops = {
@@ -117,7 +122,9 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
        bitbang->ctrl.ops = &mdio_gpio_ops;
        bitbang->ctrl.reset = pdata->reset;
        bitbang->mdc = pdata->mdc;
+       bitbang->mdc_active_low = pdata->mdc_active_low;
        bitbang->mdio = pdata->mdio;
+       bitbang->mdio_active_low = pdata->mdio_active_low;

        new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
        if (!new_bus)
diff --git a/include/linux/mdio-gpio.h b/include/linux/mdio-gpio.h
index 7c9fe3c..57e57fe 100644
--- a/include/linux/mdio-gpio.h
+++ b/include/linux/mdio-gpio.h
@@ -18,6 +18,9 @@ struct mdio_gpio_platform_data {
        unsigned int mdc;
        unsigned int mdio;

+       bool mdc_active_low;
+       bool mdio_active_low;
+
        unsigned int phy_mask;
        int irqs[PHY_MAX_ADDR];
        /* reset callback */
--
1.7.9.7


________________________________


This email and any files transmitted with it are confidential & proprietary to Systems and Software Enterprises, LLC. This information is intended solely for the use of the individual or entity to which it is addressed. Access or transmittal of the information contained in this e-mail, in full or in part, to any other organization or persons is not authorized.

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

* RE: [PATCH 3/3] net: mdio-gpio: Add support for separate MDI and MDO  gpio pins
  2014-04-16  2:16 ` [PATCH 3/3] net: mdio-gpio: Add support for separate MDI and MDO " Guenter Roeck
@ 2014-04-16  2:45   ` Chris Healy
  0 siblings, 0 replies; 13+ messages in thread
From: Chris Healy @ 2014-04-16  2:45 UTC (permalink / raw)
  To: Guenter Roeck, Florian Fainelli; +Cc: linux-kernel, netdev, cphealy

This is for a system with fixed assignments of input and output pins
(various variants of Kontron COMe).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Chris Healy <cphealy@gmail.com>
---
 drivers/net/phy/mdio-gpio.c |   34 +++++++++++++++++++++++++++++++---
 include/linux/mdio-gpio.h   |    2 ++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index fac211a..9c4defd 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -32,8 +32,8 @@

 struct mdio_gpio_info {
        struct mdiobb_ctrl ctrl;
-       int mdc, mdio;
-       int mdc_active_low, mdio_active_low;
+       int mdc, mdio, mdo;
+       int mdc_active_low, mdio_active_low, mdo_active_low;
 };

 static void *mdio_gpio_of_get_data(struct platform_device *pdev)
@@ -60,6 +60,12 @@ static void *mdio_gpio_of_get_data(struct platform_device *pdev)
        pdata->mdio = ret;
        pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW;

+       ret = of_get_gpio_flags(np, 2, &flags);
+       if (ret > 0) {
+               pdata->mdo = ret;
+               pdata->mdo_active_low = flags & OF_GPIO_ACTIVE_LOW;
+       }
+
        return pdata;
 }

@@ -68,6 +74,16 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
        struct mdio_gpio_info *bitbang =
                container_of(ctrl, struct mdio_gpio_info, ctrl);

+       if (bitbang->mdo) {
+               /* Separate output pin. Always set its value to high
+                * when changing direction. If direction is input,
+                * assume the pin serves as pull-up. If direction is
+                * output, the default value is high.
+                */
+               gpio_set_value(bitbang->mdo, 1 ^ bitbang->mdo_active_low);
+               return;
+       }
+
        if (dir)
                gpio_direction_output(bitbang->mdio,
                                      1 ^ bitbang->mdio_active_low);
@@ -88,7 +104,10 @@ static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
        struct mdio_gpio_info *bitbang =
                container_of(ctrl, struct mdio_gpio_info, ctrl);

-       gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low);
+       if (bitbang->mdo)
+               gpio_set_value(bitbang->mdo, what ^ bitbang->mdo_active_low);
+       else
+               gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low);
 }

 static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
@@ -125,6 +144,8 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
        bitbang->mdc_active_low = pdata->mdc_active_low;
        bitbang->mdio = pdata->mdio;
        bitbang->mdio_active_low = pdata->mdio_active_low;
+       bitbang->mdo = pdata->mdo;
+       bitbang->mdo_active_low = pdata->mdo_active_low;

        new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
        if (!new_bus)
@@ -151,6 +172,13 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
        if (devm_gpio_request(dev, bitbang->mdio, "mdio"))
                goto out_free_bus;

+       if (bitbang->mdo) {
+               if (devm_gpio_request(dev, bitbang->mdo, "mdo"))
+                       goto out_free_bus;
+               gpio_direction_output(bitbang->mdo, 1);
+               gpio_direction_input(bitbang->mdio);
+       }
+
        gpio_direction_output(bitbang->mdc, 0);

        dev_set_drvdata(dev, new_bus);
diff --git a/include/linux/mdio-gpio.h b/include/linux/mdio-gpio.h
index 57e57fe..66c30a7 100644
--- a/include/linux/mdio-gpio.h
+++ b/include/linux/mdio-gpio.h
@@ -17,9 +17,11 @@ struct mdio_gpio_platform_data {
        /* GPIO numbers for bus pins */
        unsigned int mdc;
        unsigned int mdio;
+       unsigned int mdo;

        bool mdc_active_low;
        bool mdio_active_low;
+       bool mdo_active_low;

        unsigned int phy_mask;
        int irqs[PHY_MAX_ADDR];
--
1.7.9.7


________________________________


This email and any files transmitted with it are confidential & proprietary to Systems and Software Enterprises, LLC. This information is intended solely for the use of the individual or entity to which it is addressed. Access or transmittal of the information contained in this e-mail, in full or in part, to any other organization or persons is not authorized.

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

* RE: [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible
  2014-04-16  2:16 ` [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible Guenter Roeck
@ 2014-04-16  2:50   ` Chris Healy
  2014-04-16  3:17     ` David Miller
  2014-04-16 18:48   ` Chris Healy
  2014-04-18 19:19   ` Sergei Shtylyov
  2 siblings, 1 reply; 13+ messages in thread
From: Chris Healy @ 2014-04-16  2:50 UTC (permalink / raw)
  To: Guenter Roeck, Florian Fainelli; +Cc: linux-kernel, netdev, cphealy

This simplifies error path and deinit/removal functions.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Chris Healy <cphealy@gmail.com>
---
 drivers/net/phy/mdio-gpio.c |   19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index e701433..e853066 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -110,7 +110,7 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
        struct mdio_gpio_info *bitbang;
        int i;

-       bitbang = kzalloc(sizeof(*bitbang), GFP_KERNEL);
+       bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL);
        if (!bitbang)
                goto out;

@@ -121,7 +121,7 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,

        new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
        if (!new_bus)
-               goto out_free_bitbang;
+               goto out;

        new_bus->name = "GPIO Bitbanged MDIO",

@@ -138,11 +138,11 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,

        snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id);

-       if (gpio_request(bitbang->mdc, "mdc"))
+       if (devm_gpio_request(dev, bitbang->mdc, "mdc"))
                goto out_free_bus;

-       if (gpio_request(bitbang->mdio, "mdio"))
-               goto out_free_mdc;
+       if (devm_gpio_request(dev, bitbang->mdio, "mdio"))
+               goto out_free_bus;

        gpio_direction_output(bitbang->mdc, 0);

@@ -150,12 +150,8 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,

        return new_bus;

-out_free_mdc:
-       gpio_free(bitbang->mdc);
 out_free_bus:
        free_mdio_bitbang(new_bus);
-out_free_bitbang:
-       kfree(bitbang);
 out:
        return NULL;
 }
@@ -163,13 +159,8 @@ out:
 static void mdio_gpio_bus_deinit(struct device *dev)
 {
        struct mii_bus *bus = dev_get_drvdata(dev);
-       struct mdio_gpio_info *bitbang = bus->priv;

-       dev_set_drvdata(dev, NULL);
-       gpio_free(bitbang->mdio);
-       gpio_free(bitbang->mdc);
        free_mdio_bitbang(bus);
-       kfree(bitbang);
 }

 static void mdio_gpio_bus_destroy(struct device *dev)
--
1.7.9.7


________________________________


This email and any files transmitted with it are confidential & proprietary to Systems and Software Enterprises, LLC. This information is intended solely for the use of the individual or entity to which it is addressed. Access or transmittal of the information contained in this e-mail, in full or in part, to any other organization or persons is not authorized.

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

* Re: [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible
  2014-04-16  2:50   ` Chris Healy
@ 2014-04-16  3:17     ` David Miller
  0 siblings, 0 replies; 13+ messages in thread
From: David Miller @ 2014-04-16  3:17 UTC (permalink / raw)
  To: chealy; +Cc: linux, f.fainelli, linux-kernel, netdev, cphealy

From: Chris Healy <chealy@imsco-us.com>
Date: Wed, 16 Apr 2014 02:50:08 +0000

> This simplifies error path and deinit/removal functions.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> Tested-by: Chris Healy <cphealy@gmail.com>

This isn't the way to add a Tested-by: tag of your own if that
is what you're trying to do.

The proper way is to reply to the original patch, quote only the
commit message, and then add your Tested-by: after the quoted
material.

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

* RE: [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible
  2014-04-16  2:16 ` [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible Guenter Roeck
  2014-04-16  2:50   ` Chris Healy
@ 2014-04-16 18:48   ` Chris Healy
  2014-04-16 18:50     ` Chris Healy
  2014-04-18 19:19   ` Sergei Shtylyov
  2 siblings, 1 reply; 13+ messages in thread
From: Chris Healy @ 2014-04-16 18:48 UTC (permalink / raw)
  To: Guenter Roeck, Florian Fainelli; +Cc: linux-kernel, netdev

On Tue, Apr 15, 2014 at 07:16:40PM -0700, Guenter Roeck wrote:
> This simplifies error path and deinit/removal functions.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Tested-by: Chris Healy <cphealy@gmail.com>

________________________________


This email and any files transmitted with it are confidential & proprietary to Systems and Software Enterprises, LLC. This information is intended solely for the use of the individual or entity to which it is addressed. Access or transmittal of the information contained in this e-mail, in full or in part, to any other organization or persons is not authorized.

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

* RE: [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible
  2014-04-16 18:48   ` Chris Healy
@ 2014-04-16 18:50     ` Chris Healy
  2014-04-16 20:22       ` Guenter Roeck
  0 siblings, 1 reply; 13+ messages in thread
From: Chris Healy @ 2014-04-16 18:50 UTC (permalink / raw)
  To: Guenter Roeck, Florian Fainelli; +Cc: linux-kernel, netdev

OK, I just sent it.  Hopefully, I didn't mess it up again!

Do I need to do the same for 2/3 and 3/3?
________________________________________
From: Chris Healy
Sent: Wednesday, April 16, 2014 11:48 AM
To: Guenter Roeck; Florian Fainelli
Cc: linux-kernel@vger.kernel.org; netdev@vger.kernel.org
Subject: RE: [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible

On Tue, Apr 15, 2014 at 07:16:40PM -0700, Guenter Roeck wrote:
> This simplifies error path and deinit/removal functions.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Tested-by: Chris Healy <cphealy@gmail.com>

________________________________


This email and any files transmitted with it are confidential & proprietary to Systems and Software Enterprises, LLC. This information is intended solely for the use of the individual or entity to which it is addressed. Access or transmittal of the information contained in this e-mail, in full or in part, to any other organization or persons is not authorized.

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

* Re: [PATCH 0/3] net: mdio-gpio enhancements
  2014-04-16  2:16 [PATCH 0/3] net: mdio-gpio enhancements Guenter Roeck
                   ` (2 preceding siblings ...)
  2014-04-16  2:16 ` [PATCH 3/3] net: mdio-gpio: Add support for separate MDI and MDO " Guenter Roeck
@ 2014-04-16 19:10 ` David Miller
  3 siblings, 0 replies; 13+ messages in thread
From: David Miller @ 2014-04-16 19:10 UTC (permalink / raw)
  To: linux; +Cc: f.fainelli, chealy, linux-kernel, netdev

From: Guenter Roeck <linux@roeck-us.net>
Date: Tue, 15 Apr 2014 19:16:39 -0700

> The following series of patches adds support for active-low gpio pins
> as well as for systems with separate MDI and MDO pins to the mdio-gpio
> driver.

Series applied, thanks.

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

* Re: [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible
  2014-04-16 18:50     ` Chris Healy
@ 2014-04-16 20:22       ` Guenter Roeck
  0 siblings, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2014-04-16 20:22 UTC (permalink / raw)
  To: Chris Healy; +Cc: Florian Fainelli, linux-kernel, netdev

On Wed, Apr 16, 2014 at 06:50:56PM +0000, Chris Healy wrote:
> OK, I just sent it.  Hopefully, I didn't mess it up again!
> 
> Do I need to do the same for 2/3 and 3/3?

Hi Chris,

David just sent an e-mail that he accepted the series, so the answer is no.

Guenter

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

* Re: [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible
  2014-04-16  2:16 ` [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible Guenter Roeck
  2014-04-16  2:50   ` Chris Healy
  2014-04-16 18:48   ` Chris Healy
@ 2014-04-18 19:19   ` Sergei Shtylyov
  2 siblings, 0 replies; 13+ messages in thread
From: Sergei Shtylyov @ 2014-04-18 19:19 UTC (permalink / raw)
  To: Guenter Roeck, Florian Fainelli; +Cc: Chris Healy, linux-kernel, netdev

Hello.

On 04/16/2014 06:16 AM, Guenter Roeck wrote:

> This simplifies error path and deinit/removal functions.

> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>   drivers/net/phy/mdio-gpio.c |   19 +++++--------------
>   1 file changed, 5 insertions(+), 14 deletions(-)

> diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
> index e701433..e853066 100644
> --- a/drivers/net/phy/mdio-gpio.c
> +++ b/drivers/net/phy/mdio-gpio.c
> @@ -110,7 +110,7 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
[...]
> @@ -163,13 +159,8 @@ out:
>   static void mdio_gpio_bus_deinit(struct device *dev)
>   {
>   	struct mii_bus *bus = dev_get_drvdata(dev);
> -	struct mdio_gpio_info *bitbang = bus->priv;
>
> -	dev_set_drvdata(dev, NULL);

    You didn't even document this "drove-by" change. Ideally, it should have 
been in a separate patch.

> -	gpio_free(bitbang->mdio);
> -	gpio_free(bitbang->mdc);
>   	free_mdio_bitbang(bus);
> -	kfree(bitbang);
>   }

WBR, Sergei


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

end of thread, other threads:[~2014-04-18 19:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-16  2:16 [PATCH 0/3] net: mdio-gpio enhancements Guenter Roeck
2014-04-16  2:16 ` [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible Guenter Roeck
2014-04-16  2:50   ` Chris Healy
2014-04-16  3:17     ` David Miller
2014-04-16 18:48   ` Chris Healy
2014-04-16 18:50     ` Chris Healy
2014-04-16 20:22       ` Guenter Roeck
2014-04-18 19:19   ` Sergei Shtylyov
2014-04-16  2:16 ` [PATCH 2/3] net: mdio-gpio: Add support for active low gpio pins Guenter Roeck
2014-04-16  2:44   ` Chris Healy
2014-04-16  2:16 ` [PATCH 3/3] net: mdio-gpio: Add support for separate MDI and MDO " Guenter Roeck
2014-04-16  2:45   ` Chris Healy
2014-04-16 19:10 ` [PATCH 0/3] net: mdio-gpio enhancements David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.