18c2ecf20Sopenharmony_ci===================== 28c2ecf20Sopenharmony_ciI2C/SMBUS Fault Codes 38c2ecf20Sopenharmony_ci===================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciThis is a summary of the most important conventions for use of fault 68c2ecf20Sopenharmony_cicodes in the I2C/SMBus stack. 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciA "Fault" is not always an "Error" 108c2ecf20Sopenharmony_ci---------------------------------- 118c2ecf20Sopenharmony_ciNot all fault reports imply errors; "page faults" should be a familiar 128c2ecf20Sopenharmony_ciexample. Software often retries idempotent operations after transient 138c2ecf20Sopenharmony_cifaults. There may be fancier recovery schemes that are appropriate in 148c2ecf20Sopenharmony_cisome cases, such as re-initializing (and maybe resetting). After such 158c2ecf20Sopenharmony_cirecovery, triggered by a fault report, there is no error. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciIn a similar way, sometimes a "fault" code just reports one defined 188c2ecf20Sopenharmony_ciresult for an operation ... it doesn't indicate that anything is wrong 198c2ecf20Sopenharmony_ciat all, just that the outcome wasn't on the "golden path". 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciIn short, your I2C driver code may need to know these codes in order 228c2ecf20Sopenharmony_cito respond correctly. Other code may need to rely on YOUR code reporting 238c2ecf20Sopenharmony_cithe right fault code, so that it can (in turn) behave correctly. 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciI2C and SMBus fault codes 278c2ecf20Sopenharmony_ci------------------------- 288c2ecf20Sopenharmony_ciThese are returned as negative numbers from most calls, with zero or 298c2ecf20Sopenharmony_cisome positive number indicating a non-fault return. The specific 308c2ecf20Sopenharmony_cinumbers associated with these symbols differ between architectures, 318c2ecf20Sopenharmony_cithough most Linux systems use <asm-generic/errno*.h> numbering. 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ciNote that the descriptions here are not exhaustive. There are other 348c2ecf20Sopenharmony_cicodes that may be returned, and other cases where these codes should 358c2ecf20Sopenharmony_cibe returned. However, drivers should not return other codes for these 368c2ecf20Sopenharmony_cicases (unless the hardware doesn't provide unique fault reports). 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciAlso, codes returned by adapter probe methods follow rules which are 398c2ecf20Sopenharmony_cispecific to their host bus (such as PCI, or the platform bus). 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciEAGAIN 438c2ecf20Sopenharmony_ci Returned by I2C adapters when they lose arbitration in master 448c2ecf20Sopenharmony_ci transmit mode: some other master was transmitting different 458c2ecf20Sopenharmony_ci data at the same time. 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci Also returned when trying to invoke an I2C operation in an 488c2ecf20Sopenharmony_ci atomic context, when some task is already using that I2C bus 498c2ecf20Sopenharmony_ci to execute some other operation. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciEBADMSG 528c2ecf20Sopenharmony_ci Returned by SMBus logic when an invalid Packet Error Code byte 538c2ecf20Sopenharmony_ci is received. This code is a CRC covering all bytes in the 548c2ecf20Sopenharmony_ci transaction, and is sent before the terminating STOP. This 558c2ecf20Sopenharmony_ci fault is only reported on read transactions; the SMBus slave 568c2ecf20Sopenharmony_ci may have a way to report PEC mismatches on writes from the 578c2ecf20Sopenharmony_ci host. Note that even if PECs are in use, you should not rely 588c2ecf20Sopenharmony_ci on these as the only way to detect incorrect data transfers. 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciEBUSY 618c2ecf20Sopenharmony_ci Returned by SMBus adapters when the bus was busy for longer 628c2ecf20Sopenharmony_ci than allowed. This usually indicates some device (maybe the 638c2ecf20Sopenharmony_ci SMBus adapter) needs some fault recovery (such as resetting), 648c2ecf20Sopenharmony_ci or that the reset was attempted but failed. 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciEINVAL 678c2ecf20Sopenharmony_ci This rather vague error means an invalid parameter has been 688c2ecf20Sopenharmony_ci detected before any I/O operation was started. Use a more 698c2ecf20Sopenharmony_ci specific fault code when you can. 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ciEIO 728c2ecf20Sopenharmony_ci This rather vague error means something went wrong when 738c2ecf20Sopenharmony_ci performing an I/O operation. Use a more specific fault 748c2ecf20Sopenharmony_ci code when you can. 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ciENODEV 778c2ecf20Sopenharmony_ci Returned by driver probe() methods. This is a bit more 788c2ecf20Sopenharmony_ci specific than ENXIO, implying the problem isn't with the 798c2ecf20Sopenharmony_ci address, but with the device found there. Driver probes 808c2ecf20Sopenharmony_ci may verify the device returns *correct* responses, and 818c2ecf20Sopenharmony_ci return this as appropriate. (The driver core will warn 828c2ecf20Sopenharmony_ci about probe faults other than ENXIO and ENODEV.) 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ciENOMEM 858c2ecf20Sopenharmony_ci Returned by any component that can't allocate memory when 868c2ecf20Sopenharmony_ci it needs to do so. 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ciENXIO 898c2ecf20Sopenharmony_ci Returned by I2C adapters to indicate that the address phase 908c2ecf20Sopenharmony_ci of a transfer didn't get an ACK. While it might just mean 918c2ecf20Sopenharmony_ci an I2C device was temporarily not responding, usually it 928c2ecf20Sopenharmony_ci means there's nothing listening at that address. 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci Returned by driver probe() methods to indicate that they 958c2ecf20Sopenharmony_ci found no device to bind to. (ENODEV may also be used.) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciEOPNOTSUPP 988c2ecf20Sopenharmony_ci Returned by an adapter when asked to perform an operation 998c2ecf20Sopenharmony_ci that it doesn't, or can't, support. 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci For example, this would be returned when an adapter that 1028c2ecf20Sopenharmony_ci doesn't support SMBus block transfers is asked to execute 1038c2ecf20Sopenharmony_ci one. In that case, the driver making that request should 1048c2ecf20Sopenharmony_ci have verified that functionality was supported before it 1058c2ecf20Sopenharmony_ci made that block transfer request. 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci Similarly, if an I2C adapter can't execute all legal I2C 1088c2ecf20Sopenharmony_ci messages, it should return this when asked to perform a 1098c2ecf20Sopenharmony_ci transaction it can't. (These limitations can't be seen in 1108c2ecf20Sopenharmony_ci the adapter's functionality mask, since the assumption is 1118c2ecf20Sopenharmony_ci that if an adapter supports I2C it supports all of I2C.) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ciEPROTO 1148c2ecf20Sopenharmony_ci Returned when slave does not conform to the relevant I2C 1158c2ecf20Sopenharmony_ci or SMBus (or chip-specific) protocol specifications. One 1168c2ecf20Sopenharmony_ci case is when the length of an SMBus block data response 1178c2ecf20Sopenharmony_ci (from the SMBus slave) is outside the range 1-32 bytes. 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciESHUTDOWN 1208c2ecf20Sopenharmony_ci Returned when a transfer was requested using an adapter 1218c2ecf20Sopenharmony_ci which is already suspended. 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciETIMEDOUT 1248c2ecf20Sopenharmony_ci This is returned by drivers when an operation took too much 1258c2ecf20Sopenharmony_ci time, and was aborted before it completed. 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci SMBus adapters may return it when an operation took more 1288c2ecf20Sopenharmony_ci time than allowed by the SMBus specification; for example, 1298c2ecf20Sopenharmony_ci when a slave stretches clocks too far. I2C has no such 1308c2ecf20Sopenharmony_ci timeouts, but it's normal for I2C adapters to impose some 1318c2ecf20Sopenharmony_ci arbitrary limits (much longer than SMBus!) too. 132