drivers/iio/chemical/sps30_serial.c
Source file repositories/reference/linux-study-clean/drivers/iio/chemical/sps30_serial.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/chemical/sps30_serial.c- Extension
.c- Size
- 10716 bytes
- Lines
- 433
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/completion.hlinux/device.hlinux/errno.hlinux/iio/iio.hlinux/minmax.hlinux/mod_devicetable.hlinux/module.hlinux/serdev.hlinux/types.hsps30.h
Detected Declarations
struct sps30_serial_privfunction sps30_serial_xferfunction sps30_serial_put_bytefunction sps30_serial_get_bytefunction sps30_serial_calc_chksumfunction sps30_serial_prep_framefunction sps30_serial_frame_validfunction sps30_serial_commandfunction sps30_serial_receive_buffunction sps30_serial_start_measfunction sps30_serial_stop_measfunction sps30_serial_resetfunction sps30_serial_read_measfunction sps30_serial_clean_fanfunction sps30_serial_read_cleaning_periodfunction sps30_serial_write_cleaning_periodfunction sps30_serial_show_infofunction sps30_serial_probe
Annotated Snippet
struct sps30_serial_priv {
struct completion new_frame;
unsigned char buf[SPS30_SERIAL_MAX_BUF_SIZE];
size_t num;
bool escaped;
bool done;
};
static int sps30_serial_xfer(struct sps30_state *state, const unsigned char *buf, size_t size)
{
struct serdev_device *serdev = to_serdev_device(state->dev);
struct sps30_serial_priv *priv = state->priv;
int ret;
priv->num = 0;
priv->escaped = false;
priv->done = false;
ret = serdev_device_write(serdev, buf, size, SPS30_SERIAL_TIMEOUT);
if (ret < 0)
return ret;
if (ret != size)
return -EIO;
ret = wait_for_completion_interruptible_timeout(&priv->new_frame, SPS30_SERIAL_TIMEOUT);
if (ret < 0)
return ret;
if (!ret)
return -ETIMEDOUT;
return 0;
}
static const struct {
u8 byte;
u8 byte2;
} sps30_serial_bytes[] = {
{ 0x11, 0x31 },
{ 0x13, 0x33 },
{ 0x7e, 0x5e },
{ 0x7d, 0x5d },
};
static int sps30_serial_put_byte(u8 *buf, u8 byte)
{
int i;
for (i = 0; i < ARRAY_SIZE(sps30_serial_bytes); i++) {
if (sps30_serial_bytes[i].byte != byte)
continue;
buf[0] = SPS30_SERIAL_ESCAPE_CHAR;
buf[1] = sps30_serial_bytes[i].byte2;
return 2;
}
buf[0] = byte;
return 1;
}
static u8 sps30_serial_get_byte(bool escaped, u8 byte2)
{
int i;
if (!escaped)
return byte2;
for (i = 0; i < ARRAY_SIZE(sps30_serial_bytes); i++) {
if (sps30_serial_bytes[i].byte2 != byte2)
continue;
return sps30_serial_bytes[i].byte;
}
return 0;
}
static unsigned char sps30_serial_calc_chksum(const unsigned char *buf, size_t num)
{
unsigned int chksum = 0;
size_t i;
for (i = 0; i < num; i++)
chksum += buf[i];
return ~chksum;
}
Annotation
- Immediate include surface: `linux/completion.h`, `linux/device.h`, `linux/errno.h`, `linux/iio/iio.h`, `linux/minmax.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/serdev.h`.
- Detected declarations: `struct sps30_serial_priv`, `function sps30_serial_xfer`, `function sps30_serial_put_byte`, `function sps30_serial_get_byte`, `function sps30_serial_calc_chksum`, `function sps30_serial_prep_frame`, `function sps30_serial_frame_valid`, `function sps30_serial_command`, `function sps30_serial_receive_buf`, `function sps30_serial_start_meas`.
- 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.