From: Muzaffer Kadir <[email protected]>

reset-gpio is already documented in dt-bindings but never implemented
in the driver.

Signed-off-by: Muzaffer Kadir <[email protected]>
---
 drivers/media/i2c/imx258.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index 9c3a6579df0d..4a0663e816b5 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -9,6 +9,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
 #include <linux/unaligned.h>
+#include <linux/gpio/consumer.h>
 
 #include <media/v4l2-cci.h>
 #include <media/v4l2-ctrls.h>
@@ -681,6 +682,7 @@ struct imx258 {
 
        struct clk *clk;
        struct regulator_bulk_data supplies[IMX258_NUM_SUPPLIES];
+       struct gpio_desc *reset_gpio;
 };
 
 static inline struct imx258 *to_imx258(struct v4l2_subdev *_sd)
@@ -1127,10 +1129,23 @@ static int imx258_power_on(struct device *dev)
        ret = clk_prepare_enable(imx258->clk);
        if (ret) {
                dev_err(dev, "failed to enable clock\n");
-               regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies);
+               goto err_disable_regulators;
+       }
+
+       ret = gpiod_set_value_cansleep(imx258->reset_gpio, 0);
+       if (ret) {
+               dev_err(dev, "failed to deassert reset\n");
+               goto err_disable_clk;
        }
        fsleep(400);
 
+       return ret;
+
+err_disable_clk:
+       clk_disable_unprepare(imx258->clk);
+err_disable_regulators:
+       regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies);
+
        return ret;
 }
 
@@ -1139,6 +1154,7 @@ static int imx258_power_off(struct device *dev)
        struct v4l2_subdev *sd = dev_get_drvdata(dev);
        struct imx258 *imx258 = to_imx258(sd);
 
+       gpiod_set_value_cansleep(imx258->reset_gpio, 1);
        clk_disable_unprepare(imx258->clk);
        regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies);
 
@@ -1383,6 +1399,12 @@ static int imx258_probe(struct i2c_client *client)
                return ret;
        }
 
+       imx258->reset_gpio = devm_gpiod_get_optional(imx258->dev, "reset",
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(imx258->reset_gpio))
+               return dev_err_probe(imx258->dev, PTR_ERR(imx258->reset_gpio),
+                                    "Failed to get reset-gpios\n");
+
        ret = imx258_get_regulators(imx258);
        if (ret)
                return dev_err_probe(imx258->dev, ret,

-- 
2.54.0



Reply via email to