From patchwork Tue Apr 16 17:22:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 162350 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp4479323jan; Tue, 16 Apr 2019 10:22:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1eYVIFf8Ign88AxjMAYnaoFhcURYU+tS2lT9dF5MqHGKDrJsFTX8zSOZfT/8FIqVZVECr X-Received: by 2002:a63:1f61:: with SMTP id q33mr72070066pgm.325.1555435336936; Tue, 16 Apr 2019 10:22:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555435336; cv=none; d=google.com; s=arc-20160816; b=s3T3Kb68TAOuyRnuSjExEo8istRqDFs/ArTndKrE7BnaBjwM+VV0MtDNMBY0flHbwL Du06+HAACs4kEj/RZ7nX6fpGUf2Hq8UyWWDRRHpuJiU7kPkbVDoNR6VsmSzoOrwx3y/D /poV2HqD2sF0plEo62DiuwPstsE7An70sgO0fq/BC4Ms4o2rU2qGie1oS+E6Vqkl/2jD plO/gd71dg5BDGu6QS1KGo7Qg4lyeLYCsOFDWA0fN0eO63oSTixg5Tr8yHcaaFjRVN5N smdqONA10b9FmP4eET5N02btL9I4W8d4XTu8uUED3DyMl9ZFYD3lcKYp9xykK0QwkkI7 DN/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=l+DLE4OaxNb2V7PhvGWjDpmhBvdDO716f9vETkoZ5+s=; b=mip3ZbDLHlixY+QWgFLuJgbDO+SrRgfT4oZIJrmyxtiETR44qAu70lEhQgn5p/wDKh tYkS13O8c/ERE6l88rR5OTvYHuH5zw1frM9Rsc4QagyUsJj8jG87amqi9J4iRRPhsMir fCbzj9YsVOKwYG4A+yKHSHX2eWzbukzoTwqK7/Jvxq0TWTb3dXfC/VJEdjqFCaTXeU4E c2FAiDOJCBtaMh6paoBE1LPaHCEGSx94eSm1+dwxyv7WVFwJYo9quRTn4G0ZHpIYc9Ve oiJFtxl4Z4qPV76IHO5HSwr5RUyigDubCA6SVmnMIeXxsR+PLExeEa4Ie9hnNzSk2bln 3OOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i6bRs4gY; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 f66si47280631pgc.400.2019.04.16.10.22.16; Tue, 16 Apr 2019 10:22:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=i6bRs4gY; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1728108AbfDPRWQ (ORCPT + 11 others); Tue, 16 Apr 2019 13:22:16 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:32953 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbfDPRWQ (ORCPT ); Tue, 16 Apr 2019 13:22:16 -0400 Received: by mail-wr1-f68.google.com with SMTP id q1so28223957wrp.0 for ; Tue, 16 Apr 2019 10:22:15 -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; bh=l+DLE4OaxNb2V7PhvGWjDpmhBvdDO716f9vETkoZ5+s=; b=i6bRs4gYw/rAuJvBXxk3XDxz4oFRVoi2rTyNwK0Se4vZMe49iY+tw+v9bwWN0UNIDj m0kfs2SYosn13L34hsmzQLkr60D1/kf2xzhVgrevNUSKMkAnOe7GDc9aIYzAIkMxWPnJ hgNLePc6+RVSik5dIR6XVCGttrZs7rBatZRDz75yXC6/Ac221n+owvp4Bfy+Cj9Pq4Kl zHyJwoSYyrtdJS7GcWgetj4EFYT6wk5jxyiEVts+MiN6S1CpsudpnuDIeSslPyRi3fmA u7vxAD+58czTA6Sy3dKih5YneDrPiG5xZUCxKkHukqnHKhOe/5veUZ/QGZ97B3qodQQE dP5w== 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; bh=l+DLE4OaxNb2V7PhvGWjDpmhBvdDO716f9vETkoZ5+s=; b=tb2xSeW3LSnOw3oKe58PV5CVI4+TDzgQFbtd53JcDb+eiv3m7dUFYC3Kfii6bqpD/d OK6ebSrmL2sfVH4B8Yz6EkLjAJERS1Cmh/TEdB2Y0AjJ0fn7VNi7+M0KIVkblAsexv8q sIYzJUMn3jKWyFm9lpInavMByud4aE1eQ5qhzADk5UcvDRKL1li2vY2s9TQwoYUsuzF9 CYqaMuqAWdb/b02NEydOd/k19Hz94gZ8KOQIKtgV3eZhrAtSHjTWBw41KKyM/w5Z1Q5k z6R7UlJoec9U5j2SVsq6BvOYk45/iM7jpRayQFp9e58KctJJPZPc8Qa66nJLcqIitLqN DEYA== X-Gm-Message-State: APjAAAWbR0PYCLG2pFlYy0NE0pASekqCVaJ/a5iVgimgdoV3KTSGSfe2 ZoKjDO5OuBPTYUi3NgfNaSbulg== X-Received: by 2002:adf:afee:: with SMTP id y46mr52015150wrd.217.1555435334298; Tue, 16 Apr 2019 10:22:14 -0700 (PDT) Received: from mai.imgcgcw.net (50.251.95.92.rev.sfr.net. [92.95.251.50]) by smtp.gmail.com with ESMTPSA id j11sm69473544wrw.85.2019.04.16.10.22.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Apr 2019 10:22:13 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, andrew.smirnov@gmail.com Subject: [PATCH] thermal/drivers/of: Add a get_temp_id callback function Date: Tue, 16 Apr 2019 19:22:03 +0200 Message-Id: <20190416172203.4679-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently when we register a sensor, we specify the sensor id and a data pointer to be passed when the get_temp function is called. However the sensor_id is not passed to the get_temp callback forcing the driver to do extra allocation and adding back pointer to find out from the sensor information the driver data and then back to the sensor id. Add a new callback get_temp_id() which will be called if set. It will call the get_temp_id() with the sensor id. That will be more consistent with the registering function. Signed-off-by: Daniel Lezcano Tested-by: Andrey Smirnov --- drivers/thermal/of-thermal.c | 19 +++++++++++++------ include/linux/thermal.h | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 2df059cc07e2..787d1cbe13f3 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -78,6 +78,8 @@ struct __thermal_zone { /* sensor interface */ void *sensor_data; + int sensor_id; + const struct thermal_zone_of_device_ops *ops; }; @@ -88,10 +90,14 @@ static int of_thermal_get_temp(struct thermal_zone_device *tz, { struct __thermal_zone *data = tz->devdata; - if (!data->ops->get_temp) - return -EINVAL; + if (data->ops->get_temp) + return data->ops->get_temp(data->sensor_data, temp); - return data->ops->get_temp(data->sensor_data, temp); + if (data->ops->get_temp_id) + return data->ops->get_temp_id(data->sensor_id, + data->sensor_data, temp); + + return -EINVAL; } static int of_thermal_set_trips(struct thermal_zone_device *tz, @@ -407,8 +413,8 @@ static struct thermal_zone_device_ops of_thermal_ops = { /*** sensor API ***/ static struct thermal_zone_device * -thermal_zone_of_add_sensor(struct device_node *zone, - struct device_node *sensor, void *data, +thermal_zone_of_add_sensor(struct device_node *zone, struct device_node *sensor, + int sensor_id, void *data, const struct thermal_zone_of_device_ops *ops) { struct thermal_zone_device *tzd; @@ -426,6 +432,7 @@ thermal_zone_of_add_sensor(struct device_node *zone, mutex_lock(&tzd->lock); tz->ops = ops; tz->sensor_data = data; + tz->sensor_id = sensor_id; tzd->ops->get_temp = of_thermal_get_temp; tzd->ops->get_trend = of_thermal_get_trend; @@ -516,7 +523,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, } if (sensor_specs.np == sensor_np && id == sensor_id) { - tzd = thermal_zone_of_add_sensor(child, sensor_np, + tzd = thermal_zone_of_add_sensor(child, sensor_np, sensor_id, data, ops); if (!IS_ERR(tzd)) tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 5f4705f46c2f..2762d7e6dd86 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -351,6 +351,7 @@ struct thermal_genl_event { * hardware. */ struct thermal_zone_of_device_ops { + int (*get_temp_id)(int, void *, int *); int (*get_temp)(void *, int *); int (*get_trend)(void *, int, enum thermal_trend *); int (*set_trips)(void *, int, int);