drivers/iio/chemical/sps30_i2c.c
Source file repositories/reference/linux-study-clean/drivers/iio/chemical/sps30_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/chemical/sps30_i2c.c- Extension
.c- Size
- 6628 bytes
- Lines
- 260
- 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/unaligned.hlinux/crc8.hlinux/delay.hlinux/device.hlinux/errno.hlinux/i2c.hlinux/mod_devicetable.hlinux/module.hlinux/types.hsps30.h
Detected Declarations
function sps30_i2c_xferfunction sps30_i2c_commandfunction sps30_i2c_start_measfunction sps30_i2c_stop_measfunction sps30_i2c_resetfunction sps30_i2c_meas_readyfunction sps30_i2c_read_measfunction sps30_i2c_clean_fanfunction sps30_i2c_read_cleaning_periodfunction sps30_i2c_write_cleaning_periodfunction sps30_i2c_show_infofunction sps30_i2c_probe
Annotated Snippet
while (arg_size) {
buf[i] = *tmp++;
buf[i + 1] = *tmp++;
buf[i + 2] = crc8(sps30_i2c_crc8_table, buf + i, 2, CRC8_INIT_VALUE);
arg_size -= 2;
i += 3;
}
}
ret = sps30_i2c_xfer(state, buf, i, buf, rsp_size);
if (ret)
return ret;
/* validate received data and strip off crc bytes */
tmp = rsp;
for (i = 0; i < rsp_size; i += 3) {
crc = crc8(sps30_i2c_crc8_table, buf + i, 2, CRC8_INIT_VALUE);
if (crc != buf[i + 2]) {
dev_err(state->dev, "data integrity check failed\n");
return -EIO;
}
*tmp++ = buf[i];
*tmp++ = buf[i + 1];
}
return 0;
}
static int sps30_i2c_start_meas(struct sps30_state *state)
{
/* request BE IEEE754 formatted data */
unsigned char buf[] = { 0x03, 0x00 };
return sps30_i2c_command(state, SPS30_I2C_START_MEAS, buf, sizeof(buf), NULL, 0);
}
static int sps30_i2c_stop_meas(struct sps30_state *state)
{
return sps30_i2c_command(state, SPS30_I2C_STOP_MEAS, NULL, 0, NULL, 0);
}
static int sps30_i2c_reset(struct sps30_state *state)
{
int ret;
ret = sps30_i2c_command(state, SPS30_I2C_RESET, NULL, 0, NULL, 0);
msleep(500);
/*
* Power-on-reset causes sensor to produce some glitch on i2c bus and
* some controllers end up in error state. Recover simply by placing
* some data on the bus, for example STOP_MEAS command, which
* is NOP in this case.
*/
sps30_i2c_stop_meas(state);
return ret;
}
static bool sps30_i2c_meas_ready(struct sps30_state *state)
{
unsigned char buf[2];
int ret;
ret = sps30_i2c_command(state, SPS30_I2C_MEAS_READY, NULL, 0, buf, sizeof(buf));
if (ret)
return false;
return buf[1];
}
static int sps30_i2c_read_meas(struct sps30_state *state, __be32 *meas, size_t num)
{
/* measurements are ready within a second */
if (msleep_interruptible(1000))
return -EINTR;
if (!sps30_i2c_meas_ready(state))
return -ETIMEDOUT;
return sps30_i2c_command(state, SPS30_I2C_READ_MEAS, NULL, 0, meas, sizeof(*meas) * num);
}
static int sps30_i2c_clean_fan(struct sps30_state *state)
{
return sps30_i2c_command(state, SPS30_I2C_CLEAN_FAN, NULL, 0, NULL, 0);
}
static int sps30_i2c_read_cleaning_period(struct sps30_state *state, __be32 *period)
{
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/crc8.h`, `linux/delay.h`, `linux/device.h`, `linux/errno.h`, `linux/i2c.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `function sps30_i2c_xfer`, `function sps30_i2c_command`, `function sps30_i2c_start_meas`, `function sps30_i2c_stop_meas`, `function sps30_i2c_reset`, `function sps30_i2c_meas_ready`, `function sps30_i2c_read_meas`, `function sps30_i2c_clean_fan`, `function sps30_i2c_read_cleaning_period`, `function sps30_i2c_write_cleaning_period`.
- 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.