Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7002087imu; Thu, 31 Jan 2019 03:21:49 -0800 (PST) X-Google-Smtp-Source: ALg8bN5dzhTzDqnEhLkXibXLj3022bFHDKAjLbkFs2u4pl3VK1FOw68ZPW3g4vBL1qLW7OG4k2zN X-Received: by 2002:a63:4745:: with SMTP id w5mr31755778pgk.377.1548933709136; Thu, 31 Jan 2019 03:21:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548933709; cv=none; d=google.com; s=arc-20160816; b=jpFu48yUQpqqxpdDVmv0BdrCA0K4Vzp/vAJlxy2q/oO/A3lvr7sIwriQX+UwV/4vej gUrvRuKB6m12q2VwRe4kS3VJorPtaoaTqdXL9PtpsRBN7HemKtaZ7XjMQWVVrW0zT06l Ppuvcz+oqQYwh5VzMy+ueR3+tITbP+soxpazn6MEegOmqkcRdJsN3Q29wO+aPxKb4QoW pypKNZvmk0YgOljv9TV6PC13jR73b0Co/XYHgwWpqgifk3w5saO0BkTivZzJRzeGsbzl b1sliT3jZLBEX1/7tF4tCQIAcyhC0dMdFc7mXPPt9io8e13B7P2QFK6PIoxFZwzCZVxV /gGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=Bz9x7L+VRYFqewkzBqiuj+1CjRhOGpjvXIj2znxyle8=; b=09Rd0ZcKU1UBP5QpDAcMP//WccqUJaxM7Cudlizt31fQMN+j4dTIOzgLaa9lvQX0sX DBrRWbKHIy8s+7XQehr49+76Ev3/HamER29EdiBRGWHASdetG4QhiyrgyrJlsO4EWVf6 /x/DVkZuGu/Y9F3DcROGSjhx+H5Qkupkm13o3dhuvVr5CwvWld5DBZ//uxTdxH+3kh2V atp9PDmoWMEFYs5cPNT7usbti7DCY64b70Wmm1nHjG6ty9yzrMiJC9hjOIk0q7nNmbIG LbuzqNTsGVlqj70ABbrs/4as2ORrVZ71pqNRpvHAdIaQMmK/Zzer/7wliB3v4TbNySaG UM+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si3991655pgh.475.2019.01.31.03.21.32; Thu, 31 Jan 2019 03:21:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732113AbfAaLV1 (ORCPT + 99 others); Thu, 31 Jan 2019 06:21:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:33070 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726863AbfAaLV0 (ORCPT ); Thu, 31 Jan 2019 06:21:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 06EEEAFD4; Thu, 31 Jan 2019 11:21:23 +0000 (UTC) Date: Thu, 31 Jan 2019 12:21:23 +0100 Message-ID: From: Takashi Iwai To: Thierry Reding Cc: "Rafael J. Wysocki" , Jon Hunter , pierre-louis.bossart@linux.intel.com, Sameer Pujar , perex@perex.cz, alsa-devel@alsa-project.org, mkumard@nvidia.com, rlokhande@nvidia.com, sharadg@nvidia.com, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH v2] ALSA: hda/tegra: enable clock during probe In-Reply-To: <20190131110530.GA23438@ulmo> References: <1548414418-5785-1-git-send-email-spujar@nvidia.com> <20190131110530.GA23438@ulmo> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 31 Jan 2019 12:05:30 +0100, Thierry Reding wrote: > > On Wed, Jan 30, 2019 at 05:40:42PM +0100, Takashi Iwai wrote: > > On Wed, 30 Jan 2019 13:45:49 +0100, > > Jon Hunter wrote: > > > > > > > > > On 25/01/2019 11:06, Sameer Pujar wrote: > > > > If CONFIG_PM is disabled or runtime PM calls are forbidden, the clocks > > > > will not be ON. This could cause issue during probe, where hda init > > > > setup is done. This patch enables clocks unconditionally during probe. > > > > > > > > Along with above, follwoing changes are done. > > > > * enable runtime PM before exiting from probe work. This helps to avoid > > > > usage of pm_runtime_get_sync/pm_runtime_put() in probe work. > > > > * hda_tegra_disable_clocks() is moved out of CONFIG_PM_SLEEP check. > > > > * runtime PM callbacks moved out of CONFIG_PM check > > > > > > > > Signed-off-by: Sameer Pujar > > > > Reviewed-by: Ravindra Lokhande > > > > Reviewed-by: Jon Hunter > > > > --- > > > > sound/pci/hda/hda_tegra.c | 26 +++++++++++++++++--------- > > > > 1 file changed, 17 insertions(+), 9 deletions(-) > > > > > > > > diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c > > > > index c8d18dc..ba6175f 100644 > > > > --- a/sound/pci/hda/hda_tegra.c > > > > +++ b/sound/pci/hda/hda_tegra.c > > > > @@ -219,7 +219,6 @@ static int hda_tegra_enable_clocks(struct hda_tegra *data) > > > > return rc; > > > > } > > > > > > > > -#ifdef CONFIG_PM_SLEEP > > > > static void hda_tegra_disable_clocks(struct hda_tegra *data) > > > > { > > > > clk_disable_unprepare(data->hda2hdmi_clk); > > > > @@ -227,6 +226,7 @@ static void hda_tegra_disable_clocks(struct hda_tegra *data) > > > > clk_disable_unprepare(data->hda_clk); > > > > } > > > > > > > > +#ifdef CONFIG_PM_SLEEP > > > > /* > > > > * power management > > > > */ > > > > @@ -257,7 +257,6 @@ static int hda_tegra_resume(struct device *dev) > > > > } > > > > #endif /* CONFIG_PM_SLEEP */ > > > > > > > > -#ifdef CONFIG_PM > > > > static int hda_tegra_runtime_suspend(struct device *dev) > > > > { > > > > struct snd_card *card = dev_get_drvdata(dev); > > > > @@ -283,7 +282,7 @@ static int hda_tegra_runtime_resume(struct device *dev) > > > > int rc; > > > > > > > > rc = hda_tegra_enable_clocks(hda); > > > > - if (rc != 0) > > > > + if (rc) > > > > return rc; > > > > if (chip && chip->running) { > > > > hda_tegra_init(hda); > > > > @@ -292,7 +291,6 @@ static int hda_tegra_runtime_resume(struct device *dev) > > > > > > > > return 0; > > > > } > > > > -#endif /* CONFIG_PM */ > > > > > > > > static const struct dev_pm_ops hda_tegra_pm = { > > > > SET_SYSTEM_SLEEP_PM_OPS(hda_tegra_suspend, hda_tegra_resume) > > > > @@ -551,9 +549,9 @@ static int hda_tegra_probe(struct platform_device *pdev) > > > > > > > > dev_set_drvdata(&pdev->dev, card); > > > > > > > > - pm_runtime_enable(hda->dev); > > > > - if (!azx_has_pm_runtime(chip)) > > > > - pm_runtime_forbid(hda->dev); > > > > + err = hda_tegra_enable_clocks(hda); > > > > + if (err) > > > > + goto out_free; > > > > > > We also need to think about power-domains here. Enabling the clocks > > > might not be enough as the appropriate power-domain needs to be enabled. > > > For 64-bit Tegra runtime-pm will handle the power-domains (assuming they > > > are populated in device-tree). So I still think it is better we call > > > pm_runtime_get_sync() at some point rather than just replying on > > > enabling the clocks. > > > > If I understand correctly the code, the pm domain is already activated > > at calling driver's probe callback. > > As far as I can tell, the domain will also be powered off again after > probe finished, unless the device grabs a runtime PM reference. This is > what happens via the dev->pm_domain->sync() call after successful probe > of a driver. Ah, a good point. This can be a problem with a probe work like this case. > It seems to me like it's not a very well defined case what to do when a > device needs to be powered up but runtime PM is not enabled. > > Adding Rafael and linux-pm, maybe they can provide some guidance on what > to do in these situations. > > To summarize, what we're debating here is how to handle powering up a > device if the pm_runtime infrastructure doesn't take care of it. Jon's > proposal here was, and we use this elsewhere, to do something like this: > > pm_runtime_enable(dev); > if (!pm_runtime_enabled(dev)) { > err = foo_runtime_resume(dev); > if (err < 0) > goto fail; > } > > So basically when runtime PM is not available, we explicitly "resume" > the device to power it up. > > It seems to me like that's a fairly common problem, so I'm wondering if > there's something that the runtime PM core could do to help with this. > Or perhaps there's already a way to achieve this that we're all > overlooking? > > Rafael, any suggestions? If any, a common helper would be appreciated, indeed. thanks, Takashi