From patchwork Wed Nov 20 12:56:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 179842 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp2064130ilf; Wed, 20 Nov 2019 04:56:58 -0800 (PST) X-Google-Smtp-Source: APXvYqx1Di9cwJgm16IGqMjdkGNLHd7n2tQ2NfDzqfiSxGho+rExx4YGwAtbo+oD2QKuLuFvecNY X-Received: by 2002:a17:906:fac7:: with SMTP id lu7mr5340835ejb.5.1574254617899; Wed, 20 Nov 2019 04:56:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574254617; cv=none; d=google.com; s=arc-20160816; b=m3PpmyTLFkTUpSCS43wz3gTmf7LNVcXpw+pteopCP0eltVb/4JYuKcvvTacODfGEsp bwukJf6GUq22JzmRWyZcnZ1nuyZWXAU4TrbvQyRLjnGu4MCI3dUQGXrz3gi/xuMxeCE/ K2bM/yl/vXIYmI+DA/PmQHaIDtbCn01neZ27Yn51u9VMhxFSIgv0PjUC3ULQWlznECVJ n0y8iG4xPD/kF5W/pkyLfxqR8CYIA/n1pAEWv8hRlp6XFF89wKMKietjM1Wt9VBWP1aK TvczMc/tbw9yp3PjlHHfxj5cxfOyy22yucGIIC7dGHYG83/fbmi1GuodcVegTwxwoSkk 9bhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=UM2VNIyhsEQWAdxoUvBsAp0FiOlz8ZfKGsaB/5AYX7U=; b=vm5LEFgzOBl4j08/TUuVlnsWkQv67n5d+thXxIqyv1l70AM6lNrOv1LB1K9EVpCUFj q8TxjtAqTi5Ro1vSn1cjNjwrO0SNhiAVoNfTjIDqe0/o7leq3qqPlAOHfjxfP24vUDE2 fz1YufnDpdjLAJuVknJ7QODdwidx8FbcVlGW7rPjBXlDVDnPPH3BYf9abq2Wj3is0MdF 1H2wFPkL6Dmt0+JI0CioElux4Q7ZcSYGo8wRi5j8wsKeYxwS7fzmG933O//SjnABTFiH H33fUk8Cb77f2lun3uslx2QquaI1o6xukQTGeW5/ThhHYh1r6nJHQeWNwojyLt/fI1yF 9qLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WD85C7u9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5si14456121edv.385.2019.11.20.04.56.57; Wed, 20 Nov 2019 04:56:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WD85C7u9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729994AbfKTM44 (ORCPT + 26 others); Wed, 20 Nov 2019 07:56:56 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:33339 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729971AbfKTM4z (ORCPT ); Wed, 20 Nov 2019 07:56:55 -0500 Received: by mail-qt1-f193.google.com with SMTP id y39so28847380qty.0 for ; Wed, 20 Nov 2019 04:56:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UM2VNIyhsEQWAdxoUvBsAp0FiOlz8ZfKGsaB/5AYX7U=; b=WD85C7u9NWEMbHwM/sjKEJ4ryfnNgTq8BlVICVvxRxopHEEe+V0gp1qsTJaBODoV7L 0qE3b01AwO9mamaPEukWnzpvRAICFGL7Y8V75jkkn9rrt7FV3M5EGCKxmLZkRM//MeLu DL8MqTPlzvfuO5j1DL1pl2mCM/ht/AVuL48lXY70xE6x0XbDx9px3UdYVm+4OPRzs+ma SVnyBCFwbqQu4TrVCYt28lHsyhxIzzrQhY1C5NU4YtVLv5/nnBpk4oDMYrgFeukxKudZ Q7lrhjUG0BvDr12OTGAnxAi5mtLuYnTL8xM4L2OxgzHcTj+BIHpX6RX18JQx3Y+DsrKi N0Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UM2VNIyhsEQWAdxoUvBsAp0FiOlz8ZfKGsaB/5AYX7U=; b=symqPNnFN3KJ9Q/DBtz0c1dsUqkkPitcRNLhuSGGSoyNqX4IWbueSusTV1Hb0n7cJX Z92Jtzt6yviqhSyzvAgT8e5KAmgjKMBzc0bRG9p3lZuhpIfGDWT4BjFKiZKzmrDRYeU/ IkrHY/mrzROHjOOagy9kCdMO0eXKWiT8hm24ZzGz3y2kJh5GUkgaM7qVG4jjyB3+xfsr yG2zwlS800s9YRsQcnZD/1m65xo35lcfFvgwoUnRnSvMWTfCapTJANHs9neTIj2jgtke TLJ7VHSTKPKHZfM55Bmgpljj1R/xmuTuXizpbZ7j1nvCzOecqqBT7Mj5/cmTuj2y+Vqf QntA== X-Gm-Message-State: APjAAAV28aQCRWR7KUCdabrTLuQtIJs8J7VTTGwWAwM/xdLFgeuOH8fr /cmyjvvUIzpwN3hRYD+ek7bVuw== X-Received: by 2002:ac8:288a:: with SMTP id i10mr2378040qti.139.1574254613445; Wed, 20 Nov 2019 04:56:53 -0800 (PST) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-246-27.washdc.fios.verizon.net. [71.255.246.27]) by smtp.googlemail.com with ESMTPSA id r2sm14109637qtc.28.2019.11.20.04.56.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Nov 2019 04:56:51 -0800 (PST) From: Thara Gopinath To: edubezval@gmail.com, rui.zhang@intel.com, ulf.hansson@linaro.org, daniel.lezcano@linaro.org, bjorn.andersson@linaro.org, agross@kernel.org Cc: amit.kucheria@verdurent.com, mark.rutland@arm.com, rjw@rjwysocki.net, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [Patch v4 4/7] thermal: Add generic power domain warming device driver. Date: Wed, 20 Nov 2019 07:56:30 -0500 Message-Id: <1574254593-16078-5-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1574254593-16078-1-git-send-email-thara.gopinath@linaro.org> References: <1574254593-16078-1-git-send-email-thara.gopinath@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Resources modeled as power domains in linux kenrel can be used to warm the SoC(eg. mx power domain on sdm845). To support this feature, introduce a generic power domain warming device driver that can be plugged into the thermal framework (The thermal framework itself requires further modifiction to support a warming device in place of a cooling device. Those extensions are not introduced in this patch series). Signed-off-by: Thara Gopinath --- v3->v4: - Removed late_init hook pd_warming_device_ops. - Use of_genpd_add_device instead of pm_genpd_add_device to attach device to the generic power domain. - Use thermal_of_cooling_device_parent_register to register the cooling device so that the device with genpd attached can be made parent of the cooling device. - With above changes, remove reference to generic_pm_domain in pd_warming_device. drivers/thermal/Kconfig | 10 +++ drivers/thermal/Makefile | 2 + drivers/thermal/pwr_domain_warming.c | 138 +++++++++++++++++++++++++++++++++++ include/linux/pwr_domain_warming.h | 29 ++++++++ 4 files changed, 179 insertions(+) create mode 100644 drivers/thermal/pwr_domain_warming.c create mode 100644 include/linux/pwr_domain_warming.h -- 2.1.4 diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index 001a21a..0c5c93e 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -187,6 +187,16 @@ config DEVFREQ_THERMAL If you want this support, you should say Y here. +config PWR_DOMAIN_WARMING_THERMAL + bool "Power Domain based warming device" + depends on PM_GENERIC_DOMAINS_OF + help + This implements the generic power domain based warming + mechanism through increasing the performance state of + a power domain. + + If you want this support, you should say Y here. + config THERMAL_EMULATION bool "Thermal emulation mode support" help diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 74a37c7..382c64a 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -27,6 +27,8 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL) += clock_cooling.o # devfreq cooling thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o +thermal_sys-$(CONFIG_PWR_DOMAIN_WARMING_THERMAL) += pwr_domain_warming.o + # platform thermal drivers obj-y += broadcom/ obj-$(CONFIG_THERMAL_MMIO) += thermal_mmio.o diff --git a/drivers/thermal/pwr_domain_warming.c b/drivers/thermal/pwr_domain_warming.c new file mode 100644 index 0000000..40162b9 --- /dev/null +++ b/drivers/thermal/pwr_domain_warming.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019, Linaro Ltd + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct pd_warming_device { + struct thermal_cooling_device *cdev; + struct device dev; + int max_state; + int cur_state; + bool runtime_resumed; +}; + +static int pd_wdev_get_max_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct pd_warming_device *pd_wdev = cdev->devdata; + + *state = pd_wdev->max_state; + return 0; +} + +static int pd_wdev_get_cur_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct pd_warming_device *pd_wdev = cdev->devdata; + + *state = dev_pm_genpd_get_performance_state(&pd_wdev->dev); + + return 0; +} + +static int pd_wdev_set_cur_state(struct thermal_cooling_device *cdev, + unsigned long state) +{ + struct pd_warming_device *pd_wdev = cdev->devdata; + struct device *dev = &pd_wdev->dev; + int ret; + + ret = dev_pm_genpd_set_performance_state(dev, state); + + if (ret) + return ret; + + if (state && !pd_wdev->runtime_resumed) { + ret = pm_runtime_get_sync(dev); + pd_wdev->runtime_resumed = true; + } else if (!state && pd_wdev->runtime_resumed) { + ret = pm_runtime_put(dev); + pd_wdev->runtime_resumed = false; + } + + return ret; +} + +static struct thermal_cooling_device_ops pd_warming_device_ops = { + .get_max_state = pd_wdev_get_max_state, + .get_cur_state = pd_wdev_get_cur_state, + .set_cur_state = pd_wdev_set_cur_state, +}; + +struct thermal_cooling_device * +pwr_domain_warming_register(struct device *parent, char *pd_name, int pd_id) +{ + struct pd_warming_device *pd_wdev; + struct of_phandle_args pd_args; + int ret; + + pd_wdev = kzalloc(sizeof(*pd_wdev), GFP_KERNEL); + if (!pd_wdev) + return ERR_PTR(-ENOMEM); + + dev_set_name(&pd_wdev->dev, "%s_warming_dev", pd_name); + pd_wdev->dev.parent = parent; + + ret = device_register(&pd_wdev->dev); + if (ret) + goto error; + + pd_args.np = parent->of_node; + pd_args.args[0] = pd_id; + pd_args.args_count = 1; + + ret = of_genpd_add_device(&pd_args, &pd_wdev->dev); + + if (ret) + goto error; + + ret = dev_pm_genpd_performance_state_count(&pd_wdev->dev); + if (ret < 0) + goto error; + + pd_wdev->max_state = ret - 1; + pm_runtime_enable(&pd_wdev->dev); + pd_wdev->runtime_resumed = false; + + pd_wdev->cdev = thermal_of_cooling_device_parent_register + (NULL, parent, pd_name, pd_wdev, + &pd_warming_device_ops); + if (IS_ERR(pd_wdev->cdev)) { + pr_err("unable to register %s cooling device\n", pd_name); + pm_runtime_disable(&pd_wdev->dev); + ret = PTR_ERR(pd_wdev->cdev); + goto error; + } + + return pd_wdev->cdev; +error: + put_device(&pd_wdev->dev); + kfree(pd_wdev); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(pwr_domain_warming_register); + +void pwr_domain_warming_unregister(struct thermal_cooling_device *cdev) +{ + struct pd_warming_device *pd_wdev = cdev->devdata; + struct device *dev = &pd_wdev->dev; + + if (pd_wdev->runtime_resumed) { + dev_pm_genpd_set_performance_state(dev, 0); + pm_runtime_put(dev); + pd_wdev->runtime_resumed = false; + } + pm_runtime_disable(dev); + thermal_cooling_device_unregister(cdev); + kfree(pd_wdev); +} +EXPORT_SYMBOL_GPL(pwr_domain_warming_unregister); diff --git a/include/linux/pwr_domain_warming.h b/include/linux/pwr_domain_warming.h new file mode 100644 index 0000000..cb6550d --- /dev/null +++ b/include/linux/pwr_domain_warming.h @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019, Linaro Ltd. + */ +#ifndef __PWR_DOMAIN_WARMING_H__ +#define __PWR_DOMAIN_WARMING_H__ + +#include +#include + +#ifdef CONFIG_PWR_DOMAIN_WARMING_THERMAL +struct thermal_cooling_device * +pwr_domain_warming_register(struct device *parent, char *pd_name, int pd_id); + +void pwr_domain_warming_unregister(struct thermal_cooling_device *cdev); + +#else +static inline struct thermal_cooling_device * +pwr_domain_warming_register(struct device *parent, char *pd_name, int pd_id) +{ + return ERR_PTR(-ENOSYS); +} + +static inline void +pwr_domain_warming_unregister(struct thermal_cooling_device *cdev) +{ +} +#endif /* CONFIG_PWR_DOMAIN_WARMING_THERMAL */ +#endif /* __PWR_DOMAIN_WARMING_H__ */