Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp379047pxb; Sun, 10 Oct 2021 00:06:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzKKNrD3SSetxJOaBNOwTm/VHB0/NyEvD5OCuZr2NnRj0hMGS7elD60u1u1ymJTNwApm7Y X-Received: by 2002:a17:902:e5cb:b0:13f:25b7:4d50 with SMTP id u11-20020a170902e5cb00b0013f25b74d50mr5387596plf.38.1633849590935; Sun, 10 Oct 2021 00:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633849590; cv=none; d=google.com; s=arc-20160816; b=slLyaKVPkS5/Mw/DpvUglhsQ2vTwLHdNb9t94cYPPdmnQk+j8K22OMke1ytVuh/bHB S9qVwfm0XCZBjbPbeRma+rKQgIHrXG3y4MLQWqlBiwsiFQECv+I9+h8ZHfVVg6aRWQ6w mWhXZUJNzDAxBdnTEdn8KMNOWFjWPrjbee7vlTrFl8F3fKh7H5eZqv4xhfeD+SkMncJ1 FEv2Ojda0ofo56vP/I4Sc5H7GBv6NWDx41f2WZPYBJfKZbQQsoLAaVQZGpOoeNK2LZx5 S7sQFxiayIcA+azGhwMp66eoEuynyb8L0XcI5AHRUMtUB+lSxOtmR9C9Et8oXafupIG2 n7+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=cktJsSFxF1fz7ozY/dNOL5+mf1uiEIW+7NslR3EWtqM=; b=nt3xFUyHcVJFJf21mLue3SXgVQ54U1Zthl/aCxuFx/lIDq6xDe8a+9SLpcnJHK7xHd x0LY0fW+v6mcX0S6DHBA5F39BcO/eC/S/3kOxOA7kGmydZFNZgV/ePxf7wuwxNnt7OLZ eEbFlKnU5eVUEbxoFdg8JvdHBZeprfLxyeWnbRL4ZajAFKwPqGyC/ouP/2iCB5yAiW/I fL1CDyr5NijDkguoZJ4cQgJ7TlXAlrSfuH285kTbpigt0O7dYmEIMuB0tDIg6we0/+Jy 1m9gbdc54it+bjppkqHl90N/YwBR0zoMfBpMCvD6trC9sdy3e3nGAdLFex8cVmR58oCy C7TA== 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 p2si21961219pjg.134.2021.10.10.00.06.17; Sun, 10 Oct 2021 00:06:30 -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 S230506AbhJJHHV (ORCPT + 99 others); Sun, 10 Oct 2021 03:07:21 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:33960 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230318AbhJJHHS (ORCPT ); Sun, 10 Oct 2021 03:07:18 -0400 X-UUID: e8612e7696b64d9dad61e46f349c5541-20211010 X-UUID: e8612e7696b64d9dad61e46f349c5541-20211010 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 122736768; Sun, 10 Oct 2021 15:05:17 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Sun, 10 Oct 2021 15:05:16 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 10 Oct 2021 15:05:15 +0800 From: Kewei Xu To: CC: , , , , , , , , , , , , , , Subject: [PATCH v8 1/5] i2c: mediatek: Reset the handshake signal between i2c and dma Date: Sun, 10 Oct 2021 15:05:12 +0800 Message-ID: <20211010070516.26763-2-kewei.xu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211010070516.26763-1-kewei.xu@mediatek.com> References: <20211010070516.26763-1-kewei.xu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 Reviewed-by: Qii Wang --- 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 72acda59eb39..dad3a85cd499 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 @@ -49,6 +50,8 @@ #define I2C_RD_TRANAC_VALUE 0x0001 #define I2C_SCL_MIS_COMP_VALUE 0x0000 #define I2C_CHN_CLR_FLAG 0x0000 +#define I2C_RELIABILITY 0x0010 +#define I2C_DMAACK_ENABLE 0x0008 #define I2C_DMA_CON_TX 0x0000 #define I2C_DMA_CON_RX 0x0001 @@ -851,6 +854,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; @@ -864,6 +868,28 @@ 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, 0x00, 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)) -- 2.25.1