diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-14 19:53:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-14 19:53:02 -0400 |
commit | 278429cff8809958d25415ba0ed32b59866ab1a8 (patch) | |
tree | 1085100d82525ff7c0fc93fad475e4320f293548 /Documentation | |
parent | e413b210c541acac1a194085627db28a122f3bdf (diff) | |
parent | a05f2c5a2735ee1d68770137fbbfc334d3b9cda9 (diff) |
Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
* 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6:
i2c-viapro: Add support for SMBus Process Call transactions
i2c: Restore i2c_smbus_process_call function
i2c: Do earlier driver model init
i2c: Only build Tyan SMBus mux drivers on x86
i2c: Guard against oopses from bad init sequences
i2c: Document the implementation details of the /dev interface
i2c: Improve dev-interface documentation
i2c-parport-light: Don't register a platform device resource
hwmon: (dme1737) Convert to a new-style i2c driver
hwmon: (dme1737) Be less i2c-centric
i2c/tps65010: Vibrator hookup to gpiolib
i2c-viapro: Add VX800/VX820 support
i2c: Renesas Highlander FPGA SMBus support
i2c-pca-isa: Don't grab arbitrary resources
i2c/isp1301_omap: Convert to a new-style i2c driver, part 2
i2c/isp1301_omap: Convert to a new-style i2c driver, part 1
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/i2c/busses/i2c-viapro | 8 | ||||
-rw-r--r-- | Documentation/i2c/dev-interface | 110 | ||||
-rw-r--r-- | Documentation/i2c/smbus-protocol | 4 | ||||
-rw-r--r-- | Documentation/i2c/writing-clients | 4 |
4 files changed, 95 insertions, 31 deletions
diff --git a/Documentation/i2c/busses/i2c-viapro b/Documentation/i2c/busses/i2c-viapro index 1405fb69984c..22efedf60c87 100644 --- a/Documentation/i2c/busses/i2c-viapro +++ b/Documentation/i2c/busses/i2c-viapro | |||
@@ -16,6 +16,9 @@ Supported adapters: | |||
16 | * VIA Technologies, Inc. CX700 | 16 | * VIA Technologies, Inc. CX700 |
17 | Datasheet: available on request and under NDA from VIA | 17 | Datasheet: available on request and under NDA from VIA |
18 | 18 | ||
19 | * VIA Technologies, Inc. VX800/VX820 | ||
20 | Datasheet: available on http://linux.via.com.tw | ||
21 | |||
19 | Authors: | 22 | Authors: |
20 | Kyösti Mälkki <kmalkki@cc.hut.fi>, | 23 | Kyösti Mälkki <kmalkki@cc.hut.fi>, |
21 | Mark D. Studebaker <mdsxyz123@yahoo.com>, | 24 | Mark D. Studebaker <mdsxyz123@yahoo.com>, |
@@ -49,6 +52,7 @@ Your lspci -n listing must show one of these : | |||
49 | device 1106:3372 (VT8237S) | 52 | device 1106:3372 (VT8237S) |
50 | device 1106:3287 (VT8251) | 53 | device 1106:3287 (VT8251) |
51 | device 1106:8324 (CX700) | 54 | device 1106:8324 (CX700) |
55 | device 1106:8353 (VX800/VX820) | ||
52 | 56 | ||
53 | If none of these show up, you should look in the BIOS for settings like | 57 | If none of these show up, you should look in the BIOS for settings like |
54 | enable ACPI / SMBus or even USB. | 58 | enable ACPI / SMBus or even USB. |
@@ -57,5 +61,5 @@ Except for the oldest chips (VT82C596A/B, VT82C686A and most probably | |||
57 | VT8231), this driver supports I2C block transactions. Such transactions | 61 | VT8231), this driver supports I2C block transactions. Such transactions |
58 | are mainly useful to read from and write to EEPROMs. | 62 | are mainly useful to read from and write to EEPROMs. |
59 | 63 | ||
60 | The CX700 additionally appears to support SMBus PEC, although this driver | 64 | The CX700/VX800/VX820 additionally appears to support SMBus PEC, although |
61 | doesn't implement it yet. | 65 | this driver doesn't implement it yet. |
diff --git a/Documentation/i2c/dev-interface b/Documentation/i2c/dev-interface index 9dd79123ddd9..3e742ba25536 100644 --- a/Documentation/i2c/dev-interface +++ b/Documentation/i2c/dev-interface | |||
@@ -4,6 +4,10 @@ the /dev interface. You need to load module i2c-dev for this. | |||
4 | 4 | ||
5 | Each registered i2c adapter gets a number, counting from 0. You can | 5 | Each registered i2c adapter gets a number, counting from 0. You can |
6 | examine /sys/class/i2c-dev/ to see what number corresponds to which adapter. | 6 | examine /sys/class/i2c-dev/ to see what number corresponds to which adapter. |
7 | Alternatively, you can run "i2cdetect -l" to obtain a formated list of all | ||
8 | i2c adapters present on your system at a given time. i2cdetect is part of | ||
9 | the i2c-tools package. | ||
10 | |||
7 | I2C device files are character device files with major device number 89 | 11 | I2C device files are character device files with major device number 89 |
8 | and a minor device number corresponding to the number assigned as | 12 | and a minor device number corresponding to the number assigned as |
9 | explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ..., | 13 | explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ..., |
@@ -17,30 +21,34 @@ So let's say you want to access an i2c adapter from a C program. The | |||
17 | first thing to do is "#include <linux/i2c-dev.h>". Please note that | 21 | first thing to do is "#include <linux/i2c-dev.h>". Please note that |
18 | there are two files named "i2c-dev.h" out there, one is distributed | 22 | there are two files named "i2c-dev.h" out there, one is distributed |
19 | with the Linux kernel and is meant to be included from kernel | 23 | with the Linux kernel and is meant to be included from kernel |
20 | driver code, the other one is distributed with lm_sensors and is | 24 | driver code, the other one is distributed with i2c-tools and is |
21 | meant to be included from user-space programs. You obviously want | 25 | meant to be included from user-space programs. You obviously want |
22 | the second one here. | 26 | the second one here. |
23 | 27 | ||
24 | Now, you have to decide which adapter you want to access. You should | 28 | Now, you have to decide which adapter you want to access. You should |
25 | inspect /sys/class/i2c-dev/ to decide this. Adapter numbers are assigned | 29 | inspect /sys/class/i2c-dev/ or run "i2cdetect -l" to decide this. |
26 | somewhat dynamically, so you can not even assume /dev/i2c-0 is the | 30 | Adapter numbers are assigned somewhat dynamically, so you can not |
27 | first adapter. | 31 | assume much about them. They can even change from one boot to the next. |
28 | 32 | ||
29 | Next thing, open the device file, as follows: | 33 | Next thing, open the device file, as follows: |
34 | |||
30 | int file; | 35 | int file; |
31 | int adapter_nr = 2; /* probably dynamically determined */ | 36 | int adapter_nr = 2; /* probably dynamically determined */ |
32 | char filename[20]; | 37 | char filename[20]; |
33 | 38 | ||
34 | sprintf(filename,"/dev/i2c-%d",adapter_nr); | 39 | snprintf(filename, 19, "/dev/i2c-%d", adapter_nr); |
35 | if ((file = open(filename,O_RDWR)) < 0) { | 40 | file = open(filename, O_RDWR); |
41 | if (file < 0) { | ||
36 | /* ERROR HANDLING; you can check errno to see what went wrong */ | 42 | /* ERROR HANDLING; you can check errno to see what went wrong */ |
37 | exit(1); | 43 | exit(1); |
38 | } | 44 | } |
39 | 45 | ||
40 | When you have opened the device, you must specify with what device | 46 | When you have opened the device, you must specify with what device |
41 | address you want to communicate: | 47 | address you want to communicate: |
48 | |||
42 | int addr = 0x40; /* The I2C address */ | 49 | int addr = 0x40; /* The I2C address */ |
43 | if (ioctl(file,I2C_SLAVE,addr) < 0) { | 50 | |
51 | if (ioctl(file, I2C_SLAVE, addr) < 0) { | ||
44 | /* ERROR HANDLING; you can check errno to see what went wrong */ | 52 | /* ERROR HANDLING; you can check errno to see what went wrong */ |
45 | exit(1); | 53 | exit(1); |
46 | } | 54 | } |
@@ -48,31 +56,41 @@ address you want to communicate: | |||
48 | Well, you are all set up now. You can now use SMBus commands or plain | 56 | Well, you are all set up now. You can now use SMBus commands or plain |
49 | I2C to communicate with your device. SMBus commands are preferred if | 57 | I2C to communicate with your device. SMBus commands are preferred if |
50 | the device supports them. Both are illustrated below. | 58 | the device supports them. Both are illustrated below. |
59 | |||
51 | __u8 register = 0x10; /* Device register to access */ | 60 | __u8 register = 0x10; /* Device register to access */ |
52 | __s32 res; | 61 | __s32 res; |
53 | char buf[10]; | 62 | char buf[10]; |
63 | |||
54 | /* Using SMBus commands */ | 64 | /* Using SMBus commands */ |
55 | res = i2c_smbus_read_word_data(file,register); | 65 | res = i2c_smbus_read_word_data(file, register); |
56 | if (res < 0) { | 66 | if (res < 0) { |
57 | /* ERROR HANDLING: i2c transaction failed */ | 67 | /* ERROR HANDLING: i2c transaction failed */ |
58 | } else { | 68 | } else { |
59 | /* res contains the read word */ | 69 | /* res contains the read word */ |
60 | } | 70 | } |
71 | |||
61 | /* Using I2C Write, equivalent of | 72 | /* Using I2C Write, equivalent of |
62 | i2c_smbus_write_word_data(file,register,0x6543) */ | 73 | i2c_smbus_write_word_data(file, register, 0x6543) */ |
63 | buf[0] = register; | 74 | buf[0] = register; |
64 | buf[1] = 0x43; | 75 | buf[1] = 0x43; |
65 | buf[2] = 0x65; | 76 | buf[2] = 0x65; |
66 | if ( write(file,buf,3) != 3) { | 77 | if (write(file, buf, 3) ! =3) { |
67 | /* ERROR HANDLING: i2c transaction failed */ | 78 | /* ERROR HANDLING: i2c transaction failed */ |
68 | } | 79 | } |
80 | |||
69 | /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */ | 81 | /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */ |
70 | if (read(file,buf,1) != 1) { | 82 | if (read(file, buf, 1) != 1) { |
71 | /* ERROR HANDLING: i2c transaction failed */ | 83 | /* ERROR HANDLING: i2c transaction failed */ |
72 | } else { | 84 | } else { |
73 | /* buf[0] contains the read byte */ | 85 | /* buf[0] contains the read byte */ |
74 | } | 86 | } |
75 | 87 | ||
88 | Note that only a subset of the I2C and SMBus protocols can be achieved by | ||
89 | the means of read() and write() calls. In particular, so-called combined | ||
90 | transactions (mixing read and write messages in the same transaction) | ||
91 | aren't supported. For this reason, this interface is almost never used by | ||
92 | user-space programs. | ||
93 | |||
76 | IMPORTANT: because of the use of inline functions, you *have* to use | 94 | IMPORTANT: because of the use of inline functions, you *have* to use |
77 | '-O' or some variation when you compile your program! | 95 | '-O' or some variation when you compile your program! |
78 | 96 | ||
@@ -80,31 +98,29 @@ IMPORTANT: because of the use of inline functions, you *have* to use | |||
80 | Full interface description | 98 | Full interface description |
81 | ========================== | 99 | ========================== |
82 | 100 | ||
83 | The following IOCTLs are defined and fully supported | 101 | The following IOCTLs are defined: |
84 | (see also i2c-dev.h): | ||
85 | 102 | ||
86 | ioctl(file,I2C_SLAVE,long addr) | 103 | ioctl(file, I2C_SLAVE, long addr) |
87 | Change slave address. The address is passed in the 7 lower bits of the | 104 | Change slave address. The address is passed in the 7 lower bits of the |
88 | argument (except for 10 bit addresses, passed in the 10 lower bits in this | 105 | argument (except for 10 bit addresses, passed in the 10 lower bits in this |
89 | case). | 106 | case). |
90 | 107 | ||
91 | ioctl(file,I2C_TENBIT,long select) | 108 | ioctl(file, I2C_TENBIT, long select) |
92 | Selects ten bit addresses if select not equals 0, selects normal 7 bit | 109 | Selects ten bit addresses if select not equals 0, selects normal 7 bit |
93 | addresses if select equals 0. Default 0. This request is only valid | 110 | addresses if select equals 0. Default 0. This request is only valid |
94 | if the adapter has I2C_FUNC_10BIT_ADDR. | 111 | if the adapter has I2C_FUNC_10BIT_ADDR. |
95 | 112 | ||
96 | ioctl(file,I2C_PEC,long select) | 113 | ioctl(file, I2C_PEC, long select) |
97 | Selects SMBus PEC (packet error checking) generation and verification | 114 | Selects SMBus PEC (packet error checking) generation and verification |
98 | if select not equals 0, disables if select equals 0. Default 0. | 115 | if select not equals 0, disables if select equals 0. Default 0. |
99 | Used only for SMBus transactions. This request only has an effect if the | 116 | Used only for SMBus transactions. This request only has an effect if the |
100 | the adapter has I2C_FUNC_SMBUS_PEC; it is still safe if not, it just | 117 | the adapter has I2C_FUNC_SMBUS_PEC; it is still safe if not, it just |
101 | doesn't have any effect. | 118 | doesn't have any effect. |
102 | 119 | ||
103 | ioctl(file,I2C_FUNCS,unsigned long *funcs) | 120 | ioctl(file, I2C_FUNCS, unsigned long *funcs) |
104 | Gets the adapter functionality and puts it in *funcs. | 121 | Gets the adapter functionality and puts it in *funcs. |
105 | 122 | ||
106 | ioctl(file,I2C_RDWR,struct i2c_rdwr_ioctl_data *msgset) | 123 | ioctl(file, I2C_RDWR, struct i2c_rdwr_ioctl_data *msgset) |
107 | |||
108 | Do combined read/write transaction without stop in between. | 124 | Do combined read/write transaction without stop in between. |
109 | Only valid if the adapter has I2C_FUNC_I2C. The argument is | 125 | Only valid if the adapter has I2C_FUNC_I2C. The argument is |
110 | a pointer to a | 126 | a pointer to a |
@@ -120,10 +136,9 @@ ioctl(file,I2C_RDWR,struct i2c_rdwr_ioctl_data *msgset) | |||
120 | The slave address and whether to use ten bit address mode has to be | 136 | The slave address and whether to use ten bit address mode has to be |
121 | set in each message, overriding the values set with the above ioctl's. | 137 | set in each message, overriding the values set with the above ioctl's. |
122 | 138 | ||
123 | 139 | ioctl(file, I2C_SMBUS, struct i2c_smbus_ioctl_data *args) | |
124 | Other values are NOT supported at this moment, except for I2C_SMBUS, | 140 | Not meant to be called directly; instead, use the access functions |
125 | which you should never directly call; instead, use the access functions | 141 | below. |
126 | below. | ||
127 | 142 | ||
128 | You can do plain i2c transactions by using read(2) and write(2) calls. | 143 | You can do plain i2c transactions by using read(2) and write(2) calls. |
129 | You do not need to pass the address byte; instead, set it through | 144 | You do not need to pass the address byte; instead, set it through |
@@ -148,7 +163,52 @@ what happened. The 'write' transactions return 0 on success; the | |||
148 | returns the number of values read. The block buffers need not be longer | 163 | returns the number of values read. The block buffers need not be longer |
149 | than 32 bytes. | 164 | than 32 bytes. |
150 | 165 | ||
151 | The above functions are all macros, that resolve to calls to the | 166 | The above functions are all inline functions, that resolve to calls to |
152 | i2c_smbus_access function, that on its turn calls a specific ioctl | 167 | the i2c_smbus_access function, that on its turn calls a specific ioctl |
153 | with the data in a specific format. Read the source code if you | 168 | with the data in a specific format. Read the source code if you |
154 | want to know what happens behind the screens. | 169 | want to know what happens behind the screens. |
170 | |||
171 | |||
172 | Implementation details | ||
173 | ====================== | ||
174 | |||
175 | For the interested, here's the code flow which happens inside the kernel | ||
176 | when you use the /dev interface to I2C: | ||
177 | |||
178 | 1* Your program opens /dev/i2c-N and calls ioctl() on it, as described in | ||
179 | section "C example" above. | ||
180 | |||
181 | 2* These open() and ioctl() calls are handled by the i2c-dev kernel | ||
182 | driver: see i2c-dev.c:i2cdev_open() and i2c-dev.c:i2cdev_ioctl(), | ||
183 | respectively. You can think of i2c-dev as a generic I2C chip driver | ||
184 | that can be programmed from user-space. | ||
185 | |||
186 | 3* Some ioctl() calls are for administrative tasks and are handled by | ||
187 | i2c-dev directly. Examples include I2C_SLAVE (set the address of the | ||
188 | device you want to access) and I2C_PEC (enable or disable SMBus error | ||
189 | checking on future transactions.) | ||
190 | |||
191 | 4* Other ioctl() calls are converted to in-kernel function calls by | ||
192 | i2c-dev. Examples include I2C_FUNCS, which queries the I2C adapter | ||
193 | functionality using i2c.h:i2c_get_functionality(), and I2C_SMBUS, which | ||
194 | performs an SMBus transaction using i2c-core.c:i2c_smbus_xfer(). | ||
195 | |||
196 | The i2c-dev driver is responsible for checking all the parameters that | ||
197 | come from user-space for validity. After this point, there is no | ||
198 | difference between these calls that came from user-space through i2c-dev | ||
199 | and calls that would have been performed by kernel I2C chip drivers | ||
200 | directly. This means that I2C bus drivers don't need to implement | ||
201 | anything special to support access from user-space. | ||
202 | |||
203 | 5* These i2c-core.c/i2c.h functions are wrappers to the actual | ||
204 | implementation of your I2C bus driver. Each adapter must declare | ||
205 | callback functions implementing these standard calls. | ||
206 | i2c.h:i2c_get_functionality() calls i2c_adapter.algo->functionality(), | ||
207 | while i2c-core.c:i2c_smbus_xfer() calls either | ||
208 | adapter.algo->smbus_xfer() if it is implemented, or if not, | ||
209 | i2c-core.c:i2c_smbus_xfer_emulated() which in turn calls | ||
210 | i2c_adapter.algo->master_xfer(). | ||
211 | |||
212 | After your I2C bus driver has processed these requests, execution runs | ||
213 | up the call chain, with almost no processing done, except by i2c-dev to | ||
214 | package the returned data, if any, in suitable format for the ioctl. | ||
diff --git a/Documentation/i2c/smbus-protocol b/Documentation/i2c/smbus-protocol index 24bfb65da17d..9df47441f0e7 100644 --- a/Documentation/i2c/smbus-protocol +++ b/Documentation/i2c/smbus-protocol | |||
@@ -109,8 +109,8 @@ specified through the Comm byte. | |||
109 | S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P | 109 | S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P |
110 | 110 | ||
111 | 111 | ||
112 | SMBus Process Call | 112 | SMBus Process Call: i2c_smbus_process_call() |
113 | ================== | 113 | ============================================= |
114 | 114 | ||
115 | This command selects a device register (through the Comm byte), sends | 115 | This command selects a device register (through the Comm byte), sends |
116 | 16 bits of data to it, and reads 16 bits of data in return. | 116 | 16 bits of data to it, and reads 16 bits of data in return. |
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index 6b61b3a2e90b..d73ee117a8ca 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
@@ -606,6 +606,8 @@ SMBus communication | |||
606 | 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); |
607 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, | 607 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, |
608 | u8 command, u16 value); | 608 | u8 command, u16 value); |
609 | extern s32 i2c_smbus_process_call(struct i2c_client *client, | ||
610 | u8 command, u16 value); | ||
609 | extern s32 i2c_smbus_read_block_data(struct i2c_client * client, | 611 | extern s32 i2c_smbus_read_block_data(struct i2c_client * client, |
610 | u8 command, u8 *values); | 612 | u8 command, u8 *values); |
611 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, | 613 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, |
@@ -621,8 +623,6 @@ These ones were removed from i2c-core because they had no users, but could | |||
621 | be added back later if needed: | 623 | be added back later if needed: |
622 | 624 | ||
623 | extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); | 625 | extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); |
624 | extern s32 i2c_smbus_process_call(struct i2c_client * client, | ||
625 | u8 command, u16 value); | ||
626 | extern s32 i2c_smbus_block_process_call(struct i2c_client *client, | 626 | extern s32 i2c_smbus_block_process_call(struct i2c_client *client, |
627 | u8 command, u8 length, | 627 | u8 command, u8 length, |
628 | u8 *values) | 628 | u8 *values) |