i2c-stub 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. MODULE: i2c-stub
  2. DESCRIPTION:
  3. This module is a very simple fake I2C/SMBus driver. It implements five
  4. types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
  5. word data, and (r/w) I2C 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. The typical use-case is like this:
  17. 1. load this module
  18. 2. use i2cset (from the i2c-tools project) to pre-load some data
  19. 3. load the target chip driver module
  20. 4. observe its behavior in the kernel log
  21. There's a script named i2c-stub-from-dump in the i2c-tools package which
  22. can load register values automatically from a chip dump.
  23. PARAMETERS:
  24. int chip_addr[10]:
  25. The SMBus addresses to emulate chips at.
  26. unsigned long functionality:
  27. Functionality override, to disable some commands. See I2C_FUNC_*
  28. constants in <linux/i2c.h> for the suitable values. For example,
  29. value 0x1f0000 would only enable the quick, byte and byte data
  30. commands.
  31. CAVEATS:
  32. If your target driver polls some byte or word waiting for it to change, the
  33. stub could lock it up. Use i2cset to unlock it.
  34. If the hardware for your driver has banked registers (e.g. Winbond sensors
  35. chips) this module will not work well - although it could be extended to
  36. support that pretty easily.
  37. If you spam it hard enough, printk can be lossy. This module really wants
  38. something like relayfs.