Documentation/driver-api/usb/typec_bus.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

API for USB Type-C Alternate Mode drivers

USB Type-C Alternate Mode driver의 SVID 기반 binding, VDM 전달, connector mux 상태, cable plug와 port API를 설명하는 한국어 전문 번역입니다.

Source pathDocumentation/driver-api/usb/typec_bus.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

typec_bus.rst:1-122

Type-C bus는 SVID와 mode number로 partner Alternate Mode driver를 연결하고 port Alternate Mode device를 VDM proxy로 사용합니다. Mode 진입·종료, connector mux state, cable plug reference와 port matching은 전용 API와 명확한 ownership 규칙에 따라 처리합니다.

문서 구성
원문 줄핵심 내용
1-34Alternate Mode bus와 driver binding
35-65VDM·mux state와 mode 전이
66-89Modal pin configuration과 cable plug
90-110Alternate Mode driver API
111-122Port·cable plug API

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
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
123

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

USB Type-C Alternate Mode 버스와 장치 결합

1-34

Alternate Mode는 USB Type-C 및 USB Power Delivery specification에 정의된 Vendor Defined Message(VDM)를 사용해 partner와 통신해야 합니다. 이 통신은 SVID(Standard or Vendor ID)마다 다르므로 각 Alternate Mode에는 전용 driver가 필요합니다.

USB Type-C bus는 발견된 partner Alternate Mode의 SVID와 mode number를 기준으로 알맞은 driver를 bind합니다.

`USB Type-C Connector Class`는 port가 지원하는 Alternate Mode마다 device를 만들고, partner가 지원하는 Alternate Mode마다 별도 device를 만듭니다. Alternate Mode driver는 partner Alternate Mode device에 bind되며, port Alternate Mode device는 port driver가 처리해야 합니다.

새 partner Alternate Mode device가 등록되면 bus는 같은 SVID와 mode를 가진, partner가 연결된 port의 Alternate Mode device에 이를 연결합니다. Port driver와 Alternate Mode driver 사이의 통신에도 동일한 API를 사용합니다.

Port Alternate Mode device는 partner와 Alternate Mode driver 사이의 proxy입니다. 따라서 port driver는 SVID-specific command를 Alternate Mode driver에서 partner로, partner에서 Alternate Mode driver로 전달하면 됩니다. Port driver가 SVID-specific 통신을 직접 구현할 필요는 없지만, partner 쪽 driver와 마찬가지로 port Alternate Mode device의 operation callback은 제공해야 합니다.

Type-C Alternate Mode 결합 경로
Partner Alternate Mode 발견SVID + mode number 등록
Type-C bus matching동일 SVID·mode의 port Alternate Mode와 link
Alternate Mode driverPartner Alternate Mode device에 bind
Port Alternate Mode device양방향 SVID command proxy
Port driverVDM 전달용 operation callback 제공

SVID와 mode number가 partner device, port proxy, 전용 driver를 연결합니다.


API for USB Type-C Alternate Mode drivers
=========================================

Introduction
------------

Alternate modes require communication with the partner using Vendor Defined
Messages (VDM) as defined in USB Type-C and USB Power Delivery Specifications.
The communication is SVID (Standard or Vendor ID) specific, i.e. specific for
every alternate mode, so every alternate mode will need a custom driver.

USB Type-C bus allows binding a driver to the discovered partner alternate
modes by using the SVID and the mode number.

:ref:`USB Type-C Connector Class <typec>` provides a device for every alternate
mode a port supports, and separate device for every alternate mode the partner
supports. The drivers for the alternate modes are bound to the partner alternate
mode devices, and the port alternate mode devices must be handled by the port
drivers.

When a new partner alternate mode device is registered, it is linked to the
alternate mode device of the port that the partner is attached to, that has
matching SVID and mode. Communication between the port driver and alternate mode
driver will happen using the same API.

The port alternate mode devices are used as a proxy between the partner and the
alternate mode drivers, so the port drivers are only expected to pass the SVID
specific commands from the alternate mode drivers to the partner, and from the
partners to the alternate mode drivers. No direct SVID specific communication is
needed from the port drivers, but the port drivers need to provide the operation
callbacks for the port alternate mode devices, just like the alternate mode
drivers need to provide them for the partner alternate mode devices.

Mode 진입, VDM 전달과 connector 상태 전이

35-65

기본적으로 Alternate Mode에 진입할 책임은 Alternate Mode driver에 있습니다. 진입 결정을 userspace에 맡길 수도 있으며 자세한 interface는 `Documentation/ABI/testing/sysfs-class-typec`에 설명되어 있습니다. Port driver는 임의로 어떤 mode에도 진입해서는 안 됩니다.

Operation callback vector에서 가장 중요한 callback은 `->vdm`입니다. Partner가 보낸 모든 SVID-specific command를 Alternate Mode driver에 전달하며, port driver의 경우 반대 방향 command도 전달합니다. Driver들은 `typec_altmode_vdm()`으로 서로 SVID-specific command를 보냅니다.

SVID-specific command 교환 결과 connector pin을 재구성해야 한다면 Alternate Mode driver는 `typec_altmode_notify()`로 bus에 알려야 합니다. 이 함수에는 협상된 SVID-specific pin configuration 값을 parameter로 전달하고, bus driver는 그 값을 mux state로 사용해 connector 뒤의 mux를 설정합니다.

SVID-specific pin configuration 값은 반드시 `TYPEC_STATE_MODAL`부터 시작해야 합니다. USB Type-C specification이 정의한 기본 connector 상태 `TYPEC_STATE_USB`와 `TYPEC_STATE_SAFE`는 bus가 가능한 첫 state 값으로 예약합니다.

Alternate Mode에 진입할 때 bus는 specification에 따라 Enter Mode 또는 Exit Mode command를 보내기 전에 connector를 `TYPEC_STATE_SAFE`로 옮깁니다. Mode를 빠져나온 뒤에는 connector를 `TYPEC_STATE_USB`로 되돌립니다.

Connector mux 상태 전이
기본 USB 동작`TYPEC_STATE_USB`
Mode 진입·종료 준비`TYPEC_STATE_SAFE`
Enter Mode + pin 협상`typec_altmode_vdm()`
Mux 재구성 알림`typec_altmode_notify(state)`
Modal pin state`TYPEC_STATE_MODAL` 이상
Mode 종료 완료`TYPEC_STATE_USB` 복귀

Alternate Mode 협상과 종료 과정에서 bus가 안전한 pin state를 보장합니다.

Usage:
------

General
~~~~~~~

By default, the alternate mode drivers are responsible for entering the mode.
It is also possible to leave the decision about entering the mode to the user
space (See Documentation/ABI/testing/sysfs-class-typec). Port drivers should not
enter any modes on their own.

``->vdm`` is the most important callback in the operation callbacks vector. It
will be used to deliver all the SVID specific commands from the partner to the
alternate mode driver, and vice versa in case of port drivers. The drivers send
the SVID specific commands to each other using :c:func:`typec_altmode_vdm()`.

If the communication with the partner using the SVID specific commands results
in need to reconfigure the pins on the connector, the alternate mode driver
needs to notify the bus using :c:func:`typec_altmode_notify()`. The driver
passes the negotiated SVID specific pin configuration value to the function as
parameter. The bus driver will then configure the mux behind the connector using
that value as the state value for the mux.

NOTE: The SVID specific pin configuration values must always start from
``TYPEC_STATE_MODAL``. USB Type-C specification defines two default states for
the connector: ``TYPEC_STATE_USB`` and ``TYPEC_STATE_SAFE``. These values are
reserved by the bus as the first possible values for the state. When the
alternate mode is entered, the bus will put the connector into
``TYPEC_STATE_SAFE`` before sending Enter or Exit Mode command as defined in USB
Type-C Specification, and also put the connector back to ``TYPEC_STATE_USB``
after the mode has been exited.

Modal pin 정의와 cable plug Alternate Mode

66-89

SVID-specific pin configuration은 첫 enum 값을 `TYPEC_STATE_MODAL`로 지정하고 이후 값을 연속해서 배치할 수 있습니다. 이렇게 하면 `ALTMODEX_CONF_A`, `ALTMODEX_CONF_B` 같은 mode별 state가 bus의 기본 USB·SAFE state와 충돌하지 않습니다.

같은 정의를 helper macro `TYPEC_MODAL_STATE()`로 작성할 수도 있습니다. Index `0`은 첫 modal state, index `1`은 다음 modal state를 뜻합니다. 원문의 enum과 macro 정의는 아래 영어 원문 block에 그대로 보존되어 있습니다.

Alternate Mode driver는 cable plug Alternate Mode device에 직접 bind되지 않고 partner Alternate Mode device에만 bind됩니다.

Alternate Mode가 SOP Prime message에 응답하는 cable을 지원하거나 요구하고, 선택적으로 SOP Double Prime message까지 사용한다면 해당 driver가 `typec_altmode_get_plug()`으로 cable plug Alternate Mode handle을 요청해 제어권을 넘겨받아야 합니다.

Modal state와 cable plug 제어
대상규칙·API
첫 SVID pin configuration`TYPEC_STATE_MODAL`
후속 configurationEnum 증가 또는 `TYPEC_MODAL_STATE(index)`
Driver bind 대상Partner Alternate Mode device
Cable 응답 대상SOP Prime, 선택적으로 SOP Double Prime
Cable plug handle`typec_altmode_get_plug()`으로 요청 후 제어


An example of working definitions for SVID specific pin configurations would
look like this::

    enum {
        ALTMODEX_CONF_A = TYPEC_STATE_MODAL,
        ALTMODEX_CONF_B,
        ...
    };

Helper macro ``TYPEC_MODAL_STATE()`` can also be used::

#define ALTMODEX_CONF_A = TYPEC_MODAL_STATE(0);
#define ALTMODEX_CONF_B = TYPEC_MODAL_STATE(1);

Cable plug alternate modes
~~~~~~~~~~~~~~~~~~~~~~~~~~

The alternate mode drivers are not bound to cable plug alternate mode devices,
only to the partner alternate mode devices. If the alternate mode supports, or
requires, a cable that responds to SOP Prime, and optionally SOP Double Prime
messages, the driver for that alternate mode must request handle to the cable
plug alternate modes using :c:func:`typec_altmode_get_plug()`, and take over
their control.

Alternate Mode driver 구조와 operation API

90-110

Driver API는 `include/linux/usb/typec_altmode.h`의 `typec_altmode_driver`와 `typec_altmode_ops` 구조를 kernel-doc으로 제공합니다. 전자는 Alternate Mode driver를, 후자는 mode 동작 callback 집합을 나타냅니다.

Alternate Mode driver의 등록과 해제에는 같은 header의 `typec_altmode_register_driver`와 `typec_altmode_unregister_driver`를 사용합니다.

`drivers/usb/typec/bus.c`는 mode 진입·종료를 위한 `typec_altmode_enter`와 `typec_altmode_exit`, Attention 전달용 `typec_altmode_attention`, VDM 교환용 `typec_altmode_vdm`, mux state 통지용 `typec_altmode_notify`를 제공합니다.

Alternate Mode driver API 묶음
분류구조·함수
Driver 구조`typec_altmode_driver`
Operation callback`typec_altmode_ops`
등록·해제`typec_altmode_register_driver`, `typec_altmode_unregister_driver`
Mode 제어`typec_altmode_enter`, `typec_altmode_exit`
Message 전달`typec_altmode_attention`, `typec_altmode_vdm`
Mux state 통지`typec_altmode_notify`


Driver API
----------

Alternate mode structs
~~~~~~~~~~~~~~~~~~~~~~

.. kernel-doc:: include/linux/usb/typec_altmode.h
   :functions: typec_altmode_driver typec_altmode_ops

Alternate mode driver registering/unregistering
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. kernel-doc:: include/linux/usb/typec_altmode.h
   :functions: typec_altmode_register_driver typec_altmode_unregister_driver

Alternate mode driver operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. kernel-doc:: drivers/usb/typec/bus.c
   :functions: typec_altmode_enter typec_altmode_exit typec_altmode_attention typec_altmode_vdm typec_altmode_notify

Port driver와 cable plug API

111-122

Port driver는 `drivers/usb/typec/bus.c`의 `typec_match_altmode`를 사용해 주어진 SVID와 mode에 맞는 Alternate Mode를 찾습니다.

Cable plug Alternate Mode를 제어하는 driver는 `typec_altmode_get_plug`으로 handle을 얻고, 사용을 마치면 `typec_altmode_put_plug`으로 reference를 반환합니다.

따라서 port 쪽 matching과 cable plug 쪽 get·put lifecycle을 분리해 관리해야 하며, partner Alternate Mode driver가 필요한 cable plug만 명시적으로 인계받는 구조입니다.

Port와 cable plug API lifecycle
Port Alternate Mode 탐색`typec_match_altmode`
Cable plug 지원 필요SOP Prime·Double Prime 요구 확인
Plug handle 획득`typec_altmode_get_plug`
Cable plug 제어Alternate Mode driver가 operation 수행
Reference 반환`typec_altmode_put_plug`

Port matching과 cable plug reference 획득·반환 흐름입니다.


API for the port drivers
~~~~~~~~~~~~~~~~~~~~~~~~

.. kernel-doc:: drivers/usb/typec/bus.c
   :functions: typec_match_altmode

Cable Plug operations
~~~~~~~~~~~~~~~~~~~~~

.. kernel-doc:: drivers/usb/typec/bus.c
   :functions: typec_altmode_get_plug typec_altmode_put_plug