blob: a6fc6916d6bc76d15748f0dd823f2ae6a2bf8b26 [file] [log] [blame]
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -03001========
2i2c-stub
3========
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -03005Description
6===========
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Guenter Roeck6f16b752014-07-17 09:56:03 -07008This module is a very simple fake I2C/SMBus driver. It implements six
Jean Delvare47103172009-12-06 17:06:28 +01009types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
Guenter Roeck6f16b752014-07-17 09:56:03 -070010word data, (r/w) I2C block data, and (r/w) SMBus block data.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Jean Delvare9d90c1f2007-10-13 23:56:31 +020012You need to provide chip addresses as a module parameter when loading this
13driver, which will then only react to SMBus commands to these addresses.
Jean Delvare7a8d29c2006-08-13 23:46:44 +020014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015No hardware is needed nor associated with this module. It will accept write
Jean Delvare9d90c1f2007-10-13 23:56:31 +020016quick commands to the specified addresses; it will respond to the other
17commands (also to the specified addresses) by reading from or writing to
18arrays in memory. It will also spam the kernel logs for every command it
19handles.
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21A pointer register with auto-increment is implemented for all byte
22operations. This allows for continuous byte reads like those supported by
23EEPROMs, among others.
24
Guenter Roeck6f16b752014-07-17 09:56:03 -070025SMBus block command support is disabled by default, and must be enabled
26explicitly by setting the respective bits (0x03000000) in the functionality
27module parameter.
28
29SMBus block commands must be written to configure an SMBus command for
30SMBus block operations. Writes can be partial. Block read commands always
31return the number of bytes selected with the largest write so far.
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033The typical use-case is like this:
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 1. load this module
Jean Delvare6471b682009-12-06 17:06:30 +010036 2. use i2cset (from the i2c-tools project) to pre-load some data
37 3. load the target chip driver module
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 4. observe its behavior in the kernel log
39
Jean Delvareb3af5472008-01-27 18:14:45 +010040There's a script named i2c-stub-from-dump in the i2c-tools package which
41can load register values automatically from a chip dump.
42
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030043Parameters
44==========
Jean Delvare7a8d29c2006-08-13 23:46:44 +020045
Jean Delvare9d90c1f2007-10-13 23:56:31 +020046int chip_addr[10]:
47 The SMBus addresses to emulate chips at.
Jean Delvare7a8d29c2006-08-13 23:46:44 +020048
Jean Delvare38f41f22009-12-06 17:06:29 +010049unsigned long functionality:
50 Functionality override, to disable some commands. See I2C_FUNC_*
51 constants in <linux/i2c.h> for the suitable values. For example,
52 value 0x1f0000 would only enable the quick, byte and byte data
53 commands.
54
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030055u8 bank_reg[10], u8 bank_mask[10], u8 bank_start[10], u8 bank_end[10]:
Jean Delvare2408c172014-07-10 12:56:59 +020056 Optional bank settings. They tell which bits in which register
57 select the active bank, as well as the range of banked registers.
58
Mauro Carvalho Chehabccf988b2019-07-26 09:51:16 -030059Caveats
60=======
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062If your target driver polls some byte or word waiting for it to change, the
63stub could lock it up. Use i2cset to unlock it.
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065If you spam it hard enough, printk can be lossy. This module really wants
66something like relayfs.