build/patch/kernel/archive/sunxi-6.4/patches.megous/media-i2c-imx258-Add-support-for-power-supplies.patch

105 lines
2.9 KiB
Diff

From 20fba3192e3d288016005b43fdad539688aa7004 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Sun, 30 Apr 2023 18:49:36 +0200
Subject: [PATCH 345/469] media: i2c: imx258: Add support for power supplies
They were documented in DT, but not implemented.
Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
drivers/media/i2c/imx258.c | 39 ++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index fcff01eecbda..d4198cc827ee 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -603,6 +603,15 @@ static const struct imx258_mode supported_modes[] = {
},
};
+/* regulator supplies */
+static const char * const imx258_supply_names[] = {
+ "vana", /* Analog (2.8V) supply */
+ "vdig", /* Digital Core (1.5V) supply */
+ "vif", /* Digital I/O (1.8V) supply */
+};
+
+#define IMX258_SUPPLY_COUNT ARRAY_SIZE(imx258_supply_names)
+
struct imx258 {
struct v4l2_subdev sd;
struct media_pad pad;
@@ -617,6 +626,7 @@ struct imx258 {
struct gpio_desc *pwdn_gpio;
struct gpio_desc *reset_gpio;
+ struct regulator_bulk_data supplies[IMX258_SUPPLY_COUNT];
/* Current mode */
const struct imx258_mode *cur_mode;
@@ -1016,11 +1026,26 @@ static int imx258_power_on(struct device *dev)
struct imx258 *imx258 = to_imx258(sd);
int ret;
+ ret = regulator_bulk_enable(IMX258_SUPPLY_COUNT, imx258->supplies);
+ if (ret) {
+ dev_err(dev, "failed to enable regulators\n");
+ return ret;
+ }
+
+ mdelay(20);
+
gpiod_set_value_cansleep(imx258->pwdn_gpio, 0);
+ mdelay(5);
+
ret = clk_prepare_enable(imx258->clk);
- if (ret)
+ if (ret) {
dev_err(dev, "failed to enable clock\n");
+ regulator_bulk_disable(IMX258_SUPPLY_COUNT, imx258->supplies);
+ return ret;
+ }
+
+ usleep_range(1000, 2000);
gpiod_set_value_cansleep(imx258->reset_gpio, 0);
@@ -1039,6 +1064,8 @@ static int imx258_power_off(struct device *dev)
gpiod_set_value_cansleep(imx258->reset_gpio, 1);
gpiod_set_value_cansleep(imx258->pwdn_gpio, 1);
+ regulator_bulk_disable(IMX258_SUPPLY_COUNT, imx258->supplies);
+
return 0;
}
@@ -1289,7 +1316,7 @@ static void imx258_free_controls(struct imx258 *imx258)
static int imx258_probe(struct i2c_client *client)
{
struct imx258 *imx258;
- int ret;
+ int ret, i;
u32 val = 0;
imx258 = devm_kzalloc(&client->dev, sizeof(*imx258), GFP_KERNEL);
@@ -1316,6 +1343,14 @@ static int imx258_probe(struct i2c_client *client)
return -EINVAL;
}
+ for (i = 0; i < IMX258_SUPPLY_COUNT; i++)
+ imx258->supplies[i].supply = imx258_supply_names[i];
+ ret = devm_regulator_bulk_get(&client->dev,
+ IMX258_SUPPLY_COUNT,
+ imx258->supplies);
+ if (ret)
+ return dev_err_probe(&client->dev, ret, "Failed to get supplies\n");
+
/* request optional power down pin */
imx258->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
GPIOD_OUT_HIGH);
--
2.34.1