aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-i801.c
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2008-07-14 16:38:25 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-07-14 16:38:25 -0400
commit97140342e69d479a3ad82bfd4c154c0b08fe3eea (patch)
tree2ee2ad225c7e4850a30bc57c4bf07251c1da1085 /drivers/i2c/busses/i2c-i801.c
parent6ea438ec8da4ec56bf415f5ea360e6b0cb59c6c3 (diff)
i2c: Bus drivers return -Errno not -1
Tighten error paths used by various i2c adapters (mostly x86) so they return real fault/errno codes instead of a "-1" (which is most often interpreted as "-EPERM"). Build tested, with eyeball review. One minor initial goal is to have adapters consistently return the code "-ENXIO" when addressing a device doesn't get an ACK response, at least in the probe paths where they are already good at stifling related logspam. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c/busses/i2c-i801.c')
-rw-r--r--drivers/i2c/busses/i2c-i801.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index b0f771fe4326..7d6d9dfcc58a 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -151,7 +151,7 @@ static int i801_transaction(int xact)
151 outb_p(temp, SMBHSTSTS); 151 outb_p(temp, SMBHSTSTS);
152 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 152 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
153 dev_dbg(&I801_dev->dev, "Failed! (%02x)\n", temp); 153 dev_dbg(&I801_dev->dev, "Failed! (%02x)\n", temp);
154 return -1; 154 return -EBUSY;
155 } else { 155 } else {
156 dev_dbg(&I801_dev->dev, "Successful!\n"); 156 dev_dbg(&I801_dev->dev, "Successful!\n");
157 } 157 }
@@ -170,7 +170,7 @@ static int i801_transaction(int xact)
170 /* If the SMBus is still busy, we give up */ 170 /* If the SMBus is still busy, we give up */
171 if (timeout >= MAX_TIMEOUT) { 171 if (timeout >= MAX_TIMEOUT) {
172 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); 172 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
173 result = -1; 173 result = -ETIMEDOUT;
174 /* try to stop the current command */ 174 /* try to stop the current command */
175 dev_dbg(&I801_dev->dev, "Terminating the current operation\n"); 175 dev_dbg(&I801_dev->dev, "Terminating the current operation\n");
176 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT); 176 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT);
@@ -179,19 +179,19 @@ static int i801_transaction(int xact)
179 } 179 }
180 180
181 if (temp & SMBHSTSTS_FAILED) { 181 if (temp & SMBHSTSTS_FAILED) {
182 result = -1; 182 result = -EIO;
183 dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n"); 183 dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n");
184 } 184 }
185 185
186 if (temp & SMBHSTSTS_BUS_ERR) { 186 if (temp & SMBHSTSTS_BUS_ERR) {
187 result = -1; 187 result = -EIO;
188 dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked " 188 dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked "
189 "until next hard reset. (sorry!)\n"); 189 "until next hard reset. (sorry!)\n");
190 /* Clock stops and slave is stuck in mid-transmission */ 190 /* Clock stops and slave is stuck in mid-transmission */
191 } 191 }
192 192
193 if (temp & SMBHSTSTS_DEV_ERR) { 193 if (temp & SMBHSTSTS_DEV_ERR) {
194 result = -1; 194 result = -ENXIO;
195 dev_dbg(&I801_dev->dev, "Error: no response!\n"); 195 dev_dbg(&I801_dev->dev, "Error: no response!\n");
196 } 196 }
197 197
@@ -231,6 +231,7 @@ static int i801_block_transaction_by_block(union i2c_smbus_data *data,
231 char read_write, int hwpec) 231 char read_write, int hwpec)
232{ 232{
233 int i, len; 233 int i, len;
234 int status;
234 235
235 inb_p(SMBHSTCNT); /* reset the data buffer index */ 236 inb_p(SMBHSTCNT); /* reset the data buffer index */
236 237
@@ -242,14 +243,15 @@ static int i801_block_transaction_by_block(union i2c_smbus_data *data,
242 outb_p(data->block[i+1], SMBBLKDAT); 243 outb_p(data->block[i+1], SMBBLKDAT);
243 } 244 }
244 245
245 if (i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | 246 status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 |
246 I801_PEC_EN * hwpec)) 247 I801_PEC_EN * hwpec);
247 return -1; 248 if (status)
249 return status;
248 250
249 if (read_write == I2C_SMBUS_READ) { 251 if (read_write == I2C_SMBUS_READ) {
250 len = inb_p(SMBHSTDAT0); 252 len = inb_p(SMBHSTDAT0);
251 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 253 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
252 return -1; 254 return -EPROTO;
253 255
254 data->block[0] = len; 256 data->block[0] = len;
255 for (i = 0; i < len; i++) 257 for (i = 0; i < len; i++)
@@ -314,11 +316,11 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
314 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) { 316 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
315 dev_err(&I801_dev->dev, 317 dev_err(&I801_dev->dev,
316 "Reset failed! (%02x)\n", temp); 318 "Reset failed! (%02x)\n", temp);
317 return -1; 319 return -EBUSY;
318 } 320 }
319 if (i != 1) 321 if (i != 1)
320 /* if die in middle of block transaction, fail */ 322 /* if die in middle of block transaction, fail */
321 return -1; 323 return -EIO;
322 } 324 }
323 325
324 if (i == 1) 326 if (i == 1)
@@ -342,19 +344,19 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
342 msleep(1); 344 msleep(1);
343 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), 345 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL),
344 SMBHSTCNT); 346 SMBHSTCNT);
345 result = -1; 347 result = -ETIMEDOUT;
346 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); 348 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
347 } 349 }
348 350
349 if (temp & SMBHSTSTS_FAILED) { 351 if (temp & SMBHSTSTS_FAILED) {
350 result = -1; 352 result = -EIO;
351 dev_dbg(&I801_dev->dev, 353 dev_dbg(&I801_dev->dev,
352 "Error: Failed bus transaction\n"); 354 "Error: Failed bus transaction\n");
353 } else if (temp & SMBHSTSTS_BUS_ERR) { 355 } else if (temp & SMBHSTSTS_BUS_ERR) {
354 result = -1; 356 result = -EIO;
355 dev_err(&I801_dev->dev, "Bus collision!\n"); 357 dev_err(&I801_dev->dev, "Bus collision!\n");
356 } else if (temp & SMBHSTSTS_DEV_ERR) { 358 } else if (temp & SMBHSTSTS_DEV_ERR) {
357 result = -1; 359 result = -ENXIO;
358 dev_dbg(&I801_dev->dev, "Error: no response!\n"); 360 dev_dbg(&I801_dev->dev, "Error: no response!\n");
359 } 361 }
360 362
@@ -362,7 +364,7 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
362 && command != I2C_SMBUS_I2C_BLOCK_DATA) { 364 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
363 len = inb_p(SMBHSTDAT0); 365 len = inb_p(SMBHSTDAT0);
364 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 366 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
365 return -1; 367 return -EPROTO;
366 data->block[0] = len; 368 data->block[0] = len;
367 } 369 }
368 370
@@ -394,7 +396,7 @@ static int i801_set_block_buffer_mode(void)
394{ 396{
395 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL); 397 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL);
396 if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0) 398 if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0)
397 return -1; 399 return -EIO;
398 return 0; 400 return 0;
399} 401}
400 402
@@ -414,7 +416,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
414 } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) { 416 } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) {
415 dev_err(&I801_dev->dev, 417 dev_err(&I801_dev->dev,
416 "I2C block read is unsupported!\n"); 418 "I2C block read is unsupported!\n");
417 return -1; 419 return -EOPNOTSUPP;
418 } 420 }
419 } 421 }
420 422
@@ -449,7 +451,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
449 return result; 451 return result;
450} 452}
451 453
452/* Return -1 on error. */ 454/* Return negative errno on error. */
453static s32 i801_access(struct i2c_adapter * adap, u16 addr, 455static s32 i801_access(struct i2c_adapter * adap, u16 addr,
454 unsigned short flags, char read_write, u8 command, 456 unsigned short flags, char read_write, u8 command,
455 int size, union i2c_smbus_data * data) 457 int size, union i2c_smbus_data * data)
@@ -514,7 +516,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
514 case I2C_SMBUS_PROC_CALL: 516 case I2C_SMBUS_PROC_CALL:
515 default: 517 default:
516 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); 518 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size);
517 return -1; 519 return -EOPNOTSUPP;
518 } 520 }
519 521
520 if (hwpec) /* enable/disable hardware PEC */ 522 if (hwpec) /* enable/disable hardware PEC */
@@ -537,7 +539,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
537 if(block) 539 if(block)
538 return ret; 540 return ret;
539 if(ret) 541 if(ret)
540 return -1; 542 return ret;
541 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) 543 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
542 return 0; 544 return 0;
543 545