Skip to contentSkip to conversation

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

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

lore
Share & tools
lore
#0 lore raw

PATCH v3 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.

---

Changes from v2:
- Removed ifdef that would break build as suggested by Simon
- Added Simon's and Heko's Reviewed-by

Changes from v1:
- Simon's feedback on ifdef vs IS_ENABLED()

Cheers,
Moritz

---
 drivers/i2c/muxes/pca954x.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/i2c/muxes/pca954x.c +39 -1
index 383f72f552..01ca1ff48d 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,8 @@
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
-#include <asm/gpio.h>
+
+#include <asm-generic/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -30,6 +32,7 @@ struct chip_desc {
 struct pca954x_priv {
 	u32 addr; /* I2C mux address */
 	u32 width; /* I2C mux width - number of busses */
+	struct gpio_desc gpio_mux_reset;
 };
 
 static const struct chip_desc chips[] = {
@@ -105,10 +108,45 @@ static int pca954x_ofdata_to_platdata(struct udevice *dev)
 	return 0;
 }
 
+static int pca954x_probe(struct udevice *dev)
+{
+	if (IS_ENABLED(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);
+	}
+
+	return 0;
+}
+
+static int pca954x_remove(struct udevice *dev)
+{
+	if (IS_ENABLED(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);
+	}
+
+	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 v3 1/1 i2c: muxes: pca954x: Add support for GPIO reset line

Hello Moritz,

Am 12.09.2017 um 15:46 schrieb Moritz Fischer:

Quoted 15 lines

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

---

Changes from v2:

(quoted diff) +0 -2
-  Removed ifdef that would break build as suggested by Simon
-  Added Simon's and Heko's Reviewed-by

Changes from v1:
- Simon's feedback on ifdef vs IS_ENABLED()

Quoted 6 lines

Cheers,
Moritz

---
  drivers/i2c/muxes/pca954x.c | 40 +++++++++++++++++++++++++++++++++++++++-
  1 file changed, 39 insertions(+), 1 deletion(-)

Applied to u-booti2c.git

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de