drivers/hwmon/pmbus/mp2856.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/pmbus/mp2856.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/pmbus/mp2856.c- Extension
.c- Size
- 10840 bytes
- Lines
- 467
- 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/err.hlinux/i2c.hlinux/init.hlinux/kernel.hlinux/module.hlinux/pmbus.hpmbus.h
Detected Declarations
struct mp2856_dataenum chipsfunction val2linear11function mp2856_read_word_helperfunction mp2856_read_voutfunction mp2856_read_phasefunction mp2856_read_phasesfunction mp2856_read_word_datafunction mp2856_read_byte_datafunction mp2856_identify_multiphasefunction mp2856_identify_multiphase_rail1function mp2856_identify_multiphase_rail2function mp2856_current_sense_gain_getfunction mp2856_identify_vout_formatfunction mp2856_is_rail2_activefunction mp2856_probe
Annotated Snippet
struct mp2856_data {
struct pmbus_driver_info info;
int vout_format[MP2856_PAGE_NUM];
int curr_sense_gain[MP2856_PAGE_NUM];
int max_phases[MP2856_PAGE_NUM];
};
#define to_mp2856_data(x) container_of(x, struct mp2856_data, info)
#define MAX_LIN_MANTISSA (1023 * 1000)
#define MIN_LIN_MANTISSA (511 * 1000)
static u16 val2linear11(s64 val)
{
s16 exponent = 0, mantissa;
bool negative = false;
if (val == 0)
return 0;
if (val < 0) {
negative = true;
val = -val;
}
/* Reduce large mantissa until it fits into 10 bit */
while (val >= MAX_LIN_MANTISSA && exponent < 15) {
exponent++;
val >>= 1;
}
/* Increase small mantissa to improve precision */
while (val < MIN_LIN_MANTISSA && exponent > -15) {
exponent--;
val <<= 1;
}
/* Convert mantissa from milli-units to units */
mantissa = clamp_val(DIV_ROUND_CLOSEST_ULL(val, 1000), 0, 0x3ff);
/* restore sign */
if (negative)
mantissa = -mantissa;
/* Convert to 5 bit exponent, 11 bit mantissa */
return (mantissa & 0x7ff) | ((exponent << 11) & 0xf800);
}
static int
mp2856_read_word_helper(struct i2c_client *client, int page, int phase, u8 reg,
u16 mask)
{
int ret = pmbus_read_word_data(client, page, phase, reg);
return (ret > 0) ? ret & mask : ret;
}
static int
mp2856_read_vout(struct i2c_client *client, struct mp2856_data *data, int page,
int phase, u8 reg)
{
int ret;
ret = mp2856_read_word_helper(client, page, phase, reg,
GENMASK(9, 0));
if (ret < 0)
return ret;
/* convert vout result to direct format */
ret = (data->vout_format[page] == vid) ?
((ret + 49) * 5) : ((ret * 1000) >> 8);
return ret;
}
static int
mp2856_read_phase(struct i2c_client *client, struct mp2856_data *data,
int page, int phase, u8 reg)
{
int ret;
int val;
ret = pmbus_read_word_data(client, page, phase, reg);
if (ret < 0)
return ret;
if (!((phase + 1) % MP2856_PAGE_NUM))
ret >>= 8;
ret &= 0xff;
/*
Annotation
- Immediate include surface: `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/pmbus.h`, `pmbus.h`.
- Detected declarations: `struct mp2856_data`, `enum chips`, `function val2linear11`, `function mp2856_read_word_helper`, `function mp2856_read_vout`, `function mp2856_read_phase`, `function mp2856_read_phases`, `function mp2856_read_word_data`, `function mp2856_read_byte_data`, `function mp2856_identify_multiphase`.
- 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.