aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c36
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-at91.c3
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c168
-rw-r--r--drivers/i2c/busses/i2c-cpm.c2
-rw-r--r--drivers/i2c/busses/i2c-elektor.c2
-rw-r--r--drivers/i2c/busses/i2c-gpio.c2
-rw-r--r--drivers/i2c/busses/i2c-highlander.c5
-rw-r--r--drivers/i2c/busses/i2c-hydra.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c59
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c16
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c3
-rw-r--r--drivers/i2c/busses/i2c-mpc.c6
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c3
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c12
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c6
-rw-r--r--drivers/i2c/busses/i2c-ocores.c2
-rw-r--r--drivers/i2c/busses/i2c-omap.c265
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c2
-rw-r--r--drivers/i2c/busses/i2c-parport.c2
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c2
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-pmcmsp.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa.c28
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c21
-rw-r--r--drivers/i2c/busses/i2c-s6000.c2
-rw-r--r--drivers/i2c/busses/i2c-sh7760.c2
-rw-r--r--drivers/i2c/busses/i2c-sibyte.c2
-rw-r--r--drivers/i2c/busses/i2c-simtec.c3
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/busses/i2c-sis630.c2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-stub.c9
-rw-r--r--drivers/i2c/busses/i2c-versatile.c3
-rw-r--r--drivers/i2c/busses/i2c-via.c2
-rw-r--r--drivers/i2c/busses/i2c-viapro.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c4
-rw-r--r--drivers/i2c/busses/scx200_i2c.c2
-rw-r--r--drivers/i2c/i2c-core.c256
-rw-r--r--drivers/i2c/i2c-dev.c36
45 files changed, 595 insertions, 397 deletions
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index dcdaf8e675bf..2b9a8f54bb2c 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -109,13 +109,13 @@ static void pca_stop(struct i2c_algo_pca_data *adap)
109 * returns after the address has been sent 109 * returns after the address has been sent
110 */ 110 */
111static int pca_address(struct i2c_algo_pca_data *adap, 111static int pca_address(struct i2c_algo_pca_data *adap,
112 struct i2c_msg *msg) 112 struct i2c_msg *msg)
113{ 113{
114 int sta = pca_get_con(adap); 114 int sta = pca_get_con(adap);
115 int addr; 115 int addr;
116 116
117 addr = ( (0x7f & msg->addr) << 1 ); 117 addr = ((0x7f & msg->addr) << 1);
118 if (msg->flags & I2C_M_RD ) 118 if (msg->flags & I2C_M_RD)
119 addr |= 1; 119 addr |= 1;
120 DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n", 120 DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n",
121 msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr); 121 msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr);
@@ -134,7 +134,7 @@ static int pca_address(struct i2c_algo_pca_data *adap,
134 * Returns after the byte has been transmitted 134 * Returns after the byte has been transmitted
135 */ 135 */
136static int pca_tx_byte(struct i2c_algo_pca_data *adap, 136static int pca_tx_byte(struct i2c_algo_pca_data *adap,
137 __u8 b) 137 __u8 b)
138{ 138{
139 int sta = pca_get_con(adap); 139 int sta = pca_get_con(adap);
140 DEB2("=== WRITE %#04x\n", b); 140 DEB2("=== WRITE %#04x\n", b);
@@ -164,13 +164,13 @@ static void pca_rx_byte(struct i2c_algo_pca_data *adap,
164 * Returns after next byte has arrived. 164 * Returns after next byte has arrived.
165 */ 165 */
166static int pca_rx_ack(struct i2c_algo_pca_data *adap, 166static int pca_rx_ack(struct i2c_algo_pca_data *adap,
167 int ack) 167 int ack)
168{ 168{
169 int sta = pca_get_con(adap); 169 int sta = pca_get_con(adap);
170 170
171 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI|I2C_PCA_CON_AA); 171 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI|I2C_PCA_CON_AA);
172 172
173 if ( ack ) 173 if (ack)
174 sta |= I2C_PCA_CON_AA; 174 sta |= I2C_PCA_CON_AA;
175 175
176 pca_set_con(adap, sta); 176 pca_set_con(adap, sta);
@@ -178,12 +178,12 @@ static int pca_rx_ack(struct i2c_algo_pca_data *adap,
178} 178}
179 179
180static int pca_xfer(struct i2c_adapter *i2c_adap, 180static int pca_xfer(struct i2c_adapter *i2c_adap,
181 struct i2c_msg *msgs, 181 struct i2c_msg *msgs,
182 int num) 182 int num)
183{ 183{
184 struct i2c_algo_pca_data *adap = i2c_adap->algo_data; 184 struct i2c_algo_pca_data *adap = i2c_adap->algo_data;
185 struct i2c_msg *msg = NULL; 185 struct i2c_msg *msg = NULL;
186 int curmsg; 186 int curmsg;
187 int numbytes = 0; 187 int numbytes = 0;
188 int state; 188 int state;
189 int ret; 189 int ret;
@@ -202,21 +202,21 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
202 202
203 DEB1("{{{ XFER %d messages\n", num); 203 DEB1("{{{ XFER %d messages\n", num);
204 204
205 if (i2c_debug>=2) { 205 if (i2c_debug >= 2) {
206 for (curmsg = 0; curmsg < num; curmsg++) { 206 for (curmsg = 0; curmsg < num; curmsg++) {
207 int addr, i; 207 int addr, i;
208 msg = &msgs[curmsg]; 208 msg = &msgs[curmsg];
209 209
210 addr = (0x7f & msg->addr) ; 210 addr = (0x7f & msg->addr) ;
211 211
212 if (msg->flags & I2C_M_RD ) 212 if (msg->flags & I2C_M_RD)
213 printk(KERN_INFO " [%02d] RD %d bytes from %#02x [%#02x, ...]\n", 213 printk(KERN_INFO " [%02d] RD %d bytes from %#02x [%#02x, ...]\n",
214 curmsg, msg->len, addr, (addr<<1) | 1); 214 curmsg, msg->len, addr, (addr << 1) | 1);
215 else { 215 else {
216 printk(KERN_INFO " [%02d] WR %d bytes to %#02x [%#02x%s", 216 printk(KERN_INFO " [%02d] WR %d bytes to %#02x [%#02x%s",
217 curmsg, msg->len, addr, addr<<1, 217 curmsg, msg->len, addr, addr << 1,
218 msg->len == 0 ? "" : ", "); 218 msg->len == 0 ? "" : ", ");
219 for(i=0; i < msg->len; i++) 219 for (i = 0; i < msg->len; i++)
220 printk("%#04x%s", msg->buf[i], i == msg->len - 1 ? "" : ", "); 220 printk("%#04x%s", msg->buf[i], i == msg->len - 1 ? "" : ", ");
221 printk("]\n"); 221 printk("]\n");
222 } 222 }
@@ -305,7 +305,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
305 goto out; 305 goto out;
306 306
307 case 0x58: /* Data byte has been received; NOT ACK has been returned */ 307 case 0x58: /* Data byte has been received; NOT ACK has been returned */
308 if ( numbytes == msg->len - 1 ) { 308 if (numbytes == msg->len - 1) {
309 pca_rx_byte(adap, &msg->buf[numbytes], 0); 309 pca_rx_byte(adap, &msg->buf[numbytes], 0);
310 curmsg++; numbytes = 0; 310 curmsg++; numbytes = 0;
311 if (curmsg == num) 311 if (curmsg == num)
@@ -352,7 +352,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
352 352
353static u32 pca_func(struct i2c_adapter *adap) 353static u32 pca_func(struct i2c_adapter *adap)
354{ 354{
355 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 355 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
356} 356}
357 357
358static const struct i2c_algorithm pca_algo = { 358static const struct i2c_algorithm pca_algo = {
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index bd8f1e4d9e6c..906a3ca50db6 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -60,7 +60,7 @@
60#include <linux/i2c.h> 60#include <linux/i2c.h>
61#include <linux/init.h> 61#include <linux/init.h>
62#include <linux/acpi.h> 62#include <linux/acpi.h>
63#include <asm/io.h> 63#include <linux/io.h>
64 64
65 65
66/* ALI1535 SMBus address offsets */ 66/* ALI1535 SMBus address offsets */
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 659f63f5e4af..b14f6d68221d 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -67,7 +67,7 @@
67#include <linux/i2c.h> 67#include <linux/i2c.h>
68#include <linux/init.h> 68#include <linux/init.h>
69#include <linux/acpi.h> 69#include <linux/acpi.h>
70#include <asm/io.h> 70#include <linux/io.h>
71 71
72/* ALI15X3 SMBus address offsets */ 72/* ALI15X3 SMBus address offsets */
73#define SMBHSTSTS (0 + ali15x3_smba) 73#define SMBHSTSTS (0 + ali15x3_smba)
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index c5a9fa488e7f..03bcd07c4697 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -43,7 +43,7 @@
43#include <linux/i2c.h> 43#include <linux/i2c.h>
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/acpi.h> 45#include <linux/acpi.h>
46#include <asm/io.h> 46#include <linux/io.h>
47 47
48/* AMD756 SMBus address offsets */ 48/* AMD756 SMBus address offsets */
49#define SMB_ADDR_OFFSET 0xE0 49#define SMB_ADDR_OFFSET 0xE0
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 2fbef27b6cd6..af1e5e254b7b 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -18,7 +18,7 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/acpi.h> 19#include <linux/acpi.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <asm/io.h> 21#include <linux/io.h>
22 22
23MODULE_LICENSE("GPL"); 23MODULE_LICENSE("GPL");
24MODULE_AUTHOR ("Vojtech Pavlik <vojtech@suse.cz>"); 24MODULE_AUTHOR ("Vojtech Pavlik <vojtech@suse.cz>");
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 06e1ecb4919f..305c07504f7e 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -23,8 +23,7 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/clk.h> 24#include <linux/clk.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26 26#include <linux/io.h>
27#include <asm/io.h>
28 27
29#include <mach/at91_twi.h> 28#include <mach/at91_twi.h>
30#include <mach/board.h> 29#include <mach/board.h>
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index f1e14dd590c9..fb26e5c67515 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -25,8 +25,6 @@
25#include <asm/portmux.h> 25#include <asm/portmux.h>
26#include <asm/irq.h> 26#include <asm/irq.h>
27 27
28#define POLL_TIMEOUT (2 * HZ)
29
30/* SMBus mode*/ 28/* SMBus mode*/
31#define TWI_I2C_MODE_STANDARD 1 29#define TWI_I2C_MODE_STANDARD 1
32#define TWI_I2C_MODE_STANDARDSUB 2 30#define TWI_I2C_MODE_STANDARDSUB 2
@@ -44,8 +42,6 @@ struct bfin_twi_iface {
44 int cur_mode; 42 int cur_mode;
45 int manual_stop; 43 int manual_stop;
46 int result; 44 int result;
47 int timeout_count;
48 struct timer_list timeout_timer;
49 struct i2c_adapter adap; 45 struct i2c_adapter adap;
50 struct completion complete; 46 struct completion complete;
51 struct i2c_msg *pmsg; 47 struct i2c_msg *pmsg;
@@ -85,14 +81,15 @@ static const u16 pin_req[2][3] = {
85 {P_TWI1_SCL, P_TWI1_SDA, 0}, 81 {P_TWI1_SCL, P_TWI1_SDA, 0},
86}; 82};
87 83
88static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) 84static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
85 unsigned short twi_int_status)
89{ 86{
90 unsigned short twi_int_status = read_INT_STAT(iface);
91 unsigned short mast_stat = read_MASTER_STAT(iface); 87 unsigned short mast_stat = read_MASTER_STAT(iface);
92 88
93 if (twi_int_status & XMTSERV) { 89 if (twi_int_status & XMTSERV) {
94 /* Transmit next data */ 90 /* Transmit next data */
95 if (iface->writeNum > 0) { 91 if (iface->writeNum > 0) {
92 SSYNC();
96 write_XMT_DATA8(iface, *(iface->transPtr++)); 93 write_XMT_DATA8(iface, *(iface->transPtr++));
97 iface->writeNum--; 94 iface->writeNum--;
98 } 95 }
@@ -114,10 +111,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
114 write_MASTER_CTL(iface, 111 write_MASTER_CTL(iface,
115 (read_MASTER_CTL(iface) | RSTART) & ~MDIR); 112 (read_MASTER_CTL(iface) | RSTART) & ~MDIR);
116 } 113 }
117 SSYNC();
118 /* Clear status */
119 write_INT_STAT(iface, XMTSERV);
120 SSYNC();
121 } 114 }
122 if (twi_int_status & RCVSERV) { 115 if (twi_int_status & RCVSERV) {
123 if (iface->readNum > 0) { 116 if (iface->readNum > 0) {
@@ -139,7 +132,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
139 } else if (iface->manual_stop) { 132 } else if (iface->manual_stop) {
140 write_MASTER_CTL(iface, 133 write_MASTER_CTL(iface,
141 read_MASTER_CTL(iface) | STOP); 134 read_MASTER_CTL(iface) | STOP);
142 SSYNC();
143 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && 135 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
144 iface->cur_msg + 1 < iface->msg_num) { 136 iface->cur_msg + 1 < iface->msg_num) {
145 if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD) 137 if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
@@ -148,44 +140,37 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
148 else 140 else
149 write_MASTER_CTL(iface, 141 write_MASTER_CTL(iface,
150 (read_MASTER_CTL(iface) | RSTART) & ~MDIR); 142 (read_MASTER_CTL(iface) | RSTART) & ~MDIR);
151 SSYNC();
152 } 143 }
153 /* Clear interrupt source */
154 write_INT_STAT(iface, RCVSERV);
155 SSYNC();
156 } 144 }
157 if (twi_int_status & MERR) { 145 if (twi_int_status & MERR) {
158 write_INT_STAT(iface, MERR);
159 write_INT_MASK(iface, 0); 146 write_INT_MASK(iface, 0);
160 write_MASTER_STAT(iface, 0x3e); 147 write_MASTER_STAT(iface, 0x3e);
161 write_MASTER_CTL(iface, 0); 148 write_MASTER_CTL(iface, 0);
162 SSYNC();
163 iface->result = -EIO; 149 iface->result = -EIO;
164 /* if both err and complete int stats are set, return proper 150
165 * results. 151 if (mast_stat & LOSTARB)
152 dev_dbg(&iface->adap.dev, "Lost Arbitration\n");
153 if (mast_stat & ANAK)
154 dev_dbg(&iface->adap.dev, "Address Not Acknowledged\n");
155 if (mast_stat & DNAK)
156 dev_dbg(&iface->adap.dev, "Data Not Acknowledged\n");
157 if (mast_stat & BUFRDERR)
158 dev_dbg(&iface->adap.dev, "Buffer Read Error\n");
159 if (mast_stat & BUFWRERR)
160 dev_dbg(&iface->adap.dev, "Buffer Write Error\n");
161
162 /* If it is a quick transfer, only address without data,
163 * not an err, return 1.
166 */ 164 */
167 if (twi_int_status & MCOMP) { 165 if (iface->cur_mode == TWI_I2C_MODE_STANDARD &&
168 write_INT_STAT(iface, MCOMP); 166 iface->transPtr == NULL &&
169 write_INT_MASK(iface, 0); 167 (twi_int_status & MCOMP) && (mast_stat & DNAK))
170 write_MASTER_CTL(iface, 0); 168 iface->result = 1;
171 SSYNC(); 169
172 /* If it is a quick transfer, only address bug no data,
173 * not an err, return 1.
174 */
175 if (iface->writeNum == 0 && (mast_stat & BUFRDERR))
176 iface->result = 1;
177 /* If address not acknowledged return -1,
178 * else return 0.
179 */
180 else if (!(mast_stat & ANAK))
181 iface->result = 0;
182 }
183 complete(&iface->complete); 170 complete(&iface->complete);
184 return; 171 return;
185 } 172 }
186 if (twi_int_status & MCOMP) { 173 if (twi_int_status & MCOMP) {
187 write_INT_STAT(iface, MCOMP);
188 SSYNC();
189 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { 174 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
190 if (iface->readNum == 0) { 175 if (iface->readNum == 0) {
191 /* set the read number to 1 and ask for manual 176 /* set the read number to 1 and ask for manual
@@ -207,7 +192,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
207 /* remove restart bit and enable master receive */ 192 /* remove restart bit and enable master receive */
208 write_MASTER_CTL(iface, 193 write_MASTER_CTL(iface,
209 read_MASTER_CTL(iface) & ~RSTART); 194 read_MASTER_CTL(iface) & ~RSTART);
210 SSYNC();
211 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && 195 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
212 iface->cur_msg+1 < iface->msg_num) { 196 iface->cur_msg+1 < iface->msg_num) {
213 iface->cur_msg++; 197 iface->cur_msg++;
@@ -226,7 +210,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
226 write_XMT_DATA8(iface, 210 write_XMT_DATA8(iface,
227 *(iface->transPtr++)); 211 *(iface->transPtr++));
228 iface->writeNum--; 212 iface->writeNum--;
229 SSYNC();
230 } 213 }
231 } 214 }
232 215
@@ -244,15 +227,13 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
244 /* remove restart bit and enable master receive */ 227 /* remove restart bit and enable master receive */
245 write_MASTER_CTL(iface, 228 write_MASTER_CTL(iface,
246 read_MASTER_CTL(iface) & ~RSTART); 229 read_MASTER_CTL(iface) & ~RSTART);
247 SSYNC();
248 } else { 230 } else {
249 iface->result = 1; 231 iface->result = 1;
250 write_INT_MASK(iface, 0); 232 write_INT_MASK(iface, 0);
251 write_MASTER_CTL(iface, 0); 233 write_MASTER_CTL(iface, 0);
252 SSYNC();
253 complete(&iface->complete);
254 } 234 }
255 } 235 }
236 complete(&iface->complete);
256} 237}
257 238
258/* Interrupt handler */ 239/* Interrupt handler */
@@ -260,38 +241,26 @@ static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
260{ 241{
261 struct bfin_twi_iface *iface = dev_id; 242 struct bfin_twi_iface *iface = dev_id;
262 unsigned long flags; 243 unsigned long flags;
244 unsigned short twi_int_status;
263 245
264 spin_lock_irqsave(&iface->lock, flags); 246 spin_lock_irqsave(&iface->lock, flags);
265 del_timer(&iface->timeout_timer); 247 while (1) {
266 bfin_twi_handle_interrupt(iface); 248 twi_int_status = read_INT_STAT(iface);
267 spin_unlock_irqrestore(&iface->lock, flags); 249 if (!twi_int_status)
268 return IRQ_HANDLED; 250 break;
269} 251 /* Clear interrupt status */
270 252 write_INT_STAT(iface, twi_int_status);
271static void bfin_twi_timeout(unsigned long data) 253 bfin_twi_handle_interrupt(iface, twi_int_status);
272{ 254 SSYNC();
273 struct bfin_twi_iface *iface = (struct bfin_twi_iface *)data;
274 unsigned long flags;
275
276 spin_lock_irqsave(&iface->lock, flags);
277 bfin_twi_handle_interrupt(iface);
278 if (iface->result == 0) {
279 iface->timeout_count--;
280 if (iface->timeout_count > 0) {
281 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
282 add_timer(&iface->timeout_timer);
283 } else {
284 iface->result = -1;
285 complete(&iface->complete);
286 }
287 } 255 }
288 spin_unlock_irqrestore(&iface->lock, flags); 256 spin_unlock_irqrestore(&iface->lock, flags);
257 return IRQ_HANDLED;
289} 258}
290 259
291/* 260/*
292 * Generic i2c master transfer entrypoint 261 * One i2c master transfer
293 */ 262 */
294static int bfin_twi_master_xfer(struct i2c_adapter *adap, 263static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
295 struct i2c_msg *msgs, int num) 264 struct i2c_msg *msgs, int num)
296{ 265{
297 struct bfin_twi_iface *iface = adap->algo_data; 266 struct bfin_twi_iface *iface = adap->algo_data;
@@ -319,7 +288,6 @@ static int bfin_twi_master_xfer(struct i2c_adapter *adap,
319 iface->transPtr = pmsg->buf; 288 iface->transPtr = pmsg->buf;
320 iface->writeNum = iface->readNum = pmsg->len; 289 iface->writeNum = iface->readNum = pmsg->len;
321 iface->result = 0; 290 iface->result = 0;
322 iface->timeout_count = 10;
323 init_completion(&(iface->complete)); 291 init_completion(&(iface->complete));
324 /* Set Transmit device address */ 292 /* Set Transmit device address */
325 write_MASTER_ADDR(iface, pmsg->addr); 293 write_MASTER_ADDR(iface, pmsg->addr);
@@ -358,30 +326,41 @@ static int bfin_twi_master_xfer(struct i2c_adapter *adap,
358 iface->manual_stop = 1; 326 iface->manual_stop = 1;
359 } 327 }
360 328
361 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
362 add_timer(&iface->timeout_timer);
363
364 /* Master enable */ 329 /* Master enable */
365 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | 330 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
366 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | 331 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
367 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); 332 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
368 SSYNC(); 333 SSYNC();
369 334
370 wait_for_completion(&iface->complete); 335 while (!iface->result) {
371 336 if (!wait_for_completion_timeout(&iface->complete,
372 rc = iface->result; 337 adap->timeout)) {
338 iface->result = -1;
339 dev_err(&adap->dev, "master transfer timeout\n");
340 }
341 }
373 342
374 if (rc == 1) 343 if (iface->result == 1)
375 return num; 344 rc = iface->cur_msg + 1;
376 else 345 else
377 return rc; 346 rc = iface->result;
347
348 return rc;
378} 349}
379 350
380/* 351/*
381 * SMBus type transfer entrypoint 352 * Generic i2c master transfer entrypoint
382 */ 353 */
354static int bfin_twi_master_xfer(struct i2c_adapter *adap,
355 struct i2c_msg *msgs, int num)
356{
357 return bfin_twi_do_master_xfer(adap, msgs, num);
358}
383 359
384int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, 360/*
361 * One I2C SMBus transfer
362 */
363int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
385 unsigned short flags, char read_write, 364 unsigned short flags, char read_write,
386 u8 command, int size, union i2c_smbus_data *data) 365 u8 command, int size, union i2c_smbus_data *data)
387{ 366{
@@ -469,7 +448,6 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
469 iface->manual_stop = 0; 448 iface->manual_stop = 0;
470 iface->read_write = read_write; 449 iface->read_write = read_write;
471 iface->command = command; 450 iface->command = command;
472 iface->timeout_count = 10;
473 init_completion(&(iface->complete)); 451 init_completion(&(iface->complete));
474 452
475 /* FIFO Initiation. Data in FIFO should be discarded before 453 /* FIFO Initiation. Data in FIFO should be discarded before
@@ -486,9 +464,6 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
486 write_MASTER_ADDR(iface, addr); 464 write_MASTER_ADDR(iface, addr);
487 SSYNC(); 465 SSYNC();
488 466
489 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
490 add_timer(&iface->timeout_timer);
491
492 switch (iface->cur_mode) { 467 switch (iface->cur_mode) {
493 case TWI_I2C_MODE_STANDARDSUB: 468 case TWI_I2C_MODE_STANDARDSUB:
494 write_XMT_DATA8(iface, iface->command); 469 write_XMT_DATA8(iface, iface->command);
@@ -550,10 +525,8 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
550 else if (iface->readNum > 255) { 525 else if (iface->readNum > 255) {
551 write_MASTER_CTL(iface, 0xff << 6); 526 write_MASTER_CTL(iface, 0xff << 6);
552 iface->manual_stop = 1; 527 iface->manual_stop = 1;
553 } else { 528 } else
554 del_timer(&iface->timeout_timer);
555 break; 529 break;
556 }
557 } 530 }
558 } 531 }
559 write_INT_MASK(iface, MCOMP | MERR | 532 write_INT_MASK(iface, MCOMP | MERR |
@@ -569,7 +542,13 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
569 } 542 }
570 SSYNC(); 543 SSYNC();
571 544
572 wait_for_completion(&iface->complete); 545 while (!iface->result) {
546 if (!wait_for_completion_timeout(&iface->complete,
547 adap->timeout)) {
548 iface->result = -1;
549 dev_err(&adap->dev, "smbus transfer timeout\n");
550 }
551 }
573 552
574 rc = (iface->result >= 0) ? 0 : -1; 553 rc = (iface->result >= 0) ? 0 : -1;
575 554
@@ -577,6 +556,17 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
577} 556}
578 557
579/* 558/*
559 * Generic I2C SMBus transfer entrypoint
560 */
561int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
562 unsigned short flags, char read_write,
563 u8 command, int size, union i2c_smbus_data *data)
564{
565 return bfin_twi_do_smbus_xfer(adap, addr, flags,
566 read_write, command, size, data);
567}
568
569/*
580 * Return what the adapter supports 570 * Return what the adapter supports
581 */ 571 */
582static u32 bfin_twi_functionality(struct i2c_adapter *adap) 572static u32 bfin_twi_functionality(struct i2c_adapter *adap)
@@ -667,10 +657,6 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
667 goto out_error_no_irq; 657 goto out_error_no_irq;
668 } 658 }
669 659
670 init_timer(&(iface->timeout_timer));
671 iface->timeout_timer.function = bfin_twi_timeout;
672 iface->timeout_timer.data = (unsigned long)iface;
673
674 p_adap = &iface->adap; 660 p_adap = &iface->adap;
675 p_adap->nr = pdev->id; 661 p_adap->nr = pdev->id;
676 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name)); 662 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name));
@@ -678,6 +664,8 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
678 p_adap->algo_data = iface; 664 p_adap->algo_data = iface;
679 p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 665 p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
680 p_adap->dev.parent = &pdev->dev; 666 p_adap->dev.parent = &pdev->dev;
667 p_adap->timeout = 5 * HZ;
668 p_adap->retries = 3;
681 669
682 rc = peripheral_request_list(pin_req[pdev->id], "i2c-bfin-twi"); 670 rc = peripheral_request_list(pin_req[pdev->id], "i2c-bfin-twi");
683 if (rc) { 671 if (rc) {
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index 9c2e10082b79..16948db38973 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -441,7 +441,7 @@ static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm)
441 init_waitqueue_head(&cpm->i2c_wait); 441 init_waitqueue_head(&cpm->i2c_wait);
442 442
443 cpm->irq = of_irq_to_resource(ofdev->node, 0, NULL); 443 cpm->irq = of_irq_to_resource(ofdev->node, 0, NULL);
444 if (cpm->irq == NO_IRQ) 444 if (!cpm->irq)
445 return -EINVAL; 445 return -EINVAL;
446 446
447 /* Install interrupt handler. */ 447 /* Install interrupt handler. */
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 612255614a66..e5b1a3bf5b80 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -37,8 +37,8 @@
37#include <linux/isa.h> 37#include <linux/isa.h>
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/i2c-algo-pcf.h> 39#include <linux/i2c-algo-pcf.h>
40#include <linux/io.h>
40 41
41#include <asm/io.h>
42#include <asm/irq.h> 42#include <asm/irq.h>
43 43
44#include "../algos/i2c-algo-pcf.h" 44#include "../algos/i2c-algo-pcf.h"
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index c21077d248af..d9aa9a649e35 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -211,7 +211,7 @@ static int __init i2c_gpio_init(void)
211 211
212 return ret; 212 return ret;
213} 213}
214module_init(i2c_gpio_init); 214subsys_initcall(i2c_gpio_init);
215 215
216static void __exit i2c_gpio_exit(void) 216static void __exit i2c_gpio_exit(void)
217{ 217{
diff --git a/drivers/i2c/busses/i2c-highlander.c b/drivers/i2c/busses/i2c-highlander.c
index ce87a902c94d..3df1bc80f37a 100644
--- a/drivers/i2c/busses/i2c-highlander.c
+++ b/drivers/i2c/busses/i2c-highlander.c
@@ -282,7 +282,6 @@ static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr,
282 union i2c_smbus_data *data) 282 union i2c_smbus_data *data)
283{ 283{
284 struct highlander_i2c_dev *dev = i2c_get_adapdata(adap); 284 struct highlander_i2c_dev *dev = i2c_get_adapdata(adap);
285 int read = read_write & I2C_SMBUS_READ;
286 u16 tmp; 285 u16 tmp;
287 286
288 init_completion(&dev->cmd_complete); 287 init_completion(&dev->cmd_complete);
@@ -337,11 +336,11 @@ static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr,
337 highlander_i2c_done(dev); 336 highlander_i2c_done(dev);
338 337
339 /* Set slave address */ 338 /* Set slave address */
340 iowrite16((addr << 1) | read, dev->base + SMSMADR); 339 iowrite16((addr << 1) | read_write, dev->base + SMSMADR);
341 340
342 highlander_i2c_command(dev, command, dev->buf_len); 341 highlander_i2c_command(dev, command, dev->buf_len);
343 342
344 if (read) 343 if (read_write == I2C_SMBUS_READ)
345 return highlander_i2c_read(dev); 344 return highlander_i2c_read(dev);
346 else 345 else
347 return highlander_i2c_write(dev); 346 return highlander_i2c_write(dev);
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index c767295ad1fb..9ff1695d8458 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -28,7 +28,7 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-algo-bit.h> 29#include <linux/i2c-algo-bit.h>
30#include <linux/init.h> 30#include <linux/init.h>
31#include <asm/io.h> 31#include <linux/io.h>
32#include <asm/hydra.h> 32#include <asm/hydra.h>
33 33
34 34
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 299b918455a3..f4b21f2bb8ed 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -138,6 +138,17 @@ static struct pci_dev *I801_dev;
138#define FEATURE_I2C_BLOCK_READ (1 << 3) 138#define FEATURE_I2C_BLOCK_READ (1 << 3)
139static unsigned int i801_features; 139static unsigned int i801_features;
140 140
141static const char *i801_feature_names[] = {
142 "SMBus PEC",
143 "Block buffer",
144 "Block process call",
145 "I2C block read",
146};
147
148static unsigned int disable_features;
149module_param(disable_features, uint, S_IRUGO | S_IWUSR);
150MODULE_PARM_DESC(disable_features, "Disable selected driver features");
151
141/* Make sure the SMBus host is ready to start transmitting. 152/* Make sure the SMBus host is ready to start transmitting.
142 Return 0 if it is, -EBUSY if it is not. */ 153 Return 0 if it is, -EBUSY if it is not. */
143static int i801_check_pre(void) 154static int i801_check_pre(void)
@@ -341,9 +352,8 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
341 do { 352 do {
342 msleep(1); 353 msleep(1);
343 status = inb_p(SMBHSTSTS); 354 status = inb_p(SMBHSTSTS);
344 } 355 } while ((!(status & SMBHSTSTS_BYTE_DONE))
345 while ((!(status & SMBHSTSTS_BYTE_DONE)) 356 && (timeout++ < MAX_TIMEOUT));
346 && (timeout++ < MAX_TIMEOUT));
347 357
348 result = i801_check_post(status, timeout > MAX_TIMEOUT); 358 result = i801_check_post(status, timeout > MAX_TIMEOUT);
349 if (result < 0) 359 if (result < 0)
@@ -440,9 +450,9 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
440} 450}
441 451
442/* Return negative errno on error. */ 452/* Return negative errno on error. */
443static s32 i801_access(struct i2c_adapter * adap, u16 addr, 453static s32 i801_access(struct i2c_adapter *adap, u16 addr,
444 unsigned short flags, char read_write, u8 command, 454 unsigned short flags, char read_write, u8 command,
445 int size, union i2c_smbus_data * data) 455 int size, union i2c_smbus_data *data)
446{ 456{
447 int hwpec; 457 int hwpec;
448 int block = 0; 458 int block = 0;
@@ -511,7 +521,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
511 else 521 else
512 outb_p(inb_p(SMBAUXCTL) & (~SMBAUXCTL_CRC), SMBAUXCTL); 522 outb_p(inb_p(SMBAUXCTL) & (~SMBAUXCTL_CRC), SMBAUXCTL);
513 523
514 if(block) 524 if (block)
515 ret = i801_block_transaction(data, read_write, size, hwpec); 525 ret = i801_block_transaction(data, read_write, size, hwpec);
516 else 526 else
517 ret = i801_transaction(xact | ENABLE_INT9); 527 ret = i801_transaction(xact | ENABLE_INT9);
@@ -523,9 +533,9 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
523 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), 533 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B),
524 SMBAUXCTL); 534 SMBAUXCTL);
525 535
526 if(block) 536 if (block)
527 return ret; 537 return ret;
528 if(ret) 538 if (ret)
529 return ret; 539 return ret;
530 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) 540 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
531 return 0; 541 return 0;
@@ -585,7 +595,7 @@ static const struct pci_device_id i801_ids[] = {
585 { 0, } 595 { 0, }
586}; 596};
587 597
588MODULE_DEVICE_TABLE (pci, i801_ids); 598MODULE_DEVICE_TABLE(pci, i801_ids);
589 599
590#if defined CONFIG_INPUT_APANEL || defined CONFIG_INPUT_APANEL_MODULE 600#if defined CONFIG_INPUT_APANEL || defined CONFIG_INPUT_APANEL_MODULE
591static unsigned char apanel_addr; 601static unsigned char apanel_addr;
@@ -689,10 +699,11 @@ static void __devinit dmi_check_onboard_devices(const struct dmi_header *dm,
689} 699}
690#endif 700#endif
691 701
692static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id *id) 702static int __devinit i801_probe(struct pci_dev *dev,
703 const struct pci_device_id *id)
693{ 704{
694 unsigned char temp; 705 unsigned char temp;
695 int err; 706 int err, i;
696#if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE 707#if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE
697 const char *vendor; 708 const char *vendor;
698#endif 709#endif
@@ -700,26 +711,28 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
700 I801_dev = dev; 711 I801_dev = dev;
701 i801_features = 0; 712 i801_features = 0;
702 switch (dev->device) { 713 switch (dev->device) {
703 case PCI_DEVICE_ID_INTEL_82801EB_3: 714 default:
704 case PCI_DEVICE_ID_INTEL_ESB_4:
705 case PCI_DEVICE_ID_INTEL_ICH6_16:
706 case PCI_DEVICE_ID_INTEL_ICH7_17:
707 case PCI_DEVICE_ID_INTEL_ESB2_17:
708 case PCI_DEVICE_ID_INTEL_ICH8_5:
709 case PCI_DEVICE_ID_INTEL_ICH9_6:
710 case PCI_DEVICE_ID_INTEL_TOLAPAI_1:
711 case PCI_DEVICE_ID_INTEL_ICH10_4:
712 case PCI_DEVICE_ID_INTEL_ICH10_5:
713 case PCI_DEVICE_ID_INTEL_PCH_SMBUS:
714 case PCI_DEVICE_ID_INTEL_CPT_SMBUS:
715 i801_features |= FEATURE_I2C_BLOCK_READ; 715 i801_features |= FEATURE_I2C_BLOCK_READ;
716 /* fall through */ 716 /* fall through */
717 case PCI_DEVICE_ID_INTEL_82801DB_3: 717 case PCI_DEVICE_ID_INTEL_82801DB_3:
718 i801_features |= FEATURE_SMBUS_PEC; 718 i801_features |= FEATURE_SMBUS_PEC;
719 i801_features |= FEATURE_BLOCK_BUFFER; 719 i801_features |= FEATURE_BLOCK_BUFFER;
720 /* fall through */
721 case PCI_DEVICE_ID_INTEL_82801CA_3:
722 case PCI_DEVICE_ID_INTEL_82801BA_2:
723 case PCI_DEVICE_ID_INTEL_82801AB_3:
724 case PCI_DEVICE_ID_INTEL_82801AA_3:
720 break; 725 break;
721 } 726 }
722 727
728 /* Disable features on user request */
729 for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
730 if (i801_features & disable_features & (1 << i))
731 dev_notice(&dev->dev, "%s disabled by user\n",
732 i801_feature_names[i]);
733 }
734 i801_features &= ~disable_features;
735
723 err = pci_enable_device(dev); 736 err = pci_enable_device(dev);
724 if (err) { 737 if (err) {
725 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n", 738 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index b1bc6e277d2a..f8ccc0fe95a8 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -39,7 +39,7 @@
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/interrupt.h> 40#include <linux/interrupt.h>
41#include <asm/irq.h> 41#include <asm/irq.h>
42#include <asm/io.h> 42#include <linux/io.h>
43#include <linux/i2c.h> 43#include <linux/i2c.h>
44#include <linux/i2c-id.h> 44#include <linux/i2c-id.h>
45#include <linux/of_platform.h> 45#include <linux/of_platform.h>
@@ -668,12 +668,12 @@ static int __devinit iic_request_irq(struct of_device *ofdev,
668 int irq; 668 int irq;
669 669
670 if (iic_force_poll) 670 if (iic_force_poll)
671 return NO_IRQ; 671 return 0;
672 672
673 irq = irq_of_parse_and_map(np, 0); 673 irq = irq_of_parse_and_map(np, 0);
674 if (irq == NO_IRQ) { 674 if (!irq) {
675 dev_err(&ofdev->dev, "irq_of_parse_and_map failed\n"); 675 dev_err(&ofdev->dev, "irq_of_parse_and_map failed\n");
676 return NO_IRQ; 676 return 0;
677 } 677 }
678 678
679 /* Disable interrupts until we finish initialization, assumes 679 /* Disable interrupts until we finish initialization, assumes
@@ -683,7 +683,7 @@ static int __devinit iic_request_irq(struct of_device *ofdev,
683 if (request_irq(irq, iic_handler, 0, "IBM IIC", dev)) { 683 if (request_irq(irq, iic_handler, 0, "IBM IIC", dev)) {
684 dev_err(&ofdev->dev, "request_irq %d failed\n", irq); 684 dev_err(&ofdev->dev, "request_irq %d failed\n", irq);
685 /* Fallback to the polling mode */ 685 /* Fallback to the polling mode */
686 return NO_IRQ; 686 return 0;
687 } 687 }
688 688
689 return irq; 689 return irq;
@@ -719,7 +719,7 @@ static int __devinit iic_probe(struct of_device *ofdev,
719 init_waitqueue_head(&dev->wq); 719 init_waitqueue_head(&dev->wq);
720 720
721 dev->irq = iic_request_irq(ofdev, dev); 721 dev->irq = iic_request_irq(ofdev, dev);
722 if (dev->irq == NO_IRQ) 722 if (!dev->irq)
723 dev_warn(&ofdev->dev, "using polling mode\n"); 723 dev_warn(&ofdev->dev, "using polling mode\n");
724 724
725 /* Board specific settings */ 725 /* Board specific settings */
@@ -766,7 +766,7 @@ static int __devinit iic_probe(struct of_device *ofdev,
766 return 0; 766 return 0;
767 767
768error_cleanup: 768error_cleanup:
769 if (dev->irq != NO_IRQ) { 769 if (dev->irq) {
770 iic_interrupt_mode(dev, 0); 770 iic_interrupt_mode(dev, 0);
771 free_irq(dev->irq, dev); 771 free_irq(dev->irq, dev);
772 } 772 }
@@ -790,7 +790,7 @@ static int __devexit iic_remove(struct of_device *ofdev)
790 790
791 i2c_del_adapter(&dev->adap); 791 i2c_del_adapter(&dev->adap);
792 792
793 if (dev->irq != NO_IRQ) { 793 if (dev->irq) {
794 iic_interrupt_mode(dev, 0); 794 iic_interrupt_mode(dev, 0);
795 free_irq(dev->irq, dev); 795 free_irq(dev->irq, dev);
796 } 796 }
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 5901707fc66a..112c61f7b8cd 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -38,8 +38,7 @@
38#include <linux/errno.h> 38#include <linux/errno.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41 41#include <linux/io.h>
42#include <asm/io.h>
43 42
44#include "i2c-iop3xx.h" 43#include "i2c-iop3xx.h"
45 44
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index f1321f763789..e86cef300c7d 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -118,7 +118,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
118 u32 x; 118 u32 x;
119 int result = 0; 119 int result = 0;
120 120
121 if (i2c->irq == NO_IRQ) { 121 if (!i2c->irq) {
122 while (!(readb(i2c->base + MPC_I2C_SR) & CSR_MIF)) { 122 while (!(readb(i2c->base + MPC_I2C_SR) & CSR_MIF)) {
123 schedule(); 123 schedule();
124 if (time_after(jiffies, orig_jiffies + timeout)) { 124 if (time_after(jiffies, orig_jiffies + timeout)) {
@@ -568,7 +568,7 @@ static int __devinit fsl_i2c_probe(struct of_device *op,
568 } 568 }
569 569
570 i2c->irq = irq_of_parse_and_map(op->node, 0); 570 i2c->irq = irq_of_parse_and_map(op->node, 0);
571 if (i2c->irq != NO_IRQ) { /* i2c->irq = NO_IRQ implies polling */ 571 if (i2c->irq) { /* no i2c->irq implies polling */
572 result = request_irq(i2c->irq, mpc_i2c_isr, 572 result = request_irq(i2c->irq, mpc_i2c_isr,
573 IRQF_SHARED, "i2c-mpc", i2c); 573 IRQF_SHARED, "i2c-mpc", i2c);
574 if (result < 0) { 574 if (result < 0) {
@@ -627,7 +627,7 @@ static int __devexit fsl_i2c_remove(struct of_device *op)
627 i2c_del_adapter(&i2c->adap); 627 i2c_del_adapter(&i2c->adap);
628 dev_set_drvdata(&op->dev, NULL); 628 dev_set_drvdata(&op->dev, NULL);
629 629
630 if (i2c->irq != NO_IRQ) 630 if (i2c->irq)
631 free_irq(i2c->irq, i2c); 631 free_irq(i2c->irq, i2c);
632 632
633 irq_dispose_mapping(i2c->irq); 633 irq_dispose_mapping(i2c->irq);
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 3623a4499084..16242063144f 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -17,8 +17,7 @@
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/mv643xx_i2c.h> 18#include <linux/mv643xx_i2c.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20 20#include <linux/io.h>
21#include <asm/io.h>
22 21
23/* Register defines */ 22/* Register defines */
24#define MV64XXX_I2C_REG_SLAVE_ADDR 0x00 23#define MV64XXX_I2C_REG_SLAVE_ADDR 0x00
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 4a48dd4ef787..a605a5029cfe 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -57,7 +57,7 @@
57#include <linux/dmi.h> 57#include <linux/dmi.h>
58#include <linux/acpi.h> 58#include <linux/acpi.h>
59#include <linux/slab.h> 59#include <linux/slab.h>
60#include <asm/io.h> 60#include <linux/io.h>
61 61
62MODULE_LICENSE("GPL"); 62MODULE_LICENSE("GPL");
63MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@gmx.net>"); 63MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@gmx.net>");
@@ -404,10 +404,9 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
404 404
405 /* SMBus adapter 1 */ 405 /* SMBus adapter 1 */
406 res1 = nforce2_probe_smb(dev, 4, NFORCE_PCI_SMB1, &smbuses[0], "SMB1"); 406 res1 = nforce2_probe_smb(dev, 4, NFORCE_PCI_SMB1, &smbuses[0], "SMB1");
407 if (res1 < 0) { 407 if (res1 < 0)
408 dev_err(&dev->dev, "Error probing SMB1.\n");
409 smbuses[0].base = 0; /* to have a check value */ 408 smbuses[0].base = 0; /* to have a check value */
410 } 409
411 /* SMBus adapter 2 */ 410 /* SMBus adapter 2 */
412 if (dmi_check_system(nforce2_dmi_blacklist2)) { 411 if (dmi_check_system(nforce2_dmi_blacklist2)) {
413 dev_err(&dev->dev, "Disabling SMB2 for safety reasons.\n"); 412 dev_err(&dev->dev, "Disabling SMB2 for safety reasons.\n");
@@ -416,11 +415,10 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
416 } else { 415 } else {
417 res2 = nforce2_probe_smb(dev, 5, NFORCE_PCI_SMB2, &smbuses[1], 416 res2 = nforce2_probe_smb(dev, 5, NFORCE_PCI_SMB2, &smbuses[1],
418 "SMB2"); 417 "SMB2");
419 if (res2 < 0) { 418 if (res2 < 0)
420 dev_err(&dev->dev, "Error probing SMB2.\n");
421 smbuses[1].base = 0; /* to have a check value */ 419 smbuses[1].base = 0; /* to have a check value */
422 }
423 } 420 }
421
424 if ((res1 < 0) && (res2 < 0)) { 422 if ((res1 < 0) && (res2 < 0)) {
425 /* we did not find even one of the SMBuses, so we give up */ 423 /* we did not find even one of the SMBuses, so we give up */
426 kfree(smbuses); 424 kfree(smbuses);
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index a4f8d33fa389..73de8ade10b1 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -704,7 +704,8 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
704 case I2C_IT_MTD: 704 case I2C_IT_MTD:
705 case I2C_IT_MTDWS: 705 case I2C_IT_MTDWS:
706 if (dev->cli.operation == I2C_READ) { 706 if (dev->cli.operation == I2C_READ) {
707 while (!readl(dev->virtbase + I2C_RISR) & I2C_IT_RXFE) { 707 while (!(readl(dev->virtbase + I2C_RISR)
708 & I2C_IT_RXFE)) {
708 if (dev->cli.count == 0) 709 if (dev->cli.count == 0)
709 break; 710 break;
710 *dev->cli.buffer = 711 *dev->cli.buffer =
@@ -914,6 +915,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
914 915
915static int __devexit nmk_i2c_remove(struct platform_device *pdev) 916static int __devexit nmk_i2c_remove(struct platform_device *pdev)
916{ 917{
918 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
917 struct nmk_i2c_dev *dev = platform_get_drvdata(pdev); 919 struct nmk_i2c_dev *dev = platform_get_drvdata(pdev);
918 920
919 i2c_del_adapter(&dev->adap); 921 i2c_del_adapter(&dev->adap);
@@ -924,6 +926,8 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev)
924 i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE); 926 i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE);
925 free_irq(dev->irq, dev); 927 free_irq(dev->irq, dev);
926 iounmap(dev->virtbase); 928 iounmap(dev->virtbase);
929 if (res)
930 release_mem_region(res->start, resource_size(res));
927 clk_disable(dev->clk); 931 clk_disable(dev->clk);
928 clk_put(dev->clk); 932 clk_put(dev->clk);
929 platform_set_drvdata(pdev, NULL); 933 platform_set_drvdata(pdev, NULL);
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index b4ed4ca802ed..0070371b29f3 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -19,7 +19,7 @@
19#include <linux/wait.h> 19#include <linux/wait.h>
20#include <linux/i2c-ocores.h> 20#include <linux/i2c-ocores.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <asm/io.h> 22#include <linux/io.h>
23 23
24struct ocores_i2c { 24struct ocores_i2c {
25 void __iomem *base; 25 void __iomem *base;
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 389ac6032a7b..7674efb55378 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -38,6 +38,7 @@
38#include <linux/clk.h> 38#include <linux/clk.h>
39#include <linux/io.h> 39#include <linux/io.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/i2c-omap.h>
41 42
42/* I2C controller revisions */ 43/* I2C controller revisions */
43#define OMAP_I2C_REV_2 0x20 44#define OMAP_I2C_REV_2 0x20
@@ -45,29 +46,37 @@
45/* I2C controller revisions present on specific hardware */ 46/* I2C controller revisions present on specific hardware */
46#define OMAP_I2C_REV_ON_2430 0x36 47#define OMAP_I2C_REV_ON_2430 0x36
47#define OMAP_I2C_REV_ON_3430 0x3C 48#define OMAP_I2C_REV_ON_3430 0x3C
49#define OMAP_I2C_REV_ON_4430 0x40
48 50
49/* timeout waiting for the controller to respond */ 51/* timeout waiting for the controller to respond */
50#define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) 52#define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
51 53
52#define OMAP_I2C_REV_REG 0x00
53#define OMAP_I2C_IE_REG 0x01
54#define OMAP_I2C_STAT_REG 0x02
55#define OMAP_I2C_IV_REG 0x03
56/* For OMAP3 I2C_IV has changed to I2C_WE (wakeup enable) */ 54/* For OMAP3 I2C_IV has changed to I2C_WE (wakeup enable) */
57#define OMAP_I2C_WE_REG 0x03 55enum {
58#define OMAP_I2C_SYSS_REG 0x04 56 OMAP_I2C_REV_REG = 0,
59#define OMAP_I2C_BUF_REG 0x05 57 OMAP_I2C_IE_REG,
60#define OMAP_I2C_CNT_REG 0x06 58 OMAP_I2C_STAT_REG,
61#define OMAP_I2C_DATA_REG 0x07 59 OMAP_I2C_IV_REG,
62#define OMAP_I2C_SYSC_REG 0x08 60 OMAP_I2C_WE_REG,
63#define OMAP_I2C_CON_REG 0x09 61 OMAP_I2C_SYSS_REG,
64#define OMAP_I2C_OA_REG 0x0a 62 OMAP_I2C_BUF_REG,
65#define OMAP_I2C_SA_REG 0x0b 63 OMAP_I2C_CNT_REG,
66#define OMAP_I2C_PSC_REG 0x0c 64 OMAP_I2C_DATA_REG,
67#define OMAP_I2C_SCLL_REG 0x0d 65 OMAP_I2C_SYSC_REG,
68#define OMAP_I2C_SCLH_REG 0x0e 66 OMAP_I2C_CON_REG,
69#define OMAP_I2C_SYSTEST_REG 0x0f 67 OMAP_I2C_OA_REG,
70#define OMAP_I2C_BUFSTAT_REG 0x10 68 OMAP_I2C_SA_REG,
69 OMAP_I2C_PSC_REG,
70 OMAP_I2C_SCLL_REG,
71 OMAP_I2C_SCLH_REG,
72 OMAP_I2C_SYSTEST_REG,
73 OMAP_I2C_BUFSTAT_REG,
74 OMAP_I2C_REVNB_LO,
75 OMAP_I2C_REVNB_HI,
76 OMAP_I2C_IRQSTATUS_RAW,
77 OMAP_I2C_IRQENABLE_SET,
78 OMAP_I2C_IRQENABLE_CLR,
79};
71 80
72/* I2C Interrupt Enable Register (OMAP_I2C_IE): */ 81/* I2C Interrupt Enable Register (OMAP_I2C_IE): */
73#define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer drain int enable */ 82#define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer drain int enable */
@@ -157,6 +166,9 @@
157#define SYSC_IDLEMODE_SMART 0x2 166#define SYSC_IDLEMODE_SMART 0x2
158#define SYSC_CLOCKACTIVITY_FCLK 0x2 167#define SYSC_CLOCKACTIVITY_FCLK 0x2
159 168
169/* Errata definitions */
170#define I2C_OMAP_ERRATA_I207 (1 << 0)
171#define I2C_OMAP3_1P153 (1 << 1)
160 172
161struct omap_i2c_dev { 173struct omap_i2c_dev {
162 struct device *dev; 174 struct device *dev;
@@ -167,9 +179,13 @@ struct omap_i2c_dev {
167 struct clk *fclk; /* Functional clock */ 179 struct clk *fclk; /* Functional clock */
168 struct completion cmd_complete; 180 struct completion cmd_complete;
169 struct resource *ioarea; 181 struct resource *ioarea;
182 u32 latency; /* maximum mpu wkup latency */
183 void (*set_mpu_wkup_lat)(struct device *dev,
184 long latency);
170 u32 speed; /* Speed of bus in Khz */ 185 u32 speed; /* Speed of bus in Khz */
171 u16 cmd_err; 186 u16 cmd_err;
172 u8 *buf; 187 u8 *buf;
188 u8 *regs;
173 size_t buf_len; 189 size_t buf_len;
174 struct i2c_adapter adapter; 190 struct i2c_adapter adapter;
175 u8 fifo_size; /* use as flag and value 191 u8 fifo_size; /* use as flag and value
@@ -186,17 +202,67 @@ struct omap_i2c_dev {
186 u16 bufstate; 202 u16 bufstate;
187 u16 syscstate; 203 u16 syscstate;
188 u16 westate; 204 u16 westate;
205 u16 errata;
206};
207
208const static u8 reg_map[] = {
209 [OMAP_I2C_REV_REG] = 0x00,
210 [OMAP_I2C_IE_REG] = 0x01,
211 [OMAP_I2C_STAT_REG] = 0x02,
212 [OMAP_I2C_IV_REG] = 0x03,
213 [OMAP_I2C_WE_REG] = 0x03,
214 [OMAP_I2C_SYSS_REG] = 0x04,
215 [OMAP_I2C_BUF_REG] = 0x05,
216 [OMAP_I2C_CNT_REG] = 0x06,
217 [OMAP_I2C_DATA_REG] = 0x07,
218 [OMAP_I2C_SYSC_REG] = 0x08,
219 [OMAP_I2C_CON_REG] = 0x09,
220 [OMAP_I2C_OA_REG] = 0x0a,
221 [OMAP_I2C_SA_REG] = 0x0b,
222 [OMAP_I2C_PSC_REG] = 0x0c,
223 [OMAP_I2C_SCLL_REG] = 0x0d,
224 [OMAP_I2C_SCLH_REG] = 0x0e,
225 [OMAP_I2C_SYSTEST_REG] = 0x0f,
226 [OMAP_I2C_BUFSTAT_REG] = 0x10,
227};
228
229const static u8 omap4_reg_map[] = {
230 [OMAP_I2C_REV_REG] = 0x04,
231 [OMAP_I2C_IE_REG] = 0x2c,
232 [OMAP_I2C_STAT_REG] = 0x28,
233 [OMAP_I2C_IV_REG] = 0x34,
234 [OMAP_I2C_WE_REG] = 0x34,
235 [OMAP_I2C_SYSS_REG] = 0x90,
236 [OMAP_I2C_BUF_REG] = 0x94,
237 [OMAP_I2C_CNT_REG] = 0x98,
238 [OMAP_I2C_DATA_REG] = 0x9c,
239 [OMAP_I2C_SYSC_REG] = 0x20,
240 [OMAP_I2C_CON_REG] = 0xa4,
241 [OMAP_I2C_OA_REG] = 0xa8,
242 [OMAP_I2C_SA_REG] = 0xac,
243 [OMAP_I2C_PSC_REG] = 0xb0,
244 [OMAP_I2C_SCLL_REG] = 0xb4,
245 [OMAP_I2C_SCLH_REG] = 0xb8,
246 [OMAP_I2C_SYSTEST_REG] = 0xbC,
247 [OMAP_I2C_BUFSTAT_REG] = 0xc0,
248 [OMAP_I2C_REVNB_LO] = 0x00,
249 [OMAP_I2C_REVNB_HI] = 0x04,
250 [OMAP_I2C_IRQSTATUS_RAW] = 0x24,
251 [OMAP_I2C_IRQENABLE_SET] = 0x2c,
252 [OMAP_I2C_IRQENABLE_CLR] = 0x30,
189}; 253};
190 254
191static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, 255static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev,
192 int reg, u16 val) 256 int reg, u16 val)
193{ 257{
194 __raw_writew(val, i2c_dev->base + (reg << i2c_dev->reg_shift)); 258 __raw_writew(val, i2c_dev->base +
259 (i2c_dev->regs[reg] << i2c_dev->reg_shift));
195} 260}
196 261
197static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) 262static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg)
198{ 263{
199 return __raw_readw(i2c_dev->base + (reg << i2c_dev->reg_shift)); 264 return __raw_readw(i2c_dev->base +
265 (i2c_dev->regs[reg] << i2c_dev->reg_shift));
200} 266}
201 267
202static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev) 268static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev)
@@ -265,7 +331,11 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev)
265 WARN_ON(dev->idle); 331 WARN_ON(dev->idle);
266 332
267 dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); 333 dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
268 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); 334 if (dev->rev >= OMAP_I2C_REV_ON_4430)
335 omap_i2c_write_reg(dev, OMAP_I2C_IRQENABLE_CLR, 1);
336 else
337 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0);
338
269 if (dev->rev < OMAP_I2C_REV_2) { 339 if (dev->rev < OMAP_I2C_REV_2) {
270 iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ 340 iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */
271 } else { 341 } else {
@@ -330,7 +400,9 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
330 * REVISIT: Some wkup sources might not be needed. 400 * REVISIT: Some wkup sources might not be needed.
331 */ 401 */
332 dev->westate = OMAP_I2C_WE_ALL; 402 dev->westate = OMAP_I2C_WE_ALL;
333 omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); 403 if (dev->rev < OMAP_I2C_REV_ON_4430)
404 omap_i2c_write_reg(dev, OMAP_I2C_WE_REG,
405 dev->westate);
334 } 406 }
335 } 407 }
336 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 408 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
@@ -357,7 +429,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
357 psc = fclk_rate / 12000000; 429 psc = fclk_rate / 12000000;
358 } 430 }
359 431
360 if (cpu_is_omap2430() || cpu_is_omap34xx()) { 432 if (!(cpu_class_is_omap1() || cpu_is_omap2420())) {
361 433
362 /* 434 /*
363 * HSI2C controller internal clk rate should be 19.2 Mhz for 435 * HSI2C controller internal clk rate should be 19.2 Mhz for
@@ -430,6 +502,11 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
430 /* Take the I2C module out of reset: */ 502 /* Take the I2C module out of reset: */
431 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 503 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
432 504
505 dev->errata = 0;
506
507 if (cpu_is_omap2430() || cpu_is_omap34xx())
508 dev->errata |= I2C_OMAP_ERRATA_I207;
509
433 /* Enable interrupts */ 510 /* Enable interrupts */
434 dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | 511 dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
435 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | 512 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
@@ -539,8 +616,12 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
539 * REVISIT: We should abort the transfer on signals, but the bus goes 616 * REVISIT: We should abort the transfer on signals, but the bus goes
540 * into arbitration and we're currently unable to recover from it. 617 * into arbitration and we're currently unable to recover from it.
541 */ 618 */
619 if (dev->set_mpu_wkup_lat != NULL)
620 dev->set_mpu_wkup_lat(dev->dev, dev->latency);
542 r = wait_for_completion_timeout(&dev->cmd_complete, 621 r = wait_for_completion_timeout(&dev->cmd_complete,
543 OMAP_I2C_TIMEOUT); 622 OMAP_I2C_TIMEOUT);
623 if (dev->set_mpu_wkup_lat != NULL)
624 dev->set_mpu_wkup_lat(dev->dev, -1);
544 dev->buf_len = 0; 625 dev->buf_len = 0;
545 if (r < 0) 626 if (r < 0)
546 return r; 627 return r;
@@ -623,6 +704,34 @@ omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat)
623 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 704 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
624} 705}
625 706
707static inline void i2c_omap_errata_i207(struct omap_i2c_dev *dev, u16 stat)
708{
709 /*
710 * I2C Errata(Errata Nos. OMAP2: 1.67, OMAP3: 1.8)
711 * Not applicable for OMAP4.
712 * Under certain rare conditions, RDR could be set again
713 * when the bus is busy, then ignore the interrupt and
714 * clear the interrupt.
715 */
716 if (stat & OMAP_I2C_STAT_RDR) {
717 /* Step 1: If RDR is set, clear it */
718 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR);
719
720 /* Step 2: */
721 if (!(omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG)
722 & OMAP_I2C_STAT_BB)) {
723
724 /* Step 3: */
725 if (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG)
726 & OMAP_I2C_STAT_RDR) {
727 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR);
728 dev_dbg(dev->dev, "RDR when bus is busy.\n");
729 }
730
731 }
732 }
733}
734
626/* rev1 devices are apparently only on some 15xx */ 735/* rev1 devices are apparently only on some 15xx */
627#ifdef CONFIG_ARCH_OMAP15XX 736#ifdef CONFIG_ARCH_OMAP15XX
628 737
@@ -684,6 +793,35 @@ omap_i2c_rev1_isr(int this_irq, void *dev_id)
684#define omap_i2c_rev1_isr NULL 793#define omap_i2c_rev1_isr NULL
685#endif 794#endif
686 795
796/*
797 * OMAP3430 Errata 1.153: When an XRDY/XDR is hit, wait for XUDF before writing
798 * data to DATA_REG. Otherwise some data bytes can be lost while transferring
799 * them from the memory to the I2C interface.
800 */
801static int errata_omap3_1p153(struct omap_i2c_dev *dev, u16 *stat, int *err)
802{
803 unsigned long timeout = 10000;
804
805 while (--timeout && !(*stat & OMAP_I2C_STAT_XUDF)) {
806 if (*stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
807 omap_i2c_ack_stat(dev, *stat & (OMAP_I2C_STAT_XRDY |
808 OMAP_I2C_STAT_XDR));
809 *err |= OMAP_I2C_STAT_XUDF;
810 return -ETIMEDOUT;
811 }
812
813 cpu_relax();
814 *stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
815 }
816
817 if (!timeout) {
818 dev_err(dev->dev, "timeout waiting on XUDF bit\n");
819 return 0;
820 }
821
822 return 0;
823}
824
687static irqreturn_t 825static irqreturn_t
688omap_i2c_isr(int this_irq, void *dev_id) 826omap_i2c_isr(int this_irq, void *dev_id)
689{ 827{
@@ -733,6 +871,10 @@ complete:
733 } 871 }
734 if (stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)) { 872 if (stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)) {
735 u8 num_bytes = 1; 873 u8 num_bytes = 1;
874
875 if (dev->errata & I2C_OMAP_ERRATA_I207)
876 i2c_omap_errata_i207(dev, stat);
877
736 if (dev->fifo_size) { 878 if (dev->fifo_size) {
737 if (stat & OMAP_I2C_STAT_RRDY) 879 if (stat & OMAP_I2C_STAT_RRDY)
738 num_bytes = dev->fifo_size; 880 num_bytes = dev->fifo_size;
@@ -747,9 +889,12 @@ complete:
747 if (dev->buf_len) { 889 if (dev->buf_len) {
748 *dev->buf++ = w; 890 *dev->buf++ = w;
749 dev->buf_len--; 891 dev->buf_len--;
750 /* Data reg from 2430 is 8 bit wide */ 892 /*
751 if (!cpu_is_omap2430() && 893 * Data reg in 2430, omap3 and
752 !cpu_is_omap34xx()) { 894 * omap4 is 8 bit wide
895 */
896 if (cpu_class_is_omap1() ||
897 cpu_is_omap2420()) {
753 if (dev->buf_len) { 898 if (dev->buf_len) {
754 *dev->buf++ = w >> 8; 899 *dev->buf++ = w >> 8;
755 dev->buf_len--; 900 dev->buf_len--;
@@ -787,9 +932,12 @@ complete:
787 if (dev->buf_len) { 932 if (dev->buf_len) {
788 w = *dev->buf++; 933 w = *dev->buf++;
789 dev->buf_len--; 934 dev->buf_len--;
790 /* Data reg from 2430 is 8 bit wide */ 935 /*
791 if (!cpu_is_omap2430() && 936 * Data reg in 2430, omap3 and
792 !cpu_is_omap34xx()) { 937 * omap4 is 8 bit wide
938 */
939 if (cpu_class_is_omap1() ||
940 cpu_is_omap2420()) {
793 if (dev->buf_len) { 941 if (dev->buf_len) {
794 w |= *dev->buf++ << 8; 942 w |= *dev->buf++ << 8;
795 dev->buf_len--; 943 dev->buf_len--;
@@ -807,25 +955,9 @@ complete:
807 break; 955 break;
808 } 956 }
809 957
810 /* 958 if ((dev->errata & I2C_OMAP3_1P153) &&
811 * OMAP3430 Errata 1.153: When an XRDY/XDR 959 errata_omap3_1p153(dev, &stat, &err))
812 * is hit, wait for XUDF before writing data 960 goto complete;
813 * to DATA_REG. Otherwise some data bytes can
814 * be lost while transferring them from the
815 * memory to the I2C interface.
816 */
817
818 if (dev->rev <= OMAP_I2C_REV_ON_3430) {
819 while (!(stat & OMAP_I2C_STAT_XUDF)) {
820 if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
821 omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
822 err |= OMAP_I2C_STAT_XUDF;
823 goto complete;
824 }
825 cpu_relax();
826 stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
827 }
828 }
829 961
830 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 962 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
831 } 963 }
@@ -857,6 +989,7 @@ omap_i2c_probe(struct platform_device *pdev)
857 struct omap_i2c_dev *dev; 989 struct omap_i2c_dev *dev;
858 struct i2c_adapter *adap; 990 struct i2c_adapter *adap;
859 struct resource *mem, *irq, *ioarea; 991 struct resource *mem, *irq, *ioarea;
992 struct omap_i2c_bus_platform_data *pdata = pdev->dev.platform_data;
860 irq_handler_t isr; 993 irq_handler_t isr;
861 int r; 994 int r;
862 u32 speed = 0; 995 u32 speed = 0;
@@ -886,10 +1019,13 @@ omap_i2c_probe(struct platform_device *pdev)
886 goto err_release_region; 1019 goto err_release_region;
887 } 1020 }
888 1021
889 if (pdev->dev.platform_data != NULL) 1022 if (pdata != NULL) {
890 speed = *(u32 *)pdev->dev.platform_data; 1023 speed = pdata->clkrate;
891 else 1024 dev->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat;
892 speed = 100; /* Defualt speed */ 1025 } else {
1026 speed = 100; /* Default speed */
1027 dev->set_mpu_wkup_lat = NULL;
1028 }
893 1029
894 dev->speed = speed; 1030 dev->speed = speed;
895 dev->idle = 1; 1031 dev->idle = 1;
@@ -905,17 +1041,27 @@ omap_i2c_probe(struct platform_device *pdev)
905 1041
906 if (cpu_is_omap7xx()) 1042 if (cpu_is_omap7xx())
907 dev->reg_shift = 1; 1043 dev->reg_shift = 1;
1044 else if (cpu_is_omap44xx())
1045 dev->reg_shift = 0;
908 else 1046 else
909 dev->reg_shift = 2; 1047 dev->reg_shift = 2;
910 1048
911 if ((r = omap_i2c_get_clocks(dev)) != 0) 1049 if ((r = omap_i2c_get_clocks(dev)) != 0)
912 goto err_iounmap; 1050 goto err_iounmap;
913 1051
1052 if (cpu_is_omap44xx())
1053 dev->regs = (u8 *) omap4_reg_map;
1054 else
1055 dev->regs = (u8 *) reg_map;
1056
914 omap_i2c_unidle(dev); 1057 omap_i2c_unidle(dev);
915 1058
916 dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; 1059 dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
917 1060
918 if (cpu_is_omap2430() || cpu_is_omap34xx()) { 1061 if (dev->rev <= OMAP_I2C_REV_ON_3430)
1062 dev->errata |= I2C_OMAP3_1P153;
1063
1064 if (!(cpu_class_is_omap1() || cpu_is_omap2420())) {
919 u16 s; 1065 u16 s;
920 1066
921 /* Set up the fifo size - Get total size */ 1067 /* Set up the fifo size - Get total size */
@@ -927,8 +1073,17 @@ omap_i2c_probe(struct platform_device *pdev)
927 * size. This is to ensure that we can handle the status on int 1073 * size. This is to ensure that we can handle the status on int
928 * call back latencies. 1074 * call back latencies.
929 */ 1075 */
930 dev->fifo_size = (dev->fifo_size / 2); 1076 if (dev->rev >= OMAP_I2C_REV_ON_4430) {
931 dev->b_hw = 1; /* Enable hardware fixes */ 1077 dev->fifo_size = 0;
1078 dev->b_hw = 0; /* Disable hardware fixes */
1079 } else {
1080 dev->fifo_size = (dev->fifo_size / 2);
1081 dev->b_hw = 1; /* Enable hardware fixes */
1082 }
1083 /* calculate wakeup latency constraint for MPU */
1084 if (dev->set_mpu_wkup_lat != NULL)
1085 dev->latency = (1000000 * dev->fifo_size) /
1086 (1000 * speed / 8);
932 } 1087 }
933 1088
934 /* reset ASAP, clearing any IRQs */ 1089 /* reset ASAP, clearing any IRQs */
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index 5f41ec0f72d2..fc5fbd1012c9 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -33,7 +33,7 @@
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-algo-bit.h> 34#include <linux/i2c-algo-bit.h>
35#include <linux/i2c-smbus.h> 35#include <linux/i2c-smbus.h>
36#include <asm/io.h> 36#include <linux/io.h>
37#include "i2c-parport.h" 37#include "i2c-parport.h"
38 38
39#define DEFAULT_BASE 0x378 39#define DEFAULT_BASE 0x378
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 846583ed4763..0eb1515541e7 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -137,7 +137,7 @@ static int parport_getsda(void *data)
137 copied. The attaching code will set getscl to NULL for adapters that 137 copied. The attaching code will set getscl to NULL for adapters that
138 cannot read SCL back, and will also make the data field point to 138 cannot read SCL back, and will also make the data field point to
139 the parallel port structure. */ 139 the parallel port structure. */
140static struct i2c_algo_bit_data parport_algo_data = { 140static const struct i2c_algo_bit_data parport_algo_data = {
141 .setsda = parport_setsda, 141 .setsda = parport_setsda,
142 .setscl = parport_setscl, 142 .setscl = parport_setscl,
143 .getsda = parport_getsda, 143 .getsda = parport_getsda,
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index d3d4a4b43a1d..4174101660c9 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -25,7 +25,7 @@
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <asm/io.h> 28#include <linux/io.h>
29 29
30static struct pci_driver pasemi_smb_driver; 30static struct pci_driver pasemi_smb_driver;
31 31
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index f7346a9bd95f..bbd77603a417 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -30,8 +30,8 @@
30#include <linux/isa.h> 30#include <linux/isa.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c-algo-pca.h> 32#include <linux/i2c-algo-pca.h>
33#include <linux/io.h>
33 34
34#include <asm/io.h>
35#include <asm/irq.h> 35#include <asm/irq.h>
36 36
37#define DRIVER "i2c-pca-isa" 37#define DRIVER "i2c-pca-isa"
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 5b2213df5ed0..ef5c78487eb7 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -23,9 +23,9 @@
23#include <linux/i2c-algo-pca.h> 23#include <linux/i2c-algo-pca.h>
24#include <linux/i2c-pca-platform.h> 24#include <linux/i2c-pca-platform.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/io.h>
26 27
27#include <asm/irq.h> 28#include <asm/irq.h>
28#include <asm/io.h>
29 29
30struct i2c_pca_pf_data { 30struct i2c_pca_pf_data {
31 void __iomem *reg_base; 31 void __iomem *reg_base;
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index ee9da6fcf69a..6d14ac2e3c41 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -39,7 +39,7 @@
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/dmi.h> 40#include <linux/dmi.h>
41#include <linux/acpi.h> 41#include <linux/acpi.h>
42#include <asm/io.h> 42#include <linux/io.h>
43 43
44 44
45/* PIIX4 SMBus address offsets */ 45/* PIIX4 SMBus address offsets */
diff --git a/drivers/i2c/busses/i2c-pmcmsp.c b/drivers/i2c/busses/i2c-pmcmsp.c
index 7b57d5f267e1..dfa7ae9c1b8e 100644
--- a/drivers/i2c/busses/i2c-pmcmsp.c
+++ b/drivers/i2c/busses/i2c-pmcmsp.c
@@ -33,7 +33,7 @@
33#include <linux/completion.h> 33#include <linux/completion.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <asm/io.h> 36#include <linux/io.h>
37 37
38#define DRV_NAME "pmcmsptwi" 38#define DRV_NAME "pmcmsptwi"
39 39
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 14d249f5ed3f..020ff23d762f 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -34,9 +34,9 @@
34#include <linux/err.h> 34#include <linux/err.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/io.h>
37 38
38#include <asm/irq.h> 39#include <asm/irq.h>
39#include <asm/io.h>
40#include <plat/i2c.h> 40#include <plat/i2c.h>
41 41
42/* 42/*
@@ -209,18 +209,6 @@ static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
209} 209}
210 210
211#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__) 211#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__)
212#else
213#define i2c_debug 0
214
215#define show_state(i2c) do { } while (0)
216#define decode_ISR(val) do { } while (0)
217#define decode_ICR(val) do { } while (0)
218#endif
219
220#define eedbg(lvl, x...) do { if ((lvl) < 1) { printk(KERN_DEBUG "" x); } } while(0)
221
222static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
223static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
224 212
225static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) 213static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
226{ 214{
@@ -236,6 +224,20 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
236 printk("\n"); 224 printk("\n");
237} 225}
238 226
227#else /* ifdef DEBUG */
228
229#define i2c_debug 0
230
231#define show_state(i2c) do { } while (0)
232#define decode_ISR(val) do { } while (0)
233#define decode_ICR(val) do { } while (0)
234#define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0)
235
236#endif /* ifdef DEBUG / else */
237
238static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
239static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
240
239static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) 241static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
240{ 242{
241 return !(readl(_ICR(i2c)) & ICR_SCLE); 243 return !(readl(_ICR(i2c)) & ICR_SCLE);
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index d27072b2249f..72902e0bbfa7 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -35,9 +35,9 @@
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/cpufreq.h> 36#include <linux/cpufreq.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/io.h>
38 39
39#include <asm/irq.h> 40#include <asm/irq.h>
40#include <asm/io.h>
41 41
42#include <plat/regs-iic.h> 42#include <plat/regs-iic.h>
43#include <plat/iic.h> 43#include <plat/iic.h>
@@ -482,7 +482,8 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c)
482static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, 482static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
483 struct i2c_msg *msgs, int num) 483 struct i2c_msg *msgs, int num)
484{ 484{
485 unsigned long timeout; 485 unsigned long iicstat, timeout;
486 int spins = 20;
486 int ret; 487 int ret;
487 488
488 if (i2c->suspended) 489 if (i2c->suspended)
@@ -521,7 +522,21 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
521 522
522 /* ensure the stop has been through the bus */ 523 /* ensure the stop has been through the bus */
523 524
524 msleep(1); 525 dev_dbg(i2c->dev, "waiting for bus idle\n");
526
527 /* first, try busy waiting briefly */
528 do {
529 iicstat = readl(i2c->regs + S3C2410_IICSTAT);
530 } while ((iicstat & S3C2410_IICSTAT_START) && --spins);
531
532 /* if that timed out sleep */
533 if (!spins) {
534 msleep(1);
535 iicstat = readl(i2c->regs + S3C2410_IICSTAT);
536 }
537
538 if (iicstat & S3C2410_IICSTAT_START)
539 dev_warn(i2c->dev, "timeout waiting for bus idle\n");
525 540
526 out: 541 out:
527 return ret; 542 return ret;
diff --git a/drivers/i2c/busses/i2c-s6000.c b/drivers/i2c/busses/i2c-s6000.c
index c91359f4965c..cadc0216e02f 100644
--- a/drivers/i2c/busses/i2c-s6000.c
+++ b/drivers/i2c/busses/i2c-s6000.c
@@ -36,8 +36,8 @@
36#include <linux/completion.h> 36#include <linux/completion.h>
37#include <linux/interrupt.h> 37#include <linux/interrupt.h>
38#include <linux/platform_device.h> 38#include <linux/platform_device.h>
39#include <linux/io.h>
39 40
40#include <asm/io.h>
41#include "i2c-s6000.h" 41#include "i2c-s6000.h"
42 42
43#define DRV_NAME "i2c-s6000" 43#define DRV_NAME "i2c-s6000"
diff --git a/drivers/i2c/busses/i2c-sh7760.c b/drivers/i2c/busses/i2c-sh7760.c
index b9680f50f541..4f93da31d3ad 100644
--- a/drivers/i2c/busses/i2c-sh7760.c
+++ b/drivers/i2c/busses/i2c-sh7760.c
@@ -16,10 +16,10 @@
16#include <linux/ioport.h> 16#include <linux/ioport.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/io.h>
19 20
20#include <asm/clock.h> 21#include <asm/clock.h>
21#include <asm/i2c-sh7760.h> 22#include <asm/i2c-sh7760.h>
22#include <asm/io.h>
23 23
24/* register offsets */ 24/* register offsets */
25#define I2CSCR 0x0 /* slave ctrl */ 25#define I2CSCR 0x0 /* slave ctrl */
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c
index 98b1ec489159..3d76a188e42f 100644
--- a/drivers/i2c/busses/i2c-sibyte.c
+++ b/drivers/i2c/busses/i2c-sibyte.c
@@ -22,7 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <asm/io.h> 25#include <linux/io.h>
26#include <asm/sibyte/sb1250_regs.h> 26#include <asm/sibyte/sb1250_regs.h>
27#include <asm/sibyte/sb1250_smbus.h> 27#include <asm/sibyte/sb1250_smbus.h>
28 28
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c
index 78b06107342c..2fc08fbf67a2 100644
--- a/drivers/i2c/busses/i2c-simtec.c
+++ b/drivers/i2c/busses/i2c-simtec.c
@@ -24,12 +24,11 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/io.h>
27 28
28#include <linux/i2c.h> 29#include <linux/i2c.h>
29#include <linux/i2c-algo-bit.h> 30#include <linux/i2c-algo-bit.h>
30 31
31#include <asm/io.h>
32
33struct simtec_i2c_data { 32struct simtec_i2c_data {
34 struct resource *ioarea; 33 struct resource *ioarea;
35 void __iomem *reg; 34 void __iomem *reg;
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 55a71370c79b..437586611d4a 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -61,7 +61,7 @@
61#include <linux/init.h> 61#include <linux/init.h>
62#include <linux/i2c.h> 62#include <linux/i2c.h>
63#include <linux/acpi.h> 63#include <linux/acpi.h>
64#include <asm/io.h> 64#include <linux/io.h>
65 65
66static int blacklist[] = { 66static int blacklist[] = {
67 PCI_DEVICE_ID_SI_540, 67 PCI_DEVICE_ID_SI_540,
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 2309c7f1bde2..e6f539e26f65 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -53,7 +53,7 @@
53#include <linux/init.h> 53#include <linux/init.h>
54#include <linux/i2c.h> 54#include <linux/i2c.h>
55#include <linux/acpi.h> 55#include <linux/acpi.h>
56#include <asm/io.h> 56#include <linux/io.h>
57 57
58/* SIS630 SMBus registers */ 58/* SIS630 SMBus registers */
59#define SMB_STS 0x80 /* status */ 59#define SMB_STS 0x80 /* status */
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index d43d8f8943dd..86837f0c4cb9 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -38,7 +38,7 @@
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/acpi.h> 40#include <linux/acpi.h>
41#include <asm/io.h> 41#include <linux/io.h>
42 42
43/* base address register in PCI config space */ 43/* base address register in PCI config space */
44#define SIS96x_BAR 0x04 44#define SIS96x_BAR 0x04
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 0c770eabe85e..b1b3447942c9 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -29,13 +29,16 @@
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30 30
31#define MAX_CHIPS 10 31#define MAX_CHIPS 10
32#define STUB_FUNC (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | \
33 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | \
34 I2C_FUNC_SMBUS_I2C_BLOCK)
32 35
33static unsigned short chip_addr[MAX_CHIPS]; 36static unsigned short chip_addr[MAX_CHIPS];
34module_param_array(chip_addr, ushort, NULL, S_IRUGO); 37module_param_array(chip_addr, ushort, NULL, S_IRUGO);
35MODULE_PARM_DESC(chip_addr, 38MODULE_PARM_DESC(chip_addr,
36 "Chip addresses (up to 10, between 0x03 and 0x77)"); 39 "Chip addresses (up to 10, between 0x03 and 0x77)");
37 40
38static unsigned long functionality = ~0UL; 41static unsigned long functionality = STUB_FUNC;
39module_param(functionality, ulong, S_IRUGO | S_IWUSR); 42module_param(functionality, ulong, S_IRUGO | S_IWUSR);
40MODULE_PARM_DESC(functionality, "Override functionality bitfield"); 43MODULE_PARM_DESC(functionality, "Override functionality bitfield");
41 44
@@ -156,9 +159,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
156 159
157static u32 stub_func(struct i2c_adapter *adapter) 160static u32 stub_func(struct i2c_adapter *adapter)
158{ 161{
159 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 162 return STUB_FUNC & functionality;
160 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
161 I2C_FUNC_SMBUS_I2C_BLOCK) & functionality;
162} 163}
163 164
164static const struct i2c_algorithm smbus_algorithm = { 165static const struct i2c_algorithm smbus_algorithm = {
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c
index 5c473833d948..60556012312f 100644
--- a/drivers/i2c/busses/i2c-versatile.c
+++ b/drivers/i2c/busses/i2c-versatile.c
@@ -15,8 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18 18#include <linux/io.h>
19#include <asm/io.h>
20 19
21#define I2C_CONTROL 0x00 20#define I2C_CONTROL 0x00
22#define I2C_CONTROLS 0x00 21#define I2C_CONTROLS 0x00
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index de78283bddbe..7799fe5bda88 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -25,7 +25,7 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/i2c-algo-bit.h> 27#include <linux/i2c-algo-bit.h>
28#include <asm/io.h> 28#include <linux/io.h>
29 29
30/* Power management registers */ 30/* Power management registers */
31#define PM_CFG_REVID 0x08 /* silicon revision code */ 31#define PM_CFG_REVID 0x08 /* silicon revision code */
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index d57292e5dae0..4c6fff5f330d 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -51,7 +51,7 @@
51#include <linux/i2c.h> 51#include <linux/i2c.h>
52#include <linux/init.h> 52#include <linux/init.h>
53#include <linux/acpi.h> 53#include <linux/acpi.h>
54#include <asm/io.h> 54#include <linux/io.h>
55 55
56static struct pci_dev *vt596_pdev; 56static struct pci_dev *vt596_pdev;
57 57
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 684395b6f3e2..4cb4bb009950 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -32,7 +32,7 @@
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <asm/io.h> 35#include <linux/io.h>
36 36
37#include <linux/scx200.h> 37#include <linux/scx200.h>
38 38
@@ -552,7 +552,7 @@ static int __init scx200_create_isa(const char *text, unsigned long base,
552 * the name and the BAR where the I/O address resource is located. ISA 552 * the name and the BAR where the I/O address resource is located. ISA
553 * devices are flagged with a bar value of -1 */ 553 * devices are flagged with a bar value of -1 */
554 554
555static struct pci_device_id scx200_pci[] = { 555static const struct pci_device_id scx200_pci[] __initconst = {
556 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE), 556 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE),
557 .driver_data = 0 }, 557 .driver_data = 0 },
558 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE), 558 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE),
diff --git a/drivers/i2c/busses/scx200_i2c.c b/drivers/i2c/busses/scx200_i2c.c
index 42df0eca43d5..7ee0d502ceab 100644
--- a/drivers/i2c/busses/scx200_i2c.c
+++ b/drivers/i2c/busses/scx200_i2c.c
@@ -27,7 +27,7 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-algo-bit.h> 29#include <linux/i2c-algo-bit.h>
30#include <asm/io.h> 30#include <linux/io.h>
31 31
32#include <linux/scx200_gpio.h> 32#include <linux/scx200_gpio.h>
33 33
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index c2258a51fe0c..db3c9f3a7647 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -159,107 +159,131 @@ static void i2c_device_shutdown(struct device *dev)
159 driver->shutdown(client); 159 driver->shutdown(client);
160} 160}
161 161
162#ifdef CONFIG_SUSPEND 162#ifdef CONFIG_PM_SLEEP
163static int i2c_device_pm_suspend(struct device *dev) 163static int i2c_legacy_suspend(struct device *dev, pm_message_t mesg)
164{ 164{
165 const struct dev_pm_ops *pm; 165 struct i2c_client *client = i2c_verify_client(dev);
166 struct i2c_driver *driver;
166 167
167 if (!dev->driver) 168 if (!client || !dev->driver)
168 return 0; 169 return 0;
169 pm = dev->driver->pm; 170 driver = to_i2c_driver(dev->driver);
170 if (!pm || !pm->suspend) 171 if (!driver->suspend)
171 return 0; 172 return 0;
172 return pm->suspend(dev); 173 return driver->suspend(client, mesg);
173} 174}
174 175
175static int i2c_device_pm_resume(struct device *dev) 176static int i2c_legacy_resume(struct device *dev)
176{ 177{
177 const struct dev_pm_ops *pm; 178 struct i2c_client *client = i2c_verify_client(dev);
179 struct i2c_driver *driver;
178 180
179 if (!dev->driver) 181 if (!client || !dev->driver)
180 return 0; 182 return 0;
181 pm = dev->driver->pm; 183 driver = to_i2c_driver(dev->driver);
182 if (!pm || !pm->resume) 184 if (!driver->resume)
183 return 0; 185 return 0;
184 return pm->resume(dev); 186 return driver->resume(client);
185} 187}
186#else
187#define i2c_device_pm_suspend NULL
188#define i2c_device_pm_resume NULL
189#endif
190 188
191#ifdef CONFIG_PM_RUNTIME 189static int i2c_device_pm_suspend(struct device *dev)
192static int i2c_device_runtime_suspend(struct device *dev)
193{ 190{
194 const struct dev_pm_ops *pm; 191 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
195 192
196 if (!dev->driver) 193 if (pm_runtime_suspended(dev))
197 return 0;
198 pm = dev->driver->pm;
199 if (!pm || !pm->runtime_suspend)
200 return 0; 194 return 0;
201 return pm->runtime_suspend(dev);
202}
203 195
204static int i2c_device_runtime_resume(struct device *dev) 196 if (pm)
205{ 197 return pm->suspend ? pm->suspend(dev) : 0;
206 const struct dev_pm_ops *pm;
207 198
208 if (!dev->driver) 199 return i2c_legacy_suspend(dev, PMSG_SUSPEND);
209 return 0;
210 pm = dev->driver->pm;
211 if (!pm || !pm->runtime_resume)
212 return 0;
213 return pm->runtime_resume(dev);
214} 200}
215 201
216static int i2c_device_runtime_idle(struct device *dev) 202static int i2c_device_pm_resume(struct device *dev)
217{ 203{
218 const struct dev_pm_ops *pm = NULL; 204 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
219 int ret; 205 int ret;
220 206
221 if (dev->driver) 207 if (pm)
222 pm = dev->driver->pm; 208 ret = pm->resume ? pm->resume(dev) : 0;
223 if (pm && pm->runtime_idle) { 209 else
224 ret = pm->runtime_idle(dev); 210 ret = i2c_legacy_resume(dev);
225 if (ret) 211
226 return ret; 212 if (!ret) {
213 pm_runtime_disable(dev);
214 pm_runtime_set_active(dev);
215 pm_runtime_enable(dev);
227 } 216 }
228 217
229 return pm_runtime_suspend(dev); 218 return ret;
230} 219}
231#else
232#define i2c_device_runtime_suspend NULL
233#define i2c_device_runtime_resume NULL
234#define i2c_device_runtime_idle NULL
235#endif
236 220
237static int i2c_device_suspend(struct device *dev, pm_message_t mesg) 221static int i2c_device_pm_freeze(struct device *dev)
238{ 222{
239 struct i2c_client *client = i2c_verify_client(dev); 223 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
240 struct i2c_driver *driver;
241 224
242 if (!client || !dev->driver) 225 if (pm_runtime_suspended(dev))
243 return 0; 226 return 0;
244 driver = to_i2c_driver(dev->driver); 227
245 if (!driver->suspend) 228 if (pm)
246 return 0; 229 return pm->freeze ? pm->freeze(dev) : 0;
247 return driver->suspend(client, mesg); 230
231 return i2c_legacy_suspend(dev, PMSG_FREEZE);
248} 232}
249 233
250static int i2c_device_resume(struct device *dev) 234static int i2c_device_pm_thaw(struct device *dev)
251{ 235{
252 struct i2c_client *client = i2c_verify_client(dev); 236 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
253 struct i2c_driver *driver;
254 237
255 if (!client || !dev->driver) 238 if (pm_runtime_suspended(dev))
256 return 0; 239 return 0;
257 driver = to_i2c_driver(dev->driver); 240
258 if (!driver->resume) 241 if (pm)
242 return pm->thaw ? pm->thaw(dev) : 0;
243
244 return i2c_legacy_resume(dev);
245}
246
247static int i2c_device_pm_poweroff(struct device *dev)
248{
249 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
250
251 if (pm_runtime_suspended(dev))
259 return 0; 252 return 0;
260 return driver->resume(client); 253
254 if (pm)
255 return pm->poweroff ? pm->poweroff(dev) : 0;
256
257 return i2c_legacy_suspend(dev, PMSG_HIBERNATE);
261} 258}
262 259
260static int i2c_device_pm_restore(struct device *dev)
261{
262 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
263 int ret;
264
265 if (pm)
266 ret = pm->restore ? pm->restore(dev) : 0;
267 else
268 ret = i2c_legacy_resume(dev);
269
270 if (!ret) {
271 pm_runtime_disable(dev);
272 pm_runtime_set_active(dev);
273 pm_runtime_enable(dev);
274 }
275
276 return ret;
277}
278#else /* !CONFIG_PM_SLEEP */
279#define i2c_device_pm_suspend NULL
280#define i2c_device_pm_resume NULL
281#define i2c_device_pm_freeze NULL
282#define i2c_device_pm_thaw NULL
283#define i2c_device_pm_poweroff NULL
284#define i2c_device_pm_restore NULL
285#endif /* !CONFIG_PM_SLEEP */
286
263static void i2c_client_dev_release(struct device *dev) 287static void i2c_client_dev_release(struct device *dev)
264{ 288{
265 kfree(to_i2c_client(dev)); 289 kfree(to_i2c_client(dev));
@@ -301,9 +325,15 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
301static const struct dev_pm_ops i2c_device_pm_ops = { 325static const struct dev_pm_ops i2c_device_pm_ops = {
302 .suspend = i2c_device_pm_suspend, 326 .suspend = i2c_device_pm_suspend,
303 .resume = i2c_device_pm_resume, 327 .resume = i2c_device_pm_resume,
304 .runtime_suspend = i2c_device_runtime_suspend, 328 .freeze = i2c_device_pm_freeze,
305 .runtime_resume = i2c_device_runtime_resume, 329 .thaw = i2c_device_pm_thaw,
306 .runtime_idle = i2c_device_runtime_idle, 330 .poweroff = i2c_device_pm_poweroff,
331 .restore = i2c_device_pm_restore,
332 SET_RUNTIME_PM_OPS(
333 pm_generic_runtime_suspend,
334 pm_generic_runtime_resume,
335 pm_generic_runtime_idle
336 )
307}; 337};
308 338
309struct bus_type i2c_bus_type = { 339struct bus_type i2c_bus_type = {
@@ -312,8 +342,6 @@ struct bus_type i2c_bus_type = {
312 .probe = i2c_device_probe, 342 .probe = i2c_device_probe,
313 .remove = i2c_device_remove, 343 .remove = i2c_device_remove,
314 .shutdown = i2c_device_shutdown, 344 .shutdown = i2c_device_shutdown,
315 .suspend = i2c_device_suspend,
316 .resume = i2c_device_resume,
317 .pm = &i2c_device_pm_ops, 345 .pm = &i2c_device_pm_ops,
318}; 346};
319EXPORT_SYMBOL_GPL(i2c_bus_type); 347EXPORT_SYMBOL_GPL(i2c_bus_type);
@@ -1193,10 +1221,10 @@ EXPORT_SYMBOL(i2c_transfer);
1193 * 1221 *
1194 * Returns negative errno, or else the number of bytes written. 1222 * Returns negative errno, or else the number of bytes written.
1195 */ 1223 */
1196int i2c_master_send(struct i2c_client *client,const char *buf ,int count) 1224int i2c_master_send(struct i2c_client *client, const char *buf, int count)
1197{ 1225{
1198 int ret; 1226 int ret;
1199 struct i2c_adapter *adap=client->adapter; 1227 struct i2c_adapter *adap = client->adapter;
1200 struct i2c_msg msg; 1228 struct i2c_msg msg;
1201 1229
1202 msg.addr = client->addr; 1230 msg.addr = client->addr;
@@ -1220,9 +1248,9 @@ EXPORT_SYMBOL(i2c_master_send);
1220 * 1248 *
1221 * Returns negative errno, or else the number of bytes read. 1249 * Returns negative errno, or else the number of bytes read.
1222 */ 1250 */
1223int i2c_master_recv(struct i2c_client *client, char *buf ,int count) 1251int i2c_master_recv(struct i2c_client *client, char *buf, int count)
1224{ 1252{
1225 struct i2c_adapter *adap=client->adapter; 1253 struct i2c_adapter *adap = client->adapter;
1226 struct i2c_msg msg; 1254 struct i2c_msg msg;
1227 int ret; 1255 int ret;
1228 1256
@@ -1424,7 +1452,7 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1424} 1452}
1425EXPORT_SYMBOL_GPL(i2c_new_probed_device); 1453EXPORT_SYMBOL_GPL(i2c_new_probed_device);
1426 1454
1427struct i2c_adapter* i2c_get_adapter(int id) 1455struct i2c_adapter *i2c_get_adapter(int id)
1428{ 1456{
1429 struct i2c_adapter *adapter; 1457 struct i2c_adapter *adapter;
1430 1458
@@ -1451,7 +1479,7 @@ static u8 crc8(u16 data)
1451{ 1479{
1452 int i; 1480 int i;
1453 1481
1454 for(i = 0; i < 8; i++) { 1482 for (i = 0; i < 8; i++) {
1455 if (data & 0x8000) 1483 if (data & 0x8000)
1456 data = data ^ POLY; 1484 data = data ^ POLY;
1457 data = data << 1; 1485 data = data << 1;
@@ -1464,7 +1492,7 @@ static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
1464{ 1492{
1465 int i; 1493 int i;
1466 1494
1467 for(i = 0; i < count; i++) 1495 for (i = 0; i < count; i++)
1468 crc = crc8((crc ^ p[i]) << 8); 1496 crc = crc8((crc ^ p[i]) << 8);
1469 return crc; 1497 return crc;
1470} 1498}
@@ -1534,7 +1562,7 @@ EXPORT_SYMBOL(i2c_smbus_read_byte);
1534 */ 1562 */
1535s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 1563s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
1536{ 1564{
1537 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1565 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1538 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); 1566 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
1539} 1567}
1540EXPORT_SYMBOL(i2c_smbus_write_byte); 1568EXPORT_SYMBOL(i2c_smbus_write_byte);
@@ -1572,9 +1600,9 @@ s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
1572{ 1600{
1573 union i2c_smbus_data data; 1601 union i2c_smbus_data data;
1574 data.byte = value; 1602 data.byte = value;
1575 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1603 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1576 I2C_SMBUS_WRITE,command, 1604 I2C_SMBUS_WRITE, command,
1577 I2C_SMBUS_BYTE_DATA,&data); 1605 I2C_SMBUS_BYTE_DATA, &data);
1578} 1606}
1579EXPORT_SYMBOL(i2c_smbus_write_byte_data); 1607EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1580 1608
@@ -1611,9 +1639,9 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1611{ 1639{
1612 union i2c_smbus_data data; 1640 union i2c_smbus_data data;
1613 data.word = value; 1641 data.word = value;
1614 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1642 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1615 I2C_SMBUS_WRITE,command, 1643 I2C_SMBUS_WRITE, command,
1616 I2C_SMBUS_WORD_DATA,&data); 1644 I2C_SMBUS_WORD_DATA, &data);
1617} 1645}
1618EXPORT_SYMBOL(i2c_smbus_write_word_data); 1646EXPORT_SYMBOL(i2c_smbus_write_word_data);
1619 1647
@@ -1690,9 +1718,9 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
1690 length = I2C_SMBUS_BLOCK_MAX; 1718 length = I2C_SMBUS_BLOCK_MAX;
1691 data.block[0] = length; 1719 data.block[0] = length;
1692 memcpy(&data.block[1], values, length); 1720 memcpy(&data.block[1], values, length);
1693 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1721 return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1694 I2C_SMBUS_WRITE,command, 1722 I2C_SMBUS_WRITE, command,
1695 I2C_SMBUS_BLOCK_DATA,&data); 1723 I2C_SMBUS_BLOCK_DATA, &data);
1696} 1724}
1697EXPORT_SYMBOL(i2c_smbus_write_block_data); 1725EXPORT_SYMBOL(i2c_smbus_write_block_data);
1698 1726
@@ -1734,10 +1762,10 @@ EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
1734 1762
1735/* Simulate a SMBus command using the i2c protocol 1763/* Simulate a SMBus command using the i2c protocol
1736 No checking of parameters is done! */ 1764 No checking of parameters is done! */
1737static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, 1765static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
1738 unsigned short flags, 1766 unsigned short flags,
1739 char read_write, u8 command, int size, 1767 char read_write, u8 command, int size,
1740 union i2c_smbus_data * data) 1768 union i2c_smbus_data *data)
1741{ 1769{
1742 /* So we need to generate a series of msgs. In the case of writing, we 1770 /* So we need to generate a series of msgs. In the case of writing, we
1743 need to use only one message; when reading, we need two. We initialize 1771 need to use only one message; when reading, we need two. We initialize
@@ -1745,7 +1773,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1745 simpler. */ 1773 simpler. */
1746 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; 1774 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
1747 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; 1775 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
1748 int num = read_write == I2C_SMBUS_READ?2:1; 1776 int num = read_write == I2C_SMBUS_READ ? 2 : 1;
1749 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, 1777 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
1750 { addr, flags | I2C_M_RD, 0, msgbuf1 } 1778 { addr, flags | I2C_M_RD, 0, msgbuf1 }
1751 }; 1779 };
@@ -1754,7 +1782,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1754 int status; 1782 int status;
1755 1783
1756 msgbuf0[0] = command; 1784 msgbuf0[0] = command;
1757 switch(size) { 1785 switch (size) {
1758 case I2C_SMBUS_QUICK: 1786 case I2C_SMBUS_QUICK:
1759 msg[0].len = 0; 1787 msg[0].len = 0;
1760 /* Special case: The read/write field is used as data */ 1788 /* Special case: The read/write field is used as data */
@@ -1781,7 +1809,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1781 if (read_write == I2C_SMBUS_READ) 1809 if (read_write == I2C_SMBUS_READ)
1782 msg[1].len = 2; 1810 msg[1].len = 2;
1783 else { 1811 else {
1784 msg[0].len=3; 1812 msg[0].len = 3;
1785 msgbuf0[1] = data->word & 0xff; 1813 msgbuf0[1] = data->word & 0xff;
1786 msgbuf0[2] = data->word >> 8; 1814 msgbuf0[2] = data->word >> 8;
1787 } 1815 }
@@ -1874,26 +1902,26 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1874 } 1902 }
1875 1903
1876 if (read_write == I2C_SMBUS_READ) 1904 if (read_write == I2C_SMBUS_READ)
1877 switch(size) { 1905 switch (size) {
1878 case I2C_SMBUS_BYTE: 1906 case I2C_SMBUS_BYTE:
1879 data->byte = msgbuf0[0]; 1907 data->byte = msgbuf0[0];
1880 break; 1908 break;
1881 case I2C_SMBUS_BYTE_DATA: 1909 case I2C_SMBUS_BYTE_DATA:
1882 data->byte = msgbuf1[0]; 1910 data->byte = msgbuf1[0];
1883 break; 1911 break;
1884 case I2C_SMBUS_WORD_DATA: 1912 case I2C_SMBUS_WORD_DATA:
1885 case I2C_SMBUS_PROC_CALL: 1913 case I2C_SMBUS_PROC_CALL:
1886 data->word = msgbuf1[0] | (msgbuf1[1] << 8); 1914 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
1887 break; 1915 break;
1888 case I2C_SMBUS_I2C_BLOCK_DATA: 1916 case I2C_SMBUS_I2C_BLOCK_DATA:
1889 for (i = 0; i < data->block[0]; i++) 1917 for (i = 0; i < data->block[0]; i++)
1890 data->block[i+1] = msgbuf1[i]; 1918 data->block[i+1] = msgbuf1[i];
1891 break; 1919 break;
1892 case I2C_SMBUS_BLOCK_DATA: 1920 case I2C_SMBUS_BLOCK_DATA:
1893 case I2C_SMBUS_BLOCK_PROC_CALL: 1921 case I2C_SMBUS_BLOCK_PROC_CALL:
1894 for (i = 0; i < msgbuf1[0] + 1; i++) 1922 for (i = 0; i < msgbuf1[0] + 1; i++)
1895 data->block[i] = msgbuf1[i]; 1923 data->block[i] = msgbuf1[i];
1896 break; 1924 break;
1897 } 1925 }
1898 return 0; 1926 return 0;
1899} 1927}
@@ -1938,7 +1966,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
1938 } 1966 }
1939 rt_mutex_unlock(&adapter->bus_lock); 1967 rt_mutex_unlock(&adapter->bus_lock);
1940 } else 1968 } else
1941 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, 1969 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write,
1942 command, protocol, data); 1970 command, protocol, data);
1943 1971
1944 return res; 1972 return res;
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index f4110aa49600..e0694e4d86c7 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -35,7 +35,7 @@
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-dev.h> 36#include <linux/i2c-dev.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <asm/uaccess.h> 38#include <linux/uaccess.h>
39 39
40static struct i2c_driver i2cdev_driver; 40static struct i2c_driver i2cdev_driver;
41 41
@@ -132,45 +132,45 @@ static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
132 * needed by those system calls and by this SMBus interface. 132 * needed by those system calls and by this SMBus interface.
133 */ 133 */
134 134
135static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, 135static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
136 loff_t *offset) 136 loff_t *offset)
137{ 137{
138 char *tmp; 138 char *tmp;
139 int ret; 139 int ret;
140 140
141 struct i2c_client *client = (struct i2c_client *)file->private_data; 141 struct i2c_client *client = file->private_data;
142 142
143 if (count > 8192) 143 if (count > 8192)
144 count = 8192; 144 count = 8192;
145 145
146 tmp = kmalloc(count,GFP_KERNEL); 146 tmp = kmalloc(count, GFP_KERNEL);
147 if (tmp==NULL) 147 if (tmp == NULL)
148 return -ENOMEM; 148 return -ENOMEM;
149 149
150 pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n", 150 pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n",
151 iminor(file->f_path.dentry->d_inode), count); 151 iminor(file->f_path.dentry->d_inode), count);
152 152
153 ret = i2c_master_recv(client,tmp,count); 153 ret = i2c_master_recv(client, tmp, count);
154 if (ret >= 0) 154 if (ret >= 0)
155 ret = copy_to_user(buf,tmp,count)?-EFAULT:ret; 155 ret = copy_to_user(buf, tmp, count) ? -EFAULT : ret;
156 kfree(tmp); 156 kfree(tmp);
157 return ret; 157 return ret;
158} 158}
159 159
160static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t count, 160static ssize_t i2cdev_write(struct file *file, const char __user *buf,
161 loff_t *offset) 161 size_t count, loff_t *offset)
162{ 162{
163 int ret; 163 int ret;
164 char *tmp; 164 char *tmp;
165 struct i2c_client *client = (struct i2c_client *)file->private_data; 165 struct i2c_client *client = file->private_data;
166 166
167 if (count > 8192) 167 if (count > 8192)
168 count = 8192; 168 count = 8192;
169 169
170 tmp = kmalloc(count,GFP_KERNEL); 170 tmp = kmalloc(count, GFP_KERNEL);
171 if (tmp==NULL) 171 if (tmp == NULL)
172 return -ENOMEM; 172 return -ENOMEM;
173 if (copy_from_user(tmp,buf,count)) { 173 if (copy_from_user(tmp, buf, count)) {
174 kfree(tmp); 174 kfree(tmp);
175 return -EFAULT; 175 return -EFAULT;
176 } 176 }
@@ -178,7 +178,7 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c
178 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n", 178 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n",
179 iminor(file->f_path.dentry->d_inode), count); 179 iminor(file->f_path.dentry->d_inode), count);
180 180
181 ret = i2c_master_send(client,tmp,count); 181 ret = i2c_master_send(client, tmp, count);
182 kfree(tmp); 182 kfree(tmp);
183 return ret; 183 return ret;
184} 184}
@@ -369,13 +369,13 @@ static noinline int i2cdev_ioctl_smbus(struct i2c_client *client,
369 369
370static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 370static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
371{ 371{
372 struct i2c_client *client = (struct i2c_client *)file->private_data; 372 struct i2c_client *client = file->private_data;
373 unsigned long funcs; 373 unsigned long funcs;
374 374
375 dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n", 375 dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n",
376 cmd, arg); 376 cmd, arg);
377 377
378 switch ( cmd ) { 378 switch (cmd) {
379 case I2C_SLAVE: 379 case I2C_SLAVE:
380 case I2C_SLAVE_FORCE: 380 case I2C_SLAVE_FORCE:
381 /* NOTE: devices set up to work with "new style" drivers 381 /* NOTE: devices set up to work with "new style" drivers
@@ -601,7 +601,7 @@ static void __exit i2c_dev_exit(void)
601{ 601{
602 i2c_del_driver(&i2cdev_driver); 602 i2c_del_driver(&i2cdev_driver);
603 class_destroy(i2c_dev_class); 603 class_destroy(i2c_dev_class);
604 unregister_chrdev(I2C_MAJOR,"i2c"); 604 unregister_chrdev(I2C_MAJOR, "i2c");
605} 605}
606 606
607MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and " 607MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "