drivers/iio/frequency/adrf6780.c

Source file repositories/reference/linux-study-clean/drivers/iio/frequency/adrf6780.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/frequency/adrf6780.c
Extension
.c
Size
13096 bytes
Lines
511
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct adrf6780_state {
	struct spi_device	*spi;
	struct clk		*clkin;
	/* Protect against concurrent accesses to the device */
	struct mutex		lock;
	bool			vga_buff_en;
	bool			lo_buff_en;
	bool			if_mode_en;
	bool			iq_mode_en;
	bool			lo_x2_en;
	bool			lo_ppf_en;
	bool			lo_en;
	bool			uc_bias_en;
	bool			lo_sideband;
	bool			vdet_out_en;
	u8			data[3] __aligned(IIO_DMA_MINALIGN);
};

static int __adrf6780_spi_read(struct adrf6780_state *st, unsigned int reg,
			       unsigned int *val)
{
	int ret;
	struct spi_transfer t = {0};

	st->data[0] = 0x80 | (reg << 1);
	st->data[1] = 0x0;
	st->data[2] = 0x0;

	t.rx_buf = &st->data[0];
	t.tx_buf = &st->data[0];
	t.len = 3;

	ret = spi_sync_transfer(st->spi, &t, 1);
	if (ret)
		return ret;

	*val = (get_unaligned_be24(&st->data[0]) >> 1) & GENMASK(15, 0);

	return ret;
}

static int adrf6780_spi_read(struct adrf6780_state *st, unsigned int reg,
			     unsigned int *val)
{
	int ret;

	mutex_lock(&st->lock);
	ret = __adrf6780_spi_read(st, reg, val);
	mutex_unlock(&st->lock);

	return ret;
}

static int __adrf6780_spi_write(struct adrf6780_state *st,
				unsigned int reg,
				unsigned int val)
{
	put_unaligned_be24((val << 1) | (reg << 17), &st->data[0]);

	return spi_write(st->spi, &st->data[0], 3);
}

static int adrf6780_spi_write(struct adrf6780_state *st, unsigned int reg,
			      unsigned int val)
{
	int ret;

	mutex_lock(&st->lock);
	ret = __adrf6780_spi_write(st, reg, val);
	mutex_unlock(&st->lock);

	return ret;
}

static int __adrf6780_spi_update_bits(struct adrf6780_state *st,
				      unsigned int reg, unsigned int mask,
				      unsigned int val)
{
	int ret;
	unsigned int data, temp;

	ret = __adrf6780_spi_read(st, reg, &data);
	if (ret)
		return ret;

	temp = (data & ~mask) | (val & mask);

	return __adrf6780_spi_write(st, reg, temp);
}

Annotation

Implementation Notes