Skip to contentSkip to conversation

driver for mic184 chip

DISCUSSION Frank Beesley 3 participants 8 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

Please find attached the source file (gzip=4k, native.3k) for a mic184 sensor. We have an older driver for the 2.4.2x kernel but it doesn't completely match what your are asking for. I ported it to kernel 2.6.9 using your guides, modified i/o to match what you have requested, and have tested to work on our hardware configuration. Please let me know of any changes that need to be made and when it might incorporated into the standard kernel distribution as we will be moving forward.

I am also working on drivers for ad5321, pca9540, adm1030, and x24165 (all for kernel 2.6.9). We also use DS18B20 and DS2401 one wire devices that I am trying to get working on a ISA bus (through a CPLD). If you are interested in these let me know and I will forward them to you when they are working.

Thanks
Frank Beesley
[email protected]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mic184.c.gz
Type: application/x-gzip
Size: 3964 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20050128/08c6ca9e/mic184.c.gz

#1 lore raw

Hi Frank,

Quoted 8 lines

Please find attached the source file (gzip=4k, native.3k) for a mic184 sensor. We have an older driver for the 2.4.2x kernel but it doesn't completely match what your are asking for. I ported it to kernel 2.6.9 using your guides, modified i/o to match what you have requested, and have tested to work on our hardware configuration. Please let me know of any changes that need to be made and when it might incorporated into the standard kernel distribution as we will be moving forward.

Never heard of that chip before, but it is so similar to the lm75 that it doesn't make any sense to me to add a different driver to the kernel tree to handle it.

The only difference your driver really makes (that I can see) is that it exposes the configuration register to userspace. I don't see much interest in doing so, since the value isn't anything standard so it won't help the regular user. Randomly changing the configuration of the fly isn't exactly clever either, and I can see that you probably never did that yourself since this part of your driver is obviously broken.

So I don't see much added value to your driver when compared with the existing, well tested lm75 driver.

Quoted 5 lines

I am also working on drivers for ad5321, pca9540, adm1030, and x24165 (all for kernel 2.6.9). We also use DS18B20 and DS2401 one wire devices that I am trying to get working on a ISA bus (through a CPLD). If you are interested in these let me know and I will forward them to you when they are working.

Please note that we already have a driver for the ADM1030 in the 2.6 kernel tree.

There is a preliminary driver for the PCA9540 chip in lm_sensor (for 2.4 kernels) but such multiplexer chips would need to integrate deeped into the i2c bus architecture instead of being simple chip drivers like I did. We have plans to do that, part of which are already implemented in lm_sensors, but nothing functional yet as some points of implementation still need to be discussed (wish I had more time...)

For one wire devices, you should take a look at the w1 subsystem which was recently introduced in the 2.6 kernels by Evgeniy Polyakov.

Signature · 2 lines
Jean Delvare
http://khali.linux-fr.org/
#2 lore raw
In reply to Frank Beesley

Hi Frank,

Quoted 7 lines

This chip is from Micrel (http://www.micrel.com/_PDF/mic184.pdf) and is a local/remote thermal supervisor. The data sheet states "This device is a pin-for-pin and and software compatible upgrade for the industry standard LM75." While this is true, the LM75 driver failed to work as we needed when I tested with it. Since we had an older (kernel 2.4.25) driver that did work, I chose to bring it forward instead of debugging/modifying the LM75.

This wasn't the correct choice IMHO. We avoid duplicating code when possible. It would be better to understand why the lm75 driver doesn't work, and fix that. Since the chips are supposedly compatible, I would suspect that the problem is only the detection method. It checks three different things:

1* that unused bits in the configuration register are clear;

2* that the registers cycle over 8-byte boudaries;

3* that addresses 0x04-0x07 aren't real registers, and instead always
return the last read (real) value.

While this heavily relies on the hardware implementation of the chip rather than its specifications, it has proven to be very reliable, at least for the original LM75 chip, which is by far the most used, even though no other hardware monitoring chip ever had that many clones. Anyway, we hardly have any other choice since the LM75 chip and clones do not offer any dedicated identification register, and can be found on a wide, common address range.

I guess that the MIC184 at least fails the unused bits test in the configuration register, since it does actually use them. Also, since it seems that one of the additional bits in the configuration register is actually a status register, it might change, so the register cycling trick could fail too if you are in bad luck - providing that the registers cycle at all, which should be verified first.

You might use i2cdump to check how the MIC184 reacts to unexpected register reads (above address 0x03), so that we can see if it behaves like the original LM75 in that respect or not.

The MIC184 datasheet isn't exactly clear about the additional bits of the configuration register. I think I understand that bit 5 switches to the external temperature sensor and bit 6 disables the interrupt output, while bit 7 would be the status bit. Is that it? I cannot find a clear detailed view of the configuration register.

Quoted 5 lines

I would like to know what is broke about the config register (unless I sent you the wrong version) because I have in fact used it. By default the config register gets loaded with 0x60 (I don't recall what all this configures but it is the default we have used forever) and when our application prepares to use it we set it to 0x40.

The set_temp_conf if defined thanks to the set macro. If you expand it, it will read:

static ssize_t set_temp_conf(struct device *dev, const char *buf, size_t count)

{
	struct i2c_client *client = to_i2c_client(dev);
	struct mic184_data *data = i2c_get_clientdata(client);
	data->temp_conf = TEMP_TO_REG(simple_strtoul(buf, NULL, 10));
	mic184_write_val(client, MIC184_REG_CONF, data->temp_conf);
	return count;
}

The use of the TEMP_TO_REG conversion macro on the configuration register value is unlikely to lead to anything valid.

I'm surprised about the default value of 0x60 you mention, because the datasheet says 0x00 is the default. If the value of 0x60 was set by the BIOS for example, it might be wiser to update the BIOS to write the value you want (0x40) than to do so afterwards at the OS level.

BTW, what system do you have this MIC184 chip on?

Quoted 3 lines

Additional features include (beyond the LM75): remote temp measurement and interrupt status and mask bits for sw polling. If no one needs it, that is fine. Just trying to contribute back.

Well, the first question would be, do *you* need it? Until further notice, you are probably the only user of the MIC184 chip with a linux system. So if you do not personally need the extra features, there is no point in implementing them.

Even if you do, the configuration of the chip depends on the way the chip is wired together on the board (whatever it is) and as such depends on the BIOS. This is the reason why no hardware monitoring driver in the linux 2.6 kernel offers an interface to that kind of configuration. We might offer module parameters (not sysfs interface) to workaround critical BIOS bugs such as an improper fan polarity configuration, but that's about it.

In your specific case, it seems that you could use i2cset to reprogram the chip if updating the BIOS isn't an option. They you should be able to load the lm75 driver with the "force" parameter and it would work fine, as far as I can see. So I think you could go without a separate driver, and even without modifying the lm75 driver.

Don't get me wrong, I really like when people contribute back code they wrote or modified. It just happens that I don't think you are doing the right thing here. For one thing having a separate driver for the MIC184 sounds overkill. For another, exposing the configuration register to userspace doesn't sound sane (e.g. changing the interrupt polarity or disabling interrupts could lead to hardware damage). Configuration belongs to the BIOS because it supposedly knows how the chip is wired, while the driver doesn't.

What we would accept is an update to the lm75 driver that makes it recognize the MIC184 chip, providing that the detection method is reliable enough not to cause misdetections. As a side note, your detection routine for the MIC184 (taken from the datasheet if I'm not mistaken) wouldn't be accepted because it is destructive (you are writing to the registers as part of the detection, which would lead to unpredictable results if the chip happened *not* to be a MIC184). You must find a way to detect the MIC184 chip without writing to the registers. Note that we don't really need to differenciate between the MIC184 and LM75 chips, because they are compatible and the differences are of no importance to the driver code, so the detection method provided by Micrel isn't what we really need here. What is really important is to not misdetect a completely different chip as being a MIC184/LM75. This is why we tried to sharpen the LM75 detection code as much as possible.

Quoted 3 lines

I am looking at the ADM1030/1031 driver currently and having some issues with it that I need to resolve. It appears that no tested it or only had limited configurations for it.

I tested it personally, and so did Alexandre d'Alton (we wrote the driver together), and it appeared to work rather fine for both of us. Please let us know the problems you are having and we'll take a look. The driver is admittedly rather new, so it might not have received as wide a testing as the other drivers did. These two ADM chips aren't exactly simple and we might have missed corner cases.

Thanks,

Signature · 2 lines
Jean Delvare
http://khali.linux-fr.org/
#3 lore raw
In reply to Frank Beesley

Hi Mark,

Quoted 2 lines

since MIC184 has TWO sensors, it should not be added to lm75 IMHO. We shouldn't add a second sensor to the lm75 driver.

It doesn't really have two sensors. It simply can use an external sensor *instead of* the internal one. It cannot use both at the same time. It is certainly possible to design a driver that continuously switches from internal to external and back, but that would require a clever timing and I don't think it's worth the effort. The chip is simply not designed for this use. I invite you to consider all the drawbacks of such a design (delayed interrupt response to overtemperature, need to have the same overtemperature and hysteresis temperature for both "channels", impossibility to know which "channel" caused an alarm/interrupt, and possibly more bad surprises if we were to really write such a driver).

Anyway, I don't think that Frank was interested in this - the mic184.c driver he proposed would only export one set of sysfs files.

Thanks,

Signature · 1 line
Jean Delvare
#4 lore raw
In reply to Frank Beesley
Quoted 16 lines

Hi Frank,

Quoted 10 lines

Please find attached the source file (gzip=4k, native.3k) for a mic184 sensor. We have an older driver for the 2.4.2x kernel but it doesn't completely match what your are asking for. I ported it to kernel 2.6.9 using your guides, modified i/o to match what you have requested, and have tested to work on our hardware configuration. Please let me know of any changes that need to be made and when it might incorporated into the standard kernel distribution as we will be moving forward.

Quoted 6 lines

Never heard of that chip before, but it is so similar to the lm75 that it doesn't make any sense to me to add a different driver to the kernel tree to handle it.

This chip is from Micrel (http://www.micrel.com/_PDF/mic184.pdf) and is a local/remote thermal supervisor. The data sheet states "This device is a pin-for-pin and and software compatible upgrade for the industry standard LM75." While this is true, the LM75 driver failed to work as we needed when I tested with it. Since we had an older (kernel 2.4.25) driver that did work, I chose to bring it forward instead of debugging/modifying the LM75.

Quoted 7 lines

The only difference your driver really makes (that I can see) is that it exposes the configuration register to userspace. I don't see much interest in doing so, since the value isn't anything standard so it won't help the regular user. Randomly changing the configuration of the fly isn't exactly clever either, and I can see that you probably never did that yourself since this part of your driver is obviously broken.

Quoted 5 lines

So I don't see much added value to your driver when compared with the existing, well tested lm75 driver.

I would like to know what is broke about the config register (unless I sent you the wrong version) because I have in fact used it. By default the config register gets loaded with 0x60 (I don't recall what all this configures but it is the default we have used forever) and when our application prepares to use it we set it to 0x40.

Additional features include (beyond the LM75): remote temp measurement and interrupt status and mask bits for sw polling.

If no one needs it, that is fine. Just trying to contribute back.

Quoted 18 lines
Quoted 7 lines

I am also working on drivers for ad5321, pca9540, adm1030, and x24165 (all for kernel 2.6.9). We also use DS18B20 and DS2401 one wire devices that I am trying to get working on a ISA bus (through a CPLD). If you are interested in these let me know and I will forward them to you when they are working.

Please note that we already have a driver for the ADM1030 in the 2.6 kernel tree.

There is a preliminary driver for the PCA9540 chip in lm_sensor (for 2.4 kernels) but such multiplexer chips would need to integrate deeped into the i2c bus architecture instead of being simple chip drivers like I did. We have plans to do that, part of which are already implemented in lm_sensors, but nothing functional yet as some points of implementation still need to be discussed (wish I had more time...)

Quoted 5 lines

For one wire devices, you should take a look at the w1 subsystem which was recently introduced in the 2.6 kernels by Evgeniy Polyakov.

I am looking at the ADM1030/1031 driver currently and having some issues with it that I need to resolve. It appears that no tested it or only had limited configurations for it.

I have briefly looked at w1 from Evgeniy but not to deep yet because of the other drivers.

#5 lore raw
In reply to Frank Beesley

since MIC184 has TWO sensors, it should not be added to lm75 IMHO. We shouldn't add a second sensor to the lm75 driver.

Nor does the chip look similar to ADM1021 or LM90, our drivers supporting chips with two temperature sensors (only), as shown in doc/chips/SUMMARY.

Therefore a separate driver looks correct to me.

mds

Quoted 144 lines · Jean Delvare

Hi Frank,

Quoted 7 lines

This chip is from Micrel (http://www.micrel.com/_PDF/mic184.pdf) and is a local/remote thermal supervisor. The data sheet states "This device is a pin-for-pin and and software compatible upgrade for the industry standard LM75." While this is true, the LM75 driver failed to work as we needed when I tested with it. Since we had an older (kernel 2.4.25) driver that did work, I chose to bring it forward instead of debugging/modifying the LM75.

This wasn't the correct choice IMHO. We avoid duplicating code when possible. It would be better to understand why the lm75 driver doesn't work, and fix that. Since the chips are supposedly compatible, I would suspect that the problem is only the detection method. It checks three different things:

1* that unused bits in the configuration register are clear;

2* that the registers cycle over 8-byte boudaries;

3* that addresses 0x04-0x07 aren't real registers, and instead always
return the last read (real) value.

While this heavily relies on the hardware implementation of the chip rather than its specifications, it has proven to be very reliable, at least for the original LM75 chip, which is by far the most used, even though no other hardware monitoring chip ever had that many clones. Anyway, we hardly have any other choice since the LM75 chip and clones do not offer any dedicated identification register, and can be found on a wide, common address range.

I guess that the MIC184 at least fails the unused bits test in the configuration register, since it does actually use them. Also, since it seems that one of the additional bits in the configuration register is actually a status register, it might change, so the register cycling trick could fail too if you are in bad luck - providing that the registers cycle at all, which should be verified first.

You might use i2cdump to check how the MIC184 reacts to unexpected register reads (above address 0x03), so that we can see if it behaves like the original LM75 in that respect or not.

The MIC184 datasheet isn't exactly clear about the additional bits of the configuration register. I think I understand that bit 5 switches to the external temperature sensor and bit 6 disables the interrupt output, while bit 7 would be the status bit. Is that it? I cannot find a clear detailed view of the configuration register.

Quoted 5 lines

I would like to know what is broke about the config register (unless I sent you the wrong version) because I have in fact used it. By default the config register gets loaded with 0x60 (I don't recall what all this configures but it is the default we have used forever) and when our application prepares to use it we set it to 0x40.

The set_temp_conf if defined thanks to the set macro. If you expand it, it will read:

static ssize_t set_temp_conf(struct device *dev, const char *buf, size_t count)

{
	struct i2c_client *client = to_i2c_client(dev);
	struct mic184_data *data = i2c_get_clientdata(client);
	data->temp_conf = TEMP_TO_REG(simple_strtoul(buf, NULL, 10));
	mic184_write_val(client, MIC184_REG_CONF, data->temp_conf);
	return count;
}

The use of the TEMP_TO_REG conversion macro on the configuration register value is unlikely to lead to anything valid.

I'm surprised about the default value of 0x60 you mention, because the datasheet says 0x00 is the default. If the value of 0x60 was set by the BIOS for example, it might be wiser to update the BIOS to write the value you want (0x40) than to do so afterwards at the OS level.

BTW, what system do you have this MIC184 chip on?

Quoted 3 lines

Additional features include (beyond the LM75): remote temp measurement and interrupt status and mask bits for sw polling. If no one needs it, that is fine. Just trying to contribute back.

Well, the first question would be, do *you* need it? Until further notice, you are probably the only user of the MIC184 chip with a linux system. So if you do not personally need the extra features, there is no point in implementing them.

Even if you do, the configuration of the chip depends on the way the chip is wired together on the board (whatever it is) and as such depends on the BIOS. This is the reason why no hardware monitoring driver in the linux 2.6 kernel offers an interface to that kind of configuration. We might offer module parameters (not sysfs interface) to workaround critical BIOS bugs such as an improper fan polarity configuration, but that's about it.

In your specific case, it seems that you could use i2cset to reprogram the chip if updating the BIOS isn't an option. They you should be able to load the lm75 driver with the "force" parameter and it would work fine, as far as I can see. So I think you could go without a separate driver, and even without modifying the lm75 driver.

Don't get me wrong, I really like when people contribute back code they wrote or modified. It just happens that I don't think you are doing the right thing here. For one thing having a separate driver for the MIC184 sounds overkill. For another, exposing the configuration register to userspace doesn't sound sane (e.g. changing the interrupt polarity or disabling interrupts could lead to hardware damage). Configuration belongs to the BIOS because it supposedly knows how the chip is wired, while the driver doesn't.

What we would accept is an update to the lm75 driver that makes it recognize the MIC184 chip, providing that the detection method is reliable enough not to cause misdetections. As a side note, your detection routine for the MIC184 (taken from the datasheet if I'm not mistaken) wouldn't be accepted because it is destructive (you are writing to the registers as part of the detection, which would lead to unpredictable results if the chip happened *not* to be a MIC184). You must find a way to detect the MIC184 chip without writing to the registers. Note that we don't really need to differenciate between the MIC184 and LM75 chips, because they are compatible and the differences are of no importance to the driver code, so the detection method provided by Micrel isn't what we really need here. What is really important is to not misdetect a completely different chip as being a MIC184/LM75. This is why we tried to sharpen the LM75 detection code as much as possible.

Quoted 3 lines

I am looking at the ADM1030/1031 driver currently and having some issues with it that I need to resolve. It appears that no tested it or only had limited configurations for it.

I tested it personally, and so did Alexandre d'Alton (we wrote the driver together), and it appeared to work rather fine for both of us. Please let us know the problems you are having and we'll take a look. The driver is admittedly rather new, so it might not have received as wide a testing as the other drivers did. These two ADM chips aren't exactly simple and we might have missed corner cases.

Thanks,

#6 lore raw
In reply to Frank Beesley

ok, I get it, I thought it was two at once.
So I agree that small mods to lm75.c would be the best way. In addition to the detection fix,
he could add a modparm that switches from internal to remote if the BIOS didn't do it.

Quoted 22 lines · Jean Delvare

Hi Mark,

Quoted 2 lines

since MIC184 has TWO sensors, it should not be added to lm75 IMHO. We shouldn't add a second sensor to the lm75 driver.

It doesn't really have two sensors. It simply can use an external sensor *instead of* the internal one. It cannot use both at the same time. It is certainly possible to design a driver that continuously switches from internal to external and back, but that would require a clever timing and I don't think it's worth the effort. The chip is simply not designed for this use. I invite you to consider all the drawbacks of such a design (delayed interrupt response to overtemperature, need to have the same overtemperature and hysteresis temperature for both "channels", impossibility to know which "channel" caused an alarm/interrupt, and possibly more bad surprises if we were to really write such a driver).

Anyway, I don't think that Frank was interested in this - the mic184.c driver he proposed would only export one set of sysfs files.

Thanks,

#7 lore raw
In reply to Frank Beesley
Quoted 20 lines · Jean Delvare

Hi Mark,

Quoted 4 lines

since MIC184 has TWO sensors, it should not be added to lm75 IMHO. We shouldn't add a second sensor to the lm75 driver.

It doesn't really have two sensors. It simply can use an external sensor *instead of* the internal one. It cannot use both at the same time. It is certainly possible to design a driver that continuously switches from internal to external and back, but that would require a clever timing and I don't think it's worth the effort. The chip is simply not designed for this use. I invite you to consider all the drawbacks of such a design (delayed interrupt response to overtemperature, need to have the same overtemperature and hysteresis temperature for both "channels", impossibility to know which "channel" caused an alarm/interrupt, and possibly more bad surprises if we were to really write such a driver).

Quoted 6 lines

Anyway, I don't think that Frank was interested in this - the mic184.c driver he proposed would only export one set of sysfs files.

Thanks,

Jean - I guess I sent one version back that did not have the correct set function. That appears to be the only thing different with my latest version. Thats what happens when you pull from a development machine instead of cvs.

Your summary seems to pretty much correct. That's fine. If anybody is looking for this driver in the future, let me know as we will continue to use it ourselves. You did have some good tips that were are going to evaluate.

As far as our target, it is a Kontron CPU module on a custom carrier board. The carrier then connects to a PCI based backplane that has i2c, onewire, pci, cplds, fpgas, multiple ps2 keypads, and other fun hardware. Currently we are running a 2.4.25 (Redhat 9 based) kernel and I am migrating to a 2.6.9 (or later, may go to 10 or 11) kernel.