drivers/iio/temperature/mcp9600.c
Source file repositories/reference/linux-study-clean/drivers/iio/temperature/mcp9600.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/temperature/mcp9600.c- Extension
.c- Size
- 16143 bytes
- Lines
- 581
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/bitops.hlinux/bits.hlinux/err.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/irq.hlinux/math.hlinux/minmax.hlinux/mod_devicetable.hlinux/module.hlinux/iio/events.hlinux/iio/iio.hdt-bindings/iio/temperature/thermocouple.h
Detected Declarations
struct mcp_chip_infostruct mcp9600_dataenum mcp9600_alertfunction mcp9600_configfunction mcp9600_readfunction mcp9600_read_rawfunction mcp9600_get_alert_indexfunction mcp9600_read_event_configfunction mcp9600_write_event_configfunction mcp9600_read_threshfunction mcp9600_write_threshfunction mcp9600_alert_handlerfunction mcp9600_alert1_handlerfunction mcp9600_alert2_handlerfunction mcp9600_alert3_handlerfunction mcp9600_alert4_handlerfunction mcp9600_probe_alertsfunction mcp9600_probe
Annotated Snippet
struct mcp_chip_info {
u8 chip_id;
const char *chip_name;
};
struct mcp9600_data {
struct i2c_client *client;
u32 thermocouple_type;
};
static int mcp9600_config(struct mcp9600_data *data)
{
struct i2c_client *client = data->client;
int ret;
u8 cfg;
cfg = FIELD_PREP(MCP9600_SENSOR_TYPE_MASK,
mcp9600_type_map[data->thermocouple_type]);
ret = i2c_smbus_write_byte_data(client, MCP9600_SENSOR_CFG, cfg);
if (ret < 0) {
dev_err(&client->dev, "Failed to set sensor configuration\n");
return ret;
}
return 0;
}
#define MCP9600_CHANNELS(hj_num_ev, hj_ev_spec_off, cj_num_ev, cj_ev_spec_off) \
{ \
{ \
.type = IIO_TEMP, \
.address = MCP9600_HOT_JUNCTION, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE) | \
BIT(IIO_CHAN_INFO_SCALE), \
.event_spec = &mcp9600_events[hj_ev_spec_off], \
.num_event_specs = hj_num_ev, \
}, \
{ \
.type = IIO_TEMP, \
.address = MCP9600_COLD_JUNCTION, \
.channel2 = IIO_MOD_TEMP_AMBIENT, \
.modified = 1, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_SCALE), \
.event_spec = &mcp9600_events[cj_ev_spec_off], \
.num_event_specs = cj_num_ev, \
}, \
}
static const struct iio_chan_spec mcp9600_channels[][2] = {
MCP9600_CHANNELS(0, 0, 0, 0), /* Alerts: - - - - */
MCP9600_CHANNELS(1, 0, 0, 0), /* Alerts: 1 - - - */
MCP9600_CHANNELS(1, 1, 0, 0), /* Alerts: - 2 - - */
MCP9600_CHANNELS(2, 0, 0, 0), /* Alerts: 1 2 - - */
MCP9600_CHANNELS(0, 0, 1, 0), /* Alerts: - - 3 - */
MCP9600_CHANNELS(1, 0, 1, 0), /* Alerts: 1 - 3 - */
MCP9600_CHANNELS(1, 1, 1, 0), /* Alerts: - 2 3 - */
MCP9600_CHANNELS(2, 0, 1, 0), /* Alerts: 1 2 3 - */
MCP9600_CHANNELS(0, 0, 1, 1), /* Alerts: - - - 4 */
MCP9600_CHANNELS(1, 0, 1, 1), /* Alerts: 1 - - 4 */
MCP9600_CHANNELS(1, 1, 1, 1), /* Alerts: - 2 - 4 */
MCP9600_CHANNELS(2, 0, 1, 1), /* Alerts: 1 2 - 4 */
MCP9600_CHANNELS(0, 0, 2, 0), /* Alerts: - - 3 4 */
MCP9600_CHANNELS(1, 0, 2, 0), /* Alerts: 1 - 3 4 */
MCP9600_CHANNELS(1, 1, 2, 0), /* Alerts: - 2 3 4 */
MCP9600_CHANNELS(2, 0, 2, 0), /* Alerts: 1 2 3 4 */
};
static int mcp9600_read(struct mcp9600_data *data,
struct iio_chan_spec const *chan, int *val)
{
int ret;
ret = i2c_smbus_read_word_swapped(data->client, chan->address);
if (ret < 0)
return ret;
*val = sign_extend32(ret, 15);
return 0;
}
static int mcp9600_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
{
struct mcp9600_data *data = iio_priv(indio_dev);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitops.h`, `linux/bits.h`, `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/interrupt.h`, `linux/irq.h`.
- Detected declarations: `struct mcp_chip_info`, `struct mcp9600_data`, `enum mcp9600_alert`, `function mcp9600_config`, `function mcp9600_read`, `function mcp9600_read_raw`, `function mcp9600_get_alert_index`, `function mcp9600_read_event_config`, `function mcp9600_write_event_config`, `function mcp9600_read_thresh`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.