drivers/iio/chemical/sps30.c
Source file repositories/reference/linux-study-clean/drivers/iio/chemical/sps30.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/chemical/sps30.c- Extension
.c- Size
- 8521 bytes
- Lines
- 380
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/crc8.hlinux/delay.hlinux/i2c.hlinux/iio/buffer.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/kernel.hlinux/module.hsps30.h
Detected Declarations
function sps30_float_to_int_clampedfunction sps30_do_measfunction sps30_do_resetfunction sps30_trigger_handlerfunction sps30_read_rawfunction start_cleaning_storefunction cleaning_period_showfunction cleaning_period_storefunction cleaning_period_available_showfunction sps30_devm_stop_measfunction sps30_probe
Annotated Snippet
switch (chan->type) {
case IIO_MASSCONCENTRATION:
mutex_lock(&state->lock);
/* read up to the number of bytes actually needed */
switch (chan->channel2) {
case IIO_MOD_PM1:
ret = sps30_do_meas(state, data, 1);
break;
case IIO_MOD_PM2P5:
ret = sps30_do_meas(state, data, 2);
break;
case IIO_MOD_PM4:
ret = sps30_do_meas(state, data, 3);
break;
case IIO_MOD_PM10:
ret = sps30_do_meas(state, data, 4);
break;
}
mutex_unlock(&state->lock);
if (ret)
return ret;
*val = data[chan->address] / 100;
*val2 = (data[chan->address] % 100) * 10000;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_MASSCONCENTRATION:
switch (chan->channel2) {
case IIO_MOD_PM1:
case IIO_MOD_PM2P5:
case IIO_MOD_PM4:
case IIO_MOD_PM10:
*val = 0;
*val2 = 10000;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
default:
return -EINVAL;
}
}
return -EINVAL;
}
static ssize_t start_cleaning_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct sps30_state *state = iio_priv(indio_dev);
int val, ret;
if (kstrtoint(buf, 0, &val) || val != 1)
return -EINVAL;
mutex_lock(&state->lock);
ret = state->ops->clean_fan(state);
mutex_unlock(&state->lock);
if (ret)
return ret;
return len;
}
static ssize_t cleaning_period_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct sps30_state *state = iio_priv(indio_dev);
__be32 val;
int ret;
mutex_lock(&state->lock);
ret = state->ops->read_cleaning_period(state, &val);
mutex_unlock(&state->lock);
if (ret)
return ret;
return sysfs_emit(buf, "%d\n", be32_to_cpu(val));
}
Annotation
- Immediate include surface: `linux/crc8.h`, `linux/delay.h`, `linux/i2c.h`, `linux/iio/buffer.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/iio/trigger_consumer.h`, `linux/iio/triggered_buffer.h`.
- Detected declarations: `function sps30_float_to_int_clamped`, `function sps30_do_meas`, `function sps30_do_reset`, `function sps30_trigger_handler`, `function sps30_read_raw`, `function start_cleaning_store`, `function cleaning_period_show`, `function cleaning_period_store`, `function cleaning_period_available_show`, `function sps30_devm_stop_meas`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.