public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Badhri Jagan Sridharan <badhri@google.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	pumahsu@google.com
Subject: Re: [PATCH v4] usb: typec: Add sysfs node to show cc orientation
Date: Wed, 26 Feb 2020 12:35:37 -0800	[thread overview]
Message-ID: <20200226203537.GA26758@roeck-us.net> (raw)
In-Reply-To: <20200226195758.150477-1-badhri@google.com>

On Wed, Feb 26, 2020 at 11:57:58AM -0800, Badhri Jagan Sridharan wrote:
> Export Type-C orientation information when available.
> - "normal": CC1 orientation
> - "reverse": CC2 orientation
> - "unknown": Orientation cannot be determined.
> 
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
> Version history:
> V4:
> - Greg's suggestion of Minor refractor to handle
>   TYPEC_ORIENTATION_NONE and default in the same case.
> V3:
> - Heikki's suggestion to us .is_visible callback.
>   unsigned int orientation_aware:1 has been introduced to
>   make support of this attribute optional for drivers such
>   as UCSI
> - Guenter's suggestion to rename to "orientation".
> - Heikki's suggestion to stick with string values instead
>   of exposing it as integer values.
> ---
>  Documentation/ABI/testing/sysfs-class-typec |  9 +++++++
>  drivers/usb/typec/class.c                   | 26 +++++++++++++++++++++
>  drivers/usb/typec/tcpm/tcpm.c               |  1 +
>  include/linux/usb/typec.h                   |  1 +
>  4 files changed, 37 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
> index 0c2eb26fdc06b..b834671522d6f 100644
> --- a/Documentation/ABI/testing/sysfs-class-typec
> +++ b/Documentation/ABI/testing/sysfs-class-typec
> @@ -108,6 +108,15 @@ Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
>  Description:
>  		Revision number of the supported USB Type-C specification.
>  
> +What:		/sys/class/typec/<port>/orientation
> +Date:		February 2020
> +Contact:	Badhri Jagan Sridharan <badhri@google.com>
> +Description:
> +		Indicates the active orientation of the Type-C connector.
> +		Valid values:
> +		- "normal": CC1 orientation
> +		- "reverse": CC2 orientation
> +		- "unknown": Orientation cannot be determined.
>  
>  USB Type-C partner devices (eg. /sys/class/typec/port0-partner/)
>  
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 12be5bb6d32ca..bf97c31d0bba1 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1244,6 +1244,25 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev,
>  }
>  static DEVICE_ATTR_RO(usb_power_delivery_revision);
>  
> +static ssize_t orientation_show(struct device *dev,
> +				   struct device_attribute *attr,
> +				   char *buf)
> +{
> +	struct typec_port *p = to_typec_port(dev);
> +	enum typec_orientation orientation = typec_get_orientation(p);
> +
> +	switch (orientation) {
> +	case TYPEC_ORIENTATION_NORMAL:
> +		return sprintf(buf, "%s\n", "normal");
> +	case TYPEC_ORIENTATION_REVERSE:
> +		return sprintf(buf, "%s\n", "reverse");
> +	case TYPEC_ORIENTATION_NONE:
> +	default:
> +		return sprintf(buf, "%s\n", "unknown");
> +	}
> +}
> +static DEVICE_ATTR_RO(orientation);
> +
>  static struct attribute *typec_attrs[] = {
>  	&dev_attr_data_role.attr,
>  	&dev_attr_power_operation_mode.attr,
> @@ -1254,6 +1273,7 @@ static struct attribute *typec_attrs[] = {
>  	&dev_attr_usb_typec_revision.attr,
>  	&dev_attr_vconn_source.attr,
>  	&dev_attr_port_type.attr,
> +	&dev_attr_orientation.attr,
>  	NULL,
>  };
>  
> @@ -1283,6 +1303,10 @@ static umode_t typec_attr_is_visible(struct kobject *kobj,
>  			return 0;
>  		if (port->cap->type != TYPEC_PORT_DRP)
>  			return 0444;
> +	} else if (attr == &dev_attr_orientation.attr) {
> +		if (port->cap->orientation_aware)
> +			return 0444;
> +		return 0;
>  	}
>  
>  	return attr->mode;
> @@ -1493,6 +1517,8 @@ int typec_set_orientation(struct typec_port *port,
>  	}
>  
>  	port->orientation = orientation;
> +	sysfs_notify(&port->dev.kobj, NULL, "orientation");
> +	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
>  
>  	return 0;
>  }
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 78077c234ef27..bc0032a6b9a14 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4742,6 +4742,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
>  	port->typec_caps.pd_revision = 0x0300;	/* USB-PD spec release 3.0 */
>  	port->typec_caps.driver_data = port;
>  	port->typec_caps.ops = &tcpm_ops;
> +	port->typec_caps.orientation_aware = 1;
>  
>  	port->partner_desc.identity = &port->partner_ident;
>  	port->port_type = port->typec_caps.type;
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index 44d28387ced48..b00a2642a9cd6 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -211,6 +211,7 @@ struct typec_capability {
>  	u16			pd_revision; /* 0300H = "3.0" */
>  	int			prefer_role;
>  	enum typec_accessory	accessory[TYPEC_MAX_ACCESSORY];
> +	unsigned int		orientation_aware:1;
>  
>  	struct fwnode_handle	*fwnode;
>  	void			*driver_data;
> -- 
> 2.25.0.265.gbab2e86ba0-goog
> 

  reply	other threads:[~2020-02-26 20:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 19:57 [PATCH v4] usb: typec: Add sysfs node to show cc orientation Badhri Jagan Sridharan
2020-02-26 20:35 ` Guenter Roeck [this message]
2020-02-27  8:11 ` 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=20200226203537.GA26758@roeck-us.net \
    --to=linux@roeck-us.net \
    --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=pumahsu@google.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