All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Jakob Hauser <jahau@rocketmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Hans de Goede <hdegoede@redhat.com>,
	linux-iio <linux-iio@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	phone-devel@vger.kernel.org,
	"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS
	<devicetree@vger.kernel.org>, Hans de Goede <hdegoede@redhat.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>," 
	<~postmarketos/upstreaming@lists.sr.ht>
Subject: Re: [PATCH v2 7/7] iio: magnetometer: yas530: Add YAS537 variant
Date: Mon, 13 Jun 2022 17:20:20 +0200	[thread overview]
Message-ID: <CAHp75VfFwSQ6bk=TMLiyA1j-AsafjGdVFbTTHJJ67C8zeYfz8Q@mail.gmail.com> (raw)
In-Reply-To: <b6e100de37921c22ebf0698f8e0e99794053303a.1655081082.git.jahau@rocketmail.com>

On Mon, Jun 13, 2022 at 3:18 AM Jakob Hauser <jahau@rocketmail.com> wrote:
>
> This adds support for the magnetometer Yamaha YAS537. The additions are based
> on comparison of Yamaha Android kernel drivers for YAS532 [1] and YAS537 [2].
>
> In the Yamaha YAS537 Android driver, there is an overflow/underflow control
> implemented. For regular usage, this seems not necessary. A similar overflow/
> underflow control of Yamaha YAS530/532 Android driver isn't integrated in the
> mainline driver. It is therefore skipped for YAS537 in mainline too.
>
> Also in the Yamaha YAS537 Android driver, at the end of the reset_yas537()
> function, a measurement is saved in "last_after_rcoil". Later on, this is
> compared to current measurements. If the difference gets too big, a new
> reset is initialized. The difference in measurements needs to be quite big,
> it's hard to say if this is necessary for regular operation. Therefore this
> isn't integrated in the mainline driver either.

...

> - * YAS537 MS-3T (2015 Samsung Galaxy S6, Note 5, Xiaomi)
> + * YAS537 MS-3T (2015 Samsung Galaxy S6, Note 5, Galaxy S7)

Not sure what happened to Xiaomi. There is nothing in the commit
message about this change.

...

> +#define YAS537_MAG_AVERAGE_32_MASK     GENMASK(6, 4) /* corresponds to 0x70 */

Useless comment.

...

> +#define YAS537_MEASURE_TIME_WORST      1500 /* us */
> +#define YAS537_DEFAULT_SENSOR_DELAY    50   /* ms */
> +#define YAS537_MAG_RCOIL_TIME          65   /* us */

Instead of the comments, use unit suffixes, i.e. _US, _MS, _US.

...

> +       /* Read data */

Not sure how useful is this comment.

...

> +       *t = ((data[0] << 8) | data[1]);

Looks like get_unaligned_be16().

> +       xy1y2[0] = ((FIELD_GET(GENMASK(5, 0), data[2]) << 8) | data[3]);
> +       xy1y2[1] = ((data[4] << 8) | data[5]);
> +       xy1y2[2] = ((data[6] << 8) | data[7]);

Ditto for all above.

...

> +                       if (h[i] < -8192)
> +                               h[i] = -8192;

-BIT(13) ?

> +                       if (h[i] > 8191)
> +                               h[i] = 8191;

Altogether seems like NIH clamp_val() or clamp_t().

...

> +                       xy1y2[i] = h[i] + 8192;

BIT(13)

...

> +       /*
> +        * Raw temperature value t is number of counts. A product description
> +        * of YAS537 mentions a temperature resulution of 0.05 °C/count.

resolution

> +        * A readout of the t value at ca. 20 °C returns approx. 8120 counts.
> +        *
> +        * 8120 counts x 0.05 °C/count corresponds to a range of 406 °C.
> +        * 0 counts would be at theoretical -386 °C.
> +        *
> +        * The formula used for YAS530/532 needs to be adapted to this
> +        * theoretical starting temperature, again calculating with 1/10:s
> +        * of degrees Celsius and finally multiplying by 100 to get milli
> +        * degrees Celsius.
> +        */

...

>                         /*
> -                        * Raw values of YAS532 are in nanotesla. Devide by
> -                        * 100000 (10^5) to get Gauss.
> +                        * Raw values of YAS532 and YAS537 are in nanotesla.
> +                        * Devide by 100000 (10^5) to get Gauss.

Divide (chance to fix a type while at it)

>                          */

...

> @@ -679,6 +887,7 @@ static int yas530_get_calibration_data(struct yas5xx *yas5xx)
>         c->r[0] = sign_extend32(FIELD_GET(GENMASK(28, 23), val), 5);
>         c->r[1] = sign_extend32(FIELD_GET(GENMASK(20, 15), val), 5);
>         c->r[2] = sign_extend32(FIELD_GET(GENMASK(12, 7), val), 5);
> +
>         return 0;
>  }
>

Not harmful, but a stray change. Ditto for the rest like this. I would
rather split them to a separate patch.

...

> +       dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 17, data);

Use less stack by "%17ph".

...

> +       /* Sanity check, is this all zeroes? */
> +       if (memchr_inv(data, 0x00, 16) == NULL) {

  if (!memchr_inv(...))

> +               if (FIELD_GET(GENMASK(5, 0), data[16]) == 0)
> +                       dev_warn(yas5xx->dev, "calibration is blank!\n");
> +       }

...

> +               for (i = 0; i < 17; i++) {

16 and 17 seems like a magic that is used a lot, perhaps define?

...

> +               ret = regmap_write(yas5xx->map, YAS537_MTC + 3,
> +                                  ((data[3] & GENMASK(7, 5)) | BIT(4)));

Here...

> +               if (ret)
> +                       return ret;
> +               ret = regmap_write(yas5xx->map, YAS537_HCK,
> +                                  (FIELD_GET(GENMASK(7, 4), data[15]) << 1));

...and here and in many other places, please drop outer parentheses,
they are not needed.

> +               if (ret)
> +                       return ret;

...

> +       usleep_range(YAS537_MAG_RCOIL_TIME, YAS537_MAG_RCOIL_TIME+100);

Please, add a comment explaining why this is needed.

...

> +               dev_info(dev, "detected YAS537 MS-3T");
> +               /* As the version naming is unknown, provide it for debug only */
> +               dev_dbg(yas5xx->dev, "YAS537 version: %s\n",
> +                       yas5xx->version ? "1" : "0");

No need to have two prints, just add a version to the above one and
drop the bottom one.


-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2022-06-13 18:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1655081082.git.jahau.ref@rocketmail.com>
2022-06-13  1:15 ` [PATCH v2 0/7] Add support for magnetometer Yamaha YAS537 Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 1/7] iio: magnetometer: yas530: Change data type of hard_offsets to signed Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 2/7] iio: magnetometer: yas530: Change range of data in volatile register Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 3/7] iio: magnetometer: yas530: Correct scaling of magnetic axes Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 4/7] iio: magnetometer: yas530: Correct temperature handling Jakob Hauser
2022-06-13 15:01     ` Andy Shevchenko
2022-06-15 21:18       ` Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 5/7] iio: magnetometer: yas530: Change data type of calibration coefficients Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 6/7] iio: magnetometer: yas530: Rename functions and registers Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 7/7] iio: magnetometer: yas530: Add YAS537 variant Jakob Hauser
2022-06-13 15:20     ` Andy Shevchenko [this message]
2022-06-13 15:22       ` Andy Shevchenko
2022-06-15 21:51         ` Jakob Hauser
2022-06-15 21:43       ` Jakob Hauser
2022-06-15 22:00         ` Jakob Hauser
2022-06-18 14:15         ` Jonathan Cameron
2022-06-13 15:23   ` [PATCH v2 0/7] Add support for magnetometer Yamaha YAS537 Andy Shevchenko

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='CAHp75VfFwSQ6bk=TMLiyA1j-AsafjGdVFbTTHJJ67C8zeYfz8Q@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=jahau@rocketmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=phone-devel@vger.kernel.org \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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.