From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Rory Filer <rfiler-usJ8hg9QsBLWpu6QEFMNjNBPR1lH4CV8@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: Newbie Question About Dev-Interface Method
Date: Fri, 8 Oct 2010 08:57:58 +0200 [thread overview]
Message-ID: <20101008085758.2f06dbad@endymion.delvare> (raw)
In-Reply-To: <8F90F944E50427428C60E12A34A309D2308DA559B4-3qf8vkpM5jTbmvMHnzRVpW3Pdy6AhKVLXbPIYa3/oNjDOqzlkpFKJg@public.gmane.org>
Hi Rory,
On Thu, 7 Oct 2010 14:37:57 -0700, Rory Filer wrote:
> I'm working on a proof-of-concept device which contains several chips connected to the same adapter (/dev/ic2-0) on the I2C bus. Some of these have kernel-space drivers (e.g. GPIO Expander) and some don't. For the ones that don't I've opted to use the method described in the kernel Documentation/i2c/dev-interface document. This works great and does all I need for now. This is the general procedure I'm following as outlined in kernel - Documentation/i2c/dev-interface.
>
> - open /dev/i2c-N
> - Set the chip's address by calling ioctl(file, I2C_SLAVE, address)
> - interact with the chip using read/write or smb calls, etc.
> - close the file when done
>
> I'm assuming that a kernel space chip driver like our gpio expander (pca953x.c) also uses the same adapter driver as my user-space application since that expander chip is on the same bus.
Let's clarify right away: i2c-dev (which handles /dev/i2c-* nodes) is
NOT an adapter driver. It is a bridge driver between user-space and
your adapter driver. Your adapter driver is most likely one living in
drivers/i2c/busses, and depends on the actual hardware you run on.
> My question is, what happens if a kernel driver is using the bus at the same time my user-mode application is?
It will work fine.
> Even if the user space app. may not be running when the chip driver runs, the adapter has an address written into it via the ioctl() call, I noted above.
Incorrect. The address isn't written to the adapter, it is a setting
local to i2c-dev and even specific to the file handle you got when
opening a /dev/i2c-* node. Each subsequent read, write or smbus call in
your user-space driver automatically includes the slave address, which
is only valid for the read, write or smbus call in question.
> Can unpredictable results occur in this scenario?
No.
> I think I could protect against it by writing a thread to serialize accesses to the I2C bus, but that only works if my entire application is running inside one process. I'm hoping someone on the list might be able to advise.
The i2c-core module already serializes all accesses to every given i2c
adapter through i2c_transfer() and i2c_smbus_xfer().
--
Jean Delvare
http://khali.linux-fr.org/wishlist.html
next prev parent reply other threads:[~2010-10-08 6:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-07 19:48 [PATCH v5] iio: light: Adding driver for ISL29018 ALS rklein-DDmLM1+adcrQT0dZR+AlfA
[not found] ` <1286480883-25589-1-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2010-10-07 21:37 ` Newbie Question About Dev-Interface Method Rory Filer
[not found] ` <8F90F944E50427428C60E12A34A309D2308DA559B4-3qf8vkpM5jTbmvMHnzRVpW3Pdy6AhKVLXbPIYa3/oNjDOqzlkpFKJg@public.gmane.org>
2010-10-08 6:57 ` Jean Delvare [this message]
[not found] ` <20101008085758.2f06dbad-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-09 2:03 ` Rory Filer
[not found] ` <8F90F944E50427428C60E12A34A309D2308DAD1B7F-3qf8vkpM5jTbmvMHnzRVpW3Pdy6AhKVLXbPIYa3/oNjDOqzlkpFKJg@public.gmane.org>
2010-10-09 7:33 ` Jean Delvare
2010-10-07 21:41 ` [PATCH v5] staging: iio: light: Adding driver for ISL29018 ALS Greg KH
[not found] ` <20101007214137.GA9269-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2010-10-07 22:39 ` Rhyland Klein
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=20101008085758.2f06dbad@endymion.delvare \
--to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=rfiler-usJ8hg9QsBLWpu6QEFMNjNBPR1lH4CV8@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