xref: /OK3568_Linux_fs/kernel/Documentation/i2c/i2c-stub.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun========
2*4882a593Smuzhiyuni2c-stub
3*4882a593Smuzhiyun========
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunDescription
6*4882a593Smuzhiyun===========
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunThis module is a very simple fake I2C/SMBus driver.  It implements six
9*4882a593Smuzhiyuntypes of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
10*4882a593Smuzhiyunword data, (r/w) I2C block data, and (r/w) SMBus block data.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunYou need to provide chip addresses as a module parameter when loading this
13*4882a593Smuzhiyundriver, which will then only react to SMBus commands to these addresses.
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunNo hardware is needed nor associated with this module.  It will accept write
16*4882a593Smuzhiyunquick commands to the specified addresses; it will respond to the other
17*4882a593Smuzhiyuncommands (also to the specified addresses) by reading from or writing to
18*4882a593Smuzhiyunarrays in memory.  It will also spam the kernel logs for every command it
19*4882a593Smuzhiyunhandles.
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunA pointer register with auto-increment is implemented for all byte
22*4882a593Smuzhiyunoperations.  This allows for continuous byte reads like those supported by
23*4882a593SmuzhiyunEEPROMs, among others.
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunSMBus block command support is disabled by default, and must be enabled
26*4882a593Smuzhiyunexplicitly by setting the respective bits (0x03000000) in the functionality
27*4882a593Smuzhiyunmodule parameter.
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunSMBus block commands must be written to configure an SMBus command for
30*4882a593SmuzhiyunSMBus block operations. Writes can be partial. Block read commands always
31*4882a593Smuzhiyunreturn the number of bytes selected with the largest write so far.
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunThe typical use-case is like this:
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun	1. load this module
36*4882a593Smuzhiyun	2. use i2cset (from the i2c-tools project) to pre-load some data
37*4882a593Smuzhiyun	3. load the target chip driver module
38*4882a593Smuzhiyun	4. observe its behavior in the kernel log
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunThere's a script named i2c-stub-from-dump in the i2c-tools package which
41*4882a593Smuzhiyuncan load register values automatically from a chip dump.
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunParameters
44*4882a593Smuzhiyun==========
45*4882a593Smuzhiyun
46*4882a593Smuzhiyunint chip_addr[10]:
47*4882a593Smuzhiyun	The SMBus addresses to emulate chips at.
48*4882a593Smuzhiyun
49*4882a593Smuzhiyununsigned long functionality:
50*4882a593Smuzhiyun	Functionality override, to disable some commands. See I2C_FUNC_*
51*4882a593Smuzhiyun	constants in <linux/i2c.h> for the suitable values. For example,
52*4882a593Smuzhiyun	value 0x1f0000 would only enable the quick, byte and byte data
53*4882a593Smuzhiyun	commands.
54*4882a593Smuzhiyun
55*4882a593Smuzhiyunu8 bank_reg[10], u8 bank_mask[10], u8 bank_start[10], u8 bank_end[10]:
56*4882a593Smuzhiyun	Optional bank settings. They tell which bits in which register
57*4882a593Smuzhiyun	select the active bank, as well as the range of banked registers.
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunCaveats
60*4882a593Smuzhiyun=======
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunIf your target driver polls some byte or word waiting for it to change, the
63*4882a593Smuzhiyunstub could lock it up.  Use i2cset to unlock it.
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunIf you spam it hard enough, printk can be lossy.  This module really wants
66*4882a593Smuzhiyunsomething like relayfs.
67