i2c-stub.rst 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ========
  2. i2c-stub
  3. ========
  4. Description
  5. ===========
  6. This module is a very simple fake I2C/SMBus driver. It implements six
  7. types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
  8. word data, (r/w) I2C block data, and (r/w) SMBus block data.
  9. You need to provide chip addresses as a module parameter when loading this
  10. driver, which will then only react to SMBus commands to these addresses.
  11. No hardware is needed nor associated with this module. It will accept write
  12. quick commands to the specified addresses; it will respond to the other
  13. commands (also to the specified addresses) by reading from or writing to
  14. arrays in memory. It will also spam the kernel logs for every command it
  15. handles.
  16. A pointer register with auto-increment is implemented for all byte
  17. operations. This allows for continuous byte reads like those supported by
  18. EEPROMs, among others.
  19. SMBus block command support is disabled by default, and must be enabled
  20. explicitly by setting the respective bits (0x03000000) in the functionality
  21. module parameter.
  22. SMBus block commands must be written to configure an SMBus command for
  23. SMBus block operations. Writes can be partial. Block read commands always
  24. return the number of bytes selected with the largest write so far.
  25. The typical use-case is like this:
  26. 1. load this module
  27. 2. use i2cset (from the i2c-tools project) to pre-load some data
  28. 3. load the target chip driver module
  29. 4. observe its behavior in the kernel log
  30. There's a script named i2c-stub-from-dump in the i2c-tools package which
  31. can load register values automatically from a chip dump.
  32. Parameters
  33. ==========
  34. int chip_addr[10]:
  35. The SMBus addresses to emulate chips at.
  36. unsigned long functionality:
  37. Functionality override, to disable some commands. See I2C_FUNC_*
  38. constants in <linux/i2c.h> for the suitable values. For example,
  39. value 0x1f0000 would only enable the quick, byte and byte data
  40. commands.
  41. u8 bank_reg[10], u8 bank_mask[10], u8 bank_start[10], u8 bank_end[10]:
  42. Optional bank settings. They tell which bits in which register
  43. select the active bank, as well as the range of banked registers.
  44. Caveats
  45. =======
  46. If your target driver polls some byte or word waiting for it to change, the
  47. stub could lock it up. Use i2cset to unlock it.
  48. If you spam it hard enough, printk can be lossy. This module really wants
  49. something like relayfs.