Mauro Carvalho Chehab | ccf988b | 2019-07-26 09:51:16 -0300 | [diff] [blame] | 1 | ======== |
| 2 | i2c-stub |
| 3 | ======== |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
Mauro Carvalho Chehab | ccf988b | 2019-07-26 09:51:16 -0300 | [diff] [blame] | 5 | Description |
| 6 | =========== |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
Guenter Roeck | 6f16b75 | 2014-07-17 09:56:03 -0700 | [diff] [blame] | 8 | This module is a very simple fake I2C/SMBus driver. It implements six |
Jean Delvare | 4710317 | 2009-12-06 17:06:28 +0100 | [diff] [blame] | 9 | types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w) |
Guenter Roeck | 6f16b75 | 2014-07-17 09:56:03 -0700 | [diff] [blame] | 10 | word data, (r/w) I2C block data, and (r/w) SMBus block data. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Jean Delvare | 9d90c1f | 2007-10-13 23:56:31 +0200 | [diff] [blame] | 12 | You need to provide chip addresses as a module parameter when loading this |
| 13 | driver, which will then only react to SMBus commands to these addresses. |
Jean Delvare | 7a8d29c | 2006-08-13 23:46:44 +0200 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | No hardware is needed nor associated with this module. It will accept write |
Jean Delvare | 9d90c1f | 2007-10-13 23:56:31 +0200 | [diff] [blame] | 16 | quick commands to the specified addresses; it will respond to the other |
| 17 | commands (also to the specified addresses) by reading from or writing to |
| 18 | arrays in memory. It will also spam the kernel logs for every command it |
| 19 | handles. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | A pointer register with auto-increment is implemented for all byte |
| 22 | operations. This allows for continuous byte reads like those supported by |
| 23 | EEPROMs, among others. |
| 24 | |
Guenter Roeck | 6f16b75 | 2014-07-17 09:56:03 -0700 | [diff] [blame] | 25 | SMBus block command support is disabled by default, and must be enabled |
| 26 | explicitly by setting the respective bits (0x03000000) in the functionality |
| 27 | module parameter. |
| 28 | |
| 29 | SMBus block commands must be written to configure an SMBus command for |
| 30 | SMBus block operations. Writes can be partial. Block read commands always |
| 31 | return the number of bytes selected with the largest write so far. |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | The typical use-case is like this: |
Mauro Carvalho Chehab | ccf988b | 2019-07-26 09:51:16 -0300 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | 1. load this module |
Jean Delvare | 6471b68 | 2009-12-06 17:06:30 +0100 | [diff] [blame] | 36 | 2. use i2cset (from the i2c-tools project) to pre-load some data |
| 37 | 3. load the target chip driver module |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | 4. observe its behavior in the kernel log |
| 39 | |
Jean Delvare | b3af547 | 2008-01-27 18:14:45 +0100 | [diff] [blame] | 40 | There's a script named i2c-stub-from-dump in the i2c-tools package which |
| 41 | can load register values automatically from a chip dump. |
| 42 | |
Mauro Carvalho Chehab | ccf988b | 2019-07-26 09:51:16 -0300 | [diff] [blame] | 43 | Parameters |
| 44 | ========== |
Jean Delvare | 7a8d29c | 2006-08-13 23:46:44 +0200 | [diff] [blame] | 45 | |
Jean Delvare | 9d90c1f | 2007-10-13 23:56:31 +0200 | [diff] [blame] | 46 | int chip_addr[10]: |
| 47 | The SMBus addresses to emulate chips at. |
Jean Delvare | 7a8d29c | 2006-08-13 23:46:44 +0200 | [diff] [blame] | 48 | |
Jean Delvare | 38f41f2 | 2009-12-06 17:06:29 +0100 | [diff] [blame] | 49 | unsigned 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 Chehab | ccf988b | 2019-07-26 09:51:16 -0300 | [diff] [blame] | 55 | u8 bank_reg[10], u8 bank_mask[10], u8 bank_start[10], u8 bank_end[10]: |
Jean Delvare | 2408c17 | 2014-07-10 12:56:59 +0200 | [diff] [blame] | 56 | 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 Chehab | ccf988b | 2019-07-26 09:51:16 -0300 | [diff] [blame] | 59 | Caveats |
| 60 | ======= |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | If your target driver polls some byte or word waiting for it to change, the |
| 63 | stub could lock it up. Use i2cset to unlock it. |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | If you spam it hard enough, printk can be lossy. This module really wants |
| 66 | something like relayfs. |