drivers/iio/gyro/adxrs290.c

Source file repositories/reference/linux-study-clean/drivers/iio/gyro/adxrs290.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/gyro/adxrs290.c
Extension
.c
Size
17750 bytes
Lines
707
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 adxrs290_state {
	struct spi_device	*spi;
	/* Serialize reads and their subsequent processing */
	struct mutex		lock;
	enum adxrs290_mode	mode;
	unsigned int		lpf_3db_freq_idx;
	unsigned int		hpf_3db_freq_idx;
	struct iio_trigger      *dready_trig;
	/* Ensure correct alignment of timestamp when present */
	struct {
		s16 channels[3];
		aligned_s64 ts;
	} buffer;
};

/*
 * Available cut-off frequencies of the low pass filter in Hz.
 * The integer part and fractional part are represented separately.
 */
static const int adxrs290_lpf_3db_freq_hz_table[][2] = {
	[0] = {480, 0},
	[1] = {320, 0},
	[2] = {160, 0},
	[3] = {80, 0},
	[4] = {56, 600000},
	[5] = {40, 0},
	[6] = {28, 300000},
	[7] = {20, 0},
};

/*
 * Available cut-off frequencies of the high pass filter in Hz.
 * The integer part and fractional part are represented separately.
 */
static const int adxrs290_hpf_3db_freq_hz_table[][2] = {
	[0] = {0, 0},
	[1] = {0, 11000},
	[2] = {0, 22000},
	[3] = {0, 44000},
	[4] = {0, 87000},
	[5] = {0, 175000},
	[6] = {0, 350000},
	[7] = {0, 700000},
	[8] = {1, 400000},
	[9] = {2, 800000},
	[10] = {11, 300000},
};

static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int *val)
{
	struct adxrs290_state *st = iio_priv(indio_dev);
	int ret = 0;
	int temp;

	mutex_lock(&st->lock);
	temp = spi_w8r16(st->spi, cmd);
	if (temp < 0) {
		ret = temp;
		goto err_unlock;
	}

	*val = sign_extend32(temp, 15);

err_unlock:
	mutex_unlock(&st->lock);
	return ret;
}

static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val)
{
	const u8 cmd = ADXRS290_READ_REG(ADXRS290_REG_TEMP0);
	struct adxrs290_state *st = iio_priv(indio_dev);
	int ret = 0;
	int temp;

	mutex_lock(&st->lock);
	temp = spi_w8r16(st->spi, cmd);
	if (temp < 0) {
		ret = temp;
		goto err_unlock;
	}

	/* extract lower 12 bits temperature reading */
	*val = sign_extend32(temp, 11);

err_unlock:
	mutex_unlock(&st->lock);
	return ret;
}

Annotation

Implementation Notes