Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp529512pxb; Thu, 19 Aug 2021 05:32:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnPFlBLkaMErh3VTnAlfGHkVsvvvnGx/CK4DImw/eRCX2O17I0V5/1OeplbX23yafXasVI X-Received: by 2002:a92:c0c9:: with SMTP id t9mr9792888ilf.79.1629376352881; Thu, 19 Aug 2021 05:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629376352; cv=none; d=google.com; s=arc-20160816; b=Vz8l+O1svW9OYO7hiTCiOM3VVgKnRno/WPVvMWnGYhZZ0/YXNckzk9adcOzYN6jYG8 wJvcVDZAbXx4JURfjQVp9p1p2qyBwQrgUV/kFuuTv+7MPgX6agLLCWIoBcVowyUV5tFE YKCR8K/7l2tnMatu0qTtSLtgCsy6mMEEwoNypYYSjyXfvPKpfUtgfvwxfioYaj9KEwBz Msn5zMbonNphaisMP4AM4cwUTqSWf4ggPPTwqUjmYkdcFbHack3xzvs7Zpdolh+/0Jn7 LVF4GQnvsihX9oYzdyVeCRk3NGUpkl4NiJFRIvT9ZwKAjXkCjn4Rxhbo4x61mZ/aTS79 +RTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RQnOV6HhqP7xV2Furr8pq5/wUZ2SXaR/nLHhOafGXkg=; b=lW9VhgTM0Tsohu2GnbudIUQ4iEmuD3mYKyP1mv6uuFt+GUhsP1o4Sc60yYmflacc3a de+j3bJkFhcRt/JizcbdS9EhUF6MRXM2cyORqReMBIlA0mTIXGPLQO1C9eV4iR3l+dqK Puwevr5Pkq/AVf1+lQBYXr3s6GnMgRP5bfTMzu+s2oVoldBU3AatIQQOtf0NZ8Ca+xTB q5k8o3a5IAo4+57DaLETELGGXFqCg9k3nOv/nQmuUmm9O2dCc8SC+B4N++GXmz0T36Xg FKI7sNv082WfkD7i5Cg+4x+I+vIcYTcd7Xpw1LTQyn9R84HnMU40POaQQUUankIesIj7 e9/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=2M3dXhUf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si2840277ioe.21.2021.08.19.05.32.10; Thu, 19 Aug 2021 05:32:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=2M3dXhUf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238924AbhHSMba (ORCPT + 99 others); Thu, 19 Aug 2021 08:31:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239643AbhHSMbV (ORCPT ); Thu, 19 Aug 2021 08:31:21 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66428C061575 for ; Thu, 19 Aug 2021 05:30:45 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id w24so3718702wmi.5 for ; Thu, 19 Aug 2021 05:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RQnOV6HhqP7xV2Furr8pq5/wUZ2SXaR/nLHhOafGXkg=; b=2M3dXhUfU0qKuKCF87Zz/LV0W9JQ4kD1+H3/waNq+P2Yf+7Rxl8X8TFZGsAZpel+Nn UCTQouixJTql6pETsgzdq8mtVxzWEhonECdt4/Xf5v1fUkW0RrD0zrFTZm00qnaz0o26 lZpjbcc2W0OR4sb1fI7KVj4jUPu+nHdBJ5TN1filcNaxa1ye9u9gnKPjuhGIHBJl/a/L GhZP3mHe787LX8EZIe3/vHcSLLHUaMXsV+46+ibrE2V6CU7Y2GC2PfV6WdMK8uhn6ltp Kezc7+/+sYCMM2G5ksZC0vXx3G2CEIy42ebH3nmIvdNWSWIho1bcFdzBl5QuwhxGliQK twXQ== 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:mime-version:content-transfer-encoding; bh=RQnOV6HhqP7xV2Furr8pq5/wUZ2SXaR/nLHhOafGXkg=; b=MTt0DfMCZsj9JZci/juZq++DVlxde9V50El8eZVsLhX3Ifr4cTlR91l3mMGW+WaJV6 UtaFJQJUj35lLXQ8936n+bQNhpwMab/bg/Q+y1iqvDnP4KGSpTj+LfeuvnFWUj2ib+wK URcKkKTfBeg9N9HwC+1W2x9MfjPAspDkZ8hh1mu+qeEviX0CaCIxmySCaxpsHeuRKV7B RoqWo2wZtVw9OVbGP3kmG2eL5LxXqbz9C+LoRtez30oYWhUkRNfXrGWb7E3TxyIIcZFy 0+Txs/1f7M1MObbq+YT9iqiXa77w3tCoLns2F1tHs73XH7J5cE3x63NEkWpvN+LDsOGC /tkA== X-Gm-Message-State: AOAM532m+gJ4bBiGo9imqs5m/AlpPzFu8HySTLTtt5akvAp6+hzRTmMO zY1O7Ve0U04aqYH8UgPlnykLcQ== X-Received: by 2002:a7b:c0c6:: with SMTP id s6mr13535984wmh.21.1629376243984; Thu, 19 Aug 2021 05:30:43 -0700 (PDT) Received: from alex-xps13.baylibre.local (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id y10sm8146814wmo.18.2021.08.19.05.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 05:30:43 -0700 (PDT) From: Alexandre Bailon To: rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, ben.tseng@mediatek.com, khilman@baylibre.com, Alexandre Bailon Subject: [RFC PATCH 1/2] thermal: provide a way to get thermal sensor from a device tree node Date: Thu, 19 Aug 2021 14:32:14 +0200 Message-Id: <20210819123215.591593-2-abailon@baylibre.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819123215.591593-1-abailon@baylibre.com> References: <20210819123215.591593-1-abailon@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to add support of a virtual thermal sensor, add a way to get a sensor using the device tree node and sensor id. Signed-off-by: Alexandre Bailon --- drivers/thermal/thermal_of.c | 43 ++++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 12 ++++++++++ 2 files changed, 55 insertions(+) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 6379f26a335f6..4d3b07ceef41a 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -82,6 +82,46 @@ struct __thermal_zone { const struct thermal_zone_of_device_ops *ops; }; + +static LIST_HEAD(thermal_sensors); + +struct thermal_sensor *thermal_of_get_sensor(struct device_node *np, int id) +{ + struct thermal_sensor *sensor; + list_for_each_entry(sensor, &thermal_sensors, node) { + if (sensor->dev->of_node == np && sensor->id == id) { + return sensor; + } + } + + return NULL; +} + +static int thermal_of_register_sensor(struct device *dev, int id, + void *sensor_data, + const struct thermal_zone_of_device_ops *ops) +{ + + struct thermal_sensor *sensor; + + sensor = thermal_of_get_sensor(dev->of_node, id); + if (sensor) + return 0; + + sensor = kzalloc(sizeof(*sensor), GFP_KERNEL); + sensor->dev = dev; + sensor->id = id; + sensor->sensor_data = sensor_data; + sensor->ops = ops; + + list_add(&sensor->node, &thermal_sensors); + + return 0; +} + + + + /*** DT thermal zone device callbacks ***/ static int of_thermal_get_temp(struct thermal_zone_device *tz, @@ -518,6 +558,9 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, if (!IS_ERR(tzd)) thermal_zone_device_enable(tzd); + /* TODO handle errors */ + thermal_of_register_sensor(dev, id, data, ops); + of_node_put(child); goto exit; } diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 8da5b61070472..3c46b142ebfef 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -104,6 +104,16 @@ struct thermal_cooling_device { struct list_head node; }; +struct thermal_sensor { + struct device *dev; + int id; + + void *sensor_data; + const struct thermal_zone_of_device_ops *ops; + + struct list_head node; +}; + /** * struct thermal_zone_device - structure for a thermal zone * @id: unique id number for each thermal zone @@ -394,6 +404,8 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz); int thermal_zone_device_enable(struct thermal_zone_device *tz); int thermal_zone_device_disable(struct thermal_zone_device *tz); void thermal_zone_device_critical(struct thermal_zone_device *tz); + +struct thermal_sensor *thermal_of_get_sensor(struct device_node *np, int id); #else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata, -- 2.31.1