drivers/iio/accel/adxl313_core.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/accel/adxl313_core.c
Extension
.c
Size
35388 bytes
Lines
1329
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

if (type == ADXL313_INACTIVITY || type == ADXL313_INACTIVITY_AC) {
			ret = regmap_read(data->regmap,
					  ADXL313_REG_TIME_INACT,
					  &inact_time_s);
			if (ret)
				return ret;

			if (!inact_time_s)
				return 0;
		}
	} else {
		/*
		 * When turning off an activity, ensure that the correct
		 * coupling event is specified. This step helps prevent misuse -
		 * for example, if an AC-coupled activity is active and the
		 * current call attempts to turn off a DC-coupled activity, this
		 * inconsistency should be detected here.
		 */
		if (adxl313_is_act_inact_ac(data, type) <= 0)
			return 0;
	}

	/* Start modifying configuration registers */
	ret = adxl313_set_measure_en(data, false);
	if (ret)
		return ret;

	/* Enable axis according to the command */
	switch (type) {
	case ADXL313_ACTIVITY:
	case ADXL313_ACTIVITY_AC:
		axis_ctrl = ADXL313_ACT_XYZ_EN;
		break;
	case ADXL313_INACTIVITY:
	case ADXL313_INACTIVITY_AC:
		axis_ctrl = ADXL313_INACT_XYZ_EN;
		break;
	default:
		return -EINVAL;
	}
	ret = regmap_assign_bits(data->regmap, ADXL313_REG_ACT_INACT_CTL,
				 axis_ctrl, cmd_en);
	if (ret)
		return ret;

	/* Update AC/DC-coupling according to the command */
	ret = adxl313_set_act_inact_ac(data, type, cmd_en);
	if (ret)
		return ret;

	/* Enable the interrupt line, according to the command */
	ret = regmap_assign_bits(data->regmap, ADXL313_REG_INT_ENABLE,
				 adxl313_act_int_reg[type], cmd_en);
	if (ret)
		return ret;

	/* Set link-bit and auto-sleep only when ACT and INACT are enabled */
	ret = adxl313_set_act_inact_linkbit(data, cmd_en);
	if (ret)
		return ret;

	return adxl313_set_measure_en(data, true);
}

static int adxl313_read_raw(struct iio_dev *indio_dev,
			    struct iio_chan_spec const *chan,
			    int *val, int *val2, long mask)
{
	struct adxl313_data *data = iio_priv(indio_dev);
	unsigned int regval;
	int ret;

	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		ret = adxl313_read_axis(data, chan);
		if (ret < 0)
			return ret;

		*val = sign_extend32(ret, chan->scan_type.realbits - 1);
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		*val = 0;

		*val2 = data->chip_info->scale_factor;

		return IIO_VAL_INT_PLUS_NANO;
	case IIO_CHAN_INFO_CALIBBIAS:
		ret = regmap_read(data->regmap,
				  ADXL313_REG_OFS_AXIS(chan->address), &regval);
		if (ret)

Annotation

Implementation Notes