From patchwork Tue Jul 30 15:24:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 170073 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp2771568ile; Tue, 30 Jul 2019 08:24:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFoL4gQujKZaZysKMaA+SxL5APp7UJ4jwVSGmVGLmMWU3Piw8psOMQPadYRU4muxaP21od X-Received: by 2002:a17:902:2808:: with SMTP id e8mr111299289plb.317.1564500294221; Tue, 30 Jul 2019 08:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564500294; cv=none; d=google.com; s=arc-20160816; b=LDNZ42+8h24/XVi49yEBnroaB+ogqfeFtByo3JhjHVMCCdHFC3asgd/W0gNiIh9DkW papBredCG+/32gC9dEVfHC86hB5wgZm8WH1uBSLiziCxkCIhUMXXuzJTpq0QIkpm9dfO 7AmwetMvBkXYv3tJ8F9bAv3C1rOMpliU6CdfPXezbm5ggYfb4f4l5qFtsKnt3QJISTFu nsbpxoCMrZpNiNTS7TSPp92w5qqxNV3iGCEhKT6bH9CXWtX9+SJrj8JtbHy8kz5NjwIa Cx0N07z/1p01M86JLjK/JaEqGBuRmC7ghWziuDPjupmkT0c1sjaVIYRvnTMnlCGyt6l+ aVcA== 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=yjlVdjPruOMY43BI1raOa3L6IFCLU0ya6RBy0Shy9/M=; b=OGFH0lZbsZN14Y+daCoBBA/9NP4XkLSTKvMHQWTWZfhahMUC0kRqRCytR421nSrJuv r/9+zgCFQ/mOywxMNR+H6/IUtRSJVP8vQFEwBLose+xOQBrOrmsX7uzwGDQkWJZho+Gv t9obI/iaiQkV2alxnW5HSDgm9VGdDQp2u/0dHfkvZan+G+BfFhTunuSryPbPW+tWB4zs TGzkWyu1BZr7mKWr4uQ0/xFxmCeMXIGNY3cumHJwYrfgMY4yLQpX7fQ+3JKZOn+Rt7+b poj67SLwb50ujZtdVAp6esUWNNSJKRI/ji7/CV6QrU0q32t9JJr2hwxhm36wr3mcsRMz EQWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wnFRxdhF; 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 t6si30267007pfe.231.2019.07.30.08.24.53; Tue, 30 Jul 2019 08:24:54 -0700 (PDT) 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=wnFRxdhF; 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 S1732291AbfG3PYu (ORCPT + 29 others); Tue, 30 Jul 2019 11:24:50 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:44239 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732273AbfG3PYr (ORCPT ); Tue, 30 Jul 2019 11:24:47 -0400 Received: by mail-qt1-f193.google.com with SMTP id 44so32393990qtg.11 for ; Tue, 30 Jul 2019 08:24:47 -0700 (PDT) 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=yjlVdjPruOMY43BI1raOa3L6IFCLU0ya6RBy0Shy9/M=; b=wnFRxdhFzAoVXTk34+7y/goDyY2S2eDHoEPHCxwYLmPhRgwC1D0mW85msH++16qpQ3 NCTDHTFBWVHqiy9uWd76S/15T4LMqWNRv75vz5fPP5exKYTzIlsE9EF42uKdF9CWNENf TUGZqEOYjShTK/Ylx+d/FvwQ828tpDQ6oltmhLbA6nt6oWjjhOQUWexGb2BUnUO37z4/ 45BcHmBklm9KLvA7kAldnGHmIFIu9t01ihKMtLRInd+/O1ECmglGapihQZFQnVmWdidA pInv6s5l2ScD/uwgumbzcNs8naueM7GGuyAZGvTQwPboOEr784BPpZOPUp+JYn9U+zgU e3PQ== 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=yjlVdjPruOMY43BI1raOa3L6IFCLU0ya6RBy0Shy9/M=; b=a+m/wjW2JN0xxs7dSJ99kNvgX5+3rAJgSq3DlgQkyrXNcnPtFJ+m7OQmM7tQrlyOlS Jqq8Hj7vuYHjIokQH/mY6+XwHHGydq06cEKjUN+2/AzPMhv+FsmyPyvadV9s1Soqy+KZ xDJ/ZQslbYzOGw8Q2bf86CqpZS1FER+GCAmr/O9lkukJEHwPh2hdSWlxnlJlq3Sw4v06 Jd2VBc28FlN5tze1wyC6drANN+33YTgITxb0Jkz0QZ/4d6CiFO6IehMoNu//pmlKiCzu HlqYhu87HGXG9TECFEVj8LYFMoksGFrNvBDmjfD806FnCFvCAWsr69xSRKkijVCmf5Ps JG8w== X-Gm-Message-State: APjAAAUvE+rRq1KzD03tcUb94CALmaOXjAizhp5VXPZCaZ2pSrNSx7x/ +79+HYBG/w6VZbq9mzXFyI6IQQ== X-Received: by 2002:ac8:3908:: with SMTP id s8mr36552603qtb.224.1564500286674; Tue, 30 Jul 2019 08:24:46 -0700 (PDT) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-245-97.washdc.fios.verizon.net. [71.255.245.97]) by smtp.googlemail.com with ESMTPSA id r14sm27251082qkm.100.2019.07.30.08.24.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jul 2019 08:24:46 -0700 (PDT) From: Thara Gopinath To: linux-arm-msm@vger.kernel.org, agross@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, bjorn.andersson@linaro.org, amit.kucheria@linaro.org, vinod.koul@linaro.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [Patch v2 1/2] soc: qcom: Extend AOSS QMP driver to support resources that are used to wake up the SoC. Date: Tue, 30 Jul 2019 11:24:42 -0400 Message-Id: <1564500283-16038-2-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1564500283-16038-1-git-send-email-thara.gopinath@linaro.org> References: <1564500283-16038-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 The AOSS QMP driver is extended to communicate with the additional resources. These resources are then registered as cooling devices with the thermal framework. Signed-off-by: Thara Gopinath --- v1->v2: Added back name variable in qmp_cooling_device to fix the compilation error. Other minor naming changes as mentioned in review on the list. drivers/soc/qcom/qcom_aoss.c | 131 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) -- 2.1.4 diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c index 5f88519..dc6201e 100644 --- a/drivers/soc/qcom/qcom_aoss.c +++ b/drivers/soc/qcom/qcom_aoss.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #define QMP_DESC_MAGIC 0x0 #define QMP_DESC_VERSION 0x4 @@ -40,6 +42,17 @@ /* 64 bytes is enough to store the requests and provides padding to 4 bytes */ #define QMP_MSG_LEN 64 +#define QMP_NUM_COOLING_RESOURCES 2 + +static bool qmp_cdev_init_state = 1; + +struct qmp_cooling_device { + struct thermal_cooling_device *cdev; + struct qmp *qmp; + char *name; + bool state; +}; + /** * struct qmp - driver state for QMP implementation * @msgram: iomem referencing the message RAM used for communication @@ -69,6 +82,7 @@ struct qmp { struct clk_hw qdss_clk; struct genpd_onecell_data pd_data; + struct qmp_cooling_device *cooling_devs; }; struct qmp_pd { @@ -385,6 +399,118 @@ static void qmp_pd_remove(struct qmp *qmp) pm_genpd_remove(data->domains[i]); } +static int qmp_cdev_get_max_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + *state = qmp_cdev_init_state; + return 0; +} + +static int qmp_cdev_get_cur_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct qmp_cooling_device *qmp_cdev = cdev->devdata; + + *state = qmp_cdev->state; + return 0; +} + +static int qmp_cdev_set_cur_state(struct thermal_cooling_device *cdev, + unsigned long state) +{ + struct qmp_cooling_device *qmp_cdev = cdev->devdata; + char buf[QMP_MSG_LEN] = {}; + bool cdev_state; + int ret; + + /* Normalize state */ + cdev_state = !!state; + + if (qmp_cdev->state == state) + return 0; + + snprintf(buf, sizeof(buf), + "{class: volt_flr, event:zero_temp, res:%s, value:%s}", + qmp_cdev->name, + cdev_state ? "off" : "on"); + + ret = qmp_send(qmp_cdev->qmp, buf, sizeof(buf)); + + if (!ret) + qmp_cdev->state = cdev_state; + + return ret; +} + +static struct thermal_cooling_device_ops qmp_cooling_device_ops = { + .get_max_state = qmp_cdev_get_max_state, + .get_cur_state = qmp_cdev_get_cur_state, + .set_cur_state = qmp_cdev_set_cur_state, +}; + +static int qmp_cooling_device_add(struct qmp *qmp, + struct qmp_cooling_device *qmp_cdev, + struct device_node *node) +{ + char *cdev_name = (char *)node->name; + + qmp_cdev->qmp = qmp; + qmp_cdev->state = qmp_cdev_init_state; + qmp_cdev->name = cdev_name; + qmp_cdev->cdev = devm_thermal_of_cooling_device_register + (qmp->dev, node, + cdev_name, + qmp_cdev, &qmp_cooling_device_ops); + + if (IS_ERR(qmp_cdev->cdev)) + dev_err(qmp->dev, "unable to register %s cooling device\n", + cdev_name); + + return PTR_ERR_OR_ZERO(qmp_cdev->cdev); +} + +static int qmp_cooling_devices_register(struct qmp *qmp) +{ + struct device_node *np, *child; + int count = QMP_NUM_COOLING_RESOURCES; + int ret; + + np = qmp->dev->of_node; + + qmp->cooling_devs = devm_kcalloc(qmp->dev, count, + sizeof(*qmp->cooling_devs), + GFP_KERNEL); + + if (!qmp->cooling_devs) + return -ENOMEM; + + for_each_available_child_of_node(np, child) { + if (!of_find_property(child, "#cooling-cells", NULL)) + continue; + ret = qmp_cooling_device_add(qmp, &qmp->cooling_devs[count++], + child); + if (ret) + goto uroll; + } + + return 0; + +uroll: + while (--count >= 0) + thermal_cooling_device_unregister + (qmp->cooling_devs[count].cdev); + + return ret; +} + +static void qmp_cooling_devices_remove(struct qmp *qmp) +{ + int i; + + for (i = 0; i < QMP_NUM_COOLING_RESOURCES; i++) + thermal_cooling_device_unregister(qmp->cooling_devs[i].cdev); +} + static int qmp_probe(struct platform_device *pdev) { struct resource *res; @@ -433,6 +559,10 @@ static int qmp_probe(struct platform_device *pdev) if (ret) goto err_remove_qdss_clk; + ret = qmp_cooling_devices_register(qmp); + if (ret) + dev_err(&pdev->dev, "failed to register aoss cooling devices\n"); + platform_set_drvdata(pdev, qmp); return 0; @@ -453,6 +583,7 @@ static int qmp_remove(struct platform_device *pdev) qmp_qdss_clk_remove(qmp); qmp_pd_remove(qmp); + qmp_cooling_devices_remove(qmp); qmp_close(qmp); mbox_free_channel(qmp->mbox_chan);