From: Jonathan Cameron <jic23@kernel.org>
To: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
Lars-Peter Clausen <lars@metafoo.de>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] iio: light: bu27034: Fix scale format
Date: Sat, 17 Jun 2023 20:30:49 +0100 [thread overview]
Message-ID: <20230617203049.5e2d304a@jic23-huawei> (raw)
In-Reply-To: <5369117315cf05b88cf0ccb87373fd77190f6ca2.1686648422.git.mazziesaccount@gmail.com>
On Tue, 13 Jun 2023 12:34:36 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> The driver is expecting accuracy of NANOs for intensity scale in
> raw_write. The IIO core is however defaulting to MICROs. This leads the
> raw-write of smallest scales to never succeed as correct selector(s) are
> not found.
>
> Fix this by implementing the .write_raw_get_fmt callback to use NANO
> accuracy for writes of IIO_CHAN_INFO_SCALE.
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor")
Applied to the fixes-togreg branch of iio.git
Note however that the fixes-togreg branch has moved on to a 'post merge window'
state as the last lot of fixes are in char-misc-next (not char-misc-linus)
and hence targetting the merge window.
As such I will be holding these locally for a while as if I push them out
it will make a mess of the ordering of branches merged into linux-next
Jonathan
> ---
> drivers/iio/light/rohm-bu27034.c | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c
> index 846c3d43aa34..f737d62bdf92 100644
> --- a/drivers/iio/light/rohm-bu27034.c
> +++ b/drivers/iio/light/rohm-bu27034.c
> @@ -572,7 +572,7 @@ static int bu27034_set_scale(struct bu27034_data *data, int chan,
> return -EINVAL;
>
> if (chan == BU27034_CHAN_ALS) {
> - if (val == 0 && val2 == 1000)
> + if (val == 0 && val2 == 1000000)
> return 0;
>
> return -EINVAL;
> @@ -584,7 +584,7 @@ static int bu27034_set_scale(struct bu27034_data *data, int chan,
> goto unlock_out;
>
> ret = iio_gts_find_gain_sel_for_scale_using_time(&data->gts, time_sel,
> - val, val2 * 1000, &gain_sel);
> + val, val2, &gain_sel);
> if (ret) {
> /*
> * Could not support scale with given time. Need to change time.
> @@ -621,7 +621,7 @@ static int bu27034_set_scale(struct bu27034_data *data, int chan,
>
> /* Can we provide requested scale with this time? */
> ret = iio_gts_find_gain_sel_for_scale_using_time(
> - &data->gts, new_time_sel, val, val2 * 1000,
> + &data->gts, new_time_sel, val, val2,
> &gain_sel);
> if (ret)
> continue;
> @@ -1213,6 +1213,21 @@ static int bu27034_read_raw(struct iio_dev *idev,
> }
> }
>
> +static int bu27034_write_raw_get_fmt(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + long mask)
> +{
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SCALE:
> + return IIO_VAL_INT_PLUS_NANO;
> + case IIO_CHAN_INFO_INT_TIME:
> + return IIO_VAL_INT_PLUS_MICRO;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> static int bu27034_write_raw(struct iio_dev *idev,
> struct iio_chan_spec const *chan,
> int val, int val2, long mask)
> @@ -1260,6 +1275,7 @@ static int bu27034_read_avail(struct iio_dev *idev,
> static const struct iio_info bu27034_info = {
> .read_raw = &bu27034_read_raw,
> .write_raw = &bu27034_write_raw,
> + .write_raw_get_fmt = &bu27034_write_raw_get_fmt,
> .read_avail = &bu27034_read_avail,
> };
>
next prev parent reply other threads:[~2023-06-17 19:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 9:34 [PATCH 0/3] ROHM BUxxx light sensor fixes Matti Vaittinen
2023-06-13 9:34 ` [PATCH 1/3] iio: light: bu27034: Fix scale format Matti Vaittinen
2023-06-17 19:30 ` Jonathan Cameron [this message]
2023-06-13 9:34 ` [PATCH 2/3] iio: light: bu27008: " Matti Vaittinen
2023-06-13 9:35 ` [PATCH 3/3] iio: light: bu27008: Fix intensity data type Matti Vaittinen
2023-06-17 19:35 ` 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=20230617203049.5e2d304a@jic23-huawei \
--to=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=mazziesaccount@gmail.com \
/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