aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c7
-rw-r--r--drivers/i2c/busses/i2c-mt65xx.c8
-rw-r--r--drivers/i2c/busses/i2c-rcar.c15
-rw-r--r--drivers/i2c/busses/i2c-sis630.c4
-rw-r--r--drivers/i2c/busses/i2c-stm32f7.c2
-rw-r--r--drivers/i2c/i2c-core-base.c9
6 files changed, 29 insertions, 16 deletions
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index ead5e7de3e4d..416f89b8f881 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -86,7 +86,6 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
86 struct i2c_timings *t = &dev->timings; 86 struct i2c_timings *t = &dev->timings;
87 u32 ss_ht = 0, fp_ht = 0, hs_ht = 0, fs_ht = 0; 87 u32 ss_ht = 0, fp_ht = 0, hs_ht = 0, fs_ht = 0;
88 88
89 dev->adapter.nr = -1;
90 dev->tx_fifo_depth = 32; 89 dev->tx_fifo_depth = 32;
91 dev->rx_fifo_depth = 32; 90 dev->rx_fifo_depth = 32;
92 91
@@ -219,7 +218,7 @@ static void i2c_dw_configure_slave(struct dw_i2c_dev *dev)
219 dev->mode = DW_IC_SLAVE; 218 dev->mode = DW_IC_SLAVE;
220} 219}
221 220
222static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id) 221static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev)
223{ 222{
224 u32 param, tx_fifo_depth, rx_fifo_depth; 223 u32 param, tx_fifo_depth, rx_fifo_depth;
225 224
@@ -233,7 +232,6 @@ static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id)
233 if (!dev->tx_fifo_depth) { 232 if (!dev->tx_fifo_depth) {
234 dev->tx_fifo_depth = tx_fifo_depth; 233 dev->tx_fifo_depth = tx_fifo_depth;
235 dev->rx_fifo_depth = rx_fifo_depth; 234 dev->rx_fifo_depth = rx_fifo_depth;
236 dev->adapter.nr = id;
237 } else if (tx_fifo_depth >= 2) { 235 } else if (tx_fifo_depth >= 2) {
238 dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth, 236 dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth,
239 tx_fifo_depth); 237 tx_fifo_depth);
@@ -358,13 +356,14 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
358 div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000); 356 div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000);
359 } 357 }
360 358
361 dw_i2c_set_fifo_size(dev, pdev->id); 359 dw_i2c_set_fifo_size(dev);
362 360
363 adap = &dev->adapter; 361 adap = &dev->adapter;
364 adap->owner = THIS_MODULE; 362 adap->owner = THIS_MODULE;
365 adap->class = I2C_CLASS_DEPRECATED; 363 adap->class = I2C_CLASS_DEPRECATED;
366 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 364 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
367 adap->dev.of_node = pdev->dev.of_node; 365 adap->dev.of_node = pdev->dev.of_node;
366 adap->nr = -1;
368 367
369 dev_pm_set_driver_flags(&pdev->dev, 368 dev_pm_set_driver_flags(&pdev->dev,
370 DPM_FLAG_SMART_PREPARE | 369 DPM_FLAG_SMART_PREPARE |
diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 660de1ee68ed..684d651612b3 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -503,7 +503,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
503 writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG); 503 writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG);
504 writel(I2C_DMA_CON_RX, i2c->pdmabase + OFFSET_CON); 504 writel(I2C_DMA_CON_RX, i2c->pdmabase + OFFSET_CON);
505 505
506 dma_rd_buf = i2c_get_dma_safe_msg_buf(msgs, 0); 506 dma_rd_buf = i2c_get_dma_safe_msg_buf(msgs, 1);
507 if (!dma_rd_buf) 507 if (!dma_rd_buf)
508 return -ENOMEM; 508 return -ENOMEM;
509 509
@@ -526,7 +526,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
526 writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG); 526 writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG);
527 writel(I2C_DMA_CON_TX, i2c->pdmabase + OFFSET_CON); 527 writel(I2C_DMA_CON_TX, i2c->pdmabase + OFFSET_CON);
528 528
529 dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 0); 529 dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 1);
530 if (!dma_wr_buf) 530 if (!dma_wr_buf)
531 return -ENOMEM; 531 return -ENOMEM;
532 532
@@ -549,7 +549,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
549 writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_INT_FLAG); 549 writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_INT_FLAG);
550 writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_CON); 550 writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_CON);
551 551
552 dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 0); 552 dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 1);
553 if (!dma_wr_buf) 553 if (!dma_wr_buf)
554 return -ENOMEM; 554 return -ENOMEM;
555 555
@@ -561,7 +561,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
561 return -ENOMEM; 561 return -ENOMEM;
562 } 562 }
563 563
564 dma_rd_buf = i2c_get_dma_safe_msg_buf((msgs + 1), 0); 564 dma_rd_buf = i2c_get_dma_safe_msg_buf((msgs + 1), 1);
565 if (!dma_rd_buf) { 565 if (!dma_rd_buf) {
566 dma_unmap_single(i2c->dev, wpaddr, 566 dma_unmap_single(i2c->dev, wpaddr,
567 msgs->len, DMA_TO_DEVICE); 567 msgs->len, DMA_TO_DEVICE);
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index dd52a068b140..a7578f6da979 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -363,9 +363,6 @@ static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv)
363 struct dma_chan *chan = priv->dma_direction == DMA_FROM_DEVICE 363 struct dma_chan *chan = priv->dma_direction == DMA_FROM_DEVICE
364 ? priv->dma_rx : priv->dma_tx; 364 ? priv->dma_rx : priv->dma_tx;
365 365
366 /* Disable DMA Master Received/Transmitted */
367 rcar_i2c_write(priv, ICDMAER, 0);
368
369 dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg), 366 dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg),
370 sg_dma_len(&priv->sg), priv->dma_direction); 367 sg_dma_len(&priv->sg), priv->dma_direction);
371 368
@@ -375,6 +372,9 @@ static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv)
375 priv->flags |= ID_P_NO_RXDMA; 372 priv->flags |= ID_P_NO_RXDMA;
376 373
377 priv->dma_direction = DMA_NONE; 374 priv->dma_direction = DMA_NONE;
375
376 /* Disable DMA Master Received/Transmitted, must be last! */
377 rcar_i2c_write(priv, ICDMAER, 0);
378} 378}
379 379
380static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv) 380static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv)
@@ -611,6 +611,15 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)
611 return true; 611 return true;
612} 612}
613 613
614/*
615 * This driver has a lock-free design because there are IP cores (at least
616 * R-Car Gen2) which have an inherent race condition in their hardware design.
617 * There, we need to clear RCAR_BUS_MASK_DATA bits as soon as possible after
618 * the interrupt was generated, otherwise an unwanted repeated message gets
619 * generated. It turned out that taking a spinlock at the beginning of the ISR
620 * was already causing repeated messages. Thus, this driver was converted to
621 * the now lockless behaviour. Please keep this in mind when hacking the driver.
622 */
614static irqreturn_t rcar_i2c_irq(int irq, void *ptr) 623static irqreturn_t rcar_i2c_irq(int irq, void *ptr)
615{ 624{
616 struct rcar_i2c_priv *priv = ptr; 625 struct rcar_i2c_priv *priv = ptr;
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 1e6805b5cef2..a57aa4fe51a4 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -478,7 +478,7 @@ static int sis630_setup(struct pci_dev *sis630_dev)
478 if (!request_region(smbus_base + SMB_STS, SIS630_SMB_IOREGION, 478 if (!request_region(smbus_base + SMB_STS, SIS630_SMB_IOREGION,
479 sis630_driver.name)) { 479 sis630_driver.name)) {
480 dev_err(&sis630_dev->dev, 480 dev_err(&sis630_dev->dev,
481 "I/O Region 0x%04hx-0x%04hx for SMBus already in use.\n", 481 "I/O Region 0x%04x-0x%04x for SMBus already in use.\n",
482 smbus_base + SMB_STS, 482 smbus_base + SMB_STS,
483 smbus_base + SMB_STS + SIS630_SMB_IOREGION - 1); 483 smbus_base + SMB_STS + SIS630_SMB_IOREGION - 1);
484 retval = -EBUSY; 484 retval = -EBUSY;
@@ -528,7 +528,7 @@ static int sis630_probe(struct pci_dev *dev, const struct pci_device_id *id)
528 sis630_adapter.dev.parent = &dev->dev; 528 sis630_adapter.dev.parent = &dev->dev;
529 529
530 snprintf(sis630_adapter.name, sizeof(sis630_adapter.name), 530 snprintf(sis630_adapter.name, sizeof(sis630_adapter.name),
531 "SMBus SIS630 adapter at %04hx", smbus_base + SMB_STS); 531 "SMBus SIS630 adapter at %04x", smbus_base + SMB_STS);
532 532
533 return i2c_add_adapter(&sis630_adapter); 533 return i2c_add_adapter(&sis630_adapter);
534} 534}
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 13e1213561d4..4284fc991cfd 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -432,7 +432,7 @@ static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
432 STM32F7_I2C_ANALOG_FILTER_DELAY_MAX : 0); 432 STM32F7_I2C_ANALOG_FILTER_DELAY_MAX : 0);
433 dnf_delay = setup->dnf * i2cclk; 433 dnf_delay = setup->dnf * i2cclk;
434 434
435 sdadel_min = setup->fall_time - i2c_specs[setup->speed].hddat_min - 435 sdadel_min = i2c_specs[setup->speed].hddat_min + setup->fall_time -
436 af_delay_min - (setup->dnf + 3) * i2cclk; 436 af_delay_min - (setup->dnf + 3) * i2cclk;
437 437
438 sdadel_max = i2c_specs[setup->speed].vddat_max - setup->rise_time - 438 sdadel_max = i2c_specs[setup->speed].vddat_max - setup->rise_time -
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index cb6c5cb0df0b..38af18645133 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -2258,7 +2258,8 @@ EXPORT_SYMBOL(i2c_put_adapter);
2258/** 2258/**
2259 * i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg 2259 * i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg
2260 * @msg: the message to be checked 2260 * @msg: the message to be checked
2261 * @threshold: the minimum number of bytes for which using DMA makes sense 2261 * @threshold: the minimum number of bytes for which using DMA makes sense.
2262 * Should at least be 1.
2262 * 2263 *
2263 * Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO. 2264 * Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO.
2264 * Or a valid pointer to be used with DMA. After use, release it by 2265 * Or a valid pointer to be used with DMA. After use, release it by
@@ -2268,7 +2269,11 @@ EXPORT_SYMBOL(i2c_put_adapter);
2268 */ 2269 */
2269u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold) 2270u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
2270{ 2271{
2271 if (msg->len < threshold) 2272 /* also skip 0-length msgs for bogus thresholds of 0 */
2273 if (!threshold)
2274 pr_debug("DMA buffer for addr=0x%02x with length 0 is bogus\n",
2275 msg->addr);
2276 if (msg->len < threshold || msg->len == 0)
2272 return NULL; 2277 return NULL;
2273 2278
2274 if (msg->flags & I2C_M_DMA_SAFE) 2279 if (msg->flags & I2C_M_DMA_SAFE)