diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-15 14:16:05 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-15 14:16:05 -0400 |
commit | dc221eae08eea3b0db127d1f152fac24d10b6a52 (patch) | |
tree | eea4cc64f2568db6aea94b9491120525ebcd738f /drivers/i2c/chips | |
parent | 98339cbd360b77c3167db287fd611468c2c44559 (diff) | |
parent | 4735c98f8447acb1c8977e2b8024640f7bf36dd6 (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: (56 commits)
i2c: Add detection capability to new-style drivers
i2c: Call client_unregister for new-style devices too
i2c: Clean up old chip drivers
i2c-ibm_iic: Register child nodes
i2c: New-style EEPROM driver using device IDs
i2c: Export the i2c_bus_type symbol
i2c-au1550: Fix PM support
i2c-dev: Delete empty detach_client callback
i2c: Drop stray references to lm_sensors
i2c: Check for ACPI resource conflicts
i2c-ocores: basic PM support
i2c-sibyte: SWARM I2C board initialization
i2c-i801: Fix handling of error conditions
i2c-i801: Rename local variable temp to status
i2c-i801: Properly report bus arbitration loss
i2c-i801: Remove verbose debugging messages
i2c-algo-pcf: Drop unused struct members
i2c-algo-pcf: Multi-master lost-arbitration improvement
i2c: Deprecate the legacy gpio drivers
i2c-pxa: Initialize early
...
Diffstat (limited to 'drivers/i2c/chips')
-rw-r--r-- | drivers/i2c/chips/Kconfig | 43 | ||||
-rw-r--r-- | drivers/i2c/chips/Makefile | 1 | ||||
-rw-r--r-- | drivers/i2c/chips/at24.c | 583 | ||||
-rw-r--r-- | drivers/i2c/chips/eeprom.c | 81 | ||||
-rw-r--r-- | drivers/i2c/chips/max6875.c | 4 | ||||
-rw-r--r-- | drivers/i2c/chips/pca9539.c | 25 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8574.c | 25 | ||||
-rw-r--r-- | drivers/i2c/chips/pcf8591.c | 33 |
8 files changed, 701 insertions, 94 deletions
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig index 2da2edfa68ec..50e0a4653741 100644 --- a/drivers/i2c/chips/Kconfig +++ b/drivers/i2c/chips/Kconfig | |||
@@ -14,6 +14,32 @@ config DS1682 | |||
14 | This driver can also be built as a module. If so, the module | 14 | This driver can also be built as a module. If so, the module |
15 | will be called ds1682. | 15 | will be called ds1682. |
16 | 16 | ||
17 | config AT24 | ||
18 | tristate "EEPROMs from most vendors" | ||
19 | depends on SYSFS && EXPERIMENTAL | ||
20 | help | ||
21 | Enable this driver to get read/write support to most I2C EEPROMs, | ||
22 | after you configure the driver to know about each EEPROM on | ||
23 | your target board. Use these generic chip names, instead of | ||
24 | vendor-specific ones like at24c64 or 24lc02: | ||
25 | |||
26 | 24c00, 24c01, 24c02, spd (readonly 24c02), 24c04, 24c08, | ||
27 | 24c16, 24c32, 24c64, 24c128, 24c256, 24c512, 24c1024 | ||
28 | |||
29 | Unless you like data loss puzzles, always be sure that any chip | ||
30 | you configure as a 24c32 (32 kbit) or larger is NOT really a | ||
31 | 24c16 (16 kbit) or smaller, and vice versa. Marking the chip | ||
32 | as read-only won't help recover from this. Also, if your chip | ||
33 | has any software write-protect mechanism you may want to review the | ||
34 | code to make sure this driver won't turn it on by accident. | ||
35 | |||
36 | If you use this with an SMBus adapter instead of an I2C adapter, | ||
37 | full functionality is not available. Only smaller devices are | ||
38 | supported (24c16 and below, max 4 kByte). | ||
39 | |||
40 | This driver can also be built as a module. If so, the module | ||
41 | will be called at24. | ||
42 | |||
17 | config SENSORS_EEPROM | 43 | config SENSORS_EEPROM |
18 | tristate "EEPROM reader" | 44 | tristate "EEPROM reader" |
19 | depends on EXPERIMENTAL | 45 | depends on EXPERIMENTAL |
@@ -26,8 +52,8 @@ config SENSORS_EEPROM | |||
26 | will be called eeprom. | 52 | will be called eeprom. |
27 | 53 | ||
28 | config SENSORS_PCF8574 | 54 | config SENSORS_PCF8574 |
29 | tristate "Philips PCF8574 and PCF8574A" | 55 | tristate "Philips PCF8574 and PCF8574A (DEPRECATED)" |
30 | depends on EXPERIMENTAL | 56 | depends on EXPERIMENTAL && GPIO_PCF857X = "n" |
31 | default n | 57 | default n |
32 | help | 58 | help |
33 | If you say yes here you get support for Philips PCF8574 and | 59 | If you say yes here you get support for Philips PCF8574 and |
@@ -36,12 +62,16 @@ config SENSORS_PCF8574 | |||
36 | This driver can also be built as a module. If so, the module | 62 | This driver can also be built as a module. If so, the module |
37 | will be called pcf8574. | 63 | will be called pcf8574. |
38 | 64 | ||
65 | This driver is deprecated and will be dropped soon. Use | ||
66 | drivers/gpio/pcf857x.c instead. | ||
67 | |||
39 | These devices are hard to detect and rarely found on mainstream | 68 | These devices are hard to detect and rarely found on mainstream |
40 | hardware. If unsure, say N. | 69 | hardware. If unsure, say N. |
41 | 70 | ||
42 | config PCF8575 | 71 | config PCF8575 |
43 | tristate "Philips PCF8575" | 72 | tristate "Philips PCF8575 (DEPRECATED)" |
44 | default n | 73 | default n |
74 | depends on GPIO_PCF857X = "n" | ||
45 | help | 75 | help |
46 | If you say yes here you get support for Philips PCF8575 chip. | 76 | If you say yes here you get support for Philips PCF8575 chip. |
47 | This chip is a 16-bit I/O expander for the I2C bus. Several other | 77 | This chip is a 16-bit I/O expander for the I2C bus. Several other |
@@ -50,12 +80,15 @@ config PCF8575 | |||
50 | This driver can also be built as a module. If so, the module | 80 | This driver can also be built as a module. If so, the module |
51 | will be called pcf8575. | 81 | will be called pcf8575. |
52 | 82 | ||
83 | This driver is deprecated and will be dropped soon. Use | ||
84 | drivers/gpio/pcf857x.c instead. | ||
85 | |||
53 | This device is hard to detect and is rarely found on mainstream | 86 | This device is hard to detect and is rarely found on mainstream |
54 | hardware. If unsure, say N. | 87 | hardware. If unsure, say N. |
55 | 88 | ||
56 | config SENSORS_PCA9539 | 89 | config SENSORS_PCA9539 |
57 | tristate "Philips PCA9539 16-bit I/O port (DEPRECATED)" | 90 | tristate "Philips PCA9539 16-bit I/O port (DEPRECATED)" |
58 | depends on EXPERIMENTAL && GPIO_PCA9539 = "n" | 91 | depends on EXPERIMENTAL && GPIO_PCA953X = "n" |
59 | help | 92 | help |
60 | If you say yes here you get support for the Philips PCA9539 | 93 | If you say yes here you get support for the Philips PCA9539 |
61 | 16-bit I/O port. | 94 | 16-bit I/O port. |
@@ -64,7 +97,7 @@ config SENSORS_PCA9539 | |||
64 | will be called pca9539. | 97 | will be called pca9539. |
65 | 98 | ||
66 | This driver is deprecated and will be dropped soon. Use | 99 | This driver is deprecated and will be dropped soon. Use |
67 | drivers/gpio/pca9539.c instead. | 100 | drivers/gpio/pca953x.c instead. |
68 | 101 | ||
69 | config SENSORS_PCF8591 | 102 | config SENSORS_PCF8591 |
70 | tristate "Philips PCF8591" | 103 | tristate "Philips PCF8591" |
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile index e47aca0ca5ae..39e3e69ed125 100644 --- a/drivers/i2c/chips/Makefile +++ b/drivers/i2c/chips/Makefile | |||
@@ -10,6 +10,7 @@ | |||
10 | # | 10 | # |
11 | 11 | ||
12 | obj-$(CONFIG_DS1682) += ds1682.o | 12 | obj-$(CONFIG_DS1682) += ds1682.o |
13 | obj-$(CONFIG_AT24) += at24.o | ||
13 | obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o | 14 | obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o |
14 | obj-$(CONFIG_SENSORS_MAX6875) += max6875.o | 15 | obj-$(CONFIG_SENSORS_MAX6875) += max6875.o |
15 | obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o | 16 | obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o |
diff --git a/drivers/i2c/chips/at24.c b/drivers/i2c/chips/at24.c new file mode 100644 index 000000000000..e764c94f3e3d --- /dev/null +++ b/drivers/i2c/chips/at24.c | |||
@@ -0,0 +1,583 @@ | |||
1 | /* | ||
2 | * at24.c - handle most I2C EEPROMs | ||
3 | * | ||
4 | * Copyright (C) 2005-2007 David Brownell | ||
5 | * Copyright (C) 2008 Wolfram Sang, Pengutronix | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | */ | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/delay.h> | ||
17 | #include <linux/mutex.h> | ||
18 | #include <linux/sysfs.h> | ||
19 | #include <linux/mod_devicetable.h> | ||
20 | #include <linux/log2.h> | ||
21 | #include <linux/bitops.h> | ||
22 | #include <linux/jiffies.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/i2c/at24.h> | ||
25 | |||
26 | /* | ||
27 | * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. | ||
28 | * Differences between different vendor product lines (like Atmel AT24C or | ||
29 | * MicroChip 24LC, etc) won't much matter for typical read/write access. | ||
30 | * There are also I2C RAM chips, likewise interchangeable. One example | ||
31 | * would be the PCF8570, which acts like a 24c02 EEPROM (256 bytes). | ||
32 | * | ||
33 | * However, misconfiguration can lose data. "Set 16-bit memory address" | ||
34 | * to a part with 8-bit addressing will overwrite data. Writing with too | ||
35 | * big a page size also loses data. And it's not safe to assume that the | ||
36 | * conventional addresses 0x50..0x57 only hold eeproms; a PCF8563 RTC | ||
37 | * uses 0x51, for just one example. | ||
38 | * | ||
39 | * Accordingly, explicit board-specific configuration data should be used | ||
40 | * in almost all cases. (One partial exception is an SMBus used to access | ||
41 | * "SPD" data for DRAM sticks. Those only use 24c02 EEPROMs.) | ||
42 | * | ||
43 | * So this driver uses "new style" I2C driver binding, expecting to be | ||
44 | * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or | ||
45 | * similar kernel-resident tables; or, configuration data coming from | ||
46 | * a bootloader. | ||
47 | * | ||
48 | * Other than binding model, current differences from "eeprom" driver are | ||
49 | * that this one handles write access and isn't restricted to 24c02 devices. | ||
50 | * It also handles larger devices (32 kbit and up) with two-byte addresses, | ||
51 | * which won't work on pure SMBus systems. | ||
52 | */ | ||
53 | |||
54 | struct at24_data { | ||
55 | struct at24_platform_data chip; | ||
56 | bool use_smbus; | ||
57 | |||
58 | /* | ||
59 | * Lock protects against activities from other Linux tasks, | ||
60 | * but not from changes by other I2C masters. | ||
61 | */ | ||
62 | struct mutex lock; | ||
63 | struct bin_attribute bin; | ||
64 | |||
65 | u8 *writebuf; | ||
66 | unsigned write_max; | ||
67 | unsigned num_addresses; | ||
68 | |||
69 | /* | ||
70 | * Some chips tie up multiple I2C addresses; dummy devices reserve | ||
71 | * them for us, and we'll use them with SMBus calls. | ||
72 | */ | ||
73 | struct i2c_client *client[]; | ||
74 | }; | ||
75 | |||
76 | /* | ||
77 | * This parameter is to help this driver avoid blocking other drivers out | ||
78 | * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C | ||
79 | * clock, one 256 byte read takes about 1/43 second which is excessive; | ||
80 | * but the 1/170 second it takes at 400 kHz may be quite reasonable; and | ||
81 | * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. | ||
82 | * | ||
83 | * This value is forced to be a power of two so that writes align on pages. | ||
84 | */ | ||
85 | static unsigned io_limit = 128; | ||
86 | module_param(io_limit, uint, 0); | ||
87 | MODULE_PARM_DESC(io_limit, "Maximum bytes per I/O (default 128)"); | ||
88 | |||
89 | /* | ||
90 | * Specs often allow 5 msec for a page write, sometimes 20 msec; | ||
91 | * it's important to recover from write timeouts. | ||
92 | */ | ||
93 | static unsigned write_timeout = 25; | ||
94 | module_param(write_timeout, uint, 0); | ||
95 | MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); | ||
96 | |||
97 | #define AT24_SIZE_BYTELEN 5 | ||
98 | #define AT24_SIZE_FLAGS 8 | ||
99 | |||
100 | #define AT24_BITMASK(x) (BIT(x) - 1) | ||
101 | |||
102 | /* create non-zero magic value for given eeprom parameters */ | ||
103 | #define AT24_DEVICE_MAGIC(_len, _flags) \ | ||
104 | ((1 << AT24_SIZE_FLAGS | (_flags)) \ | ||
105 | << AT24_SIZE_BYTELEN | ilog2(_len)) | ||
106 | |||
107 | static const struct i2c_device_id at24_ids[] = { | ||
108 | /* needs 8 addresses as A0-A2 are ignored */ | ||
109 | { "24c00", AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR) }, | ||
110 | /* old variants can't be handled with this generic entry! */ | ||
111 | { "24c01", AT24_DEVICE_MAGIC(1024 / 8, 0) }, | ||
112 | { "24c02", AT24_DEVICE_MAGIC(2048 / 8, 0) }, | ||
113 | /* spd is a 24c02 in memory DIMMs */ | ||
114 | { "spd", AT24_DEVICE_MAGIC(2048 / 8, | ||
115 | AT24_FLAG_READONLY | AT24_FLAG_IRUGO) }, | ||
116 | { "24c04", AT24_DEVICE_MAGIC(4096 / 8, 0) }, | ||
117 | /* 24rf08 quirk is handled at i2c-core */ | ||
118 | { "24c08", AT24_DEVICE_MAGIC(8192 / 8, 0) }, | ||
119 | { "24c16", AT24_DEVICE_MAGIC(16384 / 8, 0) }, | ||
120 | { "24c32", AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16) }, | ||
121 | { "24c64", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16) }, | ||
122 | { "24c128", AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16) }, | ||
123 | { "24c256", AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16) }, | ||
124 | { "24c512", AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16) }, | ||
125 | { "24c1024", AT24_DEVICE_MAGIC(1048576 / 8, AT24_FLAG_ADDR16) }, | ||
126 | { "at24", 0 }, | ||
127 | { /* END OF LIST */ } | ||
128 | }; | ||
129 | MODULE_DEVICE_TABLE(i2c, at24_ids); | ||
130 | |||
131 | /*-------------------------------------------------------------------------*/ | ||
132 | |||
133 | /* | ||
134 | * This routine supports chips which consume multiple I2C addresses. It | ||
135 | * computes the addressing information to be used for a given r/w request. | ||
136 | * Assumes that sanity checks for offset happened at sysfs-layer. | ||
137 | */ | ||
138 | static struct i2c_client *at24_translate_offset(struct at24_data *at24, | ||
139 | unsigned *offset) | ||
140 | { | ||
141 | unsigned i; | ||
142 | |||
143 | if (at24->chip.flags & AT24_FLAG_ADDR16) { | ||
144 | i = *offset >> 16; | ||
145 | *offset &= 0xffff; | ||
146 | } else { | ||
147 | i = *offset >> 8; | ||
148 | *offset &= 0xff; | ||
149 | } | ||
150 | |||
151 | return at24->client[i]; | ||
152 | } | ||
153 | |||
154 | static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, | ||
155 | unsigned offset, size_t count) | ||
156 | { | ||
157 | struct i2c_msg msg[2]; | ||
158 | u8 msgbuf[2]; | ||
159 | struct i2c_client *client; | ||
160 | int status, i; | ||
161 | |||
162 | memset(msg, 0, sizeof(msg)); | ||
163 | |||
164 | /* | ||
165 | * REVISIT some multi-address chips don't rollover page reads to | ||
166 | * the next slave address, so we may need to truncate the count. | ||
167 | * Those chips might need another quirk flag. | ||
168 | * | ||
169 | * If the real hardware used four adjacent 24c02 chips and that | ||
170 | * were misconfigured as one 24c08, that would be a similar effect: | ||
171 | * one "eeprom" file not four, but larger reads would fail when | ||
172 | * they crossed certain pages. | ||
173 | */ | ||
174 | |||
175 | /* | ||
176 | * Slave address and byte offset derive from the offset. Always | ||
177 | * set the byte address; on a multi-master board, another master | ||
178 | * may have changed the chip's "current" address pointer. | ||
179 | */ | ||
180 | client = at24_translate_offset(at24, &offset); | ||
181 | |||
182 | if (count > io_limit) | ||
183 | count = io_limit; | ||
184 | |||
185 | /* Smaller eeproms can work given some SMBus extension calls */ | ||
186 | if (at24->use_smbus) { | ||
187 | if (count > I2C_SMBUS_BLOCK_MAX) | ||
188 | count = I2C_SMBUS_BLOCK_MAX; | ||
189 | status = i2c_smbus_read_i2c_block_data(client, offset, | ||
190 | count, buf); | ||
191 | dev_dbg(&client->dev, "smbus read %zd@%d --> %d\n", | ||
192 | count, offset, status); | ||
193 | return (status < 0) ? -EIO : status; | ||
194 | } | ||
195 | |||
196 | /* | ||
197 | * When we have a better choice than SMBus calls, use a combined | ||
198 | * I2C message. Write address; then read up to io_limit data bytes. | ||
199 | * Note that read page rollover helps us here (unlike writes). | ||
200 | * msgbuf is u8 and will cast to our needs. | ||
201 | */ | ||
202 | i = 0; | ||
203 | if (at24->chip.flags & AT24_FLAG_ADDR16) | ||
204 | msgbuf[i++] = offset >> 8; | ||
205 | msgbuf[i++] = offset; | ||
206 | |||
207 | msg[0].addr = client->addr; | ||
208 | msg[0].buf = msgbuf; | ||
209 | msg[0].len = i; | ||
210 | |||
211 | msg[1].addr = client->addr; | ||
212 | msg[1].flags = I2C_M_RD; | ||
213 | msg[1].buf = buf; | ||
214 | msg[1].len = count; | ||
215 | |||
216 | status = i2c_transfer(client->adapter, msg, 2); | ||
217 | dev_dbg(&client->dev, "i2c read %zd@%d --> %d\n", | ||
218 | count, offset, status); | ||
219 | |||
220 | if (status == 2) | ||
221 | return count; | ||
222 | else if (status >= 0) | ||
223 | return -EIO; | ||
224 | else | ||
225 | return status; | ||
226 | } | ||
227 | |||
228 | static ssize_t at24_bin_read(struct kobject *kobj, struct bin_attribute *attr, | ||
229 | char *buf, loff_t off, size_t count) | ||
230 | { | ||
231 | struct at24_data *at24; | ||
232 | ssize_t retval = 0; | ||
233 | |||
234 | at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); | ||
235 | |||
236 | if (unlikely(!count)) | ||
237 | return count; | ||
238 | |||
239 | /* | ||
240 | * Read data from chip, protecting against concurrent updates | ||
241 | * from this host, but not from other I2C masters. | ||
242 | */ | ||
243 | mutex_lock(&at24->lock); | ||
244 | |||
245 | while (count) { | ||
246 | ssize_t status; | ||
247 | |||
248 | status = at24_eeprom_read(at24, buf, off, count); | ||
249 | if (status <= 0) { | ||
250 | if (retval == 0) | ||
251 | retval = status; | ||
252 | break; | ||
253 | } | ||
254 | buf += status; | ||
255 | off += status; | ||
256 | count -= status; | ||
257 | retval += status; | ||
258 | } | ||
259 | |||
260 | mutex_unlock(&at24->lock); | ||
261 | |||
262 | return retval; | ||
263 | } | ||
264 | |||
265 | |||
266 | /* | ||
267 | * REVISIT: export at24_bin{read,write}() to let other kernel code use | ||
268 | * eeprom data. For example, it might hold a board's Ethernet address, or | ||
269 | * board-specific calibration data generated on the manufacturing floor. | ||
270 | */ | ||
271 | |||
272 | |||
273 | /* | ||
274 | * Note that if the hardware write-protect pin is pulled high, the whole | ||
275 | * chip is normally write protected. But there are plenty of product | ||
276 | * variants here, including OTP fuses and partial chip protect. | ||
277 | * | ||
278 | * We only use page mode writes; the alternative is sloooow. This routine | ||
279 | * writes at most one page. | ||
280 | */ | ||
281 | static ssize_t at24_eeprom_write(struct at24_data *at24, char *buf, | ||
282 | unsigned offset, size_t count) | ||
283 | { | ||
284 | struct i2c_client *client; | ||
285 | struct i2c_msg msg; | ||
286 | ssize_t status; | ||
287 | unsigned long timeout, write_time; | ||
288 | unsigned next_page; | ||
289 | |||
290 | /* Get corresponding I2C address and adjust offset */ | ||
291 | client = at24_translate_offset(at24, &offset); | ||
292 | |||
293 | /* write_max is at most a page */ | ||
294 | if (count > at24->write_max) | ||
295 | count = at24->write_max; | ||
296 | |||
297 | /* Never roll over backwards, to the start of this page */ | ||
298 | next_page = roundup(offset + 1, at24->chip.page_size); | ||
299 | if (offset + count > next_page) | ||
300 | count = next_page - offset; | ||
301 | |||
302 | /* If we'll use I2C calls for I/O, set up the message */ | ||
303 | if (!at24->use_smbus) { | ||
304 | int i = 0; | ||
305 | |||
306 | msg.addr = client->addr; | ||
307 | msg.flags = 0; | ||
308 | |||
309 | /* msg.buf is u8 and casts will mask the values */ | ||
310 | msg.buf = at24->writebuf; | ||
311 | if (at24->chip.flags & AT24_FLAG_ADDR16) | ||
312 | msg.buf[i++] = offset >> 8; | ||
313 | |||
314 | msg.buf[i++] = offset; | ||
315 | memcpy(&msg.buf[i], buf, count); | ||
316 | msg.len = i + count; | ||
317 | } | ||
318 | |||
319 | /* | ||
320 | * Writes fail if the previous one didn't complete yet. We may | ||
321 | * loop a few times until this one succeeds, waiting at least | ||
322 | * long enough for one entire page write to work. | ||
323 | */ | ||
324 | timeout = jiffies + msecs_to_jiffies(write_timeout); | ||
325 | do { | ||
326 | write_time = jiffies; | ||
327 | if (at24->use_smbus) { | ||
328 | status = i2c_smbus_write_i2c_block_data(client, | ||
329 | offset, count, buf); | ||
330 | if (status == 0) | ||
331 | status = count; | ||
332 | } else { | ||
333 | status = i2c_transfer(client->adapter, &msg, 1); | ||
334 | if (status == 1) | ||
335 | status = count; | ||
336 | } | ||
337 | dev_dbg(&client->dev, "write %zd@%d --> %zd (%ld)\n", | ||
338 | count, offset, status, jiffies); | ||
339 | |||
340 | if (status == count) | ||
341 | return count; | ||
342 | |||
343 | /* REVISIT: at HZ=100, this is sloooow */ | ||
344 | msleep(1); | ||
345 | } while (time_before(write_time, timeout)); | ||
346 | |||
347 | return -ETIMEDOUT; | ||
348 | } | ||
349 | |||
350 | static ssize_t at24_bin_write(struct kobject *kobj, struct bin_attribute *attr, | ||
351 | char *buf, loff_t off, size_t count) | ||
352 | { | ||
353 | struct at24_data *at24; | ||
354 | ssize_t retval = 0; | ||
355 | |||
356 | at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); | ||
357 | |||
358 | if (unlikely(!count)) | ||
359 | return count; | ||
360 | |||
361 | /* | ||
362 | * Write data to chip, protecting against concurrent updates | ||
363 | * from this host, but not from other I2C masters. | ||
364 | */ | ||
365 | mutex_lock(&at24->lock); | ||
366 | |||
367 | while (count) { | ||
368 | ssize_t status; | ||
369 | |||
370 | status = at24_eeprom_write(at24, buf, off, count); | ||
371 | if (status <= 0) { | ||
372 | if (retval == 0) | ||
373 | retval = status; | ||
374 | break; | ||
375 | } | ||
376 | buf += status; | ||
377 | off += status; | ||
378 | count -= status; | ||
379 | retval += status; | ||
380 | } | ||
381 | |||
382 | mutex_unlock(&at24->lock); | ||
383 | |||
384 | return retval; | ||
385 | } | ||
386 | |||
387 | /*-------------------------------------------------------------------------*/ | ||
388 | |||
389 | static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
390 | { | ||
391 | struct at24_platform_data chip; | ||
392 | bool writable; | ||
393 | bool use_smbus = false; | ||
394 | struct at24_data *at24; | ||
395 | int err; | ||
396 | unsigned i, num_addresses; | ||
397 | kernel_ulong_t magic; | ||
398 | |||
399 | if (client->dev.platform_data) { | ||
400 | chip = *(struct at24_platform_data *)client->dev.platform_data; | ||
401 | } else { | ||
402 | if (!id->driver_data) { | ||
403 | err = -ENODEV; | ||
404 | goto err_out; | ||
405 | } | ||
406 | magic = id->driver_data; | ||
407 | chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); | ||
408 | magic >>= AT24_SIZE_BYTELEN; | ||
409 | chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); | ||
410 | /* | ||
411 | * This is slow, but we can't know all eeproms, so we better | ||
412 | * play safe. Specifying custom eeprom-types via platform_data | ||
413 | * is recommended anyhow. | ||
414 | */ | ||
415 | chip.page_size = 1; | ||
416 | } | ||
417 | |||
418 | if (!is_power_of_2(chip.byte_len)) | ||
419 | dev_warn(&client->dev, | ||
420 | "byte_len looks suspicious (no power of 2)!\n"); | ||
421 | if (!is_power_of_2(chip.page_size)) | ||
422 | dev_warn(&client->dev, | ||
423 | "page_size looks suspicious (no power of 2)!\n"); | ||
424 | |||
425 | /* Use I2C operations unless we're stuck with SMBus extensions. */ | ||
426 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | ||
427 | if (chip.flags & AT24_FLAG_ADDR16) { | ||
428 | err = -EPFNOSUPPORT; | ||
429 | goto err_out; | ||
430 | } | ||
431 | if (!i2c_check_functionality(client->adapter, | ||
432 | I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { | ||
433 | err = -EPFNOSUPPORT; | ||
434 | goto err_out; | ||
435 | } | ||
436 | use_smbus = true; | ||
437 | } | ||
438 | |||
439 | if (chip.flags & AT24_FLAG_TAKE8ADDR) | ||
440 | num_addresses = 8; | ||
441 | else | ||
442 | num_addresses = DIV_ROUND_UP(chip.byte_len, | ||
443 | (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); | ||
444 | |||
445 | at24 = kzalloc(sizeof(struct at24_data) + | ||
446 | num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); | ||
447 | if (!at24) { | ||
448 | err = -ENOMEM; | ||
449 | goto err_out; | ||
450 | } | ||
451 | |||
452 | mutex_init(&at24->lock); | ||
453 | at24->use_smbus = use_smbus; | ||
454 | at24->chip = chip; | ||
455 | at24->num_addresses = num_addresses; | ||
456 | |||
457 | /* | ||
458 | * Export the EEPROM bytes through sysfs, since that's convenient. | ||
459 | * By default, only root should see the data (maybe passwords etc) | ||
460 | */ | ||
461 | at24->bin.attr.name = "eeprom"; | ||
462 | at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; | ||
463 | at24->bin.attr.owner = THIS_MODULE; | ||
464 | at24->bin.read = at24_bin_read; | ||
465 | at24->bin.size = chip.byte_len; | ||
466 | |||
467 | writable = !(chip.flags & AT24_FLAG_READONLY); | ||
468 | if (writable) { | ||
469 | if (!use_smbus || i2c_check_functionality(client->adapter, | ||
470 | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { | ||
471 | |||
472 | unsigned write_max = chip.page_size; | ||
473 | |||
474 | at24->bin.write = at24_bin_write; | ||
475 | at24->bin.attr.mode |= S_IWUSR; | ||
476 | |||
477 | if (write_max > io_limit) | ||
478 | write_max = io_limit; | ||
479 | if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) | ||
480 | write_max = I2C_SMBUS_BLOCK_MAX; | ||
481 | at24->write_max = write_max; | ||
482 | |||
483 | /* buffer (data + address at the beginning) */ | ||
484 | at24->writebuf = kmalloc(write_max + 2, GFP_KERNEL); | ||
485 | if (!at24->writebuf) { | ||
486 | err = -ENOMEM; | ||
487 | goto err_struct; | ||
488 | } | ||
489 | } else { | ||
490 | dev_warn(&client->dev, | ||
491 | "cannot write due to controller restrictions."); | ||
492 | } | ||
493 | } | ||
494 | |||
495 | at24->client[0] = client; | ||
496 | |||
497 | /* use dummy devices for multiple-address chips */ | ||
498 | for (i = 1; i < num_addresses; i++) { | ||
499 | at24->client[i] = i2c_new_dummy(client->adapter, | ||
500 | client->addr + i); | ||
501 | if (!at24->client[i]) { | ||
502 | dev_err(&client->dev, "address 0x%02x unavailable\n", | ||
503 | client->addr + i); | ||
504 | err = -EADDRINUSE; | ||
505 | goto err_clients; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | err = sysfs_create_bin_file(&client->dev.kobj, &at24->bin); | ||
510 | if (err) | ||
511 | goto err_clients; | ||
512 | |||
513 | i2c_set_clientdata(client, at24); | ||
514 | |||
515 | dev_info(&client->dev, "%Zd byte %s EEPROM %s\n", | ||
516 | at24->bin.size, client->name, | ||
517 | writable ? "(writable)" : "(read-only)"); | ||
518 | dev_dbg(&client->dev, | ||
519 | "page_size %d, num_addresses %d, write_max %d%s\n", | ||
520 | chip.page_size, num_addresses, | ||
521 | at24->write_max, | ||
522 | use_smbus ? ", use_smbus" : ""); | ||
523 | |||
524 | return 0; | ||
525 | |||
526 | err_clients: | ||
527 | for (i = 1; i < num_addresses; i++) | ||
528 | if (at24->client[i]) | ||
529 | i2c_unregister_device(at24->client[i]); | ||
530 | |||
531 | kfree(at24->writebuf); | ||
532 | err_struct: | ||
533 | kfree(at24); | ||
534 | err_out: | ||
535 | dev_dbg(&client->dev, "probe error %d\n", err); | ||
536 | return err; | ||
537 | } | ||
538 | |||
539 | static int __devexit at24_remove(struct i2c_client *client) | ||
540 | { | ||
541 | struct at24_data *at24; | ||
542 | int i; | ||
543 | |||
544 | at24 = i2c_get_clientdata(client); | ||
545 | sysfs_remove_bin_file(&client->dev.kobj, &at24->bin); | ||
546 | |||
547 | for (i = 1; i < at24->num_addresses; i++) | ||
548 | i2c_unregister_device(at24->client[i]); | ||
549 | |||
550 | kfree(at24->writebuf); | ||
551 | kfree(at24); | ||
552 | i2c_set_clientdata(client, NULL); | ||
553 | return 0; | ||
554 | } | ||
555 | |||
556 | /*-------------------------------------------------------------------------*/ | ||
557 | |||
558 | static struct i2c_driver at24_driver = { | ||
559 | .driver = { | ||
560 | .name = "at24", | ||
561 | .owner = THIS_MODULE, | ||
562 | }, | ||
563 | .probe = at24_probe, | ||
564 | .remove = __devexit_p(at24_remove), | ||
565 | .id_table = at24_ids, | ||
566 | }; | ||
567 | |||
568 | static int __init at24_init(void) | ||
569 | { | ||
570 | io_limit = rounddown_pow_of_two(io_limit); | ||
571 | return i2c_add_driver(&at24_driver); | ||
572 | } | ||
573 | module_init(at24_init); | ||
574 | |||
575 | static void __exit at24_exit(void) | ||
576 | { | ||
577 | i2c_del_driver(&at24_driver); | ||
578 | } | ||
579 | module_exit(at24_exit); | ||
580 | |||
581 | MODULE_DESCRIPTION("Driver for most I2C EEPROMs"); | ||
582 | MODULE_AUTHOR("David Brownell and Wolfram Sang"); | ||
583 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c index 7dee001e5133..373ea8d8fe8f 100644 --- a/drivers/i2c/chips/eeprom.c +++ b/drivers/i2c/chips/eeprom.c | |||
@@ -1,15 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | eeprom.c - Part of lm_sensors, Linux kernel modules for hardware | ||
3 | monitoring | ||
4 | Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and | 2 | Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and |
5 | Philip Edelbrock <phil@netroedge.com> | 3 | Philip Edelbrock <phil@netroedge.com> |
6 | Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> | 4 | Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> |
7 | Copyright (C) 2003 IBM Corp. | 5 | Copyright (C) 2003 IBM Corp. |
8 | 6 | Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> | |
9 | 2004-01-16 Jean Delvare <khali@linux-fr.org> | ||
10 | Divide the eeprom in 32-byte (arbitrary) slices. This significantly | ||
11 | speeds sensors up, as well as various scripts using the eeprom | ||
12 | module. | ||
13 | 7 | ||
14 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify |
15 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by |
@@ -78,7 +72,7 @@ static struct i2c_driver eeprom_driver = { | |||
78 | static void eeprom_update_client(struct i2c_client *client, u8 slice) | 72 | static void eeprom_update_client(struct i2c_client *client, u8 slice) |
79 | { | 73 | { |
80 | struct eeprom_data *data = i2c_get_clientdata(client); | 74 | struct eeprom_data *data = i2c_get_clientdata(client); |
81 | int i, j; | 75 | int i; |
82 | 76 | ||
83 | mutex_lock(&data->update_lock); | 77 | mutex_lock(&data->update_lock); |
84 | 78 | ||
@@ -93,15 +87,12 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice) | |||
93 | != 32) | 87 | != 32) |
94 | goto exit; | 88 | goto exit; |
95 | } else { | 89 | } else { |
96 | if (i2c_smbus_write_byte(client, slice << 5)) { | 90 | for (i = slice << 5; i < (slice + 1) << 5; i += 2) { |
97 | dev_dbg(&client->dev, "eeprom read start has failed!\n"); | 91 | int word = i2c_smbus_read_word_data(client, i); |
98 | goto exit; | 92 | if (word < 0) |
99 | } | ||
100 | for (i = slice << 5; i < (slice + 1) << 5; i++) { | ||
101 | j = i2c_smbus_read_byte(client); | ||
102 | if (j < 0) | ||
103 | goto exit; | 93 | goto exit; |
104 | data->data[i] = (u8) j; | 94 | data->data[i] = word & 0xff; |
95 | data->data[i + 1] = word >> 8; | ||
105 | } | 96 | } |
106 | } | 97 | } |
107 | data->last_updated[slice] = jiffies; | 98 | data->last_updated[slice] = jiffies; |
@@ -159,24 +150,33 @@ static struct bin_attribute eeprom_attr = { | |||
159 | 150 | ||
160 | static int eeprom_attach_adapter(struct i2c_adapter *adapter) | 151 | static int eeprom_attach_adapter(struct i2c_adapter *adapter) |
161 | { | 152 | { |
153 | if (!(adapter->class & (I2C_CLASS_DDC | I2C_CLASS_SPD))) | ||
154 | return 0; | ||
162 | return i2c_probe(adapter, &addr_data, eeprom_detect); | 155 | return i2c_probe(adapter, &addr_data, eeprom_detect); |
163 | } | 156 | } |
164 | 157 | ||
165 | /* This function is called by i2c_probe */ | 158 | /* This function is called by i2c_probe */ |
166 | static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | 159 | static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) |
167 | { | 160 | { |
168 | struct i2c_client *new_client; | 161 | struct i2c_client *client; |
169 | struct eeprom_data *data; | 162 | struct eeprom_data *data; |
170 | int err = 0; | 163 | int err = 0; |
171 | 164 | ||
172 | /* There are three ways we can read the EEPROM data: | 165 | /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all |
166 | addresses 0x50-0x57, but we only care about 0x50. So decline | ||
167 | attaching to addresses >= 0x51 on DDC buses */ | ||
168 | if (!(adapter->class & I2C_CLASS_SPD) && address >= 0x51) | ||
169 | goto exit; | ||
170 | |||
171 | /* There are four ways we can read the EEPROM data: | ||
173 | (1) I2C block reads (faster, but unsupported by most adapters) | 172 | (1) I2C block reads (faster, but unsupported by most adapters) |
174 | (2) Consecutive byte reads (100% overhead) | 173 | (2) Word reads (128% overhead) |
175 | (3) Regular byte data reads (200% overhead) | 174 | (3) Consecutive byte reads (88% overhead, unsafe) |
176 | The third method is not implemented by this driver because all | 175 | (4) Regular byte data reads (265% overhead) |
177 | known adapters support at least the second. */ | 176 | The third and fourth methods are not implemented by this driver |
178 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA | 177 | because all known adapters support one of the first two. */ |
179 | | I2C_FUNC_SMBUS_BYTE)) | 178 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA) |
179 | && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) | ||
180 | goto exit; | 180 | goto exit; |
181 | 181 | ||
182 | if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { | 182 | if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { |
@@ -184,50 +184,49 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) | |||
184 | goto exit; | 184 | goto exit; |
185 | } | 185 | } |
186 | 186 | ||
187 | new_client = &data->client; | 187 | client = &data->client; |
188 | memset(data->data, 0xff, EEPROM_SIZE); | 188 | memset(data->data, 0xff, EEPROM_SIZE); |
189 | i2c_set_clientdata(new_client, data); | 189 | i2c_set_clientdata(client, data); |
190 | new_client->addr = address; | 190 | client->addr = address; |
191 | new_client->adapter = adapter; | 191 | client->adapter = adapter; |
192 | new_client->driver = &eeprom_driver; | 192 | client->driver = &eeprom_driver; |
193 | new_client->flags = 0; | ||
194 | 193 | ||
195 | /* Fill in the remaining client fields */ | 194 | /* Fill in the remaining client fields */ |
196 | strlcpy(new_client->name, "eeprom", I2C_NAME_SIZE); | 195 | strlcpy(client->name, "eeprom", I2C_NAME_SIZE); |
197 | data->valid = 0; | ||
198 | mutex_init(&data->update_lock); | 196 | mutex_init(&data->update_lock); |
199 | data->nature = UNKNOWN; | 197 | data->nature = UNKNOWN; |
200 | 198 | ||
201 | /* Tell the I2C layer a new client has arrived */ | 199 | /* Tell the I2C layer a new client has arrived */ |
202 | if ((err = i2c_attach_client(new_client))) | 200 | if ((err = i2c_attach_client(client))) |
203 | goto exit_kfree; | 201 | goto exit_kfree; |
204 | 202 | ||
205 | /* Detect the Vaio nature of EEPROMs. | 203 | /* Detect the Vaio nature of EEPROMs. |
206 | We use the "PCG-" or "VGN-" prefix as the signature. */ | 204 | We use the "PCG-" or "VGN-" prefix as the signature. */ |
207 | if (address == 0x57) { | 205 | if (address == 0x57 |
206 | && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { | ||
208 | char name[4]; | 207 | char name[4]; |
209 | 208 | ||
210 | name[0] = i2c_smbus_read_byte_data(new_client, 0x80); | 209 | name[0] = i2c_smbus_read_byte_data(client, 0x80); |
211 | name[1] = i2c_smbus_read_byte(new_client); | 210 | name[1] = i2c_smbus_read_byte_data(client, 0x81); |
212 | name[2] = i2c_smbus_read_byte(new_client); | 211 | name[2] = i2c_smbus_read_byte_data(client, 0x82); |
213 | name[3] = i2c_smbus_read_byte(new_client); | 212 | name[3] = i2c_smbus_read_byte_data(client, 0x83); |
214 | 213 | ||
215 | if (!memcmp(name, "PCG-", 4) || !memcmp(name, "VGN-", 4)) { | 214 | if (!memcmp(name, "PCG-", 4) || !memcmp(name, "VGN-", 4)) { |
216 | dev_info(&new_client->dev, "Vaio EEPROM detected, " | 215 | dev_info(&client->dev, "Vaio EEPROM detected, " |
217 | "enabling privacy protection\n"); | 216 | "enabling privacy protection\n"); |
218 | data->nature = VAIO; | 217 | data->nature = VAIO; |
219 | } | 218 | } |
220 | } | 219 | } |
221 | 220 | ||
222 | /* create the sysfs eeprom file */ | 221 | /* create the sysfs eeprom file */ |
223 | err = sysfs_create_bin_file(&new_client->dev.kobj, &eeprom_attr); | 222 | err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr); |
224 | if (err) | 223 | if (err) |
225 | goto exit_detach; | 224 | goto exit_detach; |
226 | 225 | ||
227 | return 0; | 226 | return 0; |
228 | 227 | ||
229 | exit_detach: | 228 | exit_detach: |
230 | i2c_detach_client(new_client); | 229 | i2c_detach_client(client); |
231 | exit_kfree: | 230 | exit_kfree: |
232 | kfree(data); | 231 | kfree(data); |
233 | exit: | 232 | exit: |
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c index cf507b3f60f3..5a0285d8b6f9 100644 --- a/drivers/i2c/chips/max6875.c +++ b/drivers/i2c/chips/max6875.c | |||
@@ -170,7 +170,7 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) | |||
170 | struct i2c_client *real_client; | 170 | struct i2c_client *real_client; |
171 | struct i2c_client *fake_client; | 171 | struct i2c_client *fake_client; |
172 | struct max6875_data *data; | 172 | struct max6875_data *data; |
173 | int err = 0; | 173 | int err; |
174 | 174 | ||
175 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA | 175 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
176 | | I2C_FUNC_SMBUS_READ_BYTE)) | 176 | | I2C_FUNC_SMBUS_READ_BYTE)) |
@@ -195,7 +195,6 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) | |||
195 | real_client->addr = address; | 195 | real_client->addr = address; |
196 | real_client->adapter = adapter; | 196 | real_client->adapter = adapter; |
197 | real_client->driver = &max6875_driver; | 197 | real_client->driver = &max6875_driver; |
198 | real_client->flags = 0; | ||
199 | strlcpy(real_client->name, "max6875", I2C_NAME_SIZE); | 198 | strlcpy(real_client->name, "max6875", I2C_NAME_SIZE); |
200 | mutex_init(&data->update_lock); | 199 | mutex_init(&data->update_lock); |
201 | 200 | ||
@@ -204,7 +203,6 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) | |||
204 | fake_client->addr = address | 1; | 203 | fake_client->addr = address | 1; |
205 | fake_client->adapter = adapter; | 204 | fake_client->adapter = adapter; |
206 | fake_client->driver = &max6875_driver; | 205 | fake_client->driver = &max6875_driver; |
207 | fake_client->flags = 0; | ||
208 | strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE); | 206 | strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE); |
209 | 207 | ||
210 | if ((err = i2c_attach_client(real_client)) != 0) | 208 | if ((err = i2c_attach_client(real_client)) != 0) |
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c index f43c4e79b55e..58ab7f26be26 100644 --- a/drivers/i2c/chips/pca9539.c +++ b/drivers/i2c/chips/pca9539.c | |||
@@ -113,7 +113,7 @@ static int pca9539_attach_adapter(struct i2c_adapter *adapter) | |||
113 | /* This function is called by i2c_probe */ | 113 | /* This function is called by i2c_probe */ |
114 | static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) | 114 | static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) |
115 | { | 115 | { |
116 | struct i2c_client *new_client; | 116 | struct i2c_client *client; |
117 | struct pca9539_data *data; | 117 | struct pca9539_data *data; |
118 | int err = 0; | 118 | int err = 0; |
119 | 119 | ||
@@ -127,29 +127,28 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) | |||
127 | goto exit; | 127 | goto exit; |
128 | } | 128 | } |
129 | 129 | ||
130 | new_client = &data->client; | 130 | client = &data->client; |
131 | i2c_set_clientdata(new_client, data); | 131 | i2c_set_clientdata(client, data); |
132 | new_client->addr = address; | 132 | client->addr = address; |
133 | new_client->adapter = adapter; | 133 | client->adapter = adapter; |
134 | new_client->driver = &pca9539_driver; | 134 | client->driver = &pca9539_driver; |
135 | new_client->flags = 0; | ||
136 | 135 | ||
137 | if (kind < 0) { | 136 | if (kind < 0) { |
138 | /* Detection: the pca9539 only has 8 registers (0-7). | 137 | /* Detection: the pca9539 only has 8 registers (0-7). |
139 | A read of 7 should succeed, but a read of 8 should fail. */ | 138 | A read of 7 should succeed, but a read of 8 should fail. */ |
140 | if ((i2c_smbus_read_byte_data(new_client, 7) < 0) || | 139 | if ((i2c_smbus_read_byte_data(client, 7) < 0) || |
141 | (i2c_smbus_read_byte_data(new_client, 8) >= 0)) | 140 | (i2c_smbus_read_byte_data(client, 8) >= 0)) |
142 | goto exit_kfree; | 141 | goto exit_kfree; |
143 | } | 142 | } |
144 | 143 | ||
145 | strlcpy(new_client->name, "pca9539", I2C_NAME_SIZE); | 144 | strlcpy(client->name, "pca9539", I2C_NAME_SIZE); |
146 | 145 | ||
147 | /* Tell the I2C layer a new client has arrived */ | 146 | /* Tell the I2C layer a new client has arrived */ |
148 | if ((err = i2c_attach_client(new_client))) | 147 | if ((err = i2c_attach_client(client))) |
149 | goto exit_kfree; | 148 | goto exit_kfree; |
150 | 149 | ||
151 | /* Register sysfs hooks */ | 150 | /* Register sysfs hooks */ |
152 | err = sysfs_create_group(&new_client->dev.kobj, | 151 | err = sysfs_create_group(&client->dev.kobj, |
153 | &pca9539_defattr_group); | 152 | &pca9539_defattr_group); |
154 | if (err) | 153 | if (err) |
155 | goto exit_detach; | 154 | goto exit_detach; |
@@ -157,7 +156,7 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) | |||
157 | return 0; | 156 | return 0; |
158 | 157 | ||
159 | exit_detach: | 158 | exit_detach: |
160 | i2c_detach_client(new_client); | 159 | i2c_detach_client(client); |
161 | exit_kfree: | 160 | exit_kfree: |
162 | kfree(data); | 161 | kfree(data); |
163 | exit: | 162 | exit: |
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c index e5b31329b56e..1b3db2b3ada9 100644 --- a/drivers/i2c/chips/pcf8574.c +++ b/drivers/i2c/chips/pcf8574.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | pcf8574.c - Part of lm_sensors, Linux kernel modules for hardware | ||
3 | monitoring | ||
4 | Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>, | 2 | Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>, |
5 | Philip Edelbrock <phil@netroedge.com>, | 3 | Philip Edelbrock <phil@netroedge.com>, |
6 | Dan Eaton <dan.eaton@rocketlogix.com> | 4 | Dan Eaton <dan.eaton@rocketlogix.com> |
@@ -129,7 +127,7 @@ static int pcf8574_attach_adapter(struct i2c_adapter *adapter) | |||
129 | /* This function is called by i2c_probe */ | 127 | /* This function is called by i2c_probe */ |
130 | static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | 128 | static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) |
131 | { | 129 | { |
132 | struct i2c_client *new_client; | 130 | struct i2c_client *client; |
133 | struct pcf8574_data *data; | 131 | struct pcf8574_data *data; |
134 | int err = 0; | 132 | int err = 0; |
135 | const char *client_name = ""; | 133 | const char *client_name = ""; |
@@ -144,12 +142,11 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | |||
144 | goto exit; | 142 | goto exit; |
145 | } | 143 | } |
146 | 144 | ||
147 | new_client = &data->client; | 145 | client = &data->client; |
148 | i2c_set_clientdata(new_client, data); | 146 | i2c_set_clientdata(client, data); |
149 | new_client->addr = address; | 147 | client->addr = address; |
150 | new_client->adapter = adapter; | 148 | client->adapter = adapter; |
151 | new_client->driver = &pcf8574_driver; | 149 | client->driver = &pcf8574_driver; |
152 | new_client->flags = 0; | ||
153 | 150 | ||
154 | /* Now, we would do the remaining detection. But the PCF8574 is plainly | 151 | /* Now, we would do the remaining detection. But the PCF8574 is plainly |
155 | impossible to detect! Stupid chip. */ | 152 | impossible to detect! Stupid chip. */ |
@@ -168,23 +165,23 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) | |||
168 | client_name = "pcf8574"; | 165 | client_name = "pcf8574"; |
169 | 166 | ||
170 | /* Fill in the remaining client fields and put it into the global list */ | 167 | /* Fill in the remaining client fields and put it into the global list */ |
171 | strlcpy(new_client->name, client_name, I2C_NAME_SIZE); | 168 | strlcpy(client->name, client_name, I2C_NAME_SIZE); |
172 | 169 | ||
173 | /* Tell the I2C layer a new client has arrived */ | 170 | /* Tell the I2C layer a new client has arrived */ |
174 | if ((err = i2c_attach_client(new_client))) | 171 | if ((err = i2c_attach_client(client))) |
175 | goto exit_free; | 172 | goto exit_free; |
176 | 173 | ||
177 | /* Initialize the PCF8574 chip */ | 174 | /* Initialize the PCF8574 chip */ |
178 | pcf8574_init_client(new_client); | 175 | pcf8574_init_client(client); |
179 | 176 | ||
180 | /* Register sysfs hooks */ | 177 | /* Register sysfs hooks */ |
181 | err = sysfs_create_group(&new_client->dev.kobj, &pcf8574_attr_group); | 178 | err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group); |
182 | if (err) | 179 | if (err) |
183 | goto exit_detach; | 180 | goto exit_detach; |
184 | return 0; | 181 | return 0; |
185 | 182 | ||
186 | exit_detach: | 183 | exit_detach: |
187 | i2c_detach_client(new_client); | 184 | i2c_detach_client(client); |
188 | exit_free: | 185 | exit_free: |
189 | kfree(data); | 186 | kfree(data); |
190 | exit: | 187 | exit: |
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c index 66c7c3bb9429..db735379f22f 100644 --- a/drivers/i2c/chips/pcf8591.c +++ b/drivers/i2c/chips/pcf8591.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | pcf8591.c - Part of lm_sensors, Linux kernel modules for hardware | ||
3 | monitoring | ||
4 | Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net> | 2 | Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net> |
5 | Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with | 3 | Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with |
6 | the help of Jean Delvare <khali@linux-fr.org> | 4 | the help of Jean Delvare <khali@linux-fr.org> |
@@ -190,7 +188,7 @@ static int pcf8591_attach_adapter(struct i2c_adapter *adapter) | |||
190 | /* This function is called by i2c_probe */ | 188 | /* This function is called by i2c_probe */ |
191 | static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | 189 | static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) |
192 | { | 190 | { |
193 | struct i2c_client *new_client; | 191 | struct i2c_client *client; |
194 | struct pcf8591_data *data; | 192 | struct pcf8591_data *data; |
195 | int err = 0; | 193 | int err = 0; |
196 | 194 | ||
@@ -205,12 +203,11 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | |||
205 | goto exit; | 203 | goto exit; |
206 | } | 204 | } |
207 | 205 | ||
208 | new_client = &data->client; | 206 | client = &data->client; |
209 | i2c_set_clientdata(new_client, data); | 207 | i2c_set_clientdata(client, data); |
210 | new_client->addr = address; | 208 | client->addr = address; |
211 | new_client->adapter = adapter; | 209 | client->adapter = adapter; |
212 | new_client->driver = &pcf8591_driver; | 210 | client->driver = &pcf8591_driver; |
213 | new_client->flags = 0; | ||
214 | 211 | ||
215 | /* Now, we would do the remaining detection. But the PCF8591 is plainly | 212 | /* Now, we would do the remaining detection. But the PCF8591 is plainly |
216 | impossible to detect! Stupid chip. */ | 213 | impossible to detect! Stupid chip. */ |
@@ -221,31 +218,31 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | |||
221 | 218 | ||
222 | /* Fill in the remaining client fields and put it into the global | 219 | /* Fill in the remaining client fields and put it into the global |
223 | list */ | 220 | list */ |
224 | strlcpy(new_client->name, "pcf8591", I2C_NAME_SIZE); | 221 | strlcpy(client->name, "pcf8591", I2C_NAME_SIZE); |
225 | mutex_init(&data->update_lock); | 222 | mutex_init(&data->update_lock); |
226 | 223 | ||
227 | /* Tell the I2C layer a new client has arrived */ | 224 | /* Tell the I2C layer a new client has arrived */ |
228 | if ((err = i2c_attach_client(new_client))) | 225 | if ((err = i2c_attach_client(client))) |
229 | goto exit_kfree; | 226 | goto exit_kfree; |
230 | 227 | ||
231 | /* Initialize the PCF8591 chip */ | 228 | /* Initialize the PCF8591 chip */ |
232 | pcf8591_init_client(new_client); | 229 | pcf8591_init_client(client); |
233 | 230 | ||
234 | /* Register sysfs hooks */ | 231 | /* Register sysfs hooks */ |
235 | err = sysfs_create_group(&new_client->dev.kobj, &pcf8591_attr_group); | 232 | err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); |
236 | if (err) | 233 | if (err) |
237 | goto exit_detach; | 234 | goto exit_detach; |
238 | 235 | ||
239 | /* Register input2 if not in "two differential inputs" mode */ | 236 | /* Register input2 if not in "two differential inputs" mode */ |
240 | if (input_mode != 3) { | 237 | if (input_mode != 3) { |
241 | if ((err = device_create_file(&new_client->dev, | 238 | if ((err = device_create_file(&client->dev, |
242 | &dev_attr_in2_input))) | 239 | &dev_attr_in2_input))) |
243 | goto exit_sysfs_remove; | 240 | goto exit_sysfs_remove; |
244 | } | 241 | } |
245 | 242 | ||
246 | /* Register input3 only in "four single ended inputs" mode */ | 243 | /* Register input3 only in "four single ended inputs" mode */ |
247 | if (input_mode == 0) { | 244 | if (input_mode == 0) { |
248 | if ((err = device_create_file(&new_client->dev, | 245 | if ((err = device_create_file(&client->dev, |
249 | &dev_attr_in3_input))) | 246 | &dev_attr_in3_input))) |
250 | goto exit_sysfs_remove; | 247 | goto exit_sysfs_remove; |
251 | } | 248 | } |
@@ -253,10 +250,10 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) | |||
253 | return 0; | 250 | return 0; |
254 | 251 | ||
255 | exit_sysfs_remove: | 252 | exit_sysfs_remove: |
256 | sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group_opt); | 253 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); |
257 | sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group); | 254 | sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); |
258 | exit_detach: | 255 | exit_detach: |
259 | i2c_detach_client(new_client); | 256 | i2c_detach_client(client); |
260 | exit_kfree: | 257 | exit_kfree: |
261 | kfree(data); | 258 | kfree(data); |
262 | exit: | 259 | exit: |