linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv8 0/2] USB Type-C Connector class
@ 2016-09-01 11:49 Heikki Krogerus
  2016-09-01 11:49 ` [PATCHv8 1/2] usb: USB Type-C connector class Heikki Krogerus
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Heikki Krogerus @ 2016-09-01 11:49 UTC (permalink / raw)
  To: Greg KH, Guenter Roeck
  Cc: Oliver Neukum, Felipe Balbi, Bin Gao, Vincent Palatin,
	linux-kernel, linux-usb

The USB Type-C class is meant to provide unified interface to the
userspace to present the USB Type-C ports in a system.


Changes since v7:
- Removed "type" attribute from partners
- Added supports_usb_power_delivery attribute for partner and cable

Changes since v6:
- current_vconn_role attr renamed to vconn_source (no API changes)
- Small documentation improvements proposed by Vincent Palatin

Changes since v5:
- Only updating the roles based on driver notifications
- Added MODULE_ALIAS for the WhiskeyCove module
- Including the patch that creates the actual platform device for the
  WhiskeyCove Type-C PHY in this series.

Changes since v4:
- Remove the port lock completely

Changes since v3:
- Documentation cleanup as proposed by Roger Quadros
- Setting partner altmodes member to NULL on removal and fixing a
  warning, as proposed by Guenter Roeck
- Added the following attributes for partners and cables:
  * supports_usb_power_delivery
  * id_header_vdo
- "id_header_vdo" is visible only when the partner or cable supports
  USB Power Delivery communication.
- Partner attribute "accessory" is hidden when the partner type is not
  "Accessory".

Changes since v2:
- Notification on role and alternate mode changes
- cleanups

Changes since v1:
- Completely rewrote alternate mode support
- Patners, cables and cable plugs presented as devices.


Heikki Krogerus (2):
  usb: USB Type-C connector class
  usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY

 Documentation/ABI/testing/sysfs-class-typec |  219 ++++++
 Documentation/usb/typec.txt                 |  103 +++
 MAINTAINERS                                 |    9 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    2 +
 drivers/usb/typec/Kconfig                   |   21 +
 drivers/usb/typec/Makefile                  |    2 +
 drivers/usb/typec/typec.c                   | 1082 +++++++++++++++++++++++++++
 drivers/usb/typec/typec_wcove.c             |  368 +++++++++
 include/linux/usb/typec.h                   |  249 ++++++
 10 files changed, 2057 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-typec
 create mode 100644 Documentation/usb/typec.txt
 create mode 100644 drivers/usb/typec/Kconfig
 create mode 100644 drivers/usb/typec/Makefile
 create mode 100644 drivers/usb/typec/typec.c
 create mode 100644 drivers/usb/typec/typec_wcove.c
 create mode 100644 include/linux/usb/typec.h

-- 
2.9.3

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCHv8 1/2] usb: USB Type-C connector class
@ 2016-09-08 20:04 Guenter Roeck
  2016-09-09  7:36 ` Heikki Krogerus
  0 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2016-09-08 20:04 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Greg KH, Oliver Neukum, Felipe Balbi, Bin Gao, Vincent Palatin,
	linux-kernel, linux-usb

On Thu, Sep 01, 2016 at 02:49:47PM +0300, Heikki Krogerus wrote:
> The purpose of USB Type-C connector class is to provide
> unified interface for the user space to get the status and
> basic information about USB Type-C connectors on a system,
> control over data role swapping, and when the port supports
> USB Power Delivery, also control over power role swapping
> and Alternate Modes.
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
... 

> +
> +static int sysfs_strmatch(const char * const *array, size_t n, const char *str)
> +{
> +	const char *item;
> +	int index;
> +
> +	for (index = 0; index < n; index++) {
> +		item = array[index];
> +		if (!item)
> +			break;
> +		if (!sysfs_streq(item, str))

This doesn't work ... sysfs_streq() returns true if there is a match,
so the "!" is wrong.

> +			return index;
> +	}
> +
> +	return -EINVAL;
> +}
> +
[ ... ]
> +
> +static ssize_t
> +preferred_role_store(struct device *dev, struct device_attribute *attr,
> +		     const char *buf, size_t size)
> +{
> +	struct typec_port *port = to_typec_port(dev);
> +	enum typec_role role;
> +	int ret;
> +
> +	if (port->cap->type != TYPEC_PORT_DRP) {
> +		dev_dbg(dev, "Preferred role only supported with DRP ports\n");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	if (!port->cap->try_role) {
> +		dev_dbg(dev, "Setting preferred role not supported\n");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	ret = sysfs_strmatch(typec_roles, ARRAY_SIZE(typec_roles), buf);
> +	if (ret < 0) {
> +		port->prefer_role = -1;
> +		return size;

Are you sure about that ? It is kind of unusual to accept "bad" strings.
Why not return -EINVAL ?

> +	}
> +
> +	role = ret;
> +
> +	ret = port->cap->try_role(port->cap, role);
> +	if (ret)
> +		return ret;
> +
> +	port->prefer_role = role;
> +	return size;
> +}
> +
[ ... ]
> +
> +static ssize_t supported_accessory_modes_show(struct device *dev,
> +					      struct device_attribute *attr,
> +					      char *buf)
> +{
> +	struct typec_port *port = to_typec_port(dev);
> +	ssize_t ret = 0;
> +	int i;
> +
> +	if (!port->cap->accessory[0])

You probably want 
	if (!port->cap->accessory)
here. Otherwise the check is quite pointless (and crashes if the pointer
is NULL).

> +		return 0;
> +
> +	for (i = 0; port->cap->accessory[i]; i++)
> +		ret += sprintf(buf + ret, "%s\n",
> +			       typec_accessory_modes[port->cap->accessory[i]]);
> +	return ret;
> +}
> +static DEVICE_ATTR_RO(supported_accessory_modes);
> +

Guenter

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-09  7:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-01 11:49 [PATCHv8 0/2] USB Type-C Connector class Heikki Krogerus
2016-09-01 11:49 ` [PATCHv8 1/2] usb: USB Type-C connector class Heikki Krogerus
2016-09-01 11:49 ` [PATCHv8 2/2] usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY Heikki Krogerus
2016-09-01 12:13 ` [PATCHv8 0/2] USB Type-C Connector class Guenter Roeck
2016-09-01 12:48   ` Heikki Krogerus
2016-09-08 20:04 [PATCHv8 1/2] usb: USB Type-C connector class Guenter Roeck
2016-09-09  7:36 ` Heikki Krogerus

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).