From nobody Tue Dec 23 23:48:00 2025 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 C826F6A031 for ; Tue, 30 Jan 2024 12:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618403; cv=none; b=OE5ixDL0b3L2F1svfYMKZgm7/I3IpHIYcOSiOYDE1GMCF6OnmuZKUjKUu1ocmxBYTn3YjuUmIb08gv14WF7+jzMl91J1P+fZ27qqN9yG4v62JpnlbVDRIghbCrVNFBCUzmrAkd2zfBQjH2xL2Mgm4XSHYMA7a6CrXQXvIGOVLEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618403; c=relaxed/simple; bh=d+n2LmHreLhTI/MtFCVdNAwCL4kj4TSCEGwtjdJIF24=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oo0V/y8CBLLeRf5jFNb8c9ZwNRVNjCBNz+IHPx4fgMoIJGR+ByRdVBrqCbA9m9J38Mayz0AagdJ0n446nT6YV8ORAl4VvNKB+tCRYekSqzgTzt6UXH1CZu3A1Rd4+zSTS/5ySXG99uVHOHYOPaoFxc55saHBo0eh2dQuo59fCjo= 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=Jg3JH6WD; arc=none smtp.client-ip=209.85.167.48 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="Jg3JH6WD" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-511207d62b6so232039e87.1 for ; Tue, 30 Jan 2024 04:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706618399; x=1707223199; 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=EXY+AEwFEHttcVholFRXocbu0KYZqhD9gVPVEuKJUGA=; b=Jg3JH6WD7QRKm/9rJiS/tqmSEV8nEKlDFfr1trhIi23wQvapoNWg3kmUrqYKyOaIV9 bs77sI4c0XSDV7aLgH2grggUZoO/cbgVQbN6ER886hKhluEqjv5KBQDmMKPvYFny681b eMd5khRfSP5Jv+SjjnN4RYdf5q6YdHBExuDMmKbhtpRuNMsqXFZ0+aleNMnzLKEflJZf PlbVO5fA5zoz9I0oN+ZIWnJ9t3xo2/J5texcO55QuhY/enT+IO1lALS65XZOriaahm3w 7J4MS4I1IjbY1k/umyFldCBZioyrZ0L9LcX0JDnq57Rr8ovVP3G6C/8fGIgl2FwhrGOt OV8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706618399; x=1707223199; 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=EXY+AEwFEHttcVholFRXocbu0KYZqhD9gVPVEuKJUGA=; b=tqumlCD7MSVX8rqo6k7c2/shgLK4obJtEFqrGLRuRqPLr31nTg6FpxS3yHIV7U9+Vr dAwl0Nf/bixVMAxx7GnSH1Jm8H4iyy05dlhLaGxyjd2bwVKBKY2CbUDLclLiolRUleuo ehyjpSPpkiGGq15D98wzbg79MWH4rgbnBQD7+YtAfA+Q9TJc7jd6goEIqT5LxJD5KHvC r2RtB1v2D7i2g6zfPKVkMd7a2knSeuYOUbOXihD95knGmYTDLa8aVsUWY4YX4RfhAlyc V+IV65IbfJbuaky6fO1w3YqEr6iVDKKhG+5QD7rxd9UB98Xc4x8d8q8+Hn3k6bGBgx0K 4BuQ== X-Gm-Message-State: AOJu0YztqzN00JghHfnvi3dMmBcSPpeNn3Mw56vB3JJIwMF5G596Ze8I S7FRHUrkl3cc3G/vMzeMlrKrm2msd4yLU1X3kwDPV3yEds8Qar3eJ/CwPk9tuxE= X-Google-Smtp-Source: AGHT+IGFvXuuehieb79UjpzAcPb/FYeFeTQCUGXTs9cTEd1CTHjA8sjaYeEvFdGy4v3y6ACQInS94Q== X-Received: by 2002:a05:6512:3b21:b0:510:544:78f with SMTP id f33-20020a0565123b2100b005100544078fmr6170159lfv.14.1706618398734; Tue, 30 Jan 2024 04:39:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:39:58 -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, Daniel Baluta , Bryan O'Donoghue , Iuliana Prodan Subject: [PATCH v3 1/5] PM: domains: Add helper functions to attach/detach multiple PM domains Date: Tue, 30 Jan 2024 13:39:47 +0100 Message-Id: <20240130123951.236243-2-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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Suggested-by: Daniel Baluta Tested-by: Bryan O'Donoghue Tested-by: Iuliana Prodan Signed-off-by: Ulf Hansson --- Changes in v3: - Added suggested-by and tested-by tags. 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 de= vice *dev, } EXPORT_SYMBOL_GPL(dev_pm_domain_attach_by_name); =20 +/** + * 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 lis= t of + * names for the PM domains that we should try to attach the device to, bu= t it + * may also provide an empty list, in case the attach should be done for a= ll 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 c= ase of + * a failure. Note that, to detach the list of PM domains, the driver shal= l 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 =3D dev->of_node; + struct dev_pm_domain_list *pds; + struct device *pd_dev =3D NULL; + int ret, i, num_pds =3D 0; + bool by_id =3D true; + u32 pd_flags =3D data ? data->pd_flags : 0; + u32 link_flags =3D 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 =3D data->num_pd_names; + by_id =3D false; + } else { + num_pds =3D of_count_phandle_with_args(np, "power-domains", + "#power-domain-cells"); + } + + if (num_pds <=3D 0) + return 0; + + pds =3D devm_kzalloc(dev, sizeof(*pds), GFP_KERNEL); + if (!pds) + return -ENOMEM; + + pds->pd_devs =3D devm_kcalloc(dev, num_pds, sizeof(*pds->pd_devs), + GFP_KERNEL); + if (!pds->pd_devs) + return -ENOMEM; + + pds->pd_links =3D 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 |=3D DL_FLAG_RPM_ACTIVE; + + for (i =3D 0; i < num_pds; i++) { + if (by_id) + pd_dev =3D dev_pm_domain_attach_by_id(dev, i); + else + pd_dev =3D dev_pm_domain_attach_by_name(dev, + data->pd_names[i]); + if (IS_ERR_OR_NULL(pd_dev)) { + ret =3D pd_dev ? PTR_ERR(pd_dev) : -ENODEV; + goto err_attach; + } + + if (link_flags) { + struct device_link *link; + + link =3D device_link_add(dev, pd_dev, link_flags); + if (!link) { + ret =3D -ENODEV; + goto err_link; + } + + pds->pd_links[i] =3D link; + } + + pds->pd_devs[i] =3D pd_dev; + } + + pds->num_pds =3D num_pds; + *list =3D pds; + return num_pds; + +err_link: + dev_pm_domain_detach(pd_dev, true); +err_attach: + while (--i >=3D 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 pow= er_off) } EXPORT_SYMBOL_GPL(dev_pm_domain_detach); =20 +/** + * 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 =3D 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 b97c5e9820f9..fb91770ba4ba 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -19,6 +19,33 @@ #include #include =20 +/* + * Flags to control the behaviour when attaching a device to its PM domain= s. + * + * 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. * @@ -420,7 +447,11 @@ struct device *dev_pm_domain_attach_by_id(struct devic= e *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 s= tate); @@ -439,7 +470,14 @@ static inline struct device *dev_pm_domain_attach_by_n= ame(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 *li= st) {} static inline int dev_pm_domain_start(struct device *dev) { return 0; --=20 2.34.1 From nobody Tue Dec 23 23:48:00 2025 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 0001A6A326 for ; Tue, 30 Jan 2024 12:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618404; cv=none; b=ugNhlQ6WC7Bng/XdWi8L1D0kvyEU7AZZYr8zOBWnfha2PBieTmER8PYEpg2DYfOHmAY11I6+Q9iV9hMrBKLZjFhn4qjMDLBlUjDpvlQIVuCZvE8Pj7xZS6ryCb9RZUK7Rx1HU7kaJtsYxS3crL1Oc1PdkF+WShUjrI5yaVM6yO0= 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.47 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-f47.google.com with SMTP id 2adb3069b0e04-511206d1c89so276516e87.1 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=RRGZEQhtvvDfph8g5YOzcOKAOs+YAFjcx+bEfLn98bI5i+ge3o2DGm+82on5kUeVcF xjHZsqpQJcWXz/7wivsrqBTdbwJmBSQjGt+OzSuy5nbeTWxlsawpybVmW3ZGLOq7q0Hk 5KBa0/EwUqPKJeDARjpFvPwwhsJvl8IYcb+uWUjm0dGs1EixszJL6zd4tfkd8hRKYTs8 hxFTafLQC2T1N6eusJJw3JxmHEcDUoeGPEohIFIcRSGg6/9K0Uq55DoFNQa2DyeS3Low eX64rA3/DaIJhZFsRpKvrNcoI6RXLeuVEireqipLtStwweocpSmppnHXFRcR5b4iAouv OJnA== X-Gm-Message-State: AOJu0YwLaaWtjiDjCHvcJOM7s+9jkztClevdWKLvCNZ2PeM9fa2Vo1D7 XnGIQrXJCdTe5ziC2CqKsYYOwnbDtZy5aBC434xp6MsVFQhhM8Z4oqXg/UYv2sM= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_ds= p_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; }; =20 @@ -955,74 +951,14 @@ static const struct rproc_ops imx_dsp_rproc_ops =3D { static int imx_dsp_attach_pm_domains(struct imx_dsp_rproc *priv) { struct device *dev =3D priv->rproc->dev.parent; - int ret, i; - - priv->num_domains =3D 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 <=3D 1) - return 0; - - priv->pd_dev =3D devm_kmalloc_array(dev, priv->num_domains, - sizeof(*priv->pd_dev), - GFP_KERNEL); - if (!priv->pd_dev) - return -ENOMEM; - - priv->pd_dev_link =3D devm_kmalloc_array(dev, priv->num_domains, - sizeof(*priv->pd_dev_link), - GFP_KERNEL); - if (!priv->pd_dev_link) - return -ENOMEM; - - for (i =3D 0; i < priv->num_domains; i++) { - priv->pd_dev[i] =3D dev_pm_domain_attach_by_id(dev, i); - if (IS_ERR(priv->pd_dev[i])) { - ret =3D 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] =3D 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 =3D -EINVAL; - goto detach_pm; - } - } - - return 0; - -detach_pm: - while (--i >=3D 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; =20 - if (priv->num_domains <=3D 1) + /* A single PM domain is already attached. */ + if (dev->pm_domain) return 0; =20 - for (i =3D 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 =3D dev_pm_domain_attach_list(dev, NULL, &priv->pd_list); + return ret < 0 ? ret : 0; } =20 /** @@ -1154,7 +1090,7 @@ static int imx_dsp_rproc_probe(struct platform_device= *pdev) return 0; =20 err_detach_domains: - imx_dsp_detach_pm_domains(priv); + dev_pm_domain_detach_list(priv->pd_list); err_put_rproc: rproc_free(rproc); =20 @@ -1168,7 +1104,7 @@ static void imx_dsp_rproc_remove(struct platform_devi= ce *pdev) =20 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); } =20 --=20 2.34.1 From nobody Tue Dec 23 23:48:00 2025 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 F06F56A33B for ; Tue, 30 Jan 2024 12:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618404; cv=none; b=sAlaEIpc5i1HaXSdJjIUIhGqb4d8amnKDHla3pbU0glJ/+7WGDA7DoFyO6AQcWu7Dw2BK4gjxIi0x1PlAMuXVG6zFuZaBq8WHI4pB/dPq0L9E82cijBP93mJ640H+kjAliYXHzAoTxDx9c67j7UDhPuIBOyjG9wmSCEAwsIKYKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618404; c=relaxed/simple; bh=o3yRXujB2ZcDVaB5sQ/vI6zeliCwrOSpjcLdCuR+/9o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mg7hjjAMF9bkZdy1oR6u42J4wDHn2cueQV2XlOzmMVi5YhYdmePAT9gy0kARKNBX+yicDWtYbdxY7lqu2ridCg8ZLsp3HdiE2gSH1umVmEfFKR4je/x4RfPN1SUj6ZwvkLT5St4R3Mmad6fsoL///MMii3d98iVYyr/PAYJ4PdU= 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=Dz9uGhwL; arc=none smtp.client-ip=209.85.167.50 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="Dz9uGhwL" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5102b00c2cdso3325038e87.3 for ; Tue, 30 Jan 2024 04:40:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706618401; x=1707223201; 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=NbVDzf0RQ8CWZb11lTphXt2uiDQVbFMo9sNICA+Shc8=; b=Dz9uGhwLGTULuinQfJNHexcxlwhxSri6VRSVsz4Uu7mkTK63niySxbvQ1ghPwuLoZR p7zGtRNjFYJ97U6LnSBdEHmlI7VZmwuc8u4C/CoLeUXcaNohW4stJak1QnNUXV65iCtz 9nxMfRnO2OtQJAMa0GDFtO8hdPNbFHJpYeVeRHi9nIvUifRkI7tyLbHRgctG2eWzN05z Votu9AhFSfwZG0XciaQnZWd4fkDEil29XO2Bj6vb7wvozESLp5ZbmbcdPOAygfkUc63H qwOMJmq3jc6p9yJnMok4rrzMqTRQimyCfv6y/z7eSVyDXcTp3K3bZBLCLV5R10boaKEj UWCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706618401; x=1707223201; 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=NbVDzf0RQ8CWZb11lTphXt2uiDQVbFMo9sNICA+Shc8=; b=q5RPNZGVxKPNK3BysdlchSo59E9BXyjbC+SttC6ejfhG7sdaRyymJ4apDb7sIQ7CgI EathniV85MfeSn/WV84qImhETKYnKK1bY7wyQcwxhqGezJLjyu/k+NPS1qa0dbetEnPf AkaK5LEYSpniFgy+nSHKqwtNrShCUH0IqaAtXZZhmw+P7b8N+FK1WSPzGLVtL3ZH0cDy 9EpptDeL++BqwHfNccPvy9M9JX/xtRb90ErTgU6uvWX5ifS8rlBXxARU8mV9lL07Q3Yk fHp+Axh3WwYkrWwT2twk0o3Hs6XMcr2vs3HIcZ/QZwrwroKniaj2BXKUFIaqkHQptOx3 68tw== X-Gm-Message-State: AOJu0YxPh2foMHx26rrrxWOXB3nmINATGNEKJzXJEKSuyTjvzBrsrF95 VHzvEQj80SVuLhD4m7VcbiHPSxjlTc1FWWFjuKb3jl1HRM6S7rb6RjeBfm67p7k= X-Google-Smtp-Source: AGHT+IFdP7vLlAvIRR4VgbZuuYG7S0kg7DlAx+K1o7hFOILkPKnF0MFzVznI27TWxp83yLfHrwOJ2w== X-Received: by 2002:ac2:5d2f:0:b0:511:1eb5:2284 with SMTP id i15-20020ac25d2f000000b005111eb52284mr810799lfb.0.1706618401156; Tue, 30 Jan 2024 04:40:01 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:40:00 -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 3/5] remoteproc: imx_rproc: Convert to dev_pm_domain_attach|detach_list() Date: Tue, 30 Jan 2024 13:39:49 +0100 Message-Id: <20240130123951.236243-4-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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_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 { =20 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); =20 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; }; =20 static const struct imx_rproc_att imx_rproc_att_imx93[] =3D { @@ -853,7 +850,7 @@ static void imx_rproc_put_scu(struct rproc *rproc) return; =20 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; } =20 @@ -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 =3D 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 =3D of_count_phandle_with_args(dev->of_node, "power-domains", - "#power-domain-cells"); - if (priv->num_pd <=3D 1) - return 0; - - priv->pd_dev =3D devm_kmalloc_array(dev, priv->num_pd, sizeof(*priv->pd_d= ev), GFP_KERNEL); - if (!priv->pd_dev) - return -ENOMEM; - - priv->pd_dev_link =3D devm_kmalloc_array(dev, priv->num_pd, sizeof(*priv-= >pd_dev_link), - GFP_KERNEL); - - if (!priv->pd_dev_link) - return -ENOMEM; - - for (i =3D 0; i < priv->num_pd; i++) { - priv->pd_dev[i] =3D dev_pm_domain_attach_by_id(dev, i); - if (IS_ERR(priv->pd_dev[i])) { - ret =3D PTR_ERR(priv->pd_dev[i]); - goto detach_pd; - } - - priv->pd_dev_link[i] =3D device_link_add(dev, priv->pd_dev[i], DL_FLAG_S= TATELESS | - DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE); - if (!priv->pd_dev_link[i]) { - dev_pm_domain_detach(priv->pd_dev[i], false); - ret =3D -EINVAL; - goto detach_pd; - } - } - - return 0; - -detach_pd: - while (--i >=3D 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 =3D rproc->priv; - int i; + int ret; + struct dev_pm_domain_attach_data pd_data =3D { + .pd_flags =3D PD_FLAG_DEV_LINK_ON, + }; =20 /* * 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 <=3D 1) + if (dev->pm_domain) return 0; =20 - for (i =3D 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 =3D dev_pm_domain_attach_list(dev, &pd_data, &priv->pd_list); + return ret < 0 ? ret : 0; } =20 static int imx_rproc_detect_mode(struct imx_rproc *priv) --=20 2.34.1 From nobody Tue Dec 23 23:48:00 2025 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 1AAB36A032 for ; Tue, 30 Jan 2024 12:40:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618406; cv=none; b=bDuHxCbwDYvczD1CrjD5vxbd0gy2l40zLFPQ5Etv7URTSYDvdJOefpgVP0J/a2EEbVEzYfLpetN+s4j2CjRkCb6BKEZcXPg/X7BTluy/amGQSgGugT760YLIQRjR4XZ4u2kQaJMGG7maT2xbgSIkshCtsZ9tuxzhNYceBOUcQd0= 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.47 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-f47.google.com with SMTP id 2adb3069b0e04-510322d5275so4213856e87.1 for ; Tue, 30 Jan 2024 04:40:04 -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=vVUSfpV83dFnM/UeS9i42MWY8y1w79xG0l7LkiOqOnEKAfHcqk7oA2z4upXFMxMXns YvPHeQj18gfinOxzdJAwz2aIvWg3HjjVReiIpU7J33kv8RPm3Z62Cl14U6TYmKLivWiX MJSM7lEcE3OS5Z5YBdEOCdJEBCID2kzPsvjbd4M1ea5WxKwgUo1a862+jw1egHAElmqX Z2B4lF4oC/Xd/mwzjrLIcohL9Xlq1jcWBSsBpxIY4UlPtu+axqXLvBKXKnYKlz2BaSds /0saKODLPl4W1l3HJPo7ONopcyY19Icxt188AJN0JnP5QtCRW6FYj/AGo4AVK5BwRRTr Djuw== X-Gm-Message-State: AOJu0YyRk7PhE/REwbtEtasQp5Y6Sfks64FrODbhPKStSvCp36PEDNbV HyEZmpWe+1BJveRdu0/rTmDn0TcLL65+z2uVtGQhjJlyDls43TII2Ok6CqGdnFs= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =20 -#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 { =20 const char **clk_ids; int num_clks; - const char **proxy_pd_names; + const char **pd_names; + unsigned int num_pds; const char *load_state; }; =20 @@ -110,8 +109,7 @@ struct qcom_adsp { size_t mem_size; bool has_iommu; =20 - struct device *proxy_pds[QCOM_Q6V5_RPROC_PROXY_PD_MAX]; - size_t proxy_pd_count; + struct dev_pm_domain_list *pd_list; =20 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); }; =20 -static int qcom_rproc_pds_attach(struct device *dev, struct qcom_adsp *ads= p, - const char **pd_names) +static int qcom_rproc_pds_attach(struct qcom_adsp *adsp, const char **pd_n= ames, + unsigned int num_pds) { - struct device **devs =3D adsp->proxy_pds; - size_t num_pds =3D 0; + struct device *dev =3D adsp->dev; + struct dev_pm_domain_attach_data pd_data =3D { + .pd_names =3D pd_names, + .num_pd_names =3D num_pds, + }; int ret; - int i; - - if (!pd_names) - return 0; =20 /* Handle single power domain */ - if (dev->pm_domain) { - devs[0] =3D dev; - pm_runtime_enable(dev); - return 1; - } + if (dev->pm_domain) + goto out; =20 - while (pd_names[num_pds]) - num_pds++; + if (!pd_names) + return 0; =20 - if (num_pds > ARRAY_SIZE(adsp->proxy_pds)) - return -E2BIG; + ret =3D dev_pm_domain_attach_list(dev, &pd_data, &adsp->pd_list); + if (ret < 0) + return ret; =20 - for (i =3D 0; i < num_pds; i++) { - devs[i] =3D dev_pm_domain_attach_by_name(dev, pd_names[i]); - if (IS_ERR_OR_NULL(devs[i])) { - ret =3D PTR_ERR(devs[i]) ? : -ENODATA; - goto unroll_attach; - } - } +out: + pm_runtime_enable(dev); + return 0; +} =20 - return num_pds; +static void qcom_rproc_pds_detach(struct qcom_adsp *adsp) +{ + struct device *dev =3D adsp->dev; + struct dev_pm_domain_list *pds =3D adsp->pd_list; =20 -unroll_attach: - for (i--; i >=3D 0; i--) - dev_pm_domain_detach(devs[i], false); + dev_pm_domain_detach_list(pds); =20 - return ret; + if (dev->pm_domain || pds) + pm_runtime_disable(adsp->dev); } =20 -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 =3D adsp->dev; - int i; + struct dev_pm_domain_list *pds =3D adsp->pd_list; + int ret, i =3D 0; =20 - /* Handle single power domain */ - if (dev->pm_domain && pd_count) { - pm_runtime_disable(dev); - return; - } + if (!dev->pm_domain && !pds) + return 0; =20 - for (i =3D 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); =20 -static int qcom_rproc_pds_enable(struct qcom_adsp *adsp, struct device **p= ds, - size_t pd_count) -{ - int ret; - int i; - - for (i =3D 0; i < pd_count; i++) { - dev_pm_genpd_set_performance_state(pds[i], INT_MAX); - ret =3D 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++; } =20 - return 0; + ret =3D 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); + } =20 -unroll_pd_votes: - for (i--; i >=3D 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); } =20 return ret; } =20 -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 =3D adsp->dev; + struct dev_pm_domain_list *pds =3D adsp->pd_list; + int i =3D 0; + + if (!dev->pm_domain && !pds) + return; + + if (dev->pm_domain) + dev_pm_genpd_set_performance_state(dev, 0); =20 - for (i =3D 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); } =20 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; =20 - ret =3D qcom_rproc_pds_enable(adsp, adsp->proxy_pds, - adsp->proxy_pd_count); + ret =3D qcom_rproc_pds_enable(adsp); if (ret < 0) goto disable_xo_clk; =20 @@ -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 *q6= v5) struct qcom_adsp *adsp =3D container_of(q6v5, struct qcom_adsp, q6v5); =20 clk_disable_unprepare(adsp->xo); - qcom_rproc_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count); + qcom_rproc_pds_disable(adsp); } =20 static int adsp_stop(struct rproc *rproc) @@ -715,13 +706,11 @@ static int adsp_probe(struct platform_device *pdev) if (ret) goto free_rproc; =20 - ret =3D qcom_rproc_pds_attach(adsp->dev, adsp, - desc->proxy_pd_names); + ret =3D 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 =3D ret; =20 ret =3D adsp_init_reset(adsp); if (ret) @@ -753,7 +742,7 @@ static int adsp_probe(struct platform_device *pdev) return 0; =20 disable_pm: - qcom_rproc_pds_detach(adsp, adsp->proxy_pds, adsp->proxy_pd_count); + qcom_rproc_pds_detach(adsp); =20 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); } =20 @@ -788,9 +777,8 @@ static const struct adsp_pil_data adsp_resource_init = =3D { "qdsp6ss_xo", "qdsp6ss_sleep", "qdsp6ss_core", NULL }, .num_clks =3D 7, - .proxy_pd_names =3D (const char*[]) { - "cx", NULL - }, + .pd_names =3D (const char*[]) { "cx" }, + .num_pds =3D 1, }; =20 static const struct adsp_pil_data adsp_sc7280_resource_init =3D { @@ -821,9 +809,8 @@ static const struct adsp_pil_data cdsp_resource_init = =3D { "q6_axim", NULL }, .num_clks =3D 7, - .proxy_pd_names =3D (const char*[]) { - "cx", NULL - }, + .pd_names =3D (const char*[]) { "cx" }, + .num_pds =3D 1, }; =20 static const struct adsp_pil_data wpss_resource_init =3D { @@ -839,9 +826,8 @@ static const struct adsp_pil_data wpss_resource_init = =3D { "ahb_bdg", "ahb", "rscp", NULL }, .num_clks =3D 3, - .proxy_pd_names =3D (const char*[]) { - "cx", "mx", NULL - }, + .pd_names =3D (const char*[]) { "cx", "mx" }, + .num_pds =3D 2, }; =20 static const struct of_device_id adsp_of_match[] =3D { --=20 2.34.1 From nobody Tue Dec 23 23:48:00 2025 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 94E5F6D1BA for ; Tue, 30 Jan 2024 12:40:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618408; cv=none; b=cYXMsj6g85GDbZY/UYuSkyKi1zRtVOTNeQ1RiBgamBfXYKMjXum93ntUVaMGzs7eVW1FA87kYeyzoalZbcDTia7vY//9/swlGf0weIdOhCu3fVQw9MWWU/tIbL142NiY57fEFVipqD495nPB9gtcnRBZDzggqXfXk3PaJqV2Bgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706618408; c=relaxed/simple; bh=amT5XvS5cIMcEYdHzb5WGCBIhqN0P7Hqeenb8AqG0zw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Op5yWQu6WvpgvUpfmOcR7D/EGpSU9hzbeWhCjNfTfZnFv6PvfRnDXNi8+1Pk1WWqK2S2Q9FSi/gYLj6NvhxEswJVtD/odRCYL0Xl1DDXBTPLgsl4MTh9+PSmKZe/wgNXLn/YInbI/CMPeyrOy0NhFdo0gTqTnNxbbsJWYx8b4s4= 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=tA7EWbFU; arc=none smtp.client-ip=209.85.167.48 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="tA7EWbFU" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-51030ce36fbso4008121e87.3 for ; Tue, 30 Jan 2024 04:40:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706618403; x=1707223203; 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=OaTT8dB3EwkGsk/s/Xq1pLso3HjDpVKzVVMDBdDT7Fc=; b=tA7EWbFUqqE2O+mCBjAt22hVvtgmbiaa6WKhNVtv3j7Zz34O6sl/TGu+Lvh0NK0FV9 YnmnVqinVSKwkH3A6XRmCpUytXb/3xeZarLVpPXe3BzWV5UoUUFb87iSXWitQoPx9QUz /1DWXCbEJd3DGhrOCsJpViJYEiRyG7R0RN82Q6B/t3FvveSdvALtxTZ+In05Qthc11pr 2W6nAqxgpFCC6tWNi9PE+ktm8UXgfNNS0YfSA+AKV6Jj+7hTmY9fi//ZkDchX0nc8KDi ZByKWMYTE7Avk4WC6vHAVOvC6hRxFxCLKY8wUKmqi3kn4/TCa17A/+Jte7Wfel7zONmf 3Pcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706618403; x=1707223203; 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=OaTT8dB3EwkGsk/s/Xq1pLso3HjDpVKzVVMDBdDT7Fc=; b=HyipHBFcO818WpqyyuD9kBUN6w+4LFv7v/sb7KJVCwDy2YZkCK/oK+VjtJnU+IfZpk 5JSe9ruARbPOZXaZlabSgwIApvu1uNVNpM5vKxaxr17xb2Wpk2x4bEprfbLaHrtSH1PA +6YdhNvCvP0AkTSUyEJDhjTus5vsWVkkcLPV7HCGIWDthOcagLe5UbGu/XLImVj1bq9J CGAKVxzMheYXwbvq7lvK9rQMg1SF10bALMJ4tkddoEJ0h2m+nuzIgYHeGE8H76DscfAh h0Cqdpl8x58IxJOv8vbRWYNnqpxK2KmTRlVx7IlJ5VHLgzXteMX/3zDad8p5mFxITPpD QsBw== X-Gm-Message-State: AOJu0YxMQoPBJjuaDqbqmNwcyLfCIKmhtWNIrcnrOJgvfI/iirIZ05uP +vpMGTosDPvNvhs5RKRoWjmPpVuMVn7iQw/Ak1YuZA+ycm508rsNfCUBC1T0lY8= X-Google-Smtp-Source: AGHT+IFnPKvzbNCMhe6s/L8G6kZw6DMvBRjhbburl1wgaBRZACQ7tPo5D9p5JxU9BQNYUd52+R0E9A== X-Received: by 2002:a05:6512:3046:b0:510:28a9:9b2a with SMTP id b6-20020a056512304600b0051028a99b2amr6215200lfb.66.1706618403620; Tue, 30 Jan 2024 04:40:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:40:03 -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, Mauro Carvalho Chehab , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue Subject: [PATCH v3 5/5] media: venus: Convert to dev_pm_domain_attach|detach_list() for vcodec Date: Tue, 30 Jan 2024 13:39:51 +0100 Message-Id: <20240130123951.236243-6-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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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: Bjorn Andersson Cc: Konrad Dybcio Cc: Tested-by: Bryan O'Donoghue Reviewed-by: Bryan O'Donoghue Signed-off-by: Ulf Hansson --- Changes in v3: - None. Changes in v2: - Added reviewed-by and tested-by 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/platf= orm/qcom/venus/core.c index a712dd4f02a5..ce206b709754 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); =20 for (i =3D 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 =3D { .vcodec0_clks =3D { "vcodec0_core", "vcodec0_bus" }, .vcodec1_clks =3D { "vcodec1_core", "vcodec1_bus" }, .vcodec_clks_num =3D 2, - .vcodec_pmdomains =3D { "venus", "vcodec0", "vcodec1" }, + .vcodec_pmdomains =3D (const char *[]) { "venus", "vcodec0", "vcodec1" }, .vcodec_pmdomains_num =3D 3, .opp_pmdomain =3D (const char *[]) { "cx", NULL }, .vcodec_num =3D 2, @@ -754,7 +756,7 @@ static const struct venus_resources sc7180_res =3D { .clks_num =3D 3, .vcodec0_clks =3D { "vcodec0_core", "vcodec0_bus" }, .vcodec_clks_num =3D 2, - .vcodec_pmdomains =3D { "venus", "vcodec0" }, + .vcodec_pmdomains =3D (const char *[]) { "venus", "vcodec0" }, .vcodec_pmdomains_num =3D 2, .opp_pmdomain =3D (const char *[]) { "cx", NULL }, .vcodec_num =3D 1, @@ -811,7 +813,7 @@ static const struct venus_resources sm8250_res =3D { .resets_num =3D 2, .vcodec0_clks =3D { "vcodec0_core" }, .vcodec_clks_num =3D 1, - .vcodec_pmdomains =3D { "venus", "vcodec0" }, + .vcodec_pmdomains =3D (const char *[]) { "venus", "vcodec0" }, .vcodec_pmdomains_num =3D 2, .opp_pmdomain =3D (const char *[]) { "mx", NULL }, .vcodec_num =3D 1, @@ -870,7 +872,7 @@ static const struct venus_resources sc7280_res =3D { .clks_num =3D 3, .vcodec0_clks =3D {"vcodec_core", "vcodec_bus"}, .vcodec_clks_num =3D 2, - .vcodec_pmdomains =3D { "venus", "vcodec0" }, + .vcodec_pmdomains =3D (const char *[]) { "venus", "vcodec0" }, .vcodec_pmdomains_num =3D 2, .opp_pmdomain =3D (const char *[]) { "cx", NULL }, .vcodec_num =3D 1, diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platf= orm/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 @@ =20 #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 =20 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, uns= igned int coreid_mask) if (ret) return ret; =20 - ret =3D pm_runtime_put_sync(core->pmdomains[1]); + ret =3D 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, uns= igned int coreid_mask) if (ret) return ret; =20 - ret =3D pm_runtime_put_sync(core->pmdomains[2]); + ret =3D 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, unsi= gned int coreid_mask) int ret; =20 if (coreid_mask & VIDC_CORE_ID_1) { - ret =3D pm_runtime_get_sync(core->pmdomains[1]); + ret =3D pm_runtime_get_sync(core->pmdomains->pd_devs[1]); if (ret < 0) return ret; =20 @@ -502,7 +502,7 @@ static int poweron_coreid(struct venus_core *core, unsi= gned int coreid_mask) } =20 if (coreid_mask & VIDC_CORE_ID_2) { - ret =3D pm_runtime_get_sync(core->pmdomains[2]); + ret =3D pm_runtime_get_sync(core->pmdomains->pd_devs[2]); if (ret < 0) return ret; =20 @@ -860,19 +860,18 @@ static int vcodec_domains_get(struct venus_core *core) struct device **opp_virt_dev; struct device *dev =3D core->dev; const struct venus_resources *res =3D core->res; - struct device *pd; - unsigned int i; + struct dev_pm_domain_attach_data vcodec_data =3D { + .pd_names =3D res->vcodec_pmdomains, + .num_pd_names =3D res->vcodec_pmdomains_num, + .pd_flags =3D PD_FLAG_NO_DEV_LINK, + }; =20 if (!res->vcodec_pmdomains_num) goto skip_pmdomains; =20 - for (i =3D 0; i < res->vcodec_pmdomains_num; i++) { - pd =3D 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] =3D pd; - } + ret =3D dev_pm_domain_attach_list(dev, &vcodec_data, &core->pmdomains); + if (ret < 0) + return ret; =20 skip_pmdomains: if (!core->res->opp_pmdomain) @@ -896,30 +895,14 @@ static int vcodec_domains_get(struct venus_core *core) return 0; =20 opp_attach_err: - for (i =3D 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; } =20 static void vcodec_domains_put(struct venus_core *core) { - const struct venus_resources *res =3D core->res; - unsigned int i; + dev_pm_domain_detach_list(core->pmdomains); =20 - if (!res->vcodec_pmdomains_num) - goto skip_pmdomains; - - for (i =3D 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; =20 @@ -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 =3D core->dev; - struct device *pmctrl =3D core->pmdomains[0]; + struct device *pmctrl =3D core->pmdomains ? + core->pmdomains->pd_devs[0] : NULL; int ret =3D 0; =20 if (on =3D=3D POWER_ON) { --=20 2.34.1