Skip to contentSkip to conversation

i2c-viapro and via686a don't mix with linux-2.6.0-test1

DISCUSSION Christoph Heine 3 participants 5 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

Hi,

With kernel 2.6.0-test1 (likely with lm-sensors 2.8.0 too), it is possible to load both via686a and i2c-viapro, but only one of them will work, depending on which was loaded first.

The reason for this is, that both drivers feel responsible for the VIA_82C686_4 and once the probe was successful, it is registered only to the driver which was loaded first. (So, you can load another driver for the device but the probe function will never get called).

Sorry for not providing a patch, I have on clue how to fix this properly.

Bye,
Christoph

#1 lore raw
Quoted 5 lines

With kernel 2.6.0-test1 (likely with lm-sensors 2.8.0 too), it is possible to load both via686a and i2c-viapro, but only one of them will work, depending on which was loaded first.

Quoted 7 lines

The reason for this is, that both drivers feel responsible for the VIA_82C686_4 and once the probe was successful, it is registered only to the driver which was loaded first. (So, you can load another driver for the device but the probe function will never get called).

Sorry for not providing a patch, I have on clue how to fix this properly.

I tested this case on my own system and I could load both modules, and both seemed to work (lm_sensors-2.8.0). I think I remember seeing something about that on the mailing list recently:

Modified Files:

	i2c-voodoo3.c i2c-via.c i2c-viapro.c i2c-i810.c i2c-savage4.c 

Log Message:
(mds) don't use pci_module_init() for video i2c drivers so we don't
conflict with video drivers

It was for a different conflict (it seems). However, the changes made to i2c-viapro.c may also prevent the conflict you observed. This is a very recent change (occured on July 2nd.). I attached the patch, could you please check wether it is already applied to the 2.6.0 kernel tree? If not, could you try to apply it and tell us if it solves your problem?

I admit I'm a bit confused, because i2c-viapro is a bus driver while via686a is a chip driver. Thus I wonder how they can conflict... However, the driver registering mechanisms of the Linux kernel is beyond me, so it may just be me ;)

Signature · 52 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
-------------- next part --------------
Index: i2c-viapro.c
=================================RCS file: /home/cvs/lm_sensors2/kernel/busses/i2c-viapro.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- i2c-viapro.c	10 Jun 2003 01:07:54 -0000	1.31
+++ i2c-viapro.c	3 Jul 2003 01:30:13 -0000	1.32
@@ -459,23 +459,41 @@
 	{ 0, }
 };
 
+/* Don't register driver to avoid driver conflicts */
+/*
 static struct pci_driver vt596_driver = {
 	.name		= "vt596 smbus",
 	.id_table	= vt596_ids,
 	.probe		= vt596_probe,
 	.remove		= __devexit_p(vt596_remove),
 };
+*/
 
 static int __init i2c_vt596_init(void)
 {
+	struct pci_dev *dev;
+	const struct pci_device_id *id;
+
 	printk("i2c-viapro.o version %s (%s)\n", LM_VERSION, LM_DATE);
+/*
 	return pci_module_init(&vt596_driver);
+*/
+	pci_for_each_dev(dev) {
+		id = pci_match_device(vt596_ids, dev);
+		if(id)
+			if(vt596_probe(dev, id) >= 0)
+				return 0;
+	}
+	return -ENODEV;
 }
 
 
 static void __exit i2c_vt596_exit(void)
 {
+/*
 	pci_unregister_driver(&vt596_driver);
+*/
+	vt596_remove(NULL);
 }
 
 MODULE_AUTHOR(
#2 lore raw
In reply to Christoph Heine
Quoted 10 lines · Jean Delvare

Log Message:
(mds) don't use pci_module_init() for video i2c drivers so we don't
conflict with video drivers

It was for a different conflict (it seems). However, the changes made to i2c-viapro.c may also prevent the conflict you observed. This is a very recent change (occured on July 2nd.). I attached the patch, could you please check wether it is already applied to the 2.6.0 kernel tree? If not, could you try to apply it and tell us if it solves your problem?

Quoted 4 lines

I admit I'm a bit confused, because i2c-viapro is a bus driver while via686a is a chip driver. Thus I wonder how they can conflict... However, the driver registering mechanisms of the Linux kernel is beyond me, so it may just be me ;)

No, this isn't a valid solution. The proper thing would be to put the i2c bus functions within the video driver.

The issue is that only one pci driver can bind to a device at the same time. You are working around it by grabbing the pci device that is already bound to another driver, but that way is racy, and can cause big problems (your driver will not be notified if the device goes away, like in a hotplug system.) Because of this, I'll be removing the pci_for_each_dev() functions from the kernel once 2.7 opens up, and possibly sooner if that takes a while...

thanks,

greg k-h

#3 lore raw
In reply to Christoph Heine

Hi Jean,

Quoted 5 lines · Jean Delvare

I think I remember seeing something about that on the mailing list recently:

Modified Files:

	i2c-voodoo3.c i2c-via.c i2c-viapro.c i2c-i810.c i2c-savage4.c 
Quoted 8 lines

Log Message:
(mds) don't use pci_module_init() for video i2c drivers so we don't
conflict with video drivers

It was for a different conflict (it seems). However, the changes made to i2c-viapro.c may also prevent the conflict you observed. This is a very recent change (occured on July 2nd.). I attached the patch, could you please check wether it is already applied to the 2.6.0 kernel tree?

It is not applied to the 2.6.0 tree.

Quoted 2 lines

If not, could you try to apply it and tell us if it solves your problem?

The patch did not apply to i2c-viapro.c in 2.6 at all and pci_for_each_dev() does not exist in the 2.6 kernel.

I've converted it to "the 2.6 way" of doing this and it works for me. :-) The new patch is in the Attachment. But somehow I feel this is not the right solution.

Quoted 2 lines

I admit I'm a bit confused, because i2c-viapro is a bus driver while via686a is a chip driver. Thus I wonder how they can conflict...

My guess is:

The sources look like that the via686a sensor is accessed directly via the isa bus and the module needs the pci configuration registers of the VT82C686A to get the base adress. And i2c-viapro needs just the the same device for the i2c bus of the VT82C686A.

Maybe some parts of via686a should be merged into i2c-viapro. (but I don't know much about the hardware and i2c in general to tell if that makes any sense.)

Bye,
Christoph

-------------- next part --------------

i2c-viapro.c renamed from i2c-viapro.c.orig +11 -9
@@ -454,22 +454,24 @@
 	{ 0, }
 };
 
-static struct pci_driver vt596_driver = {
-	.name		= "vt596 smbus",
-	.id_table	= vt596_ids,
-	.probe		= vt596_probe,
-	.remove		= __devexit_p(vt596_remove),
-};
-
 static int __init i2c_vt596_init(void)
 {
-	return pci_module_init(&vt596_driver);
+	struct pci_dev *dev = NULL;
+	const struct pci_device_id *id;
+	
+	while ((dev = pci_find_device(PCI_VENDOR_ID_VIA, PCI_ANY_ID, dev)) != NULL) {
+	id = pci_match_device(vt596_ids, dev);
+       		if(id)
+        		if(vt596_probe(dev, id) >= 0)
+            			return 0;
+	}
+	return -ENODEV;
 }
 
 
 static void __exit i2c_vt596_exit(void)
 {
-	pci_unregister_driver(&vt596_driver);
+	 vt596_remove(NULL);
 }
 
 MODULE_AUTHOR(
#4 lore raw
In reply to Christoph Heine

Review

Quoted 7 lines · Christoph Heine
(quoted diff) +7 -0
+	while ((dev = pci_find_device(PCI_VENDOR_ID_VIA, PCI_ANY_ID, dev)) != NULL) {
+	id = pci_match_device(vt596_ids, dev);
+       		if(id)
+        		if(vt596_probe(dev, id) >= 0)
+            			return 0;
+	}
+	return -ENODEV;

Heh, yes this is the "proper" way to do this on 2.5/2.6 to get the code to build and run, but it's not the "real" fix.

It still has the same problems that pci_for_each_dev() has (minus a few race conditions...)

thanks,

greg k-h