Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2649540ybf; Mon, 2 Mar 2020 12:58:52 -0800 (PST) X-Google-Smtp-Source: ADFU+vvWV2/C2V3PNqPJpOuWvlMFnQ4nCe0WCunmU8HbSi/OUkfQvyNycbr5ICz9BhinvYXfd8oc X-Received: by 2002:a9d:7d87:: with SMTP id j7mr783430otn.159.1583182732176; Mon, 02 Mar 2020 12:58:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1583182732; cv=pass; d=google.com; s=arc-20160816; b=OI2eavwwWcZpEwOca0rra2iSIdi7f0+lGAikzjxCOXlR8BXrei4auvWK7dx7PWTT3a 0PHWB2N6Qkek1YbYNQSjAZZs2fiGlVSn3h/Nl/8hYJATNXjpGp1pwikJhFYEA3PDdomF tguu0G7QhDxaKRceTXcZdziEAy+0Vbmq7bSxzMPio6xa2UcXlb/klG7VLJPLuyX5hKX+ dUA2kb2lEOFr/0oYuoRm7kYvpuGHdwyNVtLFsAXN4oNVtqY7e35gNu8ffEuDYcVLEFlb gAJhzFhEWvg/OuPMDJOsPhK1YBZmPDiydsbTTK2170iM4ANC/1/iJuRKwNJ7SVqr3X6v cx0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=EFfcAXEU3F7FxlDk2Im7xjB1qQVJKbPG3CV/CSaQVl8=; b=Kcy0z+ccszSJReglE+7PVAJkcEQ9e3GZ1BRToT7Qv/j4BlSE6zqbgJLyZC5RPuOjbN STn8qzBEEEaMo+KGAUNOFrkq3dm18fZhY0cnCxvu13Jv8BYgM6QtADo1my0ZzLUbwcl/ buTViPpjFxs6sctEMdDFypgf0RUyB3kYXJqq21L6GGC5Jn/8b6cM5D0+0lwT+ZKCzGGF UzAoALqNRZv33c1O79zaHCBkH+2defncTLsOuqIdCuCYsRv6J3D9Fupu2Aup4be+CsSM 2xtxDj/aTrocq0shu7UuDUGMwT8YSb+lSNmrLUWc4mVEbsLGTzkcRvNkI31bb8Y5SSg/ 81RA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=L6kvdPU5; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v81si6196704oia.114.2020.03.02.12.58.39; Mon, 02 Mar 2020 12:58:52 -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; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=L6kvdPU5; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726901AbgCBU5p (ORCPT + 99 others); Mon, 2 Mar 2020 15:57:45 -0500 Received: from mail-eopbgr50043.outbound.protection.outlook.com ([40.107.5.43]:50336 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726728AbgCBU5o (ORCPT ); Mon, 2 Mar 2020 15:57:44 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MGeucfAVSazP5QB1RZZMg5Oxmwky2x62Imv1CJitoPe7GqjB2ZvLghLb8297yWeJPbphnk72Qn8VbATe4oFg3d8PZrZal6arqAvPJkYeKVfod0ZQcBGOEqLBnH57F1zJyFW5x2eLg1qd/sFQXjPLT2xxVKD5LqaNgIFRdXLPQieUorkSwlHrWytxvn6sJD7GSImAoyDYNn/CVE5tpCU3EDCQRmct1H2vyl9C1vHSAJtrt1Jfx4qDd/jU6YhHr47gxWR4MapFhCz8A9M+IMUYx4U78mA/4H5AjJTyMc190v65Y5XSJnuXBC3wjX2jbXTxbDcszmoGwFCPn8E5jnr0Lg== 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-SenderADCheck; bh=EFfcAXEU3F7FxlDk2Im7xjB1qQVJKbPG3CV/CSaQVl8=; b=dctLlaIs0P7m8dIAMrbKLzSmBfHfnP/D50uKx4ILlyGlNPM2ADtYCw+SL4O3OdKhwZaLwdK8DpfbyIYKZEY2gzY3kw2F3/25yZnUdHcOZTamEcoIQYSZL6/HrpjxNd/F3no9EqjNCOlTwx6xvYaBOHHF5Ncbo515JRlJ5kbuG122Z9rkD1tYQItgt8eRp58/OUFV52n+4NltVbpewtRN+e0hvoIt4Xelt+TreLuisik9MLpmVGCFH1eRDycfXF/2xfrPs8V3aMjqUaBAfZhR/vy7lOXnyS8tp9NYEIkq3k5nl+wYq8qLhGHg7xn4VAqQlN0H+u3ShhXoKR4YTp3UWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EFfcAXEU3F7FxlDk2Im7xjB1qQVJKbPG3CV/CSaQVl8=; b=L6kvdPU5vOhewDcQL7iGlmcxTyBa3pDGzRD636o2Ug8Vw0xIt2jjnR+h2jAyZGL9d+4hulWbA+F4LEv1c3nlQl1qQtVBf75kk6uuoN3NVftJ1u/RVWIvYYerIHUSfp1RsI0IBSrQ3vSvdSN/0faLpoFxntcjyCEfWlrYF3Fk/N4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=daniel.baluta@oss.nxp.com; Received: from VI1PR0402MB3839.eurprd04.prod.outlook.com (52.134.16.147) by VI1PR0402MB3453.eurprd04.prod.outlook.com (52.134.3.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.18; Mon, 2 Mar 2020 20:57:39 +0000 Received: from VI1PR0402MB3839.eurprd04.prod.outlook.com ([fe80::35d0:31bc:91d9:ceb0]) by VI1PR0402MB3839.eurprd04.prod.outlook.com ([fe80::35d0:31bc:91d9:ceb0%7]) with mapi id 15.20.2772.019; Mon, 2 Mar 2020 20:57:38 +0000 From: Daniel Baluta To: rjw@rjwysocki.net, len.brown@intel.com, pavel@ucw.cz Cc: gregkh@linuxfoundation.org, khilman@kernel.org, ulf.hansson@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, daniel.baluta@gmail.com, pierre-louis.bossart@linux.intel.com, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, aisheng.dong@nxp.com, shengjiu.wang@nxp.com, paul.olaru@nxp.com, ranjani.sridharan@linux.intel.com, Daniel Baluta Subject: [RFC PATCH 1/2] PM / domains: Introduce multi PM domains helpers Date: Mon, 2 Mar 2020 22:56:59 +0200 Message-Id: <20200302205700.29746-2-daniel.baluta@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200302205700.29746-1-daniel.baluta@oss.nxp.com> References: <20200302205700.29746-1-daniel.baluta@oss.nxp.com> Content-Type: text/plain X-ClientProxiedBy: AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) To VI1PR0402MB3839.eurprd04.prod.outlook.com (2603:10a6:803:21::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from fsr-ub1864-103.ro-buh02.nxp.com (89.37.124.34) by AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.15 via Frontend Transport; Mon, 2 Mar 2020 20:57:37 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [89.37.124.34] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 76787022-9d97-4803-3f69-08d7beec5780 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3453:|VI1PR0402MB3453: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(396003)(376002)(346002)(136003)(366004)(199004)(189003)(2906002)(26005)(6486002)(4326008)(6506007)(5660300002)(186003)(16526019)(478600001)(7416002)(6666004)(1076003)(2616005)(66946007)(66556008)(66476007)(44832011)(8936002)(8676002)(86362001)(81166006)(81156014)(6512007)(52116002)(956004)(316002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0402MB3453;H:VI1PR0402MB3839.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:0;MX:1; Received-SPF: None (protection.outlook.com: oss.nxp.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bEjqc1sxXIpkxiqIrs1/5Y98exNa75d6swjo2drG3oa/dcmfQLswrnR272uxunayBUvMG3Of/HzpqKZpvUJLMFFB5Wm5qez7/BKoJHb39dF3J5bwLf1dDs1AfOB5VCRXpFk4100VR5B06D2I1Jo329DiYCRmxwq2Hfbs1wQH9Bf0365z2kDLvxL0Y+y2dIJzCfr6H+CPX4Z9NE/9WWIbzxZwQGB8dlKiu8bRM0DHHASwdhtLMnRu4hGwPlP25ViQmRzZdW2iGcbLvTutcXiOw6sIDrNLgfu2/Dt4UgO2aLVnNzFvada+skdl7bpnvYq4ULQ6pX40JjjaEpeRPoDBy4xHJcEAXrskxKA4nKjPectJ9ivLDMPzRtUiAfGhKM/+5JfKxmzIfhhCzWUXsjO2sEZRt7cCgGFXGbac4XT5+HHbE4TDka+VGSueTOOqpX+p X-MS-Exchange-AntiSpam-MessageData: k5Or6yQZYLbQOfTe8dRa2g2vqZLCsuCDlkYlR0bYyeRAZJi0tDcFi7fqJWmPDZK4QHSDzZgAelP0SrE6GeGn8jLu5PHydokhDWfSDL5tr8E1uw9V6ruc4ckm9VGs0OJ5BCoyQsTPr/0e7Z187j8RYA== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76787022-9d97-4803-3f69-08d7beec5780 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2020 20:57:38.8564 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DGavOBA6qMMFuXQIm/SxOfElhO0ERe/bT5A4dFh3WaenfSqYYJNN5hVKGMUL0qTJMUtvfmAu3m5sCANPlaG5bw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3453 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Baluta This patch introduces helpers support for multi PM domains. API consists of: 1) dev_multi_pm_attach - powers up all PM domains associated with a given device. Because we can attach one PM domain per device, we create virtual devices (children of initial device) and associate PM domains one per virtual device. 2) dev_multi_pm_detach - detaches all virtual devices from PM domains attached with. Signed-off-by: Daniel Baluta --- drivers/base/power/common.c | 93 +++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 19 ++++++++ 2 files changed, 112 insertions(+) diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index bbddb267c2e6..a90cc6b476e4 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -228,3 +228,96 @@ void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd) device_pm_check_callbacks(dev); } EXPORT_SYMBOL_GPL(dev_pm_domain_set); + +/** + * dev_multi_pm_attach - power up device associated power domains + * @dev: The device used to lookup the PM domains + * + * Parse device's OF node to find all PM domains specifiers. For each power + * domain found, create a virtual device and associate it with the + * current power domain. + * + * This function should typically be invoked by a driver during the + * probe phase, in the case its device requires power management through + * multiple PM domains. + * + * Returns a pointer to @dev_multi_pm_domain_data if successfully attached PM + * domains, NULL if 0 or 1 PM domains specified, else an ERR_PTR() in case of + * failures. + */ +struct dev_multi_pm_domain_data *dev_multi_pm_attach(struct device *dev) +{ + struct dev_multi_pm_domain_data *mpd, *retp; + int num_domains; + int i; + + num_domains = of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells"); + if (num_domains < 2) + return NULL; + + mpd = devm_kzalloc(dev, GFP_KERNEL, sizeof(*mpd)); + if (!mpd) + return ERR_PTR(-ENOMEM); + + mpd->dev = dev; + mpd->num_domains = num_domains; + + mpd->virt_devs = devm_kmalloc_array(dev, mpd->num_domains, + sizeof(*mpd->virt_devs), + GFP_KERNEL); + if (!mpd->virt_devs) + return ERR_PTR(-ENOMEM); + + mpd->links = devm_kmalloc_array(dev, mpd->num_domains, + sizeof(*mpd->links), GFP_KERNEL); + if (!mpd->links) + return ERR_PTR(-ENOMEM); + + for (i = 0; i < mpd->num_domains; i++) { + mpd->virt_devs[i] = dev_pm_domain_attach_by_id(dev, i); + if (IS_ERR(mpd->virt_devs[i])) { + retp = (struct dev_multi_pm_domain_data *) + mpd->virt_devs[i]; + goto exit_unroll_pm; + } + mpd->links[i] = device_link_add(dev, mpd->virt_devs[i], + DL_FLAG_STATELESS | + DL_FLAG_PM_RUNTIME | + DL_FLAG_RPM_ACTIVE); + if (!mpd->links[i]) { + retp = ERR_PTR(-ENOMEM); + dev_pm_domain_detach(mpd->virt_devs[i], false); + goto exit_unroll_pm; + } + } + return mpd; + +exit_unroll_pm: + while (--i >= 0) { + device_link_del(mpd->links[i]); + dev_pm_domain_detach(mpd->virt_devs[i], false); + } + + return retp; +} +EXPORT_SYMBOL(dev_multi_pm_attach); + +/** + * dev_multi_pm_detach - Detach a device from its PM domains. + * Each multi power domain is attached to a virtual children device + * + * @mpd: multi power domains data, contains the association between + * virtul device and PM domain + * + */ +void dev_multi_pm_detach(struct dev_multi_pm_domain_data *mpd) +{ + int i; + + for (i = 0; i < mpd->num_domains; i++) { + device_link_del(mpd->links[i]); + dev_pm_domain_detach(mpd->virt_devs[i], false); + } +} +EXPORT_SYMBOL(dev_multi_pm_detach); diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 9ec78ee53652..5bcb35150af2 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -183,6 +183,13 @@ struct generic_pm_domain_data { void *data; }; +struct dev_multi_pm_domain_data { + struct device *dev; /* parent device */ + struct device **virt_devs; /* virtual children links */ + struct device_link **links; /* links parent <-> virtual children */ + int num_domains; +}; + #ifdef CONFIG_PM_GENERIC_DOMAINS static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd) { @@ -369,18 +376,27 @@ 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 dev_multi_pm_domain_data *dev_multi_pm_attach(struct device *dev); struct device *dev_pm_domain_attach_by_id(struct device *dev, unsigned int index); struct device *dev_pm_domain_attach_by_name(struct device *dev, const char *name); void dev_pm_domain_detach(struct device *dev, bool power_off); int dev_pm_domain_start(struct device *dev); +void dev_multi_pm_detach(struct dev_multi_pm_domain_data *mpd); void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); + #else static inline int dev_pm_domain_attach(struct device *dev, bool power_on) { return 0; } + +struct dev_multi_pm_domain_data *dev_multi_pm_attach(struct device *dev) +{ + return NULL; +} + static inline struct device *dev_pm_domain_attach_by_id(struct device *dev, unsigned int index) { @@ -396,6 +412,9 @@ static inline int dev_pm_domain_start(struct device *dev) { return 0; } + +void dev_multi_pm_detach(struct dev_multi_pm_domain_data *mpd) {} + static inline void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd) {} #endif -- 2.17.1