Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3507892rdb; Sun, 10 Dec 2023 08:22:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFG3inlMQcwMYroE6hSoZVarCYe6zuVNMk9YJz3HJS1OdHI68bii6AcJJ8lslFVWg2wfTJG X-Received: by 2002:a17:902:a9c4:b0:1cf:8bb6:f9c1 with SMTP id b4-20020a170902a9c400b001cf8bb6f9c1mr1240247plr.59.1702225336150; Sun, 10 Dec 2023 08:22:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702225336; cv=none; d=google.com; s=arc-20160816; b=Rya7fR73apxK2GscKQnPzCbepWkCAOjLGp+IgjkYU+3rGcVaKfispjbQ1fN0SzdFkE kxh4F9LXEESnGMKRfKLRIIxY9Rv5vyR93ML+zEXff3F3iHJ2xLV61JvoPkarThK50q2G /y6b7VAg/E8lcqbTP9DGSSj5YP3S+C4sXIQxYyBseyTksEs/Wf1kIgvTMHTQYhPEr9OX r6XUsjG+HTvGpRpAkSKoZn+ibANbnhYjvQ9j4I0wZ1oI8Fsc5l0CxpF97wcAhOVZHpGQ +FinWDUtYL3mCTJk6hbW37iZbmCP+RcgjV7DnY4eaDmkZ1dVjYaNb0GERMRlDeE3+Svq 684Q== 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=Z10aI0H6LaRptP/8uPtj3B/80JareJR4Fij+Yz2sadA=; fh=q9SNB7AWjsM+WIxFuFxlg8zSIB3QJ7serSDiuu3995c=; b=JtYrLFqdlkXEd+evBZvRAFto+YcmVPCSRMjxEUkgl7YqbC1crNhoO9FAxxKPUm+Lk5 tHjMMMUP5dv1boTq+aY3mfJ2WPNEBsZESrBx1x9mSymwgNHjZ6lNVm0NLnxhfNPtnlap FM+C5WXmII/rN4d2jmmGDR/drOmUGAG1Jg4rQgGRHUj0lKLmaqRRLoP3V3mtLbysssnG pTKBO812K2XhptQiD0KgpFNVxzAOTCEDpmD3y/jPxqRfnZSpV8+d8xE3fjMg06zCbuiE 9kkwReCnn3jdwA0XJ221GnPc0nZjxPrFPIhiDivXkAmuvDlNbTHDIE9/uifq8I7YaF5y Srwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id w13-20020a170902a70d00b001d0824216a3si4720526plq.432.2023.12.10.08.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 08:22:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id A16C3808495E; Sun, 10 Dec 2023 08:22:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231974AbjLJQVv convert rfc822-to-8bit (ORCPT + 99 others); Sun, 10 Dec 2023 11:21:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbjLJQVu (ORCPT ); Sun, 10 Dec 2023 11:21:50 -0500 Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84354FA; Sun, 10 Dec 2023 08:21:52 -0800 (PST) Received: from EXMBX165.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX165", Issuer "EXMBX165" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id A5F2C24DB84; Mon, 11 Dec 2023 00:21:49 +0800 (CST) Received: from EXMBX072.cuchost.com (172.16.6.82) by EXMBX165.cuchost.com (172.16.6.75) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 11 Dec 2023 00:21:49 +0800 Received: from localhost.localdomain (42.189.171.87) by EXMBX072.cuchost.com (172.16.6.82) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 11 Dec 2023 00:21:44 +0800 From: Ji Sheng Teoh To: CC: , , , , , Subject: Re: [PATCH v2] i2c: cadence: Add system suspend and resume PM support Date: Mon, 11 Dec 2023 00:21:19 +0800 Message-ID: <20231210162119.364-1-jisheng.teoh@starfivetech.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20231210115412.hztjrubacnmenbvz@zenone.zhora.eu> References: <20231210115412.hztjrubacnmenbvz@zenone.zhora.eu> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [42.189.171.87] X-ClientProxiedBy: EXCAS066.cuchost.com (172.16.6.26) To EXMBX072.cuchost.com (172.16.6.82) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=1.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Sun, 10 Dec 2023 08:22:13 -0800 (PST) X-Spam-Level: * On Sun, 10 Dec 2023 12:54:12 +0100 Andi Shyti wrote: > Hi Ji Sheng, > > [...] > > > > > +static int __maybe_unused cdns_i2c_resume(struct device *dev) > > > > +{ > > > > > > I am not really understanding what you are trying to do here: > > > > > > > + struct cdns_i2c *xi2c = dev_get_drvdata(dev); > > > > + int err; > > > > + > > > > + err = cdns_i2c_runtime_resume(dev); > > > > > > First you try to resume... > > > > > > > + if (err) > > > > + return err; > > > > + > > > > + if (pm_runtime_status_suspended(dev)) { > > > > > > ... then you check if you are suspended ... > > > > This serves as a check and balance to ensure that when the system > > resumes with device in runtime suspend state, we disable the clock > > enabled in earlier cdns_i2c_runtime_resume() to ensure a balanced > > clock reference count for subsequent runtime resume transition. > > Similar implementation can be found in this commit: > > https://github.com/torvalds/linux/commit/44c99904cf61f945d02ac9976ab10dd5ccaea393 > > > > OK, this is done purely for clock balancing, but then, I still > don't understand the case. I expect the clock counter to be > unbalanced when you suspend (because is moving towards '0'). > > While, if you check if the clock is unbalanced when resuming, it > means that the clock had a negative counter (which is impossible > because the clock counter is unsigned). > > If there is any unbalancing at this stage, then I recommend you > to check what has happened previously. > > ... Or is there anything I am missing? > > Thanks, > Andi You are right, the clock counter will move towards 0 during system suspend. Conversely during system resume, the clock counter is incremented to 1 early on in cdns_i2c_runtime_resume(). So the clock counter is not negative to start with. At this point of time, clock counter is 1. If the device is in runtime suspend, we decrement the clock counter back to 0, so the subsequent runtime resume could increment it back to 1. In a sense, balancing the clock counter. Please help correct me if I've got it wrong. > > > > > + err = cdns_i2c_runtime_suspend(dev); > > > > > > ... and suspend again? Shouldn't this be _resume()? > > > > > > Thanks, > > > Andi > > > > > > > + if (err) > > > > + return err; > > > > + } > > > > + > > > > + i2c_mark_adapter_resumed(&xi2c->adap); > > > > + > > > > + return 0; > > > > +}