Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: add MP5920 driver

Add support for MPS Hot-Swap controller mp5920. This driver exposes
telemetry and limit value readings and writings.

Signed-off-by: Alex Vdovydchenko <xzeol@yahoo.com>
Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20240702115252.981416-3-xzeol@yahoo.com
[groeck: Use min_t() to limit length of displayed model string]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Alex Vdovydchenko and committed by
Guenter Roeck
cd228e7b a50fbf8a

+192
+1
Documentation/hwmon/index.rst
··· 169 169 mp2975 170 170 mp2993 171 171 mp5023 172 + mp5920 172 173 mp5990 173 174 mp9941 174 175 mpq8785
+91
Documentation/hwmon/mp5920.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + Kernel driver mp5920 4 + ==================== 5 + 6 + Supported chips: 7 + 8 + * MPS MP5920 9 + 10 + Prefix: 'mp5920' 11 + 12 + * Datasheet 13 + 14 + Publicly available at the MPS website : https://www.monolithicpower.com/en/mp5920.html 15 + 16 + Authors: 17 + 18 + Tony Ao <tony_ao@wiwynn.com> 19 + Alex Vdovydchenko <xzeol@yahoo.com> 20 + 21 + Description 22 + ----------- 23 + 24 + This driver implements support for Monolithic Power Systems, Inc. (MPS) 25 + MP5920 Hot-Swap Controller. 26 + 27 + Device compliant with: 28 + 29 + - PMBus rev 1.3 interface. 30 + 31 + Device supports direct and linear format for reading input voltage, 32 + output voltage, output current, input power and temperature. 33 + 34 + The driver exports the following attributes via the 'sysfs' files 35 + for input voltage: 36 + 37 + **in1_input** 38 + 39 + **in1_label** 40 + 41 + **in1_rated_max** 42 + 43 + **in1_rated_min** 44 + 45 + **in1_crit** 46 + 47 + **in1_alarm** 48 + 49 + The driver provides the following attributes for output voltage: 50 + 51 + **in2_input** 52 + 53 + **in2_label** 54 + 55 + **in2_rated_max** 56 + 57 + **in2_rated_min** 58 + 59 + **in2_alarm** 60 + 61 + The driver provides the following attributes for output current: 62 + 63 + **curr1_input** 64 + 65 + **curr1_label** 66 + 67 + **curr1_crit** 68 + 69 + **curr1_alarm** 70 + 71 + **curr1_rated_max** 72 + 73 + The driver provides the following attributes for input power: 74 + 75 + **power1_input** 76 + 77 + **power1_label** 78 + 79 + **power1_max** 80 + 81 + **power1_rated_max** 82 + 83 + The driver provides the following attributes for temperature: 84 + 85 + **temp1_input** 86 + 87 + **temp1_max** 88 + 89 + **temp1_crit** 90 + 91 + **temp1_alarm**
+9
drivers/hwmon/pmbus/Kconfig
··· 380 380 This driver can also be built as a module. If so, the module will 381 381 be called mp5023. 382 382 383 + config SENSORS_MP5920 384 + tristate "MPS MP5920" 385 + help 386 + If you say yes here you get hardware monitoring support for Monolithic 387 + MP5920. 388 + 389 + This driver can also be built as a module. If so, the module will 390 + be called mp5920. 391 + 383 392 config SENSORS_MP5990 384 393 tristate "MPS MP5990" 385 394 help
+1
drivers/hwmon/pmbus/Makefile
··· 40 40 obj-$(CONFIG_SENSORS_MP2975) += mp2975.o 41 41 obj-$(CONFIG_SENSORS_MP2993) += mp2993.o 42 42 obj-$(CONFIG_SENSORS_MP5023) += mp5023.o 43 + obj-$(CONFIG_SENSORS_MP5920) += mp5920.o 43 44 obj-$(CONFIG_SENSORS_MP5990) += mp5990.o 44 45 obj-$(CONFIG_SENSORS_MP9941) += mp9941.o 45 46 obj-$(CONFIG_SENSORS_MPQ7932) += mpq7932.o
+90
drivers/hwmon/pmbus/mp5920.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Hardware monitoring driver for MP5920 and compatible chips. 4 + */ 5 + 6 + #include <linux/i2c.h> 7 + #include <linux/minmax.h> 8 + #include <linux/module.h> 9 + #include <linux/of_device.h> 10 + #include "pmbus.h" 11 + 12 + static struct pmbus_driver_info mp5920_info = { 13 + .pages = 1, 14 + .format[PSC_VOLTAGE_IN] = direct, 15 + .format[PSC_VOLTAGE_OUT] = direct, 16 + .format[PSC_CURRENT_OUT] = direct, 17 + .format[PSC_POWER] = direct, 18 + .format[PSC_TEMPERATURE] = direct, 19 + .m[PSC_VOLTAGE_IN] = 2266, 20 + .b[PSC_VOLTAGE_IN] = 0, 21 + .R[PSC_VOLTAGE_IN] = -1, 22 + .m[PSC_VOLTAGE_OUT] = 2266, 23 + .b[PSC_VOLTAGE_OUT] = 0, 24 + .R[PSC_VOLTAGE_OUT] = -1, 25 + .m[PSC_CURRENT_OUT] = 546, 26 + .b[PSC_CURRENT_OUT] = 0, 27 + .R[PSC_CURRENT_OUT] = -2, 28 + .m[PSC_POWER] = 5840, 29 + .b[PSC_POWER] = 0, 30 + .R[PSC_POWER] = -3, 31 + .m[PSC_TEMPERATURE] = 1067, 32 + .b[PSC_TEMPERATURE] = 20500, 33 + .R[PSC_TEMPERATURE] = -2, 34 + .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | 35 + PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT | 36 + PMBUS_HAVE_TEMP, 37 + }; 38 + 39 + static int mp5920_probe(struct i2c_client *client) 40 + { 41 + struct device *dev = &client->dev; 42 + int ret; 43 + u8 buf[I2C_SMBUS_BLOCK_MAX]; 44 + 45 + if (!i2c_check_functionality(client->adapter, 46 + I2C_FUNC_SMBUS_READ_WORD_DATA)) 47 + return -ENODEV; 48 + 49 + ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf); 50 + if (ret < 0) 51 + return dev_err_probe(dev, ret, "Failed to read PMBUS_MFR_MODEL\n"); 52 + 53 + if (ret != 6 || strncmp(buf, "MP5920", 6)) { 54 + return dev_err_probe(dev, -ENODEV, "Model '%.*s' not supported\n", 55 + min_t(int, ret, sizeof(buf)), buf); 56 + } 57 + 58 + return pmbus_do_probe(client, &mp5920_info); 59 + } 60 + 61 + static const struct of_device_id mp5920_of_match[] = { 62 + { .compatible = "mps,mp5920" }, 63 + { } 64 + }; 65 + 66 + MODULE_DEVICE_TABLE(of, mp5920_of_match); 67 + 68 + static const struct i2c_device_id mp5920_id[] = { 69 + { "mp5920" }, 70 + { } 71 + }; 72 + 73 + MODULE_DEVICE_TABLE(i2c, mp5920_id); 74 + 75 + static struct i2c_driver mp5920_driver = { 76 + .driver = { 77 + .name = "mp5920", 78 + .of_match_table = mp5920_of_match, 79 + }, 80 + .probe = mp5920_probe, 81 + .id_table = mp5920_id, 82 + }; 83 + 84 + module_i2c_driver(mp5920_driver); 85 + 86 + MODULE_AUTHOR("Tony Ao <tony_ao@wiwynn.com>"); 87 + MODULE_AUTHOR("Alex Vdovydchenko <xzeol@yahoo.com>"); 88 + MODULE_DESCRIPTION("PMBus driver for MP5920 HSC"); 89 + MODULE_LICENSE("GPL"); 90 + MODULE_IMPORT_NS(PMBUS);