USB Type-C, how is the direction of power delivery controlled?
Say I have a laptop and a powerbank (or two laptops) with USB type C connected together, then how is it decided which charges which?
Is it controlled by the driver? Does Linux kernel supports such control?
Update:
I see this patch set (currently v14) but it's not in mainline yet.
https://lwn.net/Articles/710741/
But something called UCSI is in 4.10 already:
http://lxr.free-electrons.com/source/drivers/usb/misc/Kconfig
270 config UCSI
271 tristate "USB Type-C Connector System Software Interface driver"
272 depends on ACPI
273 help
274 UCSI driver is meant to be used as a convenience tool for desktop and
275 server systems that are not equipped to handle USB in device mode. It
276 will always select USB host role for the USB Type-C ports on systems
277 that provide UCSI interface.
So is it correct to say that the Linux kernel driver for this problem is work in progress as of 4.10?
In Linux you can control the direction of power on a given port by writing "source" or "sink" to the appropriate sysfs control, eg.:
# echo source >/sys/class/typec/port0/power_role
# cat /sys/class/typec/port0/power_role
[source] sink
The term in bracket indicates how is power currently flowing. See the kernel documentation see: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-typec
Of course all of this works only if the device connected to the USB Type-C port supports Power Delivery. So it won't work with a typical Type-C power adapter or most Type-C portable batteries as they rarely support PD as of 2019.
USB type C connected together, then how is it decided which charges which?
This is all convoluted beyond comprehension so far. Type-C connector carries two roles
- data communication
- power delivery.
These are nearly independent functions. The entire functionality depends on whether
- both ports are USB hosts
- both ports are USB devices
- one port is Dual-role-Data and another is not
- one port is Dual-role-power
...
n. both ports are DRD and DRP,
I lost all permutations here. The UCSI is an attempt by Microsoft to tame this vast permutivity into API standard. For major ideas, see this presentation, and many more publications on "UCSI interface".