drivers/iio/frequency/adf4350.c
Source file repositories/reference/linux-study-clean/drivers/iio/frequency/adf4350.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/frequency/adf4350.c- Extension
.c- Size
- 18572 bytes
- Lines
- 714
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/property.hlinux/slab.hlinux/sysfs.hlinux/spi/spi.hlinux/regulator/consumer.hlinux/err.hlinux/gcd.hlinux/gpio/consumer.hasm/div64.hlinux/clk.hlinux/clk-provider.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/frequency/adf4350.h
Detected Declarations
struct adf4350_statefunction adf4350_sync_configfunction adf4350_reg_accessfunction adf4350_tune_r_cntfunction adf4350_set_freqfunction adf4350_writefunction adf4350_readfunction adf4350_clk_del_providerfunction adf4350_clk_recalc_ratefunction adf4350_clk_set_ratefunction adf4350_clk_preparefunction adf4350_clk_unpreparefunction adf4350_clk_is_enabledfunction adf4350_clk_registerfunction adf4350_power_downfunction adf4350_probe
Annotated Snippet
struct adf4350_state {
struct spi_device *spi;
struct gpio_desc *lock_detect_gpiod;
struct adf4350_platform_data *pdata;
struct clk *clk;
struct clk *clkout;
const char *clk_out_name;
struct clk_hw hw;
unsigned long clkin;
unsigned long chspc; /* Channel Spacing */
unsigned long fpfd; /* Phase Frequency Detector */
unsigned long min_out_freq;
unsigned r0_fract;
unsigned r0_int;
unsigned r1_mod;
unsigned r4_rf_div_sel;
unsigned long regs[6];
unsigned long regs_hw[6];
unsigned long long freq_req;
/*
* Lock to protect the state of the device from potential concurrent
* writes. The device is configured via a sequence of SPI writes,
* and this lock is meant to prevent the start of another sequence
* before another one has finished.
*/
struct mutex lock;
/*
* DMA (thus cache coherency maintenance) may require that
* transfer buffers live in their own cache lines.
*/
__be32 val __aligned(IIO_DMA_MINALIGN);
};
#define to_adf4350_state(_hw) container_of(_hw, struct adf4350_state, hw)
static struct adf4350_platform_data default_pdata = {
.channel_spacing = 10000,
.r2_user_settings = ADF4350_REG2_PD_POLARITY_POS |
ADF4350_REG2_CHARGE_PUMP_CURR_uA(2500),
.r3_user_settings = ADF4350_REG3_12BIT_CLKDIV_MODE(0),
.r4_user_settings = ADF4350_REG4_OUTPUT_PWR(3) |
ADF4350_REG4_MUTE_TILL_LOCK_EN,
};
static int adf4350_sync_config(struct adf4350_state *st)
{
int ret, i, doublebuf = 0;
for (i = ADF4350_REG5; i >= ADF4350_REG0; i--) {
if ((st->regs_hw[i] != st->regs[i]) ||
((i == ADF4350_REG0) && doublebuf)) {
switch (i) {
case ADF4350_REG1:
case ADF4350_REG4:
doublebuf = 1;
break;
}
st->val = cpu_to_be32(st->regs[i] | i);
ret = spi_write(st->spi, &st->val, 4);
if (ret < 0)
return ret;
st->regs_hw[i] = st->regs[i];
dev_dbg(&st->spi->dev, "[%d] 0x%X\n",
i, (u32)st->regs[i] | i);
}
}
return 0;
}
static int adf4350_reg_access(struct iio_dev *indio_dev,
unsigned reg, unsigned writeval,
unsigned *readval)
{
struct adf4350_state *st = iio_priv(indio_dev);
int ret;
if (reg > ADF4350_REG5)
return -EINVAL;
mutex_lock(&st->lock);
if (readval == NULL) {
st->regs[reg] = writeval & ~(BIT(0) | BIT(1) | BIT(2));
ret = adf4350_sync_config(st);
} else {
*readval = st->regs_hw[reg];
ret = 0;
}
mutex_unlock(&st->lock);
Annotation
- Immediate include surface: `linux/device.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/property.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/spi/spi.h`.
- Detected declarations: `struct adf4350_state`, `function adf4350_sync_config`, `function adf4350_reg_access`, `function adf4350_tune_r_cnt`, `function adf4350_set_freq`, `function adf4350_write`, `function adf4350_read`, `function adf4350_clk_del_provider`, `function adf4350_clk_recalc_rate`, `function adf4350_clk_set_rate`.
- 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.
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.