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

Configure Feed

Select the types of activity you want to include in your feed.

hwmon: (ina238) Use the energy64 attribute type to report the energy

Use the energy64 attribute type instead of locally defined sysfs attributes
to report the accumulated energy.

No functional change intended.

Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz> # INA780
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+15 -19
+15 -19
drivers/hwmon/ina238.c
··· 548 548 return regmap_write(data->regmap, INA238_TEMP_LIMIT, regval); 549 549 } 550 550 551 - static ssize_t energy1_input_show(struct device *dev, 552 - struct device_attribute *da, char *buf) 551 + static int ina238_read_energy(struct device *dev, s64 *energy) 553 552 { 554 553 struct ina238_data *data = dev_get_drvdata(dev); 555 - int ret; 556 554 u64 regval; 557 - u64 energy; 555 + int ret; 558 556 559 557 ret = ina238_read_reg40(data->client, SQ52206_ENERGY, &regval); 560 558 if (ret) 561 559 return ret; 562 560 563 561 /* result in uJ */ 564 - energy = regval * data->energy_lsb; 565 - 566 - return sysfs_emit(buf, "%llu\n", energy); 562 + *energy = regval * data->energy_lsb; 563 + return 0; 567 564 } 568 565 569 566 static int ina238_read(struct device *dev, enum hwmon_sensor_types type, ··· 573 576 return ina238_read_curr(dev, attr, val); 574 577 case hwmon_power: 575 578 return ina238_read_power(dev, attr, val); 579 + case hwmon_energy64: 580 + return ina238_read_energy(dev, (s64 *)val); 576 581 case hwmon_temp: 577 582 return ina238_read_temp(dev, attr, val); 578 583 default: ··· 619 620 { 620 621 const struct ina238_data *data = drvdata; 621 622 bool has_power_highest = data->config->has_power_highest; 623 + bool has_energy = data->config->has_energy; 622 624 623 625 switch (type) { 624 626 case hwmon_in: ··· 660 660 default: 661 661 return 0; 662 662 } 663 + case hwmon_energy64: 664 + /* hwmon_energy_input */ 665 + if (has_energy) 666 + return 0444; 667 + return 0; 663 668 case hwmon_temp: 664 669 switch (attr) { 665 670 case hwmon_temp_input: ··· 698 693 /* 0: power */ 699 694 HWMON_P_INPUT | HWMON_P_MAX | 700 695 HWMON_P_MAX_ALARM | HWMON_P_INPUT_HIGHEST), 696 + HWMON_CHANNEL_INFO(energy64, 697 + HWMON_E_INPUT), 701 698 HWMON_CHANNEL_INFO(temp, 702 699 /* 0: die temperature */ 703 700 HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_ALARM), ··· 716 709 .ops = &ina238_hwmon_ops, 717 710 .info = ina238_info, 718 711 }; 719 - 720 - /* energy attributes are 5 bytes wide so we need u64 */ 721 - static DEVICE_ATTR_RO(energy1_input); 722 - 723 - static struct attribute *ina238_attrs[] = { 724 - &dev_attr_energy1_input.attr, 725 - NULL, 726 - }; 727 - ATTRIBUTE_GROUPS(ina238); 728 712 729 713 static int ina238_probe(struct i2c_client *client) 730 714 { ··· 816 818 data->energy_lsb = data->power_lsb * 16; 817 819 818 820 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, 819 - &ina238_chip_info, 820 - data->config->has_energy ? 821 - ina238_groups : NULL); 821 + &ina238_chip_info, NULL); 822 822 if (IS_ERR(hwmon_dev)) 823 823 return PTR_ERR(hwmon_dev); 824 824