i2c-davinci.c (fc3718918f13ad72827d62d36ea0f5fb55090644) | i2c-davinci.c (c5b4afec8e669bbe265daea24037fccfc42c4fe3) |
---|---|
1/* 2 * TI DAVINCI I2C adapter driver. 3 * 4 * Copyright (C) 2006 Texas Instruments. 5 * Copyright (C) 2007 MontaVista Software Inc. 6 * 7 * Updated by Vinod & Sudhakar Feb 2005 8 * --- 317 unchanged lines hidden (view full) --- 326 dev->buf_len = msg->len; 327 dev->stop = stop; 328 329 davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len); 330 331 INIT_COMPLETION(dev->cmd_complete); 332 dev->cmd_err = 0; 333 | 1/* 2 * TI DAVINCI I2C adapter driver. 3 * 4 * Copyright (C) 2006 Texas Instruments. 5 * Copyright (C) 2007 MontaVista Software Inc. 6 * 7 * Updated by Vinod & Sudhakar Feb 2005 8 * --- 317 unchanged lines hidden (view full) --- 326 dev->buf_len = msg->len; 327 dev->stop = stop; 328 329 davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len); 330 331 INIT_COMPLETION(dev->cmd_complete); 332 dev->cmd_err = 0; 333 |
334 /* Take I2C out of reset, configure it as master and set the 335 * start bit */ 336 flag = DAVINCI_I2C_MDR_IRS | DAVINCI_I2C_MDR_MST | DAVINCI_I2C_MDR_STT; | 334 /* Take I2C out of reset and configure it as master */ 335 flag = DAVINCI_I2C_MDR_IRS | DAVINCI_I2C_MDR_MST; |
337 338 /* if the slave address is ten bit address, enable XA bit */ 339 if (msg->flags & I2C_M_TEN) 340 flag |= DAVINCI_I2C_MDR_XA; 341 if (!(msg->flags & I2C_M_RD)) 342 flag |= DAVINCI_I2C_MDR_TRX; | 336 337 /* if the slave address is ten bit address, enable XA bit */ 338 if (msg->flags & I2C_M_TEN) 339 flag |= DAVINCI_I2C_MDR_XA; 340 if (!(msg->flags & I2C_M_RD)) 341 flag |= DAVINCI_I2C_MDR_TRX; |
343 if (stop) 344 flag |= DAVINCI_I2C_MDR_STP; 345 if (msg->len == 0) { | 342 if (msg->len == 0) |
346 flag |= DAVINCI_I2C_MDR_RM; | 343 flag |= DAVINCI_I2C_MDR_RM; |
347 flag &= ~DAVINCI_I2C_MDR_STP; 348 } | |
349 350 /* Enable receive or transmit interrupts */ 351 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG); 352 if (msg->flags & I2C_M_RD) 353 w |= DAVINCI_I2C_IMR_RRDY; 354 else 355 w |= DAVINCI_I2C_IMR_XRDY; 356 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w); 357 358 dev->terminate = 0; 359 360 /* | 344 345 /* Enable receive or transmit interrupts */ 346 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG); 347 if (msg->flags & I2C_M_RD) 348 w |= DAVINCI_I2C_IMR_RRDY; 349 else 350 w |= DAVINCI_I2C_IMR_XRDY; 351 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w); 352 353 dev->terminate = 0; 354 355 /* |
356 * Write mode register first as needed for correct behaviour 357 * on OMAP-L138, but don't set STT yet to avoid a race with XRDY 358 * occuring before we have loaded DXR 359 */ 360 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); 361 362 /* |
|
361 * First byte should be set here, not after interrupt, 362 * because transmit-data-ready interrupt can come before 363 * NACK-interrupt during sending of previous message and 364 * ICDXR may have wrong data | 363 * First byte should be set here, not after interrupt, 364 * because transmit-data-ready interrupt can come before 365 * NACK-interrupt during sending of previous message and 366 * ICDXR may have wrong data |
367 * It also saves us one interrupt, slightly faster |
|
365 */ 366 if ((!(msg->flags & I2C_M_RD)) && dev->buf_len) { 367 davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, *dev->buf++); 368 dev->buf_len--; 369 } 370 | 368 */ 369 if ((!(msg->flags & I2C_M_RD)) && dev->buf_len) { 370 davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, *dev->buf++); 371 dev->buf_len--; 372 } 373 |
371 /* write the data into mode register; start transmitting */ | 374 /* Set STT to begin transmit now DXR is loaded */ 375 flag |= DAVINCI_I2C_MDR_STT; 376 if (stop && msg->len != 0) 377 flag |= DAVINCI_I2C_MDR_STP; |
372 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); 373 374 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 375 dev->adapter.timeout); 376 if (r == 0) { 377 dev_err(dev->dev, "controller timed out\n"); 378 i2c_recover_bus(dev); 379 i2c_davinci_init(dev); --- 445 unchanged lines hidden --- | 378 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); 379 380 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 381 dev->adapter.timeout); 382 if (r == 0) { 383 dev_err(dev->dev, "controller timed out\n"); 384 i2c_recover_bus(dev); 385 i2c_davinci_init(dev); --- 445 unchanged lines hidden --- |