aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/i2c')
-rw-r--r--Documentation/i2c/busses/i2c-i81047
-rw-r--r--Documentation/i2c/busses/i2c-prosavage23
-rw-r--r--Documentation/i2c/busses/i2c-savage426
-rw-r--r--Documentation/i2c/chips/max68752
-rw-r--r--Documentation/i2c/chips/pca953910
-rw-r--r--Documentation/i2c/chips/pcf857412
-rw-r--r--Documentation/i2c/chips/pcf85759
-rw-r--r--Documentation/i2c/fault-codes127
-rw-r--r--Documentation/i2c/functionality95
-rw-r--r--Documentation/i2c/smbus-protocol81
-rw-r--r--Documentation/i2c/upgrading-clients281
-rw-r--r--Documentation/i2c/writing-clients69
12 files changed, 578 insertions, 204 deletions
diff --git a/Documentation/i2c/busses/i2c-i810 b/Documentation/i2c/busses/i2c-i810
deleted file mode 100644
index 778210ee1583..000000000000
--- a/Documentation/i2c/busses/i2c-i810
+++ /dev/null
@@ -1,47 +0,0 @@
1Kernel driver i2c-i810
2
3Supported adapters:
4 * Intel 82810, 82810-DC100, 82810E, and 82815 (GMCH)
5 * Intel 82845G (GMCH)
6
7Authors:
8 Frodo Looijaard <frodol@dds.nl>,
9 Philip Edelbrock <phil@netroedge.com>,
10 Kyösti Mälkki <kmalkki@cc.hut.fi>,
11 Ralph Metzler <rjkm@thp.uni-koeln.de>,
12 Mark D. Studebaker <mdsxyz123@yahoo.com>
13
14Main contact: Mark Studebaker <mdsxyz123@yahoo.com>
15
16Description
17-----------
18
19WARNING: If you have an '810' or '815' motherboard, your standard I2C
20temperature sensors are most likely on the 801's I2C bus. You want the
21i2c-i801 driver for those, not this driver.
22
23Now for the i2c-i810...
24
25The GMCH chip contains two I2C interfaces.
26
27The first interface is used for DDC (Data Display Channel) which is a
28serial channel through the VGA monitor connector to a DDC-compliant
29monitor. This interface is defined by the Video Electronics Standards
30Association (VESA). The standards are available for purchase at
31http://www.vesa.org .
32
33The second interface is a general-purpose I2C bus. It may be connected to a
34TV-out chip such as the BT869 or possibly to a digital flat-panel display.
35
36Features
37--------
38
39Both busses use the i2c-algo-bit driver for 'bit banging'
40and support for specific transactions is provided by i2c-algo-bit.
41
42Issues
43------
44
45If you enable bus testing in i2c-algo-bit (insmod i2c-algo-bit bit_test=1),
46the test may fail; if so, the i2c-i810 driver won't be inserted. However,
47we think this has been fixed.
diff --git a/Documentation/i2c/busses/i2c-prosavage b/Documentation/i2c/busses/i2c-prosavage
deleted file mode 100644
index 703687902511..000000000000
--- a/Documentation/i2c/busses/i2c-prosavage
+++ /dev/null
@@ -1,23 +0,0 @@
1Kernel driver i2c-prosavage
2
3Supported adapters:
4
5 S3/VIA KM266/VT8375 aka ProSavage8
6 S3/VIA KM133/VT8365 aka Savage4
7
8Author: Henk Vergonet <henk@god.dyndns.org>
9
10Description
11-----------
12
13The Savage4 chips contain two I2C interfaces (aka a I2C 'master' or
14'host').
15
16The first interface is used for DDC (Data Display Channel) which is a
17serial channel through the VGA monitor connector to a DDC-compliant
18monitor. This interface is defined by the Video Electronics Standards
19Association (VESA). The standards are available for purchase at
20http://www.vesa.org . The second interface is a general-purpose I2C bus.
21
22Usefull for gaining access to the TV Encoder chips.
23
diff --git a/Documentation/i2c/busses/i2c-savage4 b/Documentation/i2c/busses/i2c-savage4
deleted file mode 100644
index 6ecceab618d3..000000000000
--- a/Documentation/i2c/busses/i2c-savage4
+++ /dev/null
@@ -1,26 +0,0 @@
1Kernel driver i2c-savage4
2
3Supported adapters:
4 * Savage4
5 * Savage2000
6
7Authors:
8 Alexander Wold <awold@bigfoot.com>,
9 Mark D. Studebaker <mdsxyz123@yahoo.com>
10
11Description
12-----------
13
14The Savage4 chips contain two I2C interfaces (aka a I2C 'master'
15or 'host').
16
17The first interface is used for DDC (Data Display Channel) which is a
18serial channel through the VGA monitor connector to a DDC-compliant
19monitor. This interface is defined by the Video Electronics Standards
20Association (VESA). The standards are available for purchase at
21http://www.vesa.org . The DDC bus is not yet supported because its register
22is not directly memory-mapped.
23
24The second interface is a general-purpose I2C bus. This is the only
25interface supported by the driver at the moment.
26
diff --git a/Documentation/i2c/chips/max6875 b/Documentation/i2c/chips/max6875
index a0cd8af2f408..10ca43cd1a72 100644
--- a/Documentation/i2c/chips/max6875
+++ b/Documentation/i2c/chips/max6875
@@ -49,7 +49,7 @@ $ modprobe max6875 force=0,0x50
49 49
50The MAX6874/MAX6875 ignores address bit 0, so this driver attaches to multiple 50The MAX6874/MAX6875 ignores address bit 0, so this driver attaches to multiple
51addresses. For example, for address 0x50, it also reserves 0x51. 51addresses. For example, for address 0x50, it also reserves 0x51.
52The even-address instance is called 'max6875', the odd one is 'max6875 subclient'. 52The even-address instance is called 'max6875', the odd one is 'dummy'.
53 53
54 54
55Programming the chip using i2c-dev 55Programming the chip using i2c-dev
diff --git a/Documentation/i2c/chips/pca9539 b/Documentation/i2c/chips/pca9539
index 1d81c530c4a5..6aff890088b1 100644
--- a/Documentation/i2c/chips/pca9539
+++ b/Documentation/i2c/chips/pca9539
@@ -7,7 +7,7 @@ drivers/gpio/pca9539.c instead.
7Supported chips: 7Supported chips:
8 * Philips PCA9539 8 * Philips PCA9539
9 Prefix: 'pca9539' 9 Prefix: 'pca9539'
10 Addresses scanned: 0x74 - 0x77 10 Addresses scanned: none
11 Datasheet: 11 Datasheet:
12 http://www.semiconductors.philips.com/acrobat/datasheets/PCA9539_2.pdf 12 http://www.semiconductors.philips.com/acrobat/datasheets/PCA9539_2.pdf
13 13
@@ -23,6 +23,14 @@ The input sense can also be inverted.
23The 16 lines are split between two bytes. 23The 16 lines are split between two bytes.
24 24
25 25
26Detection
27---------
28
29The PCA9539 is difficult to detect and not commonly found in PC machines,
30so you have to pass the I2C bus and address of the installed PCA9539
31devices explicitly to the driver at load time via the force=... parameter.
32
33
26Sysfs entries 34Sysfs entries
27------------- 35-------------
28 36
diff --git a/Documentation/i2c/chips/pcf8574 b/Documentation/i2c/chips/pcf8574
index 5c1ad1376b62..235815c075ff 100644
--- a/Documentation/i2c/chips/pcf8574
+++ b/Documentation/i2c/chips/pcf8574
@@ -4,13 +4,13 @@ Kernel driver pcf8574
4Supported chips: 4Supported chips:
5 * Philips PCF8574 5 * Philips PCF8574
6 Prefix: 'pcf8574' 6 Prefix: 'pcf8574'
7 Addresses scanned: I2C 0x20 - 0x27 7 Addresses scanned: none
8 Datasheet: Publicly available at the Philips Semiconductors website 8 Datasheet: Publicly available at the Philips Semiconductors website
9 http://www.semiconductors.philips.com/pip/PCF8574P.html 9 http://www.semiconductors.philips.com/pip/PCF8574P.html
10 10
11 * Philips PCF8574A 11 * Philips PCF8574A
12 Prefix: 'pcf8574a' 12 Prefix: 'pcf8574a'
13 Addresses scanned: I2C 0x38 - 0x3f 13 Addresses scanned: none
14 Datasheet: Publicly available at the Philips Semiconductors website 14 Datasheet: Publicly available at the Philips Semiconductors website
15 http://www.semiconductors.philips.com/pip/PCF8574P.html 15 http://www.semiconductors.philips.com/pip/PCF8574P.html
16 16
@@ -38,12 +38,10 @@ For more informations see the datasheet.
38Accessing PCF8574(A) via /sys interface 38Accessing PCF8574(A) via /sys interface
39------------------------------------- 39-------------------------------------
40 40
41! Be careful !
42The PCF8574(A) is plainly impossible to detect ! Stupid chip. 41The PCF8574(A) is plainly impossible to detect ! Stupid chip.
43So every chip with address in the interval [20..27] and [38..3f] are 42So, you have to pass the I2C bus and address of the installed PCF857A
44detected as PCF8574(A). If you have other chips in this address 43and PCF8574A devices explicitly to the driver at load time via the
45range, the workaround is to load this module after the one 44force=... parameter.
46for your others chips.
47 45
48On detection (i.e. insmod, modprobe et al.), directories are being 46On detection (i.e. insmod, modprobe et al.), directories are being
49created for each detected PCF8574(A): 47created for each detected PCF8574(A):
diff --git a/Documentation/i2c/chips/pcf8575 b/Documentation/i2c/chips/pcf8575
index 25f5698a61cf..40b268eb276f 100644
--- a/Documentation/i2c/chips/pcf8575
+++ b/Documentation/i2c/chips/pcf8575
@@ -40,12 +40,9 @@ Detection
40--------- 40---------
41 41
42There is no method known to detect whether a chip on a given I2C address is 42There is no method known to detect whether a chip on a given I2C address is
43a PCF8575 or whether it is any other I2C device. So there are two alternatives 43a PCF8575 or whether it is any other I2C device, so you have to pass the I2C
44to let the driver find the installed PCF8575 devices: 44bus and address of the installed PCF8575 devices explicitly to the driver at
45- Load this driver after any other I2C driver for I2C devices with addresses 45load time via the force=... parameter.
46 in the range 0x20 .. 0x27.
47- Pass the I2C bus and address of the installed PCF8575 devices explicitly to
48 the driver at load time via the probe=... or force=... parameters.
49 46
50/sys interface 47/sys interface
51-------------- 48--------------
diff --git a/Documentation/i2c/fault-codes b/Documentation/i2c/fault-codes
new file mode 100644
index 000000000000..045765c0b9b5
--- /dev/null
+++ b/Documentation/i2c/fault-codes
@@ -0,0 +1,127 @@
1This is a summary of the most important conventions for use of fault
2codes in the I2C/SMBus stack.
3
4
5A "Fault" is not always an "Error"
6----------------------------------
7Not all fault reports imply errors; "page faults" should be a familiar
8example. Software often retries idempotent operations after transient
9faults. There may be fancier recovery schemes that are appropriate in
10some cases, such as re-initializing (and maybe resetting). After such
11recovery, triggered by a fault report, there is no error.
12
13In a similar way, sometimes a "fault" code just reports one defined
14result for an operation ... it doesn't indicate that anything is wrong
15at all, just that the outcome wasn't on the "golden path".
16
17In short, your I2C driver code may need to know these codes in order
18to respond correctly. Other code may need to rely on YOUR code reporting
19the right fault code, so that it can (in turn) behave correctly.
20
21
22I2C and SMBus fault codes
23-------------------------
24These are returned as negative numbers from most calls, with zero or
25some positive number indicating a non-fault return. The specific
26numbers associated with these symbols differ between architectures,
27though most Linux systems use <asm-generic/errno*.h> numbering.
28
29Note that the descriptions here are not exhaustive. There are other
30codes that may be returned, and other cases where these codes should
31be returned. However, drivers should not return other codes for these
32cases (unless the hardware doesn't provide unique fault reports).
33
34Also, codes returned by adapter probe methods follow rules which are
35specific to their host bus (such as PCI, or the platform bus).
36
37
38EAGAIN
39 Returned by I2C adapters when they lose arbitration in master
40 transmit mode: some other master was transmitting different
41 data at the same time.
42
43 Also returned when trying to invoke an I2C operation in an
44 atomic context, when some task is already using that I2C bus
45 to execute some other operation.
46
47EBADMSG
48 Returned by SMBus logic when an invalid Packet Error Code byte
49 is received. This code is a CRC covering all bytes in the
50 transaction, and is sent before the terminating STOP. This
51 fault is only reported on read transactions; the SMBus slave
52 may have a way to report PEC mismatches on writes from the
53 host. Note that even if PECs are in use, you should not rely
54 on these as the only way to detect incorrect data transfers.
55
56EBUSY
57 Returned by SMBus adapters when the bus was busy for longer
58 than allowed. This usually indicates some device (maybe the
59 SMBus adapter) needs some fault recovery (such as resetting),
60 or that the reset was attempted but failed.
61
62EINVAL
63 This rather vague error means an invalid parameter has been
64 detected before any I/O operation was started. Use a more
65 specific fault code when you can.
66
67 One example would be a driver trying an SMBus Block Write
68 with block size outside the range of 1-32 bytes.
69
70EIO
71 This rather vague error means something went wrong when
72 performing an I/O operation. Use a more specific fault
73 code when you can.
74
75ENODEV
76 Returned by driver probe() methods. This is a bit more
77 specific than ENXIO, implying the problem isn't with the
78 address, but with the device found there. Driver probes
79 may verify the device returns *correct* responses, and
80 return this as appropriate. (The driver core will warn
81 about probe faults other than ENXIO and ENODEV.)
82
83ENOMEM
84 Returned by any component that can't allocate memory when
85 it needs to do so.
86
87ENXIO
88 Returned by I2C adapters to indicate that the address phase
89 of a transfer didn't get an ACK. While it might just mean
90 an I2C device was temporarily not responding, usually it
91 means there's nothing listening at that address.
92
93 Returned by driver probe() methods to indicate that they
94 found no device to bind to. (ENODEV may also be used.)
95
96EOPNOTSUPP
97 Returned by an adapter when asked to perform an operation
98 that it doesn't, or can't, support.
99
100 For example, this would be returned when an adapter that
101 doesn't support SMBus block transfers is asked to execute
102 one. In that case, the driver making that request should
103 have verified that functionality was supported before it
104 made that block transfer request.
105
106 Similarly, if an I2C adapter can't execute all legal I2C
107 messages, it should return this when asked to perform a
108 transaction it can't. (These limitations can't be seen in
109 the adapter's functionality mask, since the assumption is
110 that if an adapter supports I2C it supports all of I2C.)
111
112EPROTO
113 Returned when slave does not conform to the relevant I2C
114 or SMBus (or chip-specific) protocol specifications. One
115 case is when the length of an SMBus block data response
116 (from the SMBus slave) is outside the range 1-32 bytes.
117
118ETIMEDOUT
119 This is returned by drivers when an operation took too much
120 time, and was aborted before it completed.
121
122 SMBus adapters may return it when an operation took more
123 time than allowed by the SMBus specification; for example,
124 when a slave stretches clocks too far. I2C has no such
125 timeouts, but it's normal for I2C adapters to impose some
126 arbitrary limits (much longer than SMBus!) too.
127
diff --git a/Documentation/i2c/functionality b/Documentation/i2c/functionality
index 60cca249e452..42c17c1fb3cd 100644
--- a/Documentation/i2c/functionality
+++ b/Documentation/i2c/functionality
@@ -51,26 +51,38 @@ A few combinations of the above flags are also defined for your convenience:
51 the transparent emulation layer) 51 the transparent emulation layer)
52 52
53 53
54ALGORITHM/ADAPTER IMPLEMENTATION 54ADAPTER IMPLEMENTATION
55-------------------------------- 55----------------------
56 56
57When you write a new algorithm driver, you will have to implement a 57When you write a new adapter driver, you will have to implement a
58function callback `functionality', that gets an i2c_adapter structure 58function callback `functionality'. Typical implementations are given
59pointer as its only parameter: 59below.
60 60
61 struct i2c_algorithm { 61A typical SMBus-only adapter would list all the SMBus transactions it
62 /* Many other things of course; check <linux/i2c.h>! */ 62supports. This example comes from the i2c-piix4 driver:
63 u32 (*functionality) (struct i2c_adapter *); 63
64 static u32 piix4_func(struct i2c_adapter *adapter)
65 {
66 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
67 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
68 I2C_FUNC_SMBUS_BLOCK_DATA;
64 } 69 }
65 70
66A typically implementation is given below, from i2c-algo-bit.c: 71A typical full-I2C adapter would use the following (from the i2c-pxa
72driver):
67 73
68 static u32 bit_func(struct i2c_adapter *adap) 74 static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
69 { 75 {
70 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 76 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
71 I2C_FUNC_PROTOCOL_MANGLING;
72 } 77 }
73 78
79I2C_FUNC_SMBUS_EMUL includes all the SMBus transactions (with the
80addition of I2C block transactions) which i2c-core can emulate using
81I2C_FUNC_I2C without any help from the adapter driver. The idea is
82to let the client drivers check for the support of SMBus functions
83without having to care whether the said functions are implemented in
84hardware by the adapter, or emulated in software by i2c-core on top
85of an I2C adapter.
74 86
75 87
76CLIENT CHECKING 88CLIENT CHECKING
@@ -78,36 +90,33 @@ CLIENT CHECKING
78 90
79Before a client tries to attach to an adapter, or even do tests to check 91Before a client tries to attach to an adapter, or even do tests to check
80whether one of the devices it supports is present on an adapter, it should 92whether one of the devices it supports is present on an adapter, it should
81check whether the needed functionality is present. There are two functions 93check whether the needed functionality is present. The typical way to do
82defined which should be used instead of calling the functionality hook 94this is (from the lm75 driver):
83in the algorithm structure directly:
84
85 /* Return the functionality mask */
86 extern u32 i2c_get_functionality (struct i2c_adapter *adap);
87
88 /* Return 1 if adapter supports everything we need, 0 if not. */
89 extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
90 95
91This is a typical way to use these functions (from the writing-clients 96 static int lm75_detect(...)
92document):
93 int foo_detect_client(struct i2c_adapter *adapter, int address,
94 unsigned short flags, int kind)
95 { 97 {
96 /* Define needed variables */ 98 (...)
97 99 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
98 /* As the very first action, we check whether the adapter has the 100 I2C_FUNC_SMBUS_WORD_DATA))
99 needed functionality: we need the SMBus read_word_data, 101 goto exit;
100 write_word_data and write_byte functions in this example. */ 102 (...)
101 if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA |
102 I2C_FUNC_SMBUS_WRITE_BYTE))
103 goto ERROR0;
104
105 /* Now we can do the real detection */
106
107 ERROR0:
108 /* Return an error */
109 } 103 }
110 104
105Here, the lm75 driver checks if the adapter can do both SMBus byte data
106and SMBus word data transactions. If not, then the driver won't work on
107this adapter and there's no point in going on. If the check above is
108successful, then the driver knows that it can call the following
109functions: i2c_smbus_read_byte_data(), i2c_smbus_write_byte_data(),
110i2c_smbus_read_word_data() and i2c_smbus_write_word_data(). As a rule of
111thumb, the functionality constants you test for with
112i2c_check_functionality() should match exactly the i2c_smbus_* functions
113which you driver is calling.
114
115Note that the check above doesn't tell whether the functionalities are
116implemented in hardware by the underlying adapter or emulated in
117software by i2c-core. Client drivers don't have to care about this, as
118i2c-core will transparently implement SMBus transactions on top of I2C
119adapters.
111 120
112 121
113CHECKING THROUGH /DEV 122CHECKING THROUGH /DEV
@@ -116,19 +125,19 @@ CHECKING THROUGH /DEV
116If you try to access an adapter from a userspace program, you will have 125If you try to access an adapter from a userspace program, you will have
117to use the /dev interface. You will still have to check whether the 126to use the /dev interface. You will still have to check whether the
118functionality you need is supported, of course. This is done using 127functionality you need is supported, of course. This is done using
119the I2C_FUNCS ioctl. An example, adapted from the lm_sensors i2cdetect 128the I2C_FUNCS ioctl. An example, adapted from the i2cdetect program, is
120program, is below: 129below:
121 130
122 int file; 131 int file;
123 if (file = open("/dev/i2c-0",O_RDWR) < 0) { 132 if (file = open("/dev/i2c-0", O_RDWR) < 0) {
124 /* Some kind of error handling */ 133 /* Some kind of error handling */
125 exit(1); 134 exit(1);
126 } 135 }
127 if (ioctl(file,I2C_FUNCS,&funcs) < 0) { 136 if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
128 /* Some kind of error handling */ 137 /* Some kind of error handling */
129 exit(1); 138 exit(1);
130 } 139 }
131 if (! (funcs & I2C_FUNC_SMBUS_QUICK)) { 140 if (!(funcs & I2C_FUNC_SMBUS_QUICK)) {
132 /* Oops, the needed functionality (SMBus write_quick function) is 141 /* Oops, the needed functionality (SMBus write_quick function) is
133 not available! */ 142 not available! */
134 exit(1); 143 exit(1);
diff --git a/Documentation/i2c/smbus-protocol b/Documentation/i2c/smbus-protocol
index 8a653c60d25a..24bfb65da17d 100644
--- a/Documentation/i2c/smbus-protocol
+++ b/Documentation/i2c/smbus-protocol
@@ -1,5 +1,6 @@
1SMBus Protocol Summary 1SMBus Protocol Summary
2====================== 2======================
3
3The following is a summary of the SMBus protocol. It applies to 4The following is a summary of the SMBus protocol. It applies to
4all revisions of the protocol (1.0, 1.1, and 2.0). 5all revisions of the protocol (1.0, 1.1, and 2.0).
5Certain protocol features which are not supported by 6Certain protocol features which are not supported by
@@ -8,6 +9,7 @@ this package are briefly described at the end of this document.
8Some adapters understand only the SMBus (System Management Bus) protocol, 9Some adapters understand only the SMBus (System Management Bus) protocol,
9which is a subset from the I2C protocol. Fortunately, many devices use 10which is a subset from the I2C protocol. Fortunately, many devices use
10only the same subset, which makes it possible to put them on an SMBus. 11only the same subset, which makes it possible to put them on an SMBus.
12
11If you write a driver for some I2C device, please try to use the SMBus 13If you write a driver for some I2C device, please try to use the SMBus
12commands if at all possible (if the device uses only that subset of the 14commands if at all possible (if the device uses only that subset of the
13I2C protocol). This makes it possible to use the device driver on both 15I2C protocol). This makes it possible to use the device driver on both
@@ -15,7 +17,12 @@ SMBus adapters and I2C adapters (the SMBus command set is automatically
15translated to I2C on I2C adapters, but plain I2C commands can not be 17translated to I2C on I2C adapters, but plain I2C commands can not be
16handled at all on most pure SMBus adapters). 18handled at all on most pure SMBus adapters).
17 19
18Below is a list of SMBus commands. 20Below is a list of SMBus protocol operations, and the functions executing
21them. Note that the names used in the SMBus protocol specifications usually
22don't match these function names. For some of the operations which pass a
23single data byte, the functions using SMBus protocol operation names execute
24a different protocol operation entirely.
25
19 26
20Key to symbols 27Key to symbols
21============== 28==============
@@ -35,17 +42,16 @@ Count (8 bits): A data byte containing the length of a block operation.
35[..]: Data sent by I2C device, as opposed to data sent by the host adapter. 42[..]: Data sent by I2C device, as opposed to data sent by the host adapter.
36 43
37 44
38SMBus Write Quick 45SMBus Quick Command
39================= 46===================
40 47
41This sends a single bit to the device, at the place of the Rd/Wr bit. 48This sends a single bit to the device, at the place of the Rd/Wr bit.
42There is no equivalent Read Quick command.
43 49
44A Addr Rd/Wr [A] P 50A Addr Rd/Wr [A] P
45 51
46 52
47SMBus Read Byte 53SMBus Receive Byte: i2c_smbus_read_byte()
48=============== 54==========================================
49 55
50This reads a single byte from a device, without specifying a device 56This reads a single byte from a device, without specifying a device
51register. Some devices are so simple that this interface is enough; for 57register. Some devices are so simple that this interface is enough; for
@@ -55,17 +61,17 @@ the previous SMBus command.
55S Addr Rd [A] [Data] NA P 61S Addr Rd [A] [Data] NA P
56 62
57 63
58SMBus Write Byte 64SMBus Send Byte: i2c_smbus_write_byte()
59================ 65========================================
60 66
61This is the reverse of Read Byte: it sends a single byte to a device. 67This operation is the reverse of Receive Byte: it sends a single byte
62See Read Byte for more information. 68to a device. See Receive Byte for more information.
63 69
64S Addr Wr [A] Data [A] P 70S Addr Wr [A] Data [A] P
65 71
66 72
67SMBus Read Byte Data 73SMBus Read Byte: i2c_smbus_read_byte_data()
68==================== 74============================================
69 75
70This reads a single byte from a device, from a designated register. 76This reads a single byte from a device, from a designated register.
71The register is specified through the Comm byte. 77The register is specified through the Comm byte.
@@ -73,30 +79,30 @@ The register is specified through the Comm byte.
73S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P 79S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P
74 80
75 81
76SMBus Read Word Data 82SMBus Read Word: i2c_smbus_read_word_data()
77==================== 83============================================
78 84
79This command is very like Read Byte Data; again, data is read from a 85This operation is very like Read Byte; again, data is read from a
80device, from a designated register that is specified through the Comm 86device, from a designated register that is specified through the Comm
81byte. But this time, the data is a complete word (16 bits). 87byte. But this time, the data is a complete word (16 bits).
82 88
83S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P 89S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
84 90
85 91
86SMBus Write Byte Data 92SMBus Write Byte: i2c_smbus_write_byte_data()
87===================== 93==============================================
88 94
89This writes a single byte to a device, to a designated register. The 95This writes a single byte to a device, to a designated register. The
90register is specified through the Comm byte. This is the opposite of 96register is specified through the Comm byte. This is the opposite of
91the Read Byte Data command. 97the Read Byte operation.
92 98
93S Addr Wr [A] Comm [A] Data [A] P 99S Addr Wr [A] Comm [A] Data [A] P
94 100
95 101
96SMBus Write Word Data 102SMBus Write Word: i2c_smbus_write_word_data()
97===================== 103==============================================
98 104
99This is the opposite operation of the Read Word Data command. 16 bits 105This is the opposite of the Read Word operation. 16 bits
100of data is written to a device, to the designated register that is 106of data is written to a device, to the designated register that is
101specified through the Comm byte. 107specified through the Comm byte.
102 108
@@ -113,8 +119,8 @@ S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
113 S Addr Rd [A] [DataLow] A [DataHigh] NA P 119 S Addr Rd [A] [DataLow] A [DataHigh] NA P
114 120
115 121
116SMBus Block Read 122SMBus Block Read: i2c_smbus_read_block_data()
117================ 123==============================================
118 124
119This command reads a block of up to 32 bytes from a device, from a 125This command reads a block of up to 32 bytes from a device, from a
120designated register that is specified through the Comm byte. The amount 126designated register that is specified through the Comm byte. The amount
@@ -124,8 +130,8 @@ S Addr Wr [A] Comm [A]
124 S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P 130 S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P
125 131
126 132
127SMBus Block Write 133SMBus Block Write: i2c_smbus_write_block_data()
128================= 134================================================
129 135
130The opposite of the Block Read command, this writes up to 32 bytes to 136The opposite of the Block Read command, this writes up to 32 bytes to
131a device, to a designated register that is specified through the 137a device, to a designated register that is specified through the
@@ -134,10 +140,11 @@ Comm byte. The amount of data is specified in the Count byte.
134S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P 140S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
135 141
136 142
137SMBus Block Process Call 143SMBus Block Write - Block Read Process Call
138======================== 144===========================================
139 145
140SMBus Block Process Call was introduced in Revision 2.0 of the specification. 146SMBus Block Write - Block Read Process Call was introduced in
147Revision 2.0 of the specification.
141 148
142This command selects a device register (through the Comm byte), sends 149This command selects a device register (through the Comm byte), sends
1431 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return. 1501 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return.
@@ -159,13 +166,16 @@ alerting device's address.
159 166
160Packet Error Checking (PEC) 167Packet Error Checking (PEC)
161=========================== 168===========================
169
162Packet Error Checking was introduced in Revision 1.1 of the specification. 170Packet Error Checking was introduced in Revision 1.1 of the specification.
163 171
164PEC adds a CRC-8 error-checking byte to all transfers. 172PEC adds a CRC-8 error-checking byte to transfers using it, immediately
173before the terminating STOP.
165 174
166 175
167Address Resolution Protocol (ARP) 176Address Resolution Protocol (ARP)
168================================= 177=================================
178
169The Address Resolution Protocol was introduced in Revision 2.0 of 179The Address Resolution Protocol was introduced in Revision 2.0 of
170the specification. It is a higher-layer protocol which uses the 180the specification. It is a higher-layer protocol which uses the
171messages above. 181messages above.
@@ -177,14 +187,17 @@ require PEC checksums.
177 187
178I2C Block Transactions 188I2C Block Transactions
179====================== 189======================
190
180The following I2C block transactions are supported by the 191The following I2C block transactions are supported by the
181SMBus layer and are described here for completeness. 192SMBus layer and are described here for completeness.
193They are *NOT* defined by the SMBus specification.
194
182I2C block transactions do not limit the number of bytes transferred 195I2C block transactions do not limit the number of bytes transferred
183but the SMBus layer places a limit of 32 bytes. 196but the SMBus layer places a limit of 32 bytes.
184 197
185 198
186I2C Block Read 199I2C Block Read: i2c_smbus_read_i2c_block_data()
187============== 200================================================
188 201
189This command reads a block of bytes from a device, from a 202This command reads a block of bytes from a device, from a
190designated register that is specified through the Comm byte. 203designated register that is specified through the Comm byte.
@@ -203,8 +216,8 @@ S Addr Wr [A] Comm1 [A] Comm2 [A]
203 S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P 216 S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
204 217
205 218
206I2C Block Write 219I2C Block Write: i2c_smbus_write_i2c_block_data()
207=============== 220==================================================
208 221
209The opposite of the Block Read command, this writes bytes to 222The opposite of the Block Read command, this writes bytes to
210a device, to a designated register that is specified through the 223a device, to a designated register that is specified through the
@@ -212,5 +225,3 @@ Comm byte. Note that command lengths of 0, 2, or more bytes are
212supported as they are indistinguishable from data. 225supported as they are indistinguishable from data.
213 226
214S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P 227S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
215
216
diff --git a/Documentation/i2c/upgrading-clients b/Documentation/i2c/upgrading-clients
new file mode 100644
index 000000000000..9a45f9bb6a25
--- /dev/null
+++ b/Documentation/i2c/upgrading-clients
@@ -0,0 +1,281 @@
1Upgrading I2C Drivers to the new 2.6 Driver Model
2=================================================
3
4Ben Dooks <ben-linux@fluff.org>
5
6Introduction
7------------
8
9This guide outlines how to alter existing Linux 2.6 client drivers from
10the old to the new new binding methods.
11
12
13Example old-style driver
14------------------------
15
16
17struct example_state {
18 struct i2c_client client;
19 ....
20};
21
22static struct i2c_driver example_driver;
23
24static unsigned short ignore[] = { I2C_CLIENT_END };
25static unsigned short normal_addr[] = { OUR_ADDR, I2C_CLIENT_END };
26
27I2C_CLIENT_INSMOD;
28
29static int example_attach(struct i2c_adapter *adap, int addr, int kind)
30{
31 struct example_state *state;
32 struct device *dev = &adap->dev; /* to use for dev_ reports */
33 int ret;
34
35 state = kzalloc(sizeof(struct example_state), GFP_KERNEL);
36 if (state == NULL) {
37 dev_err(dev, "failed to create our state\n");
38 return -ENOMEM;
39 }
40
41 example->client.addr = addr;
42 example->client.flags = 0;
43 example->client.adapter = adap;
44
45 i2c_set_clientdata(&state->i2c_client, state);
46 strlcpy(client->i2c_client.name, "example", I2C_NAME_SIZE);
47
48 ret = i2c_attach_client(&state->i2c_client);
49 if (ret < 0) {
50 dev_err(dev, "failed to attach client\n");
51 kfree(state);
52 return ret;
53 }
54
55 dev = &state->i2c_client.dev;
56
57 /* rest of the initialisation goes here. */
58
59 dev_info(dev, "example client created\n");
60
61 return 0;
62}
63
64static int __devexit example_detach(struct i2c_client *client)
65{
66 struct example_state *state = i2c_get_clientdata(client);
67
68 i2c_detach_client(client);
69 kfree(state);
70 return 0;
71}
72
73static int example_attach_adapter(struct i2c_adapter *adap)
74{
75 return i2c_probe(adap, &addr_data, example_attach);
76}
77
78static struct i2c_driver example_driver = {
79 .driver = {
80 .owner = THIS_MODULE,
81 .name = "example",
82 },
83 .attach_adapter = example_attach_adapter,
84 .detach_client = __devexit_p(example_detach),
85 .suspend = example_suspend,
86 .resume = example_resume,
87};
88
89
90Updating the client
91-------------------
92
93The new style binding model will check against a list of supported
94devices and their associated address supplied by the code registering
95the busses. This means that the driver .attach_adapter and
96.detach_adapter methods can be removed, along with the addr_data,
97as follows:
98
99- static struct i2c_driver example_driver;
100
101- static unsigned short ignore[] = { I2C_CLIENT_END };
102- static unsigned short normal_addr[] = { OUR_ADDR, I2C_CLIENT_END };
103
104- I2C_CLIENT_INSMOD;
105
106- static int example_attach_adapter(struct i2c_adapter *adap)
107- {
108- return i2c_probe(adap, &addr_data, example_attach);
109- }
110
111 static struct i2c_driver example_driver = {
112- .attach_adapter = example_attach_adapter,
113- .detach_client = __devexit_p(example_detach),
114 }
115
116Add the probe and remove methods to the i2c_driver, as so:
117
118 static struct i2c_driver example_driver = {
119+ .probe = example_probe,
120+ .remove = __devexit_p(example_remove),
121 }
122
123Change the example_attach method to accept the new parameters
124which include the i2c_client that it will be working with:
125
126- static int example_attach(struct i2c_adapter *adap, int addr, int kind)
127+ static int example_probe(struct i2c_client *client,
128+ const struct i2c_device_id *id)
129
130Change the name of example_attach to example_probe to align it with the
131i2c_driver entry names. The rest of the probe routine will now need to be
132changed as the i2c_client has already been setup for use.
133
134The necessary client fields have already been setup before
135the probe function is called, so the following client setup
136can be removed:
137
138- example->client.addr = addr;
139- example->client.flags = 0;
140- example->client.adapter = adap;
141-
142- strlcpy(client->i2c_client.name, "example", I2C_NAME_SIZE);
143
144The i2c_set_clientdata is now:
145
146- i2c_set_clientdata(&state->client, state);
147+ i2c_set_clientdata(client, state);
148
149The call to i2c_attach_client is no longer needed, if the probe
150routine exits successfully, then the driver will be automatically
151attached by the core. Change the probe routine as so:
152
153- ret = i2c_attach_client(&state->i2c_client);
154- if (ret < 0) {
155- dev_err(dev, "failed to attach client\n");
156- kfree(state);
157- return ret;
158- }
159
160
161Remove the storage of 'struct i2c_client' from the 'struct example_state'
162as we are provided with the i2c_client in our example_probe. Instead we
163store a pointer to it for when it is needed.
164
165struct example_state {
166- struct i2c_client client;
167+ struct i2c_client *client;
168
169the new i2c client as so:
170
171- struct device *dev = &adap->dev; /* to use for dev_ reports */
172+ struct device *dev = &i2c_client->dev; /* to use for dev_ reports */
173
174And remove the change after our client is attached, as the driver no
175longer needs to register a new client structure with the core:
176
177- dev = &state->i2c_client.dev;
178
179In the probe routine, ensure that the new state has the client stored
180in it:
181
182static int example_probe(struct i2c_client *i2c_client,
183 const struct i2c_device_id *id)
184{
185 struct example_state *state;
186 struct device *dev = &i2c_client->dev;
187 int ret;
188
189 state = kzalloc(sizeof(struct example_state), GFP_KERNEL);
190 if (state == NULL) {
191 dev_err(dev, "failed to create our state\n");
192 return -ENOMEM;
193 }
194
195+ state->client = i2c_client;
196
197Update the detach method, by changing the name to _remove and
198to delete the i2c_detach_client call. It is possible that you
199can also remove the ret variable as it is not not needed for
200any of the core functions.
201
202- static int __devexit example_detach(struct i2c_client *client)
203+ static int __devexit example_remove(struct i2c_client *client)
204{
205 struct example_state *state = i2c_get_clientdata(client);
206
207- i2c_detach_client(client);
208
209And finally ensure that we have the correct ID table for the i2c-core
210and other utilities:
211
212+ struct i2c_device_id example_idtable[] = {
213+ { "example", 0 },
214+ { }
215+};
216+
217+MODULE_DEVICE_TABLE(i2c, example_idtable);
218
219static struct i2c_driver example_driver = {
220 .driver = {
221 .owner = THIS_MODULE,
222 .name = "example",
223 },
224+ .id_table = example_ids,
225
226
227Our driver should now look like this:
228
229struct example_state {
230 struct i2c_client *client;
231 ....
232};
233
234static int example_probe(struct i2c_client *client,
235 const struct i2c_device_id *id)
236{
237 struct example_state *state;
238 struct device *dev = &client->dev;
239
240 state = kzalloc(sizeof(struct example_state), GFP_KERNEL);
241 if (state == NULL) {
242 dev_err(dev, "failed to create our state\n");
243 return -ENOMEM;
244 }
245
246 state->client = client;
247 i2c_set_clientdata(client, state);
248
249 /* rest of the initialisation goes here. */
250
251 dev_info(dev, "example client created\n");
252
253 return 0;
254}
255
256static int __devexit example_remove(struct i2c_client *client)
257{
258 struct example_state *state = i2c_get_clientdata(client);
259
260 kfree(state);
261 return 0;
262}
263
264static struct i2c_device_id example_idtable[] = {
265 { "example", 0 },
266 { }
267};
268
269MODULE_DEVICE_TABLE(i2c, example_idtable);
270
271static struct i2c_driver example_driver = {
272 .driver = {
273 .owner = THIS_MODULE,
274 .name = "example",
275 },
276 .id_table = example_idtable,
277 .probe = example_probe,
278 .remove = __devexit_p(example_remove),
279 .suspend = example_suspend,
280 .resume = example_resume,
281};
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index ee75cbace28d..6b61b3a2e90b 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -25,14 +25,29 @@ routines, and should be zero-initialized except for fields with data you
25provide. A client structure holds device-specific information like the 25provide. A client structure holds device-specific information like the
26driver model device node, and its I2C address. 26driver model device node, and its I2C address.
27 27
28/* iff driver uses driver model ("new style") binding model: */
29
30static struct i2c_device_id foo_idtable[] = {
31 { "foo", my_id_for_foo },
32 { "bar", my_id_for_bar },
33 { }
34};
35
36MODULE_DEVICE_TABLE(i2c, foo_idtable);
37
28static struct i2c_driver foo_driver = { 38static struct i2c_driver foo_driver = {
29 .driver = { 39 .driver = {
30 .name = "foo", 40 .name = "foo",
31 }, 41 },
32 42
33 /* iff driver uses driver model ("new style") binding model: */ 43 /* iff driver uses driver model ("new style") binding model: */
44 .id_table = foo_ids,
34 .probe = foo_probe, 45 .probe = foo_probe,
35 .remove = foo_remove, 46 .remove = foo_remove,
47 /* if device autodetection is needed: */
48 .class = I2C_CLASS_SOMETHING,
49 .detect = foo_detect,
50 .address_data = &addr_data,
36 51
37 /* else, driver uses "legacy" binding model: */ 52 /* else, driver uses "legacy" binding model: */
38 .attach_adapter = foo_attach_adapter, 53 .attach_adapter = foo_attach_adapter,
@@ -173,10 +188,9 @@ handle may be used during foo_probe(). If foo_probe() reports success
173(zero not a negative status code) it may save the handle and use it until 188(zero not a negative status code) it may save the handle and use it until
174foo_remove() returns. That binding model is used by most Linux drivers. 189foo_remove() returns. That binding model is used by most Linux drivers.
175 190
176Drivers match devices when i2c_client.driver_name and the driver name are 191The probe function is called when an entry in the id_table name field
177the same; this approach is used in several other busses that don't have 192matches the device's name. It is passed the entry that was matched so
178device typing support in the hardware. The driver and module name should 193the driver knows which one in the table matched.
179match, so hotplug/coldplug mechanisms will modprobe the driver.
180 194
181 195
182Device Creation (Standard driver model) 196Device Creation (Standard driver model)
@@ -207,6 +221,31 @@ in the I2C bus driver. You may want to save the returned i2c_client
207reference for later use. 221reference for later use.
208 222
209 223
224Device Detection (Standard driver model)
225----------------------------------------
226
227Sometimes you do not know in advance which I2C devices are connected to
228a given I2C bus. This is for example the case of hardware monitoring
229devices on a PC's SMBus. In that case, you may want to let your driver
230detect supported devices automatically. This is how the legacy model
231was working, and is now available as an extension to the standard
232driver model (so that we can finally get rid of the legacy model.)
233
234You simply have to define a detect callback which will attempt to
235identify supported devices (returning 0 for supported ones and -ENODEV
236for unsupported ones), a list of addresses to probe, and a device type
237(or class) so that only I2C buses which may have that type of device
238connected (and not otherwise enumerated) will be probed. The i2c
239core will then call you back as needed and will instantiate a device
240for you for every successful detection.
241
242Note that this mechanism is purely optional and not suitable for all
243devices. You need some reliable way to identify the supported devices
244(typically using device-specific, dedicated identification registers),
245otherwise misdetections are likely to occur and things can get wrong
246quickly.
247
248
210Device Deletion (Standard driver model) 249Device Deletion (Standard driver model)
211--------------------------------------- 250---------------------------------------
212 251
@@ -559,7 +598,6 @@ SMBus communication
559 in terms of it. Never use this function directly! 598 in terms of it. Never use this function directly!
560 599
561 600
562 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value);
563 extern s32 i2c_smbus_read_byte(struct i2c_client * client); 601 extern s32 i2c_smbus_read_byte(struct i2c_client * client);
564 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value); 602 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value);
565 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command); 603 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command);
@@ -568,30 +606,31 @@ SMBus communication
568 extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); 606 extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command);
569 extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 607 extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
570 u8 command, u16 value); 608 u8 command, u16 value);
609 extern s32 i2c_smbus_read_block_data(struct i2c_client * client,
610 u8 command, u8 *values);
571 extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 611 extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
572 u8 command, u8 length, 612 u8 command, u8 length,
573 u8 *values); 613 u8 *values);
574 extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, 614 extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
575 u8 command, u8 length, u8 *values); 615 u8 command, u8 length, u8 *values);
576
577These ones were removed in Linux 2.6.10 because they had no users, but could
578be added back later if needed:
579
580 extern s32 i2c_smbus_read_block_data(struct i2c_client * client,
581 u8 command, u8 *values);
582 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client, 616 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
583 u8 command, u8 length, 617 u8 command, u8 length,
584 u8 *values); 618 u8 *values);
619
620These ones were removed from i2c-core because they had no users, but could
621be added back later if needed:
622
623 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value);
585 extern s32 i2c_smbus_process_call(struct i2c_client * client, 624 extern s32 i2c_smbus_process_call(struct i2c_client * client,
586 u8 command, u16 value); 625 u8 command, u16 value);
587 extern s32 i2c_smbus_block_process_call(struct i2c_client *client, 626 extern s32 i2c_smbus_block_process_call(struct i2c_client *client,
588 u8 command, u8 length, 627 u8 command, u8 length,
589 u8 *values) 628 u8 *values)
590 629
591All these transactions return -1 on failure. The 'write' transactions 630All these transactions return a negative errno value on failure. The 'write'
592return 0 on success; the 'read' transactions return the read value, except 631transactions return 0 on success; the 'read' transactions return the read
593for read_block, which returns the number of values read. The block buffers 632value, except for block transactions, which return the number of values
594need not be longer than 32 bytes. 633read. The block buffers need not be longer than 32 bytes.
595 634
596You can read the file `smbus-protocol' for more information about the 635You can read the file `smbus-protocol' for more information about the
597actual SMBus protocol. 636actual SMBus protocol.