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

i2c: mpc: report correct I2C error return codes

This patch enforces correct I2C error returned codes from Freescale's
MPC i2c bus driver, allowing for proper user-space/kernel error
handling.

Signed-off-by: Danielle Costantino <danielle.costantino@gmail.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Danielle Costantino and committed by
Wolfram Sang
ab0831d0 550d0407

+9 -9
+9 -9
drivers/i2c/busses/i2c-mpc.c
··· 124 124 static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) 125 125 { 126 126 unsigned long orig_jiffies = jiffies; 127 - u32 x; 127 + u32 cmd_err; 128 128 int result = 0; 129 129 130 130 if (!i2c->irq) { ··· 133 133 if (time_after(jiffies, orig_jiffies + timeout)) { 134 134 dev_dbg(i2c->dev, "timeout\n"); 135 135 writeccr(i2c, 0); 136 - result = -EIO; 136 + result = -ETIMEDOUT; 137 137 break; 138 138 } 139 139 } 140 - x = readb(i2c->base + MPC_I2C_SR); 140 + cmd_err = readb(i2c->base + MPC_I2C_SR); 141 141 writeb(0, i2c->base + MPC_I2C_SR); 142 142 } else { 143 143 /* Interrupt mode */ ··· 150 150 result = -ETIMEDOUT; 151 151 } 152 152 153 - x = i2c->interrupt; 153 + cmd_err = i2c->interrupt; 154 154 i2c->interrupt = 0; 155 155 } 156 156 157 157 if (result < 0) 158 158 return result; 159 159 160 - if (!(x & CSR_MCF)) { 160 + if (!(cmd_err & CSR_MCF)) { 161 161 dev_dbg(i2c->dev, "unfinished\n"); 162 162 return -EIO; 163 163 } 164 164 165 - if (x & CSR_MAL) { 165 + if (cmd_err & CSR_MAL) { 166 166 dev_dbg(i2c->dev, "MAL\n"); 167 - return -EIO; 167 + return -EAGAIN; 168 168 } 169 169 170 - if (writing && (x & CSR_RXAK)) { 170 + if (writing && (cmd_err & CSR_RXAK)) { 171 171 dev_dbg(i2c->dev, "No RXAK\n"); 172 172 /* generate stop */ 173 173 writeccr(i2c, CCR_MEN); 174 - return -EIO; 174 + return -ENXIO; 175 175 } 176 176 return 0; 177 177 }