diff mbox

[4/7] net: phy: spi_ks8995: add support for resetting switch using GPIO

Message ID 1454884753-4560-5-git-send-email-helmut.buchsbaum@gmail.com
State Superseded, archived
Delegated to: David Miller
Headers show

Commit Message

Helmut Buchsbaum Feb. 7, 2016, 10:39 p.m. UTC
When using device tree it is no more possible to reset the PHY at board
level. Furthermore, doing in the driver allows to power down the switch
when the it is not used any more.

The patch introduces a new optional property "reset-gpios" denoting an
appropriate GPIO handle, e.g.:

reset-gpios = <&gpio0 46 1>

Signed-off-by: Helmut Buchsbaum <helmut.buchsbaum@gmail.com>
---
 drivers/net/phy/spi_ks8995.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

Comments

Andrew Lunn Feb. 8, 2016, 9:22 a.m. UTC | #1
On Sun, Feb 07, 2016 at 11:39:10PM +0100, Helmut Buchsbaum wrote:
> When using device tree it is no more possible to reset the PHY at board
> level. Furthermore, doing in the driver allows to power down the switch
> when the it is not used any more.
> 
> The patch introduces a new optional property "reset-gpios" denoting an
> appropriate GPIO handle, e.g.:
> 
> reset-gpios = <&gpio0 46 1>

The 1 here means active low flag.

>  
> +	pdata->reset_gpio = of_get_named_gpio(np, "reset-gpios", 0);
> +

Here you don't take any notice of the flags.

>  	/* we have something like:
>  	 * settings = <0x22 0x80 0xF0>;
>  	 *               ^   ^    ^
> @@ -484,6 +489,8 @@ static int ks8995_probe(struct spi_device *spi)
>  		if (!ks->pdata)
>  			return -ENOMEM;
>  
> +		ks->pdata->reset_gpio = -1;
> +
>  		err = ks8995_parse_dt(ks);
>  		if (err) {
>  			dev_err(&ks->spi->dev, "bad data DT data\n");
> @@ -494,6 +501,18 @@ static int ks8995_probe(struct spi_device *spi)
>  	if (!ks->pdata)
>  		ks->pdata = spi->dev.platform_data;
>  
> +	if (ks->pdata && gpio_is_valid(ks->pdata->reset_gpio)) {
> +		err = devm_gpio_request_one(&spi->dev,
> +					    ks->pdata->reset_gpio,
> +					    GPIOF_OUT_INIT_HIGH,

Hard coded HIGH. You should determine this from the flag....

DSA has the same functionality and does support the flag. You can copy
it from there.

     Andrew
diff mbox

Patch

diff --git a/drivers/net/phy/spi_ks8995.c b/drivers/net/phy/spi_ks8995.c
index d50f091..60479c4 100644
--- a/drivers/net/phy/spi_ks8995.c
+++ b/drivers/net/phy/spi_ks8995.c
@@ -19,6 +19,8 @@ 
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/of.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
 
 #include <linux/spi/spi.h>
 
@@ -127,6 +129,7 @@  struct ks8995_pdata {
 		int mask;
 	} *settings;
 	int nsettings;
+	int reset_gpio;
 };
 
 struct ks8995_switch {
@@ -406,6 +409,8 @@  static int ks8995_parse_dt(struct ks8995_switch *ks)
 	if (!np)
 		return 0;
 
+	pdata->reset_gpio = of_get_named_gpio(np, "reset-gpios", 0);
+
 	/* we have something like:
 	 * settings = <0x22 0x80 0xF0>;
 	 *               ^   ^    ^
@@ -484,6 +489,8 @@  static int ks8995_probe(struct spi_device *spi)
 		if (!ks->pdata)
 			return -ENOMEM;
 
+		ks->pdata->reset_gpio = -1;
+
 		err = ks8995_parse_dt(ks);
 		if (err) {
 			dev_err(&ks->spi->dev, "bad data DT data\n");
@@ -494,6 +501,18 @@  static int ks8995_probe(struct spi_device *spi)
 	if (!ks->pdata)
 		ks->pdata = spi->dev.platform_data;
 
+	if (ks->pdata && gpio_is_valid(ks->pdata->reset_gpio)) {
+		err = devm_gpio_request_one(&spi->dev,
+					    ks->pdata->reset_gpio,
+					    GPIOF_OUT_INIT_HIGH,
+					    "switch-reset");
+		if (err) {
+			dev_err(&spi->dev,
+				"failed to get reset-gpios: %d\n", err);
+			return -EIO;
+		}
+	}
+
 	spi_set_drvdata(spi, ks);
 
 	spi->mode = SPI_MODE_0;
@@ -534,11 +553,13 @@  static int ks8995_remove(struct spi_device *spi)
 
 	sysfs_remove_bin_file(&spi->dev.kobj, &ks->regs_attr);
 
+	if (ks->pdata && gpio_is_valid(ks->pdata->reset_gpio))
+		gpio_set_value(ks->pdata->reset_gpio, 0);
+
 	return 0;
 }
 
 /* ------------------------------------------------------------------------ */
-
 static struct spi_driver ks8995_driver = {
 	.driver = {
 		.name	    = "spi-ks8995",