From patchwork Thu May 31 10:59:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 137357 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6441269lji; Thu, 31 May 2018 04:00:07 -0700 (PDT) X-Received: by 2002:a2e:9c08:: with SMTP id s8-v6mr4929946lji.97.1527764407654; Thu, 31 May 2018 04:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527764407; cv=none; d=google.com; s=arc-20160816; b=e7dCwPMkTwClM+uSM5yM9E+/hLHJskuxLJqfHbNR6+PWobLe0diImiED2figr5WMcq dBEdCVx2B1JPUKVHgq2pjbjA+aSJesIojG0lhTX9r570PVwLyl0TSx1/F84BJHo0B7v9 4FCSv+RPHEyOlaWn1R/WpkEYjMBin0idFxlDhs0WLQjv2TaBHwmbKXzIvCz4AvUNstbl wqg/s6+fZ1HL2owbZBeunNG29vJ1ApRn9Lh5lFUGgbk6yGCASxKkI50ejOyXEgO07xPy /FYSx7SDlwR+y1wtHyH+T0e26//4Z5dzDUrPJBOidZU/XwW9Bv26O9oc6FuU+LdMBZsH RGYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ZH39p/8/sSOGcDgWkxX291KKzmCdn80SkuLPNKHKcMQ=; b=zL7+luKMzRw3XUQJ5SkOuY9t14eGsKJm6Fiul2AAd3Xp1U/NfazcsidOB6IxzPMpIt IpF3jQAQRygYj3wbPx3y3ZuJMHBpleyXzmUxlh56DaV1uxPAdxw/LuLMyqi2NP/48hck 1WqVm4nYxTxk1xodDNgQUO3xVfYxsqD5c9n9G3/hGc/XUVD/XHnBAs1v3XFV9kNPO2cM gdDYBV3AuehIu7g/V26ysLrSHuZ1Hks4+SHJZvbid9AiVT5OR94sEeXxXq3rtg8K8ziH s+eagDEUlFxCkV59xBRtymjObgVoPg+Tlaem3mV+uFzh154FtA8bJeuyfV4NoIjbQ2fs Cm/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YjFr0wp7; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s7-v6sor8796540lji.74.2018.05.31.04.00.07 for (Google Transport Security); Thu, 31 May 2018 04:00:07 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YjFr0wp7; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=ZH39p/8/sSOGcDgWkxX291KKzmCdn80SkuLPNKHKcMQ=; b=YjFr0wp783aTrhBh84Ps/VHpMo8K6f4aGv7cDGL3ZL8Yj/cs47J7vlpeyyt5CICz1R 39GCXiDUUhVXtont1VrQlbRQ3czi+4Gs7qetDv0U3HKbCGK1LnIfQ60AuPEGCboCLaa2 9z1MzZDYipigKmguliYikQUBLfevOJSBRyq/8= 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=ZH39p/8/sSOGcDgWkxX291KKzmCdn80SkuLPNKHKcMQ=; b=OuZUoe9b7wA4oCN0m5DPC7R4MLkv5pwDXiMS9R1s25IhKVD/F6PHGZbBTTX+GgmAo9 EjqJ6WD8cc2aZWjDZW2MTpGXoU4npAIX1XxmbQJrnFmaadbsjFwDGNCgImDROg0uI7mK Q8PdOuhDN7TI5nNLiRf4Mxoiwn/9+dPbJCDIJds+6G55Hpl8+JRG6bIoCvaQveMNWrBu b22bUgee2nmLf0MHMZ/bMLCbMxikDTa7nivbiaLcgqwmyWH97KH4xkEklK+ntd+B9Een hXOAwStlcajIrfO2rRMrja9Yju+1y7A3nMV8/n9whprgRyDOt39PiXbsF44i8IIThZJ/ BVDw== X-Gm-Message-State: ALKqPwdWv1rsPZbJV+P9adKxqWZxj1Td0JrXVt/h6n/Tm+weAY2bZYMz J/gkU2DUMHz0+mN7O/zEnAHW9wTY X-Google-Smtp-Source: ADUXVKIu02fHNyEgglOY/Vp1Pvlj6BoRvlakCvN+yV9KbqJrm3ntVx00gUxV8NyuaCvVXKweESp/eg== X-Received: by 2002:a2e:95d6:: with SMTP id y22-v6mr4786107ljh.90.1527764407490; Thu, 31 May 2018 04:00:07 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b20-v6sm7454383ljf.51.2018.05.31.04.00.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 04:00:06 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Greg Kroah-Hartman , Jon Hunter , Geert Uytterhoeven , Todor Tomov , Rajendra Nayak , Viresh Kumar , Vincent Guittot , Kevin Hilman , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v3 1/5] PM / Domains: dt: Allow power-domain property to be a list of specifiers Date: Thu, 31 May 2018 12:59:55 +0200 Message-Id: <20180531105959.14843-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180531105959.14843-1-ulf.hansson@linaro.org> References: <20180531105959.14843-1-ulf.hansson@linaro.org> To be able to describe topologies where devices are partitioned across multiple power domains, let's extend the power-domain property to allow being a list of PM domain specifiers. Cc: Rob Herring Cc: devicetree@vger.kernel.org Suggested-by: Jon Hunter Signed-off-by: Ulf Hansson Reviewed-by: Rob Herring Reviewed-by: Viresh Kumar --- .../bindings/power/power_domain.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) -- 2.17.0 diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt index 4733f76cbe48..9b387f861aed 100644 --- a/Documentation/devicetree/bindings/power/power_domain.txt +++ b/Documentation/devicetree/bindings/power/power_domain.txt @@ -111,8 +111,8 @@ Example 3: ==PM domain consumers== Required properties: - - power-domains : A phandle and PM domain specifier as defined by bindings of - the power controller specified by phandle. + - power-domains : A list of PM domain specifiers, as defined by bindings of + the power controller that is the PM domain provider. Example: @@ -122,9 +122,18 @@ Example: power-domains = <&power 0>; }; -The node above defines a typical PM domain consumer device, which is located -inside a PM domain with index 0 of a power controller represented by a node -with the label "power". + leaky-device@12351000 { + compatible = "foo,i-leak-current"; + reg = <0x12351000 0x1000>; + power-domains = <&power 0>, <&power 1> ; + }; + +The first example above defines a typical PM domain consumer device, which is +located inside a PM domain with index 0 of a power controller represented by a +node with the label "power". +In the second example the consumer device are partitioned across two PM domains, +the first with index 0 and the second with index 1, of a power controller that +is represented by a node with the label "power. Optional properties: - required-opps: This contains phandle to an OPP node in another device's OPP From patchwork Thu May 31 10:59:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 137358 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6441312lji; Thu, 31 May 2018 04:00:09 -0700 (PDT) X-Received: by 2002:a2e:1218:: with SMTP id t24-v6mr4825935lje.143.1527764409742; Thu, 31 May 2018 04:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527764409; cv=none; d=google.com; s=arc-20160816; b=KtL3zj7008V6Jz3QCsKtA96qzEhYgaJnGZgXfOD7nCZGK0e/Fo6GpIA7s4lUOCXckn Oc193YltGifqNh3xRfN/TH3GV/aHX14YSJE7OgF38LT2fg3CoZ8gFhe0EPGQ7puoxA7m 89gayaoxhxcTBMaNarbiaGRdo+ougt2zQzLbd/Nouu5novUP26JKEXxcyfTBg2rSef0k K9dN2uvSI2hkeYP4MCjUEAMycm9ry20u+0AxM5BxKTSi+HX7ns4An/4UC9SGIVlEYZrV X5WVtUFB7DtgqssKY+Xv2D7peXV/ys6hB4L9ZpSFFvh7IrDIdPhHRRWX4SQMrhEOBoQQ fGgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=jKz+vlX/PouqjXRFdu2AfA12MJxmgGmBdpobmfJzBo8=; b=wriocLtpjpBgdB3X2xUeta5vRQEJeh1VjBj9vCx8GztwQBLiXY/5D0bRNNx1H4TfjL sa6wP0mO2+aL7lPcycJz+6RzMpytTdXJgIs5cw58qtmHJGMG3V5at3KfCMFMzcXWU51R 0YKql4GGVqfPsxWLjHmNRDUsCLz098Q4ltbEWQG+JbTIkCLUiEdGe8btx/gQzi+2N0aJ dusyFOM2BrjguoersYX56qNeBMo/UtJWcomCHdw9EPYZ0yVxob7POaN2BTk0eoFY1yVH xRAAByujr3MHPrTBrhRyT2dpJ7gXqWMlLaEBS2Q2NFJfKRO8K2ay/xryaoPOqfS1ZhXW wvsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cfms82ve; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a10-v6sor1481651lfe.63.2018.05.31.04.00.09 for (Google Transport Security); Thu, 31 May 2018 04:00:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cfms82ve; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=jKz+vlX/PouqjXRFdu2AfA12MJxmgGmBdpobmfJzBo8=; b=Cfms82veV6wwqnFDu+KXZpAM+5lc10354WQbxw+tBsDCKTCWSGwF/ybvNCMYF3xfyw ShQVSi2fg5zaGigjwjh+swjebs4GLTXq74Z7yM0BbLIitg8Geh1ShOv53kbLZFk6v58U 2VL2JMgmRoE0QoZwDmrEP6IkRjwL1o/dCZFBw= 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=jKz+vlX/PouqjXRFdu2AfA12MJxmgGmBdpobmfJzBo8=; b=Yaj97MO9IkgiUeLPiwdbv8Ab7OdB1Axdufqks8XWTuzcYVD51aht49/aFnAPO7E4zC z6AfV70kf5qR1egnESJFu8skVJXXLW4BFlrTB85mI06xILQrs+ZJGK/WrEdKVU6lzXpr 5JzwshWPuDZSO8NFSLg1B0XjOVTnIqpLSu+U+bRSuTIEvx+vYLcwjomkFKr/sSBktODZ 8RAXbKYsItDZUt0oz5Mj2UWgekGjRbkUkCoCjsg8btGsuULL2qSnpQa9dvj/Rh7Warl/ E/OJAsULWbxXwumoArqkXzRCGVaoeb8OymxQvXHT2Xs4nOrj01Pb7N0vXdPNvWAsBnP9 1ldQ== X-Gm-Message-State: ALKqPwcq5gEPixeuVZrGriYyi1gkFwmqRZ3EZZJcKwLhCzNBtGKu//yG WmYvTEkeqBtdO7k3aqOALtkRRVnqB2wxsA== X-Google-Smtp-Source: ADUXVKJaBAMUAME0WoR58IrYcwMfr1qnoovK4ayEa2WfcnWH12CiE4JS8/9mBk9fAf5BSUPAQCvi/w== X-Received: by 2002:a19:1f51:: with SMTP id f78-v6mr4205925lff.42.1527764409363; Thu, 31 May 2018 04:00:09 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b20-v6sm7454383ljf.51.2018.05.31.04.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 04:00:08 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Greg Kroah-Hartman , Jon Hunter , Geert Uytterhoeven , Todor Tomov , Rajendra Nayak , Viresh Kumar , Vincent Guittot , Kevin Hilman , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v3 2/5] PM / Domains: Don't attach devices in genpd with multi PM domains Date: Thu, 31 May 2018 12:59:56 +0200 Message-Id: <20180531105959.14843-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180531105959.14843-1-ulf.hansson@linaro.org> References: <20180531105959.14843-1-ulf.hansson@linaro.org> The power-domain DT property may now contain a list of PM domain specifiers, which represents that a device are partitioned across multiple PM domains. This leads to a new situation in genpd_dev_pm_attach(), as only one PM domain can be attached per device. To remain things simple for the most common configuration, when a single PM domain is used, let's treat the multiple PM domain case as being specific. In other words, let's change genpd_dev_pm_attach() to check for multiple PM domains and prevent it from attach any PM domain for this case. Instead, leave this to be managed separately, from following changes to genpd. Cc: Rob Herring Cc: devicetree@vger.kernel.org Suggested-by: Jon Hunter Signed-off-by: Ulf Hansson Acked-by: Jon Hunter Tested-by: Jon Hunter Reviewed-by: Viresh Kumar --- drivers/base/power/domain.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) -- 2.17.0 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 6f403d6fccb2..908c44779ae7 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2229,10 +2229,10 @@ static void genpd_dev_pm_sync(struct device *dev) * attaches the device to retrieved pm_domain ops. * * Returns 1 on successfully attached PM domain, 0 when the device don't need a - * PM domain or a negative error code in case of failures. Note that if a - * power-domain exists for the device, but it cannot be found or turned on, - * then return -EPROBE_DEFER to ensure that the device is not probed and to - * re-try again later. + * PM domain or when multiple power-domains exists for it, else a negative error + * code. Note that if a power-domain exists for the device, but it cannot be + * found or turned on, then return -EPROBE_DEFER to ensure that the device is + * not probed and to re-try again later. */ int genpd_dev_pm_attach(struct device *dev) { @@ -2243,10 +2243,18 @@ int genpd_dev_pm_attach(struct device *dev) if (!dev->of_node) return 0; + /* + * Devices with multiple PM domains must be attached separately, as we + * can only attach one PM domain per device. + */ + if (of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells") != 1) + return 0; + ret = of_parse_phandle_with_args(dev->of_node, "power-domains", "#power-domain-cells", 0, &pd_args); if (ret < 0) - return 0; + return ret; mutex_lock(&gpd_list_lock); pd = genpd_get_from_provider(&pd_args); From patchwork Thu May 31 10:59:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 137359 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6441346lji; Thu, 31 May 2018 04:00:11 -0700 (PDT) X-Received: by 2002:a2e:1414:: with SMTP id u20-v6mr5077399ljd.134.1527764411129; Thu, 31 May 2018 04:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527764411; cv=none; d=google.com; s=arc-20160816; b=CT2JSQDver9fSpmhe6Fv7DteZh+sSX05fIigmbopwumoRLTJGwQKlGUZIIctAmM597 kCusvdu/J7SlA3er7EzDI/dJYB9ZvqxD4muJLm16tmAEx2rRBmXMPE5sen12RUzEvtuf hukUeqZ2v/VdmXwzWLdwCF1kL5Kf9t5zOTYZQrXjNeKk4ncwcwythYilmxYgeP3gPNBb 1WYGwlkzU0DCeNFEGptZJ4ziOyhEPkHlJbQeL6URzY0ZmyyNKCGeA+qR88TmPyGFci7B PK0yg2QE7KCN3OekH86Pd0w3K5iKA+CizYWoX/44kR4rO3FpSVQVTICpv8fOjMZlCUPA hSgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=eylHfMyrO/9+jv2WsRax1wLQp9A/tGnl65WxWqbRgYM=; b=o+7U9W7zjIVCpZ8Vym9s4KCTCqZU9dON34inzsV3vgCgWHdNVyQY3YsQe+1fehh8ap lgYY2G1HY1Zur4wJarOtgCEawuE/AxMBojrOHaMiHR3m8YVwmjkbWdxhtdkNYWSYqLFq hLLxOaAesSxNUgCjvd8NihkwNa0kKG9UfeDoKKeRi+1OHwR0H/XX9gDCHiWAw7xlQAv/ 8HRaowRR59UhlC2ZMZHVoDx+VaCEqFe+jM9laPcOwq6cq/STVhmmfwQTwbtrO61kMlp7 f1ixzq4kF9Yfwka22kwGbaxxmGuHA6iOCShmgbj3TXTZZmfGOVw7s1fcyxhLHYPnm1VU LJdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3s8vCs8; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i17-v6sor160236lfc.61.2018.05.31.04.00.11 for (Google Transport Security); Thu, 31 May 2018 04:00:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3s8vCs8; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=eylHfMyrO/9+jv2WsRax1wLQp9A/tGnl65WxWqbRgYM=; b=Q3s8vCs8sJ+rMFaYeWFEe1HR97YFdU3B0ttZKsbP5H3AprT3sn2/XpRA9VITdFY138 eHS4NLSch/TcPPKNHi/QEYzySsaozO5VEPW2/xwTQYSDDwCFEocZ0H2MqgD0lQVk5JZG Y/YNxfsjMIuW4ki/rCAAnKDDl8/aMeamlK6y4= 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=eylHfMyrO/9+jv2WsRax1wLQp9A/tGnl65WxWqbRgYM=; b=cE/Wp7ecmK8ULAmeLkhNNnm9cjCA9VjNfApFH270TYGmhdzGE/DRluDMwsxLZ85Ug1 FVPVHBzNTeB4blqsoXot8bk6T8XLo+oes4qc+vh5wmTiQYJKDxYE1PfZ+7YcoE9dtMLm mTH1o1b1oHWsgeAliDAWGuD0UIE2lnMhSiJRQlqTFpc5gfIUAKWpeDIdjOJ11ty964Ne H3KD9Sqq1+iVijrxOCGfHFjf2RgsNA3DFIpFOuMcnLo6XHZ+jjKaT1psBp+nPYAgrT17 gSxYGoYWJEY8FnyZ2ijwcsFgeGELPyMIYGs0kKB19+tsX1addkcVJ3g9U8RZwmFAFuzT Tgzw== X-Gm-Message-State: ALKqPwf6sYEGM9TvRSx3AntI1cxZd+lrm6PHXoMNlK+iqeuU/+Q6Yyvu O+LN3yeewOizGJw5nBVZzO36iZU0o2DsEA== X-Google-Smtp-Source: ADUXVKLrSr5wyw2yMUlV9FRYkbooKC5gewusQUuJJVyOmDsfgiaIpf6BJyC9wZByqujKM8zCb5Q1uA== X-Received: by 2002:a19:151d:: with SMTP id l29-v6mr4169149lfi.106.1527764410904; Thu, 31 May 2018 04:00:10 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b20-v6sm7454383ljf.51.2018.05.31.04.00.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 04:00:10 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Greg Kroah-Hartman , Jon Hunter , Geert Uytterhoeven , Todor Tomov , Rajendra Nayak , Viresh Kumar , Vincent Guittot , Kevin Hilman , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org Subject: [PATCH v3 3/5] PM / Domains: Split genpd_dev_pm_attach() Date: Thu, 31 May 2018 12:59:57 +0200 Message-Id: <20180531105959.14843-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180531105959.14843-1-ulf.hansson@linaro.org> References: <20180531105959.14843-1-ulf.hansson@linaro.org> To extend genpd to deal with allowing multiple PM domains per device, some of the code in genpd_dev_pm_attach() can be re-used. Let's prepare for this by moving some of the code into a sub-function. Signed-off-by: Ulf Hansson Acked-by: Jon Hunter Tested-by: Jon Hunter Reviewed-by: Viresh Kumar --- drivers/base/power/domain.c | 60 ++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 27 deletions(-) -- 2.17.0 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 908c44779ae7..b1fcbf917974 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2221,38 +2221,15 @@ static void genpd_dev_pm_sync(struct device *dev) genpd_queue_power_off_work(pd); } -/** - * genpd_dev_pm_attach - Attach a device to its PM domain using DT. - * @dev: Device to attach. - * - * Parse device's OF node to find a PM domain specifier. If such is found, - * attaches the device to retrieved pm_domain ops. - * - * Returns 1 on successfully attached PM domain, 0 when the device don't need a - * PM domain or when multiple power-domains exists for it, else a negative error - * code. Note that if a power-domain exists for the device, but it cannot be - * found or turned on, then return -EPROBE_DEFER to ensure that the device is - * not probed and to re-try again later. - */ -int genpd_dev_pm_attach(struct device *dev) +static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np, + unsigned int index) { struct of_phandle_args pd_args; struct generic_pm_domain *pd; int ret; - if (!dev->of_node) - return 0; - - /* - * Devices with multiple PM domains must be attached separately, as we - * can only attach one PM domain per device. - */ - if (of_count_phandle_with_args(dev->of_node, "power-domains", - "#power-domain-cells") != 1) - return 0; - - ret = of_parse_phandle_with_args(dev->of_node, "power-domains", - "#power-domain-cells", 0, &pd_args); + ret = of_parse_phandle_with_args(np, "power-domains", + "#power-domain-cells", index, &pd_args); if (ret < 0) return ret; @@ -2290,6 +2267,35 @@ int genpd_dev_pm_attach(struct device *dev) return ret ? -EPROBE_DEFER : 1; } + +/** + * genpd_dev_pm_attach - Attach a device to its PM domain using DT. + * @dev: Device to attach. + * + * Parse device's OF node to find a PM domain specifier. If such is found, + * attaches the device to retrieved pm_domain ops. + * + * Returns 1 on successfully attached PM domain, 0 when the device don't need a + * PM domain or when multiple power-domains exists for it, else a negative error + * code. Note that if a power-domain exists for the device, but it cannot be + * found or turned on, then return -EPROBE_DEFER to ensure that the device is + * not probed and to re-try again later. + */ +int genpd_dev_pm_attach(struct device *dev) +{ + if (!dev->of_node) + return 0; + + /* + * Devices with multiple PM domains must be attached separately, as we + * can only attach one PM domain per device. + */ + if (of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells") != 1) + return 0; + + return __genpd_dev_pm_attach(dev, dev->of_node, 0); +} EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); static const struct of_device_id idle_state_match[] = { From patchwork Thu May 31 10:59:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 137360 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6441374lji; Thu, 31 May 2018 04:00:12 -0700 (PDT) X-Received: by 2002:a19:de0a:: with SMTP id v10-v6mr3848775lfg.94.1527764412860; Thu, 31 May 2018 04:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527764412; cv=none; d=google.com; s=arc-20160816; b=Eh5Nxp5ok251G+qw+XMLMvjGuf22S4VwRCM0uk84TALV+XTP1IBzc9rZzXDWfnNmwf 5OlvuT4mL4mnFhipGeqK7tv03O4bb+1AQflQnCPhn2MDv3GldwYj5207EUu0/+unB/hq ufMrBoKr03blw5z12WlbjD7Z+6pCLli9/Rb4xZXjRr2NZNre6QtI/p3GCdE7wJhPa3DJ whXIe4gPND5zrLNMNIG7bMW+QRaz1bfexqtp+XntJ23dCRY6msANphm+1xxP8f0dhwZR cZlCeYRkQ0W17UNU7e08ZsEyhqZfbvCuPtOkA9GIRW4qwBCr2FGQ5rRmD563HuDyt1PA ImZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=PNYOIw9NEsuNENF5roerUbH6PEOPf9UriVVq7srO1ao=; b=rG/qswjQi/aOz9cSPBiShJdvH3nVJbUdMsO3WY1eQPB0NLKIHd/ZMVDxkj50JkpzF4 qzjWxel9I8Z/RIDyg3sPDuhlWPuOnbKnHv9Xnzpth4s78tziWWCct85pqsIs6B6DYQwY yxAVyd977y7aHajuGhcOI/Wpt7MQuBB/Nb9QQnJsZuLyzSah2zqZr3hLyziNF6w3qvj8 y2kilvv+/8YfazzJNAN8ILAvUYS3Ar67v5Hiz/SGXa+vxds93qax600/dR1sVfP+4qIN 1ucDjTcia+HTFc5Q25BV6XdqJ88i0afInMB8WeX/s+8kun7/1p7OwltmDHL5UVeMA9Xj ECwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C2m386/Z; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a76-v6sor8310206lfa.79.2018.05.31.04.00.12 for (Google Transport Security); Thu, 31 May 2018 04:00:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C2m386/Z; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=PNYOIw9NEsuNENF5roerUbH6PEOPf9UriVVq7srO1ao=; b=C2m386/ZCM+hg1E2O+VE+FkwYAtu5xNQ26xZF9Fz8mG+u6jkyFahRscn4u+LZRuyN/ ipQ18eKIs+dfRnSlXO3Zxaht2kUjOxyf/ifF+yE4gUqKkzZWUfGAi7AAOTsaOuHbWWG4 65DOfsmdxnrwiQ/5BtwmNEKi09XL5ri93Cmpw= 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=PNYOIw9NEsuNENF5roerUbH6PEOPf9UriVVq7srO1ao=; b=BmvUtxPsFnPGmbgsoXDSCO803a/zu1PqO50sKKtJq8DnD3m/URV42Hj+2eH7UGDk55 R2ACJkK54Nakkb/tjc/ACkVq2+LBfXTApi1oGQYwZnzBbNoRMwyFX1Y/hD9EDbu47ceG qYWhVvnN/04wvseyfZe9LpK504OEIm/rX2DbT9aY+65W2lv8UtqsvM9XV1DzpPv7mqoB rCkkd1efUbkdlsH8AWJU42zjlgF27hhs+ADp8YheUM5aWI2OSQDERuOuSx2XlNQ4porl 1vAb4NwGcK2o23lwS7UomVeoY4pgvyjTQRwsN6IgBRyDjazHaQKTfWGqCpBQwkongAeJ NFMA== X-Gm-Message-State: ALKqPwcLmBup3UPjWaTPK++fI9i9UMKFC0U8UBt09M9V0nJZQd0Zx5+R ULBdCnLcN2ziVxwU4cs37cIH5ZOa X-Google-Smtp-Source: ADUXVKJuk4Gi5a4S+ThnajpbClUgsgcJqET+6SIyP7UDuFt9kiFWKtUUYGPN5weYlJr7YDLgQrH2Sg== X-Received: by 2002:a19:f611:: with SMTP id x17-v6mr4141689lfe.116.1527764412581; Thu, 31 May 2018 04:00:12 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b20-v6sm7454383ljf.51.2018.05.31.04.00.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 04:00:11 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Greg Kroah-Hartman , Jon Hunter , Geert Uytterhoeven , Todor Tomov , Rajendra Nayak , Viresh Kumar , Vincent Guittot , Kevin Hilman , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org Subject: [PATCH v3 4/5] PM / Domains: Add support for multi PM domains per device to genpd Date: Thu, 31 May 2018 12:59:58 +0200 Message-Id: <20180531105959.14843-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180531105959.14843-1-ulf.hansson@linaro.org> References: <20180531105959.14843-1-ulf.hansson@linaro.org> To support devices being partitioned across multiple PM domains, let's begin with extending genpd to cope with these kind of configurations. Therefore, add a new exported function genpd_dev_pm_attach_by_id(), which is similar to the existing genpd_dev_pm_attach(), but with the difference that it allows its callers to provide an index to the PM domain that it wants to attach. Note that, genpd_dev_pm_attach_by_id() shall only be called by the driver core / PM core, similar to how the existing dev_pm_domain_attach() makes use of genpd_dev_pm_attach(). However, this is implemented by following changes on top. Because, only one PM domain can be attached per device, genpd needs to create a virtual device that it can attach/detach instead. More precisely, let the new function genpd_dev_pm_attach_by_id() register a virtual struct device via calling device_register(). Then let it attach this device to the corresponding PM domain, rather than the one that is provided by the caller. The actual attaching is done via re-using the existing genpd OF functions. At successful attachment, genpd_dev_pm_attach_by_id() returns the created virtual device, which allows the caller to operate on it to deal with power management. Following changes on top, provides more details in this regards. To deal with detaching of a PM domain for the multiple PM domains case, let's also extend the existing genpd_dev_pm_detach() function, to cover the cleanup of the created virtual device, via make it call device_unregister() on it. In this way, there is no need to introduce a new function to deal with detach for the multiple PM domain case, but instead the existing one is re-used. Signed-off-by: Ulf Hansson Acked-by: Jon Hunter Tested-by: Jon Hunter Reviewed-by: Viresh Kumar --- drivers/base/power/domain.c | 80 +++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 8 ++++ 2 files changed, 88 insertions(+) -- 2.17.0 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index b1fcbf917974..4925af5c4cf0 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2171,6 +2171,15 @@ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) } EXPORT_SYMBOL_GPL(of_genpd_remove_last); +static void genpd_release_dev(struct device *dev) +{ + kfree(dev); +} + +static struct bus_type genpd_bus_type = { + .name = "genpd", +}; + /** * genpd_dev_pm_detach - Detach a device from its PM domain. * @dev: Device to detach. @@ -2208,6 +2217,10 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off) /* Check if PM domain can be powered off after removing this device. */ genpd_queue_power_off_work(pd); + + /* Unregister the device if it was created by genpd. */ + if (dev->bus == &genpd_bus_type) + device_unregister(dev); } static void genpd_dev_pm_sync(struct device *dev) @@ -2298,6 +2311,67 @@ int genpd_dev_pm_attach(struct device *dev) } EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); +/** + * genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains. + * @dev: The device used to lookup the PM domain. + * @index: The index of the PM domain. + * + * Parse device's OF node to find a PM domain specifier at the provided @index. + * If such is found, creates a virtual device and attaches it to the retrieved + * pm_domain ops. To deal with detaching of the virtual device, the ->detach() + * callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach(). + * + * Returns the created virtual device if successfully attached PM domain, NULL + * when the device don't need a PM domain, else an ERR_PTR() in case of + * failures. If a power-domain exists for the device, but cannot be found or + * turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device + * is not probed and to re-try again later. + */ +struct device *genpd_dev_pm_attach_by_id(struct device *dev, + unsigned int index) +{ + struct device *genpd_dev; + int num_domains; + int ret; + + if (!dev->of_node) + return NULL; + + /* Deal only with devices using multiple PM domains. */ + num_domains = of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells"); + if (num_domains < 2 || index >= num_domains) + return NULL; + + /* Allocate and register device on the genpd bus. */ + genpd_dev = kzalloc(sizeof(*genpd_dev), GFP_KERNEL); + if (!genpd_dev) + return ERR_PTR(-ENOMEM); + + dev_set_name(genpd_dev, "genpd:%u:%s", index, dev_name(dev)); + genpd_dev->bus = &genpd_bus_type; + genpd_dev->release = genpd_release_dev; + + ret = device_register(genpd_dev); + if (ret) { + kfree(genpd_dev); + return ERR_PTR(ret); + } + + /* Try to attach the device to the PM domain at the specified index. */ + ret = __genpd_dev_pm_attach(genpd_dev, dev->of_node, index); + if (ret < 1) { + device_unregister(genpd_dev); + return ret ? ERR_PTR(ret) : NULL; + } + + pm_runtime_set_active(genpd_dev); + pm_runtime_enable(genpd_dev); + + return genpd_dev; +} +EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id); + static const struct of_device_id idle_state_match[] = { { .compatible = "domain-idle-state", }, { } @@ -2457,6 +2531,12 @@ unsigned int of_genpd_opp_to_performance_state(struct device *dev, } EXPORT_SYMBOL_GPL(of_genpd_opp_to_performance_state); +static int __init genpd_bus_init(void) +{ + return bus_register(&genpd_bus_type); +} +core_initcall(genpd_bus_init); + #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 42e0d649e653..82458e8e2e01 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -237,6 +237,8 @@ unsigned int of_genpd_opp_to_performance_state(struct device *dev, struct device_node *opp_node); int genpd_dev_pm_attach(struct device *dev); +struct device *genpd_dev_pm_attach_by_id(struct device *dev, + unsigned int index); #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ static inline int of_genpd_add_provider_simple(struct device_node *np, struct generic_pm_domain *genpd) @@ -282,6 +284,12 @@ static inline int genpd_dev_pm_attach(struct device *dev) return 0; } +static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev, + unsigned int index) +{ + return NULL; +} + static inline struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) { From patchwork Thu May 31 10:59:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 137361 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6441396lji; Thu, 31 May 2018 04:00:14 -0700 (PDT) X-Received: by 2002:a2e:9ac4:: with SMTP id p4-v6mr1119772ljj.60.1527764414637; Thu, 31 May 2018 04:00:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527764414; cv=none; d=google.com; s=arc-20160816; b=ja51FGHrB0ZuAKBKG5x+yuzzXaOjLA5RwcesnySU1DljU/3mKAL0MRv9h3Uw4VZ5qb VeOR4yx7z7UIv0spQrUku19l7gl7EFZX3DCFai1H6fVMcx1/BoPgJJ+OnC5ZhqjDJbsy iuk5dztEpqYDK/eZ6CzRqZnSsTatSAUF/dxlop3FKZjHUBptonRW1W+RdRc1fWMdUsDT pQlNFlMHMTdMDhxE8ZhbTmDrWN8/JZylIcZC3MsNp69gFFJFawhpkSAr+iCc97RJXCtH rbImKv3jYeF+73x36ItFzbawkZXPbhiQS6rv02HHKy0kX4ZYEwvJdTZWtTGTbEzRJ0YN o9gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=cWUDGKzaf3nKb2Zo8t5+5svs98XA+o/lGIHL4mv1YHE=; b=hEchBT3eJgOEa2X5t9EQkItgYApebwOn02sOjhkuNOWlcEi7K1s+2tbPd8MR9F7Zva u1/KKaN/seibaTUL/rlx15beLsvIL3SiaJ6YHu96bCEman3lf70Tbn5BSQzGiIr6VUmJ c/NybPAHq3RcYUrvbmfQKmyIqDzEBOBGuDhTAv0UWwKxJKdWQhU4a7VOxopdPyKFotrU ve3g5PeK8N26EnSjvJJOdBWgZx5noEYnHfs3xa3yJOyC4M5zpmH1HZvOFr/XmYVGhHc/ JcreWhqS/99jd2m0xegI7ktk6RPoN0FgJPc+oEDV5hxTczJ3Bkg3u0TTsdwwKgKXbrIK dKyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LGSJB2u3; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k19-v6sor6680589lfj.80.2018.05.31.04.00.14 for (Google Transport Security); Thu, 31 May 2018 04:00:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LGSJB2u3; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=cWUDGKzaf3nKb2Zo8t5+5svs98XA+o/lGIHL4mv1YHE=; b=LGSJB2u3Ty6A07G4YdCMukVUH6MT8eEXJSbM5G73Ckip4UaXDeIdXxAJBEOJtmamcS +tctrSqKQHlJnsWB96z8jjBJW0FDps1J3oXu/FTJ1OzmdZLaPXJ4BW3owGwjS473rxjc 74TcYkvqs64lHUlg37Zr6USpwh8Lv/DKq5Okk= 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=cWUDGKzaf3nKb2Zo8t5+5svs98XA+o/lGIHL4mv1YHE=; b=dEX2IpH+R+Y0ZOTlckkLtzsOmgN9nMxHVvVnJ3ZOj3sSXw8nv7+RBU9jRgWoZfQkNr AB1HW717yMBxozDCPTFpd9mqnN2PQfAmLdH7+NyNQUyOl2a4cu0RN6T5NJHmtxR2u3EO Rll6AQ+JVlEpXxZlwvs6WbGuQJ1W+rXRLYT55sVKFT9lUbGeUNqYIfBlhkAlknJ4xR9M XW6hd1kN/ceLhUeRZ72J4DN7C6QgxBhfGoPZomofR7k9PoNafVC2bYDj+8piRlBLw1dK zu4gtFCHD9eGEIjV3WFhXlAMtYwT1YP0I7JZJYwRnbR+wRGLZpb8oN06cgkEV567gkYV V/9Q== X-Gm-Message-State: ALKqPwevDbaalsR+leon59jzuIVCBB/Fl3zB4JaVFgkcJkiip1fUYMAJ q3D9kOrRY5iF3wPUDQvWUgh3uHFN X-Google-Smtp-Source: ADUXVKIGQzNkabL2KsPiRHcdiTzt3kpedg7uT3BwPSDerc7DgjDhN8gpDYkbcw0Q1znCd1NCb0Rpmw== X-Received: by 2002:a19:e117:: with SMTP id y23-v6mr4062062lfg.9.1527764414336; Thu, 31 May 2018 04:00:14 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b20-v6sm7454383ljf.51.2018.05.31.04.00.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 04:00:13 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Greg Kroah-Hartman , Jon Hunter , Geert Uytterhoeven , Todor Tomov , Rajendra Nayak , Viresh Kumar , Vincent Guittot , Kevin Hilman , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org Subject: [PATCH v3 5/5] PM / Domains: Add dev_pm_domain_attach_by_id() to manage multi PM domains Date: Thu, 31 May 2018 12:59:59 +0200 Message-Id: <20180531105959.14843-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180531105959.14843-1-ulf.hansson@linaro.org> References: <20180531105959.14843-1-ulf.hansson@linaro.org> The existing dev_pm_domain_attach() function, allows a single PM domain to be attached per device. To be able to support devices that are partitioned across multiple PM domains, let's introduce a new interface, dev_pm_domain_attach_by_id(). The dev_pm_domain_attach_by_id() returns a new allocated struct device with the corresponding attached PM domain. This enables for example a driver to operate on the new device from a power management point of view. The driver may then also benefit from using the received device, to set up so called device-links towards its original device. Depending on the situation, these links may then be dynamically changed. The new interface is typically called by drivers during their probe phase, in case they manages devices which uses multiple PM domains. If that is the case, the driver also becomes responsible of managing the detaching of the PM domains, which typically should be done at the remove phase. Detaching is done by calling the existing dev_pm_domain_detach() function and for each of the received devices from dev_pm_domain_attach_by_id(). Note, currently its only genpd that supports multiple PM domains per device, but dev_pm_domain_attach_by_id() can easily by extended to cover other PM domain types, if/when needed. Signed-off-by: Ulf Hansson Acked-by: Jon Hunter Tested-by: Jon Hunter Reviewed-by: Viresh Kumar --- drivers/base/power/common.c | 43 ++++++++++++++++++++++++++++++++++--- include/linux/pm_domain.h | 7 ++++++ 2 files changed, 47 insertions(+), 3 deletions(-) -- 2.17.0 diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index 7ae62b6355b8..df41b4780b3b 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -116,14 +116,51 @@ int dev_pm_domain_attach(struct device *dev, bool power_on) } EXPORT_SYMBOL_GPL(dev_pm_domain_attach); +/** + * dev_pm_domain_attach_by_id - Associate a device with one of its PM domains. + * @dev: The device used to lookup the PM domain. + * @index: The index of the PM domain. + * + * As @dev may only be attached to a single PM domain, the backend PM domain + * provider creates a virtual device to attach instead. If attachment succeeds, + * the ->detach() callback in the struct dev_pm_domain are assigned by the + * corresponding backend attach function, as to deal with detaching of the + * created virtual device. + * + * This function should typically be invoked by a driver during the probe phase, + * in case its device requires power management through multiple PM domains. The + * driver may benefit from using the received device, to configure device-links + * towards its original device. Depending on the use-case and if needed, the + * links may be dynamically changed by the driver, which allows it to control + * the power to the PM domains independently from each other. + * + * Callers must ensure proper synchronization of this function with power + * management callbacks. + * + * Returns the virtual created device when successfully attached to its PM + * domain, NULL in case @dev don't need a PM domain, else an ERR_PTR(). + * Note that, to detach the returned virtual device, the driver shall call + * dev_pm_domain_detach() on it, typically during the remove phase. + */ +struct device *dev_pm_domain_attach_by_id(struct device *dev, + unsigned int index) +{ + if (dev->pm_domain) + return ERR_PTR(-EEXIST); + + return genpd_dev_pm_attach_by_id(dev, index); +} +EXPORT_SYMBOL_GPL(dev_pm_domain_attach_by_id); + /** * dev_pm_domain_detach - Detach a device from its PM domain. * @dev: Device to detach. * @power_off: Used to indicate whether we should power off the device. * - * This functions will reverse the actions from dev_pm_domain_attach() and thus - * try to detach the @dev from its PM domain. Typically it should be invoked - * from subsystem level code during the remove phase. + * This functions will reverse the actions from dev_pm_domain_attach() and + * dev_pm_domain_attach_by_id(), thus it detaches @dev from its PM domain. + * Typically it should be invoked during the remove phase, either from + * subsystem level code or from drivers. * * Callers must ensure proper synchronization of this function with power * management callbacks. diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 82458e8e2e01..9206a4fef9ac 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -299,6 +299,8 @@ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) #ifdef CONFIG_PM int dev_pm_domain_attach(struct device *dev, bool power_on); +struct device *dev_pm_domain_attach_by_id(struct device *dev, + unsigned int index); void dev_pm_domain_detach(struct device *dev, bool power_off); void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); #else @@ -306,6 +308,11 @@ static inline int dev_pm_domain_attach(struct device *dev, bool power_on) { return 0; } +static inline struct device *dev_pm_domain_attach_by_id(struct device *dev, + unsigned int index) +{ + return NULL; +} static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} static inline void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd) {}