Skip to content

Commit cc28e57

Browse files
Kewei Xuwsakernel
authored andcommitted
i2c: mediatek: Dump i2c/dma register when a timeout occurs
When a timeout error occurs in i2c transter, it is usually related to the i2c/dma IP hardware configuration. Therefore, the purpose of this patch is to dump the key register values of i2c/dma when a timeout occurs in i2c for debugging. Signed-off-by: Kewei Xu <[email protected]> Reviewed-by: Qii Wang <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent e3e4949 commit cc28e57

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

drivers/i2c/busses/i2c-mt65xx.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ enum I2C_REGS_OFFSET {
130130
OFFSET_HS,
131131
OFFSET_SOFTRESET,
132132
OFFSET_DCM_EN,
133+
OFFSET_MULTI_DMA,
133134
OFFSET_PATH_DIR,
134135
OFFSET_DEBUGSTAT,
135136
OFFSET_DEBUGCTRL,
@@ -197,6 +198,7 @@ static const u16 mt_i2c_regs_v2[] = {
197198
[OFFSET_TRANSFER_LEN_AUX] = 0x44,
198199
[OFFSET_CLOCK_DIV] = 0x48,
199200
[OFFSET_SOFTRESET] = 0x50,
201+
[OFFSET_MULTI_DMA] = 0x8c,
200202
[OFFSET_SCL_MIS_COMP_POINT] = 0x90,
201203
[OFFSET_DEBUGSTAT] = 0xe4,
202204
[OFFSET_DEBUGCTRL] = 0xe8,
@@ -845,6 +847,57 @@ static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk)
845847
return 0;
846848
}
847849

850+
static void i2c_dump_register(struct mtk_i2c *i2c)
851+
{
852+
dev_dbg(i2c->dev, "SLAVE_ADDR: 0x%x, INTR_MASK: 0x%x\n",
853+
mtk_i2c_readw(i2c, OFFSET_SLAVE_ADDR),
854+
mtk_i2c_readw(i2c, OFFSET_INTR_MASK));
855+
dev_dbg(i2c->dev, "INTR_STAT: 0x%x, CONTROL: 0x%x\n",
856+
mtk_i2c_readw(i2c, OFFSET_INTR_STAT),
857+
mtk_i2c_readw(i2c, OFFSET_CONTROL));
858+
dev_dbg(i2c->dev, "TRANSFER_LEN: 0x%x, TRANSAC_LEN: 0x%x\n",
859+
mtk_i2c_readw(i2c, OFFSET_TRANSFER_LEN),
860+
mtk_i2c_readw(i2c, OFFSET_TRANSAC_LEN));
861+
dev_dbg(i2c->dev, "DELAY_LEN: 0x%x, HTIMING: 0x%x\n",
862+
mtk_i2c_readw(i2c, OFFSET_DELAY_LEN),
863+
mtk_i2c_readw(i2c, OFFSET_TIMING));
864+
dev_dbg(i2c->dev, "START: 0x%x, EXT_CONF: 0x%x\n",
865+
mtk_i2c_readw(i2c, OFFSET_START),
866+
mtk_i2c_readw(i2c, OFFSET_EXT_CONF));
867+
dev_dbg(i2c->dev, "HS: 0x%x, IO_CONFIG: 0x%x\n",
868+
mtk_i2c_readw(i2c, OFFSET_HS),
869+
mtk_i2c_readw(i2c, OFFSET_IO_CONFIG));
870+
dev_dbg(i2c->dev, "DCM_EN: 0x%x, TRANSFER_LEN_AUX: 0x%x\n",
871+
mtk_i2c_readw(i2c, OFFSET_DCM_EN),
872+
mtk_i2c_readw(i2c, OFFSET_TRANSFER_LEN_AUX));
873+
dev_dbg(i2c->dev, "CLOCK_DIV: 0x%x, FIFO_STAT: 0x%x\n",
874+
mtk_i2c_readw(i2c, OFFSET_CLOCK_DIV),
875+
mtk_i2c_readw(i2c, OFFSET_FIFO_STAT));
876+
dev_dbg(i2c->dev, "DEBUGCTRL : 0x%x, DEBUGSTAT: 0x%x\n",
877+
mtk_i2c_readw(i2c, OFFSET_DEBUGCTRL),
878+
mtk_i2c_readw(i2c, OFFSET_DEBUGSTAT));
879+
if (i2c->dev_comp->regs == mt_i2c_regs_v2) {
880+
dev_dbg(i2c->dev, "LTIMING: 0x%x, MULTI_DMA: 0x%x\n",
881+
mtk_i2c_readw(i2c, OFFSET_LTIMING),
882+
mtk_i2c_readw(i2c, OFFSET_MULTI_DMA));
883+
}
884+
dev_dbg(i2c->dev, "\nDMA_INT_FLAG: 0x%x, DMA_INT_EN: 0x%x\n",
885+
readl(i2c->pdmabase + OFFSET_INT_FLAG),
886+
readl(i2c->pdmabase + OFFSET_INT_EN));
887+
dev_dbg(i2c->dev, "DMA_EN: 0x%x, DMA_CON: 0x%x\n",
888+
readl(i2c->pdmabase + OFFSET_EN),
889+
readl(i2c->pdmabase + OFFSET_CON));
890+
dev_dbg(i2c->dev, "DMA_TX_MEM_ADDR: 0x%x, DMA_RX_MEM_ADDR: 0x%x\n",
891+
readl(i2c->pdmabase + OFFSET_TX_MEM_ADDR),
892+
readl(i2c->pdmabase + OFFSET_RX_MEM_ADDR));
893+
dev_dbg(i2c->dev, "DMA_TX_LEN: 0x%x, DMA_RX_LEN: 0x%x\n",
894+
readl(i2c->pdmabase + OFFSET_TX_LEN),
895+
readl(i2c->pdmabase + OFFSET_RX_LEN));
896+
dev_dbg(i2c->dev, "DMA_TX_4G_MODE: 0x%x, DMA_RX_4G_MODE: 0x%x",
897+
readl(i2c->pdmabase + OFFSET_TX_4G_MODE),
898+
readl(i2c->pdmabase + OFFSET_RX_4G_MODE));
899+
}
900+
848901
static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
849902
int num, int left_num)
850903
{
@@ -1075,6 +1128,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
10751128

10761129
if (ret == 0) {
10771130
dev_dbg(i2c->dev, "addr: %x, transfer timeout\n", msgs->addr);
1131+
i2c_dump_register(i2c);
10781132
mtk_i2c_init_hw(i2c);
10791133
return -ETIMEDOUT;
10801134
}

0 commit comments

Comments
 (0)