Re: [PATCH v1 2/6] i2c: npcm: Fix timeout calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all:

Thank you for your comments and they will be addressed.

Regards,
Tyrone


Jonathan Neuschäfer <j.neuschaefer@xxxxxxx> 於 2022年2月7日 週一 下午7:27寫道:
>
> Hello,
>
> On Mon, Feb 07, 2022 at 02:33:34PM +0800, Tyrone Ting wrote:
> > From: Tali Perry <tali.perry1@xxxxxxxxx>
> >
> > Use adap.timeout for timeout calculation instead of hard-coded
> > value of 35ms.
>
>
> > Use syscon to access gcr, instead of "compatible".
>
> Please put the GCR/syscon change into a separate patch, because it is
> not obvious from the commit title that such a change would happen in
> this patch.
>
> >
> > Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
> > Signed-off-by: Tali Perry <tali.perry1@xxxxxxxxx>
> > Signed-off-by: Tyrone Ting <kfting@xxxxxxxxxxx>
> > ---
> >  drivers/i2c/busses/i2c-npcm7xx.c | 18 +++++++-----------
> >  1 file changed, 7 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
> > index 2ad166355ec9..ddeee6f53621 100644
> > --- a/drivers/i2c/busses/i2c-npcm7xx.c
> > +++ b/drivers/i2c/busses/i2c-npcm7xx.c
> > @@ -2047,7 +2047,7 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
> >       u16 nwrite, nread;
> >       u8 *write_data, *read_data;
> >       u8 slave_addr;
> > -     int timeout;
> > +     unsigned long timeout;
> >       int ret = 0;
> >       bool read_block = false;
> >       bool read_PEC = false;
> > @@ -2099,13 +2099,13 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
> >        * 9: bits per transaction (including the ack/nack)
> >        */
> >       timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite);
> > -     timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
> > +     timeout = max(bus->adap.timeout, usecs_to_jiffies(timeout_usec));
> >       if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
> >               dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);
> >               return -EINVAL;
> >       }
> >
> > -     time_left = jiffies + msecs_to_jiffies(DEFAULT_STALL_COUNT) + 1;
> > +     time_left = jiffies + timeout + 1;
> >       do {
> >               /*
> >                * we must clear slave address immediately when the bus is not
> > @@ -2131,7 +2131,7 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
> >       }
> >
> >       npcm_i2c_init_params(bus);
> > -     bus->dest_addr = slave_addr;
> > +     bus->dest_addr = slave_addr << 1;
>
> This seems unrelated to timeout calculation.
>
> >       bus->msgs = msgs;
> >       bus->msgs_num = num;
> >       bus->cmd_err = 0;
> > @@ -2233,9 +2233,9 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev)
> >       struct i2c_adapter *adap;
> >       struct clk *i2c_clk;
> >       static struct regmap *gcr_regmap;
> > -     static struct regmap *clk_regmap;
> >       int irq;
> >       int ret;
> > +     struct device_node *np = pdev->dev.of_node;
> >
> >       bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL);
> >       if (!bus)
> > @@ -2250,15 +2250,11 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev)
> >               return PTR_ERR(i2c_clk);
> >       bus->apb_clk = clk_get_rate(i2c_clk);
> >
> > -     gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr");
> > +     gcr_regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
> >       if (IS_ERR(gcr_regmap))
> >               return PTR_ERR(gcr_regmap);
> >       regmap_write(gcr_regmap, NPCM_I2CSEGCTL, NPCM_I2CSEGCTL_INIT_VAL);
> >
> > -     clk_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-clk");
> > -     if (IS_ERR(clk_regmap))
> > -             return PTR_ERR(clk_regmap);
>
> I agree that clk_regmap can be removed, but I'd rather see it in a
> separate patch, because it's unrelated to the timeout calculation.
>
> > -
> >       bus->reg = devm_platform_ioremap_resource(pdev, 0);
> >       if (IS_ERR(bus->reg))
> >               return PTR_ERR(bus->reg);
> > @@ -2269,7 +2265,7 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev)
> >       adap = &bus->adap;
> >       adap->owner = THIS_MODULE;
> >       adap->retries = 3;
> > -     adap->timeout = HZ;
> > +     adap->timeout = msecs_to_jiffies(35);
> >       adap->algo = &npcm_i2c_algo;
> >       adap->quirks = &npcm_i2c_quirks;
> >       adap->algo_data = bus;
>
>
> Best regards,
> Jonathan




[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux