From: Tomasz Duszynski <tomasz.duszynski@octakon.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Tomasz Duszynski <tomasz.duszynski@octakon.com>,
linux-iio <linux-iio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
devicetree <devicetree@vger.kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Jonathan Cameron <jic23@kernel.org>,
Peter Meerwald <pmeerw@pmeerw.net>
Subject: Re: [PATCH v3 2/4] iio: chemical: scd30: add I2C interface driver
Date: Tue, 2 Jun 2020 19:48:46 +0200 [thread overview]
Message-ID: <20200602174846.GB2668@arch> (raw)
In-Reply-To: <CAHp75Vc60q1PC9j6KR1-OJHxw=nBAHt9zJK=h9f27yJxMHpb8A@mail.gmail.com>
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@octakon.com> 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
next prev parent reply other threads:[~2020-06-02 17:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 16:47 [PATCH v3 0/4] Add support for SCD30 sensor Tomasz Duszynski
2020-06-02 16:47 ` [PATCH v3 1/4] iio: chemical: scd30: add core driver Tomasz Duszynski
2020-06-02 16:47 ` [PATCH v3 2/4] iio: chemical: scd30: add I2C interface driver Tomasz Duszynski
2020-06-02 17:14 ` Andy Shevchenko
2020-06-02 17:48 ` Tomasz Duszynski [this message]
2020-06-02 16:47 ` [PATCH v3 3/4] iio: chemical: scd30: add serial " Tomasz Duszynski
2020-06-02 17:04 ` Andy Shevchenko
2020-06-02 17:57 ` Tomasz Duszynski
2020-06-02 19:15 ` Tomasz Duszynski
2020-06-02 16:47 ` [PATCH v3 4/4] dt-bindings: iio: scd30: add device binding file Tomasz Duszynski
2020-06-02 16:55 ` [PATCH v3 0/4] Add support for SCD30 sensor Andy Shevchenko
2020-06-02 18:08 ` Tomasz Duszynski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200602174846.GB2668@arch \
--to=tomasz.duszynski@octakon.com \
--cc=andy.shevchenko@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.