From patchwork Tue Jan 30 12:39:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 768331 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E07106A03D for ; Tue, 30 Jan 2024 12:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618404; cv=none; b=TIPhzgNTBBfF2LkjRaayhvt8jKofynPzGYZttzdIkIRw4u9kZfleRhPrMds2ZMVi4+12M5/9OB/X4X+MI+4Y/X9RkS8uIRd96swHzUTQ7H5Q9MYrKdVhVxBK7rStHWGo20zAAlAdBL2NScLeByos+SjPvkChLsJj384yqi0Rk3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618404; c=relaxed/simple; bh=BFGebA22Zl6KAO1sN62su1KgbqyI+ai5NQ8qVfi/A1E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eKU1nHhE0j5U9z2kMqMEklJ7tlUXiM21h4C9dfLGcXkyFyZGBxnVMw+gH4hrAMv4LyBzzVVVi2tuAn8wPS7w9OSgP3xbUUTXoJD1r6pIjKV/Wnad9kUNkQgvdVkPMD9AhC6bxBpMMARaRV9iPi2P8Rh3eW+GLppb+mhQh5DVsWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=b4mkefZy; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="b4mkefZy" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-51032e62171so3995828e87.3 for ; Tue, 30 Jan 2024 04:40:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706618400; x=1707223200; darn=vger.kernel.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=ojvRls/CWhyJwL4FHVfNMWSRHzs2rXl5HVAGDfoW6nM=; b=b4mkefZy/wYZvj24Ln8nyKb26Ue/E7zKxtrqlx60+wxXXzfqwCuclWR8j8W4XHbZ0Q ZXkw9dftcJiADz/SM59eTYmCdwegmvuoNjXWcVZ2ieTVVLHSGPgrYMTISWZ45EUTtNWK PYwQzZP9WJSt9Wh8K3807xN1x1JvJX9G3ndEfCSmljJi2JjD6Wul8JWLzqriwVHcuFRW DYnvdSQe7Hp4qpx4tZuvZJbh+9ExupHJSVMWO8lZ1sxBWzvItyJuTAFDaNFrpM2+HwHo zQyd1I7utUQWmikiKt/5uXt8Jp09j79SRDM0M/63VlhU2Eu2PQu2fnA0lyu6BFNb/JjW NhVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706618400; x=1707223200; 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=ojvRls/CWhyJwL4FHVfNMWSRHzs2rXl5HVAGDfoW6nM=; b=LPvGS/JfkNeoGQvUb1sX/R5044w1b0BIi7cc/szULf/c/YlYQEFT9HcVa3WPhQ38L6 zZqRh1qIRZHna47oJmeacYoaA4oQExy/FQvEUwwYodJ+uufulSjecBWCW0T8Y8yAbINs xHKu28ol0LOp6KkT0hDNH3p4psvKJrt3SBKuZjo7tZTwuKtIgcFqrY2thX1cmt9Wosew I93uVTwXTdbs5DVGbUiYRmQv+AUjJC834SmyphrT791j78+oK5+zntWwQ9PL8+lkxPGJ M99Pnj5X3OyfetzjL8XgZwUSsmQXFummQZhJ0D+mpRGbrdxjqd/4WsxZt3zayViHdWci fNTA== X-Gm-Message-State: AOJu0YwlwnTGXtmCjDLDxuCmU6e0aPIJI6YpM0UIj5NIGyZZ9B0PkUSf /i73awq2/WkaTcJ4eW3LbGnFusr1uG4YWGAIDNpzrrfakgX2B2LS48TRvJhYA+qNkdmTJtqJSHi gXes= X-Google-Smtp-Source: AGHT+IHH+o5l9Q/KNftmckjjUBa4Y8b+Gd+GqrxsDzrNG7OhEJZ9M9NcmzEHvh32+taKe6rgdrPpiw== X-Received: by 2002:a05:6512:2256:b0:50e:aac2:b883 with SMTP id i22-20020a056512225600b0050eaac2b883mr7035952lfu.4.1706618399945; Tue, 30 Jan 2024 04:39:59 -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 p10-20020a19f00a000000b005111b28f7c2sm200661lfc.36.2024.01.30.04.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:39:59 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Greg Kroah-Hartman , Viresh Kumar , 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, Shawn Guo , Sascha Hauer , Daniel Baluta , Iuliana Prodan , Mathieu Poirier Subject: [PATCH v3 2/5] remoteproc: imx_dsp_rproc: Convert to dev_pm_domain_attach|detach_list() Date: Tue, 30 Jan 2024 13:39:48 +0100 Message-Id: <20240130123951.236243-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240130123951.236243-1-ulf.hansson@linaro.org> References: <20240130123951.236243-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Let's avoid the boilerplate code to manage the multiple PM domain case, by converting into using dev_pm_domain_attach|detach_list(). Cc: Bjorn Andersson Cc: Shawn Guo Cc: Sascha Hauer Cc: Daniel Baluta Cc: Tested-by: Iuliana Prodan Reviewed-by: Iuliana Prodan Reviewed-by: Mathieu Poirier Signed-off-by: Ulf Hansson --- Changes in v3: - Added reviewed-by and tested-by tags. Changes in v2: - None. --- 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 a1c62d15f16c..d73727a5828a 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; }; @@ -955,74 +951,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; } /** @@ -1154,7 +1090,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); @@ -1168,7 +1104,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 Tue Jan 30 12:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 768330 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4154C6A358 for ; Tue, 30 Jan 2024 12:40:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618406; cv=none; b=Bea8vpUmIZ6Fxncq8kipmlkYCU3gr0wbnux1lfaYmGHMLBn0Rwnx2HyDJMVko0rTzfceb50Am4OfJcEXVQ/kTR8uRZbq1OwGQoQEV47uDI21s1l6LHWJMiy8KqrRfVjKZ/Yse18PqFKh66Os7rhhLX3uaRS3OVNvZO7YaUuzQfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618406; c=relaxed/simple; bh=Q/Ledumh8sSiB25tzXejDfGb21zxF+yXH8L2vrYUAiE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NTCmSkTG7yCKXKhvzRnqoOm2GWeC6QDJO956BMojmldKfj5ZDsh+H/s9pBpKr1faiYX8DLKtA7IXDHSkFrJ5Ma5NtPMFbPvA01i+osXYYPbEl3aka4p7Rz1hF4HsR8ql6ZnNUjk2L9gVY2t0PzC9NjR2LjCZIOIoZjnTeawunfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=brqVDjGU; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="brqVDjGU" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-51117bfd452so1735065e87.3 for ; Tue, 30 Jan 2024 04:40:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706618402; x=1707223202; darn=vger.kernel.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=6sB7M33Aev4PO2V7J5+eikfOicrMZ3OaY7keTZjNQuw=; b=brqVDjGUPNCQJbgQLKnK79FAxw/MoNPvCA19UEoz0d89punl7T5VhAnfRIm0NwvC9+ 3u21w21UacyLYVxZXGfq41K5V1AMDVpJxd/SLBruhGfhyRQTTgQa484g0G/Aamqby3on ZTgcO2mKUO3FrwBjU5Iqwl6zXCetp8vrDaDsmZ1QWbWke4471bXUZzGZzp0x330F3uRV qUF9Su5oBc4UYMkjFhVmsvfH8qjYUBGkR4qdAQfwR8aRRznhQNU+Di/psDXupjQFZ64J q2AjHtqTTq71E6MPh3X98I0q9M61mIfAnRbq27p1KofoF6zHIKFVtX65VMxh4cGUWrNG h79g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706618402; x=1707223202; 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=6sB7M33Aev4PO2V7J5+eikfOicrMZ3OaY7keTZjNQuw=; b=hoFeMFQLXWw6cRZI5vJ8uXVGJVcRjSwvuZqn7hmOyS/lCtwYnm95Ws0Zd7ce3iZ7H5 MolSszWtdsaSjI1t2eTQLURSfgWe0KacIVjhCblXF655ujYaRY98yo73SmD2C2oGz8cO iiZMDHMVvmrz3p/ueTWwY8EUMx0jTWrt0CsJuA1nrDCoZ0XlhzRUAZcmcW2XJJBICrhy LY4SuWUnXa0QyUJcmAfIP8Cck8zeoUFA77NmTVOgAVFWZCRIiTjM3cn9BvwML3ShCnZ2 S6vI7B65YDAwsRgIGtWE+LdLvubTFq9b2/IBQGnEy8Jdal86x45HK7MyrD7iS7GMFc5p iVZg== X-Gm-Message-State: AOJu0YzmwLn60zZGt+fMnmvbiBVydZIFZaDOK2dzJv835SLwoNnIquUO ZVdBoZ9QNOzqjI00/tAA9CoNW9uk1UZAIyUpwXrsWR7orYLOuxyGYPt+tZbV32I= X-Google-Smtp-Source: AGHT+IE/ZR80yvcmbkhg9NHljlJ433H1MVoW2Mu81CCAc7Thbu9up9kp85gS2CRY3YWjLo12boXqCA== X-Received: by 2002:a05:6512:39ca:b0:50e:b5fc:bdcc with SMTP id k10-20020a05651239ca00b0050eb5fcbdccmr8316098lfu.63.1706618402344; Tue, 30 Jan 2024 04:40:02 -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 p10-20020a19f00a000000b005111b28f7c2sm200661lfc.36.2024.01.30.04.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:40:01 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Greg Kroah-Hartman , Viresh Kumar , 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 v3 4/5] remoteproc: qcom_q6v5_adsp: Convert to dev_pm_domain_attach|detach_list() Date: Tue, 30 Jan 2024 13:39:50 +0100 Message-Id: <20240130123951.236243-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240130123951.236243-1-ulf.hansson@linaro.org> References: <20240130123951.236243-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 v3: - None. Changes in v2: - None. --- 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[] = {