bcm27xx: add support for linux v5.15
[openwrt/staging/wigyori.git] / target / linux / bcm27xx / patches-5.15 / 950-0610-media-i2c-ov5647-Add-support-for-regulator-control.patch
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
5 control.
6
7 The driver supported using GPIOs to control the shutdown line,
8 but no regulator control.
9
10 Add regulator hooks.
11
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
13 ---
14 drivers/media/i2c/ov5647.c | 37 +++++++++++++++++++++++++++++++++++++
15 1 file changed, 37 insertions(+)
16
17 --- a/drivers/media/i2c/ov5647.c
18 +++ b/drivers/media/i2c/ov5647.c
19 @@ -20,6 +20,7 @@
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>
27 @@ -82,6 +83,15 @@
28 #define OV5647_EXPOSURE_DEFAULT 1000
29 #define OV5647_EXPOSURE_MAX 65535
30
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 */
36 +};
37 +
38 +#define OV5647_NUM_SUPPLIES ARRAY_SIZE(ov5647_supply_names)
39 +
40 struct regval_list {
41 u16 addr;
42 u8 data;
43 @@ -103,6 +113,7 @@ struct ov5647 {
44 struct mutex lock;
45 struct clk *xclk;
46 struct gpio_desc *pwdn;
47 + struct regulator_bulk_data supplies[OV5647_NUM_SUPPLIES];
48 bool clock_ncont;
49 struct v4l2_ctrl_handler ctrls;
50 const struct ov5647_mode *mode;
51 @@ -787,6 +798,12 @@ static int ov5647_power_on(struct device
52
53 dev_dbg(dev, "OV5647 power on\n");
54
55 + ret = regulator_bulk_enable(OV5647_NUM_SUPPLIES, sensor->supplies);
56 + if (ret < 0) {
57 + dev_err(dev, "Failed to enable regulators\n");
58 + return ret;
59 + }
60 +
61 if (sensor->pwdn) {
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);
66 error_pwdn:
67 gpiod_set_value_cansleep(sensor->pwdn, 1);
68 + regulator_bulk_disable(OV5647_NUM_SUPPLIES, sensor->supplies);
69
70 return ret;
71 }
72 @@ -847,6 +865,7 @@ static int ov5647_power_off(struct devic
73
74 clk_disable_unprepare(sensor->xclk);
75 gpiod_set_value_cansleep(sensor->pwdn, 1);
76 + regulator_bulk_disable(OV5647_NUM_SUPPLIES, sensor->supplies);
77
78 return 0;
79 }
80 @@ -1347,6 +1366,18 @@ static const struct v4l2_ctrl_ops ov5647
81 .s_ctrl = ov5647_s_ctrl,
82 };
83
84 +static int ov5647_configure_regulators(struct device *dev,
85 + struct ov5647 *sensor)
86 +{
87 + unsigned int i;
88 +
89 + for (i = 0; i < OV5647_NUM_SUPPLIES; i++)
90 + sensor->supplies[i].supply = ov5647_supply_names[i];
91 +
92 + return devm_regulator_bulk_get(dev, OV5647_NUM_SUPPLIES,
93 + sensor->supplies);
94 +}
95 +
96 static int ov5647_init_controls(struct ov5647 *sensor, struct device *dev)
97 {
98 struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd);
99 @@ -1494,6 +1525,12 @@ static int ov5647_probe(struct i2c_clien
100 return -EINVAL;
101 }
102
103 + ret = ov5647_configure_regulators(dev, sensor);
104 + if (ret) {
105 + dev_err(dev, "Failed to get power regulators\n");
106 + return ret;
107 + }
108 +
109 mutex_init(&sensor->lock);
110
111 sensor->mode = OV5647_DEFAULT_MODE;