aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/feature-removal-schedule.txt31
-rw-r--r--Documentation/i2c/busses/i2c-i8015
-rw-r--r--Documentation/i2c/busses/i2c-viapro3
-rw-r--r--Documentation/i2c/chips/pcf857572
-rw-r--r--Documentation/i2c/i2c-stub6
-rw-r--r--Documentation/i2c/writing-clients6
-rw-r--r--arch/arm/mach-ixp4xx/avila-setup.c14
-rw-r--r--arch/arm/mach-ixp4xx/dsmg600-setup.c13
-rw-r--r--arch/arm/mach-ixp4xx/ixdp425-setup.c14
-rw-r--r--arch/arm/mach-ixp4xx/nas100d-setup.c14
-rw-r--r--arch/arm/mach-ixp4xx/nslu2-setup.c14
-rw-r--r--arch/arm/mach-omap1/board-h2.c2
-rw-r--r--arch/arm/mach-omap1/board-h3.c2
-rw-r--r--arch/arm/mach-omap1/board-osk.c3
-rw-r--r--arch/arm/mach-omap1/leds-osk.c2
-rw-r--r--arch/arm/mach-pxa/akita-ioexp.c2
-rw-r--r--arch/arm/mach-pxa/pxa27x.c6
-rw-r--r--arch/mips/au1000/common/platform.c21
-rw-r--r--arch/ppc/platforms/83xx/mpc834x_sys.c20
-rw-r--r--arch/ppc/platforms/85xx/tqm85xx.c21
-rw-r--r--arch/ppc/platforms/katana.c21
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c226
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c85
-rw-r--r--drivers/i2c/busses/Kconfig33
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-amd756.c5
-rw-r--r--drivers/i2c/busses/i2c-au1550.c177
-rw-r--r--drivers/i2c/busses/i2c-au1550.h32
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c3
-rw-r--r--drivers/i2c/busses/i2c-davinci.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c163
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c191
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.h8
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c1
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c178
-rw-r--r--drivers/i2c/busses/i2c-mpc.c29
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c1
-rw-r--r--drivers/i2c/busses/i2c-omap.c2
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c3
-rw-r--r--drivers/i2c/busses/i2c-piix4.c41
-rw-r--r--drivers/i2c/busses/i2c-pxa.c189
-rw-r--r--drivers/i2c/busses/i2c-sibyte.c29
-rw-r--r--drivers/i2c/busses/i2c-stub.c15
-rw-r--r--drivers/i2c/busses/i2c-viapro.c11
-rw-r--r--drivers/i2c/chips/Kconfig58
-rw-r--r--drivers/i2c/chips/Makefile4
-rw-r--r--drivers/i2c/chips/ds1337.c410
-rw-r--r--drivers/i2c/chips/ds1374.c267
-rw-r--r--drivers/i2c/chips/eeprom.c2
-rw-r--r--drivers/i2c/chips/isp1301_omap.c2
-rw-r--r--drivers/i2c/chips/m41t00.c413
-rw-r--r--drivers/i2c/chips/max6875.c2
-rw-r--r--drivers/i2c/chips/pcf8574.c8
-rw-r--r--drivers/i2c/chips/pcf8575.c214
-rw-r--r--drivers/i2c/chips/pcf8591.c2
-rw-r--r--drivers/i2c/chips/tps65010.c2
-rw-r--r--drivers/i2c/chips/tsl2550.c21
-rw-r--r--drivers/i2c/i2c-core.c352
-rw-r--r--drivers/i2c/i2c-dev.c29
-rw-r--r--drivers/macintosh/therm_windtunnel.c5
-rw-r--r--drivers/media/video/dpc7146.c19
-rw-r--r--drivers/media/video/ks0127.c1
-rw-r--r--drivers/media/video/mxb.c40
-rw-r--r--drivers/media/video/vino.c22
-rw-r--r--drivers/mmc/host/omap.c2
-rw-r--r--drivers/rtc/rtc-ds1672.c2
-rw-r--r--drivers/rtc/rtc-isl1208.c2
-rw-r--r--drivers/rtc/rtc-max6900.c2
-rw-r--r--drivers/rtc/rtc-pcf8563.c2
-rw-r--r--drivers/rtc/rtc-pcf8583.c2
-rw-r--r--drivers/rtc/rtc-x1205.c2
-rw-r--r--drivers/usb/host/ohci-omap.c2
-rw-r--r--drivers/usb/host/ohci-pnx4008.c5
-rw-r--r--drivers/video/matrox/matroxfb_maven.c2
-rw-r--r--drivers/video/omap/lcd_h3.c2
-rw-r--r--drivers/w1/masters/ds2482.c2
-rw-r--r--include/asm-arm/arch-ixp4xx/platform.h11
-rw-r--r--include/asm-arm/arch-pxa/i2c.h6
-rw-r--r--include/linux/i2c-id.h63
-rw-r--r--include/linux/i2c.h126
-rw-r--r--include/linux/i2c/tps65010.h (renamed from include/asm-arm/arch-omap/tps65010.h)8
-rw-r--r--include/linux/m41t00.h50
-rw-r--r--include/media/v4l2-i2c-drv-legacy.h2
-rw-r--r--sound/ppc/keywest.c3
-rw-r--r--sound/soc/codecs/cs4270.c2
-rw-r--r--sound/soc/s3c24xx/neo1973_wm8753.c2
86 files changed, 1440 insertions, 2449 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 9b8291f4c211..25370662cc5d 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -191,15 +191,6 @@ Who: Kay Sievers <kay.sievers@suse.de>
191 191
192--------------------------- 192---------------------------
193 193
194What: i2c_adapter.list
195When: July 2007
196Why: Superfluous, this list duplicates the one maintained by the driver
197 core.
198Who: Jean Delvare <khali@linux-fr.org>,
199 David Brownell <dbrownell@users.sourceforge.net>
200
201---------------------------
202
203What: ACPI procfs interface 194What: ACPI procfs interface
204When: July 2008 195When: July 2008
205Why: ACPI sysfs conversion should be finished by January 2008. 196Why: ACPI sysfs conversion should be finished by January 2008.
@@ -225,14 +216,6 @@ Who: Len Brown <len.brown@intel.com>
225 216
226--------------------------- 217---------------------------
227 218
228What: i2c-ixp2000, i2c-ixp4xx and scx200_i2c drivers
229When: September 2007
230Why: Obsolete. The new i2c-gpio driver replaces all hardware-specific
231 I2C-over-GPIO drivers.
232Who: Jean Delvare <khali@linux-fr.org>
233
234---------------------------
235
236What: 'time' kernel boot parameter 219What: 'time' kernel boot parameter
237When: January 2008 220When: January 2008
238Why: replaced by 'printk.time=<value>' so that printk timestamps can be 221Why: replaced by 'printk.time=<value>' so that printk timestamps can be
@@ -266,13 +249,6 @@ Who: Tejun Heo <htejun@gmail.com>
266 249
267--------------------------- 250---------------------------
268 251
269What: Legacy RTC drivers (under drivers/i2c/chips)
270When: November 2007
271Why: Obsolete. We have a RTC subsystem with better drivers.
272Who: Jean Delvare <khali@linux-fr.org>
273
274---------------------------
275
276What: iptables SAME target 252What: iptables SAME target
277When: 1.1. 2008 253When: 1.1. 2008
278Files: net/ipv4/netfilter/ipt_SAME.c, include/linux/netfilter_ipv4/ipt_SAME.h 254Files: net/ipv4/netfilter/ipt_SAME.c, include/linux/netfilter_ipv4/ipt_SAME.h
@@ -323,3 +299,10 @@ Why: This driver has been marked obsolete for many years.
323Who: Stephen Hemminger <shemminger@linux-foundation.org> 299Who: Stephen Hemminger <shemminger@linux-foundation.org>
324 300
325--------------------------- 301---------------------------
302
303What: i2c-i810, i2c-prosavage and i2c-savage4
304When: May 2008
305Why: These drivers are superseded by i810fb, intelfb and savagefb.
306Who: Jean Delvare <khali@linux-fr.org>
307
308---------------------------
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index fde4420e3f75..3bd958360159 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -17,9 +17,8 @@ Supported adapters:
17 Datasheets: Publicly available at the Intel website 17 Datasheets: Publicly available at the Intel website
18 18
19Authors: 19Authors:
20 Frodo Looijaard <frodol@dds.nl>,
21 Philip Edelbrock <phil@netroedge.com>,
22 Mark Studebaker <mdsxyz123@yahoo.com> 20 Mark Studebaker <mdsxyz123@yahoo.com>
21 Jean Delvare <khali@linux-fr.org>
23 22
24 23
25Module Parameters 24Module Parameters
@@ -62,7 +61,7 @@ Not supported.
62I2C Block Read Support 61I2C Block Read Support
63---------------------- 62----------------------
64 63
65Not supported at the moment. 64I2C block read is supported on the 82801EB (ICH5) and later chips.
66 65
67 66
68SMBus 2.0 Support 67SMBus 2.0 Support
diff --git a/Documentation/i2c/busses/i2c-viapro b/Documentation/i2c/busses/i2c-viapro
index 06b4be3ef6d8..1405fb69984c 100644
--- a/Documentation/i2c/busses/i2c-viapro
+++ b/Documentation/i2c/busses/i2c-viapro
@@ -10,7 +10,7 @@ Supported adapters:
10 * VIA Technologies, Inc. VT8231, VT8233, VT8233A 10 * VIA Technologies, Inc. VT8231, VT8233, VT8233A
11 Datasheet: available on request from VIA 11 Datasheet: available on request from VIA
12 12
13 * VIA Technologies, Inc. VT8235, VT8237R, VT8237A, VT8251 13 * VIA Technologies, Inc. VT8235, VT8237R, VT8237A, VT8237S, VT8251
14 Datasheet: available on request and under NDA from VIA 14 Datasheet: available on request and under NDA from VIA
15 15
16 * VIA Technologies, Inc. CX700 16 * VIA Technologies, Inc. CX700
@@ -46,6 +46,7 @@ Your lspci -n listing must show one of these :
46 device 1106:3177 (VT8235) 46 device 1106:3177 (VT8235)
47 device 1106:3227 (VT8237R) 47 device 1106:3227 (VT8237R)
48 device 1106:3337 (VT8237A) 48 device 1106:3337 (VT8237A)
49 device 1106:3372 (VT8237S)
49 device 1106:3287 (VT8251) 50 device 1106:3287 (VT8251)
50 device 1106:8324 (CX700) 51 device 1106:8324 (CX700)
51 52
diff --git a/Documentation/i2c/chips/pcf8575 b/Documentation/i2c/chips/pcf8575
new file mode 100644
index 000000000000..25f5698a61cf
--- /dev/null
+++ b/Documentation/i2c/chips/pcf8575
@@ -0,0 +1,72 @@
1About the PCF8575 chip and the pcf8575 kernel driver
2====================================================
3
4The PCF8575 chip is produced by the following manufacturers:
5
6 * Philips NXP
7 http://www.nxp.com/#/pip/cb=[type=product,path=50807/41735/41850,final=PCF8575_3]|pip=[pip=PCF8575_3][0]
8
9 * Texas Instruments
10 http://focus.ti.com/docs/prod/folders/print/pcf8575.html
11
12
13Some vendors sell small PCB's with the PCF8575 mounted on it. You can connect
14such a board to a Linux host via e.g. an USB to I2C interface. Examples of
15PCB boards with a PCF8575:
16
17 * SFE Breakout Board for PCF8575 I2C Expander by RobotShop
18 http://www.robotshop.ca/home/products/robot-parts/electronics/adapters-converters/sfe-pcf8575-i2c-expander-board.html
19
20 * Breakout Board for PCF8575 I2C Expander by Spark Fun Electronics
21 http://www.sparkfun.com/commerce/product_info.php?products_id=8130
22
23
24Description
25-----------
26The PCF8575 chip is a 16-bit I/O expander for the I2C bus. Up to eight of
27these chips can be connected to the same I2C bus. You can find this
28chip on some custom designed hardware, but you won't find it on PC
29motherboards.
30
31The PCF8575 chip consists of a 16-bit quasi-bidirectional port and an I2C-bus
32interface. Each of the sixteen I/O's can be independently used as an input or
33an output. To set up an I/O pin as an input, you have to write a 1 to the
34corresponding output.
35
36For more information please see the datasheet.
37
38
39Detection
40---------
41
42There is no method known to detect whether a chip on a given I2C address is
43a PCF8575 or whether it is any other I2C device. So there are two alternatives
44to let the driver find the installed PCF8575 devices:
45- Load this driver after any other I2C driver for I2C devices with addresses
46 in the range 0x20 .. 0x27.
47- Pass the I2C bus and address of the installed PCF8575 devices explicitly to
48 the driver at load time via the probe=... or force=... parameters.
49
50/sys interface
51--------------
52
53For each address on which a PCF8575 chip was found or forced the following
54files will be created under /sys:
55* /sys/bus/i2c/devices/<bus>-<address>/read
56* /sys/bus/i2c/devices/<bus>-<address>/write
57where bus is the I2C bus number (0, 1, ...) and address is the four-digit
58hexadecimal representation of the 7-bit I2C address of the PCF8575
59(0020 .. 0027).
60
61The read file is read-only. Reading it will trigger an I2C read and will hence
62report the current input state for the pins configured as inputs, and the
63current output value for the pins configured as outputs.
64
65The write file is read-write. Writing a value to it will configure all pins
66as output for which the corresponding bit is zero. Reading the write file will
67return the value last written, or -EAGAIN if no value has yet been written to
68the write file.
69
70On module initialization the configuration of the chip is not changed -- the
71chip is left in the state it was already configured in through either power-up
72or through previous I2C write actions.
diff --git a/Documentation/i2c/i2c-stub b/Documentation/i2c/i2c-stub
index 89e69ad3436c..0d8be1c20c16 100644
--- a/Documentation/i2c/i2c-stub
+++ b/Documentation/i2c/i2c-stub
@@ -25,6 +25,9 @@ The typical use-case is like this:
25 3. load the target sensors chip driver module 25 3. load the target sensors chip driver module
26 4. observe its behavior in the kernel log 26 4. observe its behavior in the kernel log
27 27
28There's a script named i2c-stub-from-dump in the i2c-tools package which
29can load register values automatically from a chip dump.
30
28PARAMETERS: 31PARAMETERS:
29 32
30int chip_addr[10]: 33int chip_addr[10]:
@@ -32,9 +35,6 @@ int chip_addr[10]:
32 35
33CAVEATS: 36CAVEATS:
34 37
35There are independent arrays for byte/data and word/data commands. Depending
36on if/how a target driver mixes them, you'll need to be careful.
37
38If your target driver polls some byte or word waiting for it to change, the 38If your target driver polls some byte or word waiting for it to change, the
39stub could lock it up. Use i2cset to unlock it. 39stub could lock it up. Use i2cset to unlock it.
40 40
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index 2c170032bf37..bfb0a5520817 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -267,9 +267,9 @@ insmod parameter of the form force_<kind>.
267Fortunately, as a module writer, you just have to define the `normal_i2c' 267Fortunately, as a module writer, you just have to define the `normal_i2c'
268parameter. The complete declaration could look like this: 268parameter. The complete declaration could look like this:
269 269
270 /* Scan 0x37, and 0x48 to 0x4f */ 270 /* Scan 0x4c to 0x4f */
271 static unsigned short normal_i2c[] = { 0x37, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 271 static const unsigned short normal_i2c[] = { 0x4c, 0x4d, 0x4e, 0x4f,
272 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 272 I2C_CLIENT_END };
273 273
274 /* Magic definition of all other variables and things */ 274 /* Magic definition of all other variables and things */
275 I2C_CLIENT_INSMOD; 275 I2C_CLIENT_INSMOD;
diff --git a/arch/arm/mach-ixp4xx/avila-setup.c b/arch/arm/mach-ixp4xx/avila-setup.c
index d59b8dc7dc7a..e38f45fa58ae 100644
--- a/arch/arm/mach-ixp4xx/avila-setup.c
+++ b/arch/arm/mach-ixp4xx/avila-setup.c
@@ -18,6 +18,7 @@
18#include <linux/tty.h> 18#include <linux/tty.h>
19#include <linux/serial_8250.h> 19#include <linux/serial_8250.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/i2c-gpio.h>
21 22
22#include <asm/types.h> 23#include <asm/types.h>
23#include <asm/setup.h> 24#include <asm/setup.h>
@@ -47,18 +48,17 @@ static struct platform_device avila_flash = {
47 .resource = &avila_flash_resource, 48 .resource = &avila_flash_resource,
48}; 49};
49 50
50static struct ixp4xx_i2c_pins avila_i2c_gpio_pins = { 51static struct i2c_gpio_platform_data avila_i2c_gpio_data = {
51 .sda_pin = AVILA_SDA_PIN, 52 .sda_pin = AVILA_SDA_PIN,
52 .scl_pin = AVILA_SCL_PIN, 53 .scl_pin = AVILA_SCL_PIN,
53}; 54};
54 55
55static struct platform_device avila_i2c_controller = { 56static struct platform_device avila_i2c_gpio = {
56 .name = "IXP4XX-I2C", 57 .name = "i2c-gpio",
57 .id = 0, 58 .id = 0,
58 .dev = { 59 .dev = {
59 .platform_data = &avila_i2c_gpio_pins, 60 .platform_data = &avila_i2c_gpio_data,
60 }, 61 },
61 .num_resources = 0
62}; 62};
63 63
64static struct resource avila_uart_resources[] = { 64static struct resource avila_uart_resources[] = {
@@ -133,7 +133,7 @@ static struct platform_device avila_pata = {
133}; 133};
134 134
135static struct platform_device *avila_devices[] __initdata = { 135static struct platform_device *avila_devices[] __initdata = {
136 &avila_i2c_controller, 136 &avila_i2c_gpio,
137 &avila_flash, 137 &avila_flash,
138 &avila_uart 138 &avila_uart
139}; 139};
diff --git a/arch/arm/mach-ixp4xx/dsmg600-setup.c b/arch/arm/mach-ixp4xx/dsmg600-setup.c
index 1e75e105c4f7..c473d408aa7c 100644
--- a/arch/arm/mach-ixp4xx/dsmg600-setup.c
+++ b/arch/arm/mach-ixp4xx/dsmg600-setup.c
@@ -14,6 +14,7 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/serial.h> 15#include <linux/serial.h>
16#include <linux/serial_8250.h> 16#include <linux/serial_8250.h>
17#include <linux/i2c-gpio.h>
17 18
18#include <asm/mach-types.h> 19#include <asm/mach-types.h>
19#include <asm/mach/arch.h> 20#include <asm/mach/arch.h>
@@ -37,15 +38,17 @@ static struct platform_device dsmg600_flash = {
37 .resource = &dsmg600_flash_resource, 38 .resource = &dsmg600_flash_resource,
38}; 39};
39 40
40static struct ixp4xx_i2c_pins dsmg600_i2c_gpio_pins = { 41static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
41 .sda_pin = DSMG600_SDA_PIN, 42 .sda_pin = DSMG600_SDA_PIN,
42 .scl_pin = DSMG600_SCL_PIN, 43 .scl_pin = DSMG600_SCL_PIN,
43}; 44};
44 45
45static struct platform_device dsmg600_i2c_controller = { 46static struct platform_device dsmg600_i2c_gpio = {
46 .name = "IXP4XX-I2C", 47 .name = "i2c-gpio",
47 .id = 0, 48 .id = 0,
48 .dev.platform_data = &dsmg600_i2c_gpio_pins, 49 .dev = {
50 .platform_data = &dsmg600_i2c_gpio_data,
51 },
49}; 52};
50 53
51#ifdef CONFIG_LEDS_CLASS 54#ifdef CONFIG_LEDS_CLASS
@@ -116,7 +119,7 @@ static struct platform_device dsmg600_uart = {
116}; 119};
117 120
118static struct platform_device *dsmg600_devices[] __initdata = { 121static struct platform_device *dsmg600_devices[] __initdata = {
119 &dsmg600_i2c_controller, 122 &dsmg600_i2c_gpio,
120 &dsmg600_flash, 123 &dsmg600_flash,
121}; 124};
122 125
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index d5008d8fc9a5..e89070da28bf 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -15,6 +15,7 @@
15#include <linux/tty.h> 15#include <linux/tty.h>
16#include <linux/serial_8250.h> 16#include <linux/serial_8250.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/i2c-gpio.h>
18#include <linux/io.h> 19#include <linux/io.h>
19#include <linux/mtd/mtd.h> 20#include <linux/mtd/mtd.h>
20#include <linux/mtd/nand.h> 21#include <linux/mtd/nand.h>
@@ -120,18 +121,17 @@ static struct platform_device ixdp425_flash_nand = {
120}; 121};
121#endif /* CONFIG_MTD_NAND_PLATFORM */ 122#endif /* CONFIG_MTD_NAND_PLATFORM */
122 123
123static struct ixp4xx_i2c_pins ixdp425_i2c_gpio_pins = { 124static struct i2c_gpio_platform_data ixdp425_i2c_gpio_data = {
124 .sda_pin = IXDP425_SDA_PIN, 125 .sda_pin = IXDP425_SDA_PIN,
125 .scl_pin = IXDP425_SCL_PIN, 126 .scl_pin = IXDP425_SCL_PIN,
126}; 127};
127 128
128static struct platform_device ixdp425_i2c_controller = { 129static struct platform_device ixdp425_i2c_gpio = {
129 .name = "IXP4XX-I2C", 130 .name = "i2c-gpio",
130 .id = 0, 131 .id = 0,
131 .dev = { 132 .dev = {
132 .platform_data = &ixdp425_i2c_gpio_pins, 133 .platform_data = &ixdp425_i2c_gpio_data,
133 }, 134 },
134 .num_resources = 0
135}; 135};
136 136
137static struct resource ixdp425_uart_resources[] = { 137static struct resource ixdp425_uart_resources[] = {
@@ -178,7 +178,7 @@ static struct platform_device ixdp425_uart = {
178}; 178};
179 179
180static struct platform_device *ixdp425_devices[] __initdata = { 180static struct platform_device *ixdp425_devices[] __initdata = {
181 &ixdp425_i2c_controller, 181 &ixdp425_i2c_gpio,
182 &ixdp425_flash, 182 &ixdp425_flash,
183#if defined(CONFIG_MTD_NAND_PLATFORM) || \ 183#if defined(CONFIG_MTD_NAND_PLATFORM) || \
184 defined(CONFIG_MTD_NAND_PLATFORM_MODULE) 184 defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c b/arch/arm/mach-ixp4xx/nas100d-setup.c
index 78a17413ceca..54d884fb2517 100644
--- a/arch/arm/mach-ixp4xx/nas100d-setup.c
+++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
@@ -16,6 +16,7 @@
16#include <linux/serial.h> 16#include <linux/serial.h>
17#include <linux/serial_8250.h> 17#include <linux/serial_8250.h>
18#include <linux/leds.h> 18#include <linux/leds.h>
19#include <linux/i2c-gpio.h>
19 20
20#include <asm/mach-types.h> 21#include <asm/mach-types.h>
21#include <asm/mach/arch.h> 22#include <asm/mach/arch.h>
@@ -68,16 +69,17 @@ static struct platform_device nas100d_leds = {
68}; 69};
69#endif 70#endif
70 71
71static struct ixp4xx_i2c_pins nas100d_i2c_gpio_pins = { 72static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = {
72 .sda_pin = NAS100D_SDA_PIN, 73 .sda_pin = NAS100D_SDA_PIN,
73 .scl_pin = NAS100D_SCL_PIN, 74 .scl_pin = NAS100D_SCL_PIN,
74}; 75};
75 76
76static struct platform_device nas100d_i2c_controller = { 77static struct platform_device nas100d_i2c_gpio = {
77 .name = "IXP4XX-I2C", 78 .name = "i2c-gpio",
78 .id = 0, 79 .id = 0,
79 .dev.platform_data = &nas100d_i2c_gpio_pins, 80 .dev = {
80 .num_resources = 0, 81 .platform_data = &nas100d_i2c_gpio_data,
82 },
81}; 83};
82 84
83static struct resource nas100d_uart_resources[] = { 85static struct resource nas100d_uart_resources[] = {
@@ -124,7 +126,7 @@ static struct platform_device nas100d_uart = {
124}; 126};
125 127
126static struct platform_device *nas100d_devices[] __initdata = { 128static struct platform_device *nas100d_devices[] __initdata = {
127 &nas100d_i2c_controller, 129 &nas100d_i2c_gpio,
128 &nas100d_flash, 130 &nas100d_flash,
129#ifdef CONFIG_LEDS_IXP4XX 131#ifdef CONFIG_LEDS_IXP4XX
130 &nas100d_leds, 132 &nas100d_leds,
diff --git a/arch/arm/mach-ixp4xx/nslu2-setup.c b/arch/arm/mach-ixp4xx/nslu2-setup.c
index 9bf8ccbcaccf..77277d27fcc5 100644
--- a/arch/arm/mach-ixp4xx/nslu2-setup.c
+++ b/arch/arm/mach-ixp4xx/nslu2-setup.c
@@ -18,6 +18,7 @@
18#include <linux/serial.h> 18#include <linux/serial.h>
19#include <linux/serial_8250.h> 19#include <linux/serial_8250.h>
20#include <linux/leds.h> 20#include <linux/leds.h>
21#include <linux/i2c-gpio.h>
21 22
22#include <asm/mach-types.h> 23#include <asm/mach-types.h>
23#include <asm/mach/arch.h> 24#include <asm/mach/arch.h>
@@ -41,7 +42,7 @@ static struct platform_device nslu2_flash = {
41 .resource = &nslu2_flash_resource, 42 .resource = &nslu2_flash_resource,
42}; 43};
43 44
44static struct ixp4xx_i2c_pins nslu2_i2c_gpio_pins = { 45static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = {
45 .sda_pin = NSLU2_SDA_PIN, 46 .sda_pin = NSLU2_SDA_PIN,
46 .scl_pin = NSLU2_SCL_PIN, 47 .scl_pin = NSLU2_SCL_PIN,
47}; 48};
@@ -82,11 +83,12 @@ static struct platform_device nslu2_leds = {
82}; 83};
83#endif 84#endif
84 85
85static struct platform_device nslu2_i2c_controller = { 86static struct platform_device nslu2_i2c_gpio = {
86 .name = "IXP4XX-I2C", 87 .name = "i2c-gpio",
87 .id = 0, 88 .id = 0,
88 .dev.platform_data = &nslu2_i2c_gpio_pins, 89 .dev = {
89 .num_resources = 0, 90 .platform_data = &nslu2_i2c_gpio_data,
91 },
90}; 92};
91 93
92static struct platform_device nslu2_beeper = { 94static struct platform_device nslu2_beeper = {
@@ -139,7 +141,7 @@ static struct platform_device nslu2_uart = {
139}; 141};
140 142
141static struct platform_device *nslu2_devices[] __initdata = { 143static struct platform_device *nslu2_devices[] __initdata = {
142 &nslu2_i2c_controller, 144 &nslu2_i2c_gpio,
143 &nslu2_flash, 145 &nslu2_flash,
144 &nslu2_beeper, 146 &nslu2_beeper,
145#ifdef CONFIG_LEDS_IXP4XX 147#ifdef CONFIG_LEDS_IXP4XX
diff --git a/arch/arm/mach-omap1/board-h2.c b/arch/arm/mach-omap1/board-h2.c
index 130681201c19..9393824cc150 100644
--- a/arch/arm/mach-omap1/board-h2.c
+++ b/arch/arm/mach-omap1/board-h2.c
@@ -27,6 +27,7 @@
27#include <linux/mtd/nand.h> 27#include <linux/mtd/nand.h>
28#include <linux/mtd/partitions.h> 28#include <linux/mtd/partitions.h>
29#include <linux/input.h> 29#include <linux/input.h>
30#include <linux/i2c/tps65010.h>
30 31
31#include <asm/hardware.h> 32#include <asm/hardware.h>
32#include <asm/gpio.h> 33#include <asm/gpio.h>
@@ -36,7 +37,6 @@
36#include <asm/mach/flash.h> 37#include <asm/mach/flash.h>
37#include <asm/mach/map.h> 38#include <asm/mach/map.h>
38 39
39#include <asm/arch/tps65010.h>
40#include <asm/arch/mux.h> 40#include <asm/arch/mux.h>
41#include <asm/arch/tc.h> 41#include <asm/arch/tc.h>
42#include <asm/arch/irda.h> 42#include <asm/arch/irda.h>
diff --git a/arch/arm/mach-omap1/board-h3.c b/arch/arm/mach-omap1/board-h3.c
index 4f84ae273a1f..978cdab16535 100644
--- a/arch/arm/mach-omap1/board-h3.c
+++ b/arch/arm/mach-omap1/board-h3.c
@@ -26,6 +26,7 @@
26#include <linux/mtd/nand.h> 26#include <linux/mtd/nand.h>
27#include <linux/mtd/partitions.h> 27#include <linux/mtd/partitions.h>
28#include <linux/input.h> 28#include <linux/input.h>
29#include <linux/i2c/tps65010.h>
29 30
30#include <asm/setup.h> 31#include <asm/setup.h>
31#include <asm/page.h> 32#include <asm/page.h>
@@ -37,7 +38,6 @@
37#include <asm/mach/flash.h> 38#include <asm/mach/flash.h>
38#include <asm/mach/map.h> 39#include <asm/mach/map.h>
39 40
40#include <asm/arch/tps65010.h>
41#include <asm/arch/gpioexpander.h> 41#include <asm/arch/gpioexpander.h>
42#include <asm/arch/irqs.h> 42#include <asm/arch/irqs.h>
43#include <asm/arch/mux.h> 43#include <asm/arch/mux.h>
diff --git a/arch/arm/mach-omap1/board-osk.c b/arch/arm/mach-omap1/board-osk.c
index 5db182da322b..5b575e687a2a 100644
--- a/arch/arm/mach-omap1/board-osk.c
+++ b/arch/arm/mach-omap1/board-osk.c
@@ -37,6 +37,8 @@
37#include <linux/mtd/mtd.h> 37#include <linux/mtd/mtd.h>
38#include <linux/mtd/partitions.h> 38#include <linux/mtd/partitions.h>
39 39
40#include <linux/i2c/tps65010.h>
41
40#include <asm/hardware.h> 42#include <asm/hardware.h>
41#include <asm/gpio.h> 43#include <asm/gpio.h>
42 44
@@ -46,7 +48,6 @@
46#include <asm/mach/flash.h> 48#include <asm/mach/flash.h>
47 49
48#include <asm/arch/usb.h> 50#include <asm/arch/usb.h>
49#include <asm/arch/tps65010.h>
50#include <asm/arch/mux.h> 51#include <asm/arch/mux.h>
51#include <asm/arch/tc.h> 52#include <asm/arch/tc.h>
52#include <asm/arch/common.h> 53#include <asm/arch/common.h>
diff --git a/arch/arm/mach-omap1/leds-osk.c b/arch/arm/mach-omap1/leds-osk.c
index 86de303ecab2..6939d5e7569a 100644
--- a/arch/arm/mach-omap1/leds-osk.c
+++ b/arch/arm/mach-omap1/leds-osk.c
@@ -5,13 +5,13 @@
5 */ 5 */
6#include <linux/init.h> 6#include <linux/init.h>
7#include <linux/workqueue.h> 7#include <linux/workqueue.h>
8#include <linux/i2c/tps65010.h>
8 9
9#include <asm/hardware.h> 10#include <asm/hardware.h>
10#include <asm/leds.h> 11#include <asm/leds.h>
11#include <asm/system.h> 12#include <asm/system.h>
12 13
13#include <asm/arch/gpio.h> 14#include <asm/arch/gpio.h>
14#include <asm/arch/tps65010.h>
15 15
16#include "leds.h" 16#include "leds.h"
17 17
diff --git a/arch/arm/mach-pxa/akita-ioexp.c b/arch/arm/mach-pxa/akita-ioexp.c
index 12d2fe0ceff6..254892ac30cd 100644
--- a/arch/arm/mach-pxa/akita-ioexp.c
+++ b/arch/arm/mach-pxa/akita-ioexp.c
@@ -29,7 +29,7 @@
29#define MAX7310_TIMEOUT 0x04 29#define MAX7310_TIMEOUT 0x04
30 30
31/* Addresses to scan */ 31/* Addresses to scan */
32static unsigned short normal_i2c[] = { 0x18, I2C_CLIENT_END }; 32static const unsigned short normal_i2c[] = { 0x18, I2C_CLIENT_END };
33 33
34/* I2C Magic */ 34/* I2C Magic */
35I2C_CLIENT_INSMOD; 35I2C_CLIENT_INSMOD;
diff --git a/arch/arm/mach-pxa/pxa27x.c b/arch/arm/mach-pxa/pxa27x.c
index 8e126e6b74c3..57efebdc4324 100644
--- a/arch/arm/mach-pxa/pxa27x.c
+++ b/arch/arm/mach-pxa/pxa27x.c
@@ -24,6 +24,7 @@
24#include <asm/arch/ohci.h> 24#include <asm/arch/ohci.h>
25#include <asm/arch/pm.h> 25#include <asm/arch/pm.h>
26#include <asm/arch/dma.h> 26#include <asm/arch/dma.h>
27#include <asm/arch/i2c.h>
27 28
28#include "generic.h" 29#include "generic.h"
29#include "devices.h" 30#include "devices.h"
@@ -423,6 +424,11 @@ struct platform_device pxa27x_device_i2c_power = {
423 .num_resources = ARRAY_SIZE(i2c_power_resources), 424 .num_resources = ARRAY_SIZE(i2c_power_resources),
424}; 425};
425 426
427void __init pxa_set_i2c_power_info(struct i2c_pxa_platform_data *info)
428{
429 pxa27x_device_i2c_power.dev.platform_data = info;
430}
431
426static struct platform_device *devices[] __initdata = { 432static struct platform_device *devices[] __initdata = {
427 &pxa_device_mci, 433 &pxa_device_mci,
428 &pxa_device_udc, 434 &pxa_device_udc,
diff --git a/arch/mips/au1000/common/platform.c b/arch/mips/au1000/common/platform.c
index d51e18fb789b..841904cdef4d 100644
--- a/arch/mips/au1000/common/platform.c
+++ b/arch/mips/au1000/common/platform.c
@@ -270,6 +270,24 @@ static struct platform_device smc91x_device = {
270 270
271#endif 271#endif
272 272
273/* All Alchemy demoboards with I2C have this #define in their headers */
274#ifdef SMBUS_PSC_BASE
275static struct resource pbdb_smbus_resources[] = {
276 {
277 .start = SMBUS_PSC_BASE,
278 .end = SMBUS_PSC_BASE + 0x24 - 1,
279 .flags = IORESOURCE_MEM,
280 },
281};
282
283static struct platform_device pbdb_smbus_device = {
284 .name = "au1xpsc_smbus",
285 .id = 0, /* bus number */
286 .num_resources = ARRAY_SIZE(pbdb_smbus_resources),
287 .resource = pbdb_smbus_resources,
288};
289#endif
290
273static struct platform_device *au1xxx_platform_devices[] __initdata = { 291static struct platform_device *au1xxx_platform_devices[] __initdata = {
274 &au1xxx_usb_ohci_device, 292 &au1xxx_usb_ohci_device,
275 &au1x00_pcmcia_device, 293 &au1x00_pcmcia_device,
@@ -287,6 +305,9 @@ static struct platform_device *au1xxx_platform_devices[] __initdata = {
287#ifdef CONFIG_MIPS_DB1200 305#ifdef CONFIG_MIPS_DB1200
288 &smc91x_device, 306 &smc91x_device,
289#endif 307#endif
308#ifdef SMBUS_PSC_BASE
309 &pbdb_smbus_device,
310#endif
290}; 311};
291 312
292int __init au1xxx_platform_init(void) 313int __init au1xxx_platform_init(void)
diff --git a/arch/ppc/platforms/83xx/mpc834x_sys.c b/arch/ppc/platforms/83xx/mpc834x_sys.c
index b84f8df325c4..cb0a7493ff64 100644
--- a/arch/ppc/platforms/83xx/mpc834x_sys.c
+++ b/arch/ppc/platforms/83xx/mpc834x_sys.c
@@ -224,26 +224,6 @@ mpc834x_sys_init_IRQ(void)
224 ipic_set_default_priority(); 224 ipic_set_default_priority();
225} 225}
226 226
227#if defined(CONFIG_I2C_MPC) && defined(CONFIG_SENSORS_DS1374)
228extern ulong ds1374_get_rtc_time(void);
229extern int ds1374_set_rtc_time(ulong);
230
231static int __init
232mpc834x_rtc_hookup(void)
233{
234 struct timespec tv;
235
236 ppc_md.get_rtc_time = ds1374_get_rtc_time;
237 ppc_md.set_rtc_time = ds1374_set_rtc_time;
238
239 tv.tv_nsec = 0;
240 tv.tv_sec = (ppc_md.get_rtc_time)();
241 do_settimeofday(&tv);
242
243 return 0;
244}
245late_initcall(mpc834x_rtc_hookup);
246#endif
247static __inline__ void 227static __inline__ void
248mpc834x_sys_set_bat(void) 228mpc834x_sys_set_bat(void)
249{ 229{
diff --git a/arch/ppc/platforms/85xx/tqm85xx.c b/arch/ppc/platforms/85xx/tqm85xx.c
index 4ee2bd156dc5..27ce389c1224 100644
--- a/arch/ppc/platforms/85xx/tqm85xx.c
+++ b/arch/ppc/platforms/85xx/tqm85xx.c
@@ -258,27 +258,6 @@ int tqm85xx_show_cpuinfo(struct seq_file *m)
258 return 0; 258 return 0;
259} 259}
260 260
261#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_DS1337)
262extern ulong ds1337_get_rtc_time(void);
263extern int ds1337_set_rtc_time(unsigned long nowtime);
264
265static int __init
266tqm85xx_rtc_hookup(void)
267{
268 struct timespec tv;
269
270 ppc_md.set_rtc_time = ds1337_set_rtc_time;
271 ppc_md.get_rtc_time = ds1337_get_rtc_time;
272
273 tv.tv_nsec = 0;
274 tv.tv_sec = (ppc_md.get_rtc_time)();
275 do_settimeofday(&tv);
276
277 return 0;
278}
279late_initcall(tqm85xx_rtc_hookup);
280#endif
281
282#ifdef CONFIG_PCI 261#ifdef CONFIG_PCI
283/* 262/*
284 * interrupt routing 263 * interrupt routing
diff --git a/arch/ppc/platforms/katana.c b/arch/ppc/platforms/katana.c
index 52f63e6f0856..fe6e88cdb1cd 100644
--- a/arch/ppc/platforms/katana.c
+++ b/arch/ppc/platforms/katana.c
@@ -838,27 +838,6 @@ katana_find_end_of_memory(void)
838 return bdp->bi_memsize; 838 return bdp->bi_memsize;
839} 839}
840 840
841#if defined(CONFIG_I2C_MV64XXX) && defined(CONFIG_SENSORS_M41T00)
842extern ulong m41t00_get_rtc_time(void);
843extern int m41t00_set_rtc_time(ulong);
844
845static int __init
846katana_rtc_hookup(void)
847{
848 struct timespec tv;
849
850 ppc_md.get_rtc_time = m41t00_get_rtc_time;
851 ppc_md.set_rtc_time = m41t00_set_rtc_time;
852
853 tv.tv_nsec = 0;
854 tv.tv_sec = (ppc_md.get_rtc_time)();
855 do_settimeofday(&tv);
856
857 return 0;
858}
859late_initcall(katana_rtc_hookup);
860#endif
861
862#if defined(CONFIG_SERIAL_TEXT_DEBUG) && defined(CONFIG_SERIAL_MPSC_CONSOLE) 841#if defined(CONFIG_SERIAL_TEXT_DEBUG) && defined(CONFIG_SERIAL_MPSC_CONSOLE)
863static void __init 842static void __init
864katana_map_io(void) 843katana_map_io(void)
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index a37cb6b8593c..35812823787b 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------- */ 1/* -------------------------------------------------------------------------
2/* i2c-algo-bit.c i2c driver algorithms for bit-shift adapters */ 2 * i2c-algo-bit.c i2c driver algorithms for bit-shift adapters
3/* ------------------------------------------------------------------------- */ 3 * -------------------------------------------------------------------------
4/* Copyright (C) 1995-2000 Simon G. Vogl 4 * Copyright (C) 1995-2000 Simon G. Vogl
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
@@ -15,8 +15,8 @@
15 15
16 You should have received a copy of the GNU General Public License 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 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19/* ------------------------------------------------------------------------- */ 19 * ------------------------------------------------------------------------- */
20 20
21/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki 21/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki
22 <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */ 22 <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */
@@ -60,26 +60,26 @@ MODULE_PARM_DESC(i2c_debug,
60 60
61/* --- setting states on the bus with the right timing: --------------- */ 61/* --- setting states on the bus with the right timing: --------------- */
62 62
63#define setsda(adap,val) adap->setsda(adap->data, val) 63#define setsda(adap, val) adap->setsda(adap->data, val)
64#define setscl(adap,val) adap->setscl(adap->data, val) 64#define setscl(adap, val) adap->setscl(adap->data, val)
65#define getsda(adap) adap->getsda(adap->data) 65#define getsda(adap) adap->getsda(adap->data)
66#define getscl(adap) adap->getscl(adap->data) 66#define getscl(adap) adap->getscl(adap->data)
67 67
68static inline void sdalo(struct i2c_algo_bit_data *adap) 68static inline void sdalo(struct i2c_algo_bit_data *adap)
69{ 69{
70 setsda(adap,0); 70 setsda(adap, 0);
71 udelay((adap->udelay + 1) / 2); 71 udelay((adap->udelay + 1) / 2);
72} 72}
73 73
74static inline void sdahi(struct i2c_algo_bit_data *adap) 74static inline void sdahi(struct i2c_algo_bit_data *adap)
75{ 75{
76 setsda(adap,1); 76 setsda(adap, 1);
77 udelay((adap->udelay + 1) / 2); 77 udelay((adap->udelay + 1) / 2);
78} 78}
79 79
80static inline void scllo(struct i2c_algo_bit_data *adap) 80static inline void scllo(struct i2c_algo_bit_data *adap)
81{ 81{
82 setscl(adap,0); 82 setscl(adap, 0);
83 udelay(adap->udelay / 2); 83 udelay(adap->udelay / 2);
84} 84}
85 85
@@ -91,22 +91,21 @@ static int sclhi(struct i2c_algo_bit_data *adap)
91{ 91{
92 unsigned long start; 92 unsigned long start;
93 93
94 setscl(adap,1); 94 setscl(adap, 1);
95 95
96 /* Not all adapters have scl sense line... */ 96 /* Not all adapters have scl sense line... */
97 if (!adap->getscl) 97 if (!adap->getscl)
98 goto done; 98 goto done;
99 99
100 start=jiffies; 100 start = jiffies;
101 while (! getscl(adap) ) { 101 while (!getscl(adap)) {
102 /* the hw knows how to read the clock line, 102 /* This hw knows how to read the clock line, so we wait
103 * so we wait until it actually gets high. 103 * until it actually gets high. This is safer as some
104 * This is safer as some chips may hold it low 104 * chips may hold it low ("clock stretching") while they
105 * while they are processing data internally. 105 * are processing data internally.
106 */ 106 */
107 if (time_after_eq(jiffies, start+adap->timeout)) { 107 if (time_after_eq(jiffies, start + adap->timeout))
108 return -ETIMEDOUT; 108 return -ETIMEDOUT;
109 }
110 cond_resched(); 109 cond_resched();
111 } 110 }
112#ifdef DEBUG 111#ifdef DEBUG
@@ -118,11 +117,11 @@ static int sclhi(struct i2c_algo_bit_data *adap)
118done: 117done:
119 udelay(adap->udelay); 118 udelay(adap->udelay);
120 return 0; 119 return 0;
121} 120}
122 121
123 122
124/* --- other auxiliary functions -------------------------------------- */ 123/* --- other auxiliary functions -------------------------------------- */
125static void i2c_start(struct i2c_algo_bit_data *adap) 124static void i2c_start(struct i2c_algo_bit_data *adap)
126{ 125{
127 /* assert: scl, sda are high */ 126 /* assert: scl, sda are high */
128 setsda(adap, 0); 127 setsda(adap, 0);
@@ -130,7 +129,7 @@ static void i2c_start(struct i2c_algo_bit_data *adap)
130 scllo(adap); 129 scllo(adap);
131} 130}
132 131
133static void i2c_repstart(struct i2c_algo_bit_data *adap) 132static void i2c_repstart(struct i2c_algo_bit_data *adap)
134{ 133{
135 /* assert: scl is low */ 134 /* assert: scl is low */
136 sdahi(adap); 135 sdahi(adap);
@@ -141,18 +140,18 @@ static void i2c_repstart(struct i2c_algo_bit_data *adap)
141} 140}
142 141
143 142
144static void i2c_stop(struct i2c_algo_bit_data *adap) 143static void i2c_stop(struct i2c_algo_bit_data *adap)
145{ 144{
146 /* assert: scl is low */ 145 /* assert: scl is low */
147 sdalo(adap); 146 sdalo(adap);
148 sclhi(adap); 147 sclhi(adap);
149 setsda(adap, 1); 148 setsda(adap, 1);
150 udelay(adap->udelay); 149 udelay(adap->udelay);
151} 150}
152 151
153 152
154 153
155/* send a byte without start cond., look for arbitration, 154/* send a byte without start cond., look for arbitration,
156 check ackn. from slave */ 155 check ackn. from slave */
157/* returns: 156/* returns:
158 * 1 if the device acknowledged 157 * 1 if the device acknowledged
@@ -167,27 +166,33 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
167 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 166 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
168 167
169 /* assert: scl is low */ 168 /* assert: scl is low */
170 for ( i=7 ; i>=0 ; i-- ) { 169 for (i = 7; i >= 0; i--) {
171 sb = (c >> i) & 1; 170 sb = (c >> i) & 1;
172 setsda(adap,sb); 171 setsda(adap, sb);
173 udelay((adap->udelay + 1) / 2); 172 udelay((adap->udelay + 1) / 2);
174 if (sclhi(adap)<0) { /* timed out */ 173 if (sclhi(adap) < 0) { /* timed out */
175 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " 174 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
176 "timeout at bit #%d\n", (int)c, i); 175 "timeout at bit #%d\n", (int)c, i);
177 return -ETIMEDOUT; 176 return -ETIMEDOUT;
178 }; 177 }
179 /* do arbitration here: 178 /* FIXME do arbitration here:
180 * if ( sb && ! getsda(adap) ) -> ouch! Get out of here. 179 * if (sb && !getsda(adap)) -> ouch! Get out of here.
180 *
181 * Report a unique code, so higher level code can retry
182 * the whole (combined) message and *NOT* issue STOP.
181 */ 183 */
182 scllo(adap); 184 scllo(adap);
183 } 185 }
184 sdahi(adap); 186 sdahi(adap);
185 if (sclhi(adap)<0){ /* timeout */ 187 if (sclhi(adap) < 0) { /* timeout */
186 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " 188 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
187 "timeout at ack\n", (int)c); 189 "timeout at ack\n", (int)c);
188 return -ETIMEDOUT; 190 return -ETIMEDOUT;
189 }; 191 }
190 /* read ack: SDA should be pulled down by slave */ 192
193 /* read ack: SDA should be pulled down by slave, or it may
194 * NAK (usually to report problems with the data we wrote).
195 */
191 ack = !getsda(adap); /* ack: sda is pulled low -> success */ 196 ack = !getsda(adap); /* ack: sda is pulled low -> success */
192 bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c, 197 bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c,
193 ack ? "A" : "NA"); 198 ack ? "A" : "NA");
@@ -198,24 +203,24 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
198} 203}
199 204
200 205
201static int i2c_inb(struct i2c_adapter *i2c_adap) 206static int i2c_inb(struct i2c_adapter *i2c_adap)
202{ 207{
203 /* read byte via i2c port, without start/stop sequence */ 208 /* read byte via i2c port, without start/stop sequence */
204 /* acknowledge is sent in i2c_read. */ 209 /* acknowledge is sent in i2c_read. */
205 int i; 210 int i;
206 unsigned char indata=0; 211 unsigned char indata = 0;
207 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 212 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
208 213
209 /* assert: scl is low */ 214 /* assert: scl is low */
210 sdahi(adap); 215 sdahi(adap);
211 for (i=0;i<8;i++) { 216 for (i = 0; i < 8; i++) {
212 if (sclhi(adap)<0) { /* timeout */ 217 if (sclhi(adap) < 0) { /* timeout */
213 bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit " 218 bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit "
214 "#%d\n", 7 - i); 219 "#%d\n", 7 - i);
215 return -ETIMEDOUT; 220 return -ETIMEDOUT;
216 }; 221 }
217 indata *= 2; 222 indata *= 2;
218 if ( getsda(adap) ) 223 if (getsda(adap))
219 indata |= 0x01; 224 indata |= 0x01;
220 setscl(adap, 0); 225 setscl(adap, 0);
221 udelay(i == 7 ? adap->udelay / 2 : adap->udelay); 226 udelay(i == 7 ? adap->udelay / 2 : adap->udelay);
@@ -228,66 +233,67 @@ static int i2c_inb(struct i2c_adapter *i2c_adap)
228 * Sanity check for the adapter hardware - check the reaction of 233 * Sanity check for the adapter hardware - check the reaction of
229 * the bus lines only if it seems to be idle. 234 * the bus lines only if it seems to be idle.
230 */ 235 */
231static int test_bus(struct i2c_algo_bit_data *adap, char* name) { 236static int test_bus(struct i2c_algo_bit_data *adap, char *name)
232 int scl,sda; 237{
238 int scl, sda;
233 239
234 if (adap->getscl==NULL) 240 if (adap->getscl == NULL)
235 pr_info("%s: Testing SDA only, SCL is not readable\n", name); 241 pr_info("%s: Testing SDA only, SCL is not readable\n", name);
236 242
237 sda=getsda(adap); 243 sda = getsda(adap);
238 scl=(adap->getscl==NULL?1:getscl(adap)); 244 scl = (adap->getscl == NULL) ? 1 : getscl(adap);
239 if (!scl || !sda ) { 245 if (!scl || !sda) {
240 printk(KERN_WARNING "%s: bus seems to be busy\n", name); 246 printk(KERN_WARNING "%s: bus seems to be busy\n", name);
241 goto bailout; 247 goto bailout;
242 } 248 }
243 249
244 sdalo(adap); 250 sdalo(adap);
245 sda=getsda(adap); 251 sda = getsda(adap);
246 scl=(adap->getscl==NULL?1:getscl(adap)); 252 scl = (adap->getscl == NULL) ? 1 : getscl(adap);
247 if ( 0 != sda ) { 253 if (sda) {
248 printk(KERN_WARNING "%s: SDA stuck high!\n", name); 254 printk(KERN_WARNING "%s: SDA stuck high!\n", name);
249 goto bailout; 255 goto bailout;
250 } 256 }
251 if ( 0 == scl ) { 257 if (!scl) {
252 printk(KERN_WARNING "%s: SCL unexpected low " 258 printk(KERN_WARNING "%s: SCL unexpected low "
253 "while pulling SDA low!\n", name); 259 "while pulling SDA low!\n", name);
254 goto bailout; 260 goto bailout;
255 } 261 }
256 262
257 sdahi(adap); 263 sdahi(adap);
258 sda=getsda(adap); 264 sda = getsda(adap);
259 scl=(adap->getscl==NULL?1:getscl(adap)); 265 scl = (adap->getscl == NULL) ? 1 : getscl(adap);
260 if ( 0 == sda ) { 266 if (!sda) {
261 printk(KERN_WARNING "%s: SDA stuck low!\n", name); 267 printk(KERN_WARNING "%s: SDA stuck low!\n", name);
262 goto bailout; 268 goto bailout;
263 } 269 }
264 if ( 0 == scl ) { 270 if (!scl) {
265 printk(KERN_WARNING "%s: SCL unexpected low " 271 printk(KERN_WARNING "%s: SCL unexpected low "
266 "while pulling SDA high!\n", name); 272 "while pulling SDA high!\n", name);
267 goto bailout; 273 goto bailout;
268 } 274 }
269 275
270 scllo(adap); 276 scllo(adap);
271 sda=getsda(adap); 277 sda = getsda(adap);
272 scl=(adap->getscl==NULL?0:getscl(adap)); 278 scl = (adap->getscl == NULL) ? 0 : getscl(adap);
273 if ( 0 != scl ) { 279 if (scl) {
274 printk(KERN_WARNING "%s: SCL stuck high!\n", name); 280 printk(KERN_WARNING "%s: SCL stuck high!\n", name);
275 goto bailout; 281 goto bailout;
276 } 282 }
277 if ( 0 == sda ) { 283 if (!sda) {
278 printk(KERN_WARNING "%s: SDA unexpected low " 284 printk(KERN_WARNING "%s: SDA unexpected low "
279 "while pulling SCL low!\n", name); 285 "while pulling SCL low!\n", name);
280 goto bailout; 286 goto bailout;
281 } 287 }
282 288
283 sclhi(adap); 289 sclhi(adap);
284 sda=getsda(adap); 290 sda = getsda(adap);
285 scl=(adap->getscl==NULL?1:getscl(adap)); 291 scl = (adap->getscl == NULL) ? 1 : getscl(adap);
286 if ( 0 == scl ) { 292 if (!scl) {
287 printk(KERN_WARNING "%s: SCL stuck low!\n", name); 293 printk(KERN_WARNING "%s: SCL stuck low!\n", name);
288 goto bailout; 294 goto bailout;
289 } 295 }
290 if ( 0 == sda ) { 296 if (!sda) {
291 printk(KERN_WARNING "%s: SDA unexpected low " 297 printk(KERN_WARNING "%s: SDA unexpected low "
292 "while pulling SCL high!\n", name); 298 "while pulling SCL high!\n", name);
293 goto bailout; 299 goto bailout;
@@ -314,9 +320,10 @@ static int try_address(struct i2c_adapter *i2c_adap,
314 unsigned char addr, int retries) 320 unsigned char addr, int retries)
315{ 321{
316 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 322 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
317 int i,ret = -1; 323 int i, ret = -1;
318 for (i=0;i<=retries;i++) { 324
319 ret = i2c_outb(i2c_adap,addr); 325 for (i = 0; i <= retries; i++) {
326 ret = i2c_outb(i2c_adap, addr);
320 if (ret == 1 || i == retries) 327 if (ret == 1 || i == retries)
321 break; 328 break;
322 bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); 329 bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
@@ -338,20 +345,38 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
338{ 345{
339 const unsigned char *temp = msg->buf; 346 const unsigned char *temp = msg->buf;
340 int count = msg->len; 347 int count = msg->len;
341 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; 348 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
342 int retval; 349 int retval;
343 int wrcount=0; 350 int wrcount = 0;
344 351
345 while (count > 0) { 352 while (count > 0) {
346 retval = i2c_outb(i2c_adap, *temp); 353 retval = i2c_outb(i2c_adap, *temp);
347 if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */ 354
348 count--; 355 /* OK/ACK; or ignored NAK */
356 if ((retval > 0) || (nak_ok && (retval == 0))) {
357 count--;
349 temp++; 358 temp++;
350 wrcount++; 359 wrcount++;
351 } else { /* arbitration or no acknowledge */ 360
352 dev_err(&i2c_adap->dev, "sendbytes: error - bailout.\n"); 361 /* A slave NAKing the master means the slave didn't like
353 return (retval<0)? retval : -EFAULT; 362 * something about the data it saw. For example, maybe
354 /* got a better one ?? */ 363 * the SMBus PEC was wrong.
364 */
365 } else if (retval == 0) {
366 dev_err(&i2c_adap->dev, "sendbytes: NAK bailout.\n");
367 return -EIO;
368
369 /* Timeout; or (someday) lost arbitration
370 *
371 * FIXME Lost ARB implies retrying the transaction from
372 * the first message, after the "winning" master issues
373 * its STOP. As a rule, upper layer code has no reason
374 * to know or care about this ... it is *NOT* an error.
375 */
376 } else {
377 dev_err(&i2c_adap->dev, "sendbytes: error %d\n",
378 retval);
379 return retval;
355 } 380 }
356 } 381 }
357 return wrcount; 382 return wrcount;
@@ -376,14 +401,14 @@ static int acknak(struct i2c_adapter *i2c_adap, int is_ack)
376static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 401static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
377{ 402{
378 int inval; 403 int inval;
379 int rdcount=0; /* counts bytes read */ 404 int rdcount = 0; /* counts bytes read */
380 unsigned char *temp = msg->buf; 405 unsigned char *temp = msg->buf;
381 int count = msg->len; 406 int count = msg->len;
382 const unsigned flags = msg->flags; 407 const unsigned flags = msg->flags;
383 408
384 while (count > 0) { 409 while (count > 0) {
385 inval = i2c_inb(i2c_adap); 410 inval = i2c_inb(i2c_adap);
386 if (inval>=0) { 411 if (inval >= 0) {
387 *temp = inval; 412 *temp = inval;
388 rdcount++; 413 rdcount++;
389 } else { /* read timed out */ 414 } else { /* read timed out */
@@ -431,7 +456,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
431 * returns: 456 * returns:
432 * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set 457 * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
433 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or 458 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
434 * -ETIMEDOUT, for example if the lines are stuck...) 459 * -ETIMEDOUT, for example if the lines are stuck...)
435 */ 460 */
436static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 461static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
437{ 462{
@@ -443,10 +468,10 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
443 int ret, retries; 468 int ret, retries;
444 469
445 retries = nak_ok ? 0 : i2c_adap->retries; 470 retries = nak_ok ? 0 : i2c_adap->retries;
446 471
447 if ( (flags & I2C_M_TEN) ) { 472 if (flags & I2C_M_TEN) {
448 /* a ten bit address */ 473 /* a ten bit address */
449 addr = 0xf0 | (( msg->addr >> 7) & 0x03); 474 addr = 0xf0 | ((msg->addr >> 7) & 0x03);
450 bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); 475 bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr);
451 /* try extended address code...*/ 476 /* try extended address code...*/
452 ret = try_address(i2c_adap, addr, retries); 477 ret = try_address(i2c_adap, addr, retries);
@@ -456,33 +481,33 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
456 return -EREMOTEIO; 481 return -EREMOTEIO;
457 } 482 }
458 /* the remaining 8 bit address */ 483 /* the remaining 8 bit address */
459 ret = i2c_outb(i2c_adap,msg->addr & 0x7f); 484 ret = i2c_outb(i2c_adap, msg->addr & 0x7f);
460 if ((ret != 1) && !nak_ok) { 485 if ((ret != 1) && !nak_ok) {
461 /* the chip did not ack / xmission error occurred */ 486 /* the chip did not ack / xmission error occurred */
462 dev_err(&i2c_adap->dev, "died at 2nd address code\n"); 487 dev_err(&i2c_adap->dev, "died at 2nd address code\n");
463 return -EREMOTEIO; 488 return -EREMOTEIO;
464 } 489 }
465 if ( flags & I2C_M_RD ) { 490 if (flags & I2C_M_RD) {
466 bit_dbg(3, &i2c_adap->dev, "emitting repeated " 491 bit_dbg(3, &i2c_adap->dev, "emitting repeated "
467 "start condition\n"); 492 "start condition\n");
468 i2c_repstart(adap); 493 i2c_repstart(adap);
469 /* okay, now switch into reading mode */ 494 /* okay, now switch into reading mode */
470 addr |= 0x01; 495 addr |= 0x01;
471 ret = try_address(i2c_adap, addr, retries); 496 ret = try_address(i2c_adap, addr, retries);
472 if ((ret!=1) && !nak_ok) { 497 if ((ret != 1) && !nak_ok) {
473 dev_err(&i2c_adap->dev, 498 dev_err(&i2c_adap->dev,
474 "died at repeated address code\n"); 499 "died at repeated address code\n");
475 return -EREMOTEIO; 500 return -EREMOTEIO;
476 } 501 }
477 } 502 }
478 } else { /* normal 7bit address */ 503 } else { /* normal 7bit address */
479 addr = ( msg->addr << 1 ); 504 addr = msg->addr << 1;
480 if (flags & I2C_M_RD ) 505 if (flags & I2C_M_RD)
481 addr |= 1; 506 addr |= 1;
482 if (flags & I2C_M_REV_DIR_ADDR ) 507 if (flags & I2C_M_REV_DIR_ADDR)
483 addr ^= 1; 508 addr ^= 1;
484 ret = try_address(i2c_adap, addr, retries); 509 ret = try_address(i2c_adap, addr, retries);
485 if ((ret!=1) && !nak_ok) 510 if ((ret != 1) && !nak_ok)
486 return -EREMOTEIO; 511 return -EREMOTEIO;
487 } 512 }
488 513
@@ -494,15 +519,14 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
494{ 519{
495 struct i2c_msg *pmsg; 520 struct i2c_msg *pmsg;
496 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 521 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
497 522 int i, ret;
498 int i,ret;
499 unsigned short nak_ok; 523 unsigned short nak_ok;
500 524
501 bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); 525 bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
502 i2c_start(adap); 526 i2c_start(adap);
503 for (i=0;i<num;i++) { 527 for (i = 0; i < num; i++) {
504 pmsg = &msgs[i]; 528 pmsg = &msgs[i];
505 nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; 529 nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
506 if (!(pmsg->flags & I2C_M_NOSTART)) { 530 if (!(pmsg->flags & I2C_M_NOSTART)) {
507 if (i) { 531 if (i) {
508 bit_dbg(3, &i2c_adap->dev, "emitting " 532 bit_dbg(3, &i2c_adap->dev, "emitting "
@@ -517,7 +541,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
517 goto bailout; 541 goto bailout;
518 } 542 }
519 } 543 }
520 if (pmsg->flags & I2C_M_RD ) { 544 if (pmsg->flags & I2C_M_RD) {
521 /* read bytes into buffer*/ 545 /* read bytes into buffer*/
522 ret = readbytes(i2c_adap, pmsg); 546 ret = readbytes(i2c_adap, pmsg);
523 if (ret >= 1) 547 if (ret >= 1)
@@ -551,7 +575,7 @@ bailout:
551 575
552static u32 bit_func(struct i2c_adapter *adap) 576static u32 bit_func(struct i2c_adapter *adap)
553{ 577{
554 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 578 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
555 I2C_FUNC_SMBUS_READ_BLOCK_DATA | 579 I2C_FUNC_SMBUS_READ_BLOCK_DATA |
556 I2C_FUNC_SMBUS_BLOCK_PROC_CALL | 580 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
557 I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; 581 I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
@@ -565,8 +589,8 @@ static const struct i2c_algorithm i2c_bit_algo = {
565 .functionality = bit_func, 589 .functionality = bit_func,
566}; 590};
567 591
568/* 592/*
569 * registering functions to load algorithms at runtime 593 * registering functions to load algorithms at runtime
570 */ 594 */
571static int i2c_bit_prepare_bus(struct i2c_adapter *adap) 595static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
572{ 596{
@@ -574,7 +598,7 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
574 598
575 if (bit_test) { 599 if (bit_test) {
576 int ret = test_bus(bit_adap, adap->name); 600 int ret = test_bus(bit_adap, adap->name);
577 if (ret<0) 601 if (ret < 0)
578 return -ENODEV; 602 return -ENODEV;
579 } 603 }
580 604
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index ab2e6f3498b4..8907b0191677 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -203,35 +203,6 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
203/* ----- Utility functions 203/* ----- Utility functions
204 */ 204 */
205 205
206static inline int try_address(struct i2c_algo_pcf_data *adap,
207 unsigned char addr, int retries)
208{
209 int i, status, ret = -1;
210 int wfp;
211 for (i=0;i<retries;i++) {
212 i2c_outb(adap, addr);
213 i2c_start(adap);
214 status = get_pcf(adap, 1);
215 if ((wfp = wait_for_pin(adap, &status)) >= 0) {
216 if ((status & I2C_PCF_LRB) == 0) {
217 i2c_stop(adap);
218 break; /* success! */
219 }
220 }
221 if (wfp == -EINTR) {
222 /* arbitration lost */
223 udelay(adap->udelay);
224 return -EINTR;
225 }
226 i2c_stop(adap);
227 udelay(adap->udelay);
228 }
229 DEB2(if (i) printk(KERN_DEBUG "i2c-algo-pcf.o: needed %d retries for %d\n",i,
230 addr));
231 return ret;
232}
233
234
235static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf, 206static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf,
236 int count, int last) 207 int count, int last)
237{ 208{
@@ -321,47 +292,19 @@ static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
321} 292}
322 293
323 294
324static inline int pcf_doAddress(struct i2c_algo_pcf_data *adap, 295static int pcf_doAddress(struct i2c_algo_pcf_data *adap,
325 struct i2c_msg *msg, int retries) 296 struct i2c_msg *msg)
326{ 297{
327 unsigned short flags = msg->flags; 298 unsigned short flags = msg->flags;
328 unsigned char addr; 299 unsigned char addr;
329 int ret; 300
330 if ( (flags & I2C_M_TEN) ) { 301 addr = msg->addr << 1;
331 /* a ten bit address */ 302 if (flags & I2C_M_RD)
332 addr = 0xf0 | (( msg->addr >> 7) & 0x03); 303 addr |= 1;
333 DEB2(printk(KERN_DEBUG "addr0: %d\n",addr)); 304 if (flags & I2C_M_REV_DIR_ADDR)
334 /* try extended address code...*/ 305 addr ^= 1;
335 ret = try_address(adap, addr, retries); 306 i2c_outb(adap, addr);
336 if (ret!=1) { 307
337 printk(KERN_ERR "died at extended address code.\n");
338 return -EREMOTEIO;
339 }
340 /* the remaining 8 bit address */
341 i2c_outb(adap,msg->addr & 0x7f);
342/* Status check comes here */
343 if (ret != 1) {
344 printk(KERN_ERR "died at 2nd address code.\n");
345 return -EREMOTEIO;
346 }
347 if ( flags & I2C_M_RD ) {
348 i2c_repstart(adap);
349 /* okay, now switch into reading mode */
350 addr |= 0x01;
351 ret = try_address(adap, addr, retries);
352 if (ret!=1) {
353 printk(KERN_ERR "died at extended address code.\n");
354 return -EREMOTEIO;
355 }
356 }
357 } else { /* normal 7bit address */
358 addr = ( msg->addr << 1 );
359 if (flags & I2C_M_RD )
360 addr |= 1;
361 if (flags & I2C_M_REV_DIR_ADDR )
362 addr ^= 1;
363 i2c_outb(adap, addr);
364 }
365 return 0; 308 return 0;
366} 309}
367 310
@@ -390,7 +333,7 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
390 pmsg->flags & I2C_M_RD ? "read" : "write", 333 pmsg->flags & I2C_M_RD ? "read" : "write",
391 pmsg->len, pmsg->addr, i + 1, num);) 334 pmsg->len, pmsg->addr, i + 1, num);)
392 335
393 ret = pcf_doAddress(adap, pmsg, i2c_adap->retries); 336 ret = pcf_doAddress(adap, pmsg);
394 337
395 /* Send START */ 338 /* Send START */
396 if (i == 0) { 339 if (i == 0) {
@@ -453,7 +396,7 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
453static u32 pcf_func(struct i2c_adapter *adap) 396static u32 pcf_func(struct i2c_adapter *adap)
454{ 397{
455 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 398 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
456 I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; 399 I2C_FUNC_PROTOCOL_MANGLING;
457} 400}
458 401
459/* -----exported algorithm data: ------------------------------------- */ 402/* -----exported algorithm data: ------------------------------------- */
@@ -475,9 +418,7 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap)
475 418
476 /* register new adapter to i2c module... */ 419 /* register new adapter to i2c module... */
477 adap->algo = &pcf_algo; 420 adap->algo = &pcf_algo;
478 421 adap->timeout = 100;
479 adap->timeout = 100; /* default values, should */
480 adap->retries = 3; /* be replaced by defines */
481 422
482 if ((rval = pcf_init_8584(pcf_adap))) 423 if ((rval = pcf_init_8584(pcf_adap)))
483 return rval; 424 return rval;
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index c466c6cfc2e5..8d12b26bb6c6 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -182,7 +182,8 @@ config I2C_I801
182 will be called i2c-i801. 182 will be called i2c-i801.
183 183
184config I2C_I810 184config I2C_I810
185 tristate "Intel 810/815" 185 tristate "Intel 810/815 (DEPRECATED)"
186 default n
186 depends on PCI 187 depends on PCI
187 select I2C_ALGOBIT 188 select I2C_ALGOBIT
188 help 189 help
@@ -195,6 +196,8 @@ config I2C_I810
195 i815 196 i815
196 i845G 197 i845G
197 198
199 This driver is deprecated in favor of the i810fb and intelfb drivers.
200
198 This driver can also be built as a module. If so, the module 201 This driver can also be built as a module. If so, the module
199 will be called i2c-i810. 202 will be called i2c-i810.
200 203
@@ -259,20 +262,6 @@ config I2C_IOP3XX
259 This driver can also be built as a module. If so, the module 262 This driver can also be built as a module. If so, the module
260 will be called i2c-iop3xx. 263 will be called i2c-iop3xx.
261 264
262config I2C_IXP4XX
263 tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)"
264 depends on ARCH_IXP4XX
265 select I2C_ALGOBIT
266 help
267 Say Y here if you have an Intel IXP4xx(420,421,422,425) based
268 system and are using GPIO lines for an I2C bus.
269
270 This support is also available as a module. If so, the module
271 will be called i2c-ixp4xx.
272
273 This driver is deprecated and will be dropped soon. Use i2c-gpio
274 instead.
275
276config I2C_IXP2000 265config I2C_IXP2000
277 tristate "IXP2000 GPIO-Based I2C Interface (DEPRECATED)" 266 tristate "IXP2000 GPIO-Based I2C Interface (DEPRECATED)"
278 depends on ARCH_IXP2000 267 depends on ARCH_IXP2000
@@ -396,7 +385,8 @@ config I2C_PASEMI
396 Supports the PA Semi PWRficient on-chip SMBus interfaces. 385 Supports the PA Semi PWRficient on-chip SMBus interfaces.
397 386
398config I2C_PROSAVAGE 387config I2C_PROSAVAGE
399 tristate "S3/VIA (Pro)Savage" 388 tristate "S3/VIA (Pro)Savage (DEPRECATED)"
389 default n
400 depends on PCI 390 depends on PCI
401 select I2C_ALGOBIT 391 select I2C_ALGOBIT
402 help 392 help
@@ -407,6 +397,8 @@ config I2C_PROSAVAGE
407 S3/VIA KM266/VT8375 aka ProSavage8 397 S3/VIA KM266/VT8375 aka ProSavage8
408 S3/VIA KM133/VT8365 aka Savage4 398 S3/VIA KM133/VT8365 aka Savage4
409 399
400 This driver is deprecated in favor of the savagefb driver.
401
410 This support is also available as a module. If so, the module 402 This support is also available as a module. If so, the module
411 will be called i2c-prosavage. 403 will be called i2c-prosavage.
412 404
@@ -418,13 +410,16 @@ config I2C_S3C2410
418 Samsung S3C2410 based System-on-Chip devices. 410 Samsung S3C2410 based System-on-Chip devices.
419 411
420config I2C_SAVAGE4 412config I2C_SAVAGE4
421 tristate "S3 Savage 4" 413 tristate "S3 Savage 4 (DEPRECATED)"
422 depends on PCI && EXPERIMENTAL 414 default n
415 depends on PCI
423 select I2C_ALGOBIT 416 select I2C_ALGOBIT
424 help 417 help
425 If you say yes to this option, support will be included for the 418 If you say yes to this option, support will be included for the
426 S3 Savage 4 I2C interface. 419 S3 Savage 4 I2C interface.
427 420
421 This driver is deprecated in favor of the savagefb driver.
422
428 This driver can also be built as a module. If so, the module 423 This driver can also be built as a module. If so, the module
429 will be called i2c-savage4. 424 will be called i2c-savage4.
430 425
@@ -611,7 +606,7 @@ config I2C_VIAPRO
611 VT8231 606 VT8231
612 VT8233/A 607 VT8233/A
613 VT8235 608 VT8235
614 VT8237R/A 609 VT8237R/A/S
615 VT8251 610 VT8251
616 CX700 611 CX700
617 612
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 81d43c27cf93..ea7068f1eb6b 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -20,7 +20,6 @@ obj-$(CONFIG_I2C_I810) += i2c-i810.o
20obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 20obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
21obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 21obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o
22obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o 22obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o
23obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o
24obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o 23obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
25obj-$(CONFIG_I2C_MPC) += i2c-mpc.o 24obj-$(CONFIG_I2C_MPC) += i2c-mpc.o
26obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 25obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 7490dc1771ae..573abe440842 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -334,6 +334,10 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
334 int error; 334 int error;
335 u8 temp; 335 u8 temp;
336 336
337 /* driver_data might come from user-space, so check it */
338 if (id->driver_data > ARRAY_SIZE(chipname))
339 return -EINVAL;
340
337 if (amd756_ioport) { 341 if (amd756_ioport) {
338 dev_err(&pdev->dev, "Only one device supported " 342 dev_err(&pdev->dev, "Only one device supported "
339 "(you have a strange motherboard, btw)\n"); 343 "(you have a strange motherboard, btw)\n");
@@ -405,6 +409,7 @@ static struct pci_driver amd756_driver = {
405 .id_table = amd756_ids, 409 .id_table = amd756_ids,
406 .probe = amd756_probe, 410 .probe = amd756_probe,
407 .remove = __devexit_p(amd756_remove), 411 .remove = __devexit_p(amd756_remove),
412 .dynids.use_driver_data = 1,
408}; 413};
409 414
410static int __init amd756_init(void) 415static int __init amd756_init(void)
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index 2f684166c43d..1953b26da56a 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -30,14 +30,22 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/platform_device.h>
33#include <linux/init.h> 34#include <linux/init.h>
34#include <linux/errno.h> 35#include <linux/errno.h>
35#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/slab.h>
36 38
37#include <asm/mach-au1x00/au1xxx.h> 39#include <asm/mach-au1x00/au1xxx.h>
38#include <asm/mach-au1x00/au1xxx_psc.h> 40#include <asm/mach-au1x00/au1xxx_psc.h>
39 41
40#include "i2c-au1550.h" 42struct i2c_au1550_data {
43 u32 psc_base;
44 int xfer_timeout;
45 int ack_timeout;
46 struct i2c_adapter adap;
47 struct resource *ioarea;
48};
41 49
42static int 50static int
43wait_xfer_done(struct i2c_au1550_data *adap) 51wait_xfer_done(struct i2c_au1550_data *adap)
@@ -105,7 +113,7 @@ wait_master_done(struct i2c_au1550_data *adap)
105} 113}
106 114
107static int 115static int
108do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd) 116do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q)
109{ 117{
110 volatile psc_smb_t *sp; 118 volatile psc_smb_t *sp;
111 u32 stat; 119 u32 stat;
@@ -134,6 +142,10 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd)
134 if (rd) 142 if (rd)
135 addr |= 1; 143 addr |= 1;
136 144
145 /* zero-byte xfers stop immediately */
146 if (q)
147 addr |= PSC_SMBTXRX_STP;
148
137 /* Put byte into fifo, start up master. 149 /* Put byte into fifo, start up master.
138 */ 150 */
139 sp->psc_smbtxrx = addr; 151 sp->psc_smbtxrx = addr;
@@ -142,7 +154,7 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd)
142 au_sync(); 154 au_sync();
143 if (wait_ack(adap)) 155 if (wait_ack(adap))
144 return -EIO; 156 return -EIO;
145 return 0; 157 return (q) ? wait_master_done(adap) : 0;
146} 158}
147 159
148static u32 160static u32
@@ -262,7 +274,8 @@ au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
262 274
263 for (i = 0; !err && i < num; i++) { 275 for (i = 0; !err && i < num; i++) {
264 p = &msgs[i]; 276 p = &msgs[i];
265 err = do_address(adap, p->addr, p->flags & I2C_M_RD); 277 err = do_address(adap, p->addr, p->flags & I2C_M_RD,
278 (p->len == 0));
266 if (err || !p->len) 279 if (err || !p->len)
267 continue; 280 continue;
268 if (p->flags & I2C_M_RD) 281 if (p->flags & I2C_M_RD)
@@ -294,18 +307,48 @@ static const struct i2c_algorithm au1550_algo = {
294 * Prior to calling us, the 50MHz clock frequency and routing 307 * Prior to calling us, the 50MHz clock frequency and routing
295 * must have been set up for the PSC indicated by the adapter. 308 * must have been set up for the PSC indicated by the adapter.
296 */ 309 */
297int 310static int __devinit
298i2c_au1550_add_bus(struct i2c_adapter *i2c_adap) 311i2c_au1550_probe(struct platform_device *pdev)
299{ 312{
300 struct i2c_au1550_data *adap = i2c_adap->algo_data; 313 struct i2c_au1550_data *priv;
301 volatile psc_smb_t *sp; 314 volatile psc_smb_t *sp;
302 u32 stat; 315 struct resource *r;
316 u32 stat;
317 int ret;
318
319 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
320 if (!r) {
321 ret = -ENODEV;
322 goto out;
323 }
324
325 priv = kzalloc(sizeof(struct i2c_au1550_data), GFP_KERNEL);
326 if (!priv) {
327 ret = -ENOMEM;
328 goto out;
329 }
330
331 priv->ioarea = request_mem_region(r->start, r->end - r->start + 1,
332 pdev->name);
333 if (!priv->ioarea) {
334 ret = -EBUSY;
335 goto out_mem;
336 }
303 337
304 i2c_adap->algo = &au1550_algo; 338 priv->psc_base = r->start;
339 priv->xfer_timeout = 200;
340 priv->ack_timeout = 200;
341
342 priv->adap.id = I2C_HW_AU1550_PSC;
343 priv->adap.nr = pdev->id;
344 priv->adap.algo = &au1550_algo;
345 priv->adap.algo_data = priv;
346 priv->adap.dev.parent = &pdev->dev;
347 strlcpy(priv->adap.name, "Au1xxx PSC I2C", sizeof(priv->adap.name));
305 348
306 /* Now, set up the PSC for SMBus PIO mode. 349 /* Now, set up the PSC for SMBus PIO mode.
307 */ 350 */
308 sp = (volatile psc_smb_t *)(adap->psc_base); 351 sp = (volatile psc_smb_t *)priv->psc_base;
309 sp->psc_ctrl = PSC_CTRL_DISABLE; 352 sp->psc_ctrl = PSC_CTRL_DISABLE;
310 au_sync(); 353 au_sync();
311 sp->psc_sel = PSC_SEL_PS_SMBUSMODE; 354 sp->psc_sel = PSC_SEL_PS_SMBUSMODE;
@@ -343,87 +386,87 @@ i2c_au1550_add_bus(struct i2c_adapter *i2c_adap)
343 au_sync(); 386 au_sync();
344 } while ((stat & PSC_SMBSTAT_DR) == 0); 387 } while ((stat & PSC_SMBSTAT_DR) == 0);
345 388
346 return i2c_add_adapter(i2c_adap); 389 ret = i2c_add_numbered_adapter(&priv->adap);
347} 390 if (ret == 0) {
391 platform_set_drvdata(pdev, priv);
392 return 0;
393 }
348 394
395 /* disable the PSC */
396 sp->psc_smbcfg = 0;
397 sp->psc_ctrl = PSC_CTRL_DISABLE;
398 au_sync();
349 399
350int 400 release_resource(priv->ioarea);
351i2c_au1550_del_bus(struct i2c_adapter *adap) 401 kfree(priv->ioarea);
402out_mem:
403 kfree(priv);
404out:
405 return ret;
406}
407
408static int __devexit
409i2c_au1550_remove(struct platform_device *pdev)
352{ 410{
353 return i2c_del_adapter(adap); 411 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
412 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
413
414 platform_set_drvdata(pdev, NULL);
415 i2c_del_adapter(&priv->adap);
416 sp->psc_smbcfg = 0;
417 sp->psc_ctrl = PSC_CTRL_DISABLE;
418 au_sync();
419 release_resource(priv->ioarea);
420 kfree(priv->ioarea);
421 kfree(priv);
422 return 0;
354} 423}
355 424
356static int 425static int
357pb1550_reg(struct i2c_client *client) 426i2c_au1550_suspend(struct platform_device *pdev, pm_message_t state)
358{ 427{
428 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
429 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
430
431 sp->psc_ctrl = PSC_CTRL_SUSPEND;
432 au_sync();
359 return 0; 433 return 0;
360} 434}
361 435
362static int 436static int
363pb1550_unreg(struct i2c_client *client) 437i2c_au1550_resume(struct platform_device *pdev)
364{ 438{
439 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
440 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
441
442 sp->psc_ctrl = PSC_CTRL_ENABLE;
443 au_sync();
444 while (!(sp->psc_smbstat & PSC_SMBSTAT_SR))
445 au_sync();
365 return 0; 446 return 0;
366} 447}
367 448
368static struct i2c_au1550_data pb1550_i2c_info = { 449static struct platform_driver au1xpsc_smbus_driver = {
369 SMBUS_PSC_BASE, 200, 200 450 .driver = {
370}; 451 .name = "au1xpsc_smbus",
371 452 .owner = THIS_MODULE,
372static struct i2c_adapter pb1550_board_adapter = { 453 },
373 name: "pb1550 adapter", 454 .probe = i2c_au1550_probe,
374 id: I2C_HW_AU1550_PSC, 455 .remove = __devexit_p(i2c_au1550_remove),
375 algo: NULL, 456 .suspend = i2c_au1550_suspend,
376 algo_data: &pb1550_i2c_info, 457 .resume = i2c_au1550_resume,
377 client_register: pb1550_reg,
378 client_unregister: pb1550_unreg,
379}; 458};
380 459
381/* BIG hack to support the control interface on the Wolfson WM8731
382 * audio codec on the Pb1550 board. We get an address and two data
383 * bytes to write, create an i2c message, and send it across the
384 * i2c transfer function. We do this here because we have access to
385 * the i2c adapter structure.
386 */
387static struct i2c_msg wm_i2c_msg; /* We don't want this stuff on the stack */
388static u8 i2cbuf[2];
389
390int
391pb1550_wm_codec_write(u8 addr, u8 reg, u8 val)
392{
393 wm_i2c_msg.addr = addr;
394 wm_i2c_msg.flags = 0;
395 wm_i2c_msg.buf = i2cbuf;
396 wm_i2c_msg.len = 2;
397 i2cbuf[0] = reg;
398 i2cbuf[1] = val;
399
400 return pb1550_board_adapter.algo->master_xfer(&pb1550_board_adapter, &wm_i2c_msg, 1);
401}
402
403static int __init 460static int __init
404i2c_au1550_init(void) 461i2c_au1550_init(void)
405{ 462{
406 printk(KERN_INFO "Au1550 I2C: "); 463 return platform_driver_register(&au1xpsc_smbus_driver);
407
408 /* This is where we would set up a 50MHz clock source
409 * and routing. On the Pb1550, the SMBus is PSC2, which
410 * uses a shared clock with USB. This has been already
411 * configured by Yamon as a 48MHz clock, close enough
412 * for our work.
413 */
414 if (i2c_au1550_add_bus(&pb1550_board_adapter) < 0) {
415 printk("failed to initialize.\n");
416 return -ENODEV;
417 }
418
419 printk("initialized.\n");
420 return 0;
421} 464}
422 465
423static void __exit 466static void __exit
424i2c_au1550_exit(void) 467i2c_au1550_exit(void)
425{ 468{
426 i2c_au1550_del_bus(&pb1550_board_adapter); 469 platform_driver_unregister(&au1xpsc_smbus_driver);
427} 470}
428 471
429MODULE_AUTHOR("Dan Malek, Embedded Edge, LLC."); 472MODULE_AUTHOR("Dan Malek, Embedded Edge, LLC.");
diff --git a/drivers/i2c/busses/i2c-au1550.h b/drivers/i2c/busses/i2c-au1550.h
deleted file mode 100644
index fce15d161ae7..000000000000
--- a/drivers/i2c/busses/i2c-au1550.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/*
2 * Copyright (C) 2004 Embedded Edge, LLC <dan@embeddededge.com>
3 * 2.6 port by Matt Porter <mporter@kernel.crashing.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#ifndef I2C_AU1550_H
21#define I2C_AU1550_H
22
23struct i2c_au1550_data {
24 u32 psc_base;
25 int xfer_timeout;
26 int ack_timeout;
27};
28
29int i2c_au1550_add_bus(struct i2c_adapter *);
30int i2c_au1550_del_bus(struct i2c_adapter *);
31
32#endif /* I2C_AU1550_H */
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 67224a424aba..7dbdaeb707a9 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -550,6 +550,7 @@ static int i2c_bfin_twi_probe(struct platform_device *dev)
550 550
551 p_adap = &iface->adap; 551 p_adap = &iface->adap;
552 p_adap->id = I2C_HW_BLACKFIN; 552 p_adap->id = I2C_HW_BLACKFIN;
553 p_adap->nr = dev->id;
553 strlcpy(p_adap->name, dev->name, sizeof(p_adap->name)); 554 strlcpy(p_adap->name, dev->name, sizeof(p_adap->name));
554 p_adap->algo = &bfin_twi_algorithm; 555 p_adap->algo = &bfin_twi_algorithm;
555 p_adap->algo_data = iface; 556 p_adap->algo_data = iface;
@@ -576,7 +577,7 @@ static int i2c_bfin_twi_probe(struct platform_device *dev)
576 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA); 577 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA);
577 SSYNC(); 578 SSYNC();
578 579
579 rc = i2c_add_adapter(p_adap); 580 rc = i2c_add_numbered_adapter(p_adap);
580 if (rc < 0) 581 if (rc < 0)
581 free_irq(iface->irq, iface); 582 free_irq(iface->irq, iface);
582 else 583 else
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 67679882ebef..cce5a614758d 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -510,7 +510,6 @@ static int davinci_i2c_probe(struct platform_device *pdev)
510 510
511 /* FIXME */ 511 /* FIXME */
512 adap->timeout = 1; 512 adap->timeout = 1;
513 adap->retries = 1;
514 513
515 adap->nr = pdev->id; 514 adap->nr = pdev->id;
516 r = i2c_add_numbered_adapter(adap); 515 r = i2c_add_numbered_adapter(adap);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index ac27e5f84ebe..aa9157913b9a 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -4,6 +4,7 @@
4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker 5 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
6 <mdsxyz123@yahoo.com> 6 <mdsxyz123@yahoo.com>
7 Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
7 8
8 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
@@ -21,25 +22,34 @@
21*/ 22*/
22 23
23/* 24/*
24 SUPPORTED DEVICES PCI ID 25 Supports the following Intel I/O Controller Hubs (ICH):
25 82801AA 2413 26
26 82801AB 2423 27 I/O Block I2C
27 82801BA 2443 28 region SMBus Block proc. block
28 82801CA/CAM 2483 29 Chip name PCI ID size PEC buffer call read
29 82801DB 24C3 (HW PEC supported) 30 ----------------------------------------------------------------------
30 82801EB 24D3 (HW PEC supported) 31 82801AA (ICH) 0x2413 16 no no no no
31 6300ESB 25A4 32 82801AB (ICH0) 0x2423 16 no no no no
32 ICH6 266A 33 82801BA (ICH2) 0x2443 16 no no no no
33 ICH7 27DA 34 82801CA (ICH3) 0x2483 32 soft no no no
34 ESB2 269B 35 82801DB (ICH4) 0x24c3 32 hard yes no no
35 ICH8 283E 36 82801E (ICH5) 0x24d3 32 hard yes yes yes
36 ICH9 2930 37 6300ESB 0x25a4 32 hard yes yes yes
37 Tolapai 5032 38 82801F (ICH6) 0x266a 32 hard yes yes yes
38 This driver supports several versions of Intel's I/O Controller Hubs (ICH). 39 6310ESB/6320ESB 0x269b 32 hard yes yes yes
39 For SMBus support, they are similar to the PIIX4 and are part 40 82801G (ICH7) 0x27da 32 hard yes yes yes
40 of Intel's '810' and other chipsets. 41 82801H (ICH8) 0x283e 32 hard yes yes yes
41 See the file Documentation/i2c/busses/i2c-i801 for details. 42 82801I (ICH9) 0x2930 32 hard yes yes yes
42 I2C Block Read and Process Call are not supported. 43 Tolapai 0x5032 32 hard yes ? ?
44
45 Features supported by this driver:
46 Software PEC no
47 Hardware PEC yes
48 Block buffer yes
49 Block process call transaction no
50 I2C block read transaction yes (doesn't use the block buffer)
51
52 See the file Documentation/i2c/busses/i2c-i801 for details.
43*/ 53*/
44 54
45/* Note: we assume there can only be one I801, with one SMBus interface */ 55/* Note: we assume there can only be one I801, with one SMBus interface */
@@ -62,9 +72,9 @@
62#define SMBHSTDAT0 (5 + i801_smba) 72#define SMBHSTDAT0 (5 + i801_smba)
63#define SMBHSTDAT1 (6 + i801_smba) 73#define SMBHSTDAT1 (6 + i801_smba)
64#define SMBBLKDAT (7 + i801_smba) 74#define SMBBLKDAT (7 + i801_smba)
65#define SMBPEC (8 + i801_smba) /* ICH4 only */ 75#define SMBPEC (8 + i801_smba) /* ICH3 and later */
66#define SMBAUXSTS (12 + i801_smba) /* ICH4 only */ 76#define SMBAUXSTS (12 + i801_smba) /* ICH4 and later */
67#define SMBAUXCTL (13 + i801_smba) /* ICH4 only */ 77#define SMBAUXCTL (13 + i801_smba) /* ICH4 and later */
68 78
69/* PCI Address Constants */ 79/* PCI Address Constants */
70#define SMBBAR 4 80#define SMBBAR 4
@@ -91,13 +101,13 @@
91#define I801_BYTE 0x04 101#define I801_BYTE 0x04
92#define I801_BYTE_DATA 0x08 102#define I801_BYTE_DATA 0x08
93#define I801_WORD_DATA 0x0C 103#define I801_WORD_DATA 0x0C
94#define I801_PROC_CALL 0x10 /* later chips only, unimplemented */ 104#define I801_PROC_CALL 0x10 /* unimplemented */
95#define I801_BLOCK_DATA 0x14 105#define I801_BLOCK_DATA 0x14
96#define I801_I2C_BLOCK_DATA 0x18 /* unimplemented */ 106#define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
97#define I801_BLOCK_LAST 0x34 107#define I801_BLOCK_LAST 0x34
98#define I801_I2C_BLOCK_LAST 0x38 /* unimplemented */ 108#define I801_I2C_BLOCK_LAST 0x38 /* ICH5 and later */
99#define I801_START 0x40 109#define I801_START 0x40
100#define I801_PEC_EN 0x80 /* ICH4 only */ 110#define I801_PEC_EN 0x80 /* ICH3 and later */
101 111
102/* I801 Hosts Status register bits */ 112/* I801 Hosts Status register bits */
103#define SMBHSTSTS_BYTE_DONE 0x80 113#define SMBHSTSTS_BYTE_DONE 0x80
@@ -113,7 +123,12 @@ static unsigned long i801_smba;
113static unsigned char i801_original_hstcfg; 123static unsigned char i801_original_hstcfg;
114static struct pci_driver i801_driver; 124static struct pci_driver i801_driver;
115static struct pci_dev *I801_dev; 125static struct pci_dev *I801_dev;
116static int isich4; 126
127#define FEATURE_SMBUS_PEC (1 << 0)
128#define FEATURE_BLOCK_BUFFER (1 << 1)
129#define FEATURE_BLOCK_PROC (1 << 2)
130#define FEATURE_I2C_BLOCK_READ (1 << 3)
131static unsigned int i801_features;
117 132
118static int i801_transaction(int xact) 133static int i801_transaction(int xact)
119{ 134{
@@ -242,7 +257,8 @@ static int i801_block_transaction_by_block(union i2c_smbus_data *data,
242} 257}
243 258
244static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, 259static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
245 char read_write, int hwpec) 260 char read_write, int command,
261 int hwpec)
246{ 262{
247 int i, len; 263 int i, len;
248 int smbcmd; 264 int smbcmd;
@@ -259,16 +275,24 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
259 } 275 }
260 276
261 for (i = 1; i <= len; i++) { 277 for (i = 1; i <= len; i++) {
262 if (i == len && read_write == I2C_SMBUS_READ) 278 if (i == len && read_write == I2C_SMBUS_READ) {
263 smbcmd = I801_BLOCK_LAST; 279 if (command == I2C_SMBUS_I2C_BLOCK_DATA)
264 else 280 smbcmd = I801_I2C_BLOCK_LAST;
265 smbcmd = I801_BLOCK_DATA; 281 else
282 smbcmd = I801_BLOCK_LAST;
283 } else {
284 if (command == I2C_SMBUS_I2C_BLOCK_DATA
285 && read_write == I2C_SMBUS_READ)
286 smbcmd = I801_I2C_BLOCK_DATA;
287 else
288 smbcmd = I801_BLOCK_DATA;
289 }
266 outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT); 290 outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT);
267 291
268 dev_dbg(&I801_dev->dev, "Block (pre %d): CNT=%02x, CMD=%02x, " 292 dev_dbg(&I801_dev->dev, "Block (pre %d): CNT=%02x, CMD=%02x, "
269 "ADD=%02x, DAT0=%02x, BLKDAT=%02x\n", i, 293 "ADD=%02x, DAT0=%02x, DAT1=%02x, BLKDAT=%02x\n", i,
270 inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD), 294 inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD),
271 inb_p(SMBHSTDAT0), inb_p(SMBBLKDAT)); 295 inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1), inb_p(SMBBLKDAT));
272 296
273 /* Make sure the SMBus host is ready to start transmitting */ 297 /* Make sure the SMBus host is ready to start transmitting */
274 temp = inb_p(SMBHSTSTS); 298 temp = inb_p(SMBHSTSTS);
@@ -332,7 +356,8 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
332 dev_dbg(&I801_dev->dev, "Error: no response!\n"); 356 dev_dbg(&I801_dev->dev, "Error: no response!\n");
333 } 357 }
334 358
335 if (i == 1 && read_write == I2C_SMBUS_READ) { 359 if (i == 1 && read_write == I2C_SMBUS_READ
360 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
336 len = inb_p(SMBHSTDAT0); 361 len = inb_p(SMBHSTDAT0);
337 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 362 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
338 return -1; 363 return -1;
@@ -353,9 +378,9 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
353 temp); 378 temp);
354 } 379 }
355 dev_dbg(&I801_dev->dev, "Block (post %d): CNT=%02x, CMD=%02x, " 380 dev_dbg(&I801_dev->dev, "Block (post %d): CNT=%02x, CMD=%02x, "
356 "ADD=%02x, DAT0=%02x, BLKDAT=%02x\n", i, 381 "ADD=%02x, DAT0=%02x, DAT1=%02x, BLKDAT=%02x\n", i,
357 inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD), 382 inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD),
358 inb_p(SMBHSTDAT0), inb_p(SMBBLKDAT)); 383 inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1), inb_p(SMBBLKDAT));
359 384
360 if (result < 0) 385 if (result < 0)
361 return result; 386 return result;
@@ -384,33 +409,38 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
384 pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc); 409 pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc);
385 pci_write_config_byte(I801_dev, SMBHSTCFG, 410 pci_write_config_byte(I801_dev, SMBHSTCFG,
386 hostc | SMBHSTCFG_I2C_EN); 411 hostc | SMBHSTCFG_I2C_EN);
387 } else { 412 } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) {
388 dev_err(&I801_dev->dev, 413 dev_err(&I801_dev->dev,
389 "I2C_SMBUS_I2C_BLOCK_READ not DB!\n"); 414 "I2C block read is unsupported!\n");
390 return -1; 415 return -1;
391 } 416 }
392 } 417 }
393 418
394 if (read_write == I2C_SMBUS_WRITE) { 419 if (read_write == I2C_SMBUS_WRITE
420 || command == I2C_SMBUS_I2C_BLOCK_DATA) {
395 if (data->block[0] < 1) 421 if (data->block[0] < 1)
396 data->block[0] = 1; 422 data->block[0] = 1;
397 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) 423 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
398 data->block[0] = I2C_SMBUS_BLOCK_MAX; 424 data->block[0] = I2C_SMBUS_BLOCK_MAX;
399 } else { 425 } else {
400 data->block[0] = 32; /* max for reads */ 426 data->block[0] = 32; /* max for SMBus block reads */
401 } 427 }
402 428
403 if (isich4 && i801_set_block_buffer_mode() == 0 ) 429 if ((i801_features & FEATURE_BLOCK_BUFFER)
430 && !(command == I2C_SMBUS_I2C_BLOCK_DATA
431 && read_write == I2C_SMBUS_READ)
432 && i801_set_block_buffer_mode() == 0)
404 result = i801_block_transaction_by_block(data, read_write, 433 result = i801_block_transaction_by_block(data, read_write,
405 hwpec); 434 hwpec);
406 else 435 else
407 result = i801_block_transaction_byte_by_byte(data, read_write, 436 result = i801_block_transaction_byte_by_byte(data, read_write,
408 hwpec); 437 command, hwpec);
409 438
410 if (result == 0 && hwpec) 439 if (result == 0 && hwpec)
411 i801_wait_hwpec(); 440 i801_wait_hwpec();
412 441
413 if (command == I2C_SMBUS_I2C_BLOCK_DATA) { 442 if (command == I2C_SMBUS_I2C_BLOCK_DATA
443 && read_write == I2C_SMBUS_WRITE) {
414 /* restore saved configuration register value */ 444 /* restore saved configuration register value */
415 pci_write_config_byte(I801_dev, SMBHSTCFG, hostc); 445 pci_write_config_byte(I801_dev, SMBHSTCFG, hostc);
416 } 446 }
@@ -426,7 +456,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
426 int block = 0; 456 int block = 0;
427 int ret, xact = 0; 457 int ret, xact = 0;
428 458
429 hwpec = isich4 && (flags & I2C_CLIENT_PEC) 459 hwpec = (i801_features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
430 && size != I2C_SMBUS_QUICK 460 && size != I2C_SMBUS_QUICK
431 && size != I2C_SMBUS_I2C_BLOCK_DATA; 461 && size != I2C_SMBUS_I2C_BLOCK_DATA;
432 462
@@ -462,12 +492,23 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
462 xact = I801_WORD_DATA; 492 xact = I801_WORD_DATA;
463 break; 493 break;
464 case I2C_SMBUS_BLOCK_DATA: 494 case I2C_SMBUS_BLOCK_DATA:
465 case I2C_SMBUS_I2C_BLOCK_DATA:
466 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 495 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
467 SMBHSTADD); 496 SMBHSTADD);
468 outb_p(command, SMBHSTCMD); 497 outb_p(command, SMBHSTCMD);
469 block = 1; 498 block = 1;
470 break; 499 break;
500 case I2C_SMBUS_I2C_BLOCK_DATA:
501 /* NB: page 240 of ICH5 datasheet shows that the R/#W
502 * bit should be cleared here, even when reading */
503 outb_p((addr & 0x7f) << 1, SMBHSTADD);
504 if (read_write == I2C_SMBUS_READ) {
505 /* NB: page 240 of ICH5 datasheet also shows
506 * that DATA1 is the cmd field when reading */
507 outb_p(command, SMBHSTDAT1);
508 } else
509 outb_p(command, SMBHSTCMD);
510 block = 1;
511 break;
471 case I2C_SMBUS_PROC_CALL: 512 case I2C_SMBUS_PROC_CALL:
472 default: 513 default:
473 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); 514 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size);
@@ -487,7 +528,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
487 /* Some BIOSes don't like it when PEC is enabled at reboot or resume 528 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
488 time, so we forcibly disable it after every transaction. Turn off 529 time, so we forcibly disable it after every transaction. Turn off
489 E32B for the same reason. */ 530 E32B for the same reason. */
490 if (hwpec) 531 if (hwpec || block)
491 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), 532 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B),
492 SMBAUXCTL); 533 SMBAUXCTL);
493 534
@@ -514,9 +555,11 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
514static u32 i801_func(struct i2c_adapter *adapter) 555static u32 i801_func(struct i2c_adapter *adapter)
515{ 556{
516 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 557 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
517 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 558 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
518 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 559 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
519 | (isich4 ? I2C_FUNC_SMBUS_PEC : 0); 560 ((i801_features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
561 ((i801_features & FEATURE_I2C_BLOCK_READ) ?
562 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
520} 563}
521 564
522static const struct i2c_algorithm smbus_algorithm = { 565static const struct i2c_algorithm smbus_algorithm = {
@@ -556,8 +599,8 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
556 int err; 599 int err;
557 600
558 I801_dev = dev; 601 I801_dev = dev;
602 i801_features = 0;
559 switch (dev->device) { 603 switch (dev->device) {
560 case PCI_DEVICE_ID_INTEL_82801DB_3:
561 case PCI_DEVICE_ID_INTEL_82801EB_3: 604 case PCI_DEVICE_ID_INTEL_82801EB_3:
562 case PCI_DEVICE_ID_INTEL_ESB_4: 605 case PCI_DEVICE_ID_INTEL_ESB_4:
563 case PCI_DEVICE_ID_INTEL_ICH6_16: 606 case PCI_DEVICE_ID_INTEL_ICH6_16:
@@ -565,11 +608,13 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
565 case PCI_DEVICE_ID_INTEL_ESB2_17: 608 case PCI_DEVICE_ID_INTEL_ESB2_17:
566 case PCI_DEVICE_ID_INTEL_ICH8_5: 609 case PCI_DEVICE_ID_INTEL_ICH8_5:
567 case PCI_DEVICE_ID_INTEL_ICH9_6: 610 case PCI_DEVICE_ID_INTEL_ICH9_6:
611 i801_features |= FEATURE_I2C_BLOCK_READ;
612 /* fall through */
613 case PCI_DEVICE_ID_INTEL_82801DB_3:
568 case PCI_DEVICE_ID_INTEL_TOLAPAI_1: 614 case PCI_DEVICE_ID_INTEL_TOLAPAI_1:
569 isich4 = 1; 615 i801_features |= FEATURE_SMBUS_PEC;
616 i801_features |= FEATURE_BLOCK_BUFFER;
570 break; 617 break;
571 default:
572 isich4 = 0;
573 } 618 }
574 619
575 err = pci_enable_device(dev); 620 err = pci_enable_device(dev);
@@ -610,6 +655,11 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
610 else 655 else
611 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); 656 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n");
612 657
658 /* Clear special mode bits */
659 if (i801_features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
660 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B),
661 SMBAUXCTL);
662
613 /* set up the sysfs linkage to our parent device */ 663 /* set up the sysfs linkage to our parent device */
614 i801_adapter.dev.parent = &dev->dev; 664 i801_adapter.dev.parent = &dev->dev;
615 665
@@ -678,9 +728,8 @@ static void __exit i2c_i801_exit(void)
678 pci_unregister_driver(&i801_driver); 728 pci_unregister_driver(&i801_driver);
679} 729}
680 730
681MODULE_AUTHOR ("Frodo Looijaard <frodol@dds.nl>, " 731MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, "
682 "Philip Edelbrock <phil@netroedge.com>, " 732 "Jean Delvare <khali@linux-fr.org>");
683 "and Mark D. Studebaker <mdsxyz123@yahoo.com>");
684MODULE_DESCRIPTION("I801 SMBus driver"); 733MODULE_DESCRIPTION("I801 SMBus driver");
685MODULE_LICENSE("GPL"); 734MODULE_LICENSE("GPL");
686 735
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 9b43ff7270d0..7c7eb0cfeceb 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -6,7 +6,7 @@
6 * Copyright (c) 2003, 2004 Zultys Technologies. 6 * Copyright (c) 2003, 2004 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 8 *
9 * Based on original work by 9 * Based on original work by
10 * Ian DaSilva <idasilva@mvista.com> 10 * Ian DaSilva <idasilva@mvista.com>
11 * Armin Kuster <akuster@mvista.com> 11 * Armin Kuster <akuster@mvista.com>
12 * Matt Porter <mporter@mvista.com> 12 * Matt Porter <mporter@mvista.com>
@@ -86,8 +86,8 @@ static void dump_iic_regs(const char* header, struct ibm_iic_private* dev)
86 KERN_DEBUG " sts = 0x%02x, extsts = 0x%02x\n" 86 KERN_DEBUG " sts = 0x%02x, extsts = 0x%02x\n"
87 KERN_DEBUG " clkdiv = 0x%02x, xfrcnt = 0x%02x\n" 87 KERN_DEBUG " clkdiv = 0x%02x, xfrcnt = 0x%02x\n"
88 KERN_DEBUG " xtcntlss = 0x%02x, directcntl = 0x%02x\n", 88 KERN_DEBUG " xtcntlss = 0x%02x, directcntl = 0x%02x\n",
89 in_8(&iic->cntl), in_8(&iic->mdcntl), in_8(&iic->sts), 89 in_8(&iic->cntl), in_8(&iic->mdcntl), in_8(&iic->sts),
90 in_8(&iic->extsts), in_8(&iic->clkdiv), in_8(&iic->xfrcnt), 90 in_8(&iic->extsts), in_8(&iic->clkdiv), in_8(&iic->xfrcnt),
91 in_8(&iic->xtcntlss), in_8(&iic->directcntl)); 91 in_8(&iic->xtcntlss), in_8(&iic->directcntl));
92} 92}
93# define DUMP_REGS(h,dev) dump_iic_regs((h),(dev)) 93# define DUMP_REGS(h,dev) dump_iic_regs((h),(dev))
@@ -125,7 +125,7 @@ static inline void iic_interrupt_mode(struct ibm_iic_private* dev, int enable)
125{ 125{
126 out_8(&dev->vaddr->intmsk, enable ? INTRMSK_EIMTC : 0); 126 out_8(&dev->vaddr->intmsk, enable ? INTRMSK_EIMTC : 0);
127} 127}
128 128
129/* 129/*
130 * Initialize IIC interface. 130 * Initialize IIC interface.
131 */ 131 */
@@ -134,7 +134,7 @@ static void iic_dev_init(struct ibm_iic_private* dev)
134 volatile struct iic_regs __iomem *iic = dev->vaddr; 134 volatile struct iic_regs __iomem *iic = dev->vaddr;
135 135
136 DBG("%d: init\n", dev->idx); 136 DBG("%d: init\n", dev->idx);
137 137
138 /* Clear master address */ 138 /* Clear master address */
139 out_8(&iic->lmadr, 0); 139 out_8(&iic->lmadr, 0);
140 out_8(&iic->hmadr, 0); 140 out_8(&iic->hmadr, 0);
@@ -160,7 +160,7 @@ static void iic_dev_init(struct ibm_iic_private* dev)
160 160
161 /* Clear control register */ 161 /* Clear control register */
162 out_8(&iic->cntl, 0); 162 out_8(&iic->cntl, 0);
163 163
164 /* Enable interrupts if possible */ 164 /* Enable interrupts if possible */
165 iic_interrupt_mode(dev, dev->irq >= 0); 165 iic_interrupt_mode(dev, dev->irq >= 0);
166 166
@@ -171,7 +171,7 @@ static void iic_dev_init(struct ibm_iic_private* dev)
171 DUMP_REGS("iic_init", dev); 171 DUMP_REGS("iic_init", dev);
172} 172}
173 173
174/* 174/*
175 * Reset IIC interface 175 * Reset IIC interface
176 */ 176 */
177static void iic_dev_reset(struct ibm_iic_private* dev) 177static void iic_dev_reset(struct ibm_iic_private* dev)
@@ -179,42 +179,42 @@ static void iic_dev_reset(struct ibm_iic_private* dev)
179 volatile struct iic_regs __iomem *iic = dev->vaddr; 179 volatile struct iic_regs __iomem *iic = dev->vaddr;
180 int i; 180 int i;
181 u8 dc; 181 u8 dc;
182 182
183 DBG("%d: soft reset\n", dev->idx); 183 DBG("%d: soft reset\n", dev->idx);
184 DUMP_REGS("reset", dev); 184 DUMP_REGS("reset", dev);
185 185
186 /* Place chip in the reset state */ 186 /* Place chip in the reset state */
187 out_8(&iic->xtcntlss, XTCNTLSS_SRST); 187 out_8(&iic->xtcntlss, XTCNTLSS_SRST);
188 188
189 /* Check if bus is free */ 189 /* Check if bus is free */
190 dc = in_8(&iic->directcntl); 190 dc = in_8(&iic->directcntl);
191 if (!DIRCTNL_FREE(dc)){ 191 if (!DIRCTNL_FREE(dc)){
192 DBG("%d: trying to regain bus control\n", dev->idx); 192 DBG("%d: trying to regain bus control\n", dev->idx);
193 193
194 /* Try to set bus free state */ 194 /* Try to set bus free state */
195 out_8(&iic->directcntl, DIRCNTL_SDAC | DIRCNTL_SCC); 195 out_8(&iic->directcntl, DIRCNTL_SDAC | DIRCNTL_SCC);
196 196
197 /* Wait until we regain bus control */ 197 /* Wait until we regain bus control */
198 for (i = 0; i < 100; ++i){ 198 for (i = 0; i < 100; ++i){
199 dc = in_8(&iic->directcntl); 199 dc = in_8(&iic->directcntl);
200 if (DIRCTNL_FREE(dc)) 200 if (DIRCTNL_FREE(dc))
201 break; 201 break;
202 202
203 /* Toggle SCL line */ 203 /* Toggle SCL line */
204 dc ^= DIRCNTL_SCC; 204 dc ^= DIRCNTL_SCC;
205 out_8(&iic->directcntl, dc); 205 out_8(&iic->directcntl, dc);
206 udelay(10); 206 udelay(10);
207 dc ^= DIRCNTL_SCC; 207 dc ^= DIRCNTL_SCC;
208 out_8(&iic->directcntl, dc); 208 out_8(&iic->directcntl, dc);
209 209
210 /* be nice */ 210 /* be nice */
211 cond_resched(); 211 cond_resched();
212 } 212 }
213 } 213 }
214 214
215 /* Remove reset */ 215 /* Remove reset */
216 out_8(&iic->xtcntlss, 0); 216 out_8(&iic->xtcntlss, 0);
217 217
218 /* Reinitialize interface */ 218 /* Reinitialize interface */
219 iic_dev_init(dev); 219 iic_dev_init(dev);
220} 220}
@@ -324,14 +324,14 @@ static irqreturn_t iic_handler(int irq, void *dev_id)
324{ 324{
325 struct ibm_iic_private* dev = (struct ibm_iic_private*)dev_id; 325 struct ibm_iic_private* dev = (struct ibm_iic_private*)dev_id;
326 volatile struct iic_regs __iomem *iic = dev->vaddr; 326 volatile struct iic_regs __iomem *iic = dev->vaddr;
327 327
328 DBG2("%d: irq handler, STS = 0x%02x, EXTSTS = 0x%02x\n", 328 DBG2("%d: irq handler, STS = 0x%02x, EXTSTS = 0x%02x\n",
329 dev->idx, in_8(&iic->sts), in_8(&iic->extsts)); 329 dev->idx, in_8(&iic->sts), in_8(&iic->extsts));
330 330
331 /* Acknowledge IRQ and wakeup iic_wait_for_tc */ 331 /* Acknowledge IRQ and wakeup iic_wait_for_tc */
332 out_8(&iic->sts, STS_IRQA | STS_SCMP); 332 out_8(&iic->sts, STS_IRQA | STS_SCMP);
333 wake_up_interruptible(&dev->wq); 333 wake_up_interruptible(&dev->wq);
334 334
335 return IRQ_HANDLED; 335 return IRQ_HANDLED;
336} 336}
337 337
@@ -341,19 +341,19 @@ static irqreturn_t iic_handler(int irq, void *dev_id)
341 */ 341 */
342static int iic_xfer_result(struct ibm_iic_private* dev) 342static int iic_xfer_result(struct ibm_iic_private* dev)
343{ 343{
344 volatile struct iic_regs __iomem *iic = dev->vaddr; 344 volatile struct iic_regs __iomem *iic = dev->vaddr;
345 345
346 if (unlikely(in_8(&iic->sts) & STS_ERR)){ 346 if (unlikely(in_8(&iic->sts) & STS_ERR)){
347 DBG("%d: xfer error, EXTSTS = 0x%02x\n", dev->idx, 347 DBG("%d: xfer error, EXTSTS = 0x%02x\n", dev->idx,
348 in_8(&iic->extsts)); 348 in_8(&iic->extsts));
349 349
350 /* Clear errors and possible pending IRQs */ 350 /* Clear errors and possible pending IRQs */
351 out_8(&iic->extsts, EXTSTS_IRQP | EXTSTS_IRQD | 351 out_8(&iic->extsts, EXTSTS_IRQP | EXTSTS_IRQD |
352 EXTSTS_LA | EXTSTS_ICT | EXTSTS_XFRA); 352 EXTSTS_LA | EXTSTS_ICT | EXTSTS_XFRA);
353 353
354 /* Flush master data buffer */ 354 /* Flush master data buffer */
355 out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB); 355 out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB);
356 356
357 /* Is bus free? 357 /* Is bus free?
358 * If error happened during combined xfer 358 * If error happened during combined xfer
359 * IIC interface is usually stuck in some strange 359 * IIC interface is usually stuck in some strange
@@ -376,11 +376,11 @@ static void iic_abort_xfer(struct ibm_iic_private* dev)
376{ 376{
377 volatile struct iic_regs __iomem *iic = dev->vaddr; 377 volatile struct iic_regs __iomem *iic = dev->vaddr;
378 unsigned long x; 378 unsigned long x;
379 379
380 DBG("%d: iic_abort_xfer\n", dev->idx); 380 DBG("%d: iic_abort_xfer\n", dev->idx);
381 381
382 out_8(&iic->cntl, CNTL_HMT); 382 out_8(&iic->cntl, CNTL_HMT);
383 383
384 /* 384 /*
385 * Wait for the abort command to complete. 385 * Wait for the abort command to complete.
386 * It's not worth to be optimized, just poll (timeout >= 1 tick) 386 * It's not worth to be optimized, just poll (timeout >= 1 tick)
@@ -405,13 +405,13 @@ static void iic_abort_xfer(struct ibm_iic_private* dev)
405 * Returns the number of transferred bytes or error (<0) 405 * Returns the number of transferred bytes or error (<0)
406 */ 406 */
407static int iic_wait_for_tc(struct ibm_iic_private* dev){ 407static int iic_wait_for_tc(struct ibm_iic_private* dev){
408 408
409 volatile struct iic_regs __iomem *iic = dev->vaddr; 409 volatile struct iic_regs __iomem *iic = dev->vaddr;
410 int ret = 0; 410 int ret = 0;
411 411
412 if (dev->irq >= 0){ 412 if (dev->irq >= 0){
413 /* Interrupt mode */ 413 /* Interrupt mode */
414 ret = wait_event_interruptible_timeout(dev->wq, 414 ret = wait_event_interruptible_timeout(dev->wq,
415 !(in_8(&iic->sts) & STS_PT), dev->adap.timeout * HZ); 415 !(in_8(&iic->sts) & STS_PT), dev->adap.timeout * HZ);
416 416
417 if (unlikely(ret < 0)) 417 if (unlikely(ret < 0))
@@ -424,37 +424,37 @@ static int iic_wait_for_tc(struct ibm_iic_private* dev){
424 else { 424 else {
425 /* Polling mode */ 425 /* Polling mode */
426 unsigned long x = jiffies + dev->adap.timeout * HZ; 426 unsigned long x = jiffies + dev->adap.timeout * HZ;
427 427
428 while (in_8(&iic->sts) & STS_PT){ 428 while (in_8(&iic->sts) & STS_PT){
429 if (unlikely(time_after(jiffies, x))){ 429 if (unlikely(time_after(jiffies, x))){
430 DBG("%d: poll timeout\n", dev->idx); 430 DBG("%d: poll timeout\n", dev->idx);
431 ret = -ETIMEDOUT; 431 ret = -ETIMEDOUT;
432 break; 432 break;
433 } 433 }
434 434
435 if (unlikely(signal_pending(current))){ 435 if (unlikely(signal_pending(current))){
436 DBG("%d: poll interrupted\n", dev->idx); 436 DBG("%d: poll interrupted\n", dev->idx);
437 ret = -ERESTARTSYS; 437 ret = -ERESTARTSYS;
438 break; 438 break;
439 } 439 }
440 schedule(); 440 schedule();
441 } 441 }
442 } 442 }
443 443
444 if (unlikely(ret < 0)) 444 if (unlikely(ret < 0))
445 iic_abort_xfer(dev); 445 iic_abort_xfer(dev);
446 else 446 else
447 ret = iic_xfer_result(dev); 447 ret = iic_xfer_result(dev);
448 448
449 DBG2("%d: iic_wait_for_tc -> %d\n", dev->idx, ret); 449 DBG2("%d: iic_wait_for_tc -> %d\n", dev->idx, ret);
450 450
451 return ret; 451 return ret;
452} 452}
453 453
454/* 454/*
455 * Low level master transfer routine 455 * Low level master transfer routine
456 */ 456 */
457static int iic_xfer_bytes(struct ibm_iic_private* dev, struct i2c_msg* pm, 457static int iic_xfer_bytes(struct ibm_iic_private* dev, struct i2c_msg* pm,
458 int combined_xfer) 458 int combined_xfer)
459{ 459{
460 volatile struct iic_regs __iomem *iic = dev->vaddr; 460 volatile struct iic_regs __iomem *iic = dev->vaddr;
@@ -465,48 +465,48 @@ static int iic_xfer_bytes(struct ibm_iic_private* dev, struct i2c_msg* pm,
465 u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT; 465 u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT;
466 if (pm->flags & I2C_M_RD) 466 if (pm->flags & I2C_M_RD)
467 cntl |= CNTL_RW; 467 cntl |= CNTL_RW;
468 468
469 loops = (len + 3) / 4; 469 loops = (len + 3) / 4;
470 for (i = 0; i < loops; ++i, len -= 4){ 470 for (i = 0; i < loops; ++i, len -= 4){
471 int count = len > 4 ? 4 : len; 471 int count = len > 4 ? 4 : len;
472 u8 cmd = cntl | ((count - 1) << CNTL_TCT_SHIFT); 472 u8 cmd = cntl | ((count - 1) << CNTL_TCT_SHIFT);
473 473
474 if (!(cntl & CNTL_RW)) 474 if (!(cntl & CNTL_RW))
475 for (j = 0; j < count; ++j) 475 for (j = 0; j < count; ++j)
476 out_8((void __iomem *)&iic->mdbuf, *buf++); 476 out_8((void __iomem *)&iic->mdbuf, *buf++);
477 477
478 if (i < loops - 1) 478 if (i < loops - 1)
479 cmd |= CNTL_CHT; 479 cmd |= CNTL_CHT;
480 else if (combined_xfer) 480 else if (combined_xfer)
481 cmd |= CNTL_RPST; 481 cmd |= CNTL_RPST;
482 482
483 DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, count, cmd); 483 DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, count, cmd);
484 484
485 /* Start transfer */ 485 /* Start transfer */
486 out_8(&iic->cntl, cmd); 486 out_8(&iic->cntl, cmd);
487 487
488 /* Wait for completion */ 488 /* Wait for completion */
489 ret = iic_wait_for_tc(dev); 489 ret = iic_wait_for_tc(dev);
490 490
491 if (unlikely(ret < 0)) 491 if (unlikely(ret < 0))
492 break; 492 break;
493 else if (unlikely(ret != count)){ 493 else if (unlikely(ret != count)){
494 DBG("%d: xfer_bytes, requested %d, transfered %d\n", 494 DBG("%d: xfer_bytes, requested %d, transfered %d\n",
495 dev->idx, count, ret); 495 dev->idx, count, ret);
496 496
497 /* If it's not a last part of xfer, abort it */ 497 /* If it's not a last part of xfer, abort it */
498 if (combined_xfer || (i < loops - 1)) 498 if (combined_xfer || (i < loops - 1))
499 iic_abort_xfer(dev); 499 iic_abort_xfer(dev);
500 500
501 ret = -EREMOTEIO; 501 ret = -EREMOTEIO;
502 break; 502 break;
503 } 503 }
504 504
505 if (cntl & CNTL_RW) 505 if (cntl & CNTL_RW)
506 for (j = 0; j < count; ++j) 506 for (j = 0; j < count; ++j)
507 *buf++ = in_8((void __iomem *)&iic->mdbuf); 507 *buf++ = in_8((void __iomem *)&iic->mdbuf);
508 } 508 }
509 509
510 return ret > 0 ? 0 : ret; 510 return ret > 0 ? 0 : ret;
511} 511}
512 512
@@ -517,10 +517,10 @@ static inline void iic_address(struct ibm_iic_private* dev, struct i2c_msg* msg)
517{ 517{
518 volatile struct iic_regs __iomem *iic = dev->vaddr; 518 volatile struct iic_regs __iomem *iic = dev->vaddr;
519 u16 addr = msg->addr; 519 u16 addr = msg->addr;
520 520
521 DBG2("%d: iic_address, 0x%03x (%d-bit)\n", dev->idx, 521 DBG2("%d: iic_address, 0x%03x (%d-bit)\n", dev->idx,
522 addr, msg->flags & I2C_M_TEN ? 10 : 7); 522 addr, msg->flags & I2C_M_TEN ? 10 : 7);
523 523
524 if (msg->flags & I2C_M_TEN){ 524 if (msg->flags & I2C_M_TEN){
525 out_8(&iic->cntl, CNTL_AMD); 525 out_8(&iic->cntl, CNTL_AMD);
526 out_8(&iic->lmadr, addr); 526 out_8(&iic->lmadr, addr);
@@ -537,15 +537,15 @@ static inline int iic_invalid_address(const struct i2c_msg* p)
537 return (p->addr > 0x3ff) || (!(p->flags & I2C_M_TEN) && (p->addr > 0x7f)); 537 return (p->addr > 0x3ff) || (!(p->flags & I2C_M_TEN) && (p->addr > 0x7f));
538} 538}
539 539
540static inline int iic_address_neq(const struct i2c_msg* p1, 540static inline int iic_address_neq(const struct i2c_msg* p1,
541 const struct i2c_msg* p2) 541 const struct i2c_msg* p2)
542{ 542{
543 return (p1->addr != p2->addr) 543 return (p1->addr != p2->addr)
544 || ((p1->flags & I2C_M_TEN) != (p2->flags & I2C_M_TEN)); 544 || ((p1->flags & I2C_M_TEN) != (p2->flags & I2C_M_TEN));
545} 545}
546 546
547/* 547/*
548 * Generic master transfer entrypoint. 548 * Generic master transfer entrypoint.
549 * Returns the number of processed messages or error (<0) 549 * Returns the number of processed messages or error (<0)
550 */ 550 */
551static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) 551static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
@@ -553,20 +553,20 @@ static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
553 struct ibm_iic_private* dev = (struct ibm_iic_private*)(i2c_get_adapdata(adap)); 553 struct ibm_iic_private* dev = (struct ibm_iic_private*)(i2c_get_adapdata(adap));
554 volatile struct iic_regs __iomem *iic = dev->vaddr; 554 volatile struct iic_regs __iomem *iic = dev->vaddr;
555 int i, ret = 0; 555 int i, ret = 0;
556 556
557 DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num); 557 DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num);
558 558
559 if (!num) 559 if (!num)
560 return 0; 560 return 0;
561 561
562 /* Check the sanity of the passed messages. 562 /* Check the sanity of the passed messages.
563 * Uhh, generic i2c layer is more suitable place for such code... 563 * Uhh, generic i2c layer is more suitable place for such code...
564 */ 564 */
565 if (unlikely(iic_invalid_address(&msgs[0]))){ 565 if (unlikely(iic_invalid_address(&msgs[0]))){
566 DBG("%d: invalid address 0x%03x (%d-bit)\n", dev->idx, 566 DBG("%d: invalid address 0x%03x (%d-bit)\n", dev->idx,
567 msgs[0].addr, msgs[0].flags & I2C_M_TEN ? 10 : 7); 567 msgs[0].addr, msgs[0].flags & I2C_M_TEN ? 10 : 7);
568 return -EINVAL; 568 return -EINVAL;
569 } 569 }
570 for (i = 0; i < num; ++i){ 570 for (i = 0; i < num; ++i){
571 if (unlikely(msgs[i].len <= 0)){ 571 if (unlikely(msgs[i].len <= 0)){
572 if (num == 1 && !msgs[0].len){ 572 if (num == 1 && !msgs[0].len){
@@ -576,7 +576,7 @@ static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
576 */ 576 */
577 return iic_smbus_quick(dev, &msgs[0]); 577 return iic_smbus_quick(dev, &msgs[0]);
578 } 578 }
579 DBG("%d: invalid len %d in msg[%d]\n", dev->idx, 579 DBG("%d: invalid len %d in msg[%d]\n", dev->idx,
580 msgs[i].len, i); 580 msgs[i].len, i);
581 return -EINVAL; 581 return -EINVAL;
582 } 582 }
@@ -585,34 +585,34 @@ static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
585 return -EINVAL; 585 return -EINVAL;
586 } 586 }
587 } 587 }
588 588
589 /* Check bus state */ 589 /* Check bus state */
590 if (unlikely((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE)){ 590 if (unlikely((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE)){
591 DBG("%d: iic_xfer, bus is not free\n", dev->idx); 591 DBG("%d: iic_xfer, bus is not free\n", dev->idx);
592 592
593 /* Usually it means something serious has happend. 593 /* Usually it means something serious has happend.
594 * We *cannot* have unfinished previous transfer 594 * We *cannot* have unfinished previous transfer
595 * so it doesn't make any sense to try to stop it. 595 * so it doesn't make any sense to try to stop it.
596 * Probably we were not able to recover from the 596 * Probably we were not able to recover from the
597 * previous error. 597 * previous error.
598 * The only *reasonable* thing I can think of here 598 * The only *reasonable* thing I can think of here
599 * is soft reset. --ebs 599 * is soft reset. --ebs
600 */ 600 */
601 iic_dev_reset(dev); 601 iic_dev_reset(dev);
602 602
603 if ((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE){ 603 if ((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE){
604 DBG("%d: iic_xfer, bus is still not free\n", dev->idx); 604 DBG("%d: iic_xfer, bus is still not free\n", dev->idx);
605 return -EREMOTEIO; 605 return -EREMOTEIO;
606 } 606 }
607 } 607 }
608 else { 608 else {
609 /* Flush master data buffer (just in case) */ 609 /* Flush master data buffer (just in case) */
610 out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB); 610 out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB);
611 } 611 }
612 612
613 /* Load slave address */ 613 /* Load slave address */
614 iic_address(dev, &msgs[0]); 614 iic_address(dev, &msgs[0]);
615 615
616 /* Do real transfer */ 616 /* Do real transfer */
617 for (i = 0; i < num && !ret; ++i) 617 for (i = 0; i < num && !ret; ++i)
618 ret = iic_xfer_bytes(dev, &msgs[i], i < num - 1); 618 ret = iic_xfer_bytes(dev, &msgs[i], i < num - 1);
@@ -648,7 +648,7 @@ static inline u8 iic_clckdiv(unsigned int opb)
648 648
649 /* Convert to MHz */ 649 /* Convert to MHz */
650 opb /= 1000000; 650 opb /= 1000000;
651 651
652 if (opb < 20 || opb > 150){ 652 if (opb < 20 || opb > 150){
653 printk(KERN_CRIT "ibm-iic: invalid OPB clock frequency %u MHz\n", 653 printk(KERN_CRIT "ibm-iic: invalid OPB clock frequency %u MHz\n",
654 opb); 654 opb);
@@ -666,7 +666,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
666 struct i2c_adapter* adap; 666 struct i2c_adapter* adap;
667 struct ocp_func_iic_data* iic_data = ocp->def->additions; 667 struct ocp_func_iic_data* iic_data = ocp->def->additions;
668 int ret; 668 int ret;
669 669
670 if (!iic_data) 670 if (!iic_data)
671 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n", 671 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n",
672 ocp->def->index); 672 ocp->def->index);
@@ -679,7 +679,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
679 679
680 dev->idx = ocp->def->index; 680 dev->idx = ocp->def->index;
681 ocp_set_drvdata(ocp, dev); 681 ocp_set_drvdata(ocp, dev);
682 682
683 if (!request_mem_region(ocp->def->paddr, sizeof(struct iic_regs), 683 if (!request_mem_region(ocp->def->paddr, sizeof(struct iic_regs),
684 "ibm_iic")) { 684 "ibm_iic")) {
685 ret = -EBUSY; 685 ret = -EBUSY;
@@ -692,7 +692,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
692 ret = -ENXIO; 692 ret = -ENXIO;
693 goto fail2; 693 goto fail2;
694 } 694 }
695 695
696 init_waitqueue_head(&dev->wq); 696 init_waitqueue_head(&dev->wq);
697 697
698 dev->irq = iic_force_poll ? -1 : ocp->def->irq; 698 dev->irq = iic_force_poll ? -1 : ocp->def->irq;
@@ -702,29 +702,29 @@ static int __devinit iic_probe(struct ocp_device *ocp){
702 */ 702 */
703 iic_interrupt_mode(dev, 0); 703 iic_interrupt_mode(dev, 0);
704 if (request_irq(dev->irq, iic_handler, 0, "IBM IIC", dev)){ 704 if (request_irq(dev->irq, iic_handler, 0, "IBM IIC", dev)){
705 printk(KERN_ERR "ibm-iic%d: request_irq %d failed\n", 705 printk(KERN_ERR "ibm-iic%d: request_irq %d failed\n",
706 dev->idx, dev->irq); 706 dev->idx, dev->irq);
707 /* Fallback to the polling mode */ 707 /* Fallback to the polling mode */
708 dev->irq = -1; 708 dev->irq = -1;
709 } 709 }
710 } 710 }
711 711
712 if (dev->irq < 0) 712 if (dev->irq < 0)
713 printk(KERN_WARNING "ibm-iic%d: using polling mode\n", 713 printk(KERN_WARNING "ibm-iic%d: using polling mode\n",
714 dev->idx); 714 dev->idx);
715 715
716 /* Board specific settings */ 716 /* Board specific settings */
717 dev->fast_mode = iic_force_fast ? 1 : (iic_data ? iic_data->fast_mode : 0); 717 dev->fast_mode = iic_force_fast ? 1 : (iic_data ? iic_data->fast_mode : 0);
718 718
719 /* clckdiv is the same for *all* IIC interfaces, 719 /* clckdiv is the same for *all* IIC interfaces,
720 * but I'd rather make a copy than introduce another global. --ebs 720 * but I'd rather make a copy than introduce another global. --ebs
721 */ 721 */
722 dev->clckdiv = iic_clckdiv(ocp_sys_info.opb_bus_freq); 722 dev->clckdiv = iic_clckdiv(ocp_sys_info.opb_bus_freq);
723 DBG("%d: clckdiv = %d\n", dev->idx, dev->clckdiv); 723 DBG("%d: clckdiv = %d\n", dev->idx, dev->clckdiv);
724 724
725 /* Initialize IIC interface */ 725 /* Initialize IIC interface */
726 iic_dev_init(dev); 726 iic_dev_init(dev);
727 727
728 /* Register it with i2c layer */ 728 /* Register it with i2c layer */
729 adap = &dev->adap; 729 adap = &dev->adap;
730 adap->dev.parent = &ocp->dev; 730 adap->dev.parent = &ocp->dev;
@@ -736,7 +736,6 @@ static int __devinit iic_probe(struct ocp_device *ocp){
736 adap->client_register = NULL; 736 adap->client_register = NULL;
737 adap->client_unregister = NULL; 737 adap->client_unregister = NULL;
738 adap->timeout = 1; 738 adap->timeout = 1;
739 adap->retries = 1;
740 739
741 /* 740 /*
742 * If "dev->idx" is negative we consider it as zero. 741 * If "dev->idx" is negative we consider it as zero.
@@ -750,24 +749,24 @@ static int __devinit iic_probe(struct ocp_device *ocp){
750 dev->idx); 749 dev->idx);
751 goto fail; 750 goto fail;
752 } 751 }
753 752
754 printk(KERN_INFO "ibm-iic%d: using %s mode\n", dev->idx, 753 printk(KERN_INFO "ibm-iic%d: using %s mode\n", dev->idx,
755 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); 754 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
756 755
757 return 0; 756 return 0;
758 757
759fail: 758fail:
760 if (dev->irq >= 0){ 759 if (dev->irq >= 0){
761 iic_interrupt_mode(dev, 0); 760 iic_interrupt_mode(dev, 0);
762 free_irq(dev->irq, dev); 761 free_irq(dev->irq, dev);
763 } 762 }
764 763
765 iounmap(dev->vaddr); 764 iounmap(dev->vaddr);
766fail2: 765fail2:
767 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs)); 766 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs));
768fail1: 767fail1:
769 ocp_set_drvdata(ocp, NULL); 768 ocp_set_drvdata(ocp, NULL);
770 kfree(dev); 769 kfree(dev);
771 return ret; 770 return ret;
772} 771}
773 772
@@ -783,13 +782,13 @@ static void __devexit iic_remove(struct ocp_device *ocp)
783 dev->idx); 782 dev->idx);
784 /* That's *very* bad, just shutdown IRQ ... */ 783 /* That's *very* bad, just shutdown IRQ ... */
785 if (dev->irq >= 0){ 784 if (dev->irq >= 0){
786 iic_interrupt_mode(dev, 0); 785 iic_interrupt_mode(dev, 0);
787 free_irq(dev->irq, dev); 786 free_irq(dev->irq, dev);
788 dev->irq = -1; 787 dev->irq = -1;
789 } 788 }
790 } else { 789 } else {
791 if (dev->irq >= 0){ 790 if (dev->irq >= 0){
792 iic_interrupt_mode(dev, 0); 791 iic_interrupt_mode(dev, 0);
793 free_irq(dev->irq, dev); 792 free_irq(dev->irq, dev);
794 } 793 }
795 iounmap(dev->vaddr); 794 iounmap(dev->vaddr);
@@ -798,7 +797,7 @@ static void __devexit iic_remove(struct ocp_device *ocp)
798 } 797 }
799} 798}
800 799
801static struct ocp_device_id ibm_iic_ids[] __devinitdata = 800static struct ocp_device_id ibm_iic_ids[] __devinitdata =
802{ 801{
803 { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_IIC }, 802 { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_IIC },
804 { .vendor = OCP_VENDOR_INVALID } 803 { .vendor = OCP_VENDOR_INVALID }
diff --git a/drivers/i2c/busses/i2c-ibm_iic.h b/drivers/i2c/busses/i2c-ibm_iic.h
index 59d7b437f7ff..fdaa48292cb6 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.h
+++ b/drivers/i2c/busses/i2c-ibm_iic.h
@@ -2,11 +2,11 @@
2 * drivers/i2c/busses/i2c-ibm_iic.h 2 * drivers/i2c/busses/i2c-ibm_iic.h
3 * 3 *
4 * Support for the IIC peripheral on IBM PPC 4xx 4 * Support for the IIC peripheral on IBM PPC 4xx
5 * 5 *
6 * Copyright (c) 2003 Zultys Technologies. 6 * Copyright (c) 2003 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 8 *
9 * Based on original work by 9 * Based on original work by
10 * Ian DaSilva <idasilva@mvista.com> 10 * Ian DaSilva <idasilva@mvista.com>
11 * Armin Kuster <akuster@mvista.com> 11 * Armin Kuster <akuster@mvista.com>
12 * Matt Porter <mporter@mvista.com> 12 * Matt Porter <mporter@mvista.com>
@@ -22,7 +22,7 @@
22#ifndef __I2C_IBM_IIC_H_ 22#ifndef __I2C_IBM_IIC_H_
23#define __I2C_IBM_IIC_H_ 23#define __I2C_IBM_IIC_H_
24 24
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26 26
27struct iic_regs { 27struct iic_regs {
28 u16 mdbuf; 28 u16 mdbuf;
@@ -58,7 +58,7 @@ struct ibm_iic_private {
58#define CNTL_TCT_MASK 0x30 58#define CNTL_TCT_MASK 0x30
59#define CNTL_TCT_SHIFT 4 59#define CNTL_TCT_SHIFT 4
60#define CNTL_RPST 0x08 60#define CNTL_RPST 0x08
61#define CNTL_CHT 0x04 61#define CNTL_CHT 0x04
62#define CNTL_RW 0x02 62#define CNTL_RW 0x02
63#define CNTL_PT 0x01 63#define CNTL_PT 0x01
64 64
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index c70146e4c2c0..ab41400c883e 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -490,7 +490,6 @@ iop3xx_i2c_probe(struct platform_device *pdev)
490 * Default values...should these come in from board code? 490 * Default values...should these come in from board code?
491 */ 491 */
492 new_adapter->timeout = 100; 492 new_adapter->timeout = 100;
493 new_adapter->retries = 3;
494 new_adapter->algo = &iop3xx_i2c_algo; 493 new_adapter->algo = &iop3xx_i2c_algo;
495 494
496 init_waitqueue_head(&adapter_data->waitq); 495 init_waitqueue_head(&adapter_data->waitq);
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
deleted file mode 100644
index 069ed7f3b395..000000000000
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ /dev/null
@@ -1,178 +0,0 @@
1/*
2 * drivers/i2c/busses/i2c-ixp4xx.c
3 *
4 * Intel's IXP4xx XScale NPU chipsets (IXP420, 421, 422, 425) do not have
5 * an on board I2C controller but provide 16 GPIO pins that are often
6 * used to create an I2C bus. This driver provides an i2c_adapter
7 * interface that plugs in under algo_bit and drives the GPIO pins
8 * as instructed by the alogorithm driver.
9 *
10 * Author: Deepak Saxena <dsaxena@plexity.net>
11 *
12 * Copyright (c) 2003-2004 MontaVista Software Inc.
13 *
14 * This file is licensed under the terms of the GNU General Public
15 * License version 2. This program is licensed "as is" without any
16 * warranty of any kind, whether express or implied.
17 *
18 * NOTE: Since different platforms will use different GPIO pins for
19 * I2C, this driver uses an IXP4xx-specific platform_data
20 * pointer to pass the GPIO numbers to the driver. This
21 * allows us to support all the different IXP4xx platforms
22 * w/o having to put #ifdefs in this driver.
23 *
24 * See arch/arm/mach-ixp4xx/ixdp425.c for an example of building a
25 * device list and filling in the ixp4xx_i2c_pins data structure
26 * that is passed as the platform_data to this driver.
27 */
28
29#include <linux/kernel.h>
30#include <linux/init.h>
31#include <linux/platform_device.h>
32#include <linux/module.h>
33#include <linux/i2c.h>
34#include <linux/i2c-algo-bit.h>
35
36#include <asm/hardware.h> /* Pick up IXP4xx-specific bits */
37
38static inline int ixp4xx_scl_pin(void *data)
39{
40 return ((struct ixp4xx_i2c_pins*)data)->scl_pin;
41}
42
43static inline int ixp4xx_sda_pin(void *data)
44{
45 return ((struct ixp4xx_i2c_pins*)data)->sda_pin;
46}
47
48static void ixp4xx_bit_setscl(void *data, int val)
49{
50 gpio_line_set(ixp4xx_scl_pin(data), 0);
51 gpio_line_config(ixp4xx_scl_pin(data),
52 val ? IXP4XX_GPIO_IN : IXP4XX_GPIO_OUT );
53}
54
55static void ixp4xx_bit_setsda(void *data, int val)
56{
57 gpio_line_set(ixp4xx_sda_pin(data), 0);
58 gpio_line_config(ixp4xx_sda_pin(data),
59 val ? IXP4XX_GPIO_IN : IXP4XX_GPIO_OUT );
60}
61
62static int ixp4xx_bit_getscl(void *data)
63{
64 int scl;
65
66 gpio_line_config(ixp4xx_scl_pin(data), IXP4XX_GPIO_IN );
67 gpio_line_get(ixp4xx_scl_pin(data), &scl);
68
69 return scl;
70}
71
72static int ixp4xx_bit_getsda(void *data)
73{
74 int sda;
75
76 gpio_line_config(ixp4xx_sda_pin(data), IXP4XX_GPIO_IN );
77 gpio_line_get(ixp4xx_sda_pin(data), &sda);
78
79 return sda;
80}
81
82struct ixp4xx_i2c_data {
83 struct ixp4xx_i2c_pins *gpio_pins;
84 struct i2c_adapter adapter;
85 struct i2c_algo_bit_data algo_data;
86};
87
88static int ixp4xx_i2c_remove(struct platform_device *plat_dev)
89{
90 struct ixp4xx_i2c_data *drv_data = platform_get_drvdata(plat_dev);
91
92 platform_set_drvdata(plat_dev, NULL);
93
94 i2c_del_adapter(&drv_data->adapter);
95
96 kfree(drv_data);
97
98 return 0;
99}
100
101static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
102{
103 int err;
104 struct ixp4xx_i2c_pins *gpio = plat_dev->dev.platform_data;
105 struct ixp4xx_i2c_data *drv_data =
106 kzalloc(sizeof(struct ixp4xx_i2c_data), GFP_KERNEL);
107
108 if(!drv_data)
109 return -ENOMEM;
110
111 drv_data->gpio_pins = gpio;
112
113 /*
114 * We could make a lot of these structures static, but
115 * certain platforms may have multiple GPIO-based I2C
116 * buses for various device domains, so we need per-device
117 * algo_data->data.
118 */
119 drv_data->algo_data.data = gpio;
120 drv_data->algo_data.setsda = ixp4xx_bit_setsda;
121 drv_data->algo_data.setscl = ixp4xx_bit_setscl;
122 drv_data->algo_data.getsda = ixp4xx_bit_getsda;
123 drv_data->algo_data.getscl = ixp4xx_bit_getscl;
124 drv_data->algo_data.udelay = 10;
125 drv_data->algo_data.timeout = 100;
126
127 drv_data->adapter.id = I2C_HW_B_IXP4XX;
128 drv_data->adapter.class = I2C_CLASS_HWMON;
129 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
130 sizeof(drv_data->adapter.name));
131 drv_data->adapter.algo_data = &drv_data->algo_data;
132
133 drv_data->adapter.dev.parent = &plat_dev->dev;
134
135 gpio_line_config(gpio->scl_pin, IXP4XX_GPIO_IN);
136 gpio_line_config(gpio->sda_pin, IXP4XX_GPIO_IN);
137 gpio_line_set(gpio->scl_pin, 0);
138 gpio_line_set(gpio->sda_pin, 0);
139
140 err = i2c_bit_add_bus(&drv_data->adapter);
141 if (err) {
142 printk(KERN_ERR "ERROR: Could not install %s\n", plat_dev->dev.bus_id);
143
144 kfree(drv_data);
145 return err;
146 }
147
148 platform_set_drvdata(plat_dev, drv_data);
149
150 return 0;
151}
152
153static struct platform_driver ixp4xx_i2c_driver = {
154 .probe = ixp4xx_i2c_probe,
155 .remove = ixp4xx_i2c_remove,
156 .driver = {
157 .name = "IXP4XX-I2C",
158 .owner = THIS_MODULE,
159 },
160};
161
162static int __init ixp4xx_i2c_init(void)
163{
164 return platform_driver_register(&ixp4xx_i2c_driver);
165}
166
167static void __exit ixp4xx_i2c_exit(void)
168{
169 platform_driver_unregister(&ixp4xx_i2c_driver);
170}
171
172module_init(ixp4xx_i2c_init);
173module_exit(ixp4xx_i2c_exit);
174
175MODULE_DESCRIPTION("GPIO-based I2C adapter for IXP4xx systems");
176MODULE_LICENSE("GPL");
177MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
178
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index d8de4ac88b7d..bbe787b243b7 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -180,7 +180,7 @@ static void mpc_i2c_stop(struct mpc_i2c *i2c)
180static int mpc_write(struct mpc_i2c *i2c, int target, 180static int mpc_write(struct mpc_i2c *i2c, int target,
181 const u8 * data, int length, int restart) 181 const u8 * data, int length, int restart)
182{ 182{
183 int i; 183 int i, result;
184 unsigned timeout = i2c->adap.timeout; 184 unsigned timeout = i2c->adap.timeout;
185 u32 flags = restart ? CCR_RSTA : 0; 185 u32 flags = restart ? CCR_RSTA : 0;
186 186
@@ -192,15 +192,17 @@ static int mpc_write(struct mpc_i2c *i2c, int target,
192 /* Write target byte */ 192 /* Write target byte */
193 writeb((target << 1), i2c->base + MPC_I2C_DR); 193 writeb((target << 1), i2c->base + MPC_I2C_DR);
194 194
195 if (i2c_wait(i2c, timeout, 1) < 0) 195 result = i2c_wait(i2c, timeout, 1);
196 return -1; 196 if (result < 0)
197 return result;
197 198
198 for (i = 0; i < length; i++) { 199 for (i = 0; i < length; i++) {
199 /* Write data byte */ 200 /* Write data byte */
200 writeb(data[i], i2c->base + MPC_I2C_DR); 201 writeb(data[i], i2c->base + MPC_I2C_DR);
201 202
202 if (i2c_wait(i2c, timeout, 1) < 0) 203 result = i2c_wait(i2c, timeout, 1);
203 return -1; 204 if (result < 0)
205 return result;
204 } 206 }
205 207
206 return 0; 208 return 0;
@@ -210,7 +212,7 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
210 u8 * data, int length, int restart) 212 u8 * data, int length, int restart)
211{ 213{
212 unsigned timeout = i2c->adap.timeout; 214 unsigned timeout = i2c->adap.timeout;
213 int i; 215 int i, result;
214 u32 flags = restart ? CCR_RSTA : 0; 216 u32 flags = restart ? CCR_RSTA : 0;
215 217
216 /* Start with MEN */ 218 /* Start with MEN */
@@ -221,8 +223,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
221 /* Write target address byte - this time with the read flag set */ 223 /* Write target address byte - this time with the read flag set */
222 writeb((target << 1) | 1, i2c->base + MPC_I2C_DR); 224 writeb((target << 1) | 1, i2c->base + MPC_I2C_DR);
223 225
224 if (i2c_wait(i2c, timeout, 1) < 0) 226 result = i2c_wait(i2c, timeout, 1);
225 return -1; 227 if (result < 0)
228 return result;
226 229
227 if (length) { 230 if (length) {
228 if (length == 1) 231 if (length == 1)
@@ -234,8 +237,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
234 } 237 }
235 238
236 for (i = 0; i < length; i++) { 239 for (i = 0; i < length; i++) {
237 if (i2c_wait(i2c, timeout, 0) < 0) 240 result = i2c_wait(i2c, timeout, 0);
238 return -1; 241 if (result < 0)
242 return result;
239 243
240 /* Generate txack on next to last byte */ 244 /* Generate txack on next to last byte */
241 if (i == length - 2) 245 if (i == length - 2)
@@ -309,7 +313,6 @@ static struct i2c_adapter mpc_ops = {
309 .algo = &mpc_algo, 313 .algo = &mpc_algo,
310 .class = I2C_CLASS_HWMON, 314 .class = I2C_CLASS_HWMON,
311 .timeout = 1, 315 .timeout = 1,
312 .retries = 1
313}; 316};
314 317
315static int fsl_i2c_probe(struct platform_device *pdev) 318static int fsl_i2c_probe(struct platform_device *pdev)
@@ -321,9 +324,9 @@ static int fsl_i2c_probe(struct platform_device *pdev)
321 324
322 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data; 325 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
323 326
324 if (!(i2c = kzalloc(sizeof(*i2c), GFP_KERNEL))) { 327 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
328 if (!i2c)
325 return -ENOMEM; 329 return -ENOMEM;
326 }
327 330
328 i2c->irq = platform_get_irq(pdev, 0); 331 i2c->irq = platform_get_irq(pdev, 0);
329 if (i2c->irq < 0) { 332 if (i2c->irq < 0) {
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 1bf590c74166..3dac920e53ea 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -351,6 +351,7 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
351 pci_set_drvdata(dev, smbuses); 351 pci_set_drvdata(dev, smbuses);
352 352
353 switch(dev->device) { 353 switch(dev->device) {
354 case PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS:
354 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS: 355 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS:
355 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS: 356 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS:
356 smbuses[0].blockops = 1; 357 smbuses[0].blockops = 1;
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index f2552b19ea60..da6639707ea3 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -362,8 +362,6 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
362 362
363 omap_i2c_enable_clocks(dev); 363 omap_i2c_enable_clocks(dev);
364 364
365 /* REVISIT: initialize and use adap->retries. This is an optional
366 * feature */
367 if ((r = omap_i2c_wait_for_bb(dev)) < 0) 365 if ((r = omap_i2c_wait_for_bb(dev)) < 0)
368 goto out; 366 goto out;
369 367
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index ca18e0be4901..1603c81e39d4 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -368,6 +368,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev,
368 smbus->adapter.class = I2C_CLASS_HWMON; 368 smbus->adapter.class = I2C_CLASS_HWMON;
369 smbus->adapter.algo = &smbus_algorithm; 369 smbus->adapter.algo = &smbus_algorithm;
370 smbus->adapter.algo_data = smbus; 370 smbus->adapter.algo_data = smbus;
371 smbus->adapter.nr = PCI_FUNC(dev->devfn);
371 372
372 /* set up the sysfs linkage to our parent device */ 373 /* set up the sysfs linkage to our parent device */
373 smbus->adapter.dev.parent = &dev->dev; 374 smbus->adapter.dev.parent = &dev->dev;
@@ -375,7 +376,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev,
375 reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | 376 reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR |
376 (CLK_100K_DIV & CTL_CLK_M))); 377 (CLK_100K_DIV & CTL_CLK_M)));
377 378
378 error = i2c_add_adapter(&smbus->adapter); 379 error = i2c_add_numbered_adapter(&smbus->adapter);
379 if (error) 380 if (error)
380 goto out_release_region; 381 goto out_release_region;
381 382
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 167e4137ee21..9bbe96cef719 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -121,10 +121,6 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
121{ 121{
122 unsigned char temp; 122 unsigned char temp;
123 123
124 /* match up the function */
125 if (PCI_FUNC(PIIX4_dev->devfn) != id->driver_data)
126 return -ENODEV;
127
128 dev_info(&PIIX4_dev->dev, "Found %s device\n", pci_name(PIIX4_dev)); 124 dev_info(&PIIX4_dev->dev, "Found %s device\n", pci_name(PIIX4_dev));
129 125
130 /* Don't access SMBus on IBM systems which get corrupted eeproms */ 126 /* Don't access SMBus on IBM systems which get corrupted eeproms */
@@ -389,28 +385,21 @@ static struct i2c_adapter piix4_adapter = {
389}; 385};
390 386
391static struct pci_device_id piix4_ids[] = { 387static struct pci_device_id piix4_ids[] = {
392 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3), 388 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
393 .driver_data = 3 }, 389 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) },
394 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS), 390 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) },
395 .driver_data = 0 }, 391 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS) },
396 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS), 392 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) },
397 .driver_data = 0 }, 393 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) },
398 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS), 394 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) },
399 .driver_data = 0 }, 395 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
400 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS), 396 PCI_DEVICE_ID_SERVERWORKS_OSB4) },
401 .driver_data = 0 }, 397 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
402 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4), 398 PCI_DEVICE_ID_SERVERWORKS_CSB5) },
403 .driver_data = 0 }, 399 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
404 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5), 400 PCI_DEVICE_ID_SERVERWORKS_CSB6) },
405 .driver_data = 0 }, 401 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
406 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6), 402 PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
407 .driver_data = 0 },
408 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000SB),
409 .driver_data = 0 },
410 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3),
411 .driver_data = 3 },
412 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3),
413 .driver_data = 0 },
414 { 0, } 403 { 0, }
415}; 404};
416 405
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 6426a61f8d4d..2598d29fd7a4 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -65,6 +65,7 @@ struct pxa_i2c {
65 unsigned long iosize; 65 unsigned long iosize;
66 66
67 int irq; 67 int irq;
68 int use_pio;
68}; 69};
69 70
70#define _IBMR(i2c) ((i2c)->reg_base + 0) 71#define _IBMR(i2c) ((i2c)->reg_base + 0)
@@ -163,6 +164,7 @@ static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
163#define eedbg(lvl, x...) do { if ((lvl) < 1) { printk(KERN_DEBUG "" x); } } while(0) 164#define eedbg(lvl, x...) do { if ((lvl) < 1) { printk(KERN_DEBUG "" x); } } while(0)
164 165
165static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret); 166static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
167static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
166 168
167static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) 169static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
168{ 170{
@@ -554,6 +556,71 @@ static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
554 writel(icr, _ICR(i2c)); 556 writel(icr, _ICR(i2c));
555} 557}
556 558
559static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)
560{
561 /* make timeout the same as for interrupt based functions */
562 long timeout = 2 * DEF_TIMEOUT;
563
564 /*
565 * Wait for the bus to become free.
566 */
567 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
568 udelay(1000);
569 show_state(i2c);
570 }
571
572 if (timeout <= 0) {
573 show_state(i2c);
574 dev_err(&i2c->adap.dev,
575 "i2c_pxa: timeout waiting for bus free\n");
576 return I2C_RETRY;
577 }
578
579 /*
580 * Set master mode.
581 */
582 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
583
584 return 0;
585}
586
587static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,
588 struct i2c_msg *msg, int num)
589{
590 unsigned long timeout = 500000; /* 5 seconds */
591 int ret = 0;
592
593 ret = i2c_pxa_pio_set_master(i2c);
594 if (ret)
595 goto out;
596
597 i2c->msg = msg;
598 i2c->msg_num = num;
599 i2c->msg_idx = 0;
600 i2c->msg_ptr = 0;
601 i2c->irqlogidx = 0;
602
603 i2c_pxa_start_message(i2c);
604
605 while (timeout-- && i2c->msg_num > 0) {
606 i2c_pxa_handler(0, i2c);
607 udelay(10);
608 }
609
610 i2c_pxa_stop_message(i2c);
611
612 /*
613 * We place the return code in i2c->msg_idx.
614 */
615 ret = i2c->msg_idx;
616
617out:
618 if (timeout == 0)
619 i2c_pxa_scream_blue_murder(i2c, "timeout");
620
621 return ret;
622}
623
557/* 624/*
558 * We are protected by the adapter bus mutex. 625 * We are protected by the adapter bus mutex.
559 */ 626 */
@@ -610,6 +677,35 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
610 return ret; 677 return ret;
611} 678}
612 679
680static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
681 struct i2c_msg msgs[], int num)
682{
683 struct pxa_i2c *i2c = adap->algo_data;
684 int ret, i;
685
686 /* If the I2C controller is disabled we need to reset it
687 (probably due to a suspend/resume destroying state). We do
688 this here as we can then avoid worrying about resuming the
689 controller before its users. */
690 if (!(readl(_ICR(i2c)) & ICR_IUE))
691 i2c_pxa_reset(i2c);
692
693 for (i = adap->retries; i >= 0; i--) {
694 ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
695 if (ret != I2C_RETRY)
696 goto out;
697
698 if (i2c_debug)
699 dev_dbg(&adap->dev, "Retrying transmission\n");
700 udelay(100);
701 }
702 i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
703 ret = -EREMOTEIO;
704 out:
705 i2c_pxa_set_slave(i2c, ret);
706 return ret;
707}
708
613/* 709/*
614 * i2c_pxa_master_complete - complete the message and wake up. 710 * i2c_pxa_master_complete - complete the message and wake up.
615 */ 711 */
@@ -621,7 +717,8 @@ static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret)
621 i2c->msg_num = 0; 717 i2c->msg_num = 0;
622 if (ret) 718 if (ret)
623 i2c->msg_idx = ret; 719 i2c->msg_idx = ret;
624 wake_up(&i2c->wait); 720 if (!i2c->use_pio)
721 wake_up(&i2c->wait);
625} 722}
626 723
627static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr) 724static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
@@ -840,6 +937,37 @@ static const struct i2c_algorithm i2c_pxa_algorithm = {
840 .functionality = i2c_pxa_functionality, 937 .functionality = i2c_pxa_functionality,
841}; 938};
842 939
940static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
941 .master_xfer = i2c_pxa_pio_xfer,
942 .functionality = i2c_pxa_functionality,
943};
944
945static void i2c_pxa_enable(struct platform_device *dev)
946{
947 if (cpu_is_pxa27x()) {
948 switch (dev->id) {
949 case 0:
950 pxa_gpio_mode(GPIO117_I2CSCL_MD);
951 pxa_gpio_mode(GPIO118_I2CSDA_MD);
952 break;
953 case 1:
954 local_irq_disable();
955 PCFR |= PCFR_PI2CEN;
956 local_irq_enable();
957 break;
958 }
959 }
960}
961
962static void i2c_pxa_disable(struct platform_device *dev)
963{
964 if (cpu_is_pxa27x() && dev->id == 1) {
965 local_irq_disable();
966 PCFR &= ~PCFR_PI2CEN;
967 local_irq_enable();
968 }
969}
970
843#define res_len(r) ((r)->end - (r)->start + 1) 971#define res_len(r) ((r)->end - (r)->start + 1)
844static int i2c_pxa_probe(struct platform_device *dev) 972static int i2c_pxa_probe(struct platform_device *dev)
845{ 973{
@@ -864,7 +992,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
864 } 992 }
865 993
866 i2c->adap.owner = THIS_MODULE; 994 i2c->adap.owner = THIS_MODULE;
867 i2c->adap.algo = &i2c_pxa_algorithm;
868 i2c->adap.retries = 5; 995 i2c->adap.retries = 5;
869 996
870 spin_lock_init(&i2c->lock); 997 spin_lock_init(&i2c->lock);
@@ -899,34 +1026,28 @@ static int i2c_pxa_probe(struct platform_device *dev)
899#endif 1026#endif
900 1027
901 clk_enable(i2c->clk); 1028 clk_enable(i2c->clk);
902#ifdef CONFIG_PXA27x 1029 i2c_pxa_enable(dev);
903 switch (dev->id) {
904 case 0:
905 pxa_gpio_mode(GPIO117_I2CSCL_MD);
906 pxa_gpio_mode(GPIO118_I2CSDA_MD);
907 break;
908 case 1:
909 local_irq_disable();
910 PCFR |= PCFR_PI2CEN;
911 local_irq_enable();
912 }
913#endif
914 1030
915 ret = request_irq(irq, i2c_pxa_handler, IRQF_DISABLED, 1031 if (plat) {
916 i2c->adap.name, i2c); 1032 i2c->adap.class = plat->class;
917 if (ret) 1033 i2c->use_pio = plat->use_pio;
918 goto ereqirq; 1034 }
919 1035
1036 if (i2c->use_pio) {
1037 i2c->adap.algo = &i2c_pxa_pio_algorithm;
1038 } else {
1039 i2c->adap.algo = &i2c_pxa_algorithm;
1040 ret = request_irq(irq, i2c_pxa_handler, IRQF_DISABLED,
1041 i2c->adap.name, i2c);
1042 if (ret)
1043 goto ereqirq;
1044 }
920 1045
921 i2c_pxa_reset(i2c); 1046 i2c_pxa_reset(i2c);
922 1047
923 i2c->adap.algo_data = i2c; 1048 i2c->adap.algo_data = i2c;
924 i2c->adap.dev.parent = &dev->dev; 1049 i2c->adap.dev.parent = &dev->dev;
925 1050
926 if (plat) {
927 i2c->adap.class = plat->class;
928 }
929
930 /* 1051 /*
931 * If "dev->id" is negative we consider it as zero. 1052 * If "dev->id" is negative we consider it as zero.
932 * The reason to do so is to avoid sysfs names that only make 1053 * The reason to do so is to avoid sysfs names that only make
@@ -952,17 +1073,11 @@ static int i2c_pxa_probe(struct platform_device *dev)
952 return 0; 1073 return 0;
953 1074
954eadapt: 1075eadapt:
955 free_irq(irq, i2c); 1076 if (!i2c->use_pio)
1077 free_irq(irq, i2c);
956ereqirq: 1078ereqirq:
957 clk_disable(i2c->clk); 1079 clk_disable(i2c->clk);
958 1080 i2c_pxa_disable(dev);
959#ifdef CONFIG_PXA27x
960 if (dev->id == 1) {
961 local_irq_disable();
962 PCFR &= ~PCFR_PI2CEN;
963 local_irq_enable();
964 }
965#endif
966eremap: 1081eremap:
967 clk_put(i2c->clk); 1082 clk_put(i2c->clk);
968eclk: 1083eclk:
@@ -979,18 +1094,12 @@ static int i2c_pxa_remove(struct platform_device *dev)
979 platform_set_drvdata(dev, NULL); 1094 platform_set_drvdata(dev, NULL);
980 1095
981 i2c_del_adapter(&i2c->adap); 1096 i2c_del_adapter(&i2c->adap);
982 free_irq(i2c->irq, i2c); 1097 if (!i2c->use_pio)
1098 free_irq(i2c->irq, i2c);
983 1099
984 clk_disable(i2c->clk); 1100 clk_disable(i2c->clk);
985 clk_put(i2c->clk); 1101 clk_put(i2c->clk);
986 1102 i2c_pxa_disable(dev);
987#ifdef CONFIG_PXA27x
988 if (dev->id == 1) {
989 local_irq_disable();
990 PCFR &= ~PCFR_PI2CEN;
991 local_irq_enable();
992 }
993#endif
994 1103
995 release_mem_region(i2c->iobase, i2c->iosize); 1104 release_mem_region(i2c->iobase, i2c->iosize);
996 kfree(i2c); 1105 kfree(i2c);
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c
index 503a134ec803..8fbbdb4c2f35 100644
--- a/drivers/i2c/busses/i2c-sibyte.c
+++ b/drivers/i2c/busses/i2c-sibyte.c
@@ -36,14 +36,6 @@ struct i2c_algo_sibyte_data {
36/* ----- global defines ----------------------------------------------- */ 36/* ----- global defines ----------------------------------------------- */
37#define SMB_CSR(a,r) ((long)(a->reg_base + r)) 37#define SMB_CSR(a,r) ((long)(a->reg_base + r))
38 38
39/* ----- global variables --------------------------------------------- */
40
41/* module parameters:
42 */
43static int bit_scan; /* have a look at what's hanging 'round */
44module_param(bit_scan, int, 0);
45MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
46
47 39
48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr, 40static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
49 unsigned short flags, char read_write, 41 unsigned short flags, char read_write,
@@ -140,9 +132,8 @@ static const struct i2c_algorithm i2c_sibyte_algo = {
140/* 132/*
141 * registering functions to load algorithms at runtime 133 * registering functions to load algorithms at runtime
142 */ 134 */
143int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed) 135int __init i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
144{ 136{
145 int i;
146 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; 137 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
147 138
148 /* register new adapter to i2c module... */ 139 /* register new adapter to i2c module... */
@@ -152,24 +143,6 @@ int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
152 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ)); 143 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
153 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL)); 144 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));
154 145
155 /* scan bus */
156 if (bit_scan) {
157 union i2c_smbus_data data;
158 int rc;
159 printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
160 i2c_adap->name);
161 for (i = 0x00; i < 0x7f; i++) {
162 /* XXXKW is this a realistic probe? */
163 rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0,
164 I2C_SMBUS_BYTE_DATA, &data);
165 if (!rc) {
166 printk("(%02x)",i);
167 } else
168 printk(".");
169 }
170 printk("\n");
171 }
172
173 return i2c_add_adapter(i2c_adap); 146 return i2c_add_adapter(i2c_adap);
174} 147}
175 148
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 84df29da1ddc..c2a9f8c94f5e 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -1,8 +1,8 @@
1/* 1/*
2 i2c-stub.c - Part of lm_sensors, Linux kernel modules for hardware 2 i2c-stub.c - I2C/SMBus chip emulator
3 monitoring
4 3
5 Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com> 4 Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
5 Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
6 6
7 This program is free software; you can redistribute it and/or modify 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 8 it under the terms of the GNU General Public License as published by
@@ -37,8 +37,8 @@ MODULE_PARM_DESC(chip_addr,
37 37
38struct stub_chip { 38struct stub_chip {
39 u8 pointer; 39 u8 pointer;
40 u8 bytes[256]; 40 u16 words[256]; /* Byte operations use the LSB as per SMBus
41 u16 words[256]; 41 specification */
42}; 42};
43 43
44static struct stub_chip *stub_chips; 44static struct stub_chip *stub_chips;
@@ -75,7 +75,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
75 "wrote 0x%02x.\n", 75 "wrote 0x%02x.\n",
76 addr, command); 76 addr, command);
77 } else { 77 } else {
78 data->byte = chip->bytes[chip->pointer++]; 78 data->byte = chip->words[chip->pointer++] & 0xff;
79 dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, " 79 dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, "
80 "read 0x%02x.\n", 80 "read 0x%02x.\n",
81 addr, data->byte); 81 addr, data->byte);
@@ -86,12 +86,13 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
86 86
87 case I2C_SMBUS_BYTE_DATA: 87 case I2C_SMBUS_BYTE_DATA:
88 if (read_write == I2C_SMBUS_WRITE) { 88 if (read_write == I2C_SMBUS_WRITE) {
89 chip->bytes[command] = data->byte; 89 chip->words[command] &= 0xff00;
90 chip->words[command] |= data->byte;
90 dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " 91 dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, "
91 "wrote 0x%02x at 0x%02x.\n", 92 "wrote 0x%02x at 0x%02x.\n",
92 addr, data->byte, command); 93 addr, data->byte, command);
93 } else { 94 } else {
94 data->byte = chip->bytes[command]; 95 data->byte = chip->words[command] & 0xff;
95 dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " 96 dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, "
96 "read 0x%02x at 0x%02x.\n", 97 "read 0x%02x at 0x%02x.\n",
97 addr, data->byte, command); 98 addr, data->byte, command);
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index c9ce77f13c0e..77b13d027f86 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -4,7 +4,7 @@
4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>, 5 Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>,
6 Mark D. Studebaker <mdsxyz123@yahoo.com> 6 Mark D. Studebaker <mdsxyz123@yahoo.com>
7 Copyright (C) 2005 - 2007 Jean Delvare <khali@linux-fr.org> 7 Copyright (C) 2005 - 2008 Jean Delvare <khali@linux-fr.org>
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
@@ -35,6 +35,7 @@
35 VT8235 0x3177 yes 35 VT8235 0x3177 yes
36 VT8237R 0x3227 yes 36 VT8237R 0x3227 yes
37 VT8237A 0x3337 yes 37 VT8237A 0x3337 yes
38 VT8237S 0x3372 yes
38 VT8251 0x3287 yes 39 VT8251 0x3287 yes
39 CX700 0x8324 yes 40 CX700 0x8324 yes
40 41
@@ -318,6 +319,10 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
318 unsigned char temp; 319 unsigned char temp;
319 int error = -ENODEV; 320 int error = -ENODEV;
320 321
322 /* driver_data might come from user-space, so check it */
323 if (id->driver_data & 1 || id->driver_data > 0xff)
324 return -EINVAL;
325
321 /* Determine the address of the SMBus areas */ 326 /* Determine the address of the SMBus areas */
322 if (force_addr) { 327 if (force_addr) {
323 vt596_smba = force_addr & 0xfff0; 328 vt596_smba = force_addr & 0xfff0;
@@ -389,6 +394,7 @@ found:
389 case PCI_DEVICE_ID_VIA_8251: 394 case PCI_DEVICE_ID_VIA_8251:
390 case PCI_DEVICE_ID_VIA_8237: 395 case PCI_DEVICE_ID_VIA_8237:
391 case PCI_DEVICE_ID_VIA_8237A: 396 case PCI_DEVICE_ID_VIA_8237A:
397 case PCI_DEVICE_ID_VIA_8237S:
392 case PCI_DEVICE_ID_VIA_8235: 398 case PCI_DEVICE_ID_VIA_8235:
393 case PCI_DEVICE_ID_VIA_8233A: 399 case PCI_DEVICE_ID_VIA_8233A:
394 case PCI_DEVICE_ID_VIA_8233_0: 400 case PCI_DEVICE_ID_VIA_8233_0:
@@ -440,6 +446,8 @@ static struct pci_device_id vt596_ids[] = {
440 .driver_data = SMBBA3 }, 446 .driver_data = SMBBA3 },
441 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A), 447 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A),
442 .driver_data = SMBBA3 }, 448 .driver_data = SMBBA3 },
449 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237S),
450 .driver_data = SMBBA3 },
443 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4), 451 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4),
444 .driver_data = SMBBA1 }, 452 .driver_data = SMBBA1 },
445 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8251), 453 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8251),
@@ -455,6 +463,7 @@ static struct pci_driver vt596_driver = {
455 .name = "vt596_smbus", 463 .name = "vt596_smbus",
456 .id_table = vt596_ids, 464 .id_table = vt596_ids,
457 .probe = vt596_probe, 465 .probe = vt596_probe,
466 .dynids.use_driver_data = 1,
458}; 467};
459 468
460static int __init i2c_vt596_init(void) 469static int __init i2c_vt596_init(void)
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 2e1c24f671cf..bd7082c2443d 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -4,32 +4,6 @@
4 4
5menu "Miscellaneous I2C Chip support" 5menu "Miscellaneous I2C Chip support"
6 6
7config SENSORS_DS1337
8 tristate "Dallas DS1337 and DS1339 Real Time Clock (DEPRECATED)"
9 depends on EXPERIMENTAL
10 help
11 If you say yes here you get support for Dallas Semiconductor
12 DS1337 and DS1339 real-time clock chips.
13
14 This driver can also be built as a module. If so, the module
15 will be called ds1337.
16
17 This driver is deprecated and will be dropped soon. Use
18 rtc-ds1307 instead.
19
20config SENSORS_DS1374
21 tristate "Dallas DS1374 Real Time Clock (DEPRECATED)"
22 depends on EXPERIMENTAL
23 help
24 If you say yes here you get support for Dallas Semiconductor
25 DS1374 real-time clock chips.
26
27 This driver can also be built as a module. If so, the module
28 will be called ds1374.
29
30 This driver is deprecated and will be dropped soon. Use
31 rtc-ds1374 instead.
32
33config DS1682 7config DS1682
34 tristate "Dallas DS1682 Total Elapsed Time Recorder with Alarm" 8 tristate "Dallas DS1682 Total Elapsed Time Recorder with Alarm"
35 depends on EXPERIMENTAL 9 depends on EXPERIMENTAL
@@ -57,7 +31,7 @@ config SENSORS_PCF8574
57 default n 31 default n
58 help 32 help
59 If you say yes here you get support for Philips PCF8574 and 33 If you say yes here you get support for Philips PCF8574 and
60 PCF8574A chips. 34 PCF8574A chips. These chips are 8-bit I/O expanders for the I2C bus.
61 35
62 This driver can also be built as a module. If so, the module 36 This driver can also be built as a module. If so, the module
63 will be called pcf8574. 37 will be called pcf8574.
@@ -65,6 +39,20 @@ config SENSORS_PCF8574
65 These devices are hard to detect and rarely found on mainstream 39 These devices are hard to detect and rarely found on mainstream
66 hardware. If unsure, say N. 40 hardware. If unsure, say N.
67 41
42config PCF8575
43 tristate "Philips PCF8575"
44 default n
45 help
46 If you say yes here you get support for Philips PCF8575 chip.
47 This chip is a 16-bit I/O expander for the I2C bus. Several other
48 chip manufacturers sell equivalent chips, e.g. Texas Instruments.
49
50 This driver can also be built as a module. If so, the module
51 will be called pcf8575.
52
53 This device is hard to detect and is rarely found on mainstream
54 hardware. If unsure, say N.
55
68config SENSORS_PCA9539 56config SENSORS_PCA9539
69 tristate "Philips PCA9539 16-bit I/O port" 57 tristate "Philips PCA9539 16-bit I/O port"
70 depends on EXPERIMENTAL 58 depends on EXPERIMENTAL
@@ -100,12 +88,8 @@ config ISP1301_OMAP
100 This driver can also be built as a module. If so, the module 88 This driver can also be built as a module. If so, the module
101 will be called isp1301_omap. 89 will be called isp1301_omap.
102 90
103# NOTE: This isn't really OMAP-specific, except for the current
104# interface location in <include/asm-arm/arch-omap/tps65010.h>
105# and having mostly OMAP-specific board support
106config TPS65010 91config TPS65010
107 tristate "TPS6501x Power Management chips" 92 tristate "TPS6501x Power Management chips"
108 depends on ARCH_OMAP
109 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
110 help 94 help
111 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
@@ -116,18 +100,6 @@ config TPS65010
116 This driver can also be built as a module. If so, the module 100 This driver can also be built as a module. If so, the module
117 will be called tps65010. 101 will be called tps65010.
118 102
119config SENSORS_M41T00
120 tristate "ST M41T00 RTC chip (DEPRECATED)"
121 depends on PPC32
122 help
123 If you say yes here you get support for the ST M41T00 RTC chip.
124
125 This driver can also be built as a module. If so, the module
126 will be called m41t00.
127
128 This driver is deprecated and will be dropped soon. Use
129 rtc-ds1307 or rtc-m41t80 instead.
130
131config SENSORS_MAX6875 103config SENSORS_MAX6875
132 tristate "Maxim MAX6875 Power supply supervisor" 104 tristate "Maxim MAX6875 Power supply supervisor"
133 depends on EXPERIMENTAL 105 depends on EXPERIMENTAL
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index ca924e105959..501f00cea782 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -2,14 +2,12 @@
2# Makefile for miscellaneous I2C chip drivers. 2# Makefile for miscellaneous I2C chip drivers.
3# 3#
4 4
5obj-$(CONFIG_SENSORS_DS1337) += ds1337.o
6obj-$(CONFIG_SENSORS_DS1374) += ds1374.o
7obj-$(CONFIG_DS1682) += ds1682.o 5obj-$(CONFIG_DS1682) += ds1682.o
8obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o 6obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
9obj-$(CONFIG_SENSORS_MAX6875) += max6875.o 7obj-$(CONFIG_SENSORS_MAX6875) += max6875.o
10obj-$(CONFIG_SENSORS_M41T00) += m41t00.o
11obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o 8obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o
12obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o 9obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o
10obj-$(CONFIG_PCF8575) += pcf8575.o
13obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 11obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 12obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
15obj-$(CONFIG_TPS65010) += tps65010.o 13obj-$(CONFIG_TPS65010) += tps65010.o
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c
deleted file mode 100644
index ec17d6b684a2..000000000000
--- a/drivers/i2c/chips/ds1337.c
+++ /dev/null
@@ -1,410 +0,0 @@
1/*
2 * linux/drivers/i2c/chips/ds1337.c
3 *
4 * Copyright (C) 2005 James Chapman <jchapman@katalix.com>
5 *
6 * based on linux/drivers/acorn/char/pcf8583.c
7 * Copyright (C) 2000 Russell King
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * Driver for Dallas Semiconductor DS1337 and DS1339 real time clock chip
14 */
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
20#include <linux/string.h>
21#include <linux/rtc.h> /* get the user-level API */
22#include <linux/bcd.h>
23#include <linux/list.h>
24
25/* Device registers */
26#define DS1337_REG_HOUR 2
27#define DS1337_REG_DAY 3
28#define DS1337_REG_DATE 4
29#define DS1337_REG_MONTH 5
30#define DS1337_REG_CONTROL 14
31#define DS1337_REG_STATUS 15
32
33/* FIXME - how do we export these interface constants? */
34#define DS1337_GET_DATE 0
35#define DS1337_SET_DATE 1
36
37/*
38 * Functions declaration
39 */
40static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END };
41
42I2C_CLIENT_INSMOD_1(ds1337);
43
44static int ds1337_attach_adapter(struct i2c_adapter *adapter);
45static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind);
46static void ds1337_init_client(struct i2c_client *client);
47static int ds1337_detach_client(struct i2c_client *client);
48static int ds1337_command(struct i2c_client *client, unsigned int cmd,
49 void *arg);
50
51/*
52 * Driver data (common to all clients)
53 */
54static struct i2c_driver ds1337_driver = {
55 .driver = {
56 .name = "ds1337",
57 },
58 .attach_adapter = ds1337_attach_adapter,
59 .detach_client = ds1337_detach_client,
60 .command = ds1337_command,
61};
62
63/*
64 * Client data (each client gets its own)
65 */
66struct ds1337_data {
67 struct i2c_client client;
68 struct list_head list;
69};
70
71/*
72 * Internal variables
73 */
74static LIST_HEAD(ds1337_clients);
75
76static inline int ds1337_read(struct i2c_client *client, u8 reg, u8 *value)
77{
78 s32 tmp = i2c_smbus_read_byte_data(client, reg);
79
80 if (tmp < 0)
81 return -EIO;
82
83 *value = tmp;
84
85 return 0;
86}
87
88/*
89 * Chip access functions
90 */
91static int ds1337_get_datetime(struct i2c_client *client, struct rtc_time *dt)
92{
93 int result;
94 u8 buf[7];
95 u8 val;
96 struct i2c_msg msg[2];
97 u8 offs = 0;
98
99 if (!dt) {
100 dev_dbg(&client->dev, "%s: EINVAL: dt=NULL\n", __FUNCTION__);
101 return -EINVAL;
102 }
103
104 msg[0].addr = client->addr;
105 msg[0].flags = 0;
106 msg[0].len = 1;
107 msg[0].buf = &offs;
108
109 msg[1].addr = client->addr;
110 msg[1].flags = I2C_M_RD;
111 msg[1].len = sizeof(buf);
112 msg[1].buf = &buf[0];
113
114 result = i2c_transfer(client->adapter, msg, 2);
115
116 dev_dbg(&client->dev, "%s: [%d] %02x %02x %02x %02x %02x %02x %02x\n",
117 __FUNCTION__, result, buf[0], buf[1], buf[2], buf[3],
118 buf[4], buf[5], buf[6]);
119
120 if (result == 2) {
121 dt->tm_sec = BCD2BIN(buf[0]);
122 dt->tm_min = BCD2BIN(buf[1]);
123 val = buf[2] & 0x3f;
124 dt->tm_hour = BCD2BIN(val);
125 dt->tm_wday = BCD2BIN(buf[3]) - 1;
126 dt->tm_mday = BCD2BIN(buf[4]);
127 val = buf[5] & 0x7f;
128 dt->tm_mon = BCD2BIN(val) - 1;
129 dt->tm_year = BCD2BIN(buf[6]);
130 if (buf[5] & 0x80)
131 dt->tm_year += 100;
132
133 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, "
134 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
135 __FUNCTION__, dt->tm_sec, dt->tm_min,
136 dt->tm_hour, dt->tm_mday,
137 dt->tm_mon, dt->tm_year, dt->tm_wday);
138
139 return 0;
140 }
141
142 dev_err(&client->dev, "error reading data! %d\n", result);
143 return -EIO;
144}
145
146static int ds1337_set_datetime(struct i2c_client *client, struct rtc_time *dt)
147{
148 int result;
149 u8 buf[8];
150 u8 val;
151 struct i2c_msg msg[1];
152
153 if (!dt) {
154 dev_dbg(&client->dev, "%s: EINVAL: dt=NULL\n", __FUNCTION__);
155 return -EINVAL;
156 }
157
158 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
159 "mday=%d, mon=%d, year=%d, wday=%d\n", __FUNCTION__,
160 dt->tm_sec, dt->tm_min, dt->tm_hour,
161 dt->tm_mday, dt->tm_mon, dt->tm_year, dt->tm_wday);
162
163 buf[0] = 0; /* reg offset */
164 buf[1] = BIN2BCD(dt->tm_sec);
165 buf[2] = BIN2BCD(dt->tm_min);
166 buf[3] = BIN2BCD(dt->tm_hour);
167 buf[4] = BIN2BCD(dt->tm_wday + 1);
168 buf[5] = BIN2BCD(dt->tm_mday);
169 buf[6] = BIN2BCD(dt->tm_mon + 1);
170 val = dt->tm_year;
171 if (val >= 100) {
172 val -= 100;
173 buf[6] |= (1 << 7);
174 }
175 buf[7] = BIN2BCD(val);
176
177 msg[0].addr = client->addr;
178 msg[0].flags = 0;
179 msg[0].len = sizeof(buf);
180 msg[0].buf = &buf[0];
181
182 result = i2c_transfer(client->adapter, msg, 1);
183 if (result == 1)
184 return 0;
185
186 dev_err(&client->dev, "error writing data! %d\n", result);
187 return -EIO;
188}
189
190static int ds1337_command(struct i2c_client *client, unsigned int cmd,
191 void *arg)
192{
193 dev_dbg(&client->dev, "%s: cmd=%d\n", __FUNCTION__, cmd);
194
195 switch (cmd) {
196 case DS1337_GET_DATE:
197 return ds1337_get_datetime(client, arg);
198
199 case DS1337_SET_DATE:
200 return ds1337_set_datetime(client, arg);
201
202 default:
203 return -EINVAL;
204 }
205}
206
207/*
208 * Public API for access to specific device. Useful for low-level
209 * RTC access from kernel code.
210 */
211int ds1337_do_command(int bus, int cmd, void *arg)
212{
213 struct list_head *walk;
214 struct list_head *tmp;
215 struct ds1337_data *data;
216
217 list_for_each_safe(walk, tmp, &ds1337_clients) {
218 data = list_entry(walk, struct ds1337_data, list);
219 if (data->client.adapter->nr == bus)
220 return ds1337_command(&data->client, cmd, arg);
221 }
222
223 return -ENODEV;
224}
225
226static int ds1337_attach_adapter(struct i2c_adapter *adapter)
227{
228 return i2c_probe(adapter, &addr_data, ds1337_detect);
229}
230
231/*
232 * The following function does more than just detection. If detection
233 * succeeds, it also registers the new chip.
234 */
235static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind)
236{
237 struct i2c_client *new_client;
238 struct ds1337_data *data;
239 int err = 0;
240 const char *name = "";
241
242 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
243 I2C_FUNC_I2C))
244 goto exit;
245
246 if (!(data = kzalloc(sizeof(struct ds1337_data), GFP_KERNEL))) {
247 err = -ENOMEM;
248 goto exit;
249 }
250 INIT_LIST_HEAD(&data->list);
251
252 /* The common I2C client data is placed right before the
253 * DS1337-specific data.
254 */
255 new_client = &data->client;
256 i2c_set_clientdata(new_client, data);
257 new_client->addr = address;
258 new_client->adapter = adapter;
259 new_client->driver = &ds1337_driver;
260 new_client->flags = 0;
261
262 /*
263 * Now we do the remaining detection. A negative kind means that
264 * the driver was loaded with no force parameter (default), so we
265 * must both detect and identify the chip. A zero kind means that
266 * the driver was loaded with the force parameter, the detection
267 * step shall be skipped. A positive kind means that the driver
268 * was loaded with the force parameter and a given kind of chip is
269 * requested, so both the detection and the identification steps
270 * are skipped.
271 *
272 * For detection, we read registers that are most likely to cause
273 * detection failure, i.e. those that have more bits with fixed
274 * or reserved values.
275 */
276
277 /* Default to an DS1337 if forced */
278 if (kind == 0)
279 kind = ds1337;
280
281 if (kind < 0) { /* detection and identification */
282 u8 data;
283
284 /* Check that status register bits 6-2 are zero */
285 if ((ds1337_read(new_client, DS1337_REG_STATUS, &data) < 0) ||
286 (data & 0x7c))
287 goto exit_free;
288
289 /* Check for a valid day register value */
290 if ((ds1337_read(new_client, DS1337_REG_DAY, &data) < 0) ||
291 (data == 0) || (data & 0xf8))
292 goto exit_free;
293
294 /* Check for a valid date register value */
295 if ((ds1337_read(new_client, DS1337_REG_DATE, &data) < 0) ||
296 (data == 0) || (data & 0xc0) || ((data & 0x0f) > 9) ||
297 (data >= 0x32))
298 goto exit_free;
299
300 /* Check for a valid month register value */
301 if ((ds1337_read(new_client, DS1337_REG_MONTH, &data) < 0) ||
302 (data == 0) || (data & 0x60) || ((data & 0x0f) > 9) ||
303 ((data >= 0x13) && (data <= 0x19)))
304 goto exit_free;
305
306 /* Check that control register bits 6-5 are zero */
307 if ((ds1337_read(new_client, DS1337_REG_CONTROL, &data) < 0) ||
308 (data & 0x60))
309 goto exit_free;
310
311 kind = ds1337;
312 }
313
314 if (kind == ds1337)
315 name = "ds1337";
316
317 /* We can fill in the remaining client fields */
318 strlcpy(new_client->name, name, I2C_NAME_SIZE);
319
320 /* Tell the I2C layer a new client has arrived */
321 if ((err = i2c_attach_client(new_client)))
322 goto exit_free;
323
324 /* Initialize the DS1337 chip */
325 ds1337_init_client(new_client);
326
327 /* Add client to local list */
328 list_add(&data->list, &ds1337_clients);
329
330 return 0;
331
332exit_free:
333 kfree(data);
334exit:
335 return err;
336}
337
338static void ds1337_init_client(struct i2c_client *client)
339{
340 u8 status, control;
341
342 /* On some boards, the RTC isn't configured by boot firmware.
343 * Handle that case by starting/configuring the RTC now.
344 */
345 status = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS);
346 control = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
347
348 if ((status & 0x80) || (control & 0x80)) {
349 /* RTC not running */
350 u8 buf[1+16]; /* First byte is interpreted as address */
351 struct i2c_msg msg[1];
352
353 dev_dbg(&client->dev, "%s: RTC not running!\n", __FUNCTION__);
354
355 /* Initialize all, including STATUS and CONTROL to zero */
356 memset(buf, 0, sizeof(buf));
357
358 /* Write valid values in the date/time registers */
359 buf[1+DS1337_REG_DAY] = 1;
360 buf[1+DS1337_REG_DATE] = 1;
361 buf[1+DS1337_REG_MONTH] = 1;
362
363 msg[0].addr = client->addr;
364 msg[0].flags = 0;
365 msg[0].len = sizeof(buf);
366 msg[0].buf = &buf[0];
367
368 i2c_transfer(client->adapter, msg, 1);
369 } else {
370 /* Running: ensure that device is set in 24-hour mode */
371 s32 val;
372
373 val = i2c_smbus_read_byte_data(client, DS1337_REG_HOUR);
374 if ((val >= 0) && (val & (1 << 6)))
375 i2c_smbus_write_byte_data(client, DS1337_REG_HOUR,
376 val & 0x3f);
377 }
378}
379
380static int ds1337_detach_client(struct i2c_client *client)
381{
382 int err;
383 struct ds1337_data *data = i2c_get_clientdata(client);
384
385 if ((err = i2c_detach_client(client)))
386 return err;
387
388 list_del(&data->list);
389 kfree(data);
390 return 0;
391}
392
393static int __init ds1337_init(void)
394{
395 return i2c_add_driver(&ds1337_driver);
396}
397
398static void __exit ds1337_exit(void)
399{
400 i2c_del_driver(&ds1337_driver);
401}
402
403MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
404MODULE_DESCRIPTION("DS1337 RTC driver");
405MODULE_LICENSE("GPL");
406
407EXPORT_SYMBOL_GPL(ds1337_do_command);
408
409module_init(ds1337_init);
410module_exit(ds1337_exit);
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
deleted file mode 100644
index 8a2ff0c114d9..000000000000
--- a/drivers/i2c/chips/ds1374.c
+++ /dev/null
@@ -1,267 +0,0 @@
1/*
2 * drivers/i2c/chips/ds1374.c
3 *
4 * I2C client/driver for the Maxim/Dallas DS1374 Real-Time Clock
5 *
6 * Author: Randy Vinson <rvinson@mvista.com>
7 *
8 * Based on the m41t00.c by Mark Greer <mgreer@mvista.com>
9 *
10 * 2005 (c) MontaVista Software, Inc. This file is licensed under
11 * the terms of the GNU General Public License version 2. This program
12 * is licensed "as is" without any warranty of any kind, whether express
13 * or implied.
14 */
15/*
16 * This i2c client/driver wedges between the drivers/char/genrtc.c RTC
17 * interface and the SMBus interface of the i2c subsystem.
18 * It would be more efficient to use i2c msgs/i2c_transfer directly but, as
19 * recommened in .../Documentation/i2c/writing-clients section
20 * "Sending and receiving", using SMBus level communication is preferred.
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/interrupt.h>
26#include <linux/i2c.h>
27#include <linux/rtc.h>
28#include <linux/bcd.h>
29#include <linux/mutex.h>
30#include <linux/workqueue.h>
31
32#define DS1374_REG_TOD0 0x00
33#define DS1374_REG_TOD1 0x01
34#define DS1374_REG_TOD2 0x02
35#define DS1374_REG_TOD3 0x03
36#define DS1374_REG_WDALM0 0x04
37#define DS1374_REG_WDALM1 0x05
38#define DS1374_REG_WDALM2 0x06
39#define DS1374_REG_CR 0x07
40#define DS1374_REG_SR 0x08
41#define DS1374_REG_SR_OSF 0x80
42#define DS1374_REG_TCR 0x09
43
44#define DS1374_DRV_NAME "ds1374"
45
46static DEFINE_MUTEX(ds1374_mutex);
47
48static struct i2c_driver ds1374_driver;
49static struct i2c_client *save_client;
50
51static unsigned short ignore[] = { I2C_CLIENT_END };
52static unsigned short normal_addr[] = { 0x68, I2C_CLIENT_END };
53
54static struct i2c_client_address_data addr_data = {
55 .normal_i2c = normal_addr,
56 .probe = ignore,
57 .ignore = ignore,
58};
59
60static ulong ds1374_read_rtc(void)
61{
62 ulong time = 0;
63 int reg = DS1374_REG_WDALM0;
64
65 while (reg--) {
66 s32 tmp;
67 if ((tmp = i2c_smbus_read_byte_data(save_client, reg)) < 0) {
68 dev_warn(&save_client->dev,
69 "can't read from rtc chip\n");
70 return 0;
71 }
72 time = (time << 8) | (tmp & 0xff);
73 }
74 return time;
75}
76
77static void ds1374_write_rtc(ulong time)
78{
79 int reg;
80
81 for (reg = DS1374_REG_TOD0; reg < DS1374_REG_WDALM0; reg++) {
82 if (i2c_smbus_write_byte_data(save_client, reg, time & 0xff)
83 < 0) {
84 dev_warn(&save_client->dev,
85 "can't write to rtc chip\n");
86 break;
87 }
88 time = time >> 8;
89 }
90}
91
92static void ds1374_check_rtc_status(void)
93{
94 s32 tmp;
95
96 tmp = i2c_smbus_read_byte_data(save_client, DS1374_REG_SR);
97 if (tmp < 0) {
98 dev_warn(&save_client->dev,
99 "can't read status from rtc chip\n");
100 return;
101 }
102 if (tmp & DS1374_REG_SR_OSF) {
103 dev_warn(&save_client->dev,
104 "oscillator discontinuity flagged, time unreliable\n");
105 tmp &= ~DS1374_REG_SR_OSF;
106 tmp = i2c_smbus_write_byte_data(save_client, DS1374_REG_SR,
107 tmp & 0xff);
108 if (tmp < 0)
109 dev_warn(&save_client->dev,
110 "can't clear discontinuity notification\n");
111 }
112}
113
114ulong ds1374_get_rtc_time(void)
115{
116 ulong t1, t2;
117 int limit = 10; /* arbitrary retry limit */
118
119 mutex_lock(&ds1374_mutex);
120
121 /*
122 * Since the reads are being performed one byte at a time using
123 * the SMBus vs a 4-byte i2c transfer, there is a chance that a
124 * carry will occur during the read. To detect this, 2 reads are
125 * performed and compared.
126 */
127 do {
128 t1 = ds1374_read_rtc();
129 t2 = ds1374_read_rtc();
130 } while (t1 != t2 && limit--);
131
132 mutex_unlock(&ds1374_mutex);
133
134 if (t1 != t2) {
135 dev_warn(&save_client->dev,
136 "can't get consistent time from rtc chip\n");
137 t1 = 0;
138 }
139
140 return t1;
141}
142
143static ulong new_time;
144
145static void ds1374_set_work(struct work_struct *work)
146{
147 ulong t1, t2;
148 int limit = 10; /* arbitrary retry limit */
149
150 t1 = new_time;
151
152 mutex_lock(&ds1374_mutex);
153
154 /*
155 * Since the writes are being performed one byte at a time using
156 * the SMBus vs a 4-byte i2c transfer, there is a chance that a
157 * carry will occur during the write. To detect this, the write
158 * value is read back and compared.
159 */
160 do {
161 ds1374_write_rtc(t1);
162 t2 = ds1374_read_rtc();
163 } while (t1 != t2 && limit--);
164
165 mutex_unlock(&ds1374_mutex);
166
167 if (t1 != t2)
168 dev_warn(&save_client->dev,
169 "can't confirm time set from rtc chip\n");
170}
171
172static struct workqueue_struct *ds1374_workqueue;
173
174static DECLARE_WORK(ds1374_work, ds1374_set_work);
175
176int ds1374_set_rtc_time(ulong nowtime)
177{
178 new_time = nowtime;
179
180 if (in_interrupt())
181 queue_work(ds1374_workqueue, &ds1374_work);
182 else
183 ds1374_set_work(NULL);
184
185 return 0;
186}
187
188/*
189 *****************************************************************************
190 *
191 * Driver Interface
192 *
193 *****************************************************************************
194 */
195static int ds1374_probe(struct i2c_adapter *adap, int addr, int kind)
196{
197 struct i2c_client *client;
198 int rc;
199
200 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
201 if (!client)
202 return -ENOMEM;
203
204 strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE);
205 client->addr = addr;
206 client->adapter = adap;
207 client->driver = &ds1374_driver;
208
209 ds1374_workqueue = create_singlethread_workqueue("ds1374");
210 if (!ds1374_workqueue) {
211 kfree(client);
212 return -ENOMEM; /* most expected reason */
213 }
214
215 if ((rc = i2c_attach_client(client)) != 0) {
216 kfree(client);
217 return rc;
218 }
219
220 save_client = client;
221
222 ds1374_check_rtc_status();
223
224 return 0;
225}
226
227static int ds1374_attach(struct i2c_adapter *adap)
228{
229 return i2c_probe(adap, &addr_data, ds1374_probe);
230}
231
232static int ds1374_detach(struct i2c_client *client)
233{
234 int rc;
235
236 if ((rc = i2c_detach_client(client)) == 0) {
237 kfree(i2c_get_clientdata(client));
238 destroy_workqueue(ds1374_workqueue);
239 }
240 return rc;
241}
242
243static struct i2c_driver ds1374_driver = {
244 .driver = {
245 .name = DS1374_DRV_NAME,
246 },
247 .id = I2C_DRIVERID_DS1374,
248 .attach_adapter = ds1374_attach,
249 .detach_client = ds1374_detach,
250};
251
252static int __init ds1374_init(void)
253{
254 return i2c_add_driver(&ds1374_driver);
255}
256
257static void __exit ds1374_exit(void)
258{
259 i2c_del_driver(&ds1374_driver);
260}
261
262module_init(ds1374_init);
263module_exit(ds1374_exit);
264
265MODULE_AUTHOR("Randy Vinson <rvinson@mvista.com>");
266MODULE_DESCRIPTION("Maxim/Dallas DS1374 RTC I2C Client Driver");
267MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index 1a7eeebac506..fde297b21ad7 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -35,7 +35,7 @@
35#include <linux/mutex.h> 35#include <linux/mutex.h>
36 36
37/* Addresses to scan */ 37/* Addresses to scan */
38static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54, 38static const unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
39 0x55, 0x56, 0x57, I2C_CLIENT_END }; 39 0x55, 0x56, 0x57, I2C_CLIENT_END };
40 40
41/* Insmod parameters */ 41/* Insmod parameters */
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index ebfbb2947ae6..2a3160153f54 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -100,7 +100,7 @@ struct isp1301 {
100 100
101#if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE) 101#if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
102 102
103#include <asm/arch/tps65010.h> 103#include <linux/i2c/tps65010.h>
104 104
105#else 105#else
106 106
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
deleted file mode 100644
index 3fcb646e2073..000000000000
--- a/drivers/i2c/chips/m41t00.c
+++ /dev/null
@@ -1,413 +0,0 @@
1/*
2 * I2C client/driver for the ST M41T00 family of i2c rtc chips.
3 *
4 * Author: Mark A. Greer <mgreer@mvista.com>
5 *
6 * 2005, 2006 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11/*
12 * This i2c client/driver wedges between the drivers/char/genrtc.c RTC
13 * interface and the SMBus interface of the i2c subsystem.
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/interrupt.h>
19#include <linux/i2c.h>
20#include <linux/rtc.h>
21#include <linux/bcd.h>
22#include <linux/workqueue.h>
23#include <linux/platform_device.h>
24#include <linux/m41t00.h>
25#include <asm/time.h>
26#include <asm/rtc.h>
27
28static struct i2c_driver m41t00_driver;
29static struct i2c_client *save_client;
30
31static unsigned short ignore[] = { I2C_CLIENT_END };
32static unsigned short normal_addr[] = { I2C_CLIENT_END, I2C_CLIENT_END };
33
34static struct i2c_client_address_data addr_data = {
35 .normal_i2c = normal_addr,
36 .probe = ignore,
37 .ignore = ignore,
38};
39
40struct m41t00_chip_info {
41 u8 type;
42 char *name;
43 u8 read_limit;
44 u8 sec; /* Offsets for chip regs */
45 u8 min;
46 u8 hour;
47 u8 day;
48 u8 mon;
49 u8 year;
50 u8 alarm_mon;
51 u8 alarm_hour;
52 u8 sqw;
53 u8 sqw_freq;
54};
55
56static struct m41t00_chip_info m41t00_chip_info_tbl[] = {
57 {
58 .type = M41T00_TYPE_M41T00,
59 .name = "m41t00",
60 .read_limit = 5,
61 .sec = 0,
62 .min = 1,
63 .hour = 2,
64 .day = 4,
65 .mon = 5,
66 .year = 6,
67 },
68 {
69 .type = M41T00_TYPE_M41T81,
70 .name = "m41t81",
71 .read_limit = 1,
72 .sec = 1,
73 .min = 2,
74 .hour = 3,
75 .day = 5,
76 .mon = 6,
77 .year = 7,
78 .alarm_mon = 0xa,
79 .alarm_hour = 0xc,
80 .sqw = 0x13,
81 },
82 {
83 .type = M41T00_TYPE_M41T85,
84 .name = "m41t85",
85 .read_limit = 1,
86 .sec = 1,
87 .min = 2,
88 .hour = 3,
89 .day = 5,
90 .mon = 6,
91 .year = 7,
92 .alarm_mon = 0xa,
93 .alarm_hour = 0xc,
94 .sqw = 0x13,
95 },
96};
97static struct m41t00_chip_info *m41t00_chip;
98
99ulong
100m41t00_get_rtc_time(void)
101{
102 s32 sec, min, hour, day, mon, year;
103 s32 sec1, min1, hour1, day1, mon1, year1;
104 u8 reads = 0;
105 u8 buf[8], msgbuf[1] = { 0 }; /* offset into rtc's regs */
106 struct i2c_msg msgs[] = {
107 {
108 .addr = save_client->addr,
109 .flags = 0,
110 .len = 1,
111 .buf = msgbuf,
112 },
113 {
114 .addr = save_client->addr,
115 .flags = I2C_M_RD,
116 .len = 8,
117 .buf = buf,
118 },
119 };
120
121 sec = min = hour = day = mon = year = 0;
122
123 do {
124 if (i2c_transfer(save_client->adapter, msgs, 2) < 0)
125 goto read_err;
126
127 sec1 = sec;
128 min1 = min;
129 hour1 = hour;
130 day1 = day;
131 mon1 = mon;
132 year1 = year;
133
134 sec = buf[m41t00_chip->sec] & 0x7f;
135 min = buf[m41t00_chip->min] & 0x7f;
136 hour = buf[m41t00_chip->hour] & 0x3f;
137 day = buf[m41t00_chip->day] & 0x3f;
138 mon = buf[m41t00_chip->mon] & 0x1f;
139 year = buf[m41t00_chip->year];
140 } while ((++reads < m41t00_chip->read_limit) && ((sec != sec1)
141 || (min != min1) || (hour != hour1) || (day != day1)
142 || (mon != mon1) || (year != year1)));
143
144 if ((m41t00_chip->read_limit > 1) && ((sec != sec1) || (min != min1)
145 || (hour != hour1) || (day != day1) || (mon != mon1)
146 || (year != year1)))
147 goto read_err;
148
149 sec = BCD2BIN(sec);
150 min = BCD2BIN(min);
151 hour = BCD2BIN(hour);
152 day = BCD2BIN(day);
153 mon = BCD2BIN(mon);
154 year = BCD2BIN(year);
155
156 year += 1900;
157 if (year < 1970)
158 year += 100;
159
160 return mktime(year, mon, day, hour, min, sec);
161
162read_err:
163 dev_err(&save_client->dev, "m41t00_get_rtc_time: Read error\n");
164 return 0;
165}
166EXPORT_SYMBOL_GPL(m41t00_get_rtc_time);
167
168static void
169m41t00_set(void *arg)
170{
171 struct rtc_time tm;
172 int nowtime = *(int *)arg;
173 s32 sec, min, hour, day, mon, year;
174 u8 wbuf[9], *buf = &wbuf[1], msgbuf[1] = { 0 };
175 struct i2c_msg msgs[] = {
176 {
177 .addr = save_client->addr,
178 .flags = 0,
179 .len = 1,
180 .buf = msgbuf,
181 },
182 {
183 .addr = save_client->addr,
184 .flags = I2C_M_RD,
185 .len = 8,
186 .buf = buf,
187 },
188 };
189
190 to_tm(nowtime, &tm);
191 tm.tm_year = (tm.tm_year - 1900) % 100;
192
193 sec = BIN2BCD(tm.tm_sec);
194 min = BIN2BCD(tm.tm_min);
195 hour = BIN2BCD(tm.tm_hour);
196 day = BIN2BCD(tm.tm_mday);
197 mon = BIN2BCD(tm.tm_mon);
198 year = BIN2BCD(tm.tm_year);
199
200 /* Read reg values into buf[0..7]/wbuf[1..8] */
201 if (i2c_transfer(save_client->adapter, msgs, 2) < 0) {
202 dev_err(&save_client->dev, "m41t00_set: Read error\n");
203 return;
204 }
205
206 wbuf[0] = 0; /* offset into rtc's regs */
207 buf[m41t00_chip->sec] = (buf[m41t00_chip->sec] & ~0x7f) | (sec & 0x7f);
208 buf[m41t00_chip->min] = (buf[m41t00_chip->min] & ~0x7f) | (min & 0x7f);
209 buf[m41t00_chip->hour] = (buf[m41t00_chip->hour] & ~0x3f) | (hour& 0x3f);
210 buf[m41t00_chip->day] = (buf[m41t00_chip->day] & ~0x3f) | (day & 0x3f);
211 buf[m41t00_chip->mon] = (buf[m41t00_chip->mon] & ~0x1f) | (mon & 0x1f);
212 buf[m41t00_chip->year] = year;
213
214 if (i2c_master_send(save_client, wbuf, 9) < 0)
215 dev_err(&save_client->dev, "m41t00_set: Write error\n");
216}
217
218static ulong new_time;
219/* well, isn't this API just _lovely_? */
220static void
221m41t00_barf(struct work_struct *unusable)
222{
223 m41t00_set(&new_time);
224}
225
226static struct workqueue_struct *m41t00_wq;
227static DECLARE_WORK(m41t00_work, m41t00_barf);
228
229int
230m41t00_set_rtc_time(ulong nowtime)
231{
232 new_time = nowtime;
233
234 if (in_interrupt())
235 queue_work(m41t00_wq, &m41t00_work);
236 else
237 m41t00_set(&new_time);
238
239 return 0;
240}
241EXPORT_SYMBOL_GPL(m41t00_set_rtc_time);
242
243/*
244 *****************************************************************************
245 *
246 * platform_data Driver Interface
247 *
248 *****************************************************************************
249 */
250static int __init
251m41t00_platform_probe(struct platform_device *pdev)
252{
253 struct m41t00_platform_data *pdata;
254 int i;
255
256 if (pdev && (pdata = pdev->dev.platform_data)) {
257 normal_addr[0] = pdata->i2c_addr;
258
259 for (i=0; i<ARRAY_SIZE(m41t00_chip_info_tbl); i++)
260 if (m41t00_chip_info_tbl[i].type == pdata->type) {
261 m41t00_chip = &m41t00_chip_info_tbl[i];
262 m41t00_chip->sqw_freq = pdata->sqw_freq;
263 return 0;
264 }
265 }
266 return -ENODEV;
267}
268
269static int __exit
270m41t00_platform_remove(struct platform_device *pdev)
271{
272 return 0;
273}
274
275static struct platform_driver m41t00_platform_driver = {
276 .probe = m41t00_platform_probe,
277 .remove = m41t00_platform_remove,
278 .driver = {
279 .owner = THIS_MODULE,
280 .name = M41T00_DRV_NAME,
281 },
282};
283
284/*
285 *****************************************************************************
286 *
287 * Driver Interface
288 *
289 *****************************************************************************
290 */
291static int
292m41t00_probe(struct i2c_adapter *adap, int addr, int kind)
293{
294 struct i2c_client *client;
295 int rc;
296
297 if (!i2c_check_functionality(adap, I2C_FUNC_I2C
298 | I2C_FUNC_SMBUS_BYTE_DATA))
299 return 0;
300
301 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
302 if (!client)
303 return -ENOMEM;
304
305 strlcpy(client->name, m41t00_chip->name, I2C_NAME_SIZE);
306 client->addr = addr;
307 client->adapter = adap;
308 client->driver = &m41t00_driver;
309
310 if ((rc = i2c_attach_client(client)))
311 goto attach_err;
312
313 if (m41t00_chip->type != M41T00_TYPE_M41T00) {
314 /* If asked, disable SQW, set SQW frequency & re-enable */
315 if (m41t00_chip->sqw_freq)
316 if (((rc = i2c_smbus_read_byte_data(client,
317 m41t00_chip->alarm_mon)) < 0)
318 || ((rc = i2c_smbus_write_byte_data(client,
319 m41t00_chip->alarm_mon, rc & ~0x40)) <0)
320 || ((rc = i2c_smbus_write_byte_data(client,
321 m41t00_chip->sqw,
322 m41t00_chip->sqw_freq)) < 0)
323 || ((rc = i2c_smbus_write_byte_data(client,
324 m41t00_chip->alarm_mon, rc | 0x40)) <0))
325 goto sqw_err;
326
327 /* Make sure HT (Halt Update) bit is cleared */
328 if ((rc = i2c_smbus_read_byte_data(client,
329 m41t00_chip->alarm_hour)) < 0)
330 goto ht_err;
331
332 if (rc & 0x40)
333 if ((rc = i2c_smbus_write_byte_data(client,
334 m41t00_chip->alarm_hour, rc & ~0x40))<0)
335 goto ht_err;
336 }
337
338 /* Make sure ST (stop) bit is cleared */
339 if ((rc = i2c_smbus_read_byte_data(client, m41t00_chip->sec)) < 0)
340 goto st_err;
341
342 if (rc & 0x80)
343 if ((rc = i2c_smbus_write_byte_data(client, m41t00_chip->sec,
344 rc & ~0x80)) < 0)
345 goto st_err;
346
347 m41t00_wq = create_singlethread_workqueue(m41t00_chip->name);
348 save_client = client;
349 return 0;
350
351st_err:
352 dev_err(&client->dev, "m41t00_probe: Can't clear ST bit\n");
353 goto attach_err;
354ht_err:
355 dev_err(&client->dev, "m41t00_probe: Can't clear HT bit\n");
356 goto attach_err;
357sqw_err:
358 dev_err(&client->dev, "m41t00_probe: Can't set SQW Frequency\n");
359attach_err:
360 kfree(client);
361 return rc;
362}
363
364static int
365m41t00_attach(struct i2c_adapter *adap)
366{
367 return i2c_probe(adap, &addr_data, m41t00_probe);
368}
369
370static int
371m41t00_detach(struct i2c_client *client)
372{
373 int rc;
374
375 if ((rc = i2c_detach_client(client)) == 0) {
376 kfree(client);
377 destroy_workqueue(m41t00_wq);
378 }
379 return rc;
380}
381
382static struct i2c_driver m41t00_driver = {
383 .driver = {
384 .name = M41T00_DRV_NAME,
385 },
386 .id = I2C_DRIVERID_STM41T00,
387 .attach_adapter = m41t00_attach,
388 .detach_client = m41t00_detach,
389};
390
391static int __init
392m41t00_init(void)
393{
394 int rc;
395
396 if (!(rc = platform_driver_register(&m41t00_platform_driver)))
397 rc = i2c_add_driver(&m41t00_driver);
398 return rc;
399}
400
401static void __exit
402m41t00_exit(void)
403{
404 i2c_del_driver(&m41t00_driver);
405 platform_driver_unregister(&m41t00_platform_driver);
406}
407
408module_init(m41t00_init);
409module_exit(m41t00_exit);
410
411MODULE_AUTHOR("Mark A. Greer <mgreer@mvista.com>");
412MODULE_DESCRIPTION("ST Microelectronics M41T00 RTC I2C Client Driver");
413MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 64692f666372..fb7ea5637eca 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -34,7 +34,7 @@
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35 35
36/* Do not scan - the MAX6875 access method will write to some EEPROM chips */ 36/* Do not scan - the MAX6875 access method will write to some EEPROM chips */
37static unsigned short normal_i2c[] = {I2C_CLIENT_END}; 37static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
38 38
39/* Insmod parameters */ 39/* Insmod parameters */
40I2C_CLIENT_INSMOD_1(max6875); 40I2C_CLIENT_INSMOD_1(max6875);
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index 21c6dd69193c..b3b830ccf209 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -41,9 +41,11 @@
41#include <linux/i2c.h> 41#include <linux/i2c.h>
42 42
43/* Addresses to scan */ 43/* Addresses to scan */
44static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 44static const unsigned short normal_i2c[] = {
45 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 45 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
46 I2C_CLIENT_END }; 46 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
47 I2C_CLIENT_END
48};
47 49
48/* Insmod parameters */ 50/* Insmod parameters */
49I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); 51I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
diff --git a/drivers/i2c/chips/pcf8575.c b/drivers/i2c/chips/pcf8575.c
new file mode 100644
index 000000000000..3ea08ac0bfa3
--- /dev/null
+++ b/drivers/i2c/chips/pcf8575.c
@@ -0,0 +1,214 @@
1/*
2 pcf8575.c
3
4 About the PCF8575 chip: the PCF8575 is a 16-bit I/O expander for the I2C bus
5 produced by a.o. Philips Semiconductors.
6
7 Copyright (C) 2006 Michael Hennerich, Analog Devices Inc.
8 <hennerich@blackfin.uclinux.org>
9 Based on pcf8574.c.
10
11 Copyright (c) 2007 Bart Van Assche <bart.vanassche@gmail.com>.
12 Ported this driver from ucLinux to the mainstream Linux kernel.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/
28
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/i2c.h>
32#include <linux/slab.h> /* kzalloc() */
33#include <linux/sysfs.h> /* sysfs_create_group() */
34
35/* Addresses to scan */
36static const unsigned short normal_i2c[] = {
37 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
38 I2C_CLIENT_END
39};
40
41/* Insmod parameters */
42I2C_CLIENT_INSMOD;
43
44
45/* Each client has this additional data */
46struct pcf8575_data {
47 struct i2c_client client;
48 int write; /* last written value, or error code */
49};
50
51static int pcf8575_attach_adapter(struct i2c_adapter *adapter);
52static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind);
53static int pcf8575_detach_client(struct i2c_client *client);
54
55/* This is the driver that will be inserted */
56static struct i2c_driver pcf8575_driver = {
57 .driver = {
58 .owner = THIS_MODULE,
59 .name = "pcf8575",
60 },
61 .attach_adapter = pcf8575_attach_adapter,
62 .detach_client = pcf8575_detach_client,
63};
64
65/* following are the sysfs callback functions */
66static ssize_t show_read(struct device *dev, struct device_attribute *attr,
67 char *buf)
68{
69 struct i2c_client *client = to_i2c_client(dev);
70 u16 val;
71 u8 iopin_state[2];
72
73 i2c_master_recv(client, iopin_state, 2);
74
75 val = iopin_state[0];
76 val |= iopin_state[1] << 8;
77
78 return sprintf(buf, "%u\n", val);
79}
80
81static DEVICE_ATTR(read, S_IRUGO, show_read, NULL);
82
83static ssize_t show_write(struct device *dev, struct device_attribute *attr,
84 char *buf)
85{
86 struct pcf8575_data *data = dev_get_drvdata(dev);
87 if (data->write < 0)
88 return data->write;
89 return sprintf(buf, "%d\n", data->write);
90}
91
92static ssize_t set_write(struct device *dev, struct device_attribute *attr,
93 const char *buf, size_t count)
94{
95 struct i2c_client *client = to_i2c_client(dev);
96 struct pcf8575_data *data = i2c_get_clientdata(client);
97 unsigned long val = simple_strtoul(buf, NULL, 10);
98 u8 iopin_state[2];
99
100 if (val > 0xffff)
101 return -EINVAL;
102
103 data->write = val;
104
105 iopin_state[0] = val & 0xFF;
106 iopin_state[1] = val >> 8;
107
108 i2c_master_send(client, iopin_state, 2);
109
110 return count;
111}
112
113static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
114
115static struct attribute *pcf8575_attributes[] = {
116 &dev_attr_read.attr,
117 &dev_attr_write.attr,
118 NULL
119};
120
121static const struct attribute_group pcf8575_attr_group = {
122 .attrs = pcf8575_attributes,
123};
124
125/*
126 * Real code
127 */
128
129static int pcf8575_attach_adapter(struct i2c_adapter *adapter)
130{
131 return i2c_probe(adapter, &addr_data, pcf8575_detect);
132}
133
134/* This function is called by i2c_probe */
135static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind)
136{
137 struct i2c_client *client;
138 struct pcf8575_data *data;
139 int err = 0;
140
141 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
142 goto exit;
143
144 /* OK. For now, we presume we have a valid client. We now create the
145 client structure, even though we cannot fill it completely yet. */
146 data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL);
147 if (!data) {
148 err = -ENOMEM;
149 goto exit;
150 }
151
152 client = &data->client;
153 i2c_set_clientdata(client, data);
154 client->addr = address;
155 client->adapter = adapter;
156 client->driver = &pcf8575_driver;
157 strlcpy(client->name, "pcf8575", I2C_NAME_SIZE);
158 data->write = -EAGAIN;
159
160 /* This is the place to detect whether the chip at the specified
161 address really is a PCF8575 chip. However, there is no method known
162 to detect whether an I2C chip is a PCF8575 or any other I2C chip. */
163
164 /* Tell the I2C layer a new client has arrived */
165 err = i2c_attach_client(client);
166 if (err)
167 goto exit_free;
168
169 /* Register sysfs hooks */
170 err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group);
171 if (err)
172 goto exit_detach;
173
174 return 0;
175
176exit_detach:
177 i2c_detach_client(client);
178exit_free:
179 kfree(data);
180exit:
181 return err;
182}
183
184static int pcf8575_detach_client(struct i2c_client *client)
185{
186 int err;
187
188 sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group);
189
190 err = i2c_detach_client(client);
191 if (err)
192 return err;
193
194 kfree(i2c_get_clientdata(client));
195 return 0;
196}
197
198static int __init pcf8575_init(void)
199{
200 return i2c_add_driver(&pcf8575_driver);
201}
202
203static void __exit pcf8575_exit(void)
204{
205 i2c_del_driver(&pcf8575_driver);
206}
207
208MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>, "
209 "Bart Van Assche <bart.vanassche@gmail.com>");
210MODULE_DESCRIPTION("pcf8575 driver");
211MODULE_LICENSE("GPL");
212
213module_init(pcf8575_init);
214module_exit(pcf8575_exit);
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 4dc36376eb32..865f4409c06b 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -27,7 +27,7 @@
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28 28
29/* Addresses to scan */ 29/* Addresses to scan */
30static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 30static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
31 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 31 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
32 32
33/* Insmod parameters */ 33/* Insmod parameters */
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index e320994b981c..4154a9108859 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -31,7 +31,7 @@
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33 33
34#include <asm/arch/tps65010.h> 34#include <linux/i2c/tps65010.h>
35 35
36/*-------------------------------------------------------------------------*/ 36/*-------------------------------------------------------------------------*/
37 37
diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c
index 3de4b19ba08f..a10fd2791a69 100644
--- a/drivers/i2c/chips/tsl2550.c
+++ b/drivers/i2c/chips/tsl2550.c
@@ -432,11 +432,32 @@ static int __devexit tsl2550_remove(struct i2c_client *client)
432 return 0; 432 return 0;
433} 433}
434 434
435#ifdef CONFIG_PM
436
437static int tsl2550_suspend(struct i2c_client *client, pm_message_t mesg)
438{
439 return tsl2550_set_power_state(client, 0);
440}
441
442static int tsl2550_resume(struct i2c_client *client)
443{
444 return tsl2550_set_power_state(client, 1);
445}
446
447#else
448
449#define tsl2550_suspend NULL
450#define tsl2550_resume NULL
451
452#endif /* CONFIG_PM */
453
435static struct i2c_driver tsl2550_driver = { 454static struct i2c_driver tsl2550_driver = {
436 .driver = { 455 .driver = {
437 .name = TSL2550_DRV_NAME, 456 .name = TSL2550_DRV_NAME,
438 .owner = THIS_MODULE, 457 .owner = THIS_MODULE,
439 }, 458 },
459 .suspend = tsl2550_suspend,
460 .resume = tsl2550_resume,
440 .probe = tsl2550_probe, 461 .probe = tsl2550_probe,
441 .remove = __devexit_p(tsl2550_remove), 462 .remove = __devexit_p(tsl2550_remove),
442}; 463};
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index b5e13e405e72..96da22e9a5a4 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -33,14 +33,15 @@
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/completion.h> 35#include <linux/completion.h>
36#include <linux/hardirq.h>
37#include <linux/irqflags.h>
36#include <asm/uaccess.h> 38#include <asm/uaccess.h>
39#include <asm/semaphore.h>
37 40
38#include "i2c-core.h" 41#include "i2c-core.h"
39 42
40 43
41static LIST_HEAD(adapters); 44static DEFINE_MUTEX(core_lock);
42static LIST_HEAD(drivers);
43static DEFINE_MUTEX(core_lists);
44static DEFINE_IDR(i2c_adapter_idr); 45static DEFINE_IDR(i2c_adapter_idr);
45 46
46#define is_newstyle_driver(d) ((d)->probe || (d)->remove) 47#define is_newstyle_driver(d) ((d)->probe || (d)->remove)
@@ -198,6 +199,25 @@ static struct bus_type i2c_bus_type = {
198 .resume = i2c_device_resume, 199 .resume = i2c_device_resume,
199}; 200};
200 201
202
203/**
204 * i2c_verify_client - return parameter as i2c_client, or NULL
205 * @dev: device, probably from some driver model iterator
206 *
207 * When traversing the driver model tree, perhaps using driver model
208 * iterators like @device_for_each_child(), you can't assume very much
209 * about the nodes you find. Use this function to avoid oopses caused
210 * by wrongly treating some non-I2C device as an i2c_client.
211 */
212struct i2c_client *i2c_verify_client(struct device *dev)
213{
214 return (dev->bus == &i2c_bus_type)
215 ? to_i2c_client(dev)
216 : NULL;
217}
218EXPORT_SYMBOL(i2c_verify_client);
219
220
201/** 221/**
202 * i2c_new_device - instantiate an i2c device for use with a new style driver 222 * i2c_new_device - instantiate an i2c device for use with a new style driver
203 * @adap: the adapter managing the device 223 * @adap: the adapter managing the device
@@ -276,6 +296,50 @@ void i2c_unregister_device(struct i2c_client *client)
276EXPORT_SYMBOL_GPL(i2c_unregister_device); 296EXPORT_SYMBOL_GPL(i2c_unregister_device);
277 297
278 298
299static int dummy_nop(struct i2c_client *client)
300{
301 return 0;
302}
303
304static struct i2c_driver dummy_driver = {
305 .driver.name = "dummy",
306 .probe = dummy_nop,
307 .remove = dummy_nop,
308};
309
310/**
311 * i2c_new_dummy - return a new i2c device bound to a dummy driver
312 * @adapter: the adapter managing the device
313 * @address: seven bit address to be used
314 * @type: optional label used for i2c_client.name
315 * Context: can sleep
316 *
317 * This returns an I2C client bound to the "dummy" driver, intended for use
318 * with devices that consume multiple addresses. Examples of such chips
319 * include various EEPROMS (like 24c04 and 24c08 models).
320 *
321 * These dummy devices have two main uses. First, most I2C and SMBus calls
322 * except i2c_transfer() need a client handle; the dummy will be that handle.
323 * And second, this prevents the specified address from being bound to a
324 * different driver.
325 *
326 * This returns the new i2c client, which should be saved for later use with
327 * i2c_unregister_device(); or NULL to indicate an error.
328 */
329struct i2c_client *
330i2c_new_dummy(struct i2c_adapter *adapter, u16 address, const char *type)
331{
332 struct i2c_board_info info = {
333 .driver_name = "dummy",
334 .addr = address,
335 };
336
337 if (type)
338 strlcpy(info.type, type, sizeof info.type);
339 return i2c_new_device(adapter, &info);
340}
341EXPORT_SYMBOL_GPL(i2c_new_dummy);
342
279/* ------------------------------------------------------------------------- */ 343/* ------------------------------------------------------------------------- */
280 344
281/* I2C bus adapters -- one roots each I2C or SMBUS segment */ 345/* I2C bus adapters -- one roots each I2C or SMBUS segment */
@@ -320,18 +384,27 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
320 mutex_unlock(&__i2c_board_lock); 384 mutex_unlock(&__i2c_board_lock);
321} 385}
322 386
387static int i2c_do_add_adapter(struct device_driver *d, void *data)
388{
389 struct i2c_driver *driver = to_i2c_driver(d);
390 struct i2c_adapter *adap = data;
391
392 if (driver->attach_adapter) {
393 /* We ignore the return code; if it fails, too bad */
394 driver->attach_adapter(adap);
395 }
396 return 0;
397}
398
323static int i2c_register_adapter(struct i2c_adapter *adap) 399static int i2c_register_adapter(struct i2c_adapter *adap)
324{ 400{
325 int res = 0; 401 int res = 0, dummy;
326 struct list_head *item;
327 struct i2c_driver *driver;
328 402
329 mutex_init(&adap->bus_lock); 403 mutex_init(&adap->bus_lock);
330 mutex_init(&adap->clist_lock); 404 mutex_init(&adap->clist_lock);
331 INIT_LIST_HEAD(&adap->clients); 405 INIT_LIST_HEAD(&adap->clients);
332 406
333 mutex_lock(&core_lists); 407 mutex_lock(&core_lock);
334 list_add_tail(&adap->list, &adapters);
335 408
336 /* Add the adapter to the driver core. 409 /* Add the adapter to the driver core.
337 * If the parent pointer is not set up, 410 * If the parent pointer is not set up,
@@ -356,19 +429,14 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
356 i2c_scan_static_board_info(adap); 429 i2c_scan_static_board_info(adap);
357 430
358 /* let legacy drivers scan this bus for matching devices */ 431 /* let legacy drivers scan this bus for matching devices */
359 list_for_each(item,&drivers) { 432 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap,
360 driver = list_entry(item, struct i2c_driver, list); 433 i2c_do_add_adapter);
361 if (driver->attach_adapter)
362 /* We ignore the return code; if it fails, too bad */
363 driver->attach_adapter(adap);
364 }
365 434
366out_unlock: 435out_unlock:
367 mutex_unlock(&core_lists); 436 mutex_unlock(&core_lock);
368 return res; 437 return res;
369 438
370out_list: 439out_list:
371 list_del(&adap->list);
372 idr_remove(&i2c_adapter_idr, adap->nr); 440 idr_remove(&i2c_adapter_idr, adap->nr);
373 goto out_unlock; 441 goto out_unlock;
374} 442}
@@ -394,11 +462,11 @@ retry:
394 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) 462 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
395 return -ENOMEM; 463 return -ENOMEM;
396 464
397 mutex_lock(&core_lists); 465 mutex_lock(&core_lock);
398 /* "above" here means "above or equal to", sigh */ 466 /* "above" here means "above or equal to", sigh */
399 res = idr_get_new_above(&i2c_adapter_idr, adapter, 467 res = idr_get_new_above(&i2c_adapter_idr, adapter,
400 __i2c_first_dynamic_bus_num, &id); 468 __i2c_first_dynamic_bus_num, &id);
401 mutex_unlock(&core_lists); 469 mutex_unlock(&core_lock);
402 470
403 if (res < 0) { 471 if (res < 0) {
404 if (res == -EAGAIN) 472 if (res == -EAGAIN)
@@ -443,7 +511,7 @@ retry:
443 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) 511 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
444 return -ENOMEM; 512 return -ENOMEM;
445 513
446 mutex_lock(&core_lists); 514 mutex_lock(&core_lock);
447 /* "above" here means "above or equal to", sigh; 515 /* "above" here means "above or equal to", sigh;
448 * we need the "equal to" result to force the result 516 * we need the "equal to" result to force the result
449 */ 517 */
@@ -452,7 +520,7 @@ retry:
452 status = -EBUSY; 520 status = -EBUSY;
453 idr_remove(&i2c_adapter_idr, id); 521 idr_remove(&i2c_adapter_idr, id);
454 } 522 }
455 mutex_unlock(&core_lists); 523 mutex_unlock(&core_lock);
456 if (status == -EAGAIN) 524 if (status == -EAGAIN)
457 goto retry; 525 goto retry;
458 526
@@ -462,6 +530,21 @@ retry:
462} 530}
463EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); 531EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
464 532
533static int i2c_do_del_adapter(struct device_driver *d, void *data)
534{
535 struct i2c_driver *driver = to_i2c_driver(d);
536 struct i2c_adapter *adapter = data;
537 int res;
538
539 if (!driver->detach_adapter)
540 return 0;
541 res = driver->detach_adapter(adapter);
542 if (res)
543 dev_err(&adapter->dev, "detach_adapter failed (%d) "
544 "for driver [%s]\n", res, driver->driver.name);
545 return res;
546}
547
465/** 548/**
466 * i2c_del_adapter - unregister I2C adapter 549 * i2c_del_adapter - unregister I2C adapter
467 * @adap: the adapter being unregistered 550 * @adap: the adapter being unregistered
@@ -473,35 +556,24 @@ EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
473int i2c_del_adapter(struct i2c_adapter *adap) 556int i2c_del_adapter(struct i2c_adapter *adap)
474{ 557{
475 struct list_head *item, *_n; 558 struct list_head *item, *_n;
476 struct i2c_adapter *adap_from_list;
477 struct i2c_driver *driver;
478 struct i2c_client *client; 559 struct i2c_client *client;
479 int res = 0; 560 int res = 0;
480 561
481 mutex_lock(&core_lists); 562 mutex_lock(&core_lock);
482 563
483 /* First make sure that this adapter was ever added */ 564 /* First make sure that this adapter was ever added */
484 list_for_each_entry(adap_from_list, &adapters, list) { 565 if (idr_find(&i2c_adapter_idr, adap->nr) != adap) {
485 if (adap_from_list == adap)
486 break;
487 }
488 if (adap_from_list != adap) {
489 pr_debug("i2c-core: attempting to delete unregistered " 566 pr_debug("i2c-core: attempting to delete unregistered "
490 "adapter [%s]\n", adap->name); 567 "adapter [%s]\n", adap->name);
491 res = -EINVAL; 568 res = -EINVAL;
492 goto out_unlock; 569 goto out_unlock;
493 } 570 }
494 571
495 list_for_each(item,&drivers) { 572 /* Tell drivers about this removal */
496 driver = list_entry(item, struct i2c_driver, list); 573 res = bus_for_each_drv(&i2c_bus_type, NULL, adap,
497 if (driver->detach_adapter) 574 i2c_do_del_adapter);
498 if ((res = driver->detach_adapter(adap))) { 575 if (res)
499 dev_err(&adap->dev, "detach_adapter failed " 576 goto out_unlock;
500 "for driver [%s]\n",
501 driver->driver.name);
502 goto out_unlock;
503 }
504 }
505 577
506 /* detach any active clients. This must be done first, because 578 /* detach any active clients. This must be done first, because
507 * it can fail; in which case we give up. */ 579 * it can fail; in which case we give up. */
@@ -529,7 +601,6 @@ int i2c_del_adapter(struct i2c_adapter *adap)
529 /* clean up the sysfs representation */ 601 /* clean up the sysfs representation */
530 init_completion(&adap->dev_released); 602 init_completion(&adap->dev_released);
531 device_unregister(&adap->dev); 603 device_unregister(&adap->dev);
532 list_del(&adap->list);
533 604
534 /* wait for sysfs to drop all references */ 605 /* wait for sysfs to drop all references */
535 wait_for_completion(&adap->dev_released); 606 wait_for_completion(&adap->dev_released);
@@ -540,7 +611,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
540 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); 611 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
541 612
542 out_unlock: 613 out_unlock:
543 mutex_unlock(&core_lists); 614 mutex_unlock(&core_lock);
544 return res; 615 return res;
545} 616}
546EXPORT_SYMBOL(i2c_del_adapter); 617EXPORT_SYMBOL(i2c_del_adapter);
@@ -583,21 +654,23 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
583 if (res) 654 if (res)
584 return res; 655 return res;
585 656
586 mutex_lock(&core_lists); 657 mutex_lock(&core_lock);
587 658
588 list_add_tail(&driver->list,&drivers);
589 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); 659 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
590 660
591 /* legacy drivers scan i2c busses directly */ 661 /* legacy drivers scan i2c busses directly */
592 if (driver->attach_adapter) { 662 if (driver->attach_adapter) {
593 struct i2c_adapter *adapter; 663 struct i2c_adapter *adapter;
594 664
595 list_for_each_entry(adapter, &adapters, list) { 665 down(&i2c_adapter_class.sem);
666 list_for_each_entry(adapter, &i2c_adapter_class.devices,
667 dev.node) {
596 driver->attach_adapter(adapter); 668 driver->attach_adapter(adapter);
597 } 669 }
670 up(&i2c_adapter_class.sem);
598 } 671 }
599 672
600 mutex_unlock(&core_lists); 673 mutex_unlock(&core_lock);
601 return 0; 674 return 0;
602} 675}
603EXPORT_SYMBOL(i2c_register_driver); 676EXPORT_SYMBOL(i2c_register_driver);
@@ -609,11 +682,11 @@ EXPORT_SYMBOL(i2c_register_driver);
609 */ 682 */
610void i2c_del_driver(struct i2c_driver *driver) 683void i2c_del_driver(struct i2c_driver *driver)
611{ 684{
612 struct list_head *item1, *item2, *_n; 685 struct list_head *item2, *_n;
613 struct i2c_client *client; 686 struct i2c_client *client;
614 struct i2c_adapter *adap; 687 struct i2c_adapter *adap;
615 688
616 mutex_lock(&core_lists); 689 mutex_lock(&core_lock);
617 690
618 /* new-style driver? */ 691 /* new-style driver? */
619 if (is_newstyle_driver(driver)) 692 if (is_newstyle_driver(driver))
@@ -623,8 +696,8 @@ void i2c_del_driver(struct i2c_driver *driver)
623 * attached. If so, detach them to be able to kill the driver 696 * attached. If so, detach them to be able to kill the driver
624 * afterwards. 697 * afterwards.
625 */ 698 */
626 list_for_each(item1,&adapters) { 699 down(&i2c_adapter_class.sem);
627 adap = list_entry(item1, struct i2c_adapter, list); 700 list_for_each_entry(adap, &i2c_adapter_class.devices, dev.node) {
628 if (driver->detach_adapter) { 701 if (driver->detach_adapter) {
629 if (driver->detach_adapter(adap)) { 702 if (driver->detach_adapter(adap)) {
630 dev_err(&adap->dev, "detach_adapter failed " 703 dev_err(&adap->dev, "detach_adapter failed "
@@ -648,40 +721,31 @@ void i2c_del_driver(struct i2c_driver *driver)
648 } 721 }
649 } 722 }
650 } 723 }
724 up(&i2c_adapter_class.sem);
651 725
652 unregister: 726 unregister:
653 driver_unregister(&driver->driver); 727 driver_unregister(&driver->driver);
654 list_del(&driver->list);
655 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 728 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
656 729
657 mutex_unlock(&core_lists); 730 mutex_unlock(&core_lock);
658} 731}
659EXPORT_SYMBOL(i2c_del_driver); 732EXPORT_SYMBOL(i2c_del_driver);
660 733
661/* ------------------------------------------------------------------------- */ 734/* ------------------------------------------------------------------------- */
662 735
663static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr) 736static int __i2c_check_addr(struct device *dev, void *addrp)
664{ 737{
665 struct list_head *item; 738 struct i2c_client *client = i2c_verify_client(dev);
666 struct i2c_client *client; 739 int addr = *(int *)addrp;
667 740
668 list_for_each(item,&adapter->clients) { 741 if (client && client->addr == addr)
669 client = list_entry(item, struct i2c_client, list); 742 return -EBUSY;
670 if (client->addr == addr)
671 return -EBUSY;
672 }
673 return 0; 743 return 0;
674} 744}
675 745
676static int i2c_check_addr(struct i2c_adapter *adapter, int addr) 746static int i2c_check_addr(struct i2c_adapter *adapter, int addr)
677{ 747{
678 int rval; 748 return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr);
679
680 mutex_lock(&adapter->clist_lock);
681 rval = __i2c_check_addr(adapter, addr);
682 mutex_unlock(&adapter->clist_lock);
683
684 return rval;
685} 749}
686 750
687int i2c_attach_client(struct i2c_client *client) 751int i2c_attach_client(struct i2c_client *client)
@@ -689,15 +753,6 @@ int i2c_attach_client(struct i2c_client *client)
689 struct i2c_adapter *adapter = client->adapter; 753 struct i2c_adapter *adapter = client->adapter;
690 int res = 0; 754 int res = 0;
691 755
692 mutex_lock(&adapter->clist_lock);
693 if (__i2c_check_addr(client->adapter, client->addr)) {
694 res = -EBUSY;
695 goto out_unlock;
696 }
697 list_add_tail(&client->list,&adapter->clients);
698
699 client->usage_count = 0;
700
701 client->dev.parent = &client->adapter->dev; 756 client->dev.parent = &client->adapter->dev;
702 client->dev.bus = &i2c_bus_type; 757 client->dev.bus = &i2c_bus_type;
703 758
@@ -712,13 +767,17 @@ int i2c_attach_client(struct i2c_client *client)
712 767
713 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), 768 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
714 "%d-%04x", i2c_adapter_id(adapter), client->addr); 769 "%d-%04x", i2c_adapter_id(adapter), client->addr);
715 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
716 client->name, client->dev.bus_id);
717 res = device_register(&client->dev); 770 res = device_register(&client->dev);
718 if (res) 771 if (res)
719 goto out_list; 772 goto out_err;
773
774 mutex_lock(&adapter->clist_lock);
775 list_add_tail(&client->list, &adapter->clients);
720 mutex_unlock(&adapter->clist_lock); 776 mutex_unlock(&adapter->clist_lock);
721 777
778 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
779 client->name, client->dev.bus_id);
780
722 if (adapter->client_register) { 781 if (adapter->client_register) {
723 if (adapter->client_register(client)) { 782 if (adapter->client_register(client)) {
724 dev_dbg(&adapter->dev, "client_register " 783 dev_dbg(&adapter->dev, "client_register "
@@ -729,12 +788,9 @@ int i2c_attach_client(struct i2c_client *client)
729 788
730 return 0; 789 return 0;
731 790
732out_list: 791out_err:
733 list_del(&client->list);
734 dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " 792 dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x "
735 "(%d)\n", client->name, client->addr, res); 793 "(%d)\n", client->name, client->addr, res);
736out_unlock:
737 mutex_unlock(&adapter->clist_lock);
738 return res; 794 return res;
739} 795}
740EXPORT_SYMBOL(i2c_attach_client); 796EXPORT_SYMBOL(i2c_attach_client);
@@ -744,12 +800,6 @@ int i2c_detach_client(struct i2c_client *client)
744 struct i2c_adapter *adapter = client->adapter; 800 struct i2c_adapter *adapter = client->adapter;
745 int res = 0; 801 int res = 0;
746 802
747 if (client->usage_count > 0) {
748 dev_warn(&client->dev, "Client [%s] still busy, "
749 "can't detach\n", client->name);
750 return -EBUSY;
751 }
752
753 if (adapter->client_unregister) { 803 if (adapter->client_unregister) {
754 res = adapter->client_unregister(client); 804 res = adapter->client_unregister(client);
755 if (res) { 805 if (res) {
@@ -762,9 +812,10 @@ int i2c_detach_client(struct i2c_client *client)
762 812
763 mutex_lock(&adapter->clist_lock); 813 mutex_lock(&adapter->clist_lock);
764 list_del(&client->list); 814 list_del(&client->list);
815 mutex_unlock(&adapter->clist_lock);
816
765 init_completion(&client->released); 817 init_completion(&client->released);
766 device_unregister(&client->dev); 818 device_unregister(&client->dev);
767 mutex_unlock(&adapter->clist_lock);
768 wait_for_completion(&client->released); 819 wait_for_completion(&client->released);
769 820
770 out: 821 out:
@@ -772,72 +823,58 @@ int i2c_detach_client(struct i2c_client *client)
772} 823}
773EXPORT_SYMBOL(i2c_detach_client); 824EXPORT_SYMBOL(i2c_detach_client);
774 825
775static int i2c_inc_use_client(struct i2c_client *client) 826/**
827 * i2c_use_client - increments the reference count of the i2c client structure
828 * @client: the client being referenced
829 *
830 * Each live reference to a client should be refcounted. The driver model does
831 * that automatically as part of driver binding, so that most drivers don't
832 * need to do this explicitly: they hold a reference until they're unbound
833 * from the device.
834 *
835 * A pointer to the client with the incremented reference counter is returned.
836 */
837struct i2c_client *i2c_use_client(struct i2c_client *client)
776{ 838{
777 839 get_device(&client->dev);
778 if (!try_module_get(client->driver->driver.owner)) 840 return client;
779 return -ENODEV;
780 if (!try_module_get(client->adapter->owner)) {
781 module_put(client->driver->driver.owner);
782 return -ENODEV;
783 }
784
785 return 0;
786} 841}
842EXPORT_SYMBOL(i2c_use_client);
787 843
788static void i2c_dec_use_client(struct i2c_client *client) 844/**
845 * i2c_release_client - release a use of the i2c client structure
846 * @client: the client being no longer referenced
847 *
848 * Must be called when a user of a client is finished with it.
849 */
850void i2c_release_client(struct i2c_client *client)
789{ 851{
790 module_put(client->driver->driver.owner); 852 put_device(&client->dev);
791 module_put(client->adapter->owner);
792} 853}
854EXPORT_SYMBOL(i2c_release_client);
793 855
794int i2c_use_client(struct i2c_client *client) 856struct i2c_cmd_arg {
795{ 857 unsigned cmd;
796 int ret; 858 void *arg;
797 859};
798 ret = i2c_inc_use_client(client);
799 if (ret)
800 return ret;
801
802 client->usage_count++;
803
804 return 0;
805}
806EXPORT_SYMBOL(i2c_use_client);
807 860
808int i2c_release_client(struct i2c_client *client) 861static int i2c_cmd(struct device *dev, void *_arg)
809{ 862{
810 if (!client->usage_count) { 863 struct i2c_client *client = i2c_verify_client(dev);
811 pr_debug("i2c-core: %s used one too many times\n", 864 struct i2c_cmd_arg *arg = _arg;
812 __FUNCTION__);
813 return -EPERM;
814 }
815
816 client->usage_count--;
817 i2c_dec_use_client(client);
818 865
866 if (client && client->driver && client->driver->command)
867 client->driver->command(client, arg->cmd, arg->arg);
819 return 0; 868 return 0;
820} 869}
821EXPORT_SYMBOL(i2c_release_client);
822 870
823void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg) 871void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
824{ 872{
825 struct list_head *item; 873 struct i2c_cmd_arg cmd_arg;
826 struct i2c_client *client;
827 874
828 mutex_lock(&adap->clist_lock); 875 cmd_arg.cmd = cmd;
829 list_for_each(item,&adap->clients) { 876 cmd_arg.arg = arg;
830 client = list_entry(item, struct i2c_client, list); 877 device_for_each_child(&adap->dev, &cmd_arg, i2c_cmd);
831 if (!try_module_get(client->driver->driver.owner))
832 continue;
833 if (NULL != client->driver->command) {
834 mutex_unlock(&adap->clist_lock);
835 client->driver->command(client,cmd,arg);
836 mutex_lock(&adap->clist_lock);
837 }
838 module_put(client->driver->driver.owner);
839 }
840 mutex_unlock(&adap->clist_lock);
841} 878}
842EXPORT_SYMBOL(i2c_clients_command); 879EXPORT_SYMBOL(i2c_clients_command);
843 880
@@ -848,11 +885,24 @@ static int __init i2c_init(void)
848 retval = bus_register(&i2c_bus_type); 885 retval = bus_register(&i2c_bus_type);
849 if (retval) 886 if (retval)
850 return retval; 887 return retval;
851 return class_register(&i2c_adapter_class); 888 retval = class_register(&i2c_adapter_class);
889 if (retval)
890 goto bus_err;
891 retval = i2c_add_driver(&dummy_driver);
892 if (retval)
893 goto class_err;
894 return 0;
895
896class_err:
897 class_unregister(&i2c_adapter_class);
898bus_err:
899 bus_unregister(&i2c_bus_type);
900 return retval;
852} 901}
853 902
854static void __exit i2c_exit(void) 903static void __exit i2c_exit(void)
855{ 904{
905 i2c_del_driver(&dummy_driver);
856 class_unregister(&i2c_adapter_class); 906 class_unregister(&i2c_adapter_class);
857 bus_unregister(&i2c_bus_type); 907 bus_unregister(&i2c_bus_type);
858} 908}
@@ -879,7 +929,15 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
879 } 929 }
880#endif 930#endif
881 931
882 mutex_lock_nested(&adap->bus_lock, adap->level); 932 if (in_atomic() || irqs_disabled()) {
933 ret = mutex_trylock(&adap->bus_lock);
934 if (!ret)
935 /* I2C activity is ongoing. */
936 return -EAGAIN;
937 } else {
938 mutex_lock_nested(&adap->bus_lock, adap->level);
939 }
940
883 ret = adap->algo->master_xfer(adap,msgs,num); 941 ret = adap->algo->master_xfer(adap,msgs,num);
884 mutex_unlock(&adap->bus_lock); 942 mutex_unlock(&adap->bus_lock);
885 943
@@ -978,7 +1036,7 @@ static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
978} 1036}
979 1037
980int i2c_probe(struct i2c_adapter *adapter, 1038int i2c_probe(struct i2c_adapter *adapter,
981 struct i2c_client_address_data *address_data, 1039 const struct i2c_client_address_data *address_data,
982 int (*found_proc) (struct i2c_adapter *, int, int)) 1040 int (*found_proc) (struct i2c_adapter *, int, int))
983{ 1041{
984 int i, err; 1042 int i, err;
@@ -987,7 +1045,7 @@ int i2c_probe(struct i2c_adapter *adapter,
987 /* Force entries are done first, and are not affected by ignore 1045 /* Force entries are done first, and are not affected by ignore
988 entries */ 1046 entries */
989 if (address_data->forces) { 1047 if (address_data->forces) {
990 unsigned short **forces = address_data->forces; 1048 const unsigned short * const *forces = address_data->forces;
991 int kind; 1049 int kind;
992 1050
993 for (kind = 0; forces[kind]; kind++) { 1051 for (kind = 0; forces[kind]; kind++) {
@@ -1085,7 +1143,6 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1085 return NULL; 1143 return NULL;
1086 } 1144 }
1087 1145
1088 mutex_lock(&adap->clist_lock);
1089 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { 1146 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
1090 /* Check address validity */ 1147 /* Check address validity */
1091 if (addr_list[i] < 0x03 || addr_list[i] > 0x77) { 1148 if (addr_list[i] < 0x03 || addr_list[i] > 0x77) {
@@ -1095,7 +1152,7 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1095 } 1152 }
1096 1153
1097 /* Check address availability */ 1154 /* Check address availability */
1098 if (__i2c_check_addr(adap, addr_list[i])) { 1155 if (i2c_check_addr(adap, addr_list[i])) {
1099 dev_dbg(&adap->dev, "Address 0x%02x already in " 1156 dev_dbg(&adap->dev, "Address 0x%02x already in "
1100 "use, not probing\n", addr_list[i]); 1157 "use, not probing\n", addr_list[i]);
1101 continue; 1158 continue;
@@ -1123,7 +1180,6 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1123 break; 1180 break;
1124 } 1181 }
1125 } 1182 }
1126 mutex_unlock(&adap->clist_lock);
1127 1183
1128 if (addr_list[i] == I2C_CLIENT_END) { 1184 if (addr_list[i] == I2C_CLIENT_END) {
1129 dev_dbg(&adap->dev, "Probing failed, no device found\n"); 1185 dev_dbg(&adap->dev, "Probing failed, no device found\n");
@@ -1139,12 +1195,12 @@ struct i2c_adapter* i2c_get_adapter(int id)
1139{ 1195{
1140 struct i2c_adapter *adapter; 1196 struct i2c_adapter *adapter;
1141 1197
1142 mutex_lock(&core_lists); 1198 mutex_lock(&core_lock);
1143 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); 1199 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
1144 if (adapter && !try_module_get(adapter->owner)) 1200 if (adapter && !try_module_get(adapter->owner))
1145 adapter = NULL; 1201 adapter = NULL;
1146 1202
1147 mutex_unlock(&core_lists); 1203 mutex_unlock(&core_lock);
1148 return adapter; 1204 return adapter;
1149} 1205}
1150EXPORT_SYMBOL(i2c_get_adapter); 1206EXPORT_SYMBOL(i2c_get_adapter);
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index df540d5dfaf4..393e679d9faa 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -182,27 +182,22 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c
182 return ret; 182 return ret;
183} 183}
184 184
185static int i2cdev_check(struct device *dev, void *addrp)
186{
187 struct i2c_client *client = i2c_verify_client(dev);
188
189 if (!client || client->addr != *(unsigned int *)addrp)
190 return 0;
191
192 return dev->driver ? -EBUSY : 0;
193}
194
185/* This address checking function differs from the one in i2c-core 195/* This address checking function differs from the one in i2c-core
186 in that it considers an address with a registered device, but no 196 in that it considers an address with a registered device, but no
187 bound driver, as NOT busy. */ 197 driver bound to it, as NOT busy. */
188static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) 198static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr)
189{ 199{
190 struct list_head *item; 200 return device_for_each_child(&adapter->dev, &addr, i2cdev_check);
191 struct i2c_client *client;
192 int res = 0;
193
194 mutex_lock(&adapter->clist_lock);
195 list_for_each(item, &adapter->clients) {
196 client = list_entry(item, struct i2c_client, list);
197 if (client->addr == addr) {
198 if (client->driver)
199 res = -EBUSY;
200 break;
201 }
202 }
203 mutex_unlock(&adapter->clist_lock);
204
205 return res;
206} 201}
207 202
208static int i2cdev_ioctl(struct inode *inode, struct file *file, 203static int i2cdev_ioctl(struct inode *inode, struct file *file,
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index 5452da1bb1a5..b66da74caa55 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -47,12 +47,10 @@
47 47
48#define LOG_TEMP 0 /* continously log temperature */ 48#define LOG_TEMP 0 /* continously log temperature */
49 49
50#define I2C_DRIVERID_G4FAN 0x9001 /* fixme */
51
52static int do_probe( struct i2c_adapter *adapter, int addr, int kind); 50static int do_probe( struct i2c_adapter *adapter, int addr, int kind);
53 51
54/* scan 0x48-0x4f (DS1775) and 0x2c-2x2f (ADM1030) */ 52/* scan 0x48-0x4f (DS1775) and 0x2c-2x2f (ADM1030) */
55static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 53static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
56 0x4c, 0x4d, 0x4e, 0x4f, 54 0x4c, 0x4d, 0x4e, 0x4f,
57 0x2c, 0x2d, 0x2e, 0x2f, 55 0x2c, 0x2d, 0x2e, 0x2f,
58 I2C_CLIENT_END }; 56 I2C_CLIENT_END };
@@ -357,7 +355,6 @@ static struct i2c_driver g4fan_driver = {
357 .driver = { 355 .driver = {
358 .name = "therm_windtunnel", 356 .name = "therm_windtunnel",
359 }, 357 },
360 .id = I2C_DRIVERID_G4FAN,
361 .attach_adapter = do_attach, 358 .attach_adapter = do_attach,
362 .detach_client = do_detach, 359 .detach_client = do_detach,
363}; 360};
diff --git a/drivers/media/video/dpc7146.c b/drivers/media/video/dpc7146.c
index 255dae303708..566e479e2629 100644
--- a/drivers/media/video/dpc7146.c
+++ b/drivers/media/video/dpc7146.c
@@ -87,11 +87,24 @@ struct dpc
87 int cur_input; /* current input */ 87 int cur_input; /* current input */
88}; 88};
89 89
90static int dpc_check_clients(struct device *dev, void *data)
91{
92 struct dpc* dpc = data;
93 struct i2c_client *client = i2c_verify_client(dev);
94
95 if( !client )
96 return 0;
97
98 if( I2C_SAA7111A == client->addr )
99 dpc->saa7111a = client;
100
101 return 0;
102}
103
90/* fixme: add vbi stuff here */ 104/* fixme: add vbi stuff here */
91static int dpc_probe(struct saa7146_dev* dev) 105static int dpc_probe(struct saa7146_dev* dev)
92{ 106{
93 struct dpc* dpc = NULL; 107 struct dpc* dpc = NULL;
94 struct i2c_client *client;
95 108
96 dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL); 109 dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL);
97 if( NULL == dpc ) { 110 if( NULL == dpc ) {
@@ -115,9 +128,7 @@ static int dpc_probe(struct saa7146_dev* dev)
115 } 128 }
116 129
117 /* loop through all i2c-devices on the bus and look who is there */ 130 /* loop through all i2c-devices on the bus and look who is there */
118 list_for_each_entry(client, &dpc->i2c_adapter.clients, list) 131 device_for_each_child(&dpc->i2c_adapter.dev, dpc, dpc_check_clients);
119 if( I2C_SAA7111A == client->addr )
120 dpc->saa7111a = client;
121 132
122 /* check if all devices are present */ 133 /* check if all devices are present */
123 if( 0 == dpc->saa7111a ) { 134 if( 0 == dpc->saa7111a ) {
diff --git a/drivers/media/video/ks0127.c b/drivers/media/video/ks0127.c
index b6cd21e6dab9..4895540be195 100644
--- a/drivers/media/video/ks0127.c
+++ b/drivers/media/video/ks0127.c
@@ -764,7 +764,6 @@ static struct i2c_client ks0127_client_tmpl =
764 .addr = 0, 764 .addr = 0,
765 .adapter = NULL, 765 .adapter = NULL,
766 .driver = &i2c_driver_ks0127, 766 .driver = &i2c_driver_ks0127,
767 .usage_count = 0
768}; 767};
769 768
770static int ks0127_found_proc(struct i2c_adapter *adapter, int addr, int kind) 769static int ks0127_found_proc(struct i2c_adapter *adapter, int addr, int kind)
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 98ad3092a079..add6d0d680be 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -149,10 +149,33 @@ struct mxb
149 149
150static struct saa7146_extension extension; 150static struct saa7146_extension extension;
151 151
152static int mxb_check_clients(struct device *dev, void *data)
153{
154 struct mxb* mxb = data;
155 struct i2c_client *client = i2c_verify_client(dev);
156
157 if( !client )
158 return 0;
159
160 if( I2C_ADDR_TEA6420_1 == client->addr )
161 mxb->tea6420_1 = client;
162 if( I2C_ADDR_TEA6420_2 == client->addr )
163 mxb->tea6420_2 = client;
164 if( I2C_TEA6415C_2 == client->addr )
165 mxb->tea6415c = client;
166 if( I2C_ADDR_TDA9840 == client->addr )
167 mxb->tda9840 = client;
168 if( I2C_SAA7111 == client->addr )
169 mxb->saa7111a = client;
170 if( 0x60 == client->addr )
171 mxb->tuner = client;
172
173 return 0;
174}
175
152static int mxb_probe(struct saa7146_dev* dev) 176static int mxb_probe(struct saa7146_dev* dev)
153{ 177{
154 struct mxb* mxb = NULL; 178 struct mxb* mxb = NULL;
155 struct i2c_client *client;
156 int result; 179 int result;
157 180
158 if ((result = request_module("saa7111")) < 0) { 181 if ((result = request_module("saa7111")) < 0) {
@@ -195,20 +218,7 @@ static int mxb_probe(struct saa7146_dev* dev)
195 } 218 }
196 219
197 /* loop through all i2c-devices on the bus and look who is there */ 220 /* loop through all i2c-devices on the bus and look who is there */
198 list_for_each_entry(client, &mxb->i2c_adapter.clients, list) { 221 device_for_each_child(&mxb->i2c_adapter.dev, mxb, mxb_check_clients);
199 if( I2C_ADDR_TEA6420_1 == client->addr )
200 mxb->tea6420_1 = client;
201 if( I2C_ADDR_TEA6420_2 == client->addr )
202 mxb->tea6420_2 = client;
203 if( I2C_TEA6415C_2 == client->addr )
204 mxb->tea6415c = client;
205 if( I2C_ADDR_TDA9840 == client->addr )
206 mxb->tda9840 = client;
207 if( I2C_SAA7111 == client->addr )
208 mxb->saa7111a = client;
209 if( 0x60 == client->addr )
210 mxb->tuner = client;
211 }
212 222
213 /* check if all devices are present */ 223 /* check if all devices are present */
214 if( 0 == mxb->tea6420_1 || 0 == mxb->tea6420_2 || 0 == mxb->tea6415c 224 if( 0 == mxb->tea6420_1 || 0 == mxb->tea6420_2 || 0 == mxb->tea6415c
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 9a03dc82c6ca..5bb75294b5aa 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -2589,11 +2589,7 @@ static int vino_acquire_input(struct vino_channel_settings *vcs)
2589 /* First try D1 and then SAA7191 */ 2589 /* First try D1 and then SAA7191 */
2590 if (vino_drvdata->camera.driver 2590 if (vino_drvdata->camera.driver
2591 && (vino_drvdata->camera.owner == VINO_NO_CHANNEL)) { 2591 && (vino_drvdata->camera.owner == VINO_NO_CHANNEL)) {
2592 if (i2c_use_client(vino_drvdata->camera.driver)) { 2592 i2c_use_client(vino_drvdata->camera.driver);
2593 ret = -ENODEV;
2594 goto out;
2595 }
2596
2597 vino_drvdata->camera.owner = vcs->channel; 2593 vino_drvdata->camera.owner = vcs->channel;
2598 vcs->input = VINO_INPUT_D1; 2594 vcs->input = VINO_INPUT_D1;
2599 vcs->data_norm = VINO_DATA_NORM_D1; 2595 vcs->data_norm = VINO_DATA_NORM_D1;
@@ -2602,11 +2598,7 @@ static int vino_acquire_input(struct vino_channel_settings *vcs)
2602 int input, data_norm; 2598 int input, data_norm;
2603 int saa7191_input; 2599 int saa7191_input;
2604 2600
2605 if (i2c_use_client(vino_drvdata->decoder.driver)) { 2601 i2c_use_client(vino_drvdata->decoder.driver);
2606 ret = -ENODEV;
2607 goto out;
2608 }
2609
2610 input = VINO_INPUT_COMPOSITE; 2602 input = VINO_INPUT_COMPOSITE;
2611 2603
2612 saa7191_input = vino_get_saa7191_input(input); 2604 saa7191_input = vino_get_saa7191_input(input);
@@ -2688,10 +2680,7 @@ static int vino_set_input(struct vino_channel_settings *vcs, int input)
2688 } 2680 }
2689 2681
2690 if (vino_drvdata->decoder.owner == VINO_NO_CHANNEL) { 2682 if (vino_drvdata->decoder.owner == VINO_NO_CHANNEL) {
2691 if (i2c_use_client(vino_drvdata->decoder.driver)) { 2683 i2c_use_client(vino_drvdata->decoder.driver);
2692 ret = -ENODEV;
2693 goto out;
2694 }
2695 vino_drvdata->decoder.owner = vcs->channel; 2684 vino_drvdata->decoder.owner = vcs->channel;
2696 } 2685 }
2697 2686
@@ -2759,10 +2748,7 @@ static int vino_set_input(struct vino_channel_settings *vcs, int input)
2759 } 2748 }
2760 2749
2761 if (vino_drvdata->camera.owner == VINO_NO_CHANNEL) { 2750 if (vino_drvdata->camera.owner == VINO_NO_CHANNEL) {
2762 if (i2c_use_client(vino_drvdata->camera.driver)) { 2751 i2c_use_client(vino_drvdata->camera.driver);
2763 ret = -ENODEV;
2764 goto out;
2765 }
2766 vino_drvdata->camera.owner = vcs->channel; 2752 vino_drvdata->camera.owner = vcs->channel;
2767 } 2753 }
2768 2754
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 971e18b91f4a..c9dfeb15b487 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -25,6 +25,7 @@
25#include <linux/mmc/card.h> 25#include <linux/mmc/card.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
27#include <linux/scatterlist.h> 27#include <linux/scatterlist.h>
28#include <linux/i2c/tps65010.h>
28 29
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/irq.h> 31#include <asm/irq.h>
@@ -35,7 +36,6 @@
35#include <asm/arch/dma.h> 36#include <asm/arch/dma.h>
36#include <asm/arch/mux.h> 37#include <asm/arch/mux.h>
37#include <asm/arch/fpga.h> 38#include <asm/arch/fpga.h>
38#include <asm/arch/tps65010.h>
39 39
40#define OMAP_MMC_REG_CMD 0x00 40#define OMAP_MMC_REG_CMD 0x00
41#define OMAP_MMC_REG_ARGL 0x04 41#define OMAP_MMC_REG_ARGL 0x04
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index dfef1637bfb8..e0900ca678ec 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -16,7 +16,7 @@
16#define DRV_VERSION "0.3" 16#define DRV_VERSION "0.3"
17 17
18/* Addresses to scan: none. This chip cannot be detected. */ 18/* Addresses to scan: none. This chip cannot be detected. */
19static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 19static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
20 20
21/* Insmod parameters */ 21/* Insmod parameters */
22I2C_CLIENT_INSMOD; 22I2C_CLIENT_INSMOD;
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index 1c743641b73b..725b0c73c333 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -61,7 +61,7 @@
61/* i2c configuration */ 61/* i2c configuration */
62#define ISL1208_I2C_ADDR 0xde 62#define ISL1208_I2C_ADDR 0xde
63 63
64static unsigned short normal_i2c[] = { 64static const unsigned short normal_i2c[] = {
65 ISL1208_I2C_ADDR>>1, I2C_CLIENT_END 65 ISL1208_I2C_ADDR>>1, I2C_CLIENT_END
66}; 66};
67I2C_CLIENT_INSMOD; /* defines addr_data */ 67I2C_CLIENT_INSMOD; /* defines addr_data */
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index a1cd448639c9..7683412970c4 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -54,7 +54,7 @@
54 54
55#define MAX6900_I2C_ADDR 0xa0 55#define MAX6900_I2C_ADDR 0xa0
56 56
57static unsigned short normal_i2c[] = { 57static const unsigned short normal_i2c[] = {
58 MAX6900_I2C_ADDR >> 1, 58 MAX6900_I2C_ADDR >> 1,
59 I2C_CLIENT_END 59 I2C_CLIENT_END
60}; 60};
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 0242d803ebe5..b3317fcc16c3 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -25,7 +25,7 @@
25 * located at 0x51 will pass the validation routine due to 25 * located at 0x51 will pass the validation routine due to
26 * the way the registers are implemented. 26 * the way the registers are implemented.
27 */ 27 */
28static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 28static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
29 29
30/* Module parameters */ 30/* Module parameters */
31I2C_CLIENT_INSMOD; 31I2C_CLIENT_INSMOD;
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 556d0e7da35b..c973ba94c422 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -40,7 +40,7 @@ struct pcf8583 {
40#define CTRL_ALARM 0x02 40#define CTRL_ALARM 0x02
41#define CTRL_TIMER 0x01 41#define CTRL_TIMER 0x01
42 42
43static unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; 43static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END };
44 44
45/* Module parameters */ 45/* Module parameters */
46I2C_CLIENT_INSMOD; 46I2C_CLIENT_INSMOD;
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index b3fae357ca49..b90fb1866ce9 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -32,7 +32,7 @@
32 * unknown chips, the user must explicitly set the probe parameter. 32 * unknown chips, the user must explicitly set the probe parameter.
33 */ 33 */
34 34
35static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 35static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
36 36
37/* Insmod parameters */ 37/* Insmod parameters */
38I2C_CLIENT_INSMOD; 38I2C_CLIENT_INSMOD;
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 5cfa3d1c4413..74e1f4be10bb 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -47,7 +47,7 @@
47#endif 47#endif
48 48
49#ifdef CONFIG_TPS65010 49#ifdef CONFIG_TPS65010
50#include <asm/arch/tps65010.h> 50#include <linux/i2c/tps65010.h>
51#else 51#else
52 52
53#define LOW 0 53#define LOW 0
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index ca2a6abbc117..6c52c66b659f 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -112,9 +112,9 @@ static int isp1301_detach(struct i2c_client *client);
112static int isp1301_command(struct i2c_client *client, unsigned int cmd, 112static int isp1301_command(struct i2c_client *client, unsigned int cmd,
113 void *arg); 113 void *arg);
114 114
115static unsigned short normal_i2c[] = 115static const unsigned short normal_i2c[] =
116 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END }; 116 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END };
117static unsigned short dummy_i2c_addrlist[] = { I2C_CLIENT_END }; 117static const unsigned short dummy_i2c_addrlist[] = { I2C_CLIENT_END };
118 118
119static struct i2c_client_address_data addr_data = { 119static struct i2c_client_address_data addr_data = {
120 .normal_i2c = normal_i2c, 120 .normal_i2c = normal_i2c,
@@ -123,7 +123,6 @@ static struct i2c_client_address_data addr_data = {
123}; 123};
124 124
125struct i2c_driver isp1301_driver = { 125struct i2c_driver isp1301_driver = {
126 .id = I2C_DRIVERID_I2CDEV, /* Fake Id */
127 .class = I2C_CLASS_HWMON, 126 .class = I2C_CLASS_HWMON,
128 .attach_adapter = isp1301_probe, 127 .attach_adapter = isp1301_probe,
129 .detach_client = isp1301_detach, 128 .detach_client = isp1301_detach,
diff --git a/drivers/video/matrox/matroxfb_maven.c b/drivers/video/matrox/matroxfb_maven.c
index 49cd53e46c0a..0cd58f84fb46 100644
--- a/drivers/video/matrox/matroxfb_maven.c
+++ b/drivers/video/matrox/matroxfb_maven.c
@@ -1232,7 +1232,7 @@ static int maven_shutdown_client(struct i2c_client* clnt) {
1232 return 0; 1232 return 0;
1233} 1233}
1234 1234
1235static unsigned short normal_i2c[] = { MAVEN_I2CID, I2C_CLIENT_END }; 1235static const unsigned short normal_i2c[] = { MAVEN_I2CID, I2C_CLIENT_END };
1236I2C_CLIENT_INSMOD; 1236I2C_CLIENT_INSMOD;
1237 1237
1238static struct i2c_driver maven_driver; 1238static struct i2c_driver maven_driver;
diff --git a/drivers/video/omap/lcd_h3.c b/drivers/video/omap/lcd_h3.c
index c604d935c188..31e978349a80 100644
--- a/drivers/video/omap/lcd_h3.c
+++ b/drivers/video/omap/lcd_h3.c
@@ -21,9 +21,9 @@
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/i2c/tps65010.h>
24 25
25#include <asm/arch/gpio.h> 26#include <asm/arch/gpio.h>
26#include <asm/arch/tps65010.h>
27#include <asm/arch/omapfb.h> 27#include <asm/arch/omapfb.h>
28 28
29#define MODULE_NAME "omapfb-lcd_h3" 29#define MODULE_NAME "omapfb-lcd_h3"
diff --git a/drivers/w1/masters/ds2482.c b/drivers/w1/masters/ds2482.c
index d93eb626b2f0..0fd5820d5c61 100644
--- a/drivers/w1/masters/ds2482.c
+++ b/drivers/w1/masters/ds2482.c
@@ -29,7 +29,7 @@
29 * However, the chip cannot be detected without doing an i2c write, 29 * However, the chip cannot be detected without doing an i2c write,
30 * so use the force module parameter. 30 * so use the force module parameter.
31 */ 31 */
32static unsigned short normal_i2c[] = {I2C_CLIENT_END}; 32static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
33 33
34/** 34/**
35 * Insmod parameters 35 * Insmod parameters
diff --git a/include/asm-arm/arch-ixp4xx/platform.h b/include/asm-arm/arch-ixp4xx/platform.h
index 2a44d3d67980..2ce28e3fd325 100644
--- a/include/asm-arm/arch-ixp4xx/platform.h
+++ b/include/asm-arm/arch-ixp4xx/platform.h
@@ -76,17 +76,6 @@ extern unsigned long ixp4xx_exp_bus_size;
76#define IXP4XX_UART_XTAL 14745600 76#define IXP4XX_UART_XTAL 14745600
77 77
78/* 78/*
79 * The IXP4xx chips do not have an I2C unit, so GPIO lines are just
80 * used to
81 * Used as platform_data to provide GPIO pin information to the ixp42x
82 * I2C driver.
83 */
84struct ixp4xx_i2c_pins {
85 unsigned long sda_pin;
86 unsigned long scl_pin;
87};
88
89/*
90 * This structure provide a means for the board setup code 79 * This structure provide a means for the board setup code
91 * to give information to th pata_ixp4xx driver. It is 80 * to give information to th pata_ixp4xx driver. It is
92 * passed as platform_data. 81 * passed as platform_data.
diff --git a/include/asm-arm/arch-pxa/i2c.h b/include/asm-arm/arch-pxa/i2c.h
index e404b233d8a8..80596b013443 100644
--- a/include/asm-arm/arch-pxa/i2c.h
+++ b/include/asm-arm/arch-pxa/i2c.h
@@ -65,7 +65,13 @@ struct i2c_pxa_platform_data {
65 unsigned int slave_addr; 65 unsigned int slave_addr;
66 struct i2c_slave_client *slave; 66 struct i2c_slave_client *slave;
67 unsigned int class; 67 unsigned int class;
68 int use_pio;
68}; 69};
69 70
70extern void pxa_set_i2c_info(struct i2c_pxa_platform_data *info); 71extern void pxa_set_i2c_info(struct i2c_pxa_platform_data *info);
72
73#ifdef CONFIG_PXA27x
74extern void pxa_set_i2c_power_info(struct i2c_pxa_platform_data *info);
75#endif
76
71#endif 77#endif
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index c7a51a196f51..f922b060158b 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -33,23 +33,13 @@
33 33
34#define I2C_DRIVERID_MSP3400 1 34#define I2C_DRIVERID_MSP3400 1
35#define I2C_DRIVERID_TUNER 2 35#define I2C_DRIVERID_TUNER 2
36#define I2C_DRIVERID_VIDEOTEX 3 /* please rename */
37#define I2C_DRIVERID_TDA8425 4 /* stereo sound processor */ 36#define I2C_DRIVERID_TDA8425 4 /* stereo sound processor */
38#define I2C_DRIVERID_TEA6420 5 /* audio matrix switch */ 37#define I2C_DRIVERID_TEA6420 5 /* audio matrix switch */
39#define I2C_DRIVERID_TEA6415C 6 /* video matrix switch */ 38#define I2C_DRIVERID_TEA6415C 6 /* video matrix switch */
40#define I2C_DRIVERID_TDA9840 7 /* stereo sound processor */ 39#define I2C_DRIVERID_TDA9840 7 /* stereo sound processor */
41#define I2C_DRIVERID_SAA7111A 8 /* video input processor */ 40#define I2C_DRIVERID_SAA7111A 8 /* video input processor */
42#define I2C_DRIVERID_SAA5281 9 /* videotext decoder */
43#define I2C_DRIVERID_SAA7112 10 /* video decoder, image scaler */
44#define I2C_DRIVERID_SAA7120 11 /* video encoder */
45#define I2C_DRIVERID_SAA7121 12 /* video encoder */
46#define I2C_DRIVERID_SAA7185B 13 /* video encoder */ 41#define I2C_DRIVERID_SAA7185B 13 /* video encoder */
47#define I2C_DRIVERID_CH7003 14 /* digital pc to tv encoder */
48#define I2C_DRIVERID_PCF8574A 15 /* i2c expander - 8 bit in/out */
49#define I2C_DRIVERID_PCF8582C 16 /* eeprom */
50#define I2C_DRIVERID_AT24Cxx 17 /* eeprom 1/2/4/8/16 K */
51#define I2C_DRIVERID_TEA6300 18 /* audio mixer */ 42#define I2C_DRIVERID_TEA6300 18 /* audio mixer */
52#define I2C_DRIVERID_BT829 19 /* pc to tv encoder */
53#define I2C_DRIVERID_TDA9850 20 /* audio mixer */ 43#define I2C_DRIVERID_TDA9850 20 /* audio mixer */
54#define I2C_DRIVERID_TDA9855 21 /* audio mixer */ 44#define I2C_DRIVERID_TDA9855 21 /* audio mixer */
55#define I2C_DRIVERID_SAA7110 22 /* video decoder */ 45#define I2C_DRIVERID_SAA7110 22 /* video decoder */
@@ -60,42 +50,19 @@
60#define I2C_DRIVERID_TDA7432 27 /* Stereo sound processor */ 50#define I2C_DRIVERID_TDA7432 27 /* Stereo sound processor */
61#define I2C_DRIVERID_TVMIXER 28 /* Mixer driver for tv cards */ 51#define I2C_DRIVERID_TVMIXER 28 /* Mixer driver for tv cards */
62#define I2C_DRIVERID_TVAUDIO 29 /* Generic TV sound driver */ 52#define I2C_DRIVERID_TVAUDIO 29 /* Generic TV sound driver */
63#define I2C_DRIVERID_DPL3518 30 /* Dolby decoder chip */
64#define I2C_DRIVERID_TDA9873 31 /* TV sound decoder chip */ 53#define I2C_DRIVERID_TDA9873 31 /* TV sound decoder chip */
65#define I2C_DRIVERID_TDA9875 32 /* TV sound decoder chip */ 54#define I2C_DRIVERID_TDA9875 32 /* TV sound decoder chip */
66#define I2C_DRIVERID_PIC16C54_PV9 33 /* Audio mux/ir receiver */ 55#define I2C_DRIVERID_PIC16C54_PV9 33 /* Audio mux/ir receiver */
67
68#define I2C_DRIVERID_SBATT 34 /* Smart Battery Device */
69#define I2C_DRIVERID_SBS 35 /* SB System Manager */
70#define I2C_DRIVERID_VES1893 36 /* VLSI DVB-S decoder */
71#define I2C_DRIVERID_VES1820 37 /* VLSI DVB-C decoder */
72#define I2C_DRIVERID_SAA7113 38 /* video decoder */
73#define I2C_DRIVERID_TDA8444 39 /* octuple 6-bit DAC */
74#define I2C_DRIVERID_BT819 40 /* video decoder */ 56#define I2C_DRIVERID_BT819 40 /* video decoder */
75#define I2C_DRIVERID_BT856 41 /* video encoder */ 57#define I2C_DRIVERID_BT856 41 /* video encoder */
76#define I2C_DRIVERID_VPX3220 42 /* video decoder+vbi/vtxt */ 58#define I2C_DRIVERID_VPX3220 42 /* video decoder+vbi/vtxt */
77#define I2C_DRIVERID_DRP3510 43 /* ADR decoder (Astra Radio) */
78#define I2C_DRIVERID_SP5055 44 /* Satellite tuner */
79#define I2C_DRIVERID_STV0030 45 /* Multipurpose switch */
80#define I2C_DRIVERID_SAA7108 46 /* video decoder, image scaler */
81#define I2C_DRIVERID_DS1307 47 /* DS1307 real time clock */
82#define I2C_DRIVERID_ADV7175 48 /* ADV 7175/7176 video encoder */ 59#define I2C_DRIVERID_ADV7175 48 /* ADV 7175/7176 video encoder */
83#define I2C_DRIVERID_SAA7114 49 /* video decoder */ 60#define I2C_DRIVERID_SAA7114 49 /* video decoder */
84#define I2C_DRIVERID_ZR36120 50 /* Zoran 36120 video encoder */
85#define I2C_DRIVERID_24LC32A 51 /* Microchip 24LC32A 32k EEPROM */
86#define I2C_DRIVERID_STM41T00 52 /* real time clock */
87#define I2C_DRIVERID_UDA1342 53 /* UDA1342 audio codec */
88#define I2C_DRIVERID_ADV7170 54 /* video encoder */ 61#define I2C_DRIVERID_ADV7170 54 /* video encoder */
89#define I2C_DRIVERID_MAX1617 56 /* temp sensor */
90#define I2C_DRIVERID_SAA7191 57 /* video decoder */ 62#define I2C_DRIVERID_SAA7191 57 /* video decoder */
91#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */ 63#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */
92#define I2C_DRIVERID_BT832 59 /* CMOS camera video processor */
93#define I2C_DRIVERID_TDA9887 60 /* TDA988x IF-PLL demodulator */
94#define I2C_DRIVERID_OVCAMCHIP 61 /* OmniVision CMOS image sens. */ 64#define I2C_DRIVERID_OVCAMCHIP 61 /* OmniVision CMOS image sens. */
95#define I2C_DRIVERID_TDA7313 62 /* TDA7313 audio processor */
96#define I2C_DRIVERID_MAX6900 63 /* MAX6900 real-time clock */ 65#define I2C_DRIVERID_MAX6900 63 /* MAX6900 real-time clock */
97#define I2C_DRIVERID_SAA7114H 64 /* video decoder */
98#define I2C_DRIVERID_DS1374 65 /* DS1374 real time clock */
99#define I2C_DRIVERID_TDA9874 66 /* TV sound decoder */ 66#define I2C_DRIVERID_TDA9874 66 /* TV sound decoder */
100#define I2C_DRIVERID_SAA6752HS 67 /* MPEG2 encoder */ 67#define I2C_DRIVERID_SAA6752HS 67 /* MPEG2 encoder */
101#define I2C_DRIVERID_TVEEPROM 68 /* TV EEPROM */ 68#define I2C_DRIVERID_TVEEPROM 68 /* TV EEPROM */
@@ -114,7 +81,6 @@
114#define I2C_DRIVERID_DS1672 81 /* Dallas/Maxim DS1672 RTC */ 81#define I2C_DRIVERID_DS1672 81 /* Dallas/Maxim DS1672 RTC */
115#define I2C_DRIVERID_X1205 82 /* Xicor/Intersil X1205 RTC */ 82#define I2C_DRIVERID_X1205 82 /* Xicor/Intersil X1205 RTC */
116#define I2C_DRIVERID_PCF8563 83 /* Philips PCF8563 RTC */ 83#define I2C_DRIVERID_PCF8563 83 /* Philips PCF8563 RTC */
117#define I2C_DRIVERID_RS5C372 84 /* Ricoh RS5C372 RTC */
118#define I2C_DRIVERID_BT866 85 /* Conexant bt866 video encoder */ 84#define I2C_DRIVERID_BT866 85 /* Conexant bt866 video encoder */
119#define I2C_DRIVERID_KS0127 86 /* Samsung ks0127 video decoder */ 85#define I2C_DRIVERID_KS0127 86 /* Samsung ks0127 video decoder */
120#define I2C_DRIVERID_TLV320AIC23B 87 /* TI TLV320AIC23B audio codec */ 86#define I2C_DRIVERID_TLV320AIC23B 87 /* TI TLV320AIC23B audio codec */
@@ -129,8 +95,6 @@
129#define I2C_DRIVERID_CS5345 96 /* cs5345 audio processor */ 95#define I2C_DRIVERID_CS5345 96 /* cs5345 audio processor */
130 96
131#define I2C_DRIVERID_I2CDEV 900 97#define I2C_DRIVERID_I2CDEV 900
132#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
133#define I2C_DRIVERID_ALERT 903 /* SMBus Alert Responder Client */
134 98
135/* IDs -- Use DRIVERIDs 1000-1999 for sensors. 99/* IDs -- Use DRIVERIDs 1000-1999 for sensors.
136 These were originally in sensors.h in the lm_sensors package */ 100 These were originally in sensors.h in the lm_sensors package */
@@ -176,24 +140,16 @@
176 140
177/* --- Bit algorithm adapters */ 141/* --- Bit algorithm adapters */
178#define I2C_HW_B_LP 0x010000 /* Parallel port Philips style */ 142#define I2C_HW_B_LP 0x010000 /* Parallel port Philips style */
179#define I2C_HW_B_SER 0x010002 /* Serial line interface */
180#define I2C_HW_B_BT848 0x010005 /* BT848 video boards */ 143#define I2C_HW_B_BT848 0x010005 /* BT848 video boards */
181#define I2C_HW_B_WNV 0x010006 /* Winnov Videums */
182#define I2C_HW_B_VIA 0x010007 /* Via vt82c586b */ 144#define I2C_HW_B_VIA 0x010007 /* Via vt82c586b */
183#define I2C_HW_B_HYDRA 0x010008 /* Apple Hydra Mac I/O */ 145#define I2C_HW_B_HYDRA 0x010008 /* Apple Hydra Mac I/O */
184#define I2C_HW_B_G400 0x010009 /* Matrox G400 */ 146#define I2C_HW_B_G400 0x010009 /* Matrox G400 */
185#define I2C_HW_B_I810 0x01000a /* Intel I810 */ 147#define I2C_HW_B_I810 0x01000a /* Intel I810 */
186#define I2C_HW_B_VOO 0x01000b /* 3dfx Voodoo 3 / Banshee */ 148#define I2C_HW_B_VOO 0x01000b /* 3dfx Voodoo 3 / Banshee */
187#define I2C_HW_B_PPORT 0x01000c /* Primitive parallel port adapter */
188#define I2C_HW_B_SAVG 0x01000d /* Savage 4 */
189#define I2C_HW_B_SCX200 0x01000e /* Nat'l Semi SCx200 I2C */ 149#define I2C_HW_B_SCX200 0x01000e /* Nat'l Semi SCx200 I2C */
190#define I2C_HW_B_RIVA 0x010010 /* Riva based graphics cards */ 150#define I2C_HW_B_RIVA 0x010010 /* Riva based graphics cards */
191#define I2C_HW_B_IOC 0x010011 /* IOC bit-wiggling */ 151#define I2C_HW_B_IOC 0x010011 /* IOC bit-wiggling */
192#define I2C_HW_B_TSUNA 0x010012 /* DEC Tsunami chipset */
193#define I2C_HW_B_OMAHA 0x010014 /* Omaha I2C interface (ARM) */
194#define I2C_HW_B_GUIDE 0x010015 /* Guide bit-basher */
195#define I2C_HW_B_IXP2000 0x010016 /* GPIO on IXP2000 systems */ 152#define I2C_HW_B_IXP2000 0x010016 /* GPIO on IXP2000 systems */
196#define I2C_HW_B_IXP4XX 0x010017 /* GPIO on IXP4XX systems */
197#define I2C_HW_B_S3VIA 0x010018 /* S3Via ProSavage adapter */ 153#define I2C_HW_B_S3VIA 0x010018 /* S3Via ProSavage adapter */
198#define I2C_HW_B_ZR36067 0x010019 /* Zoran-36057/36067 based boards */ 154#define I2C_HW_B_ZR36067 0x010019 /* Zoran-36057/36067 based boards */
199#define I2C_HW_B_PCILYNX 0x01001a /* TI PCILynx I2C adapter */ 155#define I2C_HW_B_PCILYNX 0x01001a /* TI PCILynx I2C adapter */
@@ -207,22 +163,11 @@
207#define I2C_HW_B_CX23885 0x010022 /* conexant 23885 based tv cards (bus1) */ 163#define I2C_HW_B_CX23885 0x010022 /* conexant 23885 based tv cards (bus1) */
208 164
209/* --- PCF 8584 based algorithms */ 165/* --- PCF 8584 based algorithms */
210#define I2C_HW_P_LP 0x020000 /* Parallel port interface */
211#define I2C_HW_P_ISA 0x020001 /* generic ISA Bus inteface card */
212#define I2C_HW_P_ELEK 0x020002 /* Elektor ISA Bus inteface card */ 166#define I2C_HW_P_ELEK 0x020002 /* Elektor ISA Bus inteface card */
213 167
214/* --- PCA 9564 based algorithms */ 168/* --- PCA 9564 based algorithms */
215#define I2C_HW_A_ISA 0x1a0000 /* generic ISA Bus interface card */ 169#define I2C_HW_A_ISA 0x1a0000 /* generic ISA Bus interface card */
216 170
217/* --- ACPI Embedded controller algorithms */
218#define I2C_HW_ACPI_EC 0x1f0000
219
220/* --- MPC824x PowerPC adapters */
221#define I2C_HW_MPC824X 0x100001 /* Motorola 8240 / 8245 */
222
223/* --- MPC8xx PowerPC adapters */
224#define I2C_HW_MPC8XX_EPON 0x110000 /* Eponymous MPC8xx I2C adapter */
225
226/* --- PowerPC on-chip adapters */ 171/* --- PowerPC on-chip adapters */
227#define I2C_HW_OCP 0x120000 /* IBM on-chip I2C adapter */ 172#define I2C_HW_OCP 0x120000 /* IBM on-chip I2C adapter */
228 173
@@ -231,7 +176,6 @@
231 176
232/* --- SGI adapters */ 177/* --- SGI adapters */
233#define I2C_HW_SGI_VINO 0x160000 178#define I2C_HW_SGI_VINO 0x160000
234#define I2C_HW_SGI_MACE 0x160001
235 179
236/* --- XSCALE on-chip adapters */ 180/* --- XSCALE on-chip adapters */
237#define I2C_HW_IOP3XX 0x140000 181#define I2C_HW_IOP3XX 0x140000
@@ -255,17 +199,10 @@
255#define I2C_HW_SMBUS_W9968CF 0x04000d 199#define I2C_HW_SMBUS_W9968CF 0x04000d
256#define I2C_HW_SMBUS_OV511 0x04000e /* OV511(+) USB 1.1 webcam ICs */ 200#define I2C_HW_SMBUS_OV511 0x04000e /* OV511(+) USB 1.1 webcam ICs */
257#define I2C_HW_SMBUS_OV518 0x04000f /* OV518(+) USB 1.1 webcam ICs */ 201#define I2C_HW_SMBUS_OV518 0x04000f /* OV518(+) USB 1.1 webcam ICs */
258#define I2C_HW_SMBUS_OV519 0x040010 /* OV519 USB 1.1 webcam IC */
259#define I2C_HW_SMBUS_OVFX2 0x040011 /* Cypress/OmniVision FX2 webcam */ 202#define I2C_HW_SMBUS_OVFX2 0x040011 /* Cypress/OmniVision FX2 webcam */
260#define I2C_HW_SMBUS_CAFE 0x040012 /* Marvell 88ALP01 "CAFE" cam */ 203#define I2C_HW_SMBUS_CAFE 0x040012 /* Marvell 88ALP01 "CAFE" cam */
261#define I2C_HW_SMBUS_ALI1563 0x040013 204#define I2C_HW_SMBUS_ALI1563 0x040013
262 205
263/* --- ISA pseudo-adapter */
264#define I2C_HW_ISA 0x050000
265
266/* --- IPMB adapter */
267#define I2C_HW_IPMB 0x0c0000
268
269/* --- MCP107 adapter */ 206/* --- MCP107 adapter */
270#define I2C_HW_MPC107 0x0d0000 207#define I2C_HW_MPC107 0x0d0000
271 208
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index a100c9f8eb7c..76014f8f3c60 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -140,7 +140,6 @@ struct i2c_driver {
140 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg); 140 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
141 141
142 struct device_driver driver; 142 struct device_driver driver;
143 struct list_head list;
144}; 143};
145#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) 144#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
146 145
@@ -155,12 +154,11 @@ struct i2c_driver {
155 * generic enough to hide second-sourcing and compatible revisions. 154 * generic enough to hide second-sourcing and compatible revisions.
156 * @adapter: manages the bus segment hosting this I2C device 155 * @adapter: manages the bus segment hosting this I2C device
157 * @driver: device's driver, hence pointer to access routines 156 * @driver: device's driver, hence pointer to access routines
158 * @usage_count: counts current number of users of this client
159 * @dev: Driver model device node for the slave. 157 * @dev: Driver model device node for the slave.
160 * @irq: indicates the IRQ generated by this device (if any) 158 * @irq: indicates the IRQ generated by this device (if any)
161 * @driver_name: Identifies new-style driver used with this device; also 159 * @driver_name: Identifies new-style driver used with this device; also
162 * used as the module name for hotplug/coldplug modprobe support. 160 * used as the module name for hotplug/coldplug modprobe support.
163 * @list: list of active/busy clients 161 * @list: list of active/busy clients (DEPRECATED)
164 * @released: used to synchronize client releases & detaches and references 162 * @released: used to synchronize client releases & detaches and references
165 * 163 *
166 * An i2c_client identifies a single device (i.e. chip) connected to an 164 * An i2c_client identifies a single device (i.e. chip) connected to an
@@ -175,16 +173,16 @@ struct i2c_client {
175 char name[I2C_NAME_SIZE]; 173 char name[I2C_NAME_SIZE];
176 struct i2c_adapter *adapter; /* the adapter we sit on */ 174 struct i2c_adapter *adapter; /* the adapter we sit on */
177 struct i2c_driver *driver; /* and our access routines */ 175 struct i2c_driver *driver; /* and our access routines */
178 int usage_count; /* How many accesses currently */
179 /* to the client */
180 struct device dev; /* the device structure */ 176 struct device dev; /* the device structure */
181 int irq; /* irq issued by device (or -1) */ 177 int irq; /* irq issued by device (or -1) */
182 char driver_name[KOBJ_NAME_LEN]; 178 char driver_name[KOBJ_NAME_LEN];
183 struct list_head list; 179 struct list_head list; /* DEPRECATED */
184 struct completion released; 180 struct completion released;
185}; 181};
186#define to_i2c_client(d) container_of(d, struct i2c_client, dev) 182#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
187 183
184extern struct i2c_client *i2c_verify_client(struct device *dev);
185
188static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj) 186static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
189{ 187{
190 struct device * const dev = container_of(kobj, struct device, kobj); 188 struct device * const dev = container_of(kobj, struct device, kobj);
@@ -261,6 +259,12 @@ i2c_new_probed_device(struct i2c_adapter *adap,
261 struct i2c_board_info *info, 259 struct i2c_board_info *info,
262 unsigned short const *addr_list); 260 unsigned short const *addr_list);
263 261
262/* For devices that use several addresses, use i2c_new_dummy() to make
263 * client handles for the extra addresses.
264 */
265extern struct i2c_client *
266i2c_new_dummy(struct i2c_adapter *adap, u16 address, const char *type);
267
264extern void i2c_unregister_device(struct i2c_client *); 268extern void i2c_unregister_device(struct i2c_client *);
265 269
266/* Mainboard arch_initcall() code should register all its I2C devices. 270/* Mainboard arch_initcall() code should register all its I2C devices.
@@ -319,8 +323,7 @@ struct i2c_adapter {
319 struct device dev; /* the adapter device */ 323 struct device dev; /* the adapter device */
320 324
321 int nr; 325 int nr;
322 struct list_head clients; 326 struct list_head clients; /* DEPRECATED */
323 struct list_head list;
324 char name[48]; 327 char name[48];
325 struct completion dev_released; 328 struct completion dev_released;
326}; 329};
@@ -357,10 +360,10 @@ static inline void i2c_set_adapdata (struct i2c_adapter *dev, void *data)
357 * command line 360 * command line
358 */ 361 */
359struct i2c_client_address_data { 362struct i2c_client_address_data {
360 unsigned short *normal_i2c; 363 const unsigned short *normal_i2c;
361 unsigned short *probe; 364 const unsigned short *probe;
362 unsigned short *ignore; 365 const unsigned short *ignore;
363 unsigned short **forces; 366 const unsigned short * const *forces;
364}; 367};
365 368
366/* Internal numbers to terminate lists */ 369/* Internal numbers to terminate lists */
@@ -389,11 +392,8 @@ static inline int i2c_add_driver(struct i2c_driver *driver)
389extern int i2c_attach_client(struct i2c_client *); 392extern int i2c_attach_client(struct i2c_client *);
390extern int i2c_detach_client(struct i2c_client *); 393extern int i2c_detach_client(struct i2c_client *);
391 394
392/* Should be used to make sure that client-struct is valid and that it 395extern struct i2c_client *i2c_use_client(struct i2c_client *client);
393 is okay to access the i2c-client. 396extern void i2c_release_client(struct i2c_client *client);
394 returns -ENODEV if client has gone in the meantime */
395extern int i2c_use_client(struct i2c_client *);
396extern int i2c_release_client(struct i2c_client *);
397 397
398/* call the i2c_client->command() of all attached clients with 398/* call the i2c_client->command() of all attached clients with
399 * the given arguments */ 399 * the given arguments */
@@ -405,7 +405,7 @@ extern void i2c_clients_command(struct i2c_adapter *adap,
405 * specific address (unless a 'force' matched); 405 * specific address (unless a 'force' matched);
406 */ 406 */
407extern int i2c_probe(struct i2c_adapter *adapter, 407extern int i2c_probe(struct i2c_adapter *adapter,
408 struct i2c_client_address_data *address_data, 408 const struct i2c_client_address_data *address_data,
409 int (*found_proc) (struct i2c_adapter *, int, int)); 409 int (*found_proc) (struct i2c_adapter *, int, int));
410 410
411extern struct i2c_adapter* i2c_get_adapter(int id); 411extern struct i2c_adapter* i2c_get_adapter(int id);
@@ -598,104 +598,93 @@ I2C_CLIENT_MODULE_PARM(probe, "List of adapter,address pairs to scan " \
598 "additionally"); \ 598 "additionally"); \
599I2C_CLIENT_MODULE_PARM(ignore, "List of adapter,address pairs not to " \ 599I2C_CLIENT_MODULE_PARM(ignore, "List of adapter,address pairs not to " \
600 "scan"); \ 600 "scan"); \
601static struct i2c_client_address_data addr_data = { \ 601const static struct i2c_client_address_data addr_data = { \
602 .normal_i2c = normal_i2c, \ 602 .normal_i2c = normal_i2c, \
603 .probe = probe, \ 603 .probe = probe, \
604 .ignore = ignore, \ 604 .ignore = ignore, \
605 .forces = forces, \ 605 .forces = forces, \
606} 606}
607 607
608#define I2C_CLIENT_FORCE_TEXT \
609 "List of adapter,address pairs to boldly assume to be present"
610
608/* These are the ones you want to use in your own drivers. Pick the one 611/* These are the ones you want to use in your own drivers. Pick the one
609 which matches the number of devices the driver differenciates between. */ 612 which matches the number of devices the driver differenciates between. */
610#define I2C_CLIENT_INSMOD \ 613#define I2C_CLIENT_INSMOD \
611 I2C_CLIENT_MODULE_PARM(force, \ 614I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
612 "List of adapter,address pairs to boldly assume " \ 615static const unsigned short * const forces[] = { force, NULL }; \
613 "to be present"); \
614 static unsigned short *forces[] = { \
615 force, \
616 NULL \
617 }; \
618I2C_CLIENT_INSMOD_COMMON 616I2C_CLIENT_INSMOD_COMMON
619 617
620#define I2C_CLIENT_INSMOD_1(chip1) \ 618#define I2C_CLIENT_INSMOD_1(chip1) \
621enum chips { any_chip, chip1 }; \ 619enum chips { any_chip, chip1 }; \
622I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ 620I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
623 "boldly assume to be present"); \
624I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ 621I2C_CLIENT_MODULE_PARM_FORCE(chip1); \
625static unsigned short *forces[] = { force, force_##chip1, NULL }; \ 622static const unsigned short * const forces[] = { force, \
623 force_##chip1, NULL }; \
626I2C_CLIENT_INSMOD_COMMON 624I2C_CLIENT_INSMOD_COMMON
627 625
628#define I2C_CLIENT_INSMOD_2(chip1, chip2) \ 626#define I2C_CLIENT_INSMOD_2(chip1, chip2) \
629enum chips { any_chip, chip1, chip2 }; \ 627enum chips { any_chip, chip1, chip2 }; \
630I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ 628I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
631 "boldly assume to be present"); \
632I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ 629I2C_CLIENT_MODULE_PARM_FORCE(chip1); \
633I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ 630I2C_CLIENT_MODULE_PARM_FORCE(chip2); \
634static unsigned short *forces[] = { force, force_##chip1, \ 631static const unsigned short * const forces[] = { force, \
635 force_##chip2, NULL }; \ 632 force_##chip1, force_##chip2, NULL }; \
636I2C_CLIENT_INSMOD_COMMON 633I2C_CLIENT_INSMOD_COMMON
637 634
638#define I2C_CLIENT_INSMOD_3(chip1, chip2, chip3) \ 635#define I2C_CLIENT_INSMOD_3(chip1, chip2, chip3) \
639enum chips { any_chip, chip1, chip2, chip3 }; \ 636enum chips { any_chip, chip1, chip2, chip3 }; \
640I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ 637I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
641 "boldly assume to be present"); \
642I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ 638I2C_CLIENT_MODULE_PARM_FORCE(chip1); \
643I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ 639I2C_CLIENT_MODULE_PARM_FORCE(chip2); \
644I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ 640I2C_CLIENT_MODULE_PARM_FORCE(chip3); \
645static unsigned short *forces[] = { force, force_##chip1, \ 641static const unsigned short * const forces[] = { force, \
646 force_##chip2, force_##chip3, \ 642 force_##chip1, force_##chip2, force_##chip3, NULL }; \
647 NULL }; \
648I2C_CLIENT_INSMOD_COMMON 643I2C_CLIENT_INSMOD_COMMON
649 644
650#define I2C_CLIENT_INSMOD_4(chip1, chip2, chip3, chip4) \ 645#define I2C_CLIENT_INSMOD_4(chip1, chip2, chip3, chip4) \
651enum chips { any_chip, chip1, chip2, chip3, chip4 }; \ 646enum chips { any_chip, chip1, chip2, chip3, chip4 }; \
652I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ 647I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
653 "boldly assume to be present"); \
654I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ 648I2C_CLIENT_MODULE_PARM_FORCE(chip1); \
655I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ 649I2C_CLIENT_MODULE_PARM_FORCE(chip2); \
656I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ 650I2C_CLIENT_MODULE_PARM_FORCE(chip3); \
657I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ 651I2C_CLIENT_MODULE_PARM_FORCE(chip4); \
658static unsigned short *forces[] = { force, force_##chip1, \ 652static const unsigned short * const forces[] = { force, \
659 force_##chip2, force_##chip3, \ 653 force_##chip1, force_##chip2, force_##chip3, \
660 force_##chip4, NULL}; \ 654 force_##chip4, NULL}; \
661I2C_CLIENT_INSMOD_COMMON 655I2C_CLIENT_INSMOD_COMMON
662 656
663#define I2C_CLIENT_INSMOD_5(chip1, chip2, chip3, chip4, chip5) \ 657#define I2C_CLIENT_INSMOD_5(chip1, chip2, chip3, chip4, chip5) \
664enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \ 658enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \
665I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ 659I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
666 "boldly assume to be present"); \
667I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ 660I2C_CLIENT_MODULE_PARM_FORCE(chip1); \
668I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ 661I2C_CLIENT_MODULE_PARM_FORCE(chip2); \
669I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ 662I2C_CLIENT_MODULE_PARM_FORCE(chip3); \
670I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ 663I2C_CLIENT_MODULE_PARM_FORCE(chip4); \
671I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ 664I2C_CLIENT_MODULE_PARM_FORCE(chip5); \
672static unsigned short *forces[] = { force, force_##chip1, \ 665static const unsigned short * const forces[] = { force, \
673 force_##chip2, force_##chip3, \ 666 force_##chip1, force_##chip2, force_##chip3, \
674 force_##chip4, force_##chip5, \ 667 force_##chip4, force_##chip5, NULL }; \
675 NULL }; \
676I2C_CLIENT_INSMOD_COMMON 668I2C_CLIENT_INSMOD_COMMON
677 669
678#define I2C_CLIENT_INSMOD_6(chip1, chip2, chip3, chip4, chip5, chip6) \ 670#define I2C_CLIENT_INSMOD_6(chip1, chip2, chip3, chip4, chip5, chip6) \
679enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \ 671enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \
680I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ 672I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
681 "boldly assume to be present"); \
682I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ 673I2C_CLIENT_MODULE_PARM_FORCE(chip1); \
683I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ 674I2C_CLIENT_MODULE_PARM_FORCE(chip2); \
684I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ 675I2C_CLIENT_MODULE_PARM_FORCE(chip3); \
685I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ 676I2C_CLIENT_MODULE_PARM_FORCE(chip4); \
686I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ 677I2C_CLIENT_MODULE_PARM_FORCE(chip5); \
687I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ 678I2C_CLIENT_MODULE_PARM_FORCE(chip6); \
688static unsigned short *forces[] = { force, force_##chip1, \ 679static const unsigned short * const forces[] = { force, \
689 force_##chip2, force_##chip3, \ 680 force_##chip1, force_##chip2, force_##chip3, \
690 force_##chip4, force_##chip5, \ 681 force_##chip4, force_##chip5, force_##chip6, NULL }; \
691 force_##chip6, NULL }; \
692I2C_CLIENT_INSMOD_COMMON 682I2C_CLIENT_INSMOD_COMMON
693 683
694#define I2C_CLIENT_INSMOD_7(chip1, chip2, chip3, chip4, chip5, chip6, chip7) \ 684#define I2C_CLIENT_INSMOD_7(chip1, chip2, chip3, chip4, chip5, chip6, chip7) \
695enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, \ 685enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, \
696 chip7 }; \ 686 chip7 }; \
697I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ 687I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
698 "boldly assume to be present"); \
699I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ 688I2C_CLIENT_MODULE_PARM_FORCE(chip1); \
700I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ 689I2C_CLIENT_MODULE_PARM_FORCE(chip2); \
701I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ 690I2C_CLIENT_MODULE_PARM_FORCE(chip3); \
@@ -703,18 +692,16 @@ I2C_CLIENT_MODULE_PARM_FORCE(chip4); \
703I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ 692I2C_CLIENT_MODULE_PARM_FORCE(chip5); \
704I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ 693I2C_CLIENT_MODULE_PARM_FORCE(chip6); \
705I2C_CLIENT_MODULE_PARM_FORCE(chip7); \ 694I2C_CLIENT_MODULE_PARM_FORCE(chip7); \
706static unsigned short *forces[] = { force, force_##chip1, \ 695static const unsigned short * const forces[] = { force, \
707 force_##chip2, force_##chip3, \ 696 force_##chip1, force_##chip2, force_##chip3, \
708 force_##chip4, force_##chip5, \ 697 force_##chip4, force_##chip5, force_##chip6, \
709 force_##chip6, force_##chip7, \ 698 force_##chip7, NULL }; \
710 NULL }; \
711I2C_CLIENT_INSMOD_COMMON 699I2C_CLIENT_INSMOD_COMMON
712 700
713#define I2C_CLIENT_INSMOD_8(chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8) \ 701#define I2C_CLIENT_INSMOD_8(chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8) \
714enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, \ 702enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, \
715 chip7, chip8 }; \ 703 chip7, chip8 }; \
716I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ 704I2C_CLIENT_MODULE_PARM(force, I2C_CLIENT_FORCE_TEXT); \
717 "boldly assume to be present"); \
718I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ 705I2C_CLIENT_MODULE_PARM_FORCE(chip1); \
719I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ 706I2C_CLIENT_MODULE_PARM_FORCE(chip2); \
720I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ 707I2C_CLIENT_MODULE_PARM_FORCE(chip3); \
@@ -723,11 +710,10 @@ I2C_CLIENT_MODULE_PARM_FORCE(chip5); \
723I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ 710I2C_CLIENT_MODULE_PARM_FORCE(chip6); \
724I2C_CLIENT_MODULE_PARM_FORCE(chip7); \ 711I2C_CLIENT_MODULE_PARM_FORCE(chip7); \
725I2C_CLIENT_MODULE_PARM_FORCE(chip8); \ 712I2C_CLIENT_MODULE_PARM_FORCE(chip8); \
726static unsigned short *forces[] = { force, force_##chip1, \ 713static const unsigned short * const forces[] = { force, \
727 force_##chip2, force_##chip3, \ 714 force_##chip1, force_##chip2, force_##chip3, \
728 force_##chip4, force_##chip5, \ 715 force_##chip4, force_##chip5, force_##chip6, \
729 force_##chip6, force_##chip7, \ 716 force_##chip7, force_##chip8, NULL }; \
730 force_##chip8, NULL }; \
731I2C_CLIENT_INSMOD_COMMON 717I2C_CLIENT_INSMOD_COMMON
732#endif /* __KERNEL__ */ 718#endif /* __KERNEL__ */
733#endif /* _LINUX_I2C_H */ 719#endif /* _LINUX_I2C_H */
diff --git a/include/asm-arm/arch-omap/tps65010.h b/include/linux/i2c/tps65010.h
index b9aa2b3a3909..7021635ed6a0 100644
--- a/include/asm-arm/arch-omap/tps65010.h
+++ b/include/linux/i2c/tps65010.h
@@ -1,4 +1,4 @@
1/* linux/include/asm-arm/arch-omap/tps65010.h 1/* linux/i2c/tps65010.h
2 * 2 *
3 * Functions to access TPS65010 power management device. 3 * Functions to access TPS65010 power management device.
4 * 4 *
@@ -25,8 +25,8 @@
25 * 675 Mass Ave, Cambridge, MA 02139, USA. 25 * 675 Mass Ave, Cambridge, MA 02139, USA.
26 */ 26 */
27 27
28#ifndef __ASM_ARCH_TPS65010_H 28#ifndef __LINUX_I2C_TPS65010_H
29#define __ASM_ARCH_TPS65010_H 29#define __LINUX_I2C_TPS65010_H
30 30
31/* 31/*
32 * ---------------------------------------------------------------------------- 32 * ----------------------------------------------------------------------------
@@ -152,5 +152,5 @@ extern int tps65010_config_vregs1(unsigned value);
152 */ 152 */
153extern int tps65013_set_low_pwr(unsigned mode); 153extern int tps65013_set_low_pwr(unsigned mode);
154 154
155#endif /* __ASM_ARCH_TPS65010_H */ 155#endif /* __LINUX_I2C_TPS65010_H */
156 156
diff --git a/include/linux/m41t00.h b/include/linux/m41t00.h
deleted file mode 100644
index b423360ca38e..000000000000
--- a/include/linux/m41t00.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 * Definitions for the ST M41T00 family of i2c rtc chips.
3 *
4 * Author: Mark A. Greer <mgreer@mvista.com>
5 *
6 * 2005, 2006 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11
12#ifndef _M41T00_H
13#define _M41T00_H
14
15#define M41T00_DRV_NAME "m41t00"
16#define M41T00_I2C_ADDR 0x68
17
18#define M41T00_TYPE_M41T00 0
19#define M41T00_TYPE_M41T81 81
20#define M41T00_TYPE_M41T85 85
21
22struct m41t00_platform_data {
23 u8 type;
24 u8 i2c_addr;
25 u8 sqw_freq;
26};
27
28/* SQW output disabled, this is default value by power on */
29#define M41T00_SQW_DISABLE (0)
30
31#define M41T00_SQW_32KHZ (1<<4) /* 32.768 KHz */
32#define M41T00_SQW_8KHZ (2<<4) /* 8.192 KHz */
33#define M41T00_SQW_4KHZ (3<<4) /* 4.096 KHz */
34#define M41T00_SQW_2KHZ (4<<4) /* 2.048 KHz */
35#define M41T00_SQW_1KHZ (5<<4) /* 1.024 KHz */
36#define M41T00_SQW_512HZ (6<<4) /* 512 Hz */
37#define M41T00_SQW_256HZ (7<<4) /* 256 Hz */
38#define M41T00_SQW_128HZ (8<<4) /* 128 Hz */
39#define M41T00_SQW_64HZ (9<<4) /* 64 Hz */
40#define M41T00_SQW_32HZ (10<<4) /* 32 Hz */
41#define M41T00_SQW_16HZ (11<<4) /* 16 Hz */
42#define M41T00_SQW_8HZ (12<<4) /* 8 Hz */
43#define M41T00_SQW_4HZ (13<<4) /* 4 Hz */
44#define M41T00_SQW_2HZ (14<<4) /* 2 Hz */
45#define M41T00_SQW_1HZ (15<<4) /* 1 Hz */
46
47extern ulong m41t00_get_rtc_time(void);
48extern int m41t00_set_rtc_time(ulong nowtime);
49
50#endif /* _M41T00_H */
diff --git a/include/media/v4l2-i2c-drv-legacy.h b/include/media/v4l2-i2c-drv-legacy.h
index 241854229d6f..e7645578fc22 100644
--- a/include/media/v4l2-i2c-drv-legacy.h
+++ b/include/media/v4l2-i2c-drv-legacy.h
@@ -34,7 +34,7 @@ struct v4l2_i2c_driver_data {
34}; 34};
35 35
36static struct v4l2_i2c_driver_data v4l2_i2c_data; 36static struct v4l2_i2c_driver_data v4l2_i2c_data;
37static struct i2c_client_address_data addr_data; 37static const struct i2c_client_address_data addr_data;
38static struct i2c_driver v4l2_i2c_driver_legacy; 38static struct i2c_driver v4l2_i2c_driver_legacy;
39static char v4l2_i2c_drv_name_legacy[32]; 39static char v4l2_i2c_drv_name_legacy[32];
40 40
diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c
index 272ae38e9b18..bb7d744faff5 100644
--- a/sound/ppc/keywest.c
+++ b/sound/ppc/keywest.c
@@ -34,8 +34,6 @@
34static struct pmac_keywest *keywest_ctx; 34static struct pmac_keywest *keywest_ctx;
35 35
36 36
37#define I2C_DRIVERID_KEYWEST 0xFEBA
38
39static int keywest_attach_adapter(struct i2c_adapter *adapter); 37static int keywest_attach_adapter(struct i2c_adapter *adapter);
40static int keywest_detach_client(struct i2c_client *client); 38static int keywest_detach_client(struct i2c_client *client);
41 39
@@ -43,7 +41,6 @@ struct i2c_driver keywest_driver = {
43 .driver = { 41 .driver = {
44 .name = "PMac Keywest Audio", 42 .name = "PMac Keywest Audio",
45 }, 43 },
46 .id = I2C_DRIVERID_KEYWEST,
47 .attach_adapter = &keywest_attach_adapter, 44 .attach_adapter = &keywest_attach_adapter,
48 .detach_client = &keywest_detach_client, 45 .detach_client = &keywest_detach_client,
49}; 46};
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index abac62866da8..dab22cc97ead 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -234,7 +234,7 @@ static int cs4270_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
234 * lower three bits are determined via the AD2, AD1, and AD0 pins 234 * lower three bits are determined via the AD2, AD1, and AD0 pins
235 * (respectively). 235 * (respectively).
236 */ 236 */
237static unsigned short normal_i2c[] = { 237static const unsigned short normal_i2c[] = {
238 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END 238 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END
239}; 239};
240I2C_CLIENT_INSMOD; 240I2C_CLIENT_INSMOD;
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index d5a8fc2cf8d6..f1f6b9478af9 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -573,7 +573,7 @@ static struct snd_soc_device neo1973_snd_devdata = {
573 573
574static struct i2c_client client_template; 574static struct i2c_client client_template;
575 575
576static unsigned short normal_i2c[] = { 0x7C, I2C_CLIENT_END }; 576static const unsigned short normal_i2c[] = { 0x7C, I2C_CLIENT_END };
577 577
578/* Magic definition of all other variables and things */ 578/* Magic definition of all other variables and things */
579I2C_CLIENT_INSMOD; 579I2C_CLIENT_INSMOD;