162306a36Sopenharmony_ci===================== 262306a36Sopenharmony_ciI2C/SMBUS Fault Codes 362306a36Sopenharmony_ci===================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciThis is a summary of the most important conventions for use of fault 662306a36Sopenharmony_cicodes in the I2C/SMBus stack. 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciA "Fault" is not always an "Error" 1062306a36Sopenharmony_ci---------------------------------- 1162306a36Sopenharmony_ciNot all fault reports imply errors; "page faults" should be a familiar 1262306a36Sopenharmony_ciexample. Software often retries idempotent operations after transient 1362306a36Sopenharmony_cifaults. There may be fancier recovery schemes that are appropriate in 1462306a36Sopenharmony_cisome cases, such as re-initializing (and maybe resetting). After such 1562306a36Sopenharmony_cirecovery, triggered by a fault report, there is no error. 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ciIn a similar way, sometimes a "fault" code just reports one defined 1862306a36Sopenharmony_ciresult for an operation ... it doesn't indicate that anything is wrong 1962306a36Sopenharmony_ciat all, just that the outcome wasn't on the "golden path". 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ciIn short, your I2C driver code may need to know these codes in order 2262306a36Sopenharmony_cito respond correctly. Other code may need to rely on YOUR code reporting 2362306a36Sopenharmony_cithe right fault code, so that it can (in turn) behave correctly. 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciI2C and SMBus fault codes 2762306a36Sopenharmony_ci------------------------- 2862306a36Sopenharmony_ciThese are returned as negative numbers from most calls, with zero or 2962306a36Sopenharmony_cisome positive number indicating a non-fault return. The specific 3062306a36Sopenharmony_cinumbers associated with these symbols differ between architectures, 3162306a36Sopenharmony_cithough most Linux systems use <asm-generic/errno*.h> numbering. 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciNote that the descriptions here are not exhaustive. There are other 3462306a36Sopenharmony_cicodes that may be returned, and other cases where these codes should 3562306a36Sopenharmony_cibe returned. However, drivers should not return other codes for these 3662306a36Sopenharmony_cicases (unless the hardware doesn't provide unique fault reports). 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciAlso, codes returned by adapter probe methods follow rules which are 3962306a36Sopenharmony_cispecific to their host bus (such as PCI, or the platform bus). 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ciEAGAIN 4362306a36Sopenharmony_ci Returned by I2C adapters when they lose arbitration in master 4462306a36Sopenharmony_ci transmit mode: some other master was transmitting different 4562306a36Sopenharmony_ci data at the same time. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci Also returned when trying to invoke an I2C operation in an 4862306a36Sopenharmony_ci atomic context, when some task is already using that I2C bus 4962306a36Sopenharmony_ci to execute some other operation. 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ciEBADMSG 5262306a36Sopenharmony_ci Returned by SMBus logic when an invalid Packet Error Code byte 5362306a36Sopenharmony_ci is received. This code is a CRC covering all bytes in the 5462306a36Sopenharmony_ci transaction, and is sent before the terminating STOP. This 5562306a36Sopenharmony_ci fault is only reported on read transactions; the SMBus slave 5662306a36Sopenharmony_ci may have a way to report PEC mismatches on writes from the 5762306a36Sopenharmony_ci host. Note that even if PECs are in use, you should not rely 5862306a36Sopenharmony_ci on these as the only way to detect incorrect data transfers. 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ciEBUSY 6162306a36Sopenharmony_ci Returned by SMBus adapters when the bus was busy for longer 6262306a36Sopenharmony_ci than allowed. This usually indicates some device (maybe the 6362306a36Sopenharmony_ci SMBus adapter) needs some fault recovery (such as resetting), 6462306a36Sopenharmony_ci or that the reset was attempted but failed. 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciEINVAL 6762306a36Sopenharmony_ci This rather vague error means an invalid parameter has been 6862306a36Sopenharmony_ci detected before any I/O operation was started. Use a more 6962306a36Sopenharmony_ci specific fault code when you can. 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciEIO 7262306a36Sopenharmony_ci This rather vague error means something went wrong when 7362306a36Sopenharmony_ci performing an I/O operation. Use a more specific fault 7462306a36Sopenharmony_ci code when you can. 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ciENODEV 7762306a36Sopenharmony_ci Returned by driver probe() methods. This is a bit more 7862306a36Sopenharmony_ci specific than ENXIO, implying the problem isn't with the 7962306a36Sopenharmony_ci address, but with the device found there. Driver probes 8062306a36Sopenharmony_ci may verify the device returns *correct* responses, and 8162306a36Sopenharmony_ci return this as appropriate. (The driver core will warn 8262306a36Sopenharmony_ci about probe faults other than ENXIO and ENODEV.) 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ciENOMEM 8562306a36Sopenharmony_ci Returned by any component that can't allocate memory when 8662306a36Sopenharmony_ci it needs to do so. 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciENXIO 8962306a36Sopenharmony_ci Returned by I2C adapters to indicate that the address phase 9062306a36Sopenharmony_ci of a transfer didn't get an ACK. While it might just mean 9162306a36Sopenharmony_ci an I2C device was temporarily not responding, usually it 9262306a36Sopenharmony_ci means there's nothing listening at that address. 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci Returned by driver probe() methods to indicate that they 9562306a36Sopenharmony_ci found no device to bind to. (ENODEV may also be used.) 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciEOPNOTSUPP 9862306a36Sopenharmony_ci Returned by an adapter when asked to perform an operation 9962306a36Sopenharmony_ci that it doesn't, or can't, support. 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci For example, this would be returned when an adapter that 10262306a36Sopenharmony_ci doesn't support SMBus block transfers is asked to execute 10362306a36Sopenharmony_ci one. In that case, the driver making that request should 10462306a36Sopenharmony_ci have verified that functionality was supported before it 10562306a36Sopenharmony_ci made that block transfer request. 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci Similarly, if an I2C adapter can't execute all legal I2C 10862306a36Sopenharmony_ci messages, it should return this when asked to perform a 10962306a36Sopenharmony_ci transaction it can't. (These limitations can't be seen in 11062306a36Sopenharmony_ci the adapter's functionality mask, since the assumption is 11162306a36Sopenharmony_ci that if an adapter supports I2C it supports all of I2C.) 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ciEPROTO 11462306a36Sopenharmony_ci Returned when slave does not conform to the relevant I2C 11562306a36Sopenharmony_ci or SMBus (or chip-specific) protocol specifications. One 11662306a36Sopenharmony_ci case is when the length of an SMBus block data response 11762306a36Sopenharmony_ci (from the SMBus slave) is outside the range 1-32 bytes. 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ciESHUTDOWN 12062306a36Sopenharmony_ci Returned when a transfer was requested using an adapter 12162306a36Sopenharmony_ci which is already suspended. 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ciETIMEDOUT 12462306a36Sopenharmony_ci This is returned by drivers when an operation took too much 12562306a36Sopenharmony_ci time, and was aborted before it completed. 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci SMBus adapters may return it when an operation took more 12862306a36Sopenharmony_ci time than allowed by the SMBus specification; for example, 12962306a36Sopenharmony_ci when a slave stretches clocks too far. I2C has no such 13062306a36Sopenharmony_ci timeouts, but it's normal for I2C adapters to impose some 13162306a36Sopenharmony_ci arbitrary limits (much longer than SMBus!) too. 132