drivers/hwmon/ltc4283.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ltc4283.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ltc4283.c- Extension
.c- Size
- 50789 bytes
- Lines
- 1796
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/auxiliary_bus.hlinux/bitfield.hlinux/bitmap.hlinux/bitops.hlinux/bits.hlinux/debugfs.hlinux/device.hlinux/device/devres.hlinux/hwmon.hlinux/i2c.hlinux/math.hlinux/math64.hlinux/minmax.hlinux/module.hlinux/mod_devicetable.hlinux/property.hlinux/regmap.hlinux/unaligned.hlinux/units.h
Detected Declarations
struct ltc4283_hwmonfunction ltc4283_read_voltage_wordfunction ltc4283_read_voltage_bytefunction ltc4283_in_regfunction ltc4283_read_in_valsfunction ltc4283_read_alarmfunction ltc4283_read_in_alarmfunction ltc4283_read_infunction ltc4283_read_current_wordfunction ltc4283_read_current_bytefunction ltc4283_read_currfunction ltc4283_read_power_wordfunction ltc4283_read_power_bytefunction ltc4283_read_powerfunction ltc4283_read_energyfunction ltc4283_readfunction ltc4283_write_power_bytefunction ltc4283_write_power_wordfunction ltc4283_reset_power_histfunction ltc4283_write_powerfunction ltc4283_write_in_historyfunction ltc4283_write_in_bytefunction ltc4283_reset_in_histfunction ltc4283_write_in_enfunction ltc4283_write_minmaxfunction ltc4283_write_infunction ltc4283_write_curr_bytefunction ltc4283_write_curr_historyfunction ltc4283_write_currfunction ltc4283_energy_enable_setfunction ltc4283_writefunction ltc4283_in_is_visiblefunction ltc4283_curr_is_visiblefunction ltc4283_power_is_visiblefunction ltc4283_is_visiblefunction ltc4283_read_labelsfunction ltc4283_set_max_limitsfunction ltc4283_parse_array_propfunction ltc4283_get_defaultsfunction ltc4283_pgio_configfunction ltc4283_adio_configfunction ltc4283_pin_configfunction ltc4283_setupfunction ltc4283_show_fault_logfunction ltc4283_show_in0_lcrit_fault_logfunction ltc4283_show_in0_crit_fault_logfunction ltc4283_show_fet_bad_fault_logfunction ltc4283_show_fet_short_fault_log
Annotated Snippet
struct ltc4283_hwmon {
struct regmap *map;
struct i2c_client *client;
unsigned long gpio_mask;
unsigned long ch_enable_mask;
/* in microwatt */
unsigned long power_max;
/* in millivolt */
u32 vsense_max;
/* in tenths of microohm*/
u32 rsense;
bool energy_en;
bool ext_fault;
};
static int ltc4283_read_voltage_word(const struct ltc4283_hwmon *st,
u32 reg, u32 fs, long *val)
{
unsigned int __raw;
int ret;
ret = regmap_read(st->map, reg, &__raw);
if (ret)
return ret;
*val = DIV_ROUND_CLOSEST(__raw * fs, BIT(16));
return 0;
}
static int ltc4283_read_voltage_byte(const struct ltc4283_hwmon *st,
u32 reg, u32 fs, long *val)
{
int ret;
u32 in;
ret = regmap_read(st->map, reg, &in);
if (ret)
return ret;
*val = DIV_ROUND_CLOSEST(in * fs, BIT(8));
return 0;
}
static u32 ltc4283_in_reg(u32 attr, u32 channel)
{
switch (attr) {
case hwmon_in_input:
if (channel == LTC4283_CHAN_VPWR)
return LTC4283_VPWR;
if (channel >= LTC4283_CHAN_ADI_1 && channel <= LTC4283_CHAN_DRAIN)
return LTC4283_ADC_2(channel - LTC4283_CHAN_ADI_1);
return LTC4283_ADC_2_DIFF(channel - LTC4283_CHAN_ADIN12);
case hwmon_in_highest:
if (channel == LTC4283_CHAN_VPWR)
return LTC4283_VPWR_MAX;
if (channel >= LTC4283_CHAN_ADI_1 && channel <= LTC4283_CHAN_DRAIN)
return LTC4283_ADC_2_MAX(channel - LTC4283_CHAN_ADI_1);
return LTC4283_ADC_2_MAX_DIFF(channel - LTC4283_CHAN_ADIN12);
case hwmon_in_lowest:
if (channel == LTC4283_CHAN_VPWR)
return LTC4283_VPWR_MIN;
if (channel >= LTC4283_CHAN_ADI_1 && channel <= LTC4283_CHAN_DRAIN)
return LTC4283_ADC_2_MIN(channel - LTC4283_CHAN_ADI_1);
return LTC4283_ADC_2_MIN_DIFF(channel - LTC4283_CHAN_ADIN12);
case hwmon_in_max:
if (channel == LTC4283_CHAN_VPWR)
return LTC4283_VPWR_MAX_TH;
if (channel >= LTC4283_CHAN_ADI_1 && channel <= LTC4283_CHAN_DRAIN)
return LTC4283_ADC_2_MAX_TH(channel - LTC4283_CHAN_ADI_1);
return LTC4283_ADC_2_MAX_TH_DIFF(channel - LTC4283_CHAN_ADIN12);
default:
if (channel == LTC4283_CHAN_VPWR)
return LTC4283_VPWR_MIN_TH;
if (channel >= LTC4283_CHAN_ADI_1 && channel <= LTC4283_CHAN_DRAIN)
return LTC4283_ADC_2_MIN_TH(channel - LTC4283_CHAN_ADI_1);
return LTC4283_ADC_2_MIN_TH_DIFF(channel - LTC4283_CHAN_ADIN12);
}
}
static int ltc4283_read_in_vals(const struct ltc4283_hwmon *st,
u32 attr, u32 channel, long *val)
{
u32 reg = ltc4283_in_reg(attr, channel);
int ret;
if (channel < LTC4283_CHAN_ADIN12) {
if (attr != hwmon_in_max && attr != hwmon_in_min)
return ltc4283_read_voltage_word(st, reg,
LTC4283_ADC2_FS_mV,
val);
Annotation
- Immediate include surface: `linux/auxiliary_bus.h`, `linux/bitfield.h`, `linux/bitmap.h`, `linux/bitops.h`, `linux/bits.h`, `linux/debugfs.h`, `linux/device.h`, `linux/device/devres.h`.
- Detected declarations: `struct ltc4283_hwmon`, `function ltc4283_read_voltage_word`, `function ltc4283_read_voltage_byte`, `function ltc4283_in_reg`, `function ltc4283_read_in_vals`, `function ltc4283_read_alarm`, `function ltc4283_read_in_alarm`, `function ltc4283_read_in`, `function ltc4283_read_current_word`, `function ltc4283_read_current_byte`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
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.