diff options
author | David Brownell <david-b@pacbell.net> | 2008-07-14 16:38:25 -0400 |
---|---|---|
committer | Jean Delvare <khali@mahadeva.delvare> | 2008-07-14 16:38:25 -0400 |
commit | 97140342e69d479a3ad82bfd4c154c0b08fe3eea (patch) | |
tree | 2ee2ad225c7e4850a30bc57c4bf07251c1da1085 /drivers/i2c/busses/i2c-amd8111.c | |
parent | 6ea438ec8da4ec56bf415f5ea360e6b0cb59c6c3 (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-amd8111.c')
-rw-r--r-- | drivers/i2c/busses/i2c-amd8111.c | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c index 5d1a27ef2504..a4f687915de1 100644 --- a/drivers/i2c/busses/i2c-amd8111.c +++ b/drivers/i2c/busses/i2c-amd8111.c | |||
@@ -77,7 +77,7 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) | |||
77 | if (!timeout) { | 77 | if (!timeout) { |
78 | dev_warn(&smbus->dev->dev, | 78 | dev_warn(&smbus->dev->dev, |
79 | "Timeout while waiting for IBF to clear\n"); | 79 | "Timeout while waiting for IBF to clear\n"); |
80 | return -1; | 80 | return -ETIMEDOUT; |
81 | } | 81 | } |
82 | 82 | ||
83 | return 0; | 83 | return 0; |
@@ -93,7 +93,7 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) | |||
93 | if (!timeout) { | 93 | if (!timeout) { |
94 | dev_warn(&smbus->dev->dev, | 94 | dev_warn(&smbus->dev->dev, |
95 | "Timeout while waiting for OBF to set\n"); | 95 | "Timeout while waiting for OBF to set\n"); |
96 | return -1; | 96 | return -ETIMEDOUT; |
97 | } | 97 | } |
98 | 98 | ||
99 | return 0; | 99 | return 0; |
@@ -102,16 +102,21 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) | |||
102 | static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, | 102 | static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, |
103 | unsigned char *data) | 103 | unsigned char *data) |
104 | { | 104 | { |
105 | if (amd_ec_wait_write(smbus)) | 105 | int status; |
106 | return -1; | 106 | |
107 | status = amd_ec_wait_write(smbus); | ||
108 | if (status) | ||
109 | return status; | ||
107 | outb(AMD_EC_CMD_RD, smbus->base + AMD_EC_CMD); | 110 | outb(AMD_EC_CMD_RD, smbus->base + AMD_EC_CMD); |
108 | 111 | ||
109 | if (amd_ec_wait_write(smbus)) | 112 | status = amd_ec_wait_write(smbus); |
110 | return -1; | 113 | if (status) |
114 | return status; | ||
111 | outb(address, smbus->base + AMD_EC_DATA); | 115 | outb(address, smbus->base + AMD_EC_DATA); |
112 | 116 | ||
113 | if (amd_ec_wait_read(smbus)) | 117 | status = amd_ec_wait_read(smbus); |
114 | return -1; | 118 | if (status) |
119 | return status; | ||
115 | *data = inb(smbus->base + AMD_EC_DATA); | 120 | *data = inb(smbus->base + AMD_EC_DATA); |
116 | 121 | ||
117 | return 0; | 122 | return 0; |
@@ -120,16 +125,21 @@ static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, | |||
120 | static unsigned int amd_ec_write(struct amd_smbus *smbus, unsigned char address, | 125 | static unsigned int amd_ec_write(struct amd_smbus *smbus, unsigned char address, |
121 | unsigned char data) | 126 | unsigned char data) |
122 | { | 127 | { |
123 | if (amd_ec_wait_write(smbus)) | 128 | int status; |
124 | return -1; | 129 | |
130 | status = amd_ec_wait_write(smbus); | ||
131 | if (status) | ||
132 | return status; | ||
125 | outb(AMD_EC_CMD_WR, smbus->base + AMD_EC_CMD); | 133 | outb(AMD_EC_CMD_WR, smbus->base + AMD_EC_CMD); |
126 | 134 | ||
127 | if (amd_ec_wait_write(smbus)) | 135 | status = amd_ec_wait_write(smbus); |
128 | return -1; | 136 | if (status) |
137 | return status; | ||
129 | outb(address, smbus->base + AMD_EC_DATA); | 138 | outb(address, smbus->base + AMD_EC_DATA); |
130 | 139 | ||
131 | if (amd_ec_wait_write(smbus)) | 140 | status = amd_ec_wait_write(smbus); |
132 | return -1; | 141 | if (status) |
142 | return status; | ||
133 | outb(data, smbus->base + AMD_EC_DATA); | 143 | outb(data, smbus->base + AMD_EC_DATA); |
134 | 144 | ||
135 | return 0; | 145 | return 0; |
@@ -267,12 +277,17 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
267 | 277 | ||
268 | default: | 278 | default: |
269 | dev_warn(&adap->dev, "Unsupported transaction %d\n", size); | 279 | dev_warn(&adap->dev, "Unsupported transaction %d\n", size); |
270 | return -1; | 280 | return -EOPNOTSUPP; |
271 | } | 281 | } |
272 | 282 | ||
273 | amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); | 283 | amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); |
274 | amd_ec_write(smbus, AMD_SMB_PRTCL, protocol); | 284 | amd_ec_write(smbus, AMD_SMB_PRTCL, protocol); |
275 | 285 | ||
286 | /* FIXME this discards status from ec_read(); so temp[0] will | ||
287 | * hold stack garbage ... the rest of this routine will act | ||
288 | * nonsensically. Ignored ec_write() status might explain | ||
289 | * some such failures... | ||
290 | */ | ||
276 | amd_ec_read(smbus, AMD_SMB_STS, temp + 0); | 291 | amd_ec_read(smbus, AMD_SMB_STS, temp + 0); |
277 | 292 | ||
278 | if (~temp[0] & AMD_SMB_STS_DONE) { | 293 | if (~temp[0] & AMD_SMB_STS_DONE) { |
@@ -286,7 +301,7 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
286 | } | 301 | } |
287 | 302 | ||
288 | if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS)) | 303 | if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS)) |
289 | return -1; | 304 | return -EIO; |
290 | 305 | ||
291 | if (read_write == I2C_SMBUS_WRITE) | 306 | if (read_write == I2C_SMBUS_WRITE) |
292 | return 0; | 307 | return 0; |