drivers/iio/magnetometer/yamaha-yas530.c

Source file repositories/reference/linux-study-clean/drivers/iio/magnetometer/yamaha-yas530.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/magnetometer/yamaha-yas530.c
Extension
.c
Size
46503 bytes
Lines
1614
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 yas5xx_calibration {
	/* Linearization calibration x, y1, y2 */
	s32 r[3];
	u32 f[3];
	/* Temperature compensation calibration */
	s16 Cx, Cy1, Cy2;
	/* Misc calibration coefficients */
	s8  a2, a3, a4, a6, a7, a8;
	s16 a5, a9;
	u8  k;
	/* clock divider */
	u8 dck;
};

struct yas5xx;

/**
 * struct yas5xx_chip_info - device-specific data and function pointers
 * @devid: device ID number
 * @product_name: product name of the YAS variant
 * @version_names: version letters or namings
 * @volatile_reg: device-specific volatile registers
 * @volatile_reg_qty: quantity of device-specific volatile registers
 * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE
 * @t_ref: number of counts at reference temperature 20 °C
 * @min_temp_x10: starting point of temperature counting in 1/10:s degrees Celsius
 * @get_measure: function pointer to get a measurement
 * @get_calibration_data: function pointer to get calibration data
 * @dump_calibration: function pointer to dump calibration for debugging
 * @measure_offsets: function pointer to measure the offsets
 * @power_on: function pointer to power-on procedure
 *
 * The "t_ref" value for YAS532/533 is known from the Android driver.
 * For YAS530 and YAS537 it was approximately measured.
 *
 * The temperatures "min_temp_x10" are derived from the temperature resolutions
 * given in the data sheets.
 */
struct yas5xx_chip_info {
	unsigned int devid;
	const char *product_name;
	const char *version_names[2];
	const int *volatile_reg;
	int volatile_reg_qty;
	u32 scaling_val2;
	u16 t_ref;
	s16 min_temp_x10;
	int (*get_measure)(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo);
	int (*get_calibration_data)(struct yas5xx *yas5xx);
	void (*dump_calibration)(struct yas5xx *yas5xx);
	int (*measure_offsets)(struct yas5xx *yas5xx);
	int (*power_on)(struct yas5xx *yas5xx);
};

/**
 * struct yas5xx - state container for the YAS5xx driver
 * @dev: parent device pointer
 * @chip_info: device-specific data and function pointers
 * @version: device version
 * @calibration: calibration settings from the OTP storage
 * @hard_offsets: offsets for each axis measured with initcoil actuated
 * @orientation: mounting matrix, flipped axis etc
 * @map: regmap to access the YAX5xx registers over I2C
 * @regs: the vdd and vddio power regulators
 * @reset: optional GPIO line used for handling RESET
 * @lock: locks the magnetometer for exclusive use during a measurement (which
 * involves several register transactions so the regmap lock is not enough)
 * so that measurements get serialized in a first-come-first serve manner
 * @scan: naturally aligned measurements
 */
struct yas5xx {
	struct device *dev;
	const struct yas5xx_chip_info *chip_info;
	unsigned int version;
	struct yas5xx_calibration calibration;
	s8 hard_offsets[3];
	struct iio_mount_matrix orientation;
	struct regmap *map;
	struct regulator_bulk_data regs[2];
	struct gpio_desc *reset;
	struct mutex lock;
	/*
	 * The scanout is 4 x 32 bits in CPU endianness.
	 * Ensure timestamp is naturally aligned
	 */
	struct {
		s32 channels[4];
		aligned_s64 ts;
	} scan;
};

Annotation

Implementation Notes