drivers/iio/proximity/rfd77402.c
Source file repositories/reference/linux-study-clean/drivers/iio/proximity/rfd77402.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/proximity/rfd77402.c- Extension
.c- Size
- 10979 bytes
- Lines
- 462
- 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/bits.hlinux/completion.hlinux/delay.hlinux/dev_printk.hlinux/errno.hlinux/i2c.hlinux/interrupt.hlinux/iopoll.hlinux/jiffies.hlinux/module.hlinux/types.hlinux/iio/iio.h
Detected Declarations
struct rfd77402_datafunction rfd77402_interrupt_handlerfunction rfd77402_wait_for_irqfunction rfd77402_set_statefunction rfd77402_wait_for_resultfunction rfd77402_measurefunction rfd77402_read_rawfunction rfd77402_config_irqfunction rfd77402_initfunction rfd77402_powerdownfunction rfd77402_disablefunction rfd77402_probefunction rfd77402_suspendfunction rfd77402_resume
Annotated Snippet
struct rfd77402_data {
struct i2c_client *client;
struct mutex lock;
struct completion completion;
bool irq_en;
};
static const struct iio_chan_spec rfd77402_channels[] = {
{
.type = IIO_DISTANCE,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE),
},
};
static irqreturn_t rfd77402_interrupt_handler(int irq, void *pdata)
{
struct rfd77402_data *data = pdata;
int ret;
ret = i2c_smbus_read_byte_data(data->client, RFD77402_ICSR);
if (ret < 0)
return IRQ_NONE;
/* Check if the interrupt is from our device */
if (!(ret & RFD77402_ICSR_RESULT))
return IRQ_NONE;
/* Signal completion of measurement */
complete(&data->completion);
return IRQ_HANDLED;
}
static int rfd77402_wait_for_irq(struct rfd77402_data *data)
{
int ret;
/*
* According to RFD77402 Datasheet v1.8,
* Section 3.1.1 "Single Measure" (Figure: Single Measure Flow Chart),
* the suggested timeout for single measure is 100 ms.
*/
ret = wait_for_completion_timeout(&data->completion,
msecs_to_jiffies(100));
if (ret == 0)
return -ETIMEDOUT;
return 0;
}
static int rfd77402_set_state(struct i2c_client *client, u8 state, u16 check)
{
int ret;
ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R,
state | RFD77402_CMD_VALID);
if (ret < 0)
return ret;
usleep_range(10000, 20000);
ret = i2c_smbus_read_word_data(client, RFD77402_STATUS_R);
if (ret < 0)
return ret;
if ((ret & RFD77402_STATUS_PM_MASK) != check)
return -ENODEV;
return 0;
}
static int rfd77402_wait_for_result(struct rfd77402_data *data)
{
struct i2c_client *client = data->client;
int val, ret;
if (data->irq_en)
return rfd77402_wait_for_irq(data);
/*
* As per RFD77402 datasheet section '3.1.1 Single Measure', the
* suggested timeout value for single measure is 100ms.
*/
ret = read_poll_timeout(i2c_smbus_read_byte_data, val,
(val < 0) || (val & RFD77402_ICSR_RESULT),
10 * USEC_PER_MSEC,
10 * 10 * USEC_PER_MSEC,
false,
client, RFD77402_ICSR);
if (val < 0)
return val;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/completion.h`, `linux/delay.h`, `linux/dev_printk.h`, `linux/errno.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/iopoll.h`.
- Detected declarations: `struct rfd77402_data`, `function rfd77402_interrupt_handler`, `function rfd77402_wait_for_irq`, `function rfd77402_set_state`, `function rfd77402_wait_for_result`, `function rfd77402_measure`, `function rfd77402_read_raw`, `function rfd77402_config_irq`, `function rfd77402_init`, `function rfd77402_powerdown`.
- 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.