Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2390008pxb; Mon, 23 Aug 2021 20:32:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOiyhIBi6eTFpXwX4hbCj90adiS+kun+H/JpJpPcOIg5rCMKx9p9Z/NW4epTj8diHmMAfY X-Received: by 2002:a17:906:d0cd:: with SMTP id bq13mr18437779ejb.66.1629775948583; Mon, 23 Aug 2021 20:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629775948; cv=none; d=google.com; s=arc-20160816; b=O9a41DFgJ+1GLU4Tn5KPmGSR4mCBwbgcEkHyspGNVbQ5Zf3+oG6BS2WgwE4IK0f83Q 7rmw5jm0WaGm9xCJtcmMZ5IhKtmmgPf5nkz8jFFPAQAqa9vV2nSeE3CbpusbR+RsaXnE 0f1wsuov3lqotO8GSJVT/MRNP5LEklv/9J0drjANd4yD4ePqItjNqH+QNEL45tjhm0Ha QaX0Nubf5Y0P79ily5ORM9s01ezi+NnPrm3rSY70yoP8Z/A7QNPJMT9FYW00qyjZaW2Y LHqenKTZj+M6B3z+UrKIuI8fqrK9gmFu54dM5wS07ktYAFAlbo8fMfp6NgiYSTIO8zVN 2vXg== 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=asWmwYZ1Fo6mnzZOv4UYZWMbVfEx+oAUonnRurdMpTBdkGTTO5D2hnYpofvrnvPdjI 2YbOXIzsLyFpiC/ZJCIDCVG1LyxIBXdRLMDXBRQKy/5JFe3FiNtyinkwyFBi1aHmF0j7 2bVTm9xcImpQzbSZD90kNHAJB41P6HHJGXg1G4CYC0359YiogCQhEeyd19F8cOkj0kjh rVGM94LHizleyieR5dn2+SJVejY5crImDRMQnO8Jg8Vr273IzU2X6Ryrp/tuVt2qK9rY 6UU0vAwoV0Zn5kfPAKx/LlrBjcxh2OKjoshXb6eTF0sfjCXLakUhAs+PTfwZwaYvZ8xe SzNw== 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 gs11si7782614ejc.747.2021.08.23.20.32.05; Mon, 23 Aug 2021 20:32:28 -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 S234357AbhHXDb1 (ORCPT + 99 others); Mon, 23 Aug 2021 23:31:27 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:56084 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S233836AbhHXDbV (ORCPT ); Mon, 23 Aug 2021 23:31:21 -0400 X-UUID: 554b264281de49dfa053e439ccf25e91-20210824 X-UUID: 554b264281de49dfa053e439ccf25e91-20210824 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 923366344; Tue, 24 Aug 2021 11:30:35 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 24 Aug 2021 11:30:33 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 24 Aug 2021 11:30:33 +0800 From: Kewei Xu To: CC: , , , , , , , , , , , , , , Subject: [RESEND PATCH v5 2/7] i2c: mediatek: Reset the handshake signal between i2c and dma Date: Tue, 24 Aug 2021 11:30:23 +0800 Message-ID: <1629775828-19993-3-git-send-email-kewei.xu@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1629775828-19993-1-git-send-email-kewei.xu@mediatek.com> References: <1629775828-19993-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