drivers/hwmon/pmbus/mp2993.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/pmbus/mp2993.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/pmbus/mp2993.c- Extension
.c- Size
- 7146 bytes
- Lines
- 262
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/module.hlinux/of_device.hpmbus.h
Detected Declarations
function mp2993_linear11_exponent_transferfunction mp2993_set_vout_formatfunction mp2993_identifyfunction mp2993_read_word_datafunction mp2993_write_word_datafunction mp2993_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Hardware monitoring driver for MPS Multi-phase Digital VR Controllers(MP2993)
*/
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include "pmbus.h"
#define MP2993_VOUT_OVUV_UINT 125
#define MP2993_VOUT_OVUV_DIV 64
#define MP2993_VIN_LIMIT_UINT 1
#define MP2993_VIN_LIMIT_DIV 8
#define MP2993_READ_VIN_UINT 1
#define MP2993_READ_VIN_DIV 32
#define MP2993_PAGE_NUM 2
#define MP2993_RAIL1_FUNC (PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | \
PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT | \
PMBUS_HAVE_TEMP | PMBUS_HAVE_PIN | \
PMBUS_HAVE_IIN | \
PMBUS_HAVE_STATUS_VOUT | \
PMBUS_HAVE_STATUS_IOUT | \
PMBUS_HAVE_STATUS_TEMP | \
PMBUS_HAVE_STATUS_INPUT)
#define MP2993_RAIL2_FUNC (PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | \
PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP | \
PMBUS_HAVE_STATUS_VOUT | \
PMBUS_HAVE_STATUS_IOUT | \
PMBUS_HAVE_STATUS_TEMP | \
PMBUS_HAVE_STATUS_INPUT)
/* Converts a linear11 data exponent to a specified value */
static u16 mp2993_linear11_exponent_transfer(u16 word, u16 expect_exponent)
{
s16 exponent, mantissa, target_exponent;
exponent = ((s16)word) >> 11;
mantissa = ((s16)((word & 0x7ff) << 5)) >> 5;
target_exponent = (s16)((expect_exponent & 0x1f) << 11) >> 11;
if (exponent > target_exponent)
mantissa = mantissa << (exponent - target_exponent);
else
mantissa = mantissa >> (target_exponent - exponent);
return (mantissa & 0x7ff) | ((expect_exponent << 11) & 0xf800);
}
static int
mp2993_set_vout_format(struct i2c_client *client, int page, int format)
{
int ret;
ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
if (ret < 0)
return ret;
return i2c_smbus_write_byte_data(client, PMBUS_VOUT_MODE, format);
}
static int mp2993_identify(struct i2c_client *client, struct pmbus_driver_info *info)
{
int ret;
/* Set vout to direct format for rail1. */
ret = mp2993_set_vout_format(client, 0, PB_VOUT_MODE_DIRECT);
if (ret < 0)
return ret;
/* Set vout to direct format for rail2. */
return mp2993_set_vout_format(client, 1, PB_VOUT_MODE_DIRECT);
}
static int mp2993_read_word_data(struct i2c_client *client, int page, int phase,
int reg)
{
int ret;
switch (reg) {
case PMBUS_VOUT_OV_FAULT_LIMIT:
case PMBUS_VOUT_UV_FAULT_LIMIT:
ret = pmbus_read_word_data(client, page, phase, reg);
if (ret < 0)
return ret;
ret = DIV_ROUND_CLOSEST(ret * MP2993_VOUT_OVUV_UINT, MP2993_VOUT_OVUV_DIV);
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/module.h`, `linux/of_device.h`, `pmbus.h`.
- Detected declarations: `function mp2993_linear11_exponent_transfer`, `function mp2993_set_vout_format`, `function mp2993_identify`, `function mp2993_read_word_data`, `function mp2993_write_word_data`, `function mp2993_probe`.
- 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.