media: ccs: Request for "reset" GPIO
authorSakari Ailus <sakari.ailus@linux.intel.com>
Thu, 18 Jun 2020 11:12:51 +0000 (13:12 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 2 Dec 2020 14:52:09 +0000 (15:52 +0100)
The DT bindings documented "reset-gpios" property but the driver never
made use of it. Instead it used a GPIO called "xshutdown", with apprently
wrong polarity.

Fix this by requesting "reset" GPIO with the right polarity first, and if
that fails, then request "xshutdown" GPIO with the old polarity. This way
it works for new users as expected while if someone, somewhere, depended
on "xshutdown" GPIO, that continues to work as well.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/i2c/ccs/ccs-core.c
drivers/media/i2c/ccs/ccs.h

index bddfee637f333d53b6002aa8de152856e61d6036..69e7990c65f322616b56c3e493ca6fed1bc475ba 100644 (file)
@@ -1295,6 +1295,7 @@ static int ccs_power_on(struct device *dev)
        }
        usleep_range(1000, 1000);
 
+       gpiod_set_value(sensor->reset, 0);
        gpiod_set_value(sensor->xshutdown, 1);
 
        sleep = SMIAPP_RESET_DELAY(sensor->hwcfg->ext_clk);
@@ -1381,6 +1382,7 @@ static int ccs_power_on(struct device *dev)
        return 0;
 
 out_cci_addr_fail:
+       gpiod_set_value(sensor->reset, 1);
        gpiod_set_value(sensor->xshutdown, 0);
        clk_disable_unprepare(sensor->ext_clk);
 
@@ -1407,6 +1409,7 @@ static int ccs_power_off(struct device *dev)
        if (sensor->hwcfg->i2c_addr_alt)
                ccs_write(sensor, SOFTWARE_RESET, CCS_SOFTWARE_RESET_ON);
 
+       gpiod_set_value(sensor->reset, 1);
        gpiod_set_value(sensor->xshutdown, 0);
        clk_disable_unprepare(sensor->ext_clk);
        usleep_range(5000, 5000);
@@ -3008,8 +3011,15 @@ static int ccs_probe(struct i2c_client *client)
                return -EINVAL;
        }
 
-       sensor->xshutdown = devm_gpiod_get_optional(&client->dev, "xshutdown",
-                                                   GPIOD_OUT_LOW);
+       sensor->reset = devm_gpiod_get_optional(&client->dev, "reset",
+                                               GPIOD_OUT_HIGH);
+       if (IS_ERR(sensor->reset))
+               return PTR_ERR(sensor->reset);
+       /* Support old users that may have used "xshutdown" property. */
+       if (!sensor->reset)
+               sensor->xshutdown = devm_gpiod_get_optional(&client->dev,
+                                                           "xshutdown",
+                                                           GPIOD_OUT_LOW);
        if (IS_ERR(sensor->xshutdown))
                return PTR_ERR(sensor->xshutdown);
 
index 8933f3d40fa562fa54db3967dbc41a8dd714272f..bfe39e02f5e9cee6fc193414dddbfcaecff91cf3 100644 (file)
@@ -219,6 +219,7 @@ struct ccs_sensor {
        struct regulator *vana;
        struct clk *ext_clk;
        struct gpio_desc *xshutdown;
+       struct gpio_desc *reset;
        void *ccs_limits;
        u8 nbinning_subtypes;
        struct ccs_binning_subtype binning_subtypes[CCS_LIM_BINNING_SUB_TYPE_MAX_N + 1];