drivers/iio/proximity/sx_common.c
Source file repositories/reference/linux-study-clean/drivers/iio/proximity/sx_common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/proximity/sx_common.c- Extension
.c- Size
- 14563 bytes
- Lines
- 550
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/bitops.hlinux/byteorder/generic.hlinux/delay.hlinux/device.hlinux/err.hlinux/export.hlinux/interrupt.hlinux/irqreturn.hlinux/i2c.hlinux/kernel.hlinux/module.hlinux/regmap.hlinux/regulator/consumer.hvdso/bits.hlinux/iio/buffer.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/trigger.hlinux/iio/triggered_buffer.hlinux/iio/trigger_consumer.hsx_common.h
Detected Declarations
function sx_common_irq_handlerfunction sx_common_push_eventsfunction for_each_set_bitfunction sx_common_enable_irqfunction sx_common_disable_irqfunction sx_common_update_chan_enfunction sx_common_get_read_channelfunction sx_common_put_read_channelfunction sx_common_get_event_channelfunction sx_common_put_event_channelfunction sx_common_read_proximityfunction sx_common_read_event_configfunction sx_common_write_event_configfunction sx_common_set_trigger_statefunction sx_common_irq_thread_handlerfunction sx_common_trigger_handlerfunction iio_for_each_active_channelfunction sx_common_buffer_preenablefunction sx_common_buffer_postdisablefunction sx_common_init_devicefunction sx_common_probe
Annotated Snippet
if (!(data->chan_event & ~BIT(chan->channel))) {
ret = sx_common_enable_irq(data, eventirq);
if (ret)
sx_common_put_event_channel(data, chan->channel);
}
} else {
ret = sx_common_put_event_channel(data, chan->channel);
if (ret)
goto out_unlock;
if (!data->chan_event) {
ret = sx_common_disable_irq(data, eventirq);
if (ret)
sx_common_get_event_channel(data, chan->channel);
}
}
out_unlock:
mutex_unlock(&data->mutex);
return ret;
}
EXPORT_SYMBOL_NS_GPL(sx_common_write_event_config, "SEMTECH_PROX");
static int sx_common_set_trigger_state(struct iio_trigger *trig, bool state)
{
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
struct sx_common_data *data = iio_priv(indio_dev);
int ret = 0;
mutex_lock(&data->mutex);
if (state)
ret = sx_common_enable_irq(data, SX_COMMON_CONVDONE_IRQ);
else if (!data->chan_read)
ret = sx_common_disable_irq(data, SX_COMMON_CONVDONE_IRQ);
if (ret)
goto out;
data->trigger_enabled = state;
out:
mutex_unlock(&data->mutex);
return ret;
}
static const struct iio_trigger_ops sx_common_trigger_ops = {
.set_trigger_state = sx_common_set_trigger_state,
};
static irqreturn_t sx_common_irq_thread_handler(int irq, void *private)
{
struct iio_dev *indio_dev = private;
struct sx_common_data *data = iio_priv(indio_dev);
int ret;
unsigned int val;
mutex_lock(&data->mutex);
ret = regmap_read(data->regmap, SX_COMMON_REG_IRQ_SRC, &val);
if (ret) {
dev_err(&data->client->dev, "i2c transfer error in irq\n");
goto out;
}
if (val & ((SX_COMMON_FAR_IRQ | SX_COMMON_CLOSE_IRQ) << data->chip_info->irq_msk_offset))
sx_common_push_events(indio_dev);
if (val & (SX_COMMON_CONVDONE_IRQ << data->chip_info->irq_msk_offset))
complete(&data->completion);
out:
mutex_unlock(&data->mutex);
return IRQ_HANDLED;
}
static irqreturn_t sx_common_trigger_handler(int irq, void *private)
{
struct iio_poll_func *pf = private;
struct iio_dev *indio_dev = pf->indio_dev;
struct sx_common_data *data = iio_priv(indio_dev);
__be16 val;
int bit, ret, i = 0;
mutex_lock(&data->mutex);
iio_for_each_active_channel(indio_dev, bit) {
ret = data->chip_info->ops.read_prox_data(data,
&indio_dev->channels[bit],
&val);
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/byteorder/generic.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/export.h`, `linux/interrupt.h`, `linux/irqreturn.h`.
- Detected declarations: `function sx_common_irq_handler`, `function sx_common_push_events`, `function for_each_set_bit`, `function sx_common_enable_irq`, `function sx_common_disable_irq`, `function sx_common_update_chan_en`, `function sx_common_get_read_channel`, `function sx_common_put_read_channel`, `function sx_common_get_event_channel`, `function sx_common_put_event_channel`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration 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.