mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:04:41 +01:00
hwmon: (pmbus) Add mp5926 driver
Add support for mps mp5926. Signed-off-by: Yuxi Wang <Yuxi.Wang@monolithicpower.com> Link: https://lore.kernel.org/r/20251219055413.1661-3-Yuxi.Wang@monolithicpower.com [groeck: Use consistent comment style, and use return value from dev_err_probe()] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
d491cd8e1e
commit
ca2cf35544
6 changed files with 294 additions and 0 deletions
|
|
@ -185,6 +185,7 @@ Hardware Monitoring Kernel Drivers
|
|||
mp2993
|
||||
mp5023
|
||||
mp5920
|
||||
mp5926
|
||||
mp5990
|
||||
mp9941
|
||||
mp9945
|
||||
|
|
|
|||
92
Documentation/hwmon/mp5926.rst
Normal file
92
Documentation/hwmon/mp5926.rst
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Kernel driver mp5926
|
||||
====================
|
||||
|
||||
Supported chips:
|
||||
|
||||
* MPS mp5926
|
||||
|
||||
Prefix: 'mp5926'
|
||||
|
||||
* Datasheet
|
||||
https://www.monolithicpower.com/en/
|
||||
|
||||
Author:
|
||||
|
||||
Yuxi Wang <Yuxi.Wang@monolithicpower.com>
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
This driver implements support for Monolithic Power Systems, Inc. (MPS)
|
||||
MP5926 Hot-Swap Controller.
|
||||
|
||||
Device compliant with:
|
||||
|
||||
- PMBus rev 1.3 interface.
|
||||
|
||||
The driver exports the following attributes via the 'sysfs' files
|
||||
for input voltage:
|
||||
|
||||
**in1_input**
|
||||
|
||||
**in1_label**
|
||||
|
||||
**in1_crit**
|
||||
|
||||
**in1_crit_alarm**
|
||||
|
||||
The driver provides the following attributes for output voltage:
|
||||
|
||||
**in2_input**
|
||||
|
||||
**in2_label**
|
||||
|
||||
**in2_lcrit**
|
||||
|
||||
**in2_lcrit_alarm**
|
||||
|
||||
**in2_rated_max**
|
||||
|
||||
**in2_rated_min**
|
||||
|
||||
The driver provides the following attributes for input current:
|
||||
|
||||
**curr1_input**
|
||||
|
||||
**curr1_label**
|
||||
|
||||
**curr1_max**
|
||||
|
||||
**curr1_max_alarm**
|
||||
|
||||
The driver provides the following attributes for output current:
|
||||
|
||||
**curr2_input**
|
||||
|
||||
**curr2_label**
|
||||
|
||||
The driver provides the following attributes for input power:
|
||||
|
||||
**power1_input**
|
||||
|
||||
**power1_label**
|
||||
|
||||
The driver provides the following attributes for output power:
|
||||
|
||||
**power2_input**
|
||||
|
||||
**power2_label**
|
||||
|
||||
The driver provides the following attributes for temperature:
|
||||
|
||||
**temp1_input**
|
||||
|
||||
**temp1_crit**
|
||||
|
||||
**temp1_crit_alarm**
|
||||
|
||||
**temp1_max**
|
||||
|
||||
**temp1_max_alarm**
|
||||
|
|
@ -17736,6 +17736,13 @@ S: Maintained
|
|||
F: Documentation/hwmon/mp2993.rst
|
||||
F: drivers/hwmon/pmbus/mp2993.c
|
||||
|
||||
MPS MP5926 DRIVER
|
||||
M: Yuxi Wang <Yuxi.Wang@monolithicpower.com>
|
||||
L: linux-hwmon@vger.kernel.org
|
||||
S: Maintained
|
||||
F: Documentation/hwmon/mp5926.rst
|
||||
F: drivers/hwmon/pmbus/mp5926.c
|
||||
|
||||
MPS MP9941 DRIVER
|
||||
M: Noah Wang <noahwang.wang@outlook.com>
|
||||
L: linux-hwmon@vger.kernel.org
|
||||
|
|
|
|||
|
|
@ -472,6 +472,15 @@ config SENSORS_MP5920
|
|||
This driver can also be built as a module. If so, the module will
|
||||
be called mp5920.
|
||||
|
||||
config SENSORS_MP5926
|
||||
tristate "MPS MP5926"
|
||||
help
|
||||
If you say yes here you get hardware monitoring support for Monolithic
|
||||
MP5926.
|
||||
|
||||
This driver can also be built as a module. If so, the module will
|
||||
be called mp5926.
|
||||
|
||||
config SENSORS_MP5990
|
||||
tristate "MPS MP5990"
|
||||
help
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ obj-$(CONFIG_SENSORS_MP2975) += mp2975.o
|
|||
obj-$(CONFIG_SENSORS_MP2993) += mp2993.o
|
||||
obj-$(CONFIG_SENSORS_MP5023) += mp5023.o
|
||||
obj-$(CONFIG_SENSORS_MP5920) += mp5920.o
|
||||
obj-$(CONFIG_SENSORS_MP5926) += mp5926.o
|
||||
obj-$(CONFIG_SENSORS_MP5990) += mp5990.o
|
||||
obj-$(CONFIG_SENSORS_MP9941) += mp9941.o
|
||||
obj-$(CONFIG_SENSORS_MP9945) += mp9945.o
|
||||
|
|
|
|||
184
drivers/hwmon/pmbus/mp5926.c
Normal file
184
drivers/hwmon/pmbus/mp5926.c
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* mp5926.c - pmbus driver for mps mp5926
|
||||
*
|
||||
* Copyright 2025 Monolithic Power Systems, Inc
|
||||
*
|
||||
* Author: Yuxi Wang <Yuxi.Wang@monolithicpower.com>
|
||||
*/
|
||||
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/bits.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/pmbus.h>
|
||||
#include "pmbus.h"
|
||||
|
||||
#define PAGE 0x01
|
||||
#define EFUSE_CFG 0xCF
|
||||
#define I_SCALE_SEL 0xC6
|
||||
#define MP5926_FUNC (PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | \
|
||||
PMBUS_HAVE_IIN | PMBUS_HAVE_PIN | \
|
||||
PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_INPUT | \
|
||||
PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_STATUS_VOUT)
|
||||
|
||||
struct mp5926_data {
|
||||
struct pmbus_driver_info info;
|
||||
u8 vout_mode;
|
||||
u8 vout_linear_exponent;
|
||||
};
|
||||
|
||||
#define to_mp5926_data(x) container_of(x, struct mp5926_data, info)
|
||||
|
||||
static int mp5926_read_byte_data(struct i2c_client *client, int page,
|
||||
int reg)
|
||||
{
|
||||
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
|
||||
struct mp5926_data *data = to_mp5926_data(info);
|
||||
int ret;
|
||||
|
||||
switch (reg) {
|
||||
case PMBUS_VOUT_MODE:
|
||||
if (data->vout_mode == linear) {
|
||||
/*
|
||||
* The VOUT format used by the chip is linear11,
|
||||
* not linear16. Report that VOUT is in linear mode
|
||||
* and return exponent value extracted while probing
|
||||
* the chip.
|
||||
*/
|
||||
return data->vout_linear_exponent;
|
||||
}
|
||||
return PB_VOUT_MODE_DIRECT;
|
||||
default:
|
||||
ret = -ENODATA;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mp5926_read_word_data(struct i2c_client *client, int page, int phase,
|
||||
int reg)
|
||||
{
|
||||
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
|
||||
struct mp5926_data *data = to_mp5926_data(info);
|
||||
int ret;
|
||||
|
||||
switch (reg) {
|
||||
case PMBUS_READ_VOUT:
|
||||
ret = pmbus_read_word_data(client, page, phase, reg);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
/*
|
||||
* Because the VOUT format used by the chip is linear11 and not
|
||||
* linear16, we disregard bits[15:11]. The exponent is reported
|
||||
* as part of the VOUT_MODE command.
|
||||
*/
|
||||
if (data->vout_mode == linear)
|
||||
ret = ((s16)((ret & 0x7ff) << 5)) >> 5;
|
||||
break;
|
||||
default:
|
||||
ret = -ENODATA;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct pmbus_driver_info mp5926_info = {
|
||||
.pages = PAGE,
|
||||
.format[PSC_VOLTAGE_IN] = direct,
|
||||
.format[PSC_CURRENT_IN] = direct,
|
||||
.format[PSC_VOLTAGE_OUT] = direct,
|
||||
.format[PSC_TEMPERATURE] = direct,
|
||||
.format[PSC_POWER] = direct,
|
||||
|
||||
.m[PSC_VOLTAGE_IN] = 16,
|
||||
.b[PSC_VOLTAGE_IN] = 0,
|
||||
.R[PSC_VOLTAGE_IN] = 0,
|
||||
|
||||
.m[PSC_CURRENT_IN] = 16,
|
||||
.b[PSC_CURRENT_IN] = 0,
|
||||
.R[PSC_CURRENT_IN] = 0,
|
||||
|
||||
.m[PSC_VOLTAGE_OUT] = 16,
|
||||
.b[PSC_VOLTAGE_OUT] = 0,
|
||||
.R[PSC_VOLTAGE_OUT] = 0,
|
||||
|
||||
.m[PSC_TEMPERATURE] = 4,
|
||||
.b[PSC_TEMPERATURE] = 0,
|
||||
.R[PSC_TEMPERATURE] = 0,
|
||||
|
||||
.m[PSC_POWER] = 25,
|
||||
.b[PSC_POWER] = 0,
|
||||
.R[PSC_POWER] = -2,
|
||||
|
||||
.read_word_data = mp5926_read_word_data,
|
||||
.read_byte_data = mp5926_read_byte_data,
|
||||
.func[0] = MP5926_FUNC,
|
||||
};
|
||||
|
||||
static int mp5926_probe(struct i2c_client *client)
|
||||
{
|
||||
struct mp5926_data *data;
|
||||
struct pmbus_driver_info *info;
|
||||
int ret;
|
||||
|
||||
data = devm_kzalloc(&client->dev, sizeof(struct mp5926_data),
|
||||
GFP_KERNEL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(&data->info, &mp5926_info, sizeof(*info));
|
||||
info = &data->info;
|
||||
ret = i2c_smbus_read_word_data(client, EFUSE_CFG);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret & BIT(12)) {
|
||||
data->vout_mode = linear;
|
||||
data->info.format[PSC_VOLTAGE_IN] = linear;
|
||||
data->info.format[PSC_CURRENT_IN] = linear;
|
||||
data->info.format[PSC_VOLTAGE_OUT] = linear;
|
||||
data->info.format[PSC_TEMPERATURE] = linear;
|
||||
data->info.format[PSC_POWER] = linear;
|
||||
ret = i2c_smbus_read_word_data(client, PMBUS_READ_VOUT);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(&client->dev, ret, "Can't get vout exponent.");
|
||||
data->vout_linear_exponent = (u8)((ret >> 11) & 0x1f);
|
||||
} else {
|
||||
data->vout_mode = direct;
|
||||
ret = i2c_smbus_read_word_data(client, I_SCALE_SEL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret & BIT(6))
|
||||
data->info.m[PSC_CURRENT_IN] = 4;
|
||||
}
|
||||
|
||||
return pmbus_do_probe(client, info);
|
||||
}
|
||||
|
||||
static const struct i2c_device_id mp5926_id[] = {
|
||||
{ "mp5926", 0 },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, mp5926_id);
|
||||
|
||||
static const struct of_device_id mp5926_of_match[] = {
|
||||
{ .compatible = "mps,mp5926" },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, mp5926_of_match);
|
||||
|
||||
static struct i2c_driver mp5926_driver = {
|
||||
.probe = mp5926_probe,
|
||||
.driver = {
|
||||
.name = "mp5926",
|
||||
.of_match_table = mp5926_of_match,
|
||||
},
|
||||
.id_table = mp5926_id,
|
||||
};
|
||||
|
||||
module_i2c_driver(mp5926_driver);
|
||||
MODULE_AUTHOR("Yuxi Wang <Yuxi.Wang@monolithicpower.com>");
|
||||
MODULE_DESCRIPTION("MPS MP5926 pmbus driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_IMPORT_NS("PMBUS");
|
||||
Loading…
Add table
Add a link
Reference in a new issue