Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1438039rdb; Sun, 7 Jan 2024 21:23:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4AKcLGfN885rMKJ7FmE9I0wKevQmcT3RVYMIZPw8d9Crs0UsiUXf62sg+JemCp+DJEXDN X-Received: by 2002:a05:6359:4c15:b0:175:4953:4637 with SMTP id kj21-20020a0563594c1500b0017549534637mr1283572rwc.50.1704691396262; Sun, 07 Jan 2024 21:23:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704691396; cv=pass; d=google.com; s=arc-20160816; b=zRHhUZwJKYbUzJlXQMRjfXRaOaQzvh0CpKZYJL6vtZ7zi9S+9y2P1j5e0grgmkAyXv /7zIJFUWRcmdFA44U/nIpuUm9y9ZFxOncTqrmxE3d/If0IASxGg8V4jEjPuBdWyz7pZm vah/K8EWRE7jbAgwx2zn5UNQvTRa3OKmMYBbtGZK7srjljAi2LM9h0GCxdLXG/lS2Pya S0v1rY455KaU3NMWDQ3m19PM61OX6e8N4jrtwC94ZmN2lJm+3zhYkqnf/thaBXCIkMf6 xw5YRvA5YEIhczmjxqDZTFxwK350E9rGM28Ih+Mrgu7M4n6rLjELn6wWs35DhW4izZdB rX7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:content-language:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=FcvonXjMC1UsUrzhChkwYUxc9/tjgBofxieUt34tVd4=; fh=fR1kiNrI3paRpPA++2FOCKATh4dF0dU2Mhyjc5x/yuM=; b=dz2XFULm+rL7zJkKW5uZIS/4b8uc2aMJ1zUtsgAZ5o38wxftsb2Z7rCuGjhWYun9ID 4YGVCYj3cM5pAu/QWpRTfAeSHkxWv5YDiO8Cx8vEJTXR6w7ZV9Vuehe6t4uiuIW90dgQ R6z+LjB6DjtwomqusVdGs8d/fL7t5hqsC8RanLq7cQvXf/y/rlZwDdE24Eo8As4Lmpkf WjrvuYh+PP8hpq/xADIhUSeIc6M4MeX1ByrtDUUNBl9e+nExaIb7DaeiZdwgL58Haq1z KvBK3jzy1K+3mYCvpPB1aIaErRHpe3lehjd08fXKNBHhfGv3tXfp8Ce4YG9NSPpN0B0W pvQA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=starfivetech.com dkim=pass dkdomain=starfivetech.com dmarc=pass fromdomain=starfivetech.com); spf=pass (google.com: domain of linux-kernel+bounces-19089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19089-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p8-20020a17090a680800b0028c1c339f5fsi5078597pjj.35.2024.01.07.21.23.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 21:23:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=starfivetech.com dkim=pass dkdomain=starfivetech.com dmarc=pass fromdomain=starfivetech.com); spf=pass (google.com: domain of linux-kernel+bounces-19089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19089-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D0140B213E1 for ; Mon, 8 Jan 2024 05:23:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 946478813; Mon, 8 Jan 2024 05:23:00 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from CHN02-BJS-obe.outbound.protection.partner.outlook.cn (mail-bjschn02on2071.outbound.protection.partner.outlook.cn [139.219.17.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A559779C2; Mon, 8 Jan 2024 05:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=starfivetech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=starfivetech.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TcJ47kYUYRTgrySJRrpep914ZwwJ0wuvtqpR2K/xBpZAHxHyhiAL8100EDjPFRHWwQjzmQsnyFwkM1jnlSYfken1Xv9RHxDcibzHklyK+8/0MjcGwpwIfEA+/30Lh6UXqnwjH5idj/92+ycEZpJ1W80REeswIsZiYfPqEuevvAZFR+OuQEY7fbFm/iPaoXhu4Gqb7ljd7ywHws5QcTVVgP9akrJTPd4BkKHocHTa5EW9j8JaPiiIyajzHtQRLgmABFiTbym/eRPo6LBW7SpPh7lzpDgDtDmTz+EWdgjI7dsBpYEkfLM9SyT49ndlGOlz3xM7HC+hPgL4fP+dBcuIjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FcvonXjMC1UsUrzhChkwYUxc9/tjgBofxieUt34tVd4=; b=eEszzH4jpCIoyZU37dnQ5EEouNeckcXZlkya/IUuaTJIXL17Sw7N/tQh5Vi0k9cckrjKQEUZYSNpjIp4nsNqcOlr+ZyX+9XOqIya+CyM/hJGDC0/1VkG9UmzVJIDVDGiME16sxpkFMmWxyWllT3ES6Ks2mJr/4YJllVJ+NZ5Z+1BzNMetXzXFqaQcmkra6fHitRsEiggW12oXP6dLTj27/sIeDvFNs4gJEOzjXF9xXf9T1fJQmgZ+HlWWDUalftpKaSW4fiVM+WisLw3Q0h118U0Vfj/CAJdXx9H8BC9EGVBWrFqEzejXtg3yWoBLb/gkb8j09gb8XP1K95fWqbHCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=starfivetech.com; dmarc=pass action=none header.from=starfivetech.com; dkim=pass header.d=starfivetech.com; arc=none Received: from ZQ0PR01MB1160.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:19::6) by ZQ0PR01MB1096.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.21; Sun, 7 Jan 2024 23:47:17 +0000 Received: from ZQ0PR01MB1160.CHNPR01.prod.partner.outlook.cn ([fe80::1dbb:b090:7d89:4e22]) by ZQ0PR01MB1160.CHNPR01.prod.partner.outlook.cn ([fe80::1dbb:b090:7d89:4e22%4]) with mapi id 15.20.7135.032; Sun, 7 Jan 2024 23:47:17 +0000 From: JiSheng Teoh To: "andi.shyti@kernel.org" CC: JiSheng Teoh , Leyfoon Tan , "linux-arm-kernel@lists.infradead.org" , "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "michal.simek@amd.com" Subject: RE: [PATCH v2] i2c: cadence: Add system suspend and resume PM support Thread-Topic: [PATCH v2] i2c: cadence: Add system suspend and resume PM support Thread-Index: AQHaKqHICsIFtOoPykiU4PTXtMLy1rCg6VYAgACMaYCAAG4PAIAASqKAgC0BRBA= Date: Sun, 7 Jan 2024 23:47:17 +0000 Message-ID: References: <20231210115412.hztjrubacnmenbvz@zenone.zhora.eu> <20231210162119.364-1-jisheng.teoh@starfivetech.com> In-Reply-To: <20231210162119.364-1-jisheng.teoh@starfivetech.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=starfivetech.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: ZQ0PR01MB1160:EE_|ZQ0PR01MB1096:EE_ x-ms-office365-filtering-correlation-id: e284a4bf-755f-4a45-2744-08dc0fdafb3f x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LQx0sz7Cg2zi5i7jLXkrrxyJoPkiEiZDv02RctFQzp537OhbYUhUBU5t6qZ6G8RI06S7CSK3JrSjhf9RCcdhdhEgLlG6O1pUalWYC32czqdkzNrAmatKJsSiI4NEagj/52Aeh+J4RYOT+qA71SynNtKSSUD1NoXh1kiOkQnXGlX6QxRY1lta1MImjTLxT9KxHyeat7bv5j1mJwL03StYq/ZS6vpF4wBNj2zmsJbA6bAFn7/hveKWgK9LTbh+elKTGmOrpHAnYTWvSf5MNzve0iJoOngJ4oqAj4wbtN93JleeTJ4+1NrbB7xfne4SrvuL2LGVVLdoHuMBHih5cf7256ifX+KpL2svFU0jm0X8Ldk3Y0CrXw52pmQ0Pocq+pGEwskT/HoWmtKB7B3e12jdhuuINEE4XbU2JdMXRJNpyHhY2Bb9UqCe0Wge3Uy0G4gQ/dkWZ8n/26PdV8LHpudlymL2VYOpEJHE2e/MuguM90Zz+/sqKyVbyONKVU/l964j3Pu02PMyhDxOMsiHMKTMiMd7hgP1m2szn1K4yEkIMIcWQHog7Jl69QxncpWyUGaQkGMTAdmR9qsnw1WKIPXjY7LfynP18mEUoxNKhoritZo6KswVjKe4qFhko3vK5DmPiJek8BL+3NjkSp2kxcmlqg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ZQ0PR01MB1160.CHNPR01.prod.partner.outlook.cn;PTR:;CAT:NONE;SFS:(13230031)(396003)(346002)(136003)(39830400003)(366004)(230922051799003)(186009)(1800799012)(64100799003)(451199024)(66446008)(7696005)(66476007)(6916009)(66556008)(40180700001)(64756008)(966005)(9686003)(71200400001)(66946007)(76116006)(41320700001)(508600001)(54906003)(38070700009)(40160700002)(8676002)(15650500001)(5660300002)(8936002)(4326008)(86362001)(26005)(122000001)(55016003)(38100700002)(83380400001)(2906002)(33656002)(41300700001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?lhBfLWmWMeCJEu2l1id5B8mF01sWaYdf9NxdkvfUYIV8Qt5y49HKIvdcIi5k?= =?us-ascii?Q?oFqJa/mL3cfPvGEuHC71AHL5abohKGcDUAfX/CsayXoOsvkuC9T6cGy3OQBE?= =?us-ascii?Q?1zZxp3IwDBxHc9aB60jDxllg0TKrm9op8aVCpgRgc6kuZlBoXs3FJGQpyMPh?= =?us-ascii?Q?+rSXj41H0rAe7K5XDZ7MCTb0i2WfmiPxh8JSnGP1nANVtbS3F5+o/6n4i/5n?= =?us-ascii?Q?HUcR/fCiLxCvIVoJZOduqBLL4e+D9SXFyQ1IWPZbN2qfa0nCgWSb7KEK/rHh?= =?us-ascii?Q?6WDZhmRxLtaX5YSi3hO7gIGjZ4fhHThsNOmxChTwzh5x4YD3za8DWezJUSn9?= =?us-ascii?Q?nMpwx/eYAHZAbMHkCPSF7NjWHwUYh/ega8xFRre8Y+/UHmfosm1c3+mqNxtn?= =?us-ascii?Q?WZOQpXlP62jDIgvls39rA5tRon/AbtONsghzClLlqa/ddR6SmwuqBEEmWQXM?= =?us-ascii?Q?Pt8B9pkxU31kQAoh7KwcHKKifravOTKh4Z0RBwp0MLo6utLO/3sHIYDcUmBH?= =?us-ascii?Q?SXAOqHEkpHQrvbq6S/g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-ascii?Q?PTjsyae+EDmlnUPpuEOkLX6BPJuQSLLuUXS9mcuGPzUFo9uokhBCj+BH586E?= =?us-ascii?Q?xBgR7+eZ8DUD3R2yUIL+JmluIDKMFrNq7Yq2ZRBSIekoDrrhbFFQuVH0PTLa?= =?us-ascii?Q?nimAJhDkPvtjWumrJa8S+jjUw81ghEqfNJ+NQ9zAavES1o86/2nTiGDx5I3B?= =?us-ascii?Q?zw=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: starfivetech.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: ZQ0PR01MB1160.CHNPR01.prod.partner.outlook.cn X-MS-Exchange-CrossTenant-Network-Message-Id: e284a4bf-755f-4a45-2744-08dc0fdafb3f X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jan 2024 23:47:17.1897 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 06fe3fa3-1221-43d3-861b-5a4ee687a85c X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fB+lhLyfQ7TSY5YmZhV92G+A1udROa3hf7NtmQQz4zlNKcA1RrT84XoaoREhf9T1GHyWSgPjHUaTTF7aP2a4u+QMlav4+sg96Q7H/SRvS1c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: ZQ0PR01MB1096 Hi Andi, > On Sun, 10 Dec 2023 12:54:12 +0100 > Andi Shyti wrote: >=20 > > 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 =3D dev_get_drvdata(dev); > > > > > + int err; > > > > > + > > > > > + err =3D 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/44c99904cf61f945d02ac9976ab > > > 10dd5ccaea393 > > > > > > > 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 >=20 > You are right, the clock counter will move towards 0 during system suspen= d. > Conversely during system resume, the clock counter is incremented to 1 ea= rly 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 su= spend, we decrement the clock counter back to 0, so the > subsequent runtime resume could increment it back to 1. In a sense, balan= cing the clock counter. > Please help correct me if I've got it wrong. >=20 Just to check on the status of this patch. Let me know if the above stateme= nt makes sense. > > > > > > > + err =3D 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; > > > > > +} >=20