From patchwork Tue Apr 16 03:22:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 10901861 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44EE517E6 for ; Tue, 16 Apr 2019 03:22:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A6C52857F for ; Tue, 16 Apr 2019 03:22:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E9AC28956; Tue, 16 Apr 2019 03:22:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83C9F2857F for ; Tue, 16 Apr 2019 03:22:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726739AbfDPDWX (ORCPT ); Mon, 15 Apr 2019 23:22:23 -0400 Received: from mail-eopbgr70053.outbound.protection.outlook.com ([40.107.7.53]:50575 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726237AbfDPDWX (ORCPT ); Mon, 15 Apr 2019 23:22:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6Y1qJnNfkOM3Ow2YFkmqivAVweRaWhs19+5fyvCNQ3A=; b=E2khNjBdUWxQQW59fMmWyfPFt7eT5uekcq9wy60cA1L6pPU4M3WIMUJKydjbaFR/m0KoK0wz2wVzRx6QDerpeT+8xJLNLeYgSmv3bv1oFx1ZlJXIQIdOwDn2osVXS9NCzWRJrIheRo1O1evJ+cGN1lxadSutfooTcflS78AJjIU= Received: from AM6PR0402MB3911.eurprd04.prod.outlook.com (52.133.30.10) by AM6PR0402MB3895.eurprd04.prod.outlook.com (52.133.29.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.11; Tue, 16 Apr 2019 03:22:17 +0000 Received: from AM6PR0402MB3911.eurprd04.prod.outlook.com ([fe80::c854:fc94:f9ed:2ca2]) by AM6PR0402MB3911.eurprd04.prod.outlook.com ([fe80::c854:fc94:f9ed:2ca2%6]) with mapi id 15.20.1792.020; Tue, 16 Apr 2019 03:22:17 +0000 From: Anson Huang To: "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.deacon@arm.com" , "rui.zhang@intel.com" , "edubezval@gmail.com" , "daniel.lezcano@linaro.org" , Aisheng Dong , "ulf.hansson@linaro.org" , Daniel Baluta , Peng Fan , "heiko@sntech.de" , "horms+renesas@verge.net.au" , "agross@kernel.org" , "olof@lixom.net" , "bjorn.andersson@linaro.org" , "jagan@amarulasolutions.com" , "enric.balletbo@collabora.com" , "marc.w.gonzalez@free.fr" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-pm@vger.kernel.org" CC: dl-linux-imx Subject: [PATCH V12 2/5] thermal: of-thermal: add API for getting sensor ID from DT Thread-Topic: [PATCH V12 2/5] thermal: of-thermal: add API for getting sensor ID from DT Thread-Index: AQHU9AOYmR6BJ3silEqzBa3crqYckQ== Date: Tue, 16 Apr 2019 03:22:17 +0000 Message-ID: <1555384609-7030-2-git-send-email-Anson.Huang@nxp.com> References: <1555384609-7030-1-git-send-email-Anson.Huang@nxp.com> In-Reply-To: <1555384609-7030-1-git-send-email-Anson.Huang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK2PR02CA0133.apcprd02.prod.outlook.com (2603:1096:202:16::17) To AM6PR0402MB3911.eurprd04.prod.outlook.com (2603:10a6:209:1c::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f05a450b-eb62-4362-819e-08d6c21aba5a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600140)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:AM6PR0402MB3895; x-ms-traffictypediagnostic: AM6PR0402MB3895: x-microsoft-antispam-prvs: x-forefront-prvs: 000947967F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39860400002)(366004)(136003)(396003)(346002)(376002)(199004)(189003)(6512007)(106356001)(105586002)(53936002)(2501003)(36756003)(6116002)(3846002)(66066001)(68736007)(486006)(110136005)(316002)(5660300002)(11346002)(446003)(476003)(2616005)(97736004)(71190400001)(71200400001)(81166006)(99286004)(8936002)(81156014)(8676002)(50226002)(52116002)(102836004)(256004)(14454004)(478600001)(6506007)(386003)(26005)(7736002)(4326008)(76176011)(86362001)(2906002)(7416002)(186003)(2201001)(25786009)(6486002)(6436002)(305945005)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:AM6PR0402MB3895;H:AM6PR0402MB3911.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 2lTIscw5KFDqFnh6h0QVSqOr2m3B8jRxzXOFmam/zHivjYcDk2t/gKsIdTWUFrhpMSQehAjzidWsw2csHyDBO3+5Eo+wRNvEm7waXJoUceEcVK2t5hNVD4FZ+FTLGik1Tiqc9r2XmO9Pk75bS3TnhOol0Z9W3+Tlbc6KQ/oFCYX8P/FKdkzab5YUggqX93msJG7WvSj/CE+IdIIMtFO+SpVK8ToJJMc8JfUAYN1vk2bqmD19jL/MdU13I2JQuR7zu4NiTLrUzp0d8PlZwFOHi9ZfW+YONKS/Z7vyBJo/n3laxqOL8nZijz7kM5BirXmuPVosYyoRYiqTXODSnfPf9Jdcazi4ta0mNTAZzWCWGczaLMuR2Z0j3sPlhmTdL/GjudiV7S5em3mmKCUUfondPzZI6Qfky/6GfmV1EwrKDj8= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f05a450b-eb62-4362-819e-08d6c21aba5a X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Apr 2019 03:22:17.8220 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0402MB3895 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On some platforms like i.MX8QXP, the thermal driver needs a real HW sensor ID from DT thermal zone, the HW sensor ID is used to get temperature from SCU firmware, and the virtual sensor ID starting from 0 to N is NOT used at all, 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. Signed-off-by: Anson Huang --- New patch. --- drivers/thermal/of-thermal.c | 53 ++++++++++++++++++++++++++++++++++---------- include/linux/thermal.h | 10 +++++++++ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 2df059c..2e4320c 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -446,6 +446,46 @@ 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_specs: pointer to output arguments structure will be passed back. + * @id: a sensor ID pointer will be passed back. + * + * This function will get sensor ID from a given thermal zone node, use + * "thermal-sensors" as list name, and get sensor ID from first phandle's + * argument. + * + * Return: 0 on success, proper error code otherwise. + */ + +int thermal_zone_of_get_sensor_id(struct device_node *tz_np, + struct of_phandle_args *sensor_specs, + u32 *id) +{ + 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->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; + } + + 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. @@ -500,21 +540,10 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, 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_specs, &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; - } - if (sensor_specs.np == sensor_np && id == sensor_id) { tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 5f4705f..970fb37 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -375,6 +375,9 @@ struct thermal_trip { /* Function declarations */ #ifdef CONFIG_THERMAL_OF +int thermal_zone_of_get_sensor_id(struct device_node *tz_np, + struct of_phandle_args *sensor_specs, + 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); @@ -386,6 +389,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 of_phandle_args *sensor_specs, + 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)