bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0814-media-i2c-imx258-Add-regulator-control.patch
1 From 518075a2587a30a5fb67f2d76e576caf230a4105 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 15 Jun 2021 18:45:40 +0100
4 Subject: [PATCH] media: i2c: imx258: Add regulator control
5
6 The device tree bindings define the relevant regulators for the
7 sensor, so update the driver to request the regulators and control
8 them at the appropriate times.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12 drivers/media/i2c/imx258.c | 42 +++++++++++++++++++++++++++++++++++++-
13 1 file changed, 41 insertions(+), 1 deletion(-)
14
15 --- a/drivers/media/i2c/imx258.c
16 +++ b/drivers/media/i2c/imx258.c
17 @@ -7,6 +7,7 @@
18 #include <linux/i2c.h>
19 #include <linux/module.h>
20 #include <linux/pm_runtime.h>
21 +#include <linux/regulator/consumer.h>
22 #include <media/v4l2-ctrls.h>
23 #include <media/v4l2-device.h>
24 #include <media/v4l2-fwnode.h>
25 @@ -524,6 +525,16 @@ static const char * const imx258_test_pa
26 "Pseudorandom Sequence (PN9)",
27 };
28
29 +/* regulator supplies */
30 +static const char * const imx258_supply_name[] = {
31 + /* Supplies can be enabled in any order */
32 + "vana", /* Analog (2.8V) supply */
33 + "vdig", /* Digital Core (1.05V) supply */
34 + "vif", /* IF (1.8V) supply */
35 +};
36 +
37 +#define IMX258_NUM_SUPPLIES ARRAY_SIZE(imx258_supply_name)
38 +
39 /* Configurations for supported link frequencies */
40 #define IMX258_LINK_FREQ_634MHZ 633600000ULL
41 #define IMX258_LINK_FREQ_320MHZ 320000000ULL
42 @@ -633,6 +644,7 @@ struct imx258 {
43 bool streaming;
44
45 struct clk *clk;
46 + struct regulator_bulk_data supplies[IMX258_NUM_SUPPLIES];
47 };
48
49 static inline struct imx258 *to_imx258(struct v4l2_subdev *_sd)
50 @@ -1030,9 +1042,19 @@ static int imx258_power_on(struct device
51 struct imx258 *imx258 = to_imx258(sd);
52 int ret;
53
54 + ret = regulator_bulk_enable(IMX258_NUM_SUPPLIES,
55 + imx258->supplies);
56 + if (ret) {
57 + dev_err(dev, "%s: failed to enable regulators\n",
58 + __func__);
59 + return ret;
60 + }
61 +
62 ret = clk_prepare_enable(imx258->clk);
63 - if (ret)
64 + if (ret) {
65 dev_err(dev, "failed to enable clock\n");
66 + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies);
67 + }
68
69 return ret;
70 }
71 @@ -1043,6 +1065,7 @@ static int imx258_power_off(struct devic
72 struct imx258 *imx258 = to_imx258(sd);
73
74 clk_disable_unprepare(imx258->clk);
75 + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies);
76
77 return 0;
78 }
79 @@ -1285,6 +1308,19 @@ static void imx258_free_controls(struct
80 mutex_destroy(&imx258->mutex);
81 }
82
83 +static int imx258_get_regulators(struct imx258 *imx258,
84 + struct i2c_client *client)
85 +{
86 + unsigned int i;
87 +
88 + for (i = 0; i < IMX258_NUM_SUPPLIES; i++)
89 + imx258->supplies[i].supply = imx258_supply_name[i];
90 +
91 + return devm_regulator_bulk_get(&client->dev,
92 + IMX258_NUM_SUPPLIES,
93 + imx258->supplies);
94 +}
95 +
96 static int imx258_probe(struct i2c_client *client)
97 {
98 struct imx258 *imx258;
99 @@ -1295,6 +1331,10 @@ static int imx258_probe(struct i2c_clien
100 if (!imx258)
101 return -ENOMEM;
102
103 + ret = imx258_get_regulators(imx258, client);
104 + if (ret)
105 + return ret;
106 +
107 imx258->clk = devm_clk_get_optional(&client->dev, NULL);
108 if (IS_ERR(imx258->clk))
109 return dev_err_probe(&client->dev, PTR_ERR(imx258->clk),