Commit 748ef103 authored by Kumar Gala's avatar Kumar Gala Committed by Greg Kroah-Hartman

[PATCH] I2C-MPC: use wait_event_interruptible_timeout between transactions

Use wait_event_interruptible_timeout so we dont waste time waiting between
transactions like we use to.  Also, we use the adapters timeout so the
ioctl cmd I2C_TIMEOUT will now work.
Signed-off-by: default avatarKumar Gala <kumar.gala@freescale.com>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent f2e1491e
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* MPC107/Tsi107 PowerPC northbridge and processors that include * MPC107/Tsi107 PowerPC northbridge and processors that include
* the same I2C unit (8240, 8245, 85xx). * the same I2C unit (8240, 8245, 85xx).
* *
* Release 0.6 * Release 0.7
* *
* This file is licensed under the terms of the GNU General Public * This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any * License version 2. This program is licensed "as is" without any
...@@ -75,7 +75,6 @@ static irqreturn_t mpc_i2c_isr(int irq, void *dev_id, struct pt_regs *regs) ...@@ -75,7 +75,6 @@ static irqreturn_t mpc_i2c_isr(int irq, void *dev_id, struct pt_regs *regs)
static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
{ {
DECLARE_WAITQUEUE(wait, current);
unsigned long orig_jiffies = jiffies; unsigned long orig_jiffies = jiffies;
u32 x; u32 x;
int result = 0; int result = 0;
...@@ -92,28 +91,22 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) ...@@ -92,28 +91,22 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
x = readb(i2c->base + MPC_I2C_SR); x = readb(i2c->base + MPC_I2C_SR);
writeb(0, i2c->base + MPC_I2C_SR); writeb(0, i2c->base + MPC_I2C_SR);
} else { } else {
set_current_state(TASK_INTERRUPTIBLE); /* Interrupt mode */
add_wait_queue(&i2c->queue, &wait); result = wait_event_interruptible_timeout(i2c->queue,
while (!(i2c->interrupt & CSR_MIF)) { (i2c->interrupt & CSR_MIF), timeout * HZ);
if (signal_pending(current)) {
pr_debug("I2C: Interrupted\n"); if (unlikely(result < 0))
result = -EINTR; pr_debug("I2C: wait interrupted\n");
break; else if (unlikely(!(i2c->interrupt & CSR_MIF))) {
} pr_debug("I2C: wait timeout\n");
if (time_after(jiffies, orig_jiffies + timeout)) { result = -ETIMEDOUT;
pr_debug("I2C: timeout\n");
result = -EIO;
break;
}
msleep_interruptible(jiffies_to_msecs(timeout));
} }
set_current_state(TASK_RUNNING);
remove_wait_queue(&i2c->queue, &wait);
x = i2c->interrupt; x = i2c->interrupt;
i2c->interrupt = 0; i2c->interrupt = 0;
} }
if (result < -0) if (result < 0)
return result; return result;
if (!(x & CSR_MCF)) { if (!(x & CSR_MCF)) {
...@@ -165,7 +158,7 @@ static int mpc_write(struct mpc_i2c *i2c, int target, ...@@ -165,7 +158,7 @@ static int mpc_write(struct mpc_i2c *i2c, int target,
const u8 * data, int length, int restart) const u8 * data, int length, int restart)
{ {
int i; int i;
unsigned timeout = HZ; unsigned timeout = i2c->adap.timeout;
u32 flags = restart ? CCR_RSTA : 0; u32 flags = restart ? CCR_RSTA : 0;
/* Start with MEN */ /* Start with MEN */
...@@ -193,7 +186,7 @@ static int mpc_write(struct mpc_i2c *i2c, int target, ...@@ -193,7 +186,7 @@ static int mpc_write(struct mpc_i2c *i2c, int target,
static int mpc_read(struct mpc_i2c *i2c, int target, static int mpc_read(struct mpc_i2c *i2c, int target,
u8 * data, int length, int restart) u8 * data, int length, int restart)
{ {
unsigned timeout = HZ; unsigned timeout = i2c->adap.timeout;
int i; int i;
u32 flags = restart ? CCR_RSTA : 0; u32 flags = restart ? CCR_RSTA : 0;
...@@ -302,6 +295,7 @@ static int __devinit mpc_i2c_probe(struct ocp_device *ocp) ...@@ -302,6 +295,7 @@ static int __devinit mpc_i2c_probe(struct ocp_device *ocp)
if (!(i2c = kmalloc(sizeof(*i2c), GFP_KERNEL))) { if (!(i2c = kmalloc(sizeof(*i2c), GFP_KERNEL))) {
return -ENOMEM; return -ENOMEM;
} }
memset(i2c, 0, sizeof(*i2c));
i2c->ocpdef = ocp->def; i2c->ocpdef = ocp->def;
init_waitqueue_head(&i2c->queue); init_waitqueue_head(&i2c->queue);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment