Merge tag 'tty-5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[linux-2.6-microblaze.git] / Documentation / driver-api / usb / typec_bus.rst
1
2 API for USB Type-C Alternate Mode drivers
3 =========================================
4
5 Introduction
6 ------------
7
8 Alternate modes require communication with the partner using Vendor Defined
9 Messages (VDM) as defined in USB Type-C and USB Power Delivery Specifications.
10 The communication is SVID (Standard or Vendor ID) specific, i.e. specific for
11 every alternate mode, so every alternate mode will need a custom driver.
12
13 USB Type-C bus allows binding a driver to the discovered partner alternate
14 modes by using the SVID and the mode number.
15
16 :ref:`USB Type-C Connector Class <typec>` provides a device for every alternate
17 mode a port supports, and separate device for every alternate mode the partner
18 supports. The drivers for the alternate modes are bound to the partner alternate
19 mode devices, and the port alternate mode devices must be handled by the port
20 drivers.
21
22 When a new partner alternate mode device is registered, it is linked to the
23 alternate mode device of the port that the partner is attached to, that has
24 matching SVID and mode. Communication between the port driver and alternate mode
25 driver will happen using the same API.
26
27 The port alternate mode devices are used as a proxy between the partner and the
28 alternate mode drivers, so the port drivers are only expected to pass the SVID
29 specific commands from the alternate mode drivers to the partner, and from the
30 partners to the alternate mode drivers. No direct SVID specific communication is
31 needed from the port drivers, but the port drivers need to provide the operation
32 callbacks for the port alternate mode devices, just like the alternate mode
33 drivers need to provide them for the partner alternate mode devices.
34
35 Usage:
36 ------
37
38 General
39 ~~~~~~~
40
41 By default, the alternate mode drivers are responsible for entering the mode.
42 It is also possible to leave the decision about entering the mode to the user
43 space (See Documentation/ABI/testing/sysfs-class-typec). Port drivers should not
44 enter any modes on their own.
45
46 ``->vdm`` is the most important callback in the operation callbacks vector. It
47 will be used to deliver all the SVID specific commands from the partner to the
48 alternate mode driver, and vice versa in case of port drivers. The drivers send
49 the SVID specific commands to each other using :c:func:`typec_altmode_vdm()`.
50
51 If the communication with the partner using the SVID specific commands results
52 in need to reconfigure the pins on the connector, the alternate mode driver
53 needs to notify the bus using :c:func:`typec_altmode_notify()`. The driver
54 passes the negotiated SVID specific pin configuration value to the function as
55 parameter. The bus driver will then configure the mux behind the connector using
56 that value as the state value for the mux.
57
58 NOTE: The SVID specific pin configuration values must always start from
59 ``TYPEC_STATE_MODAL``. USB Type-C specification defines two default states for
60 the connector: ``TYPEC_STATE_USB`` and ``TYPEC_STATE_SAFE``. These values are
61 reserved by the bus as the first possible values for the state. When the
62 alternate mode is entered, the bus will put the connector into
63 ``TYPEC_STATE_SAFE`` before sending Enter or Exit Mode command as defined in USB
64 Type-C Specification, and also put the connector back to ``TYPEC_STATE_USB``
65 after the mode has been exited.
66
67 An example of working definitions for SVID specific pin configurations would
68 look like this::
69
70     enum {
71         ALTMODEX_CONF_A = TYPEC_STATE_MODAL,
72         ALTMODEX_CONF_B,
73         ...
74     };
75
76 Helper macro ``TYPEC_MODAL_STATE()`` can also be used::
77
78 #define ALTMODEX_CONF_A = TYPEC_MODAL_STATE(0);
79 #define ALTMODEX_CONF_B = TYPEC_MODAL_STATE(1);
80
81 Cable plug alternate modes
82 ~~~~~~~~~~~~~~~~~~~~~~~~~~
83
84 The alternate mode drivers are not bound to cable plug alternate mode devices,
85 only to the partner alternate mode devices. If the alternate mode supports, or
86 requires, a cable that responds to SOP Prime, and optionally SOP Double Prime
87 messages, the driver for that alternate mode must request handle to the cable
88 plug alternate modes using :c:func:`typec_altmode_get_plug()`, and take over
89 their control.
90
91 Driver API
92 ----------
93
94 Alternate mode structs
95 ~~~~~~~~~~~~~~~~~~~~~~
96
97 .. kernel-doc:: include/linux/usb/typec_altmode.h
98    :functions: typec_altmode_driver typec_altmode_ops
99
100 Alternate mode driver registering/unregistering
101 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102
103 .. kernel-doc:: include/linux/usb/typec_altmode.h
104    :functions: typec_altmode_register_driver typec_altmode_unregister_driver
105
106 Alternate mode driver operations
107 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108
109 .. kernel-doc:: drivers/usb/typec/bus.c
110    :functions: typec_altmode_enter typec_altmode_exit typec_altmode_attention typec_altmode_vdm typec_altmode_notify
111
112 API for the port drivers
113 ~~~~~~~~~~~~~~~~~~~~~~~~
114
115 .. kernel-doc:: drivers/usb/typec/bus.c
116    :functions: typec_match_altmode
117
118 Cable Plug operations
119 ~~~~~~~~~~~~~~~~~~~~~
120
121 .. kernel-doc:: drivers/usb/typec/bus.c
122    :functions: typec_altmode_get_plug typec_altmode_put_plug