aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-09-23 12:30:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-23 12:30:48 -0400
commit40aba218969914d1b225e742617adb921cf94eae (patch)
tree663ec9cdadbedec5f8eab754cbc590298c1d40be /drivers/i2c
parentb64ada6b23d4a305fb3ca59b79dd38707fc53b69 (diff)
parentcfd550ed3d3bd509b475c7a9d425fc63bf843a7c (diff)
Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
* 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: i2c: Clearly mark ACPI drivers as such i2c: Add driver for SMBus Control Method Interface i2c-pnx: Correct use of request_region/request_mem_region MAINTAINERS: Add maintainer for AT24 and PCA9564/PCA9665 i2c-piix4: Add AMD SB900 SMBus device ID i2c/chips: Remove deprecated pcf8574 driver i2c/chips: Remove deprecated pca9539 driver i2c/chips: Remove deprecated pcf8575 driver gpio/pcf857x: Copy i2c_device_id from old pcf8574 driver i2c/scx200_acb: Provide more information on bus errors i2c: Provide compatibility links for i2c adapters i2c: Convert i2c adapters to bus devices i2c: Convert i2c clients to a device type i2c/tsl2550: Use combined SMBus transactions i2c-taos-evm: Switch echo off to improve performance i2c: Drop unused i2c_driver.id field
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/Kconfig8
-rw-r--r--drivers/i2c/busses/Kconfig19
-rw-r--r--drivers/i2c/busses/Makefile3
-rw-r--r--drivers/i2c/busses/i2c-piix4.c9
-rw-r--r--drivers/i2c/busses/i2c-pnx.c7
-rw-r--r--drivers/i2c/busses/i2c-scmi.c430
-rw-r--r--drivers/i2c/busses/i2c-taos-evm.c45
-rw-r--r--drivers/i2c/busses/scx200_acb.c6
-rw-r--r--drivers/i2c/chips/Kconfig48
-rw-r--r--drivers/i2c/chips/Makefile3
-rw-r--r--drivers/i2c/chips/pca9539.c152
-rw-r--r--drivers/i2c/chips/pcf8574.c215
-rw-r--r--drivers/i2c/chips/pcf8575.c198
-rw-r--r--drivers/i2c/chips/tsl2550.c42
-rw-r--r--drivers/i2c/i2c-core.c165
15 files changed, 621 insertions, 729 deletions
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 711ca08ab776..d7ece131b4f4 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -27,6 +27,14 @@ config I2C_BOARDINFO
27 boolean 27 boolean
28 default y 28 default y
29 29
30config I2C_COMPAT
31 boolean "Enable compatibility bits for old user-space"
32 default y
33 help
34 Say Y here if you intend to run lm-sensors 3.1.1 or older, or any
35 other user-space package which expects i2c adapters to be class
36 devices. If you don't know, say Y.
37
30config I2C_CHARDEV 38config I2C_CHARDEV
31 tristate "I2C device interface" 39 tristate "I2C device interface"
32 help 40 help
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 8206442fbabd..6bedd2fcfc15 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -113,7 +113,7 @@ config I2C_ISCH
113 will be called i2c-isch. 113 will be called i2c-isch.
114 114
115config I2C_PIIX4 115config I2C_PIIX4
116 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)" 116 tristate "Intel PIIX4 and compatible (ATI/AMD/Serverworks/Broadcom/SMSC)"
117 depends on PCI 117 depends on PCI
118 help 118 help
119 If you say yes to this option, support will be included for the Intel 119 If you say yes to this option, support will be included for the Intel
@@ -128,6 +128,7 @@ config I2C_PIIX4
128 ATI SB600 128 ATI SB600
129 ATI SB700 129 ATI SB700
130 ATI SB800 130 ATI SB800
131 AMD SB900
131 Serverworks OSB4 132 Serverworks OSB4
132 Serverworks CSB5 133 Serverworks CSB5
133 Serverworks CSB6 134 Serverworks CSB6
@@ -231,6 +232,22 @@ config I2C_VIAPRO
231 This driver can also be built as a module. If so, the module 232 This driver can also be built as a module. If so, the module
232 will be called i2c-viapro. 233 will be called i2c-viapro.
233 234
235if ACPI
236
237comment "ACPI drivers"
238
239config I2C_SCMI
240 tristate "SMBus Control Method Interface"
241 help
242 This driver supports the SMBus Control Method Interface. It needs the
243 BIOS to declare ACPI control methods as described in the SMBus Control
244 Method Interface specification.
245
246 To compile this driver as a module, choose M here:
247 the module will be called i2c-scmi.
248
249endif # ACPI
250
234comment "Mac SMBus host controller drivers" 251comment "Mac SMBus host controller drivers"
235 depends on PPC_CHRP || PPC_PMAC 252 depends on PPC_CHRP || PPC_PMAC
236 253
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index e654263bfc01..ff937ac69f5b 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -2,6 +2,9 @@
2# Makefile for the i2c bus drivers. 2# Makefile for the i2c bus drivers.
3# 3#
4 4
5# ACPI drivers
6obj-$(CONFIG_I2C_SCMI) += i2c-scmi.o
7
5# PC SMBus host controller drivers 8# PC SMBus host controller drivers
6obj-$(CONFIG_I2C_ALI1535) += i2c-ali1535.o 9obj-$(CONFIG_I2C_ALI1535) += i2c-ali1535.o
7obj-$(CONFIG_I2C_ALI1563) += i2c-ali1563.o 10obj-$(CONFIG_I2C_ALI1563) += i2c-ali1563.o
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 0249a7d762b9..a782c7a08f9e 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -22,6 +22,7 @@
22 Intel PIIX4, 440MX 22 Intel PIIX4, 440MX
23 Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100 23 Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100
24 ATI IXP200, IXP300, IXP400, SB600, SB700, SB800 24 ATI IXP200, IXP300, IXP400, SB600, SB700, SB800
25 AMD SB900
25 SMSC Victory66 26 SMSC Victory66
26 27
27 Note: we assume there can only be one device, with one SMBus interface. 28 Note: we assume there can only be one device, with one SMBus interface.
@@ -479,6 +480,7 @@ static struct pci_device_id piix4_ids[] = {
479 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) }, 480 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) },
480 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) }, 481 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) },
481 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) }, 482 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) },
483 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_SB900_SMBUS) },
482 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 484 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
483 PCI_DEVICE_ID_SERVERWORKS_OSB4) }, 485 PCI_DEVICE_ID_SERVERWORKS_OSB4) },
484 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 486 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
@@ -499,9 +501,10 @@ static int __devinit piix4_probe(struct pci_dev *dev,
499{ 501{
500 int retval; 502 int retval;
501 503
502 if ((dev->vendor == PCI_VENDOR_ID_ATI) && 504 if ((dev->vendor == PCI_VENDOR_ID_ATI &&
503 (dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) && 505 dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
504 (dev->revision >= 0x40)) 506 dev->revision >= 0x40) ||
507 dev->vendor == PCI_VENDOR_ID_AMD)
505 /* base address location etc changed in SB800 */ 508 /* base address location etc changed in SB800 */
506 retval = piix4_setup_sb800(dev, id); 509 retval = piix4_setup_sb800(dev, id);
507 else 510 else
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index ec15cff556b9..6ff6c20f1e78 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -586,7 +586,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
586 alg_data->mif.timer.data = (unsigned long)i2c_pnx->adapter; 586 alg_data->mif.timer.data = (unsigned long)i2c_pnx->adapter;
587 587
588 /* Register I/O resource */ 588 /* Register I/O resource */
589 if (!request_region(alg_data->base, I2C_PNX_REGION_SIZE, pdev->name)) { 589 if (!request_mem_region(alg_data->base, I2C_PNX_REGION_SIZE,
590 pdev->name)) {
590 dev_err(&pdev->dev, 591 dev_err(&pdev->dev,
591 "I/O region 0x%08x for I2C already in use.\n", 592 "I/O region 0x%08x for I2C already in use.\n",
592 alg_data->base); 593 alg_data->base);
@@ -650,7 +651,7 @@ out_clock:
650out_unmap: 651out_unmap:
651 iounmap((void *)alg_data->ioaddr); 652 iounmap((void *)alg_data->ioaddr);
652out_release: 653out_release:
653 release_region(alg_data->base, I2C_PNX_REGION_SIZE); 654 release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
654out_drvdata: 655out_drvdata:
655 platform_set_drvdata(pdev, NULL); 656 platform_set_drvdata(pdev, NULL);
656out: 657out:
@@ -667,7 +668,7 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)
667 i2c_del_adapter(adap); 668 i2c_del_adapter(adap);
668 i2c_pnx->set_clock_stop(pdev); 669 i2c_pnx->set_clock_stop(pdev);
669 iounmap((void *)alg_data->ioaddr); 670 iounmap((void *)alg_data->ioaddr);
670 release_region(alg_data->base, I2C_PNX_REGION_SIZE); 671 release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
671 platform_set_drvdata(pdev, NULL); 672 platform_set_drvdata(pdev, NULL);
672 673
673 return 0; 674 return 0;
diff --git a/drivers/i2c/busses/i2c-scmi.c b/drivers/i2c/busses/i2c-scmi.c
new file mode 100644
index 000000000000..276a046ac93f
--- /dev/null
+++ b/drivers/i2c/busses/i2c-scmi.c
@@ -0,0 +1,430 @@
1/*
2 * SMBus driver for ACPI SMBus CMI
3 *
4 * Copyright (C) 2009 Crane Cai <crane.cai@amd.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation version 2.
9 */
10
11#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/kernel.h>
14#include <linux/stddef.h>
15#include <linux/init.h>
16#include <linux/i2c.h>
17#include <linux/acpi.h>
18
19#define ACPI_SMBUS_HC_CLASS "smbus"
20#define ACPI_SMBUS_HC_DEVICE_NAME "cmi"
21
22ACPI_MODULE_NAME("smbus_cmi");
23
24struct smbus_methods_t {
25 char *mt_info;
26 char *mt_sbr;
27 char *mt_sbw;
28};
29
30struct acpi_smbus_cmi {
31 acpi_handle handle;
32 struct i2c_adapter adapter;
33 u8 cap_info:1;
34 u8 cap_read:1;
35 u8 cap_write:1;
36};
37
38static const struct smbus_methods_t smbus_methods = {
39 .mt_info = "_SBI",
40 .mt_sbr = "_SBR",
41 .mt_sbw = "_SBW",
42};
43
44static const struct acpi_device_id acpi_smbus_cmi_ids[] = {
45 {"SMBUS01", 0},
46 {"", 0}
47};
48
49#define ACPI_SMBUS_STATUS_OK 0x00
50#define ACPI_SMBUS_STATUS_FAIL 0x07
51#define ACPI_SMBUS_STATUS_DNAK 0x10
52#define ACPI_SMBUS_STATUS_DERR 0x11
53#define ACPI_SMBUS_STATUS_CMD_DENY 0x12
54#define ACPI_SMBUS_STATUS_UNKNOWN 0x13
55#define ACPI_SMBUS_STATUS_ACC_DENY 0x17
56#define ACPI_SMBUS_STATUS_TIMEOUT 0x18
57#define ACPI_SMBUS_STATUS_NOTSUP 0x19
58#define ACPI_SMBUS_STATUS_BUSY 0x1a
59#define ACPI_SMBUS_STATUS_PEC 0x1f
60
61#define ACPI_SMBUS_PRTCL_WRITE 0x00
62#define ACPI_SMBUS_PRTCL_READ 0x01
63#define ACPI_SMBUS_PRTCL_QUICK 0x02
64#define ACPI_SMBUS_PRTCL_BYTE 0x04
65#define ACPI_SMBUS_PRTCL_BYTE_DATA 0x06
66#define ACPI_SMBUS_PRTCL_WORD_DATA 0x08
67#define ACPI_SMBUS_PRTCL_BLOCK_DATA 0x0a
68
69
70static int
71acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
72 char read_write, u8 command, int size,
73 union i2c_smbus_data *data)
74{
75 int result = 0;
76 struct acpi_smbus_cmi *smbus_cmi = adap->algo_data;
77 unsigned char protocol;
78 acpi_status status = 0;
79 struct acpi_object_list input;
80 union acpi_object mt_params[5];
81 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
82 union acpi_object *obj;
83 union acpi_object *pkg;
84 char *method;
85 int len = 0;
86
87 dev_dbg(&adap->dev, "access size: %d %s\n", size,
88 (read_write) ? "READ" : "WRITE");
89 switch (size) {
90 case I2C_SMBUS_QUICK:
91 protocol = ACPI_SMBUS_PRTCL_QUICK;
92 command = 0;
93 if (read_write == I2C_SMBUS_WRITE) {
94 mt_params[3].type = ACPI_TYPE_INTEGER;
95 mt_params[3].integer.value = 0;
96 mt_params[4].type = ACPI_TYPE_INTEGER;
97 mt_params[4].integer.value = 0;
98 }
99 break;
100
101 case I2C_SMBUS_BYTE:
102 protocol = ACPI_SMBUS_PRTCL_BYTE;
103 if (read_write == I2C_SMBUS_WRITE) {
104 mt_params[3].type = ACPI_TYPE_INTEGER;
105 mt_params[3].integer.value = 0;
106 mt_params[4].type = ACPI_TYPE_INTEGER;
107 mt_params[4].integer.value = 0;
108 } else {
109 command = 0;
110 }
111 break;
112
113 case I2C_SMBUS_BYTE_DATA:
114 protocol = ACPI_SMBUS_PRTCL_BYTE_DATA;
115 if (read_write == I2C_SMBUS_WRITE) {
116 mt_params[3].type = ACPI_TYPE_INTEGER;
117 mt_params[3].integer.value = 1;
118 mt_params[4].type = ACPI_TYPE_INTEGER;
119 mt_params[4].integer.value = data->byte;
120 }
121 break;
122
123 case I2C_SMBUS_WORD_DATA:
124 protocol = ACPI_SMBUS_PRTCL_WORD_DATA;
125 if (read_write == I2C_SMBUS_WRITE) {
126 mt_params[3].type = ACPI_TYPE_INTEGER;
127 mt_params[3].integer.value = 2;
128 mt_params[4].type = ACPI_TYPE_INTEGER;
129 mt_params[4].integer.value = data->word;
130 }
131 break;
132
133 case I2C_SMBUS_BLOCK_DATA:
134 protocol = ACPI_SMBUS_PRTCL_BLOCK_DATA;
135 if (read_write == I2C_SMBUS_WRITE) {
136 len = data->block[0];
137 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
138 return -EINVAL;
139 mt_params[3].type = ACPI_TYPE_INTEGER;
140 mt_params[3].integer.value = len;
141 mt_params[4].type = ACPI_TYPE_BUFFER;
142 mt_params[4].buffer.pointer = data->block + 1;
143 }
144 break;
145
146 default:
147 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
148 return -EOPNOTSUPP;
149 }
150
151 if (read_write == I2C_SMBUS_READ) {
152 protocol |= ACPI_SMBUS_PRTCL_READ;
153 method = smbus_methods.mt_sbr;
154 input.count = 3;
155 } else {
156 protocol |= ACPI_SMBUS_PRTCL_WRITE;
157 method = smbus_methods.mt_sbw;
158 input.count = 5;
159 }
160
161 input.pointer = mt_params;
162 mt_params[0].type = ACPI_TYPE_INTEGER;
163 mt_params[0].integer.value = protocol;
164 mt_params[1].type = ACPI_TYPE_INTEGER;
165 mt_params[1].integer.value = addr;
166 mt_params[2].type = ACPI_TYPE_INTEGER;
167 mt_params[2].integer.value = command;
168
169 status = acpi_evaluate_object(smbus_cmi->handle, method, &input,
170 &buffer);
171 if (ACPI_FAILURE(status)) {
172 ACPI_ERROR((AE_INFO, "Evaluating %s: %i", method, status));
173 return -EIO;
174 }
175
176 pkg = buffer.pointer;
177 if (pkg && pkg->type == ACPI_TYPE_PACKAGE)
178 obj = pkg->package.elements;
179 else {
180 ACPI_ERROR((AE_INFO, "Invalid argument type"));
181 result = -EIO;
182 goto out;
183 }
184 if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) {
185 ACPI_ERROR((AE_INFO, "Invalid argument type"));
186 result = -EIO;
187 goto out;
188 }
189
190 result = obj->integer.value;
191 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s return status: %i\n",
192 method, result));
193
194 switch (result) {
195 case ACPI_SMBUS_STATUS_OK:
196 result = 0;
197 break;
198 case ACPI_SMBUS_STATUS_BUSY:
199 result = -EBUSY;
200 goto out;
201 case ACPI_SMBUS_STATUS_TIMEOUT:
202 result = -ETIMEDOUT;
203 goto out;
204 case ACPI_SMBUS_STATUS_DNAK:
205 result = -ENXIO;
206 goto out;
207 default:
208 result = -EIO;
209 goto out;
210 }
211
212 if (read_write == I2C_SMBUS_WRITE || size == I2C_SMBUS_QUICK)
213 goto out;
214
215 obj = pkg->package.elements + 1;
216 if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) {
217 ACPI_ERROR((AE_INFO, "Invalid argument type"));
218 result = -EIO;
219 goto out;
220 }
221
222 len = obj->integer.value;
223 obj = pkg->package.elements + 2;
224 switch (size) {
225 case I2C_SMBUS_BYTE:
226 case I2C_SMBUS_BYTE_DATA:
227 case I2C_SMBUS_WORD_DATA:
228 if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) {
229 ACPI_ERROR((AE_INFO, "Invalid argument type"));
230 result = -EIO;
231 goto out;
232 }
233 if (len == 2)
234 data->word = obj->integer.value;
235 else
236 data->byte = obj->integer.value;
237 break;
238 case I2C_SMBUS_BLOCK_DATA:
239 if (obj == NULL || obj->type != ACPI_TYPE_BUFFER) {
240 ACPI_ERROR((AE_INFO, "Invalid argument type"));
241 result = -EIO;
242 goto out;
243 }
244 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
245 return -EPROTO;
246 data->block[0] = len;
247 memcpy(data->block + 1, obj->buffer.pointer, len);
248 break;
249 }
250
251out:
252 kfree(buffer.pointer);
253 dev_dbg(&adap->dev, "Transaction status: %i\n", result);
254 return result;
255}
256
257static u32 acpi_smbus_cmi_func(struct i2c_adapter *adapter)
258{
259 struct acpi_smbus_cmi *smbus_cmi = adapter->algo_data;
260 u32 ret;
261
262 ret = smbus_cmi->cap_read | smbus_cmi->cap_write ?
263 I2C_FUNC_SMBUS_QUICK : 0;
264
265 ret |= smbus_cmi->cap_read ?
266 (I2C_FUNC_SMBUS_READ_BYTE |
267 I2C_FUNC_SMBUS_READ_BYTE_DATA |
268 I2C_FUNC_SMBUS_READ_WORD_DATA |
269 I2C_FUNC_SMBUS_READ_BLOCK_DATA) : 0;
270
271 ret |= smbus_cmi->cap_write ?
272 (I2C_FUNC_SMBUS_WRITE_BYTE |
273 I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
274 I2C_FUNC_SMBUS_WRITE_WORD_DATA |
275 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA) : 0;
276
277 return ret;
278}
279
280static const struct i2c_algorithm acpi_smbus_cmi_algorithm = {
281 .smbus_xfer = acpi_smbus_cmi_access,
282 .functionality = acpi_smbus_cmi_func,
283};
284
285
286static int acpi_smbus_cmi_add_cap(struct acpi_smbus_cmi *smbus_cmi,
287 const char *name)
288{
289 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
290 union acpi_object *obj;
291 acpi_status status;
292
293 if (!strcmp(name, smbus_methods.mt_info)) {
294 status = acpi_evaluate_object(smbus_cmi->handle,
295 smbus_methods.mt_info,
296 NULL, &buffer);
297 if (ACPI_FAILURE(status)) {
298 ACPI_ERROR((AE_INFO, "Evaluating %s: %i",
299 smbus_methods.mt_info, status));
300 return -EIO;
301 }
302
303 obj = buffer.pointer;
304 if (obj && obj->type == ACPI_TYPE_PACKAGE)
305 obj = obj->package.elements;
306 else {
307 ACPI_ERROR((AE_INFO, "Invalid argument type"));
308 kfree(buffer.pointer);
309 return -EIO;
310 }
311
312 if (obj->type != ACPI_TYPE_INTEGER) {
313 ACPI_ERROR((AE_INFO, "Invalid argument type"));
314 kfree(buffer.pointer);
315 return -EIO;
316 } else
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "SMBus CMI Version %x"
318 "\n", (int)obj->integer.value));
319
320 kfree(buffer.pointer);
321 smbus_cmi->cap_info = 1;
322 } else if (!strcmp(name, smbus_methods.mt_sbr))
323 smbus_cmi->cap_read = 1;
324 else if (!strcmp(name, smbus_methods.mt_sbw))
325 smbus_cmi->cap_write = 1;
326 else
327 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Unsupported CMI method: %s\n",
328 name));
329
330 return 0;
331}
332
333static acpi_status acpi_smbus_cmi_query_methods(acpi_handle handle, u32 level,
334 void *context, void **return_value)
335{
336 char node_name[5];
337 struct acpi_buffer buffer = { sizeof(node_name), node_name };
338 struct acpi_smbus_cmi *smbus_cmi = context;
339 acpi_status status;
340
341 status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
342
343 if (ACPI_SUCCESS(status))
344 acpi_smbus_cmi_add_cap(smbus_cmi, node_name);
345
346 return AE_OK;
347}
348
349static int acpi_smbus_cmi_add(struct acpi_device *device)
350{
351 struct acpi_smbus_cmi *smbus_cmi;
352
353 smbus_cmi = kzalloc(sizeof(struct acpi_smbus_cmi), GFP_KERNEL);
354 if (!smbus_cmi)
355 return -ENOMEM;
356
357 smbus_cmi->handle = device->handle;
358 strcpy(acpi_device_name(device), ACPI_SMBUS_HC_DEVICE_NAME);
359 strcpy(acpi_device_class(device), ACPI_SMBUS_HC_CLASS);
360 device->driver_data = smbus_cmi;
361 smbus_cmi->cap_info = 0;
362 smbus_cmi->cap_read = 0;
363 smbus_cmi->cap_write = 0;
364
365 acpi_walk_namespace(ACPI_TYPE_METHOD, smbus_cmi->handle, 1,
366 acpi_smbus_cmi_query_methods, smbus_cmi, NULL);
367
368 if (smbus_cmi->cap_info == 0)
369 goto err;
370
371 snprintf(smbus_cmi->adapter.name, sizeof(smbus_cmi->adapter.name),
372 "SMBus CMI adapter %s (%s)",
373 acpi_device_name(device),
374 acpi_device_uid(device));
375 smbus_cmi->adapter.owner = THIS_MODULE;
376 smbus_cmi->adapter.algo = &acpi_smbus_cmi_algorithm;
377 smbus_cmi->adapter.algo_data = smbus_cmi;
378 smbus_cmi->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
379 smbus_cmi->adapter.dev.parent = &device->dev;
380
381 if (i2c_add_adapter(&smbus_cmi->adapter)) {
382 dev_err(&device->dev, "Couldn't register adapter!\n");
383 goto err;
384 }
385
386 return 0;
387
388err:
389 kfree(smbus_cmi);
390 device->driver_data = NULL;
391 return -EIO;
392}
393
394static int acpi_smbus_cmi_remove(struct acpi_device *device, int type)
395{
396 struct acpi_smbus_cmi *smbus_cmi = acpi_driver_data(device);
397
398 i2c_del_adapter(&smbus_cmi->adapter);
399 kfree(smbus_cmi);
400 device->driver_data = NULL;
401
402 return 0;
403}
404
405static struct acpi_driver acpi_smbus_cmi_driver = {
406 .name = ACPI_SMBUS_HC_DEVICE_NAME,
407 .class = ACPI_SMBUS_HC_CLASS,
408 .ids = acpi_smbus_cmi_ids,
409 .ops = {
410 .add = acpi_smbus_cmi_add,
411 .remove = acpi_smbus_cmi_remove,
412 },
413};
414
415static int __init acpi_smbus_cmi_init(void)
416{
417 return acpi_bus_register_driver(&acpi_smbus_cmi_driver);
418}
419
420static void __exit acpi_smbus_cmi_exit(void)
421{
422 acpi_bus_unregister_driver(&acpi_smbus_cmi_driver);
423}
424
425module_init(acpi_smbus_cmi_init);
426module_exit(acpi_smbus_cmi_exit);
427
428MODULE_LICENSE("GPL");
429MODULE_AUTHOR("Crane Cai <crane.cai@amd.com>");
430MODULE_DESCRIPTION("ACPI SMBus CMI driver");
diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
index 224aa12ee7c8..dd39c1eb03ed 100644
--- a/drivers/i2c/busses/i2c-taos-evm.c
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -32,10 +32,12 @@
32 32
33#define TAOS_STATE_INIT 0 33#define TAOS_STATE_INIT 0
34#define TAOS_STATE_IDLE 1 34#define TAOS_STATE_IDLE 1
35#define TAOS_STATE_SEND 2 35#define TAOS_STATE_EOFF 2
36#define TAOS_STATE_RECV 3 36#define TAOS_STATE_RECV 3
37 37
38#define TAOS_CMD_RESET 0x12 38#define TAOS_CMD_RESET 0x12
39#define TAOS_CMD_ECHO_ON '+'
40#define TAOS_CMD_ECHO_OFF '-'
39 41
40static DECLARE_WAIT_QUEUE_HEAD(wq); 42static DECLARE_WAIT_QUEUE_HEAD(wq);
41 43
@@ -102,17 +104,9 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
102 104
103 /* Send the transaction to the TAOS EVM */ 105 /* Send the transaction to the TAOS EVM */
104 dev_dbg(&adapter->dev, "Command buffer: %s\n", taos->buffer); 106 dev_dbg(&adapter->dev, "Command buffer: %s\n", taos->buffer);
105 taos->pos = 0; 107 for (p = taos->buffer; *p; p++)
106 taos->state = TAOS_STATE_SEND; 108 serio_write(serio, *p);
107 serio_write(serio, taos->buffer[0]); 109
108 wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE,
109 msecs_to_jiffies(250));
110 if (taos->state != TAOS_STATE_IDLE) {
111 dev_err(&adapter->dev, "Transaction failed "
112 "(state=%d, pos=%d)\n", taos->state, taos->pos);
113 taos->addr = 0;
114 return -EIO;
115 }
116 taos->addr = addr; 110 taos->addr = addr;
117 111
118 /* Start the transaction and read the answer */ 112 /* Start the transaction and read the answer */
@@ -122,7 +116,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
122 wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, 116 wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE,
123 msecs_to_jiffies(150)); 117 msecs_to_jiffies(150));
124 if (taos->state != TAOS_STATE_IDLE 118 if (taos->state != TAOS_STATE_IDLE
125 || taos->pos != 6) { 119 || taos->pos != 5) {
126 dev_err(&adapter->dev, "Transaction timeout (pos=%d)\n", 120 dev_err(&adapter->dev, "Transaction timeout (pos=%d)\n",
127 taos->pos); 121 taos->pos);
128 return -EIO; 122 return -EIO;
@@ -130,7 +124,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
130 dev_dbg(&adapter->dev, "Answer buffer: %s\n", taos->buffer); 124 dev_dbg(&adapter->dev, "Answer buffer: %s\n", taos->buffer);
131 125
132 /* Interpret the returned string */ 126 /* Interpret the returned string */
133 p = taos->buffer + 2; 127 p = taos->buffer + 1;
134 p[3] = '\0'; 128 p[3] = '\0';
135 if (!strcmp(p, "NAK")) 129 if (!strcmp(p, "NAK"))
136 return -ENODEV; 130 return -ENODEV;
@@ -173,13 +167,9 @@ static irqreturn_t taos_interrupt(struct serio *serio, unsigned char data,
173 wake_up_interruptible(&wq); 167 wake_up_interruptible(&wq);
174 } 168 }
175 break; 169 break;
176 case TAOS_STATE_SEND: 170 case TAOS_STATE_EOFF:
177 if (taos->buffer[++taos->pos]) 171 taos->state = TAOS_STATE_IDLE;
178 serio_write(serio, taos->buffer[taos->pos]); 172 wake_up_interruptible(&wq);
179 else {
180 taos->state = TAOS_STATE_IDLE;
181 wake_up_interruptible(&wq);
182 }
183 break; 173 break;
184 case TAOS_STATE_RECV: 174 case TAOS_STATE_RECV:
185 taos->buffer[taos->pos++] = data; 175 taos->buffer[taos->pos++] = data;
@@ -257,6 +247,19 @@ static int taos_connect(struct serio *serio, struct serio_driver *drv)
257 } 247 }
258 strlcpy(adapter->name, name, sizeof(adapter->name)); 248 strlcpy(adapter->name, name, sizeof(adapter->name));
259 249
250 /* Turn echo off for better performance */
251 taos->state = TAOS_STATE_EOFF;
252 serio_write(serio, TAOS_CMD_ECHO_OFF);
253
254 wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE,
255 msecs_to_jiffies(250));
256 if (taos->state != TAOS_STATE_IDLE) {
257 err = -ENODEV;
258 dev_err(&adapter->dev, "Echo off failed "
259 "(state=%d)\n", taos->state);
260 goto exit_close;
261 }
262
260 err = i2c_add_adapter(adapter); 263 err = i2c_add_adapter(adapter);
261 if (err) 264 if (err)
262 goto exit_close; 265 goto exit_close;
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 648ecc6f60e6..cf994bd01d9c 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -217,8 +217,10 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
217 return; 217 return;
218 218
219 error: 219 error:
220 dev_err(&iface->adapter.dev, "%s in state %s\n", errmsg, 220 dev_err(&iface->adapter.dev,
221 scx200_acb_state_name[iface->state]); 221 "%s in state %s (addr=0x%02x, len=%d, status=0x%02x)\n", errmsg,
222 scx200_acb_state_name[iface->state], iface->address_byte,
223 iface->len, status);
222 224
223 iface->state = state_idle; 225 iface->state = state_idle;
224 iface->result = -EIO; 226 iface->result = -EIO;
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 02d746c9c474..f9618f4d4e47 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -16,54 +16,6 @@ config DS1682
16 This driver can also be built as a module. If so, the module 16 This driver can also be built as a module. If so, the module
17 will be called ds1682. 17 will be called ds1682.
18 18
19config SENSORS_PCF8574
20 tristate "Philips PCF8574 and PCF8574A (DEPRECATED)"
21 depends on EXPERIMENTAL && GPIO_PCF857X = "n"
22 default n
23 help
24 If you say yes here you get support for Philips PCF8574 and
25 PCF8574A chips. These chips are 8-bit I/O expanders for the I2C bus.
26
27 This driver can also be built as a module. If so, the module
28 will be called pcf8574.
29
30 This driver is deprecated and will be dropped soon. Use
31 drivers/gpio/pcf857x.c instead.
32
33 These devices are hard to detect and rarely found on mainstream
34 hardware. If unsure, say N.
35
36config PCF8575
37 tristate "Philips PCF8575 (DEPRECATED)"
38 default n
39 depends on GPIO_PCF857X = "n"
40 help
41 If you say yes here you get support for Philips PCF8575 chip.
42 This chip is a 16-bit I/O expander for the I2C bus. Several other
43 chip manufacturers sell equivalent chips, e.g. Texas Instruments.
44
45 This driver can also be built as a module. If so, the module
46 will be called pcf8575.
47
48 This driver is deprecated and will be dropped soon. Use
49 drivers/gpio/pcf857x.c instead.
50
51 This device is hard to detect and is rarely found on mainstream
52 hardware. If unsure, say N.
53
54config SENSORS_PCA9539
55 tristate "Philips PCA9539 16-bit I/O port (DEPRECATED)"
56 depends on EXPERIMENTAL && GPIO_PCA953X = "n"
57 help
58 If you say yes here you get support for the Philips PCA9539
59 16-bit I/O port.
60
61 This driver can also be built as a module. If so, the module
62 will be called pca9539.
63
64 This driver is deprecated and will be dropped soon. Use
65 drivers/gpio/pca953x.c instead.
66
67config SENSORS_TSL2550 19config SENSORS_TSL2550
68 tristate "Taos TSL2550 ambient light sensor" 20 tristate "Taos TSL2550 ambient light sensor"
69 depends on EXPERIMENTAL 21 depends on EXPERIMENTAL
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index f4680d16ee34..749cf3606294 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -11,9 +11,6 @@
11# 11#
12 12
13obj-$(CONFIG_DS1682) += ds1682.o 13obj-$(CONFIG_DS1682) += ds1682.o
14obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o
15obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o
16obj-$(CONFIG_PCF8575) += pcf8575.o
17obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o 14obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o
18 15
19ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 16ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
deleted file mode 100644
index 270de4e56a81..000000000000
--- a/drivers/i2c/chips/pca9539.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/*
2 pca9539.c - 16-bit I/O port with interrupt and reset
3
4 Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9*/
10
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/hwmon-sysfs.h>
16
17/* Addresses to scan: none, device is not autodetected */
18static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
19
20/* Insmod parameters */
21I2C_CLIENT_INSMOD_1(pca9539);
22
23enum pca9539_cmd
24{
25 PCA9539_INPUT_0 = 0,
26 PCA9539_INPUT_1 = 1,
27 PCA9539_OUTPUT_0 = 2,
28 PCA9539_OUTPUT_1 = 3,
29 PCA9539_INVERT_0 = 4,
30 PCA9539_INVERT_1 = 5,
31 PCA9539_DIRECTION_0 = 6,
32 PCA9539_DIRECTION_1 = 7,
33};
34
35/* following are the sysfs callback functions */
36static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr,
37 char *buf)
38{
39 struct sensor_device_attribute *psa = to_sensor_dev_attr(attr);
40 struct i2c_client *client = to_i2c_client(dev);
41 return sprintf(buf, "%d\n", i2c_smbus_read_byte_data(client,
42 psa->index));
43}
44
45static ssize_t pca9539_store(struct device *dev, struct device_attribute *attr,
46 const char *buf, size_t count)
47{
48 struct sensor_device_attribute *psa = to_sensor_dev_attr(attr);
49 struct i2c_client *client = to_i2c_client(dev);
50 unsigned long val = simple_strtoul(buf, NULL, 0);
51 if (val > 0xff)
52 return -EINVAL;
53 i2c_smbus_write_byte_data(client, psa->index, val);
54 return count;
55}
56
57/* Define the device attributes */
58
59#define PCA9539_ENTRY_RO(name, cmd_idx) \
60 static SENSOR_DEVICE_ATTR(name, S_IRUGO, pca9539_show, NULL, cmd_idx)
61
62#define PCA9539_ENTRY_RW(name, cmd_idx) \
63 static SENSOR_DEVICE_ATTR(name, S_IRUGO | S_IWUSR, pca9539_show, \
64 pca9539_store, cmd_idx)
65
66PCA9539_ENTRY_RO(input0, PCA9539_INPUT_0);
67PCA9539_ENTRY_RO(input1, PCA9539_INPUT_1);
68PCA9539_ENTRY_RW(output0, PCA9539_OUTPUT_0);
69PCA9539_ENTRY_RW(output1, PCA9539_OUTPUT_1);
70PCA9539_ENTRY_RW(invert0, PCA9539_INVERT_0);
71PCA9539_ENTRY_RW(invert1, PCA9539_INVERT_1);
72PCA9539_ENTRY_RW(direction0, PCA9539_DIRECTION_0);
73PCA9539_ENTRY_RW(direction1, PCA9539_DIRECTION_1);
74
75static struct attribute *pca9539_attributes[] = {
76 &sensor_dev_attr_input0.dev_attr.attr,
77 &sensor_dev_attr_input1.dev_attr.attr,
78 &sensor_dev_attr_output0.dev_attr.attr,
79 &sensor_dev_attr_output1.dev_attr.attr,
80 &sensor_dev_attr_invert0.dev_attr.attr,
81 &sensor_dev_attr_invert1.dev_attr.attr,
82 &sensor_dev_attr_direction0.dev_attr.attr,
83 &sensor_dev_attr_direction1.dev_attr.attr,
84 NULL
85};
86
87static struct attribute_group pca9539_defattr_group = {
88 .attrs = pca9539_attributes,
89};
90
91/* Return 0 if detection is successful, -ENODEV otherwise */
92static int pca9539_detect(struct i2c_client *client, int kind,
93 struct i2c_board_info *info)
94{
95 struct i2c_adapter *adapter = client->adapter;
96
97 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
98 return -ENODEV;
99
100 strlcpy(info->type, "pca9539", I2C_NAME_SIZE);
101
102 return 0;
103}
104
105static int pca9539_probe(struct i2c_client *client,
106 const struct i2c_device_id *id)
107{
108 /* Register sysfs hooks */
109 return sysfs_create_group(&client->dev.kobj,
110 &pca9539_defattr_group);
111}
112
113static int pca9539_remove(struct i2c_client *client)
114{
115 sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group);
116 return 0;
117}
118
119static const struct i2c_device_id pca9539_id[] = {
120 { "pca9539", 0 },
121 { }
122};
123
124static struct i2c_driver pca9539_driver = {
125 .driver = {
126 .name = "pca9539",
127 },
128 .probe = pca9539_probe,
129 .remove = pca9539_remove,
130 .id_table = pca9539_id,
131
132 .detect = pca9539_detect,
133 .address_data = &addr_data,
134};
135
136static int __init pca9539_init(void)
137{
138 return i2c_add_driver(&pca9539_driver);
139}
140
141static void __exit pca9539_exit(void)
142{
143 i2c_del_driver(&pca9539_driver);
144}
145
146MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>");
147MODULE_DESCRIPTION("PCA9539 driver");
148MODULE_LICENSE("GPL");
149
150module_init(pca9539_init);
151module_exit(pca9539_exit);
152
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
deleted file mode 100644
index 6ec309894c88..000000000000
--- a/drivers/i2c/chips/pcf8574.c
+++ /dev/null
@@ -1,215 +0,0 @@
1/*
2 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>,
3 Philip Edelbrock <phil@netroedge.com>,
4 Dan Eaton <dan.eaton@rocketlogix.com>
5 Ported to Linux 2.6 by Aurelien Jarno <aurel32@debian.org> with
6 the help of Jean Delvare <khali@linux-fr.org>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23/* A few notes about the PCF8574:
24
25* The PCF8574 is an 8-bit I/O expander for the I2C bus produced by
26 Philips Semiconductors. It is designed to provide a byte I2C
27 interface to up to 8 separate devices.
28
29* The PCF8574 appears as a very simple SMBus device which can be
30 read from or written to with SMBUS byte read/write accesses.
31
32 --Dan
33
34*/
35
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/slab.h>
39#include <linux/i2c.h>
40
41/* Addresses to scan: none, device can't be detected */
42static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
43
44/* Insmod parameters */
45I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
46
47/* Each client has this additional data */
48struct pcf8574_data {
49 int write; /* Remember last written value */
50};
51
52static void pcf8574_init_client(struct i2c_client *client);
53
54/* following are the sysfs callback functions */
55static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf)
56{
57 struct i2c_client *client = to_i2c_client(dev);
58 return sprintf(buf, "%u\n", i2c_smbus_read_byte(client));
59}
60
61static DEVICE_ATTR(read, S_IRUGO, show_read, NULL);
62
63static ssize_t show_write(struct device *dev, struct device_attribute *attr, char *buf)
64{
65 struct pcf8574_data *data = i2c_get_clientdata(to_i2c_client(dev));
66
67 if (data->write < 0)
68 return data->write;
69
70 return sprintf(buf, "%d\n", data->write);
71}
72
73static ssize_t set_write(struct device *dev, struct device_attribute *attr, const char *buf,
74 size_t count)
75{
76 struct i2c_client *client = to_i2c_client(dev);
77 struct pcf8574_data *data = i2c_get_clientdata(client);
78 unsigned long val = simple_strtoul(buf, NULL, 10);
79
80 if (val > 0xff)
81 return -EINVAL;
82
83 data->write = val;
84 i2c_smbus_write_byte(client, data->write);
85 return count;
86}
87
88static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
89
90static struct attribute *pcf8574_attributes[] = {
91 &dev_attr_read.attr,
92 &dev_attr_write.attr,
93 NULL
94};
95
96static const struct attribute_group pcf8574_attr_group = {
97 .attrs = pcf8574_attributes,
98};
99
100/*
101 * Real code
102 */
103
104/* Return 0 if detection is successful, -ENODEV otherwise */
105static int pcf8574_detect(struct i2c_client *client, int kind,
106 struct i2c_board_info *info)
107{
108 struct i2c_adapter *adapter = client->adapter;
109 const char *client_name;
110
111 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
112 return -ENODEV;
113
114 /* Now, we would do the remaining detection. But the PCF8574 is plainly
115 impossible to detect! Stupid chip. */
116
117 /* Determine the chip type */
118 if (kind <= 0) {
119 if (client->addr >= 0x38 && client->addr <= 0x3f)
120 kind = pcf8574a;
121 else
122 kind = pcf8574;
123 }
124
125 if (kind == pcf8574a)
126 client_name = "pcf8574a";
127 else
128 client_name = "pcf8574";
129 strlcpy(info->type, client_name, I2C_NAME_SIZE);
130
131 return 0;
132}
133
134static int pcf8574_probe(struct i2c_client *client,
135 const struct i2c_device_id *id)
136{
137 struct pcf8574_data *data;
138 int err;
139
140 data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL);
141 if (!data) {
142 err = -ENOMEM;
143 goto exit;
144 }
145
146 i2c_set_clientdata(client, data);
147
148 /* Initialize the PCF8574 chip */
149 pcf8574_init_client(client);
150
151 /* Register sysfs hooks */
152 err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group);
153 if (err)
154 goto exit_free;
155 return 0;
156
157 exit_free:
158 kfree(data);
159 exit:
160 return err;
161}
162
163static int pcf8574_remove(struct i2c_client *client)
164{
165 sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
166 kfree(i2c_get_clientdata(client));
167 return 0;
168}
169
170/* Called when we have found a new PCF8574. */
171static void pcf8574_init_client(struct i2c_client *client)
172{
173 struct pcf8574_data *data = i2c_get_clientdata(client);
174 data->write = -EAGAIN;
175}
176
177static const struct i2c_device_id pcf8574_id[] = {
178 { "pcf8574", 0 },
179 { "pcf8574a", 0 },
180 { }
181};
182
183static struct i2c_driver pcf8574_driver = {
184 .driver = {
185 .name = "pcf8574",
186 },
187 .probe = pcf8574_probe,
188 .remove = pcf8574_remove,
189 .id_table = pcf8574_id,
190
191 .detect = pcf8574_detect,
192 .address_data = &addr_data,
193};
194
195static int __init pcf8574_init(void)
196{
197 return i2c_add_driver(&pcf8574_driver);
198}
199
200static void __exit pcf8574_exit(void)
201{
202 i2c_del_driver(&pcf8574_driver);
203}
204
205
206MODULE_AUTHOR
207 ("Frodo Looijaard <frodol@dds.nl>, "
208 "Philip Edelbrock <phil@netroedge.com>, "
209 "Dan Eaton <dan.eaton@rocketlogix.com> "
210 "and Aurelien Jarno <aurelien@aurel32.net>");
211MODULE_DESCRIPTION("PCF8574 driver");
212MODULE_LICENSE("GPL");
213
214module_init(pcf8574_init);
215module_exit(pcf8574_exit);
diff --git a/drivers/i2c/chips/pcf8575.c b/drivers/i2c/chips/pcf8575.c
deleted file mode 100644
index 07fd7cb3c57d..000000000000
--- a/drivers/i2c/chips/pcf8575.c
+++ /dev/null
@@ -1,198 +0,0 @@
1/*
2 pcf8575.c
3
4 About the PCF8575 chip: the PCF8575 is a 16-bit I/O expander for the I2C bus
5 produced by a.o. Philips Semiconductors.
6
7 Copyright (C) 2006 Michael Hennerich, Analog Devices Inc.
8 <hennerich@blackfin.uclinux.org>
9 Based on pcf8574.c.
10
11 Copyright (c) 2007 Bart Van Assche <bart.vanassche@gmail.com>.
12 Ported this driver from ucLinux to the mainstream Linux kernel.
13
14 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
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/
28
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/i2c.h>
32#include <linux/slab.h> /* kzalloc() */
33#include <linux/sysfs.h> /* sysfs_create_group() */
34
35/* Addresses to scan: none, device can't be detected */
36static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
37
38/* Insmod parameters */
39I2C_CLIENT_INSMOD;
40
41
42/* Each client has this additional data */
43struct pcf8575_data {
44 int write; /* last written value, or error code */
45};
46
47/* following are the sysfs callback functions */
48static ssize_t show_read(struct device *dev, struct device_attribute *attr,
49 char *buf)
50{
51 struct i2c_client *client = to_i2c_client(dev);
52 u16 val;
53 u8 iopin_state[2];
54
55 i2c_master_recv(client, iopin_state, 2);
56
57 val = iopin_state[0];
58 val |= iopin_state[1] << 8;
59
60 return sprintf(buf, "%u\n", val);
61}
62
63static DEVICE_ATTR(read, S_IRUGO, show_read, NULL);
64
65static ssize_t show_write(struct device *dev, struct device_attribute *attr,
66 char *buf)
67{
68 struct pcf8575_data *data = dev_get_drvdata(dev);
69 if (data->write < 0)
70 return data->write;
71 return sprintf(buf, "%d\n", data->write);
72}
73
74static ssize_t set_write(struct device *dev, struct device_attribute *attr,
75 const char *buf, size_t count)
76{
77 struct i2c_client *client = to_i2c_client(dev);
78 struct pcf8575_data *data = i2c_get_clientdata(client);
79 unsigned long val = simple_strtoul(buf, NULL, 10);
80 u8 iopin_state[2];
81
82 if (val > 0xffff)
83 return -EINVAL;
84
85 data->write = val;
86
87 iopin_state[0] = val & 0xFF;
88 iopin_state[1] = val >> 8;
89
90 i2c_master_send(client, iopin_state, 2);
91
92 return count;
93}
94
95static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
96
97static struct attribute *pcf8575_attributes[] = {
98 &dev_attr_read.attr,
99 &dev_attr_write.attr,
100 NULL
101};
102
103static const struct attribute_group pcf8575_attr_group = {
104 .attrs = pcf8575_attributes,
105};
106
107/*
108 * Real code
109 */
110
111/* Return 0 if detection is successful, -ENODEV otherwise */
112static int pcf8575_detect(struct i2c_client *client, int kind,
113 struct i2c_board_info *info)
114{
115 struct i2c_adapter *adapter = client->adapter;
116
117 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
118 return -ENODEV;
119
120 /* This is the place to detect whether the chip at the specified
121 address really is a PCF8575 chip. However, there is no method known
122 to detect whether an I2C chip is a PCF8575 or any other I2C chip. */
123
124 strlcpy(info->type, "pcf8575", I2C_NAME_SIZE);
125
126 return 0;
127}
128
129static int pcf8575_probe(struct i2c_client *client,
130 const struct i2c_device_id *id)
131{
132 struct pcf8575_data *data;
133 int err;
134
135 data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL);
136 if (!data) {
137 err = -ENOMEM;
138 goto exit;
139 }
140
141 i2c_set_clientdata(client, data);
142 data->write = -EAGAIN;
143
144 /* Register sysfs hooks */
145 err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group);
146 if (err)
147 goto exit_free;
148
149 return 0;
150
151exit_free:
152 kfree(data);
153exit:
154 return err;
155}
156
157static int pcf8575_remove(struct i2c_client *client)
158{
159 sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group);
160 kfree(i2c_get_clientdata(client));
161 return 0;
162}
163
164static const struct i2c_device_id pcf8575_id[] = {
165 { "pcf8575", 0 },
166 { }
167};
168
169static struct i2c_driver pcf8575_driver = {
170 .driver = {
171 .owner = THIS_MODULE,
172 .name = "pcf8575",
173 },
174 .probe = pcf8575_probe,
175 .remove = pcf8575_remove,
176 .id_table = pcf8575_id,
177
178 .detect = pcf8575_detect,
179 .address_data = &addr_data,
180};
181
182static int __init pcf8575_init(void)
183{
184 return i2c_add_driver(&pcf8575_driver);
185}
186
187static void __exit pcf8575_exit(void)
188{
189 i2c_del_driver(&pcf8575_driver);
190}
191
192MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>, "
193 "Bart Van Assche <bart.vanassche@gmail.com>");
194MODULE_DESCRIPTION("pcf8575 driver");
195MODULE_LICENSE("GPL");
196
197module_init(pcf8575_init);
198module_exit(pcf8575_exit);
diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c
index b96f3025e588..aa96bd2d27ea 100644
--- a/drivers/i2c/chips/tsl2550.c
+++ b/drivers/i2c/chips/tsl2550.c
@@ -24,10 +24,9 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/delay.h>
28 27
29#define TSL2550_DRV_NAME "tsl2550" 28#define TSL2550_DRV_NAME "tsl2550"
30#define DRIVER_VERSION "1.1.2" 29#define DRIVER_VERSION "1.2"
31 30
32/* 31/*
33 * Defines 32 * Defines
@@ -96,32 +95,13 @@ static int tsl2550_set_power_state(struct i2c_client *client, int state)
96 95
97static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd) 96static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd)
98{ 97{
99 unsigned long end; 98 int ret;
100 int loop = 0, ret = 0;
101 99
102 /* 100 ret = i2c_smbus_read_byte_data(client, cmd);
103 * Read ADC channel waiting at most 400ms (see data sheet for further 101 if (ret < 0)
104 * info). 102 return ret;
105 * To avoid long busy wait we spin for few milliseconds then
106 * start sleeping.
107 */
108 end = jiffies + msecs_to_jiffies(400);
109 while (time_before(jiffies, end)) {
110 i2c_smbus_write_byte(client, cmd);
111
112 if (loop++ < 5)
113 mdelay(1);
114 else
115 msleep(1);
116
117 ret = i2c_smbus_read_byte(client);
118 if (ret < 0)
119 return ret;
120 else if (ret & 0x0080)
121 break;
122 }
123 if (!(ret & 0x80)) 103 if (!(ret & 0x80))
124 return -EIO; 104 return -EAGAIN;
125 return ret & 0x7f; /* remove the "valid" bit */ 105 return ret & 0x7f; /* remove the "valid" bit */
126} 106}
127 107
@@ -285,8 +265,6 @@ static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf)
285 return ret; 265 return ret;
286 ch0 = ret; 266 ch0 = ret;
287 267
288 mdelay(1);
289
290 ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC1); 268 ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC1);
291 if (ret < 0) 269 if (ret < 0)
292 return ret; 270 return ret;
@@ -345,11 +323,10 @@ static int tsl2550_init_client(struct i2c_client *client)
345 * Probe the chip. To do so we try to power up the device and then to 323 * Probe the chip. To do so we try to power up the device and then to
346 * read back the 0x03 code 324 * read back the 0x03 code
347 */ 325 */
348 err = i2c_smbus_write_byte(client, TSL2550_POWER_UP); 326 err = i2c_smbus_read_byte_data(client, TSL2550_POWER_UP);
349 if (err < 0) 327 if (err < 0)
350 return err; 328 return err;
351 mdelay(1); 329 if (err != TSL2550_POWER_UP)
352 if (i2c_smbus_read_byte(client) != TSL2550_POWER_UP)
353 return -ENODEV; 330 return -ENODEV;
354 data->power_state = 1; 331 data->power_state = 1;
355 332
@@ -374,7 +351,8 @@ static int __devinit tsl2550_probe(struct i2c_client *client,
374 struct tsl2550_data *data; 351 struct tsl2550_data *data;
375 int *opmode, err = 0; 352 int *opmode, err = 0;
376 353
377 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) { 354 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE
355 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
378 err = -EIO; 356 err = -EIO;
379 goto exit; 357 goto exit;
380 } 358 }
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 0e45c296d3d2..8d80fceca6a4 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -46,6 +46,7 @@ static DEFINE_MUTEX(core_lock);
46static DEFINE_IDR(i2c_adapter_idr); 46static DEFINE_IDR(i2c_adapter_idr);
47static LIST_HEAD(userspace_devices); 47static LIST_HEAD(userspace_devices);
48 48
49static struct device_type i2c_client_type;
49static int i2c_check_addr(struct i2c_adapter *adapter, int addr); 50static int i2c_check_addr(struct i2c_adapter *adapter, int addr);
50static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); 51static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
51 52
@@ -64,9 +65,13 @@ static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
64 65
65static int i2c_device_match(struct device *dev, struct device_driver *drv) 66static int i2c_device_match(struct device *dev, struct device_driver *drv)
66{ 67{
67 struct i2c_client *client = to_i2c_client(dev); 68 struct i2c_client *client = i2c_verify_client(dev);
68 struct i2c_driver *driver = to_i2c_driver(drv); 69 struct i2c_driver *driver;
70
71 if (!client)
72 return 0;
69 73
74 driver = to_i2c_driver(drv);
70 /* match on an id table if there is one */ 75 /* match on an id table if there is one */
71 if (driver->id_table) 76 if (driver->id_table)
72 return i2c_match_id(driver->id_table, client) != NULL; 77 return i2c_match_id(driver->id_table, client) != NULL;
@@ -94,10 +99,14 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
94 99
95static int i2c_device_probe(struct device *dev) 100static int i2c_device_probe(struct device *dev)
96{ 101{
97 struct i2c_client *client = to_i2c_client(dev); 102 struct i2c_client *client = i2c_verify_client(dev);
98 struct i2c_driver *driver = to_i2c_driver(dev->driver); 103 struct i2c_driver *driver;
99 int status; 104 int status;
100 105
106 if (!client)
107 return 0;
108
109 driver = to_i2c_driver(dev->driver);
101 if (!driver->probe || !driver->id_table) 110 if (!driver->probe || !driver->id_table)
102 return -ENODEV; 111 return -ENODEV;
103 client->driver = driver; 112 client->driver = driver;
@@ -114,11 +123,11 @@ static int i2c_device_probe(struct device *dev)
114 123
115static int i2c_device_remove(struct device *dev) 124static int i2c_device_remove(struct device *dev)
116{ 125{
117 struct i2c_client *client = to_i2c_client(dev); 126 struct i2c_client *client = i2c_verify_client(dev);
118 struct i2c_driver *driver; 127 struct i2c_driver *driver;
119 int status; 128 int status;
120 129
121 if (!dev->driver) 130 if (!client || !dev->driver)
122 return 0; 131 return 0;
123 132
124 driver = to_i2c_driver(dev->driver); 133 driver = to_i2c_driver(dev->driver);
@@ -136,37 +145,40 @@ static int i2c_device_remove(struct device *dev)
136 145
137static void i2c_device_shutdown(struct device *dev) 146static void i2c_device_shutdown(struct device *dev)
138{ 147{
148 struct i2c_client *client = i2c_verify_client(dev);
139 struct i2c_driver *driver; 149 struct i2c_driver *driver;
140 150
141 if (!dev->driver) 151 if (!client || !dev->driver)
142 return; 152 return;
143 driver = to_i2c_driver(dev->driver); 153 driver = to_i2c_driver(dev->driver);
144 if (driver->shutdown) 154 if (driver->shutdown)
145 driver->shutdown(to_i2c_client(dev)); 155 driver->shutdown(client);
146} 156}
147 157
148static int i2c_device_suspend(struct device *dev, pm_message_t mesg) 158static int i2c_device_suspend(struct device *dev, pm_message_t mesg)
149{ 159{
160 struct i2c_client *client = i2c_verify_client(dev);
150 struct i2c_driver *driver; 161 struct i2c_driver *driver;
151 162
152 if (!dev->driver) 163 if (!client || !dev->driver)
153 return 0; 164 return 0;
154 driver = to_i2c_driver(dev->driver); 165 driver = to_i2c_driver(dev->driver);
155 if (!driver->suspend) 166 if (!driver->suspend)
156 return 0; 167 return 0;
157 return driver->suspend(to_i2c_client(dev), mesg); 168 return driver->suspend(client, mesg);
158} 169}
159 170
160static int i2c_device_resume(struct device *dev) 171static int i2c_device_resume(struct device *dev)
161{ 172{
173 struct i2c_client *client = i2c_verify_client(dev);
162 struct i2c_driver *driver; 174 struct i2c_driver *driver;
163 175
164 if (!dev->driver) 176 if (!client || !dev->driver)
165 return 0; 177 return 0;
166 driver = to_i2c_driver(dev->driver); 178 driver = to_i2c_driver(dev->driver);
167 if (!driver->resume) 179 if (!driver->resume)
168 return 0; 180 return 0;
169 return driver->resume(to_i2c_client(dev)); 181 return driver->resume(client);
170} 182}
171 183
172static void i2c_client_dev_release(struct device *dev) 184static void i2c_client_dev_release(struct device *dev)
@@ -175,10 +187,10 @@ static void i2c_client_dev_release(struct device *dev)
175} 187}
176 188
177static ssize_t 189static ssize_t
178show_client_name(struct device *dev, struct device_attribute *attr, char *buf) 190show_name(struct device *dev, struct device_attribute *attr, char *buf)
179{ 191{
180 struct i2c_client *client = to_i2c_client(dev); 192 return sprintf(buf, "%s\n", dev->type == &i2c_client_type ?
181 return sprintf(buf, "%s\n", client->name); 193 to_i2c_client(dev)->name : to_i2c_adapter(dev)->name);
182} 194}
183 195
184static ssize_t 196static ssize_t
@@ -188,18 +200,28 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
188 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); 200 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
189} 201}
190 202
191static struct device_attribute i2c_dev_attrs[] = { 203static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
192 __ATTR(name, S_IRUGO, show_client_name, NULL), 204static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
205
206static struct attribute *i2c_dev_attrs[] = {
207 &dev_attr_name.attr,
193 /* modalias helps coldplug: modprobe $(cat .../modalias) */ 208 /* modalias helps coldplug: modprobe $(cat .../modalias) */
194 __ATTR(modalias, S_IRUGO, show_modalias, NULL), 209 &dev_attr_modalias.attr,
195 { }, 210 NULL
211};
212
213static struct attribute_group i2c_dev_attr_group = {
214 .attrs = i2c_dev_attrs,
215};
216
217static const struct attribute_group *i2c_dev_attr_groups[] = {
218 &i2c_dev_attr_group,
219 NULL
196}; 220};
197 221
198struct bus_type i2c_bus_type = { 222struct bus_type i2c_bus_type = {
199 .name = "i2c", 223 .name = "i2c",
200 .dev_attrs = i2c_dev_attrs,
201 .match = i2c_device_match, 224 .match = i2c_device_match,
202 .uevent = i2c_device_uevent,
203 .probe = i2c_device_probe, 225 .probe = i2c_device_probe,
204 .remove = i2c_device_remove, 226 .remove = i2c_device_remove,
205 .shutdown = i2c_device_shutdown, 227 .shutdown = i2c_device_shutdown,
@@ -208,6 +230,12 @@ struct bus_type i2c_bus_type = {
208}; 230};
209EXPORT_SYMBOL_GPL(i2c_bus_type); 231EXPORT_SYMBOL_GPL(i2c_bus_type);
210 232
233static struct device_type i2c_client_type = {
234 .groups = i2c_dev_attr_groups,
235 .uevent = i2c_device_uevent,
236 .release = i2c_client_dev_release,
237};
238
211 239
212/** 240/**
213 * i2c_verify_client - return parameter as i2c_client, or NULL 241 * i2c_verify_client - return parameter as i2c_client, or NULL
@@ -220,7 +248,7 @@ EXPORT_SYMBOL_GPL(i2c_bus_type);
220 */ 248 */
221struct i2c_client *i2c_verify_client(struct device *dev) 249struct i2c_client *i2c_verify_client(struct device *dev)
222{ 250{
223 return (dev->bus == &i2c_bus_type) 251 return (dev->type == &i2c_client_type)
224 ? to_i2c_client(dev) 252 ? to_i2c_client(dev)
225 : NULL; 253 : NULL;
226} 254}
@@ -273,7 +301,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
273 301
274 client->dev.parent = &client->adapter->dev; 302 client->dev.parent = &client->adapter->dev;
275 client->dev.bus = &i2c_bus_type; 303 client->dev.bus = &i2c_bus_type;
276 client->dev.release = i2c_client_dev_release; 304 client->dev.type = &i2c_client_type;
277 305
278 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), 306 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
279 client->addr); 307 client->addr);
@@ -368,13 +396,6 @@ static void i2c_adapter_dev_release(struct device *dev)
368 complete(&adap->dev_released); 396 complete(&adap->dev_released);
369} 397}
370 398
371static ssize_t
372show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
373{
374 struct i2c_adapter *adap = to_i2c_adapter(dev);
375 return sprintf(buf, "%s\n", adap->name);
376}
377
378/* 399/*
379 * Let users instantiate I2C devices through sysfs. This can be used when 400 * Let users instantiate I2C devices through sysfs. This can be used when
380 * platform initialization code doesn't contain the proper data for 401 * platform initialization code doesn't contain the proper data for
@@ -493,19 +514,34 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
493 return res; 514 return res;
494} 515}
495 516
496static struct device_attribute i2c_adapter_attrs[] = { 517static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
497 __ATTR(name, S_IRUGO, show_adapter_name, NULL), 518static DEVICE_ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device);
498 __ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device), 519
499 __ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device), 520static struct attribute *i2c_adapter_attrs[] = {
500 { }, 521 &dev_attr_name.attr,
522 &dev_attr_new_device.attr,
523 &dev_attr_delete_device.attr,
524 NULL
501}; 525};
502 526
503static struct class i2c_adapter_class = { 527static struct attribute_group i2c_adapter_attr_group = {
504 .owner = THIS_MODULE, 528 .attrs = i2c_adapter_attrs,
505 .name = "i2c-adapter",
506 .dev_attrs = i2c_adapter_attrs,
507}; 529};
508 530
531static const struct attribute_group *i2c_adapter_attr_groups[] = {
532 &i2c_adapter_attr_group,
533 NULL
534};
535
536static struct device_type i2c_adapter_type = {
537 .groups = i2c_adapter_attr_groups,
538 .release = i2c_adapter_dev_release,
539};
540
541#ifdef CONFIG_I2C_COMPAT
542static struct class_compat *i2c_adapter_compat_class;
543#endif
544
509static void i2c_scan_static_board_info(struct i2c_adapter *adapter) 545static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
510{ 546{
511 struct i2c_devinfo *devinfo; 547 struct i2c_devinfo *devinfo;
@@ -555,14 +591,22 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
555 adap->timeout = HZ; 591 adap->timeout = HZ;
556 592
557 dev_set_name(&adap->dev, "i2c-%d", adap->nr); 593 dev_set_name(&adap->dev, "i2c-%d", adap->nr);
558 adap->dev.release = &i2c_adapter_dev_release; 594 adap->dev.bus = &i2c_bus_type;
559 adap->dev.class = &i2c_adapter_class; 595 adap->dev.type = &i2c_adapter_type;
560 res = device_register(&adap->dev); 596 res = device_register(&adap->dev);
561 if (res) 597 if (res)
562 goto out_list; 598 goto out_list;
563 599
564 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 600 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
565 601
602#ifdef CONFIG_I2C_COMPAT
603 res = class_compat_create_link(i2c_adapter_compat_class, &adap->dev,
604 adap->dev.parent);
605 if (res)
606 dev_warn(&adap->dev,
607 "Failed to create compatibility class link\n");
608#endif
609
566 /* create pre-declared device nodes */ 610 /* create pre-declared device nodes */
567 if (adap->nr < __i2c_first_dynamic_bus_num) 611 if (adap->nr < __i2c_first_dynamic_bus_num)
568 i2c_scan_static_board_info(adap); 612 i2c_scan_static_board_info(adap);
@@ -741,6 +785,11 @@ int i2c_del_adapter(struct i2c_adapter *adap)
741 checking the returned value. */ 785 checking the returned value. */
742 res = device_for_each_child(&adap->dev, NULL, __unregister_client); 786 res = device_for_each_child(&adap->dev, NULL, __unregister_client);
743 787
788#ifdef CONFIG_I2C_COMPAT
789 class_compat_remove_link(i2c_adapter_compat_class, &adap->dev,
790 adap->dev.parent);
791#endif
792
744 /* clean up the sysfs representation */ 793 /* clean up the sysfs representation */
745 init_completion(&adap->dev_released); 794 init_completion(&adap->dev_released);
746 device_unregister(&adap->dev); 795 device_unregister(&adap->dev);
@@ -768,9 +817,13 @@ EXPORT_SYMBOL(i2c_del_adapter);
768 817
769static int __attach_adapter(struct device *dev, void *data) 818static int __attach_adapter(struct device *dev, void *data)
770{ 819{
771 struct i2c_adapter *adapter = to_i2c_adapter(dev); 820 struct i2c_adapter *adapter;
772 struct i2c_driver *driver = data; 821 struct i2c_driver *driver = data;
773 822
823 if (dev->type != &i2c_adapter_type)
824 return 0;
825 adapter = to_i2c_adapter(dev);
826
774 i2c_detect(adapter, driver); 827 i2c_detect(adapter, driver);
775 828
776 /* Legacy drivers scan i2c busses directly */ 829 /* Legacy drivers scan i2c busses directly */
@@ -809,8 +862,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
809 INIT_LIST_HEAD(&driver->clients); 862 INIT_LIST_HEAD(&driver->clients);
810 /* Walk the adapters that are already present */ 863 /* Walk the adapters that are already present */
811 mutex_lock(&core_lock); 864 mutex_lock(&core_lock);
812 class_for_each_device(&i2c_adapter_class, NULL, driver, 865 bus_for_each_dev(&i2c_bus_type, NULL, driver, __attach_adapter);
813 __attach_adapter);
814 mutex_unlock(&core_lock); 866 mutex_unlock(&core_lock);
815 867
816 return 0; 868 return 0;
@@ -819,10 +871,14 @@ EXPORT_SYMBOL(i2c_register_driver);
819 871
820static int __detach_adapter(struct device *dev, void *data) 872static int __detach_adapter(struct device *dev, void *data)
821{ 873{
822 struct i2c_adapter *adapter = to_i2c_adapter(dev); 874 struct i2c_adapter *adapter;
823 struct i2c_driver *driver = data; 875 struct i2c_driver *driver = data;
824 struct i2c_client *client, *_n; 876 struct i2c_client *client, *_n;
825 877
878 if (dev->type != &i2c_adapter_type)
879 return 0;
880 adapter = to_i2c_adapter(dev);
881
826 /* Remove the devices we created ourselves as the result of hardware 882 /* Remove the devices we created ourselves as the result of hardware
827 * probing (using a driver's detect method) */ 883 * probing (using a driver's detect method) */
828 list_for_each_entry_safe(client, _n, &driver->clients, detected) { 884 list_for_each_entry_safe(client, _n, &driver->clients, detected) {
@@ -850,8 +906,7 @@ static int __detach_adapter(struct device *dev, void *data)
850void i2c_del_driver(struct i2c_driver *driver) 906void i2c_del_driver(struct i2c_driver *driver)
851{ 907{
852 mutex_lock(&core_lock); 908 mutex_lock(&core_lock);
853 class_for_each_device(&i2c_adapter_class, NULL, driver, 909 bus_for_each_dev(&i2c_bus_type, NULL, driver, __detach_adapter);
854 __detach_adapter);
855 mutex_unlock(&core_lock); 910 mutex_unlock(&core_lock);
856 911
857 driver_unregister(&driver->driver); 912 driver_unregister(&driver->driver);
@@ -940,17 +995,23 @@ static int __init i2c_init(void)
940 retval = bus_register(&i2c_bus_type); 995 retval = bus_register(&i2c_bus_type);
941 if (retval) 996 if (retval)
942 return retval; 997 return retval;
943 retval = class_register(&i2c_adapter_class); 998#ifdef CONFIG_I2C_COMPAT
944 if (retval) 999 i2c_adapter_compat_class = class_compat_register("i2c-adapter");
1000 if (!i2c_adapter_compat_class) {
1001 retval = -ENOMEM;
945 goto bus_err; 1002 goto bus_err;
1003 }
1004#endif
946 retval = i2c_add_driver(&dummy_driver); 1005 retval = i2c_add_driver(&dummy_driver);
947 if (retval) 1006 if (retval)
948 goto class_err; 1007 goto class_err;
949 return 0; 1008 return 0;
950 1009
951class_err: 1010class_err:
952 class_unregister(&i2c_adapter_class); 1011#ifdef CONFIG_I2C_COMPAT
1012 class_compat_unregister(i2c_adapter_compat_class);
953bus_err: 1013bus_err:
1014#endif
954 bus_unregister(&i2c_bus_type); 1015 bus_unregister(&i2c_bus_type);
955 return retval; 1016 return retval;
956} 1017}
@@ -958,7 +1019,9 @@ bus_err:
958static void __exit i2c_exit(void) 1019static void __exit i2c_exit(void)
959{ 1020{
960 i2c_del_driver(&dummy_driver); 1021 i2c_del_driver(&dummy_driver);
961 class_unregister(&i2c_adapter_class); 1022#ifdef CONFIG_I2C_COMPAT
1023 class_compat_unregister(i2c_adapter_compat_class);
1024#endif
962 bus_unregister(&i2c_bus_type); 1025 bus_unregister(&i2c_bus_type);
963} 1026}
964 1027