Skip to contentSkip to conversation

Helps: how to use i801--SMBus functions via i2c-dev

lm-sensors MK GU 4 participants 13 messages Nov 1, 2005 – Nov 7, 2005

lore
Share & tools
lore

MK GU

author
#0 lore raw

Dear Sir,

I am new to Linux and Device driver programming. I am trying to write a device driver software module to access the ICH6 SMBus controller on the motherboard of our PC running Linux 2.6.10 kernel. I configured my 2.6.10 kernel to have I2C built-in support and your i801 module loaded. Then I loaded the i2c-dev interface module and wrote a short application software to test the functions for SMBus. After my application opened the /dev/i2c device, I received messages saying "i2c-adaptor: i2c-0 -- I2C level transfer not support" when my application software called the read and write function of the i2c-dev module. Further tracking inside the i2c-dev module shew that the algorithm parameter adap->algo->master_xfer = NULL. That means the i801 driver was not properly loaded by the i2c-dev module.

Could you advise how I can make use of the i801 module and your i2c-dev module to access the ICH6 SMBus controller?

Thanks a lot in advance.
Michael Gu

---------------------------------
Find your next car at Yahoo! Canada Autos

#1 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions via

Hi Michael,

Quoted 1 line

Dear Sir,

We are not a sir. We are a number of different people, this is a mailing list.

Quoted 4 lines

I am new to Linux and Device driver programming. I am trying to write a device driver software module to access the ICH6 SMBus controller on the motherboard of our PC running Linux 2.6.10 kernel.

This driver already exists, it's named i2c-i801. From the below, it seems that you found that already, but your sentence is somewhat confusing nevertheless.

Quoted 10 lines

I configured my 2.6.10 kernel to have I2C built-in support and your i801 module loaded. Then I loaded the i2c-dev interface module and wrote a short application software to test the functions for SMBus. After my application opened the /dev/i2c device, I received messages saying "i2c-adaptor: i2c-0 -- I2C level transfer not support" when my application software called the read and write function of the i2c-dev module. Further tracking inside the i2c-dev module shew that the algorithm parameter adap->algo->master_xfer = NULL. That means the i801 driver was not properly loaded by the i2c-dev module.

No, this means just what the error message said. The ICH6 is an SMBus master, not an I2C master. SMBus is a subset of I2C. I2C masters can emulate SMBus transactions, but not the other way around.

Quoted 2 lines

Could you advise how I can make use of the i801 module and your i2c-dev module to access the ICH6 SMBus controller?

Instead of using read() and write() on the device file, you have to use ioctl(). See in i2c-dev.h (from the lm_sensors project) for a list of available commands. You will at least need I2C_SLAVE to set the target chip address, and I2C_SMBUS to run SMBus transactions. There are helper functions in i2c-dev.h to make your life easier with SMBus transactions, so you shouldn't have to use I2C_SMBUS explicitely.

There is some documentation available in the i2c package, or online at:
http://www2.lm-sensors.nu/~lm78/cvs/i2c/doc/dev-interface

You should take a look at prog/dump/i2cset.c in the lm_sensors package, it is a nice example of how userspace programs can access SMBus. There are a few other test programs in this package, but I think this is the most simple one we have.

Signature · 1 line
Jean Delvare
#2 lore raw

[lm-sensors] RE: Helps: how to use i801--SMBus functions via

In reply to MK GU

Could anyone advise how I can make use i2c-i801 and/or i2c-dev to access ICH6 SMBus controller on a PC motherboard? I have Linux 2.6.10 and loaded i2c-core, i2c-i801and i2c-dev modules. lsmod command gave me the following info:

# lsmod

Module Size Used by

i2c_dev 8320 0

i2c_sensor 3968 0

i2c_i801 8716 0

i2c_core 16272 3 i2c_dev,i2c_sensor,i2c_i801

It seems that i2c-i801 is not used by other modules.

Thanks.

Michael Gu

-----Original Message-----
From: MK GU [mailto:[email protected]]
Sent: Tuesday, November 01, 2005 6:49 AM
To: [email protected]
Cc: Gu, Mingkun
Subject: Helps: how to use i801--SMBus functions via i2c-dev module in Linux?

Dear Sir,

I am new to Linux and Device driver programming. I am trying to write a device driver software module to access the ICH6 SMBus controller on the motherboard of our PC running Linux 2.6.10 kernel. I configured my 2.6.10 kernel to have I2C built-in support and your i801 module loaded. Then I loaded the i2c-dev interface module and wrote a short application software to test the functions for SMBus. After my application opened the /dev/i2c device, I received messages saying "i2c-adaptor: i2c-0 -- I2C level transfer not support" when my application software called the read and write function of the i2c-dev module. Further tracking inside the i2c-dev module shew that the algorithm parameter adap->algo->master_xfer = NULL. That means the i801 driver was not properly loaded by the i2c-dev module.

Could you advise how I can make use of the i801 module and your i2c-dev module to access the ICH6 SMBus controller?

Thanks a lot in advance.

Michael Gu

_____

Find your next car at Yahoo! Canada Autos <http://autos.yahoo.ca>

-----------------------------------------
This email may contain confidential and privileged material for the sole use of the intended recipient(s). Any review, use, retention, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. Also, email is susceptible to data corruption, interception, tampering, unauthorized amendment and viruses. We only send and receive emails on the basis that we are not liable for any such corruption, interception, tampering, amendment or viruses or any consequence thereof.

#3 lore raw

[lm-sensors] RE: Helps: how to use i801--SMBus functions via

In reply to MK GU
Quoted 7 lines · Mingkun

Could anyone advise how I can make use i2c-i801 and/or i2c-dev to access ICH6 SMBus controller on a PC motherboard? I have Linux 2.6.10 and loaded i2c-core, i2c-i801and i2c-dev modules. lsmod command gave me the following info:

It seems that i2c-i801 is not used by other modules.

This is OK.

If I understand it correctly all you want is to create the _userspace_ program that will send commands to the specific device on the bus. If so please have a look to linux-2.6.x/Documentation/i2c/dev-interface

Further example could be found in lm-sensors package.
i2cdump.c i2cset.c etc...

I hope this helps,

Regards
Rudolf

#4 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Jean,

With i2c-dev module, is it possible to have more than one device with the same major number and different minor numbers? Let say, if I want to have

/dev/i2c/0 89 0
/dev/i2c/1 89 1
/dev/i2c/2 89 2
......

How can I do it? I tried to insmod the i2c-dev module twice and got error message say "-1 File exists."

One more thing is whether this module provides the ability to handle interrupts?

Thanks.
MK

-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Saturday, November 05, 2005 6:11 PM
To: Gu, Mingkun
Cc: [email protected]
Subject: Re: [lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev module in Linux?

Hi Michael,

Quoted 1 line

After successfully opened /dev/i2c/0 and set

ioctl(file,I2C_SLAVE,addr)

Quoted 4 lines

with addr = 0x40, I received error messages as follows when calling write() and read() functions

i2c_adapter i2c-0: I2C level transfers not supported

I already told you it wouldn't work. The Intel i82801 is an SMBus master, you cannot send or receive arbitrary I2C messages with it (and this is what write() and read() do). You have to use the SMBus interface.

Quoted 1 line

The return value for the second call to ioctl(file, cmd, &data_arg)

was

Quoted 2 lines

-1, which indicated the functions failed when making a call to i2c_smbus_xfer() within ioctl() of i2c-dev.c.

What you tried to do is needlessly complex. Use the wrapper functions from i2c-dev.h instead.

Quoted 7 lines

c) I also tried to use the function i2c_smbus_read_word_data() in the above program. But I got compiling error say i2c_smbus_read_word_data undefined. It seems the function was not in my i2c.h file or i2c-dev.file.

Could you advise how I can get the above program access the SMBus correctly?

You need i2c-dev.h from the lm_sensors package, not from the kernel sources.

http://www2.lm-sensors.nu/~lm78/cvs/lm_sensors2/kernel/include/i2c-dev.h

Signature · 13 lines
Jean Delvare

-----------------------------------------
This email may contain confidential and privileged material for the
sole use of the intended recipient(s). Any review, use, retention,
distribution or disclosure by others is strictly prohibited. If you are
not the intended recipient (or authorized to receive for the
recipient), please contact the sender by reply email and delete all
copies of this message. Also, email is susceptible to data corruption,
interception, tampering, unauthorized amendment and viruses. We only
send and receive emails on the basis that we are not liable for any
such corruption, interception, tampering, amendment or viruses or any
consequence thereof.
#5 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Michael,

Quoted 8 lines · Mingkun Gu

With i2c-dev module, is it possible to have more than one device with the same major number and different minor numbers? Let say, if I want to have

/dev/i2c/0 89 0
/dev/i2c/1 89 1
/dev/i2c/2 89 2
......

Yes, it is possible.

Quoted 2 lines

How can I do it? I tried to insmod the i2c-dev module twice and got error message say "-1 File exists."

The function of i2c-dev is to give userspace an access to existing i2c busses. It doesn't create anything per se. If the only I2C/SMBus you have on your system is the i2c-i801, you'll only have /dev/i2c/0.

Note that it is OK to open the same device file twice, if you need to do that. Both sessions will be independant. You need to do that if there are several chips on the bus and you want to drive them all from userspace.

Quoted 2 lines

One more thing is whether this module provides the ability to handle interrupts?

The question isn't relevant for i2c-dev, as it doesn't actually drive the hardware. It only acts as a bridge.

As for i2c-i801, no, it is poll-based, not interrupt-based. Mark Hoffman had attempted to convert the driver to interrupt-based, but never completed the work.

--
Jean Delvare

#6 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Jean,

Thank you for your prompt reply. I am working on a project where a customized board sitting on the PCI slot. The board has a SMBus microcontroller which is used to control some external sensors and communicates with the ICH6 SMBus master controller on the host PC motherboard. I need to send SMBus request command packets to the microcontroller and receive SMBus response data packets from the micro which also generates an interrupt sometimes to request for immediate or urgent services.

Do you have any suggestion on how to implement such an application?

Thanks.
MK

-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Monday, November 07, 2005 10:39 AM
To: Gu, Mingkun
Cc: [email protected]
Subject: RE: [lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev module in Linux?

Hi Michael,

Quoted 2 lines · Mingkun Gu

With i2c-dev module, is it possible to have more than one device with the same major number and different minor numbers? Let say, if I want

to

Quoted 6 lines

have

/dev/i2c/0 89 0
/dev/i2c/1 89 1
/dev/i2c/2 89 2
......

Yes, it is possible.

Quoted 2 lines

How can I do it? I tried to insmod the i2c-dev module twice and got error message say "-1 File exists."

The function of i2c-dev is to give userspace an access to existing i2c busses. It doesn't create anything per se. If the only I2C/SMBus you have on your system is the i2c-i801, you'll only have /dev/i2c/0.

Note that it is OK to open the same device file twice, if you need to do that. Both sessions will be independant. You need to do that if there are several chips on the bus and you want to drive them all from userspace.

Quoted 2 lines

One more thing is whether this module provides the ability to handle interrupts?

The question isn't relevant for i2c-dev, as it doesn't actually drive the hardware. It only acts as a bridge.

As for i2c-i801, no, it is poll-based, not interrupt-based. Mark Hoffman had attempted to convert the driver to interrupt-based, but never completed the work.

--
Jean Delvare

-----------------------------------------
This email may contain confidential and privileged material for the sole use of the intended recipient(s). Any review, use, retention, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. Also, email is susceptible to data corruption, interception, tampering, unauthorized amendment and viruses. We only send and receive emails on the basis that we are not liable for any such corruption, interception, tampering, amendment or viruses or any consequence thereof.

#7 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Michael,

Quoted 10 lines · Mingkun Gu

Thank you for your prompt reply. I am working on a project where a customized board sitting on the PCI slot. The board has a SMBus microcontroller which is used to control some external sensors and communicates with the ICH6 SMBus master controller on the host PC motherboard. I need to send SMBus request command packets to the microcontroller and receive SMBus response data packets from the micro which also generates an interrupt sometimes to request for immediate or urgent services.

Do you have any suggestion on how to implement such an application?

For one thing, if you are dealing with events which require fast reactions, it might be wiser to write a kernel driver than a user-space application.

Second, as I said, the current i2c-i801 driver is not interrupt based. If you need it to react fast, you will need to rewrite it in part to use interrupts. If you do, you should get in touch with Mark M. Hoffman who has been working on this some times ago.

The details depend on the exact hardware implementation. I have to admit I am not really qualified to comment on interrupts, as I never had to deal with these so far. Please note that the i2c core in Linux doesn't support slave mode on masters at the moment. If this is something your system needs, this will be a (serious) problem.

--
Jean Delvare

#8 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Jean,

Thank you for the advices. I've also tried to write/read block data to/from the ICH6 SMBus but failed to receive successful returns. I did tried other commands. I received successful returns for I2C_SMBUS_QUICK, I2C_SMBUS_BYTE-DATA (read/write) and I2C_SMBUS_WORD_DATA (read), and unsuccessful returns (-1) for I2C_SMBUS_WORD_DATA (write) and I2C_SMBUS_BLOCK_DATA (read/write)
when calling the ioctl function of the i2c-dev module.

Any comments and advices?

Thanks.
MK

-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Monday, November 07, 2005 11:18 AM
To: Gu, Mingkun
Cc: [email protected]; Mark M. Hoffman
Subject: RE: [lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev module in Linux?

Hi Michael,

Quoted 7 lines · Mingkun Gu

Thank you for your prompt reply. I am working on a project where a customized board sitting on the PCI slot. The board has a SMBus microcontroller which is used to control some external sensors and communicates with the ICH6 SMBus master controller on the host PC motherboard. I need to send SMBus request command packets to the microcontroller and receive SMBus response data packets from the micro which also generates an interrupt sometimes to request for immediate

or

Quoted 3 lines

urgent services.

Do you have any suggestion on how to implement such an application?

For one thing, if you are dealing with events which require fast reactions, it might be wiser to write a kernel driver than a user-space application.

Second, as I said, the current i2c-i801 driver is not interrupt based. If
you need it to react fast, you will need to rewrite it in part to use interrupts. If you do, you should get in touch with Mark M. Hoffman who has been working on this some times ago.

The details depend on the exact hardware implementation. I have to admit I am not really qualified to comment on interrupts, as I never had to deal with these so far. Please note that the i2c core in Linux doesn't support slave mode on masters at the moment. If this is something your system needs, this will be a (serious) problem.

--
Jean Delvare

-----------------------------------------
This email may contain confidential and privileged material for the sole use of the intended recipient(s). Any review, use, retention, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. Also, email is susceptible to data corruption, interception, tampering, unauthorized amendment and viruses. We only send and receive emails on the basis that we are not liable for any such corruption, interception, tampering, amendment or viruses or any consequence thereof.

#9 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Michael,

Quoted 9 lines · Mingkun Gu

Thank you for the advices. I've also tried to write/read block data to/from the ICH6 SMBus but failed to receive successful returns. I did tried other commands. I received successful returns for I2C_SMBUS_QUICK, I2C_SMBUS_BYTE-DATA (read/write) and I2C_SMBUS_WORD_DATA (read), and unsuccessful returns (-1) for I2C_SMBUS_WORD_DATA (write) and I2C_SMBUS_BLOCK_DATA (read/write)
when calling the ioctl function of the i2c-dev module.

Any comments and advices?

Does your client chip actually support all these transaction types?

An SMBus transaction will only work if the target chip does expect that transaction type for the given "command" byte. If not, the chip will not ACK all the bytes or will stop sending data, causing the transaction to fail.

You may want to read the SMBus specification for clarifications on what each transaction does. You should not try random transactions. Only use the transaction types your client chip expects for each command. These should be documented.

--
Jean Delvare

#10 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Jean,

I am actually accessing the master ICH6 SMBus controller's registers and memory instead of the slave control on the customized board. According to the data sheet of ICH6, it supports block data transfer.

Best Rgds
MK

-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Monday, November 07, 2005 11:51 AM
To: Gu, Mingkun
Cc: LM Sensors
Subject: RE: [lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev module in Linux?

Hi Michael,

Quoted 3 lines · Mingkun Gu

Thank you for the advices. I've also tried to write/read block data to/from the ICH6 SMBus but failed to receive successful returns. I did tried other commands. I received successful returns for

I2C_SMBUS_QUICK,

Quoted 6 lines

I2C_SMBUS_BYTE-DATA (read/write) and I2C_SMBUS_WORD_DATA (read), and unsuccessful returns (-1) for I2C_SMBUS_WORD_DATA (write) and I2C_SMBUS_BLOCK_DATA (read/write)
when calling the ioctl function of the i2c-dev module.

Any comments and advices?

Does your client chip actually support all these transaction types?

An SMBus transaction will only work if the target chip does expect that transaction type for the given "command" byte. If not, the chip will not ACK all the bytes or will stop sending data, causing the transaction to fail.

You may want to read the SMBus specification for clarifications on what each transaction does. You should not try random transactions. Only use the transaction types your client chip expects for each command. These should be documented.

--
Jean Delvare

-----------------------------------------
This email may contain confidential and privileged material for the sole use of the intended recipient(s). Any review, use, retention, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. Also, email is susceptible to data corruption, interception, tampering, unauthorized amendment and viruses. We only send and receive emails on the basis that we are not liable for any such corruption, interception, tampering, amendment or viruses or any consequence thereof.

#11 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Michael,

Quoted 3 lines

I am actually accessing the master ICH6 SMBus controller's registers and memory instead of the slave control on the customized board. According to the data sheet of ICH6, it supports block data transfer.

Sure it does, that's not the point. The question is, is the slave device you are talking to expecting an SMBus block transfer for the command byte you are using? As I already said, SMBus transactions only work if the master and client agree on the transaction type. If you are trying random block reads/writes, no wonder it doesn't work.

That being said, SMBus block transactions are rarely used, so we can't exclude some bug for them in some of our drivers.

Signature · 1 line
Jean Delvare
#12 lore raw

[lm-sensors] Helps: how to use i801--SMBus functions viai2c-dev

In reply to MK GU

Hi Jean,

Quoted 1 line
Quoted 1 line

I am actually accessing the master ICH6 SMBus controller's registers

and

Quoted 1 line
Quoted 1 line

memory instead of the slave control on the customized board.

According

Quoted 6 lines
Quoted 1 line

to the data sheet of ICH6, it supports block data transfer.

Sure it does, that's not the point. The question is, is the slave device you are talking to expecting an SMBus block transfer for the command byte you are using? As I already said, SMBus transactions only work if the master and client agree on the transaction type. If you

are

Quoted 1 line

trying random block reads/writes, no wonder it doesn't work.

Yes, the slave device has a TI's MSP430 mixed signal microcontroller which supports block read and write of message/data packets for the SMBus standard protocol. I'm trying to send the command/data packets in data blocks. But our board with the microcontroller was not attached to the PC motherboard during my tests mentioned above. Would this be the cause for transaction errors?

---
MK

-----------------------------------------
This email may contain confidential and privileged material for the sole use of the intended recipient(s). Any review, use, retention, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. Also, email is susceptible to data corruption, interception, tampering, unauthorized amendment and viruses. We only send and receive emails on the basis that we are not liable for any such corruption, interception, tampering, amendment or viruses or any consequence thereof.