From patchwork Wed Aug 23 11:45:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13362188 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10699EE49A0 for ; Wed, 23 Aug 2023 11:45:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234472AbjHWLpu (ORCPT ); Wed, 23 Aug 2023 07:45:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230034AbjHWLpt (ORCPT ); Wed, 23 Aug 2023 07:45:49 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47F38E61 for ; Wed, 23 Aug 2023 04:45:40 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2b95d5ee18dso85330101fa.1 for ; Wed, 23 Aug 2023 04:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692791138; x=1693395938; 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=ebJ/HgXtlSXvICYWJ47VV1HDm4oEylZZhllwmAGAyX8=; b=LEhTUfNwdHcPQHKJjLDAzwuJDnDEkqdEBs0mNE/VfCpfNN9v8kGg6tC/K/y/whcubq UkyQ0To4MD5DJBqWUWBjLGupLDKDJFHMbrEgWgdBjjG3mgJK0/dsTazzHfn9W6LJDYoN dH/Mt+Ns3G5qqdWnVsfTYCKvRNbTIUBcb9+Yh71/BvpW144zOSwNUD4qTB9HMOzl9Fed ngD1VB03sV5Wm4OxWk+EVM6udAvDn+Tp2kcGg7je2KmhW23F2+ZQsqjPmHrLJhR/xsV3 KLwxkB3eEal8RpiClaqUcNmASXQbiP1zmKTM5X01sQfYmPLXB2mtO2Bl6sQUf2Kdxh++ 75mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692791138; x=1693395938; 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=ebJ/HgXtlSXvICYWJ47VV1HDm4oEylZZhllwmAGAyX8=; b=jaFrlgXZ544pKeCpTwAA2X8KFYIccHcQorY30Yc7wz/ACAoAIr+Qxm+Ju3r50tI2+w To0wnQG0oaQj+q+vadFw5SsXbK49wPjfiCJBJRaNT1LC1BS3bsAvd/yWttmOpgVJApVw Q0CPiJtXJ+fv65hPRrcrLsZUBpZLUwKOktMgP+FRXCpjLcvtrRbXyN+QTvX9D81cj+Xw 0zYtugm50My3Dd+0X9FQ7SJA+08e9Nn0HFY+lp2u8u/db7Jueul634ZcD/9ARNy0ix0o MpTtehvk+1fxvXvWx4kmxgQpkz26hQL5zn6M04gOn+bK6fjmOq8SXkpqKDsLiJJKq+L0 rNbA== X-Gm-Message-State: AOJu0YzJRg/Ol4Foivk5XvHID2kMhUw/kYW9WTYLWeQMp178OkFNUDbx hJ46tvyk+V0sTTwP9FtRkv48ew== X-Google-Smtp-Source: AGHT+IGopHKCYCAK4BIu8bEySAGAu9Ubh3cQKYty+S0IA7nJiCXRt62zsGe6sXcbndVKnkCa+KHQyw== X-Received: by 2002:a2e:9e42:0:b0:2b9:e53f:e201 with SMTP id g2-20020a2e9e42000000b002b9e53fe201mr8541267ljk.31.1692791138306; Wed, 23 Aug 2023 04:45:38 -0700 (PDT) Received: from hackbox.lan ([84.232.191.92]) by smtp.gmail.com with ESMTPSA id m18-20020a7bce12000000b003fbc0a49b57sm18503577wmc.6.2023.08.23.04.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 04:45:37 -0700 (PDT) From: Abel Vesa To: "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson , Pavel Machek , Len Brown , Greg Kroah-Hartman , Bjorn Andersson , Andy Gross , Konrad Dybcio , Mike Turquette , Stephen Boyd , Taniya Das Cc: linux-pm@vger.kernel.org, Linux Kernel Mailing List , linux-arm-msm@vger.kernel.org Subject: [PATCH v3 1/5] PM: domains: Allow devices attached to genpd to be managed by HW Date: Wed, 23 Aug 2023 14:45:24 +0300 Message-Id: <20230823114528.3677667-2-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823114528.3677667-1-abel.vesa@linaro.org> References: <20230823114528.3677667-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Ulf Hansson Some power-domains may be capable of relying on the HW to control the power for a device that's hooked up to it. Typically, for these kinds of configurations the device doesn't really need to be attached to a PM domain (genpd), from Linux point of view. However, in some cases the behaviour of the power-domain and its device can be changed in runtime. To allow a consumer driver to change the behaviour of the PM domain for its device, let's provide a new function, dev_pm_genpd_set_hwmode(). Moreover, let's add a corresponding optional genpd callback, ->set_hwmode_dev(), which the genpd provider should implement if it can support switching between HW controlled mode and SW controlled mode. Similarly, add the dev_pm_genpd_get_hwmode() to allow consumers to read the current mode and its corresponding optional genpd callback, ->get_hwmode_dev(), which the genpd provider can also implement for reading back the mode from the hardware. Signed-off-by: Ulf Hansson Signed-off-by: Abel Vesa --- Changes since v2: * None drivers/base/power/domain.c | 69 +++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 17 +++++++++ 2 files changed, 86 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 5cb2023581d4..dfb4f1de540d 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -541,6 +541,75 @@ void dev_pm_genpd_synced_poweroff(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_genpd_synced_poweroff); +/** + * dev_pm_genpd_set_hwmode - Set the HW mode for the device and its PM domain. + * + * @dev: Device for which the HW-mode should be changed. + * @enable: Value to set or unset the HW-mode. + * + * Some PM domains can rely on HW signals to control the power for a device. To + * allow a consumer driver to switch the behaviour for its device in runtime, + * which may be beneficial from a latency or energy point of view, this function + * may be called. + * + * It is assumed that the users guarantee that the genpd wouldn't be detached + * while this routine is getting called. + * + * Returns 0 on success and negative error values on failures. + */ +int dev_pm_genpd_set_hwmode(struct device *dev, bool enable) +{ + struct generic_pm_domain *genpd; + int ret = 0; + + genpd = dev_to_genpd_safe(dev); + if (!genpd) + return -ENODEV; + + if (!genpd->set_hwmode_dev) + return -EOPNOTSUPP; + + genpd_lock(genpd); + + if (dev_gpd_data(dev)->hw_mode == enable) + goto out; + + ret = genpd->set_hwmode_dev(genpd, dev, enable); + if (!ret) + dev_gpd_data(dev)->hw_mode = enable; + +out: + genpd_unlock(genpd); + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_genpd_set_hwmode); + +/** + * dev_pm_genpd_get_hwmode - Get the HW mode setting for the device. + * + * @dev: Device for which the current HW-mode setting should be fetched. + * + * This helper function allows consumer drivers to fetch the current HW mode + * setting of its the device. + * + * It is assumed that the users guarantee that the genpd wouldn't be detached + * while this routine is getting called. + */ +bool dev_pm_genpd_get_hwmode(struct device *dev) +{ + struct generic_pm_domain *genpd; + + genpd = dev_to_genpd_safe(dev); + if (!genpd) + return false; + + if (genpd->get_hwmode_dev) + return genpd->get_hwmode_dev(genpd, dev); + + return dev_gpd_data(dev)->hw_mode; +} +EXPORT_SYMBOL_GPL(dev_pm_genpd_get_hwmode); + static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) { unsigned int state_idx = genpd->state_idx; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index f776fb93eaa0..36d308ba40b0 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -146,6 +146,10 @@ struct generic_pm_domain { int (*set_performance_state)(struct generic_pm_domain *genpd, unsigned int state); struct gpd_dev_ops dev_ops; + int (*set_hwmode_dev)(struct generic_pm_domain *domain, + struct device *dev, bool enable); + bool (*get_hwmode_dev)(struct generic_pm_domain *domain, + struct device *dev); int (*attach_dev)(struct generic_pm_domain *domain, struct device *dev); void (*detach_dev)(struct generic_pm_domain *domain, @@ -208,6 +212,7 @@ struct generic_pm_domain_data { unsigned int performance_state; unsigned int default_pstate; unsigned int rpm_pstate; + bool hw_mode; void *data; }; @@ -237,6 +242,8 @@ int dev_pm_genpd_remove_notifier(struct device *dev); void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next); ktime_t dev_pm_genpd_get_next_hrtimer(struct device *dev); void dev_pm_genpd_synced_poweroff(struct device *dev); +int dev_pm_genpd_set_hwmode(struct device *dev, bool enable); +bool dev_pm_genpd_get_hwmode(struct device *dev); extern struct dev_power_governor simple_qos_governor; extern struct dev_power_governor pm_domain_always_on_gov; @@ -305,6 +312,16 @@ static inline ktime_t dev_pm_genpd_get_next_hrtimer(struct device *dev) static inline void dev_pm_genpd_synced_poweroff(struct device *dev) { } +static inline int dev_pm_genpd_set_hwmode(struct device *dev, bool enable) +{ + return -EOPNOTSUPP; +} + +static inline bool dev_pm_genpd_get_hwmode(struct device *dev) +{ + return false; +} + #define simple_qos_governor (*(struct dev_power_governor *)(NULL)) #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL)) #endif From patchwork Wed Aug 23 11:45:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13362189 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2542EE49B5 for ; Wed, 23 Aug 2023 11:45:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234480AbjHWLpu (ORCPT ); Wed, 23 Aug 2023 07:45:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234449AbjHWLpt (ORCPT ); Wed, 23 Aug 2023 07:45:49 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82F67E65 for ; Wed, 23 Aug 2023 04:45:41 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b95d5ee18dso85330341fa.1 for ; Wed, 23 Aug 2023 04:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692791140; x=1693395940; 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=O7tHqCtCBwrBi+V5VhXtnXcNtgviyB9B8EoBzfXwamQ=; b=E8GWGehguy7PP4MX5+Ef/QMUDP9jO042Djy0QuWaaJ8WBLX960EVJOJ5JAdzm6aXxS iFAsnk0PL4/fdEY9CHQ7JfdtzDW5RJ/ggoQpMcg9306EQ7lr5CZ+NR3RUnunLpQ3budb x+zdO03UVyovdggvHc4COXayuwUhMl67cK8Ne3sKgJhe7lGliC53GDaqz/Nus8BDuI7G gKqssHAGlbvdVCK/mjBJ2tNrRfpWcHTv8acmqxf7g6FXdVcZmUrNXIubaeT7V+70AMId AsNTSLsDHOoqmVD/huyhBJ6+MM/GBvTyBE6u14nvmL6bz2gc0T6OZCWPqvlvU6WS1xHT wzqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692791140; x=1693395940; 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=O7tHqCtCBwrBi+V5VhXtnXcNtgviyB9B8EoBzfXwamQ=; b=lgYN1an3ON8RJVFqTgc57ool8p7Kzouwv5681Pp4YnhJrqCR8ywEb4L05poAb4Nfvp vIsilYD6mIg+N0amHsI9VKhbSKDWTAGsBXJjVQ6BlZwilj7RQ6WWMah8JOi4LrpVIsor nttHC49lbrKCvNEFrYOvJcgP60fd9a7m4mMkfrW+NQ0JQXaqYRspnUrZsyiWLPK6ipRN xcxXcyBkuK/bwEv9KNJ+T1+/KbsNI7xP64qphCmCxgT6dOtaoDt2q/u+DKwk4aB9ZvZM ulVxpCHl2L3QDVTCSnSCNu9BIc5XpVPd683sdAjm8RJasNSA7LCvfcorpVGiVdDTHjuk /BiA== X-Gm-Message-State: AOJu0Yx9FHPh+QTFD72T4bSo/9u/Gy6a6E/qFQG7EHERpMY6Z6EOAn0o xgGZkKSYqO4WeFL5muK+DmS1Xg== X-Google-Smtp-Source: AGHT+IHdwziasj0D1MZ9uBcdhByqBC95ew9J9TcFICwlP0Jl9zRXSGXh3Dl8RPw6cWdVo/fTvnM4uQ== X-Received: by 2002:a2e:88d1:0:b0:2b6:cff1:cd1c with SMTP id a17-20020a2e88d1000000b002b6cff1cd1cmr9657741ljk.34.1692791139858; Wed, 23 Aug 2023 04:45:39 -0700 (PDT) Received: from hackbox.lan ([84.232.191.92]) by smtp.gmail.com with ESMTPSA id m18-20020a7bce12000000b003fbc0a49b57sm18503577wmc.6.2023.08.23.04.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 04:45:39 -0700 (PDT) From: Abel Vesa To: "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson , Pavel Machek , Len Brown , Greg Kroah-Hartman , Bjorn Andersson , Andy Gross , Konrad Dybcio , Mike Turquette , Stephen Boyd , Taniya Das Cc: linux-pm@vger.kernel.org, Linux Kernel Mailing List , linux-arm-msm@vger.kernel.org, Taniya Das Subject: [PATCH v3 2/5] PM: domains: Add the domain HW-managed mode to the summary Date: Wed, 23 Aug 2023 14:45:25 +0300 Message-Id: <20230823114528.3677667-3-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823114528.3677667-1-abel.vesa@linaro.org> References: <20230823114528.3677667-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Now that genpd supports dynamically switching the control for an attached device between hardware- and software-mode, let's add this information to the genpd summary in debugfs. Suggested-by: Taniya Das Signed-off-by: Abel Vesa Reviewed-by: Ulf Hansson --- Changes since v2: * Reworded the commit according to Ulf's suggestion * Dropped the _mode suffix from the status * Replaced "mode" with "managed by" in summary show function drivers/base/power/domain.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index dfb4f1de540d..93350e67b0e8 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -3171,6 +3171,15 @@ static void rtpm_status_str(struct seq_file *s, struct device *dev) seq_printf(s, "%-25s ", p); } +static void mode_status_str(struct seq_file *s, struct device *dev) +{ + struct generic_pm_domain_data *gpd_data; + + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); + + seq_printf(s, "%20s", gpd_data->hw_mode ? "HW" : "SW"); +} + static void perf_status_str(struct seq_file *s, struct device *dev) { struct generic_pm_domain_data *gpd_data; @@ -3229,6 +3238,7 @@ static int genpd_summary_one(struct seq_file *s, seq_printf(s, "\n %-50s ", kobj_path); rtpm_status_str(s, pm_data->dev); perf_status_str(s, pm_data->dev); + mode_status_str(s, pm_data->dev); kfree(kobj_path); } @@ -3245,8 +3255,9 @@ static int summary_show(struct seq_file *s, void *data) int ret = 0; seq_puts(s, "domain status children performance\n"); - seq_puts(s, " /device runtime status\n"); - seq_puts(s, "----------------------------------------------------------------------------------------------\n"); + seq_puts(s, " /device runtime status managed by\n"); + seq_puts(s, "------------------------------------------------------------------------------------------------------------\n"); + ret = mutex_lock_interruptible(&gpd_list_lock); if (ret) From patchwork Wed Aug 23 11:45:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13362191 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05D59EE49B4 for ; Wed, 23 Aug 2023 11:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234483AbjHWLpv (ORCPT ); Wed, 23 Aug 2023 07:45:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234467AbjHWLpu (ORCPT ); Wed, 23 Aug 2023 07:45:50 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E32E69 for ; Wed, 23 Aug 2023 04:45:43 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b962c226ceso85857611fa.3 for ; Wed, 23 Aug 2023 04:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692791141; x=1693395941; 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=mIFCktYXgfosXvRJrwvf1Hn5zhw2HJrFavQvWXV6mTw=; b=FdRXZNWCys86ONbUfYvQt0vxbvSb4HIgklznVQGdtN+rWYFQDHN5vkpve/5CJnNfn0 5s3VZrvsls5p+XGkTBmmmRvnisaiCbLVuu6WfI0LmwzJSHFlQGrxqLlb94eSRvdV89CH loGY5WrubIPPZJFot0gctKFAddpdRDYdQFoJ8O9IMyntHzizVbRSShqJ13RIOVWaaU/P H3fL9VZZ6ojindXZV0JU6IVQMgsegNpiMBwb/8ZOZ1R0DKhNj9dhlXnhzJjQ6SuHnVgS AUW6q+ue5ZhZhqD8S56ehtCFHqUVKhKt3CQ65kViyjmuobxfaM5uvejp3PI0Lg8wB7JX Mqlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692791141; x=1693395941; 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=mIFCktYXgfosXvRJrwvf1Hn5zhw2HJrFavQvWXV6mTw=; b=CF3iaiRNSArDalEQCbXnL6H4KABqT2c+ZZWRb1ppJmAsOZKNam3SItjXHbBNWFLj7v Z1GQlFltArFij8jJV6fCECG07MQu6sFPrMMMs9V/8XkrzVYUB6S3qdq6gdIH3QGXzzRa Yv4TCyInQcQcbIHRcTe499czQmCubbSn7QHSpZRsUfPglQ3HehfNPoZyZd/j+v5732gI s95+HJtQ3g0gpme4czo49U3D6CGjucfX+GiGfjK9QtQYmUklrUL4N6EWeHjLMVCM52VU A0GasJ8UIt9NeiS8WxJ4qSYMCMNPGB+ddImzhO4BcQdMSxBupnBdRX6B/Xr2sKELBHOH ILoQ== X-Gm-Message-State: AOJu0Ywfsm/YFcd/wg9Xch95cdGyqtsq9h+KDbSdZeA5YhiFIks8C0Ch zlyUnv5RGlQyT9AMvUV1bstL5g== X-Google-Smtp-Source: AGHT+IGfHdql2lUUitqm6RYx89C3kDrLaaP4sDPXsex/N/CCvhLQQH+Cc4IngnkpCXY+EGU9voq4uA== X-Received: by 2002:a2e:9546:0:b0:2b9:ed84:b2bf with SMTP id t6-20020a2e9546000000b002b9ed84b2bfmr8931106ljh.33.1692791141363; Wed, 23 Aug 2023 04:45:41 -0700 (PDT) Received: from hackbox.lan ([84.232.191.92]) by smtp.gmail.com with ESMTPSA id m18-20020a7bce12000000b003fbc0a49b57sm18503577wmc.6.2023.08.23.04.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 04:45:40 -0700 (PDT) From: Abel Vesa To: "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson , Pavel Machek , Len Brown , Greg Kroah-Hartman , Bjorn Andersson , Andy Gross , Konrad Dybcio , Mike Turquette , Stephen Boyd , Taniya Das Cc: linux-pm@vger.kernel.org, Linux Kernel Mailing List , linux-arm-msm@vger.kernel.org, Jagadeesh Kona Subject: [PATCH v3 3/5] clk: qcom: gdsc: Add set and get hwmode callbacks to switch GDSC mode Date: Wed, 23 Aug 2023 14:45:26 +0300 Message-Id: <20230823114528.3677667-4-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823114528.3677667-1-abel.vesa@linaro.org> References: <20230823114528.3677667-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jagadeesh Kona Add support for set and get hwmode callbacks to switch the GDSC between SW and HW modes. Currently, the GDSC is moved to HW control mode using HW_CTRL flag and if this flag is present, GDSC is moved to HW mode as part of GDSC enable itself. The intention is to keep the HW_CTRL flag functionality as is, since many older chipsets still use this flag. Introduce a new HW_CTRL_TRIGGER flag to switch the GDSC back and forth between HW/SW modes dynamically at runtime. If HW_CTRL_TRIGGER flag is present, register set_hwmode_dev callback to switch the GDSC mode which can be invoked from consumer drivers using dev_pm_genpd_set_hwmode function. Unlike HW_CTRL flag, HW_CTRL_TRIGGER won't move the GDSC to HW control mode as part of GDSC enable itself, GDSC will be moved to HW control mode only when consumer driver explicity calls dev_pm_genpd_set_hwmode to switch to HW mode. Also add the dev_pm_genpd_get_hwmode to allow the consumers to read the actual HW/SW mode from hardware. Signed-off-by: Jagadeesh Kona Signed-off-by: Abel Vesa --- Changes since v2: * Renamed gdsc_[set|get]_mode to have the hwmode suffix drivers/clk/qcom/gdsc.c | 32 ++++++++++++++++++++++++++++++++ drivers/clk/qcom/gdsc.h | 1 + 2 files changed, 33 insertions(+) diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c index 5358e28122ab..c763524cd5da 100644 --- a/drivers/clk/qcom/gdsc.c +++ b/drivers/clk/qcom/gdsc.c @@ -363,6 +363,34 @@ static int gdsc_disable(struct generic_pm_domain *domain) return 0; } +static int gdsc_set_hwmode(struct generic_pm_domain *domain, struct device *dev, bool mode) +{ + struct gdsc *sc = domain_to_gdsc(domain); + + if (sc->rsupply && !regulator_is_enabled(sc->rsupply)) { + pr_err("Cannot set mode while parent is disabled\n"); + return -EIO; + } + + return gdsc_hwctrl(sc, mode); +} + +static bool gdsc_get_hwmode(struct generic_pm_domain *domain, struct device *dev) +{ + struct gdsc *sc = domain_to_gdsc(domain); + u32 val; + int ret; + + ret = regmap_read(sc->regmap, sc->gdscr, &val); + if (ret) + return ret; + + if (val & HW_CONTROL_MASK) + return true; + + return false; +} + static int gdsc_init(struct gdsc *sc) { u32 mask, val; @@ -451,6 +479,10 @@ static int gdsc_init(struct gdsc *sc) sc->pd.power_off = gdsc_disable; if (!sc->pd.power_on) sc->pd.power_on = gdsc_enable; + if (sc->flags & HW_CTRL_TRIGGER) { + sc->pd.set_hwmode_dev = gdsc_set_hwmode; + sc->pd.get_hwmode_dev = gdsc_get_hwmode; + } ret = pm_genpd_init(&sc->pd, NULL, !on); if (ret) diff --git a/drivers/clk/qcom/gdsc.h b/drivers/clk/qcom/gdsc.h index 803512688336..1e2779b823d1 100644 --- a/drivers/clk/qcom/gdsc.h +++ b/drivers/clk/qcom/gdsc.h @@ -67,6 +67,7 @@ struct gdsc { #define ALWAYS_ON BIT(6) #define RETAIN_FF_ENABLE BIT(7) #define NO_RET_PERIPH BIT(8) +#define HW_CTRL_TRIGGER BIT(9) struct reset_controller_dev *rcdev; unsigned int *resets; unsigned int reset_count; From patchwork Wed Aug 23 11:45:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13362192 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F9ADC3DA66 for ; Wed, 23 Aug 2023 11:45:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234471AbjHWLpw (ORCPT ); Wed, 23 Aug 2023 07:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234475AbjHWLpu (ORCPT ); Wed, 23 Aug 2023 07:45:50 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ECBEE6D for ; Wed, 23 Aug 2023 04:45:44 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2bcb50e194dso57741181fa.3 for ; Wed, 23 Aug 2023 04:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692791143; x=1693395943; 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=PjH481Mf/JKMLSS8Dehl9BZait7n4XBpkdkpaAiw/gc=; b=jiMw21MAtfSSZZamwPjrKgZisbPFYjJNfmVMTY7M+qXHI+TjVXKX+VzvCia/akMOpD 7Vdte8K+0r9v3PCDyVB6vLOCrKxsuixhOtQyOh2lXtIf7CG8X86WevPFOp1Vp93g4xwl Qd/GsDcACXa6D02nXVfrQeju44MCnUlJhDKE9uHJpJFgMc8RyRSyJYDQOZJzKlALzDvV 5WQtN4D5GP/V3aIG4rsG8Gv+4SlVLs843zoVj3+vpYy3LZL5GYLHZVhpH851Tqn6JYbQ FXqxO/caaAB+zjOsK/7AGHjjotDUxWawb0SsXcewacFdq03fy3FQ/h+KYEiO6TdfXNTU xHUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692791143; x=1693395943; 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=PjH481Mf/JKMLSS8Dehl9BZait7n4XBpkdkpaAiw/gc=; b=L0jZ/tKEWCqGtVWebkkLBnPWXtFU9ilwG0dAlbKfmim8h+fhBunPrsv2bhbXwOsUIk IxLfX70RS+Gu+HPetdEKMShTv/MYqPxojwoM9gDg4W79unPcev+aS88hFcRRbjsGqflY PISlUwLcFMTXlZFHAD7KE0SM0JlqL2almwAqQ7pyvgVhoYtaY/LO1qtpmJzxQeQdEu1A 7H7pmnQj0osHcB+nAWlF5m42f5jGX+6tUqF1h/MltFQkzxge4po6KygQUBbWs6l6UE90 u3sZFjNkLoEaJINe4/9az26rbbfBWyNKuOo90YIUAK3ocv23e1J8UfN/IKsER4G+S6ip PAnw== X-Gm-Message-State: AOJu0YzVVL8JPKehkWEllhX1lO/x2YtBnXqBpQEHR0kkAKC+8iVYFutX PE+iV+FG2DxX00NmRpPgJvU4WQ== X-Google-Smtp-Source: AGHT+IHv2sYKsl83YnEQionvwx0hiN959Vk/xragTx2/5jUNBywepZwvuDhDBa1tzQ/GfQkGBPpKsQ== X-Received: by 2002:a2e:8746:0:b0:2b9:20fe:4bc4 with SMTP id q6-20020a2e8746000000b002b920fe4bc4mr8847065ljj.40.1692791142942; Wed, 23 Aug 2023 04:45:42 -0700 (PDT) Received: from hackbox.lan ([84.232.191.92]) by smtp.gmail.com with ESMTPSA id m18-20020a7bce12000000b003fbc0a49b57sm18503577wmc.6.2023.08.23.04.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 04:45:42 -0700 (PDT) From: Abel Vesa To: "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson , Pavel Machek , Len Brown , Greg Kroah-Hartman , Bjorn Andersson , Andy Gross , Konrad Dybcio , Mike Turquette , Stephen Boyd , Taniya Das Cc: linux-pm@vger.kernel.org, Linux Kernel Mailing List , linux-arm-msm@vger.kernel.org, Jagadeesh Kona Subject: [PATCH v3 4/5] clk: qcom: Use HW_CTRL_TRIGGER flag to switch video GDSC to HW mode Date: Wed, 23 Aug 2023 14:45:27 +0300 Message-Id: <20230823114528.3677667-5-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823114528.3677667-1-abel.vesa@linaro.org> References: <20230823114528.3677667-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jagadeesh Kona The current HW_CTRL flag switches the video GDSC to HW control mode as part of GDSC enable itself, instead of that use HW_CTRL_TRIGGER flag to give consumer drivers more control and switch the GDSC mode as and when required. HW_CTRL_TRIGGER flag allows consumer drivers to switch the video GDSC to HW/SW control modes at runtime using dev_pm_genpd_set_hwmode API. Signed-off-by: Jagadeesh Kona Signed-off-by: Abel Vesa --- Changes since v2: * The 5th patch was squashed into this one. No other change done. drivers/clk/qcom/videocc-sc7180.c | 2 +- drivers/clk/qcom/videocc-sc7280.c | 2 +- drivers/clk/qcom/videocc-sdm845.c | 4 ++-- drivers/clk/qcom/videocc-sm8250.c | 4 ++-- drivers/clk/qcom/videocc-sm8550.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/clk/qcom/videocc-sc7180.c b/drivers/clk/qcom/videocc-sc7180.c index 5b9b54f616b8..51439f7ba70c 100644 --- a/drivers/clk/qcom/videocc-sc7180.c +++ b/drivers/clk/qcom/videocc-sc7180.c @@ -166,7 +166,7 @@ static struct gdsc vcodec0_gdsc = { .pd = { .name = "vcodec0_gdsc", }, - .flags = HW_CTRL, + .flags = HW_CTRL_TRIGGER, .pwrsts = PWRSTS_OFF_ON, }; diff --git a/drivers/clk/qcom/videocc-sc7280.c b/drivers/clk/qcom/videocc-sc7280.c index 615695d82319..3d07b1e95986 100644 --- a/drivers/clk/qcom/videocc-sc7280.c +++ b/drivers/clk/qcom/videocc-sc7280.c @@ -236,7 +236,7 @@ static struct gdsc mvs0_gdsc = { .name = "mvs0_gdsc", }, .pwrsts = PWRSTS_OFF_ON, - .flags = HW_CTRL | RETAIN_FF_ENABLE, + .flags = HW_CTRL_TRIGGER | RETAIN_FF_ENABLE, }; static struct gdsc mvsc_gdsc = { diff --git a/drivers/clk/qcom/videocc-sdm845.c b/drivers/clk/qcom/videocc-sdm845.c index c77a4dd5d39c..dad011c48973 100644 --- a/drivers/clk/qcom/videocc-sdm845.c +++ b/drivers/clk/qcom/videocc-sdm845.c @@ -260,7 +260,7 @@ static struct gdsc vcodec0_gdsc = { }, .cxcs = (unsigned int []){ 0x890, 0x930 }, .cxc_count = 2, - .flags = HW_CTRL | POLL_CFG_GDSCR, + .flags = HW_CTRL_TRIGGER | POLL_CFG_GDSCR, .pwrsts = PWRSTS_OFF_ON, }; @@ -271,7 +271,7 @@ static struct gdsc vcodec1_gdsc = { }, .cxcs = (unsigned int []){ 0x8d0, 0x950 }, .cxc_count = 2, - .flags = HW_CTRL | POLL_CFG_GDSCR, + .flags = HW_CTRL_TRIGGER | POLL_CFG_GDSCR, .pwrsts = PWRSTS_OFF_ON, }; diff --git a/drivers/clk/qcom/videocc-sm8250.c b/drivers/clk/qcom/videocc-sm8250.c index ad46c4014a40..c1b73d852f1c 100644 --- a/drivers/clk/qcom/videocc-sm8250.c +++ b/drivers/clk/qcom/videocc-sm8250.c @@ -293,7 +293,7 @@ static struct gdsc mvs0_gdsc = { .pd = { .name = "mvs0_gdsc", }, - .flags = HW_CTRL, + .flags = HW_CTRL_TRIGGER, .pwrsts = PWRSTS_OFF_ON, }; @@ -302,7 +302,7 @@ static struct gdsc mvs1_gdsc = { .pd = { .name = "mvs1_gdsc", }, - .flags = HW_CTRL, + .flags = HW_CTRL_TRIGGER, .pwrsts = PWRSTS_OFF_ON, }; diff --git a/drivers/clk/qcom/videocc-sm8550.c b/drivers/clk/qcom/videocc-sm8550.c index 3bb136ec31b1..504b2ef264eb 100644 --- a/drivers/clk/qcom/videocc-sm8550.c +++ b/drivers/clk/qcom/videocc-sm8550.c @@ -324,7 +324,7 @@ static struct gdsc video_cc_mvs0_gdsc = { }, .pwrsts = PWRSTS_OFF_ON, .parent = &video_cc_mvs0c_gdsc.pd, - .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE | HW_CTRL, + .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE | HW_CTRL_TRIGGER, }; static struct gdsc video_cc_mvs1c_gdsc = { @@ -349,7 +349,7 @@ static struct gdsc video_cc_mvs1_gdsc = { }, .pwrsts = PWRSTS_OFF_ON, .parent = &video_cc_mvs1c_gdsc.pd, - .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE | HW_CTRL, + .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE | HW_CTRL_TRIGGER, }; static struct clk_regmap *video_cc_sm8550_clocks[] = { From patchwork Wed Aug 23 11:45:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13362193 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2C2EEE49BC for ; Wed, 23 Aug 2023 11:45:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234476AbjHWLpw (ORCPT ); Wed, 23 Aug 2023 07:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234477AbjHWLpu (ORCPT ); Wed, 23 Aug 2023 07:45:50 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 663A3E70 for ; Wed, 23 Aug 2023 04:45:46 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bccda76fb1so30479221fa.2 for ; Wed, 23 Aug 2023 04:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692791144; x=1693395944; 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=mj2meqHj1uQ8ycW47wSLw+vGt1Gkm3UaWY3FGRdov4I=; b=LxvOihteykPsbq0ELFTsjunH9/Ll/sHYoF0bL2a2KmEegWSK8l3PyI9a5mqt/x1VYu YBppL1uMhdjmPARq5c7mFKF0ek45ULf1vCjrkQRwiRGQBW68DfWSattIGoViHoWRHImk pRC6/mClZ+V8jq7/nxnYcEGU241WIaqTkuzwykfJDWGrzIDEGLMWw0e0ClhnX7st4rpE x4FJAxwrWpuJXQ/DWzKFQYq6TqCJsu/HnQaZHI/ZKuekcveLchxOJnU/ATtJRoUyNwrV vb7PglOWtDhHcnC1IRbAd4AOVBd29xdbxDwIzif9js0jEWQcj6akAa3xt4+Sp3rvZUOW I1Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692791144; x=1693395944; 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=mj2meqHj1uQ8ycW47wSLw+vGt1Gkm3UaWY3FGRdov4I=; b=ChydoNCqBoj2jhMKHKIlObMTVDJWVJC1evjVeiG00kf1/CJut++s6O+dauABxvSGXb N1qvPY6p3oW1Iz2fvxh1v9vI6Tewq+3shHHWIlqoqQS7Q2BSyYIiERpkFNCtDpS+2yD+ odNLT4lL2shwmJWE73Llwy8yY6lCFq8/1EHk7rrKByjfmgp9a9BhYBKNbq1/ce970ikt QrBSwmi/cQX2mfmCotl6Dar+p9BRvEzKpWQ8gf+eOXovpBNQShHYcndTN43emmr74sof 0cULVIdlKtqC2s/wjTYEPBc1fJ0xH4DiuZ9ToruSlo7hKxXoswEFe+IgchU6TGDdwwek Gtjw== X-Gm-Message-State: AOJu0YzKmNP/dLJ7ix0TpHzX7u+H2ZToZW9zDINfTndikUufD9HlZwr8 cwT9g2fW3V5kuOhpwAJm13xzqg== X-Google-Smtp-Source: AGHT+IHcRniuOaTwNb3qeIRnIhh7FLNsaHEOk7sAt8OJGcjm/DL1E6rAHN1GjxntF7AtC9iXjIu26g== X-Received: by 2002:a2e:908a:0:b0:2bc:b0c3:9e8d with SMTP id l10-20020a2e908a000000b002bcb0c39e8dmr8678383ljg.41.1692791144651; Wed, 23 Aug 2023 04:45:44 -0700 (PDT) Received: from hackbox.lan ([84.232.191.92]) by smtp.gmail.com with ESMTPSA id m18-20020a7bce12000000b003fbc0a49b57sm18503577wmc.6.2023.08.23.04.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 04:45:44 -0700 (PDT) From: Abel Vesa To: "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson , Pavel Machek , Len Brown , Greg Kroah-Hartman , Bjorn Andersson , Andy Gross , Konrad Dybcio , Mike Turquette , Stephen Boyd , Taniya Das Cc: linux-pm@vger.kernel.org, Linux Kernel Mailing List , linux-arm-msm@vger.kernel.org, Jagadeesh Kona Subject: [PATCH v3 5/5] venus: pm_helpers: Use dev_pm_genpd_set_hwmode to switch GDSC mode Date: Wed, 23 Aug 2023 14:45:28 +0300 Message-Id: <20230823114528.3677667-6-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823114528.3677667-1-abel.vesa@linaro.org> References: <20230823114528.3677667-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jagadeesh Kona This change demonstrates the use of dev_pm_genpd_set_hwmode API from video driver to switch the video mvs0 gdsc to SW/HW modes at runtime based on requirement. This change adds a new boolean array member vcodec_pmdomains_hwctrl in venus_resources structure to indicate if GDSC's have HW control support or not. This data is used in vcodec_control_v4() to check if GDSC has support to switch to HW control mode and then call dev_pm_genpd_set_hwmode to switch the GDSC mode. Before the GDSC HWCTL was available to the consumer, the venus driver needed to somehow keep the power from collapsing while under the driver control. The only way to do that was to clear the CORE_PWR_DISABLE bit (in wrapper POWER_CONTROL register) and, respectively, set it back after the driver control was completed. Now, that there is a way to switch the GDSC HW/SW control back and forth, the CORE_PWR_DISABLE toggling can be dropped. Signed-off-by: Jagadeesh Kona Signed-off-by: Abel Vesa --- Changes since v2: * Explained the removal of the POWER_CONTROL register toggle and why the fact the GDSC HW control knob availability to the consumer renders that useless. drivers/media/platform/qcom/venus/core.c | 4 ++ drivers/media/platform/qcom/venus/core.h | 1 + .../media/platform/qcom/venus/pm_helpers.c | 47 ++++++++----------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 054b8e74ba4f..8145062ab6f7 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -706,6 +706,7 @@ static const struct venus_resources sdm845_res_v2 = { .vcodec1_clks = { "vcodec1_core", "vcodec1_bus" }, .vcodec_clks_num = 2, .vcodec_pmdomains = { "venus", "vcodec0", "vcodec1" }, + .vcodec_pmdomains_hwctrl = { false, true, true }, .vcodec_pmdomains_num = 3, .opp_pmdomain = (const char *[]) { "cx", NULL }, .vcodec_num = 2, @@ -755,6 +756,7 @@ static const struct venus_resources sc7180_res = { .vcodec0_clks = { "vcodec0_core", "vcodec0_bus" }, .vcodec_clks_num = 2, .vcodec_pmdomains = { "venus", "vcodec0" }, + .vcodec_pmdomains_hwctrl = { false, true }, .vcodec_pmdomains_num = 2, .opp_pmdomain = (const char *[]) { "cx", NULL }, .vcodec_num = 1, @@ -812,6 +814,7 @@ static const struct venus_resources sm8250_res = { .vcodec0_clks = { "vcodec0_core" }, .vcodec_clks_num = 1, .vcodec_pmdomains = { "venus", "vcodec0" }, + .vcodec_pmdomains_hwctrl = { false, true }, .vcodec_pmdomains_num = 2, .opp_pmdomain = (const char *[]) { "mx", NULL }, .vcodec_num = 1, @@ -871,6 +874,7 @@ static const struct venus_resources sc7280_res = { .vcodec0_clks = {"vcodec_core", "vcodec_bus"}, .vcodec_clks_num = 2, .vcodec_pmdomains = { "venus", "vcodec0" }, + .vcodec_pmdomains_hwctrl = { false, true }, .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..6d591ecad482 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -73,6 +73,7 @@ struct venus_resources { const char * const vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX]; unsigned int vcodec_clks_num; const char * const vcodec_pmdomains[VIDC_PMDOMAINS_NUM_MAX]; + bool vcodec_pmdomains_hwctrl[VIDC_PMDOMAINS_NUM_MAX]; unsigned int vcodec_pmdomains_num; const char **opp_pmdomain; unsigned int vcodec_num; diff --git a/drivers/media/platform/qcom/venus/pm_helpers.c b/drivers/media/platform/qcom/venus/pm_helpers.c index 48c9084bb4db..c53eef23c793 100644 --- a/drivers/media/platform/qcom/venus/pm_helpers.c +++ b/drivers/media/platform/qcom/venus/pm_helpers.c @@ -408,35 +408,28 @@ static const struct venus_pm_ops pm_ops_v3 = { static int vcodec_control_v4(struct venus_core *core, u32 coreid, bool enable) { - void __iomem *ctrl, *stat; - u32 val; - int ret; - - if (IS_V6(core)) { - ctrl = core->wrapper_base + WRAPPER_CORE_POWER_CONTROL_V6; - stat = core->wrapper_base + WRAPPER_CORE_POWER_STATUS_V6; - } else if (coreid == VIDC_CORE_ID_1) { - ctrl = core->wrapper_base + WRAPPER_VCODEC0_MMCC_POWER_CONTROL; - stat = core->wrapper_base + WRAPPER_VCODEC0_MMCC_POWER_STATUS; - } else { - ctrl = core->wrapper_base + WRAPPER_VCODEC1_MMCC_POWER_CONTROL; - stat = core->wrapper_base + WRAPPER_VCODEC1_MMCC_POWER_STATUS; - } - - if (enable) { - writel(0, ctrl); - - ret = readl_poll_timeout(stat, val, val & BIT(1), 1, 100); - if (ret) - return ret; - } else { - writel(1, ctrl); + int i, ret = 0; + struct device *dev = core->dev; + const struct venus_resources *res = core->res; - ret = readl_poll_timeout(stat, val, !(val & BIT(1)), 1, 100); - if (ret) - return ret; + for (i = 0; i < res->vcodec_pmdomains_num; i++) { + if (res->vcodec_pmdomains_hwctrl[i]) { + + if (!core->pmdomains[i]) + return -ENODEV; + + /* + * enable( true ), switch the gdsc to SW mode + * enable( false), switch the gdsc to HW mode + */ + ret = dev_pm_genpd_set_hwmode(core->pmdomains[i], !enable); + if (ret) { + dev_err(dev, "Failed to switch power-domain:%d to %s mode\n", + i, enable ? "SW" : "HW"); + return ret; + } + } } - return 0; }