aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-09-27 11:09:48 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-27 11:09:48 -0400
commita5b08073a0b512d75fa1a7f82ee850e5c105cce9 (patch)
tree3e609b471ae2ca1f200f974fc65eaf242673db71
parentff0972c26bbf209da6f6d244cce60e695df863f6 (diff)
parent6d3aae9d74221b00e2cbf50a353527e5a71a58ba (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/i2c-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/i2c-2.6: (30 commits) i2c: Drop unimplemented slave functions i2c: Constify i2c_algorithm declarations, part 2 i2c: Constify i2c_algorithm declarations, part 1 i2c: Let drivers constify i2c_algorithm data i2c-isa: Restore driver owner i2c-viapro: Add support for the VT8237A and VT8251 i2c: Warn on i2c client creation failure i2c-core: Drop useless bitmaskings i2c-algo-pcf: Discard the mdelay data struct member i2c-algo-bit: Cleanups i2c-isa: Fail adding driver on attach_adapter error i2c: __must_check fixes (chip drivers) i2c-dev: attach/detach_adapter cleanups i2c-stub: Chip address as a module parameter i2c: Plan i2c-isa for removal i2c: New bus driver for TI OMAP boards i2c-algo-bit: Discard the mdelay data struct member i2c-matroxfb: Struct init conversion i2c: Fix copy-n-paste in subsystem Kconfig i2c-au1550: Add I2C support for Au1200 ...
-rw-r--r--Documentation/feature-removal-schedule.txt9
-rw-r--r--Documentation/i2c/busses/i2c-viapro7
-rw-r--r--Documentation/i2c/i2c-stub15
-rw-r--r--drivers/acorn/char/i2c.c1
-rw-r--r--drivers/acpi/i2c_ec.c2
-rw-r--r--drivers/hwmon/it87.c1
-rw-r--r--drivers/hwmon/lm78.c1
-rw-r--r--drivers/hwmon/pc87360.c1
-rw-r--r--drivers/hwmon/sis5595.c1
-rw-r--r--drivers/hwmon/smsc47b397.c1
-rw-r--r--drivers/hwmon/smsc47m1.c1
-rw-r--r--drivers/hwmon/via686a.c1
-rw-r--r--drivers/hwmon/vt8231.c1
-rw-r--r--drivers/hwmon/w83627ehf.c1
-rw-r--r--drivers/hwmon/w83627hf.c1
-rw-r--r--drivers/hwmon/w83781d.c1
-rw-r--r--drivers/i2c/Kconfig2
-rw-r--r--drivers/i2c/algos/Kconfig6
-rw-r--r--drivers/i2c/algos/Makefile1
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c23
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-sgi.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-sibyte.c215
-rw-r--r--drivers/i2c/busses/Kconfig34
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-au1550.c21
-rw-r--r--drivers/i2c/busses/i2c-elektor.c1
-rw-r--r--drivers/i2c/busses/i2c-hydra.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-i810.c2
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c2
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c2
-rw-r--r--drivers/i2c/busses/i2c-isa.c42
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c1
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c1
-rw-r--r--drivers/i2c/busses/i2c-mpc.c2
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c2
-rw-r--r--drivers/i2c/busses/i2c-ocores.c2
-rw-r--r--drivers/i2c/busses/i2c-omap.c676
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c1
-rw-r--r--drivers/i2c/busses/i2c-parport.c1
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-powermac.c2
-rw-r--r--drivers/i2c/busses/i2c-prosavage.c1
-rw-r--r--drivers/i2c/busses/i2c-pxa.c2
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c2
-rw-r--r--drivers/i2c/busses/i2c-savage4.c1
-rw-r--r--drivers/i2c/busses/i2c-sibyte.c160
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/busses/i2c-sis630.c2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-stub.c21
-rw-r--r--drivers/i2c/busses/i2c-via.c1
-rw-r--r--drivers/i2c/busses/i2c-viapro.c10
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c2
-rw-r--r--drivers/i2c/busses/scx200_i2c.c12
-rw-r--r--drivers/i2c/chips/eeprom.c8
-rw-r--r--drivers/i2c/chips/max6875.c25
-rw-r--r--drivers/i2c/chips/pca9539.c11
-rw-r--r--drivers/i2c/chips/pcf8574.c22
-rw-r--r--drivers/i2c/chips/pcf8591.c58
-rw-r--r--drivers/i2c/i2c-core.c72
-rw-r--r--drivers/i2c/i2c-dev.c109
-rw-r--r--drivers/ieee1394/pcilynx.c1
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c1
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c1
-rw-r--r--drivers/media/video/cx88/cx88-vp3054-i2c.c1
-rw-r--r--drivers/media/video/zoran_card.c1
-rw-r--r--drivers/video/i810/i810-i2c.c1
-rw-r--r--drivers/video/matrox/i2c-matroxfb.c12
-rw-r--r--drivers/video/savage/savagefb-i2c.c1
-rw-r--r--include/linux/i2c-algo-bit.h1
-rw-r--r--include/linux/i2c-algo-pcf.h1
-rw-r--r--include/linux/i2c-algo-sibyte.h33
-rw-r--r--include/linux/i2c.h14
83 files changed, 1219 insertions, 482 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index bf56b20652b0..93b10bd784ed 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -313,3 +313,12 @@ Why: The stacking of class devices makes these values misleading and
313Who: Kay Sievers <kay.sievers@suse.de> 313Who: Kay Sievers <kay.sievers@suse.de>
314 314
315--------------------------- 315---------------------------
316
317What: i2c-isa
318When: December 2006
319Why: i2c-isa is a non-sense and doesn't fit in the device driver
320 model. Drivers relying on it are better implemented as platform
321 drivers.
322Who: Jean Delvare <khali@linux-fr.org>
323
324---------------------------
diff --git a/Documentation/i2c/busses/i2c-viapro b/Documentation/i2c/busses/i2c-viapro
index 16775663b9f5..25680346e0ac 100644
--- a/Documentation/i2c/busses/i2c-viapro
+++ b/Documentation/i2c/busses/i2c-viapro
@@ -7,9 +7,12 @@ Supported adapters:
7 * VIA Technologies, Inc. VT82C686A/B 7 * VIA Technologies, Inc. VT82C686A/B
8 Datasheet: Sometimes available at the VIA website 8 Datasheet: Sometimes available at the VIA website
9 9
10 * VIA Technologies, Inc. VT8231, VT8233, VT8233A, VT8235, VT8237R 10 * VIA Technologies, Inc. VT8231, VT8233, VT8233A
11 Datasheet: available on request from VIA 11 Datasheet: available on request from VIA
12 12
13 * VIA Technologies, Inc. VT8235, VT8237R, VT8237A, VT8251
14 Datasheet: available on request and under NDA from VIA
15
13Authors: 16Authors:
14 Kyösti Mälkki <kmalkki@cc.hut.fi>, 17 Kyösti Mälkki <kmalkki@cc.hut.fi>,
15 Mark D. Studebaker <mdsxyz123@yahoo.com>, 18 Mark D. Studebaker <mdsxyz123@yahoo.com>,
@@ -39,6 +42,8 @@ Your lspci -n listing must show one of these :
39 device 1106:8235 (VT8231 function 4) 42 device 1106:8235 (VT8231 function 4)
40 device 1106:3177 (VT8235) 43 device 1106:3177 (VT8235)
41 device 1106:3227 (VT8237R) 44 device 1106:3227 (VT8237R)
45 device 1106:3337 (VT8237A)
46 device 1106:3287 (VT8251)
42 47
43If none of these show up, you should look in the BIOS for settings like 48If none of these show up, you should look in the BIOS for settings like
44enable ACPI / SMBus or even USB. 49enable ACPI / SMBus or even USB.
diff --git a/Documentation/i2c/i2c-stub b/Documentation/i2c/i2c-stub
index d6dcb138abf5..9cc081e69764 100644
--- a/Documentation/i2c/i2c-stub
+++ b/Documentation/i2c/i2c-stub
@@ -6,9 +6,12 @@ This module is a very simple fake I2C/SMBus driver. It implements four
6types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, and 6types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, and
7(r/w) word data. 7(r/w) word data.
8 8
9You need to provide a chip address as a module parameter when loading
10this driver, which will then only react to SMBus commands to this address.
11
9No hardware is needed nor associated with this module. It will accept write 12No hardware is needed nor associated with this module. It will accept write
10quick commands to all addresses; it will respond to the other commands (also 13quick commands to one address; it will respond to the other commands (also
11to all addresses) by reading from or writing to an array in memory. It will 14to one address) by reading from or writing to an array in memory. It will
12also spam the kernel logs for every command it handles. 15also spam the kernel logs for every command it handles.
13 16
14A pointer register with auto-increment is implemented for all byte 17A pointer register with auto-increment is implemented for all byte
@@ -21,6 +24,11 @@ The typical use-case is like this:
21 3. load the target sensors chip driver module 24 3. load the target sensors chip driver module
22 4. observe its behavior in the kernel log 25 4. observe its behavior in the kernel log
23 26
27PARAMETERS:
28
29int chip_addr:
30 The SMBus address to emulate a chip at.
31
24CAVEATS: 32CAVEATS:
25 33
26There are independent arrays for byte/data and word/data commands. Depending 34There are independent arrays for byte/data and word/data commands. Depending
@@ -33,6 +41,9 @@ If the hardware for your driver has banked registers (e.g. Winbond sensors
33chips) this module will not work well - although it could be extended to 41chips) this module will not work well - although it could be extended to
34support that pretty easily. 42support that pretty easily.
35 43
44Only one chip address is supported - although this module could be
45extended to support more.
46
36If you spam it hard enough, printk can be lossy. This module really wants 47If you spam it hard enough, printk can be lossy. This module really wants
37something like relayfs. 48something like relayfs.
38 49
diff --git a/drivers/acorn/char/i2c.c b/drivers/acorn/char/i2c.c
index c26c08b36829..bdb9c8b78ed8 100644
--- a/drivers/acorn/char/i2c.c
+++ b/drivers/acorn/char/i2c.c
@@ -308,7 +308,6 @@ static struct i2c_algo_bit_data ioc_data = {
308 .getsda = ioc_getsda, 308 .getsda = ioc_getsda,
309 .getscl = ioc_getscl, 309 .getscl = ioc_getscl,
310 .udelay = 80, 310 .udelay = 80,
311 .mdelay = 80,
312 .timeout = 100 311 .timeout = 100
313}; 312};
314 313
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
index 6809c283ec58..6342e612c203 100644
--- a/drivers/acpi/i2c_ec.c
+++ b/drivers/acpi/i2c_ec.c
@@ -293,7 +293,7 @@ static u32 acpi_ec_smb_func(struct i2c_adapter *adapter)
293 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC); 293 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC);
294} 294}
295 295
296static struct i2c_algorithm acpi_ec_smbus_algorithm = { 296static const struct i2c_algorithm acpi_ec_smbus_algorithm = {
297 .smbus_xfer = acpi_ec_smb_access, 297 .smbus_xfer = acpi_ec_smb_access,
298 .functionality = acpi_ec_smb_func, 298 .functionality = acpi_ec_smb_func,
299}; 299};
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 06df92b3ee49..b0ee57492228 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -243,6 +243,7 @@ static struct i2c_driver it87_driver = {
243 243
244static struct i2c_driver it87_isa_driver = { 244static struct i2c_driver it87_isa_driver = {
245 .driver = { 245 .driver = {
246 .owner = THIS_MODULE,
246 .name = "it87-isa", 247 .name = "it87-isa",
247 }, 248 },
248 .attach_adapter = it87_isa_attach_adapter, 249 .attach_adapter = it87_isa_attach_adapter,
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index a6ce7abf8602..fa1715b9a996 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -175,6 +175,7 @@ static struct i2c_driver lm78_driver = {
175 175
176static struct i2c_driver lm78_isa_driver = { 176static struct i2c_driver lm78_isa_driver = {
177 .driver = { 177 .driver = {
178 .owner = THIS_MODULE,
178 .name = "lm78-isa", 179 .name = "lm78-isa",
179 }, 180 },
180 .attach_adapter = lm78_isa_attach_adapter, 181 .attach_adapter = lm78_isa_attach_adapter,
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index ae05e483a778..236f9f29c624 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -238,6 +238,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev);
238 238
239static struct i2c_driver pc87360_driver = { 239static struct i2c_driver pc87360_driver = {
240 .driver = { 240 .driver = {
241 .owner = THIS_MODULE,
241 .name = "pc87360", 242 .name = "pc87360",
242 }, 243 },
243 .attach_adapter = pc87360_detect, 244 .attach_adapter = pc87360_detect,
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 063f71c5f07e..3783af4195bd 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -200,6 +200,7 @@ static void sis5595_init_client(struct i2c_client *client);
200 200
201static struct i2c_driver sis5595_driver = { 201static struct i2c_driver sis5595_driver = {
202 .driver = { 202 .driver = {
203 .owner = THIS_MODULE,
203 .name = "sis5595", 204 .name = "sis5595",
204 }, 205 },
205 .attach_adapter = sis5595_detect, 206 .attach_adapter = sis5595_detect,
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index b6086186d225..a85869393bab 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -228,6 +228,7 @@ static int smsc47b397_detect(struct i2c_adapter *adapter);
228 228
229static struct i2c_driver smsc47b397_driver = { 229static struct i2c_driver smsc47b397_driver = {
230 .driver = { 230 .driver = {
231 .owner = THIS_MODULE,
231 .name = "smsc47b397", 232 .name = "smsc47b397",
232 }, 233 },
233 .attach_adapter = smsc47b397_detect, 234 .attach_adapter = smsc47b397_detect,
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 825e8f72698f..6c81b843d831 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -128,6 +128,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
128 128
129static struct i2c_driver smsc47m1_driver = { 129static struct i2c_driver smsc47m1_driver = {
130 .driver = { 130 .driver = {
131 .owner = THIS_MODULE,
131 .name = "smsc47m1", 132 .name = "smsc47m1",
132 }, 133 },
133 .attach_adapter = smsc47m1_detect, 134 .attach_adapter = smsc47m1_detect,
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 166298f1f190..95ae056e5a94 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -574,6 +574,7 @@ static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
574 smbus_driver and isa_driver, and clients could be of either kind */ 574 smbus_driver and isa_driver, and clients could be of either kind */
575static struct i2c_driver via686a_driver = { 575static struct i2c_driver via686a_driver = {
576 .driver = { 576 .driver = {
577 .owner = THIS_MODULE,
577 .name = "via686a", 578 .name = "via686a",
578 }, 579 },
579 .attach_adapter = via686a_detect, 580 .attach_adapter = via686a_detect,
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 686f3deb3093..236ccf0e915d 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -587,6 +587,7 @@ static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
587 587
588static struct i2c_driver vt8231_driver = { 588static struct i2c_driver vt8231_driver = {
589 .driver = { 589 .driver = {
590 .owner = THIS_MODULE,
590 .name = "vt8231", 591 .name = "vt8231",
591 }, 592 },
592 .attach_adapter = vt8231_detect, 593 .attach_adapter = vt8231_detect,
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 40301bc6ce18..b21d6b9d7eac 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -903,6 +903,7 @@ static int w83627ehf_detach_client(struct i2c_client *client)
903 903
904static struct i2c_driver w83627ehf_driver = { 904static struct i2c_driver w83627ehf_driver = {
905 .driver = { 905 .driver = {
906 .owner = THIS_MODULE,
906 .name = "w83627ehf", 907 .name = "w83627ehf",
907 }, 908 },
908 .attach_adapter = w83627ehf_detect, 909 .attach_adapter = w83627ehf_detect,
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 79368d53c363..30295028ea99 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -339,6 +339,7 @@ static void w83627hf_init_client(struct i2c_client *client);
339 339
340static struct i2c_driver w83627hf_driver = { 340static struct i2c_driver w83627hf_driver = {
341 .driver = { 341 .driver = {
342 .owner = THIS_MODULE,
342 .name = "w83627hf", 343 .name = "w83627hf",
343 }, 344 },
344 .attach_adapter = w83627hf_detect, 345 .attach_adapter = w83627hf_detect,
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 7be469ed0f8f..95221b14e13a 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -288,6 +288,7 @@ static struct i2c_driver w83781d_driver = {
288 288
289static struct i2c_driver w83781d_isa_driver = { 289static struct i2c_driver w83781d_isa_driver = {
290 .driver = { 290 .driver = {
291 .owner = THIS_MODULE,
291 .name = "w83781d-isa", 292 .name = "w83781d-isa",
292 }, 293 },
293 .attach_adapter = w83781d_isa_attach_adapter, 294 .attach_adapter = w83781d_isa_attach_adapter,
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 24383afdda76..11935f66fcd8 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -1,5 +1,5 @@
1# 1#
2# Character device configuration 2# I2C subsystem configuration
3# 3#
4 4
5menu "I2C support" 5menu "I2C support"
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index 30408015d231..c034820615bb 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -53,12 +53,6 @@ config I2C_ALGO8XX
53 tristate "MPC8xx CPM I2C interface" 53 tristate "MPC8xx CPM I2C interface"
54 depends on 8xx && I2C 54 depends on 8xx && I2C
55 55
56config I2C_ALGO_SIBYTE
57 tristate "SiByte SMBus interface"
58 depends on SIBYTE_SB1xxx_SOC && I2C
59 help
60 Supports the SiByte SOC on-chip I2C interfaces (2 channels).
61
62config I2C_ALGO_SGI 56config I2C_ALGO_SGI
63 tristate "I2C SGI interfaces" 57 tristate "I2C SGI interfaces"
64 depends on I2C && (SGI_IP22 || SGI_IP32 || X86_VISWS) 58 depends on I2C && (SGI_IP22 || SGI_IP32 || X86_VISWS)
diff --git a/drivers/i2c/algos/Makefile b/drivers/i2c/algos/Makefile
index 867fe1f67401..208be04a3dbd 100644
--- a/drivers/i2c/algos/Makefile
+++ b/drivers/i2c/algos/Makefile
@@ -6,7 +6,6 @@ obj-$(CONFIG_I2C_ALGOBIT) += i2c-algo-bit.o
6obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o 6obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o
7obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o 7obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o
8obj-$(CONFIG_I2C_ALGOITE) += i2c-algo-ite.o 8obj-$(CONFIG_I2C_ALGOITE) += i2c-algo-ite.o
9obj-$(CONFIG_I2C_ALGO_SIBYTE) += i2c-algo-sibyte.o
10obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o 9obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o
11 10
12ifeq ($(CONFIG_I2C_DEBUG_ALGO),y) 11ifeq ($(CONFIG_I2C_DEBUG_ALGO),y)
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index ab230c033f99..21c36bfb5e6b 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -76,17 +76,15 @@ static inline void scllo(struct i2c_algo_bit_data *adap)
76 * Raise scl line, and do checking for delays. This is necessary for slower 76 * Raise scl line, and do checking for delays. This is necessary for slower
77 * devices. 77 * devices.
78 */ 78 */
79static inline int sclhi(struct i2c_algo_bit_data *adap) 79static int sclhi(struct i2c_algo_bit_data *adap)
80{ 80{
81 unsigned long start; 81 unsigned long start;
82 82
83 setscl(adap,1); 83 setscl(adap,1);
84 84
85 /* Not all adapters have scl sense line... */ 85 /* Not all adapters have scl sense line... */
86 if (adap->getscl == NULL ) { 86 if (!adap->getscl)
87 udelay(adap->udelay); 87 goto done;
88 return 0;
89 }
90 88
91 start=jiffies; 89 start=jiffies;
92 while (! getscl(adap) ) { 90 while (! getscl(adap) ) {
@@ -101,6 +99,8 @@ static inline int sclhi(struct i2c_algo_bit_data *adap)
101 cond_resched(); 99 cond_resched();
102 } 100 }
103 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); 101 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
102
103done:
104 udelay(adap->udelay); 104 udelay(adap->udelay);
105 return 0; 105 return 0;
106} 106}
@@ -121,7 +121,6 @@ static void i2c_repstart(struct i2c_algo_bit_data *adap)
121 DEBPROTO(printk(" Sr ")); 121 DEBPROTO(printk(" Sr "));
122 setsda(adap,1); 122 setsda(adap,1);
123 sclhi(adap); 123 sclhi(adap);
124 udelay(adap->udelay);
125 124
126 sdalo(adap); 125 sdalo(adap);
127 scllo(adap); 126 scllo(adap);
@@ -306,7 +305,7 @@ bailout:
306 * 0 chip did not answer 305 * 0 chip did not answer
307 * -x transmission error 306 * -x transmission error
308 */ 307 */
309static inline int try_address(struct i2c_adapter *i2c_adap, 308static int try_address(struct i2c_adapter *i2c_adap,
310 unsigned char addr, int retries) 309 unsigned char addr, int retries)
311{ 310{
312 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 311 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
@@ -354,15 +353,11 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
354 return (retval<0)? retval : -EFAULT; 353 return (retval<0)? retval : -EFAULT;
355 /* got a better one ?? */ 354 /* got a better one ?? */
356 } 355 }
357#if 0
358 /* from asm/delay.h */
359 __delay(adap->mdelay * (loops_per_sec / 1000) );
360#endif
361 } 356 }
362 return wrcount; 357 return wrcount;
363} 358}
364 359
365static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 360static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
366{ 361{
367 int inval; 362 int inval;
368 int rdcount=0; /* counts bytes read */ 363 int rdcount=0; /* counts bytes read */
@@ -412,7 +407,7 @@ static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
412 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or 407 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
413 * -ETIMEDOUT, for example if the lines are stuck...) 408 * -ETIMEDOUT, for example if the lines are stuck...)
414 */ 409 */
415static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 410static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
416{ 411{
417 unsigned short flags = msg->flags; 412 unsigned short flags = msg->flags;
418 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; 413 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
@@ -517,7 +512,7 @@ static u32 bit_func(struct i2c_adapter *adap)
517 512
518/* -----exported algorithm data: ------------------------------------- */ 513/* -----exported algorithm data: ------------------------------------- */
519 514
520static struct i2c_algorithm i2c_bit_algo = { 515static const struct i2c_algorithm i2c_bit_algo = {
521 .master_xfer = bit_xfer, 516 .master_xfer = bit_xfer,
522 .functionality = bit_func, 517 .functionality = bit_func,
523}; 518};
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index b88a6fcf7bd0..9081c9fbcd29 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -355,7 +355,7 @@ static int pca_init(struct i2c_algo_pca_data *adap)
355 return 0; 355 return 0;
356} 356}
357 357
358static struct i2c_algorithm pca_algo = { 358static const struct i2c_algorithm pca_algo = {
359 .master_xfer = pca_xfer, 359 .master_xfer = pca_xfer,
360 .functionality = pca_func, 360 .functionality = pca_func,
361}; 361};
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 5b24930adb5a..3b2003398966 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -458,7 +458,7 @@ static u32 pcf_func(struct i2c_adapter *adap)
458 458
459/* -----exported algorithm data: ------------------------------------- */ 459/* -----exported algorithm data: ------------------------------------- */
460 460
461static struct i2c_algorithm pcf_algo = { 461static const struct i2c_algorithm pcf_algo = {
462 .master_xfer = pcf_xfer, 462 .master_xfer = pcf_xfer,
463 .functionality = pcf_func, 463 .functionality = pcf_func,
464}; 464};
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c
index 932c4fa86c73..490d99997fd0 100644
--- a/drivers/i2c/algos/i2c-algo-sgi.c
+++ b/drivers/i2c/algos/i2c-algo-sgi.c
@@ -157,7 +157,7 @@ static u32 sgi_func(struct i2c_adapter *adap)
157 return I2C_FUNC_SMBUS_EMUL; 157 return I2C_FUNC_SMBUS_EMUL;
158} 158}
159 159
160static struct i2c_algorithm sgi_algo = { 160static const struct i2c_algorithm sgi_algo = {
161 .master_xfer = sgi_xfer, 161 .master_xfer = sgi_xfer,
162 .functionality = sgi_func, 162 .functionality = sgi_func,
163}; 163};
diff --git a/drivers/i2c/algos/i2c-algo-sibyte.c b/drivers/i2c/algos/i2c-algo-sibyte.c
deleted file mode 100644
index 32d41c6fac0f..000000000000
--- a/drivers/i2c/algos/i2c-algo-sibyte.c
+++ /dev/null
@@ -1,215 +0,0 @@
1/* ------------------------------------------------------------------------- */
2/* i2c-algo-sibyte.c i2c driver algorithms for bit-shift adapters */
3/* ------------------------------------------------------------------------- */
4/* Copyright (C) 2001,2002,2003 Broadcom Corporation
5 Copyright (C) 1995-2000 Simon G. Vogl
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 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20/* ------------------------------------------------------------------------- */
21
22/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
23 Frodo Looijaard <frodol@dds.nl>. */
24
25/* Ported for SiByte SOCs by Broadcom Corporation. */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30
31#include <asm/io.h>
32#include <asm/sibyte/sb1250_regs.h>
33#include <asm/sibyte/sb1250_smbus.h>
34
35#include <linux/i2c.h>
36#include <linux/i2c-algo-sibyte.h>
37
38/* ----- global defines ----------------------------------------------- */
39#define SMB_CSR(a,r) ((long)(a->reg_base + r))
40
41/* ----- global variables --------------------------------------------- */
42
43/* module parameters:
44 */
45static int bit_scan; /* have a look at what's hanging 'round */
46
47
48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
49 unsigned short flags, char read_write,
50 u8 command, int size, union i2c_smbus_data * data)
51{
52 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
53 int data_bytes = 0;
54 int error;
55
56 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
57 ;
58
59 switch (size) {
60 case I2C_SMBUS_QUICK:
61 csr_out32((V_SMB_ADDR(addr) | (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) |
62 V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START));
63 break;
64 case I2C_SMBUS_BYTE:
65 if (read_write == I2C_SMBUS_READ) {
66 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE),
67 SMB_CSR(adap, R_SMB_START));
68 data_bytes = 1;
69 } else {
70 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
71 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE),
72 SMB_CSR(adap, R_SMB_START));
73 }
74 break;
75 case I2C_SMBUS_BYTE_DATA:
76 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
77 if (read_write == I2C_SMBUS_READ) {
78 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE),
79 SMB_CSR(adap, R_SMB_START));
80 data_bytes = 1;
81 } else {
82 csr_out32(V_SMB_LB(data->byte), SMB_CSR(adap, R_SMB_DATA));
83 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
84 SMB_CSR(adap, R_SMB_START));
85 }
86 break;
87 case I2C_SMBUS_WORD_DATA:
88 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
89 if (read_write == I2C_SMBUS_READ) {
90 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE),
91 SMB_CSR(adap, R_SMB_START));
92 data_bytes = 2;
93 } else {
94 csr_out32(V_SMB_LB(data->word & 0xff), SMB_CSR(adap, R_SMB_DATA));
95 csr_out32(V_SMB_MB(data->word >> 8), SMB_CSR(adap, R_SMB_DATA));
96 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
97 SMB_CSR(adap, R_SMB_START));
98 }
99 break;
100 default:
101 return -1; /* XXXKW better error code? */
102 }
103
104 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
105 ;
106
107 error = csr_in32(SMB_CSR(adap, R_SMB_STATUS));
108 if (error & M_SMB_ERROR) {
109 /* Clear error bit by writing a 1 */
110 csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS));
111 return -1; /* XXXKW better error code? */
112 }
113
114 if (data_bytes == 1)
115 data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff;
116 if (data_bytes == 2)
117 data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff;
118
119 return 0;
120}
121
122static int algo_control(struct i2c_adapter *adapter,
123 unsigned int cmd, unsigned long arg)
124{
125 return 0;
126}
127
128static u32 bit_func(struct i2c_adapter *adap)
129{
130 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
131 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA);
132}
133
134
135/* -----exported algorithm data: ------------------------------------- */
136
137static struct i2c_algorithm i2c_sibyte_algo = {
138 .smbus_xfer = smbus_xfer,
139 .algo_control = algo_control, /* ioctl */
140 .functionality = bit_func,
141};
142
143/*
144 * registering functions to load algorithms at runtime
145 */
146int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
147{
148 int i;
149 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
150
151 /* register new adapter to i2c module... */
152 i2c_adap->algo = &i2c_sibyte_algo;
153
154 /* Set the frequency to 100 kHz */
155 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
156 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));
157
158 /* scan bus */
159 if (bit_scan) {
160 union i2c_smbus_data data;
161 int rc;
162 printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
163 i2c_adap->name);
164 for (i = 0x00; i < 0x7f; i++) {
165 /* XXXKW is this a realistic probe? */
166 rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0,
167 I2C_SMBUS_BYTE_DATA, &data);
168 if (!rc) {
169 printk("(%02x)",i);
170 } else
171 printk(".");
172 }
173 printk("\n");
174 }
175
176 return i2c_add_adapter(i2c_adap);
177}
178
179
180int i2c_sibyte_del_bus(struct i2c_adapter *adap)
181{
182 int res;
183
184 if ((res = i2c_del_adapter(adap)) < 0)
185 return res;
186
187 return 0;
188}
189
190int __init i2c_algo_sibyte_init (void)
191{
192 printk("i2c-algo-sibyte.o: i2c SiByte algorithm module\n");
193 return 0;
194}
195
196
197EXPORT_SYMBOL(i2c_sibyte_add_bus);
198EXPORT_SYMBOL(i2c_sibyte_del_bus);
199
200#ifdef MODULE
201MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
202MODULE_DESCRIPTION("SiByte I2C-Bus algorithm");
203module_param(bit_scan, int, 0);
204MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
205MODULE_LICENSE("GPL");
206
207int init_module(void)
208{
209 return i2c_algo_sibyte_init();
210}
211
212void cleanup_module(void)
213{
214}
215#endif
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 884320e70403..9e56c3989d68 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -75,11 +75,11 @@ config I2C_AMD8111
75 will be called i2c-amd8111. 75 will be called i2c-amd8111.
76 76
77config I2C_AU1550 77config I2C_AU1550
78 tristate "Au1550 SMBus interface" 78 tristate "Au1550/Au1200 SMBus interface"
79 depends on I2C && SOC_AU1550 79 depends on I2C && (SOC_AU1550 || SOC_AU1200)
80 help 80 help
81 If you say yes to this option, support will be included for the 81 If you say yes to this option, support will be included for the
82 Au1550 SMBus interface. 82 Au1550 and Au1200 SMBus interface.
83 83
84 This driver can also be built as a module. If so, the module 84 This driver can also be built as a module. If so, the module
85 will be called i2c-au1550. 85 will be called i2c-au1550.
@@ -287,6 +287,16 @@ config I2C_OCORES
287 This driver can also be built as a module. If so, the module 287 This driver can also be built as a module. If so, the module
288 will be called i2c-ocores. 288 will be called i2c-ocores.
289 289
290config I2C_OMAP
291 tristate "OMAP I2C adapter"
292 depends on I2C && ARCH_OMAP
293 default y if MACH_OMAP_H3 || MACH_OMAP_OSK
294 help
295 If you say yes to this option, support will be included for the
296 I2C interface on the Texas Instruments OMAP1/2 family of processors.
297 Like OMAP1510/1610/1710/5912 and OMAP242x.
298 For details see http://www.ti.com/omap.
299
290config I2C_PARPORT 300config I2C_PARPORT
291 tristate "Parallel port adapter" 301 tristate "Parallel port adapter"
292 depends on I2C && PARPORT 302 depends on I2C && PARPORT
@@ -482,19 +492,19 @@ config I2C_VIA
482 will be called i2c-via. 492 will be called i2c-via.
483 493
484config I2C_VIAPRO 494config I2C_VIAPRO
485 tristate "VIA 82C596/82C686/823x" 495 tristate "VIA 82C596/82C686/82xx"
486 depends on I2C && PCI 496 depends on I2C && PCI
487 help 497 help
488 If you say yes to this option, support will be included for the VIA 498 If you say yes to this option, support will be included for the VIA
489 82C596/82C686/823x I2C interfaces. Specifically, the following 499 82C596/82C686/82xx I2C interfaces. Specifically, the following
490 chipsets are supported: 500 chipsets are supported:
491 82C596A/B 501 VT82C596A/B
492 82C686A/B 502 VT82C686A/B
493 8231 503 VT8231
494 8233 504 VT8233/A
495 8233A 505 VT8235
496 8235 506 VT8237R/A
497 8237 507 VT8251
498 508
499 This driver can also be built as a module. If so, the module 509 This driver can also be built as a module. If so, the module
500 will be called i2c-viapro. 510 will be called i2c-viapro.
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ac56df53155b..493c87289b62 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_I2C_MPC) += i2c-mpc.o
24obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 24obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o
25obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o 25obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o
26obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 26obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o
27obj-$(CONFIG_I2C_OMAP) += i2c-omap.o
27obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 28obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
28obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 29obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
29obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 30obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index d3ef46aeeb3c..e75d339a3481 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -468,7 +468,7 @@ static u32 ali1535_func(struct i2c_adapter *adapter)
468 I2C_FUNC_SMBUS_BLOCK_DATA; 468 I2C_FUNC_SMBUS_BLOCK_DATA;
469} 469}
470 470
471static struct i2c_algorithm smbus_algorithm = { 471static const struct i2c_algorithm smbus_algorithm = {
472 .smbus_xfer = ali1535_access, 472 .smbus_xfer = ali1535_access,
473 .functionality = ali1535_func, 473 .functionality = ali1535_func,
474}; 474};
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index e6f63208fc4a..33fbb47100a3 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -367,7 +367,7 @@ static void ali1563_shutdown(struct pci_dev *dev)
367 release_region(ali1563_smba,ALI1563_SMB_IOSIZE); 367 release_region(ali1563_smba,ALI1563_SMB_IOSIZE);
368} 368}
369 369
370static struct i2c_algorithm ali1563_algorithm = { 370static const struct i2c_algorithm ali1563_algorithm = {
371 .smbus_xfer = ali1563_access, 371 .smbus_xfer = ali1563_access,
372 .functionality = ali1563_func, 372 .functionality = ali1563_func,
373}; 373};
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 7a5c0941dbc1..3f11b6e1a341 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -463,7 +463,7 @@ static u32 ali15x3_func(struct i2c_adapter *adapter)
463 I2C_FUNC_SMBUS_BLOCK_DATA; 463 I2C_FUNC_SMBUS_BLOCK_DATA;
464} 464}
465 465
466static struct i2c_algorithm smbus_algorithm = { 466static const struct i2c_algorithm smbus_algorithm = {
467 .smbus_xfer = ali15x3_access, 467 .smbus_xfer = ali15x3_access,
468 .functionality = ali15x3_func, 468 .functionality = ali15x3_func,
469}; 469};
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 1750dedaf4b5..2d21afdc5b1c 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -294,7 +294,7 @@ static u32 amd756_func(struct i2c_adapter *adapter)
294 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL; 294 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL;
295} 295}
296 296
297static struct i2c_algorithm smbus_algorithm = { 297static const struct i2c_algorithm smbus_algorithm = {
298 .smbus_xfer = amd756_access, 298 .smbus_xfer = amd756_access,
299 .functionality = amd756_func, 299 .functionality = amd756_func,
300}; 300};
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index e5ef560e686a..0fbc7186c91a 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -316,7 +316,7 @@ static u32 amd8111_func(struct i2c_adapter *adapter)
316 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC; 316 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC;
317} 317}
318 318
319static struct i2c_algorithm smbus_algorithm = { 319static const struct i2c_algorithm smbus_algorithm = {
320 .smbus_xfer = amd8111_access, 320 .smbus_xfer = amd8111_access,
321 .functionality = amd8111_func, 321 .functionality = amd8111_func,
322}; 322};
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index d06edce03bf4..d7e7c359fc36 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -34,8 +34,7 @@
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36 36
37#include <asm/mach-au1x00/au1000.h> 37#include <asm/mach-au1x00/au1xxx.h>
38#include <asm/mach-pb1x00/pb1550.h>
39#include <asm/mach-au1x00/au1xxx_psc.h> 38#include <asm/mach-au1x00/au1xxx_psc.h>
40 39
41#include "i2c-au1550.h" 40#include "i2c-au1550.h"
@@ -118,13 +117,19 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd)
118 117
119 /* Reset the FIFOs, clear events. 118 /* Reset the FIFOs, clear events.
120 */ 119 */
121 sp->psc_smbpcr = PSC_SMBPCR_DC; 120 stat = sp->psc_smbstat;
122 sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR; 121 sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR;
123 au_sync(); 122 au_sync();
124 do { 123
125 stat = sp->psc_smbpcr; 124 if (!(stat & PSC_SMBSTAT_TE) || !(stat & PSC_SMBSTAT_RE)) {
125 sp->psc_smbpcr = PSC_SMBPCR_DC;
126 au_sync(); 126 au_sync();
127 } while ((stat & PSC_SMBPCR_DC) != 0); 127 do {
128 stat = sp->psc_smbpcr;
129 au_sync();
130 } while ((stat & PSC_SMBPCR_DC) != 0);
131 udelay(50);
132 }
128 133
129 /* Write out the i2c chip address and specify operation 134 /* Write out the i2c chip address and specify operation
130 */ 135 */
@@ -279,10 +284,10 @@ au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
279static u32 284static u32
280au1550_func(struct i2c_adapter *adap) 285au1550_func(struct i2c_adapter *adap)
281{ 286{
282 return I2C_FUNC_I2C; 287 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
283} 288}
284 289
285static struct i2c_algorithm au1550_algo = { 290static const struct i2c_algorithm au1550_algo = {
286 .master_xfer = au1550_xfer, 291 .master_xfer = au1550_xfer,
287 .functionality = au1550_func, 292 .functionality = au1550_func,
288}; 293};
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 59f8308c2356..caa8e5c8bfbb 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -196,7 +196,6 @@ static struct i2c_algo_pcf_data pcf_isa_data = {
196 .getclock = pcf_isa_getclock, 196 .getclock = pcf_isa_getclock,
197 .waitforpin = pcf_isa_waitforpin, 197 .waitforpin = pcf_isa_waitforpin,
198 .udelay = 10, 198 .udelay = 10,
199 .mdelay = 10,
200 .timeout = 100, 199 .timeout = 100,
201}; 200};
202 201
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index e0cb3b0f92fa..457d48a0ab9d 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -99,7 +99,6 @@ static struct i2c_algo_bit_data hydra_bit_data = {
99 .getsda = hydra_bit_getsda, 99 .getsda = hydra_bit_getsda,
100 .getscl = hydra_bit_getscl, 100 .getscl = hydra_bit_getscl,
101 .udelay = 5, 101 .udelay = 5,
102 .mdelay = 5,
103 .timeout = HZ 102 .timeout = HZ
104}; 103};
105 104
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 7be1d0a3e8f8..bbb2fbee836f 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -434,7 +434,7 @@ static u32 i801_func(struct i2c_adapter *adapter)
434 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0); 434 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0);
435} 435}
436 436
437static struct i2c_algorithm smbus_algorithm = { 437static const struct i2c_algorithm smbus_algorithm = {
438 .smbus_xfer = i801_access, 438 .smbus_xfer = i801_access,
439 .functionality = i801_func, 439 .functionality = i801_func,
440}; 440};
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c
index 748be30f2bae..b66fb6bb1870 100644
--- a/drivers/i2c/busses/i2c-i810.c
+++ b/drivers/i2c/busses/i2c-i810.c
@@ -166,7 +166,6 @@ static struct i2c_algo_bit_data i810_i2c_bit_data = {
166 .getsda = bit_i810i2c_getsda, 166 .getsda = bit_i810i2c_getsda,
167 .getscl = bit_i810i2c_getscl, 167 .getscl = bit_i810i2c_getscl,
168 .udelay = CYCLE_DELAY, 168 .udelay = CYCLE_DELAY,
169 .mdelay = CYCLE_DELAY,
170 .timeout = TIMEOUT, 169 .timeout = TIMEOUT,
171}; 170};
172 171
@@ -182,7 +181,6 @@ static struct i2c_algo_bit_data i810_ddc_bit_data = {
182 .getsda = bit_i810ddc_getsda, 181 .getsda = bit_i810ddc_getsda,
183 .getscl = bit_i810ddc_getscl, 182 .getscl = bit_i810ddc_getscl,
184 .udelay = CYCLE_DELAY, 183 .udelay = CYCLE_DELAY,
185 .mdelay = CYCLE_DELAY,
186 .timeout = TIMEOUT, 184 .timeout = TIMEOUT,
187}; 185};
188 186
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 0599bbd65d93..5bccb5d68318 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -625,7 +625,7 @@ static u32 iic_func(struct i2c_adapter *adap)
625 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR; 625 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
626} 626}
627 627
628static struct i2c_algorithm iic_algo = { 628static const struct i2c_algorithm iic_algo = {
629 .master_xfer = iic_xfer, 629 .master_xfer = iic_xfer,
630 .functionality = iic_func 630 .functionality = iic_func
631}; 631};
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 48c56939c861..8e413150af37 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -401,7 +401,7 @@ iop3xx_i2c_func(struct i2c_adapter *adap)
401 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 401 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
402} 402}
403 403
404static struct i2c_algorithm iop3xx_i2c_algo = { 404static const struct i2c_algorithm iop3xx_i2c_algo = {
405 .master_xfer = iop3xx_i2c_master_xfer, 405 .master_xfer = iop3xx_i2c_master_xfer,
406 .algo_control = iop3xx_i2c_algo_control, 406 .algo_control = iop3xx_i2c_algo_control,
407 .functionality = iop3xx_i2c_func, 407 .functionality = iop3xx_i2c_func,
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index c3e1d3e888d7..4380653748a4 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -43,7 +43,7 @@
43static u32 isa_func(struct i2c_adapter *adapter); 43static u32 isa_func(struct i2c_adapter *adapter);
44 44
45/* This is the actual algorithm we define */ 45/* This is the actual algorithm we define */
46static struct i2c_algorithm isa_algorithm = { 46static const struct i2c_algorithm isa_algorithm = {
47 .functionality = isa_func, 47 .functionality = isa_func,
48}; 48};
49 49
@@ -89,9 +89,14 @@ int i2c_isa_add_driver(struct i2c_driver *driver)
89 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name); 89 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name);
90 90
91 /* Now look for clients */ 91 /* Now look for clients */
92 driver->attach_adapter(&isa_adapter); 92 res = driver->attach_adapter(&isa_adapter);
93 93 if (res) {
94 return 0; 94 dev_err(&isa_adapter.dev,
95 "Driver %s failed to attach adapter, unregistering\n",
96 driver->driver.name);
97 driver_unregister(&driver->driver);
98 }
99 return res;
95} 100}
96 101
97int i2c_isa_del_driver(struct i2c_driver *driver) 102int i2c_isa_del_driver(struct i2c_driver *driver)
@@ -125,6 +130,8 @@ int i2c_isa_del_driver(struct i2c_driver *driver)
125 130
126static int __init i2c_isa_init(void) 131static int __init i2c_isa_init(void)
127{ 132{
133 int err;
134
128 mutex_init(&isa_adapter.clist_lock); 135 mutex_init(&isa_adapter.clist_lock);
129 INIT_LIST_HEAD(&isa_adapter.clients); 136 INIT_LIST_HEAD(&isa_adapter.clients);
130 137
@@ -133,8 +140,16 @@ static int __init i2c_isa_init(void)
133 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); 140 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
134 isa_adapter.dev.driver = &i2c_adapter_driver; 141 isa_adapter.dev.driver = &i2c_adapter_driver;
135 isa_adapter.dev.release = &i2c_adapter_dev_release; 142 isa_adapter.dev.release = &i2c_adapter_dev_release;
136 device_register(&isa_adapter.dev); 143 err = device_register(&isa_adapter.dev);
137 device_create_file(&isa_adapter.dev, &dev_attr_name); 144 if (err) {
145 printk(KERN_ERR "i2c-isa: Failed to register device\n");
146 goto exit;
147 }
148 err = device_create_file(&isa_adapter.dev, &dev_attr_name);
149 if (err) {
150 printk(KERN_ERR "i2c-isa: Failed to create name file\n");
151 goto exit_unregister;
152 }
138 153
139 /* Add this adapter to the i2c_adapter class */ 154 /* Add this adapter to the i2c_adapter class */
140 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device)); 155 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
@@ -142,11 +157,24 @@ static int __init i2c_isa_init(void)
142 isa_adapter.class_dev.class = &i2c_adapter_class; 157 isa_adapter.class_dev.class = &i2c_adapter_class;
143 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id, 158 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
144 BUS_ID_SIZE); 159 BUS_ID_SIZE);
145 class_device_register(&isa_adapter.class_dev); 160 err = class_device_register(&isa_adapter.class_dev);
161 if (err) {
162 printk(KERN_ERR "i2c-isa: Failed to register class device\n");
163 goto exit_remove_name;
164 }
146 165
147 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 166 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
148 167
149 return 0; 168 return 0;
169
170exit_remove_name:
171 device_remove_file(&isa_adapter.dev, &dev_attr_name);
172exit_unregister:
173 init_completion(&isa_adapter.dev_released); /* Needed? */
174 device_unregister(&isa_adapter.dev);
175 wait_for_completion(&isa_adapter.dev_released);
176exit:
177 return err;
150} 178}
151 179
152static void __exit i2c_isa_exit(void) 180static void __exit i2c_isa_exit(void)
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index cd6f45d186ab..dd3f4cd3aa68 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -114,7 +114,6 @@ static int ixp2000_i2c_probe(struct platform_device *plat_dev)
114 drv_data->algo_data.getsda = ixp2000_bit_getsda; 114 drv_data->algo_data.getsda = ixp2000_bit_getsda;
115 drv_data->algo_data.getscl = ixp2000_bit_getscl; 115 drv_data->algo_data.getscl = ixp2000_bit_getscl;
116 drv_data->algo_data.udelay = 6; 116 drv_data->algo_data.udelay = 6;
117 drv_data->algo_data.mdelay = 6;
118 drv_data->algo_data.timeout = 100; 117 drv_data->algo_data.timeout = 100;
119 118
120 drv_data->adapter.id = I2C_HW_B_IXP2000, 119 drv_data->adapter.id = I2C_HW_B_IXP2000,
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index 2ed07112d683..ab573254a8aa 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -122,7 +122,6 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
122 drv_data->algo_data.getsda = ixp4xx_bit_getsda; 122 drv_data->algo_data.getsda = ixp4xx_bit_getsda;
123 drv_data->algo_data.getscl = ixp4xx_bit_getscl; 123 drv_data->algo_data.getscl = ixp4xx_bit_getscl;
124 drv_data->algo_data.udelay = 10; 124 drv_data->algo_data.udelay = 10;
125 drv_data->algo_data.mdelay = 10;
126 drv_data->algo_data.timeout = 100; 125 drv_data->algo_data.timeout = 100;
127 126
128 drv_data->adapter.id = I2C_HW_B_IXP4XX; 127 drv_data->adapter.id = I2C_HW_B_IXP4XX;
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 377ab40944b8..155a986de516 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -272,7 +272,7 @@ static u32 mpc_functionality(struct i2c_adapter *adap)
272 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 272 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
273} 273}
274 274
275static struct i2c_algorithm mpc_algo = { 275static const struct i2c_algorithm mpc_algo = {
276 .master_xfer = mpc_xfer, 276 .master_xfer = mpc_xfer,
277 .functionality = mpc_functionality, 277 .functionality = mpc_functionality,
278}; 278};
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index ac5cde1bbd2b..eacbaf745b64 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -431,7 +431,7 @@ mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
431 return num; 431 return num;
432} 432}
433 433
434static struct i2c_algorithm mv64xxx_i2c_algo = { 434static const struct i2c_algorithm mv64xxx_i2c_algo = {
435 .master_xfer = mv64xxx_i2c_xfer, 435 .master_xfer = mv64xxx_i2c_xfer,
436 .functionality = mv64xxx_i2c_functionality, 436 .functionality = mv64xxx_i2c_functionality,
437}; 437};
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 604b49e22df1..e0292e414ab2 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -109,7 +109,7 @@ static s32 nforce2_access(struct i2c_adapter *adap, u16 addr,
109static u32 nforce2_func(struct i2c_adapter *adapter); 109static u32 nforce2_func(struct i2c_adapter *adapter);
110 110
111 111
112static struct i2c_algorithm smbus_algorithm = { 112static const struct i2c_algorithm smbus_algorithm = {
113 .smbus_xfer = nforce2_access, 113 .smbus_xfer = nforce2_access,
114 .functionality = nforce2_func, 114 .functionality = nforce2_func,
115}; 115};
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 592824087c49..952a28d485ce 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -199,7 +199,7 @@ static u32 ocores_func(struct i2c_adapter *adap)
199 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 199 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
200} 200}
201 201
202static struct i2c_algorithm ocores_algorithm = { 202static const struct i2c_algorithm ocores_algorithm = {
203 .master_xfer = ocores_xfer, 203 .master_xfer = ocores_xfer,
204 .functionality = ocores_func, 204 .functionality = ocores_func,
205}; 205};
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
new file mode 100644
index 000000000000..81d87d2c2a2d
--- /dev/null
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -0,0 +1,676 @@
1/*
2 * TI OMAP I2C master mode driver
3 *
4 * Copyright (C) 2003 MontaVista Software, Inc.
5 * Copyright (C) 2004 Texas Instruments.
6 *
7 * Updated to work with multiple I2C interfaces on 24xx by
8 * Tony Lindgren <tony@atomide.com> and Imre Deak <imre.deak@nokia.com>
9 * Copyright (C) 2005 Nokia Corporation
10 *
11 * Cleaned up by Juha Yrjölä <juha.yrjola@nokia.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#include <linux/module.h>
29#include <linux/delay.h>
30#include <linux/i2c.h>
31#include <linux/err.h>
32#include <linux/interrupt.h>
33#include <linux/completion.h>
34#include <linux/platform_device.h>
35#include <linux/clk.h>
36
37#include <asm/io.h>
38
39/* timeout waiting for the controller to respond */
40#define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
41
42#define OMAP_I2C_REV_REG 0x00
43#define OMAP_I2C_IE_REG 0x04
44#define OMAP_I2C_STAT_REG 0x08
45#define OMAP_I2C_IV_REG 0x0c
46#define OMAP_I2C_SYSS_REG 0x10
47#define OMAP_I2C_BUF_REG 0x14
48#define OMAP_I2C_CNT_REG 0x18
49#define OMAP_I2C_DATA_REG 0x1c
50#define OMAP_I2C_SYSC_REG 0x20
51#define OMAP_I2C_CON_REG 0x24
52#define OMAP_I2C_OA_REG 0x28
53#define OMAP_I2C_SA_REG 0x2c
54#define OMAP_I2C_PSC_REG 0x30
55#define OMAP_I2C_SCLL_REG 0x34
56#define OMAP_I2C_SCLH_REG 0x38
57#define OMAP_I2C_SYSTEST_REG 0x3c
58
59/* I2C Interrupt Enable Register (OMAP_I2C_IE): */
60#define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */
61#define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */
62#define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */
63#define OMAP_I2C_IE_NACK (1 << 1) /* No ack interrupt enable */
64#define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */
65
66/* I2C Status Register (OMAP_I2C_STAT): */
67#define OMAP_I2C_STAT_SBD (1 << 15) /* Single byte data */
68#define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */
69#define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */
70#define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */
71#define OMAP_I2C_STAT_AAS (1 << 9) /* Address as slave */
72#define OMAP_I2C_STAT_AD0 (1 << 8) /* Address zero */
73#define OMAP_I2C_STAT_XRDY (1 << 4) /* Transmit data ready */
74#define OMAP_I2C_STAT_RRDY (1 << 3) /* Receive data ready */
75#define OMAP_I2C_STAT_ARDY (1 << 2) /* Register access ready */
76#define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */
77#define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */
78
79/* I2C Buffer Configuration Register (OMAP_I2C_BUF): */
80#define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */
81#define OMAP_I2C_BUF_XDMA_EN (1 << 7) /* TX DMA channel enable */
82
83/* I2C Configuration Register (OMAP_I2C_CON): */
84#define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */
85#define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */
86#define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */
87#define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */
88#define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */
89#define OMAP_I2C_CON_XA (1 << 8) /* Expand address */
90#define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */
91#define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */
92#define OMAP_I2C_CON_STT (1 << 0) /* Start condition (master) */
93
94/* I2C System Test Register (OMAP_I2C_SYSTEST): */
95#ifdef DEBUG
96#define OMAP_I2C_SYSTEST_ST_EN (1 << 15) /* System test enable */
97#define OMAP_I2C_SYSTEST_FREE (1 << 14) /* Free running mode */
98#define OMAP_I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */
99#define OMAP_I2C_SYSTEST_TMODE_SHIFT (12) /* Test mode select */
100#define OMAP_I2C_SYSTEST_SCL_I (1 << 3) /* SCL line sense in */
101#define OMAP_I2C_SYSTEST_SCL_O (1 << 2) /* SCL line drive out */
102#define OMAP_I2C_SYSTEST_SDA_I (1 << 1) /* SDA line sense in */
103#define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */
104#endif
105
106/* I2C System Status register (OMAP_I2C_SYSS): */
107#define OMAP_I2C_SYSS_RDONE (1 << 0) /* Reset Done */
108
109/* I2C System Configuration Register (OMAP_I2C_SYSC): */
110#define OMAP_I2C_SYSC_SRST (1 << 1) /* Soft Reset */
111
112/* REVISIT: Use platform_data instead of module parameters */
113/* Fast Mode = 400 kHz, Standard = 100 kHz */
114static int clock = 100; /* Default: 100 kHz */
115module_param(clock, int, 0);
116MODULE_PARM_DESC(clock, "Set I2C clock in kHz: 400=fast mode (default == 100)");
117
118struct omap_i2c_dev {
119 struct device *dev;
120 void __iomem *base; /* virtual */
121 int irq;
122 struct clk *iclk; /* Interface clock */
123 struct clk *fclk; /* Functional clock */
124 struct completion cmd_complete;
125 struct resource *ioarea;
126 u16 cmd_err;
127 u8 *buf;
128 size_t buf_len;
129 struct i2c_adapter adapter;
130 unsigned rev1:1;
131};
132
133static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev,
134 int reg, u16 val)
135{
136 __raw_writew(val, i2c_dev->base + reg);
137}
138
139static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg)
140{
141 return __raw_readw(i2c_dev->base + reg);
142}
143
144static int omap_i2c_get_clocks(struct omap_i2c_dev *dev)
145{
146 if (cpu_is_omap16xx() || cpu_is_omap24xx()) {
147 dev->iclk = clk_get(dev->dev, "i2c_ick");
148 if (IS_ERR(dev->iclk)) {
149 dev->iclk = NULL;
150 return -ENODEV;
151 }
152 }
153
154 dev->fclk = clk_get(dev->dev, "i2c_fck");
155 if (IS_ERR(dev->fclk)) {
156 if (dev->iclk != NULL) {
157 clk_put(dev->iclk);
158 dev->iclk = NULL;
159 }
160 dev->fclk = NULL;
161 return -ENODEV;
162 }
163
164 return 0;
165}
166
167static void omap_i2c_put_clocks(struct omap_i2c_dev *dev)
168{
169 clk_put(dev->fclk);
170 dev->fclk = NULL;
171 if (dev->iclk != NULL) {
172 clk_put(dev->iclk);
173 dev->iclk = NULL;
174 }
175}
176
177static void omap_i2c_enable_clocks(struct omap_i2c_dev *dev)
178{
179 if (dev->iclk != NULL)
180 clk_enable(dev->iclk);
181 clk_enable(dev->fclk);
182}
183
184static void omap_i2c_disable_clocks(struct omap_i2c_dev *dev)
185{
186 if (dev->iclk != NULL)
187 clk_disable(dev->iclk);
188 clk_disable(dev->fclk);
189}
190
191static int omap_i2c_init(struct omap_i2c_dev *dev)
192{
193 u16 psc = 0;
194 unsigned long fclk_rate = 12000000;
195 unsigned long timeout;
196
197 if (!dev->rev1) {
198 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST);
199 /* For some reason we need to set the EN bit before the
200 * reset done bit gets set. */
201 timeout = jiffies + OMAP_I2C_TIMEOUT;
202 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
203 while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) &
204 OMAP_I2C_SYSS_RDONE)) {
205 if (time_after(jiffies, timeout)) {
206 dev_warn(dev->dev, "timeout waiting"
207 "for controller reset\n");
208 return -ETIMEDOUT;
209 }
210 msleep(1);
211 }
212 }
213 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
214
215 if (cpu_class_is_omap1()) {
216 struct clk *armxor_ck;
217
218 armxor_ck = clk_get(NULL, "armxor_ck");
219 if (IS_ERR(armxor_ck))
220 dev_warn(dev->dev, "Could not get armxor_ck\n");
221 else {
222 fclk_rate = clk_get_rate(armxor_ck);
223 clk_put(armxor_ck);
224 }
225 /* TRM for 5912 says the I2C clock must be prescaled to be
226 * between 7 - 12 MHz. The XOR input clock is typically
227 * 12, 13 or 19.2 MHz. So we should have code that produces:
228 *
229 * XOR MHz Divider Prescaler
230 * 12 1 0
231 * 13 2 1
232 * 19.2 2 1
233 */
234 if (fclk_rate > 16000000)
235 psc = (fclk_rate + 8000000) / 12000000;
236 }
237
238 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */
239 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, psc);
240
241 /* Program desired operating rate */
242 fclk_rate /= (psc + 1) * 1000;
243 if (psc > 2)
244 psc = 2;
245
246 omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG,
247 fclk_rate / (clock * 2) - 7 + psc);
248 omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG,
249 fclk_rate / (clock * 2) - 7 + psc);
250
251 /* Take the I2C module out of reset: */
252 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
253
254 /* Enable interrupts */
255 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG,
256 (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
257 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
258 OMAP_I2C_IE_AL));
259 return 0;
260}
261
262/*
263 * Waiting on Bus Busy
264 */
265static int omap_i2c_wait_for_bb(struct omap_i2c_dev *dev)
266{
267 unsigned long timeout;
268
269 timeout = jiffies + OMAP_I2C_TIMEOUT;
270 while (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) {
271 if (time_after(jiffies, timeout)) {
272 dev_warn(dev->dev, "timeout waiting for bus ready\n");
273 return -ETIMEDOUT;
274 }
275 msleep(1);
276 }
277
278 return 0;
279}
280
281/*
282 * Low level master read/write transaction.
283 */
284static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
285 struct i2c_msg *msg, int stop)
286{
287 struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
288 int r;
289 u16 w;
290
291 dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n",
292 msg->addr, msg->len, msg->flags, stop);
293
294 if (msg->len == 0)
295 return -EINVAL;
296
297 omap_i2c_write_reg(dev, OMAP_I2C_SA_REG, msg->addr);
298
299 /* REVISIT: Could the STB bit of I2C_CON be used with probing? */
300 dev->buf = msg->buf;
301 dev->buf_len = msg->len;
302
303 omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len);
304
305 init_completion(&dev->cmd_complete);
306 dev->cmd_err = 0;
307
308 w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT;
309 if (msg->flags & I2C_M_TEN)
310 w |= OMAP_I2C_CON_XA;
311 if (!(msg->flags & I2C_M_RD))
312 w |= OMAP_I2C_CON_TRX;
313 if (stop)
314 w |= OMAP_I2C_CON_STP;
315 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
316
317 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
318 OMAP_I2C_TIMEOUT);
319 dev->buf_len = 0;
320 if (r < 0)
321 return r;
322 if (r == 0) {
323 dev_err(dev->dev, "controller timed out\n");
324 omap_i2c_init(dev);
325 return -ETIMEDOUT;
326 }
327
328 if (likely(!dev->cmd_err))
329 return 0;
330
331 /* We have an error */
332 if (dev->cmd_err & (OMAP_I2C_STAT_AL | OMAP_I2C_STAT_ROVR |
333 OMAP_I2C_STAT_XUDF)) {
334 omap_i2c_init(dev);
335 return -EIO;
336 }
337
338 if (dev->cmd_err & OMAP_I2C_STAT_NACK) {
339 if (msg->flags & I2C_M_IGNORE_NAK)
340 return 0;
341 if (stop) {
342 w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
343 w |= OMAP_I2C_CON_STP;
344 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
345 }
346 return -EREMOTEIO;
347 }
348 return -EIO;
349}
350
351
352/*
353 * Prepare controller for a transaction and call omap_i2c_xfer_msg
354 * to do the work during IRQ processing.
355 */
356static int
357omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
358{
359 struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
360 int i;
361 int r;
362
363 omap_i2c_enable_clocks(dev);
364
365 /* REVISIT: initialize and use adap->retries. This is an optional
366 * feature */
367 if ((r = omap_i2c_wait_for_bb(dev)) < 0)
368 goto out;
369
370 for (i = 0; i < num; i++) {
371 r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1)));
372 if (r != 0)
373 break;
374 }
375
376 if (r == 0)
377 r = num;
378out:
379 omap_i2c_disable_clocks(dev);
380 return r;
381}
382
383static u32
384omap_i2c_func(struct i2c_adapter *adap)
385{
386 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
387}
388
389static inline void
390omap_i2c_complete_cmd(struct omap_i2c_dev *dev, u16 err)
391{
392 dev->cmd_err |= err;
393 complete(&dev->cmd_complete);
394}
395
396static inline void
397omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat)
398{
399 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
400}
401
402static irqreturn_t
403omap_i2c_rev1_isr(int this_irq, void *dev_id, struct pt_regs *regs)
404{
405 struct omap_i2c_dev *dev = dev_id;
406 u16 iv, w;
407
408 iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG);
409 switch (iv) {
410 case 0x00: /* None */
411 break;
412 case 0x01: /* Arbitration lost */
413 dev_err(dev->dev, "Arbitration lost\n");
414 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL);
415 break;
416 case 0x02: /* No acknowledgement */
417 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK);
418 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_STP);
419 break;
420 case 0x03: /* Register access ready */
421 omap_i2c_complete_cmd(dev, 0);
422 break;
423 case 0x04: /* Receive data ready */
424 if (dev->buf_len) {
425 w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG);
426 *dev->buf++ = w;
427 dev->buf_len--;
428 if (dev->buf_len) {
429 *dev->buf++ = w >> 8;
430 dev->buf_len--;
431 }
432 } else
433 dev_err(dev->dev, "RRDY IRQ while no data requested\n");
434 break;
435 case 0x05: /* Transmit data ready */
436 if (dev->buf_len) {
437 w = *dev->buf++;
438 dev->buf_len--;
439 if (dev->buf_len) {
440 w |= *dev->buf++ << 8;
441 dev->buf_len--;
442 }
443 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
444 } else
445 dev_err(dev->dev, "XRDY IRQ while no data to send\n");
446 break;
447 default:
448 return IRQ_NONE;
449 }
450
451 return IRQ_HANDLED;
452}
453
454static irqreturn_t
455omap_i2c_isr(int this_irq, void *dev_id, struct pt_regs *regs)
456{
457 struct omap_i2c_dev *dev = dev_id;
458 u16 bits;
459 u16 stat, w;
460 int count = 0;
461
462 bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
463 while ((stat = (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG))) & bits) {
464 dev_dbg(dev->dev, "IRQ (ISR = 0x%04x)\n", stat);
465 if (count++ == 100) {
466 dev_warn(dev->dev, "Too much work in one IRQ\n");
467 break;
468 }
469
470 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
471
472 if (stat & OMAP_I2C_STAT_ARDY) {
473 omap_i2c_complete_cmd(dev, 0);
474 continue;
475 }
476 if (stat & OMAP_I2C_STAT_RRDY) {
477 w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG);
478 if (dev->buf_len) {
479 *dev->buf++ = w;
480 dev->buf_len--;
481 if (dev->buf_len) {
482 *dev->buf++ = w >> 8;
483 dev->buf_len--;
484 }
485 } else
486 dev_err(dev->dev, "RRDY IRQ while no data"
487 "requested\n");
488 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY);
489 continue;
490 }
491 if (stat & OMAP_I2C_STAT_XRDY) {
492 w = 0;
493 if (dev->buf_len) {
494 w = *dev->buf++;
495 dev->buf_len--;
496 if (dev->buf_len) {
497 w |= *dev->buf++ << 8;
498 dev->buf_len--;
499 }
500 } else
501 dev_err(dev->dev, "XRDY IRQ while no"
502 "data to send\n");
503 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
504 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY);
505 continue;
506 }
507 if (stat & OMAP_I2C_STAT_ROVR) {
508 dev_err(dev->dev, "Receive overrun\n");
509 dev->cmd_err |= OMAP_I2C_STAT_ROVR;
510 }
511 if (stat & OMAP_I2C_STAT_XUDF) {
512 dev_err(dev->dev, "Transmit overflow\n");
513 dev->cmd_err |= OMAP_I2C_STAT_XUDF;
514 }
515 if (stat & OMAP_I2C_STAT_NACK) {
516 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK);
517 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG,
518 OMAP_I2C_CON_STP);
519 }
520 if (stat & OMAP_I2C_STAT_AL) {
521 dev_err(dev->dev, "Arbitration lost\n");
522 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL);
523 }
524 }
525
526 return count ? IRQ_HANDLED : IRQ_NONE;
527}
528
529static const struct i2c_algorithm omap_i2c_algo = {
530 .master_xfer = omap_i2c_xfer,
531 .functionality = omap_i2c_func,
532};
533
534static int
535omap_i2c_probe(struct platform_device *pdev)
536{
537 struct omap_i2c_dev *dev;
538 struct i2c_adapter *adap;
539 struct resource *mem, *irq, *ioarea;
540 int r;
541
542 /* NOTE: driver uses the static register mapping */
543 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
544 if (!mem) {
545 dev_err(&pdev->dev, "no mem resource?\n");
546 return -ENODEV;
547 }
548 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
549 if (!irq) {
550 dev_err(&pdev->dev, "no irq resource?\n");
551 return -ENODEV;
552 }
553
554 ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1,
555 pdev->name);
556 if (!ioarea) {
557 dev_err(&pdev->dev, "I2C region already claimed\n");
558 return -EBUSY;
559 }
560
561 if (clock > 200)
562 clock = 400; /* Fast mode */
563 else
564 clock = 100; /* Standard mode */
565
566 dev = kzalloc(sizeof(struct omap_i2c_dev), GFP_KERNEL);
567 if (!dev) {
568 r = -ENOMEM;
569 goto err_release_region;
570 }
571
572 dev->dev = &pdev->dev;
573 dev->irq = irq->start;
574 dev->base = (void __iomem *) IO_ADDRESS(mem->start);
575 platform_set_drvdata(pdev, dev);
576
577 if ((r = omap_i2c_get_clocks(dev)) != 0)
578 goto err_free_mem;
579
580 omap_i2c_enable_clocks(dev);
581
582 if (cpu_is_omap15xx())
583 dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20;
584
585 /* reset ASAP, clearing any IRQs */
586 omap_i2c_init(dev);
587
588 r = request_irq(dev->irq, dev->rev1 ? omap_i2c_rev1_isr : omap_i2c_isr,
589 0, pdev->name, dev);
590
591 if (r) {
592 dev_err(dev->dev, "failure requesting irq %i\n", dev->irq);
593 goto err_unuse_clocks;
594 }
595 r = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
596 dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n",
597 pdev->id, r >> 4, r & 0xf, clock);
598
599 adap = &dev->adapter;
600 i2c_set_adapdata(adap, dev);
601 adap->owner = THIS_MODULE;
602 adap->class = I2C_CLASS_HWMON;
603 strncpy(adap->name, "OMAP I2C adapter", sizeof(adap->name));
604 adap->algo = &omap_i2c_algo;
605 adap->dev.parent = &pdev->dev;
606
607 /* i2c device drivers may be active on return from add_adapter() */
608 r = i2c_add_adapter(adap);
609 if (r) {
610 dev_err(dev->dev, "failure adding adapter\n");
611 goto err_free_irq;
612 }
613
614 omap_i2c_disable_clocks(dev);
615
616 return 0;
617
618err_free_irq:
619 free_irq(dev->irq, dev);
620err_unuse_clocks:
621 omap_i2c_disable_clocks(dev);
622 omap_i2c_put_clocks(dev);
623err_free_mem:
624 platform_set_drvdata(pdev, NULL);
625 kfree(dev);
626err_release_region:
627 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
628 release_mem_region(mem->start, (mem->end - mem->start) + 1);
629
630 return r;
631}
632
633static int
634omap_i2c_remove(struct platform_device *pdev)
635{
636 struct omap_i2c_dev *dev = platform_get_drvdata(pdev);
637 struct resource *mem;
638
639 platform_set_drvdata(pdev, NULL);
640
641 free_irq(dev->irq, dev);
642 i2c_del_adapter(&dev->adapter);
643 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
644 omap_i2c_put_clocks(dev);
645 kfree(dev);
646 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
647 release_mem_region(mem->start, (mem->end - mem->start) + 1);
648 return 0;
649}
650
651static struct platform_driver omap_i2c_driver = {
652 .probe = omap_i2c_probe,
653 .remove = omap_i2c_remove,
654 .driver = {
655 .name = "i2c_omap",
656 .owner = THIS_MODULE,
657 },
658};
659
660/* I2C may be needed to bring up other drivers */
661static int __init
662omap_i2c_init_driver(void)
663{
664 return platform_driver_register(&omap_i2c_driver);
665}
666subsys_initcall(omap_i2c_init_driver);
667
668static void __exit omap_i2c_exit_driver(void)
669{
670 platform_driver_unregister(&omap_i2c_driver);
671}
672module_exit(omap_i2c_exit_driver);
673
674MODULE_AUTHOR("MontaVista Software, Inc. (and others)");
675MODULE_DESCRIPTION("TI OMAP I2C bus adapter");
676MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index e09ebbb2f9f0..5eb2bd294fd9 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -103,7 +103,6 @@ static struct i2c_algo_bit_data parport_algo_data = {
103 .getsda = parport_getsda, 103 .getsda = parport_getsda,
104 .getscl = parport_getscl, 104 .getscl = parport_getscl,
105 .udelay = 50, 105 .udelay = 50,
106 .mdelay = 50,
107 .timeout = HZ, 106 .timeout = HZ,
108}; 107};
109 108
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 934bd55bae15..48a829431c7b 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -138,7 +138,6 @@ static struct i2c_algo_bit_data parport_algo_data = {
138 .getsda = parport_getsda, 138 .getsda = parport_getsda,
139 .getscl = parport_getscl, 139 .getscl = parport_getscl,
140 .udelay = 60, 140 .udelay = 60,
141 .mdelay = 60,
142 .timeout = HZ, 141 .timeout = HZ,
143}; 142};
144 143
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 8f2f65b793b9..30c7a1b38cbd 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -376,7 +376,7 @@ static u32 piix4_func(struct i2c_adapter *adapter)
376 I2C_FUNC_SMBUS_BLOCK_DATA; 376 I2C_FUNC_SMBUS_BLOCK_DATA;
377} 377}
378 378
379static struct i2c_algorithm smbus_algorithm = { 379static const struct i2c_algorithm smbus_algorithm = {
380 .smbus_xfer = piix4_access, 380 .smbus_xfer = piix4_access,
381 .functionality = piix4_func, 381 .functionality = piix4_func,
382}; 382};
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index d658d9107955..a508cb962d24 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -175,7 +175,7 @@ static u32 i2c_powermac_func(struct i2c_adapter * adapter)
175} 175}
176 176
177/* For now, we only handle smbus */ 177/* For now, we only handle smbus */
178static struct i2c_algorithm i2c_powermac_algorithm = { 178static const struct i2c_algorithm i2c_powermac_algorithm = {
179 .smbus_xfer = i2c_powermac_smbus_xfer, 179 .smbus_xfer = i2c_powermac_smbus_xfer,
180 .master_xfer = i2c_powermac_master_xfer, 180 .master_xfer = i2c_powermac_master_xfer,
181 .functionality = i2c_powermac_func, 181 .functionality = i2c_powermac_func,
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c
index 9479525892e3..7745e21874a8 100644
--- a/drivers/i2c/busses/i2c-prosavage.c
+++ b/drivers/i2c/busses/i2c-prosavage.c
@@ -180,7 +180,6 @@ static int i2c_register_bus(struct pci_dev *dev, struct s_i2c_bus *p, void __iom
180 p->algo.getsda = bit_s3via_getsda; 180 p->algo.getsda = bit_s3via_getsda;
181 p->algo.getscl = bit_s3via_getscl; 181 p->algo.getscl = bit_s3via_getscl;
182 p->algo.udelay = CYCLE_DELAY; 182 p->algo.udelay = CYCLE_DELAY;
183 p->algo.mdelay = CYCLE_DELAY;
184 p->algo.timeout = TIMEOUT; 183 p->algo.timeout = TIMEOUT;
185 p->algo.data = p; 184 p->algo.data = p;
186 p->mmvga = mmvga; 185 p->mmvga = mmvga;
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index ee114b48face..cd4ad98ad517 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -926,7 +926,7 @@ static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
926 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 926 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
927} 927}
928 928
929static struct i2c_algorithm i2c_pxa_algorithm = { 929static const struct i2c_algorithm i2c_pxa_algorithm = {
930 .master_xfer = i2c_pxa_xfer, 930 .master_xfer = i2c_pxa_xfer,
931 .functionality = i2c_pxa_functionality, 931 .functionality = i2c_pxa_functionality,
932}; 932};
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 5d2950e91fc5..9ebe429a0a0f 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -566,7 +566,7 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
566 566
567/* i2c bus registration info */ 567/* i2c bus registration info */
568 568
569static struct i2c_algorithm s3c24xx_i2c_algorithm = { 569static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
570 .master_xfer = s3c24xx_i2c_xfer, 570 .master_xfer = s3c24xx_i2c_xfer,
571 .functionality = s3c24xx_i2c_func, 571 .functionality = s3c24xx_i2c_func,
572}; 572};
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
index 0c8518298e4d..209f47ea1750 100644
--- a/drivers/i2c/busses/i2c-savage4.c
+++ b/drivers/i2c/busses/i2c-savage4.c
@@ -140,7 +140,6 @@ static struct i2c_algo_bit_data sav_i2c_bit_data = {
140 .getsda = bit_savi2c_getsda, 140 .getsda = bit_savi2c_getsda,
141 .getscl = bit_savi2c_getscl, 141 .getscl = bit_savi2c_getscl,
142 .udelay = CYCLE_DELAY, 142 .udelay = CYCLE_DELAY,
143 .mdelay = CYCLE_DELAY,
144 .timeout = TIMEOUT 143 .timeout = TIMEOUT
145}; 144};
146 145
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c
index fa503ed9f86d..8f2b1f0deb81 100644
--- a/drivers/i2c/busses/i2c-sibyte.c
+++ b/drivers/i2c/busses/i2c-sibyte.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Copyright (C) 2004 Steven J. Hill 2 * Copyright (C) 2004 Steven J. Hill
3 * Copyright (C) 2001,2002,2003 Broadcom Corporation 3 * Copyright (C) 2001,2002,2003 Broadcom Corporation
4 * Copyright (C) 1995-2000 Simon G. Vogl
4 * 5 *
5 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
@@ -17,11 +18,162 @@
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */ 19 */
19 20
21#include <linux/kernel.h>
20#include <linux/module.h> 22#include <linux/module.h>
21#include <linux/i2c-algo-sibyte.h> 23#include <linux/init.h>
24#include <linux/i2c.h>
25#include <asm/io.h>
22#include <asm/sibyte/sb1250_regs.h> 26#include <asm/sibyte/sb1250_regs.h>
23#include <asm/sibyte/sb1250_smbus.h> 27#include <asm/sibyte/sb1250_smbus.h>
24 28
29
30struct i2c_algo_sibyte_data {
31 void *data; /* private data */
32 int bus; /* which bus */
33 void *reg_base; /* CSR base */
34};
35
36/* ----- global defines ----------------------------------------------- */
37#define SMB_CSR(a,r) ((long)(a->reg_base + r))
38
39/* ----- global variables --------------------------------------------- */
40
41/* module parameters:
42 */
43static int bit_scan; /* have a look at what's hanging 'round */
44module_param(bit_scan, int, 0);
45MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
46
47
48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
49 unsigned short flags, char read_write,
50 u8 command, int size, union i2c_smbus_data * data)
51{
52 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
53 int data_bytes = 0;
54 int error;
55
56 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
57 ;
58
59 switch (size) {
60 case I2C_SMBUS_QUICK:
61 csr_out32((V_SMB_ADDR(addr) |
62 (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) |
63 V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START));
64 break;
65 case I2C_SMBUS_BYTE:
66 if (read_write == I2C_SMBUS_READ) {
67 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE),
68 SMB_CSR(adap, R_SMB_START));
69 data_bytes = 1;
70 } else {
71 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
72 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE),
73 SMB_CSR(adap, R_SMB_START));
74 }
75 break;
76 case I2C_SMBUS_BYTE_DATA:
77 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
78 if (read_write == I2C_SMBUS_READ) {
79 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE),
80 SMB_CSR(adap, R_SMB_START));
81 data_bytes = 1;
82 } else {
83 csr_out32(V_SMB_LB(data->byte),
84 SMB_CSR(adap, R_SMB_DATA));
85 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
86 SMB_CSR(adap, R_SMB_START));
87 }
88 break;
89 case I2C_SMBUS_WORD_DATA:
90 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
91 if (read_write == I2C_SMBUS_READ) {
92 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE),
93 SMB_CSR(adap, R_SMB_START));
94 data_bytes = 2;
95 } else {
96 csr_out32(V_SMB_LB(data->word & 0xff),
97 SMB_CSR(adap, R_SMB_DATA));
98 csr_out32(V_SMB_MB(data->word >> 8),
99 SMB_CSR(adap, R_SMB_DATA));
100 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
101 SMB_CSR(adap, R_SMB_START));
102 }
103 break;
104 default:
105 return -1; /* XXXKW better error code? */
106 }
107
108 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
109 ;
110
111 error = csr_in32(SMB_CSR(adap, R_SMB_STATUS));
112 if (error & M_SMB_ERROR) {
113 /* Clear error bit by writing a 1 */
114 csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS));
115 return -1; /* XXXKW better error code? */
116 }
117
118 if (data_bytes == 1)
119 data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff;
120 if (data_bytes == 2)
121 data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff;
122
123 return 0;
124}
125
126static u32 bit_func(struct i2c_adapter *adap)
127{
128 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
129 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA);
130}
131
132
133/* -----exported algorithm data: ------------------------------------- */
134
135static const struct i2c_algorithm i2c_sibyte_algo = {
136 .smbus_xfer = smbus_xfer,
137 .functionality = bit_func,
138};
139
140/*
141 * registering functions to load algorithms at runtime
142 */
143int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
144{
145 int i;
146 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
147
148 /* register new adapter to i2c module... */
149 i2c_adap->algo = &i2c_sibyte_algo;
150
151 /* Set the frequency to 100 kHz */
152 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
153 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));
154
155 /* scan bus */
156 if (bit_scan) {
157 union i2c_smbus_data data;
158 int rc;
159 printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
160 i2c_adap->name);
161 for (i = 0x00; i < 0x7f; i++) {
162 /* XXXKW is this a realistic probe? */
163 rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0,
164 I2C_SMBUS_BYTE_DATA, &data);
165 if (!rc) {
166 printk("(%02x)",i);
167 } else
168 printk(".");
169 }
170 printk("\n");
171 }
172
173 return i2c_add_adapter(i2c_adap);
174}
175
176
25static struct i2c_algo_sibyte_data sibyte_board_data[2] = { 177static struct i2c_algo_sibyte_data sibyte_board_data[2] = {
26 { NULL, 0, (void *) (CKSEG1+A_SMB_BASE(0)) }, 178 { NULL, 0, (void *) (CKSEG1+A_SMB_BASE(0)) },
27 { NULL, 1, (void *) (CKSEG1+A_SMB_BASE(1)) } 179 { NULL, 1, (void *) (CKSEG1+A_SMB_BASE(1)) }
@@ -58,13 +210,13 @@ static int __init i2c_sibyte_init(void)
58 210
59static void __exit i2c_sibyte_exit(void) 211static void __exit i2c_sibyte_exit(void)
60{ 212{
61 i2c_sibyte_del_bus(&sibyte_board_adapter[0]); 213 i2c_del_bus(&sibyte_board_adapter[0]);
62 i2c_sibyte_del_bus(&sibyte_board_adapter[1]); 214 i2c_del_bus(&sibyte_board_adapter[1]);
63} 215}
64 216
65module_init(i2c_sibyte_init); 217module_init(i2c_sibyte_init);
66module_exit(i2c_sibyte_exit); 218module_exit(i2c_sibyte_exit);
67 219
68MODULE_AUTHOR("Kip Walker <kwalker@broadcom.com>, Steven J. Hill <sjhill@realitydiluted.com>"); 220MODULE_AUTHOR("Kip Walker (Broadcom Corp.), Steven J. Hill <sjhill@realitydiluted.com>");
69MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards"); 221MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards");
70MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index b57ab74d23ec..38bbfd840b6b 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -358,7 +358,7 @@ static u32 sis5595_func(struct i2c_adapter *adapter)
358 I2C_FUNC_SMBUS_PROC_CALL; 358 I2C_FUNC_SMBUS_PROC_CALL;
359} 359}
360 360
361static struct i2c_algorithm smbus_algorithm = { 361static const struct i2c_algorithm smbus_algorithm = {
362 .smbus_xfer = sis5595_access, 362 .smbus_xfer = sis5595_access,
363 .functionality = sis5595_func, 363 .functionality = sis5595_func,
364}; 364};
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index acb75e282414..dec0bafb52ab 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -450,7 +450,7 @@ exit:
450} 450}
451 451
452 452
453static struct i2c_algorithm smbus_algorithm = { 453static const struct i2c_algorithm smbus_algorithm = {
454 .smbus_xfer = sis630_access, 454 .smbus_xfer = sis630_access,
455 .functionality = sis630_func, 455 .functionality = sis630_func,
456}; 456};
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 1a73c0532fc7..7fd07fbac336 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -242,7 +242,7 @@ static u32 sis96x_func(struct i2c_adapter *adapter)
242 I2C_FUNC_SMBUS_PROC_CALL; 242 I2C_FUNC_SMBUS_PROC_CALL;
243} 243}
244 244
245static struct i2c_algorithm smbus_algorithm = { 245static const struct i2c_algorithm smbus_algorithm = {
246 .smbus_xfer = sis96x_access, 246 .smbus_xfer = sis96x_access,
247 .functionality = sis96x_func, 247 .functionality = sis96x_func,
248}; 248};
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 73f481e93a36..a54adc50d162 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -27,6 +27,10 @@
27#include <linux/errno.h> 27#include <linux/errno.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29 29
30static unsigned short chip_addr;
31module_param(chip_addr, ushort, S_IRUGO);
32MODULE_PARM_DESC(chip_addr, "Chip address (between 0x03 and 0x77)\n");
33
30static u8 stub_pointer; 34static u8 stub_pointer;
31static u8 stub_bytes[256]; 35static u8 stub_bytes[256];
32static u16 stub_words[256]; 36static u16 stub_words[256];
@@ -37,6 +41,9 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
37{ 41{
38 s32 ret; 42 s32 ret;
39 43
44 if (addr != chip_addr)
45 return -ENODEV;
46
40 switch (size) { 47 switch (size) {
41 48
42 case I2C_SMBUS_QUICK: 49 case I2C_SMBUS_QUICK:
@@ -108,7 +115,7 @@ static u32 stub_func(struct i2c_adapter *adapter)
108 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; 115 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA;
109} 116}
110 117
111static struct i2c_algorithm smbus_algorithm = { 118static const struct i2c_algorithm smbus_algorithm = {
112 .functionality = stub_func, 119 .functionality = stub_func,
113 .smbus_xfer = stub_xfer, 120 .smbus_xfer = stub_xfer,
114}; 121};
@@ -122,7 +129,17 @@ static struct i2c_adapter stub_adapter = {
122 129
123static int __init i2c_stub_init(void) 130static int __init i2c_stub_init(void)
124{ 131{
125 printk(KERN_INFO "i2c-stub loaded\n"); 132 if (!chip_addr) {
133 printk(KERN_ERR "i2c-stub: Please specify a chip address\n");
134 return -ENODEV;
135 }
136 if (chip_addr < 0x03 || chip_addr > 0x77) {
137 printk(KERN_ERR "i2c-stub: Invalid chip address 0x%02x\n",
138 chip_addr);
139 return -EINVAL;
140 }
141
142 printk(KERN_INFO "i2c-stub: Virtual chip at 0x%02x\n", chip_addr);
126 return i2c_add_adapter(&stub_adapter); 143 return i2c_add_adapter(&stub_adapter);
127} 144}
128 145
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 484bbacfce6b..910e200ad500 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -81,7 +81,6 @@ static struct i2c_algo_bit_data bit_data = {
81 .getsda = bit_via_getsda, 81 .getsda = bit_via_getsda,
82 .getscl = bit_via_getscl, 82 .getscl = bit_via_getscl,
83 .udelay = 5, 83 .udelay = 5,
84 .mdelay = 5,
85 .timeout = HZ 84 .timeout = HZ
86}; 85};
87 86
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 47e52bf2c5ec..efc6bbf0cc0a 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -34,6 +34,8 @@
34 VT8233A 0x3147 yes? 34 VT8233A 0x3147 yes?
35 VT8235 0x3177 yes 35 VT8235 0x3177 yes
36 VT8237R 0x3227 yes 36 VT8237R 0x3227 yes
37 VT8237A 0x3337 yes
38 VT8251 0x3287 yes
37 39
38 Note: we assume there can only be one device, with one SMBus interface. 40 Note: we assume there can only be one device, with one SMBus interface.
39*/ 41*/
@@ -297,7 +299,7 @@ static u32 vt596_func(struct i2c_adapter *adapter)
297 return func; 299 return func;
298} 300}
299 301
300static struct i2c_algorithm smbus_algorithm = { 302static const struct i2c_algorithm smbus_algorithm = {
301 .smbus_xfer = vt596_access, 303 .smbus_xfer = vt596_access,
302 .functionality = vt596_func, 304 .functionality = vt596_func,
303}; 305};
@@ -381,7 +383,9 @@ found:
381 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba); 383 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba);
382 384
383 switch (pdev->device) { 385 switch (pdev->device) {
386 case PCI_DEVICE_ID_VIA_8251:
384 case PCI_DEVICE_ID_VIA_8237: 387 case PCI_DEVICE_ID_VIA_8237:
388 case PCI_DEVICE_ID_VIA_8237A:
385 case PCI_DEVICE_ID_VIA_8235: 389 case PCI_DEVICE_ID_VIA_8235:
386 case PCI_DEVICE_ID_VIA_8233A: 390 case PCI_DEVICE_ID_VIA_8233A:
387 case PCI_DEVICE_ID_VIA_8233_0: 391 case PCI_DEVICE_ID_VIA_8233_0:
@@ -432,8 +436,12 @@ static struct pci_device_id vt596_ids[] = {
432 .driver_data = SMBBA3 }, 436 .driver_data = SMBBA3 },
433 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237), 437 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237),
434 .driver_data = SMBBA3 }, 438 .driver_data = SMBBA3 },
439 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A),
440 .driver_data = SMBBA3 },
435 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4), 441 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4),
436 .driver_data = SMBBA1 }, 442 .driver_data = SMBBA1 },
443 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8251),
444 .driver_data = SMBBA3 },
437 { 0, } 445 { 0, }
438}; 446};
439 447
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
index b675773b0cc1..6c8d25183382 100644
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -160,7 +160,6 @@ static struct i2c_algo_bit_data voo_i2c_bit_data = {
160 .getsda = bit_vooi2c_getsda, 160 .getsda = bit_vooi2c_getsda,
161 .getscl = bit_vooi2c_getscl, 161 .getscl = bit_vooi2c_getscl,
162 .udelay = CYCLE_DELAY, 162 .udelay = CYCLE_DELAY,
163 .mdelay = CYCLE_DELAY,
164 .timeout = TIMEOUT 163 .timeout = TIMEOUT
165}; 164};
166 165
@@ -177,7 +176,6 @@ static struct i2c_algo_bit_data voo_ddc_bit_data = {
177 .getsda = bit_vooddc_getsda, 176 .getsda = bit_vooddc_getsda,
178 .getscl = bit_vooddc_getscl, 177 .getscl = bit_vooddc_getscl,
179 .udelay = CYCLE_DELAY, 178 .udelay = CYCLE_DELAY,
180 .mdelay = CYCLE_DELAY,
181 .timeout = TIMEOUT 179 .timeout = TIMEOUT
182}; 180};
183 181
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index eae9e81be375..32aab0d34ee9 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -383,7 +383,7 @@ static u32 scx200_acb_func(struct i2c_adapter *adapter)
383} 383}
384 384
385/* For now, we only handle combined mode (smbus) */ 385/* For now, we only handle combined mode (smbus) */
386static struct i2c_algorithm scx200_acb_algorithm = { 386static const struct i2c_algorithm scx200_acb_algorithm = {
387 .smbus_xfer = scx200_acb_smbus_xfer, 387 .smbus_xfer = scx200_acb_smbus_xfer,
388 .functionality = scx200_acb_func, 388 .functionality = scx200_acb_func,
389}; 389};
diff --git a/drivers/i2c/busses/scx200_i2c.c b/drivers/i2c/busses/scx200_i2c.c
index cb3ef5ac99fd..8b65a5cf8251 100644
--- a/drivers/i2c/busses/scx200_i2c.c
+++ b/drivers/i2c/busses/scx200_i2c.c
@@ -71,12 +71,12 @@ static int scx200_i2c_getsda(void *data)
71 */ 71 */
72 72
73static struct i2c_algo_bit_data scx200_i2c_data = { 73static struct i2c_algo_bit_data scx200_i2c_data = {
74 NULL, 74 .setsda = scx200_i2c_setsda,
75 scx200_i2c_setsda, 75 .setscl = scx200_i2c_setscl,
76 scx200_i2c_setscl, 76 .getsda = scx200_i2c_getsda,
77 scx200_i2c_getsda, 77 .getscl = scx200_i2c_getscl,
78 scx200_i2c_getscl, 78 .udelay = 10,
79 10, 10, 100, /* waits, timeout */ 79 .timeout = 100,
80}; 80};
81 81
82static struct i2c_adapter scx200_i2c_ops = { 82static struct i2c_adapter scx200_i2c_ops = {
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index 13c108269a6d..cec3a0c3894d 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -209,10 +209,14 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
209 } 209 }
210 210
211 /* create the sysfs eeprom file */ 211 /* create the sysfs eeprom file */
212 sysfs_create_bin_file(&new_client->dev.kobj, &eeprom_attr); 212 err = sysfs_create_bin_file(&new_client->dev.kobj, &eeprom_attr);
213 if (err)
214 goto exit_detach;
213 215
214 return 0; 216 return 0;
215 217
218exit_detach:
219 i2c_detach_client(new_client);
216exit_kfree: 220exit_kfree:
217 kfree(data); 221 kfree(data);
218exit: 222exit:
@@ -223,6 +227,8 @@ static int eeprom_detach_client(struct i2c_client *client)
223{ 227{
224 int err; 228 int err;
225 229
230 sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
231
226 err = i2c_detach_client(client); 232 err = i2c_detach_client(client);
227 if (err) 233 if (err)
228 return err; 234 return err;
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 88d2ddee4490..76645c142977 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -199,8 +199,7 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
199 mutex_init(&data->update_lock); 199 mutex_init(&data->update_lock);
200 200
201 /* Init fake client data */ 201 /* Init fake client data */
202 /* set the client data to the i2c_client so that it will get freed */ 202 i2c_set_clientdata(fake_client, NULL);
203 i2c_set_clientdata(fake_client, fake_client);
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;
@@ -214,13 +213,17 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
214 goto exit_kfree2; 213 goto exit_kfree2;
215 214
216 if ((err = i2c_attach_client(fake_client)) != 0) 215 if ((err = i2c_attach_client(fake_client)) != 0)
217 goto exit_detach; 216 goto exit_detach1;
218 217
219 sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr); 218 err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
219 if (err)
220 goto exit_detach2;
220 221
221 return 0; 222 return 0;
222 223
223exit_detach: 224exit_detach2:
225 i2c_detach_client(fake_client);
226exit_detach1:
224 i2c_detach_client(real_client); 227 i2c_detach_client(real_client);
225exit_kfree2: 228exit_kfree2:
226 kfree(fake_client); 229 kfree(fake_client);
@@ -229,14 +232,24 @@ exit_kfree1:
229 return err; 232 return err;
230} 233}
231 234
235/* Will be called for both the real client and the fake client */
232static int max6875_detach_client(struct i2c_client *client) 236static int max6875_detach_client(struct i2c_client *client)
233{ 237{
234 int err; 238 int err;
239 struct max6875_data *data = i2c_get_clientdata(client);
240
241 /* data is NULL for the fake client */
242 if (data)
243 sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
235 244
236 err = i2c_detach_client(client); 245 err = i2c_detach_client(client);
237 if (err) 246 if (err)
238 return err; 247 return err;
239 kfree(i2c_get_clientdata(client)); 248
249 if (data) /* real client */
250 kfree(data);
251 else /* fake client */
252 kfree(client);
240 return 0; 253 return 0;
241} 254}
242 255
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index cb22280cdd27..f43c4e79b55e 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -148,11 +148,16 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
148 if ((err = i2c_attach_client(new_client))) 148 if ((err = i2c_attach_client(new_client)))
149 goto exit_kfree; 149 goto exit_kfree;
150 150
151 /* Register sysfs hooks (don't care about failure) */ 151 /* Register sysfs hooks */
152 sysfs_create_group(&new_client->dev.kobj, &pca9539_defattr_group); 152 err = sysfs_create_group(&new_client->dev.kobj,
153 &pca9539_defattr_group);
154 if (err)
155 goto exit_detach;
153 156
154 return 0; 157 return 0;
155 158
159exit_detach:
160 i2c_detach_client(new_client);
156exit_kfree: 161exit_kfree:
157 kfree(data); 162 kfree(data);
158exit: 163exit:
@@ -163,6 +168,8 @@ static int pca9539_detach_client(struct i2c_client *client)
163{ 168{
164 int err; 169 int err;
165 170
171 sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group);
172
166 if ((err = i2c_detach_client(client))) 173 if ((err = i2c_detach_client(client)))
167 return err; 174 return err;
168 175
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index c3e6449c4481..32b25427eaba 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -105,6 +105,16 @@ static ssize_t set_write(struct device *dev, struct device_attribute *attr, cons
105 105
106static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); 106static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
107 107
108static struct attribute *pcf8574_attributes[] = {
109 &dev_attr_read.attr,
110 &dev_attr_write.attr,
111 NULL
112};
113
114static const struct attribute_group pcf8574_attr_group = {
115 .attrs = pcf8574_attributes,
116};
117
108/* 118/*
109 * Real code 119 * Real code
110 */ 120 */
@@ -166,13 +176,13 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
166 pcf8574_init_client(new_client); 176 pcf8574_init_client(new_client);
167 177
168 /* Register sysfs hooks */ 178 /* Register sysfs hooks */
169 device_create_file(&new_client->dev, &dev_attr_read); 179 err = sysfs_create_group(&new_client->dev.kobj, &pcf8574_attr_group);
170 device_create_file(&new_client->dev, &dev_attr_write); 180 if (err)
181 goto exit_detach;
171 return 0; 182 return 0;
172 183
173/* OK, this is not exactly good programming practice, usually. But it is 184 exit_detach:
174 very code-efficient in this case. */ 185 i2c_detach_client(new_client);
175
176 exit_free: 186 exit_free:
177 kfree(data); 187 kfree(data);
178 exit: 188 exit:
@@ -183,6 +193,8 @@ static int pcf8574_detach_client(struct i2c_client *client)
183{ 193{
184 int err; 194 int err;
185 195
196 sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
197
186 if ((err = i2c_detach_client(client))) 198 if ((err = i2c_detach_client(client)))
187 return err; 199 return err;
188 200
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 925a6b371fd2..4dc36376eb32 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -158,6 +158,28 @@ static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr
158static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO, 158static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO,
159 show_out0_enable, set_out0_enable); 159 show_out0_enable, set_out0_enable);
160 160
161static struct attribute *pcf8591_attributes[] = {
162 &dev_attr_out0_enable.attr,
163 &dev_attr_out0_output.attr,
164 &dev_attr_in0_input.attr,
165 &dev_attr_in1_input.attr,
166 NULL
167};
168
169static const struct attribute_group pcf8591_attr_group = {
170 .attrs = pcf8591_attributes,
171};
172
173static struct attribute *pcf8591_attributes_opt[] = {
174 &dev_attr_in2_input.attr,
175 &dev_attr_in3_input.attr,
176 NULL
177};
178
179static const struct attribute_group pcf8591_attr_group_opt = {
180 .attrs = pcf8591_attributes_opt,
181};
182
161/* 183/*
162 * Real code 184 * Real code
163 */ 185 */
@@ -211,24 +233,31 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
211 pcf8591_init_client(new_client); 233 pcf8591_init_client(new_client);
212 234
213 /* Register sysfs hooks */ 235 /* Register sysfs hooks */
214 device_create_file(&new_client->dev, &dev_attr_out0_enable); 236 err = sysfs_create_group(&new_client->dev.kobj, &pcf8591_attr_group);
215 device_create_file(&new_client->dev, &dev_attr_out0_output); 237 if (err)
216 device_create_file(&new_client->dev, &dev_attr_in0_input); 238 goto exit_detach;
217 device_create_file(&new_client->dev, &dev_attr_in1_input);
218 239
219 /* Register input2 if not in "two differential inputs" mode */ 240 /* Register input2 if not in "two differential inputs" mode */
220 if (input_mode != 3 ) 241 if (input_mode != 3) {
221 device_create_file(&new_client->dev, &dev_attr_in2_input); 242 if ((err = device_create_file(&new_client->dev,
222 243 &dev_attr_in2_input)))
244 goto exit_sysfs_remove;
245 }
246
223 /* Register input3 only in "four single ended inputs" mode */ 247 /* Register input3 only in "four single ended inputs" mode */
224 if (input_mode == 0) 248 if (input_mode == 0) {
225 device_create_file(&new_client->dev, &dev_attr_in3_input); 249 if ((err = device_create_file(&new_client->dev,
226 250 &dev_attr_in3_input)))
251 goto exit_sysfs_remove;
252 }
253
227 return 0; 254 return 0;
228
229 /* OK, this is not exactly good programming practice, usually. But it is
230 very code-efficient in this case. */
231 255
256exit_sysfs_remove:
257 sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group_opt);
258 sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group);
259exit_detach:
260 i2c_detach_client(new_client);
232exit_kfree: 261exit_kfree:
233 kfree(data); 262 kfree(data);
234exit: 263exit:
@@ -239,6 +268,9 @@ static int pcf8591_detach_client(struct i2c_client *client)
239{ 268{
240 int err; 269 int err;
241 270
271 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt);
272 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group);
273
242 if ((err = i2c_detach_client(client))) 274 if ((err = i2c_detach_client(client)))
243 return err; 275 return err;
244 276
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 9cb277d6aa48..01233f0f7771 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -183,15 +183,21 @@ int i2c_add_adapter(struct i2c_adapter *adap)
183 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); 183 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
184 adap->dev.driver = &i2c_adapter_driver; 184 adap->dev.driver = &i2c_adapter_driver;
185 adap->dev.release = &i2c_adapter_dev_release; 185 adap->dev.release = &i2c_adapter_dev_release;
186 device_register(&adap->dev); 186 res = device_register(&adap->dev);
187 device_create_file(&adap->dev, &dev_attr_name); 187 if (res)
188 goto out_list;
189 res = device_create_file(&adap->dev, &dev_attr_name);
190 if (res)
191 goto out_unregister;
188 192
189 /* Add this adapter to the i2c_adapter class */ 193 /* Add this adapter to the i2c_adapter class */
190 memset(&adap->class_dev, 0x00, sizeof(struct class_device)); 194 memset(&adap->class_dev, 0x00, sizeof(struct class_device));
191 adap->class_dev.dev = &adap->dev; 195 adap->class_dev.dev = &adap->dev;
192 adap->class_dev.class = &i2c_adapter_class; 196 adap->class_dev.class = &i2c_adapter_class;
193 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); 197 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
194 class_device_register(&adap->class_dev); 198 res = class_device_register(&adap->class_dev);
199 if (res)
200 goto out_remove_name;
195 201
196 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 202 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
197 203
@@ -206,6 +212,17 @@ int i2c_add_adapter(struct i2c_adapter *adap)
206out_unlock: 212out_unlock:
207 mutex_unlock(&core_lists); 213 mutex_unlock(&core_lists);
208 return res; 214 return res;
215
216out_remove_name:
217 device_remove_file(&adap->dev, &dev_attr_name);
218out_unregister:
219 init_completion(&adap->dev_released); /* Needed? */
220 device_unregister(&adap->dev);
221 wait_for_completion(&adap->dev_released);
222out_list:
223 list_del(&adap->list);
224 idr_remove(&i2c_adapter_idr, adap->nr);
225 goto out_unlock;
209} 226}
210 227
211 228
@@ -394,14 +411,14 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr)
394int i2c_attach_client(struct i2c_client *client) 411int i2c_attach_client(struct i2c_client *client)
395{ 412{
396 struct i2c_adapter *adapter = client->adapter; 413 struct i2c_adapter *adapter = client->adapter;
414 int res = 0;
397 415
398 mutex_lock(&adapter->clist_lock); 416 mutex_lock(&adapter->clist_lock);
399 if (__i2c_check_addr(client->adapter, client->addr)) { 417 if (__i2c_check_addr(client->adapter, client->addr)) {
400 mutex_unlock(&adapter->clist_lock); 418 res = -EBUSY;
401 return -EBUSY; 419 goto out_unlock;
402 } 420 }
403 list_add_tail(&client->list,&adapter->clients); 421 list_add_tail(&client->list,&adapter->clients);
404 mutex_unlock(&adapter->clist_lock);
405 422
406 if (adapter->client_register) { 423 if (adapter->client_register) {
407 if (adapter->client_register(client)) { 424 if (adapter->client_register(client)) {
@@ -422,10 +439,26 @@ int i2c_attach_client(struct i2c_client *client)
422 "%d-%04x", i2c_adapter_id(adapter), client->addr); 439 "%d-%04x", i2c_adapter_id(adapter), client->addr);
423 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", 440 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
424 client->name, client->dev.bus_id); 441 client->name, client->dev.bus_id);
425 device_register(&client->dev); 442 res = device_register(&client->dev);
426 device_create_file(&client->dev, &dev_attr_client_name); 443 if (res)
427 444 goto out_list;
428 return 0; 445 res = device_create_file(&client->dev, &dev_attr_client_name);
446 if (res)
447 goto out_unregister;
448
449out_unlock:
450 mutex_unlock(&adapter->clist_lock);
451 return res;
452
453out_unregister:
454 init_completion(&client->released); /* Needed? */
455 device_unregister(&client->dev);
456 wait_for_completion(&client->released);
457out_list:
458 list_del(&client->list);
459 dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x "
460 "(%d)\n", client->name, client->addr, res);
461 goto out_unlock;
429} 462}
430 463
431 464
@@ -674,11 +707,16 @@ static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
674 707
675 /* Finally call the custom detection function */ 708 /* Finally call the custom detection function */
676 err = found_proc(adapter, addr, kind); 709 err = found_proc(adapter, addr, kind);
677
678 /* -ENODEV can be returned if there is a chip at the given address 710 /* -ENODEV can be returned if there is a chip at the given address
679 but it isn't supported by this chip driver. We catch it here as 711 but it isn't supported by this chip driver. We catch it here as
680 this isn't an error. */ 712 this isn't an error. */
681 return (err == -ENODEV) ? 0 : err; 713 if (err == -ENODEV)
714 err = 0;
715
716 if (err)
717 dev_warn(&adapter->dev, "Client creation failed at 0x%x (%d)\n",
718 addr, err);
719 return err;
682} 720}
683 721
684int i2c_probe(struct i2c_adapter *adapter, 722int i2c_probe(struct i2c_adapter *adapter,
@@ -868,7 +906,7 @@ s32 i2c_smbus_read_byte(struct i2c_client *client)
868 I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data)) 906 I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data))
869 return -1; 907 return -1;
870 else 908 else
871 return 0x0FF & data.byte; 909 return data.byte;
872} 910}
873 911
874s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 912s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
@@ -884,7 +922,7 @@ s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
884 I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data)) 922 I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data))
885 return -1; 923 return -1;
886 else 924 else
887 return 0x0FF & data.byte; 925 return data.byte;
888} 926}
889 927
890s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) 928s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
@@ -903,7 +941,7 @@ s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
903 I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data)) 941 I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data))
904 return -1; 942 return -1;
905 else 943 else
906 return 0x0FFFF & data.word; 944 return data.word;
907} 945}
908 946
909s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) 947s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
@@ -1006,7 +1044,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1006 else { 1044 else {
1007 msg[0].len=3; 1045 msg[0].len=3;
1008 msgbuf0[1] = data->word & 0xff; 1046 msgbuf0[1] = data->word & 0xff;
1009 msgbuf0[2] = (data->word >> 8) & 0xff; 1047 msgbuf0[2] = data->word >> 8;
1010 } 1048 }
1011 break; 1049 break;
1012 case I2C_SMBUS_PROC_CALL: 1050 case I2C_SMBUS_PROC_CALL:
@@ -1015,7 +1053,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1015 msg[0].len = 3; 1053 msg[0].len = 3;
1016 msg[1].len = 2; 1054 msg[1].len = 2;
1017 msgbuf0[1] = data->word & 0xff; 1055 msgbuf0[1] = data->word & 0xff;
1018 msgbuf0[2] = (data->word >> 8) & 0xff; 1056 msgbuf0[2] = data->word >> 8;
1019 break; 1057 break;
1020 case I2C_SMBUS_BLOCK_DATA: 1058 case I2C_SMBUS_BLOCK_DATA:
1021 if (read_write == I2C_SMBUS_READ) { 1059 if (read_write == I2C_SMBUS_READ) {
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 58ccddd5c237..3f869033ed70 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -32,43 +32,35 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/list.h>
35#include <linux/i2c.h> 36#include <linux/i2c.h>
36#include <linux/i2c-dev.h> 37#include <linux/i2c-dev.h>
37#include <linux/platform_device.h>
38#include <asm/uaccess.h> 38#include <asm/uaccess.h>
39 39
40static struct i2c_client i2cdev_client_template; 40static struct i2c_driver i2cdev_driver;
41 41
42struct i2c_dev { 42struct i2c_dev {
43 int minor; 43 struct list_head list;
44 struct i2c_adapter *adap; 44 struct i2c_adapter *adap;
45 struct class_device *class_dev; 45 struct class_device *class_dev;
46}; 46};
47#define to_i2c_dev(d) container_of(d, struct i2c_dev, class_dev)
48 47
49#define I2C_MINORS 256 48#define I2C_MINORS 256
50static struct i2c_dev *i2c_dev_array[I2C_MINORS]; 49static LIST_HEAD(i2c_dev_list);
51static DEFINE_SPINLOCK(i2c_dev_array_lock); 50static DEFINE_SPINLOCK(i2c_dev_list_lock);
52 51
53static struct i2c_dev *i2c_dev_get_by_minor(unsigned index) 52static struct i2c_dev *i2c_dev_get_by_minor(unsigned index)
54{ 53{
55 struct i2c_dev *i2c_dev; 54 struct i2c_dev *i2c_dev;
56 55
57 spin_lock(&i2c_dev_array_lock); 56 spin_lock(&i2c_dev_list_lock);
58 i2c_dev = i2c_dev_array[index]; 57 list_for_each_entry(i2c_dev, &i2c_dev_list, list) {
59 spin_unlock(&i2c_dev_array_lock); 58 if (i2c_dev->adap->nr == index)
60 return i2c_dev; 59 goto found;
61} 60 }
62 61 i2c_dev = NULL;
63static struct i2c_dev *i2c_dev_get_by_adapter(struct i2c_adapter *adap) 62found:
64{ 63 spin_unlock(&i2c_dev_list_lock);
65 struct i2c_dev *i2c_dev = NULL;
66
67 spin_lock(&i2c_dev_array_lock);
68 if ((i2c_dev_array[adap->nr]) &&
69 (i2c_dev_array[adap->nr]->adap == adap))
70 i2c_dev = i2c_dev_array[adap->nr];
71 spin_unlock(&i2c_dev_array_lock);
72 return i2c_dev; 64 return i2c_dev;
73} 65}
74 66
@@ -76,30 +68,28 @@ static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
76{ 68{
77 struct i2c_dev *i2c_dev; 69 struct i2c_dev *i2c_dev;
78 70
71 if (adap->nr >= I2C_MINORS) {
72 printk(KERN_ERR "i2c-dev: Out of device minors (%d)\n",
73 adap->nr);
74 return ERR_PTR(-ENODEV);
75 }
76
79 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL); 77 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);
80 if (!i2c_dev) 78 if (!i2c_dev)
81 return ERR_PTR(-ENOMEM); 79 return ERR_PTR(-ENOMEM);
80 i2c_dev->adap = adap;
82 81
83 spin_lock(&i2c_dev_array_lock); 82 spin_lock(&i2c_dev_list_lock);
84 if (i2c_dev_array[adap->nr]) { 83 list_add_tail(&i2c_dev->list, &i2c_dev_list);
85 spin_unlock(&i2c_dev_array_lock); 84 spin_unlock(&i2c_dev_list_lock);
86 dev_err(&adap->dev, "i2c-dev already has a device assigned to this adapter\n");
87 goto error;
88 }
89 i2c_dev->minor = adap->nr;
90 i2c_dev_array[adap->nr] = i2c_dev;
91 spin_unlock(&i2c_dev_array_lock);
92 return i2c_dev; 85 return i2c_dev;
93error:
94 kfree(i2c_dev);
95 return ERR_PTR(-ENODEV);
96} 86}
97 87
98static void return_i2c_dev(struct i2c_dev *i2c_dev) 88static void return_i2c_dev(struct i2c_dev *i2c_dev)
99{ 89{
100 spin_lock(&i2c_dev_array_lock); 90 spin_lock(&i2c_dev_list_lock);
101 i2c_dev_array[i2c_dev->minor] = NULL; 91 list_del(&i2c_dev->list);
102 spin_unlock(&i2c_dev_array_lock); 92 spin_unlock(&i2c_dev_list_lock);
103} 93}
104 94
105static ssize_t show_adapter_name(struct class_device *class_dev, char *buf) 95static ssize_t show_adapter_name(struct class_device *class_dev, char *buf)
@@ -375,12 +365,13 @@ static int i2cdev_open(struct inode *inode, struct file *file)
375 if (!adap) 365 if (!adap)
376 return -ENODEV; 366 return -ENODEV;
377 367
378 client = kmalloc(sizeof(*client), GFP_KERNEL); 368 client = kzalloc(sizeof(*client), GFP_KERNEL);
379 if (!client) { 369 if (!client) {
380 i2c_put_adapter(adap); 370 i2c_put_adapter(adap);
381 return -ENOMEM; 371 return -ENOMEM;
382 } 372 }
383 memcpy(client, &i2cdev_client_template, sizeof(*client)); 373 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
374 client->driver = &i2cdev_driver;
384 375
385 /* registered with adapter, passed as client to user */ 376 /* registered with adapter, passed as client to user */
386 client->adapter = adap; 377 client->adapter = adap;
@@ -415,41 +406,47 @@ static struct class *i2c_dev_class;
415static int i2cdev_attach_adapter(struct i2c_adapter *adap) 406static int i2cdev_attach_adapter(struct i2c_adapter *adap)
416{ 407{
417 struct i2c_dev *i2c_dev; 408 struct i2c_dev *i2c_dev;
418 struct device *dev; 409 int res;
419 410
420 i2c_dev = get_free_i2c_dev(adap); 411 i2c_dev = get_free_i2c_dev(adap);
421 if (IS_ERR(i2c_dev)) 412 if (IS_ERR(i2c_dev))
422 return PTR_ERR(i2c_dev); 413 return PTR_ERR(i2c_dev);
423 414
424 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
425 adap->name, i2c_dev->minor);
426
427 /* register this i2c device with the driver core */ 415 /* register this i2c device with the driver core */
428 i2c_dev->adap = adap;
429 dev = &adap->dev;
430 i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL, 416 i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL,
431 MKDEV(I2C_MAJOR, i2c_dev->minor), 417 MKDEV(I2C_MAJOR, adap->nr),
432 dev, "i2c-%d", i2c_dev->minor); 418 &adap->dev, "i2c-%d",
433 if (!i2c_dev->class_dev) 419 adap->nr);
420 if (!i2c_dev->class_dev) {
421 res = -ENODEV;
434 goto error; 422 goto error;
435 class_device_create_file(i2c_dev->class_dev, &class_device_attr_name); 423 }
424 res = class_device_create_file(i2c_dev->class_dev, &class_device_attr_name);
425 if (res)
426 goto error_destroy;
427
428 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
429 adap->name, adap->nr);
436 return 0; 430 return 0;
431error_destroy:
432 class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
437error: 433error:
438 return_i2c_dev(i2c_dev); 434 return_i2c_dev(i2c_dev);
439 kfree(i2c_dev); 435 kfree(i2c_dev);
440 return -ENODEV; 436 return res;
441} 437}
442 438
443static int i2cdev_detach_adapter(struct i2c_adapter *adap) 439static int i2cdev_detach_adapter(struct i2c_adapter *adap)
444{ 440{
445 struct i2c_dev *i2c_dev; 441 struct i2c_dev *i2c_dev;
446 442
447 i2c_dev = i2c_dev_get_by_adapter(adap); 443 i2c_dev = i2c_dev_get_by_minor(adap->nr);
448 if (!i2c_dev) 444 if (!i2c_dev) /* attach_adapter must have failed */
449 return -ENODEV; 445 return 0;
450 446
447 class_device_remove_file(i2c_dev->class_dev, &class_device_attr_name);
451 return_i2c_dev(i2c_dev); 448 return_i2c_dev(i2c_dev);
452 class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, i2c_dev->minor)); 449 class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
453 kfree(i2c_dev); 450 kfree(i2c_dev);
454 451
455 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); 452 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
@@ -471,12 +468,6 @@ static struct i2c_driver i2cdev_driver = {
471 .detach_client = i2cdev_detach_client, 468 .detach_client = i2cdev_detach_client,
472}; 469};
473 470
474static struct i2c_client i2cdev_client_template = {
475 .name = "I2C /dev entry",
476 .addr = -1,
477 .driver = &i2cdev_driver,
478};
479
480static int __init i2c_dev_init(void) 471static int __init i2c_dev_init(void)
481{ 472{
482 int res; 473 int res;
diff --git a/drivers/ieee1394/pcilynx.c b/drivers/ieee1394/pcilynx.c
index e6f41238f5e8..b4f146f2c951 100644
--- a/drivers/ieee1394/pcilynx.c
+++ b/drivers/ieee1394/pcilynx.c
@@ -137,7 +137,6 @@ static struct i2c_algo_bit_data bit_data = {
137 .getsda = bit_getsda, 137 .getsda = bit_getsda,
138 .getscl = bit_getscl, 138 .getscl = bit_getscl,
139 .udelay = 5, 139 .udelay = 5,
140 .mdelay = 5,
141 .timeout = 100, 140 .timeout = 100,
142}; 141};
143 142
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index 4b562b386fcf..0dfbcc85ebb9 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -100,7 +100,6 @@ static struct i2c_algo_bit_data bttv_i2c_algo_bit_template = {
100 .getsda = bttv_bit_getsda, 100 .getsda = bttv_bit_getsda,
101 .getscl = bttv_bit_getscl, 101 .getscl = bttv_bit_getscl,
102 .udelay = 16, 102 .udelay = 16,
103 .mdelay = 10,
104 .timeout = 200, 103 .timeout = 200,
105}; 104};
106 105
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 70663805cc30..7bea34714861 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -155,7 +155,6 @@ static struct i2c_algo_bit_data cx8800_i2c_algo_template = {
155 .getsda = cx8800_bit_getsda, 155 .getsda = cx8800_bit_getsda,
156 .getscl = cx8800_bit_getscl, 156 .getscl = cx8800_bit_getscl,
157 .udelay = 16, 157 .udelay = 16,
158 .mdelay = 10,
159 .timeout = 200, 158 .timeout = 200,
160}; 159};
161 160
diff --git a/drivers/media/video/cx88/cx88-vp3054-i2c.c b/drivers/media/video/cx88/cx88-vp3054-i2c.c
index 751a754a45e9..2b4f1970c7df 100644
--- a/drivers/media/video/cx88/cx88-vp3054-i2c.c
+++ b/drivers/media/video/cx88/cx88-vp3054-i2c.c
@@ -100,7 +100,6 @@ static struct i2c_algo_bit_data vp3054_i2c_algo_template = {
100 .getsda = vp3054_bit_getsda, 100 .getsda = vp3054_bit_getsda,
101 .getscl = vp3054_bit_getscl, 101 .getscl = vp3054_bit_getscl,
102 .udelay = 16, 102 .udelay = 16,
103 .mdelay = 10,
104 .timeout = 200, 103 .timeout = 200,
105}; 104};
106 105
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index f2249ed25273..29f59c36f001 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -820,7 +820,6 @@ static struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
820 .getsda = zoran_i2c_getsda, 820 .getsda = zoran_i2c_getsda,
821 .getscl = zoran_i2c_getscl, 821 .getscl = zoran_i2c_getscl,
822 .udelay = 10, 822 .udelay = 10,
823 .mdelay = 0,
824 .timeout = 100, 823 .timeout = 100,
825}; 824};
826 825
diff --git a/drivers/video/i810/i810-i2c.c b/drivers/video/i810/i810-i2c.c
index c1f7b49975dd..7d06b38e80a0 100644
--- a/drivers/video/i810/i810-i2c.c
+++ b/drivers/video/i810/i810-i2c.c
@@ -98,7 +98,6 @@ static int i810_setup_i2c_bus(struct i810fb_i2c_chan *chan, const char *name)
98 chan->algo.getsda = i810i2c_getsda; 98 chan->algo.getsda = i810i2c_getsda;
99 chan->algo.getscl = i810i2c_getscl; 99 chan->algo.getscl = i810i2c_getscl;
100 chan->algo.udelay = 10; 100 chan->algo.udelay = 10;
101 chan->algo.mdelay = 10;
102 chan->algo.timeout = (HZ/2); 101 chan->algo.timeout = (HZ/2);
103 chan->algo.data = chan; 102 chan->algo.data = chan;
104 103
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c
index 57abbae5520f..795c1a99a680 100644
--- a/drivers/video/matrox/i2c-matroxfb.c
+++ b/drivers/video/matrox/i2c-matroxfb.c
@@ -95,12 +95,12 @@ static struct i2c_adapter matrox_i2c_adapter_template =
95 95
96static struct i2c_algo_bit_data matrox_i2c_algo_template = 96static struct i2c_algo_bit_data matrox_i2c_algo_template =
97{ 97{
98 NULL, 98 .setsda = matroxfb_gpio_setsda,
99 matroxfb_gpio_setsda, 99 .setscl = matroxfb_gpio_setscl,
100 matroxfb_gpio_setscl, 100 .getsda = matroxfb_gpio_getsda,
101 matroxfb_gpio_getsda, 101 .getscl = matroxfb_gpio_getscl,
102 matroxfb_gpio_getscl, 102 .udelay = 10,
103 10, 10, 100, 103 .timeout = 100,
104}; 104};
105 105
106static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo, 106static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index e83befd16d63..d7d810dbf0bd 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -148,7 +148,6 @@ static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan,
148 chan->adapter.algo_data = &chan->algo; 148 chan->adapter.algo_data = &chan->algo;
149 chan->adapter.dev.parent = &chan->par->pcidev->dev; 149 chan->adapter.dev.parent = &chan->par->pcidev->dev;
150 chan->algo.udelay = 40; 150 chan->algo.udelay = 40;
151 chan->algo.mdelay = 5;
152 chan->algo.timeout = 20; 151 chan->algo.timeout = 20;
153 chan->algo.data = chan; 152 chan->algo.data = chan;
154 153
diff --git a/include/linux/i2c-algo-bit.h b/include/linux/i2c-algo-bit.h
index c0e7fab28ce3..c8f8df25c7e0 100644
--- a/include/linux/i2c-algo-bit.h
+++ b/include/linux/i2c-algo-bit.h
@@ -40,7 +40,6 @@ struct i2c_algo_bit_data {
40 /* local settings */ 40 /* local settings */
41 int udelay; /* half-clock-cycle time in microsecs */ 41 int udelay; /* half-clock-cycle time in microsecs */
42 /* i.e. clock is (500 / udelay) KHz */ 42 /* i.e. clock is (500 / udelay) KHz */
43 int mdelay; /* in millisecs, unused */
44 int timeout; /* in jiffies */ 43 int timeout; /* in jiffies */
45}; 44};
46 45
diff --git a/include/linux/i2c-algo-pcf.h b/include/linux/i2c-algo-pcf.h
index 18b0adf57a3d..9908f3fc4839 100644
--- a/include/linux/i2c-algo-pcf.h
+++ b/include/linux/i2c-algo-pcf.h
@@ -35,7 +35,6 @@ struct i2c_algo_pcf_data {
35 35
36 /* local settings */ 36 /* local settings */
37 int udelay; 37 int udelay;
38 int mdelay;
39 int timeout; 38 int timeout;
40}; 39};
41 40
diff --git a/include/linux/i2c-algo-sibyte.h b/include/linux/i2c-algo-sibyte.h
deleted file mode 100644
index 03914ded8614..000000000000
--- a/include/linux/i2c-algo-sibyte.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * Copyright (C) 2001,2002,2003 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef I2C_ALGO_SIBYTE_H
20#define I2C_ALGO_SIBYTE_H 1
21
22#include <linux/i2c.h>
23
24struct i2c_algo_sibyte_data {
25 void *data; /* private data */
26 int bus; /* which bus */
27 void *reg_base; /* CSR base */
28};
29
30int i2c_sibyte_add_bus(struct i2c_adapter *, int speed);
31int i2c_sibyte_del_bus(struct i2c_adapter *);
32
33#endif /* I2C_ALGO_SIBYTE_H */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index eb0628a7ecc6..9b5d04768c2c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -64,14 +64,6 @@ extern int i2c_master_recv(struct i2c_client *,char* ,int);
64 */ 64 */
65extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); 65extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
66 66
67/*
68 * Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor.
69 * This is not tested/implemented yet and will change in the future.
70 */
71extern int i2c_slave_send(struct i2c_client *,char*,int);
72extern int i2c_slave_recv(struct i2c_client *,char*,int);
73
74
75 67
76/* This is the very generalized SMBus access routine. You probably do not 68/* This is the very generalized SMBus access routine. You probably do not
77 want to use this, though; one of the functions below may be much easier, 69 want to use this, though; one of the functions below may be much easier,
@@ -201,10 +193,6 @@ struct i2c_algorithm {
201 unsigned short flags, char read_write, 193 unsigned short flags, char read_write,
202 u8 command, int size, union i2c_smbus_data * data); 194 u8 command, int size, union i2c_smbus_data * data);
203 195
204 /* --- these optional/future use for some adapter types.*/
205 int (*slave_send)(struct i2c_adapter *,char*,int);
206 int (*slave_recv)(struct i2c_adapter *,char*,int);
207
208 /* --- ioctl like call to set div. parameters. */ 196 /* --- ioctl like call to set div. parameters. */
209 int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long); 197 int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);
210 198
@@ -220,7 +208,7 @@ struct i2c_adapter {
220 struct module *owner; 208 struct module *owner;
221 unsigned int id; 209 unsigned int id;
222 unsigned int class; 210 unsigned int class;
223 struct i2c_algorithm *algo;/* the algorithm to access the bus */ 211 const struct i2c_algorithm *algo; /* the algorithm to access the bus */
224 void *algo_data; 212 void *algo_data;
225 213
226 /* --- administration stuff. */ 214 /* --- administration stuff. */