hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/power/supply/power_supply_core.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Universal power supply monitor class
34 *
....@@ -6,8 +7,6 @@
67 * Copyright © 2003 Ian Molton <spyro@f2s.com>
78 *
89 * Modified: 2004, Oct Szabolcs Gyurko
9
- *
10
- * You may use this code as per GPL version 2
1110 */
1211
1312 #include <linux/module.h>
....@@ -32,6 +31,13 @@
3231 EXPORT_SYMBOL_GPL(power_supply_notifier);
3332
3433 static struct device_type power_supply_dev_type;
34
+
35
+struct match_device_node_array_param {
36
+ struct device_node *parent_of_node;
37
+ struct power_supply **psy;
38
+ ssize_t psy_size;
39
+ ssize_t psy_count;
40
+};
3541
3642 #define POWER_SUPPLY_DEFERRED_REGISTER_TIME msecs_to_jiffies(10)
3743
....@@ -126,6 +132,7 @@
126132 }
127133 EXPORT_SYMBOL_GPL(power_supply_changed);
128134
135
+static int psy_register_cooler(struct power_supply *psy);
129136 /*
130137 * Notify that power supply was registered after parent finished the probing.
131138 *
....@@ -133,6 +140,8 @@
133140 * calling power_supply_changed() directly from power_supply_register()
134141 * would lead to execution of get_property() function provided by the driver
135142 * too early - before the probe ends.
143
+ * Also, registering cooling device from the probe will execute the
144
+ * get_property() function. So register the cooling device after the probe.
136145 *
137146 * Avoid that by waiting on parent's mutex.
138147 */
....@@ -150,14 +159,13 @@
150159 }
151160
152161 power_supply_changed(psy);
162
+ psy_register_cooler(psy);
153163
154164 if (psy->dev.parent)
155165 mutex_unlock(&psy->dev.parent->mutex);
156166 }
157167
158168 #ifdef CONFIG_OF
159
-#include <linux/of.h>
160
-
161169 static int __power_supply_populate_supplied_from(struct device *dev,
162170 void *data)
163171 {
....@@ -350,6 +358,10 @@
350358 struct power_supply *psy = dev_get_drvdata(dev);
351359 unsigned int *count = data;
352360
361
+ if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_SCOPE, &ret))
362
+ if (ret.intval == POWER_SUPPLY_SCOPE_DEVICE)
363
+ return 0;
364
+
353365 (*count)++;
354366 if (psy->desc->type != POWER_SUPPLY_TYPE_BATTERY)
355367 if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE,
....@@ -368,8 +380,8 @@
368380 __power_supply_is_system_supplied);
369381
370382 /*
371
- * If no power class device was found at all, most probably we are
372
- * running on a desktop system, so assume we are on mains power.
383
+ * If no system scope power class device was found at all, most probably we
384
+ * are running on a desktop system, so assume we are on mains power.
373385 */
374386 if (count == 0)
375387 return 1;
....@@ -378,46 +390,49 @@
378390 }
379391 EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
380392
381
-static int __power_supply_get_supplier_max_current(struct device *dev,
382
- void *data)
393
+struct psy_get_supplier_prop_data {
394
+ struct power_supply *psy;
395
+ enum power_supply_property psp;
396
+ union power_supply_propval *val;
397
+};
398
+
399
+static int __power_supply_get_supplier_property(struct device *dev, void *_data)
383400 {
384
- union power_supply_propval ret = {0,};
385401 struct power_supply *epsy = dev_get_drvdata(dev);
386
- struct power_supply *psy = data;
402
+ struct psy_get_supplier_prop_data *data = _data;
387403
388
- if (__power_supply_is_supplied_by(epsy, psy))
389
- if (!epsy->desc->get_property(epsy,
390
- POWER_SUPPLY_PROP_CURRENT_MAX,
391
- &ret))
392
- return ret.intval;
404
+ if (__power_supply_is_supplied_by(epsy, data->psy))
405
+ if (!epsy->desc->get_property(epsy, data->psp, data->val))
406
+ return 1; /* Success */
393407
394
- return 0;
408
+ return 0; /* Continue iterating */
395409 }
396410
397
-int power_supply_set_input_current_limit_from_supplier(struct power_supply *psy)
411
+int power_supply_get_property_from_supplier(struct power_supply *psy,
412
+ enum power_supply_property psp,
413
+ union power_supply_propval *val)
398414 {
399
- union power_supply_propval val = {0,};
400
- int curr;
401
-
402
- if (!psy->desc->set_property)
403
- return -EINVAL;
415
+ struct psy_get_supplier_prop_data data = {
416
+ .psy = psy,
417
+ .psp = psp,
418
+ .val = val,
419
+ };
420
+ int ret;
404421
405422 /*
406423 * This function is not intended for use with a supply with multiple
407
- * suppliers, we simply pick the first supply to report a non 0
408
- * max-current.
424
+ * suppliers, we simply pick the first supply to report the psp.
409425 */
410
- curr = class_for_each_device(power_supply_class, NULL, psy,
411
- __power_supply_get_supplier_max_current);
412
- if (curr <= 0)
413
- return (curr == 0) ? -ENODEV : curr;
426
+ ret = class_for_each_device(power_supply_class, NULL, &data,
427
+ __power_supply_get_supplier_property);
428
+ if (ret < 0)
429
+ return ret;
430
+ if (ret == 0)
431
+ return -ENODEV;
414432
415
- val.intval = curr;
416
-
417
- return psy->desc->set_property(psy,
418
- POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val);
433
+ return 0;
419434 }
420
-EXPORT_SYMBOL_GPL(power_supply_set_input_current_limit_from_supplier);
435
+EXPORT_SYMBOL_GPL(power_supply_get_property_from_supplier);
421436
422437 int power_supply_set_battery_charged(struct power_supply *psy)
423438 {
....@@ -525,6 +540,77 @@
525540 }
526541 EXPORT_SYMBOL_GPL(power_supply_get_by_phandle);
527542
543
+static int power_supply_match_device_node_array(struct device *dev,
544
+ void *data)
545
+{
546
+ struct match_device_node_array_param *param =
547
+ (struct match_device_node_array_param *)data;
548
+ struct power_supply **psy = param->psy;
549
+ ssize_t size = param->psy_size;
550
+ ssize_t *count = &param->psy_count;
551
+
552
+ if (!dev->parent || dev->parent->of_node != param->parent_of_node)
553
+ return 0;
554
+
555
+ if (*count >= size)
556
+ return -EOVERFLOW;
557
+
558
+ psy[*count] = dev_get_drvdata(dev);
559
+ atomic_inc(&psy[*count]->use_cnt);
560
+ (*count)++;
561
+
562
+ return 0;
563
+}
564
+
565
+/**
566
+ * power_supply_get_by_phandle_array() - Similar to
567
+ * power_supply_get_by_phandle but returns an array of power supply
568
+ * objects which are associated with the phandle.
569
+ * @np: Pointer to device node holding phandle property.
570
+ * @property: Name of property holding a power supply name.
571
+ * @psy: Array of power_supply pointers provided by the client which is
572
+ * filled by power_supply_get_by_phandle_array.
573
+ * @size: size of power_supply pointer array.
574
+ *
575
+ * If power supply was found, it increases reference count for the
576
+ * internal power supply's device. The user should power_supply_put()
577
+ * after usage.
578
+ *
579
+ * Return: On success returns the number of power supply objects filled
580
+ * in the @psy array.
581
+ * -EOVERFLOW when size of @psy array is not suffice.
582
+ * -EINVAL when @psy is NULL or @size is 0.
583
+ * -ENODEV when matching device_node is not found.
584
+ */
585
+int power_supply_get_by_phandle_array(struct device_node *np,
586
+ const char *property,
587
+ struct power_supply **psy,
588
+ ssize_t size)
589
+{
590
+ struct device_node *power_supply_np;
591
+ int ret;
592
+ struct match_device_node_array_param param;
593
+
594
+ if (!psy || !size)
595
+ return -EINVAL;
596
+
597
+ power_supply_np = of_parse_phandle(np, property, 0);
598
+ if (!power_supply_np)
599
+ return -ENODEV;
600
+
601
+ param.parent_of_node = power_supply_np;
602
+ param.psy = psy;
603
+ param.psy_size = size;
604
+ param.psy_count = 0;
605
+ ret = class_for_each_device(power_supply_class, NULL, &param,
606
+ power_supply_match_device_node_array);
607
+
608
+ of_node_put(power_supply_np);
609
+
610
+ return param.psy_count;
611
+}
612
+EXPORT_SYMBOL_GPL(power_supply_get_by_phandle_array);
613
+
528614 static void devm_power_supply_put(struct device *dev, void *res)
529615 {
530616 struct power_supply **psy = res;
....@@ -568,17 +654,34 @@
568654 int power_supply_get_battery_info(struct power_supply *psy,
569655 struct power_supply_battery_info *info)
570656 {
657
+ struct power_supply_resistance_temp_table *resist_table;
571658 struct device_node *battery_np;
572659 const char *value;
573
- int err;
660
+ int err, len, index;
661
+ const __be32 *list;
574662
575663 info->energy_full_design_uwh = -EINVAL;
576664 info->charge_full_design_uah = -EINVAL;
577665 info->voltage_min_design_uv = -EINVAL;
666
+ info->voltage_max_design_uv = -EINVAL;
578667 info->precharge_current_ua = -EINVAL;
579668 info->charge_term_current_ua = -EINVAL;
580669 info->constant_charge_current_max_ua = -EINVAL;
581670 info->constant_charge_voltage_max_uv = -EINVAL;
671
+ info->temp_ambient_alert_min = INT_MIN;
672
+ info->temp_ambient_alert_max = INT_MAX;
673
+ info->temp_alert_min = INT_MIN;
674
+ info->temp_alert_max = INT_MAX;
675
+ info->temp_min = INT_MIN;
676
+ info->temp_max = INT_MAX;
677
+ info->factory_internal_resistance_uohm = -EINVAL;
678
+ info->resist_table = NULL;
679
+
680
+ for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
681
+ info->ocv_table[index] = NULL;
682
+ info->ocv_temp[index] = -EINVAL;
683
+ info->ocv_table_size[index] = -EINVAL;
684
+ }
582685
583686 if (!psy->of_node) {
584687 dev_warn(&psy->dev, "%s currently only supports devicetree\n",
....@@ -592,14 +695,16 @@
592695
593696 err = of_property_read_string(battery_np, "compatible", &value);
594697 if (err)
595
- return err;
698
+ goto out_put_node;
596699
597
- if (strcmp("simple-battery", value))
598
- return -ENODEV;
700
+ if (strcmp("simple-battery", value)) {
701
+ err = -ENODEV;
702
+ goto out_put_node;
703
+ }
599704
600705 /* The property and field names below must correspond to elements
601706 * in enum power_supply_property. For reasoning, see
602
- * Documentation/power/power_supply_class.txt.
707
+ * Documentation/power/power_supply_class.rst.
603708 */
604709
605710 of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
....@@ -608,18 +713,251 @@
608713 &info->charge_full_design_uah);
609714 of_property_read_u32(battery_np, "voltage-min-design-microvolt",
610715 &info->voltage_min_design_uv);
716
+ of_property_read_u32(battery_np, "voltage-max-design-microvolt",
717
+ &info->voltage_max_design_uv);
718
+ of_property_read_u32(battery_np, "trickle-charge-current-microamp",
719
+ &info->tricklecharge_current_ua);
611720 of_property_read_u32(battery_np, "precharge-current-microamp",
612721 &info->precharge_current_ua);
722
+ of_property_read_u32(battery_np, "precharge-upper-limit-microvolt",
723
+ &info->precharge_voltage_max_uv);
613724 of_property_read_u32(battery_np, "charge-term-current-microamp",
614725 &info->charge_term_current_ua);
615
- of_property_read_u32(battery_np, "constant_charge_current_max_microamp",
726
+ of_property_read_u32(battery_np, "re-charge-voltage-microvolt",
727
+ &info->charge_restart_voltage_uv);
728
+ of_property_read_u32(battery_np, "over-voltage-threshold-microvolt",
729
+ &info->overvoltage_limit_uv);
730
+ of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
616731 &info->constant_charge_current_max_ua);
617
- of_property_read_u32(battery_np, "constant_charge_voltage_max_microvolt",
732
+ of_property_read_u32(battery_np, "constant-charge-voltage-max-microvolt",
618733 &info->constant_charge_voltage_max_uv);
734
+ of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms",
735
+ &info->factory_internal_resistance_uohm);
619736
620
- return 0;
737
+ of_property_read_u32_index(battery_np, "ambient-celsius",
738
+ 0, &info->temp_ambient_alert_min);
739
+ of_property_read_u32_index(battery_np, "ambient-celsius",
740
+ 1, &info->temp_ambient_alert_max);
741
+ of_property_read_u32_index(battery_np, "alert-celsius",
742
+ 0, &info->temp_alert_min);
743
+ of_property_read_u32_index(battery_np, "alert-celsius",
744
+ 1, &info->temp_alert_max);
745
+ of_property_read_u32_index(battery_np, "operating-range-celsius",
746
+ 0, &info->temp_min);
747
+ of_property_read_u32_index(battery_np, "operating-range-celsius",
748
+ 1, &info->temp_max);
749
+
750
+ len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
751
+ if (len < 0 && len != -EINVAL) {
752
+ err = len;
753
+ goto out_put_node;
754
+ } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
755
+ dev_err(&psy->dev, "Too many temperature values\n");
756
+ err = -EINVAL;
757
+ goto out_put_node;
758
+ } else if (len > 0) {
759
+ of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
760
+ info->ocv_temp, len);
761
+ }
762
+
763
+ for (index = 0; index < len; index++) {
764
+ struct power_supply_battery_ocv_table *table;
765
+ char *propname;
766
+ int i, tab_len, size;
767
+
768
+ propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
769
+ if (!propname) {
770
+ power_supply_put_battery_info(psy, info);
771
+ err = -ENOMEM;
772
+ goto out_put_node;
773
+ }
774
+ list = of_get_property(battery_np, propname, &size);
775
+ if (!list || !size) {
776
+ dev_err(&psy->dev, "failed to get %s\n", propname);
777
+ kfree(propname);
778
+ power_supply_put_battery_info(psy, info);
779
+ err = -EINVAL;
780
+ goto out_put_node;
781
+ }
782
+
783
+ kfree(propname);
784
+ tab_len = size / (2 * sizeof(__be32));
785
+ info->ocv_table_size[index] = tab_len;
786
+
787
+ table = info->ocv_table[index] =
788
+ devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
789
+ if (!info->ocv_table[index]) {
790
+ power_supply_put_battery_info(psy, info);
791
+ err = -ENOMEM;
792
+ goto out_put_node;
793
+ }
794
+
795
+ for (i = 0; i < tab_len; i++) {
796
+ table[i].ocv = be32_to_cpu(*list);
797
+ list++;
798
+ table[i].capacity = be32_to_cpu(*list);
799
+ list++;
800
+ }
801
+ }
802
+
803
+ list = of_get_property(battery_np, "resistance-temp-table", &len);
804
+ if (!list || !len)
805
+ goto out_put_node;
806
+
807
+ info->resist_table_size = len / (2 * sizeof(__be32));
808
+ resist_table = info->resist_table = devm_kcalloc(&psy->dev,
809
+ info->resist_table_size,
810
+ sizeof(*resist_table),
811
+ GFP_KERNEL);
812
+ if (!info->resist_table) {
813
+ power_supply_put_battery_info(psy, info);
814
+ err = -ENOMEM;
815
+ goto out_put_node;
816
+ }
817
+
818
+ for (index = 0; index < info->resist_table_size; index++) {
819
+ resist_table[index].temp = be32_to_cpu(*list++);
820
+ resist_table[index].resistance = be32_to_cpu(*list++);
821
+ }
822
+
823
+out_put_node:
824
+ of_node_put(battery_np);
825
+ return err;
621826 }
622827 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
828
+
829
+void power_supply_put_battery_info(struct power_supply *psy,
830
+ struct power_supply_battery_info *info)
831
+{
832
+ int i;
833
+
834
+ for (i = 0; i < POWER_SUPPLY_OCV_TEMP_MAX; i++) {
835
+ if (info->ocv_table[i])
836
+ devm_kfree(&psy->dev, info->ocv_table[i]);
837
+ }
838
+
839
+ if (info->resist_table)
840
+ devm_kfree(&psy->dev, info->resist_table);
841
+}
842
+EXPORT_SYMBOL_GPL(power_supply_put_battery_info);
843
+
844
+/**
845
+ * power_supply_temp2resist_simple() - find the battery internal resistance
846
+ * percent
847
+ * @table: Pointer to battery resistance temperature table
848
+ * @table_len: The table length
849
+ * @temp: Current temperature
850
+ *
851
+ * This helper function is used to look up battery internal resistance percent
852
+ * according to current temperature value from the resistance temperature table,
853
+ * and the table must be ordered descending. Then the actual battery internal
854
+ * resistance = the ideal battery internal resistance * percent / 100.
855
+ *
856
+ * Return: the battery internal resistance percent
857
+ */
858
+int power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table,
859
+ int table_len, int temp)
860
+{
861
+ int i, resist;
862
+
863
+ for (i = 0; i < table_len; i++)
864
+ if (temp > table[i].temp)
865
+ break;
866
+
867
+ if (i > 0 && i < table_len) {
868
+ int tmp;
869
+
870
+ tmp = (table[i - 1].resistance - table[i].resistance) *
871
+ (temp - table[i].temp);
872
+ tmp /= table[i - 1].temp - table[i].temp;
873
+ resist = tmp + table[i].resistance;
874
+ } else if (i == 0) {
875
+ resist = table[0].resistance;
876
+ } else {
877
+ resist = table[table_len - 1].resistance;
878
+ }
879
+
880
+ return resist;
881
+}
882
+EXPORT_SYMBOL_GPL(power_supply_temp2resist_simple);
883
+
884
+/**
885
+ * power_supply_ocv2cap_simple() - find the battery capacity
886
+ * @table: Pointer to battery OCV lookup table
887
+ * @table_len: OCV table length
888
+ * @ocv: Current OCV value
889
+ *
890
+ * This helper function is used to look up battery capacity according to
891
+ * current OCV value from one OCV table, and the OCV table must be ordered
892
+ * descending.
893
+ *
894
+ * Return: the battery capacity.
895
+ */
896
+int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,
897
+ int table_len, int ocv)
898
+{
899
+ int i, cap, tmp;
900
+
901
+ for (i = 0; i < table_len; i++)
902
+ if (ocv > table[i].ocv)
903
+ break;
904
+
905
+ if (i > 0 && i < table_len) {
906
+ tmp = (table[i - 1].capacity - table[i].capacity) *
907
+ (ocv - table[i].ocv);
908
+ tmp /= table[i - 1].ocv - table[i].ocv;
909
+ cap = tmp + table[i].capacity;
910
+ } else if (i == 0) {
911
+ cap = table[0].capacity;
912
+ } else {
913
+ cap = table[table_len - 1].capacity;
914
+ }
915
+
916
+ return cap;
917
+}
918
+EXPORT_SYMBOL_GPL(power_supply_ocv2cap_simple);
919
+
920
+struct power_supply_battery_ocv_table *
921
+power_supply_find_ocv2cap_table(struct power_supply_battery_info *info,
922
+ int temp, int *table_len)
923
+{
924
+ int best_temp_diff = INT_MAX, temp_diff;
925
+ u8 i, best_index = 0;
926
+
927
+ if (!info->ocv_table[0])
928
+ return NULL;
929
+
930
+ for (i = 0; i < POWER_SUPPLY_OCV_TEMP_MAX; i++) {
931
+ /* Out of capacity tables */
932
+ if (!info->ocv_table[i])
933
+ break;
934
+
935
+ temp_diff = abs(info->ocv_temp[i] - temp);
936
+
937
+ if (temp_diff < best_temp_diff) {
938
+ best_temp_diff = temp_diff;
939
+ best_index = i;
940
+ }
941
+ }
942
+
943
+ *table_len = info->ocv_table_size[best_index];
944
+ return info->ocv_table[best_index];
945
+}
946
+EXPORT_SYMBOL_GPL(power_supply_find_ocv2cap_table);
947
+
948
+int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info,
949
+ int ocv, int temp)
950
+{
951
+ struct power_supply_battery_ocv_table *table;
952
+ int table_len;
953
+
954
+ table = power_supply_find_ocv2cap_table(info, temp, &table_len);
955
+ if (!table)
956
+ return -EINVAL;
957
+
958
+ return power_supply_ocv2cap_simple(table, table_len, ocv);
959
+}
960
+EXPORT_SYMBOL_GPL(power_supply_batinfo_ocv2cap);
623961
624962 int power_supply_get_property(struct power_supply *psy,
625963 enum power_supply_property psp,
....@@ -718,7 +1056,7 @@
7181056
7191057 static int psy_register_thermal(struct power_supply *psy)
7201058 {
721
- int i;
1059
+ int i, ret;
7221060
7231061 if (psy->desc->no_thermal)
7241062 return 0;
....@@ -728,7 +1066,12 @@
7281066 if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) {
7291067 psy->tzd = thermal_zone_device_register(psy->desc->name,
7301068 0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
731
- return PTR_ERR_OR_ZERO(psy->tzd);
1069
+ if (IS_ERR(psy->tzd))
1070
+ return PTR_ERR(psy->tzd);
1071
+ ret = thermal_zone_device_enable(psy->tzd);
1072
+ if (ret)
1073
+ thermal_zone_device_unregister(psy->tzd);
1074
+ return ret;
7321075 }
7331076 }
7341077 return 0;
....@@ -760,7 +1103,7 @@
7601103 return ret;
7611104 }
7621105
763
-static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,
1106
+static int ps_get_cur_charge_cntl_limit(struct thermal_cooling_device *tcd,
7641107 unsigned long *state)
7651108 {
7661109 struct power_supply *psy;
....@@ -795,7 +1138,7 @@
7951138
7961139 static const struct thermal_cooling_device_ops psy_tcd_ops = {
7971140 .get_max_state = ps_get_max_charge_cntl_limit,
798
- .get_cur_state = ps_get_cur_chrage_cntl_limit,
1141
+ .get_cur_state = ps_get_cur_charge_cntl_limit,
7991142 .set_cur_state = ps_set_cur_charge_cntl_limit,
8001143 };
8011144
....@@ -807,9 +1150,15 @@
8071150 for (i = 0; i < psy->desc->num_properties; i++) {
8081151 if (psy->desc->properties[i] ==
8091152 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) {
810
- psy->tcd = thermal_cooling_device_register(
811
- (char *)psy->desc->name,
812
- psy, &psy_tcd_ops);
1153
+ if (psy->dev.parent)
1154
+ psy->tcd = thermal_of_cooling_device_register(
1155
+ dev_of_node(psy->dev.parent),
1156
+ (char *)psy->desc->name,
1157
+ psy, &psy_tcd_ops);
1158
+ else
1159
+ psy->tcd = thermal_cooling_device_register(
1160
+ (char *)psy->desc->name,
1161
+ psy, &psy_tcd_ops);
8131162 return PTR_ERR_OR_ZERO(psy->tcd);
8141163 }
8151164 }
....@@ -880,6 +1229,7 @@
8801229 dev_set_drvdata(dev, psy);
8811230 psy->desc = desc;
8821231 if (cfg) {
1232
+ dev->groups = cfg->attr_grp;
8831233 psy->drv_data = cfg->drv_data;
8841234 psy->of_node =
8851235 cfg->fwnode ? to_of_node(cfg->fwnode) : cfg->of_node;
....@@ -914,13 +1264,13 @@
9141264 if (rc)
9151265 goto register_thermal_failed;
9161266
917
- rc = psy_register_cooler(psy);
918
- if (rc)
919
- goto register_cooler_failed;
920
-
9211267 rc = power_supply_create_triggers(psy);
9221268 if (rc)
9231269 goto create_triggers_failed;
1270
+
1271
+ rc = power_supply_add_hwmon_sysfs(psy);
1272
+ if (rc)
1273
+ goto add_hwmon_sysfs_failed;
9241274
9251275 /*
9261276 * Update use_cnt after any uevents (most notably from device_add()).
....@@ -940,13 +1290,13 @@
9401290
9411291 return psy;
9421292
1293
+add_hwmon_sysfs_failed:
1294
+ power_supply_remove_triggers(psy);
9431295 create_triggers_failed:
944
- psy_unregister_cooler(psy);
945
-register_cooler_failed:
9461296 psy_unregister_thermal(psy);
9471297 register_thermal_failed:
948
- device_del(dev);
9491298 wakeup_init_failed:
1299
+ device_del(dev);
9501300 device_add_failed:
9511301 check_supplies_failed:
9521302 dev_set_name_failed:
....@@ -1092,6 +1442,7 @@
10921442 cancel_work_sync(&psy->changed_work);
10931443 cancel_delayed_work_sync(&psy->deferred_register_work);
10941444 sysfs_remove_link(&psy->dev.kobj, "powers");
1445
+ power_supply_remove_hwmon_sysfs(psy);
10951446 power_supply_remove_triggers(psy);
10961447 psy_unregister_cooler(psy);
10971448 psy_unregister_thermal(psy);