Skip to content

Commit b4a95b8

Browse files
DimitriFedrausre
authored andcommitted
power: supply: max1720x: add support for reading internal and thermistor temperatures
If enabled in the nPackCfg register, the Temp1, Temp2 and IntTemp registers contain the temperature readings from the AIN1 thermistor, AIN2 thermistor and internal die temperature respectively. Registers are shared between SBS and normal IC functions and are always readable regardless of IC settings. Signed-off-by: Dimitri Fedrau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 92c71aa commit b4a95b8

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
What: /sys/class/power_supply/max1720x/temp_ain1
2+
Date: January 2025
3+
KernelVersion: 6.14
4+
Contact: Dimitri Fedrau <[email protected]>
5+
Description:
6+
Reports the current temperature reading from AIN1 thermistor.
7+
8+
Access: Read
9+
10+
Valid values: Represented in 1/10 Degrees Celsius
11+
12+
What: /sys/class/power_supply/max1720x/temp_ain2
13+
Date: January 2025
14+
KernelVersion: 6.14
15+
Contact: Dimitri Fedrau <[email protected]>
16+
Description:
17+
Reports the current temperature reading from AIN2 thermistor.
18+
19+
Access: Read
20+
21+
Valid values: Represented in 1/10 Degrees Celsius
22+
23+
What: /sys/class/power_supply/max1720x/temp_int
24+
Date: January 2025
25+
KernelVersion: 6.14
26+
Contact: Dimitri Fedrau <[email protected]>
27+
Description:
28+
Reports the current temperature reading from internal die.
29+
30+
Access: Read
31+
32+
Valid values: Represented in 1/10 Degrees Celsius

drivers/power/supply/max1720x_battery.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
#include <linux/unaligned.h>
1818

19+
/* SBS compliant registers */
20+
#define MAX172XX_TEMP1 0x34
21+
#define MAX172XX_INT_TEMP 0x35
22+
#define MAX172XX_TEMP2 0x3B
23+
1924
/* Nonvolatile registers */
2025
#define MAX1720X_NXTABLE0 0x80
2126
#define MAX1720X_NRSENSE 0xCF /* RSense in 10^-5 Ohm */
@@ -113,11 +118,15 @@ static const struct regmap_config max1720x_regmap_cfg = {
113118
};
114119

115120
static const struct regmap_range max1720x_nvmem_allow[] = {
121+
regmap_reg_range(MAX172XX_TEMP1, MAX172XX_INT_TEMP),
122+
regmap_reg_range(MAX172XX_TEMP2, MAX172XX_TEMP2),
116123
regmap_reg_range(MAX1720X_NXTABLE0, MAX1720X_NDEVICE_NAME4),
117124
};
118125

119126
static const struct regmap_range max1720x_nvmem_deny[] = {
120-
regmap_reg_range(0x00, 0x7F),
127+
regmap_reg_range(0x00, 0x33),
128+
regmap_reg_range(0x36, 0x3A),
129+
regmap_reg_range(0x3C, 0x7F),
121130
regmap_reg_range(0xE0, 0xFF),
122131
};
123132

@@ -388,6 +397,54 @@ static int max1720x_battery_get_property(struct power_supply *psy,
388397
return ret;
389398
}
390399

400+
static int max1720x_read_temp(struct device *dev, u8 reg, char *buf)
401+
{
402+
struct power_supply *psy = dev_get_drvdata(dev);
403+
struct max1720x_device_info *info = power_supply_get_drvdata(psy);
404+
unsigned int val;
405+
int ret;
406+
407+
ret = regmap_read(info->regmap_nv, reg, &val);
408+
if (ret < 0)
409+
return ret;
410+
411+
/*
412+
* Temperature in degrees Celsius starting at absolute zero, -273C or
413+
* 0K with an LSb of 0.1C
414+
*/
415+
return sysfs_emit(buf, "%d\n", val - 2730);
416+
}
417+
418+
static ssize_t temp_ain1_show(struct device *dev, struct device_attribute *attr,
419+
char *buf)
420+
{
421+
return max1720x_read_temp(dev, MAX172XX_TEMP1, buf);
422+
}
423+
424+
static ssize_t temp_ain2_show(struct device *dev, struct device_attribute *attr,
425+
char *buf)
426+
{
427+
return max1720x_read_temp(dev, MAX172XX_TEMP2, buf);
428+
}
429+
430+
static ssize_t temp_int_show(struct device *dev, struct device_attribute *attr,
431+
char *buf)
432+
{
433+
return max1720x_read_temp(dev, MAX172XX_INT_TEMP, buf);
434+
}
435+
436+
static DEVICE_ATTR_RO(temp_ain1);
437+
static DEVICE_ATTR_RO(temp_ain2);
438+
static DEVICE_ATTR_RO(temp_int);
439+
440+
static struct attribute *max1720x_attrs[] = {
441+
&dev_attr_temp_ain1.attr,
442+
&dev_attr_temp_ain2.attr,
443+
&dev_attr_temp_int.attr,
444+
NULL
445+
};
446+
ATTRIBUTE_GROUPS(max1720x);
447+
391448
static
392449
int max1720x_nvmem_reg_read(void *priv, unsigned int off, void *val, size_t len)
393450
{
@@ -488,6 +545,7 @@ static int max1720x_probe(struct i2c_client *client)
488545

489546
psy_cfg.drv_data = info;
490547
psy_cfg.fwnode = dev_fwnode(dev);
548+
psy_cfg.attr_grp = max1720x_groups;
491549
i2c_set_clientdata(client, info);
492550
info->regmap = devm_regmap_init_i2c(client, &max1720x_regmap_cfg);
493551
if (IS_ERR(info->regmap))

0 commit comments

Comments
 (0)