Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp2102134rdb; Thu, 17 Aug 2023 10:45:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhyVwy61ycuvHrZi2T+sNv3RloKfUnxbY0N4mGUuOUWs1Mu9MLYUeSVzX2U4zGH6FyR1B9 X-Received: by 2002:a05:6a20:dd9f:b0:13f:1622:29de with SMTP id kw31-20020a056a20dd9f00b0013f162229demr400904pzb.7.1692294342447; Thu, 17 Aug 2023 10:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692294342; cv=none; d=google.com; s=arc-20160816; b=SwM0rhXCT0EI91a5/vWOQNg6H5jKiN01ff2MkTloVdquTh1rNsksFToFsSLlnIJpa7 tu66P0QQToCmEVXFT8ve6W0mkLHgFHWfHMazB6e2U4qP8lJawKJlHwH2vH7WeySFYb0s 0eF4Lcd+le7+TANc3nJQ7XIKcU4xBG7uszI/74Vih1D+3KXE1RcvPCPwTAdUsmdUKnEc 4aH89+OvrNjZBnFvBTE01YHzU0IM8/ogqe1A1YGxo2XjDsoaRc5D0udEG7kwmTs5gYGv 3TElDJNGq0PrR5hv+7mZU3Zi/uXd+RiH9piwIcYUIj/9PvsRjlsJTG2dCilTRJT9YUEz OvqQ== 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=HQR/tp2SEIe7rTFiOa4vwUwXdB4xCf7B9Z1368qvXGM=; fh=gGhlJDYDEsdJyR07emMX5eRQjvOds3cTltK5uexKPLI=; b=JUX9R1Ymmh5s0xvQz3Ghsurw59REt1Oiq4lY1NloZLBOWulDERebMcuiUUxI2f4Al3 Q8XQTbnTLUJkjFYZ8njpxo+od/qKlP2B/eL9jG1FPm82d0JPGleDtamYsvO3Y5tyKgj2 ZQsyeyjIxmFuytvK5PYaTya3ZqniBFTyw/aFfZCg1V3bxVZHLc1tjQyz3KKpXdHARkMg aR+aC4MagOO2z3yfR+5j0i2w23xE0OORL1+YuuYbS0EShjdG4lyly+aVsxb5JxuWKOlY +v7HAsILbMWcpz7Z23MB07RleMGNqSD7tPn/6CPuBwP0MJEMyul1cEyMScW6IpsjEvuX yrAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv9-20020a056a00414900b006826c5b86dasi39651pfb.364.2023.08.17.10.45.29; Thu, 17 Aug 2023 10:45:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349853AbjHQJrH (ORCPT + 99 others); Thu, 17 Aug 2023 05:47:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349828AbjHQJqn (ORCPT ); Thu, 17 Aug 2023 05:46:43 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D222D67; Thu, 17 Aug 2023 02:46:41 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 37H9kGL5085282; Thu, 17 Aug 2023 17:46:16 +0800 (+08) (envelope-from Huangzheng.Lai@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx04.spreadtrum.com [10.0.1.214]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RRKpF0W4yz2P3khb; Thu, 17 Aug 2023 17:44:05 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx04.spreadtrum.com (10.0.1.214) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 17 Aug 2023 17:46:15 +0800 From: Huangzheng Lai To: Andi Shyti CC: Orson Zhai , Baolin Wang , Chunyan Zhang , , , huangzheng lai , Huangzheng Lai , Xiongpeng Wu Subject: [PATCH 2/8] i2c: sprd: Add I2C driver to use 'reset framework' function Date: Thu, 17 Aug 2023 17:45:14 +0800 Message-ID: <20230817094520.21286-3-Huangzheng.Lai@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> References: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.13.2.29] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx04.spreadtrum.com (10.0.1.214) X-MAIL: SHSQR01.spreadtrum.com 37H9kGL5085282 X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,MAY_BE_FORGED, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the 'reset framework' function for I2C drivers, which resets the I2C controller when a timeout exception occurs. Signed-off-by: Huangzheng Lai --- drivers/i2c/busses/i2c-sprd.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c index acc2a4d4eeae..066b3a9c30c8 100644 --- a/drivers/i2c/busses/i2c-sprd.c +++ b/drivers/i2c/busses/i2c-sprd.c @@ -17,6 +17,7 @@ #include #include #include +#include #define I2C_CTL 0x00 #define I2C_ADDR_CFG 0x04 @@ -85,6 +86,7 @@ struct sprd_i2c { u32 src_clk; u32 bus_freq; struct completion complete; + struct reset_control *rst; u8 *buf; u32 count; int irq; @@ -247,6 +249,7 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap, { struct sprd_i2c *i2c_dev = i2c_adap->algo_data; unsigned long time_left; + int ret; i2c_dev->msg = msg; i2c_dev->buf = msg->buf; @@ -278,9 +281,16 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap, time_left = wait_for_completion_timeout(&i2c_dev->complete, msecs_to_jiffies(I2C_XFER_TIMEOUT)); - if (!time_left) + if (!time_left) { + dev_err(i2c_dev->dev, "transfer timeout, I2C_STATUS = 0x%x\n", + readl(i2c_dev->base + I2C_STATUS)); + if (i2c_dev->rst != NULL) { + ret = reset_control_reset(i2c_dev->rst); + if (ret < 0) + dev_err(i2c_dev->dev, "i2c soft reset failed, ret = %d\n", ret); + } return -ETIMEDOUT; - + } return i2c_dev->err; } @@ -535,6 +545,11 @@ static int sprd_i2c_probe(struct platform_device *pdev) return ret; platform_set_drvdata(pdev, i2c_dev); + i2c_dev->rst = devm_reset_control_get(i2c_dev->dev, "i2c_rst"); + if (IS_ERR(i2c_dev->rst)) { + dev_err(i2c_dev->dev, "can't get i2c reset node\n"); + i2c_dev->rst = NULL; + } ret = clk_prepare_enable(i2c_dev->clk); if (ret) -- 2.17.1