Skip to contentSkip to conversation

i2c: muxes: pca954x: Add support for GPIO reset line

PATCH New Moritz Fischer 2 participants 4 messages Sep 5, 2017 – Sep 12, 2017 I2C muxes

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: muxes: pca954x: Add support for GPIO reset line

This commit adds support for GPIO reset lines matching the common linux "reset-gpios" devicetree binding.

Cc Heiko Schocher <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Marek Behún <[email protected]>
Cc Simon Glass <[email protected]>
Cc Michal Simek <[email protected]>
---
 drivers/i2c/muxes/pca954x.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
drivers/i2c/muxes/pca954x.c +43 -1
index 383f72f552..dd28ff057b 100644
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015 - 2016 Xilinx, Inc.
+ * Copyright (C) 2017 National Instruments Corp
  * Written by Michal Simek
  *
  * SPDX-License-Identifier:	GPL-2.0+
@@ -9,7 +10,10 @@
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
-#include <asm/gpio.h>
+
+#if CONFIG_DM_GPIO
+# include <asm-generic/gpio.h>
+#endif /* CONFIG_DM_GPIO */
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -30,6 +34,9 @@ struct chip_desc {
 struct pca954x_priv {
 	u32 addr; /* I2C mux address */
 	u32 width; /* I2C mux width - number of busses */
+#ifdef CONFIG_DM_GPIO
+	struct gpio_desc gpio_mux_reset;
+#endif /* CONFIG_DM_GPIO */
 };
 
 static const struct chip_desc chips[] = {
@@ -105,10 +112,45 @@ static int pca954x_ofdata_to_platdata(struct udevice *dev)
 	return 0;
 }
 
+static int pca954x_probe(struct udevice *dev)
+{
+#ifdef CONFIG_DM_GPIO
+	struct pca954x_priv *priv = dev_get_priv(dev);
+	int err;
+
+	err = gpio_request_by_name(dev, "reset-gpios", 0,
+			&priv->gpio_mux_reset, GPIOD_IS_OUT);
+
+	/* it's optional so only bail if we get a real error */
+	if (err && (err != -ENOENT))
+		return err;
+
+	/* dm will take care of polarity */
+	if (dm_gpio_is_valid(&priv->gpio_mux_reset))
+		dm_gpio_set_value(&priv->gpio_mux_reset, 0);
+
+#endif /* CONFIG_DM_GPIO */
+	return 0;
+}
+
+static int pca954x_remove(struct udevice *dev)
+{
+#ifdef CONFIG_DM_GPIO
+	struct pca954x_priv *priv = dev_get_priv(dev);
+
+	if (dm_gpio_is_valid(&priv->gpio_mux_reset))
+		dm_gpio_free(dev, &priv->gpio_mux_reset);
+
+#endif /* CONFIG_DM_GPIO */
+	return 0;
+}
+
 U_BOOT_DRIVER(pca954x) = {
 	.name = "pca954x",
 	.id = UCLASS_I2C_MUX,
 	.of_match = pca954x_ids,
+	.probe = pca954x_probe,
+	.remove = pca954x_remove,
 	.ops = &pca954x_ops,
 	.ofdata_to_platdata = pca954x_ofdata_to_platdata,
 	.priv_auto_alloc_size = sizeof(struct pca954x_priv),
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/1 i2c: muxes: pca954x: Add support for GPIO reset line

Quoted 26 lines · Moritz Fischer

This commit adds support for GPIO reset lines matching the common linux "reset-gpios" devicetree binding.

Cc Heiko Schocher <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Marek Behún <[email protected]>
Cc Simon Glass <[email protected]>
Cc Michal Simek <[email protected]>
---
 drivers/i2c/muxes/pca954x.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
drivers/i2c/muxes/pca954x.c +1 -0
index 383f72f552..dd28ff057b 100644
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015 - 2016 Xilinx, Inc.
+ * Copyright (C) 2017 National Instruments Corp
  * Written by Michal Simek
  *
  * SPDX-License-Identifier:    GPL-2.0+

drivers/i2c/muxes/pca954x.c line 16

Quoted 8 lines
drivers/i2c/muxes/pca954x.c +4 -1
@@ -9,7 +10,10 @@
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
-#include <asm/gpio.h>
+
+#if CONFIG_DM_GPIO
+# include <asm-generic/gpio.h>
+#endif /* CONFIG_DM_GPIO */

Can we drop the #ifdef?

Quoted 14 lines
drivers/i2c/muxes/pca954x.c +3 -0
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -30,6 +34,9 @@ struct chip_desc {
 struct pca954x_priv {
        u32 addr; /* I2C mux address */
        u32 width; /* I2C mux width - number of busses */
+#ifdef CONFIG_DM_GPIO
+       struct gpio_desc gpio_mux_reset;
+#endif /* CONFIG_DM_GPIO */
 };
 
 static const struct chip_desc chips[] = {

drivers/i2c/muxes/pca954x.c static int pca954x_ofdata_to_platdata(struct udevice *dev) · line 117

Quoted 6 lines
drivers/i2c/muxes/pca954x.c +3 -0
@@ -105,10 +112,45 @@ static int pca954x_ofdata_to_platdata(struct udevice *dev)
        return 0;
 }
 
+static int pca954x_probe(struct udevice *dev)
+{
+#ifdef CONFIG_DM_GPIO

Can we use if (IS_ENABLED(CONFIG_DM_GPIO)) ?

Quoted 42 lines
drivers/i2c/muxes/pca954x.c +32 -1
+       struct pca954x_priv *priv = dev_get_priv(dev);
+       int err;
+
+       err = gpio_request_by_name(dev, "reset-gpios", 0,
+                       &priv->gpio_mux_reset, GPIOD_IS_OUT);
+
+       /* it's optional so only bail if we get a real error */
+       if (err && (err != -ENOENT))
+               return err;
+
+       /* dm will take care of polarity */
+       if (dm_gpio_is_valid(&priv->gpio_mux_reset))
+               dm_gpio_set_value(&priv->gpio_mux_reset, 0);
+
+#endif /* CONFIG_DM_GPIO */
+       return 0;
+}
+
+static int pca954x_remove(struct udevice *dev)
+{
+#ifdef CONFIG_DM_GPIO
+       struct pca954x_priv *priv = dev_get_priv(dev);
+
+       if (dm_gpio_is_valid(&priv->gpio_mux_reset))
+               dm_gpio_free(dev, &priv->gpio_mux_reset);
+
+#endif /* CONFIG_DM_GPIO */
+       return 0;
+}
+
 U_BOOT_DRIVER(pca954x) = {
        .name = "pca954x",
        .id = UCLASS_I2C_MUX,
        .of_match = pca954x_ids,
+       .probe = pca954x_probe,
+       .remove = pca954x_remove,
        .ops = &pca954x_ops,
        .ofdata_to_platdata = pca954x_ofdata_to_platdata,
        .priv_auto_alloc_size = sizeof(struct pca954x_priv),
--

2.14.1

#2 lore raw

PATCH 1/1 i2c: muxes: pca954x: Add support for GPIO reset line

Hi Simon,

Quoted 29 lines · Simon Glass
Quoted 28 lines · Moritz Fischer

This commit adds support for GPIO reset lines matching the common linux "reset-gpios" devicetree binding.

Cc Heiko Schocher <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Marek Behún <[email protected]>
Cc Simon Glass <[email protected]>
Cc Michal Simek <[email protected]>
---
 drivers/i2c/muxes/pca954x.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
drivers/i2c/muxes/pca954x.c +1 -0
index 383f72f552..dd28ff057b 100644
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015 - 2016 Xilinx, Inc.
+ * Copyright (C) 2017 National Instruments Corp
  * Written by Michal Simek
  *
  * SPDX-License-Identifier:    GPL-2.0+
@@ -9,7 +10,10 @@
 #include <dm.h>
 #include <errno.h>
Quoted 8 lines

drivers/i2c/muxes/pca954x.c line 16

Quoted 6 lines
drivers/i2c/muxes/pca954x.c +4 -1
 #include <i2c.h>
-#include <asm/gpio.h>
+
+#if CONFIG_DM_GPIO
+# include <asm-generic/gpio.h>
+#endif /* CONFIG_DM_GPIO */

Can we drop the #ifdef?

Yeah, will do.

Quoted 18 lines
Quoted 18 lines
drivers/i2c/muxes/pca954x.c +3 -0
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -30,6 +34,9 @@ struct chip_desc {
 struct pca954x_priv {
        u32 addr; /* I2C mux address */
        u32 width; /* I2C mux width - number of busses */
+#ifdef CONFIG_DM_GPIO
+       struct gpio_desc gpio_mux_reset;
+#endif /* CONFIG_DM_GPIO */
 };
 
 static const struct chip_desc chips[] = {
@@ -105,10 +112,45 @@ static int pca954x_ofdata_to_platdata(struct udevice *dev)
        return 0;
 }
 
Quoted 5 lines

drivers/i2c/muxes/pca954x.c static int pca954x_ofdata_to_platdata(struct udevice *dev) · line 117

Quoted 3 lines
drivers/i2c/muxes/pca954x.c +3 -0
+static int pca954x_probe(struct udevice *dev)
+{
+#ifdef CONFIG_DM_GPIO

Can we use if (IS_ENABLED(CONFIG_DM_GPIO)) ?

I suppose. I was wondering. Is this in general preferable?

Quoted 35 lines
Quoted 35 lines
drivers/i2c/muxes/pca954x.c +30 -0
+       struct pca954x_priv *priv = dev_get_priv(dev);
+       int err;
+
+       err = gpio_request_by_name(dev, "reset-gpios", 0,
+                       &priv->gpio_mux_reset, GPIOD_IS_OUT);
+
+       /* it's optional so only bail if we get a real error */
+       if (err && (err != -ENOENT))
+               return err;
+
+       /* dm will take care of polarity */
+       if (dm_gpio_is_valid(&priv->gpio_mux_reset))
+               dm_gpio_set_value(&priv->gpio_mux_reset, 0);
+
+#endif /* CONFIG_DM_GPIO */
+       return 0;
+}
+
+static int pca954x_remove(struct udevice *dev)
+{
+#ifdef CONFIG_DM_GPIO
+       struct pca954x_priv *priv = dev_get_priv(dev);
+
+       if (dm_gpio_is_valid(&priv->gpio_mux_reset))
+               dm_gpio_free(dev, &priv->gpio_mux_reset);
+
+#endif /* CONFIG_DM_GPIO */
+       return 0;
+}
+
 U_BOOT_DRIVER(pca954x) = {
        .name = "pca954x",
        .id = UCLASS_I2C_MUX,
        .of_match = pca954x_ids,
Quoted 8 lines
Quoted 8 lines
drivers/i2c/muxes/pca954x.c +2 -1
+       .probe = pca954x_probe,
+       .remove = pca954x_remove,
        .ops = &pca954x_ops,
        .ofdata_to_platdata = pca954x_ofdata_to_platdata,
        .priv_auto_alloc_size = sizeof(struct pca954x_priv),
--

2.14.1

Thanks for the review,

Moritz

#3 lore raw

PATCH 1/1 i2c: muxes: pca954x: Add support for GPIO reset line

+Tom for question below

Hi Moritz,

Quoted 60 lines · Moritz Fischer

Hi Simon,

Quoted 29 lines · Simon Glass
Quoted 28 lines · Moritz Fischer

This commit adds support for GPIO reset lines matching the common linux "reset-gpios" devicetree binding.

Cc Heiko Schocher <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Marek Behún <[email protected]>
Cc Simon Glass <[email protected]>
Cc Michal Simek <[email protected]>
---
 drivers/i2c/muxes/pca954x.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
drivers/i2c/muxes/pca954x.c +1 -0
index 383f72f552..dd28ff057b 100644
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015 - 2016 Xilinx, Inc.
+ * Copyright (C) 2017 National Instruments Corp
  * Written by Michal Simek
  *
  * SPDX-License-Identifier:    GPL-2.0+
@@ -9,7 +10,10 @@
 #include <dm.h>
 #include <errno.h>
Quoted 8 lines

drivers/i2c/muxes/pca954x.c line 16

Quoted 6 lines
drivers/i2c/muxes/pca954x.c +4 -1
 #include <i2c.h>
-#include <asm/gpio.h>
+
+#if CONFIG_DM_GPIO
+# include <asm-generic/gpio.h>
+#endif /* CONFIG_DM_GPIO */

Can we drop the #ifdef?

Yeah, will do.

Quoted 18 lines
Quoted 18 lines
drivers/i2c/muxes/pca954x.c +3 -0
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -30,6 +34,9 @@ struct chip_desc {
 struct pca954x_priv {
        u32 addr; /* I2C mux address */
        u32 width; /* I2C mux width - number of busses */
+#ifdef CONFIG_DM_GPIO
+       struct gpio_desc gpio_mux_reset;
+#endif /* CONFIG_DM_GPIO */
 };
 
 static const struct chip_desc chips[] = {
@@ -105,10 +112,45 @@ static int pca954x_ofdata_to_platdata(struct udevice *dev)
        return 0;
 }
 
Quoted 7 lines
Quoted 5 lines

drivers/i2c/muxes/pca954x.c static int pca954x_ofdata_to_platdata(struct udevice *dev) · line 117

Quoted 3 lines
drivers/i2c/muxes/pca954x.c +3 -0
+static int pca954x_probe(struct udevice *dev)
+{
+#ifdef CONFIG_DM_GPIO

Can we use if (IS_ENABLED(CONFIG_DM_GPIO)) ?

I suppose. I was wondering. Is this in general preferable?

Well one benefit is that it reduces build-time code branching so we can potentially detect build errors more easily (e.g. this driver could be enabled for sandbox). We have traditionally had loads of #ifdefs in U-Boot and IMO they make the code harder to read. Note that using if() relies on not using -O0 in many cases but I think we gave up on supporting -O0 some time ago since debugging of optimised code is better these days.

Tom, what do you think?

Regards,
Simon