drivers/iio/proximity/sx9500.c
Source file repositories/reference/linux-study-clean/drivers/iio/proximity/sx9500.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/proximity/sx9500.c- Extension
.c- Size
- 25298 bytes
- Lines
- 1049
- 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/kernel.hlinux/slab.hlinux/module.hlinux/i2c.hlinux/irq.hlinux/acpi.hlinux/gpio/consumer.hlinux/regmap.hlinux/pm.hlinux/delay.hlinux/iio/iio.hlinux/iio/buffer.hlinux/iio/sysfs.hlinux/iio/events.hlinux/iio/trigger.hlinux/iio/triggered_buffer.hlinux/iio/trigger_consumer.h
Detected Declarations
struct sx9500_datastruct sx9500_reg_defaultfunction sx9500_inc_usersfunction sx9500_dec_usersfunction sx9500_inc_chan_usersfunction sx9500_dec_chan_usersfunction sx9500_inc_data_rdy_usersfunction sx9500_dec_data_rdy_usersfunction sx9500_inc_close_far_usersfunction sx9500_dec_close_far_usersfunction sx9500_read_prox_datafunction sx9500_wait_for_samplefunction sx9500_read_proximityfunction sx9500_read_samp_freqfunction sx9500_read_rawfunction sx9500_set_samp_freqfunction sx9500_write_rawfunction sx9500_irq_handlerfunction sx9500_push_eventsfunction sx9500_irq_thread_handlerfunction sx9500_read_event_configfunction sx9500_write_event_configfunction sx9500_set_trigger_statefunction sx9500_trigger_handlerfunction iio_for_each_active_channelfunction sx9500_buffer_postenablefunction sx9500_buffer_predisablefunction sx9500_init_compensationfunction sx9500_init_devicefunction sx9500_gpio_probefunction sx9500_probefunction sx9500_removefunction sx9500_suspendfunction sx9500_resume
Annotated Snippet
struct sx9500_data {
struct mutex mutex;
struct i2c_client *client;
struct iio_trigger *trig;
struct regmap *regmap;
struct gpio_desc *gpiod_rst;
/*
* Last reading of the proximity status for each channel. We
* only send an event to user space when this changes.
*/
bool prox_stat[SX9500_NUM_CHANNELS];
bool event_enabled[SX9500_NUM_CHANNELS];
bool trigger_enabled;
/* Remember enabled channels and sample rate during suspend. */
unsigned int suspend_ctrl0;
struct completion completion;
int data_rdy_users, close_far_users;
int channel_users[SX9500_NUM_CHANNELS];
};
static const struct iio_event_spec sx9500_events[] = {
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_EITHER,
.mask_separate = BIT(IIO_EV_INFO_ENABLE),
},
};
#define SX9500_CHANNEL(idx) \
{ \
.type = IIO_PROXIMITY, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
.indexed = 1, \
.channel = idx, \
.event_spec = sx9500_events, \
.num_event_specs = ARRAY_SIZE(sx9500_events), \
.scan_index = idx, \
.scan_type = { \
.sign = 'u', \
.realbits = 16, \
.storagebits = 16, \
.shift = 0, \
}, \
}
static const struct iio_chan_spec sx9500_channels[] = {
SX9500_CHANNEL(0),
SX9500_CHANNEL(1),
SX9500_CHANNEL(2),
SX9500_CHANNEL(3),
IIO_CHAN_SOFT_TIMESTAMP(4),
};
static const struct {
int val;
int val2;
} sx9500_samp_freq_table[] = {
{33, 333333},
{16, 666666},
{11, 111111},
{8, 333333},
{6, 666666},
{5, 0},
{3, 333333},
{2, 500000},
};
static const unsigned int sx9500_scan_period_table[] = {
30, 60, 90, 120, 150, 200, 300, 400,
};
static const struct regmap_range sx9500_writable_reg_ranges[] = {
regmap_reg_range(SX9500_REG_IRQ_MSK, SX9500_REG_IRQ_MSK),
regmap_reg_range(SX9500_REG_PROX_CTRL0, SX9500_REG_PROX_CTRL8),
regmap_reg_range(SX9500_REG_SENSOR_SEL, SX9500_REG_SENSOR_SEL),
regmap_reg_range(SX9500_REG_OFFSET_MSB, SX9500_REG_OFFSET_LSB),
regmap_reg_range(SX9500_REG_RESET, SX9500_REG_RESET),
};
static const struct regmap_access_table sx9500_writeable_regs = {
.yes_ranges = sx9500_writable_reg_ranges,
.n_yes_ranges = ARRAY_SIZE(sx9500_writable_reg_ranges),
};
/*
* All allocated registers are readable, so we just list unallocated
* ones.
*/
static const struct regmap_range sx9500_non_readable_reg_ranges[] = {
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/module.h`, `linux/i2c.h`, `linux/irq.h`, `linux/acpi.h`, `linux/gpio/consumer.h`, `linux/regmap.h`.
- Detected declarations: `struct sx9500_data`, `struct sx9500_reg_default`, `function sx9500_inc_users`, `function sx9500_dec_users`, `function sx9500_inc_chan_users`, `function sx9500_dec_chan_users`, `function sx9500_inc_data_rdy_users`, `function sx9500_dec_data_rdy_users`, `function sx9500_inc_close_far_users`, `function sx9500_dec_close_far_users`.
- 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.