From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Gabriel Krisman Bertazi <krisman@collabora.com>
Cc: Shreeya Patel <shreeya.patel@collabora.com>,
Jonathan Cameron <jic23@kernel.org>, <krzk@kernel.org>,
<lars@metafoo.de>, <robh+dt@kernel.org>, <Zhigang.Shi@liteon.com>,
<linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <kernel@collabora.com>,
<alvaro.soliverez@collabora.com>
Subject: Re: [PATCH 3/3] iio: light: Add support for ltrf216a sensor
Date: Tue, 12 Apr 2022 15:53:46 +0100 [thread overview]
Message-ID: <20220412155346.00005d25@Huawei.com> (raw)
In-Reply-To: <875ynexup1.fsf@collabora.com>
On Tue, 12 Apr 2022 10:06:18 -0400
Gabriel Krisman Bertazi <krisman@collabora.com> wrote:
> Shreeya Patel <shreeya.patel@collabora.com> writes:
>
> >>> + val_1 = i2c_smbus_read_byte_data(data->client, addr + 1);
> >>> + val_2 = i2c_smbus_read_byte_data(data->client, addr + 2);
> >>> + ret = (val_2 << 16) + (val_1 << 8) + val_0;
> >> This is a le24_to_cpu() conversion.
> >> Preferred choice would be to use something like
> >> u8 buf[3];
> >> int i;
> >>
> >> for (i = 0; i < 3; i++) {
> >> ret = i2c_smbus_read_byte_data(data->client, addr);
> >> if (ret < 0)
> >> return ret;
> >> buf[i] = ret;
> >> }
> >> return le24_to_cpu(buf);
> >>
> >
> > We do not have any le24_to_cpu() function in current kernel source code.
> > I was thinking to use le32_to_cpu() instead but it requires an argument of
> > type __le32 and our case we storing the values in u8 buf[3] so I'm not
> > really sure if it's possible to use le32_to_cpu() or any other function.
>
> I guess you could make it a 32-bit buffer, keep the most
> significant byte zeroed and return le32_to_cpu:
>
> u8 buf[4];
>
> memset(buf, 0x0, sizeof(buf));
>
> for (i = 0; i < 3; i++) {
> ret = i2c_smbus_read_byte_data(data->client, addr);
> if (ret < 0)
> return ret;
> buf[i] = ret;
> }
> return le32_to_cpu(buf);
>
I was being silly. It's not aligned for obvious reasons that we don't do
24bit alignment, so you need
get_unaligned_le24()
Jonathan
next prev parent reply other threads:[~2022-04-12 14:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-25 10:30 [PATCH 0/3] Add LTRF216A Driver Shreeya Patel
2022-03-25 10:30 ` [PATCH 1/3] dt-bindings: vendor-prefixes: Add 'ltr' as deprecated vendor prefix Shreeya Patel
2022-03-25 12:21 ` Krzysztof Kozlowski
2022-03-25 10:30 ` [PATCH 2/3] dt-bindings: Document ltrf216a light sensor bindings Shreeya Patel
2022-03-25 12:23 ` Krzysztof Kozlowski
2022-03-27 13:55 ` Jonathan Cameron
2022-03-28 2:49 ` Gabriel Krisman Bertazi
2022-03-25 10:30 ` [PATCH 3/3] iio: light: Add support for ltrf216a sensor Shreeya Patel
2022-03-25 12:25 ` Krzysztof Kozlowski
2022-03-27 14:30 ` Jonathan Cameron
2022-03-29 20:03 ` Shreeya Patel
2022-04-02 16:49 ` Jonathan Cameron
2022-04-11 17:06 ` Shreeya Patel
2022-04-12 14:06 ` Gabriel Krisman Bertazi
2022-04-12 14:53 ` Jonathan Cameron [this message]
2022-03-28 3:59 ` Gabriel Krisman Bertazi
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=20220412155346.00005d25@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=Zhigang.Shi@liteon.com \
--cc=alvaro.soliverez@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=kernel@collabora.com \
--cc=krisman@collabora.com \
--cc=krzk@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=shreeya.patel@collabora.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