.. | .. |
---|
343 | 343 | * ocores_isr(), we just add our polling code around it. |
---|
344 | 344 | * |
---|
345 | 345 | * It can run in atomic context |
---|
| 346 | + * |
---|
| 347 | + * Return: 0 on success, -ETIMEDOUT on timeout |
---|
346 | 348 | */ |
---|
347 | | -static void ocores_process_polling(struct ocores_i2c *i2c) |
---|
| 349 | +static int ocores_process_polling(struct ocores_i2c *i2c) |
---|
348 | 350 | { |
---|
349 | | - while (1) { |
---|
350 | | - irqreturn_t ret; |
---|
351 | | - int err; |
---|
| 351 | + irqreturn_t ret; |
---|
| 352 | + int err = 0; |
---|
352 | 353 | |
---|
| 354 | + while (1) { |
---|
353 | 355 | err = ocores_poll_wait(i2c); |
---|
354 | | - if (err) { |
---|
355 | | - i2c->state = STATE_ERROR; |
---|
| 356 | + if (err) |
---|
356 | 357 | break; /* timeout */ |
---|
357 | | - } |
---|
358 | 358 | |
---|
359 | 359 | ret = ocores_isr(-1, i2c); |
---|
360 | 360 | if (ret == IRQ_NONE) |
---|
.. | .. |
---|
365 | 365 | break; |
---|
366 | 366 | } |
---|
367 | 367 | } |
---|
| 368 | + |
---|
| 369 | + return err; |
---|
368 | 370 | } |
---|
369 | 371 | |
---|
370 | 372 | static int ocores_xfer_core(struct ocores_i2c *i2c, |
---|
371 | 373 | struct i2c_msg *msgs, int num, |
---|
372 | 374 | bool polling) |
---|
373 | 375 | { |
---|
374 | | - int ret; |
---|
| 376 | + int ret = 0; |
---|
375 | 377 | u8 ctrl; |
---|
376 | 378 | |
---|
377 | 379 | ctrl = oc_getreg(i2c, OCI2C_CONTROL); |
---|
.. | .. |
---|
389 | 391 | oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START); |
---|
390 | 392 | |
---|
391 | 393 | if (polling) { |
---|
392 | | - ocores_process_polling(i2c); |
---|
| 394 | + ret = ocores_process_polling(i2c); |
---|
393 | 395 | } else { |
---|
394 | | - ret = wait_event_timeout(i2c->wait, |
---|
395 | | - (i2c->state == STATE_ERROR) || |
---|
396 | | - (i2c->state == STATE_DONE), HZ); |
---|
397 | | - if (ret == 0) { |
---|
398 | | - ocores_process_timeout(i2c); |
---|
399 | | - return -ETIMEDOUT; |
---|
400 | | - } |
---|
| 396 | + if (wait_event_timeout(i2c->wait, |
---|
| 397 | + (i2c->state == STATE_ERROR) || |
---|
| 398 | + (i2c->state == STATE_DONE), HZ) == 0) |
---|
| 399 | + ret = -ETIMEDOUT; |
---|
| 400 | + } |
---|
| 401 | + if (ret) { |
---|
| 402 | + ocores_process_timeout(i2c); |
---|
| 403 | + return ret; |
---|
401 | 404 | } |
---|
402 | 405 | |
---|
403 | 406 | return (i2c->state == STATE_DONE) ? num : -EIO; |
---|