Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2180835rdb; Thu, 21 Sep 2023 10:41:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDKYWcZepdU3NbK0uf9oa9rIABIN08IErU6SDeGHZPfk9Icm+hAVs0gvJZ4RMvhdWxAG+B X-Received: by 2002:a05:6830:12d8:b0:6bc:d519:d7b3 with SMTP id a24-20020a05683012d800b006bcd519d7b3mr6396584otq.37.1695318080268; Thu, 21 Sep 2023 10:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695318080; cv=none; d=google.com; s=arc-20160816; b=NK3UjEiqdZInwTsubD9hz4oujJKeROs4rvSFBuG8/bDDW54nE+9SskybVxbMAT89Hs Uah1fbqN3Ag6+uWGvPVhYg6+rxPqwjqZQuIXpsQ01a0ac/ExQEfdbHDHAXBPy/bBiCdU PR+ocXQN+OBJF5X//MpK25vMZlBH+jQVUlO6dO90HO0Agb1d/LRpi/Y0cVEqOkCl5zxJ 72ZcwTaZDNHiA1S2mJ2iTetwaMQmSwhRvNY1HC0X0os6jit92lFj8R57Mt2vnQ0ppKig dpo1cr6JBVHdyAvw4ko0uoPkYBF2j+lf6w7m0xcpSRT8y/lFJPuqaM40VZRlzfxgUXMz qb4A== 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=MUrf89LolINevPIdbcaUqqDmG1RbUB/8IykP0uEhlxU=; fh=ZqJ3xrq0DGyvWtPBQo5VWOM7gaftcxyjM72UWd4YoC8=; b=0tYVOf/8Dikl3lN3QmqaHPNfZh8283xOqr2zOF1gnkJepdjgs0aI1fytTdjHaV8cxF ySG15+PFIJli9biUspzyZF6cdKE/F8NE2BiWM3Ar/QPqcvJFg12Dd1cVTS2Q74RqdfiY SqknsiNcXMNq03yYFC3s+llfvv6xJs4VsjvOll7xLwc4DJmQ8ZYSkuLVD8Ng3kwLvm20 fy4wdKRAGO2vBzUZqc6G2iv5+0g8rDz5mbIfxAfQ229pbS7EkHBMrW6m86u//sK/DSlO gTUPsWoFXzGKUVmjmLkLNNi2T2Jgf/+rwXf8jfv9+YI18OdmSX3oi8kGqU4nAstnU1pO by6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id g64-20020a636b43000000b00578fe1bdfcasi1772809pgc.860.2023.09.21.10.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 10:41:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 53362802CC3D; Thu, 21 Sep 2023 10:27:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbjIUR0u (ORCPT + 99 others); Thu, 21 Sep 2023 13:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjIUR0k (ORCPT ); Thu, 21 Sep 2023 13:26:40 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFF36573C8; Thu, 21 Sep 2023 10:18:30 -0700 (PDT) Received: from SHSQR01.spreadtrum.com (localhost [127.0.0.2] (may be forged)) by SHSQR01.spreadtrum.com with ESMTP id 38L8vCm3047513; Thu, 21 Sep 2023 16:57:12 +0800 (+08) (envelope-from Huangzheng.Lai@unisoc.com) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 38L8tUJ5040573; Thu, 21 Sep 2023 16:55:30 +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 4Rrq0B1KZJz2SZykd; Thu, 21 Sep 2023 16:52:10 +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, 21 Sep 2023 16:55:29 +0800 From: Huangzheng Lai To: Andi Shyti CC: Orson Zhai , Baolin Wang , Chunyan Zhang , , , huangzheng lai , Huangzheng Lai , Xiongpeng Wu Subject: [PATCH V2 2/7] i2c: sprd: Add I2C driver to use 'reset framework' function Date: Thu, 21 Sep 2023 16:54:52 +0800 Message-ID: <20230921085457.32446-3-Huangzheng.Lai@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921085457.32446-1-Huangzheng.Lai@unisoc.com> References: <20230921085457.32446-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 38L8tUJ5040573 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 21 Sep 2023 10:27:05 -0700 (PDT) Add 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 b44916c6741d..aa602958d4fd 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; @@ -278,9 +280,17 @@ 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) { + int ret = reset_control_reset(i2c_dev->rst); + + if (ret < 0) + dev_warn(i2c_dev->dev, "i2c soft reset failed, ret = %d\n", ret); + } return -ETIMEDOUT; - + } return i2c_dev->err; } @@ -544,6 +554,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_dbg(i2c_dev->dev, "reset control not configured!\n"); + i2c_dev->rst = NULL; + } ret = clk_prepare_enable(i2c_dev->clk); if (ret) -- 2.17.1