diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-07-28 13:04:40 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-07-28 13:04:40 -0400 |
| commit | dd63bf22fccd68913e3088c5ed5de3bf406a7546 (patch) | |
| tree | d68bd4236e1b2d32fca95f76d3850f9c70c093e0 /drivers | |
| parent | eb181a814c98255b32d30b383baca00e6ebec72e (diff) | |
| parent | d2d0ad2aec4a8f3fd15e000ed903d6beddf39644 (diff) | |
Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang:
"Some driver bugfixes"
* 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
i2c: imx: use open drain for recovery GPIO
i2c: rcar: handle RXDMA HW behaviour on Gen3
i2c: imx: Fix reinit_completion() use
i2c: davinci: Avoid zero value of CLKH
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/i2c/busses/i2c-davinci.c | 8 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-imx.c | 5 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-rcar.c | 54 |
3 files changed, 59 insertions, 8 deletions
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 75d6ab177055..7379043711df 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c | |||
| @@ -237,12 +237,16 @@ static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev) | |||
| 237 | /* | 237 | /* |
| 238 | * It's not always possible to have 1 to 2 ratio when d=7, so fall back | 238 | * It's not always possible to have 1 to 2 ratio when d=7, so fall back |
| 239 | * to minimal possible clkh in this case. | 239 | * to minimal possible clkh in this case. |
| 240 | * | ||
| 241 | * Note: | ||
| 242 | * CLKH is not allowed to be 0, in this case I2C clock is not generated | ||
| 243 | * at all | ||
| 240 | */ | 244 | */ |
| 241 | if (clk >= clkl + d) { | 245 | if (clk > clkl + d) { |
| 242 | clkh = clk - clkl - d; | 246 | clkh = clk - clkl - d; |
| 243 | clkl -= d; | 247 | clkl -= d; |
| 244 | } else { | 248 | } else { |
| 245 | clkh = 0; | 249 | clkh = 1; |
| 246 | clkl = clk - (d << 1); | 250 | clkl = clk - (d << 1); |
| 247 | } | 251 | } |
| 248 | 252 | ||
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 0207e194f84b..498c5e891649 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c | |||
| @@ -368,6 +368,7 @@ static int i2c_imx_dma_xfer(struct imx_i2c_struct *i2c_imx, | |||
| 368 | goto err_desc; | 368 | goto err_desc; |
| 369 | } | 369 | } |
| 370 | 370 | ||
| 371 | reinit_completion(&dma->cmd_complete); | ||
| 371 | txdesc->callback = i2c_imx_dma_callback; | 372 | txdesc->callback = i2c_imx_dma_callback; |
| 372 | txdesc->callback_param = i2c_imx; | 373 | txdesc->callback_param = i2c_imx; |
| 373 | if (dma_submit_error(dmaengine_submit(txdesc))) { | 374 | if (dma_submit_error(dmaengine_submit(txdesc))) { |
| @@ -622,7 +623,6 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx, | |||
| 622 | * The first byte must be transmitted by the CPU. | 623 | * The first byte must be transmitted by the CPU. |
| 623 | */ | 624 | */ |
| 624 | imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); | 625 | imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); |
| 625 | reinit_completion(&i2c_imx->dma->cmd_complete); | ||
| 626 | time_left = wait_for_completion_timeout( | 626 | time_left = wait_for_completion_timeout( |
| 627 | &i2c_imx->dma->cmd_complete, | 627 | &i2c_imx->dma->cmd_complete, |
| 628 | msecs_to_jiffies(DMA_TIMEOUT)); | 628 | msecs_to_jiffies(DMA_TIMEOUT)); |
| @@ -681,7 +681,6 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, | |||
| 681 | if (result) | 681 | if (result) |
| 682 | return result; | 682 | return result; |
| 683 | 683 | ||
| 684 | reinit_completion(&i2c_imx->dma->cmd_complete); | ||
| 685 | time_left = wait_for_completion_timeout( | 684 | time_left = wait_for_completion_timeout( |
| 686 | &i2c_imx->dma->cmd_complete, | 685 | &i2c_imx->dma->cmd_complete, |
| 687 | msecs_to_jiffies(DMA_TIMEOUT)); | 686 | msecs_to_jiffies(DMA_TIMEOUT)); |
| @@ -1010,7 +1009,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, | |||
| 1010 | i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, | 1009 | i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, |
| 1011 | "gpio"); | 1010 | "gpio"); |
| 1012 | rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); | 1011 | rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); |
| 1013 | rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH); | 1012 | rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN); |
| 1014 | 1013 | ||
| 1015 | if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER || | 1014 | if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER || |
| 1016 | PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER) { | 1015 | PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER) { |
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 5e310efd9446..3c1c817f6968 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #include <linux/of_device.h> | 32 | #include <linux/of_device.h> |
| 33 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/pm_runtime.h> | 34 | #include <linux/pm_runtime.h> |
| 35 | #include <linux/reset.h> | ||
| 35 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
| 36 | 37 | ||
| 37 | /* register offsets */ | 38 | /* register offsets */ |
| @@ -111,8 +112,9 @@ | |||
| 111 | #define ID_ARBLOST (1 << 3) | 112 | #define ID_ARBLOST (1 << 3) |
| 112 | #define ID_NACK (1 << 4) | 113 | #define ID_NACK (1 << 4) |
| 113 | /* persistent flags */ | 114 | /* persistent flags */ |
| 115 | #define ID_P_NO_RXDMA (1 << 30) /* HW forbids RXDMA sometimes */ | ||
| 114 | #define ID_P_PM_BLOCKED (1 << 31) | 116 | #define ID_P_PM_BLOCKED (1 << 31) |
| 115 | #define ID_P_MASK ID_P_PM_BLOCKED | 117 | #define ID_P_MASK (ID_P_PM_BLOCKED | ID_P_NO_RXDMA) |
| 116 | 118 | ||
| 117 | enum rcar_i2c_type { | 119 | enum rcar_i2c_type { |
| 118 | I2C_RCAR_GEN1, | 120 | I2C_RCAR_GEN1, |
| @@ -141,6 +143,8 @@ struct rcar_i2c_priv { | |||
| 141 | struct dma_chan *dma_rx; | 143 | struct dma_chan *dma_rx; |
| 142 | struct scatterlist sg; | 144 | struct scatterlist sg; |
| 143 | enum dma_data_direction dma_direction; | 145 | enum dma_data_direction dma_direction; |
| 146 | |||
| 147 | struct reset_control *rstc; | ||
| 144 | }; | 148 | }; |
| 145 | 149 | ||
| 146 | #define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent) | 150 | #define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent) |
| @@ -370,6 +374,11 @@ static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv) | |||
| 370 | dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg), | 374 | dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg), |
| 371 | sg_dma_len(&priv->sg), priv->dma_direction); | 375 | sg_dma_len(&priv->sg), priv->dma_direction); |
| 372 | 376 | ||
| 377 | /* Gen3 can only do one RXDMA per transfer and we just completed it */ | ||
| 378 | if (priv->devtype == I2C_RCAR_GEN3 && | ||
| 379 | priv->dma_direction == DMA_FROM_DEVICE) | ||
| 380 | priv->flags |= ID_P_NO_RXDMA; | ||
| 381 | |||
| 373 | priv->dma_direction = DMA_NONE; | 382 | priv->dma_direction = DMA_NONE; |
| 374 | } | 383 | } |
| 375 | 384 | ||
| @@ -407,8 +416,9 @@ static void rcar_i2c_dma(struct rcar_i2c_priv *priv) | |||
| 407 | unsigned char *buf; | 416 | unsigned char *buf; |
| 408 | int len; | 417 | int len; |
| 409 | 418 | ||
| 410 | /* Do not use DMA if it's not available or for messages < 8 bytes */ | 419 | /* Do various checks to see if DMA is feasible at all */ |
| 411 | if (IS_ERR(chan) || msg->len < 8 || !(msg->flags & I2C_M_DMA_SAFE)) | 420 | if (IS_ERR(chan) || msg->len < 8 || !(msg->flags & I2C_M_DMA_SAFE) || |
| 421 | (read && priv->flags & ID_P_NO_RXDMA)) | ||
| 412 | return; | 422 | return; |
| 413 | 423 | ||
| 414 | if (read) { | 424 | if (read) { |
| @@ -739,6 +749,25 @@ static void rcar_i2c_release_dma(struct rcar_i2c_priv *priv) | |||
| 739 | } | 749 | } |
| 740 | } | 750 | } |
| 741 | 751 | ||
| 752 | /* I2C is a special case, we need to poll the status of a reset */ | ||
| 753 | static int rcar_i2c_do_reset(struct rcar_i2c_priv *priv) | ||
| 754 | { | ||
| 755 | int i, ret; | ||
| 756 | |||
| 757 | ret = reset_control_reset(priv->rstc); | ||
| 758 | if (ret) | ||
| 759 | return ret; | ||
| 760 | |||
| 761 | for (i = 0; i < LOOP_TIMEOUT; i++) { | ||
| 762 | ret = reset_control_status(priv->rstc); | ||
| 763 | if (ret == 0) | ||
| 764 | return 0; | ||
| 765 | udelay(1); | ||
| 766 | } | ||
| 767 | |||
| 768 | return -ETIMEDOUT; | ||
| 769 | } | ||
| 770 | |||
| 742 | static int rcar_i2c_master_xfer(struct i2c_adapter *adap, | 771 | static int rcar_i2c_master_xfer(struct i2c_adapter *adap, |
| 743 | struct i2c_msg *msgs, | 772 | struct i2c_msg *msgs, |
| 744 | int num) | 773 | int num) |
| @@ -750,6 +779,16 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap, | |||
| 750 | 779 | ||
| 751 | pm_runtime_get_sync(dev); | 780 | pm_runtime_get_sync(dev); |
| 752 | 781 | ||
| 782 | /* Gen3 needs a reset before allowing RXDMA once */ | ||
| 783 | if (priv->devtype == I2C_RCAR_GEN3) { | ||
| 784 | priv->flags |= ID_P_NO_RXDMA; | ||
| 785 | if (!IS_ERR(priv->rstc)) { | ||
| 786 | ret = rcar_i2c_do_reset(priv); | ||
| 787 | if (ret == 0) | ||
| 788 | priv->flags &= ~ID_P_NO_RXDMA; | ||
| 789 | } | ||
| 790 | } | ||
| 791 | |||
| 753 | rcar_i2c_init(priv); | 792 | rcar_i2c_init(priv); |
| 754 | 793 | ||
| 755 | ret = rcar_i2c_bus_barrier(priv); | 794 | ret = rcar_i2c_bus_barrier(priv); |
| @@ -920,6 +959,15 @@ static int rcar_i2c_probe(struct platform_device *pdev) | |||
| 920 | if (ret < 0) | 959 | if (ret < 0) |
| 921 | goto out_pm_put; | 960 | goto out_pm_put; |
| 922 | 961 | ||
| 962 | if (priv->devtype == I2C_RCAR_GEN3) { | ||
| 963 | priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); | ||
| 964 | if (!IS_ERR(priv->rstc)) { | ||
| 965 | ret = reset_control_status(priv->rstc); | ||
| 966 | if (ret < 0) | ||
| 967 | priv->rstc = ERR_PTR(-ENOTSUPP); | ||
| 968 | } | ||
| 969 | } | ||
| 970 | |||
| 923 | /* Stay always active when multi-master to keep arbitration working */ | 971 | /* Stay always active when multi-master to keep arbitration working */ |
| 924 | if (of_property_read_bool(dev->of_node, "multi-master")) | 972 | if (of_property_read_bool(dev->of_node, "multi-master")) |
| 925 | priv->flags |= ID_P_PM_BLOCKED; | 973 | priv->flags |= ID_P_PM_BLOCKED; |
