[i2c] I2C Bus Driver needed?

James Chapman jchapman at katalix.com
Tue May 1 10:06:30 CEST 2007


Markus Franke wrote:
> Hi,
> 
> many thanks for your reply.
> 
> Quoting James Chapman <jchapman at katalix.com>:
> 
>> For general i2c, you'll need a bus driver so that the kernel i2c core
>> knows how to control the i2c bus with your hardware. Look at examples
>> in drivers/i2c/busses. Some bus drivers are quite complex while others
>> can be simple, depending on the capabilities of the actual i2c
>> hardware. If you need to write one, study the code of another driver
>> which has similar characteristics to your device. See Documentation/i2c
>> for more info.
> 
>> Perhaps you won't need to write one yourself if one already exists in
>> the kernel for the i2c controller device that you are using. Or perhaps
>> your SoC has hardware support that effectively hides I2C for accessing
>> certain connected devices using direct SoC register access? If so, a
>> device driver for the specific device (providing register access via a
>> char device) might be more appropriate. It all depends on your hardware.
> 
> All the drivers in "chips" directory are using a bus driver. 

Correct.

> I still 
> don't understand how it can work without a bus driver. The chip driver 
> has to call at some point in time "i2c_attach_adapter()". But generally 
> this function is only called when a new adapter is attached to the bus 
> via "i2c_add_adapter()", through the detect function of the chip driver. 
> But if I don't need a bus driver by itself because my hardware hides I2C 
> access somehow, how can this fit into the general linux i2c scheme?

My comment about you might not needing one is the very rare case where a 
SoC might have hardware support for interfacing to specific i2c device 
types. It might provide a memory-mapped register interface and handle 
i2c transactions with the hardware transparently. One example is a SoC 
that supports an external i2c nvram. It provides a register for the user 
to set a RAM offset and a register for reading/writing the data at that 
offset. Under the hood, the SoC handles all of the i2c transactions. In 
such cases, you don't need a bus driver or a chip driver or the kernel 
i2c core; you just need a custom driver for accessing the SoC's memory 
mapped registers. Such setups are very unusual, however. I note in a 
comment below that your SoC has an i2c controller so you will need a bus 
driver for accessing i2c devices on that bus.

 > I
> would like to use the existing drivers in "chips" directory as a 
> reference but it seems that it doesn't work in my case.
> 
> It would be really nice to see an example driver which is designed for a 
> SoC/AMBA/APB. If anyone is able to provide something like that I would 
> be really glad.

The Au1xxx is a MIPS SoC. It has an i2c bus driver.

> BTW, there is no bus driver already available in linux for my i2c 
> controller.

If your SoC has an i2c controller and you need to access one or more 
devices on that bus, you will need a bus driver.

-- 
James Chapman
Katalix Systems Ltd
http://www.katalix.com
Catalysts for your Embedded Linux software development




More information about the i2c mailing list