Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

David Brownell and committed by
Jean Delvare
97140342 6ea438ec

+191 -148
+2 -2
drivers/i2c/algos/i2c-algo-bit.c
··· 320 320 unsigned char addr, int retries) 321 321 { 322 322 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 323 - int i, ret = -1; 323 + int i, ret = 0; 324 324 325 325 for (i = 0; i <= retries; i++) { 326 326 ret = i2c_outb(i2c_adap, addr); ··· 508 508 addr ^= 1; 509 509 ret = try_address(i2c_adap, addr, retries); 510 510 if ((ret != 1) && !nak_ok) 511 - return -EREMOTEIO; 511 + return -ENXIO; 512 512 } 513 513 514 514 return 0;
+10 -12
drivers/i2c/busses/i2c-ali1535.c
··· 259 259 dev_err(&adap->dev, 260 260 "SMBus reset failed! (0x%02x) - controller or " 261 261 "device on bus is probably hung\n", temp); 262 - return -1; 262 + return -EBUSY; 263 263 } 264 264 } else { 265 265 /* check and clear done bit */ ··· 281 281 282 282 /* If the SMBus is still busy, we give up */ 283 283 if (timeout >= MAX_TIMEOUT) { 284 - result = -1; 284 + result = -ETIMEDOUT; 285 285 dev_err(&adap->dev, "SMBus Timeout!\n"); 286 286 } 287 287 288 288 if (temp & ALI1535_STS_FAIL) { 289 - result = -1; 289 + result = -EIO; 290 290 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 291 291 } 292 292 ··· 295 295 * do a printk. This means that bus collisions go unreported. 296 296 */ 297 297 if (temp & ALI1535_STS_BUSERR) { 298 - result = -1; 298 + result = -ENXIO; 299 299 dev_dbg(&adap->dev, 300 300 "Error: no response or bus collision ADD=%02x\n", 301 301 inb_p(SMBHSTADD)); ··· 303 303 304 304 /* haven't ever seen this */ 305 305 if (temp & ALI1535_STS_DEV) { 306 - result = -1; 306 + result = -EIO; 307 307 dev_err(&adap->dev, "Error: device error\n"); 308 308 } 309 309 310 310 /* check to see if the "command complete" indication is set */ 311 311 if (!(temp & ALI1535_STS_DONE)) { 312 - result = -1; 312 + result = -ETIMEDOUT; 313 313 dev_err(&adap->dev, "Error: command never completed\n"); 314 314 } 315 315 ··· 332 332 return result; 333 333 } 334 334 335 - /* Return -1 on error. */ 335 + /* Return negative errno on error. */ 336 336 static s32 ali1535_access(struct i2c_adapter *adap, u16 addr, 337 337 unsigned short flags, char read_write, u8 command, 338 338 int size, union i2c_smbus_data *data) ··· 359 359 switch (size) { 360 360 case I2C_SMBUS_PROC_CALL: 361 361 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); 362 - result = -1; 362 + result = -EOPNOTSUPP; 363 363 goto EXIT; 364 364 case I2C_SMBUS_QUICK: 365 365 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), ··· 420 420 break; 421 421 } 422 422 423 - if (ali1535_transaction(adap)) { 424 - /* Error in transaction */ 425 - result = -1; 423 + result = ali1535_transaction(adap); 424 + if (result) 426 425 goto EXIT; 427 - } 428 426 429 427 if ((read_write == I2C_SMBUS_WRITE) || (size == ALI1535_QUICK)) { 430 428 result = 0;
+17 -6
drivers/i2c/busses/i2c-ali1563.c
··· 67 67 { 68 68 u32 data; 69 69 int timeout; 70 + int status = -EIO; 70 71 71 72 dev_dbg(&a->dev, "Transaction (pre): STS=%02x, CNTL1=%02x, " 72 73 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", ··· 104 103 /* Issue 'kill' to host controller */ 105 104 outb_p(HST_CNTL2_KILL,SMB_HST_CNTL2); 106 105 data = inb_p(SMB_HST_STS); 106 + status = -ETIMEDOUT; 107 107 } 108 108 109 109 /* device error - no response, ignore the autodetection case */ 110 - if ((data & HST_STS_DEVERR) && (size != HST_CNTL2_QUICK)) { 111 - dev_err(&a->dev, "Device error!\n"); 110 + if (data & HST_STS_DEVERR) { 111 + if (size != HST_CNTL2_QUICK) 112 + dev_err(&a->dev, "Device error!\n"); 113 + status = -ENXIO; 112 114 } 113 - 114 115 /* bus collision */ 115 116 if (data & HST_STS_BUSERR) { 116 117 dev_err(&a->dev, "Bus collision!\n"); ··· 125 122 outb_p(0x0,SMB_HST_CNTL2); 126 123 } 127 124 128 - return -1; 125 + return status; 129 126 } 130 127 131 128 static int ali1563_block_start(struct i2c_adapter * a) 132 129 { 133 130 u32 data; 134 131 int timeout; 132 + int status = -EIO; 135 133 136 134 dev_dbg(&a->dev, "Block (pre): STS=%02x, CNTL1=%02x, " 137 135 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", ··· 168 164 169 165 if (timeout && !(data & HST_STS_BAD)) 170 166 return 0; 167 + 168 + if (timeout == 0) 169 + status = -ETIMEDOUT; 170 + 171 + if (data & HST_STS_DEVERR) 172 + status = -ENXIO; 173 + 171 174 dev_err(&a->dev, "SMBus Error: %s%s%s%s%s\n", 172 - timeout ? "Timeout " : "", 175 + timeout ? "" : "Timeout ", 173 176 data & HST_STS_FAIL ? "Transaction Failed " : "", 174 177 data & HST_STS_BUSERR ? "No response or Bus Collision " : "", 175 178 data & HST_STS_DEVERR ? "Device Error " : "", 176 179 !(data & HST_STS_DONE) ? "Transaction Never Finished " : ""); 177 - return -1; 180 + return status; 178 181 } 179 182 180 183 static int ali1563_block(struct i2c_adapter * a, union i2c_smbus_data * data, u8 rw)
+10 -9
drivers/i2c/busses/i2c-ali15x3.c
··· 282 282 dev_err(&adap->dev, "SMBus reset failed! (0x%02x) - " 283 283 "controller or device on bus is probably hung\n", 284 284 temp); 285 - return -1; 285 + return -EBUSY; 286 286 } 287 287 } else { 288 288 /* check and clear done bit */ ··· 304 304 305 305 /* If the SMBus is still busy, we give up */ 306 306 if (timeout >= MAX_TIMEOUT) { 307 - result = -1; 307 + result = -ETIMEDOUT; 308 308 dev_err(&adap->dev, "SMBus Timeout!\n"); 309 309 } 310 310 311 311 if (temp & ALI15X3_STS_TERM) { 312 - result = -1; 312 + result = -EIO; 313 313 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 314 314 } 315 315 ··· 320 320 This means that bus collisions go unreported. 321 321 */ 322 322 if (temp & ALI15X3_STS_COLL) { 323 - result = -1; 323 + result = -ENXIO; 324 324 dev_dbg(&adap->dev, 325 325 "Error: no response or bus collision ADD=%02x\n", 326 326 inb_p(SMBHSTADD)); ··· 328 328 329 329 /* haven't ever seen this */ 330 330 if (temp & ALI15X3_STS_DEV) { 331 - result = -1; 331 + result = -EIO; 332 332 dev_err(&adap->dev, "Error: device error\n"); 333 333 } 334 334 dev_dbg(&adap->dev, "Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, " ··· 338 338 return result; 339 339 } 340 340 341 - /* Return -1 on error. */ 341 + /* Return negative errno on error. */ 342 342 static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr, 343 343 unsigned short flags, char read_write, u8 command, 344 344 int size, union i2c_smbus_data * data) ··· 364 364 switch (size) { 365 365 case I2C_SMBUS_PROC_CALL: 366 366 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); 367 - return -1; 367 + return -EOPNOTSUPP; 368 368 case I2C_SMBUS_QUICK: 369 369 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 370 370 SMBHSTADD); ··· 421 421 422 422 outb_p(size, SMBHSTCNT); /* output command */ 423 423 424 - if (ali15x3_transaction(adap)) /* Error in transaction */ 425 - return -1; 424 + temp = ali15x3_transaction(adap); 425 + if (temp) 426 + return temp; 426 427 427 428 if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK)) 428 429 return 0;
+2 -2
drivers/i2c/busses/i2c-amd756-s4882.c
··· 58 58 /* We exclude the multiplexed addresses */ 59 59 if (addr == 0x4c || (addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30 60 60 || addr == 0x18) 61 - return -1; 61 + return -ENXIO; 62 62 63 63 mutex_lock(&amd756_lock); 64 64 ··· 86 86 87 87 /* We exclude the non-multiplexed addresses */ 88 88 if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30) 89 - return -1; 89 + return -ENXIO; 90 90 91 91 mutex_lock(&amd756_lock); 92 92
+10 -8
drivers/i2c/busses/i2c-amd756.c
··· 151 151 } 152 152 153 153 if (temp & GS_PRERR_STS) { 154 - result = -1; 154 + result = -ENXIO; 155 155 dev_dbg(&adap->dev, "SMBus Protocol error (no response)!\n"); 156 156 } 157 157 158 158 if (temp & GS_COL_STS) { 159 - result = -1; 159 + result = -EIO; 160 160 dev_warn(&adap->dev, "SMBus collision!\n"); 161 161 } 162 162 163 163 if (temp & GS_TO_STS) { 164 - result = -1; 164 + result = -ETIMEDOUT; 165 165 dev_dbg(&adap->dev, "SMBus protocol timeout!\n"); 166 166 } 167 167 ··· 189 189 outw_p(inw(SMB_GLOBAL_ENABLE) | GE_ABORT, SMB_GLOBAL_ENABLE); 190 190 msleep(100); 191 191 outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS); 192 - return -1; 192 + return -EIO; 193 193 } 194 194 195 - /* Return -1 on error. */ 195 + /* Return negative errno on error. */ 196 196 static s32 amd756_access(struct i2c_adapter * adap, u16 addr, 197 197 unsigned short flags, char read_write, 198 198 u8 command, int size, union i2c_smbus_data * data) 199 199 { 200 200 int i, len; 201 + int status; 201 202 202 203 /** TODO: Should I supporte the 10-bit transfers? */ 203 204 switch (size) { 204 205 case I2C_SMBUS_PROC_CALL: 205 206 dev_dbg(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); 206 207 /* TODO: Well... It is supported, I'm just not sure what to do here... */ 207 - return -1; 208 + return -EOPNOTSUPP; 208 209 case I2C_SMBUS_QUICK: 209 210 outw_p(((addr & 0x7f) << 1) | (read_write & 0x01), 210 211 SMB_HOST_ADDRESS); ··· 257 256 /* How about enabling interrupts... */ 258 257 outw_p(size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE); 259 258 260 - if (amd756_transaction(adap)) /* Error in transaction */ 261 - return -1; 259 + status = amd756_transaction(adap); 260 + if (status) 261 + return status; 262 262 263 263 if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK)) 264 264 return 0;
+31 -16
drivers/i2c/busses/i2c-amd8111.c
··· 77 77 if (!timeout) { 78 78 dev_warn(&smbus->dev->dev, 79 79 "Timeout while waiting for IBF to clear\n"); 80 - return -1; 80 + return -ETIMEDOUT; 81 81 } 82 82 83 83 return 0; ··· 93 93 if (!timeout) { 94 94 dev_warn(&smbus->dev->dev, 95 95 "Timeout while waiting for OBF to set\n"); 96 - return -1; 96 + return -ETIMEDOUT; 97 97 } 98 98 99 99 return 0; ··· 102 102 static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, 103 103 unsigned char *data) 104 104 { 105 - if (amd_ec_wait_write(smbus)) 106 - return -1; 105 + int status; 106 + 107 + status = amd_ec_wait_write(smbus); 108 + if (status) 109 + return status; 107 110 outb(AMD_EC_CMD_RD, smbus->base + AMD_EC_CMD); 108 111 109 - if (amd_ec_wait_write(smbus)) 110 - return -1; 112 + status = amd_ec_wait_write(smbus); 113 + if (status) 114 + return status; 111 115 outb(address, smbus->base + AMD_EC_DATA); 112 116 113 - if (amd_ec_wait_read(smbus)) 114 - return -1; 117 + status = amd_ec_wait_read(smbus); 118 + if (status) 119 + return status; 115 120 *data = inb(smbus->base + AMD_EC_DATA); 116 121 117 122 return 0; ··· 125 120 static unsigned int amd_ec_write(struct amd_smbus *smbus, unsigned char address, 126 121 unsigned char data) 127 122 { 128 - if (amd_ec_wait_write(smbus)) 129 - return -1; 123 + int status; 124 + 125 + status = amd_ec_wait_write(smbus); 126 + if (status) 127 + return status; 130 128 outb(AMD_EC_CMD_WR, smbus->base + AMD_EC_CMD); 131 129 132 - if (amd_ec_wait_write(smbus)) 133 - return -1; 130 + status = amd_ec_wait_write(smbus); 131 + if (status) 132 + return status; 134 133 outb(address, smbus->base + AMD_EC_DATA); 135 134 136 - if (amd_ec_wait_write(smbus)) 137 - return -1; 135 + status = amd_ec_wait_write(smbus); 136 + if (status) 137 + return status; 138 138 outb(data, smbus->base + AMD_EC_DATA); 139 139 140 140 return 0; ··· 277 267 278 268 default: 279 269 dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 280 - return -1; 270 + return -EOPNOTSUPP; 281 271 } 282 272 283 273 amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); 284 274 amd_ec_write(smbus, AMD_SMB_PRTCL, protocol); 285 275 276 + /* FIXME this discards status from ec_read(); so temp[0] will 277 + * hold stack garbage ... the rest of this routine will act 278 + * nonsensically. Ignored ec_write() status might explain 279 + * some such failures... 280 + */ 286 281 amd_ec_read(smbus, AMD_SMB_STS, temp + 0); 287 282 288 283 if (~temp[0] & AMD_SMB_STS_DONE) { ··· 301 286 } 302 287 303 288 if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS)) 304 - return -1; 289 + return -EIO; 305 290 306 291 if (read_write == I2C_SMBUS_WRITE) 307 292 return 0;
+23 -21
drivers/i2c/busses/i2c-i801.c
··· 151 151 outb_p(temp, SMBHSTSTS); 152 152 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 153 153 dev_dbg(&I801_dev->dev, "Failed! (%02x)\n", temp); 154 - return -1; 154 + return -EBUSY; 155 155 } else { 156 156 dev_dbg(&I801_dev->dev, "Successful!\n"); 157 157 } ··· 170 170 /* If the SMBus is still busy, we give up */ 171 171 if (timeout >= MAX_TIMEOUT) { 172 172 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); 173 - result = -1; 173 + result = -ETIMEDOUT; 174 174 /* try to stop the current command */ 175 175 dev_dbg(&I801_dev->dev, "Terminating the current operation\n"); 176 176 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT); ··· 179 179 } 180 180 181 181 if (temp & SMBHSTSTS_FAILED) { 182 - result = -1; 182 + result = -EIO; 183 183 dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n"); 184 184 } 185 185 186 186 if (temp & SMBHSTSTS_BUS_ERR) { 187 - result = -1; 187 + result = -EIO; 188 188 dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked " 189 189 "until next hard reset. (sorry!)\n"); 190 190 /* Clock stops and slave is stuck in mid-transmission */ 191 191 } 192 192 193 193 if (temp & SMBHSTSTS_DEV_ERR) { 194 - result = -1; 194 + result = -ENXIO; 195 195 dev_dbg(&I801_dev->dev, "Error: no response!\n"); 196 196 } 197 197 ··· 231 231 char read_write, int hwpec) 232 232 { 233 233 int i, len; 234 + int status; 234 235 235 236 inb_p(SMBHSTCNT); /* reset the data buffer index */ 236 237 ··· 243 242 outb_p(data->block[i+1], SMBBLKDAT); 244 243 } 245 244 246 - if (i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | 247 - I801_PEC_EN * hwpec)) 248 - return -1; 245 + status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | 246 + I801_PEC_EN * hwpec); 247 + if (status) 248 + return status; 249 249 250 250 if (read_write == I2C_SMBUS_READ) { 251 251 len = inb_p(SMBHSTDAT0); 252 252 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 253 - return -1; 253 + return -EPROTO; 254 254 255 255 data->block[0] = len; 256 256 for (i = 0; i < len; i++) ··· 316 314 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) { 317 315 dev_err(&I801_dev->dev, 318 316 "Reset failed! (%02x)\n", temp); 319 - return -1; 317 + return -EBUSY; 320 318 } 321 319 if (i != 1) 322 320 /* if die in middle of block transaction, fail */ 323 - return -1; 321 + return -EIO; 324 322 } 325 323 326 324 if (i == 1) ··· 344 342 msleep(1); 345 343 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), 346 344 SMBHSTCNT); 347 - result = -1; 345 + result = -ETIMEDOUT; 348 346 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); 349 347 } 350 348 351 349 if (temp & SMBHSTSTS_FAILED) { 352 - result = -1; 350 + result = -EIO; 353 351 dev_dbg(&I801_dev->dev, 354 352 "Error: Failed bus transaction\n"); 355 353 } else if (temp & SMBHSTSTS_BUS_ERR) { 356 - result = -1; 354 + result = -EIO; 357 355 dev_err(&I801_dev->dev, "Bus collision!\n"); 358 356 } else if (temp & SMBHSTSTS_DEV_ERR) { 359 - result = -1; 357 + result = -ENXIO; 360 358 dev_dbg(&I801_dev->dev, "Error: no response!\n"); 361 359 } 362 360 ··· 364 362 && command != I2C_SMBUS_I2C_BLOCK_DATA) { 365 363 len = inb_p(SMBHSTDAT0); 366 364 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 367 - return -1; 365 + return -EPROTO; 368 366 data->block[0] = len; 369 367 } 370 368 ··· 396 394 { 397 395 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL); 398 396 if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0) 399 - return -1; 397 + return -EIO; 400 398 return 0; 401 399 } 402 400 ··· 416 414 } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) { 417 415 dev_err(&I801_dev->dev, 418 416 "I2C block read is unsupported!\n"); 419 - return -1; 417 + return -EOPNOTSUPP; 420 418 } 421 419 } 422 420 ··· 451 449 return result; 452 450 } 453 451 454 - /* Return -1 on error. */ 452 + /* Return negative errno on error. */ 455 453 static s32 i801_access(struct i2c_adapter * adap, u16 addr, 456 454 unsigned short flags, char read_write, u8 command, 457 455 int size, union i2c_smbus_data * data) ··· 516 514 case I2C_SMBUS_PROC_CALL: 517 515 default: 518 516 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); 519 - return -1; 517 + return -EOPNOTSUPP; 520 518 } 521 519 522 520 if (hwpec) /* enable/disable hardware PEC */ ··· 539 537 if(block) 540 538 return ret; 541 539 if(ret) 542 - return -1; 540 + return ret; 543 541 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) 544 542 return 0; 545 543
+13 -12
drivers/i2c/busses/i2c-nforce2.c
··· 172 172 dev_dbg(&adap->dev, "SMBus Timeout!\n"); 173 173 if (smbus->can_abort) 174 174 nforce2_abort(adap); 175 - return -1; 175 + return -ETIMEDOUT; 176 176 } 177 177 if (!(temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) { 178 178 dev_dbg(&adap->dev, "Transaction failed (0x%02x)!\n", temp); 179 - return -1; 179 + return -EIO; 180 180 } 181 181 return 0; 182 182 } 183 183 184 - /* Return -1 on error */ 184 + /* Return negative errno on error */ 185 185 static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, 186 186 unsigned short flags, char read_write, 187 187 u8 command, int size, union i2c_smbus_data * data) ··· 189 189 struct nforce2_smbus *smbus = adap->algo_data; 190 190 unsigned char protocol, pec; 191 191 u8 len; 192 - int i; 192 + int i, status; 193 193 194 194 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : 195 195 NVIDIA_SMB_PRTCL_WRITE; ··· 233 233 "Transaction failed " 234 234 "(requested block size: %d)\n", 235 235 len); 236 - return -1; 236 + return -EINVAL; 237 237 } 238 238 outb_p(len, NVIDIA_SMB_BCNT); 239 239 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) ··· 245 245 246 246 default: 247 247 dev_err(&adap->dev, "Unsupported transaction %d\n", size); 248 - return -1; 248 + return -EOPNOTSUPP; 249 249 } 250 250 251 251 outb_p((addr & 0x7f) << 1, NVIDIA_SMB_ADDR); 252 252 outb_p(protocol, NVIDIA_SMB_PRTCL); 253 253 254 - if (nforce2_check_status(adap)) 255 - return -1; 254 + status = nforce2_check_status(adap); 255 + if (status) 256 + return status; 256 257 257 258 if (read_write == I2C_SMBUS_WRITE) 258 259 return 0; ··· 275 274 dev_err(&adap->dev, "Transaction failed " 276 275 "(received block size: 0x%02x)\n", 277 276 len); 278 - return -1; 277 + return -EPROTO; 279 278 } 280 279 for (i = 0; i < len; i++) 281 280 data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i); ··· 336 335 != PCIBIOS_SUCCESSFUL) { 337 336 dev_err(&dev->dev, "Error reading PCI config for %s\n", 338 337 name); 339 - return -1; 338 + return -EIO; 340 339 } 341 340 342 341 smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK; ··· 346 345 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) { 347 346 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n", 348 347 smbus->base, smbus->base+smbus->size-1, name); 349 - return -1; 348 + return -EBUSY; 350 349 } 351 350 smbus->adapter.owner = THIS_MODULE; 352 351 smbus->adapter.id = I2C_HW_SMBUS_NFORCE2; ··· 361 360 if (error) { 362 361 dev_err(&smbus->adapter.dev, "Failed to register adapter.\n"); 363 362 release_region(smbus->base, smbus->size); 364 - return -1; 363 + return error; 365 364 } 366 365 dev_info(&smbus->adapter.dev, "nForce2 SMBus adapter at %#x\n", smbus->base); 367 366 return 0;
+11 -9
drivers/i2c/busses/i2c-piix4.c
··· 253 253 outb_p(temp, SMBHSTSTS); 254 254 if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 255 255 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp); 256 - return -1; 256 + return -EBUSY; 257 257 } else { 258 258 dev_dbg(&piix4_adapter.dev, "Successful!\n"); 259 259 } ··· 275 275 /* If the SMBus is still busy, we give up */ 276 276 if (timeout >= MAX_TIMEOUT) { 277 277 dev_err(&piix4_adapter.dev, "SMBus Timeout!\n"); 278 - result = -1; 278 + result = -ETIMEDOUT; 279 279 } 280 280 281 281 if (temp & 0x10) { 282 - result = -1; 282 + result = -EIO; 283 283 dev_err(&piix4_adapter.dev, "Error: Failed bus transaction\n"); 284 284 } 285 285 286 286 if (temp & 0x08) { 287 - result = -1; 287 + result = -EIO; 288 288 dev_dbg(&piix4_adapter.dev, "Bus collision! SMBus may be " 289 289 "locked until next hard reset. (sorry!)\n"); 290 290 /* Clock stops and slave is stuck in mid-transmission */ 291 291 } 292 292 293 293 if (temp & 0x04) { 294 - result = -1; 294 + result = -ENXIO; 295 295 dev_dbg(&piix4_adapter.dev, "Error: no response!\n"); 296 296 } 297 297 ··· 309 309 return result; 310 310 } 311 311 312 - /* Return -1 on error. */ 312 + /* Return negative errno on error. */ 313 313 static s32 piix4_access(struct i2c_adapter * adap, u16 addr, 314 314 unsigned short flags, char read_write, 315 315 u8 command, int size, union i2c_smbus_data * data) 316 316 { 317 317 int i, len; 318 + int status; 318 319 319 320 switch (size) { 320 321 case I2C_SMBUS_PROC_CALL: 321 322 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); 322 - return -1; 323 + return -EOPNOTSUPP; 323 324 case I2C_SMBUS_QUICK: 324 325 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 325 326 SMBHSTADD); ··· 372 371 373 372 outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 374 373 375 - if (piix4_transaction()) /* Error in transaction */ 376 - return -1; 374 + status = piix4_transaction(); 375 + if (status) 376 + return status; 377 377 378 378 if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) 379 379 return 0;
+11 -8
drivers/i2c/busses/i2c-sis5595.c
··· 236 236 sis5595_write(SMB_STS_HI, temp >> 8); 237 237 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) { 238 238 dev_dbg(&adap->dev, "Failed! (%02x)\n", temp); 239 - return -1; 239 + return -EBUSY; 240 240 } else { 241 241 dev_dbg(&adap->dev, "Successful!\n"); 242 242 } ··· 254 254 /* If the SMBus is still busy, we give up */ 255 255 if (timeout >= MAX_TIMEOUT) { 256 256 dev_dbg(&adap->dev, "SMBus Timeout!\n"); 257 - result = -1; 257 + result = -ETIMEDOUT; 258 258 } 259 259 260 260 if (temp & 0x10) { 261 261 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 262 - result = -1; 262 + result = -ENXIO; 263 263 } 264 264 265 265 if (temp & 0x20) { 266 266 dev_err(&adap->dev, "Bus collision! SMBus may be locked until " 267 267 "next hard reset (or not...)\n"); 268 268 /* Clock stops and slave is stuck in mid-transmission */ 269 - result = -1; 269 + result = -EIO; 270 270 } 271 271 272 272 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8); ··· 282 282 return result; 283 283 } 284 284 285 - /* Return -1 on error. */ 285 + /* Return negative errno on error. */ 286 286 static s32 sis5595_access(struct i2c_adapter *adap, u16 addr, 287 287 unsigned short flags, char read_write, 288 288 u8 command, int size, union i2c_smbus_data *data) 289 289 { 290 + int status; 291 + 290 292 switch (size) { 291 293 case I2C_SMBUS_QUICK: 292 294 sis5595_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); ··· 320 318 break; 321 319 default: 322 320 dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 323 - return -1; 321 + return -EOPNOTSUPP; 324 322 } 325 323 326 324 sis5595_write(SMB_CTL_LO, ((size & 0x0E))); 327 325 328 - if (sis5595_transaction(adap)) 329 - return -1; 326 + status = sis5595_transaction(adap); 327 + if (status) 328 + return status; 330 329 331 330 if ((size != SIS5595_PROC_CALL) && 332 331 ((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK)))
+26 -21
drivers/i2c/busses/i2c-sis630.c
··· 134 134 135 135 if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) { 136 136 dev_dbg(&adap->dev, "Failed! (%02x)\n", temp); 137 - return -1; 137 + return -EBUSY; 138 138 } else { 139 139 dev_dbg(&adap->dev, "Successful!\n"); 140 140 } ··· 177 177 /* If the SMBus is still busy, we give up */ 178 178 if (timeout >= MAX_TIMEOUT) { 179 179 dev_dbg(&adap->dev, "SMBus Timeout!\n"); 180 - result = -1; 180 + result = -ETIMEDOUT; 181 181 } 182 182 183 183 if (temp & 0x02) { 184 184 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 185 - result = -1; 185 + result = -ENXIO; 186 186 } 187 187 188 188 if (temp & 0x04) { 189 189 dev_err(&adap->dev, "Bus collision!\n"); 190 - result = -1; 190 + result = -EIO; 191 191 /* 192 192 TBD: Datasheet say: 193 193 the software should clear this bit and restart SMBUS operation. ··· 250 250 if (i==8 || (len<8 && i==len)) { 251 251 dev_dbg(&adap->dev, "start trans len=%d i=%d\n",len ,i); 252 252 /* first transaction */ 253 - if (sis630_transaction_start(adap, SIS630_BLOCK_DATA, &oldclock)) 254 - return -1; 253 + rc = sis630_transaction_start(adap, 254 + SIS630_BLOCK_DATA, &oldclock); 255 + if (rc) 256 + return rc; 255 257 } 256 258 else if ((i-1)%8 == 7 || i==len) { 257 259 dev_dbg(&adap->dev, "trans_wait len=%d i=%d\n",len,i); ··· 266 264 */ 267 265 sis630_write(SMB_STS,0x10); 268 266 } 269 - if (sis630_transaction_wait(adap, SIS630_BLOCK_DATA)) { 267 + rc = sis630_transaction_wait(adap, 268 + SIS630_BLOCK_DATA); 269 + if (rc) { 270 270 dev_dbg(&adap->dev, "trans_wait failed\n"); 271 - rc = -1; 272 271 break; 273 272 } 274 273 } ··· 278 275 else { 279 276 /* read request */ 280 277 data->block[0] = len = 0; 281 - if (sis630_transaction_start(adap, SIS630_BLOCK_DATA, &oldclock)) { 282 - return -1; 283 - } 278 + rc = sis630_transaction_start(adap, 279 + SIS630_BLOCK_DATA, &oldclock); 280 + if (rc) 281 + return rc; 284 282 do { 285 - if (sis630_transaction_wait(adap, SIS630_BLOCK_DATA)) { 283 + rc = sis630_transaction_wait(adap, SIS630_BLOCK_DATA); 284 + if (rc) { 286 285 dev_dbg(&adap->dev, "trans_wait failed\n"); 287 - rc = -1; 288 286 break; 289 287 } 290 288 /* if this first transaction then read byte count */ ··· 315 311 return rc; 316 312 } 317 313 318 - /* Return -1 on error. */ 314 + /* Return negative errno on error. */ 319 315 static s32 sis630_access(struct i2c_adapter *adap, u16 addr, 320 316 unsigned short flags, char read_write, 321 317 u8 command, int size, union i2c_smbus_data *data) 322 318 { 319 + int status; 320 + 323 321 switch (size) { 324 322 case I2C_SMBUS_QUICK: 325 323 sis630_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); ··· 356 350 size = SIS630_BLOCK_DATA; 357 351 return sis630_block_data(adap, data, read_write); 358 352 default: 359 - printk("Unsupported I2C size\n"); 360 - return -1; 361 - break; 353 + printk("Unsupported SMBus operation\n"); 354 + return -EOPNOTSUPP; 362 355 } 363 356 364 - if (sis630_transaction(adap, size)) 365 - return -1; 357 + status = sis630_transaction(adap, size); 358 + if (status) 359 + return status; 366 360 367 361 if ((size != SIS630_PCALL) && 368 362 ((read_write == I2C_SMBUS_WRITE) || (size == SIS630_QUICK))) { ··· 379 373 data->word = sis630_read(SMB_BYTE) + (sis630_read(SMB_BYTE + 1) << 8); 380 374 break; 381 375 default: 382 - return -1; 383 - break; 376 + return -EOPNOTSUPP; 384 377 } 385 378 386 379 return 0;
+12 -11
drivers/i2c/busses/i2c-sis96x.c
··· 111 111 /* check it again */ 112 112 if (((temp = sis96x_read(SMB_CNT)) & 0x03) != 0x00) { 113 113 dev_dbg(&sis96x_adapter.dev, "Failed (0x%02x)\n", temp); 114 - return -1; 114 + return -EBUSY; 115 115 } else { 116 116 dev_dbg(&sis96x_adapter.dev, "Successful\n"); 117 117 } ··· 136 136 /* If the SMBus is still busy, we give up */ 137 137 if (timeout >= MAX_TIMEOUT) { 138 138 dev_dbg(&sis96x_adapter.dev, "SMBus Timeout! (0x%02x)\n", temp); 139 - result = -1; 139 + result = -ETIMEDOUT; 140 140 } 141 141 142 142 /* device error - probably missing ACK */ 143 143 if (temp & 0x02) { 144 144 dev_dbg(&sis96x_adapter.dev, "Failed bus transaction!\n"); 145 - result = -1; 145 + result = -ENXIO; 146 146 } 147 147 148 148 /* bus collision */ 149 149 if (temp & 0x04) { 150 150 dev_dbg(&sis96x_adapter.dev, "Bus collision!\n"); 151 - result = -1; 151 + result = -EIO; 152 152 } 153 153 154 154 /* Finish up by resetting the bus */ ··· 161 161 return result; 162 162 } 163 163 164 - /* Return -1 on error. */ 164 + /* Return negative errno on error. */ 165 165 static s32 sis96x_access(struct i2c_adapter * adap, u16 addr, 166 166 unsigned short flags, char read_write, 167 167 u8 command, int size, union i2c_smbus_data * data) 168 168 { 169 + int status; 169 170 170 171 switch (size) { 171 172 case I2C_SMBUS_QUICK: ··· 204 203 case I2C_SMBUS_BLOCK_DATA: 205 204 /* TO DO: */ 206 205 dev_info(&adap->dev, "SMBus block not implemented!\n"); 207 - return -1; 206 + return -EOPNOTSUPP; 208 207 break; 209 208 210 209 default: 211 - dev_info(&adap->dev, "Unsupported I2C size\n"); 212 - return -1; 213 - break; 210 + dev_info(&adap->dev, "Unsupported SMBus operation\n"); 211 + return -EOPNOTSUPP; 214 212 } 215 213 216 - if (sis96x_transaction(size)) 217 - return -1; 214 + status = sis96x_transaction(size); 215 + if (status) 216 + return status; 218 217 219 218 if ((size != SIS96x_PROC_CALL) && 220 219 ((read_write == I2C_SMBUS_WRITE) || (size == SIS96x_QUICK)))
+2 -2
drivers/i2c/busses/i2c-stub.c
··· 43 43 44 44 static struct stub_chip *stub_chips; 45 45 46 - /* Return -1 on error. */ 46 + /* Return negative errno on error. */ 47 47 static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, 48 48 char read_write, u8 command, int size, union i2c_smbus_data * data) 49 49 { ··· 120 120 121 121 default: 122 122 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); 123 - ret = -1; 123 + ret = -EOPNOTSUPP; 124 124 break; 125 125 } /* switch (size) */ 126 126
+11 -9
drivers/i2c/busses/i2c-viapro.c
··· 152 152 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 153 153 dev_err(&vt596_adapter.dev, "SMBus reset failed! " 154 154 "(0x%02x)\n", temp); 155 - return -1; 155 + return -EBUSY; 156 156 } 157 157 } 158 158 ··· 167 167 168 168 /* If the SMBus is still busy, we give up */ 169 169 if (timeout >= MAX_TIMEOUT) { 170 - result = -1; 170 + result = -ETIMEDOUT; 171 171 dev_err(&vt596_adapter.dev, "SMBus timeout!\n"); 172 172 } 173 173 174 174 if (temp & 0x10) { 175 - result = -1; 175 + result = -EIO; 176 176 dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n", 177 177 size); 178 178 } 179 179 180 180 if (temp & 0x08) { 181 - result = -1; 181 + result = -EIO; 182 182 dev_err(&vt596_adapter.dev, "SMBus collision!\n"); 183 183 } 184 184 185 185 if (temp & 0x04) { 186 186 int read = inb_p(SMBHSTADD) & 0x01; 187 - result = -1; 187 + result = -ENXIO; 188 188 /* The quick and receive byte commands are used to probe 189 189 for chips, so errors are expected, and we don't want 190 190 to frighten the user. */ ··· 202 202 return result; 203 203 } 204 204 205 - /* Return -1 on error, 0 on success */ 205 + /* Return negative errno on error, 0 on success */ 206 206 static s32 vt596_access(struct i2c_adapter *adap, u16 addr, 207 207 unsigned short flags, char read_write, u8 command, 208 208 int size, union i2c_smbus_data *data) 209 209 { 210 210 int i; 211 + int status; 211 212 212 213 switch (size) { 213 214 case I2C_SMBUS_QUICK: ··· 259 258 260 259 outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD); 261 260 262 - if (vt596_transaction(size)) /* Error in transaction */ 263 - return -1; 261 + status = vt596_transaction(size); 262 + if (status) 263 + return status; 264 264 265 265 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) 266 266 return 0; ··· 289 287 exit_unsupported: 290 288 dev_warn(&vt596_adapter.dev, "Unsupported command invoked! (0x%02x)\n", 291 289 size); 292 - return -1; 290 + return -EOPNOTSUPP; 293 291 } 294 292 295 293 static u32 vt596_func(struct i2c_adapter *adapter)