drivers/iio/chemical/sgp30.c
Source file repositories/reference/linux-study-clean/drivers/iio/chemical/sgp30.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/chemical/sgp30.c- Extension
.c- Size
- 14559 bytes
- Lines
- 588
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/crc8.hlinux/delay.hlinux/kthread.hlinux/module.hlinux/mod_devicetable.hlinux/mutex.hlinux/i2c.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct sgp_versionstruct sgp_crc_wordstruct sgp_datastruct sgp_deviceenum sgp_product_idenum sgp30_channel_idxenum sgpc3_channel_idxenum sgp_cmdenum _iaq_buffer_statefunction sgp_verify_bufferfunction sgp_read_cmdfunction sgp_measure_iaqfunction sgp_iaq_thread_sleep_untilfunction sgp_iaq_threadfnfunction sgp_read_rawfunction sgp_check_compatfunction sgp_initfunction sgp_probefunction sgp_remove
Annotated Snippet
struct sgp_version {
u8 major;
u8 minor;
};
struct sgp_crc_word {
__be16 value;
u8 crc8;
} __attribute__((__packed__));
union sgp_reading {
u8 start;
struct sgp_crc_word raw_words[4];
};
enum _iaq_buffer_state {
IAQ_BUFFER_EMPTY = 0,
IAQ_BUFFER_DEFAULT_VALS,
IAQ_BUFFER_VALID,
};
struct sgp_data {
struct i2c_client *client;
struct task_struct *iaq_thread;
struct mutex data_lock;
unsigned long iaq_init_start_jiffies;
unsigned long iaq_defval_skip_jiffies;
u16 product_id;
u16 feature_set;
unsigned long measure_interval_jiffies;
enum sgp_cmd iaq_init_cmd;
enum sgp_cmd measure_iaq_cmd;
enum sgp_cmd measure_gas_signals_cmd;
union sgp_reading buffer;
union sgp_reading iaq_buffer;
enum _iaq_buffer_state iaq_buffer_state;
};
struct sgp_device {
unsigned long product_id;
const struct iio_chan_spec *channels;
int num_channels;
};
static const struct sgp_version supported_versions_sgp30[] = {
{
.major = 1,
.minor = 0,
},
};
static const struct sgp_version supported_versions_sgpc3[] = {
{
.major = 0,
.minor = 4,
},
};
static const struct iio_chan_spec sgp30_channels[] = {
{
.type = IIO_CONCENTRATION,
.channel2 = IIO_MOD_VOC,
.modified = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
.address = SGP30_IAQ_TVOC_IDX,
},
{
.type = IIO_CONCENTRATION,
.channel2 = IIO_MOD_CO2,
.modified = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
.address = SGP30_IAQ_CO2EQ_IDX,
},
{
.type = IIO_CONCENTRATION,
.channel2 = IIO_MOD_ETHANOL,
.modified = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.address = SGP30_SIG_ETOH_IDX,
},
{
.type = IIO_CONCENTRATION,
.channel2 = IIO_MOD_H2,
.modified = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.address = SGP30_SIG_H2_IDX,
},
};
static const struct iio_chan_spec sgpc3_channels[] = {
Annotation
- Immediate include surface: `linux/crc8.h`, `linux/delay.h`, `linux/kthread.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/mutex.h`, `linux/i2c.h`, `linux/iio/iio.h`.
- Detected declarations: `struct sgp_version`, `struct sgp_crc_word`, `struct sgp_data`, `struct sgp_device`, `enum sgp_product_id`, `enum sgp30_channel_idx`, `enum sgpc3_channel_idx`, `enum sgp_cmd`, `enum _iaq_buffer_state`, `function sgp_verify_buffer`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.