linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrea Merello <andrea.merello@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	Matt Ranostay <matt.ranostay@konsulko.com>,
	Alexandru Ardelean <ardeleanalex@gmail.com>,
	Jacopo Mondi <jacopo@jmondi.org>,
	Andrea Merello <andrea.merello@iit.it>
Subject: Re: [v3 11/13] iio: imu: add BNO055 serdev driver
Date: Tue, 22 Mar 2022 11:37:47 +0100	[thread overview]
Message-ID: <CAN8YU5Pc6nto5pYgorrM4RHcn-EQXfyV+=V6ig4boG7cqBTznA@mail.gmail.com> (raw)
In-Reply-To: <CAHp75VcbkZV0ek6C-YKb3iuZKyQGp7U48j-hQ+UqXFuGEYgZ4Q@mail.gmail.com>

Some inline comments, OK for the rest.

Il giorno lun 21 feb 2022 alle ore 21:28 Andy Shevchenko
<andy.shevchenko@gmail.com> ha scritto:
>
> On Thu, Feb 17, 2022 at 5:27 PM Andrea Merello <andrea.merello@gmail.com> wrote:
> >
> > This path adds a serdev driver for communicating to a BNO055 IMU via
> > serial bus, and it enables the BNO055 core driver to work in this
> > scenario.

[...]

> > +       /**
> > +        * enum cmd_status - represent the status of a command sent to the HW.
> > +        * @STATUS_OK:   The command executed successfully.
> > +        * @STATUS_FAIL: The command failed: HW responded with an error.
> > +        * @STATUS_CRIT: The command failed: the serial communication failed.
> > +        */
> > +       enum {
> > +               STATUS_OK = 0,
> > +               STATUS_FAIL = 1,
> > +               STATUS_CRIT = -1
>
> + Comma and sort them by value?
> For the second part is an additional question, why negative?

For STATUS_CRIT, being a (bad) error, a negative value seemed
appropriate to me. STATUS_OK is zero as usual, but maybe STATUS_FAIL
should be negative also? It is some legal protocol status (unlike the
STATUS_CRIT mess), in this sense I may consider it not an error, but
still our command failed (because the IMU politely didn't accept it),
so it's an error in this sense...

I may just let all of them implicit if you prefer.

[...]

> > +       while (1) {
> > +               ret = bno055_sl_send_chunk(priv, hdr + i * 2, 2);
> > +               if (ret)
> > +                       goto fail;
> > +
> > +               if (i++ == 1)
> > +                       break;
> > +               usleep_range(2000, 3000);
> > +       }
>
> The infinite loops are hard to read and understand.
> Can you convert it to the regular while or for one?
>
> Also, this looks like a repetition of something (however it seems that
> it's two sequencial packets to send).

Maybe it's worth to unroll then?

> ...
>
> > +       const int retry_max = 5;
> > +       int retry = retry_max;
>
> > +       while (retry--) {
>
> Instead simply use
>
> unsigned int retries = 5;
>
> do {
>   ...
> } while (--retries);
>
> which is much better to understand.

OK, but still have the const var for the max (see below)

> ...
>
> > +               if (retry != (retry_max - 1))
> > +                       dev_dbg(&priv->serdev->dev, "cmd retry: %d",
> > +                               retry_max - retry);
>
> This is an invariant to the loop.

why? This triggers at all retries, not at the first attempt i.e. it
prints only if this doesn't succeed at the first time. Indeed what
seems wrong to me is that you need -1 also in the dev_dbg() argument
to produce correct text.

[...]

>
> > +       reg_addr = ((u8 *)reg)[0];
>
> This looks ugly.
> Can't you supply the data struct pointer instead of void pointer?

I confirm that it's ugly :)

Not sure about what you exactly meant, sorry; what I can do is to
introduce a local and split this ugly loc, as done in
bno055_sl_write_reg(). Is this what you are suggesting?

> ...
>
> > +       if (serdev_device_set_baudrate(serdev, 115200) != 115200) {
>
> Is it limitation / requirement by the hardware? Otherwise it should
> come from DT / ACPI.

 It's a requirement. Not sure it's really by the HW; possibly it's
statically set in device firmware.

> ...
>
> > +       ret = serdev_device_set_parity(serdev, SERDEV_PARITY_NONE);
>
> Ditto.

Ditto :)

[...]

  reply	other threads:[~2022-03-22 10:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-17 16:26 [v3 00/13] Add support for Bosch BNO055 IMU Andrea Merello
2022-02-17 16:26 ` [v3 01/13] iio: add modifiers for linear acceleration Andrea Merello
2022-02-17 16:26 ` [v3 02/13] iio: document linear acceleration modifiers Andrea Merello
2022-02-19 16:08   ` Jonathan Cameron
2022-02-17 16:27 ` [v3 03/13] iio: event_monitor: add " Andrea Merello
2022-02-17 16:27 ` [v3 04/13] iio: add modifers for pitch, yaw, roll Andrea Merello
2022-02-17 16:27 ` [v3 05/13] iio: document pitch, yaw, roll modifiers Andrea Merello
2022-02-19 16:31   ` Jonathan Cameron
2022-02-17 16:27 ` [v3 06/13] iio: event_monitor: add pitch, yaw and " Andrea Merello
2022-02-17 16:27 ` [v3 07/13] iio: imu: add Bosch Sensortec BNO055 core driver Andrea Merello
2022-02-17 16:27 ` [v3 08/13] iio: document bno055 private sysfs attributes Andrea Merello
2022-02-19 16:50   ` Jonathan Cameron
2022-02-17 16:27 ` [v3 09/13] iio: document "serial_number" sysfs attribute Andrea Merello
2022-02-19 16:52   ` Jonathan Cameron
2022-02-17 16:27 ` [v3 10/13] dt-bindings: iio: imu: add documentation for Bosch BNO055 bindings Andrea Merello
2022-02-24 19:54   ` Rob Herring
2022-02-17 16:27 ` [v3 11/13] iio: imu: add BNO055 serdev driver Andrea Merello
2022-02-17 19:47   ` kernel test robot
2022-02-18  5:20   ` kernel test robot
2022-02-21 20:27   ` Andy Shevchenko
2022-03-22 10:37     ` Andrea Merello [this message]
2022-02-17 16:27 ` [v3 12/13] iio: imu: add BNO055 I2C driver Andrea Merello
2022-02-19 17:03   ` Jonathan Cameron
2022-02-21 20:32   ` Andy Shevchenko
2022-02-17 16:27 ` [v3 13/13] docs: iio: add documentation for BNO055 driver Andrea Merello
2022-02-19 17:06   ` Jonathan Cameron
2022-03-22 10:30     ` Andrea Merello
2022-03-22 20:32       ` Jonathan Cameron

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='CAN8YU5Pc6nto5pYgorrM4RHcn-EQXfyV+=V6ig4boG7cqBTznA@mail.gmail.com' \
    --to=andrea.merello@gmail.com \
    --cc=andrea.merello@iit.it \
    --cc=andy.shevchenko@gmail.com \
    --cc=ardeleanalex@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jacopo@jmondi.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt.ranostay@konsulko.com \
    --cc=mchehab+huawei@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).