From: Kyle Tso <kyletso@google.com>
To: linux@roeck-us.net, heikki.krogerus@linux.intel.com,
gregkh@linuxfoundation.org
Cc: badhri@google.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, Kyle Tso <kyletso@google.com>
Subject: [PATCH v3] usb: typec: tcpm: Export partner Source Capabilities
Date: Sun, 14 Feb 2021 19:17:30 +0800 [thread overview]
Message-ID: <20210214111730.1436506-1-kyletso@google.com> (raw)
Export a function for other drivers to get the partner Source
Capabilities.
Signed-off-by: Kyle Tso <kyletso@google.com>
---
Changes since v1:
- add a put function to free the memory
Changes since v2:
- bring back the function tcpm_copy_pdos
drivers/usb/typec/tcpm/tcpm.c | 47 +++++++++++++++++++++++++++++++++++
include/linux/usb/tcpm.h | 2 ++
2 files changed, 49 insertions(+)
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index be0b6469dd3d..1679c75e5a3d 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -5739,6 +5739,53 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,
return 0;
}
+static int tcpm_copy_pdos(u32 *dest_pdo, const u32 *src_pdo, unsigned int nr_pdo)
+{
+ unsigned int i;
+
+ if (nr_pdo > PDO_MAX_OBJECTS)
+ nr_pdo = PDO_MAX_OBJECTS;
+
+ for (i = 0; i < nr_pdo; i++)
+ dest_pdo[i] = src_pdo[i];
+
+ return nr_pdo;
+}
+
+/*
+ * Don't call this function in interrupt context. Caller needs to free the
+ * memory by calling tcpm_put_partner_src_caps.
+ */
+int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **src_pdo)
+{
+ unsigned int nr_pdo;
+
+ mutex_lock(&port->lock);
+ if (port->nr_source_caps == 0) {
+ mutex_unlock(&port->lock);
+ return -ENODATA;
+ }
+
+ *src_pdo = kcalloc(port->nr_source_caps, sizeof(u32), GFP_KERNEL);
+ if (!src_pdo) {
+ mutex_unlock(&port->lock);
+ return -ENOMEM;
+ }
+
+ nr_pdo = tcpm_copy_pdos(*src_pdo, port->source_caps,
+ port->nr_source_caps);
+ mutex_unlock(&port->lock);
+ return nr_pdo;
+}
+EXPORT_SYMBOL_GPL(tcpm_get_partner_src_caps);
+
+void tcpm_put_partner_src_caps(u32 **src_pdo)
+{
+ kfree(*src_pdo);
+ *src_pdo = NULL;
+}
+EXPORT_SYMBOL_GPL(tcpm_put_partner_src_caps);
+
/* Power Supply access to expose source power information */
enum tcpm_psy_online_states {
TCPM_PSY_OFFLINE = 0,
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index 42fcfbe10590..f83d9ff89a13 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -161,5 +161,7 @@ void tcpm_pd_transmit_complete(struct tcpm_port *port,
enum tcpm_transmit_status status);
void tcpm_pd_hard_reset(struct tcpm_port *port);
void tcpm_tcpc_reset(struct tcpm_port *port);
+int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **pdo);
+void tcpm_put_partner_src_caps(u32 **pdo);
#endif /* __LINUX_USB_TCPM_H */
--
2.30.0.478.g8a0d178c01-goog
next reply other threads:[~2021-02-14 11:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-14 11:17 Kyle Tso [this message]
2021-02-15 13:37 ` [PATCH v3] usb: typec: tcpm: Export partner Source Capabilities Dan Carpenter
2021-03-02 7:12 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210214111730.1436506-1-kyletso@google.com \
--to=kyletso@google.com \
--cc=badhri@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).