drivers/iio/accel/bma220_core.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/accel/bma220_core.c
Extension
.c
Size
15471 bytes
Lines
586
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 bma220_data {
	struct regmap *regmap;
	struct mutex lock;
	u8 lpf_3dB_freq_idx;
	u8 range_idx;
	struct iio_trigger *trig;
	struct {
		s8 chans[3];
		/* Ensure timestamp is naturally aligned. */
		aligned_s64 timestamp;
	} scan __aligned(IIO_DMA_MINALIGN);
};

static const struct iio_chan_spec bma220_channels[] = {
	BMA220_ACCEL_CHANNEL(0, BMA220_REG_ACCEL_X, X),
	BMA220_ACCEL_CHANNEL(1, BMA220_REG_ACCEL_Y, Y),
	BMA220_ACCEL_CHANNEL(2, BMA220_REG_ACCEL_Z, Z),
	IIO_CHAN_SOFT_TIMESTAMP(3),
};

/* Available cut-off frequencies of the low pass filter in Hz. */
static const int bma220_lpf_3dB_freq_Hz_table[] = {
	[BMA220_COF_1000Hz] = 1000,
	[BMA220_COF_500Hz] = 500,
	[BMA220_COF_250Hz] = 250,
	[BMA220_COF_125Hz] = 125,
	[BMA220_COF_64Hz] = 64,
	[BMA220_COF_32Hz] = 32,
};

static const unsigned long bma220_accel_scan_masks[] = {
	BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
	0
};

static bool bma220_is_writable_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case BMA220_REG_CONF0:
	case BMA220_REG_CONF1:
	case BMA220_REG_CONF2:
	case BMA220_REG_CONF3:
	case BMA220_REG_CONF4:
	case BMA220_REG_CONF5:
	case BMA220_REG_IE0:
	case BMA220_REG_IE1:
	case BMA220_REG_IE2:
	case BMA220_REG_FILTER:
	case BMA220_REG_RANGE:
	case BMA220_REG_WDT:
		return true;
	default:
		return false;
	}
}

const struct regmap_config bma220_spi_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.read_flag_mask = BIT(7),
	.max_register = BMA220_REG_SOFTRESET,
	.cache_type = REGCACHE_NONE,
	.writeable_reg = bma220_is_writable_reg,
};
EXPORT_SYMBOL_NS_GPL(bma220_spi_regmap_config, "IIO_BOSCH_BMA220");

/*
 * Based on the datasheet the memory map differs between the SPI and the I2C
 * implementations. I2C register addresses are simply shifted to the left
 * by 1 bit yet the register size remains unchanged.
 * This driver employs the SPI memory map to correlate register names to
 * addresses regardless of the bus type.
 */

const struct regmap_config bma220_i2c_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.reg_shift = -1,
	.max_register = BMA220_REG_SOFTRESET,
	.cache_type = REGCACHE_NONE,
	.writeable_reg = bma220_is_writable_reg,
};
EXPORT_SYMBOL_NS_GPL(bma220_i2c_regmap_config, "IIO_BOSCH_BMA220");

static int bma220_data_rdy_trigger_set_state(struct iio_trigger *trig,
					     bool state)
{
	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
	struct bma220_data *data = iio_priv(indio_dev);

Annotation

Implementation Notes