Commit a676973e authored by Stephen Boyd's avatar Stephen Boyd Committed by Wolfram Sang

i2c: i2c-qcom-geni: Simplify irq handler

We don't need to use goto here, we can just collapse the if statement
and goto chain into multiple branches and then combine some duplicate
completion calls into one big if statement. Let's do it to clean up code
some more.
Signed-off-by: default avatarStephen Boyd <swboyd@chromium.org>
Reviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
Reviewed-by: default avatarAlok Chauhan <alokc@codeaurora.org>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent ef8d1639
...@@ -201,21 +201,23 @@ static void geni_i2c_err(struct geni_i2c_dev *gi2c, int err) ...@@ -201,21 +201,23 @@ static void geni_i2c_err(struct geni_i2c_dev *gi2c, int err)
static irqreturn_t geni_i2c_irq(int irq, void *dev) static irqreturn_t geni_i2c_irq(int irq, void *dev)
{ {
struct geni_i2c_dev *gi2c = dev; struct geni_i2c_dev *gi2c = dev;
int j; void __iomem *base = gi2c->se.base;
int j, p;
u32 m_stat; u32 m_stat;
u32 rx_st; u32 rx_st;
u32 dm_tx_st; u32 dm_tx_st;
u32 dm_rx_st; u32 dm_rx_st;
u32 dma; u32 dma;
u32 val;
struct i2c_msg *cur; struct i2c_msg *cur;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&gi2c->lock, flags); spin_lock_irqsave(&gi2c->lock, flags);
m_stat = readl_relaxed(gi2c->se.base + SE_GENI_M_IRQ_STATUS); m_stat = readl_relaxed(base + SE_GENI_M_IRQ_STATUS);
rx_st = readl_relaxed(gi2c->se.base + SE_GENI_RX_FIFO_STATUS); rx_st = readl_relaxed(base + SE_GENI_RX_FIFO_STATUS);
dm_tx_st = readl_relaxed(gi2c->se.base + SE_DMA_TX_IRQ_STAT); dm_tx_st = readl_relaxed(base + SE_DMA_TX_IRQ_STAT);
dm_rx_st = readl_relaxed(gi2c->se.base + SE_DMA_RX_IRQ_STAT); dm_rx_st = readl_relaxed(base + SE_DMA_RX_IRQ_STAT);
dma = readl_relaxed(gi2c->se.base + SE_GENI_DMA_MODE_EN); dma = readl_relaxed(base + SE_GENI_DMA_MODE_EN);
cur = gi2c->cur; cur = gi2c->cur;
if (!cur || if (!cur ||
...@@ -238,26 +240,17 @@ static irqreturn_t geni_i2c_irq(int irq, void *dev) ...@@ -238,26 +240,17 @@ static irqreturn_t geni_i2c_irq(int irq, void *dev)
/* Disable the TX Watermark interrupt to stop TX */ /* Disable the TX Watermark interrupt to stop TX */
if (!dma) if (!dma)
writel_relaxed(0, gi2c->se.base + writel_relaxed(0, base + SE_GENI_TX_WATERMARK_REG);
SE_GENI_TX_WATERMARK_REG); } else if (dma) {
goto irqret;
}
if (dma) {
dev_dbg(gi2c->se.dev, "i2c dma tx:0x%x, dma rx:0x%x\n", dev_dbg(gi2c->se.dev, "i2c dma tx:0x%x, dma rx:0x%x\n",
dm_tx_st, dm_rx_st); dm_tx_st, dm_rx_st);
goto irqret; } else if (cur->flags & I2C_M_RD &&
}
if (cur->flags & I2C_M_RD &&
m_stat & (M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN)) { m_stat & (M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN)) {
u32 rxcnt = rx_st & RX_FIFO_WC_MSK; u32 rxcnt = rx_st & RX_FIFO_WC_MSK;
for (j = 0; j < rxcnt; j++) { for (j = 0; j < rxcnt; j++) {
u32 val; p = 0;
int p = 0; val = readl_relaxed(base + SE_GENI_RX_FIFOn);
val = readl_relaxed(gi2c->se.base + SE_GENI_RX_FIFOn);
while (gi2c->cur_rd < cur->len && p < sizeof(val)) { while (gi2c->cur_rd < cur->len && p < sizeof(val)) {
cur->buf[gi2c->cur_rd++] = val & 0xff; cur->buf[gi2c->cur_rd++] = val & 0xff;
val >>= 8; val >>= 8;
...@@ -270,44 +263,39 @@ static irqreturn_t geni_i2c_irq(int irq, void *dev) ...@@ -270,44 +263,39 @@ static irqreturn_t geni_i2c_irq(int irq, void *dev)
m_stat & M_TX_FIFO_WATERMARK_EN) { m_stat & M_TX_FIFO_WATERMARK_EN) {
for (j = 0; j < gi2c->tx_wm; j++) { for (j = 0; j < gi2c->tx_wm; j++) {
u32 temp; u32 temp;
u32 val = 0;
int p = 0;
val = 0;
p = 0;
while (gi2c->cur_wr < cur->len && p < sizeof(val)) { while (gi2c->cur_wr < cur->len && p < sizeof(val)) {
temp = cur->buf[gi2c->cur_wr++]; temp = cur->buf[gi2c->cur_wr++];
val |= temp << (p * 8); val |= temp << (p * 8);
p++; p++;
} }
writel_relaxed(val, gi2c->se.base + SE_GENI_TX_FIFOn); writel_relaxed(val, base + SE_GENI_TX_FIFOn);
/* TX Complete, Disable the TX Watermark interrupt */ /* TX Complete, Disable the TX Watermark interrupt */
if (gi2c->cur_wr == cur->len) { if (gi2c->cur_wr == cur->len) {
writel_relaxed(0, gi2c->se.base + writel_relaxed(0, base + SE_GENI_TX_WATERMARK_REG);
SE_GENI_TX_WATERMARK_REG);
break; break;
} }
} }
} }
irqret:
if (m_stat) if (m_stat)
writel_relaxed(m_stat, gi2c->se.base + SE_GENI_M_IRQ_CLEAR); writel_relaxed(m_stat, base + SE_GENI_M_IRQ_CLEAR);
if (dma && dm_tx_st)
writel_relaxed(dm_tx_st, base + SE_DMA_TX_IRQ_CLR);
if (dma && dm_rx_st)
writel_relaxed(dm_rx_st, base + SE_DMA_RX_IRQ_CLR);
if (dma) {
if (dm_tx_st)
writel_relaxed(dm_tx_st, gi2c->se.base +
SE_DMA_TX_IRQ_CLR);
if (dm_rx_st)
writel_relaxed(dm_rx_st, gi2c->se.base +
SE_DMA_RX_IRQ_CLR);
}
/* if this is err with done-bit not set, handle that through timeout. */ /* if this is err with done-bit not set, handle that through timeout. */
if (m_stat & M_CMD_DONE_EN || m_stat & M_CMD_ABORT_EN) if (m_stat & M_CMD_DONE_EN || m_stat & M_CMD_ABORT_EN ||
complete(&gi2c->done); dm_tx_st & TX_DMA_DONE || dm_tx_st & TX_RESET_DONE ||
else if (dm_tx_st & TX_DMA_DONE || dm_tx_st & TX_RESET_DONE) dm_rx_st & RX_DMA_DONE || dm_rx_st & RX_RESET_DONE)
complete(&gi2c->done);
else if (dm_rx_st & RX_DMA_DONE || dm_rx_st & RX_RESET_DONE)
complete(&gi2c->done); complete(&gi2c->done);
spin_unlock_irqrestore(&gi2c->lock, flags); spin_unlock_irqrestore(&gi2c->lock, flags);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
......
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