Re: [PATCH v3 2/4] iio: chemical: scd30: add I2C interface driver

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

 



Hello Andy,

On Tue, Jun 02, 2020 at 08:14:13PM +0300, Andy Shevchenko wrote:
> On Tue, Jun 2, 2020 at 7:49 PM Tomasz Duszynski
> <tomasz.duszynski@xxxxxxxxxxx> wrote:
> >
> > Add I2C interface driver for the SCD30 sensor.
>
> ...
>
> > +static u16 scd30_i2c_cmd_lookup_tbl[] = {
> > +       [CMD_START_MEAS] = 0x0010,
> > +       [CMD_STOP_MEAS] = 0x0104,
> > +       [CMD_MEAS_INTERVAL] = 0x4600,
> > +       [CMD_MEAS_READY] = 0x0202,
> > +       [CMD_READ_MEAS] = 0x0300,
> > +       [CMD_ASC] = 0x5306,
> > +       [CMD_FRC] = 0x5204,
> > +       [CMD_TEMP_OFFSET] = 0x5403,
> > +       [CMD_FW_VERSION] = 0xd100,
> > +       [CMD_RESET] = 0xd304,
>
> Keep sorted by value?
>

I'd rather leave it as is simply because order here matches order in
sensor datasheet.

> > +};
>
> ...
>
> > +       ret = i2c_master_send(client, txbuf, txsize);
>
> > +       if (ret != txsize)
> > +               return ret < 0 ? ret : -EIO;
>
> Wouldn't be better
>
>   if (ret < 0)
>     return ret;
>   if (ret != txsize)
>     return -EIO;
>
> ?
>

Hmm, okay. Perhaps slightly easier to read.

> > +       if (!rxbuf)
> > +               return 0;
> > +
> > +       ret = i2c_master_recv(client, rxbuf, rxsize);
>
> > +       if (ret != rxsize)
> > +               return ret < 0 ? ret : -EIO;
>
> Ditto.
>
> ...
>
> > +static int scd30_i2c_command(struct scd30_state *state, enum scd30_cmd cmd,
> > +                            u16 arg, void *response, int size)
> > +{
> > +       char crc, buf[SCD30_I2C_MAX_BUF_SIZE], *rsp = response;
> > +       int i, ret;
>
> i -> offset ?
>

'i' is shorter and I am lazy :).

> > +       put_unaligned_be16(scd30_i2c_cmd_lookup_tbl[cmd], buf);
> > +       i = 2;
> > +
> > +       if (rsp) {
> > +               /* each two bytes are followed by a crc8 */
> > +               size += size / 2;
> > +       } else {
> > +               put_unaligned_be16(arg, buf + i);
> > +               crc = crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE);
> > +               i += 2;
>
> > +               buf[i] = crc;
> > +               i += 1;
>
> buf[offset++] = crc; ?
>

I'd rather stick to what I have now. It looks more consistent.

> > +               /* commands below don't take an argument */
> > +               if ((cmd == CMD_STOP_MEAS) || (cmd == CMD_RESET))
> > +                       i -= 3;
> > +       }
> > +
> > +       ret = scd30_i2c_xfer(state, buf, i, buf, size);
> > +       if (ret)
> > +               return ret;
> > +
> > +       /* validate received data and strip off crc bytes */
> > +       for (i = 0; i < size; i += 3) {
> > +               crc = crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE);
> > +               if (crc != buf[i + 2]) {
> > +                       dev_err(state->dev, "data integrity check failed\n");
> > +                       return -EIO;
> > +               }
> > +
>
> > +               *rsp++ = buf[i];
>
> + 0 (for the sake of consistency?
>

Adding 0 is a little bit odd.

> > +               *rsp++ = buf[i + 1];
> > +       }
> > +
> > +       return 0;
> > +}
>
> ...
>
> > +static struct i2c_driver scd30_i2c_driver = {
> > +       .driver = {
>
> > +               .name = KBUILD_MODNAME,
>
> Better to hard code.
>

I seriously doubt anyone will ever want to change module name. What for?

> > +               .of_match_table = scd30_i2c_of_match,
> > +               .pm = &scd30_pm_ops,
> > +       },
> > +       .probe_new = scd30_i2c_probe,
> > +};
>
> --
> With Best Regards,
> Andy Shevchenko



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux