@@ -28,8 +28,8 @@
#include <linux/jiffies.h>
/*
- * 'process_lock' exists because ocores_process() and ocores_process_timeout()
- * can't run in parallel.
+ * 'process_lock' serializes transfer startup with interrupt and timeout
+ * processing.
*/
struct ocores_i2c {
void __iomem *base;
@@ -148,27 +148,23 @@ static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg)
static void ocores_process(struct ocores_i2c *i2c, u8 stat)
{
- struct i2c_msg *msg = i2c->msg;
- unsigned long flags;
+ struct i2c_msg *msg;
- /*
- * If we spin here is because we are in timeout, so we are going
- * to be in STATE_ERROR. See ocores_process_timeout()
- */
- spin_lock_irqsave(&i2c->process_lock, flags);
+ lockdep_assert_held(&i2c->process_lock);
+ msg = i2c->msg;
if ((i2c->state == STATE_DONE) || (i2c->state == STATE_ERROR)) {
/* stop has been sent */
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_IACK);
wake_up(&i2c->wait);
- goto out;
+ return;
}
/* error? */
if (stat & OCI2C_STAT_ARBLOST) {
i2c->state = STATE_ERROR;
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP);
- goto out;
+ return;
}
if ((i2c->state == STATE_START) || (i2c->state == STATE_WRITE)) {
@@ -178,7 +174,7 @@ static void ocores_process(struct ocores_i2c *i2c, u8 stat)
if (stat & OCI2C_STAT_NACK) {
i2c->state = STATE_ERROR;
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP);
- goto out;
+ return;
}
} else {
msg->buf[i2c->pos++] = oc_getreg(i2c, OCI2C_DATA);
@@ -200,14 +196,14 @@ static void ocores_process(struct ocores_i2c *i2c, u8 stat)
oc_setreg(i2c, OCI2C_DATA, addr);
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
- goto out;
+ return;
}
i2c->state = (msg->flags & I2C_M_RD)
? STATE_READ : STATE_WRITE;
} else {
i2c->state = STATE_DONE;
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP);
- goto out;
+ return;
}
}
@@ -218,25 +214,31 @@ static void ocores_process(struct ocores_i2c *i2c, u8 stat)
oc_setreg(i2c, OCI2C_DATA, msg->buf[i2c->pos++]);
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_WRITE);
}
-
-out:
- spin_unlock_irqrestore(&i2c->process_lock, flags);
}
static irqreturn_t ocores_isr(int irq, void *dev_id)
{
struct ocores_i2c *i2c = dev_id;
- u8 stat = oc_getreg(i2c, OCI2C_STATUS);
+ unsigned long flags;
+ u8 stat;
+
+ spin_lock_irqsave(&i2c->process_lock, flags);
+ stat = oc_getreg(i2c, OCI2C_STATUS);
if (i2c->flags & OCORES_FLAG_BROKEN_IRQ) {
if ((stat & OCI2C_STAT_IF) && !(stat & OCI2C_STAT_BUSY))
- return IRQ_NONE;
+ goto out_none;
} else if (!(stat & OCI2C_STAT_IF)) {
- return IRQ_NONE;
+ goto out_none;
}
ocores_process(i2c, stat);
+ spin_unlock_irqrestore(&i2c->process_lock, flags);
return IRQ_HANDLED;
+
+out_none:
+ spin_unlock_irqrestore(&i2c->process_lock, flags);
+ return IRQ_NONE;
}
/**
@@ -356,8 +358,10 @@ static int ocores_xfer_core(struct ocores_i2c *i2c,
bool polling)
{
int ret = 0;
+ unsigned long flags;
u8 ctrl;
+ spin_lock_irqsave(&i2c->process_lock, flags);
ctrl = oc_getreg(i2c, OCI2C_CONTROL);
if (polling)
oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~OCI2C_CTRL_IEN);
@@ -371,6 +375,7 @@ static int ocores_xfer_core(struct ocores_i2c *i2c,
oc_setreg(i2c, OCI2C_DATA, i2c_8bit_addr_from_msg(i2c->msg));
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
+ spin_unlock_irqrestore(&i2c->process_lock, flags);
if (polling) {
ret = ocores_process_polling(i2c);