1*4882a593Smuzhiyun===================== 2*4882a593SmuzhiyunI2C/SMBUS Fault Codes 3*4882a593Smuzhiyun===================== 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunThis is a summary of the most important conventions for use of fault 6*4882a593Smuzhiyuncodes in the I2C/SMBus stack. 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunA "Fault" is not always an "Error" 10*4882a593Smuzhiyun---------------------------------- 11*4882a593SmuzhiyunNot all fault reports imply errors; "page faults" should be a familiar 12*4882a593Smuzhiyunexample. Software often retries idempotent operations after transient 13*4882a593Smuzhiyunfaults. There may be fancier recovery schemes that are appropriate in 14*4882a593Smuzhiyunsome cases, such as re-initializing (and maybe resetting). After such 15*4882a593Smuzhiyunrecovery, triggered by a fault report, there is no error. 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunIn a similar way, sometimes a "fault" code just reports one defined 18*4882a593Smuzhiyunresult for an operation ... it doesn't indicate that anything is wrong 19*4882a593Smuzhiyunat all, just that the outcome wasn't on the "golden path". 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunIn short, your I2C driver code may need to know these codes in order 22*4882a593Smuzhiyunto respond correctly. Other code may need to rely on YOUR code reporting 23*4882a593Smuzhiyunthe right fault code, so that it can (in turn) behave correctly. 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunI2C and SMBus fault codes 27*4882a593Smuzhiyun------------------------- 28*4882a593SmuzhiyunThese are returned as negative numbers from most calls, with zero or 29*4882a593Smuzhiyunsome positive number indicating a non-fault return. The specific 30*4882a593Smuzhiyunnumbers associated with these symbols differ between architectures, 31*4882a593Smuzhiyunthough most Linux systems use <asm-generic/errno*.h> numbering. 32*4882a593Smuzhiyun 33*4882a593SmuzhiyunNote that the descriptions here are not exhaustive. There are other 34*4882a593Smuzhiyuncodes that may be returned, and other cases where these codes should 35*4882a593Smuzhiyunbe returned. However, drivers should not return other codes for these 36*4882a593Smuzhiyuncases (unless the hardware doesn't provide unique fault reports). 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunAlso, codes returned by adapter probe methods follow rules which are 39*4882a593Smuzhiyunspecific to their host bus (such as PCI, or the platform bus). 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunEAGAIN 43*4882a593Smuzhiyun Returned by I2C adapters when they lose arbitration in master 44*4882a593Smuzhiyun transmit mode: some other master was transmitting different 45*4882a593Smuzhiyun data at the same time. 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun Also returned when trying to invoke an I2C operation in an 48*4882a593Smuzhiyun atomic context, when some task is already using that I2C bus 49*4882a593Smuzhiyun to execute some other operation. 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunEBADMSG 52*4882a593Smuzhiyun Returned by SMBus logic when an invalid Packet Error Code byte 53*4882a593Smuzhiyun is received. This code is a CRC covering all bytes in the 54*4882a593Smuzhiyun transaction, and is sent before the terminating STOP. This 55*4882a593Smuzhiyun fault is only reported on read transactions; the SMBus slave 56*4882a593Smuzhiyun may have a way to report PEC mismatches on writes from the 57*4882a593Smuzhiyun host. Note that even if PECs are in use, you should not rely 58*4882a593Smuzhiyun on these as the only way to detect incorrect data transfers. 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunEBUSY 61*4882a593Smuzhiyun Returned by SMBus adapters when the bus was busy for longer 62*4882a593Smuzhiyun than allowed. This usually indicates some device (maybe the 63*4882a593Smuzhiyun SMBus adapter) needs some fault recovery (such as resetting), 64*4882a593Smuzhiyun or that the reset was attempted but failed. 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunEINVAL 67*4882a593Smuzhiyun This rather vague error means an invalid parameter has been 68*4882a593Smuzhiyun detected before any I/O operation was started. Use a more 69*4882a593Smuzhiyun specific fault code when you can. 70*4882a593Smuzhiyun 71*4882a593SmuzhiyunEIO 72*4882a593Smuzhiyun This rather vague error means something went wrong when 73*4882a593Smuzhiyun performing an I/O operation. Use a more specific fault 74*4882a593Smuzhiyun code when you can. 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunENODEV 77*4882a593Smuzhiyun Returned by driver probe() methods. This is a bit more 78*4882a593Smuzhiyun specific than ENXIO, implying the problem isn't with the 79*4882a593Smuzhiyun address, but with the device found there. Driver probes 80*4882a593Smuzhiyun may verify the device returns *correct* responses, and 81*4882a593Smuzhiyun return this as appropriate. (The driver core will warn 82*4882a593Smuzhiyun about probe faults other than ENXIO and ENODEV.) 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunENOMEM 85*4882a593Smuzhiyun Returned by any component that can't allocate memory when 86*4882a593Smuzhiyun it needs to do so. 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunENXIO 89*4882a593Smuzhiyun Returned by I2C adapters to indicate that the address phase 90*4882a593Smuzhiyun of a transfer didn't get an ACK. While it might just mean 91*4882a593Smuzhiyun an I2C device was temporarily not responding, usually it 92*4882a593Smuzhiyun means there's nothing listening at that address. 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun Returned by driver probe() methods to indicate that they 95*4882a593Smuzhiyun found no device to bind to. (ENODEV may also be used.) 96*4882a593Smuzhiyun 97*4882a593SmuzhiyunEOPNOTSUPP 98*4882a593Smuzhiyun Returned by an adapter when asked to perform an operation 99*4882a593Smuzhiyun that it doesn't, or can't, support. 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun For example, this would be returned when an adapter that 102*4882a593Smuzhiyun doesn't support SMBus block transfers is asked to execute 103*4882a593Smuzhiyun one. In that case, the driver making that request should 104*4882a593Smuzhiyun have verified that functionality was supported before it 105*4882a593Smuzhiyun made that block transfer request. 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun Similarly, if an I2C adapter can't execute all legal I2C 108*4882a593Smuzhiyun messages, it should return this when asked to perform a 109*4882a593Smuzhiyun transaction it can't. (These limitations can't be seen in 110*4882a593Smuzhiyun the adapter's functionality mask, since the assumption is 111*4882a593Smuzhiyun that if an adapter supports I2C it supports all of I2C.) 112*4882a593Smuzhiyun 113*4882a593SmuzhiyunEPROTO 114*4882a593Smuzhiyun Returned when slave does not conform to the relevant I2C 115*4882a593Smuzhiyun or SMBus (or chip-specific) protocol specifications. One 116*4882a593Smuzhiyun case is when the length of an SMBus block data response 117*4882a593Smuzhiyun (from the SMBus slave) is outside the range 1-32 bytes. 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunESHUTDOWN 120*4882a593Smuzhiyun Returned when a transfer was requested using an adapter 121*4882a593Smuzhiyun which is already suspended. 122*4882a593Smuzhiyun 123*4882a593SmuzhiyunETIMEDOUT 124*4882a593Smuzhiyun This is returned by drivers when an operation took too much 125*4882a593Smuzhiyun time, and was aborted before it completed. 126*4882a593Smuzhiyun 127*4882a593Smuzhiyun SMBus adapters may return it when an operation took more 128*4882a593Smuzhiyun time than allowed by the SMBus specification; for example, 129*4882a593Smuzhiyun when a slave stretches clocks too far. I2C has no such 130*4882a593Smuzhiyun timeouts, but it's normal for I2C adapters to impose some 131*4882a593Smuzhiyun arbitrary limits (much longer than SMBus!) too. 132