diff options
author | Olender, Agata <agata.olender@intel.com> | 2021-03-08 12:23:02 +0300 |
---|---|---|
committer | Jae Hyun Yoo <jae.hyun.yoo@intel.com> | 2021-07-14 20:07:04 +0300 |
commit | 7eb999e9c7437e50999348036d58b60a56fcf39d (patch) | |
tree | 172e89156e1814a419a9a9b0bb00255ca12170c4 | |
parent | 151e026a10b0fb8f85b9dcfa53542e8f14537e48 (diff) | |
download | linux-7eb999e9c7437e50999348036d58b60a56fcf39d.tar.xz |
hwmon: peci: cleanup
Add cleanup fixes after implementing energy sensor for all
modules: cpu, dimm, platform to make all files consistent.
Signed-off-by: Olender, Agata <agata.olender@intel.com>
-rw-r--r-- | drivers/hwmon/peci-cpupower.c | 47 | ||||
-rw-r--r-- | drivers/hwmon/peci-dimmpower.c | 11 | ||||
-rw-r--r-- | drivers/hwmon/peci-hwmon.h | 16 |
3 files changed, 30 insertions, 44 deletions
diff --git a/drivers/hwmon/peci-cpupower.c b/drivers/hwmon/peci-cpupower.c index 90336d24f7a2..18efa000525b 100644 --- a/drivers/hwmon/peci-cpupower.c +++ b/drivers/hwmon/peci-cpupower.c @@ -9,10 +9,10 @@ #include <linux/platform_device.h> #include "peci-hwmon.h" -enum PECI_CPUPOWER_POWER_CONFIG_TYPES { - PECI_CPUPOWER_CONFIG_TYPE_POWER = 0, - PECI_CPUPOWER_CONFIG_TYPE_ENERGY, - PECI_CPUPOWER_CONFIG_TYPES_COUNT, +enum PECI_CPUPOWER_POWER_SENSOR_TYPES { + PECI_CPUPOWER_SENSOR_TYPE_POWER = 0, + PECI_CPUPOWER_SENSOR_TYPE_ENERGY, + PECI_CPUPOWER_SENSOR_TYPES_COUNT, }; #define PECI_CPUPOWER_POWER_CHANNEL_COUNT 1 /* Supported channels number */ @@ -27,11 +27,10 @@ struct peci_cpupower { char name[PECI_NAME_SIZE]; u32 power_config[PECI_CPUPOWER_POWER_CHANNEL_COUNT + 1]; u32 energy_config[PECI_CPUPOWER_ENERGY_CHANNEL_COUNT + 1]; - u32 config_idx; struct hwmon_channel_info power_info; struct hwmon_channel_info energy_info; - const struct hwmon_channel_info *info[PECI_CPUPOWER_CONFIG_TYPES_COUNT + 1]; + const struct hwmon_channel_info *info[PECI_CPUPOWER_SENSOR_TYPES_COUNT + 1]; struct hwmon_chip_info chip; struct peci_sensor_data @@ -54,7 +53,7 @@ struct peci_cpupower { bool ppl_time_windows_valid; }; -static const char *peci_cpupower_labels[PECI_CPUPOWER_CONFIG_TYPES_COUNT] = { +static const char *peci_cpupower_labels[PECI_CPUPOWER_SENSOR_TYPES_COUNT] = { "cpu power", "cpu energy", }; @@ -96,15 +95,14 @@ peci_cpupower_get_energy_counter(struct peci_cpupower *priv, { int ret; - /* Skip energy counter read if the interval time not elapsed */ if (!peci_sensor_need_update_with_time(sensor_data, update_interval)) { - dev_dbg(priv->dev, "skip reading peci\n"); + dev_dbg(priv->dev, "skip reading package energy over peci\n"); return 0; } ret = peci_pcs_read(priv->mgr, PECI_MBX_INDEX_ENERGY_COUNTER, - PECI_PKG_ID_CPU_PACKAGE, &sensor_data->value); + PECI_PKG_ID_CPU_PACKAGE, &sensor_data->uvalue); if (ret) { dev_dbg(priv->dev, "not able to read package energy\n"); return ret; @@ -114,7 +112,7 @@ peci_cpupower_get_energy_counter(struct peci_cpupower *priv, dev_dbg(priv->dev, "energy counter updated %duJ, jif %lu, HZ is %d jiffies\n", - sensor_data->value, sensor_data->last_updated, HZ); + sensor_data->uvalue, sensor_data->last_updated, HZ); return ret; } @@ -492,18 +490,15 @@ static int peci_cpupower_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, const char **str) { - if (!str) - return -EINVAL; - if (!peci_cpupower_is_channel_valid(type, channel)) return -EOPNOTSUPP; switch (attr) { case hwmon_power_label: - *str = peci_cpupower_labels[PECI_CPUPOWER_CONFIG_TYPE_POWER]; + *str = peci_cpupower_labels[PECI_CPUPOWER_SENSOR_TYPE_POWER]; break; case hwmon_energy_label: - *str = peci_cpupower_labels[PECI_CPUPOWER_CONFIG_TYPE_ENERGY]; + *str = peci_cpupower_labels[PECI_CPUPOWER_SENSOR_TYPE_ENERGY]; break; default: return -EOPNOTSUPP; @@ -659,6 +654,8 @@ static int peci_cpupower_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct peci_cpupower *priv; struct device *hwmon_dev; + u32 power_cfg_idx = 0; + u32 energy_cfg_idx = 0; u32 cmd_mask; cmd_mask = BIT(PECI_CMD_RD_PKG_CFG) | BIT(PECI_CMD_WR_PKG_CFG); @@ -676,23 +673,21 @@ static int peci_cpupower_probe(struct platform_device *pdev) snprintf(priv->name, PECI_NAME_SIZE, "peci_cpupower.cpu%d", mgr->client->addr - PECI_BASE_ADDR); - priv->power_config[0] = HWMON_P_LABEL | - peci_sensor_get_config(peci_cpupower_power_cfg[0], - ARRAY_SIZE(peci_cpupower_power_cfg[0])); + priv->power_config[power_cfg_idx] = HWMON_P_LABEL | + peci_sensor_get_config(peci_cpupower_power_cfg[power_cfg_idx], + ARRAY_SIZE(peci_cpupower_power_cfg[power_cfg_idx])); - priv->energy_config[0] = HWMON_E_LABEL | - peci_sensor_get_config(peci_cpupower_energy_cfg[0], - ARRAY_SIZE(peci_cpupower_energy_cfg[0])); + priv->energy_config[energy_cfg_idx] = HWMON_E_LABEL | + peci_sensor_get_config(peci_cpupower_energy_cfg[energy_cfg_idx], + ARRAY_SIZE(peci_cpupower_energy_cfg[energy_cfg_idx])); - priv->info[priv->config_idx] = &priv->power_info; + priv->info[PECI_CPUPOWER_SENSOR_TYPE_POWER] = &priv->power_info; priv->power_info.type = hwmon_power; priv->power_info.config = priv->power_config; - priv->config_idx++; - priv->info[priv->config_idx] = &priv->energy_info; + priv->info[PECI_CPUPOWER_SENSOR_TYPE_ENERGY] = &priv->energy_info; priv->energy_info.type = hwmon_energy; priv->energy_info.config = priv->energy_config; - priv->config_idx++; priv->chip.ops = &peci_cpupower_ops; priv->chip.info = priv->info; diff --git a/drivers/hwmon/peci-dimmpower.c b/drivers/hwmon/peci-dimmpower.c index 18ea4a3d032a..4005fa87f829 100644 --- a/drivers/hwmon/peci-dimmpower.c +++ b/drivers/hwmon/peci-dimmpower.c @@ -81,14 +81,14 @@ peci_dimmpower_get_energy_counter(struct peci_dimmpower *priv, if (!peci_sensor_need_update_with_time(sensor_data, update_interval)) { - dev_dbg(priv->dev, "skip reading peci\n"); + dev_dbg(priv->dev, "skip reading dimm energy over peci\n"); return 0; } ret = peci_pcs_read(priv->mgr, PECI_MBX_INDEX_ENERGY_STATUS, - PECI_PKG_ID_DIMM, &sensor_data->value); + PECI_PKG_ID_DIMM, &sensor_data->uvalue); if (ret) { - dev_dbg(priv->dev, "not able to read package energy\n"); + dev_dbg(priv->dev, "not able to read dimm energy\n"); return ret; } @@ -96,7 +96,7 @@ peci_dimmpower_get_energy_counter(struct peci_dimmpower *priv, dev_dbg(priv->dev, "energy counter updated %duJ, jif %lu, HZ is %d jiffies\n", - sensor_data->value, sensor_data->last_updated, HZ); + sensor_data->uvalue, sensor_data->last_updated, HZ); return ret; } @@ -411,9 +411,6 @@ static int peci_dimmpower_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, const char **str) { - if (!str) - return -EINVAL; - if (!peci_dimmpower_is_channel_valid(type, channel)) return -EOPNOTSUPP; diff --git a/drivers/hwmon/peci-hwmon.h b/drivers/hwmon/peci-hwmon.h index e8d5b63d0a79..911bd9840b7d 100644 --- a/drivers/hwmon/peci-hwmon.h +++ b/drivers/hwmon/peci-hwmon.h @@ -461,8 +461,6 @@ static inline int peci_pcs_calc_pwr_from_eng(struct device *dev, ulong elapsed; int ret; - if (!dev || !prev_energy || !energy || !power_in_mW) - return -EINVAL; elapsed = energy->last_updated - prev_energy->last_updated; @@ -479,19 +477,16 @@ static inline int peci_pcs_calc_pwr_from_eng(struct device *dev, u64 energy_consumed_in_mJ; u64 energy_by_jiffies; - /* Take care here about energy counter rollover */ - if ((u32)(energy->value) >= (u32)(prev_energy->value)) - energy_consumed = (u32)(energy->value) - (u32)(prev_energy->value); + if (energy->uvalue >= prev_energy->uvalue) + energy_consumed = energy->uvalue - prev_energy->uvalue; else - energy_consumed = (U32_MAX - (u32)(prev_energy->value)) + - (u32)(energy->value) + 1u; + energy_consumed = (U32_MAX - prev_energy->uvalue) + + energy->uvalue + 1u; - /* Calculate the energy here */ energy_consumed_in_mJ = peci_pcs_xn_to_munits(energy_consumed, unit); energy_by_jiffies = energy_consumed_in_mJ * HZ; - /* Calculate the power */ if (energy_by_jiffies > (u64)U32_MAX) { do_div(energy_by_jiffies, elapsed); *power_in_mW = (long)energy_by_jiffies; @@ -509,8 +504,7 @@ static inline int peci_pcs_calc_pwr_from_eng(struct device *dev, ret = -EAGAIN; } - /* Update previous energy sensor context with current value */ - prev_energy->value = energy->value; + prev_energy->uvalue = energy->uvalue; peci_sensor_mark_updated_with_time(prev_energy, energy->last_updated); return ret; |