drivers/staging/iio/frequency/ad9834.c
Source file repositories/reference/linux-study-clean/drivers/staging/iio/frequency/ad9834.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/iio/frequency/ad9834.c- Extension
.c- Size
- 13511 bytes
- Lines
- 500
- 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/clk.hlinux/interrupt.hlinux/workqueue.hlinux/device.hlinux/kernel.hlinux/slab.hlinux/sysfs.hlinux/list.hlinux/spi/spi.hlinux/regulator/consumer.hlinux/err.hlinux/module.hasm/div64.hlinux/iio/iio.hlinux/iio/sysfs.hdds.h
Detected Declarations
struct ad9834_stateenum ad9834_supported_device_idsfunction ad9834_calc_freqregfunction ad9834_write_frequencyfunction ad9834_write_phasefunction ad9834_writefunction ad9834_store_wavetypefunction ad9834_show_out0_wavetype_availablefunction ad9834_show_out1_wavetype_availablefunction ad9834_probe
Annotated Snippet
struct ad9834_state {
struct spi_device *spi;
struct clk *mclk;
unsigned short control;
unsigned short devid;
struct spi_transfer xfer;
struct spi_message msg;
struct spi_transfer freq_xfer[2];
struct spi_message freq_msg;
struct mutex lock; /* protect sensor state */
/*
* DMA (thus cache coherency maintenance) requires the
* transfer buffers to live in their own cache lines.
*/
__be16 data __aligned(IIO_DMA_MINALIGN);
__be16 freq_data[2];
};
/*
* ad9834_supported_device_ids:
*/
enum ad9834_supported_device_ids {
ID_AD9833,
ID_AD9834,
ID_AD9837,
ID_AD9838,
};
static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout)
{
unsigned long long freqreg = (u64)fout * (u64)BIT(AD9834_FREQ_BITS);
do_div(freqreg, mclk);
return freqreg;
}
static int ad9834_write_frequency(struct ad9834_state *st,
unsigned long addr, unsigned long fout)
{
unsigned long clk_freq;
unsigned long regval;
clk_freq = clk_get_rate(st->mclk);
if (!clk_freq || fout > (clk_freq / 2))
return -EINVAL;
regval = ad9834_calc_freqreg(clk_freq, fout);
st->freq_data[0] = cpu_to_be16(addr | (regval &
RES_MASK(AD9834_FREQ_BITS / 2)));
st->freq_data[1] = cpu_to_be16(addr | ((regval >>
(AD9834_FREQ_BITS / 2)) &
RES_MASK(AD9834_FREQ_BITS / 2)));
return spi_sync(st->spi, &st->freq_msg);
}
static int ad9834_write_phase(struct ad9834_state *st,
unsigned long addr, unsigned long phase)
{
if (phase >= BIT(AD9834_PHASE_BITS))
return -EINVAL;
st->data = cpu_to_be16(addr | phase);
return spi_sync(st->spi, &st->msg);
}
static ssize_t ad9834_write(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t len)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ad9834_state *st = iio_priv(indio_dev);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int ret;
unsigned long val;
ret = kstrtoul(buf, 10, &val);
if (ret)
return ret;
mutex_lock(&st->lock);
switch ((u32)this_attr->address) {
case AD9834_REG_FREQ0:
case AD9834_REG_FREQ1:
ret = ad9834_write_frequency(st, this_attr->address, val);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/interrupt.h`, `linux/workqueue.h`, `linux/device.h`, `linux/kernel.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/list.h`.
- Detected declarations: `struct ad9834_state`, `enum ad9834_supported_device_ids`, `function ad9834_calc_freqreg`, `function ad9834_write_frequency`, `function ad9834_write_phase`, `function ad9834_write`, `function ad9834_store_wavetype`, `function ad9834_show_out0_wavetype_available`, `function ad9834_show_out1_wavetype_available`, `function ad9834_probe`.
- 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.