Here's the first 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 probes and checks product id only.
This is a mimimal driver that only performs a probe. The probe goes out to the device and confirms is it an MCP9808.
The MCP9808 info is dev_info'd as below. Not clear that is something that will stay in the driver, but it was how I verified we have an MCP9808 at probe time. As I get further in the driver I suspect there may be some other device initialization to do at probe time.
 mcp9808 7-0018: MCP9808 Temperature Sensor
 mcp9808 7-0018: MCP9808 Manuf_id: 0x54, Device_id: 0x04, Rev: 0x0
 i2c i2c-7: new_device: Instantiated device mcp9808 at 0x18
Note, that even though I don't define any channels, some sysfs stuff is set up:
dev in_temp_raw name power subsystem uevent
/sys/bus/iio/devices/iio:device0$ cat name dev
/sys/bus/iio/devices/iio:device0$ cat uevent
/sys/bus/iio/devices/iio:device0$ ls power
async runtime_active_kids runtime_status
autosuspend_delay_ms runtime_active_time runtime_suspended_time
control runtime_enabled runtime_usage
Verified that iio:device0 was removed from /sys/bus/iio/devices/ when I pulled cable.
Finally, the fun stuff: indio_dev really needs that info field defined. Watch for my blog post on my first (and second) kernel oops.
This version mcp9808-probe.c
To view complete revision history go here.
Labels: Build-a-Driver, MCP9808, probe