linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Prashant Malani <pmalani@chromium.org>
To: Jameson Thies <jthies@google.com>
Cc: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org,
	bleung@google.com, abhishekpandit@chromium.org,
	andersson@kernel.org, dmitry.baryshkov@linaro.org,
	fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org,
	hdegoede@redhat.com, neil.armstrong@linaro.org,
	rajaram.regupathy@intel.com, saranya.gopal@intel.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 3/4] usb: typec: ucsi: Register SOP/SOP' Discover Identity Responses
Date: Tue, 5 Mar 2024 18:54:39 +0000	[thread overview]
Message-ID: <Zedqb6_fe0GoUR9U@chromium.org> (raw)
In-Reply-To: <20240305025804.1290919-4-jthies@google.com>

On Mar 05 02:58, Jameson Thies wrote:
> Register SOP and SOP' Discover Identity responses with the USB Type-C
> Connector Class as partner and cable identities, respectively. Discover
> Identity responses are requested from the PPM using the GET_PD_MESSAGE
> UCSI command.
> 
> Signed-off-by: Jameson Thies <jthies@google.com>

Mostly line splitting nits (which I have listed below). Once those are
addressed, please feel free to add:
Reviewed-by: Prashant Malani <pmalani@chromium.org>

> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 7c84687b5d1a3..3b64a0f51041c 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -646,6 +646,108 @@ static int ucsi_get_src_pdos(struct ucsi_connector *con)
>  	return ret;
>  }
>  
> +static int ucsi_read_identity(struct ucsi_connector *con, u8 recipient,
> +			      u8 offset, u8 bytes, void *resp)
> +{
> +	struct ucsi *ucsi = con->ucsi;
> +	u64 command;
> +	int ret;
> +
> +	command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) |
> +	    UCSI_CONNECTOR_NUMBER(con->num);
> +	command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient);
> +	command |= UCSI_GET_PD_MESSAGE_OFFSET(offset);
> +	command |= UCSI_GET_PD_MESSAGE_BYTES(bytes);
> +	command |= UCSI_GET_PD_MESSAGE_TYPE(UCSI_GET_PD_MESSAGE_TYPE_IDENTITY);
> +
> +	ret = ucsi_send_command(ucsi, command, resp, bytes);
> +	if (ret < 0)
> +		dev_err(ucsi->dev, "UCSI_GET_PD_MESSAGE failed (%d)\n", ret);
> +
> +	return ret;
> +}
> +
> +static int ucsi_get_identity(struct ucsi_connector *con, u8 recipient,
> +			      struct usb_pd_identity *id)

nit: Line limits are 100 now [1], so this can fit on one line.

> +{
> +	struct ucsi *ucsi = con->ucsi;
> +	struct ucsi_pd_message_disc_id resp = {};
> +	int ret;
> +
> +	if (ucsi->version < UCSI_VERSION_2_0) {
> +		/*
> +		 * Before UCSI v2.0, MESSAGE_IN is 16 bytes which cannot fit
> +		 * the 28 byte identity response including the VDM header.
> +		 * First request the VDM header, ID Header VDO, Cert Stat VDO
> +		 * and Product VDO.
> +		 */
> +		ret = ucsi_read_identity(con, recipient, 0, 0x10, &resp);
> +		if (ret < 0)
> +			return ret;
> +
> +
> +		/* Then request Product Type VDO1 through Product Type VDO3. */
> +		ret = ucsi_read_identity(con, recipient, 0x10, 0xc,
> +					 &resp.vdo[0]);

nit: Can fit on one line.

> +		if (ret < 0)
> +			return ret;
> +
> +	} else {
> +		/*
> +		 * In UCSI v2.0 and after, MESSAGE_IN is large enough to request
> +		 * the large enough to request the full Discover Identity
> +		 * response at once.
> +		 */
> +		ret = ucsi_read_identity(con, recipient, 0x0, 0x1c, &resp);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
> +	id->id_header = resp.id_header;
> +	id->cert_stat = resp.cert_stat;
> +	id->product = resp.product;
> +	id->vdo[0] = resp.vdo[0];
> +	id->vdo[1] = resp.vdo[1];
> +	id->vdo[2] = resp.vdo[2];
> +	return 0;
> +}
> +
> +static int ucsi_get_partner_identity(struct ucsi_connector *con)
> +{
> +	int ret;
> +
> +	ret = ucsi_get_identity(con, UCSI_RECIPIENT_SOP,
> +				 &con->partner_identity);

nit: One line please.

> +	if (ret < 0)
> +		return ret;
> +
> +	ret = typec_partner_set_identity(con->partner);
> +	if (ret < 0) {
> +		dev_err(con->ucsi->dev, "Failed to set partner identity (%d)\n",
> +			ret);

nit: One line (100 is the limit now).

> +	}
> +
> +	return ret;
> +}
> +
> +static int ucsi_get_cable_identity(struct ucsi_connector *con)
> +{
> +	int ret;
> +
> +	ret = ucsi_get_identity(con, UCSI_RECIPIENT_SOP_P,
> +				 &con->cable_identity);

nit: One line.

> +	if (ret < 0)
> +		return ret;
> +
> +	ret = typec_cable_set_identity(con->cable);
> +	if (ret < 0) {
> +		dev_err(con->ucsi->dev, "Failed to set cable identity (%d)\n",
> +			ret);

nit: One line.

Best regards,

-Prashant

[1] https://github.com/torvalds/linux/blob/master/scripts/checkpatch.pl#L59

  parent reply	other threads:[~2024-03-05 18:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05  2:58 [PATCH v4 0/4] usb: typec: ucsi: Expand SOP/SOP' Discovery Jameson Thies
2024-03-05  2:58 ` [PATCH v4 1/4] usb: typec: ucsi: Clean up UCSI_CABLE_PROP macros Jameson Thies
2024-03-27 11:14   ` Heikki Krogerus
2024-03-05  2:58 ` [PATCH v4 2/4] usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY Jameson Thies
2024-03-11 17:28   ` neil.armstrong
2024-03-11 23:47     ` Jameson Thies
2024-03-26 22:09     ` Bjorn Andersson
2024-03-26 23:19       ` Jameson Thies
2024-03-05  2:58 ` [PATCH v4 3/4] usb: typec: ucsi: Register SOP/SOP' Discover Identity Responses Jameson Thies
2024-03-05  3:06   ` Benson Leung
2024-03-05 18:54   ` Prashant Malani [this message]
2024-03-27 11:18     ` Heikki Krogerus
2024-03-05  2:58 ` [PATCH v4 4/4] usb: typec: ucsi: Register SOP' alternate modes with cable plug Jameson Thies

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=Zedqb6_fe0GoUR9U@chromium.org \
    --to=pmalani@chromium.org \
    --cc=abhishekpandit@chromium.org \
    --cc=andersson@kernel.org \
    --cc=bleung@google.com \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=jthies@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=rajaram.regupathy@intel.com \
    --cc=saranya.gopal@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;
as well as URLs for NNTP newsgroup(s).