From patchwork Tue Dec 19 21:22:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 10124427 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF88A603B5 for ; Tue, 19 Dec 2017 21:23:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2804287B3 for ; Tue, 19 Dec 2017 21:23:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B75BD28B4B; Tue, 19 Dec 2017 21:23:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CBA9287B3 for ; Tue, 19 Dec 2017 21:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752455AbdLSVXG (ORCPT ); Tue, 19 Dec 2017 16:23:06 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:46416 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752585AbdLSVXA (ORCPT ); Tue, 19 Dec 2017 16:23:00 -0500 Received: by mail-lf0-f68.google.com with SMTP id r143so21696745lfe.13 for ; Tue, 19 Dec 2017 13:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MBdQLx9+ubkVCVMjLHMxqfsimMMdg0nAUUENKeXiQtM=; b=bLhCbJDVpmtMHPJLWOWVMJdzSl6SjJo10ONv9OskTu74nxNmuqEkOR51+R7ZWU0pRC V07KpeGMHRr09TlGVv6l87Sy9cljLhv04RuougrZYLp1V/h3DIFWgOwxmilLAsKk6pd5 AZDiU0NeE0gEf8W6hPPUiPiLFmyFhcrWylBOQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MBdQLx9+ubkVCVMjLHMxqfsimMMdg0nAUUENKeXiQtM=; b=LzN7K0pmQ8RM0L8P5vOkTKXaVGuhLauVd6dtqub5SlyCMa3zb0SHdmhqXwO/IpMvzZ Nm5/VniOgpNleH4lWxeJQAF58wor1s8tyhkNSGUxsmVspJuXGZTA6Lsuu8w/DiFQC2mp feMeRT7HQJgcDb/TZzN4wIeCq0FIYq3SHVDbFOIusYInTiCCDq4e+WnBUDZZvXKJd/rF B3MXm69EssQ/bRI4ut4BG+AkPP+x6wo2gn2M0eWWtNy1pwLVOKrxHdFk0w6VhezyvEbk +5h7kPEnAhv0dS4J/vimpG7vm5fh7m7qGmhBOvpy4fjZmJbEkh3ib4VweU+aySiCw03l w7KA== X-Gm-Message-State: AKGB3mJQi+CaJtjKGuExIui3Y5n16Bsqyllr0QhvKeQuPRycMCInetiG LHtXbLuGYgPr6IAxvRVurQ85Qg== X-Google-Smtp-Source: ACJfBovBsovZnJOIlCvA8/hkGAkE58NlRQElM36NiVqqhawbJ6ulcYLKHkDrSNCRSF0HkdraB51CHg== X-Received: by 10.46.55.20 with SMTP id e20mr3153875lja.118.1513718578825; Tue, 19 Dec 2017 13:22:58 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-67.NA.cust.bahnhof.se. [158.174.22.67]) by smtp.gmail.com with ESMTPSA id 13sm3173068ljv.37.2017.12.19.13.22.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Dec 2017 13:22:58 -0800 (PST) From: Ulf Hansson To: Kishon Vijay Abraham I , linux-kernel@vger.kernel.org Cc: "Rafael J . Wysocki" , linux-pm@vger.kernel.org, Yoshihiro Shimoda , Geert Uytterhoeven , linux-renesas-soc@vger.kernel.org, Ulf Hansson Subject: [PATCH 1/3] phy: core: Move runtime PM reference counting to the parent device Date: Tue, 19 Dec 2017 22:22:29 +0100 Message-Id: <1513718551-28624-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513718551-28624-1-git-send-email-ulf.hansson@linaro.org> References: <1513718551-28624-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The runtime PM deployment in the phy core is a bit unnecessary complicated and the main reason is because it operates on the phy device, which is created by the phy core and assigned as a child device of the phy provider device. Let's simplify the code, by replacing the existing calls to phy_pm_runtime_get_sync() and phy_pm_runtime_put(), with regular calls to pm_runtime_get_sync() and pm_runtime_put(). While doing that, let's also change to give the phy provider device as the parameter to the runtime PM calls. This together with adding error paths, that allows the phy provider device to be runtime PM disabled, enables further clean up the code. More precisely, we can simply avoid to enable runtime PM for the phy device altogether, so let's do that as well. More importantly, this change also fixes an issue for system suspend. Especially in those cases when the phy provider device gets put into a low power state via calling the pm_runtime_force_suspend() helper, as is the case for a Renesas SoC, which has the phy provider device attached to the generic PM domain. The problem in this case, is that pm_runtime_force_suspend() expects the child device of the provider device to be runtime suspended, else this will trigger a WARN splat (correctly) when runtime PM gets re-enabled at system resume. In the current case, even if phy_power_off() triggers a pm_runtime_put() during system suspend the phy device (child) doesn't get runtime suspended, because that is prevented in the system suspend phases. However, by avoiding to enable runtime PM, this problem goes away. Signed-off-by: Ulf Hansson --- drivers/phy/phy-core.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index b4964b0..9fa3f13 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -222,10 +222,10 @@ int phy_init(struct phy *phy) if (!phy) return 0; - ret = phy_pm_runtime_get_sync(phy); - if (ret < 0 && ret != -ENOTSUPP) + ret = pm_runtime_get_sync(phy->dev.parent); + if (ret < 0 && ret != -EACCES) return ret; - ret = 0; /* Override possible ret == -ENOTSUPP */ + ret = 0; mutex_lock(&phy->mutex); if (phy->init_count == 0 && phy->ops->init) { @@ -239,7 +239,7 @@ int phy_init(struct phy *phy) out: mutex_unlock(&phy->mutex); - phy_pm_runtime_put(phy); + pm_runtime_put(phy->dev.parent); return ret; } EXPORT_SYMBOL_GPL(phy_init); @@ -251,10 +251,10 @@ int phy_exit(struct phy *phy) if (!phy) return 0; - ret = phy_pm_runtime_get_sync(phy); - if (ret < 0 && ret != -ENOTSUPP) + ret = pm_runtime_get_sync(phy->dev.parent); + if (ret < 0 && ret != -EACCES) return ret; - ret = 0; /* Override possible ret == -ENOTSUPP */ + ret = 0; mutex_lock(&phy->mutex); if (phy->init_count == 1 && phy->ops->exit) { @@ -268,7 +268,7 @@ int phy_exit(struct phy *phy) out: mutex_unlock(&phy->mutex); - phy_pm_runtime_put(phy); + pm_runtime_put(phy->dev.parent); return ret; } EXPORT_SYMBOL_GPL(phy_exit); @@ -286,11 +286,10 @@ int phy_power_on(struct phy *phy) goto out; } - ret = phy_pm_runtime_get_sync(phy); - if (ret < 0 && ret != -ENOTSUPP) + ret = pm_runtime_get_sync(phy->dev.parent); + if (ret < 0 && ret != -EACCES) goto err_pm_sync; - - ret = 0; /* Override possible ret == -ENOTSUPP */ + ret = 0; mutex_lock(&phy->mutex); if (phy->power_count == 0 && phy->ops->power_on) { @@ -306,7 +305,7 @@ int phy_power_on(struct phy *phy) err_pwr_on: mutex_unlock(&phy->mutex); - phy_pm_runtime_put_sync(phy); + pm_runtime_put(phy->dev.parent); err_pm_sync: if (phy->pwr) regulator_disable(phy->pwr); @@ -333,7 +332,7 @@ int phy_power_off(struct phy *phy) } --phy->power_count; mutex_unlock(&phy->mutex); - phy_pm_runtime_put(phy); + pm_runtime_put(phy->dev.parent); if (phy->pwr) regulator_disable(phy->pwr); @@ -774,11 +773,6 @@ struct phy *phy_create(struct device *dev, struct device_node *node, if (ret) goto put_dev; - if (pm_runtime_enabled(dev)) { - pm_runtime_enable(&phy->dev); - pm_runtime_no_callbacks(&phy->dev); - } - return phy; put_dev: @@ -831,7 +825,6 @@ EXPORT_SYMBOL_GPL(devm_phy_create); */ void phy_destroy(struct phy *phy) { - pm_runtime_disable(&phy->dev); device_unregister(&phy->dev); } EXPORT_SYMBOL_GPL(phy_destroy);