1 From 659037c028f28ac0f13bd54a55c6c81761fb02ce Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Mon, 22 Nov 2021 12:31:35 +0000
4 Subject: [PATCH] media: i2c: ov5647: Add support for regulator
7 The driver supported using GPIOs to control the shutdown line,
8 but no regulator control.
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
14 drivers/media/i2c/ov5647.c | 37 +++++++++++++++++++++++++++++++++++++
15 1 file changed, 37 insertions(+)
17 --- a/drivers/media/i2c/ov5647.c
18 +++ b/drivers/media/i2c/ov5647.c
20 #include <linux/module.h>
21 #include <linux/of_graph.h>
22 #include <linux/pm_runtime.h>
23 +#include <linux/regulator/consumer.h>
24 #include <linux/slab.h>
25 #include <linux/videodev2.h>
26 #include <media/v4l2-ctrls.h>
28 #define OV5647_EXPOSURE_DEFAULT 1000
29 #define OV5647_EXPOSURE_MAX 65535
31 +/* regulator supplies */
32 +static const char * const ov5647_supply_names[] = {
33 + "avdd", /* Analog power */
34 + "dovdd", /* Digital I/O power */
35 + "dvdd", /* Digital core power */
38 +#define OV5647_NUM_SUPPLIES ARRAY_SIZE(ov5647_supply_names)
43 @@ -103,6 +113,7 @@ struct ov5647 {
46 struct gpio_desc *pwdn;
47 + struct regulator_bulk_data supplies[OV5647_NUM_SUPPLIES];
49 struct v4l2_ctrl_handler ctrls;
50 const struct ov5647_mode *mode;
51 @@ -787,6 +798,12 @@ static int ov5647_power_on(struct device
53 dev_dbg(dev, "OV5647 power on\n");
55 + ret = regulator_bulk_enable(OV5647_NUM_SUPPLIES, sensor->supplies);
57 + dev_err(dev, "Failed to enable regulators\n");
62 gpiod_set_value_cansleep(sensor->pwdn, 0);
63 msleep(PWDN_ACTIVE_DELAY_MS);
64 @@ -818,6 +835,7 @@ error_clk_disable:
65 clk_disable_unprepare(sensor->xclk);
67 gpiod_set_value_cansleep(sensor->pwdn, 1);
68 + regulator_bulk_disable(OV5647_NUM_SUPPLIES, sensor->supplies);
72 @@ -847,6 +865,7 @@ static int ov5647_power_off(struct devic
74 clk_disable_unprepare(sensor->xclk);
75 gpiod_set_value_cansleep(sensor->pwdn, 1);
76 + regulator_bulk_disable(OV5647_NUM_SUPPLIES, sensor->supplies);
80 @@ -1347,6 +1366,18 @@ static const struct v4l2_ctrl_ops ov5647
81 .s_ctrl = ov5647_s_ctrl,
84 +static int ov5647_configure_regulators(struct device *dev,
85 + struct ov5647 *sensor)
89 + for (i = 0; i < OV5647_NUM_SUPPLIES; i++)
90 + sensor->supplies[i].supply = ov5647_supply_names[i];
92 + return devm_regulator_bulk_get(dev, OV5647_NUM_SUPPLIES,
96 static int ov5647_init_controls(struct ov5647 *sensor, struct device *dev)
98 struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd);
99 @@ -1494,6 +1525,12 @@ static int ov5647_probe(struct i2c_clien
103 + ret = ov5647_configure_regulators(dev, sensor);
105 + dev_err(dev, "Failed to get power regulators\n");
109 mutex_init(&sensor->lock);
111 sensor->mode = OV5647_DEFAULT_MODE;