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
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.
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 drivers/media/i2c/imx258.c | 42 +++++++++++++++++++++++++++++++++++++-
13 1 file changed, 41 insertions(+), 1 deletion(-)
15 --- a/drivers/media/i2c/imx258.c
16 +++ b/drivers/media/i2c/imx258.c
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)",
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 */
37 +#define IMX258_NUM_SUPPLIES ARRAY_SIZE(imx258_supply_name)
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 {
46 + struct regulator_bulk_data supplies[IMX258_NUM_SUPPLIES];
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);
54 + ret = regulator_bulk_enable(IMX258_NUM_SUPPLIES,
57 + dev_err(dev, "%s: failed to enable regulators\n",
62 ret = clk_prepare_enable(imx258->clk);
65 dev_err(dev, "failed to enable clock\n");
66 + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies);
71 @@ -1043,6 +1065,7 @@ static int imx258_power_off(struct devic
72 struct imx258 *imx258 = to_imx258(sd);
74 clk_disable_unprepare(imx258->clk);
75 + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies);
79 @@ -1285,6 +1308,19 @@ static void imx258_free_controls(struct
80 mutex_destroy(&imx258->mutex);
83 +static int imx258_get_regulators(struct imx258 *imx258,
84 + struct i2c_client *client)
88 + for (i = 0; i < IMX258_NUM_SUPPLIES; i++)
89 + imx258->supplies[i].supply = imx258_supply_name[i];
91 + return devm_regulator_bulk_get(&client->dev,
92 + IMX258_NUM_SUPPLIES,
96 static int imx258_probe(struct i2c_client *client)
98 struct imx258 *imx258;
99 @@ -1295,6 +1331,10 @@ static int imx258_probe(struct i2c_clien
103 + ret = imx258_get_regulators(imx258, client);
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),