From patchwork Fri Jan 5 16:00:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13512352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC625C3DA6E for ; Fri, 5 Jan 2024 16:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=czlEDbOocx+hv+9w3aeXjq/ZPftRsnviBkohxrPVGzA=; b=4brvwoiwL7qDbr N8p/JWobStk6KWbQ0tZVMW0jo99YSkYn5BCuEO9amhQbD2OgE8gzVkY8BiUKXO3ZIwraX9TI2Ind3 jgZlWa6A9GveQH2Ku4hyU7IQl3XePOMYXf5YDzq3T0FOAIqXwiYM8crcex9g/VSB/oU/46hiFcjXw WQ5jIAFHaf7/CkTaKGUmgguhwUGLRlOr5QrZPhrx9A1+TiFHio7fNtbfk9DK6R+t/se3Akmk4ltMO 57unW4UBcSmuJsIB531OlGSJRot+YzF1ri5S6WBiQHr3VQtjldjAgbnOk0s8PJqFoZeQpFefdXgLc BPTe5mMAREkV0a7t5k6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdK-00HF7y-1M; Fri, 05 Jan 2024 16:01:18 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdH-00HF6m-11 for linux-arm-kernel@lists.infradead.org; Fri, 05 Jan 2024 16:01:17 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-50eaa8b447bso1908005e87.1 for ; Fri, 05 Jan 2024 08:01:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470471; x=1705075271; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wNI1Oz48vQp4Hm9jFsOT4f7J+mpAOH6qfd1BBsjKsaA=; b=x+9Bbz5dBA4UWt1dVkdiqfh1NFob5Ifgi7jhIbuGXXs46Z+zLAAPmuJgKaUi8YUMYF 2xq6+/7Mc03zB49kgV8XmYvGdnnefaT4KW43DlfOT5DIleKvx7b0WkToSnEMavTTYVLj WVVcIgb/e86i9CNYX8P4vbbgrKlzyjTMt1T3JhMDQe7VnLlUq4scw6UaP7dRGrblXpmd H6l5sUQKDfi+lW8QVu9qL+HSrJlcHu5hXJ82MzBN83sgGwodkV8Y/U2EAgURSxSqsJc0 M8RjUPNBxj0bMIOanyMpJ4VNEHAWv9pfaEK/qrwwuj/pMpI5Aa4TQzYa4d2vOzAqUkjv ZB/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470471; x=1705075271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wNI1Oz48vQp4Hm9jFsOT4f7J+mpAOH6qfd1BBsjKsaA=; b=JC/qbTQvfJCD9KSIYS0lV38sPOlgPCd5kYdNrPc2iQfUjAB4l9ou1rcAKQ4cJd7h/0 OJMdT/sjpEc6yVelwluKs2ic7muZbjXkHUH8F0aT6ikBS6kI3CpnKz418B4wIFtaIocF ROFUq3cAdle/JXOJkYE1nlfQcO/bn5jAL9AcsR0rgmehYFfKDeTGv5z468xCokIgkhyf LXLWPAmN7zZKBiwXo+dBLk57PGKt9+PGgTHGMyItKNYUqr+IB3pQErnE2bBU3P08jVjh /a3JmwlAnmaUp4K8ofZyZJONDlFMQw3I8xmR+seDoE+1T+6xMszrZnEkAhudoTSzIZqY ZEXA== X-Gm-Message-State: AOJu0YwWyQLBfglhNcsmGjJJmLPGPsg0oawjgLmYSnteaRynbnkHDKj0 XCQbUrvVdx1wH3tw5JOoiAnZOdREPDYJqA== X-Google-Smtp-Source: AGHT+IFyphGz0Q6uyDmpcy3w7sNGqS+rbaFWXqKPDqcO5gErHcQWSgNAzPhrs714QaypH8/gnwBgJg== X-Received: by 2002:a05:6512:75:b0:50e:7bbc:b678 with SMTP id i21-20020a056512007500b0050e7bbcb678mr619227lfo.17.1704470471425; Fri, 05 Jan 2024 08:01:11 -0800 (PST) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id n5-20020a056512310500b0050e76978861sm262094lfb.277.2024.01.05.08.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:01:10 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Greg Kroah-Hartman , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Sudeep Holla , Kevin Hilman , Konrad Dybcio , Bjorn Andersson , Nikunj Kela , Prasad Sodagudi , Stephan Gerhold , Ben Horgan , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-remoteproc@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 1/5] PM: domains: Add helper functions to attach/detach multiple PM domains Date: Fri, 5 Jan 2024 17:00:59 +0100 Message-Id: <20240105160103.183092-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105160103.183092-1-ulf.hansson@linaro.org> References: <20240105160103.183092-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240105_080115_357254_8C00152F X-CRM114-Status: GOOD ( 29.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Attaching/detaching of a device to multiple PM domains has started to become a common operation for many drivers, typically during ->probe() and ->remove(). In most cases, this has lead to lots of boilerplate code in the drivers. To fixup up the situation, let's introduce a pair of helper functions, dev_pm_domain_attach|detach_list(), that driver can use instead of the open-coding. Note that, it seems reasonable to limit the support for these helpers to DT based platforms, at it's the only valid use case for now. Signed-off-by: Ulf Hansson --- Changes in v2: - Fix NULL pointer bug pointed out by Nikunj. --- drivers/base/power/common.c | 134 ++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 38 ++++++++++ 2 files changed, 172 insertions(+) diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index 44ec20918a4d..327d168dd37a 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -167,6 +167,115 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev, } EXPORT_SYMBOL_GPL(dev_pm_domain_attach_by_name); +/** + * dev_pm_domain_attach_list - Associate a device with its PM domains. + * @dev: The device used to lookup the PM domains for. + * @data: The data used for attaching to the PM domains. + * @list: An out-parameter with an allocated list of attached PM domains. + * + * This function helps to attach a device to its multiple PM domains. The + * caller, which is typically a driver's probe function, may provide a list of + * names for the PM domains that we should try to attach the device to, but it + * may also provide an empty list, in case the attach should be done for all of + * the available PM domains. + * + * Callers must ensure proper synchronization of this function with power + * management callbacks. + * + * Returns the number of attached PM domains or a negative error code in case of + * a failure. Note that, to detach the list of PM domains, the driver shall call + * dev_pm_domain_detach_list(), typically during the remove phase. + */ +int dev_pm_domain_attach_list(struct device *dev, + const struct dev_pm_domain_attach_data *data, + struct dev_pm_domain_list **list) +{ + struct device_node *np = dev->of_node; + struct dev_pm_domain_list *pds; + struct device *pd_dev = NULL; + int ret, i, num_pds = 0; + bool by_id = true; + u32 pd_flags = data ? data->pd_flags : 0; + u32 link_flags = pd_flags & PD_FLAG_NO_DEV_LINK ? 0 : + DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME; + + if (dev->pm_domain) + return -EEXIST; + + /* For now this is limited to OF based platforms. */ + if (!np) + return 0; + + if (data && data->pd_names) { + num_pds = data->num_pd_names; + by_id = false; + } else { + num_pds = of_count_phandle_with_args(np, "power-domains", + "#power-domain-cells"); + } + + if (num_pds <= 0) + return 0; + + pds = devm_kzalloc(dev, sizeof(*pds), GFP_KERNEL); + if (!pds) + return -ENOMEM; + + pds->pd_devs = devm_kcalloc(dev, num_pds, sizeof(*pds->pd_devs), + GFP_KERNEL); + if (!pds->pd_devs) + return -ENOMEM; + + pds->pd_links = devm_kcalloc(dev, num_pds, sizeof(*pds->pd_links), + GFP_KERNEL); + if (!pds->pd_links) + return -ENOMEM; + + if (link_flags && pd_flags & PD_FLAG_DEV_LINK_ON) + link_flags |= DL_FLAG_RPM_ACTIVE; + + for (i = 0; i < num_pds; i++) { + if (by_id) + pd_dev = dev_pm_domain_attach_by_id(dev, i); + else + pd_dev = dev_pm_domain_attach_by_name(dev, + data->pd_names[i]); + if (IS_ERR_OR_NULL(pd_dev)) { + ret = pd_dev ? PTR_ERR(pd_dev) : -ENODEV; + goto err_attach; + } + + if (link_flags) { + struct device_link *link; + + link = device_link_add(dev, pd_dev, link_flags); + if (!link) { + ret = -ENODEV; + goto err_link; + } + + pds->pd_links[i] = link; + } + + pds->pd_devs[i] = pd_dev; + } + + pds->num_pds = num_pds; + *list = pds; + return num_pds; + +err_link: + dev_pm_domain_detach(pd_dev, true); +err_attach: + while (--i >= 0) { + if (pds->pd_links[i]) + device_link_del(pds->pd_links[i]); + dev_pm_domain_detach(pds->pd_devs[i], true); + } + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list); + /** * dev_pm_domain_detach - Detach a device from its PM domain. * @dev: Device to detach. @@ -187,6 +296,31 @@ void dev_pm_domain_detach(struct device *dev, bool power_off) } EXPORT_SYMBOL_GPL(dev_pm_domain_detach); +/** + * dev_pm_domain_detach_list - Detach a list of PM domains. + * @list: The list of PM domains to detach. + * + * This function reverse the actions from dev_pm_domain_attach_list(). + * Typically it should be invoked during the remove phase from drivers. + * + * Callers must ensure proper synchronization of this function with power + * management callbacks. + */ +void dev_pm_domain_detach_list(struct dev_pm_domain_list *list) +{ + int i; + + if (!list) + return; + + for (i = 0; i < list->num_pds; i++) { + if (list->pd_links[i]) + device_link_del(list->pd_links[i]); + dev_pm_domain_detach(list->pd_devs[i], true); + } +} +EXPORT_SYMBOL_GPL(dev_pm_domain_detach_list); + /** * dev_pm_domain_start - Start the device through its PM domain. * @dev: Device to start. diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 34663d0d5c55..6b71fb69c349 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -19,6 +19,33 @@ #include #include +/* + * Flags to control the behaviour when attaching a device to its PM domains. + * + * PD_FLAG_NO_DEV_LINK: As the default behaviour creates a device-link + * for every PM domain that gets attached, this + * flag can be used to skip that. + * + * PD_FLAG_DEV_LINK_ON: Add the DL_FLAG_RPM_ACTIVE to power-on the + * supplier and its PM domain when creating the + * device-links. + * + */ +#define PD_FLAG_NO_DEV_LINK BIT(0) +#define PD_FLAG_DEV_LINK_ON BIT(1) + +struct dev_pm_domain_attach_data { + const char * const *pd_names; + const u32 num_pd_names; + const u32 pd_flags; +}; + +struct dev_pm_domain_list { + struct device **pd_devs; + struct device_link **pd_links; + u32 num_pds; +}; + /* * Flags to control the behaviour of a genpd. * @@ -432,7 +459,11 @@ 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); +int dev_pm_domain_attach_list(struct device *dev, + const struct dev_pm_domain_attach_data *data, + struct dev_pm_domain_list **list); void dev_pm_domain_detach(struct device *dev, bool power_off); +void dev_pm_domain_detach_list(struct dev_pm_domain_list *list); int dev_pm_domain_start(struct device *dev); void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); int dev_pm_domain_set_performance_state(struct device *dev, unsigned int state); @@ -451,7 +482,14 @@ static inline struct device *dev_pm_domain_attach_by_name(struct device *dev, { return NULL; } +static inline int dev_pm_domain_attach_list(struct device *dev, + const struct dev_pm_domain_attach_data *data, + struct dev_pm_domain_list **list) +{ + return 0; +} static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} +static inline void dev_pm_domain_detach_list(struct dev_pm_domain_list *list) {} static inline int dev_pm_domain_start(struct device *dev) { return 0; From patchwork Fri Jan 5 16:01:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13512354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3CB96C47077 for ; Fri, 5 Jan 2024 16:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=V40Fg1l3qmYfJtzM8tbjcN3h7eviDSQ9Sv6omuM0uu8=; b=cNTVdsKuMURutr 0U62zHym4Zi0zaLP9tAk0V/jL09MCJFtRqRa7opkxSrmTkgUCtXJQCk0A729a3diVIPt5ETDAnhpa dbDdfY2cpA53fmGFgmK8KfBHS7AQ1sv6t8f9uQDnjv8LvSAIuE3jj2jON/5BkFXnb8Km3Ko4/+HkD p1VBvnolUTDO2zllYm62jKQXfp0wgpRWREvgd7jH5SKCRK7RSzZpj0NsMfBq/t6CL+HYBXkUt/Qck d5J0BNlFof8CBUUTw7V7v0LMbtjP35rbTSlN7TIj8EB8VlMYnkheQG7pmIU4VY/iSPVXK81VYhxZ2 lA/lF+zvdY6n+8iLywtA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdO-00HF9w-2a; Fri, 05 Jan 2024 16:01:22 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdL-00HF7Y-0s for linux-arm-kernel@lists.infradead.org; Fri, 05 Jan 2024 16:01:21 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-50eabfac2b7so1856557e87.0 for ; Fri, 05 Jan 2024 08:01:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470475; x=1705075275; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v4adrkCiXynUojze/iFBMYeb+HEd5tnQA25jx/jo/fM=; b=yh1NYFFK0UsMMywPHOqUR2hYzT85CfdgoUorMEV+aL9/aRRV4bEEbDl3HYAiLWFOIY mND090xwTfaKHBIanHsExERviuIMhpOeDmzAZjsFAmythOCqX/qv837zGs+/ZU8Npq+J Ihg/eqqGenHbyST1J+wsaimeEW9vyJ+k9yOZa6mS/UUB8lC71abW4/b5Gg0XQmZTGlHZ RqdOBkuW+tDJPbD0Az49ri/eoX++8aLxc82Z8xs2TamOEifGTD4X/igNz0amSw67n37m TTQWPNw7w32hmqUAlFLJEPy9Tsf6mxmzzbBZ3DrzrZWJFJX5Clq1AHmAQDPn9gAj4b0e Y6kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470475; x=1705075275; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v4adrkCiXynUojze/iFBMYeb+HEd5tnQA25jx/jo/fM=; b=aZ8IrfYLSeI69bU7rbKtqwcnSjXNzJFYM/7KD2QKmXpeNvtMG16YM6k8zAXTL3rjJk ziSYf52CO+CKAQFA9uYcgI5amK+qaQ9HCwHfMRsWBNUGWMD+BPH+HJMusx0KfUJ61iJA 1YeHewGMFW3iIigdURtrknX2cLE5NpksX6tIckHIZaupgkA/MboWhd7fuKBCUZvwYcNj 8J+M/KFSbYmzyPcAm5Dn4Cs8XOh0ROl6bM98eT5dcq1tZfAAjf1umop3uGaVwxrZcEw7 nsO6JGmpQ44cH1KBaBON3aKGGq91guLOTWNVNCWNqyMzh4Iv49flWxPr5GDBnt6x+UXV bzMg== X-Gm-Message-State: AOJu0YwO+vu9u4yEaDtgIcPMkqHABjDQAfAg9McX4urXFcoxs0XpgwsA qZ8pKW30/akwziWLXp3XQWK2P6YSjTVNsw== X-Google-Smtp-Source: AGHT+IGoYR9dNkx0TbEbTrZoz2zQHdVbLCqUuOHGn2IdJYr+CWUdepckfD72bhLcMFYSTGkVG//8iA== X-Received: by 2002:a19:6447:0:b0:50e:3d5b:cfef with SMTP id b7-20020a196447000000b0050e3d5bcfefmr869108lfj.53.1704470474915; Fri, 05 Jan 2024 08:01:14 -0800 (PST) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id n5-20020a056512310500b0050e76978861sm262094lfb.277.2024.01.05.08.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:01:12 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Greg Kroah-Hartman , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Sudeep Holla , Kevin Hilman , Konrad Dybcio , Bjorn Andersson , Nikunj Kela , Prasad Sodagudi , Stephan Gerhold , Ben Horgan , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-remoteproc@vger.kernel.org, linux-media@vger.kernel.org, Mathieu Poirier , Shawn Guo , Sascha Hauer , Iuliana Prodan , Daniel Baluta Subject: [PATCH v2 2/5] remoteproc: imx_dsp_rproc: Convert to dev_pm_domain_attach|detach_list() Date: Fri, 5 Jan 2024 17:01:00 +0100 Message-Id: <20240105160103.183092-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105160103.183092-1-ulf.hansson@linaro.org> References: <20240105160103.183092-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240105_080119_309683_6509D972 X-CRM114-Status: GOOD ( 20.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Let's avoid the boilerplate code to manage the multiple PM domain case, by converting into using dev_pm_domain_attach|detach_list(). Cc: Mathieu Poirier Cc: Bjorn Andersson Cc: Shawn Guo Cc: Sascha Hauer Cc: Iuliana Prodan Cc: Daniel Baluta Cc: Signed-off-by: Ulf Hansson Tested-by: Iuliana Prodan Reviewed-by: Iuliana Prodan --- Changes in v2: - None. Iuliana/Daniel I am ccing you to request help with test/review of this change. Note that, you will need patch 1/5 in the series too, to be able to test this. Kind regards Ulf Hansson --- drivers/remoteproc/imx_dsp_rproc.c | 82 ++++-------------------------- 1 file changed, 9 insertions(+), 73 deletions(-) diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c index 8fcda9b74545..0409b7c47d5c 100644 --- a/drivers/remoteproc/imx_dsp_rproc.c +++ b/drivers/remoteproc/imx_dsp_rproc.c @@ -103,12 +103,10 @@ enum imx_dsp_rp_mbox_messages { * @tx_ch: mailbox tx channel handle * @rx_ch: mailbox rx channel handle * @rxdb_ch: mailbox rx doorbell channel handle - * @pd_dev: power domain device - * @pd_dev_link: power domain device link + * @pd_list: power domain list * @ipc_handle: System Control Unit ipc handle * @rproc_work: work for processing virtio interrupts * @pm_comp: completion primitive to sync for suspend response - * @num_domains: power domain number * @flags: control flags */ struct imx_dsp_rproc { @@ -121,12 +119,10 @@ struct imx_dsp_rproc { struct mbox_chan *tx_ch; struct mbox_chan *rx_ch; struct mbox_chan *rxdb_ch; - struct device **pd_dev; - struct device_link **pd_dev_link; + struct dev_pm_domain_list *pd_list; struct imx_sc_ipc *ipc_handle; struct work_struct rproc_work; struct completion pm_comp; - int num_domains; u32 flags; }; @@ -954,74 +950,14 @@ static const struct rproc_ops imx_dsp_rproc_ops = { static int imx_dsp_attach_pm_domains(struct imx_dsp_rproc *priv) { struct device *dev = priv->rproc->dev.parent; - int ret, i; - - priv->num_domains = of_count_phandle_with_args(dev->of_node, - "power-domains", - "#power-domain-cells"); - - /* If only one domain, then no need to link the device */ - if (priv->num_domains <= 1) - return 0; - - priv->pd_dev = devm_kmalloc_array(dev, priv->num_domains, - sizeof(*priv->pd_dev), - GFP_KERNEL); - if (!priv->pd_dev) - return -ENOMEM; - - priv->pd_dev_link = devm_kmalloc_array(dev, priv->num_domains, - sizeof(*priv->pd_dev_link), - GFP_KERNEL); - if (!priv->pd_dev_link) - return -ENOMEM; - - for (i = 0; i < priv->num_domains; i++) { - priv->pd_dev[i] = dev_pm_domain_attach_by_id(dev, i); - if (IS_ERR(priv->pd_dev[i])) { - ret = PTR_ERR(priv->pd_dev[i]); - goto detach_pm; - } - - /* - * device_link_add will check priv->pd_dev[i], if it is - * NULL, then will break. - */ - priv->pd_dev_link[i] = device_link_add(dev, - priv->pd_dev[i], - DL_FLAG_STATELESS | - DL_FLAG_PM_RUNTIME); - if (!priv->pd_dev_link[i]) { - dev_pm_domain_detach(priv->pd_dev[i], false); - ret = -EINVAL; - goto detach_pm; - } - } - - return 0; - -detach_pm: - while (--i >= 0) { - device_link_del(priv->pd_dev_link[i]); - dev_pm_domain_detach(priv->pd_dev[i], false); - } - - return ret; -} - -static int imx_dsp_detach_pm_domains(struct imx_dsp_rproc *priv) -{ - int i; + int ret; - if (priv->num_domains <= 1) + /* A single PM domain is already attached. */ + if (dev->pm_domain) return 0; - for (i = 0; i < priv->num_domains; i++) { - device_link_del(priv->pd_dev_link[i]); - dev_pm_domain_detach(priv->pd_dev[i], false); - } - - return 0; + ret = dev_pm_domain_attach_list(dev, NULL, &priv->pd_list); + return ret < 0 ? ret : 0; } /** @@ -1153,7 +1089,7 @@ static int imx_dsp_rproc_probe(struct platform_device *pdev) return 0; err_detach_domains: - imx_dsp_detach_pm_domains(priv); + dev_pm_domain_detach_list(priv->pd_list); err_put_rproc: rproc_free(rproc); @@ -1167,7 +1103,7 @@ static void imx_dsp_rproc_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); rproc_del(rproc); - imx_dsp_detach_pm_domains(priv); + dev_pm_domain_detach_list(priv->pd_list); rproc_free(rproc); } From patchwork Fri Jan 5 16:01:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13512353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE6BCC47079 for ; Fri, 5 Jan 2024 16:01:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1h7mBwpAv1GG1ygRu8D/lF8uLEt7ePGmfH1+eJ7Hxww=; b=xW9QxQFvvJFewO 6iEu+sQkk2WvPBiLFH+0qOGQVOo8lIGpKgzYL2cDq2VASRYjeoH7We2jJtj6gPuXfq+PrN+LOXlHT W+Mq3GOqBiKQEE/Tofgh7yyE6MEo6zaAdlE8XaCzSIe125zYnAxGGmvEtPQqn6V+2ppKSzjgGGIdd 7REZgBvLJrxzPzaltcV4BGQGELR/d0VpHRKpUo0y57MlZd4fejIVgCtJbJZDmK/1WrWR1ITIESG7g ojFWviO89T1v7SakfXOgsyGn5S0mK783bqUTvBUw+qkBa75/8YRdkwgaDki0Q/soQc33N1dnigyf+ x2ESE+/3VFWmqHv3iT7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdQ-00HFAX-1D; Fri, 05 Jan 2024 16:01:24 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdN-00HF7x-22 for linux-arm-kernel@lists.infradead.org; Fri, 05 Jan 2024 16:01:23 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-50ea9daac4cso1963303e87.3 for ; Fri, 05 Jan 2024 08:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470478; x=1705075278; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+xTV3KNGUOJDAGwGlyDoyXQPDYV81EgjVZP/tKxx0pk=; b=FVGuwyNzuWrZs+8nlX24vWdQf/Wh2uN78HvIQZpofxAxEyoEQGn6e8omjzTogN1NIP O0bumfvf+9R13JTemvwBXf0HXcz8JR/DvvKR/hG/PMsFmkWWwwyu87Jg11LGcoVcwlPw e7KwiUyIbJhnvkRjVVQIUYUailxO4UYpS6hFouGuQnOrHC0US8IqFIqvmPZNcB3eLdDE UQ8RdSquA6h7MW5QgBl2NbkYjZyBfajf2hXF/OZg5pmcXD1WgZp/h3+yE1dfyw9q58yE nMOxCH0uq1SZJxF8MTwWs35+bxlpV6lpGfyXYiyTjkluH/qJOiy9o6fk9ZMG3e0pBtEy MAXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470478; x=1705075278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+xTV3KNGUOJDAGwGlyDoyXQPDYV81EgjVZP/tKxx0pk=; b=BTAJT7xF/2isSCpKrpDwr3JhAyAlr0Z2hbrXqMydswF00PWG8mXSvTd3+tqols4sac 7M2A6MlfU2OBHQGC4OBwFac59lTYNf8JzBjyehUUOFgQ25XMl/Jq6F9ZVu9ryXldRJL8 +DTjCqgPXczpMzK5K4jCgUnarpBNyY8zWsXLKYd5ZlNXilMlwYm/M7eLZ12Z3BY0jidN 37iVvpF6O3OKWjC5cfKwLY/QzXftaXLqsdUovpRwPs/+xVcmS2XM6ACLkNhfiTpDhSz8 KHdc3jKzgcvDVAs1B2T5mmjVW7MjhGJKYSUSRd4+MOyKXV210ttzcuJcXSXa/HwwwIVP Aqvw== X-Gm-Message-State: AOJu0YwgTy8YrbgwURKxWb+kUJPb6pRXzm15PO68pgoIAGvwn6fd+99y yXQ9vtgCLXDFckGWc9kKy09j2ofP+dRwoQ== X-Google-Smtp-Source: AGHT+IEhceusxqe38aK6YSRaF0oSmtJx101dr5UFrhN3EnDzMmqdMwFzHk96/G1pK1okalt2N+42DA== X-Received: by 2002:a05:6512:532:b0:50e:6e9f:bc89 with SMTP id o18-20020a056512053200b0050e6e9fbc89mr1038688lfc.104.1704470477717; Fri, 05 Jan 2024 08:01:17 -0800 (PST) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id n5-20020a056512310500b0050e76978861sm262094lfb.277.2024.01.05.08.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:01:15 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Greg Kroah-Hartman , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Sudeep Holla , Kevin Hilman , Konrad Dybcio , Bjorn Andersson , Nikunj Kela , Prasad Sodagudi , Stephan Gerhold , Ben Horgan , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-remoteproc@vger.kernel.org, linux-media@vger.kernel.org, Mathieu Poirier , Shawn Guo , Sascha Hauer , Iuliana Prodan , Daniel Baluta Subject: [PATCH v2 3/5] remoteproc: imx_rproc: Convert to dev_pm_domain_attach|detach_list() Date: Fri, 5 Jan 2024 17:01:01 +0100 Message-Id: <20240105160103.183092-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105160103.183092-1-ulf.hansson@linaro.org> References: <20240105160103.183092-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240105_080121_669857_80D12242 X-CRM114-Status: GOOD ( 21.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Let's avoid the boilerplate code to manage the multiple PM domain case, by converting into using dev_pm_domain_attach|detach_list(). Cc: Mathieu Poirier Cc: Bjorn Andersson Cc: Shawn Guo Cc: Sascha Hauer Cc: Iuliana Prodan Cc: Daniel Baluta Cc: Signed-off-by: Ulf Hansson Tested-by: Iuliana Prodan Reviewed-by: Iuliana Prodan Reviewed-by: Mathieu Poirier --- Changes in v2: - None. Iuliana/Daniel I am ccing you to request help with test/review of this change. Note that, you will need patch 1/5 in the series too, to be able to test this. Kind regards Ulf Hansson --- drivers/remoteproc/imx_rproc.c | 73 +++++----------------------------- 1 file changed, 9 insertions(+), 64 deletions(-) diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c index 8bb293b9f327..3161f14442bc 100644 --- a/drivers/remoteproc/imx_rproc.c +++ b/drivers/remoteproc/imx_rproc.c @@ -92,7 +92,6 @@ struct imx_rproc_mem { static int imx_rproc_xtr_mbox_init(struct rproc *rproc); static void imx_rproc_free_mbox(struct rproc *rproc); -static int imx_rproc_detach_pd(struct rproc *rproc); struct imx_rproc { struct device *dev; @@ -113,10 +112,8 @@ struct imx_rproc { u32 rproc_pt; /* partition id */ u32 rsrc_id; /* resource id */ u32 entry; /* cpu start address */ - int num_pd; u32 core_index; - struct device **pd_dev; - struct device_link **pd_dev_link; + struct dev_pm_domain_list *pd_list; }; static const struct imx_rproc_att imx_rproc_att_imx93[] = { @@ -853,7 +850,7 @@ static void imx_rproc_put_scu(struct rproc *rproc) return; if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id)) { - imx_rproc_detach_pd(rproc); + dev_pm_domain_detach_list(priv->pd_list); return; } @@ -880,72 +877,20 @@ static int imx_rproc_partition_notify(struct notifier_block *nb, static int imx_rproc_attach_pd(struct imx_rproc *priv) { struct device *dev = priv->dev; - int ret, i; - - /* - * If there is only one power-domain entry, the platform driver framework - * will handle it, no need handle it in this driver. - */ - priv->num_pd = of_count_phandle_with_args(dev->of_node, "power-domains", - "#power-domain-cells"); - if (priv->num_pd <= 1) - return 0; - - priv->pd_dev = devm_kmalloc_array(dev, priv->num_pd, sizeof(*priv->pd_dev), GFP_KERNEL); - if (!priv->pd_dev) - return -ENOMEM; - - priv->pd_dev_link = devm_kmalloc_array(dev, priv->num_pd, sizeof(*priv->pd_dev_link), - GFP_KERNEL); - - if (!priv->pd_dev_link) - return -ENOMEM; - - for (i = 0; i < priv->num_pd; i++) { - priv->pd_dev[i] = dev_pm_domain_attach_by_id(dev, i); - if (IS_ERR(priv->pd_dev[i])) { - ret = PTR_ERR(priv->pd_dev[i]); - goto detach_pd; - } - - priv->pd_dev_link[i] = device_link_add(dev, priv->pd_dev[i], DL_FLAG_STATELESS | - DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE); - if (!priv->pd_dev_link[i]) { - dev_pm_domain_detach(priv->pd_dev[i], false); - ret = -EINVAL; - goto detach_pd; - } - } - - return 0; - -detach_pd: - while (--i >= 0) { - device_link_del(priv->pd_dev_link[i]); - dev_pm_domain_detach(priv->pd_dev[i], false); - } - - return ret; -} - -static int imx_rproc_detach_pd(struct rproc *rproc) -{ - struct imx_rproc *priv = rproc->priv; - int i; + int ret; + struct dev_pm_domain_attach_data pd_data = { + .pd_flags = PD_FLAG_DEV_LINK_ON, + }; /* * If there is only one power-domain entry, the platform driver framework * will handle it, no need handle it in this driver. */ - if (priv->num_pd <= 1) + if (dev->pm_domain) return 0; - for (i = 0; i < priv->num_pd; i++) { - device_link_del(priv->pd_dev_link[i]); - dev_pm_domain_detach(priv->pd_dev[i], false); - } - - return 0; + ret = dev_pm_domain_attach_list(dev, &pd_data, &priv->pd_list); + return ret < 0 ? ret : 0; } static int imx_rproc_detect_mode(struct imx_rproc *priv) From patchwork Fri Jan 5 16:01:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13512355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5FBA0C4707B for ; Fri, 5 Jan 2024 16:02:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aV0A8Zw4Jd/WcYaO+xYZeHYDA5o/4/47CeTGsaXxR08=; b=cOIZVt/YIqU5hK lCJLHg8QMNE+ZYuLD6J6L9Q6AvB+GToYiuSoSSuhQhAElwu+EfZISkReXTq/BRqkqbSplam27hhuK kWZRQG+bRntM1sZ5+pAVt5kt4DN4Kmldyx3DLu7Pj7m3xsypeiasWQTKGx8X315D0qY0S99rpwHQn Med/CIaSUX7a/Z46bfp1Tyo2KJ6DxX2JO/G5kFrygp06YFbKESSKNRJ8cMVrAI7n5BCrskJ6HVJgp YAreamhV1lnntrQHJZq8RJkqygX13ec76mjC73vGNS5KOzTvW5aboGym5oyuzg2FGaR3bN1lU2M8k D8/PvXajqSuWgja3FTYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdV-00HFD1-0L; Fri, 05 Jan 2024 16:01:29 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdS-00HFAB-10 for linux-arm-kernel@lists.infradead.org; Fri, 05 Jan 2024 16:01:28 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-50eabd1c701so2070092e87.3 for ; Fri, 05 Jan 2024 08:01:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470482; x=1705075282; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8L0r+j4QHpjBNKOc8LHPOJeBJ7cd09qGloI5UK65eK8=; b=L/bJUQLdWnLrs4tpIyH9/Bi/MWeZuT6AKNoCiJRrf39bYtPVDCFG4SLenc0Dyrg11O FdIwdQVUnabYmVeME9OEg2TheeXA31oZtqj6Fzgk/EHteLrNDrSF2iJuonvaK21IIK1q lo7X77YySKY5wp8dB//B/Rc6KgPrAM60KkvwfF1bGWiIJJsmyCze9j+0HnxrtwRsfRnm zb+53Gc/Syy8bZ1skvGyaKG+Ilb11tK04c7/QWZN1pFEL0wyxk9Lt4xyoXPRV3cImZj4 4j/F9dbFa1IrL1c0LNtUARvbrohIdm725aaKf/M0TP2Cd0dt6v5NAQWoAgT42clvwlsQ 9C4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470482; x=1705075282; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8L0r+j4QHpjBNKOc8LHPOJeBJ7cd09qGloI5UK65eK8=; b=g6HQ1I1DD0fcJiTZEJRcVAR7cygcJepdxa4BEYi5mb/3KTCgZJKVSUcgM85JczSSD9 NObrcRgCOsomxWm5v4yJOi1JWLyjL019nBzvjov1OR+LnPB0x/7dnHoPTjucQr5bQ7fq VFG02vzhFUPg142571pu/rVIFZoDRMp7aBfomCS1mH2V1wY6lCZn6y+AuLCOQdqPfVC7 eGnRNaSfjb5YKCST84lpEtn/iWWbBtxnb9uGBeFz+DOntH40HNC4vb81nykvb58Aw0fS 51jAJQvWP4QKlNvTU6VzH+QiOtT++Tn2cY26NUe5TrEz/+uSjXP1RCLfy5SorhvHHLi3 ZAAw== X-Gm-Message-State: AOJu0Yxwzs9NHGcPpbya9U9bm+klEgwuxQn/exe/23jHx4sh+7ByoM4T ujD5xY/EmobQzhfyeY9eBmgUqnqR7LuThg== X-Google-Smtp-Source: AGHT+IFY8QPFwT3PY8M0RvC5lrijiDKhxLr7OdAEz9xvV4euoz5pxeW0sYQSK/KqUIzreBJFVWCGVQ== X-Received: by 2002:ac2:58c1:0:b0:50e:7b4e:f7e8 with SMTP id u1-20020ac258c1000000b0050e7b4ef7e8mr1019442lfo.6.1704470482505; Fri, 05 Jan 2024 08:01:22 -0800 (PST) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id n5-20020a056512310500b0050e76978861sm262094lfb.277.2024.01.05.08.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:01:19 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Greg Kroah-Hartman , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Sudeep Holla , Kevin Hilman , Konrad Dybcio , Bjorn Andersson , Nikunj Kela , Prasad Sodagudi , Stephan Gerhold , Ben Horgan , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-remoteproc@vger.kernel.org, linux-media@vger.kernel.org, Mathieu Poirier Subject: [PATCH v2 4/5] remoteproc: qcom_q6v5_adsp: Convert to dev_pm_domain_attach|detach_list() Date: Fri, 5 Jan 2024 17:01:02 +0100 Message-Id: <20240105160103.183092-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105160103.183092-1-ulf.hansson@linaro.org> References: <20240105160103.183092-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240105_080126_350022_3107C7D3 X-CRM114-Status: GOOD ( 24.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Let's avoid some of the boilerplate code to manage the various PM domain cases, by converting into using dev_pm_domain_attach|detach_list(). As a part of the conversion, we are moving over to use device_links, which simplifies the runtime PM support too. Moreover, while attaching let's trust that an already attached single PM domain is the correct one. Cc: Mathieu Poirier Cc: Bjorn Andersson Cc: Konrad Dybcio Cc: Signed-off-by: Ulf Hansson --- Changes in v2: - None. Kind regards Ulf Hansson --- drivers/remoteproc/qcom_q6v5_adsp.c | 160 +++++++++++++--------------- 1 file changed, 73 insertions(+), 87 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5_adsp.c b/drivers/remoteproc/qcom_q6v5_adsp.c index 6c67514cc493..93f9a1537ec6 100644 --- a/drivers/remoteproc/qcom_q6v5_adsp.c +++ b/drivers/remoteproc/qcom_q6v5_adsp.c @@ -55,8 +55,6 @@ #define QDSP6SS_CORE_CBCR 0x20 #define QDSP6SS_SLEEP_CBCR 0x3c -#define QCOM_Q6V5_RPROC_PROXY_PD_MAX 3 - #define LPASS_BOOT_CORE_START BIT(0) #define LPASS_BOOT_CMD_START BIT(0) #define LPASS_EFUSE_Q6SS_EVB_SEL 0x0 @@ -74,7 +72,8 @@ struct adsp_pil_data { const char **clk_ids; int num_clks; - const char **proxy_pd_names; + const char **pd_names; + unsigned int num_pds; const char *load_state; }; @@ -110,8 +109,7 @@ struct qcom_adsp { size_t mem_size; bool has_iommu; - struct device *proxy_pds[QCOM_Q6V5_RPROC_PROXY_PD_MAX]; - size_t proxy_pd_count; + struct dev_pm_domain_list *pd_list; struct qcom_rproc_glink glink_subdev; struct qcom_rproc_ssr ssr_subdev; @@ -120,98 +118,92 @@ struct qcom_adsp { int (*shutdown)(struct qcom_adsp *adsp); }; -static int qcom_rproc_pds_attach(struct device *dev, struct qcom_adsp *adsp, - const char **pd_names) +static int qcom_rproc_pds_attach(struct qcom_adsp *adsp, const char **pd_names, + unsigned int num_pds) { - struct device **devs = adsp->proxy_pds; - size_t num_pds = 0; + struct device *dev = adsp->dev; + struct dev_pm_domain_attach_data pd_data = { + .pd_names = pd_names, + .num_pd_names = num_pds, + }; int ret; - int i; - - if (!pd_names) - return 0; /* Handle single power domain */ - if (dev->pm_domain) { - devs[0] = dev; - pm_runtime_enable(dev); - return 1; - } + if (dev->pm_domain) + goto out; - while (pd_names[num_pds]) - num_pds++; + if (!pd_names) + return 0; - if (num_pds > ARRAY_SIZE(adsp->proxy_pds)) - return -E2BIG; + ret = dev_pm_domain_attach_list(dev, &pd_data, &adsp->pd_list); + if (ret < 0) + return ret; - for (i = 0; i < num_pds; i++) { - devs[i] = dev_pm_domain_attach_by_name(dev, pd_names[i]); - if (IS_ERR_OR_NULL(devs[i])) { - ret = PTR_ERR(devs[i]) ? : -ENODATA; - goto unroll_attach; - } - } +out: + pm_runtime_enable(dev); + return 0; +} - return num_pds; +static void qcom_rproc_pds_detach(struct qcom_adsp *adsp) +{ + struct device *dev = adsp->dev; + struct dev_pm_domain_list *pds = adsp->pd_list; -unroll_attach: - for (i--; i >= 0; i--) - dev_pm_domain_detach(devs[i], false); + dev_pm_domain_detach_list(pds); - return ret; + if (dev->pm_domain || pds) + pm_runtime_disable(adsp->dev); } -static void qcom_rproc_pds_detach(struct qcom_adsp *adsp, struct device **pds, - size_t pd_count) +static int qcom_rproc_pds_enable(struct qcom_adsp *adsp) { struct device *dev = adsp->dev; - int i; + struct dev_pm_domain_list *pds = adsp->pd_list; + int ret, i = 0; - /* Handle single power domain */ - if (dev->pm_domain && pd_count) { - pm_runtime_disable(dev); - return; - } + if (!dev->pm_domain && !pds) + return 0; - for (i = 0; i < pd_count; i++) - dev_pm_domain_detach(pds[i], false); -} + if (dev->pm_domain) + dev_pm_genpd_set_performance_state(dev, INT_MAX); -static int qcom_rproc_pds_enable(struct qcom_adsp *adsp, struct device **pds, - size_t pd_count) -{ - int ret; - int i; - - for (i = 0; i < pd_count; i++) { - dev_pm_genpd_set_performance_state(pds[i], INT_MAX); - ret = pm_runtime_resume_and_get(pds[i]); - if (ret < 0) { - dev_pm_genpd_set_performance_state(pds[i], 0); - goto unroll_pd_votes; - } + while (pds && i < pds->num_pds) { + dev_pm_genpd_set_performance_state(pds->pd_devs[i], INT_MAX); + i++; } - return 0; + ret = pm_runtime_resume_and_get(dev); + if (ret < 0) { + while (pds && i > 0) { + i--; + dev_pm_genpd_set_performance_state(pds->pd_devs[i], 0); + } -unroll_pd_votes: - for (i--; i >= 0; i--) { - dev_pm_genpd_set_performance_state(pds[i], 0); - pm_runtime_put(pds[i]); + if (dev->pm_domain) + dev_pm_genpd_set_performance_state(dev, 0); } return ret; } -static void qcom_rproc_pds_disable(struct qcom_adsp *adsp, struct device **pds, - size_t pd_count) +static void qcom_rproc_pds_disable(struct qcom_adsp *adsp) { - int i; + struct device *dev = adsp->dev; + struct dev_pm_domain_list *pds = adsp->pd_list; + int i = 0; + + if (!dev->pm_domain && !pds) + return; + + if (dev->pm_domain) + dev_pm_genpd_set_performance_state(dev, 0); - for (i = 0; i < pd_count; i++) { - dev_pm_genpd_set_performance_state(pds[i], 0); - pm_runtime_put(pds[i]); + while (pds && i < pds->num_pds) { + dev_pm_genpd_set_performance_state(pds->pd_devs[i], 0); + i++; } + + pm_runtime_put(dev); } static int qcom_wpss_shutdown(struct qcom_adsp *adsp) @@ -397,8 +389,7 @@ static int adsp_start(struct rproc *rproc) if (ret) goto adsp_smmu_unmap; - ret = qcom_rproc_pds_enable(adsp, adsp->proxy_pds, - adsp->proxy_pd_count); + ret = qcom_rproc_pds_enable(adsp); if (ret < 0) goto disable_xo_clk; @@ -448,7 +439,7 @@ static int adsp_start(struct rproc *rproc) disable_adsp_clks: clk_bulk_disable_unprepare(adsp->num_clks, adsp->clks); disable_power_domain: - qcom_rproc_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count); + qcom_rproc_pds_disable(adsp); disable_xo_clk: clk_disable_unprepare(adsp->xo); adsp_smmu_unmap: @@ -464,7 +455,7 @@ static void qcom_adsp_pil_handover(struct qcom_q6v5 *q6v5) struct qcom_adsp *adsp = container_of(q6v5, struct qcom_adsp, q6v5); clk_disable_unprepare(adsp->xo); - qcom_rproc_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count); + qcom_rproc_pds_disable(adsp); } static int adsp_stop(struct rproc *rproc) @@ -715,13 +706,11 @@ static int adsp_probe(struct platform_device *pdev) if (ret) goto free_rproc; - ret = qcom_rproc_pds_attach(adsp->dev, adsp, - desc->proxy_pd_names); + ret = qcom_rproc_pds_attach(adsp, desc->pd_names, desc->num_pds); if (ret < 0) { dev_err(&pdev->dev, "Failed to attach proxy power domains\n"); goto free_rproc; } - adsp->proxy_pd_count = ret; ret = adsp_init_reset(adsp); if (ret) @@ -753,7 +742,7 @@ static int adsp_probe(struct platform_device *pdev) return 0; disable_pm: - qcom_rproc_pds_detach(adsp, adsp->proxy_pds, adsp->proxy_pd_count); + qcom_rproc_pds_detach(adsp); free_rproc: rproc_free(rproc); @@ -771,7 +760,7 @@ static void adsp_remove(struct platform_device *pdev) qcom_remove_glink_subdev(adsp->rproc, &adsp->glink_subdev); qcom_remove_sysmon_subdev(adsp->sysmon); qcom_remove_ssr_subdev(adsp->rproc, &adsp->ssr_subdev); - qcom_rproc_pds_detach(adsp, adsp->proxy_pds, adsp->proxy_pd_count); + qcom_rproc_pds_detach(adsp); rproc_free(adsp->rproc); } @@ -788,9 +777,8 @@ static const struct adsp_pil_data adsp_resource_init = { "qdsp6ss_xo", "qdsp6ss_sleep", "qdsp6ss_core", NULL }, .num_clks = 7, - .proxy_pd_names = (const char*[]) { - "cx", NULL - }, + .pd_names = (const char*[]) { "cx" }, + .num_pds = 1, }; static const struct adsp_pil_data adsp_sc7280_resource_init = { @@ -821,9 +809,8 @@ static const struct adsp_pil_data cdsp_resource_init = { "q6_axim", NULL }, .num_clks = 7, - .proxy_pd_names = (const char*[]) { - "cx", NULL - }, + .pd_names = (const char*[]) { "cx" }, + .num_pds = 1, }; static const struct adsp_pil_data wpss_resource_init = { @@ -839,9 +826,8 @@ static const struct adsp_pil_data wpss_resource_init = { "ahb_bdg", "ahb", "rscp", NULL }, .num_clks = 3, - .proxy_pd_names = (const char*[]) { - "cx", "mx", NULL - }, + .pd_names = (const char*[]) { "cx", "mx" }, + .num_pds = 2, }; static const struct of_device_id adsp_of_match[] = { From patchwork Fri Jan 5 16:01:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13512356 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37BC1C3DA6E for ; Fri, 5 Jan 2024 16:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FR9SXKiKKBYyNU/ayqCUGdPu7SNxvQRbJSlDDfFfc7o=; b=rqSBgsFjSvWvEs iyMJxMrnErroTZKtf+4SaKBjvIf5scdpbJJCnm67fFGRNezw021i7k4pFxay3yUOaj2MCIinzIPiY puOgHN3iN0FL8Rl9raC47kdi7kjUijmm5ksJMZ5xmprn/u3s4csdenOdhZTc67COWr3ie2tVfJRUN ewFXRa8Ld9ns1L1NLkYCl/suCvfgELATnh1zc5goSnVaGYS7IxWg6v4SZteXHdGV6SC+c9vs0e/te gTpZVsV/WeB3WNgFncIeujJsWXea19QTnGThmjytd6pyCwYCqHK3x4a+NMZK5NSf6IMYak9CX0USC h1M23znzPackHoNikAtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdb-00HFHW-2e; Fri, 05 Jan 2024 16:01:35 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rLmdY-00HFEK-0h for linux-arm-kernel@lists.infradead.org; Fri, 05 Jan 2024 16:01:34 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-50e5a9bcec9so2191749e87.3 for ; Fri, 05 Jan 2024 08:01:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704470491; x=1705075291; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hfaPY3yQfoH2pfubd1hE0qyxl2OsnhSkHMvbF5d+3SA=; b=HoJflE06Gs2i/QRjR3XDu0EHZPfLW+7C7rIzqAE2kLtGnkJs42W9aCjslURwYxf4rG UlqsIZoAo/DetsFFTTV3n9jr5Ky7CbvmL2bIPavYA9Vc0fuFxTnYA2v16bb4KfpO8jkk sjN/DVaXGgpmUx4EdUS0j8bTGzUcR55fE7CPLxIQwYtpgK8wzl1y0ujY2fpPbm8WpkA1 8EGa2pUZzWvtOrIoJGp8b5nWzT9Rf4AR3RcMmAxxT++uvgaJhrTnki9aNcHpcsqQlPd1 xR6McWv6JJ5Gw+WZNmvWEBz0ubrHsk/1BDfgbSzNLuZVoBlzFTgiOgtPP5kk4u/bACdZ q5RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704470491; x=1705075291; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hfaPY3yQfoH2pfubd1hE0qyxl2OsnhSkHMvbF5d+3SA=; b=IbVV3+zBGT0o5kRTVvwmJnYAvB5EAjQtsrj/nrE+F0EiksaHqgXANce7SnfHtfDAlV n84bJ47tpv5dhtyYmF8Y4YsDLg6A6g7wBxp1GNcIlA2VOlnhK3siJ6zmMo88zruvRq/k EY+B3ruK4HXo/TtL/Aupijc5rx5JfkP7EtHC6yoIheBjj+DkAPQTpx74Ne5/OI+kZLMj BAJiNz8HYxsx795BYlS98eWX/tFYx8aqlPwVLIikUd4qHU0UdKLMVkOiVqLshRVI8Rzy S5Dd4x/UMcDTF9yP44QfKxwdmm/RCAqCaxu3PpzDl8a53m6MlThb5aM69vS4JTZga/U2 QjJw== X-Gm-Message-State: AOJu0YyEFf2yUIYyt9j145wa0EAMMUN2Ntizx8nwXOr9RJflN04t74Xg qUV3r8UVA6kgQw2hHPT4s80scx0FwDcVGw== X-Google-Smtp-Source: AGHT+IERdn5J2WMksCV2xwOZSB4UlNaSC9hjgX2okCC+u7HZvOM32yjjwGik6ASHsLufYsrr/E57Ww== X-Received: by 2002:ac2:46e1:0:b0:50e:80d3:4fd4 with SMTP id q1-20020ac246e1000000b0050e80d34fd4mr1191950lfo.51.1704470490597; Fri, 05 Jan 2024 08:01:30 -0800 (PST) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id n5-20020a056512310500b0050e76978861sm262094lfb.277.2024.01.05.08.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:01:23 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Greg Kroah-Hartman , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Sudeep Holla , Kevin Hilman , Konrad Dybcio , Bjorn Andersson , Nikunj Kela , Prasad Sodagudi , Stephan Gerhold , Ben Horgan , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-remoteproc@vger.kernel.org, linux-media@vger.kernel.org, Mauro Carvalho Chehab , Stanimir Varbanov , Vikash Garodia , "Bryan O'Donoghue" Subject: [PATCH v2 5/5] media: venus: Convert to dev_pm_domain_attach|detach_list() for vcodec Date: Fri, 5 Jan 2024 17:01:03 +0100 Message-Id: <20240105160103.183092-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105160103.183092-1-ulf.hansson@linaro.org> References: <20240105160103.183092-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240105_080132_251711_A6BF97AF X-CRM114-Status: GOOD ( 23.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Let's avoid some of the boilerplate code to manage the vcodec PM domains, by converting into using dev_pm_domain_attach|detach_list(). Cc: Mauro Carvalho Chehab Cc: Stanimir Varbanov Cc: Vikash Garodia Cc: "Bryan O'Donoghue" Cc: Bjorn Andersson Cc: Konrad Dybcio Cc: Tested-by: Bryan O'Donoghue Reviewed-by: Bryan O'Donoghue Signed-off-by: Ulf Hansson --- Changes in v2: - Added tags Bryan's tags. --- drivers/media/platform/qcom/venus/core.c | 12 +++-- drivers/media/platform/qcom/venus/core.h | 7 ++- .../media/platform/qcom/venus/pm_helpers.c | 48 +++++++------------ 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 9cffe975581b..bd9b474280e4 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -114,7 +115,8 @@ static void venus_sys_error_handler(struct work_struct *work) pm_runtime_put_sync(core->dev); for (i = 0; i < max_attempts; i++) { - if (!core->pmdomains[0] || !pm_runtime_active(core->pmdomains[0])) + if (!core->pmdomains || + !pm_runtime_active(core->pmdomains->pd_devs[0])) break; usleep_range(1000, 1500); } @@ -705,7 +707,7 @@ static const struct venus_resources sdm845_res_v2 = { .vcodec0_clks = { "vcodec0_core", "vcodec0_bus" }, .vcodec1_clks = { "vcodec1_core", "vcodec1_bus" }, .vcodec_clks_num = 2, - .vcodec_pmdomains = { "venus", "vcodec0", "vcodec1" }, + .vcodec_pmdomains = (const char *[]) { "venus", "vcodec0", "vcodec1" }, .vcodec_pmdomains_num = 3, .opp_pmdomain = (const char *[]) { "cx", NULL }, .vcodec_num = 2, @@ -754,7 +756,7 @@ static const struct venus_resources sc7180_res = { .clks_num = 3, .vcodec0_clks = { "vcodec0_core", "vcodec0_bus" }, .vcodec_clks_num = 2, - .vcodec_pmdomains = { "venus", "vcodec0" }, + .vcodec_pmdomains = (const char *[]) { "venus", "vcodec0" }, .vcodec_pmdomains_num = 2, .opp_pmdomain = (const char *[]) { "cx", NULL }, .vcodec_num = 1, @@ -811,7 +813,7 @@ static const struct venus_resources sm8250_res = { .resets_num = 2, .vcodec0_clks = { "vcodec0_core" }, .vcodec_clks_num = 1, - .vcodec_pmdomains = { "venus", "vcodec0" }, + .vcodec_pmdomains = (const char *[]) { "venus", "vcodec0" }, .vcodec_pmdomains_num = 2, .opp_pmdomain = (const char *[]) { "mx", NULL }, .vcodec_num = 1, @@ -870,7 +872,7 @@ static const struct venus_resources sc7280_res = { .clks_num = 3, .vcodec0_clks = {"vcodec_core", "vcodec_bus"}, .vcodec_clks_num = 2, - .vcodec_pmdomains = { "venus", "vcodec0" }, + .vcodec_pmdomains = (const char *[]) { "venus", "vcodec0" }, .vcodec_pmdomains_num = 2, .opp_pmdomain = (const char *[]) { "cx", NULL }, .vcodec_num = 1, diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index 4a633261ece4..7ef341bf21cc 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -25,7 +25,6 @@ #define VIDC_CLKS_NUM_MAX 4 #define VIDC_VCODEC_CLKS_NUM_MAX 2 -#define VIDC_PMDOMAINS_NUM_MAX 3 #define VIDC_RESETS_NUM_MAX 2 extern int venus_fw_debug; @@ -72,7 +71,7 @@ struct venus_resources { const char * const vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX]; const char * const vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX]; unsigned int vcodec_clks_num; - const char * const vcodec_pmdomains[VIDC_PMDOMAINS_NUM_MAX]; + const char **vcodec_pmdomains; unsigned int vcodec_pmdomains_num; const char **opp_pmdomain; unsigned int vcodec_num; @@ -134,7 +133,7 @@ struct venus_format { * @video_path: an interconnect handle to video to/from memory path * @cpucfg_path: an interconnect handle to cpu configuration path * @has_opp_table: does OPP table exist - * @pmdomains: an array of pmdomains struct device pointers + * @pmdomains: a pointer to a list of pmdomains * @opp_dl_venus: an device-link for device OPP * @opp_pmdomain: an OPP power-domain * @resets: an array of reset signals @@ -187,7 +186,7 @@ struct venus_core { struct icc_path *video_path; struct icc_path *cpucfg_path; bool has_opp_table; - struct device *pmdomains[VIDC_PMDOMAINS_NUM_MAX]; + struct dev_pm_domain_list *pmdomains; struct device_link *opp_dl_venus; struct device *opp_pmdomain; struct reset_control *resets[VIDC_RESETS_NUM_MAX]; diff --git a/drivers/media/platform/qcom/venus/pm_helpers.c b/drivers/media/platform/qcom/venus/pm_helpers.c index a1b127caa90a..502822059498 100644 --- a/drivers/media/platform/qcom/venus/pm_helpers.c +++ b/drivers/media/platform/qcom/venus/pm_helpers.c @@ -455,7 +455,7 @@ static int poweroff_coreid(struct venus_core *core, unsigned int coreid_mask) if (ret) return ret; - ret = pm_runtime_put_sync(core->pmdomains[1]); + ret = pm_runtime_put_sync(core->pmdomains->pd_devs[1]); if (ret < 0) return ret; } @@ -471,7 +471,7 @@ static int poweroff_coreid(struct venus_core *core, unsigned int coreid_mask) if (ret) return ret; - ret = pm_runtime_put_sync(core->pmdomains[2]); + ret = pm_runtime_put_sync(core->pmdomains->pd_devs[2]); if (ret < 0) return ret; } @@ -484,7 +484,7 @@ static int poweron_coreid(struct venus_core *core, unsigned int coreid_mask) int ret; if (coreid_mask & VIDC_CORE_ID_1) { - ret = pm_runtime_get_sync(core->pmdomains[1]); + ret = pm_runtime_get_sync(core->pmdomains->pd_devs[1]); if (ret < 0) return ret; @@ -502,7 +502,7 @@ static int poweron_coreid(struct venus_core *core, unsigned int coreid_mask) } if (coreid_mask & VIDC_CORE_ID_2) { - ret = pm_runtime_get_sync(core->pmdomains[2]); + ret = pm_runtime_get_sync(core->pmdomains->pd_devs[2]); if (ret < 0) return ret; @@ -860,19 +860,18 @@ static int vcodec_domains_get(struct venus_core *core) struct device **opp_virt_dev; struct device *dev = core->dev; const struct venus_resources *res = core->res; - struct device *pd; - unsigned int i; + struct dev_pm_domain_attach_data vcodec_data = { + .pd_names = res->vcodec_pmdomains, + .num_pd_names = res->vcodec_pmdomains_num, + .pd_flags = PD_FLAG_NO_DEV_LINK, + }; if (!res->vcodec_pmdomains_num) goto skip_pmdomains; - for (i = 0; i < res->vcodec_pmdomains_num; i++) { - pd = dev_pm_domain_attach_by_name(dev, - res->vcodec_pmdomains[i]); - if (IS_ERR_OR_NULL(pd)) - return pd ? PTR_ERR(pd) : -ENODATA; - core->pmdomains[i] = pd; - } + ret = dev_pm_domain_attach_list(dev, &vcodec_data, &core->pmdomains); + if (ret < 0) + return ret; skip_pmdomains: if (!core->res->opp_pmdomain) @@ -896,30 +895,14 @@ static int vcodec_domains_get(struct venus_core *core) return 0; opp_attach_err: - for (i = 0; i < res->vcodec_pmdomains_num; i++) { - if (IS_ERR_OR_NULL(core->pmdomains[i])) - continue; - dev_pm_domain_detach(core->pmdomains[i], true); - } - + dev_pm_domain_detach_list(core->pmdomains); return ret; } static void vcodec_domains_put(struct venus_core *core) { - const struct venus_resources *res = core->res; - unsigned int i; + dev_pm_domain_detach_list(core->pmdomains); - if (!res->vcodec_pmdomains_num) - goto skip_pmdomains; - - for (i = 0; i < res->vcodec_pmdomains_num; i++) { - if (IS_ERR_OR_NULL(core->pmdomains[i])) - continue; - dev_pm_domain_detach(core->pmdomains[i], true); - } - -skip_pmdomains: if (!core->has_opp_table) return; @@ -1035,7 +1018,8 @@ static void core_put_v4(struct venus_core *core) static int core_power_v4(struct venus_core *core, int on) { struct device *dev = core->dev; - struct device *pmctrl = core->pmdomains[0]; + struct device *pmctrl = core->pmdomains ? + core->pmdomains->pd_devs[0] : NULL; int ret = 0; if (on == POWER_ON) {