Re: [PATCH v3 7/7] iio: pressure: bmp280: Add nvmem operations for BMP580

From: Angel Iglesias
Date: Tue Jan 31 2023 - 17:37:04 EST


On Mon, 2023-01-30 at 14:29 +0200, Andy Shevchenko wrote:
> On Sun, Jan 29, 2023 at 02:33:09AM +0100, Angel Iglesias wrote:
> > The pressure sensor BMP580 contains a non-volatile memory that stores
> > trimming and configuration params. That memory provides an programmable
> > user range of three 2-byte words.
>
> ...
>
> > +#define NVM_READ       false
> > +#define NVM_WRITE      true
>
> How is it helpful and why it's not namespaced properly (can collide with
> NVM framework)?

I thought it could provide clarity using those aliases calling
bmp580_nvm_operation() helper function on nvmen callbacks, instead of using
just true or false. Not my brightest idea for sure.

> ...
>
> > +       /* Wait until NVM is ready again */
> > +       do {
> > +               ret = regmap_read(data->regmap, BMP580_REG_STATUS, &reg);
> > +               if (ret) {
> > +                       dev_err(data->dev, "failed to check nvm status\n");
> > +                       reg &= ~BMP580_STATUS_NVM_RDY_MASK;
> > +               }
> > +       } while (time_before(jiffies, deadline) && !(reg &
> > BMP580_STATUS_NVM_RDY_MASK));
>
> regmap_read_poll_timeout()?

Yes, thanks for pointing out, that's way better than the current loop.

>
> > +       if (!(reg & BMP580_STATUS_NVM_RDY_MASK)) {
>
>         if (ret) {
>                 ...
>                 return ret;
>         }
>
> > +               dev_err(data->dev,
> > +                       "reached timeout waiting for nvm operation
> > completion\n");
> > +               return -ETIMEDOUT;
> > +       }
>
> ...
>
> > +       while (bytes >= sizeof(u16)) {
>
> sizeof(*dst) ?
>
> Or sizeof(data->le16)?
>
> > +               addr = bmp580_nvmem_addrs[offset / sizeof(u16)];
>
> Ditto.
>
> ...
>
> > +               bytes -= sizeof(u16);
> > +               offset += sizeof(u16);
>
> Ditto.
>
> > +       }
>
> ...
>
> > +static int bmp580_nvmem_write(void *priv, unsigned int offset, void *val,
> > +                             size_t bytes)
> > +{
>
> Same comments as per above function.

Got it!

> >  }
>
>

Thanks for your time,
Angel