From patchwork Thu Apr 4 08:06:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 161754 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1293365jan; Thu, 4 Apr 2019 01:07:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCg82yxx8oH7jOLd6TAvVayNDVC2rPRNDQ15hPybuv3xPeF+BqZ+O+hEWHU06H8QEmif/i X-Received: by 2002:a17:902:7247:: with SMTP id c7mr4892609pll.255.1554365226868; Thu, 04 Apr 2019 01:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554365226; cv=none; d=google.com; s=arc-20160816; b=pXX1Ycv6rz0/wXJRN/ciMo0bXd3AzgPlwmY2tlbpJqy+SKCf9Qz4ISAa3+D/FDPAzM TMEheUvKrWMu9cF3RRhx1x1esk2l2jTBc2L2UQsi7xCr/hHWnEmaGFfIiKeT0LpE6N/7 PmMFd32trnS65QQp/JPuEdvsUcUGo0XG0j+fpR8iXsyUnFgHUMunpB5MotDDWFTPQIEx 8ScNxYJqoZSQebx+eo2v3n4IRso1mfaMBGH27LHSASr3AkvxKkfnRqsYqb5gvxnTTlIc UZLs4yM6QQaoRq+sP3kytDGzMonderuUg0gmBm5fon4vV0GaBD4wqOIhIKkt1O3jdGP5 CJOA== 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:dkim-signature; bh=X5EjowjeZ3lBCaiOxRkIEY3EgwtWt+4pPPGinUjsGf0=; b=ULD2CKAg15bYcVutxdxHqghQyMhiHjQWBXVat0F2BGI//3MrpyqgO9c98aS+lLN1tf 2em/SsiybjI3AKLQQ9y8viZ7MmiWc5K8t9JrdDVfTsceCGvvyqj6prqEe2ViM4harulL rnd9E9v+zcKy7D+6zE/WVA2vJpzom+Cu16fnRyN2ekgS/+OqGxLqHxIj9WgPjRteQCTM H7X9FLbzD8J1BDHrroZekP/VsiG1gzwYoB81WEfKqXWWmy91MKIJGSkgwug892lS43oU vtMswcklT8laBQARisjJzuOw80xX+v1GVt4qkqEEeoc+pAETOrTO2Bf02k55RAwaqZfP 8dGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZQ0v5O9T; 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 j24si11544107pll.286.2019.04.04.01.07.06; Thu, 04 Apr 2019 01:07:06 -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=ZQ0v5O9T; 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 S1726530AbfDDIHG (ORCPT + 11 others); Thu, 4 Apr 2019 04:07:06 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42834 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725904AbfDDIHF (ORCPT ); Thu, 4 Apr 2019 04:07:05 -0400 Received: by mail-pl1-f193.google.com with SMTP id cv12so758806plb.9 for ; Thu, 04 Apr 2019 01:07:05 -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:in-reply-to:references; bh=X5EjowjeZ3lBCaiOxRkIEY3EgwtWt+4pPPGinUjsGf0=; b=ZQ0v5O9TBvpHSZWD1HXxvJy3G27safHY07lxtBzZc0TsvglUPkaCctkATHKclz9/0I DPaGgB7voUEjbPbAYR38btNBdH3SII2DxiWhNhn91DnE+ZwQkRncAwWuUpVLDI0EnQbA l5+vNtyfHgk946oXNrRbmuvjo0azGoBs9Hy/AMt/bv2MbfyenYW4urdN2jD+MrxqVmv8 pi4j8qGQ4HaN7AEFq/ubJ5+M0gyA0CX+vaDq0YpyexgM0I+a+agFFZuzzggG4Z7wqaAO xLDEFA/gOQcS2kVqsb1GnmmqvMf+OKqOwj51rxF9T6f3aBaX2jCppeqllJgwy1t31K8N wXYw== 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; bh=X5EjowjeZ3lBCaiOxRkIEY3EgwtWt+4pPPGinUjsGf0=; b=ksnJxhv+rCOBo3fc1nB4T7tvL1f5Tsg7JYaUjS4qCO+x8IOatWvdbeTlrC+9FbK4uj n6pMPzWCX8ofaun1haTfNsykSllO1TrNUxM4QWAytD+zr/zs+SqT0hE0+ppOCDX8E32Q bhSXMwajLkPeaecZTQ9C92ihHlwEnkH8lEhzLAqTqfAVa+3CAw5gNhsY7e78zMnJQttW cJl0alsVNS4l9+9G1wjY/LK6WB9io0Rrmw0MCGqH6jfgWjFDWPYRDXBz4sjwAWPLu4D5 CM2sfwn5AptDKLZyGxT2qCIWEWE5fxxGcJT0J3xXmoQRvgXpbnEYOHoroFiQfLfNfHMM Kj6Q== X-Gm-Message-State: APjAAAUaKdKc7IBuxjTP5swG3bhNGWEh4eaoKQwliDMc15e/NFwM9jVb zHAVO0kWXQBtQFdoqt32Ev9MAg== X-Received: by 2002:a17:902:bd41:: with SMTP id b1mr4951965plx.221.1554365224645; Thu, 04 Apr 2019 01:07:04 -0700 (PDT) Received: from mai.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id x9sm32380940pfn.60.2019.04.04.01.07.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Apr 2019 01:07:03 -0700 (PDT) From: Daniel Lezcano To: andrew.smirnov@gmail.com Cc: linux-pm@vger.kernel.org, Zhang Rui , Eduardo Valentin , linux-kernel@vger.kernel.org (open list) Subject: [PATCH RFC 1/2] thermal/drivers/of: Add a get_temp_id callback function Date: Thu, 4 Apr 2019 10:06:46 +0200 Message-Id: <20190404080647.8173-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <00a5711b-5120-9e77-91a0-e0cbab456d92@linaro.org> References: <00a5711b-5120-9e77-91a0-e0cbab456d92@linaro.org> 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 --- drivers/thermal/of-thermal.c | 19 +++++++++++++------ include/linux/thermal.h | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) -- 2.17.1 Tested-by: Andrey Smirnov 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);