drivers/iio/temperature/tmp117.c
Source file repositories/reference/linux-study-clean/drivers/iio/temperature/tmp117.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/temperature/tmp117.c- Extension
.c- Size
- 5665 bytes
- Lines
- 231
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/err.hlinux/i2c.hlinux/module.hlinux/bitops.hlinux/types.hlinux/kernel.hlinux/limits.hlinux/property.hlinux/regulator/consumer.hlinux/iio/iio.h
Detected Declarations
struct tmp117_datastruct tmp11x_infofunction tmp117_read_rawfunction tmp117_write_rawfunction tmp117_probe
Annotated Snippet
struct tmp117_data {
struct i2c_client *client;
s16 calibbias;
};
struct tmp11x_info {
const char *name;
struct iio_chan_spec const *channels;
int num_channels;
};
static int tmp117_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *channel, int *val,
int *val2, long mask)
{
struct tmp117_data *data = iio_priv(indio_dev);
s32 ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = i2c_smbus_read_word_swapped(data->client,
TMP117_REG_TEMP);
if (ret < 0)
return ret;
*val = sign_extend32(ret, 15);
return IIO_VAL_INT;
case IIO_CHAN_INFO_CALIBBIAS:
ret = i2c_smbus_read_word_swapped(data->client,
TMP117_REG_TEMP_OFFSET);
if (ret < 0)
return ret;
*val = sign_extend32(ret, 15);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
/*
* Conversion from 10s of uC to mC
* as IIO reports temperature in mC
*/
*val = TMP117_RESOLUTION_10UC / MICRODEGREE_PER_10MILLIDEGREE;
*val2 = (TMP117_RESOLUTION_10UC %
MICRODEGREE_PER_10MILLIDEGREE) * 100;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
}
static int tmp117_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec
const *channel, int val, int val2, long mask)
{
struct tmp117_data *data = iio_priv(indio_dev);
s16 off;
switch (mask) {
case IIO_CHAN_INFO_CALIBBIAS:
off = clamp_t(int, val, S16_MIN, S16_MAX);
if (off == data->calibbias)
return 0;
data->calibbias = off;
return i2c_smbus_write_word_swapped(data->client,
TMP117_REG_TEMP_OFFSET, off);
default:
return -EINVAL;
}
}
static const struct iio_chan_spec tmp117_channels[] = {
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_CALIBBIAS) |
BIT(IIO_CHAN_INFO_SCALE),
},
};
static const struct iio_chan_spec tmp116_channels[] = {
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE),
},
};
static const struct tmp11x_info tmp116_channels_info = {
.name = "tmp116",
Annotation
- Immediate include surface: `linux/delay.h`, `linux/err.h`, `linux/i2c.h`, `linux/module.h`, `linux/bitops.h`, `linux/types.h`, `linux/kernel.h`, `linux/limits.h`.
- Detected declarations: `struct tmp117_data`, `struct tmp11x_info`, `function tmp117_read_raw`, `function tmp117_write_raw`, `function tmp117_probe`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
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.