Linux USB
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: "Pilla, Siva sai kumar" <siva.sai.kumar.pilla@intel.com>
Cc: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
	Jameson Thies <jthies@google.com>,
	Benson Leung <bleung@chromium.org>,
	Bartosz Szpila <bszpila@google.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [RFC PATCH 3/3] usb: typec: ucsi: Helpers for new GET_CONNECTOR_STATUS fields
Date: Thu, 29 Aug 2024 09:43:31 +0300	[thread overview]
Message-ID: <ZtAYk27n/zt9EH+1@kuha.fi.intel.com> (raw)
In-Reply-To: <SJ0PR11MB5770FF121048EC303BCE37BA8F952@SJ0PR11MB5770.namprd11.prod.outlook.com>

On Wed, Aug 28, 2024 at 11:54:32PM +0000, Pilla, Siva sai kumar wrote:
> > 
> > UCSI v2 introduced new fields to GET_CONNECTOR_STATUS.
> > Adding a helper for each field. The helpers check that the
> > UCSI version is v2 or above.
> 
> I believe this approach helps us from ensuring new fields are only used in supported versions.
> 
> > 
> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > ---
> >  drivers/usb/typec/ucsi/ucsi.h | 66 +++++++++++++++++++++++++++++++++++
> >  1 file changed, 66 insertions(+)
> > 
> > diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> > index dfbc0f6c1b9b..adcbfc96dfcf 100644
> > --- a/drivers/usb/typec/ucsi/ucsi.h
> > +++ b/drivers/usb/typec/ucsi/ucsi.h
> > @@ -524,4 +524,70 @@ static inline void ucsi_debugfs_unregister(struct ucsi *ucsi) { }
> >  #define USB_TYPEC_NVIDIA_VLINK_DP_VDO	0x1
> >  #define USB_TYPEC_NVIDIA_VLINK_DBG_VDO	0x3
> > 
> > +/* -------------------------------------------------------------------------- */
> > +
> > +static inline enum typec_orientation ucsi_orientation(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return TYPEC_ORIENTATION_NONE;
> > +	return UCSI_FIELD(con->status, 86, 1) ? TYPEC_ORIENTATION_REVERSE :
> > +						TYPEC_ORIENTATION_NORMAL;
> > +}
> > +
> > +static inline int ucsi_sink_path_status(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return -EINVAL;
> > +	return UCSI_FIELD(con->status, 87, 1);
> > +}
> > +
> > +static inline int ucsi_reverse_current_protection_status(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return -EINVAL;
> > +	return UCSI_FIELD(con->status, 88, 1);
> > +}
> > +
> 
> I think the below fields are supported from UCSI v2.1 onwards. Can you please perform version check accordingly.

Good catch!

thanks,

> > +static inline int ucsi_power_reading_ready(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return -EINVAL;
> > +	return UCSI_FIELD(con->status, 89, 1);
> > +}
> > +
> > +static inline int ucsi_current_scale(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return -EINVAL;
> > +	return UCSI_FIELD(con->status, 90, 3) * 5; /* mA */
> > +}
> > +
> > +static inline int ucsi_peak_current(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return -EINVAL;
> > +	return UCSI_FIELD(con->status, 93, 16);
> > +}
> > +
> > +static inline int ucsi_average_current(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return -EINVAL;
> > +	return UCSI_FIELD(con->status, 109, 16);
> > +}
> > +
> > +static inline int ucsi_voltage_scale(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return -EINVAL;
> > +	return UCSI_FIELD(con->status, 125, 4) * 5; /* mV */
> > +}
> > +
> > +static inline int ucsi_voltage_reading(struct ucsi_connector *con)
> > +{
> > +	if (WARN_ON(con->ucsi->version < UCSI_VERSION_2_0))
> > +		return -EINVAL;
> > +	return UCSI_FIELD(con->status, 129, 16);
> > +}
> > +
> >  #endif /* __DRIVER_USB_TYPEC_UCSI_H */

-- 
heikki

  reply	other threads:[~2024-08-29  6:43 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 ` [RFC PATCH 1/3] usb: typec: ucsi: Helper for Get Connector Status command Heikki Krogerus
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 [this message]
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=ZtAYk27n/zt9EH+1@kuha.fi.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