Adding S4882 support to the i2c-amd756 driver
Hi all,
As mentioned some days ago, I am in the process of adding support for the Tyan S4882 motherboard to lm_sensors.
The support for the LM63 monitoring chip is already in, nothing particular to say about that.
The SMBus support is a bit trickier though, since the board uses multiplexing. For now, I added support directly into the i2c-amd756 driver. Since it increases the size of the driver, I made the extra code optional (will show as an option when configuring the kernel, or can be manually switched on and off when compiling directly in the lm_sensors tree; default is to include support).
The size isn't necessarily a problem, since the driver is small to start with, and the overhead is small as well (in absolute size, that is). However, Mark M. Hoffman objected that in the interest of maintainability, separating the S4882-specific code would be better. I'm all for that, but my attemps to do so did all fail so far.
* Composite module
I don't know how this can be done in the lm_sensors tree. Hint anyone?
* Separate module
My initial attempt to have a separate i2c-amd756-s4882 module works in that the code belongs to a different file. However, both modules will be loaded in all cases, whether the board is a S4882 or not, because the main module has references to functions belonging to the extra module. I think it might be a little confusing for the user. The correct approach would be to have three modules: 1* main code, 2* pci detection for regular boards and 3* pci detection + extra code for the S4882. Having three different modules sound overkill. Also, this would probably involve renaming files and modules, which will make things even more confusing for everyone, and significant changes to the original code. I'm not going into that.
So I think I will stick to my original plan to simply include the extra code in the main driver. If anyone object, please tell me how I can either do a composite module in the lm_sensors tree (one single module made of two source files), or any other way to have things done more cleanly.
Note: All this is for 2.4/CVS only. For 2.6, Mark M. Hoffman is working on a completely different approach for multiplexing support, and I will wait for his proposal and build my work on top of that.
Thanks.
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
Hi Mark,
Quoted 5 lines
(...) Usage, e.g.:
static struct
i2c_adapter*xyz_real_adap;
static structi2c_adapter*xyz_virt_adap;
Quoted 8 lines
static int
__initxyz_mux_init(void)
{int err; /* register myself as a driver/client */ if ((err = i2c_add_driver(&xyz_mux_driver)) goto ERROR_0;
Except that you cannot register the client at this point. If you do, it'll get kicked as soon as you "lock" the adapter.
Quoted 9 lines
/* find the real bus */
if (!((xyz_real_adap = i2c_get_adapter(<some id>))) {
err = -EINVAL;
goto ERROR_1;
}
/* lock all other clients out of it */
if ((err = i2c_lock_adapter(&xyz_real_adap))
goto ERROR_2;And register the client manually at this point. The mux client is the only client attached to the real bus.
Quoted 8 lines
/* build the virtual adapter */ /* ... */ if ((err = i2c_add_adapter(&xyz_virt_adap)) goto ERROR_3; return 0;
Quoted 4 lines
1) The above carries a built-in assumption: that the mux itself, if it is controlled by I2C/SMBus, must be a client of the immediate parent segment. Does anyone know of a mux that doesn't work that way? E.g. a 2x1 mux with a fourth bus connection for mux control only?
The S4882 itself has an interesting architecture. The Philips PCA9556 itself is not an I2C mux chip. It is an 8-bit I/O. On the S4882 each pin is used as an output, and the pins control two PCA9516 chips, which are the real (5-way) I2C muxes. The PCA9516 chips don't show on the I2C bus.
This shows that the multiplexing is highly board-dependant. It also shows that we could see PCA9556 chips which are not means for bus multiplexing, or PCA9516 chips which are controled by other means (such as LPC GPIO chips).
However, I don't see how the model you propose wouldn't cover such cases. What prevents the virtual busses from doing e.g. ISA I/O to control the multiplexer(s)?
Quoted 3 lines
2) Doesn't address the sysfs hierarchy. It would be nice to have a sysfs structure that is isomorphic to the i2c bus structure... I think USB is like that so I will look into it.
I wonder if it is worth the effort. There aren't that many multiplexed SMBus systems out there, and we still have to see multilevel muxes. The problem I see is that a sysfs structure change would most likely require changes to user-space tools such as i2cdetect. While not impossible to do, I think we have to think about these changes before taking the actual move.
Thanks,
--
Jean Delvare
Quoting myself:
Quoted 2 lines
* Composite module
I don't know how this can be done in thelm_sensorstree. Hint anyone?
I finally came to a sort of composite module. Thanks go to my beloved one for the idea of simply including i2c-amd756-s4882.c from i2c-amd756.c. Simple and unusual but it does what we need. We don't even need to alter the Makefile stuff.
Mark, does this second approach please you more than my original one? The changes to the original file are reduced to their minimal form.
We could probably go with a real composite module (separate compilation) but this means changes to kernel/busses/Module.mk, and at least one additional header file. I don't think it's worth the effort, but counterarguments are welcome.
Patch to i2c-amd756.c:
=================================RCS file: /home/cvs/lm_sensors2/kernel/busses/i2c-amd756.c,v retrieving revision 1.35
busses/i2c-amd756.c +35 -2
@@ -89,6 +89,13 @@#define AMD756_PROCESS_CALL 0x04#define AMD756_BLOCK_DATA 0x05 +/* Include S4882 support by default if compiled outside of the kernel tree. +When patching the kernel instead, inclusion can be decided as a kernel +configuration option. */ +#ifndef CONFIG_I2C_AMD756 +#define CONFIG_I2C_AMD756_S4882 +#endif +static unsigned short amd756_ioport =0 ;
@@ -315,25 +322,35 @@ .algo = &smbus_algorithm, }; -enum chiptype {AMD756 ,AMD766 ,AMD768 ,NFORCE ,AMD8111 }; +enum chiptype {AMD756 ,AMD766 ,AMD768 ,NFORCE ,AMD8111 ,S4882 };static const char * chipname[] = {"AMD756" ,"AMD766" ,"AMD768" , -"nVidia nForce" ,"AMD8111" , +"nVidia nForce" ,"AMD8111" ,"AMD8111" , };static struct pci_device_id amd756_ids[]__devinitdata = { {PCI_VENDOR_ID_AMD ,0x740B ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,AMD756 }, {PCI_VENDOR_ID_AMD ,0x7413 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,AMD766 }, {PCI_VENDOR_ID_AMD ,0x7443 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,AMD768 }, +#ifdef CONFIG_I2C_AMD756_S4882 + {PCI_VENDOR_ID_AMD ,0x746B ,PCI_VENDOR_ID_AMD ,0x36C0 ,0 ,0 ,S4882 }, +#endif {PCI_VENDOR_ID_AMD ,0x746B ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,AMD8111 }, {PCI_VENDOR_ID_NVIDIA ,0x01B4 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,NFORCE }, {0 , } }; +#ifdef CONFIG_I2C_AMD756_S4882 +#include "i2c-amd756-s4882.c" +#endif +static int __devinit amd756_probe (struct pci_dev *pdev,const struct pci_device_id *id) {int nforce = (id->driver_data =NFORCE ); +#ifdef CONFIG_I2C_AMD756_S4882 +int s4882 = (id->driver_data =S4882 ); +#endif int error;u8 temp;
@@ -379,6 +396,11 @@ printk(KERN_DEBUG DRV_NAME ": AMD756_smba = 0x%X\n", amd756_ioport);#endif +#ifdef CONFIG_I2C_AMD756_S4882 +if (s4882) +amd756_s4882_init_main (); +#endif +sprintf (amd756_adapter.name,"SMBus %s adapter at %04x" , chipname[id->driver_data], amd756_ioport);
@@ -389,6 +411,14 @@ goto out_err; } +#ifdef CONFIG_I2C_AMD756_S4882 +if (s4882) { + error =amd756_s4882_init_virtual (); +if (error) + goto out_err; + } +#endif +return 0 ; out_err:
@@ -416,6 +446,9 @@ static void __exit i2c_amd756_exit(void) { +#ifdef CONFIG_I2C_AMD756_S4882 +amd756_s4882_exit (); +#endif i2c_del_adapter (&amd756_adapter);release_region (amd756_ioport,SMB_IOSIZE ); }
=================================
New code goes in kernel/busses/i2c-amd756-s4882.c:
=================================/*
* i2c-amd756-s4882.c - i2c-amd756 extras for the Tyan S4882 motherboard *
* Copyright (C) 2004 Jean Delvare <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* We select the channels by sending commands to the Philips
* PCA9556 chip at I2C address 0x18. The main adapter is used for
* the non-multiplexed part of the bus, and 4 virtual adapters
* are defined for the multiplexed addresses: 0x50-0x53 (memory
* module EEPROM) located on channels 1-4, and 0x4c (LM63)
* located on multiplexed channels 0 and 5-7. We define one
* virtual adapter per CPU, which corresponds to two multiplexed
* channels:
* CPU0: virtual adapter 1, channels 1 and 0 * CPU1: virtual adapter 2, channels 2 and 5 * CPU2: virtual adapter 3, channels 3 and 6 * CPU3: virtual adapter 4, channels 4 and 7
* Support is only included if CONFIG_I2C_AMD756_S4882 is
* defined.
*/
static struct i2c_adapter *s4882_adapter;
static struct i2c_algorithm *s4882_algo;
static struct i2c_client pca9556_client = {
.name = "pca9556",
.adapter = &amd756_adapter,
.addr = 0x18,
.driver = NULL,
};/* Wrapper access functions for multiplexed SMBus (S4882) */ static struct semaphore amd756_lock;
static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data * data)
{
int error;
/* We exclude the multiplexed addresses */
if (addr = 0x4c || (addr & 0xfc) = 0x50 || (addr & 0xfc) = 0x30)
return -1;
down(&amd756_lock);
error = amd756_access(adap, addr, flags, read_write, command, size,
data);
up(&amd756_lock);
return error;
}/* 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 amd756_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(&amd756_lock);
if (last_channels != channels) {
union i2c_smbus_data mplxdata;
mplxdata.byte = channels;
error = amd756_access(adap, 0x18, 0, I2C_SMBUS_WRITE, 0x01,
I2C_SMBUS_BYTE_DATA, &mplxdata);
if (error)
goto UNLOCK;
last_channels = channels;
}
error = amd756_access(adap, addr, flags, read_write, command, size,
data);UNLOCK:
up(&amd756_lock); return error; }
static s32 amd756_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 amd756_access_channel(adap, addr, flags, read_write, command,
size, data, 0x03);
}static s32 amd756_access_virt2(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data * data)
{
/* CPU1: channels 2 and 5 enabled */
return amd756_access_channel(adap, addr, flags, read_write, command,
size, data, 0x24);
}static s32 amd756_access_virt3(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data * data)
{
/* CPU2: channels 3 and 6 enabled */
return amd756_access_channel(adap, addr, flags, read_write, command,
size, data, 0x48);
}static s32 amd756_access_virt4(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data * data)
{
/* CPU3: channels 4 and 7 enabled */
return amd756_access_channel(adap, addr, flags, read_write, command,
size, data, 0x90);
}static void __devinit amd756_s4882_init_main(void)
{
printk(KERN_INFO DRV_NAME ": Enabling bus multiplexing for "
"Tyan S4882\n");
init_MUTEX(&amd756_lock);
/* Intercept calls to the main adapter */
smbus_algorithm.smbus_xfer = amd756_access_virt0;
}/* return 0 on success, negative value on error */ static int __devinit amd756_s4882_init_virtual(void)
{
int i, error;
union i2c_smbus_data ioconfig;
/* Define the 4 virtual adapters and algorithms structures */
if (!(s4882_adapter = kmalloc(4 * sizeof(struct i2c_adapter),
GFP_KERNEL))) {
error = -ENOMEM;
goto ERROR0;
}
if (!(s4882_algo = kmalloc(4 * sizeof(struct i2c_algorithm),
GFP_KERNEL))) {
error = -ENOMEM;
goto ERROR1;
}
for (i = 0; i < 4; i++) {
s4882_algo[i] = smbus_algorithm;
s4882_adapter[i] = amd756_adapter;
sprintf(s4882_adapter[i].name,
"SMBus 8111 adapter (CPU%d)", i);
s4882_adapter[i].algo = s4882_algo+i;
}
/* Point to the wrapper callback functions */
s4882_algo[0].smbus_xfer = amd756_access_virt1;
s4882_algo[1].smbus_xfer = amd756_access_virt2;
s4882_algo[2].smbus_xfer = amd756_access_virt3;
s4882_algo[3].smbus_xfer = amd756_access_virt4;
/* Register the PCA9556 multiplexer */
error = i2c_attach_client(&pca9556_client);
if (error) {
printk(KERN_ERR DRV_NAME ": PCA9556 registration "
"failed\n");
goto ERROR2;
}
/* Configure the PCA9556 multiplexer */
ioconfig.byte = 0x00; /* All I/O to output mode */
error = amd756_access(&amd756_adapter, 0x18, 0,
I2C_SMBUS_WRITE, 0x03,
I2C_SMBUS_BYTE_DATA, &ioconfig);
if (error) {
printk(KERN_ERR DRV_NAME ": PCA9556 configuration "
"failed\n");
error = -EIO;
goto ERROR3;
}
/* Register virtual adapters */
for (i = 0; i < 4; i++) {
error = i2c_add_adapter(s4882_adapter+i);
if (error) {
printk(KERN_ERR DRV_NAME
": Virtual adapter %d registration "
"failed, module not inserted\n", i);
for (i--; i >= 0; i--)
i2c_del_adapter(s4882_adapter+i);
goto ERROR3;
}
}
return 0;ERROR3:
i2c_detach_client(&pca9556_client); ERROR2: kfree(s4882_algo); s4882_algo = NULL; ERROR1: kfree(s4882_adapter); s4882_adapter = NULL; ERROR0: return error; }
static void __exit amd756_s4882_exit(void)
{
if (s4882_adapter) {
int i;
for (i = 0; i < 4; i++)
i2c_del_adapter(s4882_adapter+i);
kfree(s4882_adapter);
s4882_adapter = NULL;
}
if (s4882_algo) {
kfree(s4882_algo);
s4882_algo = NULL;
}
i2c_detach_client(&pca9556_client);
}=================================
Comments welcome,
thanks.
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
Hi:
Quoted 5 lines · Jean Delvare
Quoting myself:
Quoted 2 lines
* Composite module
I don't know how this can be done in thelm_sensorstree. Hint anyone?
Quoted 7 lines
I finally came to a sort of composite module. Thanks go to my beloved one for the idea of simply including
i2c-amd756-s4882.cfromi2c-amd756.c. Simple and unusual but it does what we need. We don't even need to alter theMakefilestuff.Mark, does this second approach please you more than my original one? The changes to the original file are reduced to their minimal form.
Heh, OK. Could you just make sure that 'touch i2c-amd756-s4882.c' causes make to rebuild the object? I think the auto dependency magic will figure that out, but I'm not sure.
Regards,
Signature · 2 lines
Mark M. Hoffman [email protected]
Hi guys:
Quoted 11 lines · Jean Delvare
Quoted 6 lines
If we could come up with a "wrapper" model of an i2c bus driver for these mux situations that seems to me to be the ideal. Such a wrapper would capture the knowledge of how to mux the bus and what branch of the mux is currently selected. It would register multiple "virtual" i2c busses and mark the "parent" i2c bus as no-probe and in general attempt to prevent anything from accessing the parent bus directly.
This pretty much matches what Mark M. Hoffman suggested to me on IRC yesterday. Great you seem to agree on the proper way to do it ;) I didn't read the original virtual bus implementation proposal in enough details to say if it was similar or not.
What Jean & I chatted about was adding a pair of functions to i2c-core; they would look something like this:
int i2c_lock_adapter(struct i2c_adapter *); int i2c_unlock_adapter(struct i2c_adapter *);
The first would actually pull the adapter out of the core list, including auto-detaching any clients that might have already attached. The purpose of that is to prevent probing as you (Philip) mentioned. Usage, e.g.:
static struct i2c_adapter *xyz_real_adap;
static struct i2c_adapter *xyz_virt_adap;
static int __init xyz_mux_init(void)
{
int err;
/* register myself as a driver/client */
if ((err = i2c_add_driver(&xyz_mux_driver))
goto ERROR_0;
/* find the real bus */
if (!((xyz_real_adap = i2c_get_adapter(<some id>))) {
err = -EINVAL;
goto ERROR_1;
}
/* lock all other clients out of it */
if ((err = i2c_lock_adapter(&xyz_real_adap))
goto ERROR_2;
/* build the virtual adapter */
/* ... */
if ((err = i2c_add_adapter(&xyz_virt_adap))
goto ERROR_3;
return 0;ERROR_3:
i2c_unlock_adapter(struct i2c_adapter *); ERROR_2: i2c_put_adapter(&xyz_real_adap); ERROR_1: i2c_del_driver(&xyz_mux_driver); ERROR_0: return err; }
So, that would accomodate some useful things:
1) Muxes, obviously, but also...
2) The (hypothetical, mentioned in earlier message) i2c-trace module.
3) Whatever home-grown, out-of-band bus reservation system you have. E.g. if you have a single I2C bus segment with multiple masters, where normal I2C bus arbitration isn't good enough - you could lock the real bus and attach your clients to the virtual one, which satisfies whatever bus reservation scheme before/after transactions.
This idea isn't even half-baked yet though...
1) The above carries a built-in assumption: that the mux itself, if it is controlled by I2C/SMBus, must be a client of the immediate parent segment. Does anyone know of a mux that doesn't work that way? E.g. a 2x1 mux with a fourth bus connection for mux control only?
2) Doesn't address the sysfs hierarchy. It would be nice to have a sysfs structure that is isomorphic to the i2c bus structure... I think USB is like that so I will look into it.
Any other ideas would be appreciated.
Regards,
Signature · 2 lines
Mark M. Hoffman [email protected]
Hi Philip,
Quoted 2 lines
How does the multiplexing work on the S4882 motherboard? Is it controlled by GPIO pins or is there an I2C mux chip on the I2C bus?
I2C mux chip (Philips PCA9556) at 0x18. The mux chip controls two Philips PCA9516 chips, for a total of 8 additional branches.
Quoted 1 line
What devices are on the different branches of the I2C bus?
Four branches have one National Semiconductor LM63 monitoring chip (2 temperatures, 1 fan), four branches have up to 4 memory module SPD EEPROMs. In my modified version of the i2c-amd756 driver, I have "merged" the branches by pair so that each virtual bus corresponds to one CPU. This makes things more straightforward for the user, and also reduces the mux operations. It would be great if the solution we come up with would preserve that.
The board additionaly features an ADM1027 chip and a W83627HF chip. Running "sensors" there when all modules are loaded is truly impressive :)
Quoted 6 lines
If we could come up with a "wrapper" model of an i2c bus driver for these mux situations that seems to me to be the ideal. Such a wrapper would capture the knowledge of how to mux the bus and what branch of the mux is currently selected. It would register multiple "virtual" i2c busses and mark the "parent" i2c bus as no-probe and in general attempt to prevent anything from accessing the parent bus directly.
This pretty much matches what Mark M. Hoffman suggested to me on IRC yesterday. Great you seem to agree on the proper way to do it ;) I didn't read the original virtual bus implementation proposal in enough details to say if it was similar or not.
Quoted 4 lines
Then our normal sensor drivers would just operate on the "virtual" busses directly and the wrapper would take care of changing the mux as required in an *atomic* way so that accesses are made to the different busses correctly.
Agreed. This isn't very different from what my current code does, except that I didn't separate the parent bus and the trunk bus. Instead, the parent bus is replaced by the trunk+mux bus before it is registered. This is slightly more efficient in case i2c clients are already loaded, but I don't think this should stop us.
That said, the approach you and Mark propose will probably require some changes to the i2c core, so I don't think it belongs to lm_sensors CVS but only to linux 2.6, at least for now. For this reason, I plan to commit my changes to the i2c-amd756 driver to CVS. I hope to get it in the form of a composite module or something similar, so as to address Mark's fear for the lack of maintainability. If the solution planed for linux 2.6 isn't too intrusive (the minimum requirement is that it shouldn't alter any of the i2c_{adapter,algorithm,client,driver} structures nor prototypes of existing interface functions) and after it has been well tested, I may still consider porting it back to CVS and update the i2c-amd756 driver to make use of it.
Thanks,
Jean
How does the multiplexing work on the S4882 motherboard? Is it controlled by GPIO pins or is there an I2C mux chip on the I2C bus?
What devices are on the different branches of the I2C bus?
If we could come up with a "wrapper" model of an i2c bus driver for these mux situations that seems to me to be the ideal. Such a wrapper would capture the knowledge of how to mux the bus and what branch of the mux is currently selected. It would register multiple "virtual" i2c busses and mark the "parent" i2c bus as no-probe and in general attempt to prevent anything from accessing the parent bus directly.
Then our normal sensor drivers would just operate on the "virtual" busses directly and the wrapper would take care of changing the mux as required in an *atomic* way so that accesses are made to the different busses correctly.
:v)
Quoted 51 lines · Jean Delvare
Hi all,
As mentioned some days ago, I am in the process of adding support for the Tyan S4882 motherboard to
lm_sensors.The support for the LM63 monitoring chip is already in, nothing particular to say about that.
The SMBus support is a bit trickier though, since the board uses multiplexing. For now, I added support directly into the i2c-amd756 driver. Since it increases the size of the driver, I made the extra code optional (will show as an option when configuring the kernel, or can be manually switched on and off when compiling directly in the
lm_sensorstree; default is to include support).The size isn't necessarily a problem, since the driver is small to start with, and the overhead is small as well (in absolute size, that is). However, Mark M. Hoffman objected that in the interest of maintainability, separating the S4882-specific code would be better. I'm all for that, but my attemps to do so did all fail so far.
* Composite module
I don't know how this can be done in thelm_sensorstree. Hint anyone?* Separate module
My initial attempt to have a separate i2c-amd756-s4882 module works in that the code belongs to a different file. However, both modules will be loaded in all cases, whether the board is a S4882 or not, because the main module has references to functions belonging to the extra module. I think it might be a little confusing for the user. The correct approach would be to have three modules: 1* main code, 2* pci detection for regular boards and 3* pci detection + extra code for the S4882. Having three different modules sound overkill. Also, this would probably involve renaming files and modules, which will make things even more confusing for everyone, and significant changes to the original code. I'm not going into that.So I think I will stick to my original plan to simply include the extra code in the main driver. If anyone object, please tell me how I can either do a composite module in the
lm_sensorstree (one single module made of two source files), or any other way to have things done more cleanly.Note: All this is for 2.4/CVS only. For 2.6, Mark M. Hoffman is working on a completely different approach for multiplexing support, and I will wait for his proposal and build my work on top of that.
Thanks.
Quoted 7 lines
Quoted 3 lines
Mark, does this second approach please you more than my original one? The changes to the original file are reduced to their minimal form.
Heh, OK. Could you just make sure that 'touch
i2c-amd756-s4882.c' causes make to rebuild the object? I think the auto dependency magic will figure that out, but I'm not sure.
Yes, it works properly. Thanks for pointing the potential issue out, I admit I didn't consider the problem.
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
Hi Jean:
Quoted 8 lines
Quoted 8 lines
(...) Usage, e.g.:
static struct
i2c_adapter*xyz_real_adap;
static structi2c_adapter*xyz_virt_adap;static int
__initxyz_mux_init(void)
{
Quoted 8 lines
Quoted 5 lines
int err; /* register myself as a driver/client */ if ((err = i2c_add_driver(&xyz_mux_driver)) goto ERROR_0;Except that you cannot register the client at this point. If you do, it'll get kicked as soon as you "lock" the adapter.
Oops, of course you're right. I wrote this example code too late at night. :)
Quoted 6 lines
Quoted 6 lines
/* find the real bus */ if (!((xyz_real_adap = i2c_get_adapter(<some id>))) { err = -EINVAL; goto ERROR_1; }
Quoted 6 lines
Quoted 3 lines
/* lock all other clients out of it */ if ((err = i2c_lock_adapter(&xyz_real_adap)) goto ERROR_2;And register the client manually at this point. The mux client is the only client attached to the real bus.
Right again.
Quoted 18 lines
Quoted 8 lines
/* build the virtual adapter */ /* ... */ if ((err = i2c_add_adapter(&xyz_virt_adap)) goto ERROR_3; return 0;Quoted 4 lines
1) The above carries a built-in assumption: that the mux itself, if it is controlled by I2C/SMBus, must be a client of the immediate parent segment. Does anyone know of a mux that doesn't work that way? E.g. a 2x1 mux with a fourth bus connection for mux control only?
The S4882 itself has an interesting architecture. The Philips PCA9556 itself is not an I2C mux chip. It is an 8-bit I/O. On the S4882 each pin is used as an output, and the pins control two PCA9516 chips, which are the real (5-way) I2C muxes. The PCA9516 chips don't show on the I2C bus.
Quoted 4 lines
This shows that the multiplexing is highly board-dependant. It also shows that we could see PCA9556 chips which are not means for bus multiplexing, or PCA9516 chips which are controled by other means (such as LPC GPIO chips).
That's one reason I think the module in your case is best named "s4882" instead of any name referencing the mux chips. :) We might end up copy- pasting some of the PCA9556 code into other similar but different modules, but we can consolidate if and when it comes to that.
Quoted 3 lines
However, I don't see how the model you propose wouldn't cover such cases. What prevents the virtual busses from doing e.g. ISA I/O to control the multiplexer(s)?
True.
Quoted 10 lines
Quoted 3 lines
2) Doesn't address the sysfs hierarchy. It would be nice to have a sysfs structure that is isomorphic to the i2c bus structure... I think USB is like that so I will look into it.
I wonder if it is worth the effort. There aren't that many multiplexed SMBus systems out there, and we still have to see multilevel muxes. The problem I see is that a sysfs structure change would most likely require changes to user-space tools such as i2cdetect. While not impossible to do, I think we have to think about these changes before taking the actual move.
Yes, I'll want to tackle this in stages. The sysfs fixups can come later. It brings up a point though: if the MUX client is registered "manually" as we're calling it, what do we do with the sysfs structure? Maybe it would be better for i2c_lock_adapter to do this:
1) force all existing clients to detach
2) attach the caller client as normal
3) mark the bus as no-probe and allow no further client attachments
That would retain all the existing sysfs structure. Thoughts?
Regards,
Signature · 2 lines
Mark M. Hoffman [email protected]
Hi:
(Replying to self)
Quoted 8 lines · Mark M. Hoffman
Yes, I'll want to tackle this in stages. The sysfs fixups can come later. It brings up a point though: if the MUX client is registered "manually" as we're calling it, what do we do with the sysfs structure? Maybe it would be better for
i2c_lock_adapterto do this:1) force all existing clients to detach
2) attach the caller client as normal
3) mark the bus as no-probe and allow no further client attachments
To be more clear, what I'm suggesting would be declared like this:
int i2c_attach_client_exclusive(struct i2c_client *client);
The "unlock" part can be rolled into the normal i2c_detach_client routine.
Regards,
Signature · 2 lines
Mark M. Hoffman [email protected]