From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Stefano Tebaldi <steteb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: i2c driver doubts
Date: Fri, 24 Jul 2009 19:05:39 +0200 [thread overview]
Message-ID: <20090724190539.149b9bd5@hyperion.delvare> (raw)
In-Reply-To: <fdaba91e0907240849h6b3f1116je71acd059145a142-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
Hi Stefano,
On Fri, 24 Jul 2009 17:49:32 +0200, Stefano Tebaldi wrote:
> 2009/7/24 Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>:
> > If your device can be detected somehow, you can implement the .detect()
> > callback in your driver. This will let i2c-core instantiate the device
> > for you.
> >
> > If not, you need kernel >= 2.6.31-rc1, which has a sysfs interface to
> > instantiate (and delete) i2c devices from user-space. With older
> > kernels you can make use of the I2C_CLIENT_INSMOD* macros, which will
> > let you create devices at driver load time, but beware this is
> > deprecated and will be removed in the future.
> >
> > If you haven't yet, I strongly suggest reading
> > Documentation/i2c/instantiating-devices
>
> reading this document and asking for that issue, I have understood
> that I have to add i2c device configuration in i2c_board_info struct
> and
> call the i2c_register_board_info() in a specific architecture file
> describing platform I am using (for example, for arm architecture,
> this file can be
> linux/arch/arm/mach-pxa/mioa701.c or pcm990-baseboard.c)
> Currently I am using a standard PC and so for x86 architecture I was
> not able to find the right place where insert this registration. Then
> I tried to insert it directly in my driver, but
> I had an i2c_register_board_info() implementation missing error during
i2c_register_board_info() requires fixed i2c adapter numbers, which x86
doesn't implement. So you indeed can't use i2c_register_board_info().
> linkage of my module and then finally I used i2c_new_device() instead
> of i2c_register_board_info() (as described in method 2 of
> instantiating-devices) and now things work using i2c-stub.
> I am using a 2.6.30 kernel. I can also try I2C_CLIENT_INSMOD* macros
> or better update to kernel >= 2.6.31-rc1 and try sysfs interface to
> instantiate i2c devices as you have suggested
i2c_new_device() indeed works if you don't mind patching i2c-stub
locally. If this is only for temporary testing I guess this is
acceptable.
> > (...)
> > No, use i2c_smbus_read_i2c_block_data(). i2c_smbus_read_block_data() is
> > the SMBus variant, where you receive a block size first and only then
> > the data. SMBus devices do this but I2C devices don't.
>
> another question related to SMBus API: if I have two contigous
> registers each one containing 1 byte data and I use
> i2c_smbus_read_word_data() passing the address of the first register,
> can I obtain back the value of the two registers ?
Depends on the hardware implementation on the I2C chip side. Some chips
do support it, some do not. Just try... or look at the datasheet of
your chip.
> moreover, I read in Documentation/i2c/writing-clients the following:
>
> "If you can choose between plain I2C communication and SMBus level
> communication, please use the latter. All adapters understand SMBus level
> commands, but only some of them understand plain I2C!"
>
> Does it mean that if possibile is better to use SMBus API ?
Yes.
> But I anderstood that some SMBus functionalities could not be
> supported by some devices and i2c_check_functionality() is used for
> this purpose. Is it correct ?
This is correct. But controllers that can do I2C, can do all of SMBus by
definition. OTOH SMBus controllers can't do I2C, so if you use
i2c_transfer() (I2C) your code will not work on SMBus controllers.
Almost all x86 systems implement SMBus rather than full I2C, so you
really want to use i2c_smbus_*() functions and not i2c_transfer().
Now you're right that SMBus controllers don't have to implement all of
SMBus. Usually you have to find the correct balance between portability
and speed. If you only use byte transactions, your code will run on all
SMBus controllers, but may be slow if your chip has a large number of
(used) registers. If you start using word or block transactions, some
controllers might not support them and your driver will not work there.
As a rule of thumb, word transactions are widely supported, while block
transactions are not.
The right balance really depends on the speed improvement you get from
using block transactions for your specific chip, and on how many
different systems your driver must work. There are some cases where
portability doesn't matter at all.
And if you really need both speed and portability, you're free to
implement two (or more) register access functions in your driver, and
select the best one at run-time using i2c_check_functionality().
--
Jean Delvare
http://khali.linux-fr.org/wishlist.html
prev parent reply other threads:[~2009-07-24 17:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fdaba91e0907180554x69f0023dk5359f26b2ebf758d@mail.gmail.com>
[not found] ` <fdaba91e0907180554x69f0023dk5359f26b2ebf758d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-18 12:57 ` i2c driver doubts Stefano Tebaldi
[not found] ` <fdaba91e0907180557n32663ecdy7ce5c6818f4694ab-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-24 8:37 ` Jean Delvare
[not found] ` <20090724103738.1eac9a3b-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-07-24 15:49 ` Stefano Tebaldi
[not found] ` <fdaba91e0907240849h6b3f1116je71acd059145a142-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-24 17:05 ` Jean Delvare [this message]
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=20090724190539.149b9bd5@hyperion.delvare \
--to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=steteb-Re5JQEeQqe8AvxtiuMwx3w@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox