18c2ecf20Sopenharmony_ci========
28c2ecf20Sopenharmony_cii2c-stub
38c2ecf20Sopenharmony_ci========
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciDescription
68c2ecf20Sopenharmony_ci===========
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciThis module is a very simple fake I2C/SMBus driver.  It implements six
98c2ecf20Sopenharmony_citypes of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
108c2ecf20Sopenharmony_ciword data, (r/w) I2C block data, and (r/w) SMBus block data.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciYou need to provide chip addresses as a module parameter when loading this
138c2ecf20Sopenharmony_cidriver, which will then only react to SMBus commands to these addresses.
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciNo hardware is needed nor associated with this module.  It will accept write
168c2ecf20Sopenharmony_ciquick commands to the specified addresses; it will respond to the other
178c2ecf20Sopenharmony_cicommands (also to the specified addresses) by reading from or writing to
188c2ecf20Sopenharmony_ciarrays in memory.  It will also spam the kernel logs for every command it
198c2ecf20Sopenharmony_cihandles.
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciA pointer register with auto-increment is implemented for all byte
228c2ecf20Sopenharmony_cioperations.  This allows for continuous byte reads like those supported by
238c2ecf20Sopenharmony_ciEEPROMs, among others.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciSMBus block command support is disabled by default, and must be enabled
268c2ecf20Sopenharmony_ciexplicitly by setting the respective bits (0x03000000) in the functionality
278c2ecf20Sopenharmony_cimodule parameter.
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciSMBus block commands must be written to configure an SMBus command for
308c2ecf20Sopenharmony_ciSMBus block operations. Writes can be partial. Block read commands always
318c2ecf20Sopenharmony_cireturn the number of bytes selected with the largest write so far.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciThe typical use-case is like this:
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	1. load this module
368c2ecf20Sopenharmony_ci	2. use i2cset (from the i2c-tools project) to pre-load some data
378c2ecf20Sopenharmony_ci	3. load the target chip driver module
388c2ecf20Sopenharmony_ci	4. observe its behavior in the kernel log
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciThere's a script named i2c-stub-from-dump in the i2c-tools package which
418c2ecf20Sopenharmony_cican load register values automatically from a chip dump.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciParameters
448c2ecf20Sopenharmony_ci==========
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciint chip_addr[10]:
478c2ecf20Sopenharmony_ci	The SMBus addresses to emulate chips at.
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciunsigned long functionality:
508c2ecf20Sopenharmony_ci	Functionality override, to disable some commands. See I2C_FUNC_*
518c2ecf20Sopenharmony_ci	constants in <linux/i2c.h> for the suitable values. For example,
528c2ecf20Sopenharmony_ci	value 0x1f0000 would only enable the quick, byte and byte data
538c2ecf20Sopenharmony_ci	commands.
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciu8 bank_reg[10], u8 bank_mask[10], u8 bank_start[10], u8 bank_end[10]:
568c2ecf20Sopenharmony_ci	Optional bank settings. They tell which bits in which register
578c2ecf20Sopenharmony_ci	select the active bank, as well as the range of banked registers.
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciCaveats
608c2ecf20Sopenharmony_ci=======
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciIf your target driver polls some byte or word waiting for it to change, the
638c2ecf20Sopenharmony_cistub could lock it up.  Use i2cset to unlock it.
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciIf you spam it hard enough, printk can be lossy.  This module really wants
668c2ecf20Sopenharmony_cisomething like relayfs.
67