Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2077825pxb; Sat, 28 Aug 2021 03:53:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAKSgYwRXdWNqgCVY/OZu/4XmfUJCRdmSAS/HKCAXVJHCAKuxY4cJAbeyZ4vu3YSnDFC/1 X-Received: by 2002:a17:906:9241:: with SMTP id c1mr14777562ejx.125.1630148013991; Sat, 28 Aug 2021 03:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630148013; cv=none; d=google.com; s=arc-20160816; b=FSq2tZsBPEGHmes746d+h3//SzI8dBXt4XfgL9re1OJxv2Aw/Ab1kqiGh2HhHHc5v4 0viZAPjzeJg0oLxEfiE/SZYlb/IXINQi0C+wQrKjYf6y1jS4hEX8S8g12YyZOHAj7+lV oQSXyhNH0Mn4HYL1/N8mNSNCEDMvv7AMm+uR73M8FgXe30njU9kkT1egBHPiyIV89wu3 kwrIbK2ESNSvLnE+01jVG/R1oxRnJMn+/29xoCTe7ugh5Yge407MdW9EnyJqPI0Hr7LA S6CERD4HURogfPELjubgDDCYFue4anfLmNYGe1LAUdI8iwmse8kyWozSlmlYyyS5u3wu 6fgg== 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=WfZPJ46nyQpcIvlfmxSBsNWkXeK0ApOiCYr197AQGiU=; b=0A1sdsvWVeEmwLL05Kmdv4hzU0q7L7iNChYT5ptxvSfdMZpFE2P86gwERWrrf95+LQ QIpXjryHGRXILtILE2toSHQnpaVlvmwxKIeibN0GeJXOcBKXv2GAcn6mpDNSigoabEtu TI8EH1FP3JYFOdOIzX9xyy3vj6yBJhK8CD5KyE4JG9EfRoQsnqESs3caTLo2LYV3HtTn VCv118OKf7o7zvA0ogLcwm7l4aDGISQLZac24OMxR6aBuox8xRK5+5WYDPSe/nUMg1Zc JnPzao8pKjpAL3uOdmo/HnejQ9XLGzScc8iIMzKHXsqAJSwt5GUNdh+eBqSimfcrhU79 S4Pg== 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 dg17si7997964edb.308.2021.08.28.03.53.11; Sat, 28 Aug 2021 03:53:33 -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 S233983AbhH1KwY (ORCPT + 99 others); Sat, 28 Aug 2021 06:52:24 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:34318 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S233763AbhH1KwJ (ORCPT ); Sat, 28 Aug 2021 06:52:09 -0400 X-UUID: 8bc10a0750024c6fa5912d7948068cff-20210828 X-UUID: 8bc10a0750024c6fa5912d7948068cff-20210828 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1669177796; Sat, 28 Aug 2021 18:51:12 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Aug 2021 18:51:10 +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; Sat, 28 Aug 2021 18:51:09 +0800 From: Kewei Xu To: CC: , , , , , , , , , , , , , , Subject: [PATCH v6 2/7] i2c: mediatek: Reset the handshake signal between i2c and dma Date: Sat, 28 Aug 2021 18:50:54 +0800 Message-ID: <1630147859-17031-3-git-send-email-kewei.xu@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1630147859-17031-1-git-send-email-kewei.xu@mediatek.com> References: <1630147859-17031-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..7a1c538 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 && i2c->op != I2C_MASTER_WRRD && 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