[U-Boot] [PATCH] i2c: designware: Get clock rate from clock DM

Ley Foon Tan lftan.linux at gmail.com
Thu May 30 09:07:36 UTC 2019


On Thu, May 30, 2019 at 4:59 PM Marek Vasut <marex at denx.de> wrote:
>
> On 5/30/19 10:43 AM, Ley Foon Tan wrote:
> > Get clock rate from clock DM if CONFIG_CLK is enabled.
> > Otherwise, uses IC_CLK define.
> >
> > Signed-off-by: Ley Foon Tan <ley.foon.tan at intel.com>
> > ---
> >  drivers/i2c/designware_i2c.c | 54 +++++++++++++++++++++++++++++-------
> >  1 file changed, 44 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/i2c/designware_i2c.c b/drivers/i2c/designware_i2c.c
> > index 9ccc2411a6..a1ed30650c 100644
> > --- a/drivers/i2c/designware_i2c.c
> > +++ b/drivers/i2c/designware_i2c.c
> > @@ -4,6 +4,7 @@
> >   * Vipin Kumar, ST Micoelectronics, vipin.kumar at st.com.
> >   */
> >
> > +#include <clk.h>
> >  #include <common.h>
> >  #include <dm.h>
> >  #include <i2c.h>
> > @@ -35,6 +36,9 @@ struct dw_i2c {
> >       struct i2c_regs *regs;
> >       struct dw_scl_sda_cfg *scl_sda_cfg;
> >       struct reset_ctl_bulk resets;
> > +#if CONFIG_IS_ENABLED(CLK)
> > +     struct clk clk;
> > +#endif
> >  };
> >
> >  #ifdef CONFIG_SYS_I2C_DW_ENABLE_STATUS_UNSUPPORTED
> > @@ -78,7 +82,7 @@ static int dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
> >   */
> >  static unsigned int __dw_i2c_set_bus_speed(struct i2c_regs *i2c_base,
> >                                          struct dw_scl_sda_cfg *scl_sda_cfg,
> > -                                        unsigned int speed)
> > +                                        unsigned int speed, u32 bus_mhz)
>
> unsigned int bus_mhz , it's not a fixed-width register content, but just
> some random unsigned integer.
You mean change u32 to unsigned int?
>
> [...]
>
> > @@ -523,8 +527,20 @@ static int designware_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
> >  static int designware_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
> >  {
> >       struct dw_i2c *i2c = dev_get_priv(bus);
> > +     ulong rate;
> > +
> > +#if CONFIG_IS_ENABLED(CLK)
> > +     rate = clk_get_rate(&i2c->clk);
>
> Do we need to re-read the bus frequency for each transfer ?
> I would expect set_bus_speed callback to set the frequencies once and
> then keep them that way until it's called again.
Yes, we can get clock rate when request clock in _probe(). Then keep a
copy for future use.
Will change it.

Thanks.

Regards
Ley Foon


More information about the U-Boot mailing list