162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci============ 462306a36Sopenharmony_ciI3C protocol 562306a36Sopenharmony_ci============ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciDisclaimer 862306a36Sopenharmony_ci========== 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciThis chapter will focus on aspects that matter to software developers. For 1162306a36Sopenharmony_cieverything hardware related (like how things are transmitted on the bus, how 1262306a36Sopenharmony_cicollisions are prevented, ...) please have a look at the I3C specification. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciThis document is just a brief introduction to the I3C protocol and the concepts 1562306a36Sopenharmony_ciit brings to the table. If you need more information, please refer to the MIPI 1662306a36Sopenharmony_ciI3C specification (can be downloaded here 1762306a36Sopenharmony_cihttps://resources.mipi.org/mipi-i3c-v1-download). 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciIntroduction 2062306a36Sopenharmony_ci============ 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciThe I3C (pronounced 'eye-three-see') is a MIPI standardized protocol designed 2362306a36Sopenharmony_cito overcome I2C limitations (limited speed, external signals needed for 2462306a36Sopenharmony_ciinterrupts, no automatic detection of the devices connected to the bus, ...) 2562306a36Sopenharmony_ciwhile remaining power-efficient. 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ciI3C Bus 2862306a36Sopenharmony_ci======= 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciAn I3C bus is made of several I3C devices and possibly some I2C devices as 3162306a36Sopenharmony_ciwell, but let's focus on I3C devices for now. 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciAn I3C device on the I3C bus can have one of the following roles: 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci* Master: the device is driving the bus. It's the one in charge of initiating 3662306a36Sopenharmony_ci transactions or deciding who is allowed to talk on the bus (slave generated 3762306a36Sopenharmony_ci events are possible in I3C, see below). 3862306a36Sopenharmony_ci* Slave: the device acts as a slave, and is not able to send frames to another 3962306a36Sopenharmony_ci slave on the bus. The device can still send events to the master on 4062306a36Sopenharmony_ci its own initiative if the master allowed it. 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ciI3C is a multi-master protocol, so there might be several masters on a bus, 4362306a36Sopenharmony_cithough only one device can act as a master at a given time. In order to gain 4462306a36Sopenharmony_cibus ownership, a master has to follow a specific procedure. 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ciEach device on the I3C bus has to be assigned a dynamic address to be able to 4762306a36Sopenharmony_cicommunicate. Until this is done, the device should only respond to a limited 4862306a36Sopenharmony_ciset of commands. If it has a static address (also called legacy I2C address), 4962306a36Sopenharmony_cithe device can reply to I2C transfers. 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ciIn addition to these per-device addresses, the protocol defines a broadcast 5262306a36Sopenharmony_ciaddress in order to address all devices on the bus. 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ciOnce a dynamic address has been assigned to a device, this address will be used 5562306a36Sopenharmony_cifor any direct communication with the device. Note that even after being 5662306a36Sopenharmony_ciassigned a dynamic address, the device should still process broadcast messages. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciI3C Device discovery 5962306a36Sopenharmony_ci==================== 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciThe I3C protocol defines a mechanism to automatically discover devices present 6262306a36Sopenharmony_cion the bus, their capabilities and the functionalities they provide. In this 6362306a36Sopenharmony_ciregard I3C is closer to a discoverable bus like USB than it is to I2C or SPI. 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ciThe discovery mechanism is called DAA (Dynamic Address Assignment), because it 6662306a36Sopenharmony_cinot only discovers devices but also assigns them a dynamic address. 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ciDuring DAA, each I3C device reports 3 important things: 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci* BCR: Bus Characteristic Register. This 8-bit register describes the device bus 7162306a36Sopenharmony_ci related capabilities 7262306a36Sopenharmony_ci* DCR: Device Characteristic Register. This 8-bit register describes the 7362306a36Sopenharmony_ci functionalities provided by the device 7462306a36Sopenharmony_ci* Provisional ID: A 48-bit unique identifier. On a given bus there should be no 7562306a36Sopenharmony_ci Provisional ID collision, otherwise the discovery mechanism may fail. 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ciI3C slave events 7862306a36Sopenharmony_ci================ 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ciThe I3C protocol allows slaves to generate events on their own, and thus allows 8162306a36Sopenharmony_cithem to take temporary control of the bus. 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciThis mechanism is called IBI for In Band Interrupts, and as stated in the name, 8462306a36Sopenharmony_ciit allows devices to generate interrupts without requiring an external signal. 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciDuring DAA, each device on the bus has been assigned an address, and this 8762306a36Sopenharmony_ciaddress will serve as a priority identifier to determine who wins if 2 different 8862306a36Sopenharmony_cidevices are generating an interrupt at the same moment on the bus (the lower the 8962306a36Sopenharmony_cidynamic address the higher the priority). 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ciMasters are allowed to inhibit interrupts if they want to. This inhibition 9262306a36Sopenharmony_cirequest can be broadcast (applies to all devices) or sent to a specific 9362306a36Sopenharmony_cidevice. 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ciI3C Hot-Join 9662306a36Sopenharmony_ci============ 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ciThe Hot-Join mechanism is similar to USB hotplug. This mechanism allows 9962306a36Sopenharmony_cislaves to join the bus after it has been initialized by the master. 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ciThis covers the following use cases: 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci* the device is not powered when the bus is probed 10462306a36Sopenharmony_ci* the device is hotplugged on the bus through an extension board 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ciThis mechanism is relying on slave events to inform the master that a new 10762306a36Sopenharmony_cidevice joined the bus and is waiting for a dynamic address. 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ciThe master is then free to address the request as it wishes: ignore it or 11062306a36Sopenharmony_ciassign a dynamic address to the slave. 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ciI3C transfer types 11362306a36Sopenharmony_ci================== 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ciIf you omit SMBus (which is just a standardization on how to access registers 11662306a36Sopenharmony_ciexposed by I2C devices), I2C has only one transfer type. 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ciI3C defines 3 different classes of transfer in addition to I2C transfers which 11962306a36Sopenharmony_ciare here for backward compatibility with I2C devices. 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciI3C CCC commands 12262306a36Sopenharmony_ci---------------- 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciCCC (Common Command Code) commands are meant to be used for anything that is 12562306a36Sopenharmony_cirelated to bus management and all features that are common to a set of devices. 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciCCC commands contain an 8-bit CCC ID describing the command that is executed. 12862306a36Sopenharmony_ciThe MSB of this ID specifies whether this is a broadcast command (bit7 = 0) or a 12962306a36Sopenharmony_ciunicast one (bit7 = 1). 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ciThe command ID can be followed by a payload. Depending on the command, this 13262306a36Sopenharmony_cipayload is either sent by the master sending the command (write CCC command), 13362306a36Sopenharmony_cior sent by the slave receiving the command (read CCC command). Of course, read 13462306a36Sopenharmony_ciaccesses only apply to unicast commands. 13562306a36Sopenharmony_ciNote that, when sending a CCC command to a specific device, the device address 13662306a36Sopenharmony_ciis passed in the first byte of the payload. 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ciThe payload length is not explicitly passed on the bus, and should be extracted 13962306a36Sopenharmony_cifrom the CCC ID. 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ciNote that vendors can use a dedicated range of CCC IDs for their own commands 14262306a36Sopenharmony_ci(0x61-0x7f and 0xe0-0xef). 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ciI3C Private SDR transfers 14562306a36Sopenharmony_ci------------------------- 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ciPrivate SDR (Single Data Rate) transfers should be used for anything that is 14862306a36Sopenharmony_cidevice specific and does not require high transfer speed. 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ciIt is the equivalent of I2C transfers but in the I3C world. Each transfer is 15162306a36Sopenharmony_cipassed the device address (dynamic address assigned during DAA), a payload 15262306a36Sopenharmony_ciand a direction. 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ciThe only difference with I2C is that the transfer is much faster (typical clock 15562306a36Sopenharmony_cifrequency is 12.5MHz). 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ciI3C HDR commands 15862306a36Sopenharmony_ci---------------- 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ciHDR commands should be used for anything that is device specific and requires 16162306a36Sopenharmony_cihigh transfer speed. 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ciThe first thing attached to an HDR command is the HDR mode. There are currently 16462306a36Sopenharmony_ci3 different modes defined by the I3C specification (refer to the specification 16562306a36Sopenharmony_cifor more details): 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci* HDR-DDR: Double Data Rate mode 16862306a36Sopenharmony_ci* HDR-TSP: Ternary Symbol Pure. Only usable on busses with no I2C devices 16962306a36Sopenharmony_ci* HDR-TSL: Ternary Symbol Legacy. Usable on busses with I2C devices 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ciWhen sending an HDR command, the whole bus has to enter HDR mode, which is done 17262306a36Sopenharmony_ciusing a broadcast CCC command. 17362306a36Sopenharmony_ciOnce the bus has entered a specific HDR mode, the master sends the HDR command. 17462306a36Sopenharmony_ciAn HDR command is made of: 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci* one 16-bits command word in big endian 17762306a36Sopenharmony_ci* N 16-bits data words in big endian 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ciThose words may be wrapped with specific preambles/post-ambles which depend on 18062306a36Sopenharmony_cithe chosen HDR mode and are detailed here (see the specification for more 18162306a36Sopenharmony_cidetails). 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ciThe 16-bits command word is made of: 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci* bit[15]: direction bit, read is 1, write is 0 18662306a36Sopenharmony_ci* bit[14:8]: command code. Identifies the command being executed, the amount of 18762306a36Sopenharmony_ci data words and their meaning 18862306a36Sopenharmony_ci* bit[7:1]: I3C address of the device this command is addressed to 18962306a36Sopenharmony_ci* bit[0]: reserved/parity-bit 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ciBackward compatibility with I2C devices 19262306a36Sopenharmony_ci======================================= 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ciThe I3C protocol has been designed to be backward compatible with I2C devices. 19562306a36Sopenharmony_ciThis backward compatibility allows one to connect a mix of I2C and I3C devices 19662306a36Sopenharmony_cion the same bus, though, in order to be really efficient, I2C devices should 19762306a36Sopenharmony_cibe equipped with 50 ns spike filters. 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ciI2C devices can't be discovered like I3C ones and have to be statically 20062306a36Sopenharmony_cideclared. In order to let the master know what these devices are capable of 20162306a36Sopenharmony_ci(both in terms of bus related limitations and functionalities), the software 20262306a36Sopenharmony_cihas to provide some information, which is done through the LVR (Legacy I2C 20362306a36Sopenharmony_ciVirtual Register). 204