gpio-fault-injection 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. Linux I2C fault injection
  2. =========================
  3. The GPIO based I2C bus master driver can be configured to provide fault
  4. injection capabilities. It is then meant to be connected to another I2C bus
  5. which is driven by the I2C bus master driver under test. The GPIO fault
  6. injection driver can create special states on the bus which the other I2C bus
  7. master driver should handle gracefully.
  8. Once the Kconfig option I2C_GPIO_FAULT_INJECTOR is enabled, there will be an
  9. 'i2c-fault-injector' subdirectory in the Kernel debugfs filesystem, usually
  10. mounted at /sys/kernel/debug. There will be a separate subdirectory per GPIO
  11. driven I2C bus. Each subdirectory will contain files to trigger the fault
  12. injection. They will be described now along with their intended use-cases.
  13. "scl"
  14. -----
  15. By reading this file, you get the current state of SCL. By writing, you can
  16. change its state to either force it low or to release it again. So, by using
  17. "echo 0 > scl" you force SCL low and thus, no communication will be possible
  18. because the bus master under test will not be able to clock. It should detect
  19. the condition of SCL being unresponsive and report an error to the upper
  20. layers.
  21. "sda"
  22. -----
  23. By reading this file, you get the current state of SDA. By writing, you can
  24. change its state to either force it low or to release it again. So, by using
  25. "echo 0 > sda" you force SDA low and thus, data cannot be transmitted. The bus
  26. master under test should detect this condition and trigger a bus recovery (see
  27. I2C specification version 4, section 3.1.16) using the helpers of the Linux I2C
  28. core (see 'struct bus_recovery_info'). However, the bus recovery will not
  29. succeed because SDA is still pinned low until you manually release it again
  30. with "echo 1 > sda". A test with an automatic release can be done with the
  31. 'incomplete_transfer' file.
  32. "incomplete_transfer"
  33. ---------------------
  34. This file is write only and you need to write the address of an existing I2C
  35. client device to it. Then, a transfer to this device will be started, but it
  36. will stop at the ACK phase after the address of the client has been
  37. transmitted. Because the device will ACK its presence, this results in SDA
  38. being pulled low by the device while SCL is high. So, similar to the "sda" file
  39. above, the bus master under test should detect this condition and try a bus
  40. recovery. This time, however, it should succeed and the device should release
  41. SDA after toggling SCL. Please note: there are I2C client devices which detect
  42. a stuck SDA on their side and release it on their own after a few milliseconds.
  43. Also, there are external devices deglitching and monitoring the I2C bus. They
  44. can also detect a stuck SDA and will init a bus recovery on their own. If you
  45. want to implement bus recovery in a bus master driver, make sure you checked
  46. your hardware setup carefully before.