drivers/iio/proximity/sx9324.c
Source file repositories/reference/linux-study-clean/drivers/iio/proximity/sx9324.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/proximity/sx9324.c- Extension
.c- Size
- 34327 bytes
- Lines
- 1166
- 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/acpi.hlinux/bits.hlinux/bitfield.hlinux/delay.hlinux/i2c.hlinux/interrupt.hlinux/kernel.hlinux/log2.hlinux/mod_devicetable.hlinux/module.hlinux/pm.hlinux/property.hlinux/regmap.hlinux/iio/iio.hsx_common.h
Detected Declarations
function sx9324_phase_configuration_showfunction sx9324_read_prox_datafunction sx9324_wait_for_samplefunction sx9324_read_gainfunction sx9324_read_samp_freqfunction sx9324_read_rawfunction sx9324_read_availfunction sx9324_set_samp_freqfunction sx9324_read_threshfunction sx9324_read_hysteresisfunction sx9324_read_far_debouncefunction sx9324_read_close_debouncefunction sx9324_read_event_valfunction sx9324_write_threshfunction sx9324_write_hysteresisfunction sx9324_write_far_debouncefunction sx9324_write_close_debouncefunction sx9324_write_event_valfunction sx9324_write_gainfunction sx9324_write_rawfunction sx9324_init_compensationfunction sx9324_parse_phase_propfunction sx_common_get_raw_register_configfunction sx9324_get_default_regfunction sx9324_check_whoamifunction sx9324_probefunction sx9324_suspendfunction sx9324_resumefunction scoped_guard
Annotated Snippet
switch (dir) {
case IIO_EV_DIR_RISING:
return sx9324_read_far_debounce(data, val);
case IIO_EV_DIR_FALLING:
return sx9324_read_close_debounce(data, val);
default:
return -EINVAL;
}
case IIO_EV_INFO_HYSTERESIS:
return sx9324_read_hysteresis(data, chan, val);
default:
return -EINVAL;
}
}
static int sx9324_write_thresh(struct sx_common_data *data,
const struct iio_chan_spec *chan, int _val)
{
unsigned int reg, val = _val;
reg = SX9324_REG_PROX_CTRL6 + chan->channel / 2;
if (val >= 1)
val = int_sqrt(2 * val);
if (val > 0xff)
return -EINVAL;
guard(mutex)(&data->mutex);
return regmap_write(data->regmap, reg, val);
}
static int sx9324_write_hysteresis(struct sx_common_data *data,
const struct iio_chan_spec *chan, int _val)
{
unsigned int hyst, val = _val;
int ret, pthresh;
ret = sx9324_read_thresh(data, chan, &pthresh);
if (ret < 0)
return ret;
if (val == 0)
hyst = 0;
else if (val >= pthresh >> 2)
hyst = 3;
else if (val >= pthresh >> 3)
hyst = 2;
else if (val >= pthresh >> 4)
hyst = 1;
else
return -EINVAL;
hyst = FIELD_PREP(SX9324_REG_PROX_CTRL5_HYST_MASK, hyst);
guard(mutex)(&data->mutex);
return regmap_update_bits(data->regmap, SX9324_REG_PROX_CTRL5,
SX9324_REG_PROX_CTRL5_HYST_MASK, hyst);
}
static int sx9324_write_far_debounce(struct sx_common_data *data, int _val)
{
unsigned int regval, val = _val;
if (val > 0)
val = ilog2(val);
if (!FIELD_FIT(SX9324_REG_PROX_CTRL5_FAR_DEBOUNCE_MASK, val))
return -EINVAL;
regval = FIELD_PREP(SX9324_REG_PROX_CTRL5_FAR_DEBOUNCE_MASK, val);
guard(mutex)(&data->mutex);
return regmap_update_bits(data->regmap, SX9324_REG_PROX_CTRL5,
SX9324_REG_PROX_CTRL5_FAR_DEBOUNCE_MASK,
regval);
}
static int sx9324_write_close_debounce(struct sx_common_data *data, int _val)
{
unsigned int regval, val = _val;
if (val > 0)
val = ilog2(val);
if (!FIELD_FIT(SX9324_REG_PROX_CTRL5_CLOSE_DEBOUNCE_MASK, val))
return -EINVAL;
regval = FIELD_PREP(SX9324_REG_PROX_CTRL5_CLOSE_DEBOUNCE_MASK, val);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/bits.h`, `linux/bitfield.h`, `linux/delay.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/log2.h`.
- Detected declarations: `function sx9324_phase_configuration_show`, `function sx9324_read_prox_data`, `function sx9324_wait_for_sample`, `function sx9324_read_gain`, `function sx9324_read_samp_freq`, `function sx9324_read_raw`, `function sx9324_read_avail`, `function sx9324_set_samp_freq`, `function sx9324_read_thresh`, `function sx9324_read_hysteresis`.
- 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.