xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/i3c/protocol.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun============
4*4882a593SmuzhiyunI3C protocol
5*4882a593Smuzhiyun============
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunDisclaimer
8*4882a593Smuzhiyun==========
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunThis chapter will focus on aspects that matter to software developers. For
11*4882a593Smuzhiyuneverything hardware related (like how things are transmitted on the bus, how
12*4882a593Smuzhiyuncollisions are prevented, ...) please have a look at the I3C specification.
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunThis document is just a brief introduction to the I3C protocol and the concepts
15*4882a593Smuzhiyunit brings to the table. If you need more information, please refer to the MIPI
16*4882a593SmuzhiyunI3C specification (can be downloaded here
17*4882a593Smuzhiyunhttps://resources.mipi.org/mipi-i3c-v1-download).
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunIntroduction
20*4882a593Smuzhiyun============
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunThe I3C (pronounced 'eye-three-see') is a MIPI standardized protocol designed
23*4882a593Smuzhiyunto overcome I2C limitations (limited speed, external signals needed for
24*4882a593Smuzhiyuninterrupts, no automatic detection of the devices connected to the bus, ...)
25*4882a593Smuzhiyunwhile remaining power-efficient.
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunI3C Bus
28*4882a593Smuzhiyun=======
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunAn I3C bus is made of several I3C devices and possibly some I2C devices as
31*4882a593Smuzhiyunwell, but let's focus on I3C devices for now.
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunAn I3C device on the I3C bus can have one of the following roles:
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun* Master: the device is driving the bus. It's the one in charge of initiating
36*4882a593Smuzhiyun  transactions or deciding who is allowed to talk on the bus (slave generated
37*4882a593Smuzhiyun  events are possible in I3C, see below).
38*4882a593Smuzhiyun* Slave: the device acts as a slave, and is not able to send frames to another
39*4882a593Smuzhiyun  slave on the bus. The device can still send events to the master on
40*4882a593Smuzhiyun  its own initiative if the master allowed it.
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunI3C is a multi-master protocol, so there might be several masters on a bus,
43*4882a593Smuzhiyunthough only one device can act as a master at a given time. In order to gain
44*4882a593Smuzhiyunbus ownership, a master has to follow a specific procedure.
45*4882a593Smuzhiyun
46*4882a593SmuzhiyunEach device on the I3C bus has to be assigned a dynamic address to be able to
47*4882a593Smuzhiyuncommunicate. Until this is done, the device should only respond to a limited
48*4882a593Smuzhiyunset of commands. If it has a static address (also called legacy I2C address),
49*4882a593Smuzhiyunthe device can reply to I2C transfers.
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunIn addition to these per-device addresses, the protocol defines a broadcast
52*4882a593Smuzhiyunaddress in order to address all devices on the bus.
53*4882a593Smuzhiyun
54*4882a593SmuzhiyunOnce a dynamic address has been assigned to a device, this address will be used
55*4882a593Smuzhiyunfor any direct communication with the device. Note that even after being
56*4882a593Smuzhiyunassigned a dynamic address, the device should still process broadcast messages.
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunI3C Device discovery
59*4882a593Smuzhiyun====================
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunThe I3C protocol defines a mechanism to automatically discover devices present
62*4882a593Smuzhiyunon the bus, their capabilities and the functionalities they provide. In this
63*4882a593Smuzhiyunregard I3C is closer to a discoverable bus like USB than it is to I2C or SPI.
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunThe discovery mechanism is called DAA (Dynamic Address Assignment), because it
66*4882a593Smuzhiyunnot only discovers devices but also assigns them a dynamic address.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunDuring DAA, each I3C device reports 3 important things:
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun* BCR: Bus Characteristic Register. This 8-bit register describes the device bus
71*4882a593Smuzhiyun  related capabilities
72*4882a593Smuzhiyun* DCR: Device Characteristic Register. This 8-bit register describes the
73*4882a593Smuzhiyun  functionalities provided by the device
74*4882a593Smuzhiyun* Provisional ID: A 48-bit unique identifier. On a given bus there should be no
75*4882a593Smuzhiyun  Provisional ID collision, otherwise the discovery mechanism may fail.
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunI3C slave events
78*4882a593Smuzhiyun================
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunThe I3C protocol allows slaves to generate events on their own, and thus allows
81*4882a593Smuzhiyunthem to take temporary control of the bus.
82*4882a593Smuzhiyun
83*4882a593SmuzhiyunThis mechanism is called IBI for In Band Interrupts, and as stated in the name,
84*4882a593Smuzhiyunit allows devices to generate interrupts without requiring an external signal.
85*4882a593Smuzhiyun
86*4882a593SmuzhiyunDuring DAA, each device on the bus has been assigned an address, and this
87*4882a593Smuzhiyunaddress will serve as a priority identifier to determine who wins if 2 different
88*4882a593Smuzhiyundevices are generating an interrupt at the same moment on the bus (the lower the
89*4882a593Smuzhiyundynamic address the higher the priority).
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunMasters are allowed to inhibit interrupts if they want to. This inhibition
92*4882a593Smuzhiyunrequest can be broadcast (applies to all devices) or sent to a specific
93*4882a593Smuzhiyundevice.
94*4882a593Smuzhiyun
95*4882a593SmuzhiyunI3C Hot-Join
96*4882a593Smuzhiyun============
97*4882a593Smuzhiyun
98*4882a593SmuzhiyunThe Hot-Join mechanism is similar to USB hotplug. This mechanism allows
99*4882a593Smuzhiyunslaves to join the bus after it has been initialized by the master.
100*4882a593Smuzhiyun
101*4882a593SmuzhiyunThis covers the following use cases:
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun* the device is not powered when the bus is probed
104*4882a593Smuzhiyun* the device is hotplugged on the bus through an extension board
105*4882a593Smuzhiyun
106*4882a593SmuzhiyunThis mechanism is relying on slave events to inform the master that a new
107*4882a593Smuzhiyundevice joined the bus and is waiting for a dynamic address.
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunThe master is then free to address the request as it wishes: ignore it or
110*4882a593Smuzhiyunassign a dynamic address to the slave.
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunI3C transfer types
113*4882a593Smuzhiyun==================
114*4882a593Smuzhiyun
115*4882a593SmuzhiyunIf you omit SMBus (which is just a standardization on how to access registers
116*4882a593Smuzhiyunexposed by I2C devices), I2C has only one transfer type.
117*4882a593Smuzhiyun
118*4882a593SmuzhiyunI3C defines 3 different classes of transfer in addition to I2C transfers which
119*4882a593Smuzhiyunare here for backward compatibility with I2C devices.
120*4882a593Smuzhiyun
121*4882a593SmuzhiyunI3C CCC commands
122*4882a593Smuzhiyun----------------
123*4882a593Smuzhiyun
124*4882a593SmuzhiyunCCC (Common Command Code) commands are meant to be used for anything that is
125*4882a593Smuzhiyunrelated to bus management and all features that are common to a set of devices.
126*4882a593Smuzhiyun
127*4882a593SmuzhiyunCCC commands contain an 8-bit CCC ID describing the command that is executed.
128*4882a593SmuzhiyunThe MSB of this ID specifies whether this is a broadcast command (bit7 = 0) or a
129*4882a593Smuzhiyununicast one (bit7 = 1).
130*4882a593Smuzhiyun
131*4882a593SmuzhiyunThe command ID can be followed by a payload. Depending on the command, this
132*4882a593Smuzhiyunpayload is either sent by the master sending the command (write CCC command),
133*4882a593Smuzhiyunor sent by the slave receiving the command (read CCC command). Of course, read
134*4882a593Smuzhiyunaccesses only apply to unicast commands.
135*4882a593SmuzhiyunNote that, when sending a CCC command to a specific device, the device address
136*4882a593Smuzhiyunis passed in the first byte of the payload.
137*4882a593Smuzhiyun
138*4882a593SmuzhiyunThe payload length is not explicitly passed on the bus, and should be extracted
139*4882a593Smuzhiyunfrom the CCC ID.
140*4882a593Smuzhiyun
141*4882a593SmuzhiyunNote that vendors can use a dedicated range of CCC IDs for their own commands
142*4882a593Smuzhiyun(0x61-0x7f and 0xe0-0xef).
143*4882a593Smuzhiyun
144*4882a593SmuzhiyunI3C Private SDR transfers
145*4882a593Smuzhiyun-------------------------
146*4882a593Smuzhiyun
147*4882a593SmuzhiyunPrivate SDR (Single Data Rate) transfers should be used for anything that is
148*4882a593Smuzhiyundevice specific and does not require high transfer speed.
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunIt is the equivalent of I2C transfers but in the I3C world. Each transfer is
151*4882a593Smuzhiyunpassed the device address (dynamic address assigned during DAA), a payload
152*4882a593Smuzhiyunand a direction.
153*4882a593Smuzhiyun
154*4882a593SmuzhiyunThe only difference with I2C is that the transfer is much faster (typical clock
155*4882a593Smuzhiyunfrequency is 12.5MHz).
156*4882a593Smuzhiyun
157*4882a593SmuzhiyunI3C HDR commands
158*4882a593Smuzhiyun----------------
159*4882a593Smuzhiyun
160*4882a593SmuzhiyunHDR commands should be used for anything that is device specific and requires
161*4882a593Smuzhiyunhigh transfer speed.
162*4882a593Smuzhiyun
163*4882a593SmuzhiyunThe first thing attached to an HDR command is the HDR mode. There are currently
164*4882a593Smuzhiyun3 different modes defined by the I3C specification (refer to the specification
165*4882a593Smuzhiyunfor more details):
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun* HDR-DDR: Double Data Rate mode
168*4882a593Smuzhiyun* HDR-TSP: Ternary Symbol Pure. Only usable on busses with no I2C devices
169*4882a593Smuzhiyun* HDR-TSL: Ternary Symbol Legacy. Usable on busses with I2C devices
170*4882a593Smuzhiyun
171*4882a593SmuzhiyunWhen sending an HDR command, the whole bus has to enter HDR mode, which is done
172*4882a593Smuzhiyunusing a broadcast CCC command.
173*4882a593SmuzhiyunOnce the bus has entered a specific HDR mode, the master sends the HDR command.
174*4882a593SmuzhiyunAn HDR command is made of:
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun* one 16-bits command word in big endian
177*4882a593Smuzhiyun* N 16-bits data words in big endian
178*4882a593Smuzhiyun
179*4882a593SmuzhiyunThose words may be wrapped with specific preambles/post-ambles which depend on
180*4882a593Smuzhiyunthe chosen HDR mode and are detailed here (see the specification for more
181*4882a593Smuzhiyundetails).
182*4882a593Smuzhiyun
183*4882a593SmuzhiyunThe 16-bits command word is made of:
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun* bit[15]: direction bit, read is 1, write is 0
186*4882a593Smuzhiyun* bit[14:8]: command code. Identifies the command being executed, the amount of
187*4882a593Smuzhiyun  data words and their meaning
188*4882a593Smuzhiyun* bit[7:1]: I3C address of the device this command is addressed to
189*4882a593Smuzhiyun* bit[0]: reserved/parity-bit
190*4882a593Smuzhiyun
191*4882a593SmuzhiyunBackward compatibility with I2C devices
192*4882a593Smuzhiyun=======================================
193*4882a593Smuzhiyun
194*4882a593SmuzhiyunThe I3C protocol has been designed to be backward compatible with I2C devices.
195*4882a593SmuzhiyunThis backward compatibility allows one to connect a mix of I2C and I3C devices
196*4882a593Smuzhiyunon the same bus, though, in order to be really efficient, I2C devices should
197*4882a593Smuzhiyunbe equipped with 50 ns spike filters.
198*4882a593Smuzhiyun
199*4882a593SmuzhiyunI2C devices can't be discovered like I3C ones and have to be statically
200*4882a593Smuzhiyundeclared. In order to let the master know what these devices are capable of
201*4882a593Smuzhiyun(both in terms of bus related limitations and functionalities), the software
202*4882a593Smuzhiyunhas to provide some information, which is done through the LVR (Legacy I2C
203*4882a593SmuzhiyunVirtual Register).
204