From: Hans de Goede <j.w.r.degoede@hhs.nl>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] First cut of a adt7470 driver
Date: Wed, 11 Jul 2007 12:47:00 +0000 [thread overview]
Message-ID: <4694D144.3030909@hhs.nl> (raw)
In-Reply-To: <20070706211144.GI3435@tree.beaverton.ibm.com>
Darrick J. Wong wrote:
I just realized I failed to respond to this point, here is my response:
>> Why use read_byte twice in read16, but write_word in write16?
>
> A "16 bit" register is really two 8 bit register reads/writes, and the
> register with the lower address has to be read/written first. Hence the
> weird helper functions.
>
Here is the code you use for this:
+static inline int adt7470_read_word_data(struct i2c_client *client, u8 reg)
+{
+ u16 foo;
+ foo = i2c_smbus_read_byte_data(client, reg);
+ foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8);
+ return foo;
+}
+
+static inline int adt7470_write_word_data(struct i2c_client *client, u8 reg,
+ u16 value)
+{
+ u16 x = cpu_to_le16(value);
+
+ return i2c_smbus_write_word_data(client, reg, x & 0xFF)
+ && i2c_smbus_write_word_data(client, reg + 1, x >> 8);
+}
+
I understand that you need to somehow read / write a byte 2 times to get a
word, but why in adt7470_read_word_data() call i2c_smbus_read_byte_data twice?
while in adt7470_write_word_data() you use cpu_to_le16() and then
i2c_smbus_write_word_data(). Why not use i2c_smbus_read_word_data() in
adt7470_read_word_data() instead of calling i2c_smbus_read_byte_data twice?
BTW I have serious doubts about you calling cpu_to_le16(), I would expect that
i2c_smbus_write_word_data() wants the data to be in cpu endianness.
Regards,
Hans
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
next prev parent reply other threads:[~2007-07-11 12:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-06 21:11 [lm-sensors] [PATCH] First cut of a adt7470 driver Darrick J. Wong
2007-07-07 8:21 ` Hans de Goede
2007-07-07 8:23 ` Hans de Goede
2007-07-08 16:53 ` Jean Delvare
2007-07-10 18:59 ` Darrick J. Wong
2007-07-10 23:33 ` Darrick J. Wong
2007-07-11 5:23 ` Hans de Goede
2007-07-11 12:47 ` Hans de Goede [this message]
2007-07-13 12:08 ` Hans de Goede
2007-07-14 14:23 ` Vadim Zeitlin
2007-07-14 20:05 ` Jean Delvare
2007-07-14 20:17 ` Hans de Goede
2007-07-16 20:18 ` Darrick J. Wong
2007-07-16 22:19 ` Philip Pokorny
2007-07-19 16:47 ` Jean Delvare
2007-07-19 16:57 ` Jean Delvare
2007-07-19 17:11 ` Hans de Goede
2007-07-21 20:07 ` Jean Delvare
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=4694D144.3030909@hhs.nl \
--to=j.w.r.degoede@hhs.nl \
--cc=lm-sensors@vger.kernel.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.