Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1663311ybv; Fri, 21 Feb 2020 01:14:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxwmEsGHyB3uRHmbCDAH+DUE0jGfcDhvjSZt3dXCqgw1Pkd25VRN0TcHKbOYaJ8Pod+ZJRr X-Received: by 2002:a9d:4c06:: with SMTP id l6mr28104473otf.161.1582276497264; Fri, 21 Feb 2020 01:14:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582276497; cv=none; d=google.com; s=arc-20160816; b=oMyyF56D4Q037nPbmRRA2SAfRFIrUS1r//VvC2sCY1zvP0nkJoI9dqiDz1WzWklBk5 QuGrNF+VE0cPjbDbroz5+Oo2LGaEhNl3itCrhuLk51Y/V+TCN5REsok0oLml+3Xw4He6 fn/ieZbO3whborztLV0oYvL+293Cjvoh19yxc2xaa6xyyNjWX6lbz/Npe/3wX9SraBqp r2l2Yr8UTtBlNIh32z3Q4yqeyf9YXzLjXjyPsiiwTTdqcxHqOuHUE5uTKz0t32hgwDJI jjj86W3aYqXHxD5ZfDf2PnosMrOu9SVmuySA0Y7KJwUftFi7CX579HeVqZQ9ZtUlq39e HOxw== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=azk1Q7pvujWav83kMuWej4FskuG4+RLdHCFFEc4Heqw=; b=X7JhLfJr6Q4t9iFg373kZxQ5JZdG3xfpjf/yaW8h3Kbrp+USB42oIrZpd50f85dxDr jBwfiOUEHT4/G4nWR4BPMoWwQYHB3gmSuNzPqs+ncWyhUm5NmqUxbiBXmQ7ePeUb8L4g AC73G4tzlgq/ujrKsGdZ80JnK+y6pIfI3sqG/WuLRYIYm6J1TCEvYC3hc2rtYGIG0e43 YG5ZNthlOeg/egkiqBuecRA1r+x8a3lACml/tLewg24kgLZwe/+pY61WJ+LgE2M7M0Uv nV5ZqN0tS1/bb26K5XqijgE08Z00XA9W14Pn83ZXV74hmx/Zcp0WHxDTyYZFePHeQmbO skMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z2T3cugD; 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 v14si1180632oto.127.2020.02.21.01.14.45; Fri, 21 Feb 2020 01:14:57 -0800 (PST) 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=z2T3cugD; 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 S1727907AbgBUJLT (ORCPT + 99 others); Fri, 21 Feb 2020 04:11:19 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55471 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726440AbgBUJLS (ORCPT ); Fri, 21 Feb 2020 04:11:18 -0500 Received: by mail-wm1-f67.google.com with SMTP id q9so856140wmj.5 for ; Fri, 21 Feb 2020 01:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=azk1Q7pvujWav83kMuWej4FskuG4+RLdHCFFEc4Heqw=; b=z2T3cugDBfcE9X09MGRjd1QXuGNe3k89XEsa3u0eDeWOjb3aCWK7Ft/FfZK/LaBp5S mzIVECOghk4NpHUsInWmKqapwZC/g4y0SeeaJRHeXOhBNDJbuLJz+Nyc7jvkzsLPKiii FuFaEvWrnG8eDMWl3EKLJrSY2eoIeqEaDiZzR5HMvECjyYnN1bjVGuTMPjIJWvypDWH6 8M+ghap0Yu9P8fqWKEC2v3RavqEHHLRV4CxBb3p8tpN7PblBBfBHF/qC89Xr1rU3UZjk 7cXlSzm2/U6bWYXYtYr/47MqGjJlaD9W/zyzzhgE5xO3NSUNm1WRL8SwIFIH8V6tAsZ1 O1bg== 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:content-transfer-encoding :in-reply-to:user-agent; bh=azk1Q7pvujWav83kMuWej4FskuG4+RLdHCFFEc4Heqw=; b=uefF1bYzkP49qdr6y2wMKbrDAWpqogB6d7mq3MQtfXcA+enAIlNFUr//OVN6oTqz5N HZwCRjvIFpETsWl6YmQ8UVNEZPKhpCBv2B8obtHn1x/b2K4h84n5KNEn5nTgfCqGRul6 DjE329keOsXHmzAVTacmAjx1fpVPUkHFrIbS1CVcfll8PeG4n281/A88TkoWPMRfdISb d+B9tbxHMenRqWVNWzPq7jsLrh29LEbA/IiZqHKX9GJ5iEonH2GwuCDF4vLXdLNitCn6 TxgkN2lSuTQPMs/5MPXUHhgnvokswqv7fQolTAcBsBu7khiBco47w0TzY3XdAYBPD/ge sNDQ== X-Gm-Message-State: APjAAAU731Wr6ybVymWucImEjgalOqwY2Cp82Vp92+hyZ4eFPn9/bVV9 RNBvTUMUSafKew7jy247xGIR3Q== X-Received: by 2002:a7b:c14d:: with SMTP id z13mr2534616wmi.71.1582276276286; Fri, 21 Feb 2020 01:11:16 -0800 (PST) Received: from linaro.org ([2a01:e34:ed2f:f020:2dfb:b5ce:9043:4adb]) by smtp.gmail.com with ESMTPSA id u23sm3032858wmu.14.2020.02.21.01.11.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Feb 2020 01:11:15 -0800 (PST) Date: Fri, 21 Feb 2020 10:11:12 +0100 From: Daniel Lezcano To: Anson Huang Cc: robh+dt@kernel.org, mark.rutland@arm.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, catalin.marinas@arm.com, will@kernel.org, rui.zhang@intel.com, amit.kucheria@verdurent.com, aisheng.dong@nxp.com, linux@roeck-us.net, srinivas.kandagatla@linaro.org, krzk@kernel.org, fugang.duan@nxp.com, peng.fan@nxp.com, daniel.baluta@nxp.com, bjorn.andersson@linaro.org, olof@lixom.net, dinguyen@kernel.org, leonard.crestez@nxp.com, marcin.juszkiewicz@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, Linux-imx@nxp.com Subject: Re: [PATCH V15 RESEND 2/5] thermal: of-thermal: add API for getting sensor ID from DT Message-ID: <20200221091112.GA10516@linaro.org> References: <1582161028-2844-1-git-send-email-Anson.Huang@nxp.com> <1582161028-2844-2-git-send-email-Anson.Huang@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1582161028-2844-2-git-send-email-Anson.Huang@nxp.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, Feb 20, 2020 at 09:10:25AM +0800, Anson Huang wrote: > This patch adds new API thermal_zone_of_get_sensor_id() to > provide the feature of getting sensor ID from DT thermal > zone's node. It's useful for thermal driver to register the > specific thermal zone devices from DT in a common way. > > Signed-off-by: Anson Huang > Reviewed-by: Dong Aisheng > --- > Changes since V14: > - improve the commit message and comment, no code change. > --- > drivers/thermal/of-thermal.c | 65 +++++++++++++++++++++++++++++++++----------- > include/linux/thermal.h | 10 +++++++ > 2 files changed, 59 insertions(+), 16 deletions(-) > > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index ef0baa9..0f57108 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -449,6 +449,53 @@ thermal_zone_of_add_sensor(struct device_node *zone, > } > > /** > + * thermal_zone_of_get_sensor_id - get sensor ID from a DT thermal zone > + * @tz_np: a valid thermal zone device node. > + * @sensor_np: a sensor node of a valid sensor device. > + * @id: the sensor ID returned if success. > + * > + * This function will get sensor ID from a given thermal zone node and > + * the sensor node must match the temperature provider @sensor_np. > + * > + * Return: 0 on success, proper error code otherwise. > + */ > + > +int thermal_zone_of_get_sensor_id(struct device_node *tz_np, > + struct device_node *sensor_np, > + u32 *id) > +{ > + struct of_phandle_args sensor_specs; > + int ret; > + > + ret = of_parse_phandle_with_args(tz_np, > + "thermal-sensors", > + "#thermal-sensor-cells", > + 0, > + &sensor_specs); > + if (ret) > + return ret; > + > + if (sensor_specs.np != sensor_np) { > + of_node_put(sensor_specs.np); > + return -ENODEV; > + } > + > + if (sensor_specs.args_count >= 1) { For the sake of clarity, move the sanity tests before: if (sensor_specs.args_count > 1) pr_warn("..."); *id = sensor_specs.args_count ? sensor_specs.args[0] : 0; > + *id = sensor_specs.args[0]; > + WARN(sensor_specs.args_count > 1, > + "%pOFn: too many cells in sensor specifier %d\n", > + sensor_specs.np, sensor_specs.args_count); > + } else { > + *id = 0; > + } > + > + of_node_put(sensor_specs.np); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(thermal_zone_of_get_sensor_id); > + > +/** > * thermal_zone_of_sensor_register - registers a sensor to a DT thermal zone > * @dev: a valid struct device pointer of a sensor device. Must contain > * a valid .of_node, for the sensor node. > @@ -499,36 +546,22 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, > sensor_np = of_node_get(dev->of_node); > > for_each_available_child_of_node(np, child) { > - struct of_phandle_args sensor_specs; > int ret, id; > > /* For now, thermal framework supports only 1 sensor per zone */ > - ret = of_parse_phandle_with_args(child, "thermal-sensors", > - "#thermal-sensor-cells", > - 0, &sensor_specs); > + ret = thermal_zone_of_get_sensor_id(child, sensor_np, &id); > if (ret) > continue; > > - if (sensor_specs.args_count >= 1) { > - id = sensor_specs.args[0]; > - WARN(sensor_specs.args_count > 1, > - "%pOFn: too many cells in sensor specifier %d\n", > - sensor_specs.np, sensor_specs.args_count); > - } else { > - id = 0; > - } Please take also the opportunity to factor out the function thermal_zone_of_sensor_register(). > - if (sensor_specs.np == sensor_np && id == sensor_id) { > + if (id == sensor_id) { > tzd = thermal_zone_of_add_sensor(child, sensor_np, > data, ops); > if (!IS_ERR(tzd)) > tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); > > - of_node_put(sensor_specs.np); > of_node_put(child); > goto exit; > } > - of_node_put(sensor_specs.np); > } > exit: > of_node_put(sensor_np); > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 126913c6..53e6f67 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -364,6 +364,9 @@ struct thermal_trip { > > /* Function declarations */ > #ifdef CONFIG_THERMAL_OF > +int thermal_zone_of_get_sensor_id(struct device_node *tz_np, > + struct device_node *sensor_np, > + u32 *id); > struct thermal_zone_device * > thermal_zone_of_sensor_register(struct device *dev, int id, void *data, > const struct thermal_zone_of_device_ops *ops); > @@ -375,6 +378,13 @@ struct thermal_zone_device *devm_thermal_zone_of_sensor_register( > void devm_thermal_zone_of_sensor_unregister(struct device *dev, > struct thermal_zone_device *tz); > #else > + > +static int thermal_zone_of_get_sensor_id(struct device_node *tz_np, > + struct device_node *sensor_np, > + u32 *id) > +{ > + return -ENOENT; > +} > static inline struct thermal_zone_device * > thermal_zone_of_sensor_register(struct device *dev, int id, void *data, > const struct thermal_zone_of_device_ops *ops) > -- > 2.7.4 > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog