From patchwork Tue May 8 17:48:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 10386777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EC9A7602C2 for ; Tue, 8 May 2018 17:49:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E39DD28E49 for ; Tue, 8 May 2018 17:49:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D85CF290B6; Tue, 8 May 2018 17:49:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F25A290B3 for ; Tue, 8 May 2018 17:49:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755489AbeEHRtL (ORCPT ); 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= 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }; /**