From: Bingbu Cao <bingbu.cao@linux.intel.com>
To: Hans de Goede <hdegoede@redhat.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Tianshu Qiu <tian.shu.qiu@intel.com>,
Bingbu Cao <bingbu.cao@intel.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Kate Hsuan <hpa@redhat.com>,
linux-media@vger.kernel.org
Subject: Re: [PATCH 1/2] media: ov2740: Add support for reset GPIO
Date: Mon, 20 Nov 2023 12:04:05 +0800 [thread overview]
Message-ID: <8a2988c5-e01d-1515-b908-2e28a6545120@linux.intel.com> (raw)
In-Reply-To: <20231115123817.196252-2-hdegoede@redhat.com>
Hans,
Thanks for your patch.
On 11/15/23 8:38 PM, Hans de Goede wrote:
> 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 ThinkPad models with
> IPU6 + ov2740 sensor, the sensor driver must control the reset GPIO
> and the sensor's clock itself.
>
> Add support for having the driver control an optional reset GPIO.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/media/i2c/ov2740.c | 48 ++++++++++++++++++++++++++++++++++++--
> 1 file changed, 46 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
> index 24e468485fbf..e5f9569a229d 100644
> --- a/drivers/media/i2c/ov2740.c
> +++ b/drivers/media/i2c/ov2740.c
> @@ -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>
> @@ -333,6 +334,9 @@ struct ov2740 {
> struct v4l2_ctrl *hblank;
> struct v4l2_ctrl *exposure;
>
> + /* GPIOs, clocks */
It looks like the 'clock' should be in another one (2/2), :).
> + struct gpio_desc *reset_gpio;
> +
> /* Current mode */
> const struct ov2740_mode *cur_mode;
>
> @@ -1058,6 +1062,26 @@ static int ov2740_register_nvmem(struct i2c_client *client,
> return 0;
> }
>
> +static int ov2740_suspend(struct device *dev)
> +{
> + struct v4l2_subdev *sd = dev_get_drvdata(dev);
> + struct ov2740 *ov2740 = to_ov2740(sd);
> +
> + gpiod_set_value_cansleep(ov2740->reset_gpio, 1);
> + return 0;
> +}
> +
> +static int ov2740_resume(struct device *dev)
> +{
> + struct v4l2_subdev *sd = dev_get_drvdata(dev);
> + struct ov2740 *ov2740 = to_ov2740(sd);
> +
> + gpiod_set_value_cansleep(ov2740->reset_gpio, 0);
> + msleep(20);
I remember that usleep_range() is prefered for <=20ms.
> +
> + return 0;
> +}
> +
> static int ov2740_probe(struct i2c_client *client)
> {
> struct device *dev = &client->dev;
> @@ -1073,12 +1097,24 @@ static int ov2740_probe(struct i2c_client *client)
> if (!ov2740)
> return -ENOMEM;
>
> + ov2740->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> + if (IS_ERR(ov2740->reset_gpio))
> + return dev_err_probe(dev, PTR_ERR(ov2740->reset_gpio),
> + "failed to get reset GPIO\n");
> +
> v4l2_i2c_subdev_init(&ov2740->sd, client, &ov2740_subdev_ops);
> full_power = acpi_dev_state_d0(&client->dev);
> if (full_power) {
> - ret = ov2740_identify_module(ov2740);
> + /* ACPI does not always clear the reset GPIO / enable the clock */
> + ret = ov2740_resume(dev);
> if (ret)
> - return dev_err_probe(dev, ret, "failed to find sensor\n");
> + return dev_err_probe(dev, ret, "failed to power on sensor\n");
> +
> + ret = ov2740_identify_module(ov2740);
> + if (ret) {
> + dev_err_probe(dev, ret, "failed to find sensor\n");
> + goto probe_error_power_off;
> + }
> }
>
> ov2740->cur_mode = &supported_modes[0];
> @@ -1132,9 +1168,16 @@ static int ov2740_probe(struct i2c_client *client)
> probe_error_v4l2_ctrl_handler_free:
> v4l2_ctrl_handler_free(ov2740->sd.ctrl_handler);
>
> +probe_error_power_off:
> + if (full_power)
> + ov2740_suspend(dev);
> +
> return ret;
> }
>
> +static DEFINE_RUNTIME_DEV_PM_OPS(ov2740_pm_ops, ov2740_suspend, ov2740_resume,
> + NULL);
> +
> static const struct acpi_device_id ov2740_acpi_ids[] = {
> {"INT3474"},
> {}
> @@ -1146,6 +1189,7 @@ static struct i2c_driver ov2740_i2c_driver = {
> .driver = {
> .name = "ov2740",
> .acpi_match_table = ov2740_acpi_ids,
> + .pm = pm_sleep_ptr(&ov2740_pm_ops),
> },
> .probe = ov2740_probe,
> .remove = ov2740_remove,
>
Except the minor comment.
Reviewed-by: Bingbu Cao <bingbu.cao@intel.com>
--
Best regards,
Bingbu Cao
next prev parent reply other threads:[~2023-11-20 4:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-15 12:38 [PATCH 0/2] media: ov2740: Add support for reset GPIO and external clock Hans de Goede
2023-11-15 12:38 ` [PATCH 1/2] media: ov2740: Add support for reset GPIO Hans de Goede
2023-11-20 4:04 ` Bingbu Cao [this message]
2023-11-20 9:58 ` Hans de Goede
2023-11-15 12:38 ` [PATCH 2/2] media: ov2740: Add support for external clock Hans de Goede
2023-11-20 4:06 ` Bingbu Cao
2023-11-20 10:00 ` Hans de Goede
2023-11-20 16:32 ` Sakari Ailus
2023-11-23 9:57 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8a2988c5-e01d-1515-b908-2e28a6545120@linux.intel.com \
--to=bingbu.cao@linux.intel.com \
--cc=bingbu.cao@intel.com \
--cc=hdegoede@redhat.com \
--cc=hpa@redhat.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tian.shu.qiu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox