Skip to contentSkip to conversation

Add i2c-viapro.c

PATCH In review Kronos 2 participants 4 messages Apr 11, 2003

Subsystems (2)
lore
Share & tools
lore

Kronos

author
#0 lore raw

PATCH 1/1 Add i2c-viapro.c

Hi,
the following patch (against 2.5.67) adds support for the SMBus bus on VIA motherboard based of 82C596, 82C686 and 823x. It is needed, for example, for the eeprom driver and for w83781d. I've tested it on a 8233 chipset. Comments and feedback are welcome.

drivers/i2c/busses/Kconfig +26 -0
diff -urN -X dontdiff linux-2.5.vanilla/drivers/i2c/busses/Kconfig linux-2.5.i2c/drivers/i2c/busses/Kconfig
@@ -116,5 +116,31 @@
 	  in the lm_sensors package, which you can download at 
 	  http://www.lm-sensors.nu
 
+
+config I2C_VIAPRO
+	tristate "  VIA 82C596/82C686/823x"
+	depends on I2C && PCI && EXPERIMENTAL
+	help
+
+	  If you say yes to this option, support will be included for the VIA
+	  82C596/82C686/823x I2C interfaces.  Specifically, the following 
+	  chipsets are supported:
+	  82C596A/B
+	  82C686A/B
+	  8231
+	  8233
+	  8233A
+	  8235
+
+	  This can also be built as a module which can be inserted and removed
+	  while the kernel is running.  If you want to compile it as a module,
+	  say M here and read <file:Documentation/modules.txt>.
+
+	  The module will be called i2c-viapro.
+
+	  You will also need the latest user-space utilties: you can find them
+	  in the lm_sensors package, which you can download at
+	  http://www.lm-sensors.nu
+
 endmenu
 
drivers/i2c/busses/Makefile +1 -0
diff -urN -X dontdiff linux-2.5.vanilla/drivers/i2c/busses/Makefile linux-2.5.i2c/drivers/i2c/busses/Makefile
@@ -8,3 +8,4 @@
 obj-$(CONFIG_I2C_I801)		+= i2c-i801.o
 obj-$(CONFIG_I2C_ISA)		+= i2c-isa.o
 obj-$(CONFIG_I2C_PIIX4)		+= i2c-piix4.o
+obj-$(CONFIG_I2C_VIAPRO)	+= i2c-viapro.o
drivers/i2c/busses/i2c-viapro.c +536 -0

536 lines not on this page · raw message

Luca

Signature · 3 lines
Reply-To: [email protected]
Home: http://kronoz.cjb.net
Windows NT: Designed for the Internet. The Internet: Designed for Unix.
#1 lore raw
Quoted 5 lines · Kronos

Hi,
the following patch (against 2.5.67) adds support for the SMBus bus on VIA motherboard based of 82C596, 82C686 and 823x. It is needed, for example, for the eeprom driver and for w83781d. I've tested it on a 8233 chipset. Comments and feedback are welcome.

Looks good, with a few minor things that I can see:

drivers/i2c/busses/i2c-viapro.c line 136

Quoted 2 lines
drivers/i2c/busses/i2c-viapro.c +2 -0
+/* Detect whether a compatible device can be found, and initialize it. */
+int vt596_setup(void)

This function should take a struct pci_dev * as a paramater, that way we don't have to do:

Quoted 4 lines
drivers/i2c/busses/i2c-viapro.c +4 -0
+	/* First check whether we can access PCI at all */
+	if (pci_present() == 0)
+		return(-ENODEV);
+

drivers/i2c/busses/i2c-viapro.c line 155

Quoted 10 lines
drivers/i2c/busses/i2c-viapro.c +10 -0
+	/* Look for a supported device/function */
+	do {
+		if((VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA, num->dev,
+					        VT596_dev)))
+			break;
+	} while ((++num)->dev);
+
+	if (VT596_dev == NULL)
+		return(-ENODEV);
+	dev_info("Found Via %s device\n", num->name);

All of this is not necessary, as the pci core will give is a proper pointer to a device that is in the pci device list that is passed to it.

drivers/i2c/busses/i2c-viapro.c line 232

Quoted 13 lines
drivers/i2c/busses/i2c-viapro.c +13 -0
+#ifdef DEBUG
+	if ((temp & 0x0E) == 8)
+		dev_info(&VT596_dev->dev, "using Interrupt 9 for SMBus.\n");
+	else if ((temp & 0x0E) == 0)
+		dev_info(&VT596_dev->dev, "using Interrupt SMI# for SMBus.\n");
+	else
+		dev_warn(&VT596_dev->dev, "Illegal Interrupt configuration "
+			"(or code out of date)!\n");
+
+	pci_read_config_byte(VT596_dev, SMBREV, &temp);
+	dev_info(&VT596_dev->dev, "SMBREV = 0x%X\n", temp);
+	dev_info(&VT596_dev->dev, "VT596_smba = 0x%X\n", vt596_smba);
+#endif	/* DEBUG */

You can drop the #ifdef and change the dev_info() and dev_warn() calls here to dev_dbg().

drivers/i2c/busses/i2c-viapro.c line 489

Quoted 5 lines
drivers/i2c/busses/i2c-viapro.c +5 -0
+static int __devinit vt596_probe(struct pci_dev *dev, const struct pci_device_id *id)
+{
+	int retval;
+
+	retval = vt596_setup();

Here's where we can just pass the dev paramater to the function.

Other than those minor things, it looks very good. Almost ready to add to the tree.

thanks,

greg k-h

author
#2 lore raw

Il Fri, Apr 11, 2003 at 12:54:15PM -0700, Greg KH ha scritto:

Quoted 15 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+/* Detect whether a compatible device can be found, and initialize it. */
+int vt596_setup(void)

This function should take a struct pci_dev * as a paramater, that way we don't have to do:

Quoted 9 lines
(quoted diff) +9 -0
+	/* First check whether we can access PCI at all */
+	if (pci_present() == 0)
+		return(-ENODEV);
+
+	/* Look for a supported device/function */
+	do {
+		if((VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA, num->dev,
+					        VT596_dev)))
+			break;
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+	} while ((++num)->dev);
+
+	if (VT596_dev == NULL)
+		return(-ENODEV);
+	dev_info("Found Via %s device\n", num->name);

All of this is not necessary, as the pci core will give is a proper pointer to a device that is in the pci device list that is passed to it.

Ok. I deleted the array of struct sd (supported devices) and moved the base field into pci_device_id->driver_data, sd.hstcfg was always 0xD2 so I defaulted the static variable smb_cf_hstcfg to this value. It still works ;)

Quoted 17 lines
Quoted 4 lines
(quoted diff) +3 -0
+#ifdef DEBUG
+	if ((temp & 0x0E) == 8)
+		dev_info(&VT596_dev->dev, "using Interrupt 9 for SMBus.\n");

Review

Quoted 10 lines
(quoted diff) +10 -0
+	else if ((temp & 0x0E) == 0)
+		dev_info(&VT596_dev->dev, "using Interrupt SMI# for SMBus.\n");
+	else
+		dev_warn(&VT596_dev->dev, "Illegal Interrupt configuration "
+			"(or code out of date)!\n");
+
+	pci_read_config_byte(VT596_dev, SMBREV, &temp);
+	dev_info(&VT596_dev->dev, "SMBREV = 0x%X\n", temp);
+	dev_info(&VT596_dev->dev, "VT596_smba = 0x%X\n", vt596_smba);
+#endif	/* DEBUG */

You can drop the #ifdef and change the dev_info() and dev_warn() calls here to dev_dbg().

Done.

Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static int __devinit vt596_probe(struct pci_dev *dev, const struct pci_device_id *id)
+{
+	int retval;
+
+	retval = vt596_setup();

Here's where we can just pass the dev paramater to the function.

Ok, done. But now vt596_setup needs also the pci_device_id, maybe I should merge vt596_probe and vt596_setup.

drivers/i2c/busses/Kconfig +26 -0
diff -urN -X dontdiff linux-2.5.vanilla/drivers/i2c/busses/Kconfig linux-2.5.i2c/drivers/i2c/busses/Kconfig
@@ -116,5 +116,31 @@
 	  in the lm_sensors package, which you can download at 
 	  http://www.lm-sensors.nu
 
+
+config I2C_VIAPRO
+	tristate "  VIA 82C596/82C686/823x"
+	depends on I2C && PCI && EXPERIMENTAL
+	help
+
+	  If you say yes to this option, support will be included for the VIA
+	  82C596/82C686/823x I2C interfaces.  Specifically, the following 
+	  chipsets are supported:
+	  82C596A/B
+	  82C686A/B
+	  8231
+	  8233
+	  8233A
+	  8235
+
+	  This can also be built as a module which can be inserted and removed
+	  while the kernel is running.  If you want to compile it as a module,
+	  say M here and read <file:Documentation/modules.txt>.
+
+	  The module will be called i2c-viapro.
+
+	  You will also need the latest user-space utilties: you can find them
+	  in the lm_sensors package, which you can download at
+	  http://www.lm-sensors.nu
+
 endmenu
 
drivers/i2c/busses/Makefile +1 -0
diff -urN -X dontdiff linux-2.5.vanilla/drivers/i2c/busses/Makefile linux-2.5.i2c/drivers/i2c/busses/Makefile
@@ -8,3 +8,4 @@
 obj-$(CONFIG_I2C_I801)		+= i2c-i801.o
 obj-$(CONFIG_I2C_ISA)		+= i2c-isa.o
 obj-$(CONFIG_I2C_PIIX4)		+= i2c-piix4.o
+obj-$(CONFIG_I2C_VIAPRO)	+= i2c-viapro.o
drivers/i2c/busses/i2c-viapro.c +504 -0

504 lines not on this page · raw message

Luca

Signature · 4 lines
Reply-To: [email protected]
Home: http://kronoz.cjb.net
"It is more complicated than you think"
                -- The Eighth Networking Truth from RFC 1925
#3 lore raw
Quoted 4 lines

Ok. I deleted the array of struct sd (supported devices) and moved the base field into pci_device_id->driver_data, sd.hstcfg was always 0xD2 so I defaulted the static variable smb_cf_hstcfg to this value. It still works ;)

Looks good, I've applied this and will send it out.

thanks,

greg k-h