[i2c] "regd i2c-viapro bus driver"

Jean Delvare khali at linux-fr.org
Mon Oct 9 22:25:46 CEST 2006

Hi Savitha,

> After reading your suggestions, i thought it is better
> to explain you my requirement, than asking vague
> questions. 
> My typical setup is like below
>        PCI Bus              I2C/SMBus
> cpu <------------> Vt8251<------------>i2C Device-X
>     PCI driver(i2c-viapro)  i2c driver(need to write)
> Coming from bottom up, the i2c Device-X will interrupt
> the VT 8251 whenever the data is raady. The i2c Device
> driver which needs to be developed by me, is required
> to handle this interrupt and read the i2c device-X
> data and some how i need to pass it to application
> layer(user mode). In the application layer, based on
> the data read from the device-X, i need to call
> different functions.
> Initially i read the i2c docs realted to i2c driver
> stack and found the details. After that, i started
> making each driver work from top. I understand that
> the i2c-viapro is the bus driver which sits on the top
> of stack. I started making it work with your
> guidelines and suggesttions. Now i need to write the
> i2c Device-X driver for my device. This is where i
> came across my questions like how to handle interrupts
> from i2c device etc. Now after reading your comments,
> it looks like interrupt handling is not supported in
> i2c protocol!. With the above information, i would
> like to know
> 1. Is it possible to handle the I2C device in
> interrupt mode? IF yes what all need to be
> modified/developed to support this?

In the current state, it seems difficult, but then it probably depends
on how portable your driver is supposed to be and how you intend to
connect the interrupt line from your mysterious I2C device to the
VT8251. I guess that nothing prevents a Linux i2c chip driver from
registering with an arbitrary IRQ.

> 2.How do i read the i2c Device using Polling mode?

Just take a look at any i2c-based hardware monitoring driver, say
drivers/hwmon/lm75.c for a simple one. The function polling for
registers values is lm75_update_device. It simply uses the i2c-core API.

If you need to poll the device on a regular basis, the kernel has
mechanisms to do that like for example timers, but this is not specific
to i2c at all. Note though that the i2c bus is rather slow and repeated
polling should be considered with great care only.

> 3.Can i pass the data read from the Device-X (using
> i2c Device-X driver) directly to application layer or
> in other words, can the application layer(user mode)
> read the data directly from the Device X driver?. 

You have two possibilities. Either you write a kernel driver, which
reads the values from device X, and then exports them to user-space
typically through /sysfs (but there are some other ways too.) This is
what the hardware monitoring drivers (such as lm75) do. Or you access
the device directly from user-space, using the i2c-dev driver. The
lm_sensors package has examples of how this is done (see for example
prog/detect/i2cdetect.c or prog/dump/i2cget.c.) Each approach has his
advantages and drawbacks, so it really depends on your needs and
constraints. One sure thing is that you can't use interrupts from

Jean Delvare

More information about the i2c mailing list