Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1843769pxb; Mon, 23 Aug 2021 06:07:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5tac9fqw8sSCKXhRbmnuHrAH+j8GuN8vUTfYhUYJ27D4Bdi/mYUl8T0fNomuZ7ON/0ZWI X-Received: by 2002:a2e:a274:: with SMTP id k20mr27796549ljm.370.1629724070916; Mon, 23 Aug 2021 06:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629724070; cv=none; d=google.com; s=arc-20160816; b=P4IbllurT4bjkXvhjCtCO2wI0Sg3reX5+yVCL2QIk4jv/6uGTmDzLR0FTSwBXFscEQ QjZXK3r1l5fSAyicvwl92GTLyIIgv5f9fCdtbglxPls6ill32jgdBgPQB42P0/MsP0Po iTJXzekZ0XZZoD6v1tCI33ACBqNIn01+BUkS6ZPD5fgL5gcQ92k/fdhq/vEHWBW94ipG v0UqecHHtKE7M9mj3Hsj250qO91gQLMwGu3cJ2u21huAb7BX4Qoft/VE4s+aiaoRvleu dWJIj6UcMxG4nJ9qr7EBWxyNWDEsoyl6kQ0DRXaf33HdWMnIplOpodo3YKQ97jKT7bYh yV7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=3OJQYYzWWlrlDYAjOc2lh0eMFat0ENxL+kymn7pYWwc=; b=UDfvb+tGedzh7Oc5nRhN9491c/Wes1yBU4DFrA6cxwUmT8rHupgCb/fABWH7HwfGYG ZJj7+YsmbzHpp7ksdYhkLDZmIY5ExaPe9M2cW0DcNPcvPLygPVrOrdHRyQ3u21H56JzJ J1Yg+R7UpWeD4HmMYJMkx7V4TYYaJpkWb1S5crSSTXG6Dlq3FX1ZayCDN8b1PmRcl2o1 WwnUXy2kz3vJzKOFr2JCzPXQGAJtZ6QUYInMpFCWVA91juSHV8mW/9FmC8qSWXYszvGJ PvPq2d4i7gzAXrz82K23tK3dGPA8wjm2ubfIo1Jk9pdqUgRZQxNRBd6c9fIj+oRCr/6t 5YGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si14255202eds.128.2021.08.23.06.07.22; Mon, 23 Aug 2021 06:07:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237292AbhHWNGc (ORCPT + 99 others); Mon, 23 Aug 2021 09:06:32 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53818 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S237164AbhHWNGb (ORCPT ); Mon, 23 Aug 2021 09:06:31 -0400 X-UUID: 113cba8d4ec64a4ba5f8e2a8d3c28c7a-20210823 X-UUID: 113cba8d4ec64a4ba5f8e2a8d3c28c7a-20210823 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 896504563; Mon, 23 Aug 2021 21:05:44 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Aug 2021 21:05:42 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 23 Aug 2021 21:05:41 +0800 From: Kewei Xu To: CC: , , , , , , , , , , , , , , Subject: [PATCH 2/7] i2c: mediatek: Reset the handshake signal between i2c and dma Date: Mon, 23 Aug 2021 21:05:32 +0800 Message-ID: <1629723937-10839-3-git-send-email-kewei.xu@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1629723937-10839-1-git-send-email-kewei.xu@mediatek.com> References: <1629723937-10839-1-git-send-email-kewei.xu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Due to changes in the hardware design of the handshaking signal between i2c and dma, it is necessary to reset the handshaking signal before each transfer to ensure that the multi-msgs can be transferred correctly. Signed-off-by: Kewei Xu --- drivers/i2c/busses/i2c-mt65xx.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c index 2661ed0..abda525 100644 --- a/drivers/i2c/busses/i2c-mt65xx.c +++ b/drivers/i2c/busses/i2c-mt65xx.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,9 @@ #define I2C_RD_TRANAC_VALUE 0x0001 #define I2C_SCL_MIS_COMP_VALUE 0x0000 #define I2C_CHN_CLR_FLAG 0x0000 +#define I2C_CLR_DEBUGCTR 0x0000 +#define I2C_RELIABILITY 0x0010 +#define I2C_DMAACK_ENABLE 0x0008 #define I2C_DMA_CON_TX 0x0000 #define I2C_DMA_CON_RX 0x0001 @@ -842,6 +846,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, u16 restart_flag = 0; u16 dma_sync = 0; u32 reg_4g_mode; + u32 reg_dma_reset; u8 *dma_rd_buf = NULL; u8 *dma_wr_buf = NULL; dma_addr_t rpaddr = 0; @@ -855,6 +860,27 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, reinit_completion(&i2c->msg_complete); + if (i2c->dev_comp->apdma_sync && left_num > 1) { + mtk_i2c_writew(i2c, I2C_CLR_DEBUGCTR, OFFSET_DEBUGCTRL); + writel(I2C_DMA_HANDSHAKE_RST | I2C_DMA_WARM_RST, + i2c->pdmabase + OFFSET_RST); + + ret = readw_poll_timeout(i2c->pdmabase + OFFSET_RST, + reg_dma_reset, + !(reg_dma_reset & I2C_DMA_WARM_RST), + 0, 100); + if (ret) { + dev_err(i2c->dev, "DMA warm reset timeout\n"); + return -ETIMEDOUT; + } + + writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_RST); + mtk_i2c_writew(i2c, I2C_HANDSHAKE_RST, OFFSET_SOFTRESET); + mtk_i2c_writew(i2c, I2C_CHN_CLR_FLAG, OFFSET_SOFTRESET); + mtk_i2c_writew(i2c, I2C_RELIABILITY | I2C_DMAACK_ENABLE, + OFFSET_DEBUGCTRL); + } + control_reg = mtk_i2c_readw(i2c, OFFSET_CONTROL) & ~(I2C_CONTROL_DIR_CHANGE | I2C_CONTROL_RS); if ((i2c->speed_hz > I2C_MAX_FAST_MODE_PLUS_FREQ) || (left_num >= 1)) -- 1.9.1