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? > +}; ... > + 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; ? > + 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 ? > + 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; ? > + /* 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? > + *rsp++ = buf[i + 1]; > + } > + > + return 0; > +} ... > +static struct i2c_driver scd30_i2c_driver = { > + .driver = { > + .name = KBUILD_MODNAME, Better to hard code. > + .of_match_table = scd30_i2c_of_match, > + .pm = &scd30_pm_ops, > + }, > + .probe_new = scd30_i2c_probe, > +}; -- With Best Regards, Andy Shevchenko