* [PATCH 1/2] dt-bindings: power: Extend battery bindings with type
@ 2021-06-27 23:45 Linus Walleij
2021-06-27 23:45 ` [PATCH 2/2] power: supply: core: Parse battery type/technology Linus Walleij
2021-07-16 14:09 ` [PATCH 1/2] dt-bindings: power: Extend battery bindings with type Sebastian Reichel
0 siblings, 2 replies; 11+ messages in thread
From: Linus Walleij @ 2021-06-27 23:45 UTC (permalink / raw)
To: Sebastian Reichel, Marcus Cooper; +Cc: linux-pm, Linus Walleij
This adds a battery-type property and bindings for the different
"technologies" that are used in Linux. More types can be added.
This is needed to convert the custom ST-Ericsson AB8500 battery
properties over to the generic battery bindings.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
I need a bunch of new bindings for switch the STE AB8500 custom
bindings out, but I need to start somewhere, this is as good as
any place to start.
---
.../devicetree/bindings/power/supply/battery.yaml | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Documentation/devicetree/bindings/power/supply/battery.yaml b/Documentation/devicetree/bindings/power/supply/battery.yaml
index c3b4b7543591..3561ae2c1d58 100644
--- a/Documentation/devicetree/bindings/power/supply/battery.yaml
+++ b/Documentation/devicetree/bindings/power/supply/battery.yaml
@@ -31,6 +31,20 @@ properties:
compatible:
const: simple-battery
+ battery-type:
+ description: This describes the chemical technology of the battery.
+ oneOf:
+ - const: nickel-cadmium
+ - const: nickel-metal-hydride
+ - const: lithium-ion
+ description: This is a blanket type for all lithium-ion batteries,
+ including those below. If possible, a precise compatible string
+ from below should be used, but sometimes it is unknown which specific
+ lithium ion battery is employed and this wide compatible can be used.
+ - const: lithium-ion-polymer
+ - const: lithium-ion-iron-phosphate
+ - const: lithium-ion-manganese-oxide
+
over-voltage-threshold-microvolt:
description: battery over-voltage limit
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] power: supply: core: Parse battery type/technology
2021-06-27 23:45 [PATCH 1/2] dt-bindings: power: Extend battery bindings with type Linus Walleij
@ 2021-06-27 23:45 ` Linus Walleij
2021-06-28 2:13 ` kernel test robot
` (3 more replies)
2021-07-16 14:09 ` [PATCH 1/2] dt-bindings: power: Extend battery bindings with type Sebastian Reichel
1 sibling, 4 replies; 11+ messages in thread
From: Linus Walleij @ 2021-06-27 23:45 UTC (permalink / raw)
To: Sebastian Reichel, Marcus Cooper; +Cc: linux-pm, Linus Walleij
This extends the struct power_supply_battery_info with a
"technology" field makes the core DT parser optionally obtain
this from the device tree.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
This is needed to migrate the STE AB8500 custom battery bindings
and parser to the generic parser.
---
drivers/power/supply/power_supply_core.c | 20 ++++++++++++++++++++
include/linux/power_supply.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index d99e2f11c183..9771a3236932 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -571,6 +571,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
int err, len, index;
const __be32 *list;
+ info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
info->energy_full_design_uwh = -EINVAL;
info->charge_full_design_uah = -EINVAL;
info->voltage_min_design_uv = -EINVAL;
@@ -618,6 +619,25 @@ int power_supply_get_battery_info(struct power_supply *psy,
* Documentation/power/power_supply_class.rst.
*/
+ err = err = of_property_read_string(battery_np, "battery-type", &value);
+ if (!err) {
+ if (!strcmp("nickel-cadmium", value))
+ info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
+ else if (!strcmp("nickel-metal-hydride", value))
+ info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
+ else if (!strcmp("lithium-ion", value))
+ /* Imprecise lithium-ion type */
+ info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
+ else if (!strcmp("lithium-ion-polymer", value))
+ info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
+ else if (!strcmp("lithium-ion-iron-phosphate", value))
+ info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
+ else if (!strcmp("lithium-ion-manganese-oxide", value))
+ info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
+ else
+ dev_warn(&psy->dev, "%s unknown battery type\n", value);
+ }
+
of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
&info->energy_full_design_uwh);
of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index be203985ecdd..9ca1f120a211 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -352,6 +352,7 @@ struct power_supply_resistance_temp_table {
*/
struct power_supply_battery_info {
+ unsigned int technology; /* from the enum above */
int energy_full_design_uwh; /* microWatt-hours */
int charge_full_design_uah; /* microAmp-hours */
int voltage_min_design_uv; /* microVolts */
--
2.31.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] power: supply: core: Parse battery type/technology
2021-06-27 23:45 ` [PATCH 2/2] power: supply: core: Parse battery type/technology Linus Walleij
@ 2021-06-28 2:13 ` kernel test robot
2021-06-28 2:18 ` kernel test robot
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2021-06-28 2:13 UTC (permalink / raw)
To: Linus Walleij, Sebastian Reichel, Marcus Cooper
Cc: kbuild-all, clang-built-linux, linux-pm, Linus Walleij
[-- Attachment #1: Type: text/plain, Size: 10147 bytes --]
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.13 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
config: mips-randconfig-r011-20210628 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 4c92e31dd0f1bd152eda883af20ff7fbcaa14945)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# https://github.com/0day-ci/linux/commit/2bf6622db1c3b0d7e5cad624e16c0a448d37547b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
git checkout 2bf6622db1c3b0d7e5cad624e16c0a448d37547b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> drivers/power/supply/power_supply_core.c:622:12: warning: multiple unsequenced modifications to 'err' [-Wunsequenced]
err = err = of_property_read_string(battery_np, "battery-type", &value);
~ ^
1 warning generated.
vim +/err +622 drivers/power/supply/power_supply_core.c
564
565 int power_supply_get_battery_info(struct power_supply *psy,
566 struct power_supply_battery_info *info)
567 {
568 struct power_supply_resistance_temp_table *resist_table;
569 struct device_node *battery_np;
570 const char *value;
571 int err, len, index;
572 const __be32 *list;
573
574 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
575 info->energy_full_design_uwh = -EINVAL;
576 info->charge_full_design_uah = -EINVAL;
577 info->voltage_min_design_uv = -EINVAL;
578 info->voltage_max_design_uv = -EINVAL;
579 info->precharge_current_ua = -EINVAL;
580 info->charge_term_current_ua = -EINVAL;
581 info->constant_charge_current_max_ua = -EINVAL;
582 info->constant_charge_voltage_max_uv = -EINVAL;
583 info->temp_ambient_alert_min = INT_MIN;
584 info->temp_ambient_alert_max = INT_MAX;
585 info->temp_alert_min = INT_MIN;
586 info->temp_alert_max = INT_MAX;
587 info->temp_min = INT_MIN;
588 info->temp_max = INT_MAX;
589 info->factory_internal_resistance_uohm = -EINVAL;
590 info->resist_table = NULL;
591
592 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
593 info->ocv_table[index] = NULL;
594 info->ocv_temp[index] = -EINVAL;
595 info->ocv_table_size[index] = -EINVAL;
596 }
597
598 if (!psy->of_node) {
599 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
600 __func__);
601 return -ENXIO;
602 }
603
604 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
605 if (!battery_np)
606 return -ENODEV;
607
608 err = of_property_read_string(battery_np, "compatible", &value);
609 if (err)
610 goto out_put_node;
611
612 if (strcmp("simple-battery", value)) {
613 err = -ENODEV;
614 goto out_put_node;
615 }
616
617 /* The property and field names below must correspond to elements
618 * in enum power_supply_property. For reasoning, see
619 * Documentation/power/power_supply_class.rst.
620 */
621
> 622 err = err = of_property_read_string(battery_np, "battery-type", &value);
623 if (!err) {
624 if (!strcmp("nickel-cadmium", value))
625 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
626 else if (!strcmp("nickel-metal-hydride", value))
627 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
628 else if (!strcmp("lithium-ion", value))
629 /* Imprecise lithium-ion type */
630 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
631 else if (!strcmp("lithium-ion-polymer", value))
632 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
633 else if (!strcmp("lithium-ion-iron-phosphate", value))
634 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
635 else if (!strcmp("lithium-ion-manganese-oxide", value))
636 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
637 else
638 dev_warn(&psy->dev, "%s unknown battery type\n", value);
639 }
640
641 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
642 &info->energy_full_design_uwh);
643 of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
644 &info->charge_full_design_uah);
645 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
646 &info->voltage_min_design_uv);
647 of_property_read_u32(battery_np, "voltage-max-design-microvolt",
648 &info->voltage_max_design_uv);
649 of_property_read_u32(battery_np, "trickle-charge-current-microamp",
650 &info->tricklecharge_current_ua);
651 of_property_read_u32(battery_np, "precharge-current-microamp",
652 &info->precharge_current_ua);
653 of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
654 &info->precharge_voltage_max_uv);
655 of_property_read_u32(battery_np, "charge-term-current-microamp",
656 &info->charge_term_current_ua);
657 of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
658 &info->charge_restart_voltage_uv);
659 of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
660 &info->overvoltage_limit_uv);
661 of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
662 &info->constant_charge_current_max_ua);
663 of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
664 &info->constant_charge_voltage_max_uv);
665 of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
666 &info->factory_internal_resistance_uohm);
667
668 of_property_read_u32_index(battery_np, "ambient-celsius",
669 0, &info->temp_ambient_alert_min);
670 of_property_read_u32_index(battery_np, "ambient-celsius",
671 1, &info->temp_ambient_alert_max);
672 of_property_read_u32_index(battery_np, "alert-celsius",
673 0, &info->temp_alert_min);
674 of_property_read_u32_index(battery_np, "alert-celsius",
675 1, &info->temp_alert_max);
676 of_property_read_u32_index(battery_np, "operating-range-celsius",
677 0, &info->temp_min);
678 of_property_read_u32_index(battery_np, "operating-range-celsius",
679 1, &info->temp_max);
680
681 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
682 if (len < 0 && len != -EINVAL) {
683 err = len;
684 goto out_put_node;
685 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
686 dev_err(&psy->dev, "Too many temperature values\n");
687 err = -EINVAL;
688 goto out_put_node;
689 } else if (len > 0) {
690 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
691 info->ocv_temp, len);
692 }
693
694 for (index = 0; index < len; index++) {
695 struct power_supply_battery_ocv_table *table;
696 char *propname;
697 int i, tab_len, size;
698
699 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
700 list = of_get_property(battery_np, propname, &size);
701 if (!list || !size) {
702 dev_err(&psy->dev, "failed to get %s\n", propname);
703 kfree(propname);
704 power_supply_put_battery_info(psy, info);
705 err = -EINVAL;
706 goto out_put_node;
707 }
708
709 kfree(propname);
710 tab_len = size / (2 * sizeof(__be32));
711 info->ocv_table_size[index] = tab_len;
712
713 table = info->ocv_table[index] =
714 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
715 if (!info->ocv_table[index]) {
716 power_supply_put_battery_info(psy, info);
717 err = -ENOMEM;
718 goto out_put_node;
719 }
720
721 for (i = 0; i < tab_len; i++) {
722 table[i].ocv = be32_to_cpu(*list);
723 list++;
724 table[i].capacity = be32_to_cpu(*list);
725 list++;
726 }
727 }
728
729 list = of_get_property(battery_np, "resistance-temp-table", &len);
730 if (!list || !len)
731 goto out_put_node;
732
733 info->resist_table_size = len / (2 * sizeof(__be32));
734 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
735 info->resist_table_size,
736 sizeof(*resist_table),
737 GFP_KERNEL);
738 if (!info->resist_table) {
739 power_supply_put_battery_info(psy, info);
740 err = -ENOMEM;
741 goto out_put_node;
742 }
743
744 for (index = 0; index < info->resist_table_size; index++) {
745 resist_table[index].temp = be32_to_cpu(*list++);
746 resist_table[index].resistance = be32_to_cpu(*list++);
747 }
748
749 out_put_node:
750 of_node_put(battery_np);
751 return err;
752 }
753 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
754
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 23896 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] power: supply: core: Parse battery type/technology
@ 2021-06-28 2:13 ` kernel test robot
0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2021-06-28 2:13 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 10383 bytes --]
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.13 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
config: mips-randconfig-r011-20210628 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 4c92e31dd0f1bd152eda883af20ff7fbcaa14945)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# https://github.com/0day-ci/linux/commit/2bf6622db1c3b0d7e5cad624e16c0a448d37547b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
git checkout 2bf6622db1c3b0d7e5cad624e16c0a448d37547b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> drivers/power/supply/power_supply_core.c:622:12: warning: multiple unsequenced modifications to 'err' [-Wunsequenced]
err = err = of_property_read_string(battery_np, "battery-type", &value);
~ ^
1 warning generated.
vim +/err +622 drivers/power/supply/power_supply_core.c
564
565 int power_supply_get_battery_info(struct power_supply *psy,
566 struct power_supply_battery_info *info)
567 {
568 struct power_supply_resistance_temp_table *resist_table;
569 struct device_node *battery_np;
570 const char *value;
571 int err, len, index;
572 const __be32 *list;
573
574 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
575 info->energy_full_design_uwh = -EINVAL;
576 info->charge_full_design_uah = -EINVAL;
577 info->voltage_min_design_uv = -EINVAL;
578 info->voltage_max_design_uv = -EINVAL;
579 info->precharge_current_ua = -EINVAL;
580 info->charge_term_current_ua = -EINVAL;
581 info->constant_charge_current_max_ua = -EINVAL;
582 info->constant_charge_voltage_max_uv = -EINVAL;
583 info->temp_ambient_alert_min = INT_MIN;
584 info->temp_ambient_alert_max = INT_MAX;
585 info->temp_alert_min = INT_MIN;
586 info->temp_alert_max = INT_MAX;
587 info->temp_min = INT_MIN;
588 info->temp_max = INT_MAX;
589 info->factory_internal_resistance_uohm = -EINVAL;
590 info->resist_table = NULL;
591
592 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
593 info->ocv_table[index] = NULL;
594 info->ocv_temp[index] = -EINVAL;
595 info->ocv_table_size[index] = -EINVAL;
596 }
597
598 if (!psy->of_node) {
599 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
600 __func__);
601 return -ENXIO;
602 }
603
604 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
605 if (!battery_np)
606 return -ENODEV;
607
608 err = of_property_read_string(battery_np, "compatible", &value);
609 if (err)
610 goto out_put_node;
611
612 if (strcmp("simple-battery", value)) {
613 err = -ENODEV;
614 goto out_put_node;
615 }
616
617 /* The property and field names below must correspond to elements
618 * in enum power_supply_property. For reasoning, see
619 * Documentation/power/power_supply_class.rst.
620 */
621
> 622 err = err = of_property_read_string(battery_np, "battery-type", &value);
623 if (!err) {
624 if (!strcmp("nickel-cadmium", value))
625 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
626 else if (!strcmp("nickel-metal-hydride", value))
627 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
628 else if (!strcmp("lithium-ion", value))
629 /* Imprecise lithium-ion type */
630 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
631 else if (!strcmp("lithium-ion-polymer", value))
632 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
633 else if (!strcmp("lithium-ion-iron-phosphate", value))
634 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
635 else if (!strcmp("lithium-ion-manganese-oxide", value))
636 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
637 else
638 dev_warn(&psy->dev, "%s unknown battery type\n", value);
639 }
640
641 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
642 &info->energy_full_design_uwh);
643 of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
644 &info->charge_full_design_uah);
645 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
646 &info->voltage_min_design_uv);
647 of_property_read_u32(battery_np, "voltage-max-design-microvolt",
648 &info->voltage_max_design_uv);
649 of_property_read_u32(battery_np, "trickle-charge-current-microamp",
650 &info->tricklecharge_current_ua);
651 of_property_read_u32(battery_np, "precharge-current-microamp",
652 &info->precharge_current_ua);
653 of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
654 &info->precharge_voltage_max_uv);
655 of_property_read_u32(battery_np, "charge-term-current-microamp",
656 &info->charge_term_current_ua);
657 of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
658 &info->charge_restart_voltage_uv);
659 of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
660 &info->overvoltage_limit_uv);
661 of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
662 &info->constant_charge_current_max_ua);
663 of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
664 &info->constant_charge_voltage_max_uv);
665 of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
666 &info->factory_internal_resistance_uohm);
667
668 of_property_read_u32_index(battery_np, "ambient-celsius",
669 0, &info->temp_ambient_alert_min);
670 of_property_read_u32_index(battery_np, "ambient-celsius",
671 1, &info->temp_ambient_alert_max);
672 of_property_read_u32_index(battery_np, "alert-celsius",
673 0, &info->temp_alert_min);
674 of_property_read_u32_index(battery_np, "alert-celsius",
675 1, &info->temp_alert_max);
676 of_property_read_u32_index(battery_np, "operating-range-celsius",
677 0, &info->temp_min);
678 of_property_read_u32_index(battery_np, "operating-range-celsius",
679 1, &info->temp_max);
680
681 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
682 if (len < 0 && len != -EINVAL) {
683 err = len;
684 goto out_put_node;
685 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
686 dev_err(&psy->dev, "Too many temperature values\n");
687 err = -EINVAL;
688 goto out_put_node;
689 } else if (len > 0) {
690 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
691 info->ocv_temp, len);
692 }
693
694 for (index = 0; index < len; index++) {
695 struct power_supply_battery_ocv_table *table;
696 char *propname;
697 int i, tab_len, size;
698
699 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
700 list = of_get_property(battery_np, propname, &size);
701 if (!list || !size) {
702 dev_err(&psy->dev, "failed to get %s\n", propname);
703 kfree(propname);
704 power_supply_put_battery_info(psy, info);
705 err = -EINVAL;
706 goto out_put_node;
707 }
708
709 kfree(propname);
710 tab_len = size / (2 * sizeof(__be32));
711 info->ocv_table_size[index] = tab_len;
712
713 table = info->ocv_table[index] =
714 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
715 if (!info->ocv_table[index]) {
716 power_supply_put_battery_info(psy, info);
717 err = -ENOMEM;
718 goto out_put_node;
719 }
720
721 for (i = 0; i < tab_len; i++) {
722 table[i].ocv = be32_to_cpu(*list);
723 list++;
724 table[i].capacity = be32_to_cpu(*list);
725 list++;
726 }
727 }
728
729 list = of_get_property(battery_np, "resistance-temp-table", &len);
730 if (!list || !len)
731 goto out_put_node;
732
733 info->resist_table_size = len / (2 * sizeof(__be32));
734 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
735 info->resist_table_size,
736 sizeof(*resist_table),
737 GFP_KERNEL);
738 if (!info->resist_table) {
739 power_supply_put_battery_info(psy, info);
740 err = -ENOMEM;
741 goto out_put_node;
742 }
743
744 for (index = 0; index < info->resist_table_size; index++) {
745 resist_table[index].temp = be32_to_cpu(*list++);
746 resist_table[index].resistance = be32_to_cpu(*list++);
747 }
748
749 out_put_node:
750 of_node_put(battery_np);
751 return err;
752 }
753 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
754
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 23896 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] power: supply: core: Parse battery type/technology
2021-06-27 23:45 ` [PATCH 2/2] power: supply: core: Parse battery type/technology Linus Walleij
@ 2021-06-28 2:18 ` kernel test robot
2021-06-28 2:18 ` kernel test robot
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2021-06-28 2:18 UTC (permalink / raw)
To: Linus Walleij, Sebastian Reichel, Marcus Cooper
Cc: kbuild-all, linux-pm, Linus Walleij
[-- Attachment #1: Type: text/plain, Size: 10092 bytes --]
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.13 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
config: alpha-randconfig-r003-20210628 (attached as .config)
compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/2bf6622db1c3b0d7e5cad624e16c0a448d37547b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
git checkout 2bf6622db1c3b0d7e5cad624e16c0a448d37547b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
drivers/power/supply/power_supply_core.c: In function 'power_supply_get_battery_info':
>> drivers/power/supply/power_supply_core.c:622:6: warning: operation on 'err' may be undefined [-Wsequence-point]
622 | err = err = of_property_read_string(battery_np, "battery-type", &value);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/err +622 drivers/power/supply/power_supply_core.c
564
565 int power_supply_get_battery_info(struct power_supply *psy,
566 struct power_supply_battery_info *info)
567 {
568 struct power_supply_resistance_temp_table *resist_table;
569 struct device_node *battery_np;
570 const char *value;
571 int err, len, index;
572 const __be32 *list;
573
574 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
575 info->energy_full_design_uwh = -EINVAL;
576 info->charge_full_design_uah = -EINVAL;
577 info->voltage_min_design_uv = -EINVAL;
578 info->voltage_max_design_uv = -EINVAL;
579 info->precharge_current_ua = -EINVAL;
580 info->charge_term_current_ua = -EINVAL;
581 info->constant_charge_current_max_ua = -EINVAL;
582 info->constant_charge_voltage_max_uv = -EINVAL;
583 info->temp_ambient_alert_min = INT_MIN;
584 info->temp_ambient_alert_max = INT_MAX;
585 info->temp_alert_min = INT_MIN;
586 info->temp_alert_max = INT_MAX;
587 info->temp_min = INT_MIN;
588 info->temp_max = INT_MAX;
589 info->factory_internal_resistance_uohm = -EINVAL;
590 info->resist_table = NULL;
591
592 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
593 info->ocv_table[index] = NULL;
594 info->ocv_temp[index] = -EINVAL;
595 info->ocv_table_size[index] = -EINVAL;
596 }
597
598 if (!psy->of_node) {
599 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
600 __func__);
601 return -ENXIO;
602 }
603
604 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
605 if (!battery_np)
606 return -ENODEV;
607
608 err = of_property_read_string(battery_np, "compatible", &value);
609 if (err)
610 goto out_put_node;
611
612 if (strcmp("simple-battery", value)) {
613 err = -ENODEV;
614 goto out_put_node;
615 }
616
617 /* The property and field names below must correspond to elements
618 * in enum power_supply_property. For reasoning, see
619 * Documentation/power/power_supply_class.rst.
620 */
621
> 622 err = err = of_property_read_string(battery_np, "battery-type", &value);
623 if (!err) {
624 if (!strcmp("nickel-cadmium", value))
625 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
626 else if (!strcmp("nickel-metal-hydride", value))
627 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
628 else if (!strcmp("lithium-ion", value))
629 /* Imprecise lithium-ion type */
630 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
631 else if (!strcmp("lithium-ion-polymer", value))
632 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
633 else if (!strcmp("lithium-ion-iron-phosphate", value))
634 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
635 else if (!strcmp("lithium-ion-manganese-oxide", value))
636 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
637 else
638 dev_warn(&psy->dev, "%s unknown battery type\n", value);
639 }
640
641 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
642 &info->energy_full_design_uwh);
643 of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
644 &info->charge_full_design_uah);
645 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
646 &info->voltage_min_design_uv);
647 of_property_read_u32(battery_np, "voltage-max-design-microvolt",
648 &info->voltage_max_design_uv);
649 of_property_read_u32(battery_np, "trickle-charge-current-microamp",
650 &info->tricklecharge_current_ua);
651 of_property_read_u32(battery_np, "precharge-current-microamp",
652 &info->precharge_current_ua);
653 of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
654 &info->precharge_voltage_max_uv);
655 of_property_read_u32(battery_np, "charge-term-current-microamp",
656 &info->charge_term_current_ua);
657 of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
658 &info->charge_restart_voltage_uv);
659 of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
660 &info->overvoltage_limit_uv);
661 of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
662 &info->constant_charge_current_max_ua);
663 of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
664 &info->constant_charge_voltage_max_uv);
665 of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
666 &info->factory_internal_resistance_uohm);
667
668 of_property_read_u32_index(battery_np, "ambient-celsius",
669 0, &info->temp_ambient_alert_min);
670 of_property_read_u32_index(battery_np, "ambient-celsius",
671 1, &info->temp_ambient_alert_max);
672 of_property_read_u32_index(battery_np, "alert-celsius",
673 0, &info->temp_alert_min);
674 of_property_read_u32_index(battery_np, "alert-celsius",
675 1, &info->temp_alert_max);
676 of_property_read_u32_index(battery_np, "operating-range-celsius",
677 0, &info->temp_min);
678 of_property_read_u32_index(battery_np, "operating-range-celsius",
679 1, &info->temp_max);
680
681 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
682 if (len < 0 && len != -EINVAL) {
683 err = len;
684 goto out_put_node;
685 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
686 dev_err(&psy->dev, "Too many temperature values\n");
687 err = -EINVAL;
688 goto out_put_node;
689 } else if (len > 0) {
690 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
691 info->ocv_temp, len);
692 }
693
694 for (index = 0; index < len; index++) {
695 struct power_supply_battery_ocv_table *table;
696 char *propname;
697 int i, tab_len, size;
698
699 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
700 list = of_get_property(battery_np, propname, &size);
701 if (!list || !size) {
702 dev_err(&psy->dev, "failed to get %s\n", propname);
703 kfree(propname);
704 power_supply_put_battery_info(psy, info);
705 err = -EINVAL;
706 goto out_put_node;
707 }
708
709 kfree(propname);
710 tab_len = size / (2 * sizeof(__be32));
711 info->ocv_table_size[index] = tab_len;
712
713 table = info->ocv_table[index] =
714 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
715 if (!info->ocv_table[index]) {
716 power_supply_put_battery_info(psy, info);
717 err = -ENOMEM;
718 goto out_put_node;
719 }
720
721 for (i = 0; i < tab_len; i++) {
722 table[i].ocv = be32_to_cpu(*list);
723 list++;
724 table[i].capacity = be32_to_cpu(*list);
725 list++;
726 }
727 }
728
729 list = of_get_property(battery_np, "resistance-temp-table", &len);
730 if (!list || !len)
731 goto out_put_node;
732
733 info->resist_table_size = len / (2 * sizeof(__be32));
734 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
735 info->resist_table_size,
736 sizeof(*resist_table),
737 GFP_KERNEL);
738 if (!info->resist_table) {
739 power_supply_put_battery_info(psy, info);
740 err = -ENOMEM;
741 goto out_put_node;
742 }
743
744 for (index = 0; index < info->resist_table_size; index++) {
745 resist_table[index].temp = be32_to_cpu(*list++);
746 resist_table[index].resistance = be32_to_cpu(*list++);
747 }
748
749 out_put_node:
750 of_node_put(battery_np);
751 return err;
752 }
753 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
754
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 24175 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] power: supply: core: Parse battery type/technology
@ 2021-06-28 2:18 ` kernel test robot
0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2021-06-28 2:18 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 10326 bytes --]
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.13 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
config: alpha-randconfig-r003-20210628 (attached as .config)
compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/2bf6622db1c3b0d7e5cad624e16c0a448d37547b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
git checkout 2bf6622db1c3b0d7e5cad624e16c0a448d37547b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
drivers/power/supply/power_supply_core.c: In function 'power_supply_get_battery_info':
>> drivers/power/supply/power_supply_core.c:622:6: warning: operation on 'err' may be undefined [-Wsequence-point]
622 | err = err = of_property_read_string(battery_np, "battery-type", &value);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/err +622 drivers/power/supply/power_supply_core.c
564
565 int power_supply_get_battery_info(struct power_supply *psy,
566 struct power_supply_battery_info *info)
567 {
568 struct power_supply_resistance_temp_table *resist_table;
569 struct device_node *battery_np;
570 const char *value;
571 int err, len, index;
572 const __be32 *list;
573
574 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
575 info->energy_full_design_uwh = -EINVAL;
576 info->charge_full_design_uah = -EINVAL;
577 info->voltage_min_design_uv = -EINVAL;
578 info->voltage_max_design_uv = -EINVAL;
579 info->precharge_current_ua = -EINVAL;
580 info->charge_term_current_ua = -EINVAL;
581 info->constant_charge_current_max_ua = -EINVAL;
582 info->constant_charge_voltage_max_uv = -EINVAL;
583 info->temp_ambient_alert_min = INT_MIN;
584 info->temp_ambient_alert_max = INT_MAX;
585 info->temp_alert_min = INT_MIN;
586 info->temp_alert_max = INT_MAX;
587 info->temp_min = INT_MIN;
588 info->temp_max = INT_MAX;
589 info->factory_internal_resistance_uohm = -EINVAL;
590 info->resist_table = NULL;
591
592 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
593 info->ocv_table[index] = NULL;
594 info->ocv_temp[index] = -EINVAL;
595 info->ocv_table_size[index] = -EINVAL;
596 }
597
598 if (!psy->of_node) {
599 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
600 __func__);
601 return -ENXIO;
602 }
603
604 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
605 if (!battery_np)
606 return -ENODEV;
607
608 err = of_property_read_string(battery_np, "compatible", &value);
609 if (err)
610 goto out_put_node;
611
612 if (strcmp("simple-battery", value)) {
613 err = -ENODEV;
614 goto out_put_node;
615 }
616
617 /* The property and field names below must correspond to elements
618 * in enum power_supply_property. For reasoning, see
619 * Documentation/power/power_supply_class.rst.
620 */
621
> 622 err = err = of_property_read_string(battery_np, "battery-type", &value);
623 if (!err) {
624 if (!strcmp("nickel-cadmium", value))
625 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
626 else if (!strcmp("nickel-metal-hydride", value))
627 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
628 else if (!strcmp("lithium-ion", value))
629 /* Imprecise lithium-ion type */
630 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
631 else if (!strcmp("lithium-ion-polymer", value))
632 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
633 else if (!strcmp("lithium-ion-iron-phosphate", value))
634 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
635 else if (!strcmp("lithium-ion-manganese-oxide", value))
636 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
637 else
638 dev_warn(&psy->dev, "%s unknown battery type\n", value);
639 }
640
641 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
642 &info->energy_full_design_uwh);
643 of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
644 &info->charge_full_design_uah);
645 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
646 &info->voltage_min_design_uv);
647 of_property_read_u32(battery_np, "voltage-max-design-microvolt",
648 &info->voltage_max_design_uv);
649 of_property_read_u32(battery_np, "trickle-charge-current-microamp",
650 &info->tricklecharge_current_ua);
651 of_property_read_u32(battery_np, "precharge-current-microamp",
652 &info->precharge_current_ua);
653 of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
654 &info->precharge_voltage_max_uv);
655 of_property_read_u32(battery_np, "charge-term-current-microamp",
656 &info->charge_term_current_ua);
657 of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
658 &info->charge_restart_voltage_uv);
659 of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
660 &info->overvoltage_limit_uv);
661 of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
662 &info->constant_charge_current_max_ua);
663 of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
664 &info->constant_charge_voltage_max_uv);
665 of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
666 &info->factory_internal_resistance_uohm);
667
668 of_property_read_u32_index(battery_np, "ambient-celsius",
669 0, &info->temp_ambient_alert_min);
670 of_property_read_u32_index(battery_np, "ambient-celsius",
671 1, &info->temp_ambient_alert_max);
672 of_property_read_u32_index(battery_np, "alert-celsius",
673 0, &info->temp_alert_min);
674 of_property_read_u32_index(battery_np, "alert-celsius",
675 1, &info->temp_alert_max);
676 of_property_read_u32_index(battery_np, "operating-range-celsius",
677 0, &info->temp_min);
678 of_property_read_u32_index(battery_np, "operating-range-celsius",
679 1, &info->temp_max);
680
681 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
682 if (len < 0 && len != -EINVAL) {
683 err = len;
684 goto out_put_node;
685 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
686 dev_err(&psy->dev, "Too many temperature values\n");
687 err = -EINVAL;
688 goto out_put_node;
689 } else if (len > 0) {
690 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
691 info->ocv_temp, len);
692 }
693
694 for (index = 0; index < len; index++) {
695 struct power_supply_battery_ocv_table *table;
696 char *propname;
697 int i, tab_len, size;
698
699 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
700 list = of_get_property(battery_np, propname, &size);
701 if (!list || !size) {
702 dev_err(&psy->dev, "failed to get %s\n", propname);
703 kfree(propname);
704 power_supply_put_battery_info(psy, info);
705 err = -EINVAL;
706 goto out_put_node;
707 }
708
709 kfree(propname);
710 tab_len = size / (2 * sizeof(__be32));
711 info->ocv_table_size[index] = tab_len;
712
713 table = info->ocv_table[index] =
714 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
715 if (!info->ocv_table[index]) {
716 power_supply_put_battery_info(psy, info);
717 err = -ENOMEM;
718 goto out_put_node;
719 }
720
721 for (i = 0; i < tab_len; i++) {
722 table[i].ocv = be32_to_cpu(*list);
723 list++;
724 table[i].capacity = be32_to_cpu(*list);
725 list++;
726 }
727 }
728
729 list = of_get_property(battery_np, "resistance-temp-table", &len);
730 if (!list || !len)
731 goto out_put_node;
732
733 info->resist_table_size = len / (2 * sizeof(__be32));
734 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
735 info->resist_table_size,
736 sizeof(*resist_table),
737 GFP_KERNEL);
738 if (!info->resist_table) {
739 power_supply_put_battery_info(psy, info);
740 err = -ENOMEM;
741 goto out_put_node;
742 }
743
744 for (index = 0; index < info->resist_table_size; index++) {
745 resist_table[index].temp = be32_to_cpu(*list++);
746 resist_table[index].resistance = be32_to_cpu(*list++);
747 }
748
749 out_put_node:
750 of_node_put(battery_np);
751 return err;
752 }
753 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
754
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 24175 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] power: supply: core: Parse battery type/technology
2021-06-27 23:45 ` [PATCH 2/2] power: supply: core: Parse battery type/technology Linus Walleij
@ 2021-06-28 2:20 ` kernel test robot
2021-06-28 2:18 ` kernel test robot
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2021-06-28 2:20 UTC (permalink / raw)
To: Linus Walleij, Sebastian Reichel, Marcus Cooper
Cc: kbuild-all, clang-built-linux, linux-pm, Linus Walleij
[-- Attachment #1: Type: text/plain, Size: 10153 bytes --]
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.13 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
config: arm64-randconfig-r033-20210628 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 4c92e31dd0f1bd152eda883af20ff7fbcaa14945)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/2bf6622db1c3b0d7e5cad624e16c0a448d37547b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
git checkout 2bf6622db1c3b0d7e5cad624e16c0a448d37547b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> drivers/power/supply/power_supply_core.c:622:12: warning: multiple unsequenced modifications to 'err' [-Wunsequenced]
err = err = of_property_read_string(battery_np, "battery-type", &value);
~ ^
1 warning generated.
vim +/err +622 drivers/power/supply/power_supply_core.c
564
565 int power_supply_get_battery_info(struct power_supply *psy,
566 struct power_supply_battery_info *info)
567 {
568 struct power_supply_resistance_temp_table *resist_table;
569 struct device_node *battery_np;
570 const char *value;
571 int err, len, index;
572 const __be32 *list;
573
574 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
575 info->energy_full_design_uwh = -EINVAL;
576 info->charge_full_design_uah = -EINVAL;
577 info->voltage_min_design_uv = -EINVAL;
578 info->voltage_max_design_uv = -EINVAL;
579 info->precharge_current_ua = -EINVAL;
580 info->charge_term_current_ua = -EINVAL;
581 info->constant_charge_current_max_ua = -EINVAL;
582 info->constant_charge_voltage_max_uv = -EINVAL;
583 info->temp_ambient_alert_min = INT_MIN;
584 info->temp_ambient_alert_max = INT_MAX;
585 info->temp_alert_min = INT_MIN;
586 info->temp_alert_max = INT_MAX;
587 info->temp_min = INT_MIN;
588 info->temp_max = INT_MAX;
589 info->factory_internal_resistance_uohm = -EINVAL;
590 info->resist_table = NULL;
591
592 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
593 info->ocv_table[index] = NULL;
594 info->ocv_temp[index] = -EINVAL;
595 info->ocv_table_size[index] = -EINVAL;
596 }
597
598 if (!psy->of_node) {
599 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
600 __func__);
601 return -ENXIO;
602 }
603
604 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
605 if (!battery_np)
606 return -ENODEV;
607
608 err = of_property_read_string(battery_np, "compatible", &value);
609 if (err)
610 goto out_put_node;
611
612 if (strcmp("simple-battery", value)) {
613 err = -ENODEV;
614 goto out_put_node;
615 }
616
617 /* The property and field names below must correspond to elements
618 * in enum power_supply_property. For reasoning, see
619 * Documentation/power/power_supply_class.rst.
620 */
621
> 622 err = err = of_property_read_string(battery_np, "battery-type", &value);
623 if (!err) {
624 if (!strcmp("nickel-cadmium", value))
625 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
626 else if (!strcmp("nickel-metal-hydride", value))
627 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
628 else if (!strcmp("lithium-ion", value))
629 /* Imprecise lithium-ion type */
630 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
631 else if (!strcmp("lithium-ion-polymer", value))
632 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
633 else if (!strcmp("lithium-ion-iron-phosphate", value))
634 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
635 else if (!strcmp("lithium-ion-manganese-oxide", value))
636 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
637 else
638 dev_warn(&psy->dev, "%s unknown battery type\n", value);
639 }
640
641 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
642 &info->energy_full_design_uwh);
643 of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
644 &info->charge_full_design_uah);
645 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
646 &info->voltage_min_design_uv);
647 of_property_read_u32(battery_np, "voltage-max-design-microvolt",
648 &info->voltage_max_design_uv);
649 of_property_read_u32(battery_np, "trickle-charge-current-microamp",
650 &info->tricklecharge_current_ua);
651 of_property_read_u32(battery_np, "precharge-current-microamp",
652 &info->precharge_current_ua);
653 of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
654 &info->precharge_voltage_max_uv);
655 of_property_read_u32(battery_np, "charge-term-current-microamp",
656 &info->charge_term_current_ua);
657 of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
658 &info->charge_restart_voltage_uv);
659 of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
660 &info->overvoltage_limit_uv);
661 of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
662 &info->constant_charge_current_max_ua);
663 of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
664 &info->constant_charge_voltage_max_uv);
665 of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
666 &info->factory_internal_resistance_uohm);
667
668 of_property_read_u32_index(battery_np, "ambient-celsius",
669 0, &info->temp_ambient_alert_min);
670 of_property_read_u32_index(battery_np, "ambient-celsius",
671 1, &info->temp_ambient_alert_max);
672 of_property_read_u32_index(battery_np, "alert-celsius",
673 0, &info->temp_alert_min);
674 of_property_read_u32_index(battery_np, "alert-celsius",
675 1, &info->temp_alert_max);
676 of_property_read_u32_index(battery_np, "operating-range-celsius",
677 0, &info->temp_min);
678 of_property_read_u32_index(battery_np, "operating-range-celsius",
679 1, &info->temp_max);
680
681 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
682 if (len < 0 && len != -EINVAL) {
683 err = len;
684 goto out_put_node;
685 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
686 dev_err(&psy->dev, "Too many temperature values\n");
687 err = -EINVAL;
688 goto out_put_node;
689 } else if (len > 0) {
690 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
691 info->ocv_temp, len);
692 }
693
694 for (index = 0; index < len; index++) {
695 struct power_supply_battery_ocv_table *table;
696 char *propname;
697 int i, tab_len, size;
698
699 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
700 list = of_get_property(battery_np, propname, &size);
701 if (!list || !size) {
702 dev_err(&psy->dev, "failed to get %s\n", propname);
703 kfree(propname);
704 power_supply_put_battery_info(psy, info);
705 err = -EINVAL;
706 goto out_put_node;
707 }
708
709 kfree(propname);
710 tab_len = size / (2 * sizeof(__be32));
711 info->ocv_table_size[index] = tab_len;
712
713 table = info->ocv_table[index] =
714 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
715 if (!info->ocv_table[index]) {
716 power_supply_put_battery_info(psy, info);
717 err = -ENOMEM;
718 goto out_put_node;
719 }
720
721 for (i = 0; i < tab_len; i++) {
722 table[i].ocv = be32_to_cpu(*list);
723 list++;
724 table[i].capacity = be32_to_cpu(*list);
725 list++;
726 }
727 }
728
729 list = of_get_property(battery_np, "resistance-temp-table", &len);
730 if (!list || !len)
731 goto out_put_node;
732
733 info->resist_table_size = len / (2 * sizeof(__be32));
734 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
735 info->resist_table_size,
736 sizeof(*resist_table),
737 GFP_KERNEL);
738 if (!info->resist_table) {
739 power_supply_put_battery_info(psy, info);
740 err = -ENOMEM;
741 goto out_put_node;
742 }
743
744 for (index = 0; index < info->resist_table_size; index++) {
745 resist_table[index].temp = be32_to_cpu(*list++);
746 resist_table[index].resistance = be32_to_cpu(*list++);
747 }
748
749 out_put_node:
750 of_node_put(battery_np);
751 return err;
752 }
753 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
754
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 28083 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] power: supply: core: Parse battery type/technology
@ 2021-06-28 2:20 ` kernel test robot
0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2021-06-28 2:20 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 10389 bytes --]
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.13 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
config: arm64-randconfig-r033-20210628 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 4c92e31dd0f1bd152eda883af20ff7fbcaa14945)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/2bf6622db1c3b0d7e5cad624e16c0a448d37547b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
git checkout 2bf6622db1c3b0d7e5cad624e16c0a448d37547b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> drivers/power/supply/power_supply_core.c:622:12: warning: multiple unsequenced modifications to 'err' [-Wunsequenced]
err = err = of_property_read_string(battery_np, "battery-type", &value);
~ ^
1 warning generated.
vim +/err +622 drivers/power/supply/power_supply_core.c
564
565 int power_supply_get_battery_info(struct power_supply *psy,
566 struct power_supply_battery_info *info)
567 {
568 struct power_supply_resistance_temp_table *resist_table;
569 struct device_node *battery_np;
570 const char *value;
571 int err, len, index;
572 const __be32 *list;
573
574 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
575 info->energy_full_design_uwh = -EINVAL;
576 info->charge_full_design_uah = -EINVAL;
577 info->voltage_min_design_uv = -EINVAL;
578 info->voltage_max_design_uv = -EINVAL;
579 info->precharge_current_ua = -EINVAL;
580 info->charge_term_current_ua = -EINVAL;
581 info->constant_charge_current_max_ua = -EINVAL;
582 info->constant_charge_voltage_max_uv = -EINVAL;
583 info->temp_ambient_alert_min = INT_MIN;
584 info->temp_ambient_alert_max = INT_MAX;
585 info->temp_alert_min = INT_MIN;
586 info->temp_alert_max = INT_MAX;
587 info->temp_min = INT_MIN;
588 info->temp_max = INT_MAX;
589 info->factory_internal_resistance_uohm = -EINVAL;
590 info->resist_table = NULL;
591
592 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
593 info->ocv_table[index] = NULL;
594 info->ocv_temp[index] = -EINVAL;
595 info->ocv_table_size[index] = -EINVAL;
596 }
597
598 if (!psy->of_node) {
599 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
600 __func__);
601 return -ENXIO;
602 }
603
604 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
605 if (!battery_np)
606 return -ENODEV;
607
608 err = of_property_read_string(battery_np, "compatible", &value);
609 if (err)
610 goto out_put_node;
611
612 if (strcmp("simple-battery", value)) {
613 err = -ENODEV;
614 goto out_put_node;
615 }
616
617 /* The property and field names below must correspond to elements
618 * in enum power_supply_property. For reasoning, see
619 * Documentation/power/power_supply_class.rst.
620 */
621
> 622 err = err = of_property_read_string(battery_np, "battery-type", &value);
623 if (!err) {
624 if (!strcmp("nickel-cadmium", value))
625 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
626 else if (!strcmp("nickel-metal-hydride", value))
627 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
628 else if (!strcmp("lithium-ion", value))
629 /* Imprecise lithium-ion type */
630 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
631 else if (!strcmp("lithium-ion-polymer", value))
632 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
633 else if (!strcmp("lithium-ion-iron-phosphate", value))
634 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
635 else if (!strcmp("lithium-ion-manganese-oxide", value))
636 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
637 else
638 dev_warn(&psy->dev, "%s unknown battery type\n", value);
639 }
640
641 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
642 &info->energy_full_design_uwh);
643 of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
644 &info->charge_full_design_uah);
645 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
646 &info->voltage_min_design_uv);
647 of_property_read_u32(battery_np, "voltage-max-design-microvolt",
648 &info->voltage_max_design_uv);
649 of_property_read_u32(battery_np, "trickle-charge-current-microamp",
650 &info->tricklecharge_current_ua);
651 of_property_read_u32(battery_np, "precharge-current-microamp",
652 &info->precharge_current_ua);
653 of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
654 &info->precharge_voltage_max_uv);
655 of_property_read_u32(battery_np, "charge-term-current-microamp",
656 &info->charge_term_current_ua);
657 of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
658 &info->charge_restart_voltage_uv);
659 of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
660 &info->overvoltage_limit_uv);
661 of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
662 &info->constant_charge_current_max_ua);
663 of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
664 &info->constant_charge_voltage_max_uv);
665 of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
666 &info->factory_internal_resistance_uohm);
667
668 of_property_read_u32_index(battery_np, "ambient-celsius",
669 0, &info->temp_ambient_alert_min);
670 of_property_read_u32_index(battery_np, "ambient-celsius",
671 1, &info->temp_ambient_alert_max);
672 of_property_read_u32_index(battery_np, "alert-celsius",
673 0, &info->temp_alert_min);
674 of_property_read_u32_index(battery_np, "alert-celsius",
675 1, &info->temp_alert_max);
676 of_property_read_u32_index(battery_np, "operating-range-celsius",
677 0, &info->temp_min);
678 of_property_read_u32_index(battery_np, "operating-range-celsius",
679 1, &info->temp_max);
680
681 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
682 if (len < 0 && len != -EINVAL) {
683 err = len;
684 goto out_put_node;
685 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
686 dev_err(&psy->dev, "Too many temperature values\n");
687 err = -EINVAL;
688 goto out_put_node;
689 } else if (len > 0) {
690 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
691 info->ocv_temp, len);
692 }
693
694 for (index = 0; index < len; index++) {
695 struct power_supply_battery_ocv_table *table;
696 char *propname;
697 int i, tab_len, size;
698
699 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
700 list = of_get_property(battery_np, propname, &size);
701 if (!list || !size) {
702 dev_err(&psy->dev, "failed to get %s\n", propname);
703 kfree(propname);
704 power_supply_put_battery_info(psy, info);
705 err = -EINVAL;
706 goto out_put_node;
707 }
708
709 kfree(propname);
710 tab_len = size / (2 * sizeof(__be32));
711 info->ocv_table_size[index] = tab_len;
712
713 table = info->ocv_table[index] =
714 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
715 if (!info->ocv_table[index]) {
716 power_supply_put_battery_info(psy, info);
717 err = -ENOMEM;
718 goto out_put_node;
719 }
720
721 for (i = 0; i < tab_len; i++) {
722 table[i].ocv = be32_to_cpu(*list);
723 list++;
724 table[i].capacity = be32_to_cpu(*list);
725 list++;
726 }
727 }
728
729 list = of_get_property(battery_np, "resistance-temp-table", &len);
730 if (!list || !len)
731 goto out_put_node;
732
733 info->resist_table_size = len / (2 * sizeof(__be32));
734 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
735 info->resist_table_size,
736 sizeof(*resist_table),
737 GFP_KERNEL);
738 if (!info->resist_table) {
739 power_supply_put_battery_info(psy, info);
740 err = -ENOMEM;
741 goto out_put_node;
742 }
743
744 for (index = 0; index < info->resist_table_size; index++) {
745 resist_table[index].temp = be32_to_cpu(*list++);
746 resist_table[index].resistance = be32_to_cpu(*list++);
747 }
748
749 out_put_node:
750 of_node_put(battery_np);
751 return err;
752 }
753 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
754
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 28083 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] power: supply: core: Parse battery type/technology
2021-06-27 23:45 ` [PATCH 2/2] power: supply: core: Parse battery type/technology Linus Walleij
@ 2021-06-28 3:43 ` kernel test robot
2021-06-28 2:18 ` kernel test robot
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2021-06-28 3:43 UTC (permalink / raw)
To: Linus Walleij, Sebastian Reichel, Marcus Cooper
Cc: kbuild-all, linux-pm, Linus Walleij
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.13 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
compiler: nios2-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
cppcheck warnings: (new ones prefixed by >>)
>> drivers/power/supply/power_supply_core.c:622:6: warning: Redundant assignment of 'err' to itself. [selfAssignment]
err = err = of_property_read_string(battery_np, "battery-type", &value);
^
vim +/err +622 drivers/power/supply/power_supply_core.c
564
565 int power_supply_get_battery_info(struct power_supply *psy,
566 struct power_supply_battery_info *info)
567 {
568 struct power_supply_resistance_temp_table *resist_table;
569 struct device_node *battery_np;
570 const char *value;
571 int err, len, index;
572 const __be32 *list;
573
574 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
575 info->energy_full_design_uwh = -EINVAL;
576 info->charge_full_design_uah = -EINVAL;
577 info->voltage_min_design_uv = -EINVAL;
578 info->voltage_max_design_uv = -EINVAL;
579 info->precharge_current_ua = -EINVAL;
580 info->charge_term_current_ua = -EINVAL;
581 info->constant_charge_current_max_ua = -EINVAL;
582 info->constant_charge_voltage_max_uv = -EINVAL;
583 info->temp_ambient_alert_min = INT_MIN;
584 info->temp_ambient_alert_max = INT_MAX;
585 info->temp_alert_min = INT_MIN;
586 info->temp_alert_max = INT_MAX;
587 info->temp_min = INT_MIN;
588 info->temp_max = INT_MAX;
589 info->factory_internal_resistance_uohm = -EINVAL;
590 info->resist_table = NULL;
591
592 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
593 info->ocv_table[index] = NULL;
594 info->ocv_temp[index] = -EINVAL;
595 info->ocv_table_size[index] = -EINVAL;
596 }
597
598 if (!psy->of_node) {
599 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
600 __func__);
601 return -ENXIO;
602 }
603
604 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
605 if (!battery_np)
606 return -ENODEV;
607
608 err = of_property_read_string(battery_np, "compatible", &value);
609 if (err)
610 goto out_put_node;
611
612 if (strcmp("simple-battery", value)) {
613 err = -ENODEV;
614 goto out_put_node;
615 }
616
617 /* The property and field names below must correspond to elements
618 * in enum power_supply_property. For reasoning, see
619 * Documentation/power/power_supply_class.rst.
620 */
621
> 622 err = err = of_property_read_string(battery_np, "battery-type", &value);
623 if (!err) {
624 if (!strcmp("nickel-cadmium", value))
625 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
626 else if (!strcmp("nickel-metal-hydride", value))
627 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
628 else if (!strcmp("lithium-ion", value))
629 /* Imprecise lithium-ion type */
630 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
631 else if (!strcmp("lithium-ion-polymer", value))
632 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
633 else if (!strcmp("lithium-ion-iron-phosphate", value))
634 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
635 else if (!strcmp("lithium-ion-manganese-oxide", value))
636 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
637 else
638 dev_warn(&psy->dev, "%s unknown battery type\n", value);
639 }
640
641 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
642 &info->energy_full_design_uwh);
643 of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
644 &info->charge_full_design_uah);
645 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
646 &info->voltage_min_design_uv);
647 of_property_read_u32(battery_np, "voltage-max-design-microvolt",
648 &info->voltage_max_design_uv);
649 of_property_read_u32(battery_np, "trickle-charge-current-microamp",
650 &info->tricklecharge_current_ua);
651 of_property_read_u32(battery_np, "precharge-current-microamp",
652 &info->precharge_current_ua);
653 of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
654 &info->precharge_voltage_max_uv);
655 of_property_read_u32(battery_np, "charge-term-current-microamp",
656 &info->charge_term_current_ua);
657 of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
658 &info->charge_restart_voltage_uv);
659 of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
660 &info->overvoltage_limit_uv);
661 of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
662 &info->constant_charge_current_max_ua);
663 of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
664 &info->constant_charge_voltage_max_uv);
665 of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
666 &info->factory_internal_resistance_uohm);
667
668 of_property_read_u32_index(battery_np, "ambient-celsius",
669 0, &info->temp_ambient_alert_min);
670 of_property_read_u32_index(battery_np, "ambient-celsius",
671 1, &info->temp_ambient_alert_max);
672 of_property_read_u32_index(battery_np, "alert-celsius",
673 0, &info->temp_alert_min);
674 of_property_read_u32_index(battery_np, "alert-celsius",
675 1, &info->temp_alert_max);
676 of_property_read_u32_index(battery_np, "operating-range-celsius",
677 0, &info->temp_min);
678 of_property_read_u32_index(battery_np, "operating-range-celsius",
679 1, &info->temp_max);
680
681 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
682 if (len < 0 && len != -EINVAL) {
683 err = len;
684 goto out_put_node;
685 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
686 dev_err(&psy->dev, "Too many temperature values\n");
687 err = -EINVAL;
688 goto out_put_node;
689 } else if (len > 0) {
690 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
691 info->ocv_temp, len);
692 }
693
694 for (index = 0; index < len; index++) {
695 struct power_supply_battery_ocv_table *table;
696 char *propname;
697 int i, tab_len, size;
698
699 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
700 list = of_get_property(battery_np, propname, &size);
701 if (!list || !size) {
702 dev_err(&psy->dev, "failed to get %s\n", propname);
703 kfree(propname);
704 power_supply_put_battery_info(psy, info);
705 err = -EINVAL;
706 goto out_put_node;
707 }
708
709 kfree(propname);
710 tab_len = size / (2 * sizeof(__be32));
711 info->ocv_table_size[index] = tab_len;
712
713 table = info->ocv_table[index] =
714 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
715 if (!info->ocv_table[index]) {
716 power_supply_put_battery_info(psy, info);
717 err = -ENOMEM;
718 goto out_put_node;
719 }
720
721 for (i = 0; i < tab_len; i++) {
722 table[i].ocv = be32_to_cpu(*list);
723 list++;
724 table[i].capacity = be32_to_cpu(*list);
725 list++;
726 }
727 }
728
729 list = of_get_property(battery_np, "resistance-temp-table", &len);
730 if (!list || !len)
731 goto out_put_node;
732
733 info->resist_table_size = len / (2 * sizeof(__be32));
734 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
735 info->resist_table_size,
736 sizeof(*resist_table),
737 GFP_KERNEL);
738 if (!info->resist_table) {
739 power_supply_put_battery_info(psy, info);
740 err = -ENOMEM;
741 goto out_put_node;
742 }
743
744 for (index = 0; index < info->resist_table_size; index++) {
745 resist_table[index].temp = be32_to_cpu(*list++);
746 resist_table[index].resistance = be32_to_cpu(*list++);
747 }
748
749 out_put_node:
750 of_node_put(battery_np);
751 return err;
752 }
753 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
754
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] power: supply: core: Parse battery type/technology
@ 2021-06-28 3:43 ` kernel test robot
0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2021-06-28 3:43 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 9429 bytes --]
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.13 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Linus-Walleij/dt-bindings-power-Extend-battery-bindings-with-type/20210628-074842
base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
compiler: nios2-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
cppcheck warnings: (new ones prefixed by >>)
>> drivers/power/supply/power_supply_core.c:622:6: warning: Redundant assignment of 'err' to itself. [selfAssignment]
err = err = of_property_read_string(battery_np, "battery-type", &value);
^
vim +/err +622 drivers/power/supply/power_supply_core.c
564
565 int power_supply_get_battery_info(struct power_supply *psy,
566 struct power_supply_battery_info *info)
567 {
568 struct power_supply_resistance_temp_table *resist_table;
569 struct device_node *battery_np;
570 const char *value;
571 int err, len, index;
572 const __be32 *list;
573
574 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
575 info->energy_full_design_uwh = -EINVAL;
576 info->charge_full_design_uah = -EINVAL;
577 info->voltage_min_design_uv = -EINVAL;
578 info->voltage_max_design_uv = -EINVAL;
579 info->precharge_current_ua = -EINVAL;
580 info->charge_term_current_ua = -EINVAL;
581 info->constant_charge_current_max_ua = -EINVAL;
582 info->constant_charge_voltage_max_uv = -EINVAL;
583 info->temp_ambient_alert_min = INT_MIN;
584 info->temp_ambient_alert_max = INT_MAX;
585 info->temp_alert_min = INT_MIN;
586 info->temp_alert_max = INT_MAX;
587 info->temp_min = INT_MIN;
588 info->temp_max = INT_MAX;
589 info->factory_internal_resistance_uohm = -EINVAL;
590 info->resist_table = NULL;
591
592 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
593 info->ocv_table[index] = NULL;
594 info->ocv_temp[index] = -EINVAL;
595 info->ocv_table_size[index] = -EINVAL;
596 }
597
598 if (!psy->of_node) {
599 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
600 __func__);
601 return -ENXIO;
602 }
603
604 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
605 if (!battery_np)
606 return -ENODEV;
607
608 err = of_property_read_string(battery_np, "compatible", &value);
609 if (err)
610 goto out_put_node;
611
612 if (strcmp("simple-battery", value)) {
613 err = -ENODEV;
614 goto out_put_node;
615 }
616
617 /* The property and field names below must correspond to elements
618 * in enum power_supply_property. For reasoning, see
619 * Documentation/power/power_supply_class.rst.
620 */
621
> 622 err = err = of_property_read_string(battery_np, "battery-type", &value);
623 if (!err) {
624 if (!strcmp("nickel-cadmium", value))
625 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
626 else if (!strcmp("nickel-metal-hydride", value))
627 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
628 else if (!strcmp("lithium-ion", value))
629 /* Imprecise lithium-ion type */
630 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
631 else if (!strcmp("lithium-ion-polymer", value))
632 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
633 else if (!strcmp("lithium-ion-iron-phosphate", value))
634 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
635 else if (!strcmp("lithium-ion-manganese-oxide", value))
636 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
637 else
638 dev_warn(&psy->dev, "%s unknown battery type\n", value);
639 }
640
641 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
642 &info->energy_full_design_uwh);
643 of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
644 &info->charge_full_design_uah);
645 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
646 &info->voltage_min_design_uv);
647 of_property_read_u32(battery_np, "voltage-max-design-microvolt",
648 &info->voltage_max_design_uv);
649 of_property_read_u32(battery_np, "trickle-charge-current-microamp",
650 &info->tricklecharge_current_ua);
651 of_property_read_u32(battery_np, "precharge-current-microamp",
652 &info->precharge_current_ua);
653 of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
654 &info->precharge_voltage_max_uv);
655 of_property_read_u32(battery_np, "charge-term-current-microamp",
656 &info->charge_term_current_ua);
657 of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
658 &info->charge_restart_voltage_uv);
659 of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
660 &info->overvoltage_limit_uv);
661 of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
662 &info->constant_charge_current_max_ua);
663 of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
664 &info->constant_charge_voltage_max_uv);
665 of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
666 &info->factory_internal_resistance_uohm);
667
668 of_property_read_u32_index(battery_np, "ambient-celsius",
669 0, &info->temp_ambient_alert_min);
670 of_property_read_u32_index(battery_np, "ambient-celsius",
671 1, &info->temp_ambient_alert_max);
672 of_property_read_u32_index(battery_np, "alert-celsius",
673 0, &info->temp_alert_min);
674 of_property_read_u32_index(battery_np, "alert-celsius",
675 1, &info->temp_alert_max);
676 of_property_read_u32_index(battery_np, "operating-range-celsius",
677 0, &info->temp_min);
678 of_property_read_u32_index(battery_np, "operating-range-celsius",
679 1, &info->temp_max);
680
681 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
682 if (len < 0 && len != -EINVAL) {
683 err = len;
684 goto out_put_node;
685 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
686 dev_err(&psy->dev, "Too many temperature values\n");
687 err = -EINVAL;
688 goto out_put_node;
689 } else if (len > 0) {
690 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
691 info->ocv_temp, len);
692 }
693
694 for (index = 0; index < len; index++) {
695 struct power_supply_battery_ocv_table *table;
696 char *propname;
697 int i, tab_len, size;
698
699 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
700 list = of_get_property(battery_np, propname, &size);
701 if (!list || !size) {
702 dev_err(&psy->dev, "failed to get %s\n", propname);
703 kfree(propname);
704 power_supply_put_battery_info(psy, info);
705 err = -EINVAL;
706 goto out_put_node;
707 }
708
709 kfree(propname);
710 tab_len = size / (2 * sizeof(__be32));
711 info->ocv_table_size[index] = tab_len;
712
713 table = info->ocv_table[index] =
714 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
715 if (!info->ocv_table[index]) {
716 power_supply_put_battery_info(psy, info);
717 err = -ENOMEM;
718 goto out_put_node;
719 }
720
721 for (i = 0; i < tab_len; i++) {
722 table[i].ocv = be32_to_cpu(*list);
723 list++;
724 table[i].capacity = be32_to_cpu(*list);
725 list++;
726 }
727 }
728
729 list = of_get_property(battery_np, "resistance-temp-table", &len);
730 if (!list || !len)
731 goto out_put_node;
732
733 info->resist_table_size = len / (2 * sizeof(__be32));
734 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
735 info->resist_table_size,
736 sizeof(*resist_table),
737 GFP_KERNEL);
738 if (!info->resist_table) {
739 power_supply_put_battery_info(psy, info);
740 err = -ENOMEM;
741 goto out_put_node;
742 }
743
744 for (index = 0; index < info->resist_table_size; index++) {
745 resist_table[index].temp = be32_to_cpu(*list++);
746 resist_table[index].resistance = be32_to_cpu(*list++);
747 }
748
749 out_put_node:
750 of_node_put(battery_np);
751 return err;
752 }
753 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
754
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] dt-bindings: power: Extend battery bindings with type
2021-06-27 23:45 [PATCH 1/2] dt-bindings: power: Extend battery bindings with type Linus Walleij
2021-06-27 23:45 ` [PATCH 2/2] power: supply: core: Parse battery type/technology Linus Walleij
@ 2021-07-16 14:09 ` Sebastian Reichel
1 sibling, 0 replies; 11+ messages in thread
From: Sebastian Reichel @ 2021-07-16 14:09 UTC (permalink / raw)
To: Linus Walleij; +Cc: Marcus Cooper, linux-pm, Rob Herring
[-- Attachment #1: Type: text/plain, Size: 2172 bytes --]
Hi,
On Mon, Jun 28, 2021 at 01:45:14AM +0200, Linus Walleij wrote:
> This adds a battery-type property and bindings for the different
> "technologies" that are used in Linux. More types can be added.
Makes sense to have this.
> This is needed to convert the custom ST-Ericsson AB8500 battery
> properties over to the generic battery bindings.
Great :)
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> I need a bunch of new bindings for switch the STE AB8500 custom
> bindings out, but I need to start somewhere, this is as good as
> any place to start.
> ---
> .../devicetree/bindings/power/supply/battery.yaml | 14 ++++++++++++++
This should be CC'd to Rob Herring.
> 1 file changed, 14 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/power/supply/battery.yaml b/Documentation/devicetree/bindings/power/supply/battery.yaml
> index c3b4b7543591..3561ae2c1d58 100644
> --- a/Documentation/devicetree/bindings/power/supply/battery.yaml
> +++ b/Documentation/devicetree/bindings/power/supply/battery.yaml
> @@ -31,6 +31,20 @@ properties:
> compatible:
> const: simple-battery
>
> + battery-type:
The smart battery standard names the property storing this information
"DeviceChemistry", which (as a non-native speaker) seems like a
better fitting name. Thoughts?
> + description: This describes the chemical technology of the battery.
> + oneOf:
> + - const: nickel-cadmium
> + - const: nickel-metal-hydride
> + - const: lithium-ion
> + description: This is a blanket type for all lithium-ion batteries,
> + including those below. If possible, a precise compatible string
> + from below should be used, but sometimes it is unknown which specific
> + lithium ion battery is employed and this wide compatible can be used.
> + - const: lithium-ion-polymer
> + - const: lithium-ion-iron-phosphate
> + - const: lithium-ion-manganese-oxide
The values look good to me.
-- Sebastian
> over-voltage-threshold-microvolt:
> description: battery over-voltage limit
>
> --
> 2.31.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-07-16 14:10 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 23:45 [PATCH 1/2] dt-bindings: power: Extend battery bindings with type Linus Walleij
2021-06-27 23:45 ` [PATCH 2/2] power: supply: core: Parse battery type/technology Linus Walleij
2021-06-28 2:13 ` kernel test robot
2021-06-28 2:13 ` kernel test robot
2021-06-28 2:18 ` kernel test robot
2021-06-28 2:18 ` kernel test robot
2021-06-28 2:20 ` kernel test robot
2021-06-28 2:20 ` kernel test robot
2021-06-28 3:43 ` kernel test robot
2021-06-28 3:43 ` kernel test robot
2021-07-16 14:09 ` [PATCH 1/2] dt-bindings: power: Extend battery bindings with type Sebastian Reichel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.