drivers/iio/light/si1145.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/si1145.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/si1145.c- Extension
.c- Size
- 35269 bytes
- Lines
- 1361
- 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.
- 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/module.hlinux/i2c.hlinux/err.hlinux/slab.hlinux/delay.hlinux/irq.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/iio/buffer.hlinux/util_macros.h
Detected Declarations
struct si1145_part_infostruct si1145_datafunction __si1145_command_resetfunction si1145_commandfunction si1145_param_updatefunction si1145_param_setfunction si1145_param_queryfunction si1145_uncompressfunction si1145_compressfunction si1145_set_meas_ratefunction si1145_read_samp_freqfunction si1145_store_samp_freqfunction si1145_trigger_handlerfunction iio_for_each_active_channelfunction si1145_set_chlistfunction for_each_set_bitfunction si1145_measurefunction si1145_scale_from_adcgainfunction si1145_proximity_adcgain_from_scalefunction si1145_intensity_adcgain_from_scalefunction si1145_read_rawfunction si1145_write_rawfunction BITfunction si1145_initializefunction si1145_buffer_preenablefunction si1145_validate_scan_maskfunction si1145_trigger_set_statefunction si1145_probe_triggerfunction si1145_probe
Annotated Snippet
struct si1145_part_info {
u8 part;
const struct iio_info *iio_info;
const struct iio_chan_spec *channels;
unsigned int num_channels;
unsigned int num_leds;
bool uncompressed_meas_rate;
};
/**
* struct si1145_data - si1145 chip state data
* @client: I2C client
* @lock: mutex to protect shared state.
* @cmdlock: Low-level mutex to protect command execution only
* @rsp_seq: Next expected response number or -1 if counter reset required
* @scan_mask: Saved scan mask to avoid duplicate set_chlist
* @autonomous: If automatic measurements are active (for buffer support)
* @part_info: Part information
* @trig: Pointer to iio trigger
* @meas_rate: Value of MEAS_RATE register. Only set in HW in auto mode
* @buffer: Used to pack data read from sensor.
*/
struct si1145_data {
struct i2c_client *client;
struct mutex lock;
struct mutex cmdlock;
int rsp_seq;
const struct si1145_part_info *part_info;
unsigned long scan_mask;
bool autonomous;
struct iio_trigger *trig;
int meas_rate;
/*
* Ensure timestamp will be naturally aligned if present.
* Maximum buffer size (may be only partly used if not all
* channels are enabled):
* 6*2 bytes channels data + 4 bytes alignment +
* 8 bytes timestamp
*/
u8 buffer[24] __aligned(8);
};
/*
* __si1145_command_reset() - Send CMD_NOP and wait for response 0
*
* Does not modify data->rsp_seq
*
* Return: 0 on success and -errno on error.
*/
static int __si1145_command_reset(struct si1145_data *data)
{
struct device *dev = &data->client->dev;
unsigned long stop_jiffies;
int ret;
ret = i2c_smbus_write_byte_data(data->client, SI1145_REG_COMMAND,
SI1145_CMD_NOP);
if (ret < 0)
return ret;
msleep(SI1145_COMMAND_MINSLEEP_MS);
stop_jiffies = jiffies + SI1145_COMMAND_TIMEOUT_MS * HZ / 1000;
while (true) {
ret = i2c_smbus_read_byte_data(data->client,
SI1145_REG_RESPONSE);
if (ret <= 0)
return ret;
if (time_after(jiffies, stop_jiffies)) {
dev_warn(dev, "timeout on reset\n");
return -ETIMEDOUT;
}
msleep(SI1145_COMMAND_MINSLEEP_MS);
}
}
/*
* si1145_command() - Execute a command and poll the response register
*
* All conversion overflows are reported as -EOVERFLOW
* INVALID_SETTING is reported as -EINVAL
* Timeouts are reported as -ETIMEDOUT
*
* Return: 0 on success or -errno on failure
*/
static int si1145_command(struct si1145_data *data, u8 cmd)
{
struct device *dev = &data->client->dev;
unsigned long stop_jiffies;
int ret;
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/err.h`, `linux/slab.h`, `linux/delay.h`, `linux/irq.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct si1145_part_info`, `struct si1145_data`, `function __si1145_command_reset`, `function si1145_command`, `function si1145_param_update`, `function si1145_param_set`, `function si1145_param_query`, `function si1145_uncompress`, `function si1145_compress`, `function si1145_set_meas_rate`.
- 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.
- 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.