Skip to contentSkip to conversation

userspace dev-interface linux-2.6.7

DISCUSSION Nils Roeder 3 participants 10 messages May 19, 2005 – Jun 25, 2005

lore
Share & tools
lore
#0 lore raw

hi

i use a userspace program to access /dev/i2c-0 which uses (/doc/dev-interface)
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
which works fine in linux-2.4.x

'porting' this to linux-2.6.7 causes too many errors. can anyone point me to the right direction so solve these ? (i realised in 2.6.7 the smbus macros are missing in i2c-dev.h so i am basically a bit lost...)

a more interesting question (for me at least) is -
do i actually need to do that.
just today (i must admit) i tried lmsensors for the first time, crosscompiled 'i2cdetect' and realised it can find all my devices attached to /dev/i2c-0.
so, can i read and write to the devices found by i2cdetect (e.g 0x4b on /dev/i2c-0)
using kernel drivers rather than my userspace program, if so how (or where can i read about it) ?

cheers,
nils

#1 lore raw
Quoted 6 lines

that helps indeed, thanks very much.
why is this not mentioned in
linux-2.6.x/Documentation/i2c/dev-interface ?

while it is mentioned in
http://www2.lm-sensors.nu/~lm78/cvs/lm_sensors2/doc/developers/applications

No idea, most probably because nobody updated the dev-interface document since the i2c-dev header file was split. If you submit a patch updating it, I'll review it and have it applied.

Thanks,

Signature · 1 line
Jean Delvare
#2 lore raw
In reply to Nils Roeder
Quoted 8 lines · Nils Roeder

hi

i use a userspace program to access /dev/i2c-0 which uses (/doc/dev-interface)
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
which works fine in linux-2.4.x

Quoted 4 lines

'porting' this to linux-2.6.7 causes too many errors. can anyone point me to the right direction so solve these ? (i realised in 2.6.7 the smbus macros are missing in i2c-dev.h so i am basically a bit lost...)

Yes plz read further.

Quoted 9 lines

a more interesting question (for me at least) is -
do i actually need to do that.
just today (i must admit) i tried lmsensors for the first time, crosscompiled 'i2cdetect' and realised it can find all my devices attached to /dev/i2c-0.
so, can i read and write to the devices found by i2cdetect (e.g 0x4b on /dev/i2c-0)
using kernel drivers rather than my userspace program, if so how (or where can i read about it)

Have you read linux-2.6.XXXX/Documentation/i2c ?

There is file called dev-interface, that should help you. If you have any more questions, just write again.

Regards

Rudolf

#3 lore raw
In reply to Nils Roeder

Rudolf Marek wrote:
[snip]

Quoted 5 lines

Have you read linux-2.6.XXXX/Documentation/i2c ?

There is file called dev-interface, that should help you. If you have any more questions, just write again.

thanks for replying.
Linux-2.6.XXXX/Documentation/i2c is what i read.
the problem is that #include <linux/i2c-dev.h> causes compiler errors because of the missing I2C_SMBUS_... macros in 2.6.x (if you want i include the error output, my example program or
the linux/i2c-dev.h file i am using)
although all this is fixable, i am surprised that i couldn't find any howto/tutorial/advice on that - or am i the only one having this problem ?

thanks,
nils

#4 lore raw
In reply to Nils Roeder

Jean Delvare wrote:
[snip]

Quoted 8 lines

There are two i2c-dev.h files, one for kernel-space and one for user-space. If you are writing a user-space tool which will access /dev/i2c-*, you need the user-space version of i2c-dev.h, which is distributed with lm_sensors for historical reasons, although I believe the kernel-headers package has a copy as well. This version will work regardless of the version of the kernel you are using.

Quoted 4 lines

Hope that helps,
--
Jean Delvare

that helps indeed, thanks very much.
why is this not mentioned in
linux-2.6.x/Documentation/i2c/dev-interface ?

while it is mentioned in
http://www2.lm-sensors.nu/~lm78/cvs/lm_sensors2/doc/developers/applications

thanks again,
nils

#5 lore raw
In reply to Nils Roeder

Jean Delvare wrote:
[snip]

Quoted 3 lines

No idea, most probably because nobody updated the dev-interface document since the i2c-dev header file was split. If you submit a patch updating it, I'll review it and have it applied.

i am happy to submit an update patch for the dev-interface document, but at the moment i still have too many errors - i assume not many people use /dev from user-space in 2.6.x anymore ?

so far :

(i) use lm_sensors i2c-dev.h instead of kernel header file #include <linux/i2c.h>
#include "i2c-dev.h" /* lm_sensors header file */

causes compile errors due to <linux/i2c.h>

(ii)
putting some #ifdef __KERNEL__ back into <linux/i2c.h> helps. two errors remain:

i2c-dev.h:39: error: redefinition of struct i2c_msg' i2c-dev.h:123: error: redefinition of union i2c_smbus_data'

(iii)
commenting out the above definitions in "i2c-dev.h" helps compiling, but i am not sure it should be done...

any suggestions anyone ?

regards

nils roeder

#6 lore raw
In reply to Nils Roeder

Hi Nils,

Quoted 8 lines

Linux-2.6.XXXX/Documentation/i2c is what i read.
the problem is that #include <linux/i2c-dev.h> causes compiler errors because of the missing I2C_SMBUS_... macros in 2.6.x (if you want i include the error output, my example program or
the linux/i2c-dev.h file i am using)
although all this is fixable, i am surprised that i couldn't find any howto/tutorial/advice on that - or am i the only one having this problem ?

There are two i2c-dev.h files, one for kernel-space and one for user-space. If you are writing a user-space tool which will access /dev/i2c-*, you need the user-space version of i2c-dev.h, which is distributed with lm_sensors for historical reasons, although I believe the kernel-headers package has a copy as well. This version will work regardless of the version of the kernel you are using.

Hope that helps,
--
Jean Delvare

#7 lore raw
In reply to Nils Roeder

Hi Nils,

Quoted 3 lines

i am happy to submit an update patch for the dev-interface document, but at the moment i still have too many errors - i assume not many people use /dev from user-space in 2.6.x anymore ?

Well, i2cdetect, i2cdump and i2cset can be compiled when running a 2.6 kernel - so lots of people actually do.

Quoted 5 lines

(i) use lm_sensors i2c-dev.h instead of kernel header file #include <linux/i2c.h>
#include "i2c-dev.h" /* lm_sensors header file */

causes compile errors due to <linux/i2c.h>

Do not include linux/i2c.h in a user-space program. This is a kernel-space header file. If should work just fine without it, the only header file you really need is i2c-dev.h.

Signature · 1 line
Jean Delvare
#8 lore raw
In reply to Nils Roeder

hi,

here is an updated version of Documentation/i2c/dev_interface which just adds that there are two versions of i2c-dev.h and that the userspace version is distributed with lm_sensors.

nils
-------------- next part --------------

i2c/dev-interface renamed from i2c/dev-interface.orig +3 -1
@@ -16,7 +16,9 @@ C example
 So let's say you want to access an i2c adapter from a C program. The
 first thing to do is `#include <linux/i2c.h>" and "#include <linux/i2c-dev.h>. 
 Yes, I know, you should never include kernel header files, but until glibc 
-knows about i2c, there is not much choice.
+knows about i2c, there is not much choice. For this purpose there are two 
+i2c-dev.h files, one for kernel-space and one for user-space. The user-space 
+version of i2c-dev.h is distributed with lm_sensors for historical reasons.
 
 Now, you have to decide which adapter you want to access. You should
 inspect /sys/class/i2c-dev/ to decide this. Adapter numbers are assigned
#9 lore raw
In reply to Nils Roeder

Hi Nils,

Sorry for the late answer.

Quoted 3 lines

here is an updated version of Documentation/i2c/dev_interface which just adds that there are two versions of i2c-dev.h and that the userspace version is distributed with lm_sensors.

It wasn't totally exact, so I reworded it and commited the change to i2c-CVS. Thanks for the suggestion. A similar change is on its way to Linux 2.6.

Thanks,

Signature · 1 line
Jean Delvare