Commit 3796e048 authored by Tony Lindgren's avatar Tony Lindgren

I2C: Clean-up i2c-omap

Clean-up i2c-omap
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
parent c434c15d
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
* Additional contributions by: * Additional contributions by:
* Tony Lindgren <tony@atomide.com> * Tony Lindgren <tony@atomide.com>
* Imre Deak <imre.deak@nokia.com> * Imre Deak <imre.deak@nokia.com>
* Juha Yrjl <juha.yrjola@nokia.com> * Juha Yrjölä <juha.yrjola@solidboot.com>
* Syed Khasim <x0khasim@ti.com> * Syed Khasim <x0khasim@ti.com>
* Nishant Menon <nm@ti.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -35,8 +36,7 @@ ...@@ -35,8 +36,7 @@
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/io.h>
#include <asm/io.h>
/* Hack to enable zero length transfers and smbus quick until clean fix /* Hack to enable zero length transfers and smbus quick until clean fix
is available */ is available */
...@@ -64,8 +64,8 @@ ...@@ -64,8 +64,8 @@
#define OMAP_I2C_BUFSTAT_REG 0x40 #define OMAP_I2C_BUFSTAT_REG 0x40
/* I2C Interrupt Enable Register (OMAP_I2C_IE): */ /* I2C Interrupt Enable Register (OMAP_I2C_IE): */
#define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer draining int enable */ #define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer drain int enable */
#define OMAP_I2C_IE_RDR (1 << 13) /* RX Buffer draining int enable */ #define OMAP_I2C_IE_RDR (1 << 13) /* RX Buffer drain int enable */
#define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */ #define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */
#define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */ #define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */
#define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */ #define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */
...@@ -221,7 +221,7 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev) ...@@ -221,7 +221,7 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev)
dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0);
if (dev->rev1) if (dev->rev1)
iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */
else else
omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate); omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate);
/* /*
...@@ -439,18 +439,24 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap, ...@@ -439,18 +439,24 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
/*
* Don't write stt and stp together on some hardware
*/
if (dev->b_hw && stop) { if (dev->b_hw && stop) {
unsigned long delay = jiffies + OMAP_I2C_TIMEOUT; unsigned long delay = jiffies + OMAP_I2C_TIMEOUT;
u16 con = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
while (con & OMAP_I2C_CON_STT) {
con = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
/* H/w behavior: dont write stt and stp together.. */
while (omap_i2c_read_reg(dev, OMAP_I2C_CON_REG) & OMAP_I2C_CON_STT) {
/* Let the user know if i2c is in a bad state */ /* Let the user know if i2c is in a bad state */
if (time_after (jiffies, delay)) { if (time_after(jiffies, delay)) {
dev_err(dev->dev, "controller timed out " dev_err(dev->dev, "controller timed out "
"waiting for start condition to finish\n"); "waiting for start condition to finish\n");
return -ETIMEDOUT; return -ETIMEDOUT;
} }
cpu_relax();
} }
w |= OMAP_I2C_CON_STP; w |= OMAP_I2C_CON_STP;
w &= ~OMAP_I2C_CON_STT; w &= ~OMAP_I2C_CON_STT;
omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
...@@ -503,7 +509,8 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) ...@@ -503,7 +509,8 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
omap_i2c_unidle(dev); omap_i2c_unidle(dev);
if ((r = omap_i2c_wait_for_bb(dev)) < 0) r = omap_i2c_wait_for_bb(dev);
if (r < 0)
goto out; goto out;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
...@@ -640,8 +647,11 @@ omap_i2c_isr(int this_irq, void *dev_id) ...@@ -640,8 +647,11 @@ omap_i2c_isr(int this_irq, void *dev_id)
if (stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)) { if (stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)) {
u8 num_bytes = 1; u8 num_bytes = 1;
if (dev->fifo_size) { if (dev->fifo_size) {
num_bytes = (stat & OMAP_I2C_STAT_RRDY) ? dev->fifo_size : if (stat & OMAP_I2C_STAT_RRDY)
omap_i2c_read_reg(dev, OMAP_I2C_BUFSTAT_REG); num_bytes = dev->fifo_size;
else
num_bytes = omap_i2c_read_reg(dev,
OMAP_I2C_BUFSTAT_REG);
} }
while (num_bytes) { while (num_bytes) {
num_bytes--; num_bytes--;
...@@ -659,22 +669,28 @@ omap_i2c_isr(int this_irq, void *dev_id) ...@@ -659,22 +669,28 @@ omap_i2c_isr(int this_irq, void *dev_id)
} }
} else { } else {
if (stat & OMAP_I2C_STAT_RRDY) if (stat & OMAP_I2C_STAT_RRDY)
dev_err(dev->dev, "RRDY IRQ while no data " dev_err(dev->dev,
"requested\n"); "RRDY IRQ while no data"
" requested\n");
if (stat & OMAP_I2C_STAT_RDR) if (stat & OMAP_I2C_STAT_RDR)
dev_err(dev->dev, "RDR IRQ while no data " dev_err(dev->dev,
"requested\n"); "RDR IRQ while no data"
" requested\n");
break; break;
} }
} }
omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)); omap_i2c_ack_stat(dev,
stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR));
continue; continue;
} }
if (stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)) { if (stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)) {
u8 num_bytes = 1; u8 num_bytes = 1;
if (dev->fifo_size) { if (dev->fifo_size) {
num_bytes = (stat & OMAP_I2C_STAT_XRDY) ? dev->fifo_size : if (stat & OMAP_I2C_STAT_XRDY)
omap_i2c_read_reg(dev, OMAP_I2C_BUFSTAT_REG); num_bytes = dev->fifo_size;
else
num_bytes = omap_i2c_read_reg(dev,
OMAP_I2C_BUFSTAT_REG);
} }
while (num_bytes) { while (num_bytes) {
num_bytes--; num_bytes--;
...@@ -692,16 +708,19 @@ omap_i2c_isr(int this_irq, void *dev_id) ...@@ -692,16 +708,19 @@ omap_i2c_isr(int this_irq, void *dev_id)
} }
} else { } else {
if (stat & OMAP_I2C_STAT_XRDY) if (stat & OMAP_I2C_STAT_XRDY)
dev_err(dev->dev, "XRDY IRQ while no " dev_err(dev->dev,
"data to send\n"); "XRDY IRQ while no "
"data to send\n");
if (stat & OMAP_I2C_STAT_XDR) if (stat & OMAP_I2C_STAT_XDR)
dev_err(dev->dev, "XDR IRQ while no " dev_err(dev->dev,
"data to send\n"); "XDR IRQ while no "
"data to send\n");
break; break;
} }
omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
} }
omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)); omap_i2c_ack_stat(dev,
stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
continue; continue;
} }
if (stat & OMAP_I2C_STAT_ROVR) { if (stat & OMAP_I2C_STAT_ROVR) {
...@@ -772,7 +791,8 @@ omap_i2c_probe(struct platform_device *pdev) ...@@ -772,7 +791,8 @@ omap_i2c_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dev); platform_set_drvdata(pdev, dev);
if ((r = omap_i2c_get_clocks(dev)) != 0) r = omap_i2c_get_clocks(dev);
if (r != 0)
goto err_iounmap; goto err_iounmap;
omap_i2c_unidle(dev); omap_i2c_unidle(dev);
...@@ -781,13 +801,16 @@ omap_i2c_probe(struct platform_device *pdev) ...@@ -781,13 +801,16 @@ omap_i2c_probe(struct platform_device *pdev)
dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20; dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20;
if (cpu_is_omap2430() || cpu_is_omap34xx()) { if (cpu_is_omap2430() || cpu_is_omap34xx()) {
u16 s;
/* Set up the fifo size - Get total size */ /* Set up the fifo size - Get total size */
dev->fifo_size = 0x8 << s = (omap_i2c_read_reg(dev, OMAP_I2C_BUFSTAT_REG) >> 14) & 0x3;
((omap_i2c_read_reg(dev, OMAP_I2C_BUFSTAT_REG) >> 14) & 0x3); dev->fifo_size = 0x8 << s;
/* /*
* Set up notification threshold as half the total available size * Set up notification threshold as half the total available
* This is to ensure that we can handle the status on int call back * size. This is to ensure that we can handle the status on int
* latencies * call back latencies.
*/ */
dev->fifo_size = (dev->fifo_size / 2); dev->fifo_size = (dev->fifo_size / 2);
dev->b_hw = 1; /* Enable hardware fixes */ dev->b_hw = 1; /* Enable hardware fixes */
......
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