extensions and fixes
Subsystems (2)
v3 cover extensions and fixes
This series covers three areas of power supply class:
1-5. constify property and usb_type lists as they should not be changed
after driver registration
6-8. fix and clean up HWMON labels
9-11. extend core to support input/battery/output supply point
measurements
I guess the first part is largely independent, so I can extract it to a separate series if that's useful.
---
v2: splits power_supply_hwmon_read_string() fix from extensioa
(patches 3-4)
v3: removes power_supply_hwmon_read_string() parameter checks and
adds a prerequisite patches to two drivers to make them compile after property list constification patch is applied
---
Michał Mirosław (11):
power: charger-manager: remove duplicate assignment
power: charger-manager: don't write through desc->properties
power: generic-adc-battery: fold psy_props[] to private data
power: supply: core: reduce power_supply_show_usb_type() parameters
power: supply: core: allow to constify property lists
power: supply: core: fix HWMON temperature labels
power: supply: core: tabularize HWMON temperature labels
power: supply: core: hide unused HWMON labels
power: supply: core: add input voltage/current measurements
power: supply: core: add output voltage measurements
power: supply: core: document measurement points
Documentation/power/power_supply_class.rst | 6 + drivers/power/supply/charger-manager.c | 17 +- drivers/power/supply/generic-adc-battery.c | 30 ++-- drivers/power/supply/power_supply_hwmon.c | 178 +++++++++++++++++++-- drivers/power/supply/power_supply_sysfs.c | 15 +- include/linux/power_supply.h | 9 +- 6 files changed, 211 insertions(+), 44 deletions(-)
Signature · 1 line
2.20.1
PATCH v3 1/11 power: charger-manager: remove duplicate assignment
num_properties is already copied earlier using memcpy(). Remove the duplicate.
---
v3: initial version
--- drivers/power/supply/charger-manager.c | 1 - 1 file changed, 1 deletion(-)
drivers/power/supply/charger-manager.c +0 -1
@@ -1728,7 +1728,6 @@ static int charger_manager_probe(struct platform_device *pdev)memcpy (cm->charger_psy_desc.properties, default_charger_props,sizeof (enum power_supply_property ) *ARRAY_SIZE (default_charger_props)); - cm->charger_psy_desc.num_properties = psy_default.num_properties;/* Find which optional psy-properties are available */ fuel_gauge =power_supply_get_by_name (desc->psy_fuel_gauge);
Signature · 1 line
2.20.1
PATCH v3 2/11 power: charger-manager: don't write through desc->properties
In reply to Michał Mirosławpsy_desc->properties will become pointer to const. Avoid writing through the pointer to enable constification of the tables elsewhere.
---
v3: initial version
--- drivers/power/supply/charger-manager.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/power/supply/charger-manager.c +10 -6
@@ -1425,15 +1425,18 @@ static int cm_init_thermal_data(struct charger_manager *cm, struct power_supply *fuel_gauge) {struct charger_desc *desc = cm->desc; +enum power_supply_property *props;union power_supply_propval val;int ret; + props = (void *)cm->charger_psy_desc.properties; +/* Verify whether fuel gauge provides battery temperature */ ret =power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_TEMP , &val);if (!ret) { - cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = + props[cm->charger_psy_desc.num_properties] =POWER_SUPPLY_PROP_TEMP ; cm->charger_psy_desc.num_properties++; cm->desc->measure_battery_temp = true;
@@ -1446,7 +1449,7 @@ static int cm_init_thermal_data(struct charger_manager *cm,return PTR_ERR (cm->tzd_batt);/* Use external thermometer */ - cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = + props[cm->charger_psy_desc.num_properties] =POWER_SUPPLY_PROP_TEMP_AMBIENT ; cm->charger_psy_desc.num_properties++; cm->desc->measure_battery_temp = true;
@@ -1622,6 +1625,7 @@ static int charger_manager_probe(struct platform_device *pdev)union power_supply_propval val;struct power_supply *fuel_gauge;struct power_supply_config psy_cfg = {}; +enum power_supply_property *props;if (IS_ERR (desc)) {dev_err (&pdev->dev,"No platform data (desc) found\n" );
@@ -1717,7 +1721,7 @@ static int charger_manager_probe(struct platform_device *pdev) cm->charger_psy_desc.name = cm->psy_name_buf;/* Allocate for psy properties because they may vary */ - cm->charger_psy_desc.properties = + cm->charger_psy_desc.properties = props = devm_kcalloc(&pdev->dev, ARRAY_SIZE(default_charger_props) + NUM_CHARGER_PSY_OPTIONAL,
@@ -1725,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)if (!cm->charger_psy_desc.properties)return -ENOMEM ; -memcpy (cm->charger_psy_desc.properties, default_charger_props, +memcpy (props, default_charger_props,sizeof (enum power_supply_property ) *ARRAY_SIZE (default_charger_props));
@@ -1738,14 +1742,14 @@ static int charger_manager_probe(struct platform_device *pdev) }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CHARGE_NOW , &val)) { - cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = + props[cm->charger_psy_desc.num_properties] =POWER_SUPPLY_PROP_CHARGE_NOW ; cm->charger_psy_desc.num_properties++; }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CURRENT_NOW , &val)) { - cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = + props[cm->charger_psy_desc.num_properties] =POWER_SUPPLY_PROP_CURRENT_NOW ; cm->charger_psy_desc.num_properties++; }
Signature · 1 line
2.20.1
Re: [PATCH v3 02/11] power: charger-manager: don't write through desc->properties
Hi,
Quoted 5 lines · Michał Mirosław
psy_desc->propertieswill become pointer to const. Avoid writing through the pointer to enable constification of the tables elsewhere.Signed-off-by Michał Mirosław <[email protected]>---
For patches 1-3 I used my version, that I wrote in parallel while reviewing a different patch series. It is slightly different, but achieves the same goal.
-- Sebastian
Re: [PATCH v3 02/11] power: charger-manager: don't write through desc->properties
Quoted 10 lines · Sebastian Reichel
Hi,
Quoted 4 lines · Michał Mirosław
psy_desc->propertieswill become pointer to const. Avoid writing through the pointer to enable constification of the tables elsewhere.Signed-off-by Michał Mirosław <[email protected]>For patches 1-3 I used my version, that I wrote in parallel while reviewing a different patch series. It is slightly different, but achieves the same goal.
There is a bug in the tree now regarding use of num_properties in charger-manager. Following patch should fix it.
Best Regards,
Michał Mirosław
drivers/power/supply/charger-manager.c +2 -2
@@ -1740,14 +1740,14 @@ static int charger_manager_probe(struct platform_device *pdev) }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CHARGE_NOW , &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] =POWER_SUPPLY_PROP_CHARGE_NOW ; num_properties++; }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CURRENT_NOW , &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] =POWER_SUPPLY_PROP_CURRENT_NOW ; num_properties++; }
PATCH 1/1 power: charger-manager: fix adding of optional properties
Use num_properties to index added property.
This will prevent overwriting POWER_SUPPLY_PROP_CHARGE_NOW with POWER_SUPPLY_PROP_CURRENT_NOW and leaving the latter entry uninitialized.
For clarity, num_properties is initialized with length of the copied array instead of relying on previously memcpy'd value.
--- drivers/power/supply/charger-manager.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/power/supply/charger-manager.c +3 -3
@@ -1729,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)memcpy (properties, default_charger_props,sizeof (enum power_supply_property ) *ARRAY_SIZE (default_charger_props)); - num_properties = psy_default.num_properties; + num_properties =ARRAY_SIZE (default_charger_props);/* Find which optional psy-properties are available */ fuel_gauge =power_supply_get_by_name (desc->psy_fuel_gauge);
@@ -1740,14 +1740,14 @@ static int charger_manager_probe(struct platform_device *pdev) }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CHARGE_NOW , &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] =POWER_SUPPLY_PROP_CHARGE_NOW ; num_properties++; }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CURRENT_NOW , &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] =POWER_SUPPLY_PROP_CURRENT_NOW ; num_properties++; }
Signature · 1 line
2.20.1
Re: [PATCH] power: charger-manager: fix adding of optional properties
Hi,
Quoted 11 lines · Michał Mirosław
Use
num_propertiesto index added property.
This will prevent overwritingPOWER_SUPPLY_PROP_CHARGE_NOWwithPOWER_SUPPLY_PROP_CURRENT_NOWand leaving the latter entry uninitialized.For clarity,
num_propertiesis initialized with length of the copied array instead of relying on previously memcpy'd value.Fixes 0a46510addc7 ("power: supply: charger-manager: Prepare for const properties")Signed-off-by Michał Mirosław <[email protected]>---
I folded your fix directly into the charger-manager patch, which did not yet reach linux-next. If you send the num_properties part as a separate one, I will merge it.
-- Sebastian
Quoted 36 lines
drivers/power/supply/charger-manager.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/power/supply/charger-manager.c +3
-3@@ -1729,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)memcpy (properties, default_charger_props,sizeof (enum power_supply_property ) *ARRAY_SIZE (default_charger_props)); - num_properties = psy_default.num_properties; + num_properties =ARRAY_SIZE (default_charger_props);/* Find which optional psy-properties are available */ fuel_gauge =power_supply_get_by_name (desc->psy_fuel_gauge);@@ -1740,14 +1740,14 @@ static int charger_manager_probe(struct platform_device *pdev) }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CHARGE_NOW , &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] =POWER_SUPPLY_PROP_CHARGE_NOW ; num_properties++; }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CURRENT_NOW , &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] =POWER_SUPPLY_PROP_CURRENT_NOW ; num_properties++; }Signature · 1 line
2.20.1
Re: [PATCH] power: charger-manager: fix adding of optional properties
Quoted 11 lines · Sebastian Reichel
Hi,
Quoted 8 lines · Michał Mirosław
Use
num_propertiesto index added property.
This will prevent overwritingPOWER_SUPPLY_PROP_CHARGE_NOWwithPOWER_SUPPLY_PROP_CURRENT_NOWand leaving the latter entry uninitialized.For clarity,
num_propertiesis initialized with length of the copied array instead of relying on previously memcpy'd value.
Quoted 7 lines
Quoted 3 lines
Fixes 0a46510addc7 ("power: supply: charger-manager: Prepare for const properties")Signed-off-by Michał Mirosław <[email protected]>---
I folded your fix directly into the charger-manager patch, which did not yet reach linux-next. If you send the
num_propertiespart as a separate one, I will merge it.
Since your patch already changes the line, maybe you could squash first hunk below into it?
Quoted 16 lines
Quoted 16 lines
drivers/power/supply/charger-manager.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/power/supply/charger-manager.c +1
-1@@ -1729,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)memcpy (properties, default_charger_props,sizeof (enum power_supply_property ) *ARRAY_SIZE (default_charger_props)); - num_properties = psy_default.num_properties; + num_properties =ARRAY_SIZE (default_charger_props);/* Find which optional psy-properties are available */ fuel_gauge =power_supply_get_by_name (desc->psy_fuel_gauge);
[...]
PATCH 1/1 power: charger-manager: clarify num_properties starting value
In reply to Sebastian ReichelInitialize num_properties with length of the copied array instead of relying on previously memcpy'd value. This makes it clear how the array and the counter are related.
--- drivers/power/supply/charger-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/charger-manager.c +1 -1
@@ -1729,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)memcpy (properties, default_charger_props,sizeof (enum power_supply_property ) *ARRAY_SIZE (default_charger_props)); - num_properties = psy_default.num_properties; + num_properties =ARRAY_SIZE (default_charger_props);/* Find which optional psy-properties are available */ fuel_gauge =power_supply_get_by_name (desc->psy_fuel_gauge);
Signature · 1 line
2.20.1
Re: [PATCH] power: charger-manager: clarify num_properties starting value
Hi,
Quoted 6 lines · Michał Mirosław
Initialize
num_propertieswith length of the copied array instead of relying on previously memcpy'd value. This makes it clear how the array and the counter are related.Signed-off-by Michał Mirosław <[email protected]>---
Thanks, queued.
-- Sebastian
Quoted 19 lines
drivers/power/supply/charger-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/supply/charger-manager.c +1
-1@@ -1729,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)memcpy (properties, default_charger_props,sizeof (enum power_supply_property ) *ARRAY_SIZE (default_charger_props)); - num_properties = psy_default.num_properties; + num_properties =ARRAY_SIZE (default_charger_props);/* Find which optional psy-properties are available */ fuel_gauge =power_supply_get_by_name (desc->psy_fuel_gauge);Signature · 1 line
2.20.1
Re: [PATCH v3 02/11] power: charger-manager: don't write through desc->properties
In reply to Michał MirosławHi,
Quoted 7 lines · Michał Mirosław
Quoted 6 lines · Sebastian Reichel
Hi,
Quoted 3 lines · Michał Mirosław
psy_desc->propertieswill become pointer to const. Avoid writing through the pointer to enable constification of the tables elsewhere.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Michał Mirosław <[email protected]>For patches 1-3 I used my version, that I wrote in parallel while reviewing a different patch series. It is slightly different, but achieves the same goal.
There is a bug in the tree now regarding use of
num_propertiesin charger-manager. Following patch should fix it.
Thanks, I folded this into the charger-manager patch.
-- Sebastian
Quoted 24 lines
Best Regards,
Michał Mirosławdrivers/power/supply/charger-manager.c +2
-2@@ -1740,14 +1740,14 @@ static int charger_manager_probe(struct platform_device *pdev) }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CHARGE_NOW , &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] =POWER_SUPPLY_PROP_CHARGE_NOW ; num_properties++; }if (!power_supply_get_property (fuel_gauge,POWER_SUPPLY_PROP_CURRENT_NOW , &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] =POWER_SUPPLY_PROP_CURRENT_NOW ; num_properties++; }
PATCH v3 3/11 power: generic-adc-battery: fold psy_props[] to private data
In reply to Michał Mirosławpsy_desc->properties will become pointer to const, so we can't use it for filling the property set. Let's append the list to private data structure and avoid introducing another variable to temporarily hold the pointer.
---
v3: new patch, required before constification of property lists
--- drivers/power/supply/generic-adc-battery.c | 30 ++++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-)
drivers/power/supply/generic-adc-battery.c +10 -20
@@ -52,6 +52,7 @@ struct gab {int level;int status;bool cable_plugged; +enum power_supply_property psy_props[]; };static struct gab *to_generic_bat (struct power_supply *psy)
@@ -246,7 +247,10 @@ static int gab_probe(struct platform_device *pdev)int index =ARRAY_SIZE (gab_props);bool any = false; - adc_bat =devm_kzalloc (&pdev->dev,sizeof (*adc_bat),GFP_KERNEL ); + adc_bat =devm_kzalloc (&pdev->dev, +struct_size (adc_bat, psy_props, +ARRAY_SIZE (gab_props) +ARRAY_SIZE (gab_chan_name)), +GFP_KERNEL );if (!adc_bat) {dev_err (&pdev->dev,"failed to allocate memory\n" );return -ENOMEM ;
@@ -264,20 +268,8 @@ static int gab_probe(struct platform_device *pdev) psy_desc->external_power_changed = gab_ext_power_changed; adc_bat->pdata = pdata; -/* -* copying the static properties and allocating extra memory for holding -* the extra configurable properties received from platform data. -*/ - psy_desc->properties =kcalloc (ARRAY_SIZE (gab_props) + -ARRAY_SIZE (gab_chan_name), -sizeof (*psy_desc->properties), -GFP_KERNEL ); -if (!psy_desc->properties) { - ret = -ENOMEM ; - goto first_mem_fail; - } - -memcpy (psy_desc->properties, gab_props,sizeof (gab_props)); +/* copy static properties */ +memcpy (adc_bat->psy_props, gab_props,sizeof (gab_props));/* * getting channel from iio and copying the battery properties
@@ -294,12 +286,12 @@ static int gab_probe(struct platform_device *pdev)int index2;for (index2 =0 ; index2 < index; index2++) { -if (psy_desc->properties[index2] == +if (adc_bat->psy_props[index2] == gab_dyn_props[chan])break ;/* already known */ }if (index2 == index)/* really new */ - psy_desc->properties[index++] = + adc_bat->psy_props[index++] = gab_dyn_props[chan]; any = true; }
@@ -317,6 +309,7 @@ static int gab_probe(struct platform_device *pdev)* as come channels may be not be supported by the device.So * we need to take care of that. */ + psy_desc->properties = adc_bat->psy_props; psy_desc->num_properties = index; adc_bat->psy =power_supply_register (&pdev->dev, psy_desc, &psy_cfg);
@@ -358,8 +351,6 @@ static int gab_probe(struct platform_device *pdev)iio_channel_release (adc_bat->channel[chan]); } second_mem_fail: -kfree (psy_desc->properties); -first_mem_fail:return ret; }
@@ -381,7 +372,6 @@ static int gab_remove(struct platform_device *pdev)iio_channel_release (adc_bat->channel[chan]); } -kfree (adc_bat->psy_desc.properties);cancel_delayed_work (&adc_bat->bat_work);return 0 ; }
Signature · 1 line
2.20.1
PATCH v3 4/11 power: supply: core: reduce power_supply_show_usb_type() parameters
In reply to Michał MirosławReduce power_supply_show_usb_type() parameter count by folding power_supply_desc dereference into the function. This makes following patch making usb_types const easier.
--- drivers/power/supply/power_supply_sysfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/power/supply/power_supply_sysfs.c +4 -6
@@ -78,8 +78,7 @@ static const char * const power_supply_scope_text[] = { };static ssize_t power_supply_show_usb_type (struct device *dev, -enum power_supply_usb_type *usb_types, -ssize_t num_usb_types, +const struct power_supply_desc *desc,union power_supply_propval *value,char *buf) {
@@ -88,8 +87,8 @@ static ssize_t power_supply_show_usb_type(struct device *dev,bool match = false;int i; -for (i =0 ; i < num_usb_types; ++i) { - usb_type = usb_types[i]; +for (i =0 ; i < desc->num_usb_types; ++i) { + usb_type = desc->usb_types[i];if (value->intval == usb_type) { count += sprintf(buf + count, "[%s] ",
@@ -163,8 +162,7 @@ static ssize_t power_supply_show_property(struct device *dev, power_supply_type_text[value.intval]);break ;case POWER_SUPPLY_PROP_USB_TYPE : - ret =power_supply_show_usb_type (dev, psy->desc->usb_types, - psy->desc->num_usb_types, + ret =power_supply_show_usb_type (dev, psy->desc, &value, buf);break ;case POWER_SUPPLY_PROP_SCOPE :
Signature · 1 line
2.20.1
Re: [PATCH v3 04/11] power: supply: core: reduce power_supply_show_usb_type() parameters
Hi,
Quoted 6 lines · Michał Mirosław
Reduce
power_supply_show_usb_type()parameter count by foldingpower_supply_descdereference into the function. This makes following patch makingusb_typesconst easier.Signed-off-by Michał Mirosław <[email protected]>---
Thanks, queued.
-- Sebastian
Quoted 41 lines
drivers/power/supply/power_supply_sysfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/power/supply/power_supply_sysfs.c +4
-6@@ -78,8 +78,7 @@ static const char * const power_supply_scope_text[] = { };static ssize_t power_supply_show_usb_type (struct device *dev, -enum power_supply_usb_type *usb_types, -ssize_t num_usb_types, +const struct power_supply_desc *desc,union power_supply_propval *value,char *buf) {@@ -88,8 +87,8 @@ static ssize_t power_supply_show_usb_type(struct device *dev,bool match = false;int i; -for (i =0 ; i < num_usb_types; ++i) { - usb_type = usb_types[i]; +for (i =0 ; i < desc->num_usb_types; ++i) { + usb_type = desc->usb_types[i];if (value->intval == usb_type) { count += sprintf(buf + count, "[%s] ",@@ -163,8 +162,7 @@ static ssize_t power_supply_show_property(struct device *dev, power_supply_type_text[value.intval]);break ;case POWER_SUPPLY_PROP_USB_TYPE : - ret =power_supply_show_usb_type (dev, psy->desc->usb_types, - psy->desc->num_usb_types, + ret =power_supply_show_usb_type (dev, psy->desc, &value, buf);break ;case POWER_SUPPLY_PROP_SCOPE :Signature · 1 line
2.20.1
PATCH v3 5/11 power: supply: core: allow to constify property lists
In reply to Michał MirosławSince tables pointed to by power_supply_desc->properties and ->usb_types are not expected to change after registration, mark the pointers accordingly
--- include/linux/power_supply.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/power_supply.h +2 -2
@@ -223,9 +223,9 @@ struct power_supply_config {struct power_supply_desc {const char *name;enum power_supply_type type; -enum power_supply_usb_type *usb_types; +const enum power_supply_usb_type *usb_types;size_t num_usb_types; -enum power_supply_property *properties; +const enum power_supply_property *properties;size_t num_properties;/*
Signature · 1 line
2.20.1
Re: [PATCH v3 05/11] power: supply: core: allow to constify property lists
Hi,
Quoted 6 lines · Michał Mirosław
Since tables pointed to by
power_supply_desc->propertiesand ->usb_types are not expected to change after registration, mark the pointers accordinglySigned-off-by Michał Mirosław <[email protected]>---
Thanks, queued.
-- Sebastian
Quoted 22 lines
include/linux/power_supply.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/power_supply.h +2
-2@@ -223,9 +223,9 @@ struct power_supply_config {struct power_supply_desc {const char *name;enum power_supply_type type; -enum power_supply_usb_type *usb_types; +const enum power_supply_usb_type *usb_types;size_t num_usb_types; -enum power_supply_property *properties; +const enum power_supply_property *properties;size_t num_properties;/* Signature · 1 line
2.20.1
PATCH v3 6/11 power: supply: core: fix HWMON temperature labels
In reply to Michał MirosławtempX_label files are swapped compared to what power_supply_hwmon_temp_to_property() uses. Make them match.
---
v2: split parameter checking to separate patch
--- drivers/power/supply/power_supply_hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/power_supply_hwmon.c +1 -1
@@ -144,7 +144,7 @@ static int power_supply_hwmon_read_string(struct device *dev, u32 attr, int channel, const char **str) { - *str = channel ?"temp" :"temp ambient" ; + *str = channel ?"temp ambient" :"temp" ;return 0 ; }
Signature · 1 line
2.20.1
Re: [PATCH v3 06/11] power: supply: core: fix HWMON temperature labels
Hi,
Quoted 9 lines · Michał Mirosław
tempX_labelfiles are swapped compared to whatpower_supply_hwmon_temp_to_property()uses. Make them match.Fixes e67d4dfc9ff1 ("power: supply: Add HWMON compatibility layer")Signed-off-by Michał Mirosław <[email protected]>---
v2: split parameter checking to separate patch
---
Thanks, queued.
-- Sebastian
Quoted 19 lines
drivers/power/supply/power_supply_hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/supply/power_supply_hwmon.c +1
-1@@ -144,7 +144,7 @@ static int power_supply_hwmon_read_string(struct device *dev, u32 attr, int channel, const char **str) { - *str = channel ?"temp" :"temp ambient" ; + *str = channel ?"temp ambient" :"temp" ;return 0 ; }Signature · 1 line
2.20.1
PATCH v3 7/11 power: supply: core: tabularize HWMON temperature labels
In reply to Michał MirosławRework power_supply_hwmon_read_string() to check it's parameters. This allows to extend it later with labels for other types of measurements.
---
v2: split from fix temperature labels
v3: remove power_supply_hwmon_read_string() parameter checks
as it is internal API (suggested by Guenter Roeck)
--- drivers/power/supply/power_supply_hwmon.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/power/supply/power_supply_hwmon.c +13 -1
@@ -13,6 +13,11 @@ struct power_supply_hwmon {unsigned long *props; }; +static const char *const ps_temp_label[] = { +"temp" , +"ambient temp" , +}; +static int power_supply_hwmon_in_to_property (u32 attr) {switch (attr) {
@@ -144,7 +149,14 @@ static int power_supply_hwmon_read_string(struct device *dev, u32 attr, int channel, const char **str) { - *str = channel ?"temp ambient" :"temp" ; + switch (type) { + case hwmon_temp: + *str = ps_temp_label[channel]; +break ; +default : +unreachable (); + } +return 0 ; }
Signature · 1 line
2.20.1
kbuild test robot
build botRe: [PATCH v3 07/11] power: supply: core: tabularize HWMON temperature labels
I love your patch! Perhaps something to improve:
Hi "Michał,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on hwmon/hwmon-next linus/master v5.6 next-20200404] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Micha-Miros-aw/extensions-and-fixes/20200405-044024 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: x86_64-randconfig-b002-20200405 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 62f3a9650a9f289a07a5f480764fb655178c2334)
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/power/supply/power_supply_hwmon.o: warning: objtool: power_supply_hwmon_read_string() falls through to next function power_supply_hwmon_write()
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v3 07/11] power: supply: core: tabularize HWMON temperature labels
Quoted 21 lines · kbuild test robot
Hi "Michał,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on hwmon/hwmon-next linus/master v5.6 next-20200404] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Micha-Miros-aw/extensions-and-fixes/20200405-044024 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: x86_64-randconfig-b002-20200405 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 62f3a9650a9f289a07a5f480764fb655178c2334)reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64
Quoted 6 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/power/supply/power_supply_hwmon.o: warning: objtool:power_supply_hwmon_read_string()falls through to next functionpower_supply_hwmon_write()
I'm guessing this is from the unreachable:
https://github.com/0day-ci/linux/commit/b8b2d14ca46ca54257f55c9af58ea25695b9ee36
I'll need to play with this some more as I couldn't reproduce with a simplified test case, but looks like a compiler bug. Filed
https://github.com/ClangBuiltLinux/linux/issues/978 for me to track.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH v3 07/11] power: supply: core: tabularize HWMON temperature labels
Quoted 27 lines · Nick Desaulniers
Quoted 26 lines · kbuild test robot
Hi "Michał,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on hwmon/hwmon-next linus/master v5.6 next-20200404] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Micha-Miros-aw/extensions-and-fixes/20200405-044024 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: x86_64-randconfig-b002-20200405 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 62f3a9650a9f289a07a5f480764fb655178c2334)reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/power/supply/power_supply_hwmon.o: warning: objtool:power_supply_hwmon_read_string()falls through to next functionpower_supply_hwmon_write()I'm guessing this is from the unreachable:
https://github.com/0day-ci/linux/commit/b8b2d14ca46ca54257f55c9af58ea25695b9ee36
I'll need to play with this some more as I couldn't reproduce with a simplified test case, but looks like a compiler bug. Filed
https://github.com/ClangBuiltLinux/linux/issues/978 for me to track.
Hi Nick,
Just guessing: have you tried adding another unrelated function to the testcase? I would expect that 'fall through to next function' needs some other function to match.
Best Regards,
Michał Mirosław
Re: [PATCH v3 07/11] power: supply: core: tabularize HWMON temperature labels
Quoted 37 lines · Michał Mirosław
Quoted 27 lines · Nick Desaulniers
Quoted 26 lines · kbuild test robot
Hi "Michał,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on hwmon/hwmon-next linus/master v5.6 next-20200404] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Micha-Miros-aw/extensions-and-fixes/20200405-044024 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: x86_64-randconfig-b002-20200405 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 62f3a9650a9f289a07a5f480764fb655178c2334)reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/power/supply/power_supply_hwmon.o: warning: objtool:power_supply_hwmon_read_string()falls through to next functionpower_supply_hwmon_write()I'm guessing this is from the unreachable:
https://github.com/0day-ci/linux/commit/b8b2d14ca46ca54257f55c9af58ea25695b9ee36
I'll need to play with this some more as I couldn't reproduce with a simplified test case, but looks like a compiler bug. Filed
https://github.com/ClangBuiltLinux/linux/issues/978 for me to track.
Quoted 5 lines
Hi Nick,
Just guessing: have you tried adding another unrelated function to the testcase? I would expect that 'fall through to next function' needs some other function to match.
I was throwing the test case linked into godbolt and looking at the generated assembly. It contained no jumps, only movs and conditional movs. Thank you for the suggestion.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH v3 07/11] power: supply: core: tabularize HWMON temperature labels
+ Ilie
Quoted 39 lines · Nick Desaulniers
Quoted 37 lines · Michał Mirosław
Quoted 34 lines · Nick Desaulniers
Quoted 21 lines · kbuild test robot
Hi "Michał,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on hwmon/hwmon-next linus/master v5.6 next-20200404] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Micha-Miros-aw/extensions-and-fixes/20200405-044024 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: x86_64-randconfig-b002-20200405 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 62f3a9650a9f289a07a5f480764fb655178c2334)reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64Quoted 6 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/power/supply/power_supply_hwmon.o: warning: objtool:power_supply_hwmon_read_string()falls through to next functionpower_supply_hwmon_write()I'm guessing this is from the unreachable:
https://github.com/0day-ci/linux/commit/b8b2d14ca46ca54257f55c9af58ea25695b9ee36
I'll need to play with this some more as I couldn't reproduce with a simplified test case, but looks like a compiler bug. Filed
https://github.com/ClangBuiltLinux/linux/issues/978 for me to track.
Quoted 5 lines
Quoted 5 lines
Hi Nick,
Just guessing: have you tried adding another unrelated function to the testcase? I would expect that 'fall through to next function' needs some other function to match.
See Ilie's suggestion:
https://github.com/ClangBuiltLinux/linux/issues/978#issuecomment-610633039
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH v3 07/11] power: supply: core: tabularize HWMON temperature labels
In reply to Nick DesaulniersQuoted 27 lines · Nick Desaulniers
Quoted 26 lines · kbuild test robot
Hi "Michał,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on hwmon/hwmon-next linus/master v5.6 next-20200404] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Micha-Miros-aw/extensions-and-fixes/20200405-044024 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: x86_64-randconfig-b002-20200405 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 62f3a9650a9f289a07a5f480764fb655178c2334)reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/power/supply/power_supply_hwmon.o: warning: objtool:power_supply_hwmon_read_string()falls through to next functionpower_supply_hwmon_write()I'm guessing this is from the unreachable:
https://github.com/0day-ci/linux/commit/b8b2d14ca46ca54257f55c9af58ea25695b9ee36
I'll need to play with this some more as I couldn't reproduce with a simplified test case, but looks like a compiler bug. Filed
https://github.com/ClangBuiltLinux/linux/issues/978 for me to track.
Hi,
For gcc this is bug 51513 [1]. This does not affect correctness of the code, so I wonder if we should/need be trying to work around it.
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51513
Best Regards,
Michał Mirosław
Re: [PATCH v3 07/11] power: supply: core: tabularize HWMON temperature labels
Hi,
Quoted 36 lines · Michał Mirosław
Quoted 27 lines · Nick Desaulniers
Quoted 26 lines · kbuild test robot
Hi "Michał,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on hwmon/hwmon-next linus/master v5.6 next-20200404] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Micha-Miros-aw/extensions-and-fixes/20200405-044024 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: x86_64-randconfig-b002-20200405 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 62f3a9650a9f289a07a5f480764fb655178c2334)reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/power/supply/power_supply_hwmon.o: warning: objtool:power_supply_hwmon_read_string()falls through to next functionpower_supply_hwmon_write()I'm guessing this is from the unreachable:
https://github.com/0day-ci/linux/commit/b8b2d14ca46ca54257f55c9af58ea25695b9ee36
I'll need to play with this some more as I couldn't reproduce with a simplified test case, but looks like a compiler bug. Filed
https://github.com/ClangBuiltLinux/linux/issues/978 for me to track.
Quoted 6 lines
Hi,
For gcc this is bug 51513 [1]. This does not affect correctness of the code, so I wonder if we should/need be trying to work around it.
Yes, we need to work around it for now. If I understand the situation correctly, a simple workaround would be:
default:
/*
* unreachable, but not explicitly marked because this triggers
* a compiler bug in gcc and llvm:
*
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51513
* https://github.com/ClangBuiltLinux/linux/issues/978
*/
break;
-- Sebastian
PATCH v3 8/11 power: supply: core: hide unused HWMON labels
In reply to Michał MirosławCurrently HWMON emulation shows all labels (temp and ambient temp) regardless if power supply supports reading the values. Check that at least one property is enabled for each label.
---
v3: use a tabule for type checking instead of switch() sequence
--- drivers/power/supply/power_supply_hwmon.c | 42 +++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-)
drivers/power/supply/power_supply_hwmon.c +39 -3
@@ -103,6 +103,39 @@ static bool power_supply_hwmon_is_a_label(enum hwmon_sensor_types type,return type == hwmon_temp && attr == hwmon_temp_label; } +struct hwmon_type_attr_list { +const u32 *attrs; +size_t n_attrs; +}; + +static const u32 ps_temp_attrs[] = { + hwmon_temp_input, + hwmon_temp_min, hwmon_temp_max, + hwmon_temp_min_alarm, hwmon_temp_max_alarm, +}; + +static const struct hwmon_type_attr_list ps_type_attrs[hwmon_max] = { + [hwmon_temp] = { ps_temp_attrs,ARRAY_SIZE (ps_temp_attrs) }, +}; + +static bool power_supply_hwmon_has_input ( +const struct power_supply_hwmon *psyhw, +enum hwmon_sensor_types type,int channel) +{ +const struct hwmon_type_attr_list *attr_list = &ps_type_attrs[type]; +size_t i; + +for (i =0 ; i < attr_list->n_attrs; ++i) { +int prop =power_supply_hwmon_to_property (type, + attr_list->attrs[i], channel); + +if (prop >=0 &&test_bit (prop, psyhw->props)) +return true; + } + +return false; +} +static bool power_supply_hwmon_is_writable (enum hwmon_sensor_types type,u32 attr) {
@@ -129,9 +162,12 @@ static umode_t power_supply_hwmon_is_visible(const void *data,const struct power_supply_hwmon *psyhw = data;int prop; - -if (power_supply_hwmon_is_a_label (type, attr)) -return 0444 ; +if (power_supply_hwmon_is_a_label (type, attr)) { +if (power_supply_hwmon_has_input (psyhw, type, channel)) +return 0444 ; +else +return 0 ; + } prop =power_supply_hwmon_to_property (type, attr, channel);if (prop <0 || !test_bit (prop, psyhw->props))
Signature · 1 line
2.20.1
Re: [PATCH v3 08/11] power: supply: core: hide unused HWMON labels
Hi,
Quoted 6 lines · Michał Mirosław
Currently HWMON emulation shows all labels (temp and ambient temp) regardless if power supply supports reading the values. Check that at least one property is enabled for each label.
Signed-off-by Michał Mirosław <[email protected]>---
Thanks, queued.
-- Sebastian
Quoted 68 lines
v3: use a tabule for type checking instead of
switch()sequence--- drivers/power/supply/power_supply_hwmon.c | 42 +++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-)drivers/power/supply/power_supply_hwmon.c +39
-3@@ -103,6 +103,39 @@ static bool power_supply_hwmon_is_a_label(enum hwmon_sensor_types type,return type == hwmon_temp && attr == hwmon_temp_label; } +struct hwmon_type_attr_list { +const u32 *attrs; +size_t n_attrs; +}; + +static const u32 ps_temp_attrs[] = { + hwmon_temp_input, + hwmon_temp_min, hwmon_temp_max, + hwmon_temp_min_alarm, hwmon_temp_max_alarm, +}; + +static const struct hwmon_type_attr_list ps_type_attrs[hwmon_max] = { + [hwmon_temp] = { ps_temp_attrs,ARRAY_SIZE (ps_temp_attrs) }, +}; + +static bool power_supply_hwmon_has_input ( +const struct power_supply_hwmon *psyhw, +enum hwmon_sensor_types type,int channel) +{ +const struct hwmon_type_attr_list *attr_list = &ps_type_attrs[type]; +size_t i; + +for (i =0 ; i < attr_list->n_attrs; ++i) { +int prop =power_supply_hwmon_to_property (type, + attr_list->attrs[i], channel); + +if (prop >=0 &&test_bit (prop, psyhw->props)) +return true; + } + +return false; +} +static bool power_supply_hwmon_is_writable (enum hwmon_sensor_types type,u32 attr) {@@ -129,9 +162,12 @@ static umode_t power_supply_hwmon_is_visible(const void *data,const struct power_supply_hwmon *psyhw = data;int prop; - -if (power_supply_hwmon_is_a_label (type, attr)) -return 0444 ; +if (power_supply_hwmon_is_a_label (type, attr)) { +if (power_supply_hwmon_has_input (psyhw, type, channel)) +return 0444 ; +else +return 0 ; + } prop =power_supply_hwmon_to_property (type, attr, channel);if (prop <0 || !test_bit (prop, psyhw->props))Signature · 1 line
2.20.1
PATCH v3 9/11 power: supply: core: add input voltage/current measurements
In reply to Michał MirosławIntroduce input voltage and current limits and measurements. This makes room for e.g. VBUS measurements in USB chargers.
---
v2: add parameter checking in power_supply_hwmon_read_string()
v3: remove power_supply_hwmon_read_string() parameter checks
as it is internal API (suggested by Guenter Roeck)
--- drivers/power/supply/power_supply_hwmon.c | 97 +++++++++++++++++++++-- drivers/power/supply/power_supply_sysfs.c | 2 + include/linux/power_supply.h | 2 + 3 files changed, 96 insertions(+), 5 deletions(-)
drivers/power/supply/power_supply_hwmon.c +92 -5
@@ -13,12 +13,17 @@ struct power_supply_hwmon {unsigned long *props; }; +static const char *const ps_input_label[] = { +"battery" , +"external source" , +}; +static const char *const ps_temp_label[] = {"temp" ,"ambient temp" , }; -static int power_supply_hwmon_in_to_property (u32 attr) +static int power_supply_hwmon_in0_to_property (u32 attr) {switch (attr) {case hwmon_in_average:
@@ -34,7 +39,31 @@ static int power_supply_hwmon_in_to_property(u32 attr) } } -static int power_supply_hwmon_curr_to_property (u32 attr) +static int power_supply_hwmon_in1_to_property (u32 attr) +{ +switch (attr) { +case hwmon_in_max: +return POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT ; +case hwmon_in_input: +return POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW ; +default : +return -EINVAL ; + } +} + +static int power_supply_hwmon_in_to_property (u32 attr,int channel) +{ +switch (channel) { +case 0 : +return power_supply_hwmon_in0_to_property (attr); +case 1 : +return power_supply_hwmon_in1_to_property (attr); +default : +return -EINVAL ; + } +} + +static int power_supply_hwmon_curr0_to_property (u32 attr) {switch (attr) {case hwmon_curr_average:
@@ -48,6 +77,30 @@ static int power_supply_hwmon_curr_to_property(u32 attr) } } +static int power_supply_hwmon_curr1_to_property (u32 attr) +{ +switch (attr) { +case hwmon_curr_max: +return POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT ; +case hwmon_curr_input: +return POWER_SUPPLY_PROP_INPUT_CURRENT_NOW ; +default : +return -EINVAL ; + } +} + +static int power_supply_hwmon_curr_to_property (u32 attr,int channel) +{ +switch (channel) { +case 0 : +return power_supply_hwmon_curr0_to_property (attr); +case 1 : +return power_supply_hwmon_curr1_to_property (attr); +default : +return -EINVAL ; + } +} +static int power_supply_hwmon_temp_to_property (u32 attr,int channel) {if (channel) {
@@ -87,9 +140,9 @@ power_supply_hwmon_to_property(enum hwmon_sensor_types type, {switch (type) {case hwmon_in: -return power_supply_hwmon_in_to_property (attr); +return power_supply_hwmon_in_to_property (attr, channel);case hwmon_curr: -return power_supply_hwmon_curr_to_property (attr); +return power_supply_hwmon_curr_to_property (attr, channel);case hwmon_temp:return power_supply_hwmon_temp_to_property (attr, channel);default :
@@ -100,7 +153,9 @@ power_supply_hwmon_to_property(enum hwmon_sensor_types type,static bool power_supply_hwmon_is_a_label (enum hwmon_sensor_types type,u32 attr) { -return type == hwmon_temp && attr == hwmon_temp_label; +return (type == hwmon_temp && attr == hwmon_temp_label) || + (type == hwmon_in && attr == hwmon_in_label) || + (type == hwmon_curr && attr == hwmon_curr_label); }struct hwmon_type_attr_list {
@@ -114,7 +169,19 @@ static const u32 ps_temp_attrs[] = { hwmon_temp_min_alarm, hwmon_temp_max_alarm, }; +static const u32 ps_in_attrs[] = { + hwmon_in_input, hwmon_in_average, + hwmon_in_min, hwmon_in_max, +}; + +static const u32 ps_curr_attrs[] = { + hwmon_curr_input, hwmon_curr_average, + hwmon_curr_max, +}; +static const struct hwmon_type_attr_list ps_type_attrs[hwmon_max] = { + [hwmon_in] = { ps_in_attrs,ARRAY_SIZE (ps_in_attrs) }, + [hwmon_curr] = { ps_curr_attrs,ARRAY_SIZE (ps_curr_attrs) }, [hwmon_temp] = { ps_temp_attrs,ARRAY_SIZE (ps_temp_attrs) }, };
@@ -186,6 +253,11 @@ static int power_supply_hwmon_read_string(struct device *dev, const char **str) {switch (type) { +case hwmon_in: +case hwmon_curr: + *str = ps_input_label[channel]; +break ; +case hwmon_temp: *str = ps_temp_label[channel];break ;
@@ -303,15 +375,26 @@ static const struct hwmon_channel_info *power_supply_hwmon_info[] = { HWMON_T_MAX_ALARM),HWMON_CHANNEL_INFO (curr, +HWMON_C_LABEL |HWMON_C_AVERAGE |HWMON_C_MAX | +HWMON_C_INPUT , + +HWMON_C_LABEL | +HWMON_C_MAX |HWMON_C_INPUT ),HWMON_CHANNEL_INFO (in, +HWMON_I_LABEL |HWMON_I_AVERAGE |HWMON_I_MIN |HWMON_I_MAX | +HWMON_I_INPUT , + +HWMON_I_LABEL | +HWMON_I_MAX |HWMON_I_INPUT ), + NULL };
@@ -376,6 +459,10 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)case POWER_SUPPLY_PROP_VOLTAGE_MIN :case POWER_SUPPLY_PROP_VOLTAGE_MAX :case POWER_SUPPLY_PROP_VOLTAGE_NOW : +case POWER_SUPPLY_PROP_INPUT_CURRENT_NOW : +case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT : +case POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW : +case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT :set_bit (prop, psyhw->props);break ;default :
drivers/power/supply/power_supply_sysfs.c +2 -0
@@ -273,7 +273,9 @@ static struct device_attribute power_supply_attrs[] = {POWER_SUPPLY_ATTR (charge_control_limit_max),POWER_SUPPLY_ATTR (charge_control_start_threshold),POWER_SUPPLY_ATTR (charge_control_end_threshold), +POWER_SUPPLY_ATTR (input_current_now),POWER_SUPPLY_ATTR (input_current_limit), +POWER_SUPPLY_ATTR (input_voltage_now),POWER_SUPPLY_ATTR (input_voltage_limit),POWER_SUPPLY_ATTR (input_power_limit), POWER_SUPPLY_ATTR(energy_full_design),
include/linux/power_supply.h +2 -0
@@ -127,7 +127,9 @@ enum power_supply_property {POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX ,POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD ,/* in percents! */ POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD ,/* in percents! */ +POWER_SUPPLY_PROP_INPUT_CURRENT_NOW ,POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT , +POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW ,POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT ,POWER_SUPPLY_PROP_INPUT_POWER_LIMIT , POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
Signature · 1 line
2.20.1
PATCH v3 10/11 power: supply: core: add output voltage measurements
In reply to Michał MirosławAdd support for supply output voltage to be measured and configured. This might be different from the voltage on the storage element (battery).
--- drivers/power/supply/power_supply_hwmon.c | 25 +++++++++++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 3 +++ include/linux/power_supply.h | 3 +++ 3 files changed, 31 insertions(+)
drivers/power/supply/power_supply_hwmon.c +25 -0
@@ -16,6 +16,7 @@ struct power_supply_hwmon {static const char *const ps_input_label[] = {"battery" ,"external source" , +"load" , };static const char *const ps_temp_label[] = {
@@ -51,6 +52,20 @@ static int power_supply_hwmon_in1_to_property(u32 attr) } } +static int power_supply_hwmon_in2_to_property (u32 attr) +{ +switch (attr) { +case hwmon_in_min: +return POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN ; +case hwmon_in_max: +return POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MAX ; +case hwmon_in_input: +return POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW ; +default : +return -EINVAL ; + } +} +static int power_supply_hwmon_in_to_property (u32 attr,int channel) {switch (channel) {
@@ -58,6 +73,8 @@ static int power_supply_hwmon_in_to_property(u32 attr, int channel)return power_supply_hwmon_in0_to_property (attr);case 1 :return power_supply_hwmon_in1_to_property (attr); +case 2 : +return power_supply_hwmon_in2_to_property (attr);default :return -EINVAL ; }
@@ -393,6 +410,11 @@ static const struct hwmon_channel_info *power_supply_hwmon_info[] = {HWMON_I_LABEL |HWMON_I_MAX | +HWMON_I_INPUT , + +HWMON_I_LABEL | +HWMON_I_MIN | +HWMON_I_MAX | HWMON_I_INPUT), NULL
@@ -463,6 +485,9 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT :case POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW :case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT : +case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN : +case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MAX : +case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW :set_bit (prop, psyhw->props);break ;default :
drivers/power/supply/power_supply_sysfs.c +3 -0
@@ -278,6 +278,9 @@ static struct device_attribute power_supply_attrs[] = {POWER_SUPPLY_ATTR (input_voltage_now),POWER_SUPPLY_ATTR (input_voltage_limit),POWER_SUPPLY_ATTR (input_power_limit), +POWER_SUPPLY_ATTR (output_voltage_now), +POWER_SUPPLY_ATTR (output_voltage_min), +POWER_SUPPLY_ATTR (output_voltage_max),POWER_SUPPLY_ATTR (energy_full_design),POWER_SUPPLY_ATTR (energy_empty_design), POWER_SUPPLY_ATTR(energy_full),
include/linux/power_supply.h +3 -0
@@ -132,6 +132,9 @@ enum power_supply_property {POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW ,POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT ,POWER_SUPPLY_PROP_INPUT_POWER_LIMIT , +POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW , +POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN , +POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MAX ,POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN ,POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN , POWER_SUPPLY_PROP_ENERGY_FULL,
Signature · 1 line
2.20.1
PATCH v3 11/11 power: supply: core: document measurement points
In reply to Michał MirosławDocument used prefixes for input/output/storage voltages and currents.
--- Documentation/power/power_supply_class.rst | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/power/power_supply_class.rst +6 -0
@@ -28,6 +28,12 @@ indication (including whether to use it at all) are fully controllable by user and/or specific machine defaults, per design principles of LED framework). +There are three defined points of measurement for the benefit of mobile and +UPS-like power supplies: INPUT (external power source), OUTPUT (power output +from the module), and unmarked (power flowing to/from a storage element, +eg. battery). Battery is viewed as a power source, so current flowing to +the battery (charging it) is shown negative. + Attributes/properties ~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.20.1