build/patch/kernel/archive/sunxi-6.1/patches.megous/media-i2c-imx258-Set-xvclk-rate-before-each-power-on.patch

62 lines
1.9 KiB
Diff
Raw Permalink Normal View History

From e41f2c9a9ca8fb5af2bcf10a73cd93955b125e8f Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Sun, 22 May 2022 16:40:22 +0200
Subject: [PATCH 349/389] media: i2c: imx258: Set xvclk rate before each power
on
This is to be able to share clock with another sensor driver
which expects a different clock frequency.
Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
drivers/media/i2c/imx258.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index 486d685f34ce..4f47253e182d 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -1024,8 +1024,23 @@ static int imx258_power_on(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct imx258 *imx258 = to_imx258(sd);
+ u32 val = 0;
int ret;
+ if (imx258->clk) {
+ ret = clk_set_rate(imx258->clk, IMX258_INPUT_CLOCK_FREQ);
+ if (ret < 0)
+ dev_warn(dev, "Failed to set clk rate\n");
+
+ val = clk_get_rate(imx258->clk);
+ if (val < IMX258_INPUT_CLOCK_FREQ_MIN ||
+ val > IMX258_INPUT_CLOCK_FREQ_MAX) {
+ dev_err(dev, "clk mismatched, expecting %u, got %u Hz\n",
+ IMX258_INPUT_CLOCK_FREQ, val);
+ return -EINVAL;
+ }
+ }
+
ret = regulator_bulk_enable(IMX258_SUPPLY_COUNT, imx258->supplies);
if (ret) {
dev_err(dev, "failed to enable regulators\n");
@@ -1315,12 +1330,9 @@ static int imx258_probe(struct i2c_client *client)
val = clk_get_rate(imx258->clk);
}
- if (val < IMX258_INPUT_CLOCK_FREQ_MIN
- || val > IMX258_INPUT_CLOCK_FREQ_MAX) {
- dev_err(&client->dev, "input clock frequency %u not supported\n",
- val);
- return -EINVAL;
- }
+ //XXX: the driver just checked for the clock to be as expected here
+ // but we now just configure the clock to expected value before power on
+ // if possible
/*
* Check that the device is mounted upside down. The driver only
--
2.35.3