aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorTomoya MORINAGA <tomoya.rohm@gmail.com>2012-04-19 02:38:05 -0400
committerWolfram Sang <w.sang@pengutronix.de>2012-05-12 08:28:13 -0400
commit199bca2a72a3a5cd71401b4f12171393742be84a (patch)
tree67e359c6fed52fa173e82c69ef7eece64bd38c6d /drivers/i2c
parent5cc056327ae3a3fac7411691c27ac61be2c55957 (diff)
i2c-eg20t: Merge two functions
By previous patch, pch_i2c_wait_for_xfer_complete can be merged to pch_i2c_wait_for_check_xfer. Signed-off-by: Tomoya MORINAGA <tomoya.rohm@gmail.com> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c65
1 files changed, 22 insertions, 43 deletions
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index 943084a3b690..9da12cecb3bb 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -317,33 +317,6 @@ static void pch_i2c_start(struct i2c_algo_pch_data *adap)
317} 317}
318 318
319/** 319/**
320 * pch_i2c_wait_for_xfer_complete() - initiates a wait for the tx complete event
321 * @adap: Pointer to struct i2c_algo_pch_data.
322 */
323static s32 pch_i2c_wait_for_xfer_complete(struct i2c_algo_pch_data *adap)
324{
325 long ret;
326 ret = wait_event_timeout(pch_event,
327 (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
328
329 if (ret == 0) {
330 pch_err(adap, "timeout: %x\n", adap->pch_event_flag);
331 adap->pch_event_flag = 0;
332 return -ETIMEDOUT;
333 }
334
335 if (adap->pch_event_flag & I2C_ERROR_MASK) {
336 pch_err(adap, "error bits set: %x\n", adap->pch_event_flag);
337 adap->pch_event_flag = 0;
338 return -EIO;
339 }
340
341 adap->pch_event_flag = 0;
342
343 return 0;
344}
345
346/**
347 * pch_i2c_getack() - to confirm ACK/NACK 320 * pch_i2c_getack() - to confirm ACK/NACK
348 * @adap: Pointer to struct i2c_algo_pch_data. 321 * @adap: Pointer to struct i2c_algo_pch_data.
349 */ 322 */
@@ -375,27 +348,33 @@ static void pch_i2c_stop(struct i2c_algo_pch_data *adap)
375 348
376static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap) 349static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap)
377{ 350{
378 int rtn; 351 long ret;
379 352
380 rtn = pch_i2c_wait_for_xfer_complete(adap); 353 ret = wait_event_timeout(pch_event,
381 if (rtn == 0) { 354 (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
382 if (pch_i2c_getack(adap)) { 355 if (!ret) {
383 pch_dbg(adap, "Receive NACK for slave address" 356 pch_err(adap, "%s:wait-event timeout\n", __func__);
384 "setting\n"); 357 adap->pch_event_flag = 0;
385 return -EIO; 358 pch_i2c_stop(adap);
386 } 359 pch_i2c_init(adap);
387 } else if (rtn == -EIO) { /* Arbitration Lost */ 360 return -ETIMEDOUT;
361 }
362
363 if (adap->pch_event_flag & I2C_ERROR_MASK) {
388 pch_err(adap, "Lost Arbitration\n"); 364 pch_err(adap, "Lost Arbitration\n");
365 adap->pch_event_flag = 0;
389 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT); 366 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT);
390 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT); 367 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT);
391 pch_i2c_init(adap); 368 pch_i2c_init(adap);
392 return -EAGAIN; 369 return -EAGAIN;
393 } else { /* wait-event timeout */ 370 }
394 pch_err(adap, "%s(L.%d):wait-event timeout\n", 371
395 __func__, __LINE__); 372 adap->pch_event_flag = 0;
396 pch_i2c_stop(adap); 373
397 pch_i2c_init(adap); 374 if (pch_i2c_getack(adap)) {
398 return -ETIME; 375 pch_dbg(adap, "Receive NACK for slave address"
376 "setting\n");
377 return -EIO;
399 } 378 }
400 379
401 return 0; 380 return 0;