i2c-stub 2.3 KB

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