Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3392012yba; Tue, 16 Apr 2019 10:23:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxWrCOQgDYaSQ0jv5WQLW4CyvgrcdnQeUfIBl9M3IdN/FArfLjbm4OHb0+BByT+2WqT2cp X-Received: by 2002:a17:902:bb0d:: with SMTP id l13mr80901517pls.141.1555435387948; Tue, 16 Apr 2019 10:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555435387; cv=none; d=google.com; s=arc-20160816; b=R59fCSdC5HgIUN8Ip3Bcp6SfKqcLAAUnSrw8MDWJNV/yrHpQp4jQXWusrnFDjfhcSO 45Lu+7qxlhaXRnq0Wme3uNtTqfdnY7kni4SBg3xfi9L0hmTsAa+OQaNLHM0PjeOWwJES pPnQKoFEnRO5zaDpIk4eAbfFh10l3WFc2+Blt5ZUB8vqAgMKb0oqX29hk2dTXZxT+Bqi ITpYnjcqW76OT4UTF1hfu42F+SrTNoKS8qeW2ogr/edfHrP4xHiLz4QHTlggzOC7SKO3 +LA/wFSXFAuXjqdYM0USiDoM/4PRMKecbgAdpVJYfJB4k+4wYhD2r+2M1HyFglUDPWaN wUAQ== 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=wgntkqvMiMb089UMI/o7CfvvI+7Rf0w5EpwgzXnZgTxkm9WOtsN4H+yHOYjUQUxiBs zwHSJDKJp7Awb1yDvojYU6zLGUHv8QbC/jTrg6C4bNeSCAJkzA9yt+NwML9WZkgMnc52 Lt5JXBxYdu9/dVCZ9Km3Dt9Mc+uvMcJoV3MWcf69V7p0mdQuZNsK19IS0GD+rVHkZwxc CzyzzHrfiAIRfhbmV/Ier1OuKyd8f4DiGE3KutibdgxnwP2mGEa7vcsoDcRx02Api7Vj pbYexoUbkx/vR4wgUS6kxcq/wJ/q9BO7WZ8D9wA54Y/cYt3MmxWuvoPvUgzNesfdRrhr JVEA== 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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 1si12545654plz.292.2019.04.16.10.22.50; Tue, 16 Apr 2019 10:23:07 -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=@linaro.org header.s=google header.b=i6bRs4gY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729251AbfDPRWQ (ORCPT + 99 others); Tue, 16 Apr 2019 13:22:16 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36881 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728000AbfDPRWQ (ORCPT ); Tue, 16 Apr 2019 13:22:16 -0400 Received: by mail-wr1-f66.google.com with SMTP id w10so28229326wrm.4 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=YNQQ5MHviWd5iSTbM7wdT/j44w/UY01fQ8165b0jK11wXnvAnXuAc4lsgGqr1JA0Qx aq6UoV7X3ejQX2J06trdqCLMg3UmlAyBGEJXNbx+BNNTeqK0zvMhXiBK4QqgGYf8O32P bxDzh40TXDMkVgLxpR5qNgx90XHeyVxHPiz36ys9hI7RLkerQdQmef1iVQlZTDys/x7L qqNZ6SMDJhCzsVqELUpU6yT5TeNHNvqCZ8aIwoYZC+ZstVhlPDxeSAKNazzj+62mFB25 dMZhvSE4oYrxfI4EaVspBjmLlTHzXPt8heKfGXONzQUmIiSJB7ePn2bf3omLxe1mZM0L AZ4A== X-Gm-Message-State: APjAAAWQ0P+xX9eBWub4ONopxcNgmGADOp8Nl4eHJksME+Syrdd+Uy/k 1rdxdAmaD/3KgxIgnuLuek/r9Q== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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); -- 2.17.1