drivers/iio/amplifiers/hmc425a.c
Source file repositories/reference/linux-study-clean/drivers/iio/amplifiers/hmc425a.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/amplifiers/hmc425a.c- Extension
.c- Size
- 10517 bytes
- Lines
- 426
- 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/bits.hlinux/bitops.hlinux/device.hlinux/err.hlinux/gpio/consumer.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/kernel.hlinux/math.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/slab.hlinux/regulator/consumer.hlinux/sysfs.h
Detected Declarations
struct hmc425a_chip_infostruct hmc425a_stateenum hmc425a_typefunction gain_dB_to_codefunction hmc425a_gain_dB_to_codefunction hmc540s_gain_dB_to_codefunction adrf5740_gain_dB_to_codefunction ltc6373_gain_dB_to_codefunction code_to_gain_dBfunction hmc425a_code_to_gain_dBfunction hmc540s_code_to_gain_dBfunction adrf5740_code_to_gain_dBfunction ltc6373_code_to_gain_dBfunction hmc425a_writefunction hmc425a_read_rawfunction hmc425a_write_rawfunction hmc425a_write_raw_get_fmtfunction ltc6373_read_powerdownfunction ltc6373_write_powerdownfunction hmc425a_probe
Annotated Snippet
struct hmc425a_chip_info {
const char *name;
const struct iio_chan_spec *channels;
unsigned int num_channels;
unsigned int num_gpios;
int gain_min;
int gain_max;
int default_gain;
int powerdown_val;
bool has_powerdown;
int (*gain_dB_to_code)(int gain, int *code);
int (*code_to_gain_dB)(int code, int *val, int *val2);
};
struct hmc425a_state {
struct mutex lock; /* protect sensor state */
const struct hmc425a_chip_info *chip_info;
struct gpio_descs *gpios;
u32 gain;
bool powerdown;
};
static int gain_dB_to_code(struct hmc425a_state *st, int val, int val2, int *code)
{
const struct hmc425a_chip_info *inf = st->chip_info;
int gain;
if (val < 0)
gain = (val * 1000) - (val2 / 1000);
else
gain = (val * 1000) + (val2 / 1000);
if (gain > inf->gain_max || gain < inf->gain_min)
return -EINVAL;
if (st->powerdown)
return -EPERM;
return st->chip_info->gain_dB_to_code(gain, code);
}
static int hmc425a_gain_dB_to_code(int gain, int *code)
{
*code = ~((abs(gain) / 500) & 0x3F);
return 0;
}
static int hmc540s_gain_dB_to_code(int gain, int *code)
{
*code = ~((abs(gain) / 1000) & 0xF);
return 0;
}
static int adrf5740_gain_dB_to_code(int gain, int *code)
{
int temp = (abs(gain) / 2000) & 0xF;
/* Bit [0-3]: 2dB 4dB 8dB 8dB */
*code = temp & BIT(3) ? temp | BIT(2) : temp;
return 0;
}
static int ltc6373_gain_dB_to_code(int gain, int *code)
{
*code = ~(DIV_ROUND_CLOSEST(gain, LTC6373_CONVERSION_CONSTANT) + 3)
& LTC6373_CONVERSION_MASK;
return 0;
}
static int code_to_gain_dB(struct hmc425a_state *st, int *val, int *val2)
{
if (st->powerdown)
return -EPERM;
return st->chip_info->code_to_gain_dB(st->gain, val, val2);
}
static int hmc425a_code_to_gain_dB(int code, int *val, int *val2)
{
*val = (~code * -500) / 1000;
*val2 = ((~code * -500) % 1000) * 1000;
return 0;
}
static int hmc540s_code_to_gain_dB(int code, int *val, int *val2)
{
*val = (~code * -1000) / 1000;
*val2 = ((~code * -1000) % 1000) * 1000;
return 0;
}
Annotation
- Immediate include surface: `linux/bits.h`, `linux/bitops.h`, `linux/device.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/kernel.h`.
- Detected declarations: `struct hmc425a_chip_info`, `struct hmc425a_state`, `enum hmc425a_type`, `function gain_dB_to_code`, `function hmc425a_gain_dB_to_code`, `function hmc540s_gain_dB_to_code`, `function adrf5740_gain_dB_to_code`, `function ltc6373_gain_dB_to_code`, `function code_to_gain_dB`, `function hmc425a_code_to_gain_dB`.
- 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.