drivers/iio/pressure/ms5637.c
Source file repositories/reference/linux-study-clean/drivers/iio/pressure/ms5637.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/pressure/ms5637.c- Extension
.c- Size
- 6489 bytes
- Lines
- 252
- 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/init.hlinux/device.hlinux/kernel.hlinux/stat.hlinux/module.hlinux/mod_devicetable.hlinux/i2c.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/mutex.h../common/ms_sensors/ms_sensors_i2c.h
Detected Declarations
struct ms_tp_datafunction ms5637_show_samp_freqfunction ms5637_read_rawfunction ms5637_write_rawfunction ms5637_probe
Annotated Snippet
struct ms_tp_data {
const char *name;
const struct ms_tp_hw_data *hw;
};
static const int ms5637_samp_freq[6] = { 960, 480, 240, 120, 60, 30 };
static ssize_t ms5637_show_samp_freq(struct device *dev, struct device_attribute *attr, char *buf)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ms_tp_dev *dev_data = iio_priv(indio_dev);
int i, len = 0;
for (i = 0; i <= dev_data->hw->max_res_index; i++)
len += sysfs_emit_at(buf, len, "%u ", ms5637_samp_freq[i]);
sysfs_emit_at(buf, len - 1, "\n");
return len;
}
static int ms5637_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *channel, int *val,
int *val2, long mask)
{
int ret;
int temperature;
unsigned int pressure;
struct ms_tp_dev *dev_data = iio_priv(indio_dev);
switch (mask) {
case IIO_CHAN_INFO_PROCESSED:
ret = ms_sensors_read_temp_and_pressure(dev_data,
&temperature,
&pressure);
if (ret)
return ret;
switch (channel->type) {
case IIO_TEMP: /* in milli °C */
*val = temperature;
return IIO_VAL_INT;
case IIO_PRESSURE: /* in kPa */
*val = pressure / 1000;
*val2 = (pressure % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
case IIO_CHAN_INFO_SAMP_FREQ:
*val = ms5637_samp_freq[dev_data->res_index];
return IIO_VAL_INT;
default:
return -EINVAL;
}
}
static int ms5637_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
struct ms_tp_dev *dev_data = iio_priv(indio_dev);
int i;
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
i = ARRAY_SIZE(ms5637_samp_freq);
while (i-- > 0)
if (val == ms5637_samp_freq[i])
break;
if (i < 0)
return -EINVAL;
dev_data->res_index = i;
return 0;
default:
return -EINVAL;
}
}
static const struct iio_chan_spec ms5637_channels[] = {
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
{
.type = IIO_PRESSURE,
Annotation
- Immediate include surface: `linux/init.h`, `linux/device.h`, `linux/kernel.h`, `linux/stat.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/i2c.h`, `linux/iio/iio.h`.
- Detected declarations: `struct ms_tp_data`, `function ms5637_show_samp_freq`, `function ms5637_read_raw`, `function ms5637_write_raw`, `function ms5637_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.