drivers/staging/iio/impedance-analyzer/ad5933.c
Source file repositories/reference/linux-study-clean/drivers/staging/iio/impedance-analyzer/ad5933.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/iio/impedance-analyzer/ad5933.c- Extension
.c- Size
- 18941 bytes
- Lines
- 757
- Domain
- Driver Families
- Bucket
- drivers/staging
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/clk.hlinux/delay.hlinux/device.hlinux/err.hlinux/i2c.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/regulator/consumer.hlinux/sysfs.hlinux/types.hlinux/iio/buffer.hlinux/iio/iio.hlinux/iio/kfifo_buf.hlinux/iio/sysfs.h
Detected Declarations
struct ad5933_statefunction ad5933_i2c_writefunction ad5933_i2c_readfunction ad5933_cmdfunction ad5933_resetfunction ad5933_wait_busyfunction ad5933_set_freqfunction ad5933_setupfunction ad5933_calc_out_rangesfunction ad5933_show_frequencyfunction ad5933_store_frequencyfunction ad5933_showfunction ad5933_storefunction ad5933_read_rawfunction ad5933_ring_preenablefunction ad5933_ring_postenablefunction ad5933_ring_postdisablefunction ad5933_workfunction ad5933_probe
Annotated Snippet
struct ad5933_state {
struct i2c_client *client;
struct clk *mclk;
struct delayed_work work;
struct mutex lock; /* Protect sensor state */
unsigned long mclk_hz;
unsigned char ctrl_hb;
unsigned char ctrl_lb;
unsigned int range_avail[4];
unsigned short vref_mv;
unsigned short settling_cycles;
unsigned short freq_points;
unsigned int freq_start;
unsigned int freq_inc;
unsigned int state;
unsigned int poll_time_jiffies;
};
#define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
_scan_index, _realbits) { \
.type = (_type), \
.extend_name = (_extend_name), \
.info_mask_separate = (_info_mask_separate), \
.address = (_address), \
.scan_index = (_scan_index), \
.scan_type = { \
.sign = 's', \
.realbits = (_realbits), \
.storagebits = 16, \
}, \
}
static const struct iio_chan_spec ad5933_channels[] = {
AD5933_CHANNEL(IIO_TEMP, NULL, BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE), AD5933_REG_TEMP_DATA, -1, 14),
/* Ring Channels */
AD5933_CHANNEL(IIO_VOLTAGE, "real", 0, AD5933_REG_REAL_DATA, 0, 16),
AD5933_CHANNEL(IIO_VOLTAGE, "imag", 0, AD5933_REG_IMAG_DATA, 1, 16),
};
static int ad5933_i2c_write(struct i2c_client *client, u8 reg, u8 len, u8 *data)
{
int ret;
while (len--) {
ret = i2c_smbus_write_byte_data(client, reg++, *data++);
if (ret < 0) {
dev_err(&client->dev, "I2C write error\n");
return ret;
}
}
return 0;
}
static int ad5933_i2c_read(struct i2c_client *client, u8 reg, u8 len, u8 *data)
{
int ret;
while (len--) {
ret = i2c_smbus_read_byte_data(client, reg++);
if (ret < 0) {
dev_err(&client->dev, "I2C read error\n");
return ret;
}
*data++ = ret;
}
return 0;
}
static int ad5933_cmd(struct ad5933_state *st, unsigned char cmd)
{
unsigned char dat = st->ctrl_hb | cmd;
return ad5933_i2c_write(st->client,
AD5933_REG_CONTROL_HB, 1, &dat);
}
static int ad5933_reset(struct ad5933_state *st)
{
unsigned char dat = st->ctrl_lb | AD5933_CTRL_RESET;
return ad5933_i2c_write(st->client,
AD5933_REG_CONTROL_LB, 1, &dat);
}
static int ad5933_wait_busy(struct ad5933_state *st, unsigned char event)
{
unsigned char val, timeout = AD5933_MAX_RETRIES;
int ret;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/kernel.h`.
- Detected declarations: `struct ad5933_state`, `function ad5933_i2c_write`, `function ad5933_i2c_read`, `function ad5933_cmd`, `function ad5933_reset`, `function ad5933_wait_busy`, `function ad5933_set_freq`, `function ad5933_setup`, `function ad5933_calc_out_ranges`, `function ad5933_show_frequency`.
- Atlas domain: Driver Families / drivers/staging.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.