From: Fedor Ross Date: Wed, 7 Aug 2024 14:08:00 +0000 (+0200) Subject: i2c: imx_lpi2c: Replace hard-coded bus speed value with bus->speed_hz X-Git-Url: http://git.dujemihanovic.xyz/%22http:/www.sics.se/static/git-favicon.png?a=commitdiff_plain;h=34c6731abe4fa5efadbb7519a050d2fcbdba3cab;p=u-boot.git i2c: imx_lpi2c: Replace hard-coded bus speed value with bus->speed_hz Instead of using the hard-coded bus speed value I2C_SPEED_STANDARD_RATE, use the actual configured bus speed. This way the bus speed doesn't change suddenly after calling the imx_lpi2c_probe_chip() function for example. Signed-off-by: Fedor Ross --- diff --git a/drivers/i2c/imx_lpi2c.c b/drivers/i2c/imx_lpi2c.c index 3c43f61d81..54db6fa863 100644 --- a/drivers/i2c/imx_lpi2c.c +++ b/drivers/i2c/imx_lpi2c.c @@ -19,7 +19,7 @@ #define LPI2C_NACK_TOUT_MS 1 #define LPI2C_TIMEOUT_MS 100 -static int bus_i2c_init(struct udevice *bus, int speed); +static int bus_i2c_init(struct udevice *bus); /* Weak linked function for overridden by some SoC power function */ int __weak init_i2c_power(unsigned i2c_num) @@ -172,7 +172,7 @@ static int bus_i2c_start(struct udevice *bus, u8 addr, u8 dir) debug("i2c: start check busy bus: 0x%x\n", result); /* Try to init the lpi2c then check the bus busy again */ - bus_i2c_init(bus, I2C_SPEED_STANDARD_RATE); + bus_i2c_init(bus); result = imx_lpci2c_check_busy_bus(regs); if (result) { printf("i2c: Error check busy bus: 0x%x\n", result); @@ -344,11 +344,14 @@ static int bus_i2c_set_bus_speed(struct udevice *bus, int speed) return 0; } -static int bus_i2c_init(struct udevice *bus, int speed) +static int bus_i2c_init(struct udevice *bus) { u32 val; int ret; + struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus); + int speed = i2c->speed_hz; + struct imx_lpi2c_bus *i2c_bus = dev_get_priv(bus); struct imx_lpi2c_reg *regs = (struct imx_lpi2c_reg *)(i2c_bus->base); /* reset peripheral */ @@ -388,13 +391,13 @@ static int imx_lpi2c_probe_chip(struct udevice *bus, u32 chip, result = bus_i2c_start(bus, chip, 0); if (result) { bus_i2c_stop(bus); - bus_i2c_init(bus, I2C_SPEED_STANDARD_RATE); + bus_i2c_init(bus); return result; } result = bus_i2c_stop(bus); if (result) - bus_i2c_init(bus, I2C_SPEED_STANDARD_RATE); + bus_i2c_init(bus); return result; } @@ -489,7 +492,7 @@ static int imx_lpi2c_probe(struct udevice *bus) return ret; } - ret = bus_i2c_init(bus, I2C_SPEED_STANDARD_RATE); + ret = bus_i2c_init(bus); if (ret < 0) return ret;