* Re: [PATCH 2/5] power: supply: core: add function to get supplies from fwnode
@ 2025-03-16 19:34 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-03-16 19:34 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20250312-batt_ops-v1-2-88e0bb3129fd@google.com>
References: <20250312-batt_ops-v1-2-88e0bb3129fd@google.com>
TO: Amit Sunil Dhamne via B4 Relay <devnull+amitsd.google.com@kernel.org>
TO: Rob Herring <robh@kernel.org>
TO: Krzysztof Kozlowski <krzk@kernel.org>
TO: Conor Dooley <conor+dt@kernel.org>
TO: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
TO: Badhri Jagan Sridharan <badhri@google.com>
TO: Sebastian Reichel <sre@kernel.org>
TO: Heikki Krogerus <heikki.krogerus@linux.intel.com>
TO: "Rafael J. Wysocki" <rafael@kernel.org>
TO: Len Brown <len.brown@intel.com>
TO: Pavel Machek <pavel@kernel.org>
CC: devicetree@vger.kernel.org
CC: linux-kernel@vger.kernel.org
CC: linux-usb@vger.kernel.org
CC: linux-pm@vger.kernel.org
CC: RD Babiera <rdbabiera@google.com>
CC: Kyle Tso <kyletso@google.com>
CC: Amit Sunil Dhamne <amitsd@google.com>
Hi Amit,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 80e54e84911a923c40d7bee33a34c1b4be148d7a]
url: https://github.com/intel-lab-lkp/linux/commits/Amit-Sunil-Dhamne-via-B4-Relay/dt-bindings-connector-add-fixed-batteries-property/20250313-074635
base: 80e54e84911a923c40d7bee33a34c1b4be148d7a
patch link: https://lore.kernel.org/r/20250312-batt_ops-v1-2-88e0bb3129fd%40google.com
patch subject: [PATCH 2/5] power: supply: core: add function to get supplies from fwnode
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: riscv-randconfig-r073-20250316 (https://download.01.org/0day-ci/archive/20250317/202503170343.AW93SIMu-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 14.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202503170343.AW93SIMu-lkp@intel.com/
smatch warnings:
drivers/power/supply/power_supply_core.c:649 power_supply_get_by_fwnode_reference_array() error: uninitialized symbol 'ret'.
vim +/ret +649 drivers/power/supply/power_supply_core.c
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 600
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 601 /**
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 602 * power_supply_get_by_fwnode_reference_array() - Returns an array of power
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 603 * supply objects associated with each fwnode reference present in the property
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 604 * @fwnode: Pointer to fwnode to lookup property
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 605 * @property: Name of property holding references
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 606 * @psy: Resulting array of power_supply pointers. To be provided by the caller.
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 607 * @size: size of power_supply pointer array.
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 608 *
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 609 * If power supply was found, it increases reference count for the
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 610 * internal power supply's device. The user should power_supply_put()
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 611 * after usage.
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 612 *
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 613 * Return: On success returns the number of power supply objects filled
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 614 * in the @psy array.
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 615 * -EOVERFLOW when size of @psy array is not suffice.
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 616 * -EINVAL when @psy is NULL or @size is 0.
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 617 * -ENODATA when fwnode does not contain the given property
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 618 */
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 619 int power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 620 const char *property,
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 621 struct power_supply **psy,
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 622 ssize_t size)
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 623 {
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 624 int ret, index, count = 0;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 625 struct fwnode_reference_args args;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 626 struct device *dev;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 627
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 628 if (!psy || !size)
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 629 return -EINVAL;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 630
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 631 for (index = 0; index < size &&
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 632 !(ret = fwnode_property_get_reference_args(fwnode, property, NULL,
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 633 0, index, &args));
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 634 ++index) {
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 635 dev = class_find_device(&power_supply_class, NULL, args.fwnode,
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 636 power_supply_match_fwnode);
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 637 fwnode_handle_put(args.fwnode);
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 638 if (!dev)
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 639 continue;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 640
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 641 if (count > size)
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 642 return -EOVERFLOW;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 643
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 644 psy[count] = dev_get_drvdata(dev);
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 645 atomic_inc(&psy[count]->use_cnt);
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 646 ++count;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 647 }
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 648
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 @649 if (ret != -ENOENT)
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 650 return ret;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 651
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 652 return index ? count : -ENODATA;
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 653 }
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 654 EXPORT_SYMBOL_GPL(power_supply_get_by_fwnode_reference_array);
0c8087f6d68b4cd Amit Sunil Dhamne 2025-03-12 655
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 0/5] Add support for Battery Status & Battery Caps AMS in TCPM
@ 2025-03-12 23:42 Amit Sunil Dhamne
2025-03-12 23:42 ` Amit Sunil Dhamne via B4 Relay
0 siblings, 1 reply; 5+ messages in thread
From: Amit Sunil Dhamne @ 2025-03-12 23:42 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Badhri Jagan Sridharan, Sebastian Reichel,
Heikki Krogerus, Rafael J. Wysocki, Len Brown, Pavel Machek
Cc: devicetree, linux-kernel, linux-usb, linux-pm, RD Babiera,
Kyle Tso, Amit Sunil Dhamne
Support for Battery Status & Battery Caps messages in response to
Get_Battery_Status & Get_Battery_Cap request is required by USB PD devices
powered by battery, as per "USB PD R3.1 V1.8 Spec", "6.13 Message
Applicability" section. This patchset adds support for these AMSes
to achieve greater compliance with the spec.
Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
---
Amit Sunil Dhamne (5):
dt-bindings: connector: add fixed-batteries property
power: supply: core: add function to get supplies from fwnode
usb: typec: tcpm: Add support for Battery Status response message
power: supply: core: add vendor and product id properties
usb: typec: tcpm: Add support for Battery Cap response message
Documentation/ABI/testing/sysfs-class-power | 20 ++
.../bindings/connector/usb-connector.yaml | 8 +
.../devicetree/bindings/usb/maxim,max33359.yaml | 1 +
Documentation/power/power_supply_class.rst | 11 ++
drivers/power/supply/power_supply_core.c | 60 ++++++
drivers/power/supply/power_supply_sysfs.c | 2 +
drivers/usb/typec/tcpm/tcpm.c | 217 ++++++++++++++++++++-
include/linux/power_supply.h | 7 +
include/linux/usb/pd.h | 65 ++++++
9 files changed, 388 insertions(+), 3 deletions(-)
---
base-commit: 80e54e84911a923c40d7bee33a34c1b4be148d7a
change-id: 20250311-batt_ops-be1bd71ca254
Best regards,
--
Amit Sunil Dhamne <amitsd@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/5] power: supply: core: add function to get supplies from fwnode
2025-03-12 23:42 [PATCH 0/5] Add support for Battery Status & Battery Caps AMS in TCPM Amit Sunil Dhamne
@ 2025-03-12 23:42 ` Amit Sunil Dhamne via B4 Relay
0 siblings, 0 replies; 5+ messages in thread
From: Amit Sunil Dhamne @ 2025-03-12 23:42 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Badhri Jagan Sridharan, Sebastian Reichel,
Heikki Krogerus, Rafael J. Wysocki, Len Brown, Pavel Machek
Cc: devicetree, linux-kernel, linux-usb, linux-pm, RD Babiera,
Kyle Tso, Amit Sunil Dhamne
Add a new helper function power_supply_get_by_fwnode_reference_array()
to retrieve a list of power_supplies associated with the fwnode's
property. The property can contain multiple nodes where each node is
associated with a power_supply. The list of power_supply objects will be
stored in an array supplied by the caller and the return value will
indicate the size of the resulting array.
Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
---
drivers/power/supply/power_supply_core.c | 60 ++++++++++++++++++++++++++++++++
include/linux/power_supply.h | 5 +++
2 files changed, 65 insertions(+)
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 76c340b38015af0a67a0d91305e6242a8646bf53..df1a52f85125748c4fdcb10687aa7ed2f626ded1 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -593,6 +593,66 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
#endif /* CONFIG_OF */
+static int power_supply_match_fwnode(struct device *dev, const void *data)
+{
+ return dev && dev->parent && dev->parent->fwnode == data;
+}
+
+/**
+ * power_supply_get_by_fwnode_reference_array() - Returns an array of power
+ * supply objects associated with each fwnode reference present in the property
+ * @fwnode: Pointer to fwnode to lookup property
+ * @property: Name of property holding references
+ * @psy: Resulting array of power_supply pointers. To be provided by the caller.
+ * @size: size of power_supply pointer array.
+ *
+ * If power supply was found, it increases reference count for the
+ * internal power supply's device. The user should power_supply_put()
+ * after usage.
+ *
+ * Return: On success returns the number of power supply objects filled
+ * in the @psy array.
+ * -EOVERFLOW when size of @psy array is not suffice.
+ * -EINVAL when @psy is NULL or @size is 0.
+ * -ENODATA when fwnode does not contain the given property
+ */
+int power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
+ const char *property,
+ struct power_supply **psy,
+ ssize_t size)
+{
+ int ret, index, count = 0;
+ struct fwnode_reference_args args;
+ struct device *dev;
+
+ if (!psy || !size)
+ return -EINVAL;
+
+ for (index = 0; index < size &&
+ !(ret = fwnode_property_get_reference_args(fwnode, property, NULL,
+ 0, index, &args));
+ ++index) {
+ dev = class_find_device(&power_supply_class, NULL, args.fwnode,
+ power_supply_match_fwnode);
+ fwnode_handle_put(args.fwnode);
+ if (!dev)
+ continue;
+
+ if (count > size)
+ return -EOVERFLOW;
+
+ psy[count] = dev_get_drvdata(dev);
+ atomic_inc(&psy[count]->use_cnt);
+ ++count;
+ }
+
+ if (ret != -ENOENT)
+ return ret;
+
+ return index ? count : -ENODATA;
+}
+EXPORT_SYMBOL_GPL(power_supply_get_by_fwnode_reference_array);
+
int power_supply_get_battery_info(struct power_supply *psy,
struct power_supply_battery_info **info_out)
{
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 6ed53b292162469d7b357734d5589bff18a201d0..3f062607e5cd7c7f04384e34128ae0953e25d981 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -820,6 +820,11 @@ devm_power_supply_get_by_phandle(struct device *dev, const char *property)
{ return NULL; }
#endif /* CONFIG_OF */
+extern int
+power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
+ const char *property,
+ struct power_supply **psy,
+ ssize_t size);
extern const enum power_supply_property power_supply_battery_info_properties[];
extern const size_t power_supply_battery_info_properties_size;
extern int power_supply_get_battery_info(struct power_supply *psy,
--
2.49.0.rc0.332.g42c0ae87b1-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/5] power: supply: core: add function to get supplies from fwnode
@ 2025-03-12 23:42 ` Amit Sunil Dhamne via B4 Relay
0 siblings, 0 replies; 5+ messages in thread
From: Amit Sunil Dhamne via B4 Relay @ 2025-03-12 23:42 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Badhri Jagan Sridharan, Sebastian Reichel,
Heikki Krogerus, Rafael J. Wysocki, Len Brown, Pavel Machek
Cc: devicetree, linux-kernel, linux-usb, linux-pm, RD Babiera,
Kyle Tso, Amit Sunil Dhamne
From: Amit Sunil Dhamne <amitsd@google.com>
Add a new helper function power_supply_get_by_fwnode_reference_array()
to retrieve a list of power_supplies associated with the fwnode's
property. The property can contain multiple nodes where each node is
associated with a power_supply. The list of power_supply objects will be
stored in an array supplied by the caller and the return value will
indicate the size of the resulting array.
Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
---
drivers/power/supply/power_supply_core.c | 60 ++++++++++++++++++++++++++++++++
include/linux/power_supply.h | 5 +++
2 files changed, 65 insertions(+)
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 76c340b38015af0a67a0d91305e6242a8646bf53..df1a52f85125748c4fdcb10687aa7ed2f626ded1 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -593,6 +593,66 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
#endif /* CONFIG_OF */
+static int power_supply_match_fwnode(struct device *dev, const void *data)
+{
+ return dev && dev->parent && dev->parent->fwnode == data;
+}
+
+/**
+ * power_supply_get_by_fwnode_reference_array() - Returns an array of power
+ * supply objects associated with each fwnode reference present in the property
+ * @fwnode: Pointer to fwnode to lookup property
+ * @property: Name of property holding references
+ * @psy: Resulting array of power_supply pointers. To be provided by the caller.
+ * @size: size of power_supply pointer array.
+ *
+ * If power supply was found, it increases reference count for the
+ * internal power supply's device. The user should power_supply_put()
+ * after usage.
+ *
+ * Return: On success returns the number of power supply objects filled
+ * in the @psy array.
+ * -EOVERFLOW when size of @psy array is not suffice.
+ * -EINVAL when @psy is NULL or @size is 0.
+ * -ENODATA when fwnode does not contain the given property
+ */
+int power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
+ const char *property,
+ struct power_supply **psy,
+ ssize_t size)
+{
+ int ret, index, count = 0;
+ struct fwnode_reference_args args;
+ struct device *dev;
+
+ if (!psy || !size)
+ return -EINVAL;
+
+ for (index = 0; index < size &&
+ !(ret = fwnode_property_get_reference_args(fwnode, property, NULL,
+ 0, index, &args));
+ ++index) {
+ dev = class_find_device(&power_supply_class, NULL, args.fwnode,
+ power_supply_match_fwnode);
+ fwnode_handle_put(args.fwnode);
+ if (!dev)
+ continue;
+
+ if (count > size)
+ return -EOVERFLOW;
+
+ psy[count] = dev_get_drvdata(dev);
+ atomic_inc(&psy[count]->use_cnt);
+ ++count;
+ }
+
+ if (ret != -ENOENT)
+ return ret;
+
+ return index ? count : -ENODATA;
+}
+EXPORT_SYMBOL_GPL(power_supply_get_by_fwnode_reference_array);
+
int power_supply_get_battery_info(struct power_supply *psy,
struct power_supply_battery_info **info_out)
{
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 6ed53b292162469d7b357734d5589bff18a201d0..3f062607e5cd7c7f04384e34128ae0953e25d981 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -820,6 +820,11 @@ devm_power_supply_get_by_phandle(struct device *dev, const char *property)
{ return NULL; }
#endif /* CONFIG_OF */
+extern int
+power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
+ const char *property,
+ struct power_supply **psy,
+ ssize_t size);
extern const enum power_supply_property power_supply_battery_info_properties[];
extern const size_t power_supply_battery_info_properties_size;
extern int power_supply_get_battery_info(struct power_supply *psy,
--
2.49.0.rc0.332.g42c0ae87b1-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 2/5] power: supply: core: add function to get supplies from fwnode
2025-03-12 23:42 ` Amit Sunil Dhamne via B4 Relay
(?)
@ 2025-03-19 13:54 ` Heikki Krogerus
2025-04-08 19:54 ` Amit Sunil Dhamne
-1 siblings, 1 reply; 5+ messages in thread
From: Heikki Krogerus @ 2025-03-19 13:54 UTC (permalink / raw)
To: amitsd
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Badhri Jagan Sridharan, Sebastian Reichel,
Rafael J. Wysocki, Len Brown, Pavel Machek, devicetree,
linux-kernel, linux-usb, linux-pm, RD Babiera, Kyle Tso
On Wed, Mar 12, 2025 at 04:42:02PM -0700, Amit Sunil Dhamne via B4 Relay wrote:
> From: Amit Sunil Dhamne <amitsd@google.com>
>
> Add a new helper function power_supply_get_by_fwnode_reference_array()
> to retrieve a list of power_supplies associated with the fwnode's
> property. The property can contain multiple nodes where each node is
> associated with a power_supply. The list of power_supply objects will be
> stored in an array supplied by the caller and the return value will
> indicate the size of the resulting array.
I don't think this API is necessary. If I've understood what you are
after here, the batteries should simply have the Type-C psy(s) listed
in the supplied_to and/or supplied_from.
So you just need to make sure your battery nodes have the USB Type-C
node(s) listed in the "power-supplies" property in your DT, no?
thanks,
> Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
> ---
> drivers/power/supply/power_supply_core.c | 60 ++++++++++++++++++++++++++++++++
> include/linux/power_supply.h | 5 +++
> 2 files changed, 65 insertions(+)
>
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 76c340b38015af0a67a0d91305e6242a8646bf53..df1a52f85125748c4fdcb10687aa7ed2f626ded1 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -593,6 +593,66 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
> EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
> #endif /* CONFIG_OF */
>
> +static int power_supply_match_fwnode(struct device *dev, const void *data)
> +{
> + return dev && dev->parent && dev->parent->fwnode == data;
> +}
> +
> +/**
> + * power_supply_get_by_fwnode_reference_array() - Returns an array of power
> + * supply objects associated with each fwnode reference present in the property
> + * @fwnode: Pointer to fwnode to lookup property
> + * @property: Name of property holding references
> + * @psy: Resulting array of power_supply pointers. To be provided by the caller.
> + * @size: size of power_supply pointer array.
> + *
> + * If power supply was found, it increases reference count for the
> + * internal power supply's device. The user should power_supply_put()
> + * after usage.
> + *
> + * Return: On success returns the number of power supply objects filled
> + * in the @psy array.
> + * -EOVERFLOW when size of @psy array is not suffice.
> + * -EINVAL when @psy is NULL or @size is 0.
> + * -ENODATA when fwnode does not contain the given property
> + */
> +int power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
> + const char *property,
> + struct power_supply **psy,
> + ssize_t size)
> +{
> + int ret, index, count = 0;
> + struct fwnode_reference_args args;
> + struct device *dev;
> +
> + if (!psy || !size)
> + return -EINVAL;
> +
> + for (index = 0; index < size &&
> + !(ret = fwnode_property_get_reference_args(fwnode, property, NULL,
> + 0, index, &args));
> + ++index) {
> + dev = class_find_device(&power_supply_class, NULL, args.fwnode,
> + power_supply_match_fwnode);
> + fwnode_handle_put(args.fwnode);
> + if (!dev)
> + continue;
> +
> + if (count > size)
> + return -EOVERFLOW;
> +
> + psy[count] = dev_get_drvdata(dev);
> + atomic_inc(&psy[count]->use_cnt);
> + ++count;
> + }
> +
> + if (ret != -ENOENT)
> + return ret;
> +
> + return index ? count : -ENODATA;
> +}
> +EXPORT_SYMBOL_GPL(power_supply_get_by_fwnode_reference_array);
> +
> int power_supply_get_battery_info(struct power_supply *psy,
> struct power_supply_battery_info **info_out)
> {
> diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
> index 6ed53b292162469d7b357734d5589bff18a201d0..3f062607e5cd7c7f04384e34128ae0953e25d981 100644
> --- a/include/linux/power_supply.h
> +++ b/include/linux/power_supply.h
> @@ -820,6 +820,11 @@ devm_power_supply_get_by_phandle(struct device *dev, const char *property)
> { return NULL; }
> #endif /* CONFIG_OF */
>
> +extern int
> +power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
> + const char *property,
> + struct power_supply **psy,
> + ssize_t size);
> extern const enum power_supply_property power_supply_battery_info_properties[];
> extern const size_t power_supply_battery_info_properties_size;
> extern int power_supply_get_battery_info(struct power_supply *psy,
>
> --
> 2.49.0.rc0.332.g42c0ae87b1-goog
>
--
heikki
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 2/5] power: supply: core: add function to get supplies from fwnode
2025-03-19 13:54 ` Heikki Krogerus
@ 2025-04-08 19:54 ` Amit Sunil Dhamne
0 siblings, 0 replies; 5+ messages in thread
From: Amit Sunil Dhamne @ 2025-04-08 19:54 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Greg Kroah-Hartman, Badhri Jagan Sridharan, Sebastian Reichel,
Rafael J. Wysocki, Len Brown, Pavel Machek, devicetree,
linux-kernel, linux-usb, linux-pm, RD Babiera, Kyle Tso
On 3/19/25 6:54 AM, Heikki Krogerus wrote:
> On Wed, Mar 12, 2025 at 04:42:02PM -0700, Amit Sunil Dhamne via B4 Relay wrote:
>> From: Amit Sunil Dhamne <amitsd@google.com>
>>
>> Add a new helper function power_supply_get_by_fwnode_reference_array()
>> to retrieve a list of power_supplies associated with the fwnode's
>> property. The property can contain multiple nodes where each node is
>> associated with a power_supply. The list of power_supply objects will be
>> stored in an array supplied by the caller and the return value will
>> indicate the size of the resulting array.
> I don't think this API is necessary. If I've understood what you are
> after here, the batteries should simply have the Type-C psy(s) listed
> in the supplied_to and/or supplied_from.
>
> So you just need to make sure your battery nodes have the USB Type-C
> node(s) listed in the "power-supplies" property in your DT, no?
Thanks Heikki! I will evaluate between this approach vs OF graph
approach (as suggested in previous review) and implement it in v2.
>
> thanks,
>> Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
>> ---
>> drivers/power/supply/power_supply_core.c | 60 ++++++++++++++++++++++++++++++++
>> include/linux/power_supply.h | 5 +++
>> 2 files changed, 65 insertions(+)
>>
>> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
>> index 76c340b38015af0a67a0d91305e6242a8646bf53..df1a52f85125748c4fdcb10687aa7ed2f626ded1 100644
>> --- a/drivers/power/supply/power_supply_core.c
>> +++ b/drivers/power/supply/power_supply_core.c
>> @@ -593,6 +593,66 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
>> EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
>> #endif /* CONFIG_OF */
>>
>> +static int power_supply_match_fwnode(struct device *dev, const void *data)
>> +{
>> + return dev && dev->parent && dev->parent->fwnode == data;
>> +}
>> +
>> +/**
>> + * power_supply_get_by_fwnode_reference_array() - Returns an array of power
>> + * supply objects associated with each fwnode reference present in the property
>> + * @fwnode: Pointer to fwnode to lookup property
>> + * @property: Name of property holding references
>> + * @psy: Resulting array of power_supply pointers. To be provided by the caller.
>> + * @size: size of power_supply pointer array.
>> + *
>> + * If power supply was found, it increases reference count for the
>> + * internal power supply's device. The user should power_supply_put()
>> + * after usage.
>> + *
>> + * Return: On success returns the number of power supply objects filled
>> + * in the @psy array.
>> + * -EOVERFLOW when size of @psy array is not suffice.
>> + * -EINVAL when @psy is NULL or @size is 0.
>> + * -ENODATA when fwnode does not contain the given property
>> + */
>> +int power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
>> + const char *property,
>> + struct power_supply **psy,
>> + ssize_t size)
>> +{
>> + int ret, index, count = 0;
>> + struct fwnode_reference_args args;
>> + struct device *dev;
>> +
>> + if (!psy || !size)
>> + return -EINVAL;
>> +
>> + for (index = 0; index < size &&
>> + !(ret = fwnode_property_get_reference_args(fwnode, property, NULL,
>> + 0, index, &args));
>> + ++index) {
>> + dev = class_find_device(&power_supply_class, NULL, args.fwnode,
>> + power_supply_match_fwnode);
>> + fwnode_handle_put(args.fwnode);
>> + if (!dev)
>> + continue;
>> +
>> + if (count > size)
>> + return -EOVERFLOW;
>> +
>> + psy[count] = dev_get_drvdata(dev);
>> + atomic_inc(&psy[count]->use_cnt);
>> + ++count;
>> + }
>> +
>> + if (ret != -ENOENT)
>> + return ret;
>> +
>> + return index ? count : -ENODATA;
>> +}
>> +EXPORT_SYMBOL_GPL(power_supply_get_by_fwnode_reference_array);
>> +
>> int power_supply_get_battery_info(struct power_supply *psy,
>> struct power_supply_battery_info **info_out)
>> {
>> diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
>> index 6ed53b292162469d7b357734d5589bff18a201d0..3f062607e5cd7c7f04384e34128ae0953e25d981 100644
>> --- a/include/linux/power_supply.h
>> +++ b/include/linux/power_supply.h
>> @@ -820,6 +820,11 @@ devm_power_supply_get_by_phandle(struct device *dev, const char *property)
>> { return NULL; }
>> #endif /* CONFIG_OF */
>>
>> +extern int
>> +power_supply_get_by_fwnode_reference_array(struct fwnode_handle *fwnode,
>> + const char *property,
>> + struct power_supply **psy,
>> + ssize_t size);
>> extern const enum power_supply_property power_supply_battery_info_properties[];
>> extern const size_t power_supply_battery_info_properties_size;
>> extern int power_supply_get_battery_info(struct power_supply *psy,
>>
>> --
>> 2.49.0.rc0.332.g42c0ae87b1-goog
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-08 19:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-16 19:34 [PATCH 2/5] power: supply: core: add function to get supplies from fwnode kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2025-03-12 23:42 [PATCH 0/5] Add support for Battery Status & Battery Caps AMS in TCPM Amit Sunil Dhamne
2025-03-12 23:42 ` [PATCH 2/5] power: supply: core: add function to get supplies from fwnode Amit Sunil Dhamne
2025-03-12 23:42 ` Amit Sunil Dhamne via B4 Relay
2025-03-19 13:54 ` Heikki Krogerus
2025-04-08 19:54 ` Amit Sunil Dhamne
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.