* [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-07-24 16:29 ` Mikko Perttunen
0 siblings, 0 replies; 36+ messages in thread
From: Mikko Perttunen @ 2017-07-24 16:29 UTC (permalink / raw)
To: rui.zhang, edubezval, thierry.reding, jonathanh
Cc: linux-pm, linux-tegra, linux-arm-kernel, linux-kernel,
Mikko Perttunen
On Tegra186, the BPMP (Boot and Power Management Processor) exposes an
interface to thermal sensors on the system-on-chip. This driver
implements access to the interface. It supports reading the
temperature, setting trip points and receiving notification of a
tripped trip point.
Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
v2:
- don't allocate space for disabled zones
- allow compilation with COMPILE_TEST
drivers/thermal/Makefile | 2 +-
drivers/thermal/tegra/Kconfig | 7 +
drivers/thermal/tegra/Makefile | 3 +-
drivers/thermal/tegra/bpmp-thermal.c | 263 +++++++++++++++++++++++++++++++++++
4 files changed, 273 insertions(+), 2 deletions(-)
create mode 100644 drivers/thermal/tegra/bpmp-thermal.c
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 094d7039981c..c03dccdba7b8 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -54,7 +54,7 @@ obj-$(CONFIG_INTEL_BXT_PMIC_THERMAL) += intel_bxt_pmic_thermal.o
obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o
obj-$(CONFIG_ST_THERMAL) += st/
obj-$(CONFIG_QCOM_TSENS) += qcom/
-obj-$(CONFIG_TEGRA_SOCTHERM) += tegra/
+obj-y += tegra/
obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o
diff --git a/drivers/thermal/tegra/Kconfig b/drivers/thermal/tegra/Kconfig
index cec586ec7e4b..f8740f7852e3 100644
--- a/drivers/thermal/tegra/Kconfig
+++ b/drivers/thermal/tegra/Kconfig
@@ -10,4 +10,11 @@ config TEGRA_SOCTHERM
zones to manage temperatures. This option is also required for the
emergency thermal reset (thermtrip) feature to function.
+config TEGRA_BPMP_THERMAL
+ tristate "Tegra BPMP thermal sensing"
+ depends on TEGRA_BPMP || COMPILE_TEST
+ help
+ Enable this option for support for sensing system temperature of NVIDIA
+ Tegra systems-on-chip with the BPMP coprocessor (Tegra186).
+
endmenu
diff --git a/drivers/thermal/tegra/Makefile b/drivers/thermal/tegra/Makefile
index 1ce1af2cf0f5..757abcd1feaf 100644
--- a/drivers/thermal/tegra/Makefile
+++ b/drivers/thermal/tegra/Makefile
@@ -1,4 +1,5 @@
-obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
+obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
+obj-$(CONFIG_TEGRA_BPMP_THERMAL) += bpmp-thermal.o
tegra-soctherm-y := soctherm.o soctherm-fuse.o
tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC) += tegra124-soctherm.o
diff --git a/drivers/thermal/tegra/bpmp-thermal.c b/drivers/thermal/tegra/bpmp-thermal.c
new file mode 100644
index 000000000000..b0980dbca3b3
--- /dev/null
+++ b/drivers/thermal/tegra/bpmp-thermal.c
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2015-2017, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Author:
+ * Mikko Perttunen <mperttunen@nvidia.com>
+ * Aapo Vienamo <avienamo@nvidia.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+#include <linux/workqueue.h>
+
+#include <soc/tegra/bpmp.h>
+#include <soc/tegra/bpmp-abi.h>
+
+struct tegra_bpmp_thermal_zone {
+ struct tegra_bpmp_thermal *tegra;
+ struct thermal_zone_device *tzd;
+ struct work_struct tz_device_update_work;
+ unsigned int idx;
+};
+
+struct tegra_bpmp_thermal {
+ struct device *dev;
+ struct tegra_bpmp *bpmp;
+ unsigned int num_zones;
+ struct tegra_bpmp_thermal_zone **zones;
+};
+
+static int tegra_bpmp_thermal_get_temp(void *data, int *out_temp)
+{
+ struct tegra_bpmp_thermal_zone *zone = data;
+ struct mrq_thermal_host_to_bpmp_request req;
+ union mrq_thermal_bpmp_to_host_response reply;
+ struct tegra_bpmp_message msg;
+ int err;
+
+ memset(&req, 0, sizeof(req));
+ req.type = CMD_THERMAL_GET_TEMP;
+ req.get_temp.zone = zone->idx;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.mrq = MRQ_THERMAL;
+ msg.tx.data = &req;
+ msg.tx.size = sizeof(req);
+ msg.rx.data = &reply;
+ msg.rx.size = sizeof(reply);
+
+ err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
+ if (err)
+ return err;
+
+ *out_temp = reply.get_temp.temp;
+
+ return 0;
+}
+
+static int tegra_bpmp_thermal_set_trips(void *data, int low, int high)
+{
+ struct tegra_bpmp_thermal_zone *zone = data;
+ struct mrq_thermal_host_to_bpmp_request req;
+ struct tegra_bpmp_message msg;
+
+ memset(&req, 0, sizeof(req));
+ req.type = CMD_THERMAL_SET_TRIP;
+ req.set_trip.zone = zone->idx;
+ req.set_trip.enabled = true;
+ req.set_trip.low = low;
+ req.set_trip.high = high;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.mrq = MRQ_THERMAL;
+ msg.tx.data = &req;
+ msg.tx.size = sizeof(req);
+
+ return tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
+}
+
+static void tz_device_update_work_fn(struct work_struct *work)
+{
+ struct tegra_bpmp_thermal_zone *zone;
+
+ zone = container_of(work, struct tegra_bpmp_thermal_zone,
+ tz_device_update_work);
+
+ thermal_zone_device_update(zone->tzd, THERMAL_TRIP_VIOLATED);
+}
+
+static void bpmp_mrq_thermal(unsigned int mrq, struct tegra_bpmp_channel *ch,
+ void *data)
+{
+ struct mrq_thermal_bpmp_to_host_request *req;
+ struct tegra_bpmp_thermal *tegra = data;
+ int i;
+
+ req = (struct mrq_thermal_bpmp_to_host_request *)ch->ib->data;
+
+ if (req->type != CMD_THERMAL_HOST_TRIP_REACHED) {
+ dev_err(tegra->dev, "%s: invalid request type: %d\n",
+ __func__, req->type);
+ tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
+ return;
+ }
+
+ for (i = 0; i < tegra->num_zones; ++i) {
+ if (tegra->zones[i]->idx != req->host_trip_reached.zone)
+ continue;
+
+ schedule_work(&tegra->zones[i]->tz_device_update_work);
+ tegra_bpmp_mrq_return(ch, 0, NULL, 0);
+ return;
+ }
+
+ dev_err(tegra->dev, "%s: invalid thermal zone: %d\n", __func__,
+ req->host_trip_reached.zone);
+ tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
+}
+
+static int tegra_bpmp_thermal_get_num_zones(struct tegra_bpmp *bpmp,
+ int *num_zones)
+{
+ struct mrq_thermal_host_to_bpmp_request req;
+ union mrq_thermal_bpmp_to_host_response reply;
+ struct tegra_bpmp_message msg;
+ int err;
+
+ memset(&req, 0, sizeof(req));
+ req.type = CMD_THERMAL_GET_NUM_ZONES;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.mrq = MRQ_THERMAL;
+ msg.tx.data = &req;
+ msg.tx.size = sizeof(req);
+ msg.rx.data = &reply;
+ msg.rx.size = sizeof(reply);
+
+ err = tegra_bpmp_transfer(bpmp, &msg);
+ if (err)
+ return err;
+
+ *num_zones = reply.get_num_zones.num;
+
+ return 0;
+}
+
+static const struct thermal_zone_of_device_ops tegra_bpmp_of_thermal_ops = {
+ .get_temp = tegra_bpmp_thermal_get_temp,
+ .set_trips = tegra_bpmp_thermal_set_trips,
+};
+
+static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
+{
+ struct tegra_bpmp *bpmp = dev_get_drvdata(pdev->dev.parent);
+ struct tegra_bpmp_thermal *tegra;
+ struct thermal_zone_device *tzd;
+ unsigned int i, max_num_zones;
+ int err;
+
+ tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL);
+ if (!tegra)
+ return -ENOMEM;
+
+ tegra->dev = &pdev->dev;
+ tegra->bpmp = bpmp;
+
+ err = tegra_bpmp_thermal_get_num_zones(bpmp, &max_num_zones);
+ if (err) {
+ dev_err(&pdev->dev, "failed to get the number of zones: %d\n",
+ err);
+ return err;
+ }
+
+ tegra->zones = devm_kcalloc(&pdev->dev, max_num_zones,
+ sizeof(*tegra->zones), GFP_KERNEL);
+ if (!tegra->zones)
+ return -ENOMEM;
+
+ for (i = 0; i < max_num_zones; ++i) {
+ struct tegra_bpmp_thermal_zone *zone;
+ int temp;
+
+ zone = devm_kzalloc(&pdev->dev, sizeof(*zone), GFP_KERNEL);
+ if (!zone)
+ return -ENOMEM;
+
+ zone->idx = i;
+ zone->tegra = tegra;
+
+ err = tegra_bpmp_thermal_get_temp(zone, &temp);
+ if (err < 0) {
+ devm_kfree(&pdev->dev, zone);
+ continue;
+ }
+
+ tzd = devm_thermal_zone_of_sensor_register(
+ &pdev->dev, i, zone, &tegra_bpmp_of_thermal_ops);
+ if (IS_ERR(tzd)) {
+ if (PTR_ERR(tzd) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ devm_kfree(&pdev->dev, zone);
+ continue;
+ }
+
+ zone->tzd = tzd;
+ INIT_WORK(&zone->tz_device_update_work,
+ tz_device_update_work_fn);
+
+ tegra->zones[tegra->num_zones++] = zone;
+ }
+
+ err = tegra_bpmp_request_mrq(bpmp, MRQ_THERMAL, bpmp_mrq_thermal,
+ tegra);
+ if (err) {
+ dev_err(&pdev->dev, "failed to register mrq handler: %d\n",
+ err);
+ return err;
+ }
+
+ platform_set_drvdata(pdev, tegra);
+
+ return 0;
+}
+
+static int tegra_bpmp_thermal_remove(struct platform_device *pdev)
+{
+ struct tegra_bpmp_thermal *tegra = platform_get_drvdata(pdev);
+
+ tegra_bpmp_free_mrq(tegra->bpmp, MRQ_THERMAL, tegra);
+
+ return 0;
+}
+
+static const struct of_device_id tegra_bpmp_thermal_of_match[] = {
+ { .compatible = "nvidia,tegra186-bpmp-thermal" },
+ { },
+};
+MODULE_DEVICE_TABLE(of, tegra_bpmp_thermal_of_match);
+
+static struct platform_driver tegra_bpmp_thermal_driver = {
+ .probe = tegra_bpmp_thermal_probe,
+ .remove = tegra_bpmp_thermal_remove,
+ .driver = {
+ .name = "tegra-bpmp-thermal",
+ .of_match_table = tegra_bpmp_thermal_of_match,
+ },
+};
+module_platform_driver(tegra_bpmp_thermal_driver);
+
+MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
+MODULE_DESCRIPTION("NVIDIA Tegra BPMP thermal sensor driver");
+MODULE_LICENSE("GPL v2");
--
2.13.3
^ permalink raw reply related [flat|nested] 36+ messages in thread* [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-07-24 16:29 ` Mikko Perttunen
0 siblings, 0 replies; 36+ messages in thread
From: Mikko Perttunen @ 2017-07-24 16:29 UTC (permalink / raw)
To: linux-arm-kernel
On Tegra186, the BPMP (Boot and Power Management Processor) exposes an
interface to thermal sensors on the system-on-chip. This driver
implements access to the interface. It supports reading the
temperature, setting trip points and receiving notification of a
tripped trip point.
Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
v2:
- don't allocate space for disabled zones
- allow compilation with COMPILE_TEST
drivers/thermal/Makefile | 2 +-
drivers/thermal/tegra/Kconfig | 7 +
drivers/thermal/tegra/Makefile | 3 +-
drivers/thermal/tegra/bpmp-thermal.c | 263 +++++++++++++++++++++++++++++++++++
4 files changed, 273 insertions(+), 2 deletions(-)
create mode 100644 drivers/thermal/tegra/bpmp-thermal.c
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 094d7039981c..c03dccdba7b8 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -54,7 +54,7 @@ obj-$(CONFIG_INTEL_BXT_PMIC_THERMAL) += intel_bxt_pmic_thermal.o
obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o
obj-$(CONFIG_ST_THERMAL) += st/
obj-$(CONFIG_QCOM_TSENS) += qcom/
-obj-$(CONFIG_TEGRA_SOCTHERM) += tegra/
+obj-y += tegra/
obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o
diff --git a/drivers/thermal/tegra/Kconfig b/drivers/thermal/tegra/Kconfig
index cec586ec7e4b..f8740f7852e3 100644
--- a/drivers/thermal/tegra/Kconfig
+++ b/drivers/thermal/tegra/Kconfig
@@ -10,4 +10,11 @@ config TEGRA_SOCTHERM
zones to manage temperatures. This option is also required for the
emergency thermal reset (thermtrip) feature to function.
+config TEGRA_BPMP_THERMAL
+ tristate "Tegra BPMP thermal sensing"
+ depends on TEGRA_BPMP || COMPILE_TEST
+ help
+ Enable this option for support for sensing system temperature of NVIDIA
+ Tegra systems-on-chip with the BPMP coprocessor (Tegra186).
+
endmenu
diff --git a/drivers/thermal/tegra/Makefile b/drivers/thermal/tegra/Makefile
index 1ce1af2cf0f5..757abcd1feaf 100644
--- a/drivers/thermal/tegra/Makefile
+++ b/drivers/thermal/tegra/Makefile
@@ -1,4 +1,5 @@
-obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
+obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
+obj-$(CONFIG_TEGRA_BPMP_THERMAL) += bpmp-thermal.o
tegra-soctherm-y := soctherm.o soctherm-fuse.o
tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC) += tegra124-soctherm.o
diff --git a/drivers/thermal/tegra/bpmp-thermal.c b/drivers/thermal/tegra/bpmp-thermal.c
new file mode 100644
index 000000000000..b0980dbca3b3
--- /dev/null
+++ b/drivers/thermal/tegra/bpmp-thermal.c
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2015-2017, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Author:
+ * Mikko Perttunen <mperttunen@nvidia.com>
+ * Aapo Vienamo <avienamo@nvidia.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+#include <linux/workqueue.h>
+
+#include <soc/tegra/bpmp.h>
+#include <soc/tegra/bpmp-abi.h>
+
+struct tegra_bpmp_thermal_zone {
+ struct tegra_bpmp_thermal *tegra;
+ struct thermal_zone_device *tzd;
+ struct work_struct tz_device_update_work;
+ unsigned int idx;
+};
+
+struct tegra_bpmp_thermal {
+ struct device *dev;
+ struct tegra_bpmp *bpmp;
+ unsigned int num_zones;
+ struct tegra_bpmp_thermal_zone **zones;
+};
+
+static int tegra_bpmp_thermal_get_temp(void *data, int *out_temp)
+{
+ struct tegra_bpmp_thermal_zone *zone = data;
+ struct mrq_thermal_host_to_bpmp_request req;
+ union mrq_thermal_bpmp_to_host_response reply;
+ struct tegra_bpmp_message msg;
+ int err;
+
+ memset(&req, 0, sizeof(req));
+ req.type = CMD_THERMAL_GET_TEMP;
+ req.get_temp.zone = zone->idx;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.mrq = MRQ_THERMAL;
+ msg.tx.data = &req;
+ msg.tx.size = sizeof(req);
+ msg.rx.data = &reply;
+ msg.rx.size = sizeof(reply);
+
+ err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
+ if (err)
+ return err;
+
+ *out_temp = reply.get_temp.temp;
+
+ return 0;
+}
+
+static int tegra_bpmp_thermal_set_trips(void *data, int low, int high)
+{
+ struct tegra_bpmp_thermal_zone *zone = data;
+ struct mrq_thermal_host_to_bpmp_request req;
+ struct tegra_bpmp_message msg;
+
+ memset(&req, 0, sizeof(req));
+ req.type = CMD_THERMAL_SET_TRIP;
+ req.set_trip.zone = zone->idx;
+ req.set_trip.enabled = true;
+ req.set_trip.low = low;
+ req.set_trip.high = high;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.mrq = MRQ_THERMAL;
+ msg.tx.data = &req;
+ msg.tx.size = sizeof(req);
+
+ return tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
+}
+
+static void tz_device_update_work_fn(struct work_struct *work)
+{
+ struct tegra_bpmp_thermal_zone *zone;
+
+ zone = container_of(work, struct tegra_bpmp_thermal_zone,
+ tz_device_update_work);
+
+ thermal_zone_device_update(zone->tzd, THERMAL_TRIP_VIOLATED);
+}
+
+static void bpmp_mrq_thermal(unsigned int mrq, struct tegra_bpmp_channel *ch,
+ void *data)
+{
+ struct mrq_thermal_bpmp_to_host_request *req;
+ struct tegra_bpmp_thermal *tegra = data;
+ int i;
+
+ req = (struct mrq_thermal_bpmp_to_host_request *)ch->ib->data;
+
+ if (req->type != CMD_THERMAL_HOST_TRIP_REACHED) {
+ dev_err(tegra->dev, "%s: invalid request type: %d\n",
+ __func__, req->type);
+ tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
+ return;
+ }
+
+ for (i = 0; i < tegra->num_zones; ++i) {
+ if (tegra->zones[i]->idx != req->host_trip_reached.zone)
+ continue;
+
+ schedule_work(&tegra->zones[i]->tz_device_update_work);
+ tegra_bpmp_mrq_return(ch, 0, NULL, 0);
+ return;
+ }
+
+ dev_err(tegra->dev, "%s: invalid thermal zone: %d\n", __func__,
+ req->host_trip_reached.zone);
+ tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
+}
+
+static int tegra_bpmp_thermal_get_num_zones(struct tegra_bpmp *bpmp,
+ int *num_zones)
+{
+ struct mrq_thermal_host_to_bpmp_request req;
+ union mrq_thermal_bpmp_to_host_response reply;
+ struct tegra_bpmp_message msg;
+ int err;
+
+ memset(&req, 0, sizeof(req));
+ req.type = CMD_THERMAL_GET_NUM_ZONES;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.mrq = MRQ_THERMAL;
+ msg.tx.data = &req;
+ msg.tx.size = sizeof(req);
+ msg.rx.data = &reply;
+ msg.rx.size = sizeof(reply);
+
+ err = tegra_bpmp_transfer(bpmp, &msg);
+ if (err)
+ return err;
+
+ *num_zones = reply.get_num_zones.num;
+
+ return 0;
+}
+
+static const struct thermal_zone_of_device_ops tegra_bpmp_of_thermal_ops = {
+ .get_temp = tegra_bpmp_thermal_get_temp,
+ .set_trips = tegra_bpmp_thermal_set_trips,
+};
+
+static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
+{
+ struct tegra_bpmp *bpmp = dev_get_drvdata(pdev->dev.parent);
+ struct tegra_bpmp_thermal *tegra;
+ struct thermal_zone_device *tzd;
+ unsigned int i, max_num_zones;
+ int err;
+
+ tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL);
+ if (!tegra)
+ return -ENOMEM;
+
+ tegra->dev = &pdev->dev;
+ tegra->bpmp = bpmp;
+
+ err = tegra_bpmp_thermal_get_num_zones(bpmp, &max_num_zones);
+ if (err) {
+ dev_err(&pdev->dev, "failed to get the number of zones: %d\n",
+ err);
+ return err;
+ }
+
+ tegra->zones = devm_kcalloc(&pdev->dev, max_num_zones,
+ sizeof(*tegra->zones), GFP_KERNEL);
+ if (!tegra->zones)
+ return -ENOMEM;
+
+ for (i = 0; i < max_num_zones; ++i) {
+ struct tegra_bpmp_thermal_zone *zone;
+ int temp;
+
+ zone = devm_kzalloc(&pdev->dev, sizeof(*zone), GFP_KERNEL);
+ if (!zone)
+ return -ENOMEM;
+
+ zone->idx = i;
+ zone->tegra = tegra;
+
+ err = tegra_bpmp_thermal_get_temp(zone, &temp);
+ if (err < 0) {
+ devm_kfree(&pdev->dev, zone);
+ continue;
+ }
+
+ tzd = devm_thermal_zone_of_sensor_register(
+ &pdev->dev, i, zone, &tegra_bpmp_of_thermal_ops);
+ if (IS_ERR(tzd)) {
+ if (PTR_ERR(tzd) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ devm_kfree(&pdev->dev, zone);
+ continue;
+ }
+
+ zone->tzd = tzd;
+ INIT_WORK(&zone->tz_device_update_work,
+ tz_device_update_work_fn);
+
+ tegra->zones[tegra->num_zones++] = zone;
+ }
+
+ err = tegra_bpmp_request_mrq(bpmp, MRQ_THERMAL, bpmp_mrq_thermal,
+ tegra);
+ if (err) {
+ dev_err(&pdev->dev, "failed to register mrq handler: %d\n",
+ err);
+ return err;
+ }
+
+ platform_set_drvdata(pdev, tegra);
+
+ return 0;
+}
+
+static int tegra_bpmp_thermal_remove(struct platform_device *pdev)
+{
+ struct tegra_bpmp_thermal *tegra = platform_get_drvdata(pdev);
+
+ tegra_bpmp_free_mrq(tegra->bpmp, MRQ_THERMAL, tegra);
+
+ return 0;
+}
+
+static const struct of_device_id tegra_bpmp_thermal_of_match[] = {
+ { .compatible = "nvidia,tegra186-bpmp-thermal" },
+ { },
+};
+MODULE_DEVICE_TABLE(of, tegra_bpmp_thermal_of_match);
+
+static struct platform_driver tegra_bpmp_thermal_driver = {
+ .probe = tegra_bpmp_thermal_probe,
+ .remove = tegra_bpmp_thermal_remove,
+ .driver = {
+ .name = "tegra-bpmp-thermal",
+ .of_match_table = tegra_bpmp_thermal_of_match,
+ },
+};
+module_platform_driver(tegra_bpmp_thermal_driver);
+
+MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
+MODULE_DESCRIPTION("NVIDIA Tegra BPMP thermal sensor driver");
+MODULE_LICENSE("GPL v2");
--
2.13.3
^ permalink raw reply related [flat|nested] 36+ messages in thread* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
2017-07-24 16:29 ` Mikko Perttunen
@ 2017-08-11 2:57 ` Zhang Rui
-1 siblings, 0 replies; 36+ messages in thread
From: Zhang Rui @ 2017-08-11 2:57 UTC (permalink / raw)
To: Mikko Perttunen, edubezval, thierry.reding, jonathanh, wni
Cc: linux-pm, linux-tegra, linux-arm-kernel, linux-kernel
On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
> an
> interface to thermal sensors on the system-on-chip. This driver
> implements access to the interface. It supports reading the
> temperature, setting trip points and receiving notification of a
> tripped trip point.
>
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Wei Ni,
what do you think of this patch?
thanks,
rui
> ---
> v2:
> - don't allocate space for disabled zones
> - allow compilation with COMPILE_TEST
>
> drivers/thermal/Makefile | 2 +-
> drivers/thermal/tegra/Kconfig | 7 +
> drivers/thermal/tegra/Makefile | 3 +-
> drivers/thermal/tegra/bpmp-thermal.c | 263
> +++++++++++++++++++++++++++++++++++
> 4 files changed, 273 insertions(+), 2 deletions(-)
> create mode 100644 drivers/thermal/tegra/bpmp-thermal.c
>
> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
> index 094d7039981c..c03dccdba7b8 100644
> --- a/drivers/thermal/Makefile
> +++ b/drivers/thermal/Makefile
> @@ -54,7 +54,7 @@ obj-$(CONFIG_INTEL_BXT_PMIC_THERMAL) +=
> intel_bxt_pmic_thermal.o
> obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o
> obj-$(CONFIG_ST_THERMAL) += st/
> obj-$(CONFIG_QCOM_TSENS) += qcom/
> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra/
> +obj-y += tegra/
> obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
> obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
> obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o
> diff --git a/drivers/thermal/tegra/Kconfig
> b/drivers/thermal/tegra/Kconfig
> index cec586ec7e4b..f8740f7852e3 100644
> --- a/drivers/thermal/tegra/Kconfig
> +++ b/drivers/thermal/tegra/Kconfig
> @@ -10,4 +10,11 @@ config TEGRA_SOCTHERM
> zones to manage temperatures. This option is also required
> for the
> emergency thermal reset (thermtrip) feature to function.
>
> +config TEGRA_BPMP_THERMAL
> + tristate "Tegra BPMP thermal sensing"
> + depends on TEGRA_BPMP || COMPILE_TEST
> + help
> + Enable this option for support for sensing system
> temperature of NVIDIA
> + Tegra systems-on-chip with the BPMP coprocessor (Tegra186).
> +
> endmenu
> diff --git a/drivers/thermal/tegra/Makefile
> b/drivers/thermal/tegra/Makefile
> index 1ce1af2cf0f5..757abcd1feaf 100644
> --- a/drivers/thermal/tegra/Makefile
> +++ b/drivers/thermal/tegra/Makefile
> @@ -1,4 +1,5 @@
> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
> +obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
> +obj-$(CONFIG_TEGRA_BPMP_THERMAL) += bpmp-thermal.o
>
> tegra-soctherm-y := soctherm.o
> soctherm-fuse.o
> tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC) += tegra124-
> soctherm.o
> diff --git a/drivers/thermal/tegra/bpmp-thermal.c
> b/drivers/thermal/tegra/bpmp-thermal.c
> new file mode 100644
> index 000000000000..b0980dbca3b3
> --- /dev/null
> +++ b/drivers/thermal/tegra/bpmp-thermal.c
> @@ -0,0 +1,263 @@
> +/*
> + * Copyright (c) 2015-2017, NVIDIA CORPORATION. All rights
> reserved.
> + *
> + * Author:
> + * Mikko Perttunen <mperttunen@nvidia.com>
> + * Aapo Vienamo <avienamo@nvidia.com>
> + *
> + * This software is licensed under the terms of the GNU General
> Public
> + * License version 2, as published by the Free Software Foundation,
> and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/err.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/thermal.h>
> +#include <linux/workqueue.h>
> +
> +#include <soc/tegra/bpmp.h>
> +#include <soc/tegra/bpmp-abi.h>
> +
> +struct tegra_bpmp_thermal_zone {
> + struct tegra_bpmp_thermal *tegra;
> + struct thermal_zone_device *tzd;
> + struct work_struct tz_device_update_work;
> + unsigned int idx;
> +};
> +
> +struct tegra_bpmp_thermal {
> + struct device *dev;
> + struct tegra_bpmp *bpmp;
> + unsigned int num_zones;
> + struct tegra_bpmp_thermal_zone **zones;
> +};
> +
> +static int tegra_bpmp_thermal_get_temp(void *data, int *out_temp)
> +{
> + struct tegra_bpmp_thermal_zone *zone = data;
> + struct mrq_thermal_host_to_bpmp_request req;
> + union mrq_thermal_bpmp_to_host_response reply;
> + struct tegra_bpmp_message msg;
> + int err;
> +
> + memset(&req, 0, sizeof(req));
> + req.type = CMD_THERMAL_GET_TEMP;
> + req.get_temp.zone = zone->idx;
> +
> + memset(&msg, 0, sizeof(msg));
> + msg.mrq = MRQ_THERMAL;
> + msg.tx.data = &req;
> + msg.tx.size = sizeof(req);
> + msg.rx.data = &reply;
> + msg.rx.size = sizeof(reply);
> +
> + err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
> + if (err)
> + return err;
> +
> + *out_temp = reply.get_temp.temp;
> +
> + return 0;
> +}
> +
> +static int tegra_bpmp_thermal_set_trips(void *data, int low, int
> high)
> +{
> + struct tegra_bpmp_thermal_zone *zone = data;
> + struct mrq_thermal_host_to_bpmp_request req;
> + struct tegra_bpmp_message msg;
> +
> + memset(&req, 0, sizeof(req));
> + req.type = CMD_THERMAL_SET_TRIP;
> + req.set_trip.zone = zone->idx;
> + req.set_trip.enabled = true;
> + req.set_trip.low = low;
> + req.set_trip.high = high;
> +
> + memset(&msg, 0, sizeof(msg));
> + msg.mrq = MRQ_THERMAL;
> + msg.tx.data = &req;
> + msg.tx.size = sizeof(req);
> +
> + return tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
> +}
> +
> +static void tz_device_update_work_fn(struct work_struct *work)
> +{
> + struct tegra_bpmp_thermal_zone *zone;
> +
> + zone = container_of(work, struct tegra_bpmp_thermal_zone,
> + tz_device_update_work);
> +
> + thermal_zone_device_update(zone->tzd,
> THERMAL_TRIP_VIOLATED);
> +}
> +
> +static void bpmp_mrq_thermal(unsigned int mrq, struct
> tegra_bpmp_channel *ch,
> + void *data)
> +{
> + struct mrq_thermal_bpmp_to_host_request *req;
> + struct tegra_bpmp_thermal *tegra = data;
> + int i;
> +
> + req = (struct mrq_thermal_bpmp_to_host_request *)ch->ib-
> >data;
> +
> + if (req->type != CMD_THERMAL_HOST_TRIP_REACHED) {
> + dev_err(tegra->dev, "%s: invalid request type:
> %d\n",
> + __func__, req->type);
> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
> + return;
> + }
> +
> + for (i = 0; i < tegra->num_zones; ++i) {
> + if (tegra->zones[i]->idx != req-
> >host_trip_reached.zone)
> + continue;
> +
> + schedule_work(&tegra->zones[i]-
> >tz_device_update_work);
> + tegra_bpmp_mrq_return(ch, 0, NULL, 0);
> + return;
> + }
> +
> + dev_err(tegra->dev, "%s: invalid thermal zone: %d\n",
> __func__,
> + req->host_trip_reached.zone);
> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
> +}
> +
> +static int tegra_bpmp_thermal_get_num_zones(struct tegra_bpmp *bpmp,
> + int *num_zones)
> +{
> + struct mrq_thermal_host_to_bpmp_request req;
> + union mrq_thermal_bpmp_to_host_response reply;
> + struct tegra_bpmp_message msg;
> + int err;
> +
> + memset(&req, 0, sizeof(req));
> + req.type = CMD_THERMAL_GET_NUM_ZONES;
> +
> + memset(&msg, 0, sizeof(msg));
> + msg.mrq = MRQ_THERMAL;
> + msg.tx.data = &req;
> + msg.tx.size = sizeof(req);
> + msg.rx.data = &reply;
> + msg.rx.size = sizeof(reply);
> +
> + err = tegra_bpmp_transfer(bpmp, &msg);
> + if (err)
> + return err;
> +
> + *num_zones = reply.get_num_zones.num;
> +
> + return 0;
> +}
> +
> +static const struct thermal_zone_of_device_ops
> tegra_bpmp_of_thermal_ops = {
> + .get_temp = tegra_bpmp_thermal_get_temp,
> + .set_trips = tegra_bpmp_thermal_set_trips,
> +};
> +
> +static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
> +{
> + struct tegra_bpmp *bpmp = dev_get_drvdata(pdev->dev.parent);
> + struct tegra_bpmp_thermal *tegra;
> + struct thermal_zone_device *tzd;
> + unsigned int i, max_num_zones;
> + int err;
> +
> + tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra),
> GFP_KERNEL);
> + if (!tegra)
> + return -ENOMEM;
> +
> + tegra->dev = &pdev->dev;
> + tegra->bpmp = bpmp;
> +
> + err = tegra_bpmp_thermal_get_num_zones(bpmp,
> &max_num_zones);
> + if (err) {
> + dev_err(&pdev->dev, "failed to get the number of
> zones: %d\n",
> + err);
> + return err;
> + }
> +
> + tegra->zones = devm_kcalloc(&pdev->dev, max_num_zones,
> + sizeof(*tegra->zones),
> GFP_KERNEL);
> + if (!tegra->zones)
> + return -ENOMEM;
> +
> + for (i = 0; i < max_num_zones; ++i) {
> + struct tegra_bpmp_thermal_zone *zone;
> + int temp;
> +
> + zone = devm_kzalloc(&pdev->dev, sizeof(*zone),
> GFP_KERNEL);
> + if (!zone)
> + return -ENOMEM;
> +
> + zone->idx = i;
> + zone->tegra = tegra;
> +
> + err = tegra_bpmp_thermal_get_temp(zone, &temp);
> + if (err < 0) {
> + devm_kfree(&pdev->dev, zone);
> + continue;
> + }
> +
> + tzd = devm_thermal_zone_of_sensor_register(
> + &pdev->dev, i, zone,
> &tegra_bpmp_of_thermal_ops);
> + if (IS_ERR(tzd)) {
> + if (PTR_ERR(tzd) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> + devm_kfree(&pdev->dev, zone);
> + continue;
> + }
> +
> + zone->tzd = tzd;
> + INIT_WORK(&zone->tz_device_update_work,
> + tz_device_update_work_fn);
> +
> + tegra->zones[tegra->num_zones++] = zone;
> + }
> +
> + err = tegra_bpmp_request_mrq(bpmp, MRQ_THERMAL,
> bpmp_mrq_thermal,
> + tegra);
> + if (err) {
> + dev_err(&pdev->dev, "failed to register mrq handler:
> %d\n",
> + err);
> + return err;
> + }
> +
> + platform_set_drvdata(pdev, tegra);
> +
> + return 0;
> +}
> +
> +static int tegra_bpmp_thermal_remove(struct platform_device *pdev)
> +{
> + struct tegra_bpmp_thermal *tegra =
> platform_get_drvdata(pdev);
> +
> + tegra_bpmp_free_mrq(tegra->bpmp, MRQ_THERMAL, tegra);
> +
> + return 0;
> +}
> +
> +static const struct of_device_id tegra_bpmp_thermal_of_match[] = {
> + { .compatible = "nvidia,tegra186-bpmp-thermal" },
> + { },
> +};
> +MODULE_DEVICE_TABLE(of, tegra_bpmp_thermal_of_match);
> +
> +static struct platform_driver tegra_bpmp_thermal_driver = {
> + .probe = tegra_bpmp_thermal_probe,
> + .remove = tegra_bpmp_thermal_remove,
> + .driver = {
> + .name = "tegra-bpmp-thermal",
> + .of_match_table = tegra_bpmp_thermal_of_match,
> + },
> +};
> +module_platform_driver(tegra_bpmp_thermal_driver);
> +
> +MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
> +MODULE_DESCRIPTION("NVIDIA Tegra BPMP thermal sensor driver");
> +MODULE_LICENSE("GPL v2");
^ permalink raw reply [flat|nested] 36+ messages in thread* [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-08-11 2:57 ` Zhang Rui
0 siblings, 0 replies; 36+ messages in thread
From: Zhang Rui @ 2017-08-11 2:57 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
> an
> interface to thermal sensors on the system-on-chip. This driver
> implements access to the interface. It supports reading the
> temperature, setting trip points and receiving notification of a
> tripped trip point.
>
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Wei Ni,
what do you think of this patch?
thanks,
rui
> ---
> v2:
> - don't allocate space for disabled zones
> - allow compilation with COMPILE_TEST
>
> ?drivers/thermal/Makefile?????????????|???2 +-
> ?drivers/thermal/tegra/Kconfig????????|???7 +
> ?drivers/thermal/tegra/Makefile???????|???3 +-
> ?drivers/thermal/tegra/bpmp-thermal.c | 263
> +++++++++++++++++++++++++++++++++++
> ?4 files changed, 273 insertions(+), 2 deletions(-)
> ?create mode 100644 drivers/thermal/tegra/bpmp-thermal.c
>
> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
> index 094d7039981c..c03dccdba7b8 100644
> --- a/drivers/thermal/Makefile
> +++ b/drivers/thermal/Makefile
> @@ -54,7 +54,7 @@ obj-$(CONFIG_INTEL_BXT_PMIC_THERMAL) +=
> intel_bxt_pmic_thermal.o
> ?obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o
> ?obj-$(CONFIG_ST_THERMAL) += st/
> ?obj-$(CONFIG_QCOM_TSENS) += qcom/
> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra/
> +obj-y += tegra/
> ?obj-$(CONFIG_HISI_THERMAL)?????+= hisi_thermal.o
> ?obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
> ?obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o
> diff --git a/drivers/thermal/tegra/Kconfig
> b/drivers/thermal/tegra/Kconfig
> index cec586ec7e4b..f8740f7852e3 100644
> --- a/drivers/thermal/tegra/Kconfig
> +++ b/drivers/thermal/tegra/Kconfig
> @@ -10,4 +10,11 @@ config TEGRA_SOCTHERM
> ? ??zones to manage temperatures. This option is also required
> for the
> ? ??emergency thermal reset (thermtrip) feature to function.
> ?
> +config TEGRA_BPMP_THERMAL
> + tristate "Tegra BPMP thermal sensing"
> + depends on TEGRA_BPMP || COMPILE_TEST
> + help
> + ?Enable this option for support for sensing system
> temperature of NVIDIA
> + ?Tegra systems-on-chip with the BPMP coprocessor (Tegra186).
> +
> ?endmenu
> diff --git a/drivers/thermal/tegra/Makefile
> b/drivers/thermal/tegra/Makefile
> index 1ce1af2cf0f5..757abcd1feaf 100644
> --- a/drivers/thermal/tegra/Makefile
> +++ b/drivers/thermal/tegra/Makefile
> @@ -1,4 +1,5 @@
> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
> +obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
> +obj-$(CONFIG_TEGRA_BPMP_THERMAL) += bpmp-thermal.o
> ?
> ?tegra-soctherm-y := soctherm.o
> soctherm-fuse.o
> ?tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC) += tegra124-
> soctherm.o
> diff --git a/drivers/thermal/tegra/bpmp-thermal.c
> b/drivers/thermal/tegra/bpmp-thermal.c
> new file mode 100644
> index 000000000000..b0980dbca3b3
> --- /dev/null
> +++ b/drivers/thermal/tegra/bpmp-thermal.c
> @@ -0,0 +1,263 @@
> +/*
> + * Copyright (c) 2015-2017, NVIDIA CORPORATION.??All rights
> reserved.
> + *
> + * Author:
> + * Mikko Perttunen <mperttunen@nvidia.com>
> + * Aapo Vienamo <avienamo@nvidia.com>
> + *
> + * This software is licensed under the terms of the GNU General
> Public
> + * License version 2, as published by the Free Software Foundation,
> and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.??See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/err.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/thermal.h>
> +#include <linux/workqueue.h>
> +
> +#include <soc/tegra/bpmp.h>
> +#include <soc/tegra/bpmp-abi.h>
> +
> +struct tegra_bpmp_thermal_zone {
> + struct tegra_bpmp_thermal *tegra;
> + struct thermal_zone_device *tzd;
> + struct work_struct tz_device_update_work;
> + unsigned int idx;
> +};
> +
> +struct tegra_bpmp_thermal {
> + struct device *dev;
> + struct tegra_bpmp *bpmp;
> + unsigned int num_zones;
> + struct tegra_bpmp_thermal_zone **zones;
> +};
> +
> +static int tegra_bpmp_thermal_get_temp(void *data, int *out_temp)
> +{
> + struct tegra_bpmp_thermal_zone *zone = data;
> + struct mrq_thermal_host_to_bpmp_request req;
> + union mrq_thermal_bpmp_to_host_response reply;
> + struct tegra_bpmp_message msg;
> + int err;
> +
> + memset(&req, 0, sizeof(req));
> + req.type = CMD_THERMAL_GET_TEMP;
> + req.get_temp.zone = zone->idx;
> +
> + memset(&msg, 0, sizeof(msg));
> + msg.mrq = MRQ_THERMAL;
> + msg.tx.data = &req;
> + msg.tx.size = sizeof(req);
> + msg.rx.data = &reply;
> + msg.rx.size = sizeof(reply);
> +
> + err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
> + if (err)
> + return err;
> +
> + *out_temp = reply.get_temp.temp;
> +
> + return 0;
> +}
> +
> +static int tegra_bpmp_thermal_set_trips(void *data, int low, int
> high)
> +{
> + struct tegra_bpmp_thermal_zone *zone = data;
> + struct mrq_thermal_host_to_bpmp_request req;
> + struct tegra_bpmp_message msg;
> +
> + memset(&req, 0, sizeof(req));
> + req.type = CMD_THERMAL_SET_TRIP;
> + req.set_trip.zone = zone->idx;
> + req.set_trip.enabled = true;
> + req.set_trip.low = low;
> + req.set_trip.high = high;
> +
> + memset(&msg, 0, sizeof(msg));
> + msg.mrq = MRQ_THERMAL;
> + msg.tx.data = &req;
> + msg.tx.size = sizeof(req);
> +
> + return tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
> +}
> +
> +static void tz_device_update_work_fn(struct work_struct *work)
> +{
> + struct tegra_bpmp_thermal_zone *zone;
> +
> + zone = container_of(work, struct tegra_bpmp_thermal_zone,
> + ????tz_device_update_work);
> +
> + thermal_zone_device_update(zone->tzd,
> THERMAL_TRIP_VIOLATED);
> +}
> +
> +static void bpmp_mrq_thermal(unsigned int mrq, struct
> tegra_bpmp_channel *ch,
> + ?????void *data)
> +{
> + struct mrq_thermal_bpmp_to_host_request *req;
> + struct tegra_bpmp_thermal *tegra = data;
> + int i;
> +
> + req = (struct mrq_thermal_bpmp_to_host_request *)ch->ib-
> >data;
> +
> + if (req->type != CMD_THERMAL_HOST_TRIP_REACHED) {
> + dev_err(tegra->dev, "%s: invalid request type:
> %d\n",
> + __func__, req->type);
> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
> + return;
> + }
> +
> + for (i = 0; i < tegra->num_zones; ++i) {
> + if (tegra->zones[i]->idx != req-
> >host_trip_reached.zone)
> + continue;
> +
> + schedule_work(&tegra->zones[i]-
> >tz_device_update_work);
> + tegra_bpmp_mrq_return(ch, 0, NULL, 0);
> + return;
> + }
> +
> + dev_err(tegra->dev, "%s: invalid thermal zone: %d\n",
> __func__,
> + req->host_trip_reached.zone);
> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
> +}
> +
> +static int tegra_bpmp_thermal_get_num_zones(struct tegra_bpmp *bpmp,
> + ????int *num_zones)
> +{
> + struct mrq_thermal_host_to_bpmp_request req;
> + union mrq_thermal_bpmp_to_host_response reply;
> + struct tegra_bpmp_message msg;
> + int err;
> +
> + memset(&req, 0, sizeof(req));
> + req.type = CMD_THERMAL_GET_NUM_ZONES;
> +
> + memset(&msg, 0, sizeof(msg));
> + msg.mrq = MRQ_THERMAL;
> + msg.tx.data = &req;
> + msg.tx.size = sizeof(req);
> + msg.rx.data = &reply;
> + msg.rx.size = sizeof(reply);
> +
> + err = tegra_bpmp_transfer(bpmp, &msg);
> + if (err)
> + return err;
> +
> + *num_zones = reply.get_num_zones.num;
> +
> + return 0;
> +}
> +
> +static const struct thermal_zone_of_device_ops
> tegra_bpmp_of_thermal_ops = {
> + .get_temp = tegra_bpmp_thermal_get_temp,
> + .set_trips = tegra_bpmp_thermal_set_trips,
> +};
> +
> +static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
> +{
> + struct tegra_bpmp *bpmp = dev_get_drvdata(pdev->dev.parent);
> + struct tegra_bpmp_thermal *tegra;
> + struct thermal_zone_device *tzd;
> + unsigned int i, max_num_zones;
> + int err;
> +
> + tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra),
> GFP_KERNEL);
> + if (!tegra)
> + return -ENOMEM;
> +
> + tegra->dev = &pdev->dev;
> + tegra->bpmp = bpmp;
> +
> + err = tegra_bpmp_thermal_get_num_zones(bpmp,
> &max_num_zones);
> + if (err) {
> + dev_err(&pdev->dev, "failed to get the number of
> zones: %d\n",
> + err);
> + return err;
> + }
> +
> + tegra->zones = devm_kcalloc(&pdev->dev, max_num_zones,
> + ????sizeof(*tegra->zones),
> GFP_KERNEL);
> + if (!tegra->zones)
> + return -ENOMEM;
> +
> + for (i = 0; i < max_num_zones; ++i) {
> + struct tegra_bpmp_thermal_zone *zone;
> + int temp;
> +
> + zone = devm_kzalloc(&pdev->dev, sizeof(*zone),
> GFP_KERNEL);
> + if (!zone)
> + return -ENOMEM;
> +
> + zone->idx = i;
> + zone->tegra = tegra;
> +
> + err = tegra_bpmp_thermal_get_temp(zone, &temp);
> + if (err < 0) {
> + devm_kfree(&pdev->dev, zone);
> + continue;
> + }
> +
> + tzd = devm_thermal_zone_of_sensor_register(
> + &pdev->dev, i, zone,
> &tegra_bpmp_of_thermal_ops);
> + if (IS_ERR(tzd)) {
> + if (PTR_ERR(tzd) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> + devm_kfree(&pdev->dev, zone);
> + continue;
> + }
> +
> + zone->tzd = tzd;
> + INIT_WORK(&zone->tz_device_update_work,
> + ??tz_device_update_work_fn);
> +
> + tegra->zones[tegra->num_zones++] = zone;
> + }
> +
> + err = tegra_bpmp_request_mrq(bpmp, MRQ_THERMAL,
> bpmp_mrq_thermal,
> + ?????tegra);
> + if (err) {
> + dev_err(&pdev->dev, "failed to register mrq handler:
> %d\n",
> + err);
> + return err;
> + }
> +
> + platform_set_drvdata(pdev, tegra);
> +
> + return 0;
> +}
> +
> +static int tegra_bpmp_thermal_remove(struct platform_device *pdev)
> +{
> + struct tegra_bpmp_thermal *tegra =
> platform_get_drvdata(pdev);
> +
> + tegra_bpmp_free_mrq(tegra->bpmp, MRQ_THERMAL, tegra);
> +
> + return 0;
> +}
> +
> +static const struct of_device_id tegra_bpmp_thermal_of_match[] = {
> + { .compatible = "nvidia,tegra186-bpmp-thermal" },
> + { },
> +};
> +MODULE_DEVICE_TABLE(of, tegra_bpmp_thermal_of_match);
> +
> +static struct platform_driver tegra_bpmp_thermal_driver = {
> + .probe = tegra_bpmp_thermal_probe,
> + .remove = tegra_bpmp_thermal_remove,
> + .driver = {
> + .name = "tegra-bpmp-thermal",
> + .of_match_table = tegra_bpmp_thermal_of_match,
> + },
> +};
> +module_platform_driver(tegra_bpmp_thermal_driver);
> +
> +MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
> +MODULE_DESCRIPTION("NVIDIA Tegra BPMP thermal sensor driver");
> +MODULE_LICENSE("GPL v2");
^ permalink raw reply [flat|nested] 36+ messages in thread* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
2017-08-11 2:57 ` Zhang Rui
(?)
@ 2017-08-21 2:40 ` Wei Ni
-1 siblings, 0 replies; 36+ messages in thread
From: Wei Ni @ 2017-08-21 2:40 UTC (permalink / raw)
To: Zhang Rui, Mikko Perttunen, edubezval, thierry.reding, jonathanh
Cc: linux-tegra, linux-kernel, linux-arm-kernel, linux-pm
On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
>> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
>> an
>> interface to thermal sensors on the system-on-chip. This driver
>> implements access to the interface. It supports reading the
>> temperature, setting trip points and receiving notification of a
>> tripped trip point.
>>
>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>
> Wei Ni,
>
> what do you think of this patch?
Reviewed this patch, it looked fine to me.
>
> thanks,
> rui
>> ---
>> v2:
>> - don't allocate space for disabled zones
>> - allow compilation with COMPILE_TEST
>>
>> drivers/thermal/Makefile | 2 +-
>> drivers/thermal/tegra/Kconfig | 7 +
>> drivers/thermal/tegra/Makefile | 3 +-
>> drivers/thermal/tegra/bpmp-thermal.c | 263
>> +++++++++++++++++++++++++++++++++++
>> 4 files changed, 273 insertions(+), 2 deletions(-)
>> create mode 100644 drivers/thermal/tegra/bpmp-thermal.c
>>
>> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
>> index 094d7039981c..c03dccdba7b8 100644
>> --- a/drivers/thermal/Makefile
>> +++ b/drivers/thermal/Makefile
>> @@ -54,7 +54,7 @@ obj-$(CONFIG_INTEL_BXT_PMIC_THERMAL) +=
>> intel_bxt_pmic_thermal.o
>> obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o
>> obj-$(CONFIG_ST_THERMAL) += st/
>> obj-$(CONFIG_QCOM_TSENS) += qcom/
>> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra/
>> +obj-y += tegra/
>> obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
>> obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
>> obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o
>> diff --git a/drivers/thermal/tegra/Kconfig
>> b/drivers/thermal/tegra/Kconfig
>> index cec586ec7e4b..f8740f7852e3 100644
>> --- a/drivers/thermal/tegra/Kconfig
>> +++ b/drivers/thermal/tegra/Kconfig
>> @@ -10,4 +10,11 @@ config TEGRA_SOCTHERM
>> zones to manage temperatures. This option is also required
>> for the
>> emergency thermal reset (thermtrip) feature to function.
>>
>> +config TEGRA_BPMP_THERMAL
>> + tristate "Tegra BPMP thermal sensing"
>> + depends on TEGRA_BPMP || COMPILE_TEST
>> + help
>> + Enable this option for support for sensing system
>> temperature of NVIDIA
>> + Tegra systems-on-chip with the BPMP coprocessor (Tegra186).
>> +
>> endmenu
>> diff --git a/drivers/thermal/tegra/Makefile
>> b/drivers/thermal/tegra/Makefile
>> index 1ce1af2cf0f5..757abcd1feaf 100644
>> --- a/drivers/thermal/tegra/Makefile
>> +++ b/drivers/thermal/tegra/Makefile
>> @@ -1,4 +1,5 @@
>> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
>> +obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
>> +obj-$(CONFIG_TEGRA_BPMP_THERMAL) += bpmp-thermal.o
>>
>> tegra-soctherm-y := soctherm.o
>> soctherm-fuse.o
>> tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC) += tegra124-
>> soctherm.o
>> diff --git a/drivers/thermal/tegra/bpmp-thermal.c
>> b/drivers/thermal/tegra/bpmp-thermal.c
>> new file mode 100644
>> index 000000000000..b0980dbca3b3
>> --- /dev/null
>> +++ b/drivers/thermal/tegra/bpmp-thermal.c
>> @@ -0,0 +1,263 @@
>> +/*
>> + * Copyright (c) 2015-2017, NVIDIA CORPORATION. All rights
>> reserved.
>> + *
>> + * Author:
>> + * Mikko Perttunen <mperttunen@nvidia.com>
>> + * Aapo Vienamo <avienamo@nvidia.com>
>> + *
>> + * This software is licensed under the terms of the GNU General
>> Public
>> + * License version 2, as published by the Free Software Foundation,
>> and
>> + * may be copied, distributed, and modified under those terms.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + */
>> +
>> +#include <linux/err.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/thermal.h>
>> +#include <linux/workqueue.h>
>> +
>> +#include <soc/tegra/bpmp.h>
>> +#include <soc/tegra/bpmp-abi.h>
>> +
>> +struct tegra_bpmp_thermal_zone {
>> + struct tegra_bpmp_thermal *tegra;
>> + struct thermal_zone_device *tzd;
>> + struct work_struct tz_device_update_work;
>> + unsigned int idx;
>> +};
>> +
>> +struct tegra_bpmp_thermal {
>> + struct device *dev;
>> + struct tegra_bpmp *bpmp;
>> + unsigned int num_zones;
>> + struct tegra_bpmp_thermal_zone **zones;
>> +};
>> +
>> +static int tegra_bpmp_thermal_get_temp(void *data, int *out_temp)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone = data;
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + union mrq_thermal_bpmp_to_host_response reply;
>> + struct tegra_bpmp_message msg;
>> + int err;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_GET_TEMP;
>> + req.get_temp.zone = zone->idx;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> + msg.rx.data = &reply;
>> + msg.rx.size = sizeof(reply);
>> +
>> + err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
>> + if (err)
>> + return err;
>> +
>> + *out_temp = reply.get_temp.temp;
>> +
>> + return 0;
>> +}
>> +
>> +static int tegra_bpmp_thermal_set_trips(void *data, int low, int
>> high)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone = data;
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + struct tegra_bpmp_message msg;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_SET_TRIP;
>> + req.set_trip.zone = zone->idx;
>> + req.set_trip.enabled = true;
>> + req.set_trip.low = low;
>> + req.set_trip.high = high;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> +
>> + return tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
>> +}
>> +
>> +static void tz_device_update_work_fn(struct work_struct *work)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone;
>> +
>> + zone = container_of(work, struct tegra_bpmp_thermal_zone,
>> + tz_device_update_work);
>> +
>> + thermal_zone_device_update(zone->tzd,
>> THERMAL_TRIP_VIOLATED);
>> +}
>> +
>> +static void bpmp_mrq_thermal(unsigned int mrq, struct
>> tegra_bpmp_channel *ch,
>> + void *data)
>> +{
>> + struct mrq_thermal_bpmp_to_host_request *req;
>> + struct tegra_bpmp_thermal *tegra = data;
>> + int i;
>> +
>> + req = (struct mrq_thermal_bpmp_to_host_request *)ch->ib-
>>> data;
>> +
>> + if (req->type != CMD_THERMAL_HOST_TRIP_REACHED) {
>> + dev_err(tegra->dev, "%s: invalid request type:
>> %d\n",
>> + __func__, req->type);
>> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
>> + return;
>> + }
>> +
>> + for (i = 0; i < tegra->num_zones; ++i) {
>> + if (tegra->zones[i]->idx != req-
>>> host_trip_reached.zone)
>> + continue;
>> +
>> + schedule_work(&tegra->zones[i]-
>>> tz_device_update_work);
>> + tegra_bpmp_mrq_return(ch, 0, NULL, 0);
>> + return;
>> + }
>> +
>> + dev_err(tegra->dev, "%s: invalid thermal zone: %d\n",
>> __func__,
>> + req->host_trip_reached.zone);
>> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
>> +}
>> +
>> +static int tegra_bpmp_thermal_get_num_zones(struct tegra_bpmp *bpmp,
>> + int *num_zones)
>> +{
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + union mrq_thermal_bpmp_to_host_response reply;
>> + struct tegra_bpmp_message msg;
>> + int err;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_GET_NUM_ZONES;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> + msg.rx.data = &reply;
>> + msg.rx.size = sizeof(reply);
>> +
>> + err = tegra_bpmp_transfer(bpmp, &msg);
>> + if (err)
>> + return err;
>> +
>> + *num_zones = reply.get_num_zones.num;
>> +
>> + return 0;
>> +}
>> +
>> +static const struct thermal_zone_of_device_ops
>> tegra_bpmp_of_thermal_ops = {
>> + .get_temp = tegra_bpmp_thermal_get_temp,
>> + .set_trips = tegra_bpmp_thermal_set_trips,
>> +};
>> +
>> +static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
>> +{
>> + struct tegra_bpmp *bpmp = dev_get_drvdata(pdev->dev.parent);
>> + struct tegra_bpmp_thermal *tegra;
>> + struct thermal_zone_device *tzd;
>> + unsigned int i, max_num_zones;
>> + int err;
>> +
>> + tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra),
>> GFP_KERNEL);
>> + if (!tegra)
>> + return -ENOMEM;
>> +
>> + tegra->dev = &pdev->dev;
>> + tegra->bpmp = bpmp;
>> +
>> + err = tegra_bpmp_thermal_get_num_zones(bpmp,
>> &max_num_zones);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to get the number of
>> zones: %d\n",
>> + err);
>> + return err;
>> + }
>> +
>> + tegra->zones = devm_kcalloc(&pdev->dev, max_num_zones,
>> + sizeof(*tegra->zones),
>> GFP_KERNEL);
>> + if (!tegra->zones)
>> + return -ENOMEM;
>> +
>> + for (i = 0; i < max_num_zones; ++i) {
>> + struct tegra_bpmp_thermal_zone *zone;
>> + int temp;
>> +
>> + zone = devm_kzalloc(&pdev->dev, sizeof(*zone),
>> GFP_KERNEL);
>> + if (!zone)
>> + return -ENOMEM;
>> +
>> + zone->idx = i;
>> + zone->tegra = tegra;
>> +
>> + err = tegra_bpmp_thermal_get_temp(zone, &temp);
>> + if (err < 0) {
>> + devm_kfree(&pdev->dev, zone);
>> + continue;
>> + }
>> +
>> + tzd = devm_thermal_zone_of_sensor_register(
>> + &pdev->dev, i, zone,
>> &tegra_bpmp_of_thermal_ops);
>> + if (IS_ERR(tzd)) {
>> + if (PTR_ERR(tzd) == -EPROBE_DEFER)
>> + return -EPROBE_DEFER;
>> + devm_kfree(&pdev->dev, zone);
>> + continue;
>> + }
>> +
>> + zone->tzd = tzd;
>> + INIT_WORK(&zone->tz_device_update_work,
>> + tz_device_update_work_fn);
>> +
>> + tegra->zones[tegra->num_zones++] = zone;
>> + }
>> +
>> + err = tegra_bpmp_request_mrq(bpmp, MRQ_THERMAL,
>> bpmp_mrq_thermal,
>> + tegra);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to register mrq handler:
>> %d\n",
>> + err);
>> + return err;
>> + }
>> +
>> + platform_set_drvdata(pdev, tegra);
>> +
>> + return 0;
>> +}
>> +
>> +static int tegra_bpmp_thermal_remove(struct platform_device *pdev)
>> +{
>> + struct tegra_bpmp_thermal *tegra =
>> platform_get_drvdata(pdev);
>> +
>> + tegra_bpmp_free_mrq(tegra->bpmp, MRQ_THERMAL, tegra);
>> +
>> + return 0;
>> +}
>> +
>> +static const struct of_device_id tegra_bpmp_thermal_of_match[] = {
>> + { .compatible = "nvidia,tegra186-bpmp-thermal" },
>> + { },
>> +};
>> +MODULE_DEVICE_TABLE(of, tegra_bpmp_thermal_of_match);
>> +
>> +static struct platform_driver tegra_bpmp_thermal_driver = {
>> + .probe = tegra_bpmp_thermal_probe,
>> + .remove = tegra_bpmp_thermal_remove,
>> + .driver = {
>> + .name = "tegra-bpmp-thermal",
>> + .of_match_table = tegra_bpmp_thermal_of_match,
>> + },
>> +};
>> +module_platform_driver(tegra_bpmp_thermal_driver);
>> +
>> +MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
>> +MODULE_DESCRIPTION("NVIDIA Tegra BPMP thermal sensor driver");
>> +MODULE_LICENSE("GPL v2");
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
^ permalink raw reply [flat|nested] 36+ messages in thread* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-08-21 2:40 ` Wei Ni
0 siblings, 0 replies; 36+ messages in thread
From: Wei Ni @ 2017-08-21 2:40 UTC (permalink / raw)
To: Zhang Rui, Mikko Perttunen, edubezval, thierry.reding, jonathanh
Cc: linux-tegra, linux-kernel, linux-arm-kernel, linux-pm
On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
>> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
>> an
>> interface to thermal sensors on the system-on-chip. This driver
>> implements access to the interface. It supports reading the
>> temperature, setting trip points and receiving notification of a
>> tripped trip point.
>>
>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>
> Wei Ni,
>
> what do you think of this patch?
Reviewed this patch, it looked fine to me.
>
> thanks,
> rui
>> ---
>> v2:
>> - don't allocate space for disabled zones
>> - allow compilation with COMPILE_TEST
>>
>> drivers/thermal/Makefile | 2 +-
>> drivers/thermal/tegra/Kconfig | 7 +
>> drivers/thermal/tegra/Makefile | 3 +-
>> drivers/thermal/tegra/bpmp-thermal.c | 263
>> +++++++++++++++++++++++++++++++++++
>> 4 files changed, 273 insertions(+), 2 deletions(-)
>> create mode 100644 drivers/thermal/tegra/bpmp-thermal.c
>>
>> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
>> index 094d7039981c..c03dccdba7b8 100644
>> --- a/drivers/thermal/Makefile
>> +++ b/drivers/thermal/Makefile
>> @@ -54,7 +54,7 @@ obj-$(CONFIG_INTEL_BXT_PMIC_THERMAL) +=
>> intel_bxt_pmic_thermal.o
>> obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o
>> obj-$(CONFIG_ST_THERMAL) += st/
>> obj-$(CONFIG_QCOM_TSENS) += qcom/
>> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra/
>> +obj-y += tegra/
>> obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
>> obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
>> obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o
>> diff --git a/drivers/thermal/tegra/Kconfig
>> b/drivers/thermal/tegra/Kconfig
>> index cec586ec7e4b..f8740f7852e3 100644
>> --- a/drivers/thermal/tegra/Kconfig
>> +++ b/drivers/thermal/tegra/Kconfig
>> @@ -10,4 +10,11 @@ config TEGRA_SOCTHERM
>> zones to manage temperatures. This option is also required
>> for the
>> emergency thermal reset (thermtrip) feature to function.
>>
>> +config TEGRA_BPMP_THERMAL
>> + tristate "Tegra BPMP thermal sensing"
>> + depends on TEGRA_BPMP || COMPILE_TEST
>> + help
>> + Enable this option for support for sensing system
>> temperature of NVIDIA
>> + Tegra systems-on-chip with the BPMP coprocessor (Tegra186).
>> +
>> endmenu
>> diff --git a/drivers/thermal/tegra/Makefile
>> b/drivers/thermal/tegra/Makefile
>> index 1ce1af2cf0f5..757abcd1feaf 100644
>> --- a/drivers/thermal/tegra/Makefile
>> +++ b/drivers/thermal/tegra/Makefile
>> @@ -1,4 +1,5 @@
>> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
>> +obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
>> +obj-$(CONFIG_TEGRA_BPMP_THERMAL) += bpmp-thermal.o
>>
>> tegra-soctherm-y := soctherm.o
>> soctherm-fuse.o
>> tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC) += tegra124-
>> soctherm.o
>> diff --git a/drivers/thermal/tegra/bpmp-thermal.c
>> b/drivers/thermal/tegra/bpmp-thermal.c
>> new file mode 100644
>> index 000000000000..b0980dbca3b3
>> --- /dev/null
>> +++ b/drivers/thermal/tegra/bpmp-thermal.c
>> @@ -0,0 +1,263 @@
>> +/*
>> + * Copyright (c) 2015-2017, NVIDIA CORPORATION. All rights
>> reserved.
>> + *
>> + * Author:
>> + * Mikko Perttunen <mperttunen@nvidia.com>
>> + * Aapo Vienamo <avienamo@nvidia.com>
>> + *
>> + * This software is licensed under the terms of the GNU General
>> Public
>> + * License version 2, as published by the Free Software Foundation,
>> and
>> + * may be copied, distributed, and modified under those terms.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + */
>> +
>> +#include <linux/err.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/thermal.h>
>> +#include <linux/workqueue.h>
>> +
>> +#include <soc/tegra/bpmp.h>
>> +#include <soc/tegra/bpmp-abi.h>
>> +
>> +struct tegra_bpmp_thermal_zone {
>> + struct tegra_bpmp_thermal *tegra;
>> + struct thermal_zone_device *tzd;
>> + struct work_struct tz_device_update_work;
>> + unsigned int idx;
>> +};
>> +
>> +struct tegra_bpmp_thermal {
>> + struct device *dev;
>> + struct tegra_bpmp *bpmp;
>> + unsigned int num_zones;
>> + struct tegra_bpmp_thermal_zone **zones;
>> +};
>> +
>> +static int tegra_bpmp_thermal_get_temp(void *data, int *out_temp)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone = data;
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + union mrq_thermal_bpmp_to_host_response reply;
>> + struct tegra_bpmp_message msg;
>> + int err;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_GET_TEMP;
>> + req.get_temp.zone = zone->idx;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> + msg.rx.data = &reply;
>> + msg.rx.size = sizeof(reply);
>> +
>> + err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
>> + if (err)
>> + return err;
>> +
>> + *out_temp = reply.get_temp.temp;
>> +
>> + return 0;
>> +}
>> +
>> +static int tegra_bpmp_thermal_set_trips(void *data, int low, int
>> high)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone = data;
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + struct tegra_bpmp_message msg;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_SET_TRIP;
>> + req.set_trip.zone = zone->idx;
>> + req.set_trip.enabled = true;
>> + req.set_trip.low = low;
>> + req.set_trip.high = high;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> +
>> + return tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
>> +}
>> +
>> +static void tz_device_update_work_fn(struct work_struct *work)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone;
>> +
>> + zone = container_of(work, struct tegra_bpmp_thermal_zone,
>> + tz_device_update_work);
>> +
>> + thermal_zone_device_update(zone->tzd,
>> THERMAL_TRIP_VIOLATED);
>> +}
>> +
>> +static void bpmp_mrq_thermal(unsigned int mrq, struct
>> tegra_bpmp_channel *ch,
>> + void *data)
>> +{
>> + struct mrq_thermal_bpmp_to_host_request *req;
>> + struct tegra_bpmp_thermal *tegra = data;
>> + int i;
>> +
>> + req = (struct mrq_thermal_bpmp_to_host_request *)ch->ib-
>>> data;
>> +
>> + if (req->type != CMD_THERMAL_HOST_TRIP_REACHED) {
>> + dev_err(tegra->dev, "%s: invalid request type:
>> %d\n",
>> + __func__, req->type);
>> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
>> + return;
>> + }
>> +
>> + for (i = 0; i < tegra->num_zones; ++i) {
>> + if (tegra->zones[i]->idx != req-
>>> host_trip_reached.zone)
>> + continue;
>> +
>> + schedule_work(&tegra->zones[i]-
>>> tz_device_update_work);
>> + tegra_bpmp_mrq_return(ch, 0, NULL, 0);
>> + return;
>> + }
>> +
>> + dev_err(tegra->dev, "%s: invalid thermal zone: %d\n",
>> __func__,
>> + req->host_trip_reached.zone);
>> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
>> +}
>> +
>> +static int tegra_bpmp_thermal_get_num_zones(struct tegra_bpmp *bpmp,
>> + int *num_zones)
>> +{
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + union mrq_thermal_bpmp_to_host_response reply;
>> + struct tegra_bpmp_message msg;
>> + int err;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_GET_NUM_ZONES;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> + msg.rx.data = &reply;
>> + msg.rx.size = sizeof(reply);
>> +
>> + err = tegra_bpmp_transfer(bpmp, &msg);
>> + if (err)
>> + return err;
>> +
>> + *num_zones = reply.get_num_zones.num;
>> +
>> + return 0;
>> +}
>> +
>> +static const struct thermal_zone_of_device_ops
>> tegra_bpmp_of_thermal_ops = {
>> + .get_temp = tegra_bpmp_thermal_get_temp,
>> + .set_trips = tegra_bpmp_thermal_set_trips,
>> +};
>> +
>> +static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
>> +{
>> + struct tegra_bpmp *bpmp = dev_get_drvdata(pdev->dev.parent);
>> + struct tegra_bpmp_thermal *tegra;
>> + struct thermal_zone_device *tzd;
>> + unsigned int i, max_num_zones;
>> + int err;
>> +
>> + tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra),
>> GFP_KERNEL);
>> + if (!tegra)
>> + return -ENOMEM;
>> +
>> + tegra->dev = &pdev->dev;
>> + tegra->bpmp = bpmp;
>> +
>> + err = tegra_bpmp_thermal_get_num_zones(bpmp,
>> &max_num_zones);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to get the number of
>> zones: %d\n",
>> + err);
>> + return err;
>> + }
>> +
>> + tegra->zones = devm_kcalloc(&pdev->dev, max_num_zones,
>> + sizeof(*tegra->zones),
>> GFP_KERNEL);
>> + if (!tegra->zones)
>> + return -ENOMEM;
>> +
>> + for (i = 0; i < max_num_zones; ++i) {
>> + struct tegra_bpmp_thermal_zone *zone;
>> + int temp;
>> +
>> + zone = devm_kzalloc(&pdev->dev, sizeof(*zone),
>> GFP_KERNEL);
>> + if (!zone)
>> + return -ENOMEM;
>> +
>> + zone->idx = i;
>> + zone->tegra = tegra;
>> +
>> + err = tegra_bpmp_thermal_get_temp(zone, &temp);
>> + if (err < 0) {
>> + devm_kfree(&pdev->dev, zone);
>> + continue;
>> + }
>> +
>> + tzd = devm_thermal_zone_of_sensor_register(
>> + &pdev->dev, i, zone,
>> &tegra_bpmp_of_thermal_ops);
>> + if (IS_ERR(tzd)) {
>> + if (PTR_ERR(tzd) == -EPROBE_DEFER)
>> + return -EPROBE_DEFER;
>> + devm_kfree(&pdev->dev, zone);
>> + continue;
>> + }
>> +
>> + zone->tzd = tzd;
>> + INIT_WORK(&zone->tz_device_update_work,
>> + tz_device_update_work_fn);
>> +
>> + tegra->zones[tegra->num_zones++] = zone;
>> + }
>> +
>> + err = tegra_bpmp_request_mrq(bpmp, MRQ_THERMAL,
>> bpmp_mrq_thermal,
>> + tegra);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to register mrq handler:
>> %d\n",
>> + err);
>> + return err;
>> + }
>> +
>> + platform_set_drvdata(pdev, tegra);
>> +
>> + return 0;
>> +}
>> +
>> +static int tegra_bpmp_thermal_remove(struct platform_device *pdev)
>> +{
>> + struct tegra_bpmp_thermal *tegra =
>> platform_get_drvdata(pdev);
>> +
>> + tegra_bpmp_free_mrq(tegra->bpmp, MRQ_THERMAL, tegra);
>> +
>> + return 0;
>> +}
>> +
>> +static const struct of_device_id tegra_bpmp_thermal_of_match[] = {
>> + { .compatible = "nvidia,tegra186-bpmp-thermal" },
>> + { },
>> +};
>> +MODULE_DEVICE_TABLE(of, tegra_bpmp_thermal_of_match);
>> +
>> +static struct platform_driver tegra_bpmp_thermal_driver = {
>> + .probe = tegra_bpmp_thermal_probe,
>> + .remove = tegra_bpmp_thermal_remove,
>> + .driver = {
>> + .name = "tegra-bpmp-thermal",
>> + .of_match_table = tegra_bpmp_thermal_of_match,
>> + },
>> +};
>> +module_platform_driver(tegra_bpmp_thermal_driver);
>> +
>> +MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
>> +MODULE_DESCRIPTION("NVIDIA Tegra BPMP thermal sensor driver");
>> +MODULE_LICENSE("GPL v2");
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
^ permalink raw reply [flat|nested] 36+ messages in thread* [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-08-21 2:40 ` Wei Ni
0 siblings, 0 replies; 36+ messages in thread
From: Wei Ni @ 2017-08-21 2:40 UTC (permalink / raw)
To: linux-arm-kernel
On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
>> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
>> an
>> interface to thermal sensors on the system-on-chip. This driver
>> implements access to the interface. It supports reading the
>> temperature, setting trip points and receiving notification of a
>> tripped trip point.
>>
>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>
> Wei Ni,
>
> what do you think of this patch?
Reviewed this patch, it looked fine to me.
>
> thanks,
> rui
>> ---
>> v2:
>> - don't allocate space for disabled zones
>> - allow compilation with COMPILE_TEST
>>
>> drivers/thermal/Makefile | 2 +-
>> drivers/thermal/tegra/Kconfig | 7 +
>> drivers/thermal/tegra/Makefile | 3 +-
>> drivers/thermal/tegra/bpmp-thermal.c | 263
>> +++++++++++++++++++++++++++++++++++
>> 4 files changed, 273 insertions(+), 2 deletions(-)
>> create mode 100644 drivers/thermal/tegra/bpmp-thermal.c
>>
>> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
>> index 094d7039981c..c03dccdba7b8 100644
>> --- a/drivers/thermal/Makefile
>> +++ b/drivers/thermal/Makefile
>> @@ -54,7 +54,7 @@ obj-$(CONFIG_INTEL_BXT_PMIC_THERMAL) +=
>> intel_bxt_pmic_thermal.o
>> obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o
>> obj-$(CONFIG_ST_THERMAL) += st/
>> obj-$(CONFIG_QCOM_TSENS) += qcom/
>> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra/
>> +obj-y += tegra/
>> obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
>> obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
>> obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o
>> diff --git a/drivers/thermal/tegra/Kconfig
>> b/drivers/thermal/tegra/Kconfig
>> index cec586ec7e4b..f8740f7852e3 100644
>> --- a/drivers/thermal/tegra/Kconfig
>> +++ b/drivers/thermal/tegra/Kconfig
>> @@ -10,4 +10,11 @@ config TEGRA_SOCTHERM
>> zones to manage temperatures. This option is also required
>> for the
>> emergency thermal reset (thermtrip) feature to function.
>>
>> +config TEGRA_BPMP_THERMAL
>> + tristate "Tegra BPMP thermal sensing"
>> + depends on TEGRA_BPMP || COMPILE_TEST
>> + help
>> + Enable this option for support for sensing system
>> temperature of NVIDIA
>> + Tegra systems-on-chip with the BPMP coprocessor (Tegra186).
>> +
>> endmenu
>> diff --git a/drivers/thermal/tegra/Makefile
>> b/drivers/thermal/tegra/Makefile
>> index 1ce1af2cf0f5..757abcd1feaf 100644
>> --- a/drivers/thermal/tegra/Makefile
>> +++ b/drivers/thermal/tegra/Makefile
>> @@ -1,4 +1,5 @@
>> -obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
>> +obj-$(CONFIG_TEGRA_SOCTHERM) += tegra-soctherm.o
>> +obj-$(CONFIG_TEGRA_BPMP_THERMAL) += bpmp-thermal.o
>>
>> tegra-soctherm-y := soctherm.o
>> soctherm-fuse.o
>> tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC) += tegra124-
>> soctherm.o
>> diff --git a/drivers/thermal/tegra/bpmp-thermal.c
>> b/drivers/thermal/tegra/bpmp-thermal.c
>> new file mode 100644
>> index 000000000000..b0980dbca3b3
>> --- /dev/null
>> +++ b/drivers/thermal/tegra/bpmp-thermal.c
>> @@ -0,0 +1,263 @@
>> +/*
>> + * Copyright (c) 2015-2017, NVIDIA CORPORATION. All rights
>> reserved.
>> + *
>> + * Author:
>> + * Mikko Perttunen <mperttunen@nvidia.com>
>> + * Aapo Vienamo <avienamo@nvidia.com>
>> + *
>> + * This software is licensed under the terms of the GNU General
>> Public
>> + * License version 2, as published by the Free Software Foundation,
>> and
>> + * may be copied, distributed, and modified under those terms.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + */
>> +
>> +#include <linux/err.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/thermal.h>
>> +#include <linux/workqueue.h>
>> +
>> +#include <soc/tegra/bpmp.h>
>> +#include <soc/tegra/bpmp-abi.h>
>> +
>> +struct tegra_bpmp_thermal_zone {
>> + struct tegra_bpmp_thermal *tegra;
>> + struct thermal_zone_device *tzd;
>> + struct work_struct tz_device_update_work;
>> + unsigned int idx;
>> +};
>> +
>> +struct tegra_bpmp_thermal {
>> + struct device *dev;
>> + struct tegra_bpmp *bpmp;
>> + unsigned int num_zones;
>> + struct tegra_bpmp_thermal_zone **zones;
>> +};
>> +
>> +static int tegra_bpmp_thermal_get_temp(void *data, int *out_temp)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone = data;
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + union mrq_thermal_bpmp_to_host_response reply;
>> + struct tegra_bpmp_message msg;
>> + int err;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_GET_TEMP;
>> + req.get_temp.zone = zone->idx;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> + msg.rx.data = &reply;
>> + msg.rx.size = sizeof(reply);
>> +
>> + err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
>> + if (err)
>> + return err;
>> +
>> + *out_temp = reply.get_temp.temp;
>> +
>> + return 0;
>> +}
>> +
>> +static int tegra_bpmp_thermal_set_trips(void *data, int low, int
>> high)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone = data;
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + struct tegra_bpmp_message msg;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_SET_TRIP;
>> + req.set_trip.zone = zone->idx;
>> + req.set_trip.enabled = true;
>> + req.set_trip.low = low;
>> + req.set_trip.high = high;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> +
>> + return tegra_bpmp_transfer(zone->tegra->bpmp, &msg);
>> +}
>> +
>> +static void tz_device_update_work_fn(struct work_struct *work)
>> +{
>> + struct tegra_bpmp_thermal_zone *zone;
>> +
>> + zone = container_of(work, struct tegra_bpmp_thermal_zone,
>> + tz_device_update_work);
>> +
>> + thermal_zone_device_update(zone->tzd,
>> THERMAL_TRIP_VIOLATED);
>> +}
>> +
>> +static void bpmp_mrq_thermal(unsigned int mrq, struct
>> tegra_bpmp_channel *ch,
>> + void *data)
>> +{
>> + struct mrq_thermal_bpmp_to_host_request *req;
>> + struct tegra_bpmp_thermal *tegra = data;
>> + int i;
>> +
>> + req = (struct mrq_thermal_bpmp_to_host_request *)ch->ib-
>>> data;
>> +
>> + if (req->type != CMD_THERMAL_HOST_TRIP_REACHED) {
>> + dev_err(tegra->dev, "%s: invalid request type:
>> %d\n",
>> + __func__, req->type);
>> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
>> + return;
>> + }
>> +
>> + for (i = 0; i < tegra->num_zones; ++i) {
>> + if (tegra->zones[i]->idx != req-
>>> host_trip_reached.zone)
>> + continue;
>> +
>> + schedule_work(&tegra->zones[i]-
>>> tz_device_update_work);
>> + tegra_bpmp_mrq_return(ch, 0, NULL, 0);
>> + return;
>> + }
>> +
>> + dev_err(tegra->dev, "%s: invalid thermal zone: %d\n",
>> __func__,
>> + req->host_trip_reached.zone);
>> + tegra_bpmp_mrq_return(ch, -EINVAL, NULL, 0);
>> +}
>> +
>> +static int tegra_bpmp_thermal_get_num_zones(struct tegra_bpmp *bpmp,
>> + int *num_zones)
>> +{
>> + struct mrq_thermal_host_to_bpmp_request req;
>> + union mrq_thermal_bpmp_to_host_response reply;
>> + struct tegra_bpmp_message msg;
>> + int err;
>> +
>> + memset(&req, 0, sizeof(req));
>> + req.type = CMD_THERMAL_GET_NUM_ZONES;
>> +
>> + memset(&msg, 0, sizeof(msg));
>> + msg.mrq = MRQ_THERMAL;
>> + msg.tx.data = &req;
>> + msg.tx.size = sizeof(req);
>> + msg.rx.data = &reply;
>> + msg.rx.size = sizeof(reply);
>> +
>> + err = tegra_bpmp_transfer(bpmp, &msg);
>> + if (err)
>> + return err;
>> +
>> + *num_zones = reply.get_num_zones.num;
>> +
>> + return 0;
>> +}
>> +
>> +static const struct thermal_zone_of_device_ops
>> tegra_bpmp_of_thermal_ops = {
>> + .get_temp = tegra_bpmp_thermal_get_temp,
>> + .set_trips = tegra_bpmp_thermal_set_trips,
>> +};
>> +
>> +static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
>> +{
>> + struct tegra_bpmp *bpmp = dev_get_drvdata(pdev->dev.parent);
>> + struct tegra_bpmp_thermal *tegra;
>> + struct thermal_zone_device *tzd;
>> + unsigned int i, max_num_zones;
>> + int err;
>> +
>> + tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra),
>> GFP_KERNEL);
>> + if (!tegra)
>> + return -ENOMEM;
>> +
>> + tegra->dev = &pdev->dev;
>> + tegra->bpmp = bpmp;
>> +
>> + err = tegra_bpmp_thermal_get_num_zones(bpmp,
>> &max_num_zones);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to get the number of
>> zones: %d\n",
>> + err);
>> + return err;
>> + }
>> +
>> + tegra->zones = devm_kcalloc(&pdev->dev, max_num_zones,
>> + sizeof(*tegra->zones),
>> GFP_KERNEL);
>> + if (!tegra->zones)
>> + return -ENOMEM;
>> +
>> + for (i = 0; i < max_num_zones; ++i) {
>> + struct tegra_bpmp_thermal_zone *zone;
>> + int temp;
>> +
>> + zone = devm_kzalloc(&pdev->dev, sizeof(*zone),
>> GFP_KERNEL);
>> + if (!zone)
>> + return -ENOMEM;
>> +
>> + zone->idx = i;
>> + zone->tegra = tegra;
>> +
>> + err = tegra_bpmp_thermal_get_temp(zone, &temp);
>> + if (err < 0) {
>> + devm_kfree(&pdev->dev, zone);
>> + continue;
>> + }
>> +
>> + tzd = devm_thermal_zone_of_sensor_register(
>> + &pdev->dev, i, zone,
>> &tegra_bpmp_of_thermal_ops);
>> + if (IS_ERR(tzd)) {
>> + if (PTR_ERR(tzd) == -EPROBE_DEFER)
>> + return -EPROBE_DEFER;
>> + devm_kfree(&pdev->dev, zone);
>> + continue;
>> + }
>> +
>> + zone->tzd = tzd;
>> + INIT_WORK(&zone->tz_device_update_work,
>> + tz_device_update_work_fn);
>> +
>> + tegra->zones[tegra->num_zones++] = zone;
>> + }
>> +
>> + err = tegra_bpmp_request_mrq(bpmp, MRQ_THERMAL,
>> bpmp_mrq_thermal,
>> + tegra);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to register mrq handler:
>> %d\n",
>> + err);
>> + return err;
>> + }
>> +
>> + platform_set_drvdata(pdev, tegra);
>> +
>> + return 0;
>> +}
>> +
>> +static int tegra_bpmp_thermal_remove(struct platform_device *pdev)
>> +{
>> + struct tegra_bpmp_thermal *tegra =
>> platform_get_drvdata(pdev);
>> +
>> + tegra_bpmp_free_mrq(tegra->bpmp, MRQ_THERMAL, tegra);
>> +
>> + return 0;
>> +}
>> +
>> +static const struct of_device_id tegra_bpmp_thermal_of_match[] = {
>> + { .compatible = "nvidia,tegra186-bpmp-thermal" },
>> + { },
>> +};
>> +MODULE_DEVICE_TABLE(of, tegra_bpmp_thermal_of_match);
>> +
>> +static struct platform_driver tegra_bpmp_thermal_driver = {
>> + .probe = tegra_bpmp_thermal_probe,
>> + .remove = tegra_bpmp_thermal_remove,
>> + .driver = {
>> + .name = "tegra-bpmp-thermal",
>> + .of_match_table = tegra_bpmp_thermal_of_match,
>> + },
>> +};
>> +module_platform_driver(tegra_bpmp_thermal_driver);
>> +
>> +MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
>> +MODULE_DESCRIPTION("NVIDIA Tegra BPMP thermal sensor driver");
>> +MODULE_LICENSE("GPL v2");
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
^ permalink raw reply [flat|nested] 36+ messages in thread[parent not found: <4315091f-03b1-2df6-b224-6a29d3261371-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
2017-08-21 2:40 ` Wei Ni
@ 2017-08-30 19:32 ` Thierry Reding
-1 siblings, 0 replies; 36+ messages in thread
From: Thierry Reding @ 2017-08-30 19:32 UTC (permalink / raw)
To: Wei Ni
Cc: Zhang Rui, Mikko Perttunen, edubezval-Re5JQEeQqe8AvxtiuMwx3w,
jonathanh-DDmLM1+adcrQT0dZR+AlfA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-pm-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 758 bytes --]
On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
>
>
> On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> > On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> >> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
> >> an
> >> interface to thermal sensors on the system-on-chip. This driver
> >> implements access to the interface. It supports reading the
> >> temperature, setting trip points and receiving notification of a
> >> tripped trip point.
> >>
> >> Signed-off-by: Mikko Perttunen <mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> >
> > Wei Ni,
> >
> > what do you think of this patch?
>
> Reviewed this patch, it looked fine to me.
Can I take this as a Reviewed-by?
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-08-30 19:32 ` Thierry Reding
0 siblings, 0 replies; 36+ messages in thread
From: Thierry Reding @ 2017-08-30 19:32 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
>
>
> On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> > On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> >> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
> >> an
> >> interface to thermal sensors on the system-on-chip. This driver
> >> implements access to the interface. It supports reading the
> >> temperature, setting trip points and receiving notification of a
> >> tripped trip point.
> >>
> >> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> >
> > Wei Ni,
> >
> > what do you think of this patch?
>
> Reviewed this patch, it looked fine to me.
Can I take this as a Reviewed-by?
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170830/cc7fc6fb/attachment.sig>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
2017-08-30 19:32 ` Thierry Reding
(?)
@ 2017-10-02 13:03 ` Wei Ni
-1 siblings, 0 replies; 36+ messages in thread
From: Wei Ni @ 2017-10-02 13:03 UTC (permalink / raw)
To: Thierry Reding
Cc: Zhang Rui, Mikko Perttunen, edubezval, jonathanh, linux-tegra,
linux-kernel, linux-arm-kernel, linux-pm
On 08/30/2017 12:32 PM, Thierry Reding wrote:
> * PGP Signed by an unknown key
>
> On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
>>
>>
>> On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
>>> On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
>>>> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
>>>> an
>>>> interface to thermal sensors on the system-on-chip. This driver
>>>> implements access to the interface. It supports reading the
>>>> temperature, setting trip points and receiving notification of a
>>>> tripped trip point.
>>>>
>>>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>>>
>>> Wei Ni,
>>>
>>> what do you think of this patch?
>>
>> Reviewed this patch, it looked fine to me.
>
> Can I take this as a Reviewed-by?
Hi Thierry,
Sorry for late response.
Yes I think you can take this as Reviewed-by.
BTW, although I have reviewed this serial patches, actually I haven't
been work on thermal drivers for a long time, I think Mikko is good on
thermal upstream issues 😊
Thanks.
Wei.
>
> Thierry
>
> * Unknown Key
> * 0x7F3EB3A1
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-10-02 13:03 ` Wei Ni
0 siblings, 0 replies; 36+ messages in thread
From: Wei Ni @ 2017-10-02 13:03 UTC (permalink / raw)
To: Thierry Reding
Cc: Zhang Rui, Mikko Perttunen, edubezval, jonathanh, linux-tegra,
linux-kernel, linux-arm-kernel, linux-pm
On 08/30/2017 12:32 PM, Thierry Reding wrote:
> * PGP Signed by an unknown key
>
> On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
>>
>>
>> On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
>>> On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
>>>> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
>>>> an
>>>> interface to thermal sensors on the system-on-chip. This driver
>>>> implements access to the interface. It supports reading the
>>>> temperature, setting trip points and receiving notification of a
>>>> tripped trip point.
>>>>
>>>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>>>
>>> Wei Ni,
>>>
>>> what do you think of this patch?
>>
>> Reviewed this patch, it looked fine to me.
>
> Can I take this as a Reviewed-by?
Hi Thierry,
Sorry for late response.
Yes I think you can take this as Reviewed-by.
BTW, although I have reviewed this serial patches, actually I haven't
been work on thermal drivers for a long time, I think Mikko is good on
thermal upstream issues 😊
Thanks.
Wei.
>
> Thierry
>
> * Unknown Key
> * 0x7F3EB3A1
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-10-02 13:03 ` Wei Ni
0 siblings, 0 replies; 36+ messages in thread
From: Wei Ni @ 2017-10-02 13:03 UTC (permalink / raw)
To: linux-arm-kernel
On 08/30/2017 12:32 PM, Thierry Reding wrote:
> * PGP Signed by an unknown key
>
> On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
>>
>>
>> On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
>>> On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
>>>> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
>>>> an
>>>> interface to thermal sensors on the system-on-chip. This driver
>>>> implements access to the interface. It supports reading the
>>>> temperature, setting trip points and receiving notification of a
>>>> tripped trip point.
>>>>
>>>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>>>
>>> Wei Ni,
>>>
>>> what do you think of this patch?
>>
>> Reviewed this patch, it looked fine to me.
>
> Can I take this as a Reviewed-by?
Hi Thierry,
Sorry for late response.
Yes I think you can take this as Reviewed-by.
BTW, although I have reviewed this serial patches, actually I haven't
been work on thermal drivers for a long time, I think Mikko is good on
thermal upstream issues ?
Thanks.
Wei.
>
> Thierry
>
> * Unknown Key
> * 0x7F3EB3A1
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
2017-08-21 2:40 ` Wei Ni
(?)
@ 2017-08-31 12:45 ` Thierry Reding
-1 siblings, 0 replies; 36+ messages in thread
From: Thierry Reding @ 2017-08-31 12:45 UTC (permalink / raw)
To: Zhang Rui
Cc: Wei Ni, Mikko Perttunen, edubezval-Re5JQEeQqe8AvxtiuMwx3w,
jonathanh-DDmLM1+adcrQT0dZR+AlfA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-pm-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 980 bytes --]
On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
>
>
> On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> > On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> >> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
> >> an
> >> interface to thermal sensors on the system-on-chip. This driver
> >> implements access to the interface. It supports reading the
> >> temperature, setting trip points and receiving notification of a
> >> tripped trip point.
> >>
> >> Signed-off-by: Mikko Perttunen <mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> >
> > Wei Ni,
> >
> > what do you think of this patch?
>
> Reviewed this patch, it looked fine to me.
Hi Zhang,
given the build-time dependencies, how about if I take this into the
Tegra tree with an Acked-by from you? I can provide a stable branch with
the dependencies included if you want to pull it into your tree in order
to resolve dependencies.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-08-31 12:45 ` Thierry Reding
0 siblings, 0 replies; 36+ messages in thread
From: Thierry Reding @ 2017-08-31 12:45 UTC (permalink / raw)
To: Zhang Rui
Cc: Wei Ni, Mikko Perttunen, edubezval, jonathanh, linux-tegra,
linux-kernel, linux-arm-kernel, linux-pm
[-- Attachment #1: Type: text/plain, Size: 951 bytes --]
On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
>
>
> On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> > On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> >> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
> >> an
> >> interface to thermal sensors on the system-on-chip. This driver
> >> implements access to the interface. It supports reading the
> >> temperature, setting trip points and receiving notification of a
> >> tripped trip point.
> >>
> >> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> >
> > Wei Ni,
> >
> > what do you think of this patch?
>
> Reviewed this patch, it looked fine to me.
Hi Zhang,
given the build-time dependencies, how about if I take this into the
Tegra tree with an Acked-by from you? I can provide a stable branch with
the dependencies included if you want to pull it into your tree in order
to resolve dependencies.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-08-31 12:45 ` Thierry Reding
0 siblings, 0 replies; 36+ messages in thread
From: Thierry Reding @ 2017-08-31 12:45 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
>
>
> On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> > On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> >> On Tegra186, the BPMP (Boot and Power Management Processor) exposes
> >> an
> >> interface to thermal sensors on the system-on-chip. This driver
> >> implements access to the interface. It supports reading the
> >> temperature, setting trip points and receiving notification of a
> >> tripped trip point.
> >>
> >> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> >
> > Wei Ni,
> >
> > what do you think of this patch?
>
> Reviewed this patch, it looked fine to me.
Hi Zhang,
given the build-time dependencies, how about if I take this into the
Tegra tree with an Acked-by from you? I can provide a stable branch with
the dependencies included if you want to pull it into your tree in order
to resolve dependencies.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170831/16408449/attachment.sig>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
2017-08-31 12:45 ` Thierry Reding
@ 2017-09-01 1:23 ` Zhang Rui
-1 siblings, 0 replies; 36+ messages in thread
From: Zhang Rui @ 2017-09-01 1:23 UTC (permalink / raw)
To: Thierry Reding
Cc: Wei Ni, Mikko Perttunen, edubezval, jonathanh, linux-tegra,
linux-kernel, linux-arm-kernel, linux-pm
On Thu, 2017-08-31 at 14:45 +0200, Thierry Reding wrote:
> On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
> >
> >
> >
> > On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> > >
> > > On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> > > >
> > > > On Tegra186, the BPMP (Boot and Power Management Processor)
> > > > exposes
> > > > an
> > > > interface to thermal sensors on the system-on-chip. This driver
> > > > implements access to the interface. It supports reading the
> > > > temperature, setting trip points and receiving notification of
> > > > a
> > > > tripped trip point.
> > > >
> > > > Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Acked-by: Zhang Rui <rui.zhang@intel.com>
for this patch and patch 1/5.
> > > Wei Ni,
> > >
> > > what do you think of this patch?
> > Reviewed this patch, it looked fine to me.
> Hi Zhang,
>
> given the build-time dependencies, how about if I take this into the
> Tegra tree with an Acked-by from you?
Sounds okay to me. Done. :)
thanks,
rui
> I can provide a stable branch with
> the dependencies included if you want to pull it into your tree in
> order
> to resolve dependencies.
>
> Thierry
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH v2 5/5] thermal: Add Tegra BPMP thermal sensor driver
@ 2017-09-01 1:23 ` Zhang Rui
0 siblings, 0 replies; 36+ messages in thread
From: Zhang Rui @ 2017-09-01 1:23 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, 2017-08-31 at 14:45 +0200, Thierry Reding wrote:
> On Mon, Aug 21, 2017 at 10:40:44AM +0800, Wei Ni wrote:
> >
> >
> >
> > On Friday, August 11, 2017 10:57 AM, Zhang Rui wrote:
> > >
> > > On Mon, 2017-07-24 at 19:29 +0300, Mikko Perttunen wrote:
> > > >
> > > > On Tegra186, the BPMP (Boot and Power Management Processor)
> > > > exposes
> > > > an
> > > > interface to thermal sensors on the system-on-chip. This driver
> > > > implements access to the interface. It supports reading the
> > > > temperature, setting trip points and receiving notification of
> > > > a
> > > > tripped trip point.
> > > >
> > > > Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Acked-by: Zhang Rui <rui.zhang@intel.com>
for this patch and patch 1/5.
> > > Wei Ni,
> > >
> > > what do you think of this patch?
> > Reviewed this patch, it looked fine to me.
> Hi Zhang,
>
> given the build-time dependencies, how about if I take this into the
> Tegra tree with an Acked-by from you?
Sounds okay to me. Done. :)
thanks,
rui
> I can provide a stable branch with
> the dependencies included if you want to pull it into your tree in
> order
> to resolve dependencies.
>
> Thierry
^ permalink raw reply [flat|nested] 36+ messages in thread