Commit 4dcaadc3 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-31-rc5/i2c-fixes' of git://git.fluff.org/bjdooks/linux

* 'for-31-rc5/i2c-fixes' of git://git.fluff.org/bjdooks/linux:
  i2c-tegra: fix possible race condition after tx
  i2c-tegra: add I2C_FUNC_SMBUS_EMUL
  i2c-tegra: Add of_match_table
  i2c-pxa2xx: return proper error code in ce4100_i2c_probe error paths
parents 4fbcc42d 96219c3a
...@@ -109,12 +109,15 @@ static int __devinit ce4100_i2c_probe(struct pci_dev *dev, ...@@ -109,12 +109,15 @@ static int __devinit ce4100_i2c_probe(struct pci_dev *dev,
return -EINVAL; return -EINVAL;
} }
sds = kzalloc(sizeof(*sds), GFP_KERNEL); sds = kzalloc(sizeof(*sds), GFP_KERNEL);
if (!sds) if (!sds) {
ret = -ENOMEM;
goto err_mem; goto err_mem;
}
for (i = 0; i < ARRAY_SIZE(sds->pdev); i++) { for (i = 0; i < ARRAY_SIZE(sds->pdev); i++) {
sds->pdev[i] = add_i2c_device(dev, i); sds->pdev[i] = add_i2c_device(dev, i);
if (IS_ERR(sds->pdev[i])) { if (IS_ERR(sds->pdev[i])) {
ret = PTR_ERR(sds->pdev[i]);
while (--i >= 0) while (--i >= 0)
platform_device_unregister(sds->pdev[i]); platform_device_unregister(sds->pdev[i]);
goto err_dev_add; goto err_dev_add;
......
...@@ -270,14 +270,30 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) ...@@ -270,14 +270,30 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
/* Rounds down to not include partial word at the end of buf */ /* Rounds down to not include partial word at the end of buf */
words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD;
if (words_to_transfer > tx_fifo_avail)
words_to_transfer = tx_fifo_avail;
i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); /* It's very common to have < 4 bytes, so optimize that case. */
if (words_to_transfer) {
buf += words_to_transfer * BYTES_PER_FIFO_WORD; if (words_to_transfer > tx_fifo_avail)
buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; words_to_transfer = tx_fifo_avail;
tx_fifo_avail -= words_to_transfer;
/*
* Update state before writing to FIFO. If this casues us
* to finish writing all bytes (AKA buf_remaining goes to 0) we
* have a potential for an interrupt (PACKET_XFER_COMPLETE is
* not maskable). We need to make sure that the isr sees
* buf_remaining as 0 and doesn't call us back re-entrantly.
*/
buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD;
tx_fifo_avail -= words_to_transfer;
i2c_dev->msg_buf_remaining = buf_remaining;
i2c_dev->msg_buf = buf +
words_to_transfer * BYTES_PER_FIFO_WORD;
barrier();
i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
buf += words_to_transfer * BYTES_PER_FIFO_WORD;
}
/* /*
* If there is a partial word at the end of buf, handle it manually to * If there is a partial word at the end of buf, handle it manually to
...@@ -287,14 +303,15 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) ...@@ -287,14 +303,15 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
if (tx_fifo_avail > 0 && buf_remaining > 0) { if (tx_fifo_avail > 0 && buf_remaining > 0) {
BUG_ON(buf_remaining > 3); BUG_ON(buf_remaining > 3);
memcpy(&val, buf, buf_remaining); memcpy(&val, buf, buf_remaining);
/* Again update before writing to FIFO to make sure isr sees. */
i2c_dev->msg_buf_remaining = 0;
i2c_dev->msg_buf = NULL;
barrier();
i2c_writel(i2c_dev, val, I2C_TX_FIFO); i2c_writel(i2c_dev, val, I2C_TX_FIFO);
buf_remaining = 0;
tx_fifo_avail--;
} }
BUG_ON(tx_fifo_avail > 0 && buf_remaining > 0);
i2c_dev->msg_buf_remaining = buf_remaining;
i2c_dev->msg_buf = buf;
return 0; return 0;
} }
...@@ -411,9 +428,10 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) ...@@ -411,9 +428,10 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
tegra_i2c_mask_irq(i2c_dev, I2C_INT_TX_FIFO_DATA_REQ); tegra_i2c_mask_irq(i2c_dev, I2C_INT_TX_FIFO_DATA_REQ);
} }
if ((status & I2C_INT_PACKET_XFER_COMPLETE) && if (status & I2C_INT_PACKET_XFER_COMPLETE) {
!i2c_dev->msg_buf_remaining) BUG_ON(i2c_dev->msg_buf_remaining);
complete(&i2c_dev->msg_complete); complete(&i2c_dev->msg_complete);
}
i2c_writel(i2c_dev, status, I2C_INT_STATUS); i2c_writel(i2c_dev, status, I2C_INT_STATUS);
if (i2c_dev->is_dvc) if (i2c_dev->is_dvc)
...@@ -531,7 +549,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], ...@@ -531,7 +549,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
static u32 tegra_i2c_func(struct i2c_adapter *adap) static u32 tegra_i2c_func(struct i2c_adapter *adap)
{ {
return I2C_FUNC_I2C; return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
} }
static const struct i2c_algorithm tegra_i2c_algo = { static const struct i2c_algorithm tegra_i2c_algo = {
...@@ -719,6 +737,17 @@ static int tegra_i2c_resume(struct platform_device *pdev) ...@@ -719,6 +737,17 @@ static int tegra_i2c_resume(struct platform_device *pdev)
} }
#endif #endif
#if defined(CONFIG_OF)
/* Match table for of_platform binding */
static const struct of_device_id tegra_i2c_of_match[] __devinitconst = {
{ .compatible = "nvidia,tegra20-i2c", },
{},
};
MODULE_DEVICE_TABLE(of, tegra_i2c_of_match);
#else
#define tegra_i2c_of_match NULL
#endif
static struct platform_driver tegra_i2c_driver = { static struct platform_driver tegra_i2c_driver = {
.probe = tegra_i2c_probe, .probe = tegra_i2c_probe,
.remove = tegra_i2c_remove, .remove = tegra_i2c_remove,
...@@ -729,6 +758,7 @@ static struct platform_driver tegra_i2c_driver = { ...@@ -729,6 +758,7 @@ static struct platform_driver tegra_i2c_driver = {
.driver = { .driver = {
.name = "tegra-i2c", .name = "tegra-i2c",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = tegra_i2c_of_match,
}, },
}; };
......
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