* [PATCH] i2c: at91: Using "clock-frequency" property from devicetree
@ 2025-05-22 8:17 Alexander Shiyan
2025-05-26 13:50 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Alexander Shiyan @ 2025-05-22 8:17 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan
This patch allows the I2C bus frequency to be configured from
devicetree. This improves compatibility with AT91-based systems
with different I2C device clock requirements.
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
drivers/i2c/busses/i2c-at91.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 75113706f8..596ca04e45 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -24,9 +24,8 @@
#include <driver.h>
#include <init.h>
-#define DEFAULT_TWI_CLK_HZ 100000 /* max 400 Kbits/s */
-#define AT91_I2C_TIMEOUT (100 * MSECOND) /* transfer timeout */
-#define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */
+#define AT91_I2C_TIMEOUT (100 * MSECOND) /* transfer timeout */
+#define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */
/* AT91 TWI register definitions */
#define AT91_TWI_CR 0x0000 /* Control Register */
@@ -149,7 +148,7 @@ static void at91_init_twi_bus(struct at91_twi_dev *dev)
* Calculate symmetric clock as stated in datasheet:
* twi_clk = F_MAIN / (2 * (cdiv * (1 << ckdiv) + offset))
*/
-static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
+static void at91_calc_twi_clock(struct at91_twi_dev *dev)
{
int ckdiv, cdiv, div, hold = 0, filter_width = 0;
const struct at91_twi_pdata *pdata = dev->pdata;
@@ -160,7 +159,7 @@ static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
i2c_parse_fw_timings(dev->dev, t, true);
div = max(0, (int)DIV_ROUND_UP(clk_get_rate(dev->clk),
- 2 * twi_clk) - offset);
+ 2 * t->bus_freq_hz) - offset);
ckdiv = fls(div >> 8);
cdiv = div >> ckdiv;
@@ -519,7 +518,6 @@ static int at91_twi_probe(struct device *dev)
struct at91_twi_dev *i2c_at91;
const struct at91_twi_pdata *i2c_data;
int rc = 0;
- u32 bus_clk_rate;
i2c_data = device_get_match_data(dev);
if (!i2c_data)
@@ -549,9 +547,7 @@ static int at91_twi_probe(struct device *dev)
clk_enable(i2c_at91->clk);
- bus_clk_rate = DEFAULT_TWI_CLK_HZ;
-
- at91_calc_twi_clock(i2c_at91, bus_clk_rate);
+ at91_calc_twi_clock(i2c_at91);
at91_init_twi_bus(i2c_at91);
i2c_at91->adapter.master_xfer = at91_twi_xfer;
--
2.39.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] i2c: at91: Using "clock-frequency" property from devicetree
2025-05-22 8:17 [PATCH] i2c: at91: Using "clock-frequency" property from devicetree Alexander Shiyan
@ 2025-05-26 13:50 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-05-26 13:50 UTC (permalink / raw)
To: barebox, Alexander Shiyan
On Thu, 22 May 2025 11:17:14 +0300, Alexander Shiyan wrote:
> This patch allows the I2C bus frequency to be configured from
> devicetree. This improves compatibility with AT91-based systems
> with different I2C device clock requirements.
>
>
Applied, thanks!
[1/1] i2c: at91: Using "clock-frequency" property from devicetree
https://git.pengutronix.de/cgit/barebox/commit/?id=5dd7360f3b17 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-26 13:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-22 8:17 [PATCH] i2c: at91: Using "clock-frequency" property from devicetree Alexander Shiyan
2025-05-26 13:50 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox