hwmon: (max77705) add initial support
Subsystems (4)
Dzmitry Sankouski
maintainerPATCH v4 1/1 hwmon: (max77705) add initial support
Add support for max77705 hwmon. Includes charger input, system bus, and vbyp measurements.
---
Maxim MAX77705 is a Companion Power Management and Type-C interface IC. It includes charger and fuel gauge blocks, and is capable of measuring charger input current, system bus volatage and current, and bypass voltage.
Add support for mentioned measurements.
---
Changes in v4:
- Fix review comments.
- Link to v3: https://lore.kernel.org/r/20250405-initial-support-for-max77705-sensors-v3-1-e5f64fccd005@gmail.com
Changes in v3:
- Fix review comments.
- Fix v2 changed message.
- Link to v2: https://lore.kernel.org/r/20250304-initial-support-for-max77705-sensors-v2-1-58d2207c732b@gmail.com
Changes in v2:
- Fix review comments.
- Link to v1: https://lore.kernel.org/r/20250225-initial-support-for-max77705-sensors-v1-1-2be6467628b0@gmail.com
---
Changes in v4:
- documentation: "===" line is as long as the text
- simplify the dependency to depends on MFD_MAX77705
- cleanup headers
- sign_extend current measurements - add 'is_signed' parameter to
max77705_read_and_convert function
- replace ARRAY_SIZE(voltage_channel_desc) to 2
- remove last blank line
Changes in v3:
- change resolution type to u32
- pass regmap from parent
- rebase on latest linux-next, containg max77705 driver
Changes in v2:
- sort headers alphabetically
- swap curr channel info, to align indeces with channel_desc struct
- reword coverletter
- fix checkpatch --strict warnings
- remove struct max77705_hwmon, use regmap directly
- move register validation logic to is_visible function
- move common register reading and converting logic to separate function
- remove unnessesary {} in if statement
- s/i2c->dev/pdev->dev in dev_err_probe
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/max77705.rst | 39 ++++++++++++++++++++++++++++++++ MAINTAINERS | 7 ++++++ drivers/hwmon/Kconfig | 9 ++++++++ drivers/hwmon/Makefile | 1 + drivers/hwmon/max77705-hwmon.c | 242 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 299 insertions(+)
Documentation/hwmon/index.rst +1 -0
@@ -161,6 +161,7 @@ Hardware Monitoring Kernel Drivers max6639 max6650 max6697 + max77705 max8688 mc13783-adc mc34vr500
Documentation/hwmon/max77705.rst new file +39 -0
@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver max77705 +====================== + +Supported chips: + + * Maxim Integrated MAX77705 + + Prefix: 'max77705' + + Addresses scanned: none + + Datasheet: Not available + +Authors: + - Dzmitry Sankouski <[email protected]> + +Description +----------- + +The MAX77705 PMIC provides current and voltage measurements besides fuelgauge: +- chip input current +- system bus current and voltage +- VBYP voltage + +Sysfs Attributes +---------------- + +================= ======================================== +in1_label "vbyp" +in1_input Measured chip vbyp voltage +in2_label "vsys" +in2_input Measured chip system bus voltage +curr1_label "iin" +curr1_input Measured chip input current. +curr2_label "isys" +curr2_input Measured chip system bus current. +================= ========================================
MAINTAINERS +7 -0
@@ -18369,6 +18369,13 @@ S: Maintained F: Documentation/hwmon/pc87427.rst F: drivers/hwmon/pc87427.c +MAX77705 HARDWARE MONITORING DRIVER +M: Dzmitry Sankouski <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/hwmon/max77705.rst +F: drivers/hwmon/max77705-hwmon.c + PCA9532 LED DRIVER M: Riku Voipio <[email protected]> S: Maintained
drivers/hwmon/Kconfig +9 -0
@@ -1308,6 +1308,15 @@ config SENSORS_MAX31790 This driver can also be built as a module. If so, the module will be called max31790. +config SENSORS_MAX77705 + tristate "MAX77705 current and voltage sensor" + depends on MFD_MAX77705 + help + If you say yes here you get support for MAX77705 sensors connected with I2C. + + This driver can also be built as a module. If so, the module + will be called max77705-hwmon. + config SENSORS_MC34VR500 tristate "NXP MC34VR500 hardware monitoring driver" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -161,6 +161,7 @@ obj-$(CONFIG_SENSORS_MAX6650) += max6650.o obj-$(CONFIG_SENSORS_MAX6697) += max6697.o obj-$(CONFIG_SENSORS_MAX31790) += max31790.o obj-$(CONFIG_MAX31827) += max31827.o +obj-$(CONFIG_SENSORS_MAX77705) += max77705-hwmon.o obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o obj-$(CONFIG_SENSORS_MC34VR500) += mc34vr500.o obj-$(CONFIG_SENSORS_MCP3021) += mcp3021.o
drivers/hwmon/max77705-hwmon.c new file +242 -0
242 lines not on this page · raw message
---
base-commit: a4cda136f021ad44b8b52286aafd613030a6db5f
change-id: 20250123-initial-support-for-max77705-sensors-ad0170ac1ec5
Best regards,
Signature · 1 line
Dzmitry Sankouski <[email protected]>
Guenter Roeck
maintainerQuoted 226 lines · Dzmitry Sankouski
Add support for max77705 hwmon. Includes charger input, system bus, and vbyp measurements.
Signed-off-by Dzmitry Sankouski <[email protected]>---
Maxim MAX77705 is a Companion Power Management and Type-C interface IC. It includes charger and fuel gauge blocks, and is capable of measuring charger input current, system bus volatage and current, and bypass voltage.Add support for mentioned measurements.
---
Changes in v4:
- Fix review comments.
- Link to v3: https://lore.kernel.org/r/20250405-initial-support-for-max77705-sensors-v3-1-e5f64fccd005@gmail.comChanges in v3:
- Fix review comments.
- Fix v2 changed message.
- Link to v2: https://lore.kernel.org/r/20250304-initial-support-for-max77705-sensors-v2-1-58d2207c732b@gmail.comChanges in v2:
- Fix review comments.
- Link to v1: https://lore.kernel.org/r/20250225-initial-support-for-max77705-sensors-v1-1-2be6467628b0@gmail.com
---
Changes in v4:
- documentation: "===" line is as long as the text
- simplify the dependency to depends onMFD_MAX77705
- cleanup headers
-sign_extendcurrent measurements - add 'is_signed' parameter to
max77705_read_and_convertfunction
- replaceARRAY_SIZE(voltage_channel_desc)to 2
- remove last blank lineChanges in v3:
- change resolution type to u32
- pass regmap from parent
- rebase on latest linux-next, containg max77705 driverChanges in v2:
- sort headers alphabetically
- swap curr channel info, to align indeces withchannel_descstruct
- reword coverletter
- fix checkpatch --strict warnings
- remove structmax77705_hwmon, use regmap directly
- move register validation logic tois_visiblefunction
- move common register reading and converting logic to separate function
- remove unnessesary {} in if statement
- s/i2c->dev/pdev->dev indev_err_probe--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/max77705.rst | 39 ++++++++++++++++++++++++++++++++ MAINTAINERS | 7 ++++++ drivers/hwmon/Kconfig | 9 ++++++++ drivers/hwmon/Makefile | 1 + drivers/hwmon/max77705-hwmon.c | 242 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 299 insertions(+)Documentation/hwmon/index.rst +1
-0@@ -161,6 +161,7 @@ Hardware Monitoring Kernel Drivers max6639 max6650 max6697 + max77705 max8688 mc13783-adc mc34vr500Documentation/hwmon/max77705.rst new file +39
-0@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver max77705 +====================== + +Supported chips: + + * Maxim Integrated MAX77705 + + Prefix: 'max77705' + + Addresses scanned: none + + Datasheet: Not available + +Authors: + - Dzmitry Sankouski <[email protected]> + +Description +----------- + +The MAX77705 PMIC provides current and voltage measurements besides fuelgauge: +- chip input current +- system bus current and voltage +- VBYP voltage + +Sysfs Attributes +---------------- + +================= ======================================== +in1_label "vbyp" +in1_input Measured chip vbyp voltage +in2_label "vsys" +in2_input Measured chip system bus voltage +curr1_label "iin" +curr1_input Measured chip input current. +curr2_label "isys" +curr2_input Measured chip system bus current. +================= ========================================MAINTAINERS +7
-0@@ -18369,6 +18369,13 @@ S: Maintained F: Documentation/hwmon/pc87427.rst F: drivers/hwmon/pc87427.c +MAX77705 HARDWARE MONITORING DRIVER +M: Dzmitry Sankouski <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/hwmon/max77705.rst +F: drivers/hwmon/max77705-hwmon.c + PCA9532 LED DRIVER M: Riku Voipio <[email protected]> S: Maintaineddrivers/hwmon/Kconfig +9
-0@@ -1308,6 +1308,15 @@ config SENSORS_MAX31790 This driver can also be built as a module. If so, the module will be called max31790. +config SENSORS_MAX77705 + tristate "MAX77705 current and voltage sensor" + depends on MFD_MAX77705 + help + If you say yes here you get support for MAX77705 sensors connected with I2C. + + This driver can also be built as a module. If so, the module + will be called max77705-hwmon. + config SENSORS_MC34VR500 tristate "NXP MC34VR500 hardware monitoring driver" depends on I2Cdrivers/hwmon/Makefile +1
-0@@ -161,6 +161,7 @@ obj-$(CONFIG_SENSORS_MAX6650) += max6650.o obj-$(CONFIG_SENSORS_MAX6697) += max6697.o obj-$(CONFIG_SENSORS_MAX31790) += max31790.o obj-$(CONFIG_MAX31827) += max31827.o +obj-$(CONFIG_SENSORS_MAX77705) += max77705-hwmon.o obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o obj-$(CONFIG_SENSORS_MC34VR500) += mc34vr500.o obj-$(CONFIG_SENSORS_MCP3021) += mcp3021.odrivers/hwmon/max77705-hwmon.c new file +55
-0@@ -0,0 +1,242 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* MAX77705 voltage and current hwmon driver. +* +* Copyright (C) 2025 Dzmitry Sankouski <[email protected]> +*/ + +#include <linux/err.h> +#include <linux/hwmon-sysfs.h> +#include <linux/hwmon.h> +#include <linux/kernel.h> +#include <linux/mfd/max77705-private.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +struct channel_desc { +u8 reg; +u8 avg_reg; +const char *const label; +// register resolution. nano Volts for voltage, nano Amperes for current +u32 resolution; +}; + +static const struct channel_desc current_channel_desc[] = { + { + .reg =IIN_REG , + .label ="IIN_REG" , + .resolution =125000 + }, + { + .reg =ISYS_REG , + .avg_reg =AVGISYS_REG , + .label ="ISYS_REG" , + .resolution =312500 + } +}; + +static const struct channel_desc voltage_channel_desc[] = { + { + .reg =VBYP_REG , + .label ="VBYP_REG" , + .resolution =427246 + }, + { + .reg =VSYS_REG , + .label ="VSYS_REG" , + .resolution =156250 + } +}; + +static const struct regmap_range max77705_hwmon_readable_ranges[] = { +regmap_reg_range (AVGISYS_REG ,AVGISYS_REG +1 ), +regmap_reg_range (IIN_REG ,IIN_REG +1 ), +regmap_reg_range (ISYS_REG ,ISYS_REG +1 ), +regmap_reg_range (VBYP_REG ,VBYP_REG +1 ),
drivers/hwmon/max77705-hwmon.c line 65
Quoted 10 lines
drivers/hwmon/max77705-hwmon.c new file +10
-0+ regmap_reg_range(VSYS_REG, VSYS_REG + 1), +}; + +static const struct regmap_access_table max77705_hwmon_readable_table = { + .yes_ranges = max77705_hwmon_readable_ranges, + .n_yes_ranges =ARRAY_SIZE (max77705_hwmon_readable_ranges), +}; + +static int max77705_read_and_convert (struct regmap *regmap,u8 reg,u32 res, +u8 is_signed,long *val)
is_signed could (and should) be bool.
Quoted 15 lines
drivers/hwmon/max77705-hwmon.c new file +15
-0+{ +int ret; +u32 regval; + + ret =regmap_read (regmap, reg, ®val); +if (ret <0 ) +return ret; + +if (is_signed) + *val =mult_frac ((long )sign_extend32 (regval,15 ), res,1000000 ); +else + *val =mult_frac ((long )regval, res,1000000 ); + +return 0 ; +}
drivers/hwmon/max77705-hwmon.c line 90
Quoted 10 lines
drivers/hwmon/max77705-hwmon.c new file +10
-0+ +static umode_t max77705_is_visible (const void *data, +enum hwmon_sensor_types type, +u32 attr,int channel) +{ +switch (type) { +case hwmon_in: +if (channel >=2 ) +return 0 ; +
This and the same check is just as unnecessary as earlier.
drivers/hwmon/max77705-hwmon.c line 102
Quoted 12 lines
drivers/hwmon/max77705-hwmon.c new file +12
-0+switch (attr) { +case hwmon_in_input: +case hwmon_in_label: +return 0444 ; +default : +break ; + } +break ; +case hwmon_curr: +if (channel >=2 ) +return 0 ; +
Same here.
Quoted 50 lines
drivers/hwmon/max77705-hwmon.c new file +50
-0+switch (attr) { +case hwmon_curr_input: +case hwmon_in_label: +return 0444 ; +case hwmon_curr_average: +if (current_channel_desc[channel].avg_reg) +return 0444 ; +break ; +default : +break ; + } +break ; +default : +break ; + } +return 0 ; +} + +static int max77705_read_string (struct device *dev,enum hwmon_sensor_types type,u32 attr, +int channel,const char **buf) +{ +switch (type) { +case hwmon_curr: +switch (attr) { +case hwmon_in_label: + *buf = current_channel_desc[channel].label; +return 0 ; +default : +return -EOPNOTSUPP ; + } + +case hwmon_in: +switch (attr) { +case hwmon_in_label: + *buf = voltage_channel_desc[channel].label; +return 0 ; +default : +return -EOPNOTSUPP ; + } +default : +return -EOPNOTSUPP ; + } +} + +static int max77705_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct regmap *regmap =dev_get_drvdata (dev); +u8 reg, is_signed; +u32 res;
drivers/hwmon/max77705-hwmon.c line 162
Quoted 10 lines
drivers/hwmon/max77705-hwmon.c new file +10
-0+ +switch (type) { +case hwmon_curr: + is_signed =1 ; +switch (attr) { +case hwmon_curr_input: + reg = current_channel_desc[channel].reg; + res = current_channel_desc[channel].resolution; + +return max77705_read_and_convert (regmap, reg, res, is_signed, val);
I fail to understand the need for the is_signed variable. Why not just pass a bool "true" ?
drivers/hwmon/max77705-hwmon.c line 167
Quoted 5 lines
drivers/hwmon/max77705-hwmon.c new file +5
-0+case hwmon_curr_average: + reg = current_channel_desc[channel].avg_reg; + res = current_channel_desc[channel].resolution; + +return max77705_read_and_convert (regmap, reg, res, is_signed, val);
same here.
drivers/hwmon/max77705-hwmon.c line 179
Quoted 12 lines
drivers/hwmon/max77705-hwmon.c new file +12
-0+default : +return -EOPNOTSUPP ; + } + +case hwmon_in: + is_signed =0 ; +switch (attr) { +case hwmon_in_input: + reg = voltage_channel_desc[channel].reg; + res = voltage_channel_desc[channel].resolution; + +return max77705_read_and_convert (regmap, reg, res, is_signed, val);
... and "false" here.
Quoted 69 lines
drivers/hwmon/max77705-hwmon.c new file +63
-1+default : +return -EOPNOTSUPP ; + } +default : +return -EOPNOTSUPP ; + } + +return 0 ; +} + +static const struct hwmon_ops max77705_hwmon_ops = { + .is_visible = max77705_is_visible, + .read = max77705_read, + .read_string = max77705_read_string, +}; + +static const struct hwmon_channel_info *max77705_info[] = { +HWMON_CHANNEL_INFO (in, +HWMON_I_INPUT |HWMON_I_LABEL , +HWMON_I_INPUT |HWMON_I_LABEL + ), +HWMON_CHANNEL_INFO (curr, +HWMON_C_INPUT |HWMON_C_LABEL , +HWMON_C_INPUT |HWMON_C_AVERAGE |HWMON_C_LABEL + ), +NULL +}; + +static const struct hwmon_chip_info max77705_chip_info = { + .ops = &max77705_hwmon_ops, + .info = max77705_info, +}; + +static int max77705_hwmon_probe (struct platform_device *pdev) +{ +struct device *hwmon_dev; +struct regmap *regmap; + + regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!regmap) +return -ENODEV ; + + hwmon_dev =devm_hwmon_device_register_with_info (&pdev->dev,"max77705" , regmap, + &max77705_chip_info,NULL ); +if (IS_ERR (hwmon_dev)) +return dev_err_probe (&pdev->dev,PTR_ERR (hwmon_dev), +"Unable to register hwmon device\n" ); + +return 0 ; +}; + +static struct platform_driver max77705_hwmon_driver = { + .driver = { + .name ="max77705-hwmon" , + }, + .probe = max77705_hwmon_probe, +}; + +module_platform_driver (max77705_hwmon_driver); + +MODULE_AUTHOR ("Dzmitry Sankouski <[email protected]>" ); +MODULE_DESCRIPTION ("MAX77705 monitor driver" ); +MODULE_LICENSE ("GPL" ); ---base-commit:
a4cda136f021ad44b8b52286aafd613030a6db5f
change-id: 20250123-initial-support-for-max77705-sensors-ad0170ac1ec5Best regards,
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Dzmitry,
kernel test robot noticed the following build warnings:
[auto build test WARNING on a4cda136f021ad44b8b52286aafd613030a6db5f]
url: https://github.com/intel-lab-lkp/linux/commits/Dzmitry-Sankouski/hwmon-max77705-add-initial-support/20250414-123556 base: a4cda136f021ad44b8b52286aafd613030a6db5f patch link: https://lore.kernel.org/r/20250412-initial-support-for-max77705-sensors-v4-1-2e4cf268a3d0%40gmail.com patch subject: [PATCH v4] hwmon: (max77705) add initial support config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20250415/[email protected]/config) compiler: sh4-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250415/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/hwmon/max77705-hwmon.c:59:41: warning: 'max77705_hwmon_readable_table' defined but not used [-Wunused-const-variable=]
59 | static const struct regmap_access_table max77705_hwmon_readable_table = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/max77705_hwmon_readable_table +59 drivers/hwmon/max77705-hwmon.c
58
> 59 static const struct regmap_access_table max77705_hwmon_readable_table = {
60 .yes_ranges = max77705_hwmon_readable_ranges,
61 .n_yes_ranges = ARRAY_SIZE(max77705_hwmon_readable_ranges),
62 };
63 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Dzmitry,
kernel test robot noticed the following build warnings:
[auto build test WARNING on a4cda136f021ad44b8b52286aafd613030a6db5f]
url: https://github.com/intel-lab-lkp/linux/commits/Dzmitry-Sankouski/hwmon-max77705-add-initial-support/20250414-123556 base: a4cda136f021ad44b8b52286aafd613030a6db5f patch link: https://lore.kernel.org/r/20250412-initial-support-for-max77705-sensors-v4-1-2e4cf268a3d0%40gmail.com patch subject: [PATCH v4] hwmon: (max77705) add initial support config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20250415/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250415/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/hwmon/max77705-hwmon.c:59:41: warning: unused variable 'max77705_hwmon_readable_table' [-Wunused-const-variable]
59 | static const struct regmap_access_table max77705_hwmon_readable_table = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~1 warning generated.
vim +/max77705_hwmon_readable_table +59 drivers/hwmon/max77705-hwmon.c
58
> 59 static const struct regmap_access_table max77705_hwmon_readable_table = {
60 .yes_ranges = max77705_hwmon_readable_ranges,
61 .n_yes_ranges = ARRAY_SIZE(max77705_hwmon_readable_ranges),
62 };
63 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki