drivers/iio/magnetometer/tmag5273.c
Source file repositories/reference/linux-study-clean/drivers/iio/magnetometer/tmag5273.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/magnetometer/tmag5273.c- Extension
.c- Size
- 19680 bytes
- Lines
- 736
- 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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/bits.hlinux/delay.hlinux/module.hlinux/i2c.hlinux/regmap.hlinux/pm_runtime.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct tmag5273_dataenum tmag5273_channelsenum tmag5273_scale_indexfunction tmag5273_get_measurefunction tmag5273_write_osrfunction tmag5273_write_scalefunction tmag5273_read_availfunction tmag5273_read_rawfunction tmag5273_write_rawfunction tmag5273_volatile_regfunction tmag5273_set_operating_modefunction tmag5273_read_device_propertyfunction tmag5273_wake_upfunction tmag5273_chip_initfunction tmag5273_check_device_idfunction tmag5273_power_downfunction tmag5273_probefunction tmag5273_runtime_suspendfunction tmag5273_runtime_resume
Annotated Snippet
struct tmag5273_data {
struct device *dev;
unsigned int devid;
unsigned int version;
char name[16];
unsigned int conv_avg;
enum tmag5273_scale_index scale_index;
unsigned int angle_measurement;
struct regmap *map;
/*
* Locks the sensor 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.
*/
struct mutex lock;
};
static const char *const tmag5273_angle_names[] = { "off", "x-y", "y-z", "x-z" };
/*
* Averaging enables additional sampling of the sensor data to reduce the noise
* effect, but also increases conversion time.
*/
static const unsigned int tmag5273_avg_table[] = {
1, 2, 4, 8, 16, 32,
};
/*
* Magnetic resolution in Gauss for different TMAG5273 versions.
* Scale[Gauss] = Range[mT] * 1000 / 2^15 * 10, (1 mT = 10 Gauss)
* Only version 1 and 2 are valid, version 0 and 3 are reserved.
*/
static const struct iio_val_int_plus_micro tmag5273_scale[][MAGN_RANGE_NUM] = {
{ { 0, 0 }, { 0, 0 } },
{ { 0, 12200 }, { 0, 24400 } },
{ { 0, 40600 }, { 0, 81200 } },
{ { 0, 0 }, { 0, 0 } },
};
static int tmag5273_get_measure(struct tmag5273_data *data, s16 *t, s16 *x,
s16 *y, s16 *z, u16 *angle, u16 *magnitude)
{
unsigned int status, val;
__be16 reg_data[4];
int ret;
mutex_lock(&data->lock);
/*
* Max. conversion time is 2425 us in 32x averaging mode for all three
* channels. Since we are in continuous measurement mode, a measurement
* may already be there, so poll for completed measurement with
* timeout.
*/
ret = regmap_read_poll_timeout(data->map, TMAG5273_CONV_STATUS, status,
status & TMAG5273_CONV_STATUS_COMPLETE,
100, 10000);
if (ret) {
dev_err(data->dev, "timeout waiting for measurement\n");
goto out_unlock;
}
ret = regmap_bulk_read(data->map, TMAG5273_T_MSB_RESULT, reg_data,
sizeof(reg_data));
if (ret)
goto out_unlock;
*t = be16_to_cpu(reg_data[0]);
*x = be16_to_cpu(reg_data[1]);
*y = be16_to_cpu(reg_data[2]);
*z = be16_to_cpu(reg_data[3]);
ret = regmap_bulk_read(data->map, TMAG5273_ANGLE_RESULT_MSB,
®_data[0], sizeof(reg_data[0]));
if (ret)
goto out_unlock;
/*
* angle has 9 bits integer value and 4 bits fractional part
* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
* 0 0 0 a a a a a a a a a f f f f
*/
*angle = be16_to_cpu(reg_data[0]);
ret = regmap_read(data->map, TMAG5273_MAGNITUDE_RESULT, &val);
if (ret < 0)
goto out_unlock;
*magnitude = val;
out_unlock:
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/delay.h`, `linux/module.h`, `linux/i2c.h`, `linux/regmap.h`, `linux/pm_runtime.h`, `linux/iio/iio.h`.
- Detected declarations: `struct tmag5273_data`, `enum tmag5273_channels`, `enum tmag5273_scale_index`, `function tmag5273_get_measure`, `function tmag5273_write_osr`, `function tmag5273_write_scale`, `function tmag5273_read_avail`, `function tmag5273_read_raw`, `function tmag5273_write_raw`, `function tmag5273_volatile_reg`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.