Re: [PATCH 36/43] gpio: pca953x: Add reset-gpios property

2014-06-11 Thread Philipp Zabel
Am Samstag, den 07.06.2014, 14:56 -0700 schrieb Steve Longerbeam:
[...]
>  static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val,
> @@ -735,6 +741,26 @@ static int pca953x_probe(struct i2c_client *client,
>   /* If I2C node has no interrupts property, disable GPIO 
> interrupts */
>   if (of_find_property(client->dev.of_node, "interrupts", NULL) 
> == NULL)
>   irq_base = -1;
> +
> + /* see if we need to de-assert a reset pin */
> + ret = of_get_named_gpio_flags(client->dev.of_node,
> +   "reset-gpios", 0,
> +   &chip->reset_gpio_flags);
> + if (gpio_is_valid(ret)) {
> + chip->reset_gpio = ret;
> + ret = devm_gpio_request_one(&client->dev,
> + chip->reset_gpio,
> + GPIOF_DIR_OUT,
> + "pca953x_reset");
> + if (ret == 0) {
> + /* bring chip out of reset */
> + dev_info(&client->dev, "releasing reset\n");

I think dev_dbg would be more appropriate.

> + gpio_set_value(chip->reset_gpio,
> +(chip->reset_gpio_flags ==
> + OF_GPIO_ACTIVE_LOW) ? 1 : 0);
> + }

You could use the gpiod API (include/gpio/consumer.h) here and have it
do the polarity handling automatically.

regards
Philipp

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 36/43] gpio: pca953x: Add reset-gpios property

2014-06-07 Thread Steve Longerbeam
Add optional reset-gpios property. If present, de-assert the
specified reset gpio pin to bring the chip out of reset.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpio/gpio-pca953x.c |   26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index d550d8e..6e212f7 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -22,6 +22,7 @@
 #include 
 #ifdef CONFIG_OF_GPIO
 #include 
+#include 
 #endif
 
 #define PCA953X_INPUT  0
@@ -98,6 +99,11 @@ struct pca953x_chip {
struct gpio_chip gpio_chip;
const char *const *names;
int chip_type;
+
+#ifdef CONFIG_OF_GPIO
+   enum of_gpio_flags reset_gpio_flags;
+   int reset_gpio;
+#endif
 };
 
 static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val,
@@ -735,6 +741,26 @@ static int pca953x_probe(struct i2c_client *client,
/* If I2C node has no interrupts property, disable GPIO 
interrupts */
if (of_find_property(client->dev.of_node, "interrupts", NULL) 
== NULL)
irq_base = -1;
+
+   /* see if we need to de-assert a reset pin */
+   ret = of_get_named_gpio_flags(client->dev.of_node,
+ "reset-gpios", 0,
+ &chip->reset_gpio_flags);
+   if (gpio_is_valid(ret)) {
+   chip->reset_gpio = ret;
+   ret = devm_gpio_request_one(&client->dev,
+   chip->reset_gpio,
+   GPIOF_DIR_OUT,
+   "pca953x_reset");
+   if (ret == 0) {
+   /* bring chip out of reset */
+   dev_info(&client->dev, "releasing reset\n");
+   gpio_set_value(chip->reset_gpio,
+  (chip->reset_gpio_flags ==
+   OF_GPIO_ACTIVE_LOW) ? 1 : 0);
+   }
+   } else if (ret == -EPROBE_DEFER)
+   return ret;
 #endif
}
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html