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

usb: typec: Separate USB Power Delivery from USB Type-C



Introducing a small device class for USB Power Delivery.
The idea with it is that we do not mix any more USB Power
Delivery information into the USB Type-C connectors only.
This separation will make it possible to register USB Power
Delivery devices also from other places, for example from
USB Type-C Bridges (see USB Type-C Bridge Specification).

The device class will not always deal with only the messages
and objects that were negotiated with the partner, but
instead messages and objects that can be used in the
negotiation. That allows the USB PD devices to be shared and
reconfigured. The ports can decide which objects are to be
advertised to the partner before the contract is negotiated.
It is also possible to allow the user space to make that
decision if needed.

Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20220502132058.86236-2-heikki.krogerus@linux.intel.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f061f43d
Loading
Loading
Loading
Loading
+240 −0
Original line number Diff line number Diff line
What:		/sys/class/usb_power_delivery
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Directory for USB Power Delivery devices.

What:		/sys/class/usb_power_delivery/.../revision
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		File showing the USB Power Delivery Specification Revision used
		in communication.

What:		/sys/class/usb_power_delivery/.../version
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		This is an optional attribute file showing the version of the
		specific revision of the USB Power Delivery Specification. In
		most cases the specification version is not known and the file
		is not available.

What:		/sys/class/usb_power_delivery/.../source-capabilities
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		The source capabilities message "Source_Capabilities" contains a
		set of Power Data Objects (PDO), each representing a type of
		power supply. The order of the PDO objects is defined in the USB
		Power Delivery Specification. Each PDO - power supply - will
		have its own device, and the PDO device name will start with the
		object position number as the first character followed by the
		power supply type name (":" as delimiter).

			/sys/class/usb_power_delivery/.../source_capabilities/<position>:<type>

What:		/sys/class/usb_power_delivery/.../sink-capabilities
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		The sink capability message "Sink_Capabilities" contains a set
		of Power Data Objects (PDO) just like with source capabilities,
		but instead of describing the power capabilities, these objects
		describe the power requirements.

		The order of the objects in the sink capability message is the
		same as with the source capabilities message.

Fixed Supplies

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:fixed_supply
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Devices containing the attributes (the bit fields) defined for
		Fixed Supplies.

		The device "1:fixed_supply" is special. USB Power Delivery
		Specification dictates that the first PDO (at object position
		1), and the only mandatory PDO, is always the vSafe5V Fixed
		Supply Object. vSafe5V Object has additional fields defined for
		it that the other Fixed Supply Objects do not have and that are
		related to the USB capabilities rather than power capabilities.

What:		/sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/dual_role_power
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		This file contains boolean value that tells does the device
		support both source and sink power roles.

What:		/sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/usb_suspend_supported
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		This file shows the value of the USB Suspend Supported bit in
		vSafe5V Fixed Supply Object. If the bit is set then the device
		will follow the USB 2.0 and USB 3.2 rules for suspend and
		resume.

What:		/sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/unconstrained_power
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		This file shows the value of the Unconstrained Power bit in
		vSafe5V Fixed Supply Object. The bit is set when an external
		source of power, powerful enough to power the entire system on
		its own, is available for the device.

What:		/sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/usb_communication_capable
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		This file shows the value of the USB Communication Capable bit in
		vSafe5V Fixed Supply Object.

What:		/sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/dual_role_data
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		This file shows the value of the Dual-Role Data bit in vSafe5V
		Fixed Supply Object. Dual role data means ability act as both
		USB host and USB device.

What:		/sys/class/usb_power_delivery/.../<capability>/1:fixed_supply/unchunked_extended_messages_supported
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		This file shows the value of the Unchunked Extended Messages
		Supported bit in vSafe5V Fixed Supply Object.

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:fixed_supply/voltage
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		The voltage the supply supports in millivolts.

What:		/sys/class/usb_power_delivery/.../source-capabilities/<position>:fixed_supply/maximum_current
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Maximum current of the fixed source supply in milliamperes.

What:		/sys/class/usb_power_delivery/.../sink-capabilities/<position>:fixed_supply/operational_current
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Operational current of the sink in milliamperes.

What:		/sys/class/usb_power_delivery/.../sink-capabilities/<position>:fixed_supply/fast_role_swap_current
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		This file contains the value of the "Fast Role Swap USB Type-C
		Current" field that tells the current level the sink requires
		after a Fast Role Swap.
		0 - Fast Swap not supported"
		1 - Default USB Power"
		2 - 1.5A@5V"
		3 - 3.0A@5V"

Variable Supplies

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:variable_supply
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Variable Power Supply PDO.

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:variable_supply/maximum_voltage
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Maximum Voltage in millivolts.

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:variable_supply/minimum_voltage
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Minimum Voltage in millivolts.

What:		/sys/class/usb_power_delivery/.../source-capabilities/<position>:variable_supply/maximum_current
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		The maximum current in milliamperes that the source can supply
		at the given Voltage range.

What:		/sys/class/usb_power_delivery/.../sink-capabilities/<position>:variable_supply/operational_current
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		The operational current in milliamperes that the sink requires
		at the given Voltage range.

Battery Supplies

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:battery
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Battery PDO.

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:battery/maximum_voltage
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Maximum Voltage in millivolts.

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:battery/minimum_voltage
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Minimum Voltage in millivolts.

What:		/sys/class/usb_power_delivery/.../source-capabilities/<position>:battery/maximum_power
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Maximum allowable Power in milliwatts.

What:		/sys/class/usb_power_delivery/.../sink-capabilities/<position>:battery/operational_power
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		The operational power that the sink requires at the given
		voltage range.

Standard Power Range (SPR) Programmable Power Supplies

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:programmable_supply
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Programmable Power Supply (PPS) Augmented PDO (APDO).

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:programmable_supply/maximum_voltage
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Maximum Voltage in millivolts.

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:programmable_supply/minimum_voltage
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Minimum Voltage in millivolts.

What:		/sys/class/usb_power_delivery/.../<capability>/<position>:programmable_supply/maximum_current
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		Maximum Current in milliamperes.

What:		/sys/class/usb_power_delivery/.../source-capabilities/<position>:programmable_supply/pps_power_limited
Date:		May 2022
Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
		The PPS Power Limited bit indicates whether or not the source
		supply will exceed the rated output power if requested.
+1 −1
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_TYPEC)		+= typec.o
typec-y				:= class.o mux.o bus.o
typec-y				:= class.o mux.o bus.o pd.o
typec-$(CONFIG_ACPI)		+= port-mapper.o
obj-$(CONFIG_TYPEC)		+= altmodes/
obj-$(CONFIG_TYPEC_TCPM)	+= tcpm/

drivers/usb/typec/pd.c

0 → 100644
+708 −0

File added.

Preview size limit exceeded, changes collapsed.

drivers/usb/typec/pd.h

0 → 100644
+30 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __USB_POWER_DELIVERY__
#define __USB_POWER_DELIVERY__

#include <linux/device.h>
#include <linux/usb/typec.h>

struct usb_power_delivery {
	struct device dev;
	int id;
	u16 revision;
	u16 version;
};

struct usb_power_delivery_capabilities {
	struct device dev;
	struct usb_power_delivery *pd;
	enum typec_role role;
};

#define to_usb_power_delivery_capabilities(o) container_of(o, struct usb_power_delivery_capabilities, dev)
#define to_usb_power_delivery(o) container_of(o, struct usb_power_delivery, dev)

struct usb_power_delivery *usb_power_delivery_find(const char *name);

int usb_power_delivery_init(void);
void usb_power_delivery_exit(void);

#endif /* __USB_POWER_DELIVERY__ */
+38 −0
Original line number Diff line number Diff line
@@ -495,4 +495,42 @@ static inline unsigned int rdo_max_power(u32 rdo)

#define PD_P_SNK_STDBY_MW	2500	/* 2500 mW */

#if IS_ENABLED(CONFIG_TYPEC)

struct usb_power_delivery;

/**
 * usb_power_delivery_desc - USB Power Delivery Descriptor
 * @revision: USB Power Delivery Specification Revision
 * @version: USB Power Delivery Specicication Version - optional
 */
struct usb_power_delivery_desc {
	u16 revision;
	u16 version;
};

/**
 * usb_power_delivery_capabilities_desc - Description of USB Power Delivery Capabilities Message
 * @pdo: The Power Data Objects in the Capability Message
 * @role: Power role of the capabilities
 */
struct usb_power_delivery_capabilities_desc {
	u32 pdo[PDO_MAX_OBJECTS];
	enum typec_role role;
};

struct usb_power_delivery_capabilities *
usb_power_delivery_register_capabilities(struct usb_power_delivery *pd,
					 struct usb_power_delivery_capabilities_desc *desc);
void usb_power_delivery_unregister_capabilities(struct usb_power_delivery_capabilities *cap);

struct usb_power_delivery *usb_power_delivery_register(struct device *parent,
						       struct usb_power_delivery_desc *desc);
void usb_power_delivery_unregister(struct usb_power_delivery *pd);

int usb_power_delivery_link_device(struct usb_power_delivery *pd, struct device *dev);
void usb_power_delivery_unlink_device(struct usb_power_delivery *pd, struct device *dev);

#endif /* CONFIG_TYPEC */

#endif /* __LINUX_USB_PD_H */
Loading