drivers/iio/accel/adxl380.c

Source file repositories/reference/linux-study-clean/drivers/iio/accel/adxl380.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/accel/adxl380.c
Extension
.c
Size
49468 bytes
Lines
2006
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 adxl380_state {
	struct regmap *regmap;
	struct device *dev;
	const struct adxl380_chip_info *chip_info;
	/*
	 * Synchronize access to members of driver state, and ensure atomicity
	 * of consecutive regmap operations.
	 */
	struct mutex lock;
	enum adxl380_axis tap_axis_en;
	u8 range;
	u8 odr;
	u8 fifo_set_size;
	u8 transf_buf[3];
	u16 watermark;
	u32 act_time_ms;
	u32 act_threshold;
	u32 inact_time_ms;
	u32 inact_threshold;
	u32 tap_latent_us;
	u32 tap_window_us;
	u32 tap_duration_us;
	u32 tap_threshold;
	int irq;
	int int_map[2];
	int lpf_tbl[4];
	int hpf_tbl[7][2];

	__be16 fifo_buf[ADXL380_FIFO_SAMPLES] __aligned(IIO_DMA_MINALIGN);
};

bool adxl380_readable_noinc_reg(struct device *dev, unsigned int reg)
{
	return reg == ADXL380_FIFO_DATA;
}
EXPORT_SYMBOL_NS_GPL(adxl380_readable_noinc_reg, "IIO_ADXL380");

static int adxl380_act_inact_enabled(struct adxl380_state *st, bool *enabled)
{
	unsigned int act_inact_ctl;
	int ret;

	if (!st->chip_info->has_low_power) {
		*enabled = false;
		return 0;
	}

	ret = regmap_read(st->regmap, ADXL380_ACT_INACT_CTL_REG, &act_inact_ctl);
	if (ret)
		return ret;

	*enabled = FIELD_GET(ADXL380_ACT_EN_MSK, act_inact_ctl) ||
		   FIELD_GET(ADXL380_INACT_EN_MSK, act_inact_ctl);

	return 0;
}

static int adxl380_set_measure_en(struct adxl380_state *st, bool en)
{
	int ret;
	u8 op_mode = ADXL380_OP_MODE_STANDBY;

	if (en) {
		bool act_inact_enabled;

		ret = adxl380_act_inact_enabled(st, &act_inact_enabled);
		if (ret)
			return ret;

		/*
		 * Activity/Inactivity detection available only in VLP/ULP
		 * mode and for devices that support low power modes.
		 */
		if (act_inact_enabled)
			st->odr = ADXL380_ODR_VLP;

		if (st->odr == ADXL380_ODR_VLP)
			op_mode = ADXL380_OP_MODE_VLP;
		else
			op_mode = ADXL380_OP_MODE_HP;
	}

	return regmap_update_bits(st->regmap, ADXL380_OP_MODE_REG,
				 ADXL380_OP_MODE_MSK,
				 FIELD_PREP(ADXL380_OP_MODE_MSK, op_mode));
}

static void adxl380_scale_act_inact_thresholds(struct adxl380_state *st,
					       u8 old_range,
					       u8 new_range)

Annotation

Implementation Notes