aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-04 20:46:27 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-04 20:46:27 -0400
commit8d41f0e8d51742aba5bbcab9acb5238a8578c917 (patch)
treec69e7ffaf2a8598283422d20643154a298d08293
parent8bc8493063f938c932819958a7b5a0d56046bc96 (diff)
parent5b68790cd5e2879067bcbc45b01eeb6081e7d731 (diff)
Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
* 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6: (44 commits) i2c-s3c2410: Fix bug in releasing driver i2c-s3c2410: Fix I2C SDA to SCL setup time i2c: New i2c-tiny-usb bus driver i2c: Documentation update i2c: SPIN_LOCK_UNLOCKED cleanup i2c: Obsolete i2c-ixp2000, i2c-ixp4xx and scx200_i2c i2c: New Simtec I2C bus driver i2c: Bitbanging I2C bus driver using the GPIO API Use menuconfig objects - I2C i2c: Restore i2c_smbus_read_block_data i2c-pxa: Clean transaction stop i2c-algo-bit: Improve debugging i2c-algo-bit: Implement a 50/50 SCL duty cycle i2c-omap: Switch to static adapter numbering i2c: Blackfin Two Wire Interface driver i2c-algo-sgi: Comment and whitespace cleanups i2c: Make i2c_del_driver a void function i2c: Move i2c-isa-only exported symbol declarations i2c: Document i2c_new_device() i2c: Add i2c_new_probed_device() ... Fixed trivial conflict in Documentation/feature-removal-schedule.txt manually. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Documentation/feature-removal-schedule.txt21
-rw-r--r--Documentation/i2c/busses/i2c-nforce22
-rw-r--r--Documentation/i2c/porting-clients18
-rw-r--r--Documentation/i2c/summary29
-rw-r--r--Documentation/i2c/writing-clients415
-rw-r--r--MAINTAINERS19
-rw-r--r--arch/powerpc/platforms/powermac/cpufreq_32.c1
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/i2c/Kconfig18
-rw-r--r--drivers/i2c/Makefile1
-rw-r--r--drivers/i2c/algos/Kconfig8
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c286
-rw-r--r--drivers/i2c/algos/i2c-algo-sgi.c9
-rw-r--r--drivers/i2c/busses/Kconfig151
-rw-r--r--drivers/i2c/busses/Makefile4
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c644
-rw-r--r--drivers/i2c/busses/i2c-elektor.c51
-rw-r--r--drivers/i2c/busses/i2c-gpio.c215
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-isa.c43
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c2
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c2
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c6
-rw-r--r--drivers/i2c/busses/i2c-omap.c3
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c144
-rw-r--r--drivers/i2c/busses/i2c-parport.c25
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c35
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa.c15
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c96
-rw-r--r--drivers/i2c/busses/i2c-simtec.c186
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-tiny-usb.c277
-rw-r--r--drivers/i2c/busses/i2c-viapro.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c3
-rw-r--r--drivers/i2c/chips/Kconfig21
-rw-r--r--drivers/i2c/i2c-boardinfo.c90
-rw-r--r--drivers/i2c/i2c-core.c662
-rw-r--r--drivers/i2c/i2c-core.h31
-rw-r--r--drivers/macintosh/therm_windtunnel.c3
-rw-r--r--drivers/media/dvb/b2c2/flexcop-i2c.c3
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-i2c.c2
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.c4
-rw-r--r--drivers/media/video/cx2341x.c1
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_priv.h1
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.c1
-rw-r--r--drivers/video/intelfb/intelfb_i2c.c3
-rw-r--r--drivers/video/matrox/i2c-matroxfb.c2
-rw-r--r--include/linux/i2c-algo-bit.h7
-rw-r--r--include/linux/i2c-gpio.h38
-rw-r--r--include/linux/i2c-id.h3
-rw-r--r--include/linux/i2c.h123
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/media/ovcamchip.h1
-rw-r--r--include/media/tuner.h1
-rw-r--r--sound/oss/dmasound/tas_ioctl.h1
61 files changed, 2879 insertions, 870 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 1a9e600a73a8..7d252dbe7d17 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -190,18 +190,10 @@ Who: Jean Delvare <khali@linux-fr.org>
190 190
191--------------------------- 191---------------------------
192 192
193What: i2c_adapter.dev 193What: i2c_adapter.list
194 i2c_adapter.list
195When: July 2007 194When: July 2007
196Why: Superfluous, given i2c_adapter.class_dev: 195Why: Superfluous, this list duplicates the one maintained by the driver
197 * The "dev" was a stand-in for the physical device node that legacy 196 core.
198 drivers would not have; but now it's almost always present. Any
199 remaining legacy drivers must upgrade (they now trigger warnings).
200 * The "list" duplicates class device children.
201 The delay in removing this is so upgraded lm_sensors and libsensors
202 can get deployed. (Removal causes minor changes in the sysfs layout,
203 notably the location of the adapter type name and parenting the i2c
204 client hardware directly from their controller.)
205Who: Jean Delvare <khali@linux-fr.org>, 197Who: Jean Delvare <khali@linux-fr.org>,
206 David Brownell <dbrownell@users.sourceforge.net> 198 David Brownell <dbrownell@users.sourceforge.net>
207 199
@@ -331,3 +323,10 @@ Who: Cornelia Huck <cornelia.huck@de.ibm.com>
331 323
332--------------------------- 324---------------------------
333 325
326What: i2c-ixp2000, i2c-ixp4xx and scx200_i2c drivers
327When: September 2007
328Why: Obsolete. The new i2c-gpio driver replaces all hardware-specific
329 I2C-over-GPIO drivers.
330Who: Jean Delvare <khali@linux-fr.org>
331
332---------------------------
diff --git a/Documentation/i2c/busses/i2c-nforce2 b/Documentation/i2c/busses/i2c-nforce2
index 7f61fbc03f7f..fae3495bcbaf 100644
--- a/Documentation/i2c/busses/i2c-nforce2
+++ b/Documentation/i2c/busses/i2c-nforce2
@@ -9,6 +9,8 @@ Supported adapters:
9 * nForce4 MCP-04 10de:0034 9 * nForce4 MCP-04 10de:0034
10 * nForce4 MCP51 10de:0264 10 * nForce4 MCP51 10de:0264
11 * nForce4 MCP55 10de:0368 11 * nForce4 MCP55 10de:0368
12 * nForce4 MCP61 10de:03EB
13 * nForce4 MCP65 10de:0446
12 14
13Datasheet: not publicly available, but seems to be similar to the 15Datasheet: not publicly available, but seems to be similar to the
14 AMD-8111 SMBus 2.0 adapter. 16 AMD-8111 SMBus 2.0 adapter.
diff --git a/Documentation/i2c/porting-clients b/Documentation/i2c/porting-clients
index ca272b263a92..7bf82c08f6ca 100644
--- a/Documentation/i2c/porting-clients
+++ b/Documentation/i2c/porting-clients
@@ -1,4 +1,4 @@
1Revision 6, 2005-11-20 1Revision 7, 2007-04-19
2Jean Delvare <khali@linux-fr.org> 2Jean Delvare <khali@linux-fr.org>
3Greg KH <greg@kroah.com> 3Greg KH <greg@kroah.com>
4 4
@@ -20,6 +20,10 @@ yours for best results.
20 20
21Technical changes: 21Technical changes:
22 22
23* [Driver type] Any driver that was relying on i2c-isa has to be
24 converted to a proper isa, platform or pci driver. This is not
25 covered by this guide.
26
23* [Includes] Get rid of "version.h" and <linux/i2c-proc.h>. 27* [Includes] Get rid of "version.h" and <linux/i2c-proc.h>.
24 Includes typically look like that: 28 Includes typically look like that:
25 #include <linux/module.h> 29 #include <linux/module.h>
@@ -27,12 +31,10 @@ Technical changes:
27 #include <linux/slab.h> 31 #include <linux/slab.h>
28 #include <linux/jiffies.h> 32 #include <linux/jiffies.h>
29 #include <linux/i2c.h> 33 #include <linux/i2c.h>
30 #include <linux/i2c-isa.h> /* for ISA drivers */
31 #include <linux/hwmon.h> /* for hardware monitoring drivers */ 34 #include <linux/hwmon.h> /* for hardware monitoring drivers */
32 #include <linux/hwmon-sysfs.h> 35 #include <linux/hwmon-sysfs.h>
33 #include <linux/hwmon-vid.h> /* if you need VRM support */ 36 #include <linux/hwmon-vid.h> /* if you need VRM support */
34 #include <linux/err.h> /* for class registration */ 37 #include <linux/err.h> /* for class registration */
35 #include <asm/io.h> /* if you have I/O operations */
36 Please respect this inclusion order. Some extra headers may be 38 Please respect this inclusion order. Some extra headers may be
37 required for a given driver (e.g. "lm75.h"). 39 required for a given driver (e.g. "lm75.h").
38 40
@@ -69,20 +71,16 @@ Technical changes:
69 sensors mailing list <lm-sensors@lm-sensors.org> by providing a 71 sensors mailing list <lm-sensors@lm-sensors.org> by providing a
70 patch to the Documentation/hwmon/sysfs-interface file. 72 patch to the Documentation/hwmon/sysfs-interface file.
71 73
72* [Attach] For I2C drivers, the attach function should make sure 74* [Attach] The attach function should make sure that the adapter's
73 that the adapter's class has I2C_CLASS_HWMON (or whatever class is 75 class has I2C_CLASS_HWMON (or whatever class is suitable for your
74 suitable for your driver), using the following construct: 76 driver), using the following construct:
75 if (!(adapter->class & I2C_CLASS_HWMON)) 77 if (!(adapter->class & I2C_CLASS_HWMON))
76 return 0; 78 return 0;
77 ISA-only drivers of course don't need this.
78 Call i2c_probe() instead of i2c_detect(). 79 Call i2c_probe() instead of i2c_detect().
79 80
80* [Detect] As mentioned earlier, the flags parameter is gone. 81* [Detect] As mentioned earlier, the flags parameter is gone.
81 The type_name and client_name strings are replaced by a single 82 The type_name and client_name strings are replaced by a single
82 name string, which will be filled with a lowercase, short string. 83 name string, which will be filled with a lowercase, short string.
83 In i2c-only drivers, drop the i2c_is_isa_adapter check, it's
84 useless. Same for isa-only drivers, as the test would always be
85 true. Only hybrid drivers (which are quite rare) still need it.
86 The labels used for error paths are reduced to the number needed. 84 The labels used for error paths are reduced to the number needed.
87 It is advised that the labels are given descriptive names such as 85 It is advised that the labels are given descriptive names such as
88 exit and exit_free. Don't forget to properly set err before 86 exit and exit_free. Don't forget to properly set err before
diff --git a/Documentation/i2c/summary b/Documentation/i2c/summary
index 41dde8776791..aea60bf7e8f0 100644
--- a/Documentation/i2c/summary
+++ b/Documentation/i2c/summary
@@ -4,17 +4,23 @@ I2C and SMBus
4============= 4=============
5 5
6I2C (pronounce: I squared C) is a protocol developed by Philips. It is a 6I2C (pronounce: I squared C) is a protocol developed by Philips. It is a
7slow two-wire protocol (10-400 kHz), but it suffices for many types of 7slow two-wire protocol (variable speed, up to 400 kHz), with a high speed
8devices. 8extension (3.4 MHz). It provides an inexpensive bus for connecting many
9types of devices with infrequent or low bandwidth communications needs.
10I2C is widely used with embedded systems. Some systems use variants that
11don't meet branding requirements, and so are not advertised as being I2C.
9 12
10SMBus (System Management Bus) is a subset of the I2C protocol. Many 13SMBus (System Management Bus) is based on the I2C protocol, and is mostly
11modern mainboards have a System Management Bus. There are a lot of 14a subset of I2C protocols and signaling. Many I2C devices will work on an
12devices which can be connected to a SMBus; the most notable are modern 15SMBus, but some SMBus protocols add semantics beyond what is required to
13memory chips with EEPROM memories and chips for hardware monitoring. 16achieve I2C branding. Modern PC mainboards rely on SMBus. The most common
17devices connected through SMBus are RAM modules configured using I2C EEPROMs,
18and hardware monitoring chips.
14 19
15Because the SMBus is just a special case of the generalized I2C bus, we 20Because the SMBus is mostly a subset of the generalized I2C bus, we can
16can simulate the SMBus protocol on plain I2C busses. The reverse is 21use its protocols on many I2C systems. However, there are systems that don't
17regretfully impossible. 22meet both SMBus and I2C electrical constraints; and others which can't
23implement all the common SMBus protocol semantics or messages.
18 24
19 25
20Terminology 26Terminology
@@ -29,6 +35,7 @@ When we talk about I2C, we use the following terms:
29An Algorithm driver contains general code that can be used for a whole class 35An Algorithm driver contains general code that can be used for a whole class
30of I2C adapters. Each specific adapter driver depends on one algorithm 36of I2C adapters. Each specific adapter driver depends on one algorithm
31driver. 37driver.
38
32A Driver driver (yes, this sounds ridiculous, sorry) contains the general 39A Driver driver (yes, this sounds ridiculous, sorry) contains the general
33code to access some type of device. Each detected device gets its own 40code to access some type of device. Each detected device gets its own
34data in the Client structure. Usually, Driver and Client are more closely 41data in the Client structure. Usually, Driver and Client are more closely
@@ -40,6 +47,10 @@ a separate Adapter and Algorithm driver), and drivers for your I2C devices
40in this package. See the lm_sensors project http://www.lm-sensors.nu 47in this package. See the lm_sensors project http://www.lm-sensors.nu
41for device drivers. 48for device drivers.
42 49
50At this time, Linux only operates I2C (or SMBus) in master mode; you can't
51use these APIs to make a Linux system behave as a slave/device, either to
52speak a custom protocol or to emulate some other device.
53
43 54
44Included Bus Drivers 55Included Bus Drivers
45==================== 56====================
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index fbcff96f4ca1..3d8d36b0ad12 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -1,5 +1,5 @@
1This is a small guide for those who want to write kernel drivers for I2C 1This is a small guide for those who want to write kernel drivers for I2C
2or SMBus devices. 2or SMBus devices, using Linux as the protocol host/master (not slave).
3 3
4To set up a driver, you need to do several things. Some are optional, and 4To set up a driver, you need to do several things. Some are optional, and
5some things can be done slightly or completely different. Use this as a 5some things can be done slightly or completely different. Use this as a
@@ -29,8 +29,16 @@ static struct i2c_driver foo_driver = {
29 .driver = { 29 .driver = {
30 .name = "foo", 30 .name = "foo",
31 }, 31 },
32
33 /* iff driver uses driver model ("new style") binding model: */
34 .probe = foo_probe,
35 .remove = foo_remove,
36
37 /* else, driver uses "legacy" binding model: */
32 .attach_adapter = foo_attach_adapter, 38 .attach_adapter = foo_attach_adapter,
33 .detach_client = foo_detach_client, 39 .detach_client = foo_detach_client,
40
41 /* these may be used regardless of the driver binding model */
34 .shutdown = foo_shutdown, /* optional */ 42 .shutdown = foo_shutdown, /* optional */
35 .suspend = foo_suspend, /* optional */ 43 .suspend = foo_suspend, /* optional */
36 .resume = foo_resume, /* optional */ 44 .resume = foo_resume, /* optional */
@@ -40,7 +48,8 @@ static struct i2c_driver foo_driver = {
40The name field is the driver name, and must not contain spaces. It 48The name field is the driver name, and must not contain spaces. It
41should match the module name (if the driver can be compiled as a module), 49should match the module name (if the driver can be compiled as a module),
42although you can use MODULE_ALIAS (passing "foo" in this example) to add 50although you can use MODULE_ALIAS (passing "foo" in this example) to add
43another name for the module. 51another name for the module. If the driver name doesn't match the module
52name, the module won't be automatically loaded (hotplug/coldplug).
44 53
45All other fields are for call-back functions which will be explained 54All other fields are for call-back functions which will be explained
46below. 55below.
@@ -65,16 +74,13 @@ An example structure is below.
65 74
66 struct foo_data { 75 struct foo_data {
67 struct i2c_client client; 76 struct i2c_client client;
68 struct semaphore lock; /* For ISA access in `sensors' drivers. */
69 int sysctl_id; /* To keep the /proc directory entry for
70 `sensors' drivers. */
71 enum chips type; /* To keep the chips type for `sensors' drivers. */ 77 enum chips type; /* To keep the chips type for `sensors' drivers. */
72 78
73 /* Because the i2c bus is slow, it is often useful to cache the read 79 /* Because the i2c bus is slow, it is often useful to cache the read
74 information of a chip for some time (for example, 1 or 2 seconds). 80 information of a chip for some time (for example, 1 or 2 seconds).
75 It depends of course on the device whether this is really worthwhile 81 It depends of course on the device whether this is really worthwhile
76 or even sensible. */ 82 or even sensible. */
77 struct semaphore update_lock; /* When we are reading lots of information, 83 struct mutex update_lock; /* When we are reading lots of information,
78 another process should not update the 84 another process should not update the
79 below information */ 85 below information */
80 char valid; /* != 0 if the following fields are valid. */ 86 char valid; /* != 0 if the following fields are valid. */
@@ -95,8 +101,7 @@ some obscure clients). But we need generic reading and writing routines.
95I have found it useful to define foo_read and foo_write function for this. 101I have found it useful to define foo_read and foo_write function for this.
96For some cases, it will be easier to call the i2c functions directly, 102For some cases, it will be easier to call the i2c functions directly,
97but many chips have some kind of register-value idea that can easily 103but many chips have some kind of register-value idea that can easily
98be encapsulated. Also, some chips have both ISA and I2C interfaces, and 104be encapsulated.
99it useful to abstract from this (only for `sensors' drivers).
100 105
101The below functions are simple examples, and should not be copied 106The below functions are simple examples, and should not be copied
102literally. 107literally.
@@ -119,28 +124,101 @@ literally.
119 return i2c_smbus_write_word_data(client,reg,value); 124 return i2c_smbus_write_word_data(client,reg,value);
120 } 125 }
121 126
122For sensors code, you may have to cope with ISA registers too. Something
123like the below often works. Note the locking!
124
125 int foo_read_value(struct i2c_client *client, u8 reg)
126 {
127 int res;
128 if (i2c_is_isa_client(client)) {
129 down(&(((struct foo_data *) (client->data)) -> lock));
130 outb_p(reg,client->addr + FOO_ADDR_REG_OFFSET);
131 res = inb_p(client->addr + FOO_DATA_REG_OFFSET);
132 up(&(((struct foo_data *) (client->data)) -> lock));
133 return res;
134 } else
135 return i2c_smbus_read_byte_data(client,reg);
136 }
137
138Writing is done the same way.
139
140 127
141Probing and attaching 128Probing and attaching
142===================== 129=====================
143 130
131The Linux I2C stack was originally written to support access to hardware
132monitoring chips on PC motherboards, and thus it embeds some assumptions
133that are more appropriate to SMBus (and PCs) than to I2C. One of these
134assumptions is that most adapters and devices drivers support the SMBUS_QUICK
135protocol to probe device presence. Another is that devices and their drivers
136can be sufficiently configured using only such probe primitives.
137
138As Linux and its I2C stack became more widely used in embedded systems
139and complex components such as DVB adapters, those assumptions became more
140problematic. Drivers for I2C devices that issue interrupts need more (and
141different) configuration information, as do drivers handling chip variants
142that can't be distinguished by protocol probing, or which need some board
143specific information to operate correctly.
144
145Accordingly, the I2C stack now has two models for associating I2C devices
146with their drivers: the original "legacy" model, and a newer one that's
147fully compatible with the Linux 2.6 driver model. These models do not mix,
148since the "legacy" model requires drivers to create "i2c_client" device
149objects after SMBus style probing, while the Linux driver model expects
150drivers to be given such device objects in their probe() routines.
151
152
153Standard Driver Model Binding ("New Style")
154-------------------------------------------
155
156System infrastructure, typically board-specific initialization code or
157boot firmware, reports what I2C devices exist. For example, there may be
158a table, in the kernel or from the boot loader, identifying I2C devices
159and linking them to board-specific configuration information about IRQs
160and other wiring artifacts, chip type, and so on. That could be used to
161create i2c_client objects for each I2C device.
162
163I2C device drivers using this binding model work just like any other
164kind of driver in Linux: they provide a probe() method to bind to
165those devices, and a remove() method to unbind.
166
167 static int foo_probe(struct i2c_client *client);
168 static int foo_remove(struct i2c_client *client);
169
170Remember that the i2c_driver does not create those client handles. The
171handle may be used during foo_probe(). If foo_probe() reports success
172(zero not a negative status code) it may save the handle and use it until
173foo_remove() returns. That binding model is used by most Linux drivers.
174
175Drivers match devices when i2c_client.driver_name and the driver name are
176the same; this approach is used in several other busses that don't have
177device typing support in the hardware. The driver and module name should
178match, so hotplug/coldplug mechanisms will modprobe the driver.
179
180
181Device Creation (Standard driver model)
182---------------------------------------
183
184If you know for a fact that an I2C device is connected to a given I2C bus,
185you can instantiate that device by simply filling an i2c_board_info
186structure with the device address and driver name, and calling
187i2c_new_device(). This will create the device, then the driver core will
188take care of finding the right driver and will call its probe() method.
189If a driver supports different device types, you can specify the type you
190want using the type field. You can also specify an IRQ and platform data
191if needed.
192
193Sometimes you know that a device is connected to a given I2C bus, but you
194don't know the exact address it uses. This happens on TV adapters for
195example, where the same driver supports dozens of slightly different
196models, and I2C device addresses change from one model to the next. In
197that case, you can use the i2c_new_probed_device() variant, which is
198similar to i2c_new_device(), except that it takes an additional list of
199possible I2C addresses to probe. A device is created for the first
200responsive address in the list. If you expect more than one device to be
201present in the address range, simply call i2c_new_probed_device() that
202many times.
203
204The call to i2c_new_device() or i2c_new_probed_device() typically happens
205in the I2C bus driver. You may want to save the returned i2c_client
206reference for later use.
207
208
209Device Deletion (Standard driver model)
210---------------------------------------
211
212Each I2C device which has been created using i2c_new_device() or
213i2c_new_probed_device() can be unregistered by calling
214i2c_unregister_device(). If you don't call it explicitly, it will be
215called automatically before the underlying I2C bus itself is removed, as a
216device can't survive its parent in the device driver model.
217
218
219Legacy Driver Binding Model
220---------------------------
221
144Most i2c devices can be present on several i2c addresses; for some this 222Most i2c devices can be present on several i2c addresses; for some this
145is determined in hardware (by soldering some chip pins to Vcc or Ground), 223is determined in hardware (by soldering some chip pins to Vcc or Ground),
146for others this can be changed in software (by writing to specific client 224for others this can be changed in software (by writing to specific client
@@ -157,13 +235,9 @@ detection algorithm.
157You do not have to use this parameter interface; but don't try to use 235You do not have to use this parameter interface; but don't try to use
158function i2c_probe() if you don't. 236function i2c_probe() if you don't.
159 237
160NOTE: If you want to write a `sensors' driver, the interface is slightly
161 different! See below.
162
163 238
164 239Probing classes (Legacy model)
165Probing classes 240------------------------------
166---------------
167 241
168All parameters are given as lists of unsigned 16-bit integers. Lists are 242All parameters are given as lists of unsigned 16-bit integers. Lists are
169terminated by I2C_CLIENT_END. 243terminated by I2C_CLIENT_END.
@@ -210,8 +284,8 @@ Note that you *have* to call the defined variable `normal_i2c',
210without any prefix! 284without any prefix!
211 285
212 286
213Attaching to an adapter 287Attaching to an adapter (Legacy model)
214----------------------- 288--------------------------------------
215 289
216Whenever a new adapter is inserted, or for all adapters if the driver is 290Whenever a new adapter is inserted, or for all adapters if the driver is
217being registered, the callback attach_adapter() is called. Now is the 291being registered, the callback attach_adapter() is called. Now is the
@@ -237,17 +311,13 @@ them (unless a `force' parameter was used). In addition, addresses that
237are already in use (by some other registered client) are skipped. 311are already in use (by some other registered client) are skipped.
238 312
239 313
240The detect client function 314The detect client function (Legacy model)
241-------------------------- 315-----------------------------------------
242 316
243The detect client function is called by i2c_probe. The `kind' parameter 317The detect client function is called by i2c_probe. The `kind' parameter
244contains -1 for a probed detection, 0 for a forced detection, or a positive 318contains -1 for a probed detection, 0 for a forced detection, or a positive
245number for a forced detection with a chip type forced. 319number for a forced detection with a chip type forced.
246 320
247Below, some things are only needed if this is a `sensors' driver. Those
248parts are between /* SENSORS ONLY START */ and /* SENSORS ONLY END */
249markers.
250
251Returning an error different from -ENODEV in a detect function will cause 321Returning an error different from -ENODEV in a detect function will cause
252the detection to stop: other addresses and adapters won't be scanned. 322the detection to stop: other addresses and adapters won't be scanned.
253This should only be done on fatal or internal errors, such as a memory 323This should only be done on fatal or internal errors, such as a memory
@@ -256,64 +326,20 @@ shortage or i2c_attach_client failing.
256For now, you can ignore the `flags' parameter. It is there for future use. 326For now, you can ignore the `flags' parameter. It is there for future use.
257 327
258 int foo_detect_client(struct i2c_adapter *adapter, int address, 328 int foo_detect_client(struct i2c_adapter *adapter, int address,
259 unsigned short flags, int kind) 329 int kind)
260 { 330 {
261 int err = 0; 331 int err = 0;
262 int i; 332 int i;
263 struct i2c_client *new_client; 333 struct i2c_client *client;
264 struct foo_data *data; 334 struct foo_data *data;
265 const char *client_name = ""; /* For non-`sensors' drivers, put the real 335 const char *name = "";
266 name here! */
267 336
268 /* Let's see whether this adapter can support what we need. 337 /* Let's see whether this adapter can support what we need.
269 Please substitute the things you need here! 338 Please substitute the things you need here! */
270 For `sensors' drivers, add `! is_isa &&' to the if statement */
271 if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA | 339 if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA |
272 I2C_FUNC_SMBUS_WRITE_BYTE)) 340 I2C_FUNC_SMBUS_WRITE_BYTE))
273 goto ERROR0; 341 goto ERROR0;
274 342
275 /* SENSORS ONLY START */
276 const char *type_name = "";
277 int is_isa = i2c_is_isa_adapter(adapter);
278
279 /* Do this only if the chip can additionally be found on the ISA bus
280 (hybrid chip). */
281
282 if (is_isa) {
283
284 /* Discard immediately if this ISA range is already used */
285 /* FIXME: never use check_region(), only request_region() */
286 if (check_region(address,FOO_EXTENT))
287 goto ERROR0;
288
289 /* Probe whether there is anything on this address.
290 Some example code is below, but you will have to adapt this
291 for your own driver */
292
293 if (kind < 0) /* Only if no force parameter was used */ {
294 /* We may need long timeouts at least for some chips. */
295 #define REALLY_SLOW_IO
296 i = inb_p(address + 1);
297 if (inb_p(address + 2) != i)
298 goto ERROR0;
299 if (inb_p(address + 3) != i)
300 goto ERROR0;
301 if (inb_p(address + 7) != i)
302 goto ERROR0;
303 #undef REALLY_SLOW_IO
304
305 /* Let's just hope nothing breaks here */
306 i = inb_p(address + 5) & 0x7f;
307 outb_p(~i & 0x7f,address+5);
308 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
309 outb_p(i,address+5);
310 return 0;
311 }
312 }
313 }
314
315 /* SENSORS ONLY END */
316
317 /* OK. For now, we presume we have a valid client. We now create the 343 /* OK. For now, we presume we have a valid client. We now create the
318 client structure, even though we cannot fill it completely yet. 344 client structure, even though we cannot fill it completely yet.
319 But it allows us to access several i2c functions safely */ 345 But it allows us to access several i2c functions safely */
@@ -323,13 +349,12 @@ For now, you can ignore the `flags' parameter. It is there for future use.
323 goto ERROR0; 349 goto ERROR0;
324 } 350 }
325 351
326 new_client = &data->client; 352 client = &data->client;
327 i2c_set_clientdata(new_client, data); 353 i2c_set_clientdata(client, data);
328 354
329 new_client->addr = address; 355 client->addr = address;
330 new_client->adapter = adapter; 356 client->adapter = adapter;
331 new_client->driver = &foo_driver; 357 client->driver = &foo_driver;
332 new_client->flags = 0;
333 358
334 /* Now, we do the remaining detection. If no `force' parameter is used. */ 359 /* Now, we do the remaining detection. If no `force' parameter is used. */
335 360
@@ -337,19 +362,17 @@ For now, you can ignore the `flags' parameter. It is there for future use.
337 parameter was used. */ 362 parameter was used. */
338 if (kind < 0) { 363 if (kind < 0) {
339 /* The below is of course bogus */ 364 /* The below is of course bogus */
340 if (foo_read(new_client,FOO_REG_GENERIC) != FOO_GENERIC_VALUE) 365 if (foo_read(client, FOO_REG_GENERIC) != FOO_GENERIC_VALUE)
341 goto ERROR1; 366 goto ERROR1;
342 } 367 }
343 368
344 /* SENSORS ONLY START */
345
346 /* Next, specific detection. This is especially important for `sensors' 369 /* Next, specific detection. This is especially important for `sensors'
347 devices. */ 370 devices. */
348 371
349 /* Determine the chip type. Not needed if a `force_CHIPTYPE' parameter 372 /* Determine the chip type. Not needed if a `force_CHIPTYPE' parameter
350 was used. */ 373 was used. */
351 if (kind <= 0) { 374 if (kind <= 0) {
352 i = foo_read(new_client,FOO_REG_CHIPTYPE); 375 i = foo_read(client, FOO_REG_CHIPTYPE);
353 if (i == FOO_TYPE_1) 376 if (i == FOO_TYPE_1)
354 kind = chip1; /* As defined in the enum */ 377 kind = chip1; /* As defined in the enum */
355 else if (i == FOO_TYPE_2) 378 else if (i == FOO_TYPE_2)
@@ -363,63 +386,31 @@ For now, you can ignore the `flags' parameter. It is there for future use.
363 386
364 /* Now set the type and chip names */ 387 /* Now set the type and chip names */
365 if (kind == chip1) { 388 if (kind == chip1) {
366 type_name = "chip1"; /* For /proc entry */ 389 name = "chip1";
367 client_name = "CHIP 1";
368 } else if (kind == chip2) { 390 } else if (kind == chip2) {
369 type_name = "chip2"; /* For /proc entry */ 391 name = "chip2";
370 client_name = "CHIP 2";
371 } 392 }
372 393
373 /* Reserve the ISA region */
374 if (is_isa)
375 request_region(address,FOO_EXTENT,type_name);
376
377 /* SENSORS ONLY END */
378
379 /* Fill in the remaining client fields. */ 394 /* Fill in the remaining client fields. */
380 strcpy(new_client->name,client_name); 395 strlcpy(client->name, name, I2C_NAME_SIZE);
381
382 /* SENSORS ONLY BEGIN */
383 data->type = kind; 396 data->type = kind;
384 /* SENSORS ONLY END */ 397 mutex_init(&data->update_lock); /* Only if you use this field */
385
386 data->valid = 0; /* Only if you use this field */
387 init_MUTEX(&data->update_lock); /* Only if you use this field */
388 398
389 /* Any other initializations in data must be done here too. */ 399 /* Any other initializations in data must be done here too. */
390 400
391 /* Tell the i2c layer a new client has arrived */
392 if ((err = i2c_attach_client(new_client)))
393 goto ERROR3;
394
395 /* SENSORS ONLY BEGIN */
396 /* Register a new directory entry with module sensors. See below for
397 the `template' structure. */
398 if ((i = i2c_register_entry(new_client, type_name,
399 foo_dir_table_template,THIS_MODULE)) < 0) {
400 err = i;
401 goto ERROR4;
402 }
403 data->sysctl_id = i;
404
405 /* SENSORS ONLY END */
406
407 /* This function can write default values to the client registers, if 401 /* This function can write default values to the client registers, if
408 needed. */ 402 needed. */
409 foo_init_client(new_client); 403 foo_init_client(client);
404
405 /* Tell the i2c layer a new client has arrived */
406 if ((err = i2c_attach_client(client)))
407 goto ERROR1;
408
410 return 0; 409 return 0;
411 410
412 /* OK, this is not exactly good programming practice, usually. But it is 411 /* OK, this is not exactly good programming practice, usually. But it is
413 very code-efficient in this case. */ 412 very code-efficient in this case. */
414 413
415 ERROR4:
416 i2c_detach_client(new_client);
417 ERROR3:
418 ERROR2:
419 /* SENSORS ONLY START */
420 if (is_isa)
421 release_region(address,FOO_EXTENT);
422 /* SENSORS ONLY END */
423 ERROR1: 414 ERROR1:
424 kfree(data); 415 kfree(data);
425 ERROR0: 416 ERROR0:
@@ -427,8 +418,8 @@ For now, you can ignore the `flags' parameter. It is there for future use.
427 } 418 }
428 419
429 420
430Removing the client 421Removing the client (Legacy model)
431=================== 422==================================
432 423
433The detach_client call back function is called when a client should be 424The detach_client call back function is called when a client should be
434removed. It may actually fail, but only when panicking. This code is 425removed. It may actually fail, but only when panicking. This code is
@@ -436,22 +427,12 @@ much simpler than the attachment code, fortunately!
436 427
437 int foo_detach_client(struct i2c_client *client) 428 int foo_detach_client(struct i2c_client *client)
438 { 429 {
439 int err,i; 430 int err;
440
441 /* SENSORS ONLY START */
442 /* Deregister with the `i2c-proc' module. */
443 i2c_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id);
444 /* SENSORS ONLY END */
445 431
446 /* Try to detach the client from i2c space */ 432 /* Try to detach the client from i2c space */
447 if ((err = i2c_detach_client(client))) 433 if ((err = i2c_detach_client(client)))
448 return err; 434 return err;
449 435
450 /* HYBRID SENSORS CHIP ONLY START */
451 if i2c_is_isa_client(client)
452 release_region(client->addr,LM78_EXTENT);
453 /* HYBRID SENSORS CHIP ONLY END */
454
455 kfree(i2c_get_clientdata(client)); 436 kfree(i2c_get_clientdata(client));
456 return 0; 437 return 0;
457 } 438 }
@@ -464,45 +445,34 @@ When the kernel is booted, or when your foo driver module is inserted,
464you have to do some initializing. Fortunately, just attaching (registering) 445you have to do some initializing. Fortunately, just attaching (registering)
465the driver module is usually enough. 446the driver module is usually enough.
466 447
467 /* Keep track of how far we got in the initialization process. If several
468 things have to initialized, and we fail halfway, only those things
469 have to be cleaned up! */
470 static int __initdata foo_initialized = 0;
471
472 static int __init foo_init(void) 448 static int __init foo_init(void)
473 { 449 {
474 int res; 450 int res;
475 printk("foo version %s (%s)\n",FOO_VERSION,FOO_DATE);
476 451
477 if ((res = i2c_add_driver(&foo_driver))) { 452 if ((res = i2c_add_driver(&foo_driver))) {
478 printk("foo: Driver registration failed, module not inserted.\n"); 453 printk("foo: Driver registration failed, module not inserted.\n");
479 foo_cleanup();
480 return res; 454 return res;
481 } 455 }
482 foo_initialized ++;
483 return 0; 456 return 0;
484 } 457 }
485 458
486 void foo_cleanup(void) 459 static void __exit foo_cleanup(void)
487 { 460 {
488 if (foo_initialized == 1) { 461 i2c_del_driver(&foo_driver);
489 if ((res = i2c_del_driver(&foo_driver))) {
490 printk("foo: Driver registration failed, module not removed.\n");
491 return;
492 }
493 foo_initialized --;
494 }
495 } 462 }
496 463
497 /* Substitute your own name and email address */ 464 /* Substitute your own name and email address */
498 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>" 465 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"
499 MODULE_DESCRIPTION("Driver for Barf Inc. Foo I2C devices"); 466 MODULE_DESCRIPTION("Driver for Barf Inc. Foo I2C devices");
500 467
468 /* a few non-GPL license types are also allowed */
469 MODULE_LICENSE("GPL");
470
501 module_init(foo_init); 471 module_init(foo_init);
502 module_exit(foo_cleanup); 472 module_exit(foo_cleanup);
503 473
504Note that some functions are marked by `__init', and some data structures 474Note that some functions are marked by `__init', and some data structures
505by `__init_data'. Hose functions and structures can be removed after 475by `__initdata'. These functions and structures can be removed after
506kernel booting (or module loading) is completed. 476kernel booting (or module loading) is completed.
507 477
508 478
@@ -632,110 +602,7 @@ General purpose routines
632Below all general purpose routines are listed, that were not mentioned 602Below all general purpose routines are listed, that were not mentioned
633before. 603before.
634 604
635 /* This call returns a unique low identifier for each registered adapter, 605 /* This call returns a unique low identifier for each registered adapter.
636 * or -1 if the adapter was not registered.
637 */ 606 */
638 extern int i2c_adapter_id(struct i2c_adapter *adap); 607 extern int i2c_adapter_id(struct i2c_adapter *adap);
639 608
640
641The sensors sysctl/proc interface
642=================================
643
644This section only applies if you write `sensors' drivers.
645
646Each sensors driver creates a directory in /proc/sys/dev/sensors for each
647registered client. The directory is called something like foo-i2c-4-65.
648The sensors module helps you to do this as easily as possible.
649
650The template
651------------
652
653You will need to define a ctl_table template. This template will automatically
654be copied to a newly allocated structure and filled in where necessary when
655you call sensors_register_entry.
656
657First, I will give an example definition.
658 static ctl_table foo_dir_table_template[] = {
659 { FOO_SYSCTL_FUNC1, "func1", NULL, 0, 0644, NULL, &i2c_proc_real,
660 &i2c_sysctl_real,NULL,&foo_func },
661 { FOO_SYSCTL_FUNC2, "func2", NULL, 0, 0644, NULL, &i2c_proc_real,
662 &i2c_sysctl_real,NULL,&foo_func },
663 { FOO_SYSCTL_DATA, "data", NULL, 0, 0644, NULL, &i2c_proc_real,
664 &i2c_sysctl_real,NULL,&foo_data },
665 { 0 }
666 };
667
668In the above example, three entries are defined. They can either be
669accessed through the /proc interface, in the /proc/sys/dev/sensors/*
670directories, as files named func1, func2 and data, or alternatively
671through the sysctl interface, in the appropriate table, with identifiers
672FOO_SYSCTL_FUNC1, FOO_SYSCTL_FUNC2 and FOO_SYSCTL_DATA.
673
674The third, sixth and ninth parameters should always be NULL, and the
675fourth should always be 0. The fifth is the mode of the /proc file;
6760644 is safe, as the file will be owned by root:root.
677
678The seventh and eighth parameters should be &i2c_proc_real and
679&i2c_sysctl_real if you want to export lists of reals (scaled
680integers). You can also use your own function for them, as usual.
681Finally, the last parameter is the call-back to gather the data
682(see below) if you use the *_proc_real functions.
683
684
685Gathering the data
686------------------
687
688The call back functions (foo_func and foo_data in the above example)
689can be called in several ways; the operation parameter determines
690what should be done:
691
692 * If operation == SENSORS_PROC_REAL_INFO, you must return the
693 magnitude (scaling) in nrels_mag;
694 * If operation == SENSORS_PROC_REAL_READ, you must read information
695 from the chip and return it in results. The number of integers
696 to display should be put in nrels_mag;
697 * If operation == SENSORS_PROC_REAL_WRITE, you must write the
698 supplied information to the chip. nrels_mag will contain the number
699 of integers, results the integers themselves.
700
701The *_proc_real functions will display the elements as reals for the
702/proc interface. If you set the magnitude to 2, and supply 345 for
703SENSORS_PROC_REAL_READ, it would display 3.45; and if the user would
704write 45.6 to the /proc file, it would be returned as 4560 for
705SENSORS_PROC_REAL_WRITE. A magnitude may even be negative!
706
707An example function:
708
709 /* FOO_FROM_REG and FOO_TO_REG translate between scaled values and
710 register values. Note the use of the read cache. */
711 void foo_in(struct i2c_client *client, int operation, int ctl_name,
712 int *nrels_mag, long *results)
713 {
714 struct foo_data *data = client->data;
715 int nr = ctl_name - FOO_SYSCTL_FUNC1; /* reduce to 0 upwards */
716
717 if (operation == SENSORS_PROC_REAL_INFO)
718 *nrels_mag = 2;
719 else if (operation == SENSORS_PROC_REAL_READ) {
720 /* Update the readings cache (if necessary) */
721 foo_update_client(client);
722 /* Get the readings from the cache */
723 results[0] = FOO_FROM_REG(data->foo_func_base[nr]);
724 results[1] = FOO_FROM_REG(data->foo_func_more[nr]);
725 results[2] = FOO_FROM_REG(data->foo_func_readonly[nr]);
726 *nrels_mag = 2;
727 } else if (operation == SENSORS_PROC_REAL_WRITE) {
728 if (*nrels_mag >= 1) {
729 /* Update the cache */
730 data->foo_base[nr] = FOO_TO_REG(results[0]);
731 /* Update the chip */
732 foo_write_value(client,FOO_REG_FUNC_BASE(nr),data->foo_base[nr]);
733 }
734 if (*nrels_mag >= 2) {
735 /* Update the cache */
736 data->foo_more[nr] = FOO_TO_REG(results[1]);
737 /* Update the chip */
738 foo_write_value(client,FOO_REG_FUNC_MORE(nr),data->foo_more[nr]);
739 }
740 }
741 }
diff --git a/MAINTAINERS b/MAINTAINERS
index 17c5e30f20f3..1e8c37054ea2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -733,6 +733,13 @@ M: tigran@aivazian.fsnet.co.uk
733L: linux-kernel@vger.kernel.org 733L: linux-kernel@vger.kernel.org
734S: Maintained 734S: Maintained
735 735
736BLACKFIN I2C TWI DRIVER
737P: Sonic Zhang
738M: sonic.zhang@analog.com
739L: uclinux-dist-devel@blackfin.uclinux.org (subscribers-only)
740W: http://blackfin.uclinux.org/
741S: Supported
742
736BLOCK LAYER 743BLOCK LAYER
737P: Jens Axboe 744P: Jens Axboe
738M: axboe@kernel.dk 745M: axboe@kernel.dk
@@ -1459,6 +1466,11 @@ L: linux-scsi@vger.kernel.org
1459W: http://www.icp-vortex.com/ 1466W: http://www.icp-vortex.com/
1460S: Supported 1467S: Supported
1461 1468
1469GENERIC GPIO I2C DRIVER
1470P: Haavard Skinnemoen
1471M: hskinnemoen@atmel.com
1472S: Supported
1473
1462GENERIC HDLC DRIVER, N2, C101, PCI200SYN and WANXL DRIVERS 1474GENERIC HDLC DRIVER, N2, C101, PCI200SYN and WANXL DRIVERS
1463P: Krzysztof Halasa 1475P: Krzysztof Halasa
1464M: khc@pm.waw.pl 1476M: khc@pm.waw.pl
@@ -1631,6 +1643,13 @@ L: i2c@lm-sensors.org
1631T: quilt http://khali.linux-fr.org/devel/linux-2.6/jdelvare-i2c/ 1643T: quilt http://khali.linux-fr.org/devel/linux-2.6/jdelvare-i2c/
1632S: Maintained 1644S: Maintained
1633 1645
1646I2C-TINY-USB DRIVER
1647P: Till Harbaum
1648M: till@harbaum.org
1649L: i2c@lm-sensors.org
1650T: http://www.harbaum.org/till/i2c_tiny_usb
1651S: Maintained
1652
1634i386 BOOT CODE 1653i386 BOOT CODE
1635P: Riley H. Williams 1654P: Riley H. Williams
1636M: Riley@Williams.Name 1655M: Riley@Williams.Name
diff --git a/arch/powerpc/platforms/powermac/cpufreq_32.c b/arch/powerpc/platforms/powermac/cpufreq_32.c
index 8943a9456bb7..1fe35dab0e9e 100644
--- a/arch/powerpc/platforms/powermac/cpufreq_32.c
+++ b/arch/powerpc/platforms/powermac/cpufreq_32.c
@@ -25,7 +25,6 @@
25#include <linux/cpufreq.h> 25#include <linux/cpufreq.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/sysdev.h> 27#include <linux/sysdev.h>
28#include <linux/i2c.h>
29#include <linux/hardirq.h> 28#include <linux/hardirq.h>
30#include <asm/prom.h> 29#include <asm/prom.h>
31#include <asm/machdep.h> 30#include <asm/machdep.h>
diff --git a/drivers/Makefile b/drivers/Makefile
index 920c975bb6d4..26ca9031ea49 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -58,7 +58,7 @@ obj-$(CONFIG_GAMEPORT) += input/gameport/
58obj-$(CONFIG_INPUT) += input/ 58obj-$(CONFIG_INPUT) += input/
59obj-$(CONFIG_I2O) += message/ 59obj-$(CONFIG_I2O) += message/
60obj-$(CONFIG_RTC_LIB) += rtc/ 60obj-$(CONFIG_RTC_LIB) += rtc/
61obj-$(CONFIG_I2C) += i2c/ 61obj-y += i2c/
62obj-$(CONFIG_W1) += w1/ 62obj-$(CONFIG_W1) += w1/
63obj-$(CONFIG_HWMON) += hwmon/ 63obj-$(CONFIG_HWMON) += hwmon/
64obj-$(CONFIG_PHONE) += telephony/ 64obj-$(CONFIG_PHONE) += telephony/
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 11935f66fcd8..434a61b415a3 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -2,9 +2,7 @@
2# I2C subsystem configuration 2# I2C subsystem configuration
3# 3#
4 4
5menu "I2C support" 5menuconfig I2C
6
7config I2C
8 tristate "I2C support" 6 tristate "I2C support"
9 ---help--- 7 ---help---
10 I2C (pronounce: I-square-C) is a slow serial bus protocol used in 8 I2C (pronounce: I-square-C) is a slow serial bus protocol used in
@@ -22,9 +20,14 @@ config I2C
22 This I2C support can also be built as a module. If so, the module 20 This I2C support can also be built as a module. If so, the module
23 will be called i2c-core. 21 will be called i2c-core.
24 22
23if I2C
24
25config I2C_BOARDINFO
26 boolean
27 default y
28
25config I2C_CHARDEV 29config I2C_CHARDEV
26 tristate "I2C device interface" 30 tristate "I2C device interface"
27 depends on I2C
28 help 31 help
29 Say Y here to use i2c-* device files, usually found in the /dev 32 Say Y here to use i2c-* device files, usually found in the /dev
30 directory on your system. They make it possible to have user-space 33 directory on your system. They make it possible to have user-space
@@ -40,7 +43,6 @@ source drivers/i2c/chips/Kconfig
40 43
41config I2C_DEBUG_CORE 44config I2C_DEBUG_CORE
42 bool "I2C Core debugging messages" 45 bool "I2C Core debugging messages"
43 depends on I2C
44 help 46 help
45 Say Y here if you want the I2C core to produce a bunch of debug 47 Say Y here if you want the I2C core to produce a bunch of debug
46 messages to the system log. Select this if you are having a 48 messages to the system log. Select this if you are having a
@@ -48,7 +50,6 @@ config I2C_DEBUG_CORE
48 50
49config I2C_DEBUG_ALGO 51config I2C_DEBUG_ALGO
50 bool "I2C Algorithm debugging messages" 52 bool "I2C Algorithm debugging messages"
51 depends on I2C
52 help 53 help
53 Say Y here if you want the I2C algorithm drivers to produce a bunch 54 Say Y here if you want the I2C algorithm drivers to produce a bunch
54 of debug messages to the system log. Select this if you are having 55 of debug messages to the system log. Select this if you are having
@@ -57,7 +58,6 @@ config I2C_DEBUG_ALGO
57 58
58config I2C_DEBUG_BUS 59config I2C_DEBUG_BUS
59 bool "I2C Bus debugging messages" 60 bool "I2C Bus debugging messages"
60 depends on I2C
61 help 61 help
62 Say Y here if you want the I2C bus drivers to produce a bunch of 62 Say Y here if you want the I2C bus drivers to produce a bunch of
63 debug messages to the system log. Select this if you are having 63 debug messages to the system log. Select this if you are having
@@ -66,12 +66,10 @@ config I2C_DEBUG_BUS
66 66
67config I2C_DEBUG_CHIP 67config I2C_DEBUG_CHIP
68 bool "I2C Chip debugging messages" 68 bool "I2C Chip debugging messages"
69 depends on I2C
70 help 69 help
71 Say Y here if you want the I2C chip drivers to produce a bunch of 70 Say Y here if you want the I2C chip drivers to produce a bunch of
72 debug messages to the system log. Select this if you are having 71 debug messages to the system log. Select this if you are having
73 a problem with I2C support and want to see more of what is going 72 a problem with I2C support and want to see more of what is going
74 on. 73 on.
75 74
76endmenu 75endif # I2C
77
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 71c5a854ac5d..ba26e6cbe74e 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -2,6 +2,7 @@
2# Makefile for the i2c core. 2# Makefile for the i2c core.
3# 3#
4 4
5obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o
5obj-$(CONFIG_I2C) += i2c-core.o 6obj-$(CONFIG_I2C) += i2c-core.o
6obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o 7obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
7obj-y += busses/ chips/ algos/ 8obj-y += busses/ chips/ algos/
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index af0203409dd1..58899078810b 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -3,11 +3,9 @@
3# 3#
4 4
5menu "I2C Algorithms" 5menu "I2C Algorithms"
6 depends on I2C
7 6
8config I2C_ALGOBIT 7config I2C_ALGOBIT
9 tristate "I2C bit-banging interfaces" 8 tristate "I2C bit-banging interfaces"
10 depends on I2C
11 help 9 help
12 This allows you to use a range of I2C adapters called bit-banging 10 This allows you to use a range of I2C adapters called bit-banging
13 adapters. Say Y if you own an I2C adapter belonging to this class 11 adapters. Say Y if you own an I2C adapter belonging to this class
@@ -18,7 +16,6 @@ config I2C_ALGOBIT
18 16
19config I2C_ALGOPCF 17config I2C_ALGOPCF
20 tristate "I2C PCF 8584 interfaces" 18 tristate "I2C PCF 8584 interfaces"
21 depends on I2C
22 help 19 help
23 This allows you to use a range of I2C adapters called PCF adapters. 20 This allows you to use a range of I2C adapters called PCF adapters.
24 Say Y if you own an I2C adapter belonging to this class and then say 21 Say Y if you own an I2C adapter belonging to this class and then say
@@ -29,7 +26,6 @@ config I2C_ALGOPCF
29 26
30config I2C_ALGOPCA 27config I2C_ALGOPCA
31 tristate "I2C PCA 9564 interfaces" 28 tristate "I2C PCA 9564 interfaces"
32 depends on I2C
33 help 29 help
34 This allows you to use a range of I2C adapters called PCA adapters. 30 This allows you to use a range of I2C adapters called PCA adapters.
35 Say Y if you own an I2C adapter belonging to this class and then say 31 Say Y if you own an I2C adapter belonging to this class and then say
@@ -40,11 +36,11 @@ config I2C_ALGOPCA
40 36
41config I2C_ALGO8XX 37config I2C_ALGO8XX
42 tristate "MPC8xx CPM I2C interface" 38 tristate "MPC8xx CPM I2C interface"
43 depends on 8xx && I2C 39 depends on 8xx
44 40
45config I2C_ALGO_SGI 41config I2C_ALGO_SGI
46 tristate "I2C SGI interfaces" 42 tristate "I2C SGI interfaces"
47 depends on I2C && (SGI_IP22 || SGI_IP32 || X86_VISWS) 43 depends on SGI_IP22 || SGI_IP32 || X86_VISWS
48 help 44 help
49 Supports the SGI interfaces like the ones found on SGI Indy VINO 45 Supports the SGI interfaces like the ones found on SGI Indy VINO
50 or SGI O2 MACE. 46 or SGI O2 MACE.
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 95aa5395a5be..8a5f5825bb72 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -33,19 +33,30 @@
33 33
34 34
35/* ----- global defines ----------------------------------------------- */ 35/* ----- global defines ----------------------------------------------- */
36#define DEB(x) if (i2c_debug>=1) x;
37#define DEB2(x) if (i2c_debug>=2) x;
38#define DEBSTAT(x) if (i2c_debug>=3) x; /* print several statistical values*/
39#define DEBPROTO(x) if (i2c_debug>=9) { x; }
40 /* debug the protocol by showing transferred bits */
41 36
37#ifdef DEBUG
38#define bit_dbg(level, dev, format, args...) \
39 do { \
40 if (i2c_debug >= level) \
41 dev_dbg(dev, format, ##args); \
42 } while (0)
43#else
44#define bit_dbg(level, dev, format, args...) \
45 do {} while (0)
46#endif /* DEBUG */
42 47
43/* ----- global variables --------------------------------------------- */ 48/* ----- global variables --------------------------------------------- */
44 49
45/* module parameters:
46 */
47static int i2c_debug;
48static int bit_test; /* see if the line-setting functions work */ 50static int bit_test; /* see if the line-setting functions work */
51module_param(bit_test, bool, 0);
52MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
53
54#ifdef DEBUG
55static int i2c_debug = 1;
56module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
57MODULE_PARM_DESC(i2c_debug,
58 "debug level - 0 off; 1 normal; 2 verbose; 3 very verbose");
59#endif
49 60
50/* --- setting states on the bus with the right timing: --------------- */ 61/* --- setting states on the bus with the right timing: --------------- */
51 62
@@ -57,19 +68,19 @@ static int bit_test; /* see if the line-setting functions work */
57static inline void sdalo(struct i2c_algo_bit_data *adap) 68static inline void sdalo(struct i2c_algo_bit_data *adap)
58{ 69{
59 setsda(adap,0); 70 setsda(adap,0);
60 udelay(adap->udelay); 71 udelay((adap->udelay + 1) / 2);
61} 72}
62 73
63static inline void sdahi(struct i2c_algo_bit_data *adap) 74static inline void sdahi(struct i2c_algo_bit_data *adap)
64{ 75{
65 setsda(adap,1); 76 setsda(adap,1);
66 udelay(adap->udelay); 77 udelay((adap->udelay + 1) / 2);
67} 78}
68 79
69static inline void scllo(struct i2c_algo_bit_data *adap) 80static inline void scllo(struct i2c_algo_bit_data *adap)
70{ 81{
71 setscl(adap,0); 82 setscl(adap,0);
72 udelay(adap->udelay); 83 udelay(adap->udelay / 2);
73} 84}
74 85
75/* 86/*
@@ -98,7 +109,11 @@ static int sclhi(struct i2c_algo_bit_data *adap)
98 } 109 }
99 cond_resched(); 110 cond_resched();
100 } 111 }
101 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); 112#ifdef DEBUG
113 if (jiffies != start && i2c_debug >= 3)
114 pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go "
115 "high\n", jiffies - start);
116#endif
102 117
103done: 118done:
104 udelay(adap->udelay); 119 udelay(adap->udelay);
@@ -110,30 +125,29 @@ done:
110static void i2c_start(struct i2c_algo_bit_data *adap) 125static void i2c_start(struct i2c_algo_bit_data *adap)
111{ 126{
112 /* assert: scl, sda are high */ 127 /* assert: scl, sda are high */
113 DEBPROTO(printk("S ")); 128 setsda(adap, 0);
114 sdalo(adap); 129 udelay(adap->udelay);
115 scllo(adap); 130 scllo(adap);
116} 131}
117 132
118static void i2c_repstart(struct i2c_algo_bit_data *adap) 133static void i2c_repstart(struct i2c_algo_bit_data *adap)
119{ 134{
120 /* scl, sda may not be high */ 135 /* assert: scl is low */
121 DEBPROTO(printk(" Sr ")); 136 sdahi(adap);
122 setsda(adap,1);
123 sclhi(adap); 137 sclhi(adap);
124 138 setsda(adap, 0);
125 sdalo(adap); 139 udelay(adap->udelay);
126 scllo(adap); 140 scllo(adap);
127} 141}
128 142
129 143
130static void i2c_stop(struct i2c_algo_bit_data *adap) 144static void i2c_stop(struct i2c_algo_bit_data *adap)
131{ 145{
132 DEBPROTO(printk("P\n"));
133 /* assert: scl is low */ 146 /* assert: scl is low */
134 sdalo(adap); 147 sdalo(adap);
135 sclhi(adap); 148 sclhi(adap);
136 sdahi(adap); 149 setsda(adap, 1);
150 udelay(adap->udelay);
137} 151}
138 152
139 153
@@ -145,7 +159,7 @@ static void i2c_stop(struct i2c_algo_bit_data *adap)
145 * 0 if the device did not ack 159 * 0 if the device did not ack
146 * -ETIMEDOUT if an error occurred (while raising the scl line) 160 * -ETIMEDOUT if an error occurred (while raising the scl line)
147 */ 161 */
148static int i2c_outb(struct i2c_adapter *i2c_adap, char c) 162static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
149{ 163{
150 int i; 164 int i;
151 int sb; 165 int sb;
@@ -154,34 +168,32 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, char c)
154 168
155 /* assert: scl is low */ 169 /* assert: scl is low */
156 for ( i=7 ; i>=0 ; i-- ) { 170 for ( i=7 ; i>=0 ; i-- ) {
157 sb = c & ( 1 << i ); 171 sb = (c >> i) & 1;
158 setsda(adap,sb); 172 setsda(adap,sb);
159 udelay(adap->udelay); 173 udelay((adap->udelay + 1) / 2);
160 DEBPROTO(printk(KERN_DEBUG "%d",sb!=0));
161 if (sclhi(adap)<0) { /* timed out */ 174 if (sclhi(adap)<0) { /* timed out */
162 sdahi(adap); /* we don't want to block the net */ 175 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
163 DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i)); 176 "timeout at bit #%d\n", (int)c, i);
164 return -ETIMEDOUT; 177 return -ETIMEDOUT;
165 }; 178 };
166 /* do arbitration here: 179 /* do arbitration here:
167 * if ( sb && ! getsda(adap) ) -> ouch! Get out of here. 180 * if ( sb && ! getsda(adap) ) -> ouch! Get out of here.
168 */ 181 */
169 setscl(adap, 0 ); 182 scllo(adap);
170 udelay(adap->udelay);
171 } 183 }
172 sdahi(adap); 184 sdahi(adap);
173 if (sclhi(adap)<0){ /* timeout */ 185 if (sclhi(adap)<0){ /* timeout */
174 DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff)); 186 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
175 return -ETIMEDOUT; 187 "timeout at ack\n", (int)c);
188 return -ETIMEDOUT;
176 }; 189 };
177 /* read ack: SDA should be pulled down by slave */ 190 /* read ack: SDA should be pulled down by slave */
178 ack=getsda(adap); /* ack: sda is pulled low ->success. */ 191 ack = !getsda(adap); /* ack: sda is pulled low -> success */
179 DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack)); 192 bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c,
193 ack ? "A" : "NA");
180 194
181 DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) );
182 DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );
183 scllo(adap); 195 scllo(adap);
184 return 0==ack; /* return 1 if device acked */ 196 return ack;
185 /* assert: scl is low (sda undef) */ 197 /* assert: scl is low (sda undef) */
186} 198}
187 199
@@ -198,19 +210,18 @@ static int i2c_inb(struct i2c_adapter *i2c_adap)
198 sdahi(adap); 210 sdahi(adap);
199 for (i=0;i<8;i++) { 211 for (i=0;i<8;i++) {
200 if (sclhi(adap)<0) { /* timeout */ 212 if (sclhi(adap)<0) { /* timeout */
201 DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i)); 213 bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit "
214 "#%d\n", 7 - i);
202 return -ETIMEDOUT; 215 return -ETIMEDOUT;
203 }; 216 };
204 indata *= 2; 217 indata *= 2;
205 if ( getsda(adap) ) 218 if ( getsda(adap) )
206 indata |= 0x01; 219 indata |= 0x01;
207 scllo(adap); 220 setscl(adap, 0);
221 udelay(i == 7 ? adap->udelay / 2 : adap->udelay);
208 } 222 }
209 /* assert: scl is low */ 223 /* assert: scl is low */
210 DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff)); 224 return indata;
211
212 DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
213 return (int) (indata & 0xff);
214} 225}
215 226
216/* 227/*
@@ -221,73 +232,67 @@ static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
221 int scl,sda; 232 int scl,sda;
222 233
223 if (adap->getscl==NULL) 234 if (adap->getscl==NULL)
224 printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, " 235 pr_info("%s: Testing SDA only, SCL is not readable\n", name);
225 "SCL is not readable.\n");
226 236
227 sda=getsda(adap); 237 sda=getsda(adap);
228 scl=(adap->getscl==NULL?1:getscl(adap)); 238 scl=(adap->getscl==NULL?1:getscl(adap));
229 printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda);
230 if (!scl || !sda ) { 239 if (!scl || !sda ) {
231 printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name); 240 printk(KERN_WARNING "%s: bus seems to be busy\n", name);
232 goto bailout; 241 goto bailout;
233 } 242 }
234 243
235 sdalo(adap); 244 sdalo(adap);
236 sda=getsda(adap); 245 sda=getsda(adap);
237 scl=(adap->getscl==NULL?1:getscl(adap)); 246 scl=(adap->getscl==NULL?1:getscl(adap));
238 printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda);
239 if ( 0 != sda ) { 247 if ( 0 != sda ) {
240 printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n"); 248 printk(KERN_WARNING "%s: SDA stuck high!\n", name);
241 goto bailout; 249 goto bailout;
242 } 250 }
243 if ( 0 == scl ) { 251 if ( 0 == scl ) {
244 printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low " 252 printk(KERN_WARNING "%s: SCL unexpected low "
245 "while pulling SDA low!\n"); 253 "while pulling SDA low!\n", name);
246 goto bailout; 254 goto bailout;
247 } 255 }
248 256
249 sdahi(adap); 257 sdahi(adap);
250 sda=getsda(adap); 258 sda=getsda(adap);
251 scl=(adap->getscl==NULL?1:getscl(adap)); 259 scl=(adap->getscl==NULL?1:getscl(adap));
252 printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda);
253 if ( 0 == sda ) { 260 if ( 0 == sda ) {
254 printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n"); 261 printk(KERN_WARNING "%s: SDA stuck low!\n", name);
255 goto bailout; 262 goto bailout;
256 } 263 }
257 if ( 0 == scl ) { 264 if ( 0 == scl ) {
258 printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low " 265 printk(KERN_WARNING "%s: SCL unexpected low "
259 "while pulling SDA high!\n"); 266 "while pulling SDA high!\n", name);
260 goto bailout; 267 goto bailout;
261 } 268 }
262 269
263 scllo(adap); 270 scllo(adap);
264 sda=getsda(adap); 271 sda=getsda(adap);
265 scl=(adap->getscl==NULL?0:getscl(adap)); 272 scl=(adap->getscl==NULL?0:getscl(adap));
266 printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda);
267 if ( 0 != scl ) { 273 if ( 0 != scl ) {
268 printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n"); 274 printk(KERN_WARNING "%s: SCL stuck high!\n", name);
269 goto bailout; 275 goto bailout;
270 } 276 }
271 if ( 0 == sda ) { 277 if ( 0 == sda ) {
272 printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low " 278 printk(KERN_WARNING "%s: SDA unexpected low "
273 "while pulling SCL low!\n"); 279 "while pulling SCL low!\n", name);
274 goto bailout; 280 goto bailout;
275 } 281 }
276 282
277 sclhi(adap); 283 sclhi(adap);
278 sda=getsda(adap); 284 sda=getsda(adap);
279 scl=(adap->getscl==NULL?1:getscl(adap)); 285 scl=(adap->getscl==NULL?1:getscl(adap));
280 printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda);
281 if ( 0 == scl ) { 286 if ( 0 == scl ) {
282 printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n"); 287 printk(KERN_WARNING "%s: SCL stuck low!\n", name);
283 goto bailout; 288 goto bailout;
284 } 289 }
285 if ( 0 == sda ) { 290 if ( 0 == sda ) {
286 printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low " 291 printk(KERN_WARNING "%s: SDA unexpected low "
287 "while pulling SCL high!\n"); 292 "while pulling SCL high!\n", name);
288 goto bailout; 293 goto bailout;
289 } 294 }
290 printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name); 295 pr_info("%s: Test OK\n", name);
291 return 0; 296 return 0;
292bailout: 297bailout:
293 sdahi(adap); 298 sdahi(adap);
@@ -312,44 +317,39 @@ static int try_address(struct i2c_adapter *i2c_adap,
312 int i,ret = -1; 317 int i,ret = -1;
313 for (i=0;i<=retries;i++) { 318 for (i=0;i<=retries;i++) {
314 ret = i2c_outb(i2c_adap,addr); 319 ret = i2c_outb(i2c_adap,addr);
315 if (ret==1) 320 if (ret == 1 || i == retries)
316 break; /* success! */
317 i2c_stop(adap);
318 udelay(5/*adap->udelay*/);
319 if (i==retries) /* no success */
320 break; 321 break;
321 i2c_start(adap); 322 bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
323 i2c_stop(adap);
322 udelay(adap->udelay); 324 udelay(adap->udelay);
325 yield();
326 bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
327 i2c_start(adap);
323 } 328 }
324 DEB2(if (i) 329 if (i && ret)
325 printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n", 330 bit_dbg(1, &i2c_adap->dev, "Used %d tries to %s client at "
326 i+1, addr & 1 ? "read" : "write", addr>>1, 331 "0x%02x: %s\n", i + 1,
327 ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" ) 332 addr & 1 ? "read from" : "write to", addr >> 1,
328 ); 333 ret == 1 ? "success" : "failed, timeout?");
329 return ret; 334 return ret;
330} 335}
331 336
332static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 337static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
333{ 338{
334 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 339 const unsigned char *temp = msg->buf;
335 char c;
336 const char *temp = msg->buf;
337 int count = msg->len; 340 int count = msg->len;
338 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; 341 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
339 int retval; 342 int retval;
340 int wrcount=0; 343 int wrcount=0;
341 344
342 while (count > 0) { 345 while (count > 0) {
343 c = *temp; 346 retval = i2c_outb(i2c_adap, *temp);
344 DEB2(dev_dbg(&i2c_adap->dev, "sendbytes: writing %2.2X\n", c&0xff));
345 retval = i2c_outb(i2c_adap,c);
346 if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */ 347 if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */
347 count--; 348 count--;
348 temp++; 349 temp++;
349 wrcount++; 350 wrcount++;
350 } else { /* arbitration or no acknowledge */ 351 } else { /* arbitration or no acknowledge */
351 dev_err(&i2c_adap->dev, "sendbytes: error - bailout.\n"); 352 dev_err(&i2c_adap->dev, "sendbytes: error - bailout.\n");
352 i2c_stop(adap);
353 return (retval<0)? retval : -EFAULT; 353 return (retval<0)? retval : -EFAULT;
354 /* got a better one ?? */ 354 /* got a better one ?? */
355 } 355 }
@@ -362,7 +362,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
362 int inval; 362 int inval;
363 int rdcount=0; /* counts bytes read */ 363 int rdcount=0; /* counts bytes read */
364 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 364 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
365 char *temp = msg->buf; 365 unsigned char *temp = msg->buf;
366 int count = msg->len; 366 int count = msg->len;
367 367
368 while (count > 0) { 368 while (count > 0) {
@@ -371,30 +371,44 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
371 *temp = inval; 371 *temp = inval;
372 rdcount++; 372 rdcount++;
373 } else { /* read timed out */ 373 } else { /* read timed out */
374 printk(KERN_ERR "i2c-algo-bit.o: readbytes: i2c_inb timed out.\n");
375 break; 374 break;
376 } 375 }
377 376
378 temp++; 377 temp++;
379 count--; 378 count--;
380 379
381 if (msg->flags & I2C_M_NO_RD_ACK) 380 if (msg->flags & I2C_M_NO_RD_ACK) {
381 bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x\n",
382 inval);
382 continue; 383 continue;
383
384 if ( count > 0 ) { /* send ack */
385 sdalo(adap);
386 DEBPROTO(printk(" Am "));
387 } else {
388 sdahi(adap); /* neg. ack on last byte */
389 DEBPROTO(printk(" NAm "));
390 } 384 }
385
386 /* assert: sda is high */
387 if (count) /* send ack */
388 setsda(adap, 0);
389 udelay((adap->udelay + 1) / 2);
390 bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x %s\n", inval,
391 count ? "A" : "NA");
391 if (sclhi(adap)<0) { /* timeout */ 392 if (sclhi(adap)<0) { /* timeout */
392 sdahi(adap); 393 dev_err(&i2c_adap->dev, "readbytes: timeout at ack\n");
393 printk(KERN_ERR "i2c-algo-bit.o: readbytes: Timeout at ack\n");
394 return -ETIMEDOUT; 394 return -ETIMEDOUT;
395 }; 395 };
396 scllo(adap); 396 scllo(adap);
397 sdahi(adap); 397
398 /* Some SMBus transactions require that we receive the
399 transaction length as the first read byte. */
400 if (rdcount == 1 && (msg->flags & I2C_M_RECV_LEN)) {
401 if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) {
402 dev_err(&i2c_adap->dev, "readbytes: invalid "
403 "block length (%d)\n", inval);
404 return -EREMOTEIO;
405 }
406 /* The original count value accounts for the extra
407 bytes, that is, either 1 for a regular transaction,
408 or 2 for a PEC transaction. */
409 count += inval;
410 msg->len += inval;
411 }
398 } 412 }
399 return rdcount; 413 return rdcount;
400} 414}
@@ -421,27 +435,31 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
421 if ( (flags & I2C_M_TEN) ) { 435 if ( (flags & I2C_M_TEN) ) {
422 /* a ten bit address */ 436 /* a ten bit address */
423 addr = 0xf0 | (( msg->addr >> 7) & 0x03); 437 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
424 DEB2(printk(KERN_DEBUG "addr0: %d\n",addr)); 438 bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr);
425 /* try extended address code...*/ 439 /* try extended address code...*/
426 ret = try_address(i2c_adap, addr, retries); 440 ret = try_address(i2c_adap, addr, retries);
427 if ((ret != 1) && !nak_ok) { 441 if ((ret != 1) && !nak_ok) {
428 printk(KERN_ERR "died at extended address code.\n"); 442 dev_err(&i2c_adap->dev,
443 "died at extended address code\n");
429 return -EREMOTEIO; 444 return -EREMOTEIO;
430 } 445 }
431 /* the remaining 8 bit address */ 446 /* the remaining 8 bit address */
432 ret = i2c_outb(i2c_adap,msg->addr & 0x7f); 447 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
433 if ((ret != 1) && !nak_ok) { 448 if ((ret != 1) && !nak_ok) {
434 /* the chip did not ack / xmission error occurred */ 449 /* the chip did not ack / xmission error occurred */
435 printk(KERN_ERR "died at 2nd address code.\n"); 450 dev_err(&i2c_adap->dev, "died at 2nd address code\n");
436 return -EREMOTEIO; 451 return -EREMOTEIO;
437 } 452 }
438 if ( flags & I2C_M_RD ) { 453 if ( flags & I2C_M_RD ) {
454 bit_dbg(3, &i2c_adap->dev, "emitting repeated "
455 "start condition\n");
439 i2c_repstart(adap); 456 i2c_repstart(adap);
440 /* okay, now switch into reading mode */ 457 /* okay, now switch into reading mode */
441 addr |= 0x01; 458 addr |= 0x01;
442 ret = try_address(i2c_adap, addr, retries); 459 ret = try_address(i2c_adap, addr, retries);
443 if ((ret!=1) && !nak_ok) { 460 if ((ret!=1) && !nak_ok) {
444 printk(KERN_ERR "died at extended address code.\n"); 461 dev_err(&i2c_adap->dev,
462 "died at repeated address code\n");
445 return -EREMOTEIO; 463 return -EREMOTEIO;
446 } 464 }
447 } 465 }
@@ -468,44 +486,62 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
468 int i,ret; 486 int i,ret;
469 unsigned short nak_ok; 487 unsigned short nak_ok;
470 488
489 bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
471 i2c_start(adap); 490 i2c_start(adap);
472 for (i=0;i<num;i++) { 491 for (i=0;i<num;i++) {
473 pmsg = &msgs[i]; 492 pmsg = &msgs[i];
474 nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; 493 nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
475 if (!(pmsg->flags & I2C_M_NOSTART)) { 494 if (!(pmsg->flags & I2C_M_NOSTART)) {
476 if (i) { 495 if (i) {
496 bit_dbg(3, &i2c_adap->dev, "emitting "
497 "repeated start condition\n");
477 i2c_repstart(adap); 498 i2c_repstart(adap);
478 } 499 }
479 ret = bit_doAddress(i2c_adap, pmsg); 500 ret = bit_doAddress(i2c_adap, pmsg);
480 if ((ret != 0) && !nak_ok) { 501 if ((ret != 0) && !nak_ok) {
481 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n" 502 bit_dbg(1, &i2c_adap->dev, "NAK from "
482 ,msgs[i].addr,i)); 503 "device addr 0x%02x msg #%d\n",
483 return (ret<0) ? ret : -EREMOTEIO; 504 msgs[i].addr, i);
505 goto bailout;
484 } 506 }
485 } 507 }
486 if (pmsg->flags & I2C_M_RD ) { 508 if (pmsg->flags & I2C_M_RD ) {
487 /* read bytes into buffer*/ 509 /* read bytes into buffer*/
488 ret = readbytes(i2c_adap, pmsg); 510 ret = readbytes(i2c_adap, pmsg);
489 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret)); 511 if (ret >= 1)
490 if (ret < pmsg->len ) { 512 bit_dbg(2, &i2c_adap->dev, "read %d byte%s\n",
491 return (ret<0)? ret : -EREMOTEIO; 513 ret, ret == 1 ? "" : "s");
514 if (ret < pmsg->len) {
515 if (ret >= 0)
516 ret = -EREMOTEIO;
517 goto bailout;
492 } 518 }
493 } else { 519 } else {
494 /* write bytes from buffer */ 520 /* write bytes from buffer */
495 ret = sendbytes(i2c_adap, pmsg); 521 ret = sendbytes(i2c_adap, pmsg);
496 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret)); 522 if (ret >= 1)
497 if (ret < pmsg->len ) { 523 bit_dbg(2, &i2c_adap->dev, "wrote %d byte%s\n",
498 return (ret<0) ? ret : -EREMOTEIO; 524 ret, ret == 1 ? "" : "s");
525 if (ret < pmsg->len) {
526 if (ret >= 0)
527 ret = -EREMOTEIO;
528 goto bailout;
499 } 529 }
500 } 530 }
501 } 531 }
532 ret = i;
533
534bailout:
535 bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
502 i2c_stop(adap); 536 i2c_stop(adap);
503 return num; 537 return ret;
504} 538}
505 539
506static u32 bit_func(struct i2c_adapter *adap) 540static u32 bit_func(struct i2c_adapter *adap)
507{ 541{
508 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 542 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
543 I2C_FUNC_SMBUS_READ_BLOCK_DATA |
544 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
509 I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; 545 I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
510} 546}
511 547
@@ -520,7 +556,7 @@ static const struct i2c_algorithm i2c_bit_algo = {
520/* 556/*
521 * registering functions to load algorithms at runtime 557 * registering functions to load algorithms at runtime
522 */ 558 */
523int i2c_bit_add_bus(struct i2c_adapter *adap) 559static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
524{ 560{
525 struct i2c_algo_bit_data *bit_adap = adap->algo_data; 561 struct i2c_algo_bit_data *bit_adap = adap->algo_data;
526 562
@@ -530,25 +566,39 @@ int i2c_bit_add_bus(struct i2c_adapter *adap)
530 return -ENODEV; 566 return -ENODEV;
531 } 567 }
532 568
533 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n"));
534
535 /* register new adapter to i2c module... */ 569 /* register new adapter to i2c module... */
536 adap->algo = &i2c_bit_algo; 570 adap->algo = &i2c_bit_algo;
537 571
538 adap->timeout = 100; /* default values, should */ 572 adap->timeout = 100; /* default values, should */
539 adap->retries = 3; /* be replaced by defines */ 573 adap->retries = 3; /* be replaced by defines */
540 574
575 return 0;
576}
577
578int i2c_bit_add_bus(struct i2c_adapter *adap)
579{
580 int err;
581
582 err = i2c_bit_prepare_bus(adap);
583 if (err)
584 return err;
585
541 return i2c_add_adapter(adap); 586 return i2c_add_adapter(adap);
542} 587}
543EXPORT_SYMBOL(i2c_bit_add_bus); 588EXPORT_SYMBOL(i2c_bit_add_bus);
544 589
590int i2c_bit_add_numbered_bus(struct i2c_adapter *adap)
591{
592 int err;
593
594 err = i2c_bit_prepare_bus(adap);
595 if (err)
596 return err;
597
598 return i2c_add_numbered_adapter(adap);
599}
600EXPORT_SYMBOL(i2c_bit_add_numbered_bus);
601
545MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); 602MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
546MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); 603MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
547MODULE_LICENSE("GPL"); 604MODULE_LICENSE("GPL");
548
549module_param(bit_test, bool, 0);
550module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
551
552MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
553MODULE_PARM_DESC(i2c_debug,
554 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c
index ac2d5053078a..6eaf145e1ada 100644
--- a/drivers/i2c/algos/i2c-algo-sgi.c
+++ b/drivers/i2c/algos/i2c-algo-sgi.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * i2c-algo-sgi.c: i2c driver algorithms for SGI adapters. 2 * i2c-algo-sgi.c: i2c driver algorithm used by the VINO (SGI Indy) and
3 * 3 * MACE (SGI O2) chips.
4 *
4 * This file is subject to the terms and conditions of the GNU General Public 5 * This file is subject to the terms and conditions of the GNU General Public
5 * License version 2 as published by the Free Software Foundation. 6 * License version 2 as published by the Free Software Foundation.
6 * 7 *
@@ -162,8 +163,8 @@ static const struct i2c_algorithm sgi_algo = {
162 .functionality = sgi_func, 163 .functionality = sgi_func,
163}; 164};
164 165
165/* 166/*
166 * registering functions to load algorithms at runtime 167 * registering functions to load algorithms at runtime
167 */ 168 */
168int i2c_sgi_add_bus(struct i2c_adapter *adap) 169int i2c_sgi_add_bus(struct i2c_adapter *adap)
169{ 170{
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index ece31d2c6c64..838dc1c19d61 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -3,11 +3,10 @@
3# 3#
4 4
5menu "I2C Hardware Bus support" 5menu "I2C Hardware Bus support"
6 depends on I2C
7 6
8config I2C_ALI1535 7config I2C_ALI1535
9 tristate "ALI 1535" 8 tristate "ALI 1535"
10 depends on I2C && PCI 9 depends on PCI
11 help 10 help
12 If you say yes to this option, support will be included for the SMB 11 If you say yes to this option, support will be included for the SMB
13 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB 12 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB
@@ -19,7 +18,7 @@ config I2C_ALI1535
19 18
20config I2C_ALI1563 19config I2C_ALI1563
21 tristate "ALI 1563" 20 tristate "ALI 1563"
22 depends on I2C && PCI && EXPERIMENTAL 21 depends on PCI && EXPERIMENTAL
23 help 22 help
24 If you say yes to this option, support will be included for the SMB 23 If you say yes to this option, support will be included for the SMB
25 Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB 24 Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB
@@ -31,7 +30,7 @@ config I2C_ALI1563
31 30
32config I2C_ALI15X3 31config I2C_ALI15X3
33 tristate "ALI 15x3" 32 tristate "ALI 15x3"
34 depends on I2C && PCI 33 depends on PCI
35 help 34 help
36 If you say yes to this option, support will be included for the 35 If you say yes to this option, support will be included for the
37 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces. 36 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces.
@@ -41,7 +40,7 @@ config I2C_ALI15X3
41 40
42config I2C_AMD756 41config I2C_AMD756
43 tristate "AMD 756/766/768/8111 and nVidia nForce" 42 tristate "AMD 756/766/768/8111 and nVidia nForce"
44 depends on I2C && PCI 43 depends on PCI
45 help 44 help
46 If you say yes to this option, support will be included for the AMD 45 If you say yes to this option, support will be included for the AMD
47 756/766/768 mainboard I2C interfaces. The driver also includes 46 756/766/768 mainboard I2C interfaces. The driver also includes
@@ -66,7 +65,7 @@ config I2C_AMD756_S4882
66 65
67config I2C_AMD8111 66config I2C_AMD8111
68 tristate "AMD 8111" 67 tristate "AMD 8111"
69 depends on I2C && PCI 68 depends on PCI
70 help 69 help
71 If you say yes to this option, support will be included for the 70 If you say yes to this option, support will be included for the
72 second (SMBus 2.0) AMD 8111 mainboard I2C interface. 71 second (SMBus 2.0) AMD 8111 mainboard I2C interface.
@@ -76,14 +75,14 @@ config I2C_AMD8111
76 75
77config I2C_AT91 76config I2C_AT91
78 tristate "Atmel AT91 I2C Two-Wire interface (TWI)" 77 tristate "Atmel AT91 I2C Two-Wire interface (TWI)"
79 depends on I2C && ARCH_AT91 && EXPERIMENTAL 78 depends on ARCH_AT91 && EXPERIMENTAL
80 help 79 help
81 This supports the use of the I2C interface on Atmel AT91 80 This supports the use of the I2C interface on Atmel AT91
82 processors. 81 processors.
83 82
84config I2C_AU1550 83config I2C_AU1550
85 tristate "Au1550/Au1200 SMBus interface" 84 tristate "Au1550/Au1200 SMBus interface"
86 depends on I2C && (SOC_AU1550 || SOC_AU1200) 85 depends on SOC_AU1550 || SOC_AU1200
87 help 86 help
88 If you say yes to this option, support will be included for the 87 If you say yes to this option, support will be included for the
89 Au1550 and Au1200 SMBus interface. 88 Au1550 and Au1200 SMBus interface.
@@ -91,9 +90,25 @@ config I2C_AU1550
91 This driver can also be built as a module. If so, the module 90 This driver can also be built as a module. If so, the module
92 will be called i2c-au1550. 91 will be called i2c-au1550.
93 92
93config I2C_BLACKFIN_TWI
94 tristate "Blackfin TWI I2C support"
95 depends on BF534 || BF536 || BF537
96 help
97 This is the TWI I2C device driver for Blackfin 534/536/537.
98 This driver can also be built as a module. If so, the module
99 will be called i2c-bfin-twi.
100
101config I2C_BLACKFIN_TWI_CLK_KHZ
102 int "Blackfin TWI I2C clock (kHz)"
103 depends on I2C_BLACKFIN_TWI
104 range 10 400
105 default 50
106 help
107 The unit of the TWI clock is kHz.
108
94config I2C_ELEKTOR 109config I2C_ELEKTOR
95 tristate "Elektor ISA card" 110 tristate "Elektor ISA card"
96 depends on I2C && ISA && BROKEN_ON_SMP 111 depends on ISA && BROKEN_ON_SMP
97 select I2C_ALGOPCF 112 select I2C_ALGOPCF
98 help 113 help
99 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own 114 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own
@@ -102,9 +117,17 @@ config I2C_ELEKTOR
102 This support is also available as a module. If so, the module 117 This support is also available as a module. If so, the module
103 will be called i2c-elektor. 118 will be called i2c-elektor.
104 119
120config I2C_GPIO
121 tristate "GPIO-based bitbanging I2C"
122 depends on GENERIC_GPIO
123 select I2C_ALGOBIT
124 help
125 This is a very simple bitbanging I2C driver utilizing the
126 arch-neutral GPIO API to control the SCL and SDA lines.
127
105config I2C_HYDRA 128config I2C_HYDRA
106 tristate "CHRP Apple Hydra Mac I/O I2C interface" 129 tristate "CHRP Apple Hydra Mac I/O I2C interface"
107 depends on I2C && PCI && PPC_CHRP && EXPERIMENTAL 130 depends on PCI && PPC_CHRP && EXPERIMENTAL
108 select I2C_ALGOBIT 131 select I2C_ALGOBIT
109 help 132 help
110 This supports the use of the I2C interface in the Apple Hydra Mac 133 This supports the use of the I2C interface in the Apple Hydra Mac
@@ -116,7 +139,7 @@ config I2C_HYDRA
116 139
117config I2C_I801 140config I2C_I801
118 tristate "Intel 82801 (ICH)" 141 tristate "Intel 82801 (ICH)"
119 depends on I2C && PCI 142 depends on PCI
120 help 143 help
121 If you say yes to this option, support will be included for the Intel 144 If you say yes to this option, support will be included for the Intel
122 801 family of mainboard I2C interfaces. Specifically, the following 145 801 family of mainboard I2C interfaces. Specifically, the following
@@ -139,7 +162,7 @@ config I2C_I801
139 162
140config I2C_I810 163config I2C_I810
141 tristate "Intel 810/815" 164 tristate "Intel 810/815"
142 depends on I2C && PCI 165 depends on PCI
143 select I2C_ALGOBIT 166 select I2C_ALGOBIT
144 help 167 help
145 If you say yes to this option, support will be included for the Intel 168 If you say yes to this option, support will be included for the Intel
@@ -156,7 +179,7 @@ config I2C_I810
156 179
157config I2C_PXA 180config I2C_PXA
158 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)" 181 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)"
159 depends on I2C && EXPERIMENTAL && ARCH_PXA 182 depends on EXPERIMENTAL && ARCH_PXA
160 help 183 help
161 If you have devices in the PXA I2C bus, say yes to this option. 184 If you have devices in the PXA I2C bus, say yes to this option.
162 This driver can also be built as a module. If so, the module 185 This driver can also be built as a module. If so, the module
@@ -172,7 +195,7 @@ config I2C_PXA_SLAVE
172 195
173config I2C_PIIX4 196config I2C_PIIX4
174 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)" 197 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)"
175 depends on I2C && PCI 198 depends on PCI
176 help 199 help
177 If you say yes to this option, support will be included for the Intel 200 If you say yes to this option, support will be included for the Intel
178 PIIX4 family of mainboard I2C interfaces. Specifically, the following 201 PIIX4 family of mainboard I2C interfaces. Specifically, the following
@@ -195,7 +218,7 @@ config I2C_PIIX4
195 218
196config I2C_IBM_IIC 219config I2C_IBM_IIC
197 tristate "IBM PPC 4xx on-chip I2C interface" 220 tristate "IBM PPC 4xx on-chip I2C interface"
198 depends on IBM_OCP && I2C 221 depends on IBM_OCP
199 help 222 help
200 Say Y here if you want to use IIC peripheral found on 223 Say Y here if you want to use IIC peripheral found on
201 embedded IBM PPC 4xx based systems. 224 embedded IBM PPC 4xx based systems.
@@ -205,7 +228,7 @@ config I2C_IBM_IIC
205 228
206config I2C_IOP3XX 229config I2C_IOP3XX
207 tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" 230 tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface"
208 depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX) && I2C 231 depends on ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX
209 help 232 help
210 Say Y here if you want to use the IIC bus controller on 233 Say Y here if you want to use the IIC bus controller on
211 the Intel IOPx3xx I/O Processors or IXP4xx Network Processors. 234 the Intel IOPx3xx I/O Processors or IXP4xx Network Processors.
@@ -215,11 +238,10 @@ config I2C_IOP3XX
215 238
216config I2C_ISA 239config I2C_ISA
217 tristate 240 tristate
218 depends on I2C
219 241
220config I2C_IXP4XX 242config I2C_IXP4XX
221 tristate "IXP4xx GPIO-Based I2C Interface" 243 tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)"
222 depends on I2C && ARCH_IXP4XX 244 depends on ARCH_IXP4XX
223 select I2C_ALGOBIT 245 select I2C_ALGOBIT
224 help 246 help
225 Say Y here if you have an Intel IXP4xx(420,421,422,425) based 247 Say Y here if you have an Intel IXP4xx(420,421,422,425) based
@@ -228,9 +250,12 @@ config I2C_IXP4XX
228 This support is also available as a module. If so, the module 250 This support is also available as a module. If so, the module
229 will be called i2c-ixp4xx. 251 will be called i2c-ixp4xx.
230 252
253 This driver is deprecated and will be dropped soon. Use i2c-gpio
254 instead.
255
231config I2C_IXP2000 256config I2C_IXP2000
232 tristate "IXP2000 GPIO-Based I2C Interface" 257 tristate "IXP2000 GPIO-Based I2C Interface (DEPRECATED)"
233 depends on I2C && ARCH_IXP2000 258 depends on ARCH_IXP2000
234 select I2C_ALGOBIT 259 select I2C_ALGOBIT
235 help 260 help
236 Say Y here if you have an Intel IXP2000(2400, 2800, 2850) based 261 Say Y here if you have an Intel IXP2000(2400, 2800, 2850) based
@@ -239,9 +264,12 @@ config I2C_IXP2000
239 This support is also available as a module. If so, the module 264 This support is also available as a module. If so, the module
240 will be called i2c-ixp2000. 265 will be called i2c-ixp2000.
241 266
267 This driver is deprecated and will be dropped soon. Use i2c-gpio
268 instead.
269
242config I2C_POWERMAC 270config I2C_POWERMAC
243 tristate "Powermac I2C interface" 271 tristate "Powermac I2C interface"
244 depends on I2C && PPC_PMAC 272 depends on PPC_PMAC
245 default y 273 default y
246 help 274 help
247 This exposes the various PowerMac i2c interfaces to the linux i2c 275 This exposes the various PowerMac i2c interfaces to the linux i2c
@@ -253,7 +281,7 @@ config I2C_POWERMAC
253 281
254config I2C_MPC 282config I2C_MPC
255 tristate "MPC107/824x/85xx/52xx/86xx" 283 tristate "MPC107/824x/85xx/52xx/86xx"
256 depends on I2C && PPC32 284 depends on PPC32
257 help 285 help
258 If you say yes to this option, support will be included for the 286 If you say yes to this option, support will be included for the
259 built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and 287 built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and
@@ -265,7 +293,7 @@ config I2C_MPC
265 293
266config I2C_NFORCE2 294config I2C_NFORCE2
267 tristate "Nvidia nForce2, nForce3 and nForce4" 295 tristate "Nvidia nForce2, nForce3 and nForce4"
268 depends on I2C && PCI 296 depends on PCI
269 help 297 help
270 If you say yes to this option, support will be included for the Nvidia 298 If you say yes to this option, support will be included for the Nvidia
271 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces. 299 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces.
@@ -275,7 +303,7 @@ config I2C_NFORCE2
275 303
276config I2C_OCORES 304config I2C_OCORES
277 tristate "OpenCores I2C Controller" 305 tristate "OpenCores I2C Controller"
278 depends on I2C && EXPERIMENTAL 306 depends on EXPERIMENTAL
279 help 307 help
280 If you say yes to this option, support will be included for the 308 If you say yes to this option, support will be included for the
281 OpenCores I2C controller. For details see 309 OpenCores I2C controller. For details see
@@ -286,7 +314,7 @@ config I2C_OCORES
286 314
287config I2C_OMAP 315config I2C_OMAP
288 tristate "OMAP I2C adapter" 316 tristate "OMAP I2C adapter"
289 depends on I2C && ARCH_OMAP 317 depends on ARCH_OMAP
290 default y if MACH_OMAP_H3 || MACH_OMAP_OSK 318 default y if MACH_OMAP_H3 || MACH_OMAP_OSK
291 help 319 help
292 If you say yes to this option, support will be included for the 320 If you say yes to this option, support will be included for the
@@ -296,7 +324,7 @@ config I2C_OMAP
296 324
297config I2C_PARPORT 325config I2C_PARPORT
298 tristate "Parallel port adapter" 326 tristate "Parallel port adapter"
299 depends on I2C && PARPORT 327 depends on PARPORT
300 select I2C_ALGOBIT 328 select I2C_ALGOBIT
301 help 329 help
302 This supports parallel port I2C adapters such as the ones made by 330 This supports parallel port I2C adapters such as the ones made by
@@ -320,7 +348,6 @@ config I2C_PARPORT
320 348
321config I2C_PARPORT_LIGHT 349config I2C_PARPORT_LIGHT
322 tristate "Parallel port adapter (light)" 350 tristate "Parallel port adapter (light)"
323 depends on I2C
324 select I2C_ALGOBIT 351 select I2C_ALGOBIT
325 help 352 help
326 This supports parallel port I2C adapters such as the ones made by 353 This supports parallel port I2C adapters such as the ones made by
@@ -344,13 +371,13 @@ config I2C_PARPORT_LIGHT
344 371
345config I2C_PASEMI 372config I2C_PASEMI
346 tristate "PA Semi SMBus interface" 373 tristate "PA Semi SMBus interface"
347 depends on PPC_PASEMI && I2C && PCI 374 depends on PPC_PASEMI && PCI
348 help 375 help
349 Supports the PA Semi PWRficient on-chip SMBus interfaces. 376 Supports the PA Semi PWRficient on-chip SMBus interfaces.
350 377
351config I2C_PROSAVAGE 378config I2C_PROSAVAGE
352 tristate "S3/VIA (Pro)Savage" 379 tristate "S3/VIA (Pro)Savage"
353 depends on I2C && PCI 380 depends on PCI
354 select I2C_ALGOBIT 381 select I2C_ALGOBIT
355 help 382 help
356 If you say yes to this option, support will be included for the 383 If you say yes to this option, support will be included for the
@@ -365,19 +392,19 @@ config I2C_PROSAVAGE
365 392
366config I2C_RPXLITE 393config I2C_RPXLITE
367 tristate "Embedded Planet RPX Lite/Classic support" 394 tristate "Embedded Planet RPX Lite/Classic support"
368 depends on (RPXLITE || RPXCLASSIC) && I2C 395 depends on RPXLITE || RPXCLASSIC
369 select I2C_ALGO8XX 396 select I2C_ALGO8XX
370 397
371config I2C_S3C2410 398config I2C_S3C2410
372 tristate "S3C2410 I2C Driver" 399 tristate "S3C2410 I2C Driver"
373 depends on I2C && ARCH_S3C2410 400 depends on ARCH_S3C2410
374 help 401 help
375 Say Y here to include support for I2C controller in the 402 Say Y here to include support for I2C controller in the
376 Samsung S3C2410 based System-on-Chip devices. 403 Samsung S3C2410 based System-on-Chip devices.
377 404
378config I2C_SAVAGE4 405config I2C_SAVAGE4
379 tristate "S3 Savage 4" 406 tristate "S3 Savage 4"
380 depends on I2C && PCI && EXPERIMENTAL 407 depends on PCI && EXPERIMENTAL
381 select I2C_ALGOBIT 408 select I2C_ALGOBIT
382 help 409 help
383 If you say yes to this option, support will be included for the 410 If you say yes to this option, support will be included for the
@@ -388,13 +415,25 @@ config I2C_SAVAGE4
388 415
389config I2C_SIBYTE 416config I2C_SIBYTE
390 tristate "SiByte SMBus interface" 417 tristate "SiByte SMBus interface"
391 depends on SIBYTE_SB1xxx_SOC && I2C 418 depends on SIBYTE_SB1xxx_SOC
392 help 419 help
393 Supports the SiByte SOC on-chip I2C interfaces (2 channels). 420 Supports the SiByte SOC on-chip I2C interfaces (2 channels).
394 421
422config I2C_SIMTEC
423 tristate "Simtec Generic I2C interface"
424 select I2C_ALGOBIT
425 help
426 If you say yes to this option, support will be inclyded for
427 the Simtec Generic I2C interface. This driver is for the
428 simple I2C bus used on newer Simtec products for general
429 I2C, such as DDC on the Simtec BBD2016A.
430
431 This driver can also be build as a module. If so, the module
432 will be called i2c-simtec.
433
395config SCx200_I2C 434config SCx200_I2C
396 tristate "NatSemi SCx200 I2C using GPIO pins" 435 tristate "NatSemi SCx200 I2C using GPIO pins (DEPRECATED)"
397 depends on SCx200_GPIO && I2C 436 depends on SCx200_GPIO
398 select I2C_ALGOBIT 437 select I2C_ALGOBIT
399 help 438 help
400 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus. 439 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus.
@@ -404,6 +443,9 @@ config SCx200_I2C
404 This support is also available as a module. If so, the module 443 This support is also available as a module. If so, the module
405 will be called scx200_i2c. 444 will be called scx200_i2c.
406 445
446 This driver is deprecated and will be dropped soon. Use i2c-gpio
447 (or scx200_acb) instead.
448
407config SCx200_I2C_SCL 449config SCx200_I2C_SCL
408 int "GPIO pin used for SCL" 450 int "GPIO pin used for SCL"
409 depends on SCx200_I2C 451 depends on SCx200_I2C
@@ -422,7 +464,7 @@ config SCx200_I2C_SDA
422 464
423config SCx200_ACB 465config SCx200_ACB
424 tristate "Geode ACCESS.bus support" 466 tristate "Geode ACCESS.bus support"
425 depends on X86_32 && I2C && PCI 467 depends on X86_32 && PCI
426 help 468 help
427 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and 469 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and
428 SC1100 processors and the CS5535 and CS5536 Geode companion devices. 470 SC1100 processors and the CS5535 and CS5536 Geode companion devices.
@@ -434,7 +476,7 @@ config SCx200_ACB
434 476
435config I2C_SIS5595 477config I2C_SIS5595
436 tristate "SiS 5595" 478 tristate "SiS 5595"
437 depends on I2C && PCI 479 depends on PCI
438 help 480 help
439 If you say yes to this option, support will be included for the 481 If you say yes to this option, support will be included for the
440 SiS5595 SMBus (a subset of I2C) interface. 482 SiS5595 SMBus (a subset of I2C) interface.
@@ -444,7 +486,7 @@ config I2C_SIS5595
444 486
445config I2C_SIS630 487config I2C_SIS630
446 tristate "SiS 630/730" 488 tristate "SiS 630/730"
447 depends on I2C && PCI 489 depends on PCI
448 help 490 help
449 If you say yes to this option, support will be included for the 491 If you say yes to this option, support will be included for the
450 SiS630 and SiS730 SMBus (a subset of I2C) interface. 492 SiS630 and SiS730 SMBus (a subset of I2C) interface.
@@ -454,7 +496,7 @@ config I2C_SIS630
454 496
455config I2C_SIS96X 497config I2C_SIS96X
456 tristate "SiS 96x" 498 tristate "SiS 96x"
457 depends on I2C && PCI 499 depends on PCI
458 help 500 help
459 If you say yes to this option, support will be included for the SiS 501 If you say yes to this option, support will be included for the SiS
460 96x SMBus (a subset of I2C) interfaces. Specifically, the following 502 96x SMBus (a subset of I2C) interfaces. Specifically, the following
@@ -472,7 +514,7 @@ config I2C_SIS96X
472 514
473config I2C_STUB 515config I2C_STUB
474 tristate "I2C/SMBus Test Stub" 516 tristate "I2C/SMBus Test Stub"
475 depends on I2C && EXPERIMENTAL && 'm' 517 depends on EXPERIMENTAL && m
476 default 'n' 518 default 'n'
477 help 519 help
478 This module may be useful to developers of SMBus client drivers, 520 This module may be useful to developers of SMBus client drivers,
@@ -483,9 +525,20 @@ config I2C_STUB
483 525
484 If you don't know what to do here, definitely say N. 526 If you don't know what to do here, definitely say N.
485 527
528config I2C_TINY_USB
529 tristate "I2C-Tiny-USB"
530 depends on USB
531 help
532 If you say yes to this option, support will be included for the
533 i2c-tiny-usb, a simple do-it-yourself USB to I2C interface. See
534 http://www.harbaum.org/till/i2c_tiny_usb for hardware details.
535
536 This driver can also be built as a module. If so, the module
537 will be called i2c-tiny-usb.
538
486config I2C_VERSATILE 539config I2C_VERSATILE
487 tristate "ARM Versatile/Realview I2C bus support" 540 tristate "ARM Versatile/Realview I2C bus support"
488 depends on I2C && (ARCH_VERSATILE || ARCH_REALVIEW) 541 depends on ARCH_VERSATILE || ARCH_REALVIEW
489 select I2C_ALGOBIT 542 select I2C_ALGOBIT
490 help 543 help
491 Say yes if you want to support the I2C serial bus on ARMs Versatile 544 Say yes if you want to support the I2C serial bus on ARMs Versatile
@@ -496,7 +549,7 @@ config I2C_VERSATILE
496 549
497config I2C_ACORN 550config I2C_ACORN
498 bool "Acorn IOC/IOMD I2C bus support" 551 bool "Acorn IOC/IOMD I2C bus support"
499 depends on I2C && ARCH_ACORN 552 depends on ARCH_ACORN
500 default y 553 default y
501 select I2C_ALGOBIT 554 select I2C_ALGOBIT
502 help 555 help
@@ -506,7 +559,7 @@ config I2C_ACORN
506 559
507config I2C_VIA 560config I2C_VIA
508 tristate "VIA 82C586B" 561 tristate "VIA 82C586B"
509 depends on I2C && PCI && EXPERIMENTAL 562 depends on PCI && EXPERIMENTAL
510 select I2C_ALGOBIT 563 select I2C_ALGOBIT
511 help 564 help
512 If you say yes to this option, support will be included for the VIA 565 If you say yes to this option, support will be included for the VIA
@@ -517,7 +570,7 @@ config I2C_VIA
517 570
518config I2C_VIAPRO 571config I2C_VIAPRO
519 tristate "VIA VT82C596/82C686/82xx and CX700" 572 tristate "VIA VT82C596/82C686/82xx and CX700"
520 depends on I2C && PCI 573 depends on PCI
521 help 574 help
522 If you say yes to this option, support will be included for the VIA 575 If you say yes to this option, support will be included for the VIA
523 VT82C596 and later SMBus interface. Specifically, the following 576 VT82C596 and later SMBus interface. Specifically, the following
@@ -536,7 +589,7 @@ config I2C_VIAPRO
536 589
537config I2C_VOODOO3 590config I2C_VOODOO3
538 tristate "Voodoo 3" 591 tristate "Voodoo 3"
539 depends on I2C && PCI 592 depends on PCI
540 select I2C_ALGOBIT 593 select I2C_ALGOBIT
541 help 594 help
542 If you say yes to this option, support will be included for the 595 If you say yes to this option, support will be included for the
@@ -547,7 +600,7 @@ config I2C_VOODOO3
547 600
548config I2C_PCA_ISA 601config I2C_PCA_ISA
549 tristate "PCA9564 on an ISA bus" 602 tristate "PCA9564 on an ISA bus"
550 depends on I2C 603 depends on ISA
551 select I2C_ALGOPCA 604 select I2C_ALGOPCA
552 default n 605 default n
553 help 606 help
@@ -564,7 +617,7 @@ config I2C_PCA_ISA
564 617
565config I2C_MV64XXX 618config I2C_MV64XXX
566 tristate "Marvell mv64xxx I2C Controller" 619 tristate "Marvell mv64xxx I2C Controller"
567 depends on I2C && MV64X60 && EXPERIMENTAL 620 depends on MV64X60 && EXPERIMENTAL
568 help 621 help
569 If you say yes to this option, support will be included for the 622 If you say yes to this option, support will be included for the
570 built-in I2C interface on the Marvell 64xxx line of host bridges. 623 built-in I2C interface on the Marvell 64xxx line of host bridges.
@@ -574,7 +627,7 @@ config I2C_MV64XXX
574 627
575config I2C_PNX 628config I2C_PNX
576 tristate "I2C bus support for Philips PNX targets" 629 tristate "I2C bus support for Philips PNX targets"
577 depends on ARCH_PNX4008 && I2C 630 depends on ARCH_PNX4008
578 help 631 help
579 This driver supports the Philips IP3204 I2C IP block master and/or 632 This driver supports the Philips IP3204 I2C IP block master and/or
580 slave controller 633 slave controller
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 290b54018354..14d1432f698b 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -10,7 +10,9 @@ obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o
10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o 10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o
11obj-$(CONFIG_I2C_AT91) += i2c-at91.o 11obj-$(CONFIG_I2C_AT91) += i2c-at91.o
12obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 12obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
13obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
13obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o 14obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
15obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
14obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o 16obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o
15obj-$(CONFIG_I2C_I801) += i2c-i801.o 17obj-$(CONFIG_I2C_I801) += i2c-i801.o
16obj-$(CONFIG_I2C_I810) += i2c-i810.o 18obj-$(CONFIG_I2C_I810) += i2c-i810.o
@@ -37,10 +39,12 @@ obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o
37obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 39obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o
38obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o 40obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o
39obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o 41obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
42obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o
40obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o 43obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o
41obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o 44obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o
42obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o 45obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o
43obj-$(CONFIG_I2C_STUB) += i2c-stub.o 46obj-$(CONFIG_I2C_STUB) += i2c-stub.o
47obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o
44obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 48obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
45obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o 49obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o
46obj-$(CONFIG_I2C_VIA) += i2c-via.o 50obj-$(CONFIG_I2C_VIA) += i2c-via.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 1e277ba5a9f3..f14372ac2fc5 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -497,7 +497,7 @@ static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_
497 /* set up the sysfs linkage to our parent device */ 497 /* set up the sysfs linkage to our parent device */
498 ali1535_adapter.dev.parent = &dev->dev; 498 ali1535_adapter.dev.parent = &dev->dev;
499 499
500 snprintf(ali1535_adapter.name, I2C_NAME_SIZE, 500 snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
501 "SMBus ALI1535 adapter at %04x", ali1535_smba); 501 "SMBus ALI1535 adapter at %04x", ali1535_smba);
502 return i2c_add_adapter(&ali1535_adapter); 502 return i2c_add_adapter(&ali1535_adapter);
503} 503}
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index e47fe01bf42a..93bf87d70961 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -492,7 +492,7 @@ static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_
492 /* set up the sysfs linkage to our parent device */ 492 /* set up the sysfs linkage to our parent device */
493 ali15x3_adapter.dev.parent = &dev->dev; 493 ali15x3_adapter.dev.parent = &dev->dev;
494 494
495 snprintf(ali15x3_adapter.name, I2C_NAME_SIZE, 495 snprintf(ali15x3_adapter.name, sizeof(ali15x3_adapter.name),
496 "SMBus ALI15X3 adapter at %04x", ali15x3_smba); 496 "SMBus ALI15X3 adapter at %04x", ali15x3_smba);
497 return i2c_add_adapter(&ali15x3_adapter); 497 return i2c_add_adapter(&ali15x3_adapter);
498} 498}
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 0c70f8293341..c9fca7b49267 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -365,7 +365,7 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
365 } 365 }
366 366
367 smbus->adapter.owner = THIS_MODULE; 367 smbus->adapter.owner = THIS_MODULE;
368 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 368 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
369 "SMBus2 AMD8111 adapter at %04x", smbus->base); 369 "SMBus2 AMD8111 adapter at %04x", smbus->base);
370 smbus->adapter.id = I2C_HW_SMBUS_AMD8111; 370 smbus->adapter.id = I2C_HW_SMBUS_AMD8111;
371 smbus->adapter.class = I2C_CLASS_HWMON; 371 smbus->adapter.class = I2C_CLASS_HWMON;
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
new file mode 100644
index 000000000000..6311039dfe60
--- /dev/null
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -0,0 +1,644 @@
1/*
2 * drivers/i2c/busses/i2c-bfin-twi.c
3 *
4 * Description: Driver for Blackfin Two Wire Interface
5 *
6 * Author: sonicz <sonic.zhang@analog.com>
7 *
8 * Copyright (c) 2005-2007 Analog Devices, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/i2c.h>
29#include <linux/mm.h>
30#include <linux/timer.h>
31#include <linux/spinlock.h>
32#include <linux/completion.h>
33#include <linux/interrupt.h>
34#include <linux/platform_device.h>
35
36#include <asm/blackfin.h>
37#include <asm/irq.h>
38
39#define POLL_TIMEOUT (2 * HZ)
40
41/* SMBus mode*/
42#define TWI_I2C_MODE_STANDARD 0x01
43#define TWI_I2C_MODE_STANDARDSUB 0x02
44#define TWI_I2C_MODE_COMBINED 0x04
45
46struct bfin_twi_iface {
47 struct mutex twi_lock;
48 int irq;
49 spinlock_t lock;
50 char read_write;
51 u8 command;
52 u8 *transPtr;
53 int readNum;
54 int writeNum;
55 int cur_mode;
56 int manual_stop;
57 int result;
58 int timeout_count;
59 struct timer_list timeout_timer;
60 struct i2c_adapter adap;
61 struct completion complete;
62};
63
64static struct bfin_twi_iface twi_iface;
65
66static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
67{
68 unsigned short twi_int_status = bfin_read_TWI_INT_STAT();
69 unsigned short mast_stat = bfin_read_TWI_MASTER_STAT();
70
71 if (twi_int_status & XMTSERV) {
72 /* Transmit next data */
73 if (iface->writeNum > 0) {
74 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
75 iface->writeNum--;
76 }
77 /* start receive immediately after complete sending in
78 * combine mode.
79 */
80 else if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
81 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
82 | MDIR | RSTART);
83 } else if (iface->manual_stop)
84 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
85 | STOP);
86 SSYNC();
87 /* Clear status */
88 bfin_write_TWI_INT_STAT(XMTSERV);
89 SSYNC();
90 }
91 if (twi_int_status & RCVSERV) {
92 if (iface->readNum > 0) {
93 /* Receive next data */
94 *(iface->transPtr) = bfin_read_TWI_RCV_DATA8();
95 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
96 /* Change combine mode into sub mode after
97 * read first data.
98 */
99 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
100 /* Get read number from first byte in block
101 * combine mode.
102 */
103 if (iface->readNum == 1 && iface->manual_stop)
104 iface->readNum = *iface->transPtr + 1;
105 }
106 iface->transPtr++;
107 iface->readNum--;
108 } else if (iface->manual_stop) {
109 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
110 | STOP);
111 SSYNC();
112 }
113 /* Clear interrupt source */
114 bfin_write_TWI_INT_STAT(RCVSERV);
115 SSYNC();
116 }
117 if (twi_int_status & MERR) {
118 bfin_write_TWI_INT_STAT(MERR);
119 bfin_write_TWI_INT_MASK(0);
120 bfin_write_TWI_MASTER_STAT(0x3e);
121 bfin_write_TWI_MASTER_CTL(0);
122 SSYNC();
123 iface->result = -1;
124 /* if both err and complete int stats are set, return proper
125 * results.
126 */
127 if (twi_int_status & MCOMP) {
128 bfin_write_TWI_INT_STAT(MCOMP);
129 bfin_write_TWI_INT_MASK(0);
130 bfin_write_TWI_MASTER_CTL(0);
131 SSYNC();
132 /* If it is a quick transfer, only address bug no data,
133 * not an err, return 1.
134 */
135 if (iface->writeNum == 0 && (mast_stat & BUFRDERR))
136 iface->result = 1;
137 /* If address not acknowledged return -1,
138 * else return 0.
139 */
140 else if (!(mast_stat & ANAK))
141 iface->result = 0;
142 }
143 complete(&iface->complete);
144 return;
145 }
146 if (twi_int_status & MCOMP) {
147 bfin_write_TWI_INT_STAT(MCOMP);
148 SSYNC();
149 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
150 if (iface->readNum == 0) {
151 /* set the read number to 1 and ask for manual
152 * stop in block combine mode
153 */
154 iface->readNum = 1;
155 iface->manual_stop = 1;
156 bfin_write_TWI_MASTER_CTL(
157 bfin_read_TWI_MASTER_CTL()
158 | (0xff << 6));
159 } else {
160 /* set the readd number in other
161 * combine mode.
162 */
163 bfin_write_TWI_MASTER_CTL(
164 (bfin_read_TWI_MASTER_CTL() &
165 (~(0xff << 6))) |
166 ( iface->readNum << 6));
167 }
168 /* remove restart bit and enable master receive */
169 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() &
170 ~RSTART);
171 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() |
172 MEN | MDIR);
173 SSYNC();
174 } else {
175 iface->result = 1;
176 bfin_write_TWI_INT_MASK(0);
177 bfin_write_TWI_MASTER_CTL(0);
178 SSYNC();
179 complete(&iface->complete);
180 }
181 }
182}
183
184/* Interrupt handler */
185static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
186{
187 struct bfin_twi_iface *iface = dev_id;
188 unsigned long flags;
189
190 spin_lock_irqsave(&iface->lock, flags);
191 del_timer(&iface->timeout_timer);
192 bfin_twi_handle_interrupt(iface);
193 spin_unlock_irqrestore(&iface->lock, flags);
194 return IRQ_HANDLED;
195}
196
197static void bfin_twi_timeout(unsigned long data)
198{
199 struct bfin_twi_iface *iface = (struct bfin_twi_iface *)data;
200 unsigned long flags;
201
202 spin_lock_irqsave(&iface->lock, flags);
203 bfin_twi_handle_interrupt(iface);
204 if (iface->result == 0) {
205 iface->timeout_count--;
206 if (iface->timeout_count > 0) {
207 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
208 add_timer(&iface->timeout_timer);
209 } else {
210 iface->result = -1;
211 complete(&iface->complete);
212 }
213 }
214 spin_unlock_irqrestore(&iface->lock, flags);
215}
216
217/*
218 * Generic i2c master transfer entrypoint
219 */
220static int bfin_twi_master_xfer(struct i2c_adapter *adap,
221 struct i2c_msg *msgs, int num)
222{
223 struct bfin_twi_iface *iface = adap->algo_data;
224 struct i2c_msg *pmsg;
225 int i, ret;
226 int rc = 0;
227
228 if (!(bfin_read_TWI_CONTROL() & TWI_ENA))
229 return -ENXIO;
230
231 mutex_lock(&iface->twi_lock);
232
233 while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) {
234 mutex_unlock(&iface->twi_lock);
235 yield();
236 mutex_lock(&iface->twi_lock);
237 }
238
239 ret = 0;
240 for (i = 0; rc >= 0 && i < num; i++) {
241 pmsg = &msgs[i];
242 if (pmsg->flags & I2C_M_TEN) {
243 dev_err(&(adap->dev), "i2c-bfin-twi: 10 bits addr "
244 "not supported !\n");
245 rc = -EINVAL;
246 break;
247 }
248
249 iface->cur_mode = TWI_I2C_MODE_STANDARD;
250 iface->manual_stop = 0;
251 iface->transPtr = pmsg->buf;
252 iface->writeNum = iface->readNum = pmsg->len;
253 iface->result = 0;
254 iface->timeout_count = 10;
255 /* Set Transmit device address */
256 bfin_write_TWI_MASTER_ADDR(pmsg->addr);
257
258 /* FIFO Initiation. Data in FIFO should be
259 * discarded before start a new operation.
260 */
261 bfin_write_TWI_FIFO_CTL(0x3);
262 SSYNC();
263 bfin_write_TWI_FIFO_CTL(0);
264 SSYNC();
265
266 if (pmsg->flags & I2C_M_RD)
267 iface->read_write = I2C_SMBUS_READ;
268 else {
269 iface->read_write = I2C_SMBUS_WRITE;
270 /* Transmit first data */
271 if (iface->writeNum > 0) {
272 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
273 iface->writeNum--;
274 SSYNC();
275 }
276 }
277
278 /* clear int stat */
279 bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV);
280
281 /* Interrupt mask . Enable XMT, RCV interrupt */
282 bfin_write_TWI_INT_MASK(MCOMP | MERR |
283 ((iface->read_write == I2C_SMBUS_READ)?
284 RCVSERV : XMTSERV));
285 SSYNC();
286
287 if (pmsg->len > 0 && pmsg->len <= 255)
288 bfin_write_TWI_MASTER_CTL(pmsg->len << 6);
289 else if (pmsg->len > 255) {
290 bfin_write_TWI_MASTER_CTL(0xff << 6);
291 iface->manual_stop = 1;
292 } else
293 break;
294
295 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
296 add_timer(&iface->timeout_timer);
297
298 /* Master enable */
299 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
300 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
301 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
302 SSYNC();
303
304 wait_for_completion(&iface->complete);
305
306 rc = iface->result;
307 if (rc == 1)
308 ret++;
309 else if (rc == -1)
310 break;
311 }
312
313 /* Release mutex */
314 mutex_unlock(&iface->twi_lock);
315
316 return ret;
317}
318
319/*
320 * SMBus type transfer entrypoint
321 */
322
323int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
324 unsigned short flags, char read_write,
325 u8 command, int size, union i2c_smbus_data *data)
326{
327 struct bfin_twi_iface *iface = adap->algo_data;
328 int rc = 0;
329
330 if (!(bfin_read_TWI_CONTROL() & TWI_ENA))
331 return -ENXIO;
332
333 mutex_lock(&iface->twi_lock);
334
335 while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) {
336 mutex_unlock(&iface->twi_lock);
337 yield();
338 mutex_lock(&iface->twi_lock);
339 }
340
341 iface->writeNum = 0;
342 iface->readNum = 0;
343
344 /* Prepare datas & select mode */
345 switch (size) {
346 case I2C_SMBUS_QUICK:
347 iface->transPtr = NULL;
348 iface->cur_mode = TWI_I2C_MODE_STANDARD;
349 break;
350 case I2C_SMBUS_BYTE:
351 if (data == NULL)
352 iface->transPtr = NULL;
353 else {
354 if (read_write == I2C_SMBUS_READ)
355 iface->readNum = 1;
356 else
357 iface->writeNum = 1;
358 iface->transPtr = &data->byte;
359 }
360 iface->cur_mode = TWI_I2C_MODE_STANDARD;
361 break;
362 case I2C_SMBUS_BYTE_DATA:
363 if (read_write == I2C_SMBUS_READ) {
364 iface->readNum = 1;
365 iface->cur_mode = TWI_I2C_MODE_COMBINED;
366 } else {
367 iface->writeNum = 1;
368 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
369 }
370 iface->transPtr = &data->byte;
371 break;
372 case I2C_SMBUS_WORD_DATA:
373 if (read_write == I2C_SMBUS_READ) {
374 iface->readNum = 2;
375 iface->cur_mode = TWI_I2C_MODE_COMBINED;
376 } else {
377 iface->writeNum = 2;
378 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
379 }
380 iface->transPtr = (u8 *)&data->word;
381 break;
382 case I2C_SMBUS_PROC_CALL:
383 iface->writeNum = 2;
384 iface->readNum = 2;
385 iface->cur_mode = TWI_I2C_MODE_COMBINED;
386 iface->transPtr = (u8 *)&data->word;
387 break;
388 case I2C_SMBUS_BLOCK_DATA:
389 if (read_write == I2C_SMBUS_READ) {
390 iface->readNum = 0;
391 iface->cur_mode = TWI_I2C_MODE_COMBINED;
392 } else {
393 iface->writeNum = data->block[0] + 1;
394 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
395 }
396 iface->transPtr = data->block;
397 break;
398 default:
399 return -1;
400 }
401
402 iface->result = 0;
403 iface->manual_stop = 0;
404 iface->read_write = read_write;
405 iface->command = command;
406 iface->timeout_count = 10;
407
408 /* FIFO Initiation. Data in FIFO should be discarded before
409 * start a new operation.
410 */
411 bfin_write_TWI_FIFO_CTL(0x3);
412 SSYNC();
413 bfin_write_TWI_FIFO_CTL(0);
414
415 /* clear int stat */
416 bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV);
417
418 /* Set Transmit device address */
419 bfin_write_TWI_MASTER_ADDR(addr);
420 SSYNC();
421
422 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
423 add_timer(&iface->timeout_timer);
424
425 switch (iface->cur_mode) {
426 case TWI_I2C_MODE_STANDARDSUB:
427 bfin_write_TWI_XMT_DATA8(iface->command);
428 bfin_write_TWI_INT_MASK(MCOMP | MERR |
429 ((iface->read_write == I2C_SMBUS_READ) ?
430 RCVSERV : XMTSERV));
431 SSYNC();
432
433 if (iface->writeNum + 1 <= 255)
434 bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6);
435 else {
436 bfin_write_TWI_MASTER_CTL(0xff << 6);
437 iface->manual_stop = 1;
438 }
439 /* Master enable */
440 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
441 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
442 break;
443 case TWI_I2C_MODE_COMBINED:
444 bfin_write_TWI_XMT_DATA8(iface->command);
445 bfin_write_TWI_INT_MASK(MCOMP | MERR | RCVSERV | XMTSERV);
446 SSYNC();
447
448 if (iface->writeNum > 0)
449 bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6);
450 else
451 bfin_write_TWI_MASTER_CTL(0x1 << 6);
452 /* Master enable */
453 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
454 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
455 break;
456 default:
457 bfin_write_TWI_MASTER_CTL(0);
458 if (size != I2C_SMBUS_QUICK) {
459 /* Don't access xmit data register when this is a
460 * read operation.
461 */
462 if (iface->read_write != I2C_SMBUS_READ) {
463 if (iface->writeNum > 0) {
464 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
465 if (iface->writeNum <= 255)
466 bfin_write_TWI_MASTER_CTL(iface->writeNum << 6);
467 else {
468 bfin_write_TWI_MASTER_CTL(0xff << 6);
469 iface->manual_stop = 1;
470 }
471 iface->writeNum--;
472 } else {
473 bfin_write_TWI_XMT_DATA8(iface->command);
474 bfin_write_TWI_MASTER_CTL(1 << 6);
475 }
476 } else {
477 if (iface->readNum > 0 && iface->readNum <= 255)
478 bfin_write_TWI_MASTER_CTL(iface->readNum << 6);
479 else if (iface->readNum > 255) {
480 bfin_write_TWI_MASTER_CTL(0xff << 6);
481 iface->manual_stop = 1;
482 } else {
483 del_timer(&iface->timeout_timer);
484 break;
485 }
486 }
487 }
488 bfin_write_TWI_INT_MASK(MCOMP | MERR |
489 ((iface->read_write == I2C_SMBUS_READ) ?
490 RCVSERV : XMTSERV));
491 SSYNC();
492
493 /* Master enable */
494 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
495 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
496 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
497 break;
498 }
499 SSYNC();
500
501 wait_for_completion(&iface->complete);
502
503 rc = (iface->result >= 0) ? 0 : -1;
504
505 /* Release mutex */
506 mutex_unlock(&iface->twi_lock);
507
508 return rc;
509}
510
511/*
512 * Return what the adapter supports
513 */
514static u32 bfin_twi_functionality(struct i2c_adapter *adap)
515{
516 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
517 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
518 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL |
519 I2C_FUNC_I2C;
520}
521
522
523static struct i2c_algorithm bfin_twi_algorithm = {
524 .master_xfer = bfin_twi_master_xfer,
525 .smbus_xfer = bfin_twi_smbus_xfer,
526 .functionality = bfin_twi_functionality,
527};
528
529
530static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
531{
532/* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/
533
534 /* Disable TWI */
535 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() & ~TWI_ENA);
536 SSYNC();
537
538 return 0;
539}
540
541static int i2c_bfin_twi_resume(struct platform_device *dev)
542{
543/* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/
544
545 /* Enable TWI */
546 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA);
547 SSYNC();
548
549 return 0;
550}
551
552static int i2c_bfin_twi_probe(struct platform_device *dev)
553{
554 struct bfin_twi_iface *iface = &twi_iface;
555 struct i2c_adapter *p_adap;
556 int rc;
557
558 mutex_init(&(iface->twi_lock));
559 spin_lock_init(&(iface->lock));
560 init_completion(&(iface->complete));
561 iface->irq = IRQ_TWI;
562
563 init_timer(&(iface->timeout_timer));
564 iface->timeout_timer.function = bfin_twi_timeout;
565 iface->timeout_timer.data = (unsigned long)iface;
566
567 p_adap = &iface->adap;
568 p_adap->id = I2C_HW_BLACKFIN;
569 strlcpy(p_adap->name, dev->name, sizeof(p_adap->name));
570 p_adap->algo = &bfin_twi_algorithm;
571 p_adap->algo_data = iface;
572 p_adap->class = I2C_CLASS_ALL;
573 p_adap->dev.parent = &dev->dev;
574
575 rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
576 IRQF_DISABLED, dev->name, iface);
577 if (rc) {
578 dev_err(&(p_adap->dev), "i2c-bfin-twi: can't get IRQ %d !\n",
579 iface->irq);
580 return -ENODEV;
581 }
582
583 /* Set TWI internal clock as 10MHz */
584 bfin_write_TWI_CONTROL(((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F);
585
586 /* Set Twi interface clock as specified */
587 bfin_write_TWI_CLKDIV((( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ )
588 << 8) | (( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ )
589 & 0xFF));
590
591 /* Enable TWI */
592 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA);
593 SSYNC();
594
595 rc = i2c_add_adapter(p_adap);
596 if (rc < 0)
597 free_irq(iface->irq, iface);
598 else
599 platform_set_drvdata(dev, iface);
600
601 return rc;
602}
603
604static int i2c_bfin_twi_remove(struct platform_device *pdev)
605{
606 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
607
608 platform_set_drvdata(pdev, NULL);
609
610 i2c_del_adapter(&(iface->adap));
611 free_irq(iface->irq, iface);
612
613 return 0;
614}
615
616static struct platform_driver i2c_bfin_twi_driver = {
617 .probe = i2c_bfin_twi_probe,
618 .remove = i2c_bfin_twi_remove,
619 .suspend = i2c_bfin_twi_suspend,
620 .resume = i2c_bfin_twi_resume,
621 .driver = {
622 .name = "i2c-bfin-twi",
623 .owner = THIS_MODULE,
624 },
625};
626
627static int __init i2c_bfin_twi_init(void)
628{
629 pr_info("I2C: Blackfin I2C TWI driver\n");
630
631 return platform_driver_register(&i2c_bfin_twi_driver);
632}
633
634static void __exit i2c_bfin_twi_exit(void)
635{
636 platform_driver_unregister(&i2c_bfin_twi_driver);
637}
638
639MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
640MODULE_DESCRIPTION("I2C-Bus adapter routines for Blackfin TWI");
641MODULE_LICENSE("GPL");
642
643module_init(i2c_bfin_twi_init);
644module_exit(i2c_bfin_twi_exit);
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 834967464814..804f0a551c05 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -35,6 +35,7 @@
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/wait.h> 36#include <linux/wait.h>
37 37
38#include <linux/isa.h>
38#include <linux/i2c.h> 39#include <linux/i2c.h>
39#include <linux/i2c-algo-pcf.h> 40#include <linux/i2c-algo-pcf.h>
40 41
@@ -207,7 +208,7 @@ static struct i2c_adapter pcf_isa_ops = {
207 .name = "i2c-elektor", 208 .name = "i2c-elektor",
208}; 209};
209 210
210static int __init i2c_pcfisa_init(void) 211static int __devinit elektor_match(struct device *dev, unsigned int id)
211{ 212{
212#ifdef __alpha__ 213#ifdef __alpha__
213 /* check to see we have memory mapped PCF8584 connected to the 214 /* check to see we have memory mapped PCF8584 connected to the
@@ -222,9 +223,8 @@ static int __init i2c_pcfisa_init(void)
222 /* yeap, we've found cypress, let's check config */ 223 /* yeap, we've found cypress, let's check config */
223 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { 224 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
224 225
225 pr_debug("%s: found cy82c693, config " 226 dev_dbg(dev, "found cy82c693, config "
226 "register 0x47 = 0x%02x\n", 227 "register 0x47 = 0x%02x\n", config);
227 pcf_isa_ops.name, config);
228 228
229 /* UP2000 board has this register set to 0xe1, 229 /* UP2000 board has this register set to 0xe1,
230 but the most significant bit as seems can be 230 but the most significant bit as seems can be
@@ -244,9 +244,9 @@ static int __init i2c_pcfisa_init(void)
244 8.25 MHz (PCI/4) clock 244 8.25 MHz (PCI/4) clock
245 (this can be read from cypress) */ 245 (this can be read from cypress) */
246 clock = I2C_PCF_CLK | I2C_PCF_TRNS90; 246 clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
247 pr_info("%s: found API UP2000 like " 247 dev_info(dev, "found API UP2000 like "
248 "board, will probe PCF8584 " 248 "board, will probe PCF8584 "
249 "later\n", pcf_isa_ops.name); 249 "later\n");
250 } 250 }
251 } 251 }
252 pci_dev_put(cy693_dev); 252 pci_dev_put(cy693_dev);
@@ -256,22 +256,27 @@ static int __init i2c_pcfisa_init(void)
256 256
257 /* sanity checks for mmapped I/O */ 257 /* sanity checks for mmapped I/O */
258 if (mmapped && base < 0xc8000) { 258 if (mmapped && base < 0xc8000) {
259 printk(KERN_ERR "%s: incorrect base address (%#x) specified " 259 dev_err(dev, "incorrect base address (%#x) specified "
260 "for mmapped I/O\n", pcf_isa_ops.name, base); 260 "for mmapped I/O\n", base);
261 return -ENODEV; 261 return 0;
262 } 262 }
263 263
264 if (base == 0) { 264 if (base == 0) {
265 base = DEFAULT_BASE; 265 base = DEFAULT_BASE;
266 } 266 }
267 return 1;
268}
267 269
270static int __devinit elektor_probe(struct device *dev, unsigned int id)
271{
268 init_waitqueue_head(&pcf_wait); 272 init_waitqueue_head(&pcf_wait);
269 if (pcf_isa_init()) 273 if (pcf_isa_init())
270 return -ENODEV; 274 return -ENODEV;
275 pcf_isa_ops.dev.parent = dev;
271 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) 276 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
272 goto fail; 277 goto fail;
273 278
274 dev_info(&pcf_isa_ops.dev, "found device at %#x\n", base); 279 dev_info(dev, "found device at %#x\n", base);
275 280
276 return 0; 281 return 0;
277 282
@@ -291,7 +296,7 @@ static int __init i2c_pcfisa_init(void)
291 return -ENODEV; 296 return -ENODEV;
292} 297}
293 298
294static void i2c_pcfisa_exit(void) 299static int __devexit elektor_remove(struct device *dev, unsigned int id)
295{ 300{
296 i2c_del_adapter(&pcf_isa_ops); 301 i2c_del_adapter(&pcf_isa_ops);
297 302
@@ -307,6 +312,28 @@ static void i2c_pcfisa_exit(void)
307 iounmap(base_iomem); 312 iounmap(base_iomem);
308 release_mem_region(base, 2); 313 release_mem_region(base, 2);
309 } 314 }
315
316 return 0;
317}
318
319static struct isa_driver i2c_elektor_driver = {
320 .match = elektor_match,
321 .probe = elektor_probe,
322 .remove = __devexit_p(elektor_remove),
323 .driver = {
324 .owner = THIS_MODULE,
325 .name = "i2c-elektor",
326 },
327};
328
329static int __init i2c_pcfisa_init(void)
330{
331 return isa_register_driver(&i2c_elektor_driver, 1);
332}
333
334static void __exit i2c_pcfisa_exit(void)
335{
336 isa_unregister_driver(&i2c_elektor_driver);
310} 337}
311 338
312MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); 339MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
new file mode 100644
index 000000000000..a7dd54654a9a
--- /dev/null
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -0,0 +1,215 @@
1/*
2 * Bitbanging I2C bus driver using the GPIO API
3 *
4 * Copyright (C) 2007 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/i2c.h>
11#include <linux/i2c-algo-bit.h>
12#include <linux/i2c-gpio.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16
17#include <asm/gpio.h>
18
19/* Toggle SDA by changing the direction of the pin */
20static void i2c_gpio_setsda_dir(void *data, int state)
21{
22 struct i2c_gpio_platform_data *pdata = data;
23
24 if (state)
25 gpio_direction_input(pdata->sda_pin);
26 else
27 gpio_direction_output(pdata->sda_pin, 0);
28}
29
30/*
31 * Toggle SDA by changing the output value of the pin. This is only
32 * valid for pins configured as open drain (i.e. setting the value
33 * high effectively turns off the output driver.)
34 */
35static void i2c_gpio_setsda_val(void *data, int state)
36{
37 struct i2c_gpio_platform_data *pdata = data;
38
39 gpio_set_value(pdata->sda_pin, state);
40}
41
42/* Toggle SCL by changing the direction of the pin. */
43static void i2c_gpio_setscl_dir(void *data, int state)
44{
45 struct i2c_gpio_platform_data *pdata = data;
46
47 if (state)
48 gpio_direction_input(pdata->scl_pin);
49 else
50 gpio_direction_output(pdata->scl_pin, 0);
51}
52
53/*
54 * Toggle SCL by changing the output value of the pin. This is used
55 * for pins that are configured as open drain and for output-only
56 * pins. The latter case will break the i2c protocol, but it will
57 * often work in practice.
58 */
59static void i2c_gpio_setscl_val(void *data, int state)
60{
61 struct i2c_gpio_platform_data *pdata = data;
62
63 gpio_set_value(pdata->scl_pin, state);
64}
65
66int i2c_gpio_getsda(void *data)
67{
68 struct i2c_gpio_platform_data *pdata = data;
69
70 return gpio_get_value(pdata->sda_pin);
71}
72
73int i2c_gpio_getscl(void *data)
74{
75 struct i2c_gpio_platform_data *pdata = data;
76
77 return gpio_get_value(pdata->scl_pin);
78}
79
80static int __init i2c_gpio_probe(struct platform_device *pdev)
81{
82 struct i2c_gpio_platform_data *pdata;
83 struct i2c_algo_bit_data *bit_data;
84 struct i2c_adapter *adap;
85 int ret;
86
87 pdata = pdev->dev.platform_data;
88 if (!pdata)
89 return -ENXIO;
90
91 ret = -ENOMEM;
92 adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
93 if (!adap)
94 goto err_alloc_adap;
95 bit_data = kzalloc(sizeof(struct i2c_algo_bit_data), GFP_KERNEL);
96 if (!bit_data)
97 goto err_alloc_bit_data;
98
99 ret = gpio_request(pdata->sda_pin, "sda");
100 if (ret)
101 goto err_request_sda;
102 ret = gpio_request(pdata->scl_pin, "scl");
103 if (ret)
104 goto err_request_scl;
105
106 if (pdata->sda_is_open_drain) {
107 gpio_direction_output(pdata->sda_pin, 1);
108 bit_data->setsda = i2c_gpio_setsda_val;
109 } else {
110 gpio_direction_input(pdata->sda_pin);
111 bit_data->setsda = i2c_gpio_setsda_dir;
112 }
113
114 if (pdata->scl_is_open_drain || pdata->scl_is_output_only) {
115 gpio_direction_output(pdata->scl_pin, 1);
116 bit_data->setscl = i2c_gpio_setscl_val;
117 } else {
118 gpio_direction_input(pdata->scl_pin);
119 bit_data->setscl = i2c_gpio_setscl_dir;
120 }
121
122 if (!pdata->scl_is_output_only)
123 bit_data->getscl = i2c_gpio_getscl;
124 bit_data->getsda = i2c_gpio_getsda;
125
126 if (pdata->udelay)
127 bit_data->udelay = pdata->udelay;
128 else if (pdata->scl_is_output_only)
129 bit_data->udelay = 50; /* 10 kHz */
130 else
131 bit_data->udelay = 5; /* 100 kHz */
132
133 if (pdata->timeout)
134 bit_data->timeout = pdata->timeout;
135 else
136 bit_data->timeout = HZ / 10; /* 100 ms */
137
138 bit_data->data = pdata;
139
140 adap->owner = THIS_MODULE;
141 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
142 adap->algo_data = bit_data;
143 adap->dev.parent = &pdev->dev;
144
145 ret = i2c_bit_add_bus(adap);
146 if (ret)
147 goto err_add_bus;
148
149 platform_set_drvdata(pdev, adap);
150
151 dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n",
152 pdata->sda_pin, pdata->scl_pin,
153 pdata->scl_is_output_only
154 ? ", no clock stretching" : "");
155
156 return 0;
157
158err_add_bus:
159 gpio_free(pdata->scl_pin);
160err_request_scl:
161 gpio_free(pdata->sda_pin);
162err_request_sda:
163 kfree(bit_data);
164err_alloc_bit_data:
165 kfree(adap);
166err_alloc_adap:
167 return ret;
168}
169
170static int __exit i2c_gpio_remove(struct platform_device *pdev)
171{
172 struct i2c_gpio_platform_data *pdata;
173 struct i2c_adapter *adap;
174
175 adap = platform_get_drvdata(pdev);
176 pdata = pdev->dev.platform_data;
177
178 i2c_del_adapter(adap);
179 gpio_free(pdata->scl_pin);
180 gpio_free(pdata->sda_pin);
181 kfree(adap->algo_data);
182 kfree(adap);
183
184 return 0;
185}
186
187static struct platform_driver i2c_gpio_driver = {
188 .driver = {
189 .name = "i2c-gpio",
190 .owner = THIS_MODULE,
191 },
192 .remove = __exit_p(i2c_gpio_remove),
193};
194
195static int __init i2c_gpio_init(void)
196{
197 int ret;
198
199 ret = platform_driver_probe(&i2c_gpio_driver, i2c_gpio_probe);
200 if (ret)
201 printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret);
202
203 return ret;
204}
205module_init(i2c_gpio_init);
206
207static void __exit i2c_gpio_exit(void)
208{
209 platform_driver_unregister(&i2c_gpio_driver);
210}
211module_exit(i2c_gpio_exit);
212
213MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
214MODULE_DESCRIPTION("Platform-independent bitbanging I2C driver");
215MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index a320e7d82c1f..611b57192c96 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -527,7 +527,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
527 /* set up the sysfs linkage to our parent device */ 527 /* set up the sysfs linkage to our parent device */
528 i801_adapter.dev.parent = &dev->dev; 528 i801_adapter.dev.parent = &dev->dev;
529 529
530 snprintf(i801_adapter.name, I2C_NAME_SIZE, 530 snprintf(i801_adapter.name, sizeof(i801_adapter.name),
531 "SMBus I801 adapter at %04lx", i801_smba); 531 "SMBus I801 adapter at %04lx", i801_smba);
532 err = i2c_add_adapter(&i801_adapter); 532 err = i2c_add_adapter(&i801_adapter);
533 if (err) { 533 if (err) {
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index 5f33bc9c1e02..b0e1370075de 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -41,6 +41,10 @@
41#include <linux/platform_device.h> 41#include <linux/platform_device.h>
42#include <linux/completion.h> 42#include <linux/completion.h>
43 43
44/* Exported by i2c-core for i2c-isa only */
45extern void i2c_adapter_dev_release(struct device *dev);
46extern struct class i2c_adapter_class;
47
44static u32 isa_func(struct i2c_adapter *adapter); 48static u32 isa_func(struct i2c_adapter *adapter);
45 49
46/* This is the actual algorithm we define */ 50/* This is the actual algorithm we define */
@@ -64,16 +68,6 @@ static u32 isa_func(struct i2c_adapter *adapter)
64} 68}
65 69
66 70
67/* Copied from i2c-core */
68static ssize_t show_adapter_name(struct device *dev,
69 struct device_attribute *attr, char *buf)
70{
71 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
72 return sprintf(buf, "%s\n", adap->name);
73}
74static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
75
76
77/* We implement an interface which resembles i2c_{add,del}_driver, 71/* We implement an interface which resembles i2c_{add,del}_driver,
78 but for i2c-isa drivers. We don't have to remember and handle lists 72 but for i2c-isa drivers. We don't have to remember and handle lists
79 of drivers and adapters so this is much more simple, of course. */ 73 of drivers and adapters so this is much more simple, of course. */
@@ -139,41 +133,18 @@ static int __init i2c_isa_init(void)
139 isa_adapter.nr = ANY_I2C_ISA_BUS; 133 isa_adapter.nr = ANY_I2C_ISA_BUS;
140 isa_adapter.dev.parent = &platform_bus; 134 isa_adapter.dev.parent = &platform_bus;
141 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); 135 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
142 isa_adapter.dev.driver = &i2c_adapter_driver;
143 isa_adapter.dev.release = &i2c_adapter_dev_release; 136 isa_adapter.dev.release = &i2c_adapter_dev_release;
137 isa_adapter.dev.class = &i2c_adapter_class;
144 err = device_register(&isa_adapter.dev); 138 err = device_register(&isa_adapter.dev);
145 if (err) { 139 if (err) {
146 printk(KERN_ERR "i2c-isa: Failed to register device\n"); 140 printk(KERN_ERR "i2c-isa: Failed to register device\n");
147 goto exit; 141 goto exit;
148 } 142 }
149 err = device_create_file(&isa_adapter.dev, &dev_attr_name);
150 if (err) {
151 printk(KERN_ERR "i2c-isa: Failed to create name file\n");
152 goto exit_unregister;
153 }
154
155 /* Add this adapter to the i2c_adapter class */
156 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
157 isa_adapter.class_dev.dev = &isa_adapter.dev;
158 isa_adapter.class_dev.class = &i2c_adapter_class;
159 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
160 BUS_ID_SIZE);
161 err = class_device_register(&isa_adapter.class_dev);
162 if (err) {
163 printk(KERN_ERR "i2c-isa: Failed to register class device\n");
164 goto exit_remove_name;
165 }
166 143
167 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 144 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
168 145
169 return 0; 146 return 0;
170 147
171exit_remove_name:
172 device_remove_file(&isa_adapter.dev, &dev_attr_name);
173exit_unregister:
174 init_completion(&isa_adapter.dev_released); /* Needed? */
175 device_unregister(&isa_adapter.dev);
176 wait_for_completion(&isa_adapter.dev_released);
177exit: 148exit:
178 return err; 149 return err;
179} 150}
@@ -201,15 +172,11 @@ static void __exit i2c_isa_exit(void)
201 /* Clean up the sysfs representation */ 172 /* Clean up the sysfs representation */
202 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); 173 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
203 init_completion(&isa_adapter.dev_released); 174 init_completion(&isa_adapter.dev_released);
204 init_completion(&isa_adapter.class_dev_released);
205 class_device_unregister(&isa_adapter.class_dev);
206 device_remove_file(&isa_adapter.dev, &dev_attr_name);
207 device_unregister(&isa_adapter.dev); 175 device_unregister(&isa_adapter.dev);
208 176
209 /* Wait for sysfs to drop all references */ 177 /* Wait for sysfs to drop all references */
210 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); 178 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n");
211 wait_for_completion(&isa_adapter.dev_released); 179 wait_for_completion(&isa_adapter.dev_released);
212 wait_for_completion(&isa_adapter.class_dev_released);
213 180
214 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); 181 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name);
215} 182}
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index efa3ecc5522a..6352121a2827 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -118,7 +118,7 @@ static int ixp2000_i2c_probe(struct platform_device *plat_dev)
118 118
119 drv_data->adapter.id = I2C_HW_B_IXP2000, 119 drv_data->adapter.id = I2C_HW_B_IXP2000,
120 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, 120 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
121 I2C_NAME_SIZE); 121 sizeof(drv_data->adapter.name));
122 drv_data->adapter.algo_data = &drv_data->algo_data, 122 drv_data->adapter.algo_data = &drv_data->algo_data,
123 123
124 drv_data->adapter.dev.parent = &plat_dev->dev; 124 drv_data->adapter.dev.parent = &plat_dev->dev;
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index 08e89b83984a..069ed7f3b395 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -127,7 +127,7 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
127 drv_data->adapter.id = I2C_HW_B_IXP4XX; 127 drv_data->adapter.id = I2C_HW_B_IXP4XX;
128 drv_data->adapter.class = I2C_CLASS_HWMON; 128 drv_data->adapter.class = I2C_CLASS_HWMON;
129 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, 129 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
130 I2C_NAME_SIZE); 130 sizeof(drv_data->adapter.name));
131 drv_data->adapter.algo_data = &drv_data->algo_data; 131 drv_data->adapter.algo_data = &drv_data->algo_data;
132 132
133 drv_data->adapter.dev.parent = &plat_dev->dev; 133 drv_data->adapter.dev.parent = &plat_dev->dev;
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index a3283b907eb8..a55b3335d1be 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -508,7 +508,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
508 } 508 }
509 509
510 strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter", 510 strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter",
511 I2C_NAME_SIZE); 511 sizeof(drv_data->adapter.name));
512 512
513 init_waitqueue_head(&drv_data->waitq); 513 init_waitqueue_head(&drv_data->waitq);
514 spin_lock_init(&drv_data->lock); 514 spin_lock_init(&drv_data->lock);
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 1514ec5b77f8..3cd0d63e7b50 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -33,6 +33,8 @@
33 nForce4 MCP-04 0034 33 nForce4 MCP-04 0034
34 nForce4 MCP51 0264 34 nForce4 MCP51 0264
35 nForce4 MCP55 0368 35 nForce4 MCP55 0368
36 nForce MCP61 03EB
37 nForce MCP65 0446
36 38
37 This driver supports the 2 SMBuses that are included in the MCP of the 39 This driver supports the 2 SMBuses that are included in the MCP of the
38 nForce2/3/4/5xx chipsets. 40 nForce2/3/4/5xx chipsets.
@@ -200,6 +202,8 @@ static struct pci_device_id nforce2_ids[] = {
200 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) }, 202 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) },
201 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) }, 203 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) },
202 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) }, 204 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) },
205 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS) },
206 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS) },
203 { 0 } 207 { 0 }
204}; 208};
205 209
@@ -240,7 +244,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
240 smbus->adapter.algo = &smbus_algorithm; 244 smbus->adapter.algo = &smbus_algorithm;
241 smbus->adapter.algo_data = smbus; 245 smbus->adapter.algo_data = smbus;
242 smbus->adapter.dev.parent = &dev->dev; 246 smbus->adapter.dev.parent = &dev->dev;
243 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 247 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
244 "SMBus nForce2 adapter at %04x", smbus->base); 248 "SMBus nForce2 adapter at %04x", smbus->base);
245 249
246 error = i2c_add_adapter(&smbus->adapter); 250 error = i2c_add_adapter(&smbus->adapter);
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index bcd8367cede1..e471e3bfdc1e 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -605,7 +605,8 @@ omap_i2c_probe(struct platform_device *pdev)
605 adap->dev.parent = &pdev->dev; 605 adap->dev.parent = &pdev->dev;
606 606
607 /* i2c device drivers may be active on return from add_adapter() */ 607 /* i2c device drivers may be active on return from add_adapter() */
608 r = i2c_add_adapter(adap); 608 adap->nr = pdev->id;
609 r = i2c_add_numbered_adapter(adap);
609 if (r) { 610 if (r) {
610 dev_err(dev->dev, "failure adding adapter\n"); 611 dev_err(dev->dev, "failure adding adapter\n");
611 goto err_free_irq; 612 goto err_free_irq;
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index 4bc42810b9aa..49a95e2887bc 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------ * 1/* ------------------------------------------------------------------------ *
2 * i2c-parport.c I2C bus over parallel port * 2 * i2c-parport-light.c I2C bus over parallel port *
3 * ------------------------------------------------------------------------ * 3 * ------------------------------------------------------------------------ *
4 Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org>
5 5
6 Based on older i2c-velleman.c driver 6 Based on older i2c-velleman.c driver
7 Copyright (C) 1995-2000 Simon G. Vogl 7 Copyright (C) 1995-2000 Simon G. Vogl
@@ -27,6 +27,7 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/platform_device.h>
30#include <linux/ioport.h> 31#include <linux/ioport.h>
31#include <linux/i2c.h> 32#include <linux/i2c.h>
32#include <linux/i2c-algo-bit.h> 33#include <linux/i2c-algo-bit.h>
@@ -34,6 +35,9 @@
34#include "i2c-parport.h" 35#include "i2c-parport.h"
35 36
36#define DEFAULT_BASE 0x378 37#define DEFAULT_BASE 0x378
38#define DRVNAME "i2c-parport-light"
39
40static struct platform_device *pdev;
37 41
38static u16 base; 42static u16 base;
39module_param(base, ushort, 0); 43module_param(base, ushort, 0);
@@ -106,7 +110,7 @@ static struct i2c_algo_bit_data parport_algo_data = {
106 .timeout = HZ, 110 .timeout = HZ,
107}; 111};
108 112
109/* ----- I2c structure ---------------------------------------------------- */ 113/* ----- Driver registration ---------------------------------------------- */
110 114
111static struct i2c_adapter parport_adapter = { 115static struct i2c_adapter parport_adapter = {
112 .owner = THIS_MODULE, 116 .owner = THIS_MODULE,
@@ -116,55 +120,141 @@ static struct i2c_adapter parport_adapter = {
116 .name = "Parallel port adapter (light)", 120 .name = "Parallel port adapter (light)",
117}; 121};
118 122
119/* ----- Module loading, unloading and information ------------------------ */ 123static int __devinit i2c_parport_probe(struct platform_device *pdev)
124{
125 int err;
126 struct resource *res;
127
128 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
129 if (!request_region(res->start, res->end - res->start + 1, DRVNAME))
130 return -EBUSY;
131
132 /* Reset hardware to a sane state (SCL and SDA high) */
133 parport_setsda(NULL, 1);
134 parport_setscl(NULL, 1);
135 /* Other init if needed (power on...) */
136 if (adapter_parm[type].init.val)
137 line_set(1, &adapter_parm[type].init);
138
139 parport_adapter.dev.parent = &pdev->dev;
140 err = i2c_bit_add_bus(&parport_adapter);
141 if (err) {
142 dev_err(&pdev->dev, "Unable to register with I2C\n");
143 goto exit_region;
144 }
145 return 0;
146
147exit_region:
148 release_region(res->start, res->end - res->start + 1);
149 return err;
150}
151
152static int __devexit i2c_parport_remove(struct platform_device *pdev)
153{
154 struct resource *res;
155
156 i2c_del_adapter(&parport_adapter);
157
158 /* Un-init if needed (power off...) */
159 if (adapter_parm[type].init.val)
160 line_set(0, &adapter_parm[type].init);
161
162 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
163 release_region(res->start, res->end - res->start + 1);
164 return 0;
165}
166
167static struct platform_driver i2c_parport_driver = {
168 .driver = {
169 .owner = THIS_MODULE,
170 .name = DRVNAME,
171 },
172 .probe = i2c_parport_probe,
173 .remove = __devexit_p(i2c_parport_remove),
174};
175
176static int __init i2c_parport_device_add(u16 address)
177{
178 struct resource res = {
179 .start = address,
180 .end = address + 2,
181 .name = DRVNAME,
182 .flags = IORESOURCE_IO,
183 };
184 int err;
185
186 pdev = platform_device_alloc(DRVNAME, -1);
187 if (!pdev) {
188 err = -ENOMEM;
189 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
190 goto exit;
191 }
192
193 err = platform_device_add_resources(pdev, &res, 1);
194 if (err) {
195 printk(KERN_ERR DRVNAME ": Device resource addition failed "
196 "(%d)\n", err);
197 goto exit_device_put;
198 }
199
200 err = platform_device_add(pdev);
201 if (err) {
202 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
203 err);
204 goto exit_device_put;
205 }
206
207 return 0;
208
209exit_device_put:
210 platform_device_put(pdev);
211exit:
212 return err;
213}
120 214
121static int __init i2c_parport_init(void) 215static int __init i2c_parport_init(void)
122{ 216{
217 int err;
218
123 if (type < 0) { 219 if (type < 0) {
124 printk(KERN_WARNING "i2c-parport: adapter type unspecified\n"); 220 printk(KERN_ERR DRVNAME ": adapter type unspecified\n");
125 return -ENODEV; 221 return -ENODEV;
126 } 222 }
127 223
128 if (type >= ARRAY_SIZE(adapter_parm)) { 224 if (type >= ARRAY_SIZE(adapter_parm)) {
129 printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type); 225 printk(KERN_ERR DRVNAME ": invalid type (%d)\n", type);
130 return -ENODEV; 226 return -ENODEV;
131 } 227 }
132 228
133 if (base == 0) { 229 if (base == 0) {
134 printk(KERN_INFO "i2c-parport: using default base 0x%x\n", DEFAULT_BASE); 230 pr_info(DRVNAME ": using default base 0x%x\n", DEFAULT_BASE);
135 base = DEFAULT_BASE; 231 base = DEFAULT_BASE;
136 } 232 }
137 233
138 if (!request_region(base, 3, "i2c-parport"))
139 return -ENODEV;
140
141 if (!adapter_parm[type].getscl.val) 234 if (!adapter_parm[type].getscl.val)
142 parport_algo_data.getscl = NULL; 235 parport_algo_data.getscl = NULL;
143 236
144 /* Reset hardware to a sane state (SCL and SDA high) */ 237 /* Sets global pdev as a side effect */
145 parport_setsda(NULL, 1); 238 err = i2c_parport_device_add(base);
146 parport_setscl(NULL, 1); 239 if (err)
147 /* Other init if needed (power on...) */ 240 goto exit;
148 if (adapter_parm[type].init.val)
149 line_set(1, &adapter_parm[type].init);
150 241
151 if (i2c_bit_add_bus(&parport_adapter) < 0) { 242 err = platform_driver_register(&i2c_parport_driver);
152 printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); 243 if (err)
153 release_region(base, 3); 244 goto exit_device;
154 return -ENODEV;
155 }
156 245
157 return 0; 246 return 0;
247
248exit_device:
249 platform_device_unregister(pdev);
250exit:
251 return err;
158} 252}
159 253
160static void __exit i2c_parport_exit(void) 254static void __exit i2c_parport_exit(void)
161{ 255{
162 /* Un-init if needed (power off...) */ 256 platform_driver_unregister(&i2c_parport_driver);
163 if (adapter_parm[type].init.val) 257 platform_device_unregister(pdev);
164 line_set(0, &adapter_parm[type].init);
165
166 i2c_del_adapter(&parport_adapter);
167 release_region(base, 3);
168} 258}
169 259
170MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 260MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 66696a40c7b5..8c953707253f 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------ * 1/* ------------------------------------------------------------------------ *
2 * i2c-parport.c I2C bus over parallel port * 2 * i2c-parport.c I2C bus over parallel port *
3 * ------------------------------------------------------------------------ * 3 * ------------------------------------------------------------------------ *
4 Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org>
5 5
6 Based on older i2c-philips-par.c driver 6 Based on older i2c-philips-par.c driver
7 Copyright (C) 1995-2000 Simon G. Vogl 7 Copyright (C) 1995-2000 Simon G. Vogl
@@ -137,19 +137,12 @@ static struct i2c_algo_bit_data parport_algo_data = {
137 .setscl = parport_setscl, 137 .setscl = parport_setscl,
138 .getsda = parport_getsda, 138 .getsda = parport_getsda,
139 .getscl = parport_getscl, 139 .getscl = parport_getscl,
140 .udelay = 60, 140 .udelay = 10, /* ~50 kbps */
141 .timeout = HZ, 141 .timeout = HZ,
142}; 142};
143 143
144/* ----- I2c and parallel port call-back functions and structures --------- */ 144/* ----- I2c and parallel port call-back functions and structures --------- */
145 145
146static struct i2c_adapter parport_adapter = {
147 .owner = THIS_MODULE,
148 .class = I2C_CLASS_HWMON,
149 .id = I2C_HW_B_LP,
150 .name = "Parallel port adapter",
151};
152
153static void i2c_parport_attach (struct parport *port) 146static void i2c_parport_attach (struct parport *port)
154{ 147{
155 struct i2c_par *adapter; 148 struct i2c_par *adapter;
@@ -169,10 +162,17 @@ static void i2c_parport_attach (struct parport *port)
169 } 162 }
170 163
171 /* Fill the rest of the structure */ 164 /* Fill the rest of the structure */
172 adapter->adapter = parport_adapter; 165 adapter->adapter.owner = THIS_MODULE;
166 adapter->adapter.class = I2C_CLASS_HWMON;
167 adapter->adapter.id = I2C_HW_B_LP;
168 strlcpy(adapter->adapter.name, "Parallel port adapter",
169 sizeof(adapter->adapter.name));
173 adapter->algo_data = parport_algo_data; 170 adapter->algo_data = parport_algo_data;
174 if (!adapter_parm[type].getscl.val) 171 /* Slow down if we can't sense SCL */
172 if (!adapter_parm[type].getscl.val) {
175 adapter->algo_data.getscl = NULL; 173 adapter->algo_data.getscl = NULL;
174 adapter->algo_data.udelay = 50; /* ~10 kbps */
175 }
176 adapter->algo_data.data = port; 176 adapter->algo_data.data = port;
177 adapter->adapter.algo_data = &adapter->algo_data; 177 adapter->adapter.algo_data = &adapter->algo_data;
178 178
@@ -214,11 +214,12 @@ static void i2c_parport_detach (struct parport *port)
214 for (prev = NULL, adapter = adapter_list; adapter; 214 for (prev = NULL, adapter = adapter_list; adapter;
215 prev = adapter, adapter = adapter->next) { 215 prev = adapter, adapter = adapter->next) {
216 if (adapter->pdev->port == port) { 216 if (adapter->pdev->port == port) {
217 i2c_del_adapter(&adapter->adapter);
218
217 /* Un-init if needed (power off...) */ 219 /* Un-init if needed (power off...) */
218 if (adapter_parm[type].init.val) 220 if (adapter_parm[type].init.val)
219 line_set(port, 0, &adapter_parm[type].init); 221 line_set(port, 0, &adapter_parm[type].init);
220 222
221 i2c_del_adapter(&adapter->adapter);
222 parport_unregister_device(adapter->pdev); 223 parport_unregister_device(adapter->pdev);
223 if (prev) 224 if (prev)
224 prev->next = adapter->next; 225 prev->next = adapter->next;
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index bf89eeef74e9..58e32714afb5 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -358,7 +358,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev,
358 } 358 }
359 359
360 smbus->adapter.owner = THIS_MODULE; 360 smbus->adapter.owner = THIS_MODULE;
361 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 361 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
362 "PA Semi SMBus adapter at 0x%lx", smbus->base); 362 "PA Semi SMBus adapter at 0x%lx", smbus->base);
363 smbus->adapter.class = I2C_CLASS_HWMON; 363 smbus->adapter.class = I2C_CLASS_HWMON;
364 smbus->adapter.algo = &smbus_algorithm; 364 smbus->adapter.algo = &smbus_algorithm;
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index cc6536a19eca..5f94e617fe0c 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -28,6 +28,7 @@
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/wait.h> 29#include <linux/wait.h>
30 30
31#include <linux/isa.h>
31#include <linux/i2c.h> 32#include <linux/i2c.h>
32#include <linux/i2c-algo-pca.h> 33#include <linux/i2c-algo-pca.h>
33 34
@@ -119,27 +120,26 @@ static struct i2c_adapter pca_isa_ops = {
119 .name = "PCA9564 ISA Adapter", 120 .name = "PCA9564 ISA Adapter",
120}; 121};
121 122
122static int __init pca_isa_init(void) 123static int __devinit pca_isa_probe(struct device *dev, unsigned int id)
123{ 124{
124
125 init_waitqueue_head(&pca_wait); 125 init_waitqueue_head(&pca_wait);
126 126
127 printk(KERN_INFO "i2c-pca-isa: i/o base %#08lx. irq %d\n", base, irq); 127 dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq);
128 128
129 if (!request_region(base, IO_SIZE, "i2c-pca-isa")) { 129 if (!request_region(base, IO_SIZE, "i2c-pca-isa")) {
130 printk(KERN_ERR "i2c-pca-isa: I/O address %#08lx is in use.\n", base); 130 dev_err(dev, "I/O address %#08lx is in use\n", base);
131 goto out; 131 goto out;
132 } 132 }
133 133
134 if (irq > -1) { 134 if (irq > -1) {
135 if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) { 135 if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) {
136 printk(KERN_ERR "i2c-pca-isa: Request irq%d failed\n", irq); 136 dev_err(dev, "Request irq%d failed\n", irq);
137 goto out_region; 137 goto out_region;
138 } 138 }
139 } 139 }
140 140
141 if (i2c_pca_add_bus(&pca_isa_ops) < 0) { 141 if (i2c_pca_add_bus(&pca_isa_ops) < 0) {
142 printk(KERN_ERR "i2c-pca-isa: Failed to add i2c bus\n"); 142 dev_err(dev, "Failed to add i2c bus\n");
143 goto out_irq; 143 goto out_irq;
144 } 144 }
145 145
@@ -154,7 +154,7 @@ static int __init pca_isa_init(void)
154 return -ENODEV; 154 return -ENODEV;
155} 155}
156 156
157static void pca_isa_exit(void) 157static int __devexit pca_isa_remove(struct device *dev, unsigned int id)
158{ 158{
159 i2c_del_adapter(&pca_isa_ops); 159 i2c_del_adapter(&pca_isa_ops);
160 160
@@ -163,6 +163,27 @@ static void pca_isa_exit(void)
163 free_irq(irq, &pca_isa_ops); 163 free_irq(irq, &pca_isa_ops);
164 } 164 }
165 release_region(base, IO_SIZE); 165 release_region(base, IO_SIZE);
166
167 return 0;
168}
169
170static struct isa_driver pca_isa_driver = {
171 .probe = pca_isa_probe,
172 .remove = __devexit_p(pca_isa_remove),
173 .driver = {
174 .owner = THIS_MODULE,
175 .name = "i2c-pca-isa",
176 }
177};
178
179static int __init pca_isa_init(void)
180{
181 return isa_register_driver(&pca_isa_driver, 1);
182}
183
184static void __exit pca_isa_exit(void)
185{
186 isa_unregister_driver(&pca_isa_driver);
166} 187}
167 188
168MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); 189MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 21b180904085..5a52bf5e3fb0 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -428,7 +428,7 @@ static int __devinit piix4_probe(struct pci_dev *dev,
428 /* set up the sysfs linkage to our parent device */ 428 /* set up the sysfs linkage to our parent device */
429 piix4_adapter.dev.parent = &dev->dev; 429 piix4_adapter.dev.parent = &dev->dev;
430 430
431 snprintf(piix4_adapter.name, I2C_NAME_SIZE, 431 snprintf(piix4_adapter.name, sizeof(piix4_adapter.name),
432 "SMBus PIIX4 adapter at %04x", piix4_smba); 432 "SMBus PIIX4 adapter at %04x", piix4_smba);
433 433
434 if ((retval = i2c_add_adapter(&piix4_adapter))) { 434 if ((retval = i2c_add_adapter(&piix4_adapter))) {
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 14e83d0aac8c..c059b27fa881 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -539,6 +539,18 @@ static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
539 writel(icr | ICR_START | ICR_TB, _ICR(i2c)); 539 writel(icr | ICR_START | ICR_TB, _ICR(i2c));
540} 540}
541 541
542static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
543{
544 u32 icr;
545
546 /*
547 * Clear the STOP and ACK flags
548 */
549 icr = readl(_ICR(i2c));
550 icr &= ~(ICR_STOP | ICR_ACKNAK);
551 writel(icr, _IRC(i2c));
552}
553
542/* 554/*
543 * We are protected by the adapter bus mutex. 555 * We are protected by the adapter bus mutex.
544 */ 556 */
@@ -581,6 +593,7 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
581 * The rest of the processing occurs in the interrupt handler. 593 * The rest of the processing occurs in the interrupt handler.
582 */ 594 */
583 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 595 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
596 i2c_pxa_stop_message(i2c);
584 597
585 /* 598 /*
586 * We place the return code in i2c->msg_idx. 599 * We place the return code in i2c->msg_idx.
@@ -825,7 +838,7 @@ static const struct i2c_algorithm i2c_pxa_algorithm = {
825}; 838};
826 839
827static struct pxa_i2c i2c_pxa = { 840static struct pxa_i2c i2c_pxa = {
828 .lock = SPIN_LOCK_UNLOCKED, 841 .lock = __SPIN_LOCK_UNLOCKED(i2c_pxa.lock),
829 .adap = { 842 .adap = {
830 .owner = THIS_MODULE, 843 .owner = THIS_MODULE,
831 .algo = &i2c_pxa_algorithm, 844 .algo = &i2c_pxa_algorithm,
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 556f244aae76..e68a96f589fd 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -61,6 +61,8 @@ struct s3c24xx_i2c {
61 unsigned int msg_idx; 61 unsigned int msg_idx;
62 unsigned int msg_ptr; 62 unsigned int msg_ptr;
63 63
64 unsigned int tx_setup;
65
64 enum s3c24xx_i2c_state state; 66 enum s3c24xx_i2c_state state;
65 67
66 void __iomem *regs; 68 void __iomem *regs;
@@ -199,8 +201,11 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c,
199 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); 201 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr);
200 writeb(addr, i2c->regs + S3C2410_IICDS); 202 writeb(addr, i2c->regs + S3C2410_IICDS);
201 203
202 // delay a bit and reset iiccon before setting start (per samsung) 204 /* delay here to ensure the data byte has gotten onto the bus
203 udelay(1); 205 * before the transaction is started */
206
207 ndelay(i2c->tx_setup);
208
204 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); 209 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon);
205 writel(iiccon, i2c->regs + S3C2410_IICCON); 210 writel(iiccon, i2c->regs + S3C2410_IICCON);
206 211
@@ -322,7 +327,15 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
322 if (!is_msgend(i2c)) { 327 if (!is_msgend(i2c)) {
323 byte = i2c->msg->buf[i2c->msg_ptr++]; 328 byte = i2c->msg->buf[i2c->msg_ptr++];
324 writeb(byte, i2c->regs + S3C2410_IICDS); 329 writeb(byte, i2c->regs + S3C2410_IICDS);
325 330
331 /* delay after writing the byte to allow the
332 * data setup time on the bus, as writing the
333 * data to the register causes the first bit
334 * to appear on SDA, and SCL will change as
335 * soon as the interrupt is acknowledged */
336
337 ndelay(i2c->tx_setup);
338
326 } else if (!is_lastmsg(i2c)) { 339 } else if (!is_lastmsg(i2c)) {
327 /* we need to go to the next i2c message */ 340 /* we need to go to the next i2c message */
328 341
@@ -570,9 +583,10 @@ static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
570}; 583};
571 584
572static struct s3c24xx_i2c s3c24xx_i2c = { 585static struct s3c24xx_i2c s3c24xx_i2c = {
573 .lock = SPIN_LOCK_UNLOCKED, 586 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_i2c.lock),
574 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait), 587 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait),
575 .adap = { 588 .tx_setup = 50,
589 .adap = {
576 .name = "s3c2410-i2c", 590 .name = "s3c2410-i2c",
577 .owner = THIS_MODULE, 591 .owner = THIS_MODULE,
578 .algo = &s3c24xx_i2c_algorithm, 592 .algo = &s3c24xx_i2c_algorithm,
@@ -731,26 +745,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
731 return 0; 745 return 0;
732} 746}
733 747
734static void s3c24xx_i2c_free(struct s3c24xx_i2c *i2c)
735{
736 if (i2c->clk != NULL && !IS_ERR(i2c->clk)) {
737 clk_disable(i2c->clk);
738 clk_put(i2c->clk);
739 i2c->clk = NULL;
740 }
741
742 if (i2c->regs != NULL) {
743 iounmap(i2c->regs);
744 i2c->regs = NULL;
745 }
746
747 if (i2c->ioarea != NULL) {
748 release_resource(i2c->ioarea);
749 kfree(i2c->ioarea);
750 i2c->ioarea = NULL;
751 }
752}
753
754/* s3c24xx_i2c_probe 748/* s3c24xx_i2c_probe
755 * 749 *
756 * called by the bus driver when a suitable device is found 750 * called by the bus driver when a suitable device is found
@@ -769,7 +763,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
769 if (IS_ERR(i2c->clk)) { 763 if (IS_ERR(i2c->clk)) {
770 dev_err(&pdev->dev, "cannot get clock\n"); 764 dev_err(&pdev->dev, "cannot get clock\n");
771 ret = -ENOENT; 765 ret = -ENOENT;
772 goto out; 766 goto err_noclk;
773 } 767 }
774 768
775 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); 769 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
@@ -782,7 +776,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
782 if (res == NULL) { 776 if (res == NULL) {
783 dev_err(&pdev->dev, "cannot find IO resource\n"); 777 dev_err(&pdev->dev, "cannot find IO resource\n");
784 ret = -ENOENT; 778 ret = -ENOENT;
785 goto out; 779 goto err_clk;
786 } 780 }
787 781
788 i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1, 782 i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1,
@@ -791,7 +785,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
791 if (i2c->ioarea == NULL) { 785 if (i2c->ioarea == NULL) {
792 dev_err(&pdev->dev, "cannot request IO\n"); 786 dev_err(&pdev->dev, "cannot request IO\n");
793 ret = -ENXIO; 787 ret = -ENXIO;
794 goto out; 788 goto err_clk;
795 } 789 }
796 790
797 i2c->regs = ioremap(res->start, (res->end-res->start)+1); 791 i2c->regs = ioremap(res->start, (res->end-res->start)+1);
@@ -799,7 +793,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
799 if (i2c->regs == NULL) { 793 if (i2c->regs == NULL) {
800 dev_err(&pdev->dev, "cannot map IO\n"); 794 dev_err(&pdev->dev, "cannot map IO\n");
801 ret = -ENXIO; 795 ret = -ENXIO;
802 goto out; 796 goto err_ioarea;
803 } 797 }
804 798
805 dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res); 799 dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res);
@@ -813,7 +807,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
813 807
814 ret = s3c24xx_i2c_init(i2c); 808 ret = s3c24xx_i2c_init(i2c);
815 if (ret != 0) 809 if (ret != 0)
816 goto out; 810 goto err_iomap;
817 811
818 /* find the IRQ for this unit (note, this relies on the init call to 812 /* find the IRQ for this unit (note, this relies on the init call to
819 * ensure no current IRQs pending 813 * ensure no current IRQs pending
@@ -823,7 +817,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
823 if (res == NULL) { 817 if (res == NULL) {
824 dev_err(&pdev->dev, "cannot find IRQ\n"); 818 dev_err(&pdev->dev, "cannot find IRQ\n");
825 ret = -ENOENT; 819 ret = -ENOENT;
826 goto out; 820 goto err_iomap;
827 } 821 }
828 822
829 ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, 823 ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED,
@@ -831,7 +825,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
831 825
832 if (ret != 0) { 826 if (ret != 0) {
833 dev_err(&pdev->dev, "cannot claim IRQ\n"); 827 dev_err(&pdev->dev, "cannot claim IRQ\n");
834 goto out; 828 goto err_iomap;
835 } 829 }
836 830
837 i2c->irq = res; 831 i2c->irq = res;
@@ -841,17 +835,29 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
841 ret = i2c_add_adapter(&i2c->adap); 835 ret = i2c_add_adapter(&i2c->adap);
842 if (ret < 0) { 836 if (ret < 0) {
843 dev_err(&pdev->dev, "failed to add bus to i2c core\n"); 837 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
844 goto out; 838 goto err_irq;
845 } 839 }
846 840
847 platform_set_drvdata(pdev, i2c); 841 platform_set_drvdata(pdev, i2c);
848 842
849 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id); 843 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id);
844 return 0;
850 845
851 out: 846 err_irq:
852 if (ret < 0) 847 free_irq(i2c->irq->start, i2c);
853 s3c24xx_i2c_free(i2c); 848
849 err_iomap:
850 iounmap(i2c->regs);
854 851
852 err_ioarea:
853 release_resource(i2c->ioarea);
854 kfree(i2c->ioarea);
855
856 err_clk:
857 clk_disable(i2c->clk);
858 clk_put(i2c->clk);
859
860 err_noclk:
855 return ret; 861 return ret;
856} 862}
857 863
@@ -863,11 +869,17 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
863static int s3c24xx_i2c_remove(struct platform_device *pdev) 869static int s3c24xx_i2c_remove(struct platform_device *pdev)
864{ 870{
865 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); 871 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
866 872
867 if (i2c != NULL) { 873 i2c_del_adapter(&i2c->adap);
868 s3c24xx_i2c_free(i2c); 874 free_irq(i2c->irq->start, i2c);
869 platform_set_drvdata(pdev, NULL); 875
870 } 876 clk_disable(i2c->clk);
877 clk_put(i2c->clk);
878
879 iounmap(i2c->regs);
880
881 release_resource(i2c->ioarea);
882 kfree(i2c->ioarea);
871 883
872 return 0; 884 return 0;
873} 885}
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c
new file mode 100644
index 000000000000..10af8d31e12a
--- /dev/null
+++ b/drivers/i2c/busses/i2c-simtec.c
@@ -0,0 +1,186 @@
1/*
2 * Copyright (C) 2005 Simtec Electronics
3 * Ben Dooks <ben@simtec.co.uk>
4 *
5 * Simtec Generic I2C Controller
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
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/platform_device.h>
26
27#include <linux/i2c.h>
28#include <linux/i2c-algo-bit.h>
29
30#include <asm/io.h>
31
32struct simtec_i2c_data {
33 struct resource *ioarea;
34 void __iomem *reg;
35 struct i2c_adapter adap;
36 struct i2c_algo_bit_data bit;
37};
38
39#define CMD_SET_SDA (1<<2)
40#define CMD_SET_SCL (1<<3)
41
42#define STATE_SDA (1<<0)
43#define STATE_SCL (1<<1)
44
45/* i2c bit-bus functions */
46
47static void simtec_i2c_setsda(void *pw, int state)
48{
49 struct simtec_i2c_data *pd = pw;
50 writeb(CMD_SET_SDA | (state ? STATE_SDA : 0), pd->reg);
51}
52
53static void simtec_i2c_setscl(void *pw, int state)
54{
55 struct simtec_i2c_data *pd = pw;
56 writeb(CMD_SET_SCL | (state ? STATE_SCL : 0), pd->reg);
57}
58
59static int simtec_i2c_getsda(void *pw)
60{
61 struct simtec_i2c_data *pd = pw;
62 return readb(pd->reg) & STATE_SDA ? 1 : 0;
63}
64
65static int simtec_i2c_getscl(void *pw)
66{
67 struct simtec_i2c_data *pd = pw;
68 return readb(pd->reg) & STATE_SCL ? 1 : 0;
69}
70
71/* device registration */
72
73static int simtec_i2c_probe(struct platform_device *dev)
74{
75 struct simtec_i2c_data *pd;
76 struct resource *res;
77 int size;
78 int ret;
79
80 pd = kzalloc(sizeof(struct simtec_i2c_data), GFP_KERNEL);
81 if (pd == NULL) {
82 dev_err(&dev->dev, "cannot allocate private data\n");
83 return -ENOMEM;
84 }
85
86 platform_set_drvdata(dev, pd);
87
88 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
89 if (res == NULL) {
90 dev_err(&dev->dev, "cannot find IO resource\n");
91 ret = -ENOENT;
92 goto err;
93 }
94
95 size = (res->end-res->start)+1;
96
97 pd->ioarea = request_mem_region(res->start, size, dev->name);
98 if (pd->ioarea == NULL) {
99 dev_err(&dev->dev, "cannot request IO\n");
100 ret = -ENXIO;
101 goto err;
102 }
103
104 pd->reg = ioremap(res->start, size);
105 if (pd->reg == NULL) {
106 dev_err(&dev->dev, "cannot map IO\n");
107 ret = -ENXIO;
108 goto err_res;
109 }
110
111 /* setup the private data */
112
113 pd->adap.owner = THIS_MODULE;
114 pd->adap.algo_data = &pd->bit;
115 pd->adap.dev.parent = &dev->dev;
116
117 strlcpy(pd->adap.name, "Simtec I2C", sizeof(pd->adap.name));
118
119 pd->bit.data = pd;
120 pd->bit.setsda = simtec_i2c_setsda;
121 pd->bit.setscl = simtec_i2c_setscl;
122 pd->bit.getsda = simtec_i2c_getsda;
123 pd->bit.getscl = simtec_i2c_getscl;
124 pd->bit.timeout = HZ;
125 pd->bit.udelay = 20;
126
127 ret = i2c_bit_add_bus(&pd->adap);
128 if (ret)
129 goto err_all;
130
131 return 0;
132
133 err_all:
134 iounmap(pd->reg);
135
136 err_res:
137 release_resource(pd->ioarea);
138 kfree(pd->ioarea);
139
140 err:
141 kfree(pd);
142 return ret;
143}
144
145static int simtec_i2c_remove(struct platform_device *dev)
146{
147 struct simtec_i2c_data *pd = platform_get_drvdata(dev);
148
149 i2c_del_adapter(&pd->adap);
150
151 iounmap(pd->reg);
152 release_resource(pd->ioarea);
153 kfree(pd->ioarea);
154 kfree(pd);
155
156 return 0;
157}
158
159
160/* device driver */
161
162static struct platform_driver simtec_i2c_driver = {
163 .driver = {
164 .name = "simtec-i2c",
165 .owner = THIS_MODULE,
166 },
167 .probe = simtec_i2c_probe,
168 .remove = simtec_i2c_remove,
169};
170
171static int __init i2c_adap_simtec_init(void)
172{
173 return platform_driver_register(&simtec_i2c_driver);
174}
175
176static void __exit i2c_adap_simtec_exit(void)
177{
178 platform_driver_unregister(&simtec_i2c_driver);
179}
180
181module_init(i2c_adap_simtec_init);
182module_exit(i2c_adap_simtec_exit);
183
184MODULE_DESCRIPTION("Simtec Generic I2C Bus driver");
185MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
186MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 4157b0cd604c..dc235bb8e24d 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -300,7 +300,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
300 /* set up the sysfs linkage to our parent device */ 300 /* set up the sysfs linkage to our parent device */
301 sis96x_adapter.dev.parent = &dev->dev; 301 sis96x_adapter.dev.parent = &dev->dev;
302 302
303 snprintf(sis96x_adapter.name, I2C_NAME_SIZE, 303 snprintf(sis96x_adapter.name, sizeof(sis96x_adapter.name),
304 "SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base); 304 "SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base);
305 305
306 if ((retval = i2c_add_adapter(&sis96x_adapter))) { 306 if ((retval = i2c_add_adapter(&sis96x_adapter))) {
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
new file mode 100644
index 000000000000..907999049d50
--- /dev/null
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -0,0 +1,277 @@
1/*
2 * driver for the i2c-tiny-usb adapter - 1.0
3 * http://www.harbaum.org/till/i2c_tiny_usb
4 *
5 * Copyright (C) 2006-2007 Till Harbaum (Till@Harbaum.org)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/module.h>
16
17/* include interfaces to usb layer */
18#include <linux/usb.h>
19
20/* include interface to i2c layer */
21#include <linux/i2c.h>
22
23/* commands via USB, must match command ids in the firmware */
24#define CMD_ECHO 0
25#define CMD_GET_FUNC 1
26#define CMD_SET_DELAY 2
27#define CMD_GET_STATUS 3
28
29#define CMD_I2C_IO 4
30#define CMD_I2C_IO_BEGIN (1<<0)
31#define CMD_I2C_IO_END (1<<1)
32
33/* i2c bit delay, default is 10us -> 100kHz */
34static int delay = 10;
35module_param(delay, int, 0);
36MODULE_PARM_DESC(delay, "bit delay in microseconds, "
37 "e.g. 10 for 100kHz (default is 100kHz)");
38
39static int usb_read(struct i2c_adapter *adapter, int cmd,
40 int value, int index, void *data, int len);
41
42static int usb_write(struct i2c_adapter *adapter, int cmd,
43 int value, int index, void *data, int len);
44
45/* ----- begin of i2c layer ---------------------------------------------- */
46
47#define STATUS_IDLE 0
48#define STATUS_ADDRESS_ACK 1
49#define STATUS_ADDRESS_NAK 2
50
51static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
52{
53 unsigned char status;
54 struct i2c_msg *pmsg;
55 int i;
56
57 dev_dbg(&adapter->dev, "master xfer %d messages:\n", num);
58
59 for (i = 0 ; i < num ; i++) {
60 int cmd = CMD_I2C_IO;
61
62 if (i == 0)
63 cmd |= CMD_I2C_IO_BEGIN;
64
65 if (i == num-1)
66 cmd |= CMD_I2C_IO_END;
67
68 pmsg = &msgs[i];
69
70 dev_dbg(&adapter->dev,
71 " %d: %s (flags %d) %d bytes to 0x%02x\n",
72 i, pmsg->flags & I2C_M_RD ? "read" : "write",
73 pmsg->flags, pmsg->len, pmsg->addr);
74
75 /* and directly send the message */
76 if (pmsg->flags & I2C_M_RD) {
77 /* read data */
78 if (usb_read(adapter, cmd,
79 pmsg->flags, pmsg->addr,
80 pmsg->buf, pmsg->len) != pmsg->len) {
81 dev_err(&adapter->dev,
82 "failure reading data\n");
83 return -EREMOTEIO;
84 }
85 } else {
86 /* write data */
87 if (usb_write(adapter, cmd,
88 pmsg->flags, pmsg->addr,
89 pmsg->buf, pmsg->len) != pmsg->len) {
90 dev_err(&adapter->dev,
91 "failure writing data\n");
92 return -EREMOTEIO;
93 }
94 }
95
96 /* read status */
97 if (usb_read(adapter, CMD_GET_STATUS, 0, 0, &status, 1) != 1) {
98 dev_err(&adapter->dev, "failure reading status\n");
99 return -EREMOTEIO;
100 }
101
102 dev_dbg(&adapter->dev, " status = %d\n", status);
103 if (status == STATUS_ADDRESS_NAK)
104 return -EREMOTEIO;
105 }
106
107 return i;
108}
109
110static u32 usb_func(struct i2c_adapter *adapter)
111{
112 u32 func;
113
114 /* get functionality from adapter */
115 if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) !=
116 sizeof(func)) {
117 dev_err(&adapter->dev, "failure reading functionality\n");
118 return 0;
119 }
120
121 return func;
122}
123
124/* This is the actual algorithm we define */
125static const struct i2c_algorithm usb_algorithm = {
126 .master_xfer = usb_xfer,
127 .functionality = usb_func,
128};
129
130/* ----- end of i2c layer ------------------------------------------------ */
131
132/* ----- begin of usb layer ---------------------------------------------- */
133
134/* The usb i2c interface uses a vid/pid pair donated by */
135/* Future Technology Devices International Ltd. */
136static struct usb_device_id i2c_tiny_usb_table [] = {
137 { USB_DEVICE(0x0403, 0xc631) },
138 { } /* Terminating entry */
139};
140
141MODULE_DEVICE_TABLE(usb, i2c_tiny_usb_table);
142
143/* Structure to hold all of our device specific stuff */
144struct i2c_tiny_usb {
145 struct usb_device *usb_dev; /* the usb device for this device */
146 struct usb_interface *interface; /* the interface for this device */
147 struct i2c_adapter adapter; /* i2c related things */
148};
149
150static int usb_read(struct i2c_adapter *adapter, int cmd,
151 int value, int index, void *data, int len)
152{
153 struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data;
154
155 /* do control transfer */
156 return usb_control_msg(dev->usb_dev, usb_rcvctrlpipe(dev->usb_dev, 0),
157 cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE |
158 USB_DIR_IN, value, index, data, len, 2000);
159}
160
161static int usb_write(struct i2c_adapter *adapter, int cmd,
162 int value, int index, void *data, int len)
163{
164 struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data;
165
166 /* do control transfer */
167 return usb_control_msg(dev->usb_dev, usb_sndctrlpipe(dev->usb_dev, 0),
168 cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
169 value, index, data, len, 2000);
170}
171
172static void i2c_tiny_usb_free(struct i2c_tiny_usb *dev)
173{
174 usb_put_dev(dev->usb_dev);
175 kfree(dev);
176}
177
178static int i2c_tiny_usb_probe(struct usb_interface *interface,
179 const struct usb_device_id *id)
180{
181 struct i2c_tiny_usb *dev;
182 int retval = -ENOMEM;
183 u16 version;
184
185 dev_dbg(&interface->dev, "probing usb device\n");
186
187 /* allocate memory for our device state and initialize it */
188 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
189 if (dev == NULL) {
190 dev_err(&interface->dev, "Out of memory\n");
191 goto error;
192 }
193
194 dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
195 dev->interface = interface;
196
197 /* save our data pointer in this interface device */
198 usb_set_intfdata(interface, dev);
199
200 version = le16_to_cpu(dev->usb_dev->descriptor.bcdDevice);
201 dev_info(&interface->dev,
202 "version %x.%02x found at bus %03d address %03d\n",
203 version >> 8, version & 0xff,
204 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
205
206 /* setup i2c adapter description */
207 dev->adapter.owner = THIS_MODULE;
208 dev->adapter.class = I2C_CLASS_HWMON;
209 dev->adapter.algo = &usb_algorithm;
210 dev->adapter.algo_data = dev;
211 snprintf(dev->adapter.name, I2C_NAME_SIZE,
212 "i2c-tiny-usb at bus %03d device %03d",
213 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
214
215 if (usb_write(&dev->adapter, CMD_SET_DELAY,
216 cpu_to_le16(delay), 0, NULL, 0) != 0) {
217 dev_err(&dev->adapter.dev,
218 "failure setting delay to %dus\n", delay);
219 retval = -EIO;
220 goto error;
221 }
222
223 dev->adapter.dev.parent = &dev->interface->dev;
224
225 /* and finally attach to i2c layer */
226 i2c_add_adapter(&dev->adapter);
227
228 /* inform user about successful attachment to i2c layer */
229 dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n");
230
231 return 0;
232
233 error:
234 if (dev)
235 i2c_tiny_usb_free(dev);
236
237 return retval;
238}
239
240static void i2c_tiny_usb_disconnect(struct usb_interface *interface)
241{
242 struct i2c_tiny_usb *dev = usb_get_intfdata(interface);
243
244 i2c_del_adapter(&dev->adapter);
245 usb_set_intfdata(interface, NULL);
246 i2c_tiny_usb_free(dev);
247
248 dev_dbg(&interface->dev, "disconnected\n");
249}
250
251static struct usb_driver i2c_tiny_usb_driver = {
252 .name = "i2c-tiny-usb",
253 .probe = i2c_tiny_usb_probe,
254 .disconnect = i2c_tiny_usb_disconnect,
255 .id_table = i2c_tiny_usb_table,
256};
257
258static int __init usb_i2c_tiny_usb_init(void)
259{
260 /* register this driver with the USB subsystem */
261 return usb_register(&i2c_tiny_usb_driver);
262}
263
264static void __exit usb_i2c_tiny_usb_exit(void)
265{
266 /* deregister this driver with the USB subsystem */
267 usb_deregister(&i2c_tiny_usb_driver);
268}
269
270module_init(usb_i2c_tiny_usb_init);
271module_exit(usb_i2c_tiny_usb_exit);
272
273/* ----- end of usb layer ------------------------------------------------ */
274
275MODULE_AUTHOR("Till Harbaum <Till@Harbaum.org>");
276MODULE_DESCRIPTION("i2c-tiny-usb driver v1.0");
277MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 03c5fc868548..7a2bc06304fc 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -404,7 +404,7 @@ found:
404 } 404 }
405 405
406 vt596_adapter.dev.parent = &pdev->dev; 406 vt596_adapter.dev.parent = &pdev->dev;
407 snprintf(vt596_adapter.name, I2C_NAME_SIZE, 407 snprintf(vt596_adapter.name, sizeof(vt596_adapter.name),
408 "SMBus Via Pro adapter at %04x", vt596_smba); 408 "SMBus Via Pro adapter at %04x", vt596_smba);
409 409
410 vt596_pdev = pci_dev_get(pdev); 410 vt596_pdev = pci_dev_get(pdev);
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 0b082c5a0195..0db56e7bc34e 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -441,7 +441,7 @@ static __init struct scx200_acb_iface *scx200_create_iface(const char *text,
441 441
442 adapter = &iface->adapter; 442 adapter = &iface->adapter;
443 i2c_set_adapdata(adapter, iface); 443 i2c_set_adapdata(adapter, iface);
444 snprintf(adapter->name, I2C_NAME_SIZE, "%s ACB%d", text, index); 444 snprintf(adapter->name, sizeof(adapter->name), "%s ACB%d", text, index);
445 adapter->owner = THIS_MODULE; 445 adapter->owner = THIS_MODULE;
446 adapter->id = I2C_HW_SMBUS_SCX200; 446 adapter->id = I2C_HW_SMBUS_SCX200;
447 adapter->algo = &scx200_acb_algorithm; 447 adapter->algo = &scx200_acb_algorithm;
@@ -599,6 +599,7 @@ static __init int scx200_scan_pci(void)
599 else { 599 else {
600 int i; 600 int i;
601 601
602 pci_dev_put(pdev);
602 for (i = 0; i < MAX_DEVICES; ++i) { 603 for (i = 0; i < MAX_DEVICES; ++i) {
603 if (base[i] == 0) 604 if (base[i] == 0)
604 continue; 605 continue;
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 87ee3ce58618..ea085a006ead 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -3,11 +3,10 @@
3# 3#
4 4
5menu "Miscellaneous I2C Chip support" 5menu "Miscellaneous I2C Chip support"
6 depends on I2C
7 6
8config SENSORS_DS1337 7config SENSORS_DS1337
9 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock" 8 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock"
10 depends on I2C && EXPERIMENTAL 9 depends on EXPERIMENTAL
11 help 10 help
12 If you say yes here you get support for Dallas Semiconductor 11 If you say yes here you get support for Dallas Semiconductor
13 DS1337 and DS1339 real-time clock chips. 12 DS1337 and DS1339 real-time clock chips.
@@ -17,7 +16,7 @@ config SENSORS_DS1337
17 16
18config SENSORS_DS1374 17config SENSORS_DS1374
19 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock" 18 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock"
20 depends on I2C && EXPERIMENTAL 19 depends on EXPERIMENTAL
21 help 20 help
22 If you say yes here you get support for Dallas Semiconductor 21 If you say yes here you get support for Dallas Semiconductor
23 DS1374 real-time clock chips. 22 DS1374 real-time clock chips.
@@ -27,7 +26,7 @@ config SENSORS_DS1374
27 26
28config SENSORS_EEPROM 27config SENSORS_EEPROM
29 tristate "EEPROM reader" 28 tristate "EEPROM reader"
30 depends on I2C && EXPERIMENTAL 29 depends on EXPERIMENTAL
31 help 30 help
32 If you say yes here you get read-only access to the EEPROM data 31 If you say yes here you get read-only access to the EEPROM data
33 available on modern memory DIMMs and Sony Vaio laptops. Such 32 available on modern memory DIMMs and Sony Vaio laptops. Such
@@ -38,7 +37,7 @@ config SENSORS_EEPROM
38 37
39config SENSORS_PCF8574 38config SENSORS_PCF8574
40 tristate "Philips PCF8574 and PCF8574A" 39 tristate "Philips PCF8574 and PCF8574A"
41 depends on I2C && EXPERIMENTAL 40 depends on EXPERIMENTAL
42 default n 41 default n
43 help 42 help
44 If you say yes here you get support for Philips PCF8574 and 43 If you say yes here you get support for Philips PCF8574 and
@@ -52,7 +51,7 @@ config SENSORS_PCF8574
52 51
53config SENSORS_PCA9539 52config SENSORS_PCA9539
54 tristate "Philips PCA9539 16-bit I/O port" 53 tristate "Philips PCA9539 16-bit I/O port"
55 depends on I2C && EXPERIMENTAL 54 depends on EXPERIMENTAL
56 help 55 help
57 If you say yes here you get support for the Philips PCA9539 56 If you say yes here you get support for the Philips PCA9539
58 16-bit I/O port. 57 16-bit I/O port.
@@ -62,7 +61,7 @@ config SENSORS_PCA9539
62 61
63config SENSORS_PCF8591 62config SENSORS_PCF8591
64 tristate "Philips PCF8591" 63 tristate "Philips PCF8591"
65 depends on I2C && EXPERIMENTAL 64 depends on EXPERIMENTAL
66 default n 65 default n
67 help 66 help
68 If you say yes here you get support for Philips PCF8591 chips. 67 If you say yes here you get support for Philips PCF8591 chips.
@@ -75,7 +74,7 @@ config SENSORS_PCF8591
75 74
76config ISP1301_OMAP 75config ISP1301_OMAP
77 tristate "Philips ISP1301 with OMAP OTG" 76 tristate "Philips ISP1301 with OMAP OTG"
78 depends on I2C && ARCH_OMAP_OTG 77 depends on ARCH_OMAP_OTG
79 help 78 help
80 If you say yes here you get support for the Philips ISP1301 79 If you say yes here you get support for the Philips ISP1301
81 USB-On-The-Go transceiver working with the OMAP OTG controller. 80 USB-On-The-Go transceiver working with the OMAP OTG controller.
@@ -90,7 +89,7 @@ config ISP1301_OMAP
90# and having mostly OMAP-specific board support 89# and having mostly OMAP-specific board support
91config TPS65010 90config TPS65010
92 tristate "TPS6501x Power Management chips" 91 tristate "TPS6501x Power Management chips"
93 depends on I2C && ARCH_OMAP 92 depends on ARCH_OMAP
94 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK 93 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK
95 help 94 help
96 If you say yes here you get support for the TPS6501x series of 95 If you say yes here you get support for the TPS6501x series of
@@ -103,7 +102,7 @@ config TPS65010
103 102
104config SENSORS_M41T00 103config SENSORS_M41T00
105 tristate "ST M41T00 RTC chip" 104 tristate "ST M41T00 RTC chip"
106 depends on I2C && PPC32 105 depends on PPC32
107 help 106 help
108 If you say yes here you get support for the ST M41T00 RTC chip. 107 If you say yes here you get support for the ST M41T00 RTC chip.
109 108
@@ -112,7 +111,7 @@ config SENSORS_M41T00
112 111
113config SENSORS_MAX6875 112config SENSORS_MAX6875
114 tristate "Maxim MAX6875 Power supply supervisor" 113 tristate "Maxim MAX6875 Power supply supervisor"
115 depends on I2C && EXPERIMENTAL 114 depends on EXPERIMENTAL
116 help 115 help
117 If you say yes here you get support for the Maxim MAX6875 116 If you say yes here you get support for the Maxim MAX6875
118 EEPROM-programmable, quad power-supply sequencer/supervisor. 117 EEPROM-programmable, quad power-supply sequencer/supervisor.
diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c
new file mode 100644
index 000000000000..ffb35f09df03
--- /dev/null
+++ b/drivers/i2c/i2c-boardinfo.c
@@ -0,0 +1,90 @@
1/*
2 * i2c-boardinfo.h - collect pre-declarations of I2C devices
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include <linux/kernel.h>
20#include <linux/i2c.h>
21
22#include "i2c-core.h"
23
24
25/* These symbols are exported ONLY FOR the i2c core.
26 * No other users will be supported.
27 */
28DEFINE_MUTEX(__i2c_board_lock);
29EXPORT_SYMBOL_GPL(__i2c_board_lock);
30
31LIST_HEAD(__i2c_board_list);
32EXPORT_SYMBOL_GPL(__i2c_board_list);
33
34int __i2c_first_dynamic_bus_num;
35EXPORT_SYMBOL_GPL(__i2c_first_dynamic_bus_num);
36
37
38/**
39 * i2c_register_board_info - statically declare I2C devices
40 * @busnum: identifies the bus to which these devices belong
41 * @info: vector of i2c device descriptors
42 * @len: how many descriptors in the vector; may be zero to reserve
43 * the specified bus number.
44 *
45 * Systems using the Linux I2C driver stack can declare tables of board info
46 * while they initialize. This should be done in board-specific init code
47 * near arch_initcall() time, or equivalent, before any I2C adapter driver is
48 * registered. For example, mainboard init code could define several devices,
49 * as could the init code for each daughtercard in a board stack.
50 *
51 * The I2C devices will be created later, after the adapter for the relevant
52 * bus has been registered. After that moment, standard driver model tools
53 * are used to bind "new style" I2C drivers to the devices. The bus number
54 * for any device declared using this routine is not available for dynamic
55 * allocation.
56 *
57 * The board info passed can safely be __initdata, but be careful of embedded
58 * pointers (for platform_data, functions, etc) since that won't be copied.
59 */
60int __init
61i2c_register_board_info(int busnum,
62 struct i2c_board_info const *info, unsigned len)
63{
64 int status;
65
66 mutex_lock(&__i2c_board_lock);
67
68 /* dynamic bus numbers will be assigned after the last static one */
69 if (busnum >= __i2c_first_dynamic_bus_num)
70 __i2c_first_dynamic_bus_num = busnum + 1;
71
72 for (status = 0; len; len--, info++) {
73 struct i2c_devinfo *devinfo;
74
75 devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL);
76 if (!devinfo) {
77 pr_debug("i2c-core: can't register boardinfo!\n");
78 status = -ENOMEM;
79 break;
80 }
81
82 devinfo->busnum = busnum;
83 devinfo->board_info = *info;
84 list_add_tail(&devinfo->list, &__i2c_board_list);
85 }
86
87 mutex_unlock(&__i2c_board_lock);
88
89 return status;
90}
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 21fe1406c8b4..64f8e56d300e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -35,29 +35,92 @@
35#include <linux/completion.h> 35#include <linux/completion.h>
36#include <asm/uaccess.h> 36#include <asm/uaccess.h>
37 37
38#include "i2c-core.h"
39
38 40
39static LIST_HEAD(adapters); 41static LIST_HEAD(adapters);
40static LIST_HEAD(drivers); 42static LIST_HEAD(drivers);
41static DEFINE_MUTEX(core_lists); 43static DEFINE_MUTEX(core_lists);
42static DEFINE_IDR(i2c_adapter_idr); 44static DEFINE_IDR(i2c_adapter_idr);
43 45
46#define is_newstyle_driver(d) ((d)->probe || (d)->remove)
44 47
45/* ------------------------------------------------------------------------- */ 48/* ------------------------------------------------------------------------- */
46 49
47/* match always succeeds, as we want the probe() to tell if we really accept this match */
48static int i2c_device_match(struct device *dev, struct device_driver *drv) 50static int i2c_device_match(struct device *dev, struct device_driver *drv)
49{ 51{
50 return 1; 52 struct i2c_client *client = to_i2c_client(dev);
53 struct i2c_driver *driver = to_i2c_driver(drv);
54
55 /* make legacy i2c drivers bypass driver model probing entirely;
56 * such drivers scan each i2c adapter/bus themselves.
57 */
58 if (!is_newstyle_driver(driver))
59 return 0;
60
61 /* new style drivers use the same kind of driver matching policy
62 * as platform devices or SPI: compare device and driver IDs.
63 */
64 return strcmp(client->driver_name, drv->name) == 0;
65}
66
67#ifdef CONFIG_HOTPLUG
68
69/* uevent helps with hotplug: modprobe -q $(MODALIAS) */
70static int i2c_device_uevent(struct device *dev, char **envp, int num_envp,
71 char *buffer, int buffer_size)
72{
73 struct i2c_client *client = to_i2c_client(dev);
74 int i = 0, length = 0;
75
76 /* by definition, legacy drivers can't hotplug */
77 if (dev->driver || !client->driver_name)
78 return 0;
79
80 if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
81 "MODALIAS=%s", client->driver_name))
82 return -ENOMEM;
83 envp[i] = NULL;
84 dev_dbg(dev, "uevent\n");
85 return 0;
51} 86}
52 87
88#else
89#define i2c_device_uevent NULL
90#endif /* CONFIG_HOTPLUG */
91
53static int i2c_device_probe(struct device *dev) 92static int i2c_device_probe(struct device *dev)
54{ 93{
55 return -ENODEV; 94 struct i2c_client *client = to_i2c_client(dev);
95 struct i2c_driver *driver = to_i2c_driver(dev->driver);
96
97 if (!driver->probe)
98 return -ENODEV;
99 client->driver = driver;
100 dev_dbg(dev, "probe\n");
101 return driver->probe(client);
56} 102}
57 103
58static int i2c_device_remove(struct device *dev) 104static int i2c_device_remove(struct device *dev)
59{ 105{
60 return 0; 106 struct i2c_client *client = to_i2c_client(dev);
107 struct i2c_driver *driver;
108 int status;
109
110 if (!dev->driver)
111 return 0;
112
113 driver = to_i2c_driver(dev->driver);
114 if (driver->remove) {
115 dev_dbg(dev, "remove\n");
116 status = driver->remove(client);
117 } else {
118 dev->driver = NULL;
119 status = 0;
120 }
121 if (status == 0)
122 client->driver = NULL;
123 return status;
61} 124}
62 125
63static void i2c_device_shutdown(struct device *dev) 126static void i2c_device_shutdown(struct device *dev)
@@ -95,122 +158,184 @@ static int i2c_device_resume(struct device * dev)
95 return driver->resume(to_i2c_client(dev)); 158 return driver->resume(to_i2c_client(dev));
96} 159}
97 160
161static void i2c_client_release(struct device *dev)
162{
163 struct i2c_client *client = to_i2c_client(dev);
164 complete(&client->released);
165}
166
167static void i2c_client_dev_release(struct device *dev)
168{
169 kfree(to_i2c_client(dev));
170}
171
172static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
173{
174 struct i2c_client *client = to_i2c_client(dev);
175 return sprintf(buf, "%s\n", client->name);
176}
177
178static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
179{
180 struct i2c_client *client = to_i2c_client(dev);
181 return client->driver_name
182 ? sprintf(buf, "%s\n", client->driver_name)
183 : 0;
184}
185
186static struct device_attribute i2c_dev_attrs[] = {
187 __ATTR(name, S_IRUGO, show_client_name, NULL),
188 /* modalias helps coldplug: modprobe $(cat .../modalias) */
189 __ATTR(modalias, S_IRUGO, show_modalias, NULL),
190 { },
191};
192
98struct bus_type i2c_bus_type = { 193struct bus_type i2c_bus_type = {
99 .name = "i2c", 194 .name = "i2c",
195 .dev_attrs = i2c_dev_attrs,
100 .match = i2c_device_match, 196 .match = i2c_device_match,
197 .uevent = i2c_device_uevent,
101 .probe = i2c_device_probe, 198 .probe = i2c_device_probe,
102 .remove = i2c_device_remove, 199 .remove = i2c_device_remove,
103 .shutdown = i2c_device_shutdown, 200 .shutdown = i2c_device_shutdown,
104 .suspend = i2c_device_suspend, 201 .suspend = i2c_device_suspend,
105 .resume = i2c_device_resume, 202 .resume = i2c_device_resume,
106}; 203};
204EXPORT_SYMBOL_GPL(i2c_bus_type);
107 205
108/* ------------------------------------------------------------------------- */ 206/**
207 * i2c_new_device - instantiate an i2c device for use with a new style driver
208 * @adap: the adapter managing the device
209 * @info: describes one I2C device; bus_num is ignored
210 *
211 * Create a device to work with a new style i2c driver, where binding is
212 * handled through driver model probe()/remove() methods. This call is not
213 * appropriate for use by mainboad initialization logic, which usually runs
214 * during an arch_initcall() long before any i2c_adapter could exist.
215 *
216 * This returns the new i2c client, which may be saved for later use with
217 * i2c_unregister_device(); or NULL to indicate an error.
218 */
219struct i2c_client *
220i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
221{
222 struct i2c_client *client;
223 int status;
109 224
110void i2c_adapter_dev_release(struct device *dev) 225 client = kzalloc(sizeof *client, GFP_KERNEL);
226 if (!client)
227 return NULL;
228
229 client->adapter = adap;
230
231 client->dev.platform_data = info->platform_data;
232 client->flags = info->flags;
233 client->addr = info->addr;
234 client->irq = info->irq;
235
236 strlcpy(client->driver_name, info->driver_name,
237 sizeof(client->driver_name));
238 strlcpy(client->name, info->type, sizeof(client->name));
239
240 /* a new style driver may be bound to this device when we
241 * return from this function, or any later moment (e.g. maybe
242 * hotplugging will load the driver module). and the device
243 * refcount model is the standard driver model one.
244 */
245 status = i2c_attach_client(client);
246 if (status < 0) {
247 kfree(client);
248 client = NULL;
249 }
250 return client;
251}
252EXPORT_SYMBOL_GPL(i2c_new_device);
253
254
255/**
256 * i2c_unregister_device - reverse effect of i2c_new_device()
257 * @client: value returned from i2c_new_device()
258 */
259void i2c_unregister_device(struct i2c_client *client)
111{ 260{
112 struct i2c_adapter *adap = dev_to_i2c_adapter(dev); 261 struct i2c_adapter *adapter = client->adapter;
113 complete(&adap->dev_released); 262 struct i2c_driver *driver = client->driver;
263
264 if (driver && !is_newstyle_driver(driver)) {
265 dev_err(&client->dev, "can't unregister devices "
266 "with legacy drivers\n");
267 WARN_ON(1);
268 return;
269 }
270
271 mutex_lock(&adapter->clist_lock);
272 list_del(&client->list);
273 mutex_unlock(&adapter->clist_lock);
274
275 device_unregister(&client->dev);
114} 276}
277EXPORT_SYMBOL_GPL(i2c_unregister_device);
115 278
116struct device_driver i2c_adapter_driver = {
117 .owner = THIS_MODULE,
118 .name = "i2c_adapter",
119 .bus = &i2c_bus_type,
120};
121 279
122/* ------------------------------------------------------------------------- */ 280/* ------------------------------------------------------------------------- */
123 281
124/* I2C bus adapters -- one roots each I2C or SMBUS segment */ 282/* I2C bus adapters -- one roots each I2C or SMBUS segment */
125 283
126static void i2c_adapter_class_dev_release(struct class_device *dev) 284void i2c_adapter_dev_release(struct device *dev)
127{ 285{
128 struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev); 286 struct i2c_adapter *adap = to_i2c_adapter(dev);
129 complete(&adap->class_dev_released); 287 complete(&adap->dev_released);
130} 288}
289EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); /* exported to i2c-isa */
131 290
132static ssize_t i2c_adapter_show_name(struct class_device *cdev, char *buf) 291static ssize_t
292show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
133{ 293{
134 struct i2c_adapter *adap = class_dev_to_i2c_adapter(cdev); 294 struct i2c_adapter *adap = to_i2c_adapter(dev);
135 return sprintf(buf, "%s\n", adap->name); 295 return sprintf(buf, "%s\n", adap->name);
136} 296}
137 297
138static struct class_device_attribute i2c_adapter_attrs[] = { 298static struct device_attribute i2c_adapter_attrs[] = {
139 __ATTR(name, S_IRUGO, i2c_adapter_show_name, NULL), 299 __ATTR(name, S_IRUGO, show_adapter_name, NULL),
140 { }, 300 { },
141}; 301};
142 302
143struct class i2c_adapter_class = { 303struct class i2c_adapter_class = {
144 .owner = THIS_MODULE, 304 .owner = THIS_MODULE,
145 .name = "i2c-adapter", 305 .name = "i2c-adapter",
146 .class_dev_attrs = i2c_adapter_attrs, 306 .dev_attrs = i2c_adapter_attrs,
147 .release = &i2c_adapter_class_dev_release,
148}; 307};
308EXPORT_SYMBOL_GPL(i2c_adapter_class); /* exported to i2c-isa */
149 309
150static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) 310static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
151{
152 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
153 return sprintf(buf, "%s\n", adap->name);
154}
155static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
156
157
158static void i2c_client_release(struct device *dev)
159{
160 struct i2c_client *client = to_i2c_client(dev);
161 complete(&client->released);
162}
163
164static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
165{ 311{
166 struct i2c_client *client = to_i2c_client(dev); 312 struct i2c_devinfo *devinfo;
167 return sprintf(buf, "%s\n", client->name); 313
314 mutex_lock(&__i2c_board_lock);
315 list_for_each_entry(devinfo, &__i2c_board_list, list) {
316 if (devinfo->busnum == adapter->nr
317 && !i2c_new_device(adapter,
318 &devinfo->board_info))
319 printk(KERN_ERR "i2c-core: can't create i2c%d-%04x\n",
320 i2c_adapter_id(adapter),
321 devinfo->board_info.addr);
322 }
323 mutex_unlock(&__i2c_board_lock);
168} 324}
169 325
170/* 326static int i2c_register_adapter(struct i2c_adapter *adap)
171 * We can't use the DEVICE_ATTR() macro here, as we used the same name for
172 * an i2c adapter attribute (above).
173 */
174static struct device_attribute dev_attr_client_name =
175 __ATTR(name, S_IRUGO, &show_client_name, NULL);
176
177
178/* ---------------------------------------------------
179 * registering functions
180 * ---------------------------------------------------
181 */
182
183/* -----
184 * i2c_add_adapter is called from within the algorithm layer,
185 * when a new hw adapter registers. A new device is register to be
186 * available for clients.
187 */
188int i2c_add_adapter(struct i2c_adapter *adap)
189{ 327{
190 int id, res = 0; 328 int res = 0;
191 struct list_head *item; 329 struct list_head *item;
192 struct i2c_driver *driver; 330 struct i2c_driver *driver;
193 331
194 mutex_lock(&core_lists);
195
196 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) {
197 res = -ENOMEM;
198 goto out_unlock;
199 }
200
201 res = idr_get_new(&i2c_adapter_idr, adap, &id);
202 if (res < 0) {
203 if (res == -EAGAIN)
204 res = -ENOMEM;
205 goto out_unlock;
206 }
207
208 adap->nr = id & MAX_ID_MASK;
209 mutex_init(&adap->bus_lock); 332 mutex_init(&adap->bus_lock);
210 mutex_init(&adap->clist_lock); 333 mutex_init(&adap->clist_lock);
211 list_add_tail(&adap->list,&adapters);
212 INIT_LIST_HEAD(&adap->clients); 334 INIT_LIST_HEAD(&adap->clients);
213 335
336 mutex_lock(&core_lists);
337 list_add_tail(&adap->list, &adapters);
338
214 /* Add the adapter to the driver core. 339 /* Add the adapter to the driver core.
215 * If the parent pointer is not set up, 340 * If the parent pointer is not set up,
216 * we add this adapter to the host bus. 341 * we add this adapter to the host bus.
@@ -221,27 +346,19 @@ int i2c_add_adapter(struct i2c_adapter *adap)
221 "physical device\n", adap->name); 346 "physical device\n", adap->name);
222 } 347 }
223 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); 348 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
224 adap->dev.driver = &i2c_adapter_driver;
225 adap->dev.release = &i2c_adapter_dev_release; 349 adap->dev.release = &i2c_adapter_dev_release;
350 adap->dev.class = &i2c_adapter_class;
226 res = device_register(&adap->dev); 351 res = device_register(&adap->dev);
227 if (res) 352 if (res)
228 goto out_list; 353 goto out_list;
229 res = device_create_file(&adap->dev, &dev_attr_name);
230 if (res)
231 goto out_unregister;
232
233 /* Add this adapter to the i2c_adapter class */
234 memset(&adap->class_dev, 0x00, sizeof(struct class_device));
235 adap->class_dev.dev = &adap->dev;
236 adap->class_dev.class = &i2c_adapter_class;
237 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
238 res = class_device_register(&adap->class_dev);
239 if (res)
240 goto out_remove_name;
241 354
242 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 355 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
243 356
244 /* inform drivers of new adapters */ 357 /* create pre-declared device nodes for new-style drivers */
358 if (adap->nr < __i2c_first_dynamic_bus_num)
359 i2c_scan_static_board_info(adap);
360
361 /* let legacy drivers scan this bus for matching devices */
245 list_for_each(item,&drivers) { 362 list_for_each(item,&drivers) {
246 driver = list_entry(item, struct i2c_driver, list); 363 driver = list_entry(item, struct i2c_driver, list);
247 if (driver->attach_adapter) 364 if (driver->attach_adapter)
@@ -253,18 +370,98 @@ out_unlock:
253 mutex_unlock(&core_lists); 370 mutex_unlock(&core_lists);
254 return res; 371 return res;
255 372
256out_remove_name:
257 device_remove_file(&adap->dev, &dev_attr_name);
258out_unregister:
259 init_completion(&adap->dev_released); /* Needed? */
260 device_unregister(&adap->dev);
261 wait_for_completion(&adap->dev_released);
262out_list: 373out_list:
263 list_del(&adap->list); 374 list_del(&adap->list);
264 idr_remove(&i2c_adapter_idr, adap->nr); 375 idr_remove(&i2c_adapter_idr, adap->nr);
265 goto out_unlock; 376 goto out_unlock;
266} 377}
267 378
379/**
380 * i2c_add_adapter - declare i2c adapter, use dynamic bus number
381 * @adapter: the adapter to add
382 *
383 * This routine is used to declare an I2C adapter when its bus number
384 * doesn't matter. Examples: for I2C adapters dynamically added by
385 * USB links or PCI plugin cards.
386 *
387 * When this returns zero, a new bus number was allocated and stored
388 * in adap->nr, and the specified adapter became available for clients.
389 * Otherwise, a negative errno value is returned.
390 */
391int i2c_add_adapter(struct i2c_adapter *adapter)
392{
393 int id, res = 0;
394
395retry:
396 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
397 return -ENOMEM;
398
399 mutex_lock(&core_lists);
400 /* "above" here means "above or equal to", sigh */
401 res = idr_get_new_above(&i2c_adapter_idr, adapter,
402 __i2c_first_dynamic_bus_num, &id);
403 mutex_unlock(&core_lists);
404
405 if (res < 0) {
406 if (res == -EAGAIN)
407 goto retry;
408 return res;
409 }
410
411 adapter->nr = id;
412 return i2c_register_adapter(adapter);
413}
414EXPORT_SYMBOL(i2c_add_adapter);
415
416/**
417 * i2c_add_numbered_adapter - declare i2c adapter, use static bus number
418 * @adap: the adapter to register (with adap->nr initialized)
419 *
420 * This routine is used to declare an I2C adapter when its bus number
421 * matters. Example: for I2C adapters from system-on-chip CPUs, or
422 * otherwise built in to the system's mainboard, and where i2c_board_info
423 * is used to properly configure I2C devices.
424 *
425 * If no devices have pre-been declared for this bus, then be sure to
426 * register the adapter before any dynamically allocated ones. Otherwise
427 * the required bus ID may not be available.
428 *
429 * When this returns zero, the specified adapter became available for
430 * clients using the bus number provided in adap->nr. Also, the table
431 * of I2C devices pre-declared using i2c_register_board_info() is scanned,
432 * and the appropriate driver model device nodes are created. Otherwise, a
433 * negative errno value is returned.
434 */
435int i2c_add_numbered_adapter(struct i2c_adapter *adap)
436{
437 int id;
438 int status;
439
440 if (adap->nr & ~MAX_ID_MASK)
441 return -EINVAL;
442
443retry:
444 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
445 return -ENOMEM;
446
447 mutex_lock(&core_lists);
448 /* "above" here means "above or equal to", sigh;
449 * we need the "equal to" result to force the result
450 */
451 status = idr_get_new_above(&i2c_adapter_idr, adap, adap->nr, &id);
452 if (status == 0 && id != adap->nr) {
453 status = -EBUSY;
454 idr_remove(&i2c_adapter_idr, id);
455 }
456 mutex_unlock(&core_lists);
457 if (status == -EAGAIN)
458 goto retry;
459
460 if (status == 0)
461 status = i2c_register_adapter(adap);
462 return status;
463}
464EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
268 465
269int i2c_del_adapter(struct i2c_adapter *adap) 466int i2c_del_adapter(struct i2c_adapter *adap)
270{ 467{
@@ -302,9 +499,19 @@ int i2c_del_adapter(struct i2c_adapter *adap)
302 /* detach any active clients. This must be done first, because 499 /* detach any active clients. This must be done first, because
303 * it can fail; in which case we give up. */ 500 * it can fail; in which case we give up. */
304 list_for_each_safe(item, _n, &adap->clients) { 501 list_for_each_safe(item, _n, &adap->clients) {
502 struct i2c_driver *driver;
503
305 client = list_entry(item, struct i2c_client, list); 504 client = list_entry(item, struct i2c_client, list);
505 driver = client->driver;
506
507 /* new style, follow standard driver model */
508 if (!driver || is_newstyle_driver(driver)) {
509 i2c_unregister_device(client);
510 continue;
511 }
306 512
307 if ((res=client->driver->detach_client(client))) { 513 /* legacy drivers create and remove clients themselves */
514 if ((res = driver->detach_client(client))) {
308 dev_err(&adap->dev, "detach_client failed for client " 515 dev_err(&adap->dev, "detach_client failed for client "
309 "[%s] at address 0x%02x\n", client->name, 516 "[%s] at address 0x%02x\n", client->name,
310 client->addr); 517 client->addr);
@@ -314,17 +521,13 @@ int i2c_del_adapter(struct i2c_adapter *adap)
314 521
315 /* clean up the sysfs representation */ 522 /* clean up the sysfs representation */
316 init_completion(&adap->dev_released); 523 init_completion(&adap->dev_released);
317 init_completion(&adap->class_dev_released);
318 class_device_unregister(&adap->class_dev);
319 device_remove_file(&adap->dev, &dev_attr_name);
320 device_unregister(&adap->dev); 524 device_unregister(&adap->dev);
321 list_del(&adap->list); 525 list_del(&adap->list);
322 526
323 /* wait for sysfs to drop all references */ 527 /* wait for sysfs to drop all references */
324 wait_for_completion(&adap->dev_released); 528 wait_for_completion(&adap->dev_released);
325 wait_for_completion(&adap->class_dev_released);
326 529
327 /* free dynamically allocated bus id */ 530 /* free bus id */
328 idr_remove(&i2c_adapter_idr, adap->nr); 531 idr_remove(&i2c_adapter_idr, adap->nr);
329 532
330 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); 533 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
@@ -333,24 +536,42 @@ int i2c_del_adapter(struct i2c_adapter *adap)
333 mutex_unlock(&core_lists); 536 mutex_unlock(&core_lists);
334 return res; 537 return res;
335} 538}
539EXPORT_SYMBOL(i2c_del_adapter);
540
336 541
542/* ------------------------------------------------------------------------- */
337 543
338/* ----- 544/*
339 * What follows is the "upwards" interface: commands for talking to clients, 545 * An i2c_driver is used with one or more i2c_client (device) nodes to access
340 * which implement the functions to access the physical information of the 546 * i2c slave chips, on a bus instance associated with some i2c_adapter. There
341 * chips. 547 * are two models for binding the driver to its device: "new style" drivers
548 * follow the standard Linux driver model and just respond to probe() calls
549 * issued if the driver core sees they match(); "legacy" drivers create device
550 * nodes themselves.
342 */ 551 */
343 552
344int i2c_register_driver(struct module *owner, struct i2c_driver *driver) 553int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
345{ 554{
346 struct list_head *item;
347 struct i2c_adapter *adapter;
348 int res; 555 int res;
349 556
557 /* new style driver methods can't mix with legacy ones */
558 if (is_newstyle_driver(driver)) {
559 if (driver->attach_adapter || driver->detach_adapter
560 || driver->detach_client) {
561 printk(KERN_WARNING
562 "i2c-core: driver [%s] is confused\n",
563 driver->driver.name);
564 return -EINVAL;
565 }
566 }
567
350 /* add the driver to the list of i2c drivers in the driver core */ 568 /* add the driver to the list of i2c drivers in the driver core */
351 driver->driver.owner = owner; 569 driver->driver.owner = owner;
352 driver->driver.bus = &i2c_bus_type; 570 driver->driver.bus = &i2c_bus_type;
353 571
572 /* for new style drivers, when registration returns the driver core
573 * will have called probe() for all matching-but-unbound devices.
574 */
354 res = driver_register(&driver->driver); 575 res = driver_register(&driver->driver);
355 if (res) 576 if (res)
356 return res; 577 return res;
@@ -360,10 +581,11 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
360 list_add_tail(&driver->list,&drivers); 581 list_add_tail(&driver->list,&drivers);
361 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); 582 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
362 583
363 /* now look for instances of driver on our adapters */ 584 /* legacy drivers scan i2c busses directly */
364 if (driver->attach_adapter) { 585 if (driver->attach_adapter) {
365 list_for_each(item,&adapters) { 586 struct i2c_adapter *adapter;
366 adapter = list_entry(item, struct i2c_adapter, list); 587
588 list_for_each_entry(adapter, &adapters, list) {
367 driver->attach_adapter(adapter); 589 driver->attach_adapter(adapter);
368 } 590 }
369 } 591 }
@@ -373,16 +595,22 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
373} 595}
374EXPORT_SYMBOL(i2c_register_driver); 596EXPORT_SYMBOL(i2c_register_driver);
375 597
376int i2c_del_driver(struct i2c_driver *driver) 598/**
599 * i2c_del_driver - unregister I2C driver
600 * @driver: the driver being unregistered
601 */
602void i2c_del_driver(struct i2c_driver *driver)
377{ 603{
378 struct list_head *item1, *item2, *_n; 604 struct list_head *item1, *item2, *_n;
379 struct i2c_client *client; 605 struct i2c_client *client;
380 struct i2c_adapter *adap; 606 struct i2c_adapter *adap;
381 607
382 int res = 0;
383
384 mutex_lock(&core_lists); 608 mutex_lock(&core_lists);
385 609
610 /* new-style driver? */
611 if (is_newstyle_driver(driver))
612 goto unregister;
613
386 /* Have a look at each adapter, if clients of this driver are still 614 /* Have a look at each adapter, if clients of this driver are still
387 * attached. If so, detach them to be able to kill the driver 615 * attached. If so, detach them to be able to kill the driver
388 * afterwards. 616 * afterwards.
@@ -390,11 +618,10 @@ int i2c_del_driver(struct i2c_driver *driver)
390 list_for_each(item1,&adapters) { 618 list_for_each(item1,&adapters) {
391 adap = list_entry(item1, struct i2c_adapter, list); 619 adap = list_entry(item1, struct i2c_adapter, list);
392 if (driver->detach_adapter) { 620 if (driver->detach_adapter) {
393 if ((res = driver->detach_adapter(adap))) { 621 if (driver->detach_adapter(adap)) {
394 dev_err(&adap->dev, "detach_adapter failed " 622 dev_err(&adap->dev, "detach_adapter failed "
395 "for driver [%s]\n", 623 "for driver [%s]\n",
396 driver->driver.name); 624 driver->driver.name);
397 goto out_unlock;
398 } 625 }
399 } else { 626 } else {
400 list_for_each_safe(item2, _n, &adap->clients) { 627 list_for_each_safe(item2, _n, &adap->clients) {
@@ -404,25 +631,26 @@ int i2c_del_driver(struct i2c_driver *driver)
404 dev_dbg(&adap->dev, "detaching client [%s] " 631 dev_dbg(&adap->dev, "detaching client [%s] "
405 "at 0x%02x\n", client->name, 632 "at 0x%02x\n", client->name,
406 client->addr); 633 client->addr);
407 if ((res = driver->detach_client(client))) { 634 if (driver->detach_client(client)) {
408 dev_err(&adap->dev, "detach_client " 635 dev_err(&adap->dev, "detach_client "
409 "failed for client [%s] at " 636 "failed for client [%s] at "
410 "0x%02x\n", client->name, 637 "0x%02x\n", client->name,
411 client->addr); 638 client->addr);
412 goto out_unlock;
413 } 639 }
414 } 640 }
415 } 641 }
416 } 642 }
417 643
644 unregister:
418 driver_unregister(&driver->driver); 645 driver_unregister(&driver->driver);
419 list_del(&driver->list); 646 list_del(&driver->list);
420 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 647 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
421 648
422 out_unlock:
423 mutex_unlock(&core_lists); 649 mutex_unlock(&core_lists);
424 return 0;
425} 650}
651EXPORT_SYMBOL(i2c_del_driver);
652
653/* ------------------------------------------------------------------------- */
426 654
427static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr) 655static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr)
428{ 656{
@@ -447,6 +675,7 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr)
447 675
448 return rval; 676 return rval;
449} 677}
678EXPORT_SYMBOL(i2c_check_addr);
450 679
451int i2c_attach_client(struct i2c_client *client) 680int i2c_attach_client(struct i2c_client *client)
452{ 681{
@@ -463,9 +692,15 @@ int i2c_attach_client(struct i2c_client *client)
463 client->usage_count = 0; 692 client->usage_count = 0;
464 693
465 client->dev.parent = &client->adapter->dev; 694 client->dev.parent = &client->adapter->dev;
466 client->dev.driver = &client->driver->driver;
467 client->dev.bus = &i2c_bus_type; 695 client->dev.bus = &i2c_bus_type;
468 client->dev.release = &i2c_client_release; 696
697 if (client->driver)
698 client->dev.driver = &client->driver->driver;
699
700 if (client->driver && !is_newstyle_driver(client->driver))
701 client->dev.release = i2c_client_release;
702 else
703 client->dev.release = i2c_client_dev_release;
469 704
470 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), 705 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
471 "%d-%04x", i2c_adapter_id(adapter), client->addr); 706 "%d-%04x", i2c_adapter_id(adapter), client->addr);
@@ -474,9 +709,6 @@ int i2c_attach_client(struct i2c_client *client)
474 res = device_register(&client->dev); 709 res = device_register(&client->dev);
475 if (res) 710 if (res)
476 goto out_list; 711 goto out_list;
477 res = device_create_file(&client->dev, &dev_attr_client_name);
478 if (res)
479 goto out_unregister;
480 mutex_unlock(&adapter->clist_lock); 712 mutex_unlock(&adapter->clist_lock);
481 713
482 if (adapter->client_register) { 714 if (adapter->client_register) {
@@ -489,10 +721,6 @@ int i2c_attach_client(struct i2c_client *client)
489 721
490 return 0; 722 return 0;
491 723
492out_unregister:
493 init_completion(&client->released); /* Needed? */
494 device_unregister(&client->dev);
495 wait_for_completion(&client->released);
496out_list: 724out_list:
497 list_del(&client->list); 725 list_del(&client->list);
498 dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " 726 dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x "
@@ -501,7 +729,7 @@ out_unlock:
501 mutex_unlock(&adapter->clist_lock); 729 mutex_unlock(&adapter->clist_lock);
502 return res; 730 return res;
503} 731}
504 732EXPORT_SYMBOL(i2c_attach_client);
505 733
506int i2c_detach_client(struct i2c_client *client) 734int i2c_detach_client(struct i2c_client *client)
507{ 735{
@@ -527,7 +755,6 @@ int i2c_detach_client(struct i2c_client *client)
527 mutex_lock(&adapter->clist_lock); 755 mutex_lock(&adapter->clist_lock);
528 list_del(&client->list); 756 list_del(&client->list);
529 init_completion(&client->released); 757 init_completion(&client->released);
530 device_remove_file(&client->dev, &dev_attr_client_name);
531 device_unregister(&client->dev); 758 device_unregister(&client->dev);
532 mutex_unlock(&adapter->clist_lock); 759 mutex_unlock(&adapter->clist_lock);
533 wait_for_completion(&client->released); 760 wait_for_completion(&client->released);
@@ -535,6 +762,7 @@ int i2c_detach_client(struct i2c_client *client)
535 out: 762 out:
536 return res; 763 return res;
537} 764}
765EXPORT_SYMBOL(i2c_detach_client);
538 766
539static int i2c_inc_use_client(struct i2c_client *client) 767static int i2c_inc_use_client(struct i2c_client *client)
540{ 768{
@@ -567,6 +795,7 @@ int i2c_use_client(struct i2c_client *client)
567 795
568 return 0; 796 return 0;
569} 797}
798EXPORT_SYMBOL(i2c_use_client);
570 799
571int i2c_release_client(struct i2c_client *client) 800int i2c_release_client(struct i2c_client *client)
572{ 801{
@@ -581,6 +810,7 @@ int i2c_release_client(struct i2c_client *client)
581 810
582 return 0; 811 return 0;
583} 812}
813EXPORT_SYMBOL(i2c_release_client);
584 814
585void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg) 815void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
586{ 816{
@@ -601,6 +831,7 @@ void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
601 } 831 }
602 mutex_unlock(&adap->clist_lock); 832 mutex_unlock(&adap->clist_lock);
603} 833}
834EXPORT_SYMBOL(i2c_clients_command);
604 835
605static int __init i2c_init(void) 836static int __init i2c_init(void)
606{ 837{
@@ -609,16 +840,12 @@ static int __init i2c_init(void)
609 retval = bus_register(&i2c_bus_type); 840 retval = bus_register(&i2c_bus_type);
610 if (retval) 841 if (retval)
611 return retval; 842 return retval;
612 retval = driver_register(&i2c_adapter_driver);
613 if (retval)
614 return retval;
615 return class_register(&i2c_adapter_class); 843 return class_register(&i2c_adapter_class);
616} 844}
617 845
618static void __exit i2c_exit(void) 846static void __exit i2c_exit(void)
619{ 847{
620 class_unregister(&i2c_adapter_class); 848 class_unregister(&i2c_adapter_class);
621 driver_unregister(&i2c_adapter_driver);
622 bus_unregister(&i2c_bus_type); 849 bus_unregister(&i2c_bus_type);
623} 850}
624 851
@@ -638,8 +865,9 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
638#ifdef DEBUG 865#ifdef DEBUG
639 for (ret = 0; ret < num; ret++) { 866 for (ret = 0; ret < num; ret++) {
640 dev_dbg(&adap->dev, "master_xfer[%d] %c, addr=0x%02x, " 867 dev_dbg(&adap->dev, "master_xfer[%d] %c, addr=0x%02x, "
641 "len=%d\n", ret, msgs[ret].flags & I2C_M_RD ? 868 "len=%d%s\n", ret, (msgs[ret].flags & I2C_M_RD)
642 'R' : 'W', msgs[ret].addr, msgs[ret].len); 869 ? 'R' : 'W', msgs[ret].addr, msgs[ret].len,
870 (msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : "");
643 } 871 }
644#endif 872#endif
645 873
@@ -653,6 +881,7 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
653 return -ENOSYS; 881 return -ENOSYS;
654 } 882 }
655} 883}
884EXPORT_SYMBOL(i2c_transfer);
656 885
657int i2c_master_send(struct i2c_client *client,const char *buf ,int count) 886int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
658{ 887{
@@ -671,6 +900,7 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
671 transmitted, else error code. */ 900 transmitted, else error code. */
672 return (ret == 1) ? count : ret; 901 return (ret == 1) ? count : ret;
673} 902}
903EXPORT_SYMBOL(i2c_master_send);
674 904
675int i2c_master_recv(struct i2c_client *client, char *buf ,int count) 905int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
676{ 906{
@@ -690,7 +920,7 @@ int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
690 transmitted, else error code. */ 920 transmitted, else error code. */
691 return (ret == 1) ? count : ret; 921 return (ret == 1) ? count : ret;
692} 922}
693 923EXPORT_SYMBOL(i2c_master_recv);
694 924
695int i2c_control(struct i2c_client *client, 925int i2c_control(struct i2c_client *client,
696 unsigned int cmd, unsigned long arg) 926 unsigned int cmd, unsigned long arg)
@@ -712,6 +942,7 @@ int i2c_control(struct i2c_client *client,
712 } 942 }
713 return ret; 943 return ret;
714} 944}
945EXPORT_SYMBOL(i2c_control);
715 946
716/* ---------------------------------------------------- 947/* ----------------------------------------------------
717 * the i2c address scanning function 948 * the i2c address scanning function
@@ -853,6 +1084,70 @@ int i2c_probe(struct i2c_adapter *adapter,
853 1084
854 return 0; 1085 return 0;
855} 1086}
1087EXPORT_SYMBOL(i2c_probe);
1088
1089struct i2c_client *
1090i2c_new_probed_device(struct i2c_adapter *adap,
1091 struct i2c_board_info *info,
1092 unsigned short const *addr_list)
1093{
1094 int i;
1095
1096 /* Stop here if the bus doesn't support probing */
1097 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) {
1098 dev_err(&adap->dev, "Probing not supported\n");
1099 return NULL;
1100 }
1101
1102 mutex_lock(&adap->clist_lock);
1103 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
1104 /* Check address validity */
1105 if (addr_list[i] < 0x03 || addr_list[i] > 0x77) {
1106 dev_warn(&adap->dev, "Invalid 7-bit address "
1107 "0x%02x\n", addr_list[i]);
1108 continue;
1109 }
1110
1111 /* Check address availability */
1112 if (__i2c_check_addr(adap, addr_list[i])) {
1113 dev_dbg(&adap->dev, "Address 0x%02x already in "
1114 "use, not probing\n", addr_list[i]);
1115 continue;
1116 }
1117
1118 /* Test address responsiveness
1119 The default probe method is a quick write, but it is known
1120 to corrupt the 24RF08 EEPROMs due to a state machine bug,
1121 and could also irreversibly write-protect some EEPROMs, so
1122 for address ranges 0x30-0x37 and 0x50-0x5f, we use a byte
1123 read instead. Also, some bus drivers don't implement
1124 quick write, so we fallback to a byte read it that case
1125 too. */
1126 if ((addr_list[i] & ~0x07) == 0x30
1127 || (addr_list[i] & ~0x0f) == 0x50
1128 || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) {
1129 if (i2c_smbus_xfer(adap, addr_list[i], 0,
1130 I2C_SMBUS_READ, 0,
1131 I2C_SMBUS_BYTE, NULL) >= 0)
1132 break;
1133 } else {
1134 if (i2c_smbus_xfer(adap, addr_list[i], 0,
1135 I2C_SMBUS_WRITE, 0,
1136 I2C_SMBUS_QUICK, NULL) >= 0)
1137 break;
1138 }
1139 }
1140 mutex_unlock(&adap->clist_lock);
1141
1142 if (addr_list[i] == I2C_CLIENT_END) {
1143 dev_dbg(&adap->dev, "Probing failed, no device found\n");
1144 return NULL;
1145 }
1146
1147 info->addr = addr_list[i];
1148 return i2c_new_device(adap, info);
1149}
1150EXPORT_SYMBOL_GPL(i2c_new_probed_device);
856 1151
857struct i2c_adapter* i2c_get_adapter(int id) 1152struct i2c_adapter* i2c_get_adapter(int id)
858{ 1153{
@@ -866,11 +1161,13 @@ struct i2c_adapter* i2c_get_adapter(int id)
866 mutex_unlock(&core_lists); 1161 mutex_unlock(&core_lists);
867 return adapter; 1162 return adapter;
868} 1163}
1164EXPORT_SYMBOL(i2c_get_adapter);
869 1165
870void i2c_put_adapter(struct i2c_adapter *adap) 1166void i2c_put_adapter(struct i2c_adapter *adap)
871{ 1167{
872 module_put(adap->owner); 1168 module_put(adap->owner);
873} 1169}
1170EXPORT_SYMBOL(i2c_put_adapter);
874 1171
875/* The SMBus parts */ 1172/* The SMBus parts */
876 1173
@@ -939,6 +1236,7 @@ s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value)
939 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1236 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
940 value,0,I2C_SMBUS_QUICK,NULL); 1237 value,0,I2C_SMBUS_QUICK,NULL);
941} 1238}
1239EXPORT_SYMBOL(i2c_smbus_write_quick);
942 1240
943s32 i2c_smbus_read_byte(struct i2c_client *client) 1241s32 i2c_smbus_read_byte(struct i2c_client *client)
944{ 1242{
@@ -949,12 +1247,14 @@ s32 i2c_smbus_read_byte(struct i2c_client *client)
949 else 1247 else
950 return data.byte; 1248 return data.byte;
951} 1249}
1250EXPORT_SYMBOL(i2c_smbus_read_byte);
952 1251
953s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 1252s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
954{ 1253{
955 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1254 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
956 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); 1255 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
957} 1256}
1257EXPORT_SYMBOL(i2c_smbus_write_byte);
958 1258
959s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) 1259s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
960{ 1260{
@@ -965,6 +1265,7 @@ s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
965 else 1265 else
966 return data.byte; 1266 return data.byte;
967} 1267}
1268EXPORT_SYMBOL(i2c_smbus_read_byte_data);
968 1269
969s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) 1270s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
970{ 1271{
@@ -974,6 +1275,7 @@ s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
974 I2C_SMBUS_WRITE,command, 1275 I2C_SMBUS_WRITE,command,
975 I2C_SMBUS_BYTE_DATA,&data); 1276 I2C_SMBUS_BYTE_DATA,&data);
976} 1277}
1278EXPORT_SYMBOL(i2c_smbus_write_byte_data);
977 1279
978s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) 1280s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
979{ 1281{
@@ -984,6 +1286,7 @@ s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
984 else 1286 else
985 return data.word; 1287 return data.word;
986} 1288}
1289EXPORT_SYMBOL(i2c_smbus_read_word_data);
987 1290
988s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) 1291s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
989{ 1292{
@@ -993,6 +1296,23 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
993 I2C_SMBUS_WRITE,command, 1296 I2C_SMBUS_WRITE,command,
994 I2C_SMBUS_WORD_DATA,&data); 1297 I2C_SMBUS_WORD_DATA,&data);
995} 1298}
1299EXPORT_SYMBOL(i2c_smbus_write_word_data);
1300
1301/* Returns the number of read bytes */
1302s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command,
1303 u8 *values)
1304{
1305 union i2c_smbus_data data;
1306
1307 if (i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1308 I2C_SMBUS_READ, command,
1309 I2C_SMBUS_BLOCK_DATA, &data))
1310 return -1;
1311
1312 memcpy(values, &data.block[1], data.block[0]);
1313 return data.block[0];
1314}
1315EXPORT_SYMBOL(i2c_smbus_read_block_data);
996 1316
997s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, 1317s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
998 u8 length, const u8 *values) 1318 u8 length, const u8 *values)
@@ -1007,6 +1327,7 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
1007 I2C_SMBUS_WRITE,command, 1327 I2C_SMBUS_WRITE,command,
1008 I2C_SMBUS_BLOCK_DATA,&data); 1328 I2C_SMBUS_BLOCK_DATA,&data);
1009} 1329}
1330EXPORT_SYMBOL(i2c_smbus_write_block_data);
1010 1331
1011/* Returns the number of read bytes */ 1332/* Returns the number of read bytes */
1012s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values) 1333s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values)
@@ -1021,6 +1342,7 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *val
1021 memcpy(values, &data.block[1], data.block[0]); 1342 memcpy(values, &data.block[1], data.block[0]);
1022 return data.block[0]; 1343 return data.block[0];
1023} 1344}
1345EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
1024 1346
1025s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, 1347s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command,
1026 u8 length, const u8 *values) 1348 u8 length, const u8 *values)
@@ -1035,6 +1357,7 @@ s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command,
1035 I2C_SMBUS_WRITE, command, 1357 I2C_SMBUS_WRITE, command,
1036 I2C_SMBUS_I2C_BLOCK_DATA, &data); 1358 I2C_SMBUS_I2C_BLOCK_DATA, &data);
1037} 1359}
1360EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
1038 1361
1039/* Simulate a SMBus command using the i2c protocol 1362/* Simulate a SMBus command using the i2c protocol
1040 No checking of parameters is done! */ 1363 No checking of parameters is done! */
@@ -1098,9 +1421,9 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1098 break; 1421 break;
1099 case I2C_SMBUS_BLOCK_DATA: 1422 case I2C_SMBUS_BLOCK_DATA:
1100 if (read_write == I2C_SMBUS_READ) { 1423 if (read_write == I2C_SMBUS_READ) {
1101 dev_err(&adapter->dev, "Block read not supported " 1424 msg[1].flags |= I2C_M_RECV_LEN;
1102 "under I2C emulation!\n"); 1425 msg[1].len = 1; /* block length will be added by
1103 return -1; 1426 the underlying bus driver */
1104 } else { 1427 } else {
1105 msg[0].len = data->block[0] + 2; 1428 msg[0].len = data->block[0] + 2;
1106 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { 1429 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
@@ -1114,9 +1437,21 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1114 } 1437 }
1115 break; 1438 break;
1116 case I2C_SMBUS_BLOCK_PROC_CALL: 1439 case I2C_SMBUS_BLOCK_PROC_CALL:
1117 dev_dbg(&adapter->dev, "Block process call not supported " 1440 num = 2; /* Another special case */
1118 "under I2C emulation!\n"); 1441 read_write = I2C_SMBUS_READ;
1119 return -1; 1442 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
1443 dev_err(&adapter->dev, "%s called with invalid "
1444 "block proc call size (%d)\n", __FUNCTION__,
1445 data->block[0]);
1446 return -1;
1447 }
1448 msg[0].len = data->block[0] + 2;
1449 for (i = 1; i < msg[0].len; i++)
1450 msgbuf0[i] = data->block[i-1];
1451 msg[1].flags |= I2C_M_RECV_LEN;
1452 msg[1].len = 1; /* block length will be added by
1453 the underlying bus driver */
1454 break;
1120 case I2C_SMBUS_I2C_BLOCK_DATA: 1455 case I2C_SMBUS_I2C_BLOCK_DATA:
1121 if (read_write == I2C_SMBUS_READ) { 1456 if (read_write == I2C_SMBUS_READ) {
1122 msg[1].len = I2C_SMBUS_BLOCK_MAX; 1457 msg[1].len = I2C_SMBUS_BLOCK_MAX;
@@ -1180,6 +1515,11 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1180 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) 1515 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
1181 data->block[i+1] = msgbuf1[i]; 1516 data->block[i+1] = msgbuf1[i];
1182 break; 1517 break;
1518 case I2C_SMBUS_BLOCK_DATA:
1519 case I2C_SMBUS_BLOCK_PROC_CALL:
1520 for (i = 0; i < msgbuf1[0] + 1; i++)
1521 data->block[i] = msgbuf1[i];
1522 break;
1183 } 1523 }
1184 return 0; 1524 return 0;
1185} 1525}
@@ -1204,43 +1544,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1204 1544
1205 return res; 1545 return res;
1206} 1546}
1207
1208
1209/* Next four are needed by i2c-isa */
1210EXPORT_SYMBOL_GPL(i2c_adapter_dev_release);
1211EXPORT_SYMBOL_GPL(i2c_adapter_driver);
1212EXPORT_SYMBOL_GPL(i2c_adapter_class);
1213EXPORT_SYMBOL_GPL(i2c_bus_type);
1214
1215EXPORT_SYMBOL(i2c_add_adapter);
1216EXPORT_SYMBOL(i2c_del_adapter);
1217EXPORT_SYMBOL(i2c_del_driver);
1218EXPORT_SYMBOL(i2c_attach_client);
1219EXPORT_SYMBOL(i2c_detach_client);
1220EXPORT_SYMBOL(i2c_use_client);
1221EXPORT_SYMBOL(i2c_release_client);
1222EXPORT_SYMBOL(i2c_clients_command);
1223EXPORT_SYMBOL(i2c_check_addr);
1224
1225EXPORT_SYMBOL(i2c_master_send);
1226EXPORT_SYMBOL(i2c_master_recv);
1227EXPORT_SYMBOL(i2c_control);
1228EXPORT_SYMBOL(i2c_transfer);
1229EXPORT_SYMBOL(i2c_get_adapter);
1230EXPORT_SYMBOL(i2c_put_adapter);
1231EXPORT_SYMBOL(i2c_probe);
1232
1233EXPORT_SYMBOL(i2c_smbus_xfer); 1547EXPORT_SYMBOL(i2c_smbus_xfer);
1234EXPORT_SYMBOL(i2c_smbus_write_quick);
1235EXPORT_SYMBOL(i2c_smbus_read_byte);
1236EXPORT_SYMBOL(i2c_smbus_write_byte);
1237EXPORT_SYMBOL(i2c_smbus_read_byte_data);
1238EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1239EXPORT_SYMBOL(i2c_smbus_read_word_data);
1240EXPORT_SYMBOL(i2c_smbus_write_word_data);
1241EXPORT_SYMBOL(i2c_smbus_write_block_data);
1242EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
1243EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
1244 1548
1245MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); 1549MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
1246MODULE_DESCRIPTION("I2C-Bus main module"); 1550MODULE_DESCRIPTION("I2C-Bus main module");
diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
new file mode 100644
index 000000000000..cd5bff874855
--- /dev/null
+++ b/drivers/i2c/i2c-core.h
@@ -0,0 +1,31 @@
1/*
2 * i2c-core.h - interfaces internal to the I2C framework
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19struct i2c_devinfo {
20 struct list_head list;
21 int busnum;
22 struct i2c_board_info board_info;
23};
24
25/* board_lock protects board_list and first_dynamic_bus_num.
26 * only i2c core components are allowed to use these symbols.
27 */
28extern struct mutex __i2c_board_lock;
29extern struct list_head __i2c_board_list;
30extern int __i2c_first_dynamic_bus_num;
31
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index 35233de460ad..3d0354e96a97 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -459,7 +459,8 @@ therm_of_probe( struct of_device *dev, const struct of_device_id *match )
459static int 459static int
460therm_of_remove( struct of_device *dev ) 460therm_of_remove( struct of_device *dev )
461{ 461{
462 return i2c_del_driver( &g4fan_driver ); 462 i2c_del_driver( &g4fan_driver );
463 return 0;
463} 464}
464 465
465static struct of_device_id therm_of_match[] = {{ 466static struct of_device_id therm_of_match[] = {{
diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c
index 5347a406fff7..02a0ea6e1c17 100644
--- a/drivers/media/dvb/b2c2/flexcop-i2c.c
+++ b/drivers/media/dvb/b2c2/flexcop-i2c.c
@@ -183,7 +183,8 @@ int flexcop_i2c_init(struct flexcop_device *fc)
183 mutex_init(&fc->i2c_mutex); 183 mutex_init(&fc->i2c_mutex);
184 184
185 memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter)); 185 memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter));
186 strncpy(fc->i2c_adap.name, "B2C2 FlexCop device",I2C_NAME_SIZE); 186 strncpy(fc->i2c_adap.name, "B2C2 FlexCop device",
187 sizeof(fc->i2c_adap.name));
187 188
188 i2c_set_adapdata(&fc->i2c_adap,fc); 189 i2c_set_adapdata(&fc->i2c_adap,fc);
189 190
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
index 70df31b0a8a9..088b6dee3a7f 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
@@ -19,7 +19,7 @@ int dvb_usb_i2c_init(struct dvb_usb_device *d)
19 return -EINVAL; 19 return -EINVAL;
20 } 20 }
21 21
22 strncpy(d->i2c_adap.name,d->desc->name,I2C_NAME_SIZE); 22 strncpy(d->i2c_adap.name, d->desc->name, sizeof(d->i2c_adap.name));
23#ifdef I2C_ADAP_CLASS_TV_DIGITAL 23#ifdef I2C_ADAP_CLASS_TV_DIGITAL
24 d->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL, 24 d->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL,
25#else 25#else
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c
index a18c8f45a2ee..315e09e95b0c 100644
--- a/drivers/media/dvb/frontends/dibx000_common.c
+++ b/drivers/media/dvb/frontends/dibx000_common.c
@@ -105,9 +105,9 @@ struct i2c_adapter * dibx000_get_i2c_adapter(struct dibx000_i2c_master *mst, enu
105} 105}
106EXPORT_SYMBOL(dibx000_get_i2c_adapter); 106EXPORT_SYMBOL(dibx000_get_i2c_adapter);
107 107
108static int i2c_adapter_init(struct i2c_adapter *i2c_adap, struct i2c_algorithm *algo, const char name[I2C_NAME_SIZE], struct dibx000_i2c_master *mst) 108static int i2c_adapter_init(struct i2c_adapter *i2c_adap, struct i2c_algorithm *algo, const char *name, struct dibx000_i2c_master *mst)
109{ 109{
110 strncpy(i2c_adap->name, name, I2C_NAME_SIZE); 110 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
111 i2c_adap->class = I2C_CLASS_TV_DIGITAL, 111 i2c_adap->class = I2C_CLASS_TV_DIGITAL,
112 i2c_adap->algo = algo; 112 i2c_adap->algo = algo;
113 i2c_adap->algo_data = NULL; 113 i2c_adap->algo_data = NULL;
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 88dbdddeec42..d73c86aeeaac 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -26,7 +26,6 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <linux/i2c.h>
30 29
31#include <media/tuner.h> 30#include <media/tuner.h>
32#include <media/cx2341x.h> 31#include <media/cx2341x.h>
diff --git a/drivers/media/video/ovcamchip/ovcamchip_priv.h b/drivers/media/video/ovcamchip/ovcamchip_priv.h
index 1231335a9f4a..50c7763d44b3 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_priv.h
+++ b/drivers/media/video/ovcamchip/ovcamchip_priv.h
@@ -15,6 +15,7 @@
15#ifndef __LINUX_OVCAMCHIP_PRIV_H 15#ifndef __LINUX_OVCAMCHIP_PRIV_H
16#define __LINUX_OVCAMCHIP_PRIV_H 16#define __LINUX_OVCAMCHIP_PRIV_H
17 17
18#include <linux/i2c.h>
18#include <media/ovcamchip.h> 19#include <media/ovcamchip.h>
19 20
20#ifdef DEBUG 21#ifdef DEBUG
diff --git a/drivers/media/video/usbvision/usbvision-cards.c b/drivers/media/video/usbvision/usbvision-cards.c
index 13f69fe6360d..51ab265d566a 100644
--- a/drivers/media/video/usbvision/usbvision-cards.c
+++ b/drivers/media/video/usbvision/usbvision-cards.c
@@ -24,7 +24,6 @@
24 24
25 25
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/i2c.h>
28#include <media/v4l2-dev.h> 27#include <media/v4l2-dev.h>
29#include <media/tuner.h> 28#include <media/tuner.h>
30#include "usbvision.h" 29#include "usbvision.h"
diff --git a/drivers/video/intelfb/intelfb_i2c.c b/drivers/video/intelfb/intelfb_i2c.c
index f4ede5f6b588..61e4c8759b23 100644
--- a/drivers/video/intelfb/intelfb_i2c.c
+++ b/drivers/video/intelfb/intelfb_i2c.c
@@ -104,7 +104,8 @@ static int intelfb_setup_i2c_bus(struct intelfb_info *dinfo,
104 104
105 chan->dinfo = dinfo; 105 chan->dinfo = dinfo;
106 chan->reg = reg; 106 chan->reg = reg;
107 snprintf(chan->adapter.name, I2C_NAME_SIZE, "intelfb %s", name); 107 snprintf(chan->adapter.name, sizeof(chan->adapter.name),
108 "intelfb %s", name);
108 chan->adapter.owner = THIS_MODULE; 109 chan->adapter.owner = THIS_MODULE;
109 chan->adapter.id = I2C_HW_B_INTELFB; 110 chan->adapter.id = I2C_HW_B_INTELFB;
110 chan->adapter.algo_data = &chan->algo; 111 chan->adapter.algo_data = &chan->algo;
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c
index 5ec718a5fe22..4baab7be58de 100644
--- a/drivers/video/matrox/i2c-matroxfb.c
+++ b/drivers/video/matrox/i2c-matroxfb.c
@@ -111,7 +111,7 @@ static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
111 b->mask.data = data; 111 b->mask.data = data;
112 b->mask.clock = clock; 112 b->mask.clock = clock;
113 b->adapter = matrox_i2c_adapter_template; 113 b->adapter = matrox_i2c_adapter_template;
114 snprintf(b->adapter.name, I2C_NAME_SIZE, name, 114 snprintf(b->adapter.name, sizeof(b->adapter.name), name,
115 minfo->fbcon.node); 115 minfo->fbcon.node);
116 i2c_set_adapdata(&b->adapter, b); 116 i2c_set_adapdata(&b->adapter, b);
117 b->adapter.algo_data = &b->bac; 117 b->adapter.algo_data = &b->bac;
diff --git a/include/linux/i2c-algo-bit.h b/include/linux/i2c-algo-bit.h
index 937da70cb4c4..9ee0f800592f 100644
--- a/include/linux/i2c-algo-bit.h
+++ b/include/linux/i2c-algo-bit.h
@@ -38,11 +38,14 @@ struct i2c_algo_bit_data {
38 int (*getscl) (void *data); 38 int (*getscl) (void *data);
39 39
40 /* local settings */ 40 /* local settings */
41 int udelay; /* half-clock-cycle time in microsecs */ 41 int udelay; /* half clock cycle time in us,
42 /* i.e. clock is (500 / udelay) KHz */ 42 minimum 2 us for fast-mode I2C,
43 minimum 5 us for standard-mode I2C and SMBus,
44 maximum 50 us for SMBus */
43 int timeout; /* in jiffies */ 45 int timeout; /* in jiffies */
44}; 46};
45 47
46int i2c_bit_add_bus(struct i2c_adapter *); 48int i2c_bit_add_bus(struct i2c_adapter *);
49int i2c_bit_add_numbered_bus(struct i2c_adapter *);
47 50
48#endif /* _LINUX_I2C_ALGO_BIT_H */ 51#endif /* _LINUX_I2C_ALGO_BIT_H */
diff --git a/include/linux/i2c-gpio.h b/include/linux/i2c-gpio.h
new file mode 100644
index 000000000000..c1bcb1f1d73b
--- /dev/null
+++ b/include/linux/i2c-gpio.h
@@ -0,0 +1,38 @@
1/*
2 * i2c-gpio interface to platform code
3 *
4 * Copyright (C) 2007 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#ifndef _LINUX_I2C_GPIO_H
11#define _LINUX_I2C_GPIO_H
12
13/**
14 * struct i2c_gpio_platform_data - Platform-dependent data for i2c-gpio
15 * @sda_pin: GPIO pin ID to use for SDA
16 * @scl_pin: GPIO pin ID to use for SCL
17 * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz
18 * @timeout: clock stretching timeout in jiffies. If the slave keeps
19 * SCL low for longer than this, the transfer will time out.
20 * @sda_is_open_drain: SDA is configured as open drain, i.e. the pin
21 * isn't actively driven high when setting the output value high.
22 * gpio_get_value() must return the actual pin state even if the
23 * pin is configured as an output.
24 * @scl_is_open_drain: SCL is set up as open drain. Same requirements
25 * as for sda_is_open_drain apply.
26 * @scl_is_output_only: SCL output drivers cannot be turned off.
27 */
28struct i2c_gpio_platform_data {
29 unsigned int sda_pin;
30 unsigned int scl_pin;
31 int udelay;
32 int timeout;
33 unsigned int sda_is_open_drain:1;
34 unsigned int scl_is_open_drain:1;
35 unsigned int scl_is_output_only:1;
36};
37
38#endif /* _LINUX_I2C_GPIO_H */
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index 9c21dc793d7b..0e8da684ce68 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -258,8 +258,9 @@
258/* --- MCP107 adapter */ 258/* --- MCP107 adapter */
259#define I2C_HW_MPC107 0x0d0000 259#define I2C_HW_MPC107 0x0d0000
260 260
261/* --- Marvell mv64xxx i2c adapter */ 261/* --- Embedded adapters */
262#define I2C_HW_MV64XXX 0x190000 262#define I2C_HW_MV64XXX 0x190000
263#define I2C_HW_BLACKFIN 0x190001 /* ADI Blackfin I2C TWI driver */
263 264
264/* --- Miscellaneous adapters */ 265/* --- Miscellaneous adapters */
265#define I2C_HW_SAA7146 0x060000 /* SAA7146 video decoder bus */ 266#define I2C_HW_SAA7146 0x060000 /* SAA7146 video decoder bus */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 9428092017e3..cae7d618030c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -35,11 +35,6 @@
35#include <linux/sched.h> /* for completion */ 35#include <linux/sched.h> /* for completion */
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37 37
38/* --- For i2c-isa ---------------------------------------------------- */
39
40extern void i2c_adapter_dev_release(struct device *dev);
41extern struct device_driver i2c_adapter_driver;
42extern struct class i2c_adapter_class;
43extern struct bus_type i2c_bus_type; 38extern struct bus_type i2c_bus_type;
44 39
45/* --- General options ------------------------------------------------ */ 40/* --- General options ------------------------------------------------ */
@@ -87,6 +82,9 @@ extern s32 i2c_smbus_write_byte_data(struct i2c_client * client,
87extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); 82extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command);
88extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 83extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
89 u8 command, u16 value); 84 u8 command, u16 value);
85/* Returns the number of read bytes */
86extern s32 i2c_smbus_read_block_data(struct i2c_client *client,
87 u8 command, u8 *values);
90extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 88extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
91 u8 command, u8 length, 89 u8 command, u8 length,
92 const u8 *values); 90 const u8 *values);
@@ -114,7 +112,7 @@ struct i2c_driver {
114 * can be used by the driver to test if the bus meets its conditions 112 * can be used by the driver to test if the bus meets its conditions
115 * & seek for the presence of the chip(s) it supports. If found, it 113 * & seek for the presence of the chip(s) it supports. If found, it
116 * registers the client(s) that are on the bus to the i2c admin. via 114 * registers the client(s) that are on the bus to the i2c admin. via
117 * i2c_attach_client. 115 * i2c_attach_client. (LEGACY I2C DRIVERS ONLY)
118 */ 116 */
119 int (*attach_adapter)(struct i2c_adapter *); 117 int (*attach_adapter)(struct i2c_adapter *);
120 int (*detach_adapter)(struct i2c_adapter *); 118 int (*detach_adapter)(struct i2c_adapter *);
@@ -122,10 +120,17 @@ struct i2c_driver {
122 /* tells the driver that a client is about to be deleted & gives it 120 /* tells the driver that a client is about to be deleted & gives it
123 * the chance to remove its private data. Also, if the client struct 121 * the chance to remove its private data. Also, if the client struct
124 * has been dynamically allocated by the driver in the function above, 122 * has been dynamically allocated by the driver in the function above,
125 * it must be freed here. 123 * it must be freed here. (LEGACY I2C DRIVERS ONLY)
126 */ 124 */
127 int (*detach_client)(struct i2c_client *); 125 int (*detach_client)(struct i2c_client *);
128 126
127 /* Standard driver model interfaces, for "new style" i2c drivers.
128 * With the driver model, device enumeration is NEVER done by drivers;
129 * it's done by infrastructure. (NEW STYLE DRIVERS ONLY)
130 */
131 int (*probe)(struct i2c_client *);
132 int (*remove)(struct i2c_client *);
133
129 /* driver model interfaces that don't relate to enumeration */ 134 /* driver model interfaces that don't relate to enumeration */
130 void (*shutdown)(struct i2c_client *); 135 void (*shutdown)(struct i2c_client *);
131 int (*suspend)(struct i2c_client *, pm_message_t mesg); 136 int (*suspend)(struct i2c_client *, pm_message_t mesg);
@@ -141,25 +146,34 @@ struct i2c_driver {
141}; 146};
142#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) 147#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
143 148
144#define I2C_NAME_SIZE 50 149#define I2C_NAME_SIZE 20
145 150
146/* 151/**
147 * i2c_client identifies a single device (i.e. chip) that is connected to an 152 * struct i2c_client - represent an I2C slave device
148 * i2c bus. The behaviour is defined by the routines of the driver. This 153 * @addr: Address used on the I2C bus connected to the parent adapter.
149 * function is mainly used for lookup & other admin. functions. 154 * @name: Indicates the type of the device, usually a chip name that's
155 * generic enough to hide second-sourcing and compatible revisions.
156 * @dev: Driver model device node for the slave.
157 * @driver_name: Identifies new-style driver used with this device; also
158 * used as the module name for hotplug/coldplug modprobe support.
159 *
160 * An i2c_client identifies a single device (i.e. chip) connected to an
161 * i2c bus. The behaviour is defined by the routines of the driver.
150 */ 162 */
151struct i2c_client { 163struct i2c_client {
152 unsigned int flags; /* div., see below */ 164 unsigned short flags; /* div., see below */
153 unsigned short addr; /* chip address - NOTE: 7bit */ 165 unsigned short addr; /* chip address - NOTE: 7bit */
154 /* addresses are stored in the */ 166 /* addresses are stored in the */
155 /* _LOWER_ 7 bits */ 167 /* _LOWER_ 7 bits */
168 char name[I2C_NAME_SIZE];
156 struct i2c_adapter *adapter; /* the adapter we sit on */ 169 struct i2c_adapter *adapter; /* the adapter we sit on */
157 struct i2c_driver *driver; /* and our access routines */ 170 struct i2c_driver *driver; /* and our access routines */
158 int usage_count; /* How many accesses currently */ 171 int usage_count; /* How many accesses currently */
159 /* to the client */ 172 /* to the client */
160 struct device dev; /* the device structure */ 173 struct device dev; /* the device structure */
174 int irq; /* irq issued by device (or -1) */
175 char driver_name[KOBJ_NAME_LEN];
161 struct list_head list; 176 struct list_head list;
162 char name[I2C_NAME_SIZE];
163 struct completion released; 177 struct completion released;
164}; 178};
165#define to_i2c_client(d) container_of(d, struct i2c_client, dev) 179#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
@@ -179,6 +193,76 @@ static inline void i2c_set_clientdata (struct i2c_client *dev, void *data)
179 dev_set_drvdata (&dev->dev, data); 193 dev_set_drvdata (&dev->dev, data);
180} 194}
181 195
196/**
197 * struct i2c_board_info - template for device creation
198 * @driver_name: identifies the driver to be bound to the device
199 * @type: optional chip type information, to initialize i2c_client.name
200 * @flags: to initialize i2c_client.flags
201 * @addr: stored in i2c_client.addr
202 * @platform_data: stored in i2c_client.dev.platform_data
203 * @irq: stored in i2c_client.irq
204
205 * I2C doesn't actually support hardware probing, although controllers and
206 * devices may be able to use I2C_SMBUS_QUICK to tell whether or not there's
207 * a device at a given address. Drivers commonly need more information than
208 * that, such as chip type, configuration, associated IRQ, and so on.
209 *
210 * i2c_board_info is used to build tables of information listing I2C devices
211 * that are present. This information is used to grow the driver model tree
212 * for "new style" I2C drivers. For mainboards this is done statically using
213 * i2c_register_board_info(), where @bus_num represents an adapter that isn't
214 * yet available. For add-on boards, i2c_new_device() does this dynamically
215 * with the adapter already known.
216 */
217struct i2c_board_info {
218 char driver_name[KOBJ_NAME_LEN];
219 char type[I2C_NAME_SIZE];
220 unsigned short flags;
221 unsigned short addr;
222 void *platform_data;
223 int irq;
224};
225
226/**
227 * I2C_BOARD_INFO - macro used to list an i2c device and its driver
228 * @driver: identifies the driver to use with the device
229 * @dev_addr: the device's address on the bus.
230 *
231 * This macro initializes essential fields of a struct i2c_board_info,
232 * declaring what has been provided on a particular board. Optional
233 * fields (such as the chip type, its associated irq, or device-specific
234 * platform_data) are provided using conventional syntax.
235 */
236#define I2C_BOARD_INFO(driver,dev_addr) \
237 .driver_name = (driver), .addr = (dev_addr)
238
239
240/* Add-on boards should register/unregister their devices; e.g. a board
241 * with integrated I2C, a config eeprom, sensors, and a codec that's
242 * used in conjunction with the primary hardware.
243 */
244extern struct i2c_client *
245i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
246
247/* If you don't know the exact address of an I2C device, use this variant
248 * instead, which can probe for device presence in a list of possible
249 * addresses.
250 */
251extern struct i2c_client *
252i2c_new_probed_device(struct i2c_adapter *adap,
253 struct i2c_board_info *info,
254 unsigned short const *addr_list);
255
256extern void i2c_unregister_device(struct i2c_client *);
257
258/* Mainboard arch_initcall() code should register all its I2C devices.
259 * This is done at arch_initcall time, before declaring any i2c adapters.
260 * Modules for add-on boards must use other calls.
261 */
262extern int
263i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned n);
264
265
182/* 266/*
183 * The following structs are for those who like to implement new bus drivers: 267 * The following structs are for those who like to implement new bus drivers:
184 * i2c_algorithm is the interface to a class of hardware solutions which can 268 * i2c_algorithm is the interface to a class of hardware solutions which can
@@ -228,17 +312,14 @@ struct i2c_adapter {
228 int timeout; 312 int timeout;
229 int retries; 313 int retries;
230 struct device dev; /* the adapter device */ 314 struct device dev; /* the adapter device */
231 struct class_device class_dev; /* the class device */
232 315
233 int nr; 316 int nr;
234 struct list_head clients; 317 struct list_head clients;
235 struct list_head list; 318 struct list_head list;
236 char name[I2C_NAME_SIZE]; 319 char name[48];
237 struct completion dev_released; 320 struct completion dev_released;
238 struct completion class_dev_released;
239}; 321};
240#define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) 322#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
241#define class_dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, class_dev)
242 323
243static inline void *i2c_get_adapdata (struct i2c_adapter *dev) 324static inline void *i2c_get_adapdata (struct i2c_adapter *dev)
244{ 325{
@@ -290,9 +371,10 @@ struct i2c_client_address_data {
290 */ 371 */
291extern int i2c_add_adapter(struct i2c_adapter *); 372extern int i2c_add_adapter(struct i2c_adapter *);
292extern int i2c_del_adapter(struct i2c_adapter *); 373extern int i2c_del_adapter(struct i2c_adapter *);
374extern int i2c_add_numbered_adapter(struct i2c_adapter *);
293 375
294extern int i2c_register_driver(struct module *, struct i2c_driver *); 376extern int i2c_register_driver(struct module *, struct i2c_driver *);
295extern int i2c_del_driver(struct i2c_driver *); 377extern void i2c_del_driver(struct i2c_driver *);
296 378
297static inline int i2c_add_driver(struct i2c_driver *driver) 379static inline int i2c_add_driver(struct i2c_driver *driver)
298{ 380{
@@ -365,6 +447,7 @@ struct i2c_msg {
365#define I2C_M_REV_DIR_ADDR 0x2000 447#define I2C_M_REV_DIR_ADDR 0x2000
366#define I2C_M_IGNORE_NAK 0x1000 448#define I2C_M_IGNORE_NAK 0x1000
367#define I2C_M_NO_RD_ACK 0x0800 449#define I2C_M_NO_RD_ACK 0x0800
450#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
368 __u16 len; /* msg length */ 451 __u16 len; /* msg length */
369 __u8 *buf; /* pointer to msg data */ 452 __u8 *buf; /* pointer to msg data */
370}; 453};
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 1b0ddbb8a804..5a48e963d06b 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1213,11 +1213,13 @@
1213#define PCI_DEVICE_ID_NVIDIA_NVENET_16 0x03E5 1213#define PCI_DEVICE_ID_NVIDIA_NVENET_16 0x03E5
1214#define PCI_DEVICE_ID_NVIDIA_NVENET_17 0x03E6 1214#define PCI_DEVICE_ID_NVIDIA_NVENET_17 0x03E6
1215#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA 0x03E7 1215#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA 0x03E7
1216#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS 0x03EB
1216#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE 0x03EC 1217#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE 0x03EC
1217#define PCI_DEVICE_ID_NVIDIA_NVENET_18 0x03EE 1218#define PCI_DEVICE_ID_NVIDIA_NVENET_18 0x03EE
1218#define PCI_DEVICE_ID_NVIDIA_NVENET_19 0x03EF 1219#define PCI_DEVICE_ID_NVIDIA_NVENET_19 0x03EF
1219#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2 0x03F6 1220#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2 0x03F6
1220#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3 0x03F7 1221#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3 0x03F7
1222#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS 0x0446
1221#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE 0x0448 1223#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE 0x0448
1222#define PCI_DEVICE_ID_NVIDIA_NVENET_20 0x0450 1224#define PCI_DEVICE_ID_NVIDIA_NVENET_20 0x0450
1223#define PCI_DEVICE_ID_NVIDIA_NVENET_21 0x0451 1225#define PCI_DEVICE_ID_NVIDIA_NVENET_21 0x0451
diff --git a/include/media/ovcamchip.h b/include/media/ovcamchip.h
index 0f43451f8bb3..05b9569ef1c8 100644
--- a/include/media/ovcamchip.h
+++ b/include/media/ovcamchip.h
@@ -16,7 +16,6 @@
16 16
17#include <linux/videodev.h> 17#include <linux/videodev.h>
18#include <media/v4l2-common.h> 18#include <media/v4l2-common.h>
19#include <linux/i2c.h>
20 19
21/* --------------------------------- */ 20/* --------------------------------- */
22/* ENUMERATIONS */ 21/* ENUMERATIONS */
diff --git a/include/media/tuner.h b/include/media/tuner.h
index a41ac41113ac..6dcf3c45707d 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -23,6 +23,7 @@
23#define _TUNER_H 23#define _TUNER_H
24 24
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <linux/i2c.h>
26#include <media/tuner-types.h> 27#include <media/tuner-types.h>
27 28
28extern int tuner_debug; 29extern int tuner_debug;
diff --git a/sound/oss/dmasound/tas_ioctl.h b/sound/oss/dmasound/tas_ioctl.h
index dccae3a40e01..9d12b373b4a9 100644
--- a/sound/oss/dmasound/tas_ioctl.h
+++ b/sound/oss/dmasound/tas_ioctl.h
@@ -1,7 +1,6 @@
1#ifndef _TAS_IOCTL_H_ 1#ifndef _TAS_IOCTL_H_
2#define _TAS_IOCTL_H_ 2#define _TAS_IOCTL_H_
3 3
4#include <linux/i2c.h>
5#include <linux/soundcard.h> 4#include <linux/soundcard.h>
6 5
7 6