aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-mpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses/i2c-mpc.c')
-rw-r--r--drivers/i2c/busses/i2c-mpc.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 81335b76c425..bbe787b243b7 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -180,7 +180,7 @@ static void mpc_i2c_stop(struct mpc_i2c *i2c)
180static int mpc_write(struct mpc_i2c *i2c, int target, 180static int mpc_write(struct mpc_i2c *i2c, int target,
181 const u8 * data, int length, int restart) 181 const u8 * data, int length, int restart)
182{ 182{
183 int i; 183 int i, result;
184 unsigned timeout = i2c->adap.timeout; 184 unsigned timeout = i2c->adap.timeout;
185 u32 flags = restart ? CCR_RSTA : 0; 185 u32 flags = restart ? CCR_RSTA : 0;
186 186
@@ -192,15 +192,17 @@ static int mpc_write(struct mpc_i2c *i2c, int target,
192 /* Write target byte */ 192 /* Write target byte */
193 writeb((target << 1), i2c->base + MPC_I2C_DR); 193 writeb((target << 1), i2c->base + MPC_I2C_DR);
194 194
195 if (i2c_wait(i2c, timeout, 1) < 0) 195 result = i2c_wait(i2c, timeout, 1);
196 return -1; 196 if (result < 0)
197 return result;
197 198
198 for (i = 0; i < length; i++) { 199 for (i = 0; i < length; i++) {
199 /* Write data byte */ 200 /* Write data byte */
200 writeb(data[i], i2c->base + MPC_I2C_DR); 201 writeb(data[i], i2c->base + MPC_I2C_DR);
201 202
202 if (i2c_wait(i2c, timeout, 1) < 0) 203 result = i2c_wait(i2c, timeout, 1);
203 return -1; 204 if (result < 0)
205 return result;
204 } 206 }
205 207
206 return 0; 208 return 0;
@@ -210,7 +212,7 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
210 u8 * data, int length, int restart) 212 u8 * data, int length, int restart)
211{ 213{
212 unsigned timeout = i2c->adap.timeout; 214 unsigned timeout = i2c->adap.timeout;
213 int i; 215 int i, result;
214 u32 flags = restart ? CCR_RSTA : 0; 216 u32 flags = restart ? CCR_RSTA : 0;
215 217
216 /* Start with MEN */ 218 /* Start with MEN */
@@ -221,8 +223,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
221 /* Write target address byte - this time with the read flag set */ 223 /* Write target address byte - this time with the read flag set */
222 writeb((target << 1) | 1, i2c->base + MPC_I2C_DR); 224 writeb((target << 1) | 1, i2c->base + MPC_I2C_DR);
223 225
224 if (i2c_wait(i2c, timeout, 1) < 0) 226 result = i2c_wait(i2c, timeout, 1);
225 return -1; 227 if (result < 0)
228 return result;
226 229
227 if (length) { 230 if (length) {
228 if (length == 1) 231 if (length == 1)
@@ -234,8 +237,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
234 } 237 }
235 238
236 for (i = 0; i < length; i++) { 239 for (i = 0; i < length; i++) {
237 if (i2c_wait(i2c, timeout, 0) < 0) 240 result = i2c_wait(i2c, timeout, 0);
238 return -1; 241 if (result < 0)
242 return result;
239 243
240 /* Generate txack on next to last byte */ 244 /* Generate txack on next to last byte */
241 if (i == length - 2) 245 if (i == length - 2)
@@ -320,9 +324,9 @@ static int fsl_i2c_probe(struct platform_device *pdev)
320 324
321 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data; 325 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
322 326
323 if (!(i2c = kzalloc(sizeof(*i2c), GFP_KERNEL))) { 327 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
328 if (!i2c)
324 return -ENOMEM; 329 return -ENOMEM;
325 }
326 330
327 i2c->irq = platform_get_irq(pdev, 0); 331 i2c->irq = platform_get_irq(pdev, 0);
328 if (i2c->irq < 0) { 332 if (i2c->irq < 0) {