Commit 1cd51cca authored by Troy Kisky's avatar Troy Kisky Committed by Kevin Hilman

I2C: ARM: DaVinci: Changes to match mainline

Spacing changes and simplify terminate_read.
No longer check buffer pointer for NULL, only buf_len.
Signed-off-by: default avatarTroy Kisky <troy.kisky@boundarydevices.com>
Signed-off-by: default avatarKevin Hilman <khilman@deeprootsystems.com>
parent cf21f43a
...@@ -179,10 +179,10 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev) ...@@ -179,10 +179,10 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev)
psc = (input_clock / 7000000) - 1; psc = (input_clock / 7000000) - 1;
if ((input_clock / (psc + 1)) > 12000000) if ((input_clock / (psc + 1)) > 12000000)
psc++; /* better to run under spec than over */ psc++; /* better to run under spec than over */
d = (psc >= 2)? 5 : 7 - psc; d = (psc >= 2) ? 5 : 7 - psc;
clk = ((input_clock / (psc + 1)) / (pdata->bus_freq * 1000)) - (d<<1); clk = ((input_clock / (psc + 1)) / (pdata->bus_freq * 1000)) - (d << 1);
clkh = clk>>1; clkh = clk >> 1;
clkl = clk - clkh; clkl = clk - clkh;
davinci_i2c_write_reg(dev, DAVINCI_I2C_PSC_REG, psc); davinci_i2c_write_reg(dev, DAVINCI_I2C_PSC_REG, psc);
...@@ -307,11 +307,14 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) ...@@ -307,11 +307,14 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
if (r == 0) { if (r == 0) {
dev_err(dev->dev, "controller timed out\n"); dev_err(dev->dev, "controller timed out\n");
i2c_davinci_init(dev); i2c_davinci_init(dev);
dev->buf = NULL; dev->buf_len = 0;
return -ETIMEDOUT; return -ETIMEDOUT;
} }
if (dev->buf_len) { if (dev->buf_len) {
/* signal may have aborted the transfer */ /* This should be 0 if all bytes were transferred
* or dev->cmd_err denotes an error.
* A signal may have aborted the transfer.
*/
if (r >= 0) { if (r >= 0) {
dev_err(dev->dev, "abnormal termination buf_len=%i\n", dev_err(dev->dev, "abnormal termination buf_len=%i\n",
dev->buf_len); dev->buf_len);
...@@ -319,7 +322,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) ...@@ -319,7 +322,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
} }
dev->terminate = 1; dev->terminate = 1;
wmb(); wmb();
dev->buf = NULL; dev->buf_len = 0;
} }
if (r < 0) if (r < 0)
return r; return r;
...@@ -362,7 +365,8 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) ...@@ -362,7 +365,8 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
ret = i2c_davinci_xfer_msg(adap, &msgs[i], (i == (num - 1))); ret = i2c_davinci_xfer_msg(adap, &msgs[i], (i == (num - 1)));
dev_dbg(dev->dev, "%s ret: %d\n", __func__, ret); dev_dbg(dev->dev, "%s [%d/%d] ret: %d\n", __func__, i + 1, num,
ret);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -374,24 +378,21 @@ static u32 i2c_davinci_func(struct i2c_adapter *adap) ...@@ -374,24 +378,21 @@ static u32 i2c_davinci_func(struct i2c_adapter *adap)
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
} }
static inline void terminate_read(struct davinci_i2c_dev *dev) static void terminate_read(struct davinci_i2c_dev *dev)
{ {
if (dev->buf_len) u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
dev->buf_len--; w |= DAVINCI_I2C_MDR_NACK;
if (dev->buf_len) { davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
w |= DAVINCI_I2C_MDR_NACK;
davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
}
/* Throw away data */ /* Throw away data */
davinci_i2c_read_reg(dev, DAVINCI_I2C_DRR_REG); davinci_i2c_read_reg(dev, DAVINCI_I2C_DRR_REG);
if (!dev->terminate) if (!dev->terminate)
dev_err(dev->dev, "RDR IRQ while no data requested\n"); dev_err(dev->dev, "RDR IRQ while no data requested\n");
} }
static inline void terminate_write(struct davinci_i2c_dev *dev) static void terminate_write(struct davinci_i2c_dev *dev)
{ {
u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
w |= DAVINCI_I2C_MDR_RM|DAVINCI_I2C_MDR_STP; w |= DAVINCI_I2C_MDR_RM | DAVINCI_I2C_MDR_STP;
davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
if (!dev->terminate) if (!dev->terminate)
...@@ -445,7 +446,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id) ...@@ -445,7 +446,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
break; break;
case DAVINCI_I2C_IVR_RDR: case DAVINCI_I2C_IVR_RDR:
if (dev->buf && dev->buf_len) { if (dev->buf_len) {
*dev->buf++ = *dev->buf++ =
davinci_i2c_read_reg(dev, davinci_i2c_read_reg(dev,
DAVINCI_I2C_DRR_REG); DAVINCI_I2C_DRR_REG);
...@@ -463,7 +464,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id) ...@@ -463,7 +464,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
break; break;
case DAVINCI_I2C_IVR_XRDY: case DAVINCI_I2C_IVR_XRDY:
if (dev->buf && dev->buf_len) { if (dev->buf_len) {
davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG,
*dev->buf++); *dev->buf++);
dev->buf_len--; dev->buf_len--;
......
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