From patchwork Mon Jul 29 16:33:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 170023 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp1485417ile; Mon, 29 Jul 2019 09:33:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpC0Ek85Jb413TQBMsF3eCH/c1IUxp+iH733IMGeWkQ+VH6b+cpmS2U0F/4IXMWXkYAE52 X-Received: by 2002:a65:4841:: with SMTP id i1mr104696285pgs.316.1564418007771; Mon, 29 Jul 2019 09:33:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564418007; cv=none; d=google.com; s=arc-20160816; b=Abb3uSJtTt1FvmJm8WuRxigp0ah16TyOjEViTLrHpEpIWMr9BDBszgO6zHZ0zqg/qq 8msZawAZADQV0CqNnXoCHO3AjRYYqO9z9Txj8zutgPMYyLh9RnHEoxF4HPaMFrIAbm3l RsdNeHjNTywTJ8CyQd20UjgHDaNNLIZjDSeVvforQmf/76dF04PfqNid17MFZs6Sx/D8 pLyvsgNxkRRb3TyQMvQBkecIiDex/KVr7pit9FrKpeFS9feS/gKoc0B+8L2OxLCPBMpF H5KA0ZR7vkA7f4A3Kof1iFNNepzvGbqs/g5yjOlaSIOz/naeesD9556h5uIxF5btbXPz J9sg== 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=H5OjemuZecMAb99bi2dOA9LV9giMPI14c3KRHJNod1Y=; b=HP5Kr+4PimYN5WkaD77cf1vzJUrni38VS1TmnP6Qs1zQY7h45gtiJvWPVfKOlA2+9H eY0ThO6yM/ycZTHcejQpSjdad6JBcbeaEfcUweCykx9vjy4aYjyd6PklY3jUxLwfZaq7 QT737UD5K1cC5AghrA8/V5lbi703DB/G4cjx+0YrVViJIAUHiWfXSEQuLuH05AWfO1Ey kVDLWgpIzXLxgSN2Ip8m1oIxHbvt3/b1aPrnBovn0TVe5Fa0ia+e0HIwulzUucvsithX nrLJ4AMwINWqTkq9JkI38BWuIhHpY38EaApYG1pi+2gO3SeQXGWt8Dy6rWKnHLbiuCFQ HeNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eVbmB86K; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 i3si26145851pld.357.2019.07.29.09.33.27; Mon, 29 Jul 2019 09:33:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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=eVbmB86K; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1729078AbfG2QdZ (ORCPT + 8 others); Mon, 29 Jul 2019 12:33:25 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:40864 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729090AbfG2QdY (ORCPT ); Mon, 29 Jul 2019 12:33:24 -0400 Received: by mail-vs1-f67.google.com with SMTP id a186so39634679vsd.7 for ; Mon, 29 Jul 2019 09:33:24 -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=H5OjemuZecMAb99bi2dOA9LV9giMPI14c3KRHJNod1Y=; b=eVbmB86KNL3hg/6szqN46y2vPcjG+t1zRVqB9e3+A2a1MqdxJDdQYJA2i8m6c/yO+g RN8hIgQAjT+IG8eNXG+PQ2e3WZYT7IFvmmGJVebVbHwk8KYavVwtiGgiDGkuXFss+nYN W25VwnpXq3GdoCyX7l9PG0dijgche9ANQ1WzCwRWhPpKWvYuCEY8X43DZzKjP1cNptFZ PdnpUaF4hYWmztc+wO9dCmo9WsnDMLfEgYi9WuX/2w4uhzT6kge5J3TCbufZs62IqQ2f peuUxdcMeruNAkBv7p2RonlFunH+quicPdCOsTEAv/YYBSCIjDTlcL6YA5r6QC6hO21s D4ug== 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=H5OjemuZecMAb99bi2dOA9LV9giMPI14c3KRHJNod1Y=; b=AXvTBab9xeJw7j4YJqY6whn4/q9djFdiB6qF6bobKyFN4h0ACxkJyaDLrIpxfUfc3F D/BUPNWRF0VowzH5UcInEMbDRoMXxvLhuHhnu7XroU8eGZDdcHl1I3xoxBJqCqrVaow6 oUm2J5mQtqJg7r9hAt6MIVVqGamj+y/LsPUNLrg7IQ887OuLUsaYbGTwxjMyiU1ksK1Z LAA5g6Fi93MOvEKlXfQXFDy1Qa4Y9NOf1oYaDhk4ycRV8OdvAmfOta5x7V6cVdtP0cUr Ldbvb5rBWyakznG/zTIveisawJLBdqeE4B3vWQ27EyiIj3YUTo800Xb2/VrS5gm9UEP7 ww0w== X-Gm-Message-State: APjAAAVhisy0nNo7Ou+Lw7KBzu5Eag6q7amgJI+hVLDcVbycPGtpG5Wn gYZaINPhA7LawF4V445iRJfPw3O8cJI= X-Received: by 2002:a67:b14c:: with SMTP id z12mr4505264vsl.11.1564418003895; Mon, 29 Jul 2019 09:33:23 -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 o9sm39762738vkd.27.2019.07.29.09.33.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Jul 2019 09:33:23 -0700 (PDT) From: Thara Gopinath To: linux-arm-msm@vger.kernel.org, agross@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] soc: qcom: Extend AOSS QMP driver to support resources that are used to wake up the SoC. Date: Mon, 29 Jul 2019 12:33:20 -0400 Message-Id: <1564418001-24940-2-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1564418001-24940-1-git-send-email-thara.gopinath@linaro.org> References: <1564418001-24940-1-git-send-email-thara.gopinath@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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 --- drivers/soc/qcom/qcom_aoss.c | 129 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) -- 2.1.4 diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c index 5f88519..010877e 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,16 @@ /* 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; + bool state; +}; + /** * struct qmp - driver state for QMP implementation * @msgram: iomem referencing the message RAM used for communication @@ -69,6 +81,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 +398,117 @@ 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->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_cooling_devices; + } + + return 0; + +uroll_cooling_devices: + 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 +557,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 +581,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);