I2C: New chip driver: sis5595
Quoted 7 lines · Aurelien Jarno
Please find below the new version of the patch against kernel 2.6.11-rc2-mm2 to add the sis5595 driver (sensor part).
drivers/i2c/chips/sis5595.c +1
-0+struct sis5595_data {
drivers/i2c/chips/sis5595.c
Quoted 10 lines
drivers/i2c/chips/sis5595.c +6
-0+char valid;/* !=0 if following fields are valid */ +}; +static struct sis5595_data *sis5595_update_device (struct device *dev) +{ +if ((jiffies - data->last_updated >HZ +HZ /2 ) || + (jiffies < data->last_updated) || !data->valid) {
[snip reading some values]
drivers/i2c/chips/sis5595.c
Quoted 5 lines
drivers/i2c/chips/sis5595.c +4
-0+ data->last_updated = jiffies; + data->valid =1 ; + } +}
Maybe you should call sis5595_update_device() in initialization finction and get rid of "value" field. It's sole purpose to fill "struct sis5595" when it's known that "last_updated" field contains crap.
drivers/i2c/chips/sis5595.c
Quoted 3 lines
drivers/i2c/chips/sis5595.c +2
-0+dev_err (&s_bridge->dev,"sis5595.ko: Error: Looked for SIS5595 but found unsupported device %.4X\n" , *i); +dev_err (&s_bridge->dev,"sis5595.ko: base address not set - upgrade BIOS or use force_addr=0xaddr\n" );
".ko" isn't needed. "Error: " in the first line too.
Alexey
Hi Alexey,
Quoted 3 lines
Maybe you should call
sis5595_update_device()in initialization function and get rid of "value" field. It's sole purpose to fill "struct sis5595" when it's known that "last_updated" field contains crap.
I assume you meant "valid" field.
Doesn't work. If you discard the "valid" field and call the update function at init time, you cannot be sure that the update function will actually do something. It all depends on the jiffies value relative to last_updated (0 at this point). This is exactly what "valid" is there for.
An alternative is to add a parameter to the update function, that would force the update to happen regardless of time consideration. This doesn't really change anything though, you simply remove a structure member and replace it with a function parameter. How does it help?
Third possibility would be to initialize "last_updated" to anything less than jiffies-(HZ+HZ/2) at init time, so as to be sure that the next update will occur. Is it doable? Or maybe if we initialize "last_updated" to the max possible jiffies count, it'll have the same effect. But is it doable?
At any rate, the exact same issue exists in every over existing hardware monitoring driver. If we change our mind we'll do it for all drivers, not only this new one (sis5595), so Aurelien's patch is fine with me.
Thanks,
--
Jean Delvare
Quoted 9 lines · Jean Delvare
Quoted 3 lines
Maybe you should call
sis5595_update_device()in initialization function and get rid of "value" field. It's sole purpose to fill "struct sis5595" when it's known that "last_updated" field contains crap.Doesn't work. If you discard the "valid" field and call the update function at init time, you cannot be sure that the update function will actually do something. It all depends on the jiffies value relative to
last_updated(0 at this point). This is exactly what "valid" is there for.
What about making sis5595_update_device() a simple jiffies-related wrapper around function that updates "struct sis5595" unconditionally. I'm not sure I plugged sis5595_do_update_client right, but you'll get the idea.
Alexey
drivers/i2c/chips/sis5595.c renamed from drivers/i2c/chips/sis5595.c.orig +37 -42
@@ -184,7 +184,6 @@ struct sis5595_data {struct semaphore lock;struct semaphore update_lock; -char valid;/* !=0 if following fields are valid */ unsigned long last_updated;/* In jiffies */ char maxins;/* == 3 if temp enabled, otherwise == 4 */ u8 revision;/* Reg. value */
@@ -209,6 +208,7 @@ static int sis5595_detach_client(structstatic int sis5595_read_value (struct i2c_client *client,u8 register);static int sis5595_write_value (struct i2c_client *client,u8 register,u8 value); +static void sis5595_do_update_client (struct i2c_client *client);static struct sis5595_data *sis5595_update_device (struct device *dev);static void sis5595_init_client (struct i2c_client *client);static int sis5595_find_sis (int *address);
@@ -586,7 +586,6 @@ int sis5595_detect(struct i2c_adapter *a/* Fill in the remaining client fields and put it into the global list */ strlcpy (new_client->name,"sis5595" ,I2C_NAME_SIZE ); - data->valid =0 ;init_MUTEX (&data->update_lock);/* Tell the I2C layer a new client has arrived */
@@ -691,56 +690,52 @@ static void sis5595_init_client(struct iif (!(config &0x01 ))sis5595_write_value (client,SIS5595_REG_CONFIG , (config &0xf7 ) |0x01 ); +sis5595_do_update_client (client); } -static struct sis5595_data *sis5595_update_device (struct device *dev) +static void sis5595_do_update_client (struct i2c_client *client) { -struct i2c_client *client =to_i2c_client (dev);struct sis5595_data *data =i2c_get_clientdata (client);int i;down (&data->update_lock); - -if ((jiffies - data->last_updated >HZ +HZ /2 ) || - (jiffies < data->last_updated) || !data->valid) { - -for (i =0 ; i <= data->maxins; i++) { - data->in[i] = -sis5595_read_value (client,SIS5595_REG_IN (i)); - data->in_min[i] = -sis5595_read_value (client, -SIS5595_REG_IN_MIN (i)); - data->in_max[i] = -sis5595_read_value (client, -SIS5595_REG_IN_MAX (i)); - } -for (i =0 ; i <2 ; i++) { - data->fan[i] = -sis5595_read_value (client,SIS5595_REG_FAN (i)); - data->fan_min[i] = -sis5595_read_value (client, -SIS5595_REG_FAN_MIN (i)); - } -if (data->maxins ==3 ) { - data->temp = -sis5595_read_value (client,SIS5595_REG_TEMP ); - data->temp_over = -sis5595_read_value (client,SIS5595_REG_TEMP_OVER ); - data->temp_hyst = -sis5595_read_value (client,SIS5595_REG_TEMP_HYST ); - } - i =sis5595_read_value (client,SIS5595_REG_FANDIV ); - data->fan_div[0 ] = (i >>4 ) &0x03 ; - data->fan_div[1 ] = i >>6 ; - data->alarms = -sis5595_read_value (client,SIS5595_REG_ALARM1 ) | - (sis5595_read_value (client,SIS5595_REG_ALARM2 ) <<8 ); - data->last_updated = jiffies; - data->valid =1 ; +for (i =0 ; i <= data->maxins; i++) { + data->in[i] =sis5595_read_value (client,SIS5595_REG_IN (i)); + data->in_min[i] =sis5595_read_value (client, +SIS5595_REG_IN_MIN (i)); + data->in_max[i] =sis5595_read_value (client, +SIS5595_REG_IN_MAX (i)); } - +for (i =0 ; i <2 ; i++) { + data->fan[i] =sis5595_read_value (client,SIS5595_REG_FAN (i)); + data->fan_min[i] =sis5595_read_value (client, +SIS5595_REG_FAN_MIN (i)); + } +if (data->maxins ==3 ) { + data->temp =sis5595_read_value (client,SIS5595_REG_TEMP ); + data->temp_over =sis5595_read_value (client, +SIS5595_REG_TEMP_OVER ); + data->temp_hyst =sis5595_read_value (client, +SIS5595_REG_TEMP_HYST ); + } + i =sis5595_read_value (client,SIS5595_REG_FANDIV ); + data->fan_div[0 ] = (i >>4 ) &0x03 ; + data->fan_div[1 ] = i >>6 ; + data->alarms =sis5595_read_value (client,SIS5595_REG_ALARM1 ) | + (sis5595_read_value (client,SIS5595_REG_ALARM2 ) <<8 ); + data->last_updated = jiffies;up (&data->update_lock); +} + +static struct sis5595_data *sis5595_update_device (struct device *dev) +{ +struct i2c_client *client =to_i2c_client (dev); +struct sis5595_data *data =i2c_get_clientdata (client); +if ((jiffies - data->last_updated >HZ +HZ /2 ) || + (jiffies < data->last_updated)) { +sis5595_do_update_client (client); + }return data; }
Hi Alexey,
Quoted 3 lines
What about making
sis5595_update_device()a simple jiffies-related wrapper around function that updates "struct sis5595" unconditionally. I'm not sure I pluggedsis5595_do_update_clientright, but you'll get the idea.
Yeah I get the idea, I think I had something similar in mind some times ago but it failed to please me for the following reasons:
1* It forces a chip update (i.e. full register read) on driver load (or more precisely on client detection). Since I2C/SMBus accesses are really slow, it will result in a significant time penalty. As the read values are only considered valid for 1.5 second (or equivalent duration for the other drivers), this penalty brings statistically no benefit in return.
2* Each subsequent update (or attempt thereof) will conditionally require an additional function call, which represents a small time penalty again (much more than a comparison if I'm not mistaken).
We are only trying to avoid a conditional test and to get rid of a local variable, and end up with a much slower init and an additional function call later. The loss seems to overweight the gain, don't you think?
So I wouldn't go that way. To me, the only acceptable simplification is the initialization of "last_updated" to something which ensures that the first update attempt will succeed - providing we actually can do that.
Now I wonder, this is certainly not the only drivers in the kernel which need to do this, right? Didn't the other ones solve the issue already? Would be worth taking a look.
Thanks,
--
Jean Delvare
Quoting myself:
Quoted 4 lines
To me, the only acceptable simplification is
the initialization of "last_updated" to something which ensures that the first update attempt will succeed - providing we actually can do that.
On second thought, we obviously cannot, because jiffies wrap, so there is no single initial value of "last_updated", either relative or absolute, which can ensure this condition to be true. I think we are stuck we this "valid" flag, or at least with the concept thereof. Possibly we can use "last_updated" itself as a flag if we absolutely want to get rid of "valid". "last_updated == 0" would mean the same as "valid == 0" did. The probability of "last_updated" to become 0 again after init time is obviously thin, and it wouldn't really hurt if it did (it would simply allow an extra update to happen). That said, this makes the code somewhat trickier.
What could (and should) be done anyway is to use time_after() or something equivalent for the jiffies checks, instead of direct coparison, in all hardware monitoring drivers.
Thanks,
--
Jean Delvare
Quoted 10 lines · Jean Delvare
Quoted 3 lines
What about making
sis5595_update_device()a simple jiffies-related wrapper around function that updates "struct sis5595" unconditionally. I'm not sure I pluggedsis5595_do_update_clientright, but you'll get the idea.1* It forces a chip update (i.e. full register read) on driver load (or more precisely on client detection). Since I2C/SMBus accesses are really slow, it will result in a significant time penalty. As the read values are only considered valid for 1.5 second (or equivalent duration for the other drivers), this penalty brings statistically no benefit in return.
Quoted 3 lines
2* Each subsequent update (or attempt thereof) will conditionally require an additional function call, which represents a small time penalty again (much more than a comparison if I'm not mistaken).
lm90 (all sensors chips have approximately the same speed, right?) spec says:
"It takes the LM90 31.25 ms to measure the temperature of the remote diod and internal diode". Google says: "The buses [I2C, SMBus] operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions."
What I'm trying to say that you shouldn't care about s/cmp; jcc/call/ if the actual measurement is infinite from CPU's POV.
Quoted 2 lines
We are only trying to avoid a conditional test and to get rid of a local variable, and end up with a much slower init
Well, yes, I agree that initialization will become slower. But how long is register read (from first outb command to the moment when CPU sees it)? I'm trying to build time hierarchy of things we're discussing in my head.
Alexey
Hi Alexey,
Quoted 2 lines
lm90 (all sensors chips have approximately the same speed, right?) spec says:
Absolutely not, it depends on the raw speed (internal clock) and the number of channels. But in fact it doesn't matter, see below.
Quoted 2 lines
"It takes the LM90 31.25 ms to measure the temperature of the remote diode and internal diode".
This is completely unrelated to the time it takes to read the registers. The temperature (or other) measurements are done in the backgroud, continuously, by the hardware monitoring chips.
Quoted 2 lines
Google says: "The buses [I2C, SMBus] operate at the same speed, up to 100kHz, but the I2C bus has both 400kHz and 2MHz versions."
And this is what matters, because this tells you how much time it takes to read one register. Multiply by the number of registers you need to read (from 4 to 50, depends on the chip) and you have an approximative total of time required by the update function, when the jiffies test succeeds.
In other words, what matters in terms of speed is the SMBus the chip is connected to, not the speed of the chip itself. Typical speed for motherboard SMBus is 16kHz.
Let's look at how things work. These hardware monitoring chip drivers export files to sysfs, which map more or less directly to the registers. When one reads the sysfs file, the driver will attempt to read all registers, cache all values and return the requested one. If an update occured recently (typically less than 2 seconds ago) then the cached value is directly returned instead. The reason why this is implemented that way is that most chips stop monitoring when they receive read requests. If we allowed registers to be read individually and without caching the results, chips could possibly be kept busy forever, which would be dangerous. We also want to avoid SMBus saturation.
Typically, people will read all sysfs files in a row (by running "sensors" or any other hardware monitoring tool). This means that, for a given read series:
1* The first sysfs file read will most probably trigger an update. 2* All the other sysfs file reads will hit the cache.
Quoted 2 lines
What I'm trying to say that you shouldn't care about s/cmp; jcc/call/ if the actual measurement is infinite from CPU's POV.
That's absolutely right, optimizing the case in which the update *will* occur (case 1* above) is worthless because it only occurs once in a series, and is inherently slow. However, we still want to make the cache hits (case 2* above) as fast as possible (IMHO at least) because it can happen several dozen times in a series.
Your proposal actually slows down 1* (additional function call) but not 2*, so I'm fine with that. However, it also implies a mandatory update at init time, which may take several seconds with no benefit, and I am *not* fine with that.
Quoted 3 lines
Well, yes, I agree that initialization will become slower. But how long is register read (from first outb command to the moment when CPU sees it)? I'm trying to build time hierarchy of things we're discussing in my head.
It's not outb/inb but (in the most common case) i2c_smbus_read_byte_data. It *is* damn slow in comparison with any other command, I/O or not. This is why I don't want to add any at init time for no reason.
Thanks,
--
Jean Delvare
Quoted 5 lines · Alexey Dobriyan
Review
Quoted 3 lines
(quoted diff) +2
-0+ dev_err(&s_bridge->dev, "sis5595.ko: Error: Looked for SIS5595 but found unsupported device %.4X\n", *i); + dev_err(&s_bridge->dev, "sis5595.ko: base address not set - upgrade BIOS or use force_addr=0xaddr\n");".ko" isn't needed. "Error: " in the first line too.
You're right. So greg, here is the new patch, that fixes that.
Please apply.
Thanks,
Aurelien
drivers/i2c/chips/Kconfig +12 -0
@@ -262,6 +262,18 @@ This driver can also be built as a module. If so, the module will be called smsc47b397. +config SENSORS_SIS5595 + tristate "Silicon Integrated Systems Corp. SiS5595" + depends on I2C && PCI && EXPERIMENTAL + select I2C_SENSOR + select I2C_ISA + help + If you say yes here you get support for the integrated sensors in + SiS5595 South Bridges. + + This driver can also be built as a module. If so, the module + will be called sis5595. + config SENSORS_SMSC47M1 tristate "SMSC LPC47M10x and compatibles" depends on I2C && EXPERIMENTAL
drivers/i2c/chips/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o +obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
drivers/i2c/chips/sis5595.c +772 -0
772 lines not on this page · raw message
Signature · 4 lines
.''`. Aurelien Jarno GPG: 1024D/F1BCDB73 : :' : Debian GNU/Linux developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
drivers/i2c/chips/sis5595.c line 524
Quoted 1 line · Aurelien Jarno
drivers/i2c/chips/sis5595.c +1
-0+if (force_addr)
Please put a space after the "if" and before the "(". You do this in a number of places.
thanks,
greg k-h
drivers/i2c/chips/sis5595.c line 486
Quoted 9 lines · Aurelien Jarno
drivers/i2c/chips/sis5595.c +9
-0+/* Locate SiS bridge and correct base address for SIS5595 */ +static int sis5595_find_sis (int *address) +{ +u16 val; +int *i; + +if (!(s_bridge = +pci_get_device (PCI_VENDOR_ID_SI ,PCI_DEVICE_ID_SI_503 ,NULL ))) +return -ENODEV ;
You never free the reference you grabbed on the pci_dev here. Please read the docs on how pci_get_device() is to be used, it isn't just a drop in replacement for pci_find_device(), sorry.
drivers/i2c/chips/sis5595.c line 490
Quoted 3 lines
drivers/i2c/chips/sis5595.c +3
-0+/* Look for imposters */ +for (i = blacklist; *i !=0 ; i++) { +if (pci_get_device (PCI_VENDOR_ID_SI , *i,NULL )) {
Same here, you are leaking a reference count.
Why are you not using the pci driver interface instead?
thanks,
greg k-h
Hi Greg & all,
Quoted 14 lines
drivers/i2c/chips/sis5595.c line 486
Quoted 9 lines
drivers/i2c/chips/sis5595.c +9
-0+/* Locate SiS bridge and correct base address for SIS5595 */ +static int sis5595_find_sis (int *address) +{ +u16 val; +int *i; + +if (!(s_bridge = +pci_get_device (PCI_VENDOR_ID_SI ,PCI_DEVICE_ID_SI_503 ,NULL ))) +return -ENODEV ;You never free the reference you grabbed on the
pci_devhere. Please read the docs on howpci_get_device()is to be used, it isn't just a drop in replacement forpci_find_device(), sorry.
Quoted 7 lines
drivers/i2c/chips/sis5595.c line 490
Quoted 3 lines
drivers/i2c/chips/sis5595.c +3
-0+/* Look for imposters */ +for (i = blacklist; *i !=0 ; i++) { +if (pci_get_device (PCI_VENDOR_ID_SI , *i,NULL )) {Same here, you are leaking a reference count.
Why are you not using the pci driver interface instead?
Not sure it exactly answers your question, but the sis5595 much ressembles the via686a in that respect, i.e. it isn't driving a PCI device, merely grabbing the ISA I/O address data from PCI configuration space, then driving that ISA device. I'd guess that whatever was done in via686a (including the recent updates) should work equally well for the sis5595.
Thanks,
--
Jean Delvare