mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/8] i2c: lpi2c: determine clk rate during probe
Date: Fri,  2 Feb 2024 16:31:06 +0100	[thread overview]
Message-ID: <20240202153113.245488-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240202153113.245488-1-s.hauer@pengutronix.de>

The clock rate is not expected to change during runtime, so we can
determine it during probe instead of later when actually transferring
messages. This helps us to integrate PBL support into the driver where
we don't have clk_get_rate() available.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index f28a445601..91203d90be 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -104,6 +104,7 @@ struct lpi2c_imx_struct {
 	unsigned int		txfifosize;
 	unsigned int		rxfifosize;
 	enum lpi2c_imx_mode	mode;
+	unsigned long		clk_rate;
 };
 
 static void lpi2c_imx_intctrl(struct lpi2c_imx_struct *lpi2c_imx,
@@ -197,23 +198,19 @@ static void lpi2c_imx_stop(struct lpi2c_imx_struct *lpi2c_imx)
 static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)
 {
 	u8 prescale, filt, sethold, datavd;
-	unsigned int clk_rate, clk_cycle, clkhi, clklo;
+	unsigned int clk_cycle, clkhi, clklo;
 	enum lpi2c_imx_pincfg pincfg;
 	unsigned int temp;
 
 	lpi2c_imx_set_mode(lpi2c_imx);
 
-	clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
-	if (!clk_rate)
-		return -EINVAL;
-
 	if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
 		filt = 0;
 	else
 		filt = 2;
 
 	for (prescale = 0; prescale <= 7; prescale++) {
-		clk_cycle = clk_rate / ((1 << prescale) * lpi2c_imx->bitrate)
+		clk_cycle = lpi2c_imx->clk_rate / ((1 << prescale) * lpi2c_imx->bitrate)
 			    - 3 - (filt >> 1);
 		clkhi = DIV_ROUND_UP(clk_cycle, I2C_CLK_RATIO + 1);
 		clklo = clk_cycle - clkhi;
@@ -493,6 +490,8 @@ static int lpi2c_imx_probe(struct device *dev)
 	if (ret)
 		return ret;
 
+	lpi2c_imx->clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
+
 	temp = readl(lpi2c_imx->base + LPI2C_PARAM);
 	lpi2c_imx->txfifosize = 1 << (temp & 0x0f);
 	lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f);
-- 
2.39.2




  reply	other threads:[~2024-02-02 15:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 15:31 [PATCH 0/8] ARM: i.MX93: TQMA93xx: Add LGA variant Sascha Hauer
2024-02-02 15:31 ` Sascha Hauer [this message]
2024-02-02 15:31 ` [PATCH 2/8] i2c: lpi2c: use udelay for timeout loops Sascha Hauer
2024-02-02 15:31 ` [PATCH 3/8] i2c: lpi2c: add PBL support Sascha Hauer
2024-02-02 15:31 ` [PATCH 4/8] pbl: eeprom: return error from eeprom_read() Sascha Hauer
2024-02-02 15:55   ` Ahmad Fatoum
2024-02-02 15:31 ` [PATCH 5/8] common: add TQ EEPROM support Sascha Hauer
2024-02-02 15:56   ` Ahmad Fatoum
2024-02-02 15:31 ` [PATCH 6/8] ARM: i.MX9: add i2c base address defines Sascha Hauer
2024-02-02 15:31 ` [PATCH 7/8] ARM: i.MX9: rename TQ i.MX93 board to TQMA93XX Sascha Hauer
2024-02-02 15:31 ` [PATCH 8/8] ARM: i.MX: tqma93xx: Add LGA board variant Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240202153113.245488-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox