net: davicom: dm9000: switch to using gpiod API
Subsystems (6)
PATCH 1/3 net: davicom: dm9000: switch to using gpiod API
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of of_get_named_gpio_flags() which I want to make private to gpiolib.
--- drivers/net/ethernet/davicom/dm9000.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/net/ethernet/davicom/dm9000.c +14 -12
@@ -28,8 +28,7 @@#include <linux/irq.h> #include <linux/slab.h> #include <linux/regulator/consumer.h> -#include <linux/gpio.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <asm/delay.h> #include <asm/irq.h>
@@ -1421,8 +1420,7 @@ dm9000_probe(struct platform_device *pdev)int iosize;int i;u32 id_val; -int reset_gpios; -enum of_gpio_flags flags; +struct gpio_desc *reset_gpio;struct regulator *power;bool inv_mac_addr = false;u8 addr[ETH_ALEN ];
@@ -1442,20 +1440,24 @@ dm9000_probe(struct platform_device *pdev)dev_dbg (dev,"regulator enabled\n" ); } - reset_gpios =of_get_named_gpio_flags (dev->of_node,"reset-gpios" ,0 , - &flags); -if (gpio_is_valid (reset_gpios)) { - ret =devm_gpio_request_one (dev, reset_gpios, flags, -"dm9000_reset" ); + reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); + ret =PTR_ERR_OR_ZERO (reset_gpio); +if (ret) { +dev_err (dev,"failed to request reset gpio: %d\n" , ret); + goto out_regulator_disable; + } + +if (reset_gpio) { + ret =gpiod_set_consumer_name (reset_gpio,"dm9000_reset" );if (ret) { -dev_err (dev,"failed to request reset gpio %d: %d\n" , - reset_gpios, ret); +dev_err (dev,"failed to set reset gpio name: %d\n" , + ret); goto out_regulator_disable; }/* According to manual PWRST# Low Period Min 1ms */ msleep (2 ); -gpio_set_value (reset_gpios,1 ); +gpiod_set_value_cansleep (reset_gpio,0 );/* Needs 3ms to read eeprom when PWRST is deasserted */ msleep (4 ); }
Signature · 1 line
2.37.2.789.g6183377224-goog
PATCH 2/3 net: ks8851: switch to using gpiod API
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of of_get_named_gpio_flags() which I want to make private to gpiolib.
--- drivers/net/ethernet/micrel/ks8851.h | 2 +- drivers/net/ethernet/micrel/ks8851_common.c | 40 ++++++++++----------- 2 files changed, 20 insertions(+), 22 deletions(-)
drivers/net/ethernet/micrel/ks8851.h +1 -1
@@ -403,7 +403,7 @@ struct ks8851_net {struct eeprom_93cx6 eeprom;struct regulator *vdd_reg;struct regulator *vdd_io; -int gpio; +struct gpio_desc *gpio;struct mii_bus *mii_bus; void (*lock)(struct ks8851_net *ks,
drivers/net/ethernet/micrel/ks8851_common.c +19 -21
@@ -17,10 +17,9 @@#include <linux/cache.h> #include <linux/crc32.h> #include <linux/mii.h> +#include <linux/gpio/consumer.h> #include <linux/regulator/consumer.h> -#include <linux/gpio.h> -#include <linux/of_gpio.h> #include <linux/of_mdio.h> #include <linux/of_net.h>
@@ -1117,24 +1116,23 @@ int ks8851_probe_common(struct net_device *netdev, struct device *dev, {struct ks8851_net *ks =netdev_priv (netdev);unsigned cider; -int gpio;int ret; ks->netdev = netdev; ks->tx_space =6144 ; - gpio =of_get_named_gpio_flags (dev->of_node,"reset-gpios" ,0 ,NULL ); -if (gpio == -EPROBE_DEFER ) -return gpio; - - ks->gpio = gpio; -if (gpio_is_valid (gpio)) { - ret =devm_gpio_request_one (dev, gpio, -GPIOF_OUT_INIT_LOW ,"ks8851_rst_n" ); -if (ret) { -dev_err (dev,"reset gpio request failed\n" ); -return ret; - } + ks->gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); + ret =PTR_ERR_OR_ZERO (ks->gpio); +if (ret) { +if (ret != -EPROBE_DEFER ) +dev_err (dev,"reset gpio request failed: %d\n" , ret); +return ret; + } + + ret =gpiod_set_consumer_name (ks->gpio,"ks8851_rst_n" ); +if (ret) { +dev_err (dev,"failed to set reset gpio name: %d\n" , ret); +return ret; } ks->vdd_io =devm_regulator_get (dev,"vdd-io" );
@@ -1161,9 +1159,9 @@ int ks8851_probe_common(struct net_device *netdev, struct device *dev, goto err_reg; } -if (gpio_is_valid (gpio)) { +if (ks->gpio) {usleep_range (10000 ,11000 ); -gpio_set_value (gpio,1 ); +gpiod_set_value_cansleep (ks->gpio,0 ); }spin_lock_init (&ks->statelock);
@@ -1239,8 +1237,8 @@ int ks8851_probe_common(struct net_device *netdev, struct device *dev, err_id:ks8851_unregister_mdiobus (ks); err_mdio: -if (gpio_is_valid (gpio)) -gpio_set_value (gpio,0 ); +if (ks->gpio) +gpiod_set_value_cansleep (ks->gpio,1 );regulator_disable (ks->vdd_reg); err_reg:regulator_disable (ks->vdd_io);
@@ -1259,8 +1257,8 @@ void ks8851_remove_common(struct device *dev)dev_info (dev,"remove\n" );unregister_netdev (priv->netdev); -if (gpio_is_valid (priv->gpio)) -gpio_set_value (priv->gpio,0 ); +if (priv->gpio) +gpiod_set_value_cansleep (priv->gpio,1 );regulator_disable (priv->vdd_reg);regulator_disable (priv->vdd_io); }
Signature · 1 line
2.37.2.789.g6183377224-goog
Re: [PATCH 2/3] net: ks8851: switch to using gpiod API
Quoted 5 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Signed-off-by Dmitry Torokhov <[email protected]>
Yours,
Linus Walleij
PATCH 3/3 net: phy: spi_ks8895: switch to using gpiod API
In reply to Dmitry TorokhovThis patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of of_get_named_gpio_flags() which I want to make private to gpiolib.
--- drivers/net/phy/spi_ks8995.c | 69 ++++++++---------------------------- 1 file changed, 14 insertions(+), 55 deletions(-)
drivers/net/phy/spi_ks8995.c +14 -55
@@ -17,7 +17,6 @@#include <linux/device.h> #include <linux/gpio/consumer.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/spi/spi.h>
@@ -137,15 +136,10 @@ static const struct ks8995_chip_params ks8995_chip[] = { }, }; -struct ks8995_pdata { -int reset_gpio; -enum of_gpio_flags reset_gpio_flags; -}; -struct ks8995_switch {struct spi_device *spi;struct mutex lock; -struct ks8995_pdata *pdata; +struct gpio_desc *reset_gpio;struct bin_attribute regs_attr;const struct ks8995_chip_params *chip;int revision_id;
@@ -401,24 +395,6 @@ static int ks8995_get_revision(struct ks8995_switch *ks)return err; } -/* ks8995_parse_dt - setup platform data from devicetree -* @ks: pointer to switch instance -* -* Parses supported DT properties and sets up platform data -* accordingly. -*/ -static void ks8995_parse_dt (struct ks8995_switch *ks) -{ -struct device_node *np = ks->spi->dev.of_node; -struct ks8995_pdata *pdata = ks->pdata; - -if (!np) -return ; - - pdata->reset_gpio =of_get_named_gpio_flags (np,"reset-gpios" ,0 , - &pdata->reset_gpio_flags); -} -static const struct bin_attribute ks8995_registers_attr = { .attr = { .name ="registers" ,
@@ -449,38 +425,22 @@ static int ks8995_probe(struct spi_device *spi) ks->spi = spi; ks->chip = &ks8995_chip[variant]; -if (ks->spi->dev.of_node) { - ks->pdata =devm_kzalloc (&spi->dev,sizeof (*ks->pdata), -GFP_KERNEL ); -if (!ks->pdata) -return -ENOMEM ; - - ks->pdata->reset_gpio =-1 ; - -ks8995_parse_dt (ks); + ks->reset_gpio =devm_gpiod_get_optional (&spi->dev,"reset" , +GPIOD_OUT_HIGH ); + err =PTR_ERR_OR_ZERO (ks->reset_gpio); +if (err) { +dev_err (&spi->dev, +"failed to get reset gpio: %d\n" , err); +return err; } -if (!ks->pdata) - ks->pdata = spi->dev.platform_data; + err =gpiod_set_consumer_name (ks->reset_gpio,"switch-reset" ); +if (err) +return err;/* de-assert switch reset */ -if (ks->pdata &&gpio_is_valid (ks->pdata->reset_gpio)) { -unsigned long flags; - - flags = (ks->pdata->reset_gpio_flags ==OF_GPIO_ACTIVE_LOW ? -GPIOF_ACTIVE_LOW :0 ); - - err =devm_gpio_request_one (&spi->dev, - ks->pdata->reset_gpio, - flags,"switch-reset" ); -if (err) { -dev_err (&spi->dev, -"failed to get reset-gpios: %d\n" , err); -return -EIO ; - } - -gpiod_set_value (gpio_to_desc (ks->pdata->reset_gpio),0 ); - } +/* FIXME: this likely requires a delay */ +gpiod_set_value_cansleep (ks->reset_gpio,0 );spi_set_drvdata (spi, ks);
@@ -524,8 +484,7 @@ static void ks8995_remove(struct spi_device *spi)sysfs_remove_bin_file (&spi->dev.kobj, &ks->regs_attr);/* assert reset */ -if (ks->pdata &&gpio_is_valid (ks->pdata->reset_gpio)) -gpiod_set_value (gpio_to_desc (ks->pdata->reset_gpio),1 ); +gpiod_set_value_cansleep (ks->reset_gpio,1 ); }/* ------------------------------------------------------------------------ */
Signature · 1 line
2.37.2.789.g6183377224-goog
Re: [PATCH 3/3] net: phy: spi_ks8895: switch to using gpiod API
Quoted 5 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Signed-off-by Dmitry Torokhov <[email protected]>
Yours,
Linus Walleij
Quoted 5 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Signed-off-by Dmitry Torokhov <[email protected]>
I think net patches need [PATCH net-next] in the subject to get applied.
Yours,
Linus Walleij
Andrew Lunn
maintainerQuoted 7 lines · Linus Walleij
Quoted 4 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.
Quoted 6 lines
Quoted 1 line
Signed-off-by Dmitry Torokhov <[email protected]>Reviewed-by Linus Walleij <[email protected]>I think net patches need [PATCH net-next] in the subject to get applied.
Correct.
https://docs.kernel.org/process/maintainer-netdev.html
For the odd drive by patch, the Maintainers often do accept patches without it. So wait and see.
Andrew
Paolo Abeni
maintainerQuoted 15 lines · Andrew Lunn
Quoted 7 lines · Linus Walleij
Quoted 4 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Quoted 6 lines
Quoted 1 line
Signed-off-by Dmitry Torokhov <[email protected]>Reviewed-by Linus Walleij <[email protected]>I think net patches need [PATCH net-next] in the subject to get applied.
Quoted 6 lines
Correct.
https://docs.kernel.org/process/maintainer-netdev.html
For the odd drive by patch, the Maintainers often do accept patches without it. So wait and see.
Due to a series of unfortunate coincidences the netdev backlog has grown unusually long. Since the patches LGMT I'm going to apply them to net-next without asking a repost.
@Dmitry: next time, please add the relevant tag, thanks!
Paolo
This series was applied to netdev/net-next.git (master) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Tue, 6 Sep 2022 13:49:20 -0700 you wrote:
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/net/ethernet/davicom/dm9000.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
Here is the summary with links:
- [1/3] net: davicom: dm9000: switch to using gpiod API
https://git.kernel.org/netdev/net-next/c/db49ca38579d - [2/3] net: ks8851: switch to using gpiod API https://git.kernel.org/netdev/net-next/c/7b77bb5c8130 - [3/3] net: phy: spi_ks8895: switch to using gpiod API https://git.kernel.org/netdev/net-next/c/006534ec2804
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Paul Cercueil
maintainerHi Dmitry,
Quoted 54 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/net/ethernet/davicom/dm9000.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)drivers/net/ethernet/davicom/dm9000.c +11
-10@@ -28,8 +28,7 @@#include <linux/irq.h> #include <linux/slab.h> #include <linux/regulator/consumer.h> -#include <linux/gpio.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <asm/delay.h> #include <asm/irq.h> @@ -1421,8 +1420,7 @@ dm9000_probe(struct platform_device *pdev)int iosize;int i;u32 id_val; -int reset_gpios; -enum of_gpio_flags flags; +struct gpio_desc *reset_gpio;struct regulator *power;bool inv_mac_addr = false;u8 addr[ETH_ALEN ];@@ -1442,20 +1440,24 @@ dm9000_probe(struct platform_device *pdev)dev_dbg (dev,"regulator enabled\n" ); } - reset_gpios =of_get_named_gpio_flags (dev->of_node,"reset-gpios" ,0 , - &flags); -if (gpio_is_valid (reset_gpios)) { - ret =devm_gpio_request_one (dev, reset_gpios, flags, -"dm9000_reset" ); + reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); + ret =PTR_ERR_OR_ZERO (reset_gpio); +if (ret) { +dev_err (dev,"failed to request reset gpio: %d\n" , ret); + goto out_regulator_disable; + } + +if (reset_gpio) { + ret =gpiod_set_consumer_name (reset_gpio,"dm9000_reset" );if (ret) { - dev_err(dev, "failed to request reset gpio %d: %d\n",
drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1461
Quoted 10 lines
drivers/net/ethernet/davicom/dm9000.c +3
-2- reset_gpios, ret); +dev_err (dev,"failed to set reset gpio name: %d\n" , + ret); goto out_regulator_disable; }/* According to manual PWRST# Low Period Min 1ms */ msleep (2 ); -gpio_set_value (reset_gpios,1 ); +gpiod_set_value_cansleep (reset_gpio,0 );
Why is that 1 magically turned into a 0?
On my CI20 board I can't get the DM9000 chip to probe correctly with this patch (it fails to read the ID). If I revert this patch then everything works fine.
Cheers,
-Paul
Quoted 6 lines
drivers/net/ethernet/davicom/dm9000.c +0
-0/* Needs 3ms to read eeprom when PWRST is deasserted */ msleep (4 );}
--
2.37.2.789.g6183377224-goog
Hi Paul,
Quoted 64 lines · Paul Cercueil
Hi Dmitry,
Quoted 60 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/net/ethernet/davicom/dm9000.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)drivers/net/ethernet/davicom/dm9000.c +13
-11@@ -28,8 +28,7 @@#include <linux/irq.h> #include <linux/slab.h> #include <linux/regulator/consumer.h> -#include <linux/gpio.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <asm/delay.h> #include <asm/irq.h> @@ -1421,8 +1420,7 @@ dm9000_probe(struct platform_device *pdev)int iosize;int i;u32 id_val; -int reset_gpios; -enum of_gpio_flags flags; +struct gpio_desc *reset_gpio;struct regulator *power;bool inv_mac_addr = false;u8 addr[ETH_ALEN ];@@ -1442,20 +1440,24 @@ dm9000_probe(struct platform_device *pdev)dev_dbg (dev,"regulator enabled\n" ); } - reset_gpios =of_get_named_gpio_flags (dev->of_node,"reset-gpios" ,0 , - &flags); -if (gpio_is_valid (reset_gpios)) { - ret =devm_gpio_request_one (dev, reset_gpios, flags, -"dm9000_reset" ); + reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); + ret =PTR_ERR_OR_ZERO (reset_gpio); +if (ret) { +dev_err (dev,"failed to request reset gpio: %d\n" , ret); + goto out_regulator_disable; + } + +if (reset_gpio) { + ret =gpiod_set_consumer_name (reset_gpio,"dm9000_reset" );if (ret) { -dev_err (dev,"failed to request reset gpio %d: %d\n" , - reset_gpios, ret); +dev_err (dev,"failed to set reset gpio name: %d\n" , + ret); goto out_regulator_disable; }
Quoted 6 lines
drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1460
Quoted 4 lines
drivers/net/ethernet/davicom/dm9000.c +1
-1/* According to manual PWRST# Low Period Min 1ms */ msleep (2 ); -gpio_set_value (reset_gpios,1 ); +gpiod_set_value_cansleep (reset_gpio,0 );Why is that 1 magically turned into a 0?
Because gpiod uses logical states (think active/inactive), not absolute ones. Here we are deasserting the reset line.
Quoted 4 lines
On my CI20 board I can't get the DM9000 chip to probe correctly with this patch (it fails to read the ID).
If I revert this patch then everything works fine.
Sorry, it is my fault of course: I missed that board has incorrect annotation for the reset line. I will send out the patch below (formatted properly of course):
arch/mips/boot/dts/ingenic/ci20.dts +1 -1
@@ -438,7 +438,7 @@ dm9000@6 { ingenic,nemc-tAW = <50>; ingenic,nemc-tSTRV = <100>; - reset-gpios = <&gpf 12 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpf 12 GPIO_ACTIVE_LOW>; vcc-supply = <ð0_power>; interrupt-parent = <&gpe>;
Thanks.
Signature · 1 line
Dmitry
Paul Cercueil
maintainerQuoted 83 lines · Dmitry Torokhov
Hi Paul,
Quoted 69 lines · Paul Cercueil
Hi Dmitry,
Quoted 1 line · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API
to
Quoted 1 line
gpiod API, and removes use of
of_get_named_gpio_flags()which Iwant to
Quoted 5 lines
make private to gpiolib.
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/net/ethernet/davicom/dm9000.c | 26++++++++++++++------------
Quoted 28 lines
1 file changed, 14 insertions(+), 12 deletions(-)drivers/net/ethernet/davicom/dm9000.c +2
-4@@ -28,8 +28,7 @@#include <linux/irq.h> #include <linux/slab.h> #include <linux/regulator/consumer.h> -#include <linux/gpio.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <asm/delay.h> #include <asm/irq.h> @@ -1421,8 +1420,7 @@ dm9000_probe(struct platform_device *pdev)int iosize;int i;u32 id_val; -int reset_gpios; -enum of_gpio_flags flags; +struct gpio_desc *reset_gpio;struct regulator *power;bool inv_mac_addr = false;u8 addr[ETH_ALEN ];drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1445
Quoted 4 lines
drivers/net/ethernet/davicom/dm9000.c +0
-1@@ -1442,20 +1440,24 @@ dm9000_probe(struct platform_device *pdev)dev_dbg (dev,"regulator enabled\n" ); } - reset_gpios = of_get_named_gpio_flags(dev->of_node,"reset-gpios", 0,
drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1443
Quoted 5 lines
drivers/net/ethernet/davicom/dm9000.c +1
-4- &flags); -if (gpio_is_valid (reset_gpios)) { - ret =devm_gpio_request_one (dev, reset_gpios, flags, -"dm9000_reset" ); + reset_gpio = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_HIGH);Quoted 16 lines
drivers/net/ethernet/davicom/dm9000.c +10
-2+ ret =PTR_ERR_OR_ZERO (reset_gpio); +if (ret) { +dev_err (dev,"failed to request reset gpio: %d\n" , ret); + goto out_regulator_disable; + } + +if (reset_gpio) { + ret =gpiod_set_consumer_name (reset_gpio,"dm9000_reset" );if (ret) { -dev_err (dev,"failed to request reset gpio %d: %d\n" , - reset_gpios, ret); +dev_err (dev,"failed to set reset gpio name: %d\n" , + ret); goto out_regulator_disable; }Quoted 6 lines
drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1460
Quoted 4 lines
drivers/net/ethernet/davicom/dm9000.c +1
-1/* According to manual PWRST# Low Period Min 1ms */ msleep (2 ); -gpio_set_value (reset_gpios,1 ); +gpiod_set_value_cansleep (reset_gpio,0 );Why is that 1 magically turned into a 0?
Because gpiod uses logical states (think active/inactive), not absolute ones. Here we are deasserting the reset line.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
On my CI20 board I can't get the DM9000 chip to probe correctly
with this
patch (it fails to read the ID).
If I revert this patch then everything works fine.Sorry, it is my fault of course: I missed that board has incorrect annotation for the reset line. I will send out the patch below (formatted properly of course):
So in *theory* you wouldn't fix it like that, because the driver should work with old Device Tree files, even if it had a broken property, as long as it used to work in the past.
The ci20.dts file however is always built into the kernel and I'm not aware of anybody doing things differently. As long as you make that explicit in your commit message I think Rob won't mind.
If he does, or if more boards are affected, an alternative is to switch the polarity of the GPIO in the driver, like so:
if (of_machine_is_compatible("mips,ci20") &&
gpiod_is_active_low(reset_gpio)) {
gpiod_toggle_active_low(reset_gpio);
}Cheers,
-Paul
Quoted 19 lines
arch/mips/boot/dts/ingenic/ci20.dts +1
-1@@ -438,7 +438,7 @@ dm9000@6 { ingenic,nemc-tAW = <50>; ingenic,nemc-tSTRV = <100>; - reset-gpios = <&gpf 12 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpf 12 GPIO_ACTIVE_LOW>; vcc-supply = <ð0_power>; interrupt-parent = <&gpe>;Thanks.
--
Dmitry
Quoted 104 lines · Paul Cercueil
Quoted 83 lines · Dmitry Torokhov
Hi Paul,
Quoted 69 lines · Paul Cercueil
Hi Dmitry,
Quoted 1 line · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API
to
Quoted 1 line
gpiod API, and removes use of
of_get_named_gpio_flags()which Iwant to
Quoted 5 lines
make private to gpiolib.
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/net/ethernet/davicom/dm9000.c | 26++++++++++++++------------
Quoted 28 lines
1 file changed, 14 insertions(+), 12 deletions(-)drivers/net/ethernet/davicom/dm9000.c +2
-4@@ -28,8 +28,7 @@#include <linux/irq.h> #include <linux/slab.h> #include <linux/regulator/consumer.h> -#include <linux/gpio.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <asm/delay.h> #include <asm/irq.h> @@ -1421,8 +1420,7 @@ dm9000_probe(struct platform_device *pdev)int iosize;int i;u32 id_val; -int reset_gpios; -enum of_gpio_flags flags; +struct gpio_desc *reset_gpio;struct regulator *power;bool inv_mac_addr = false;u8 addr[ETH_ALEN ];drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1445
Quoted 4 lines
drivers/net/ethernet/davicom/dm9000.c +0
-1@@ -1442,20 +1440,24 @@ dm9000_probe(struct platform_device *pdev)dev_dbg (dev,"regulator enabled\n" ); } - reset_gpios = of_get_named_gpio_flags(dev->of_node,"reset-gpios", 0,
drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1443
Quoted 5 lines
drivers/net/ethernet/davicom/dm9000.c +1
-4- &flags); -if (gpio_is_valid (reset_gpios)) { - ret =devm_gpio_request_one (dev, reset_gpios, flags, -"dm9000_reset" ); + reset_gpio = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_HIGH);Quoted 16 lines
drivers/net/ethernet/davicom/dm9000.c +10
-2+ ret =PTR_ERR_OR_ZERO (reset_gpio); +if (ret) { +dev_err (dev,"failed to request reset gpio: %d\n" , ret); + goto out_regulator_disable; + } + +if (reset_gpio) { + ret =gpiod_set_consumer_name (reset_gpio,"dm9000_reset" );if (ret) { -dev_err (dev,"failed to request reset gpio %d: %d\n" , - reset_gpios, ret); +dev_err (dev,"failed to set reset gpio name: %d\n" , + ret); goto out_regulator_disable; }Quoted 6 lines
drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1460
Quoted 4 lines
drivers/net/ethernet/davicom/dm9000.c +1
-1/* According to manual PWRST# Low Period Min 1ms */ msleep (2 ); -gpio_set_value (reset_gpios,1 ); +gpiod_set_value_cansleep (reset_gpio,0 );Why is that 1 magically turned into a 0?
Because gpiod uses logical states (think active/inactive), not absolute ones. Here we are deasserting the reset line.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
On my CI20 board I can't get the DM9000 chip to probe correctly
with this
patch (it fails to read the ID).
If I revert this patch then everything works fine.Sorry, it is my fault of course: I missed that board has incorrect annotation for the reset line. I will send out the patch below (formatted properly of course):
So in *theory* you wouldn't fix it like that, because the driver should work with old Device Tree files, even if it had a broken property, as long as it used to work in the past.
The
ci20.dtsfile however is always built into the kernel and I'm not aware of anybody doing things differently. As long as you make that explicit in your commit message I think Rob won't mind.
Quoted 7 lines
If he does, or if more boards are affected, an alternative is to switch the polarity of the GPIO in the driver, like so:
if (
of_machine_is_compatible("mips,ci20")&&gpiod_is_active_low(reset_gpio)) { gpiod_toggle_active_low(reset_gpio); }
Right, we are typically hiding this kind of quirks in gpiolib-of instead of polluting drivers, but yes, it is possible.
Thanks.
Signature · 1 line
Dmitry
Andrew Lunn
maintainerQuoted 4 lines
Quoted 1 line
Why is that 1 magically turned into a 0?
Because gpiod uses logical states (think active/inactive), not absolute ones. Here we are deasserting the reset line.
This is the same question/answer you had with me. Maybe it is worth putting this into the commit message for other patches in your series to prevent this question/answer again and again.
Andrew
Quoted 8 lines · Andrew Lunn
Quoted 4 lines
Quoted 1 line
Why is that 1 magically turned into a 0?
Because gpiod uses logical states (think active/inactive), not absolute ones. Here we are deasserting the reset line.
This is the same question/answer you had with me. Maybe it is worth putting this into the commit message for other patches in your series to prevent this question/answer again and again.
Right... Actually I think I'll go and define that GPIO_STATE_ACTIVE/ GPIO_STATE_INACTIVE and try to get Linus and Bart to accept it as code speaks louder than words ;)
Thanks.
Signature · 1 line
Dmitry
Quoted 6 lines · Dmitry Torokhov
Quoted 5 lines · Andrew Lunn
Quoted 4 lines
Quoted 1 line
Why is that 1 magically turned into a 0?
Because gpiod uses logical states (think active/inactive), not absolute ones. Here we are deasserting the reset line.
Quoted 7 lines
Quoted 3 lines
This is the same question/answer you had with me. Maybe it is worth putting this into the commit message for other patches in your series to prevent this question/answer again and again.
Right... Actually I think I'll go and define that GPIO_STATE_ACTIVE/
GPIO_STATE_INACTIVEand try to get Linus and Bart to accept it as code speaks louder than words ;)
What I have said about that is that it should be accompanied by some sed or cocinelle script to change this everywhere in the kernel instead of using 0/1 to the gpiod_set/direction etc functions. Then Torvalds can run that toward the end of the merge window to just change this everywhere at once and be done with it.
The reason I want it that way is that I am royally tired of changes that begin in one tiny corner and then the change keeps confusing users for years until it is finally fixed up 15 kernel revisions later.
Since that has created a support nightmare in the past, I am now advocating an all-or-nothing approach with that type of change.
Yours,
Linus Walleij