Skip to contentSkip to conversation

Patch for I2C + sysfs

DISCUSSION Greg KH 3 participants 7 messages May 19, 2005

lore
Share & tools
lore

Greg KH

author
#0 lore raw
Quoted 3 lines · Matthew Mastracci

This patch ensures that I2C adapter devices show up under the /sys/bus/i2c directory. Without, only I2C devices themselves will show up, breaking HAL.

Ccing the sensors list, as I should have pointed you to that in the first place, sorry.

i2c/i2c-core.c 2004-01-08 20:47:22.000000000 -0700 line 148

Quoted 9 lines
i2c/i2c-core.c 2004-01-08 20:47:22.000000000 -0700 renamed from i2c/i2c-core.c~ 2004-01-08 20:47:05.000000000 -0700 +1 -0
@@ -143,6 +143,7 @@
        sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
        adap->dev.driver = &i2c_adapter_driver;
        adap->dev.release = &i2c_adapter_dev_release;
+       adap->dev.bus = &i2c_bus_type;
        device_register(&adap->dev);
        device_create_file(&adap->dev, &dev_attr_name);

But adapters are not on the i2c bus. They are the "root" of the i2c bus. I2C adapters live as devices on other busses (PCI, platform, etc.)

What exactly is the problem that HAL can't see the devices in the place where they are in the sysfs tree?

thanks,

greg k-h

#1 lore raw
Quoted 4 lines · Greg KH

But i2c adapters _are not_ on the i2c bus. They are the "bridge device" between say the PCI bus and the i2c bus. They are really just a PCI device, and so that's where they are in the tree.

Ok, so they are exactly like PCI devices of class 12, subclass 3 (USB serial controller) as seen in this screenshot

http://freedesktop.org/~david/hal-pci-usb.png

right? (except of course they bridge PCI with i2c instead of USB)

Many thanks,
David

author
#2 lore raw
In reply to Greg KH
Quoted 8 lines · Matthew Mastracci

This patch names the subclients of the w83781d with
unique names to support the I2C device in HAL. I2C devices need to have unique names since there are no other unique identifiers.

--- drivers/i2c/chips/w83781d.c.orig 2004-01-08 23:31:54.296510000
-0700
+++ drivers/i2c/chips/w83781d.c 2004-01-08 23:25:57.616510000 -0700

Review line 1141

Quoted 10 lines
(quoted diff) +2 -2
@@ -1134,8 +1134,8 @@
                data->lm75[i]->adapter = adapter;
                data->lm75[i]->driver = &w83781d_driver;
                data->lm75[i]->flags = 0;
-               strlcpy(data->lm75[i]->name, client_name,
-                       I2C_NAME_SIZE);
+               snprintf(data->lm75[i]->name, I2C_NAME_SIZE, "%s %d",
+                       client_name, i);
                if ((err = i2c_attach_client(data->lm75[i]))) {
                        dev_err(&new_client->dev, "Subclient %d "
                                "registration at address 0x%x "

No, their path in sysfs is a "unique identifier". They can have the same "name" but be in different places, right? Can you show me a sysfs tree that has a problem that this patch fixes?

thanks,

greg k-h

author
#3 lore raw
In reply to Greg KH
Quoted 5 lines · Matthew Mastracci
Quoted 2 lines

But adapters are not on the i2c bus. They are the "root" of the i2c bus. I2C adapters live as devices on other busses (PCI, platform, etc.)

I'm modelling this after the usb sysfs entry. The usb adapters themselves appear in /sys/bus/usb/devices:

That is because those "usbX" devices _are_ real USB devices. They are the USB root hub, which lives in the silicon inside the USB controller. The kernel sees them as a real USB device, and they talk USB to the kernel.

I2C adapters are not like that.

Quoted 6 lines
Quoted 2 lines

What exactly is the problem that HAL can't see the devices in the place where they are in the sysfs tree?

Without this patch, the device only appears in two places:

* under the class directory with class "i2c-adapter", and

This is why that class directory was created. In order that userspace can find all of the i2c adapters.

Quoted 7 lines

* under the root devices tree in its respective pci path.

If you contrast this with the usb controllers, they appear in three places:

* under the class directory with class "usb_host",
* under the root devices tree in its repective pci path, and
* under the /sys/bus/usb directory

Again, the USB root hubs are a different type of device, you can't compare the two, sorry.

Quoted 9 lines

HAL uses libsysfs, which parses the contents of the various bus/ directories to determine the appropriate bus for the given subdevices beneath each device. It assumes that for each valid device directory directory in the /sys/devices/ tree, there is an entry in one of the bus directories.

Since the I2C-n directories don't appear in any of the bus directories, libsysfs can only print "unknown" bus for them and they can't be appropriately placed within the HAL tree.

But i2c adapters _are not_ on the i2c bus. They are the "bridge device" between say the PCI bus and the i2c bus. They are really just a PCI device, and so that's where they are in the tree.

Quoted 2 lines

I had assumed that since the I2C adapters are similar in function to the usb_host devices, they should appear in the same place.

Nope, apples and oranges.

Quoted 2 lines

If this is not the case, should the usb hosts be under the PCI bus tree as well? In that case, should the I2C adapters be there too?

USB hosts do show up in /sys/class/usb_hosts/ just like the i2c adapters do :)

Hope this helps,

greg k-h

author
#4 lore raw
In reply to Greg KH
Quoted 6 lines · David Zeuthen
Quoted 4 lines · Greg KH

But i2c adapters _are not_ on the i2c bus. They are the "bridge device" between say the PCI bus and the i2c bus. They are really just a PCI device, and so that's where they are in the tree.

Quoted 6 lines

Ok, so they are exactly like PCI devices of class 12, subclass 3 (USB serial controller) as seen in this screenshot

http://freedesktop.org/~david/hal-pci-usb.png

right? (except of course they bridge PCI with i2c instead of USB)

Exactly. But for USB, we have an extra device, the USB root hub (usbX in sysfs).

Hope this helps,

greg k-h

#5 lore raw
In reply to Greg KH

Greg KH wrote:

Thanks for the response, Greg. I've CC'd David Zeuthen of HAL on this one, perhaps to provide more input.

Quoted 9 lines
Quoted 3 lines

This patch ensures that I2C adapter devices show up under the /sys/bus/i2c directory. Without, only I2C devices themselves will show up, breaking HAL.

Ccing the sensors list, as I should have pointed you to that in the first place, sorry.

Quoted 13 lines

i2c/i2c-core.c 2004-01-08 20:47:22.000000000 -0700 line 148

Quoted 9 lines
i2c/i2c-core.c 2004-01-08 20:47:22.000000000 -0700 renamed from i2c/i2c-core.c~ 2004-01-08 20:47:05.000000000 -0700 +1 -0
@@ -143,6 +143,7 @@
       sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
       adap->dev.driver = &i2c_adapter_driver;
       adap->dev.release = &i2c_adapter_dev_release;
+       adap->dev.bus = &i2c_bus_type;
       device_register(&adap->dev);
       device_create_file(&adap->dev, &dev_attr_name);

But adapters are not on the i2c bus. They are the "root" of the i2c bus. I2C adapters live as devices on other busses (PCI, platform, etc.)

I'm modelling this after the usb sysfs entry. The usb adapters themselves appear in /sys/bus/usb/devices:

[ truncated ls -l ]
lrwxrwxrwx 1 root root 53 Jan 8 20:33 3-0:1.0 ->
./../../devices/pci0000:00/0000:00:02.1/usb3/3-0:1.0
lrwxrwxrwx 1 root root 45 Jan 8 20:33 usb1 ->
./../../devices/pci0000:00/0000:00:02.2/usb1
lrwxrwxrwx 1 root root 45 Jan 8 20:33 usb2 ->
./../../devices/pci0000:00/0000:00:02.0/usb2
lrwxrwxrwx 1 root root 45 Jan 8 20:33 usb3 ->
./../../devices/pci0000:00/0000:00:02.1/usb3 [matthew@matt devices]$ cat usb1/product EHCI Host Controller

Quoted 3 lines

What exactly is the problem that HAL can't see the devices in the place where they are in the sysfs tree?

Without this patch, the device only appears in two places:

* under the class directory with class "i2c-adapter", and
* under the root devices tree in its respective pci path.

If you contrast this with the usb controllers, they appear in three places:

* under the class directory with class "usb_host",
* under the root devices tree in its repective pci path, and
* under the /sys/bus/usb directory

HAL uses libsysfs, which parses the contents of the various bus/ directories to determine the appropriate bus for the given subdevices beneath each device. It assumes that for each valid device directory directory in the /sys/devices/ tree, there is an entry in one of the bus directories.

Since the I2C-n directories don't appear in any of the bus directories, libsysfs can only print "unknown" bus for them and they can't be appropriately placed within the HAL tree.

I had assumed that since the I2C adapters are similar in function to the usb_host devices, they should appear in the same place.

If this is not the case, should the usb hosts be under the PCI bus tree as well? In that case, should the I2C adapters be there too?

Quoted 5 lines

thanks,

greg k-h

No prob. Thanks for the feedback!

Matt.

#6 lore raw
In reply to Greg KH
Quoted 2 lines · Greg KH

This is why that class directory was created. In order that userspace can find all of the i2c adapters.

Okay, good explaination. Sorry to bother you with this question - I have a better understanding of what the /sys/bus directory is for. :)

In fact, on further examination, i2c-adapter class devices are similar to scsi_host class devices. scsi_hosts don't appear on the scsi bus - only scsi_devices do.

Thanks for your time,
Matt.