Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3246589rdb; Thu, 16 Nov 2023 04:42:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkRjQR67MgOPH5May+pQ+Gbz1waJh1Mksnc3ocj5rZEw5rYmVZe6zTlrkOZwyLyL7gJgXu X-Received: by 2002:a05:6830:1215:b0:6d6:4e53:c81a with SMTP id r21-20020a056830121500b006d64e53c81amr8069574otp.29.1700138530430; Thu, 16 Nov 2023 04:42:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700138530; cv=none; d=google.com; s=arc-20160816; b=mXmAOT6bf9K9F9+T5L8vYZlzNvKxIAfRiJClq++lSxhUfdvUAUkwP44hzhS6Lny9j6 uMBLrqCmN7Cm1e8y/qTvpBn77T4VTy9KfeVBvS2oI6xJVCm6HJlu5YfI8UVXo0p79v3Y 5bpPmejjwg3IXOXFy1x1QqpltYuU3x6EA/r5Pe/veS9D27KhY+IAvJduAxzly/mClEPW itmFl5h6xTRMGOV5Y9hAroBzMUu3Dgs++l8JLaukpp6ps/8JW4Ux2uUaJ+/qUSJ3BCdI As0wV1pBpHSGoiSBxa9LzYBmcXJZ4wiQaROQ4knHH4sDfKOTWI2p/3qb9AfMlDUmKrsL Cg6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=yoxqpsuiM/+zBUSb3hx2v44rgcCVTqxUysf3cLoA924=; fh=gITdw7bURVsgu1WFDWW+etvmcoJ0xK8NnUcjcEVG9Bk=; b=AX3dnNNCfhQXuCaAtkt3P1D/AKnE2u6YZFDne15BZN1x6PQhflid6XxL5MvlBbhbFT Ol/hA1hWdF2UCq3EzkpHq24/plVCsn1wUR/ADQF0NBUwsM29gOzyk8zmBXL5jDbrZnFY 8k2Ad/B+AqQO7NmFzv7F4gq5QdNEXu+VtUHZG5ZfZVAhMTuyr4NTpFY9hLkhqpWPBxCm N/b6oC06ZphRh37SjPqQ17NTHKCi7aEiNz+Xecxmyh6Pn45Nx8gVV2/GbcAQ4mRi+D8Y 2wqCmyC6F+rq33GYc0ALweBFLfbyDWtz+CHgaxq5FDG6NJ6wqHlcTtXnOoad80wgzVkr z36A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=naPC5FlE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id z67-20020a633346000000b005c1b582e79asi5806184pgz.34.2023.11.16.04.42.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 04:42:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=naPC5FlE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 93DAE8183F3A; Thu, 16 Nov 2023 04:42:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345022AbjKPMl6 (ORCPT + 99 others); Thu, 16 Nov 2023 07:41:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344966AbjKPMl5 (ORCPT ); Thu, 16 Nov 2023 07:41:57 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14C30D8 for ; Thu, 16 Nov 2023 04:41:54 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47BD7C433C8; Thu, 16 Nov 2023 12:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700138513; bh=vLGyRyE7xZ4srKu6DV6MaEhKkGUc+EK7JixMRPPZLu8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=naPC5FlEcHUpIG7KPTqcFrWgDAQBrCPlZNLUlBMx+SgTqAoTsIt+Ie6lwGNcVw8HT mO48U9xc+J7nkmTCu+PPbnnSdK4v98ieT4m16G1gEhQQw6F5YmbnNZ+JBznpqzLLh5 3NtPrgxClTTHbd0JbVdhToJwnyfv/KOO7bLAchKCNmcd+nUA0rDctkb0L3jkNvcRDJ AfHz6Ps0lUxXCMpzwQ68hlSZcfnXOPM97yEuP/w8qXyaMfSn415m3amGbkANCNTEqp vqn6KzXtjjj8gXOySCTcw/qFJEU2fc3Quu30FGy95JSgr/OSEcgW/TGCzu4rNhUML7 clsYg4Cr/Jf5w== Message-ID: Date: Thu, 16 Nov 2023 14:40:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/6] usb: cdns3-ti: add suspend/resume procedures for J7200 Content-Language: en-US To: =?UTF-8?Q?Th=C3=A9o_Lebrun?= , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Chen , Pawel Laszczak , Nishanth Menon , Vignesh Raghavendra , Tero Kristo Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20231113-j7200-usb-suspend-v1-0-ad1ee714835c@bootlin.com> <20231113-j7200-usb-suspend-v1-3-ad1ee714835c@bootlin.com> <5080372b-1f48-4cbc-a6c4-8689c28983cb@kernel.org> From: Roger Quadros In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 16 Nov 2023 04:42:07 -0800 (PST) On 15/11/2023 17:02, Théo Lebrun wrote: > Hi Roger, > > On Wed Nov 15, 2023 at 12:37 PM CET, Roger Quadros wrote: >> On 13/11/2023 16:26, Théo Lebrun wrote: >>> Hardware initialisation is only done at probe. The J7200 USB controller >>> is reset at resume because of power-domains toggling off & on. We >>> therefore (1) toggle PM runtime at suspend/resume & (2) reconfigure the >>> hardware at resume. >> >> at probe we are doing a pm_runtime_get() and never doing a put thus >> preventing any runtime PM. > > Indeed. The get() from probe/resume are in symmetry with the put() from > suspend. Is this wrong in some manner? > >>> index c331bcd2faeb..50b38c4b9c87 100644 >>> --- a/drivers/usb/cdns3/cdns3-ti.c >>> +++ b/drivers/usb/cdns3/cdns3-ti.c >>> @@ -197,6 +197,50 @@ static int cdns_ti_probe(struct platform_device *pdev) >>> return error; >>> } >>> >>> +#ifdef CONFIG_PM >>> + >>> +static int cdns_ti_suspend(struct device *dev) >>> +{ >>> + struct cdns_ti *data = dev_get_drvdata(dev); >>> + >>> + if (!of_device_is_compatible(dev_of_node(dev), "ti,j7200-usb")) >>> + return 0; >>> + >>> + pm_runtime_put_sync(data->dev); >>> + >>> + return 0; >> >> You might want to check suspend/resume ops in cdns3-plat and >> do something similar here. > > I'm unsure what you are referring to specifically in cdns3-plat? What I meant is, calling pm_runtime_get/put() from system suspend/resume hooks doesn't seem right. How about using something like pm_runtime_forbid(dev) on devices which loose USB context on runtime suspend e.g. J7200. So at probe we can get rid of the pm_runtime_get_sync() call. e.g. pm_runtime_set_active(dev); pm_runtime_enable(dev); if (cnds_ti->can_loose_context) pm_runtime_forbid(dev); pm_runtime_set_autosuspend_delay(dev, CNDS_TI_AUTOSUSPEND_DELAY); /* could be 20ms? */ pm_runtime_mark_last_busy(dev); pm_runtime_use_autosuspend(dev); You will need to modify the suspend/resume handlers accordingly. https://docs.kernel.org/power/runtime_pm.html#runtime-pm-and-system-sleep What I'm not sure of is if there are any TI platforms that retain USB context on power domain off. Let me get back on this. Till then we can assume that all platforms loose USB context on power domain off. One comment below. > + return ret; > +} > > - Using pm_runtime_status_suspended() to get the current PM runtime > state & act on it? I don't see why because we know the pm_runtime > state is a single put() at probe. > > - Having a `in_lpm` flag to track low-power mode state? I wouldn't see > why we'd want that as we don't register runtime_suspend & > runtime_resume callbacks and system syspend/resume can be assumed to > be called in the right order. > > - Checking the `device_may_wakeup()`? That doesn't apply to this driver > which cannot be a wakeup source. > > Thanks for your review! > Regards, > > --> +static int cdns_ti_resume(struct device *dev) > +{ > + struct cdns_ti *data = dev_get_drvdata(dev); > + int ret; > + > + if (!of_device_is_compatible(dev_of_node(dev), "ti,j7200-usb")) > + return 0; > + > + ret = pm_runtime_get_sync(dev); > + if (ret < 0) { > + dev_err(dev, "pm_runtime_get_sync failed: %d\n", ret); > + goto err; > + } > + > + cdns_ti_init_hw(data); > + > + return 0; > + > +err: > + pm_runtime_put_sync(data->dev); > + pm_runtime_disable(data->dev); Why do you do a pm_runtime_disable() here? > + return ret; > +} > Théo Lebrun, Bootlin > Embedded Linux and Kernel engineering > https://bootlin.com > > ------------------------------------------------------------------------ > > -- cheers, -roger