All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakob Hauser <jahau@rocketmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.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,
	~postmarketos/upstreaming@lists.sr.ht
Subject: Re: [PATCH v4 10/10] iio: magnetometer: yas530: Add YAS537 variant
Date: Sat, 30 Jul 2022 15:31:56 +0200	[thread overview]
Message-ID: <fa6c77e9-1d22-de2f-4cad-4afadf8c6a2a@rocketmail.com> (raw)
In-Reply-To: <CAHp75VcPMZSpDS_S_4mM2bfq4154HVMHzZHvdJnP6oUA7RtpiQ@mail.gmail.com>

Hi Andy,

On 30.07.22 13:32, Andy Shevchenko wrote:
> On Sat, Jul 30, 2022 at 1:10 AM Jakob Hauser <jahau@rocketmail.com> wrote:
>> On 29.07.22 19:24, Andy Shevchenko wrote:
>>> On Fri, Jul 29, 2022 at 1:13 AM Jakob Hauser <jahau@rocketmail.com> wrote:
> 
> ..
> 
>>>> We don't know for sure whether it is a 16-bit register or an incomplete
>>>> register naming.
>>>
>>> By the values you write into it seems to be a __be16 calibration
>>> register. The value to write is 0x3f8 which might ring a bell to you
>>> if you know what other values related to ADC.
>>
>> Sigh, ok, I'll apply bulk write.
>>
>> How to do it correctly? I guess:
>>
>>         __be16 buf = cpu_to_be16(GENMASK(9, 3));
> 
> Looks like that, yes.
> 
>>         ret = regmap_bulk_write(yas5xx->map, YAS537_ADCCAL, &buf, 2);
> 
> sizeof(buf)

OK

>>         if (ret)
>>                 return ret;
>>
>> The whole block would then look like:
>>
>>         /* Writing ADCCAL and TRM registers */
>>         __be16 buf = cpu_to_be16(GENMASK(9, 3));
> 
> (Taking into account that definitions are at the top of the function it would be
> 
>   __be16 buf;
>   ...
>   buf = cpu_to_be16(...);

Thanks for the details, I'll implement it like this.

>>         ret = regmap_bulk_write(yas5xx->map, YAS537_ADCCAL, &buf, 2);
>>         if (ret)
>>                 return ret;
>>         ret = regmap_write(yas5xx->map, YAS537_TRM, GENMASK(7, 0));
>>         if (ret)
>>                 return ret;
> 
> ..
> 
>>> To the 4100 denominator:
>>> https://github.com/XPerience-AOSP-Lollipop/android_kernel_wingtech_msm8916/blob/xpe-11.1/drivers/input/misc/yas_mag_drv-yas537.c#L235,
>>> seems you can find a lot by browsing someone's code and perhaps a Git
>>> history.
>>
>> I've seen that comment before but I don't understand its meaning.
> 
> It points out that there is a SMPLTIM, which I decode as Sample Time,
> which is in 4.1 msec steps (up to 255 steps).

Also thanks for this interpretation, that makes sense. Then the
denominator consists of factor 1000 to convert microseconds back to
milliseconds and a factor of 4.1 milliseconds per step. The value
"intrvl", which is written into the YAS537_MEASURE_INTERVAL register,
would then be the number of steps of the sample time.

However, I wouldn't add anything of this into the driver as a comment or
as a name, because we're just guessing.

> 
> ..
> 
>>>> Still I didn't get your comment. Is your intention to change the "50
>>>> milliseconds * 1000" to "50000 microseconds" in the define?
>>>>
>>>> It would look like ...
>>>>
>>>>         #define YAS537_DEFAULT_SENSOR_DELAY_US  50000
>>>>
>>>> ... though I would prefer to keep current define, as it is implemented
>>>> now and stated above:
>>>>
>>>>         #define YAS537_DEFAULT_SENSOR_DELAY_MS  50
>>>
>>> No, just to show in the actual calculation that you convert MS to US
>>> using MILLI.
>>
>> Sorry, I still don't get what you want me to do. What do you mean by
>> "using MILLI", can you elaborate?
> 
> You use formula x * 1000 to convert milliseconds to microseconds. My
> suggestion is to replace 1000 with MILLI which adds information about
> exponent sign, i.e. 10^-3 (which may be important to the reader).

Hm, ok, but the MILLI has to be defined. Or is it predefined somewhere?
I couldn't find any examples.

To my interpretation, it would look like this (upper part showing the
location of the define, lower part the formula):

    ...
    #define YAS537_LCK_MASK_GET             GENMASK(3, 0)
    #define YAS537_OC_MASK_GET              GENMASK(5, 0)

    #define MILLI                           1000

    /* Turn off device regulators etc after 5 seconds of inactivity */
    #define YAS5XX_AUTOSUSPEND_DELAY_MS     5000

    enum chip_ids {
            ...
    };

    ...

    intrvl = (YAS537_DEFAULT_SENSOR_DELAY_MS * MILLI
             - YAS537_MEASURE_TIME_WORST_US) / 4100;

I think the define and the formula both look strange.

Kind regards,
Jakob

  reply	other threads:[~2022-07-30 13:32 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1656883851.git.jahau.ref@rocketmail.com>
2022-07-03 22:02 ` [PATCH v4 00/10] Add support for magnetometer Yamaha YAS537 Jakob Hauser
2022-07-03 22:02   ` [PATCH v4 01/10] iio: magnetometer: yas530: Change data type of hard_offsets to signed Jakob Hauser
2022-07-03 22:02   ` [PATCH v4 02/10] iio: magnetometer: yas530: Change range of data in volatile register Jakob Hauser
2022-07-03 22:02   ` [PATCH v4 03/10] iio: magnetometer: yas530: Correct scaling of magnetic axes Jakob Hauser
2022-07-03 22:02   ` [PATCH v4 04/10] iio: magnetometer: yas530: Correct temperature handling Jakob Hauser
2022-07-03 22:02   ` [PATCH v4 05/10] iio: magnetometer: yas530: Change data type of calibration coefficients Jakob Hauser
2022-07-03 22:02   ` [PATCH v4 06/10] iio: magnetometer: yas530: Rename functions and registers Jakob Hauser
2022-07-04 18:04     ` Andy Shevchenko
2022-07-26 21:40       ` Jakob Hauser
2022-07-03 22:02   ` [PATCH v4 07/10] iio: magnetometer: yas530: Move printk %*ph parameters out from stack Jakob Hauser
2022-07-04 18:06     ` Andy Shevchenko
2022-07-03 22:02   ` [PATCH v4 08/10] iio: magnetometer: yas530: Apply documentation and style fixes Jakob Hauser
2022-07-04 18:07     ` Andy Shevchenko
2022-07-04 23:29     ` Linus Walleij
2022-07-03 22:04   ` [PATCH v4 09/10] iio: magnetometer: yas530: Introduce "chip_info" structure Jakob Hauser
2022-07-04 19:37     ` Andy Shevchenko
2022-07-16 17:10       ` Jonathan Cameron
2022-07-26 22:01       ` Jakob Hauser
2022-07-27 17:39         ` Andy Shevchenko
2022-07-28 23:05           ` Jakob Hauser
2022-07-29 16:08             ` Andy Shevchenko
2022-07-29 22:52               ` Jakob Hauser
2022-07-29 16:13             ` Andy Shevchenko
2022-07-29 22:56               ` Jakob Hauser
2022-07-30  0:53                 ` Andy Shevchenko
2022-07-03 22:05   ` [PATCH v4 10/10] iio: magnetometer: yas530: Add YAS537 variant Jakob Hauser
2022-07-04 19:47     ` Andy Shevchenko
2022-07-26 22:13       ` Jakob Hauser
2022-07-27 17:46         ` Andy Shevchenko
2022-07-28 23:13           ` Jakob Hauser
2022-07-29 17:24             ` Andy Shevchenko
2022-07-29 23:10               ` Jakob Hauser
2022-07-30 11:32                 ` Andy Shevchenko
2022-07-30 13:31                   ` Jakob Hauser [this message]
2022-07-30 16:36                     ` Andy Shevchenko
2022-07-31 17:53                       ` Jakob Hauser
2022-08-03 18:27                       ` Linus Walleij
2022-07-04 23:31   ` [PATCH v4 00/10] Add support for magnetometer Yamaha YAS537 Linus Walleij
2022-07-16 17:05     ` 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=fa6c77e9-1d22-de2f-4cad-4afadf8c6a2a@rocketmail.com \
    --to=jahau@rocketmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hdegoede@redhat.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.