Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1b0bc2d authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Greg Kroah-Hartman
Browse files

usb: typec: Add support for UCSI interface



UCSI - USB Type-C Connector System Software Interface - is a
specification that defines set of registers and data
structures for controlling the USB Type-C ports. It's
designed for systems where an embedded controller (EC) is in
charge of the USB Type-C PHY or USB Power Delivery
controller. It is designed for systems with EC, but it is
not limited to them, and for example some USB Power Delivery
controllers will use it as their direct control interface.

With UCSI the EC (or USB PD controller) acts as the port
manager, implementing all USB Type-C and Power Delivery state
machines. The OS can use the interfaces for reading the
status of the ports and controlling basic operations like
role swapping.

The UCSI specification highlights the fact that it does not
define the interface method (PCI/I2C/ACPI/etc.).
Therefore the driver is implemented as library and every
supported interface method needs its own driver. Driver for
ACPI is provided in separate patch following this one.

The initial driver includes support for all required
features from UCSI specification version 1.0 (getting
connector capabilities and status, and support for power and
data role swapping), but none of the optional UCSI features
(alternate modes, power source capabilities, and cable
capabilities).

Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c68bb0ef
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -19,4 +19,6 @@ config TYPEC_WCOVE
	  To compile this driver as module, choose M here: the module will be
	  called typec_wcove

source "drivers/usb/typec/ucsi/Kconfig"

endmenu
+1 −0
Original line number Diff line number Diff line
obj-$(CONFIG_TYPEC)		+= typec.o
obj-$(CONFIG_TYPEC_WCOVE)	+= typec_wcove.o
obj-$(CONFIG_TYPEC_UCSI)	+= ucsi/
+23 −0
Original line number Diff line number Diff line
config TYPEC_UCSI
	tristate "USB Type-C Connector System Software Interface driver"
	depends on !CPU_BIG_ENDIAN
	select TYPEC
	help
	  USB Type-C Connector System Software Interface (UCSI) is a
	  specification for an interface that allows the operating system to
	  control the USB Type-C ports. On UCSI system the USB Type-C ports
	  function autonomously by default, but in order to get the status of
	  the ports and support basic operations like role swapping, the driver
	  is required. UCSI is available on most of the new Intel based systems
	  that are equipped with Embedded Controller and USB Type-C ports.

	  UCSI specification does not define the interface method, so depending
	  on the platform, ACPI, PCI, I2C, etc. may be used. Therefore this
	  driver only provides the core part, and separate drivers are needed
	  for every supported interface method.

	  The UCSI specification can be downloaded from:
	  http://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html

	  To compile the driver as a module, choose M here: the module will be
	  called typec_ucsi.
+7 −0
Original line number Diff line number Diff line
CFLAGS_trace.o			:= -I$(src)

obj-$(CONFIG_TYPEC_UCSI)	+= typec_ucsi.o

typec_ucsi-y			:= ucsi.o

typec_ucsi-$(CONFIG_FTRACE)	+= trace.o
+64 −0
Original line number Diff line number Diff line
#ifndef __UCSI_DEBUG_H
#define __UCSI_DEBUG_H

#include "ucsi.h"

static const char * const ucsi_cmd_strs[] = {
	[0]				= "Unknown command",
	[UCSI_PPM_RESET]		= "PPM_RESET",
	[UCSI_CANCEL]			= "CANCEL",
	[UCSI_CONNECTOR_RESET]		= "CONNECTOR_RESET",
	[UCSI_ACK_CC_CI]		= "ACK_CC_CI",
	[UCSI_SET_NOTIFICATION_ENABLE]	= "SET_NOTIFICATION_ENABLE",
	[UCSI_GET_CAPABILITY]		= "GET_CAPABILITY",
	[UCSI_GET_CONNECTOR_CAPABILITY]	= "GET_CONNECTOR_CAPABILITY",
	[UCSI_SET_UOM]			= "SET_UOM",
	[UCSI_SET_UOR]			= "SET_UOR",
	[UCSI_SET_PDM]			= "SET_PDM",
	[UCSI_SET_PDR]			= "SET_PDR",
	[UCSI_GET_ALTERNATE_MODES]	= "GET_ALTERNATE_MODES",
	[UCSI_GET_CAM_SUPPORTED]	= "GET_CAM_SUPPORTED",
	[UCSI_GET_CURRENT_CAM]		= "GET_CURRENT_CAM",
	[UCSI_SET_NEW_CAM]		= "SET_NEW_CAM",
	[UCSI_GET_PDOS]			= "GET_PDOS",
	[UCSI_GET_CABLE_PROPERTY]	= "GET_CABLE_PROPERTY",
	[UCSI_GET_CONNECTOR_STATUS]	= "GET_CONNECTOR_STATUS",
	[UCSI_GET_ERROR_STATUS]		= "GET_ERROR_STATUS",
};

static inline const char *ucsi_cmd_str(u64 raw_cmd)
{
	u8 cmd = raw_cmd & GENMASK(7, 0);

	return ucsi_cmd_strs[(cmd >= ARRAY_SIZE(ucsi_cmd_strs)) ? 0 : cmd];
}

static const char * const ucsi_ack_strs[] = {
	[0]				= "",
	[UCSI_ACK_EVENT]		= "event",
	[UCSI_ACK_CMD]			= "command",
};

static inline const char *ucsi_ack_str(u8 ack)
{
	return ucsi_ack_strs[(ack >= ARRAY_SIZE(ucsi_ack_strs)) ? 0 : ack];
}

static inline const char *ucsi_cci_str(u32 cci)
{
	if (cci & GENMASK(7, 0)) {
		if (cci & BIT(29))
			return "Event pending (ACK completed)";
		if (cci & BIT(31))
			return "Event pending (command completed)";
		return "Connector Change";
	}
	if (cci & BIT(29))
		return "ACK completed";
	if (cci & BIT(31))
		return "Command completed";

	return "";
}

#endif /* __UCSI_DEBUG_H */
Loading