drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

Source file repositories/reference/linux-study-clean/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
Extension
.c
Size
64105 bytes
Lines
2271
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 (mask & INV_MPU6050_SENSOR_ACCL) {
			if (en)
				pwr_mgmt2 &= ~INV_MPU6050_BIT_PWR_ACCL_STBY;
			else
				pwr_mgmt2 |= INV_MPU6050_BIT_PWR_ACCL_STBY;
		}
		if (mask & INV_MPU6050_SENSOR_GYRO) {
			if (en)
				pwr_mgmt2 &= ~INV_MPU6050_BIT_PWR_GYRO_STBY;
			else
				pwr_mgmt2 |= INV_MPU6050_BIT_PWR_GYRO_STBY;
		}

		/* switch clock to internal when turning gyro off */
		if (mask & INV_MPU6050_SENSOR_GYRO && !en) {
			ret = inv_mpu6050_clock_switch(st, INV_CLK_INTERNAL);
			if (ret)
				return ret;
		}

		/* update sensors engine */
		dev_dbg(regmap_get_device(st->map), "pwr_mgmt_2: 0x%x\n",
			pwr_mgmt2);
		ret = regmap_write(st->map, st->reg->pwr_mgmt_2, pwr_mgmt2);
		if (ret)
			return ret;
		if (mask & INV_MPU6050_SENSOR_ACCL)
			st->chip_config.accl_en = en;
		if (mask & INV_MPU6050_SENSOR_GYRO)
			st->chip_config.gyro_en = en;

		/* compute required time to have sensors stabilized */
		sleep = 0;
		if (en) {
			if (mask & INV_MPU6050_SENSOR_ACCL) {
				if (sleep < st->hw->startup_time.accel)
					sleep = st->hw->startup_time.accel;
			}
			if (mask & INV_MPU6050_SENSOR_GYRO) {
				if (sleep < st->hw->startup_time.gyro)
					sleep = st->hw->startup_time.gyro;
			}
		} else {
			if (mask & INV_MPU6050_SENSOR_GYRO) {
				if (sleep < INV_MPU6050_GYRO_DOWN_TIME)
					sleep = INV_MPU6050_GYRO_DOWN_TIME;
			}
		}
		if (sleep)
			msleep(sleep);

		/* switch clock to PLL when turning gyro on */
		if (mask & INV_MPU6050_SENSOR_GYRO && en) {
			ret = inv_mpu6050_clock_switch(st, INV_CLK_PLL);
			if (ret)
				return ret;
		}
	}

	/* enable/disable accel intelligence control */
	if (mask & INV_MPU6050_SENSOR_WOM) {
		val = en ? INV_MPU6500_BIT_ACCEL_INTEL_EN |
			   INV_MPU6500_BIT_ACCEL_INTEL_MODE : 0;
		ret = regmap_write(st->map, INV_MPU6500_REG_ACCEL_INTEL_CTRL, val);
		if (ret)
			return ret;
		st->chip_config.wom_en = en;
	}

	return 0;
}

static int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st,
				     bool power_on)
{
	int result;

	result = inv_mpu6050_pwr_mgmt_1_write(st, !power_on, false, -1, -1);
	if (result)
		return result;

	if (power_on)
		usleep_range(INV_MPU6050_REG_UP_TIME_MIN,
			     INV_MPU6050_REG_UP_TIME_MAX);

	return 0;
}

static int inv_mpu6050_set_gyro_fsr(struct inv_mpu6050_state *st,
				    enum inv_mpu6050_fsr_e val)

Annotation

Implementation Notes