drivers/iio/light/si1133.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/si1133.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/si1133.c- Extension
.c- Size
- 25383 bytes
- Lines
- 1076
- 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/delay.hlinux/i2c.hlinux/interrupt.hlinux/module.hlinux/regmap.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/util_macros.hlinux/unaligned.h
Detected Declarations
struct si1133_datastruct si1133_coeffstruct si1133_lux_coeffenum si1133_int_timefunction si1133_calculate_polynomial_innerfunction si1133_calculate_outputfunction si1133_calc_polynomialfunction si1133_cmd_reset_swfunction si1133_parse_response_errfunction si1133_cmd_reset_counterfunction si1133_commandfunction si1133_param_setfunction si1133_param_queryfunction si1133_get_int_time_indexfunction si1133_set_integration_timefunction si1133_set_chlistfunction si1133_chan_set_adcconfigfunction si1133_update_adcconfigfunction si1133_set_adcmuxfunction si1133_force_measurementfunction si1133_bulk_readfunction si1133_measurefunction si1133_threaded_irq_handlerfunction si1133_scale_to_swgainfunction si1133_chan_set_adcsensfunction si1133_update_adcsensfunction si1133_get_luxfunction si1133_read_rawfunction si1133_write_rawfunction si1133_init_lux_channelsfunction si1133_initializefunction si1133_validate_idsfunction si1133_probe
Annotated Snippet
struct si1133_data {
struct regmap *regmap;
struct i2c_client *client;
/* Lock protecting one command at a time can be processed */
struct mutex mutex;
int rsp_seq;
u8 scan_mask;
u8 adc_sens[6];
u8 adc_config[6];
struct completion completion;
};
struct si1133_coeff {
s16 info;
u16 mag;
};
struct si1133_lux_coeff {
struct si1133_coeff coeff_high[4];
struct si1133_coeff coeff_low[9];
};
static const struct si1133_lux_coeff lux_coeff = {
{
{ 0, 209},
{ 1665, 93},
{ 2064, 65},
{-2671, 234}
},
{
{ 0, 0},
{ 1921, 29053},
{-1022, 36363},
{ 2320, 20789},
{ -367, 57909},
{-1774, 38240},
{ -608, 46775},
{-1503, 51831},
{-1886, 58928}
}
};
static int si1133_calculate_polynomial_inner(s32 input, u8 fraction, u16 mag,
s8 shift)
{
return ((input << fraction) / mag) << shift;
}
static int si1133_calculate_output(s32 x, s32 y, u8 x_order, u8 y_order,
u8 input_fraction, s8 sign,
const struct si1133_coeff *coeffs)
{
s8 shift;
int x1 = 1;
int x2 = 1;
int y1 = 1;
int y2 = 1;
shift = ((u16)coeffs->info & 0xFF00) >> 8;
shift ^= 0xFF;
shift += 1;
shift = -shift;
if (x_order > 0) {
x1 = si1133_calculate_polynomial_inner(x, input_fraction,
coeffs->mag, shift);
if (x_order > 1)
x2 = x1;
}
if (y_order > 0) {
y1 = si1133_calculate_polynomial_inner(y, input_fraction,
coeffs->mag, shift);
if (y_order > 1)
y2 = y1;
}
return sign * x1 * x2 * y1 * y2;
}
/*
* The algorithm is from:
* https://siliconlabs.github.io/Gecko_SDK_Doc/efm32zg/html/si1133_8c_source.html#l00716
*/
static int si1133_calc_polynomial(s32 x, s32 y, u8 input_fraction, u8 num_coeff,
const struct si1133_coeff *coeffs)
{
Annotation
- Immediate include surface: `linux/delay.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/module.h`, `linux/regmap.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/util_macros.h`.
- Detected declarations: `struct si1133_data`, `struct si1133_coeff`, `struct si1133_lux_coeff`, `enum si1133_int_time`, `function si1133_calculate_polynomial_inner`, `function si1133_calculate_output`, `function si1133_calc_polynomial`, `function si1133_cmd_reset_sw`, `function si1133_parse_response_err`, `function si1133_cmd_reset_counter`.
- 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.