[PATCH 3/8] regmap: Allow specifying read/write width

Pratyush Yadav p.yadav at ti.com
Thu Jun 4 15:44:49 CEST 2020


On 31/05/20 08:08AM, Simon Glass wrote:
> Hi Pratyush,
> 
> On Wed, 27 May 2020 at 06:52, Pratyush Yadav <p.yadav at ti.com> wrote:
> >
> > Right now, regmap_read() and regmap_write() read/write a 32-bit value
> > only. To write other lengths, regmap_raw_read() and regmap_raw_write()
> > need to be used.
> >
> > This means that any driver ported from Linux that relies on
> > regmap_{read,write}() to know the size already has to be updated at each
> > callsite. This makes the port harder to maintain.
> >
> > So, allow specifying the read/write width to make it easier to port the
> > drivers, since now the only change needed is when initializing the
> > regmap.
> >
> > Signed-off-by: Pratyush Yadav <p.yadav at ti.com>
> > ---
> >  drivers/core/regmap.c | 12 +++++++++---
> >  include/regmap.h      | 28 ++++++++++++++++++----------
> >  2 files changed, 27 insertions(+), 13 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg at chromium.org>
> 
> See below
> 
> >
> > diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
> > index 24651fb3ec..0180246095 100644
> > --- a/drivers/core/regmap.c
> > +++ b/drivers/core/regmap.c
> > @@ -245,7 +245,7 @@ struct regmap *devm_regmap_init(struct udevice *dev,
> >                                 const struct regmap_config *config)
> >  {
> >         int rc;
> > -       struct regmap **mapp;
> > +       struct regmap **mapp, *map;
> >
> >         mapp = devres_alloc(devm_regmap_release, sizeof(struct regmap *),
> >                             __GFP_ZERO);
> > @@ -256,6 +256,10 @@ struct regmap *devm_regmap_init(struct udevice *dev,
> >         if (rc)
> >                 return ERR_PTR(rc);
> >
> > +       map = *mapp;
> > +       if (config)
> > +               map->width = config->width;
> > +
> >         devres_add(dev, mapp);
> >         return *mapp;
> >  }
> > @@ -378,7 +382,8 @@ int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
> >
> >  int regmap_read(struct regmap *map, uint offset, uint *valp)
> >  {
> > -       return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
> > +       return regmap_raw_read(map, offset, valp,
> > +                              map->width ? map->width : REGMAP_SIZE_32);
> 
> Can you set up map->width so you can avoid the checks?

Ok. I'll set the default to 4 in regmap_alloc() and let callers 
over-ride it if they need.

-- 
Regards,
Pratyush Yadav
Texas Instruments India


More information about the U-Boot mailing list