Build-a-Driver #2: Read Raw

Here's the second patch in the Build-a-Driver series for MCP9808.
(If this post seems out of context, please refer to "Build-a-Driver Introduction" post.)

mcp9808: this version adds read raw temperature support only

To do this we need to define our read raw handler in mcp9808_info that understands one channel type IIO_TEMP, which we have now defined as a channel in indio_dev. We add another register define from the datasheet, MCP9808_REG_TAMBIENT, and use a read_word_swapped that we determined was needed when reading the manuf & device id registers.

We don't do anything with the raw data, just return it.

See our new sysfs channel:
/sys/bus/iio/devices/iio:device0# ls
dev in_temp_raw name power subsystem uevent
/sys/bus/iio/devices/iio:device0# cat name dev

Test output:
raw temp register reading: 49538
celcius temperature calculated 24.1250
calcs positive temps only: (raw & 0x0fff) / 16

(My test is only calculating the positive.   "raw" is in two's compliment format and we will need to
provide support for calc positive & negative in the next patch.)

This version mcp9808-read-raw.c
To view complete revision history go here.

Labels: ,