Received: by 10.192.165.148 with SMTP id m20csp4590990imm; Tue, 8 May 2018 10:50:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrR6t34FFuu6H4hksvzV3YlJqlqTESCWFz6TjThQS5S1GHLNHmwBJ4EEVKEfciXlI2s+f9s X-Received: by 2002:a17:902:bb06:: with SMTP id l6-v6mr42695648pls.255.1525801823428; Tue, 08 May 2018 10:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525801823; cv=none; d=google.com; s=arc-20160816; b=kItCy+r3piuZ9neyRi984IUU6hyoLoUPbm79+Or1mzf5H5IpA3q8/awz34HvQUXRyr E+R8GKCISTIkN1RmFN6r2NY7bOrXM73Nkhcaxd7UKsNRvYA9fZz89BTM3SzABRwexe9l ibMsXZb54vfpIytixA2sQFTip20DfpNS+GDkLgDH/q3xNrXMm8Ur5KDjgxtmSjhq6/uy 7UGRwqM5BJCj/XaOeyXpJiPRm+FpiVTw3JAJ7syF5X8elc1cDhtqtWxRruab+/VgVxCK PO1xWZVRDLSpwolIA8tHDOnNLKiNAosOuyQpeBqKV8Zcd+mp/W8ZPSZ6To7mO6oiTBSl jULQ== 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:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=yF4ND/tQk5F/T7bw7LwqpBnCv2P6oqNnNz31xhsOCfA=; b=bv34d7uEyJlcDutGL7Zy+Yd4jhSmhjd1GxRDH+jD5+6VIK6/FvkGz0WWgySUExTCBp vAj1YRsF2t704vB8XlXu3MnEgCA4FwfXYm0Km7YA1Tt1XrM+Mc+IpfQrVPrB3pAjduEg WzyfMZFJ2h+ptJ77zJYjhK0rxN/qst/ZJpzXxr05+ZBHhBpPZLtj5wmGzCsy1kM1KiTi tEGkuHD6SDrVEk1r+v3sd8pMTkHrFWS3zYx9z4hse0STlLZI9h2mf5q3LeUJj5wDJ4/c QUBXHdLJHq7ObNF6CJTv3p4vLNAuw0oUDjm8YZ040KQC44pKhkT1a94xn7Hg3Ynp1Nnm kI8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=eKMPec+W; dkim=pass header.i=@codeaurora.org header.s=default header.b=Kcc8uDz+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v10-v6si23011580ply.328.2018.05.08.10.50.08; Tue, 08 May 2018 10:50:23 -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=@codeaurora.org header.s=default header.b=eKMPec+W; dkim=pass header.i=@codeaurora.org header.s=default header.b=Kcc8uDz+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755541AbeEHRtL (ORCPT + 99 others); Tue, 8 May 2018 13:49:11 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:38908 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751806AbeEHRtI (ORCPT ); Tue, 8 May 2018 13:49:08 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 073EB60C64; Tue, 8 May 2018 17:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525801748; bh=ag3r13bGMalgSBk9EhSFbcjYgNs40cZWRIRGRo7q/hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eKMPec+WJVfvSnCHpjB4jg1NAHXDGn1WDH3PcPp7fN0Gh0uK8xon5QAIg58d8qUGr Lb5B9NUJB0xq1TiBdLH1j25r67tT6QqGmUFQujiElBucDVUP33mQOil7KseCkZ4jDT OkqZhZ/GJn7Z36eowo0nAlLzl/em2FzbLzhDCb+U= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ilina@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5DB5660B23; Tue, 8 May 2018 17:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525801747; bh=ag3r13bGMalgSBk9EhSFbcjYgNs40cZWRIRGRo7q/hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kcc8uDz+dgQeZglK9F8jsciBzo5UlqRPwJvuqzwtWgfOBItdUZr0eernu9jIBvYr8 YUzoIfFqoQOfBmqDZsf53ZaRnwD+hFJn0g/UuNpHbxC6gjWwoi28ZUcbyqyM3rjR3a uwUxRCF1TMnCUGXdfMLjTaAInUlwnbaifZwtJs1Q= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 5DB5660B23 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org From: Lina Iyer To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, daniel.lezcano@linaro.org, amit.kucheria@linaro.org, Lina Iyer Subject: [PATCH RFC 2/4] drivers: of-thermal: allow multiple thermal zones for a sensor Date: Tue, 8 May 2018 11:48:57 -0600 Message-Id: <20180508174859.26539-3-ilina@codeaurora.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180508174859.26539-1-ilina@codeaurora.org> References: <20180508174859.26539-1-ilina@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To allow different mitigative actions based on a sensor temperature, it is desirable to have multiple thermal zones share the same source. The thermal zones could have different thresholds, mitigative actions and even different governors. Signed-off-by: Lina Iyer --- drivers/thermal/of-thermal.c | 32 ++++++++++++++++++++++++++------ include/linux/thermal.h | 2 ++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index b402edd09ed1..06e581a37c67 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -39,10 +39,14 @@ struct __thermal_bind_params { * struct thermal_sensor - Holds individual sensor data * @sensor_data: sensor driver private data passed as input argument * @ops: sensor driver ops + * @tz_list: list of thermal zones for this sensor + * @lock: lock sensor during operations */ struct thermal_sensor { void *sensor_data; const struct thermal_zone_of_device_ops *ops; + struct list_head tz_list; + struct mutex lock; }; /** @@ -430,11 +434,24 @@ thermal_zone_of_add_sensor(struct device_node *zone, if (sensor->ops->set_emul_temp) tzd->ops->set_emul_temp = of_thermal_set_emul_temp; + mutex_lock(&sensor->lock); + list_add_tail(&tzd->sensor_tzd, &sensor->tz_list); + mutex_unlock(&sensor->lock); mutex_unlock(&tzd->lock); return tzd; } +static struct thermal_zone_device * +thermal_zone_of_get_sensor_tzd(struct thermal_sensor *sensor) +{ + if (list_empty(&sensor->tz_list)) + return ERR_PTR(-ENODEV); + + return list_first_entry(&sensor->tz_list, struct thermal_zone_device, + sensor_tzd); +} + /** * thermal_zone_of_sensor_register - registers a sensor to a DT thermal zone * @dev: a valid struct device pointer of a sensor device. Must contain @@ -460,12 +477,11 @@ thermal_zone_of_add_sensor(struct device_node *zone, * 01 - This function must enqueue the new sensor instead of using * it as the only source of temperature values. * - * 02 - There must be a way to match the sensor with all thermal zones - * that refer to it. - * * Return: On success returns a valid struct thermal_zone_device, * otherwise, it returns a corresponding ERR_PTR(). Caller must * check the return value with help of IS_ERR() helper. + * The returned thermal_zone_device is one of the thermal zones that is + * using this sensor as the temeprature source. */ struct thermal_zone_device * thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, @@ -489,6 +505,8 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, of_node_put(np); return ERR_PTR(-ENOMEM); } + INIT_LIST_HEAD(&sensor->tz_list); + mutex_init(&sensor->lock); sensor->sensor_data = data; sensor->ops = ops; sensor_np = of_node_get(dev->of_node); @@ -521,14 +539,14 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, of_node_put(sensor_specs.np); of_node_put(child); - goto exit; } of_node_put(sensor_specs.np); } -exit: + of_node_put(sensor_np); of_node_put(np); + tzd = thermal_zone_of_get_sensor_tzd(sensor); if (tzd == ERR_PTR(-ENODEV)) kfree(sensor); return tzd; @@ -569,7 +587,9 @@ void thermal_zone_of_sensor_unregister(struct device *dev, tzd->ops->get_trend = NULL; tzd->ops->set_emul_temp = NULL; - kfree(tz->sensor); + list_del(&tzd->sensor_tzd); + if (list_empty(&tz->sensor->tz_list)) + kfree(tz->sensor); tz->sensor = NULL; mutex_unlock(&tzd->lock); } diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 7a133bd6ff86..09e1669a4919 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -188,6 +188,7 @@ struct thermal_attr { * @node: node in thermal_tz_list (in thermal_core.c) * @poll_queue: delayed work for polling * @notify_event: Last notification event + * @sensor_tzd: node in sensor's list of thermal zone devices */ struct thermal_zone_device { int id; @@ -220,6 +221,7 @@ struct thermal_zone_device { struct list_head node; struct delayed_work poll_queue; enum thermal_notify_event notify_event; + struct list_head sensor_tzd; }; /** -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project