[i2c] Userspace Headers for recent kernels

Jean Delvare khali at linux-fr.org
Tue Sep 19 22:14:06 CEST 2006


Hi Don,

> I am trying to find or create some header files (i2c-dev.h and i2c.h
> if needed).  That will work for user-space programs with recent kernels
> like 2.6.17.13.
> 
> I have read the various messages in this lists archives and elsewhere
> which say:
> 
> 	- The kernel headers are not for users (no kidding they produce
> 	  copious errors).
> 
> 	- The Lm-sensors headers should be used.
> 
> However all the versions of lm-sensors I have found, including the current
> SVN, don't seem to match the kernel code.  For example the function
> i2c_smbus_write_byte() in the kernel wants a struct i2c_client while the
> lm-sensors file declares it with an int (a file number).
> 
> Am I missing something?  If not does anyone have such headers?

The file you need is indeed kernel/include/i2c-dev.h from the
lm_sensors package. It is installed
as /usr/local/include/linux/i2c-dev.h by "make user_install. This file
will work for both 2.4 and 2.6 kernels.

Some of the inline functions declared in this file have the same name
as some functions in the kernel, because they are similar in spirit.
However, the kernel structure are not available from user-space.
User-space uses ioctls to control the kernel (bus) drivers, and the
inline functions in i2c-dev.h are wrappers for these ioctls. If you are
confused by the different function signatures, just consider that the
similar names are unfortunate. These are really different functions.

For a simple example of user-space tool using i2c-dev, please see
prog/dump/i2cset.c in the lm_sensors package.

-- 
Jean Delvare



More information about the i2c mailing list