[i2c] linux 2.6.20.2 patched from maxim, and i2c

Jean Delvare khali at linux-fr.org
Wed Apr 18 15:01:22 CEST 2007


Hi Matt,

On Mon, 16 Apr 2007 15:36:31 -0400, Matt Gessner wrote:
> I've been doing a lot of looking, and haven't found the answer to this
> question:
> 
> I have two devices on my AT91RM9200 TWI bus, tlv320 from TI.
> 
> How do I talk to these two devices?  Do I make /dev/i2c-0 and /dev/i2c-1?

No. /dev/i2c-* nodes correspond to I2C buses, not I2C devices. If you
only have the AT91RM9200 TWI bus, it should show as /dev/i2c-0
(or /dev/i2c/0) as soon as you load the i2c-dev driver.

> That didn't work.  If I just open /dev/i2c-0, when I try to ioctl I2C_SLAVE
> before each write, I get an illegal seek error (turns out I think it's
> really -EBUSY returned by i2c-dev.c's ioctl function.

The I2C_SLAVE ioctl only needs to be used once, before the first
message. Then i2c-dev will remember the slave address for all
subsequent messages, until another I2C_SLAVE ioctl is issued.

That being said, setting I2C_SLAVE shouldn't return an illegal seek
error. This error message corresponds to ESPIPE and i2c-dev never
returns that. I suspect you've done something wrong.

i2c-dev will return -EBUSY if you attempt to set the slave address to
an address which the kernel is already using. If you know what you're
doing, you can use the I2C_SLAVE_FORCE ioctl to bypass this check. But
in general this is a bad idea and you don't want to do that. An I2C
device should be handled either by a kernel driver, or through i2c-dev,
not both.

You can use "i2cdetect 0" (from the lm-sensors package) to probe your
I2C bus and see what devices are present, and whether they are in use
(UU) or not.

> Or do I have to open only one at a time, set the I2C_SLAVE and do everything
> I want in one shot, close the device, and then open the other one?

You can to pretty much everything you want, the i2c-dev interface is
very flexible. As long as you set the I2C slave address after each
open, it should work OK. But ideally you would only close the device
node when you're completely done, as additional close and open have a
cost.

-- 
Jean Delvare



More information about the i2c mailing list