f4c122de93709326146e312a3250e59425b37575
[openwrt/staging/ldir.git] / target / linux / bcm27xx / patches-5.4 / 950-0819-media-i2c-imx290-fix-reset-GPIO-pin-handling.patch
1 From 47f49370b3c1c7f4d4aae855966d2a3beef6c6d4 Mon Sep 17 00:00:00 2001
2 From: Andrey Konovalov <andrey.konovalov@linaro.org>
3 Date: Fri, 12 Jun 2020 15:53:48 +0200
4 Subject: [PATCH] media: i2c: imx290: fix reset GPIO pin handling
5
6 Commit 3909a92d7df622b41b9ceeeea694e641cad7667b upstream.
7
8 According to https://www.kernel.org/doc/Documentation/gpio/consumer.txt,
9
10 - all of the gpiod_set_value_xxx() functions operate with the *logical*
11 value. So in imx290_power_on() the reset signal should be cleared
12 (de-asserted) with gpiod_set_value_cansleep(imx290->rst_gpio, 0), and in
13 imx290_power_off() the value of 1 must be used to apply/assert the reset
14 to the sensor. In the device tree the reset pin is described as
15 GPIO_ACTIVE_LOW, and gpiod_set_value_xxx() functions take this into
16 account,
17
18 - when devm_gpiod_get_optional() is called with GPIOD_ASIS, the GPIO is
19 not initialized, and the direction must be set later; using a GPIO
20 without setting its direction first is illegal and will result in undefined
21 behavior. Fix this by using GPIOD_OUT_HIGH instead of GPIOD_ASIS (this
22 asserts the reset signal to the sensor initially).
23
24 Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
25 Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
26 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
27 Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
28 ---
29 drivers/media/i2c/imx290.c | 7 ++++---
30 1 file changed, 4 insertions(+), 3 deletions(-)
31
32 --- a/drivers/media/i2c/imx290.c
33 +++ b/drivers/media/i2c/imx290.c
34 @@ -628,7 +628,7 @@ static int imx290_power_on(struct device
35 }
36
37 usleep_range(1, 2);
38 - gpiod_set_value_cansleep(imx290->rst_gpio, 1);
39 + gpiod_set_value_cansleep(imx290->rst_gpio, 0);
40 usleep_range(30000, 31000);
41
42 return 0;
43 @@ -641,7 +641,7 @@ static int imx290_power_off(struct devic
44 struct imx290 *imx290 = to_imx290(sd);
45
46 clk_disable_unprepare(imx290->xclk);
47 - gpiod_set_value_cansleep(imx290->rst_gpio, 0);
48 + gpiod_set_value_cansleep(imx290->rst_gpio, 1);
49 regulator_bulk_disable(IMX290_NUM_SUPPLIES, imx290->supplies);
50
51 return 0;
52 @@ -757,7 +757,8 @@ static int imx290_probe(struct i2c_clien
53 goto free_err;
54 }
55
56 - imx290->rst_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
57 + imx290->rst_gpio = devm_gpiod_get_optional(dev, "reset",
58 + GPIOD_OUT_HIGH);
59 if (IS_ERR(imx290->rst_gpio)) {
60 dev_err(dev, "Cannot get reset gpio\n");
61 ret = PTR_ERR(imx290->rst_gpio);