]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
media: hi556: Add support for reset GPIO
authorHans de Goede <hdegoede@redhat.com>
Mon, 15 Apr 2024 13:10:36 +0000 (15:10 +0200)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 22 Apr 2024 09:41:05 +0000 (11:41 +0200)
On some ACPI platforms, such as Chromebooks the ACPI methods to
change the power-state (_PS0 and _PS3) fully take care of powering
on/off the sensor.

On other ACPI platforms, such as e.g. various HP models with IPU6 +
hi556 sensor, the sensor driver must control the reset GPIO itself.

Add support for having the driver control an optional reset GPIO.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/i2c/hi556.c

index c54cd49e56a1d2463d08ae8d66d22e9749ddd973..e084f7888e29af39b039f5b2ed3cc51ef2e25a5d 100644 (file)
@@ -4,6 +4,7 @@
 #include <asm/unaligned.h>
 #include <linux/acpi.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
@@ -633,6 +634,9 @@ struct hi556 {
        struct v4l2_ctrl *hblank;
        struct v4l2_ctrl *exposure;
 
+       /* GPIOs, clocks, etc. */
+       struct gpio_desc *reset_gpio;
+
        /* Current mode */
        const struct hi556_mode *cur_mode;
 
@@ -1276,6 +1280,25 @@ static void hi556_remove(struct i2c_client *client)
        mutex_destroy(&hi556->mutex);
 }
 
+static int hi556_suspend(struct device *dev)
+{
+       struct v4l2_subdev *sd = dev_get_drvdata(dev);
+       struct hi556 *hi556 = to_hi556(sd);
+
+       gpiod_set_value_cansleep(hi556->reset_gpio, 1);
+       return 0;
+}
+
+static int hi556_resume(struct device *dev)
+{
+       struct v4l2_subdev *sd = dev_get_drvdata(dev);
+       struct hi556 *hi556 = to_hi556(sd);
+
+       gpiod_set_value_cansleep(hi556->reset_gpio, 0);
+       usleep_range(5000, 5500);
+       return 0;
+}
+
 static int hi556_probe(struct i2c_client *client)
 {
        struct hi556 *hi556;
@@ -1295,12 +1318,24 @@ static int hi556_probe(struct i2c_client *client)
 
        v4l2_i2c_subdev_init(&hi556->sd, client, &hi556_subdev_ops);
 
+       hi556->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
+                                                   GPIOD_OUT_HIGH);
+       if (IS_ERR(hi556->reset_gpio))
+               return dev_err_probe(&client->dev, PTR_ERR(hi556->reset_gpio),
+                                    "failed to get reset GPIO\n");
+
        full_power = acpi_dev_state_d0(&client->dev);
        if (full_power) {
+               /* Ensure non ACPI managed resources are enabled */
+               ret = hi556_resume(&client->dev);
+               if (ret)
+                       return dev_err_probe(&client->dev, ret,
+                                            "failed to power on sensor\n");
+
                ret = hi556_identify_module(hi556);
                if (ret) {
                        dev_err(&client->dev, "failed to find sensor: %d", ret);
-                       return ret;
+                       goto probe_error_power_off;
                }
        }
 
@@ -1345,9 +1380,16 @@ probe_error_v4l2_ctrl_handler_free:
        v4l2_ctrl_handler_free(hi556->sd.ctrl_handler);
        mutex_destroy(&hi556->mutex);
 
+probe_error_power_off:
+       if (full_power)
+               hi556_suspend(&client->dev);
+
        return ret;
 }
 
+static DEFINE_RUNTIME_DEV_PM_OPS(hi556_pm_ops, hi556_suspend, hi556_resume,
+                                NULL);
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id hi556_acpi_ids[] = {
        {"INT3537"},
@@ -1361,6 +1403,7 @@ static struct i2c_driver hi556_i2c_driver = {
        .driver = {
                .name = "hi556",
                .acpi_match_table = ACPI_PTR(hi556_acpi_ids),
+               .pm = pm_sleep_ptr(&hi556_pm_ops),
        },
        .probe = hi556_probe,
        .remove = hi556_remove,