Skip to contentSkip to conversation

NCLV-D SMBus - proposal to a solution

DISCUSSION Rudolf Marek 4 participants 6 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

Hello,

Here I would like to propose some solution and "to be done" list to asus board types.

1) Patch to kernel that adds io region allocation for ICH4 in /proc/ioports

2) Some kind of multiplexing bus driver that will allow us to "see" both of memory EEPROMs and monitoring chip.

3) Some other ASUS server boards considerations.

Ad 1)
Remember we could not see the region in /proc/ioports for GPIO ports? I will create the patch that will fix this. (It is just one line to quirks.c)

Ad 2)
Thank you for information there are very helpful. We agreed with Jean that most clean solution to a problem would be a "multiplexing bus driver" (users can use until this is done the isaset trick). As you might noticed the multiplexer just switches the intel SMBus host between four busses. We are interrested in bus 0 and bus 1. One is with SPD EEPROMs and second contain 792 chip. We have already similar driver in kernel for this that is called i2c-amd756-s4882.c.

Your driver will be very similar except that the multiplexer itself is not on the smbus but you need to do same trick as with isaset command. Generally you would need to register the PCI device to your multiplexing driver, get the GPIO base addr (same as my hide and seek patch) and switch it to 0x0 or 0x08 when you have request from bus 0 or bus 1...

How is the multiplexed bus concept working:

It creates more busses from i2c core point of view. When there is some request to read or write from a driver it will go to this virtual bus driver, this driver will switch the bus and call the original driver. So it just create handlers for "xfer" function that is the transmission function.

When it is done you will have more virtual busses.

modprobe i2c-i801
modprobe your multiplex driver

so if you will do
i2cdetect 0
It will switch the multiplexer and you will see only SPD eeproms here if you will do:
i2cdetect 1
You will see addresses with 792 chip.

Later you just modprobe eeprom and modprobe w83792 and all will work as expected . You will see in sensors command both eeproms and chip data.

The existing driver has 200 lines and I guess yours would have like 300 so it is not so difficult to write it. Unfortunalely I'm quite busy these days and Jean has a lot of work too so I cant write it for you but of course I will help you.

Ad 3)
Maybe it will be wise to check if other asus motherboards are done same way so we can extend this concept to more motherboards with winbond chips. We have already a user with 792 chip on ASUS mb but also hidden. His board is ASUS NCL-DS. Please can you ask Asus, about this motherboard? (similar way we did this time, also great would be the SMBUS schematics)

Maybe you should extend the question like: What ASUS motherboards that use our chips needs multiplexer switching? How this switch needs to be done?

Because I think they will use similar approach so than it would be very easy to add the functionality or create diffrent driver very quickly.

I also would like to hear comments from others if any.

Regards

Rudolf

#1 lore raw

Hi Mark,

Quoted 3 lines

This is a good time to bring up the i2c-virtual driver as an alternative to the -s4882.c style of multiplexing driver. I believe this is a cleaner and more general approach to bus multiplexing.

I agree it is more general, and possibly cleaner as a result. However, it will fail to be as flexible as the s4882 style approach.

The S4882 has 8 busses, 2 for each CPU. The 2 busses of each CPU are "compatible" (no common address) so I merged them, which results in better performance (less switching required) and lower memory footprint. I don't think you'll be able to do that with the i2c-virtual approach.

In the NCLV-D case, it has 4 different bus lines, but we only really want to handle 2. How can you do that with i2c-virtual?

Also, I think I remember that i2c-virtual somehow assumes that the multiplexer itself is an i2c chip, right? This is not the case for the NCLV-D.

Additionally I don't much like the change that was required to i2c-core. Exporting non-locking versions of core functions for the use of one single driver makes very little sense. I'd rather merge a part of i2c-virtual into i2c-core if that's what it takes.

Quoted 5 lines

The i2c-virtual driver is checked in to sensors but the small changes required to i2c-core.c are not checked in. I held off late last year because 2.9.0 was coming out soon. Now that 2.9.1 is out it's time to look at it again. I have to rework the i2c-core changes because they conflicted with other recent changes to i2c-core.

Yeah, I remember that.

The more I think of it, the more obvious it is that such a change doesn't belong to the 2.4 kernel, but 2.6. I do not want any more changes to the i2c subsystem of Linux 2.4 (except for bug fixes and documentation updates, of course). It's more than time to move the development effort to 2.6, and only do support on 2.4.

Quoted 1 line

attached are the proposed changes to i2c-core for comment.

Eerk. By brain doesn't read non-unified patches very well, sorry.

Signature · 1 line
Jean Delvare
#2 lore raw
In reply to Rudolf Marek
Quoted 41 lines · Rudolf Marek

Hello,

2) Some kind of multiplexing bus driver that will allow us to "see" both of memory EEPROMs and monitoring chip.

Ad 2)
Thank you for information there are very helpful. We agreed with Jean that most clean solution to a problem would be a "multiplexing bus driver" (users can use until this is done the isaset trick). As you might noticed the multiplexer just switches the intel SMBus host between four busses. We are interrested in bus 0 and bus 1. One is with SPD EEPROMs and second contain 792 chip. We have already similar driver in kernel for this that is called i2c-amd756-s4882.c.

Your driver will be very similar except that the multiplexer itself is not on the smbus but you need to do same trick as with isaset command. Generally you would need to register the PCI device to your multiplexing driver, get the GPIO base addr (same as my hide and seek patch) and switch it to 0x0 or 0x08 when you have request from bus 0 or bus 1...

How is the multiplexed bus concept working:

It creates more busses from i2c core point of view. When there is some request to read or write from a driver it will go to this virtual bus driver, this driver will switch the bus and call the original driver. So it just create handlers for "xfer" function that is the transmission function.

When it is done you will have more virtual busses.

modprobe i2c-i801
modprobe your multiplex driver

so if you will do
i2cdetect 0
It will switch the multiplexer and you will see only SPD eeproms here if you will do:
i2cdetect 1
You will see addresses with 792 chip.

Quoted 7 lines

Later you just modprobe eeprom and modprobe w83792 and all will work as expected . You will see in sensors command both eeproms and chip data.

The existing driver has 200 lines and I guess yours would have like 300 so it is not so difficult to write it. Unfortunalely I'm quite busy these days and Jean has a lot of work too so I cant write it for you but of course I will help you.

This is a good time to bring up the i2c-virtual driver as an alternative to the -s4882.c style of multiplexing driver. I believe this is a cleaner and more general approach to bus multiplexing.

The i2c-virtual driver is checked in to sensors but the small changes required to i2c-core.c are not checked in. I held off late last year because 2.9.0 was coming out soon. Now that 2.9.1 is out it's time to look at it again.
I have to rework the i2c-core changes because they conflicted with
other recent changes to i2c-core.

attached are the proposed changes to i2c-core for comment.

mds
-------------- next part --------------
88a89,91

Quoted 3 lines

*
* i2c_add_adapter_nolock does the actual work. It is split
* out so it can be called externally by i2c-virtual.c without deadlocking.

90c93
< int i2c_add_adapter(struct i2c_adapter *adap)
---

Quoted 1 line

int i2c_add_adapter_nolock(struct i2c_adapter *adap)

94d96
< down(&core_lists);
129a132,140

Quoted 9 lines
	return res;
}

int i2c_add_adapter(struct i2c_adapter *adap)

{
	int res;

	down(&core_lists);
        res = i2c_add_adapter_nolock(adap);

130a142

Quoted 1 line

135c147,154
< int i2c_del_adapter(struct i2c_adapter *adap)
---

Quoted 8 lines

/*
* i2c_del_adapter is the corresponding function to detach all clients
* for a bus/adapter and then deregister it.
*
* i2c_del_adapter_nolock does the actual work. It is split
* out so it can be called externally by i2c-virtual.c without deadlocking. */
int i2c_del_adapter_nolock(struct i2c_adapter *adap)

139d157
< down(&core_lists);
188a207,215

Quoted 9 lines
	return res;
}

int i2c_del_adapter(struct i2c_adapter *adap)

{
	int res;

	down(&core_lists);
        res = i2c_del_adapter_nolock(adap);

189a217

Quoted 1 line

313c341,349
< for (i = 0; i < I2C_CLIENT_MAX ; i++)
---

Quoted 9 lines

#if defined(CONFIG_I2C_VIRTUAL) || defined(CONFIG_I2C_VIRTUAL_MODULE)
/* Must check for aliasing on i2c-multiplexed busses since a virt
* bus will always appear to have its own mux as an address. Without
* this check we can get infinite recursion during bus scans. */
for ( ; adapter; adapter = i2c_virt_parent(adapter))

#endif
            for (i = 0; i < I2C_CLIENT_MAX ; i++) {

316c352
<
---

Quoted 1 line
            }

1480a1517,1518

Quoted 2 lines

EXPORT_SYMBOL(i2c_add_adapter_nolock);
EXPORT_SYMBOL(i2c_del_adapter_nolock);

#3 lore raw
In reply to Rudolf Marek
Quoted 11 lines · Jean Delvare

Hi Mark,

Quoted 3 lines

This is a good time to bring up the i2c-virtual driver as an alternative to the -s4882.c style of multiplexing driver. I believe this is a cleaner and more general approach to bus multiplexing.

I agree it is more general, and possibly cleaner as a result. However, it will fail to be as flexible as the s4882 style approach.

Quoted 8 lines

The S4882 has 8 busses, 2 for each CPU. The 2 busses of each CPU are "compatible" (no common address) so I merged them, which results in better performance (less switching required) and lower memory footprint. I don't think you'll be able to do that with the i2c-virtual approach.

In the NCLV-D case, it has 4 different bus lines, but we only really want to handle 2. How can you do that with i2c-virtual?

i2c-virtual is the generic part. It would be handled in a new nclv-d module for the specifics of that board.

Quoted 4 lines

Also, I think I remember that i2c-virtual somehow assumes that the multiplexer itself is an i2c chip, right? This is not the case for the NCLV-D.

no the mux itself can be anything.
It is controlled by another driver which does the specific switching. See pca954x.c.
i2c-virtual.c only contains the generic part.

While pca954x is large, it is overly complex and needs a lot of cleanup. I belive a module for NCLV could be fairly small.

Quoted 9 lines
Quoted 7 lines

The i2c-virtual driver is checked in to sensors but the small changes required to i2c-core.c are not checked in. I held off late last year because 2.9.0 was coming out soon. Now that 2.9.1 is out it's time to look at it again. I have to rework the i2c-core changes because they conflicted with other recent changes to i2c-core.

Quoted 9 lines

Yeah, I remember that.

The more I think of it, the more obvious it is that such a change doesn't belong to the 2.4 kernel, but 2.6. I do not want any more changes to the i2c subsystem of Linux 2.4 (except for bug fixes and documentation updates, of course). It's more than time to move the development effort to 2.6, and only do support on 2.4.

well it's a modest change and CVS / 2.4 is a better sandbox to
test out the changes, at least for me. 2.4 was where the virtual driver was developed by the original submitter Ken Harrenstein.

Quoted 5 lines
Quoted 1 line

attached are the proposed changes to i2c-core for comment.

Eerk. By brain doesn't read non-unified patches very well, sorry.

eerk :) here is unified diff

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

i2c-core.c renamed from i2c-core.c.orig +44 -6
@@ -86,12 +86,14 @@
  * i2c_add_adapter is called from within the algorithm layer,
  * when a new hw adapter registers. A new device is register to be
  * available for clients.
+ *
+ * i2c_add_adapter_nolock does the actual work.  It is split
+ * out so it can be called externally by i2c-virtual.c without deadlocking.
  */
-int i2c_add_adapter(struct i2c_adapter *adap)
+int i2c_add_adapter_nolock(struct i2c_adapter *adap)
 {
 	int i,j,res = 0;
 
-	down(&core_lists);
 	for (i = 0; i < I2C_ADAP_MAX; i++)
 		if (NULL = adapters[i])
 			break;
@@ -127,16 +129,32 @@
 	DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
 	           adap->name,i));
 ERROR0:
+	return res;
+}
+
+int i2c_add_adapter(struct i2c_adapter *adap)
+{
+	int res;
+
+	down(&core_lists);
+        res = i2c_add_adapter_nolock(adap);
 	up(&core_lists);
+
 	return res;
 }
 
 
-int i2c_del_adapter(struct i2c_adapter *adap)
+/*
+ * i2c_del_adapter is the corresponding function to detach all clients
+ * for a bus/adapter and then deregister it.
+ *
+ * i2c_del_adapter_nolock does the actual work.  It is split
+ * out so it can be called externally by i2c-virtual.c without deadlocking.
+ */
+int i2c_del_adapter_nolock(struct i2c_adapter *adap)
 {
 	int i,j,res = 0;
 
-	down(&core_lists);
 	for (i = 0; i < I2C_ADAP_MAX; i++)
 		if (adap = adapters[i])
 			break;
@@ -186,7 +204,17 @@
 	adapters[i] = NULL;
 	DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
 ERROR0:
+	return res;
+}
+
+int i2c_del_adapter(struct i2c_adapter *adap)
+{
+	int res;
+
+	down(&core_lists);
+        res = i2c_del_adapter_nolock(adap);
 	up(&core_lists);
+
 	return res;
 }
 
@@ -310,10 +338,18 @@
 static int __i2c_check_addr (struct i2c_adapter *adapter, int addr)
 {
 	int i;
-	for (i = 0; i < I2C_CLIENT_MAX ; i++) 
+
+#if defined(CONFIG_I2C_VIRTUAL) || defined(CONFIG_I2C_VIRTUAL_MODULE)
+	/* Must check for aliasing on i2c-multiplexed busses since a virt
+         * bus will always appear to have its own mux as an address.  Without
+         * this check we can get infinite recursion during bus scans.
+         */
+	for ( ; adapter; adapter = i2c_virt_parent(adapter))
+#endif
+            for (i = 0; i < I2C_CLIENT_MAX ; i++) {
 		if (adapter->clients[i] && (adapter->clients[i]->addr = addr))
 			return -EBUSY;
-
+            }
 	return 0;
 }
 
@@ -1478,6 +1514,8 @@
 
 EXPORT_SYMBOL(i2c_add_adapter);
 EXPORT_SYMBOL(i2c_del_adapter);
+EXPORT_SYMBOL(i2c_add_adapter_nolock);
+EXPORT_SYMBOL(i2c_del_adapter_nolock);
 EXPORT_SYMBOL(i2c_add_driver);
 EXPORT_SYMBOL(i2c_del_driver);
 EXPORT_SYMBOL(i2c_attach_client);
#4 lore raw
In reply to Rudolf Marek

Hello,

Seems you reply got filtered from spamfilter but thanks to Phil, he catches it from time to time. It seems that footers with chinese
get marked as probable spam in most cases.

Quoted 3 lines

This is the answer from ASUS:
So far most server boards with W83792(A)D follow the same SMBus topology. You do not need to pay attention to this issue.

Ok I have here a quick and dirty shot that implements the multiplexing driver. It is a more scatch than the real thing but it reflect how it will be done.

I followed the driver made by Jean. This is more is different it has a "mux" in ISA IO space. The asus MB is detected in two phases. (ISA bridge and then subsystem ID of SMBUS)

Please comment the idea. I'm still busy theese days so I cant work on this in next two weeks I think. But maybe Chunhao or someone from Winbond want to do that earlier.

Thanks

regards

Rudolf

extern struct i2c_adapter i801_smbus;

static struct i2c_adapter *asus_adapter;
static struct i2c_algorithm *asus_algo;

static int muxbase;

/* Wrapper access functions for multiplexed SMBus */ static struct semaphore i801_lock;

void mux_switch(int what) {

//here should be the mux switching code similar to one bellow //we should switch the bus according specs

// + val=inb((region&~GPIO_IOSIZE_MASK)+GPIO_OUTPUT2_REG_HIGH);

// + val&=~0x4; /* GPIO42 : 0 (Low) */

// + val|=0x8; /* GPIO43 : 1 (High) */

// + outb(val, (region&~GPIO_IOSIZE_MASK)+GPIO_OUTPUT2_REG_HIGH);

// + printk(KERN_INFO "PCI: Canceling ASUS hide and seek played
with SMBus monitoring chi

outb(muxbase+addr, whatbits)

}

/* We remember the last used channels combination so as to only switch
channels when it is really needed. This greatly reduces the SMBus overhead, but also assumes that nobody will be writing to the PCA9556 in our back. */
static u8 last_channels;

static inline s32 i801_access_channel(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data * data, u8 channels)

{
	int error;

// /* We exclude the non-multiplexed addresses */
// if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30)
// return -1;
//

	down(&i801_lock);

	if (last_channels != channels) { //this is wise ;)
		mux_switch(channels);
		last_channels = channels;
	}
	error = i801_smbus.algo->smbus_xfer(adap, addr, flags, read_write,
					      command, size, data);

UNLOCK:

	up(&i801_lock);
	return error;
}

static s32 i801_access_virt1(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size,
union i2c_smbus_data * data)

{
	/* CPU0: channels 1 and 0 enabled */
	return i801_access_channel(adap, addr, flags, read_write, command,
				     size, data, 0x1);
}

static s32 i801_access_virt0(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size,
union i2c_smbus_data * data)
{

	return i801_access_channel(adap, addr, flags, read_write, command,
				     size, data, 0x00);
}

//static int __init i801_asus_init(void)
//{

static int __devinit asus_sb_probe(struct pci_dev *dev, const struct pci_device_id *id)

{
	int i, error;
	int asus_server_board_hides_smbus_devices=0;
	union i2c_smbus_data ioconfig;

        struct pci_dev *smbdev = NULL;
	
	//we are here because INTEL ISA Brigde is present

while (smbdev = pci_get_device(PCI_VENDOR_ID_INTEL,
PCI_DEVICE_ID_INTEL_ESB_4, smbdev)) {

       if (unlikely(smbdev->subsystem_vendor = PCI_VENDOR_ID_ASUSTEK)) {

                       switch(smbdev->subsystem_device) {

                       case 0x8117:
                               asus_server_board_hides_smbus_devices = 1;

                               break;

                       }

       }

    }

//we know this is our board
if (asus_server_board_hides_smbus_devices!=1) return -ENODEV; //get GPIO base

        pci_read_config_dword(dev, 0x58, &muxbase);
	
	if (muxbase=0) { // error
	}

//register
if (!request_region(muxbase, 0xDONTKNOW, "GPIO MUX")) { //error
}

	/* Unregister physical bus */
	error = i2c_del_adapter(&i801_smbus);
	if (error) {
		if (error = -EINVAL)
			error = -ENODEV;
		else
			dev_err(&i801_smbus.dev, "Physical bus removal "
				"failed\n");
		goto ERROR0;
	}

	printk(KERN_INFO "Enabling SMBus multiplexing for ASUS\n");
	init_MUTEX(&i801_lock);

	/* Define the 2 virtual adapters and algorithms structures */
	if (!(asus_adapter = kmalloc(2 * sizeof(struct i2c_adapter),
				      GFP_KERNEL))) {
		error = -ENOMEM;
		goto ERROR1;
	}
	if (!(asus_algo = kmalloc(2 * sizeof(struct i2c_algorithm),
				   GFP_KERNEL))) {
		error = -ENOMEM;
		goto ERROR2;
	}

	/* Fill in the new structures */
	asus_algo[0] = *(i801_smbus.algo);
	asus_algo[1] = *(i801_smbus.algo);

	asus_algo[0].smbus_xfer = i801_access_virt0;
	asus_algo[1].smbus_xfer = i801_access_virt1;

	asus_adapter[0] = i801_smbus;
	asus_adapter[1] = i801_smbus;
	asus_adapter[0].algo = asus_algo;
	asus_adapter[1].algo = asus_algo+1;


		error = i2c_add_adapter(asus_adapter+0);
		
		error = i2c_add_adapter(asus_adapter+1);

		if (error) {
			dev_err(&i801_smbus.dev,
			       "Virtual adapter %d registration "
			       "failed, module not inserted\n", i);
			for (i--; i >= 0; i--)
				i2c_del_adapter(asus_adapter+i);
			goto ERROR3;
		}

//REDO ERR HANDLING
//return -ENODEV because we want only part of the device same as i2c-viapro.c

	return 0;

ERROR3:

	kfree(asus_algo);
	asus_algo = NULL;
ERROR2:
	kfree(asus_adapter);
	asus_adapter = NULL;
ERROR1:
	i2c_del_adapter(&i801_smbus);
ERROR0:
	return error;
}

static void __devexit asus_sb_remove(struct pci_dev *dev) {

//this needs redo too

	if (asus_adapter) {
		int i;

		for (i = 0; i < 5; i++)
			i2c_del_adapter(asus_adapter+i);
		kfree(asus_adapter);
		asus_adapter = NULL;
	}
	if (asus_algo) {
		kfree(asus_algo);
		asus_algo = NULL;
	}

	/* Restore physical bus */
	if (i2c_add_adapter(&i801_smbus))
		dev_err(&i801_smbus.dev, "Physical bus restoration "
			"failed\n");
}
static struct pci_device_id asus_sb_ids[] = {
	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1) },
	{ 0, }
};

MODULE_DEVICE_TABLE (pci, asus_sb_ids);

static struct pci_driver asus_sb_driver = {
	.name		= "asus_sb_smbus",
	.id_table	= asus_sb_ids,
	.probe		= asus_sb_probe,
	.remove		= __devexit_p(asus_sb_remove),
};

static int __init i2c_asus_sb_init(void)

{
	return pci_register_driver(&asus_sb_driver);
}

static void __exit i2c_asus_sb_exit(void)

{
	pci_unregister_driver(&asus_sb_driver);
}

MODULE_LICENSE("GPL");

module_init(i2c_asus_sb_init);
module_exit(i2c_asus_sb_exit);

#5 lore raw
In reply to Rudolf Marek

Dear Rudolf

Thank you for your suggestion on implementing the multiplexing driver, I will start to implement it and ask your help after some time, when I*m a little free, because I*m so busy with my new project, you know. :-(

Thanks
Best Regards
Chunhao

Quoted 285 lines

-----Original Message-----
From: Rudolf Marek [mailto:[email protected]]
Sent: 2005爛4堎23゜ 5:43
To: lm_sensors
Cc: PI14 HUANG0; PI10 LHHsu; PI14 DZSHEN
Subject: Re: NCLV-D SMBus - proposal to a solution

Hello,

Seems you reply got filtered from spamfilter but thanks to Phil, he catches it
from time to time. It seems that footers with chinese
get marked as probable spam in most cases.

Quoted 3 lines

This is the answer from ASUS:
So far most server boards with W83792(A)D follow the same SMBus topology. You do not need to pay attention to this issue.

Ok I have here a quick and dirty shot that implements the multiplexing driver. It is a more scatch than the real thing but it reflect how it will be done.

I followed the driver made by Jean. This is more is different it has a "mux" in ISA IO space. The asus MB is detected in two phases. (ISA bridge and then subsystem ID of SMBUS)

Please comment the idea. I'm still busy theese days so I cant work on this in next two weeks I think. But maybe Chunhao or someone from Winbond want to do that earlier.

Thanks

regards

Rudolf

extern struct i2c_adapter i801_smbus;

static struct i2c_adapter *asus_adapter;
static struct i2c_algorithm *asus_algo;

static int muxbase;

/* Wrapper access functions for multiplexed SMBus */ static struct semaphore i801_lock;

void mux_switch(int what) {

//here should be the mux switching code similar to one bellow //we should switch the bus according specs

// +
val=inb((region&~GPIO_IOSIZE_MASK)+GPIO_OUTPUT2_REG_HIGH);

// + val&=~0x4; /* GPIO42 : 0 (Low) */

// + val|=0x8; /* GPIO43 : 1 (High) */

// + outb(val,
(region&~GPIO_IOSIZE_MASK)+GPIO_OUTPUT2_REG_HIGH);

// + printk(KERN_INFO "PCI: Canceling ASUS hide and seek
played
with SMBus monitoring chi

outb(muxbase+addr, whatbits)

}

/* We remember the last used channels combination so as to only switch
channels when it is really needed. This greatly reduces the SMBus overhead, but also assumes that nobody will be writing to the PCA9556 in our back. */
static u8 last_channels;

static inline s32 i801_access_channel(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data * data, u8 channels)

{
	int error;

// /* We exclude the non-multiplexed addresses */
// if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30)
// return -1;
//

	down(&i801_lock);

	if (last_channels != channels) { //this is wise ;)
		mux_switch(channels);
		last_channels = channels;
	}
	error = i801_smbus.algo->smbus_xfer(adap, addr, flags, read_write,
					      command, size, data);

UNLOCK:

	up(&i801_lock);
	return error;
}

static s32 i801_access_virt1(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size,
union i2c_smbus_data * data)

{
	/* CPU0: channels 1 and 0 enabled */
	return i801_access_channel(adap, addr, flags, read_write, command,
				     size, data, 0x1);
}

static s32 i801_access_virt0(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size,
union i2c_smbus_data * data)
{

	return i801_access_channel(adap, addr, flags, read_write, command,
				     size, data, 0x00);
}

//static int __init i801_asus_init(void)
//{

static int __devinit asus_sb_probe(struct pci_dev *dev, const struct pci_device_id *id)

{
	int i, error;
	int asus_server_board_hides_smbus_devices=0;
	union i2c_smbus_data ioconfig;

        struct pci_dev *smbdev = NULL;

	//we are here because INTEL ISA Brigde is present

while (smbdev = pci_get_device(PCI_VENDOR_ID_INTEL,
PCI_DEVICE_ID_INTEL_ESB_4, smbdev)) {

       if (unlikely(smbdev->subsystem_vendor = PCI_VENDOR_ID_ASUSTEK)) {

                       switch(smbdev->subsystem_device) {

                       case 0x8117:
                               asus_server_board_hides_smbus_devices = 1;

                               break;

                       }

       }

    }

//we know this is our board
if (asus_server_board_hides_smbus_devices!=1) return -ENODEV; //get GPIO base

        pci_read_config_dword(dev, 0x58, &muxbase);

	if (muxbase=0) { // error
	}

//register
if (!request_region(muxbase, 0xDONTKNOW, "GPIO MUX")) { //error
}

	/* Unregister physical bus */
	error = i2c_del_adapter(&i801_smbus);
	if (error) {
		if (error = -EINVAL)
			error = -ENODEV;
		else
			dev_err(&i801_smbus.dev, "Physical bus removal "
				"failed\n");
		goto ERROR0;
	}

	printk(KERN_INFO "Enabling SMBus multiplexing for ASUS\n");
	init_MUTEX(&i801_lock);

	/* Define the 2 virtual adapters and algorithms structures */
	if (!(asus_adapter = kmalloc(2 * sizeof(struct i2c_adapter),
				      GFP_KERNEL))) {
		error = -ENOMEM;
		goto ERROR1;
	}
	if (!(asus_algo = kmalloc(2 * sizeof(struct i2c_algorithm),
				   GFP_KERNEL))) {
		error = -ENOMEM;
		goto ERROR2;
	}

	/* Fill in the new structures */
	asus_algo[0] = *(i801_smbus.algo);
	asus_algo[1] = *(i801_smbus.algo);

	asus_algo[0].smbus_xfer = i801_access_virt0;
	asus_algo[1].smbus_xfer = i801_access_virt1;

	asus_adapter[0] = i801_smbus;
	asus_adapter[1] = i801_smbus;
	asus_adapter[0].algo = asus_algo;
	asus_adapter[1].algo = asus_algo+1;


		error = i2c_add_adapter(asus_adapter+0);

		error = i2c_add_adapter(asus_adapter+1);

		if (error) {
			dev_err(&i801_smbus.dev,
			       "Virtual adapter %d registration "
			       "failed, module not inserted\n", i);
			for (i--; i >= 0; i--)
				i2c_del_adapter(asus_adapter+i);
			goto ERROR3;
		}

//REDO ERR HANDLING
//return -ENODEV because we want only part of the device same as i2c-viapro.c

	return 0;

ERROR3:

	kfree(asus_algo);
	asus_algo = NULL;
ERROR2:
	kfree(asus_adapter);
	asus_adapter = NULL;
ERROR1:
	i2c_del_adapter(&i801_smbus);
ERROR0:
	return error;
}

static void __devexit asus_sb_remove(struct pci_dev *dev) {

//this needs redo too

	if (asus_adapter) {
		int i;

		for (i = 0; i < 5; i++)
			i2c_del_adapter(asus_adapter+i);
		kfree(asus_adapter);
		asus_adapter = NULL;
	}
	if (asus_algo) {
		kfree(asus_algo);
		asus_algo = NULL;
	}

	/* Restore physical bus */
	if (i2c_add_adapter(&i801_smbus))
		dev_err(&i801_smbus.dev, "Physical bus restoration "
			"failed\n");
}
static struct pci_device_id asus_sb_ids[] = {
	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1) },
	{ 0, }
};

MODULE_DEVICE_TABLE (pci, asus_sb_ids);

static struct pci_driver asus_sb_driver = {
	.name		= "asus_sb_smbus",
	.id_table	= asus_sb_ids,
	.probe		= asus_sb_probe,
	.remove		= __devexit_p(asus_sb_remove),
};

static int __init i2c_asus_sb_init(void)

{
	return pci_register_driver(&asus_sb_driver);
}

static void __exit i2c_asus_sb_exit(void)

Quoted 8 lines
{
	pci_unregister_driver(&asus_sb_driver);
}

MODULE_LICENSE("GPL");

module_init(i2c_asus_sb_init);
module_exit(i2c_asus_sb_exit);

==============================================The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original author of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such person, please kindly reply the sender indicating accordingly and delete all copies of it from your computer and network server immediately. We thank you for your cooperation. It is advisable that any unauthorized use of confidential information of Winbond is strictly prohibited; and any information in this email that does not relate to the official business of Winbond shall be deemed as neither given nor endorsed by Winbond.==============================================If your computer is unable to decode Chinese font, please ignore the following message. They essentially repea!
t the&nbsp; English statement above.本信件內所含華邦電子的財產性機密性資訊, 僅授權原發信人指定之收信人取閱之用. 假使您並非被指定之收信人或因任何原因在未經授權的情形之下收到本信件, 請您告知原發信人並立即將信件從電腦與網路伺服器中予以消除. 對於您的合作, 我們先此致謝. 特此提醒, 任何未經授權擅自使用華邦電子的機密資訊的行為是被嚴格禁止的. 信件與華邦電子營業無關之內容,不得視為華邦電子之立場或意見.