Re: [PATCH v4 08/11] i2c: designware: Convert driver to using regmap API

From: Serge Semin
Date: Wed May 27 2020 - 10:40:04 EST


On Wed, May 27, 2020 at 04:50:23PM +0300, Andy Shevchenko wrote:
> On Wed, May 27, 2020 at 03:01:08PM +0300, Serge Semin wrote:
> > Seeing the DW I2C driver is using flags-based accessors with two
> > conditional clauses it would be better to replace them with the regmap
> > API IO methods and to initialize the regmap object with read/write
> > callbacks specific to the controller registers map implementation. This
> > will be also handy for the drivers with non-standard registers mapping
> > (like an embedded into the Baikal-T1 System Controller DW I2C block, which
> > glue-driver is a part of this series).
> >
> > As before the driver tries to detect the mapping setup at probe stage and
> > creates a regmap object accordingly, which will be used by the rest of the
> > code to correctly access the controller registers. In two places it was
> > appropriate to convert the hand-written read-modify-write and
> > read-poll-loop design patterns to the corresponding regmap API
> > ready-to-use methods.
> >
> > Note the regmap IO methods return value is checked only at the probe
> > stage. The rest of the code won't do this because basically we have
> > MMIO-based regmap so non of the read/write methods can fail (this also
> > won't be needed for the Baikal-T1-specific I2C controller).
>
> Thanks! My comments below.
>
> ...
>
> > #include <linux/export.h>
> > #include <linux/i2c.h>
> > #include <linux/interrupt.h>
> > +#include <linux/regmap.h>
> > #include <linux/io.h>
> > #include <linux/kernel.h>
> > #include <linux/module.h>
>

> Please, keep ordered.

Thanks. I'll fix the order. It must have been shifted after rebase.
I made sure the order was ok before that.

>
> ...
>
> > +static int dw_reg_write_word(void *context, unsigned int reg, unsigned int val)
> > +{
> > + struct dw_i2c_dev *dev = context;
> > +
>
> > + writew_relaxed((u16)val, dev->base + reg);
> > + writew_relaxed((u16)(val >> 16), dev->base + reg + 2);
>
> What does explicit casting here help to?
> I think you may drop it.

Good question. It has been there originally. I'll remove it in the next patchset
version.

>
> > + return 0;
> > }
>
> ...
>
> > #include <linux/errno.h>
> > #include <linux/i2c.h>
> > #include <linux/interrupt.h>
> > +#include <linux/regmap.h>
> > #include <linux/io.h>
> > #include <linux/module.h>
> > #include <linux/pm_runtime.h>
>
> Order?

Ok.

-Sergey

>
> --
> With Best Regards,
> Andy Shevchenko
>
>