aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhishek Sahu <absahu@codeaurora.org>2018-03-12 09:14:58 -0400
committerWolfram Sang <wsa@the-dreams.de>2018-03-24 08:20:20 -0400
commitecb6e1e5f4352055a5761b945a833a925d51bf8d (patch)
tree2756f6072ba0e8c76e47dce06bf9077abfa66dbe
parent08f15963bc751bc818294c0f75a9aaca299c4052 (diff)
i2c: qup: change completion timeout according to transfer length
Currently the completion timeout is being taken according to maximum transfer length which is too high if SCL is operating in high frequency. This patch calculates timeout on the basis of one-byte transfer time and uses the same for completion timeout. Signed-off-by: Abhishek Sahu <absahu@codeaurora.org> Reviewed-by: Andy Gross <andy.gross@linaro.org> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/busses/i2c-qup.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c
index bf1b7eec8a4c..13c751e2dd9a 100644
--- a/drivers/i2c/busses/i2c-qup.c
+++ b/drivers/i2c/busses/i2c-qup.c
@@ -121,8 +121,12 @@
121#define MX_TX_RX_LEN SZ_64K 121#define MX_TX_RX_LEN SZ_64K
122#define MX_BLOCKS (MX_TX_RX_LEN / QUP_READ_LIMIT) 122#define MX_BLOCKS (MX_TX_RX_LEN / QUP_READ_LIMIT)
123 123
124/* Max timeout in ms for 32k bytes */ 124/*
125#define TOUT_MAX 300 125 * Minimum transfer timeout for i2c transfers in seconds. It will be added on
126 * the top of maximum transfer time calculated from i2c bus speed to compensate
127 * the overheads.
128 */
129#define TOUT_MIN 2
126 130
127/* Default values. Use these if FW query fails */ 131/* Default values. Use these if FW query fails */
128#define DEFAULT_CLK_FREQ 100000 132#define DEFAULT_CLK_FREQ 100000
@@ -163,6 +167,7 @@ struct qup_i2c_dev {
163 int in_blk_sz; 167 int in_blk_sz;
164 168
165 unsigned long one_byte_t; 169 unsigned long one_byte_t;
170 unsigned long xfer_timeout;
166 struct qup_i2c_block blk; 171 struct qup_i2c_block blk;
167 172
168 struct i2c_msg *msg; 173 struct i2c_msg *msg;
@@ -849,7 +854,7 @@ static int qup_i2c_bam_do_xfer(struct qup_i2c_dev *qup, struct i2c_msg *msg,
849 dma_async_issue_pending(qup->brx.dma); 854 dma_async_issue_pending(qup->brx.dma);
850 } 855 }
851 856
852 if (!wait_for_completion_timeout(&qup->xfer, TOUT_MAX * HZ)) { 857 if (!wait_for_completion_timeout(&qup->xfer, qup->xfer_timeout)) {
853 dev_err(qup->dev, "normal trans timed out\n"); 858 dev_err(qup->dev, "normal trans timed out\n");
854 ret = -ETIMEDOUT; 859 ret = -ETIMEDOUT;
855 } 860 }
@@ -1605,6 +1610,8 @@ nodma:
1605 */ 1610 */
1606 one_bit_t = (USEC_PER_SEC / clk_freq) + 1; 1611 one_bit_t = (USEC_PER_SEC / clk_freq) + 1;
1607 qup->one_byte_t = one_bit_t * 9; 1612 qup->one_byte_t = one_bit_t * 9;
1613 qup->xfer_timeout = TOUT_MIN * HZ +
1614 usecs_to_jiffies(MX_TX_RX_LEN * qup->one_byte_t);
1608 1615
1609 dev_dbg(qup->dev, "IN:block:%d, fifo:%d, OUT:block:%d, fifo:%d\n", 1616 dev_dbg(qup->dev, "IN:block:%d, fifo:%d, OUT:block:%d, fifo:%d\n",
1610 qup->in_blk_sz, qup->in_fifo_sz, 1617 qup->in_blk_sz, qup->in_fifo_sz,