Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3736426yba; Tue, 23 Apr 2019 08:47:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxa+KHAyF4tavp6vmfV8Du2ulrl1wlhBZJOlKJLtE2++zPLBHbv3A2ZRB7O8ODJOgcro3Mt X-Received: by 2002:a17:902:f209:: with SMTP id gn9mr27185228plb.109.1556034443090; Tue, 23 Apr 2019 08:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556034443; cv=none; d=google.com; s=arc-20160816; b=QCT21dcWh9g05E92OpJLeQEnWto/E+A6naV3e9p2TMF8vP2nMk0UlDjjlpaFpKbC9R q/51ED0Ss3hSZA3/rZAMEhWZ3KF/px73iTdestRGXVpSfVLrKeu6UWzudbOIHHQm65bj Q+4JMVwsxPsBbXvQ48Y5wc1gpNdzcM9D8h1Br4b5592wT2u2V5cvJwz/EzTdjxPicUun qqGCJYY4FMgJnSwRSHdbZdNIN5sT0no3BLudEugqMF0wvVdNnz/d3/l6SlnPz2aNmK97 Plxfn6HASwNz7uUz9i7GgeTfF6Zyiy8vCSzItu80RJ+CT5zjqGjzV0dXSkT7ezQuyT41 pLEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UHKhNGF9h6UnRkG1fb5S0yRAer4+UyZQ8Isf84BVwlc=; b=C+bmyZr+ZPlHnT16nt7G8L1dzXyGGyl8RDBau175rgGIRsrywn05rMpOaF5rqRcz2p nx53m9dP+I5ba9I4KCyN6mCEdqgHZohFBQ1Uj9H2Kt4H2o7pDndVSYZUqRYKtESK1X5r yYmCt/G0ULDKpFPIkZiWfmf2BSZySGXQPAnLiAcD//mBqlMAl0QXlY9FbYZi9vBzFpXb e2d02LxWAdKnE9AfwmHMMuZBLkLRrAoJy3sh5rXH1xwHgR9UqCnThbMeDse+4d76lcia Pn7ghnP3udt9Nw89Hg0W6Et5V2w5et2HC7Aw2ClZXtX7qaXkyRijWp+Isuut3obBpPSA cLMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="I/ZfuxG4"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f80si10045905pff.23.2019.04.23.08.47.07; Tue, 23 Apr 2019 08:47:23 -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=@gmail.com header.s=20161025 header.b="I/ZfuxG4"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728491AbfDWPoh (ORCPT + 99 others); Tue, 23 Apr 2019 11:44:37 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35387 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728406AbfDWPof (ORCPT ); Tue, 23 Apr 2019 11:44:35 -0400 Received: by mail-pg1-f193.google.com with SMTP id g8so7820834pgf.2; Tue, 23 Apr 2019 08:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UHKhNGF9h6UnRkG1fb5S0yRAer4+UyZQ8Isf84BVwlc=; b=I/ZfuxG4emX1qFeKLWISK6/79zfkCARgP4ZSgnvjXKqP6YbYDE7vO2Z6Rb7bxpLujP wghU3+u88ssKhf6mLMcTDUNu4MJIRcPoToVRsK4RWqMJThO3uFNwG/SG8mVc7sYxNsoi jTuvhc+txnqXi5qMk/Y5tP1T3J7AD9ALqrFKHD8rC/bMJdjlTQlAtJDRVi2BvcDGFYYq N/Bi6gDF5Vms7KSymsgexaN684iDBLPfzbki0s5cXdu+ks7/e8beiWJpVkQbMnUTHKmB YfKWRzddej7uL+KC/JYbEqpSRjeK4RVCmDlyrjLk9tZvgOMHvCsBgqAJnZLk7MXVxOd2 7scA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UHKhNGF9h6UnRkG1fb5S0yRAer4+UyZQ8Isf84BVwlc=; b=Xu5LMYsiVfD+RO9Y101cK+UdSgIT0+HraRr2A5TaisSrwyB0ytomb6VIcPSez8v9MO QD8/BNkbIuKX0djTPaLnqY1m+9itcELT1ka4Lsq5dqumKiHIrzEoGjX0ZPLldgiRvklj YR4XP7epHov1ixTMClqnnm3hztjyxoJV8EXqWBtgToGVAcxz95qtSsQmH81Rt+OgA0kR uW07krEfgQn1EqIyJEsNxF9Nhey1kWQUnxkdLxbSqUEV7oIN5Cde66i3p54Sb20+Hj2C u7qUTiBrW/oSthBTEbwbnr4PLBoWpTAS4JclGJj77YAHnXgqBa8c6gC3kQ1AvAmlveIO pywg== X-Gm-Message-State: APjAAAVkwPDSR1xWnTXA54mpFQjbM91XEHLYrRpChhwgIOgk8PSwMbCY pikpcw4AKWkFgMK1sDx9+r4= X-Received: by 2002:a62:62c2:: with SMTP id w185mr3739702pfb.237.1556034274772; Tue, 23 Apr 2019 08:44:34 -0700 (PDT) Received: from localhost.localdomain ([2601:644:8201:32e0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id m131sm41015465pga.3.2019.04.23.08.44.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 08:44:33 -0700 (PDT) Date: Tue, 23 Apr 2019 08:44:31 -0700 From: Eduardo Valentin To: Daniel Lezcano Cc: rui.zhang@intel.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, andrew.smirnov@gmail.com Subject: Re: [PATCH] thermal/drivers/of: Add a get_temp_id callback function Message-ID: <20190423154430.GA16014@localhost.localdomain> References: <20190416172203.4679-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190416172203.4679-1-daniel.lezcano@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Tue, Apr 16, 2019 at 07:22:03PM +0200, Daniel Lezcano wrote: > 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. I still do not understand why we need to have a get_id callback. The use cases I have seen so far, which I have been intentionally rejecting, are mainly solvable by creating other compatible entries. And really, if you have, say a bandgap, chip that supports multiple sensors, but on SoC version A it has 5 sensors, and on SoC version B it has only 4, or on SoC version C, it has 5 but they are either logially located in different places (gpu vs iva regions), these are all cases in which you want a different compatible! Do you mind sharing why you need a get sensor id callback? > > 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 >