Re: [PATCH 4/4] media: hi556: Add support for avdd regulator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 2/3/24 11:15, Jacopo Mondi wrote:
> Hi Hans
> 
> On Thu, Feb 01, 2024 at 10:58:41PM +0100, 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 HP models with IPU6 +
>> hi556 sensor, the sensor driver must control the avdd regulator itself.
>>
>> Add support for having the driver control the sensor's avdd regulator.
>> Note this relies on the regulator-core providing a dummy regulator
>> (which it does by default) on platforms where Linux is not aware of
>> the avdd regulator.
>>
> 
> Please excuse the question from an ACPI illiterate, but does it mean
> that, in example:
> 1) Chromebooks: you get a dummy
> 2) HP: you get an actual regulator reference

Yes that is correct.

Regards,

Hans




> 
>> Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx>
>> ---
>>  drivers/media/i2c/hi556.c | 24 ++++++++++++++++++++++++
>>  1 file changed, 24 insertions(+)
>>
>> diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c
>> index fb6ba6984e38..90eff282a6e2 100644
>> --- a/drivers/media/i2c/hi556.c
>> +++ b/drivers/media/i2c/hi556.c
>> @@ -9,6 +9,7 @@
>>  #include <linux/i2c.h>
>>  #include <linux/module.h>
>>  #include <linux/pm_runtime.h>
>> +#include <linux/regulator/consumer.h>
>>  #include <media/v4l2-ctrls.h>
>>  #include <media/v4l2-device.h>
>>  #include <media/v4l2-fwnode.h>
>> @@ -638,6 +639,7 @@ struct hi556 {
>>  	/* GPIOs, clocks, etc. */
>>  	struct gpio_desc *reset_gpio;
>>  	struct clk *clk;
>> +	struct regulator *avdd;
>>
>>  	/* Current mode */
>>  	const struct hi556_mode *cur_mode;
>> @@ -1287,8 +1289,17 @@ static int hi556_suspend(struct device *dev)
>>  {
>>  	struct v4l2_subdev *sd = dev_get_drvdata(dev);
>>  	struct hi556 *hi556 = to_hi556(sd);
>> +	int ret;
>>
>>  	gpiod_set_value_cansleep(hi556->reset_gpio, 1);
>> +
>> +	ret = regulator_disable(hi556->avdd);
>> +	if (ret) {
>> +		dev_err(dev, "failed to disable avdd: %d\n", ret);
>> +		gpiod_set_value_cansleep(hi556->reset_gpio, 0);
> 
> I understand in error paths you're supposed to reverse the previously
> done operations, but, as this is a reset, isn't it better to keep the
> reset enabled since we're suspending anyway ?
> 
>> +		return ret;
>> +	}
>> +
>>  	clk_disable_unprepare(hi556->clk);
>>  	return 0;
>>  }
>> @@ -1303,6 +1314,13 @@ static int hi556_resume(struct device *dev)
>>  	if (ret)
>>  		return ret;
>>
>> +	ret = regulator_enable(hi556->avdd);
>> +	if (ret) {
>> +		dev_err(dev, "failed to enable avdd: %d\n", ret);
>> +		clk_disable_unprepare(hi556->clk);
>> +		return ret;
>> +	}
>> +
>>  	gpiod_set_value_cansleep(hi556->reset_gpio, 0);
>>  	usleep_range(5000, 5500);
>>  	return 0;
>> @@ -1338,6 +1356,12 @@ static int hi556_probe(struct i2c_client *client)
>>  		return dev_err_probe(&client->dev, PTR_ERR(hi556->clk),
>>  				     "failed to get clock\n");
>>
>> +	/* The regulator core will provide a "dummy" regulator if necessary */
>> +	hi556->avdd = devm_regulator_get(&client->dev, "avdd");
>> +	if (IS_ERR(hi556->avdd))
>> +		return dev_err_probe(&client->dev, PTR_ERR(hi556->avdd),
>> +				     "failed to get avdd regulator\n");
>> +
>>  	full_power = acpi_dev_state_d0(&client->dev);
>>  	if (full_power) {
>>  		/* Ensure non ACPI managed resources are enabled */
>> --
>> 2.43.0
>>
>>
> 





[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux