From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Cc: Jameson Thies <jthies@google.com>,
Benson Leung <bleung@chromium.org>,
Bartosz Szpila <bszpila@google.com>,
"Pilla, Siva sai kumar" <siva.sai.kumar.pilla@intel.com>,
linux-usb@vger.kernel.org
Subject: [RFC PATCH 1/3] usb: typec: ucsi: Helper for Get Connector Status command
Date: Wed, 28 Aug 2024 19:14:59 +0300 [thread overview]
Message-ID: <20240828161502.2774996-2-heikki.krogerus@linux.intel.com> (raw)
In-Reply-To: <20240828161502.2774996-1-heikki.krogerus@linux.intel.com>
That command is executed from several locations in the
driver, so providing a dedicated helper function for it.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/usb/typec/ucsi/ucsi.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index f0b5867048e2..2e6773715efe 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -646,6 +646,16 @@ static void ucsi_unregister_altmodes(struct ucsi_connector *con, u8 recipient)
}
}
+static int ucsi_get_connector_status(struct ucsi_connector *con, bool conn_ack)
+{
+ u64 command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
+ struct ucsi *ucsi = con->ucsi;
+ int ret;
+
+ ret = ucsi_send_command_common(ucsi, command, &con->status, sizeof(con->status), conn_ack);
+ return ret < 0 ? ret : 0;
+}
+
static int ucsi_read_pdos(struct ucsi_connector *con,
enum typec_role role, int is_partner,
u32 *pdos, int offset, int num_pdos)
@@ -1113,12 +1123,10 @@ static int ucsi_check_connector_capability(struct ucsi_connector *con)
static int ucsi_check_connection(struct ucsi_connector *con)
{
u8 prev_flags = con->status.flags;
- u64 command;
int ret;
- command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
- ret = ucsi_send_command(con->ucsi, command, &con->status, sizeof(con->status));
- if (ret < 0) {
+ ret = ucsi_get_connector_status(con, false);
+ if (ret) {
dev_err(con->ucsi->dev, "GET_CONNECTOR_STATUS failed (%d)\n", ret);
return ret;
}
@@ -1192,16 +1200,12 @@ static void ucsi_handle_connector_change(struct work_struct *work)
work);
struct ucsi *ucsi = con->ucsi;
enum typec_role role;
- u64 command;
int ret;
mutex_lock(&con->lock);
- command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
-
- ret = ucsi_send_command_common(ucsi, command, &con->status,
- sizeof(con->status), true);
- if (ret < 0) {
+ ret = ucsi_get_connector_status(con, true);
+ if (ret) {
dev_err(ucsi->dev, "%s: GET_CONNECTOR_STATUS failed (%d)\n",
__func__, ret);
clear_bit(EVENT_PENDING, &con->ucsi->flags);
@@ -1610,14 +1614,11 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
}
/* Get the status */
- command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
- ret = ucsi_send_command(ucsi, command, &con->status, sizeof(con->status));
- if (ret < 0) {
+ ret = ucsi_get_connector_status(con, false);
+ if (ret) {
dev_err(ucsi->dev, "con%d: failed to get status\n", con->num);
- ret = 0;
goto out;
}
- ret = 0; /* ucsi_send_command() returns length on success */
if (ucsi->ops->connector_status)
ucsi->ops->connector_status(con);
--
2.45.2
next prev parent reply other threads:[~2024-08-28 16:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-28 16:14 [RFC PATCH 0/3] usb: typec: ucsi: New way to handle GET_CONNECTOR_STATUS Heikki Krogerus
2024-08-28 16:14 ` Heikki Krogerus [this message]
2024-08-28 16:15 ` [RFC PATCH 2/3] usb: typec: ucsi: Remove struct ucsi_connector_status Heikki Krogerus
2024-08-29 21:37 ` Abhishek Pandit-Subedi
2024-08-28 16:15 ` [RFC PATCH 3/3] usb: typec: ucsi: Helpers for new GET_CONNECTOR_STATUS fields Heikki Krogerus
2024-08-28 23:54 ` Pilla, Siva sai kumar
2024-08-29 6:43 ` Heikki Krogerus
2024-08-29 21:49 ` Abhishek Pandit-Subedi
2024-08-30 8:37 ` Heikki Krogerus
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=20240828161502.2774996-2-heikki.krogerus@linux.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=abhishekpandit@chromium.org \
--cc=bleung@chromium.org \
--cc=bszpila@google.com \
--cc=jthies@google.com \
--cc=linux-usb@vger.kernel.org \
--cc=siva.sai.kumar.pilla@intel.com \
/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