[PATCH 2/3] i2c: imx_lpi2c: Replace hard-coded bus speed value with bus->speed_hz

Marek Vasut marex at denx.de
Wed Jul 24 12:11:49 CEST 2024


On 7/24/24 11:59 AM, fedorross at gmail.com wrote:
> From: Fedor Ross <fedor.ross at ifm.com>
> 
> 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 <fedor.ross at ifm.com>
> Cc: Heiko Schocher <hs at denx.de>
> Cc: Tom Rini <trini at konsulko.com>
> Cc: Marek Vasut <marex at denx.de>
> ---
>   drivers/i2c/imx_lpi2c.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/imx_lpi2c.c b/drivers/i2c/imx_lpi2c.c
> index 3c43f61d819..7b10b2b252d 100644
> --- a/drivers/i2c/imx_lpi2c.c
> +++ b/drivers/i2c/imx_lpi2c.c
> @@ -163,6 +163,7 @@ static int bus_i2c_receive(struct udevice *bus, u8 *rxbuf, int len)
>   static int bus_i2c_start(struct udevice *bus, u8 addr, u8 dir)
>   {
>   	lpi2c_status_t result;
> +	struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus);
>   	struct imx_lpi2c_bus *i2c_bus = dev_get_priv(bus);
>   	struct imx_lpi2c_reg *regs = (struct imx_lpi2c_reg *)(i2c_bus->base);
>   	u32 val;
> @@ -172,7 +173,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, i2c->speed_hz);

Drop the second parameter of bus_i2c_init(). In bus_i2c_init(), do:

struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus);
int speed = i2c->speed_hz;

That should clean the proliferation of "speed" variable.


More information about the U-Boot mailing list