hwmon gets MCP9808 support

The MCP9808 temperature sensor now has a life in hwmon!

hwmon == Hardware Monitoring subsystem.

hwmon is the subsystem for sensor chips that monitor the system health.  These are typically sensors for temperatures, voltages and fan speeds.  Although both IIO and hwmon support temperature sensors, hwmon is the home of the low sample rate sensors. 

The IIO subsystem maintainer recognized MCP9808 as one of those 'low sample rate' sensors when he saw an earlier blog post.  He suggested I begin the IIO or hwmon subsystem discussion on the appropriate mailing lists: linux-hwmon & linux-iio. I started that thread and subsequently ended my mcp9808 drivers' journey into the IIO subsytem.

Read the iio or hwmon discussion on the linux-iio mailing list.

hwmon already had a driver that could support MCP9808.  It's called jc42 and it supports a class of sensors that are JC-42 compliant.  Although MCP9808 is not JC-42 compliant, its registers are compatible to the standard, so we can treat it as such.  hwmon/jc42 already had MCP9804, a close cousin of MCP9808 supported.

You can see the JC-42 standard here:
http://www.jedec.org/sites/default/files/docs/4_01_04R19.pdf
(Sorry, JEDEC makes you complete a free registration before you can view the PDF.)

This kernel documentation on jc42 driver shows all the JC-42 compliant chips it supports.   We can instantiate the MCP9808 sensor and use it immediately.

I submitted this patch to the hwmon subsystem so that the MCP9808 can also be auto-detected:
[PATCH] hwmon: (jc42) Add support for Microchip MCP9808 temperature sensor

Additional notes from my diversion into hwmon:

1)  hwmon and lm-sensors
I loaded up the lm-sensors package and explored. The lm-sensors package is aimed at allowing you to peek at (and act/react to) the health of your system.  The hwmon drivers support a sysfs interface to the lm-sensors. You can use the sensors-detect script to find out what sensors your system has, and then it tells you which hwmon drivers you need to load in order to start monitoring those sensors via it's other tools. Actually, it does more that just tell you, it's willing to modify your config and do it all magically for you.

Update:  lm-sensors is maintained on github.  I did my first ever github pull request to add MCP9808 info to the sensors-detect script. 

2)  hwmon/jc42 driver implementation
hwmon.jc42 driver implements more features of the MCP9808 sensor than I had prepared.  It was interesting to see how it was implemented.  I had looked at the critical temps and alarms, and assumed I would not be implementing them without implementing alerts or events. I don't know!  I see that jc42 implements them way more simply than I had imagined.  It made me want to go dig back into my mcp9808 driver! 

3)  Standards
The other interesting part of this was the whole standard 'thing'.   While, IIO certainly supports multiple devices with single drivers, I haven't seen a standard for a type or class of sensors.  That doesn't mean it doesn't exist by any means!  I am new to this, certainly there is standards activity. Need to explore more!

Labels: , , , , ,