Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 1/3] media: i2c: imx219: add support for specifying clock-frequencies
@ 2020-12-06 17:27 michael.srba
  2020-12-06 17:27 ` [PATCH v2 2/3] media: dt-bindings: media: i2c: imx219: document clock-frequency property michael.srba
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: michael.srba @ 2020-12-06 17:27 UTC (permalink / raw)
  To: Dave Stevenson, Mauro Carvalho Chehab, Rob Herring, Shawn Guo,
	Sascha Hauer
  Cc: devicetree, Geert Uytterhoeven, Magnus Damm, linux-renesas-soc,
	Michael Srba, NXP Linux Team, Pengutronix Kernel Team,
	Fabio Estevam, linux-arm-kernel, linux-media

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>

---

changes since v1: default to exactly 24MHz when `clock-frequency` is not present

---
 drivers/media/i2c/imx219.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index f64c0ef7a897..b6500e2ab19e 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1443,13 +1443,28 @@ 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_warn(dev, "could not get xclk frequency\n");
+
+		/* default to 24MHz */
+		imx219->xclk_freq = 24000000;
+	}
+
+	/* 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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-06 17:27 [PATCH v2 1/3] media: i2c: imx219: add support for specifying clock-frequencies michael.srba
2020-12-06 17:27 ` [PATCH v2 2/3] media: dt-bindings: media: i2c: imx219: document clock-frequency property michael.srba
2020-12-06 17:27 ` [PATCH v2 3/3] arm64: dts: update device trees to specify clock-frequency in imx219 node michael.srba
2020-12-07  5:59 ` [PATCH v2 1/3] media: i2c: imx219: add support for specifying clock-frequencies Sascha Hauer
2020-12-10 20:51   ` Michael Srba
2020-12-18  9:59     ` Krzysztof Kozlowski
2020-12-18 10:48 ` Dave Stevenson

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git