Commit 901c9229 authored by Hans de Goede's avatar Hans de Goede Committed by Hans Verkuil

media: hi556: Add support for avdd regulator

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.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
parent f9fc7063
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
#include <media/v4l2-ctrls.h> #include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-fwnode.h> #include <media/v4l2-fwnode.h>
...@@ -638,6 +639,7 @@ struct hi556 { ...@@ -638,6 +639,7 @@ struct hi556 {
/* GPIOs, clocks, etc. */ /* GPIOs, clocks, etc. */
struct gpio_desc *reset_gpio; struct gpio_desc *reset_gpio;
struct clk *clk; struct clk *clk;
struct regulator *avdd;
/* Current mode */ /* Current mode */
const struct hi556_mode *cur_mode; const struct hi556_mode *cur_mode;
...@@ -1286,8 +1288,17 @@ static int hi556_suspend(struct device *dev) ...@@ -1286,8 +1288,17 @@ static int hi556_suspend(struct device *dev)
{ {
struct v4l2_subdev *sd = dev_get_drvdata(dev); struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct hi556 *hi556 = to_hi556(sd); struct hi556 *hi556 = to_hi556(sd);
int ret;
gpiod_set_value_cansleep(hi556->reset_gpio, 1); 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);
return ret;
}
clk_disable_unprepare(hi556->clk); clk_disable_unprepare(hi556->clk);
return 0; return 0;
} }
...@@ -1302,6 +1313,13 @@ static int hi556_resume(struct device *dev) ...@@ -1302,6 +1313,13 @@ static int hi556_resume(struct device *dev)
if (ret) if (ret)
return 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); gpiod_set_value_cansleep(hi556->reset_gpio, 0);
usleep_range(5000, 5500); usleep_range(5000, 5500);
return 0; return 0;
...@@ -1337,6 +1355,12 @@ static int hi556_probe(struct i2c_client *client) ...@@ -1337,6 +1355,12 @@ static int hi556_probe(struct i2c_client *client)
return dev_err_probe(&client->dev, PTR_ERR(hi556->clk), return dev_err_probe(&client->dev, PTR_ERR(hi556->clk),
"failed to get clock\n"); "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); full_power = acpi_dev_state_d0(&client->dev);
if (full_power) { if (full_power) {
/* Ensure non ACPI managed resources are enabled */ /* Ensure non ACPI managed resources are enabled */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment