|
16 | 16 |
|
17 | 17 | #include <linux/unaligned.h>
|
18 | 18 |
|
| 19 | +/* SBS compliant registers */ |
| 20 | +#define MAX172XX_TEMP1 0x34 |
| 21 | +#define MAX172XX_INT_TEMP 0x35 |
| 22 | +#define MAX172XX_TEMP2 0x3B |
| 23 | + |
19 | 24 | /* Nonvolatile registers */
|
20 | 25 | #define MAX1720X_NXTABLE0 0x80
|
21 | 26 | #define MAX1720X_NRSENSE 0xCF /* RSense in 10^-5 Ohm */
|
@@ -113,11 +118,15 @@ static const struct regmap_config max1720x_regmap_cfg = {
|
113 | 118 | };
|
114 | 119 |
|
115 | 120 | 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), |
116 | 123 | regmap_reg_range(MAX1720X_NXTABLE0, MAX1720X_NDEVICE_NAME4),
|
117 | 124 | };
|
118 | 125 |
|
119 | 126 | 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), |
121 | 130 | regmap_reg_range(0xE0, 0xFF),
|
122 | 131 | };
|
123 | 132 |
|
@@ -388,6 +397,54 @@ static int max1720x_battery_get_property(struct power_supply *psy,
|
388 | 397 | return ret;
|
389 | 398 | }
|
390 | 399 |
|
| 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 | + |
391 | 448 | static
|
392 | 449 | int max1720x_nvmem_reg_read(void *priv, unsigned int off, void *val, size_t len)
|
393 | 450 | {
|
@@ -488,6 +545,7 @@ static int max1720x_probe(struct i2c_client *client)
|
488 | 545 |
|
489 | 546 | psy_cfg.drv_data = info;
|
490 | 547 | psy_cfg.fwnode = dev_fwnode(dev);
|
| 548 | + psy_cfg.attr_grp = max1720x_groups; |
491 | 549 | i2c_set_clientdata(client, info);
|
492 | 550 | info->regmap = devm_regmap_init_i2c(client, &max1720x_regmap_cfg);
|
493 | 551 | if (IS_ERR(info->regmap))
|
|
0 commit comments