From: Paul Carpenter <paul-YHLC2tV1sDlxR4N9A70vTlRxknfHcPLb9dF7HbQ/qKg@public.gmane.org>
To: Andy Lutomirski <luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: What endianness is word in i2c_smbus_data?
Date: Wed, 17 Jul 2013 14:05:52 +0100 [thread overview]
Message-ID: <51E696B0.3050808@pcserviceselectronics.co.uk> (raw)
In-Reply-To: <CALCETrUKK2j17LP+dVe61UCj05w914RRgyGXhorP1nfS7=rKnA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
Andy Lutomirski wrote:
> I'm rather confused here. In SMBUS, the "read word" operation returns
> two bytes. Just to be confusing, the SMBUS spec calls the first byte
> "Data Byte Low" and the second byte "Data Byte High". But they really
> are the first and second bytes -- Read Word will return whatever Read
> Byte would have as its first byte. Let's call these bytes B1 and B2
> for first and second.
No that tells you WHATEVER the HOST endianness the bus transfer is
always treated the same, so when two bytes are combined (into a word,
the first will be the low byte for the HOST and the second will be the
high byte for the HOST. These may actually be different for the SLAVE
device.
> The eeprom and at24 drivers expect data->word to be (B2 << 8) | B1.
> That is, data->word is the cpu representation of the value on the bus
> if that value is treated as little-endian. Is that indeed the correct
> interpretation? If so, should it be documented somewhere?
Several I2C devices eg PCF8575 and MCP23017 often give 16 bit results as
2 byte transfers, knowing which byte order from device to bus to host
needs matching.
So knowing that a word is made up of bytes transmitted or received in a
particular order is important as some devices do transmit high byte
first.
> --Andy
>
--
Paul Carpenter | paul-YHLC2tV1sDlxR4N9A70vTlRxknfHcPLb9dF7HbQ/qKg@public.gmane.org
<http://www.pcserviceselectronics.co.uk/> PC Services
<http://www.pcserviceselectronics.co.uk/pi/> Raspberry Pi Add-ons
<http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
<http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
<http://www.badweb.org.uk/> For those web sites you hate
WARNING: multiple messages have this Message-ID (diff)
From: Paul Carpenter <paul@pcserviceselectronics.co.uk>
To: Andy Lutomirski <luto@amacapital.net>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: What endianness is word in i2c_smbus_data?
Date: Wed, 17 Jul 2013 14:05:52 +0100 [thread overview]
Message-ID: <51E696B0.3050808@pcserviceselectronics.co.uk> (raw)
In-Reply-To: <CALCETrUKK2j17LP+dVe61UCj05w914RRgyGXhorP1nfS7=rKnA@mail.gmail.com>
Andy Lutomirski wrote:
> I'm rather confused here. In SMBUS, the "read word" operation returns
> two bytes. Just to be confusing, the SMBUS spec calls the first byte
> "Data Byte Low" and the second byte "Data Byte High". But they really
> are the first and second bytes -- Read Word will return whatever Read
> Byte would have as its first byte. Let's call these bytes B1 and B2
> for first and second.
No that tells you WHATEVER the HOST endianness the bus transfer is
always treated the same, so when two bytes are combined (into a word,
the first will be the low byte for the HOST and the second will be the
high byte for the HOST. These may actually be different for the SLAVE
device.
> The eeprom and at24 drivers expect data->word to be (B2 << 8) | B1.
> That is, data->word is the cpu representation of the value on the bus
> if that value is treated as little-endian. Is that indeed the correct
> interpretation? If so, should it be documented somewhere?
Several I2C devices eg PCF8575 and MCP23017 often give 16 bit results as
2 byte transfers, knowing which byte order from device to bus to host
needs matching.
So knowing that a word is made up of bytes transmitted or received in a
particular order is important as some devices do transmit high byte
first.
> --Andy
>
--
Paul Carpenter | paul@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/> PC Services
<http://www.pcserviceselectronics.co.uk/pi/> Raspberry Pi Add-ons
<http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
<http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
<http://www.badweb.org.uk/> For those web sites you hate
next prev parent reply other threads:[~2013-07-17 13:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-17 1:57 What endianness is word in i2c_smbus_data? Andy Lutomirski
[not found] ` <CALCETrUKK2j17LP+dVe61UCj05w914RRgyGXhorP1nfS7=rKnA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-07-17 13:05 ` Paul Carpenter [this message]
2013-07-17 13:05 ` Paul Carpenter
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=51E696B0.3050808@pcserviceselectronics.co.uk \
--to=paul-yhlc2tv1sdlxr4n9a70vtlrxknfhcplb9df7hbq/qkg@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.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 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.