Add a function to register a power supply device for a partner. Also,
ensure that the registered power supply gets unregistered when the
partner is removed.
Signed-off-by: Prashant Malani <[email protected]>
---
drivers/usb/typec/class.c | 18 +++++++++++++++++-
drivers/usb/typec/class.h | 2 ++
include/linux/usb/typec.h | 5 +++++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index aeef453aa658..14a898440342 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -845,11 +845,27 @@ EXPORT_SYMBOL_GPL(typec_register_partner);
*/
void typec_unregister_partner(struct typec_partner *partner)
{
- if (!IS_ERR_OR_NULL(partner))
+ if (!IS_ERR_OR_NULL(partner)) {
+ power_supply_unregister(partner->psy);
device_unregister(&partner->dev);
+ }
}
EXPORT_SYMBOL_GPL(typec_unregister_partner);
+int typec_partner_register_psy(struct typec_partner *partner, const struct power_supply_desc *desc,
+ const struct power_supply_config *cfg)
+{
+ partner->psy = power_supply_register(&partner->dev, desc, cfg);
+ if (IS_ERR(partner->psy)) {
+ dev_err(&partner->dev, "failed to register partner power supply (%ld)\n",
+ PTR_ERR(partner->psy));
+ return PTR_ERR(partner->psy);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(typec_partner_register_psy);
+
/* ------------------------------------------------------------------------- */
/* Type-C Cable Plugs */
diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h
index aef03eb7e152..b75b0f22d982 100644
--- a/drivers/usb/typec/class.h
+++ b/drivers/usb/typec/class.h
@@ -4,6 +4,7 @@
#define __USB_TYPEC_CLASS__
#include <linux/device.h>
+#include <linux/power_supply.h>
#include <linux/usb/typec.h>
struct typec_mux;
@@ -33,6 +34,7 @@ struct typec_partner {
int num_altmodes;
u16 pd_revision; /* 0300H = "3.0" */
enum usb_pd_svdm_ver svdm_version;
+ struct power_supply *psy;
};
struct typec_port {
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index e2e44bb1dad8..905527dab78c 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -22,6 +22,9 @@ struct typec_altmode_ops;
struct fwnode_handle;
struct device;
+struct power_supply_desc;
+struct power_supply_config;
+
enum typec_port_type {
TYPEC_PORT_SRC,
TYPEC_PORT_SNK,
@@ -132,6 +135,8 @@ int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmod
struct typec_altmode
*typec_partner_register_altmode(struct typec_partner *partner,
const struct typec_altmode_desc *desc);
+int typec_partner_register_psy(struct typec_partner *partner, const struct power_supply_desc *desc,
+ const struct power_supply_config *cfg);
int typec_plug_set_num_altmodes(struct typec_plug *plug, int num_altmodes);
struct typec_altmode
*typec_plug_register_altmode(struct typec_plug *plug,
--
2.33.0.153.gba50c8fa24-goog