drivers/hwmon/pmbus/mp2975.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/pmbus/mp2975.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/pmbus/mp2975.c- Extension
.c- Size
- 29420 bytes
- Lines
- 1107
- 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/bitops.hlinux/err.hlinux/i2c.hlinux/init.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hpmbus.h
Detected Declarations
struct mp2975_driver_infostruct mp2975_dataenum chipsfunction mp2975_read_byte_datafunction mp2975_read_word_helperfunction mp2975_vid2directfunction mp2975_data2reg_linear11function mp2975_read_phasefunction mp2975_read_phasesfunction mp2973_read_word_datafunction mp2973_write_word_datafunction mp2975_read_word_datafunction mp2975_identify_multiphase_rail2function mp2975_set_phase_rail1function mp2975_set_phase_rail2function mp2975_identify_multiphasefunction mp2975_identify_vidfunction mp2975_identify_rails_vidfunction mp2973_identify_rails_vidfunction mp2975_current_sense_gain_getfunction mp2975_vref_getfunction mp2975_vref_offset_getfunction mp2975_vout_max_getfunction mp2975_set_vout_formatfunction mp2975_vout_ov_scale_getfunction mp2975_vout_per_rail_config_getfunction mp2975_probe
Annotated Snippet
struct mp2975_driver_info {
const struct pmbus_driver_info *info;
enum chips chip_id;
};
struct mp2975_data {
struct pmbus_driver_info info;
enum chips chip_id;
int vout_scale;
int max_phases[MP2975_PAGE_NUM];
int vid_step[MP2975_PAGE_NUM];
int vref[MP2975_PAGE_NUM];
int vref_off[MP2975_PAGE_NUM];
int vout_max[MP2975_PAGE_NUM];
int vout_ov_fixed[MP2975_PAGE_NUM];
int curr_sense_gain[MP2975_PAGE_NUM];
};
static const struct regulator_desc __maybe_unused mp2975_reg_desc[] = {
PMBUS_REGULATOR("vout", 0),
PMBUS_REGULATOR("vout", 1),
};
#define to_mp2975_data(x) container_of(x, struct mp2975_data, info)
static int mp2975_read_byte_data(struct i2c_client *client, int page, int reg)
{
switch (reg) {
case PMBUS_VOUT_MODE:
/*
* Report direct format as configured by MFR_DC_LOOP_CTRL.
* Unlike on MP2971/MP2973 the reported VOUT_MODE isn't automatically
* internally updated, but always reads as PB_VOUT_MODE_VID.
*/
return PB_VOUT_MODE_DIRECT;
default:
return -ENODATA;
}
}
static int
mp2975_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
mp2975_vid2direct(int vrf, int val)
{
switch (vrf) {
case vr12:
if (val >= 0x01)
return 250 + (val - 1) * 5;
break;
case vr13:
if (val >= 0x01)
return 500 + (val - 1) * 10;
break;
case imvp9:
if (val >= 0x01)
return 200 + (val - 1) * 10;
break;
default:
return -EINVAL;
}
return 0;
}
#define MAX_LIN_MANTISSA (1023 * 1000)
#define MIN_LIN_MANTISSA (511 * 1000)
/* Converts a milli-unit DIRECT value to LINEAR11 format */
static u16 mp2975_data2reg_linear11(s64 val)
{
s16 exponent = 0, mantissa;
bool negative = false;
/* simple case */
if (val == 0)
return 0;
/* 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 */
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `pmbus.h`.
- Detected declarations: `struct mp2975_driver_info`, `struct mp2975_data`, `enum chips`, `function mp2975_read_byte_data`, `function mp2975_read_word_helper`, `function mp2975_vid2direct`, `function mp2975_data2reg_linear11`, `function mp2975_read_phase`, `function mp2975_read_phases`, `function mp2973_read_word_data`.
- 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.