All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] media: i2c: imx219: add support for specifying clock-frequencies
@ 2020-12-05 18:33 ` michael.srba
  0 siblings, 0 replies; 18+ messages in thread
From: michael.srba @ 2020-12-05 18:33 UTC (permalink / raw)
  To: Dave Stevenson, Mauro Carvalho Chehab, Rob Herring, Shawn Guo,
	Sascha Hauer
  Cc: Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Geert Uytterhoeven, Magnus Damm, linux-media, devicetree,
	linux-arm-kernel, linux-renesas-soc, Michael Srba

From: Michael Srba <Michael.Srba@seznam.cz>

This patch adds 1% tolerance on input clock, similar to other camera sensor
drivers. It also allows for specifying the actual clock in the device tree,
instead of relying on it being already set to the right frequency (which is
often not the case).

Signed-off-by: Michael Srba <Michael.Srba@seznam.cz>
---
 drivers/media/i2c/imx219.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index f64c0ef7a897..a8f05562d0af 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1443,13 +1443,26 @@ static int imx219_probe(struct i2c_client *client)
 		return PTR_ERR(imx219->xclk);
 	}
 
-	imx219->xclk_freq = clk_get_rate(imx219->xclk);
-	if (imx219->xclk_freq != IMX219_XCLK_FREQ) {
+	ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency", &imx219->xclk_freq);
+	if (ret) {
+		dev_err(dev, "could not get xclk frequency\n");
+		return ret;
+	}
+
+	/* this driver currently expects 24MHz; allow 1% tolerance */
+	if (imx219->xclk_freq < 23760000 || imx219->xclk_freq > 24240000) {
 		dev_err(dev, "xclk frequency not supported: %d Hz\n",
 			imx219->xclk_freq);
 		return -EINVAL;
 	}
 
+	ret = clk_set_rate(imx219->xclk, imx219->xclk_freq);
+	if (ret) {
+		dev_err(dev, "could not set xclk frequency\n");
+		return ret;
+	}
+
+
 	ret = imx219_get_regulators(imx219);
 	if (ret) {
 		dev_err(dev, "failed to get regulators\n");
-- 
2.29.2


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-12-07  9:47 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-05 18:33 [PATCH 1/3] media: i2c: imx219: add support for specifying clock-frequencies michael.srba
2020-12-05 18:33 ` michael.srba
2020-12-05 18:33 ` [PATCH 2/3] media: dt-bindings: media: i2c: imx219: document clock-frequency property michael.srba
2020-12-05 18:33   ` michael.srba
2020-12-07  9:46   ` Krzysztof Kozlowski
2020-12-07  9:46     ` Krzysztof Kozlowski
2020-12-05 18:33 ` [PATCH 3/3] arm64: dts: update device trees to specify clock-frequency in imx219 node michael.srba
2020-12-05 18:33   ` michael.srba
2020-12-05 18:55   ` Geert Uytterhoeven
2020-12-05 18:55     ` Geert Uytterhoeven
2020-12-06 17:20     ` Michael Srba
2020-12-06 17:20       ` Michael Srba
2020-12-05 18:54 ` [PATCH 1/3] media: i2c: imx219: add support for specifying clock-frequencies Geert Uytterhoeven
2020-12-05 18:54   ` Geert Uytterhoeven
2020-12-06 17:18   ` Michael Srba
2020-12-06 17:18     ` Michael Srba
2020-12-07  9:44 ` Krzysztof Kozlowski
2020-12-07  9:44   ` Krzysztof Kozlowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.