Skip to contentSkip to conversation

thermal: Add HiSilicon Kunpeng thermal driver and Maintainers

PATCH Superseded Yang Shen 3 participants 9 messages Mar 16, 2020 – Apr 14, 2020 Thermal

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yang Shen

author
#0 lore raw

v2 cover thermal: Add HiSilicon Kunpeng thermal driver and Maintainers

Add HiSilicon Kunpeng thermal driver and Maintainers.

Changelog:
v2:
* fix sizeof(* tdev) and sizeof(* tdev->tsensor)

Yang Shen (2):
thermal: Add HiSilicon Kunpeng thermal driver
MAINTAINERS: Add maintainers for kunpeng thermal

 MAINTAINERS                       |   7 ++
 drivers/thermal/Kconfig           |   8 ++
 drivers/thermal/Makefile          |   1 +
 drivers/thermal/kunpeng_thermal.c | 219 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 235 insertions(+)
 create mode 100644 drivers/thermal/kunpeng_thermal.c

--
2.7.4

author
#1 lore raw

PATCH v2 1/2 thermal: Add HiSilicon Kunpeng thermal driver

Support HiSilicon Kunpeng tsensor. the driver will report the max temperature for each core.

---
 drivers/thermal/Kconfig           |   8 ++
 drivers/thermal/Makefile          |   1 +
 drivers/thermal/kunpeng_thermal.c | 219 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/thermal/kunpeng_thermal.c
drivers/thermal/Kconfig +8 -0
index 5a05db5..7611b5d 100644
@@ -239,6 +239,14 @@ config HISI_THERMAL
 	  thermal framework. cpufreq is used as the cooling device to throttle
 	  CPUs when the passive trip is crossed.
 
+config KUNPENG_THERMAL
+	tristate "HiSilicon kunpeng thermal driver"
+	depends on ARM64 || COMPILE_TEST
+	help
+	  Enable this to plug HiSilicon kunpeng's thermal sensors driver into
+	  the Linux thermal framework, which supports to get the highest
+	  temperature of one Kunpeng SoC.
+
 config IMX_THERMAL
 	tristate "Temperature sensor driver for Freescale i.MX SoCs"
 	depends on ARCH_MXC || COMPILE_TEST
drivers/thermal/Makefile +1 -0
index 9fb88e2..88ffca5 100644
@@ -57,3 +57,4 @@ obj-$(CONFIG_GENERIC_ADC_THERMAL)	+= thermal-generic-adc.o
 obj-$(CONFIG_ZX2967_THERMAL)	+= zx2967_thermal.o
 obj-$(CONFIG_UNIPHIER_THERMAL)	+= uniphier_thermal.o
 obj-$(CONFIG_AMLOGIC_THERMAL)     += amlogic_thermal.o
+obj-$(CONFIG_KUNPENG_THERMAL)     += kunpeng_thermal.o
drivers/thermal/kunpeng_thermal.c new file +219 -0

219 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH V2 1/2] thermal: Add HiSilicon Kunpeng thermal driver

Hi Yang,

Quoted 19 lines · Yang Shen

Support HiSilicon Kunpeng tsensor. the driver will report the max temperature for each core.

---
 drivers/thermal/Kconfig           |   8 ++
 drivers/thermal/Makefile          |   1 +
 drivers/thermal/kunpeng_thermal.c | 219 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/thermal/kunpeng_thermal.c
drivers/thermal/Kconfig +0 -0
index 5a05db5..7611b5d 100644

drivers/thermal/Kconfig config HISI_THERMAL · line 244

Quoted 6 lines
drivers/thermal/Kconfig +3 -0
@@ -239,6 +239,14 @@ config HISI_THERMAL
          thermal framework. cpufreq is used as the cooling device to throttle
          CPUs when the passive trip is crossed.
 
+config KUNPENG_THERMAL
+       tristate "HiSilicon kunpeng thermal driver"
+       depends on ARM64 || COMPILE_TEST

Please make this depend on your SoC, not all of ARM64. Perhaps ARCH_HISI?

Quoted 32 lines
drivers/thermal/Kconfig +5 -0
+       help
+         Enable this to plug HiSilicon kunpeng's thermal sensors driver into
+         the Linux thermal framework, which supports to get the highest
+         temperature of one Kunpeng SoC.
+
 config IMX_THERMAL
        tristate "Temperature sensor driver for Freescale i.MX SoCs"
        depends on ARCH_MXC || COMPILE_TEST
drivers/thermal/Makefile +1 -0
index 9fb88e2..88ffca5 100644
@@ -57,3 +57,4 @@ obj-$(CONFIG_GENERIC_ADC_THERMAL)     += thermal-generic-adc.o
 obj-$(CONFIG_ZX2967_THERMAL)   += zx2967_thermal.o
 obj-$(CONFIG_UNIPHIER_THERMAL) += uniphier_thermal.o
 obj-$(CONFIG_AMLOGIC_THERMAL)     += amlogic_thermal.o
+obj-$(CONFIG_KUNPENG_THERMAL)     += kunpeng_thermal.o
drivers/thermal/kunpeng_thermal.c new file +9 -0
new file mode 100644
index 0000000..5b5df82
@@ -0,0 +1,219 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2020 HiSilicon Limited. */
+
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/kernel.h>

drivers/thermal/kunpeng_thermal.c line 19

Quoted 10 lines
drivers/thermal/kunpeng_thermal.c new file +10 -0
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define KUNPENG_TSENSOR_CONTROL                        0x20D0
+#define KUNPENG_TSENSOR_ST                     0x60D0
+#define KUNPENG_TSENSOR_SAMPLE                 0x60D4
+#define KUNPENG_TSENSOR_CONTROL_EN             BIT(0)
+
+#define KUNPENG_TSENSOR_IS_ENABLE(reg)         ((reg) & 0x1)

Typo: ENABLED

Quoted 44 lines
drivers/thermal/kunpeng_thermal.c new file +44 -0
+#define KUNPENG_TSENSOR_IS_READY(reg)          (((reg) >> 12) & 0x1)
+#define KUNPENG_TSENSOR_IS_VALID(reg)          (((reg) >> 31) & 0x1)
+#define KUNPENG_TSENSOR_TRIM_HIGH(reg)         (((reg) >> 15) & 0x7FF)
+#define KUNPENG_TSENSOR_TRIM_LOW(reg)          ((reg) & 0x7FF)
+#define KUNPENG_TSENSOR_TEMP_VAL(reg)          ((reg) & 0x3FF)
+#define KUNPENG_TSENSOR_BASE_NUM(num)          (2 * (num))
+#define KUNPENG_TSENSOR_TRIM_NUM(num)          (2 * (num) + 1)
+
+#define KUNPENG_TSENSOR_RD_INTVRL_US           5
+#define KUNPENG_TSENSOR_RD_TMOUT_US            2000
+#define KUNPENG_TSENSOR_BASIC_TMP              25000
+#define KUNPENG_TSENSOR_BASIC_TRIM_RANGE       80000
+
+struct kunpeng_tsensor {
+       void __iomem *base;
+       void __iomem *trim_register;
+};
+
+struct kunpeng_thermal_dev {
+       u32 num_tsensors;
+       struct kunpeng_tsensor tsensor[];
+};
+
+static int kunpeng_thermal_temp_correct(u32 tmp, u32 trim)
+{
+       int trim_high = KUNPENG_TSENSOR_TRIM_HIGH(trim);
+       int trim_low = KUNPENG_TSENSOR_TRIM_LOW(trim);
+       int val = KUNPENG_TSENSOR_TEMP_VAL(tmp);
+
+       if (trim_high == trim_low)
+               return INT_MIN;
+
+       /* temperature of tsensor needs to be calibrated */
+       return KUNPENG_TSENSOR_BASIC_TRIM_RANGE * (val - trim_low)
+              / (trim_high - trim_low) + KUNPENG_TSENSOR_BASIC_TMP;
+}
+
+static int kunpeng_thermal_get_temp(struct thermal_zone_device *thermal,
+                                   int *temp)
+{
+       struct kunpeng_thermal_dev *tdev = thermal->devdata;
+       int tempmax = INT_MIN;
+       u32 i, reg, tmp, trim;
+       int ret;

drivers/thermal/kunpeng_thermal.c line 73

Quoted 10 lines
drivers/thermal/kunpeng_thermal.c new file +10 -0
+
+       for (i = 0; i < tdev->num_tsensors; i++) {
+               /* Waiting for tsensor ready */
+               ret = readl_relaxed_poll_timeout(tdev->tsensor[i].base +
+                                                KUNPENG_TSENSOR_ST, reg,
+                                                KUNPENG_TSENSOR_IS_READY(reg),
+                                                KUNPENG_TSENSOR_RD_INTVRL_US,
+                                                KUNPENG_TSENSOR_RD_TMOUT_US);
+               if (ret) {
+                       dev_err(&thermal->device,

dev_dbg? If it's an error, you probably want to return here. No point in flooding the console with messages.

drivers/thermal/kunpeng_thermal.c line 78

Quoted 5 lines
drivers/thermal/kunpeng_thermal.c new file +5 -0
+                               "Tsensor%u isn't ready!\n", i);
+                       continue;
+               }
+
+               /* checking if tsensors are valid */

s/tsensors/temperature/ ?

drivers/thermal/kunpeng_thermal.c line 82

Quoted 4 lines
drivers/thermal/kunpeng_thermal.c new file +4 -0
+               tmp = readl_relaxed(tdev->tsensor[i].base
+                                   + KUNPENG_TSENSOR_SAMPLE);
+               if (!KUNPENG_TSENSOR_IS_VALID(tmp)) {
+                       dev_err(&thermal->device,

dev_dbg?

drivers/thermal/kunpeng_thermal.c line 91

Quoted 9 lines
drivers/thermal/kunpeng_thermal.c new file +9 -0
+                               "Tsensor%u temperature is invalid!\n", i);
+                       continue;
+               }
+
+               trim = readl_relaxed(tdev->tsensor[i].trim_register);
+
+               ret = kunpeng_thermal_temp_correct(tmp, trim);
+               if (ret == INT_MIN) {
+                       dev_err(&thermal->device,

dev_dbg?

Quoted 21 lines
drivers/thermal/kunpeng_thermal.c new file +21 -0
+                               "Tsensor%u trim value is invalid!\n", i);
+                       continue;
+               }
+
+               tempmax = max(ret, tempmax);
+       }
+
+       if (tempmax == INT_MIN)
+               return -EINVAL;
+
+       *temp = tempmax;
+
+       return 0;
+}
+
+static struct thermal_zone_device_ops ops = {
+       .get_temp       = kunpeng_thermal_get_temp,
+};
+
+static int kunpeng_thermal_get_iobase(struct platform_device *pdev,
+                                     struct kunpeng_tsensor *tsensor,

drivers/thermal/kunpeng_thermal.c line 122

Quoted 10 lines
drivers/thermal/kunpeng_thermal.c new file +10 -0
+                                     u32 resource_num)
+{
+       struct resource *res;
+       void __iomem *base;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, resource_num);
+       if (!res)
+               return -EINVAL;
+
+       base = devm_ioremap(&pdev->dev, res->start, resource_size(res));

Consider using devm_ioremap_resource()

Quoted 5 lines
drivers/thermal/kunpeng_thermal.c new file +5 -0
+       if (IS_ERR(base))
+               return -EINVAL;
+
+       if (resource_num & 1)
+               tsensor->trim_register = base;

drivers/thermal/kunpeng_thermal.c line 137

Quoted 10 lines
drivers/thermal/kunpeng_thermal.c new file +10 -0
+       else
+               tsensor->base = base;
+
+       return 0;
+}
+
+/**
+ * kunpeng_thermal_probe() - Enable tsensors. And register device to thermal.
+ *
+ * This driver and IMU share tsensor devices. This funciton only enable the

Typo: function

drivers/thermal/kunpeng_thermal.c line 138

Quoted 1 line
drivers/thermal/kunpeng_thermal.c new file +1 -0
+ * devices but never change configure or disable them.

Probe functions typically only enable the device. I don't think you need to put that into comments.

Quoted 22 lines
drivers/thermal/kunpeng_thermal.c new file +22 -0
+ */
+static int kunpeng_thermal_probe(struct platform_device *pdev)
+{
+       u32 num_tsensors = pdev->num_resources >> 1;
+       struct thermal_zone_device *thermal_zone;
+       struct kunpeng_thermal_dev *tdev;
+       u32 i, reg;
+       int ret;
+
+       tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev) + sizeof(*tdev->tsensor) *
+                           num_tsensors, GFP_KERNEL);
+       if (!tdev)
+               return -ENOMEM;
+
+       tdev->num_tsensors = num_tsensors;
+
+       for (i = 0; i < num_tsensors; i++) {
+               ret = kunpeng_thermal_get_iobase(pdev, &tdev->tsensor[i],
+                                                KUNPENG_TSENSOR_BASE_NUM(i));
+               if (ret) {
+                       dev_err(&pdev->dev, "Fail to ioremap base!\n");
+                       return ret;

drivers/thermal/kunpeng_thermal.c line 170

Quoted 10 lines
drivers/thermal/kunpeng_thermal.c new file +10 -0
+               }
+
+               ret = kunpeng_thermal_get_iobase(pdev, &tdev->tsensor[i],
+                                                KUNPENG_TSENSOR_TRIM_NUM(i));
+               if (ret) {
+                       dev_err(&pdev->dev, "Fail to ioremap trim register!\n");
+                       return ret;
+               }
+
+               /* Enable thermal sensors when devices are disable */

Get rid of this comment

drivers/thermal/kunpeng_thermal.c line 176

Quoted 6 lines
drivers/thermal/kunpeng_thermal.c new file +6 -0
+               reg = readl_relaxed(tdev->tsensor[i].base +
+                                   KUNPENG_TSENSOR_CONTROL);
+               if (!KUNPENG_TSENSOR_IS_ENABLE(reg))
+                       writel_relaxed(reg | KUNPENG_TSENSOR_CONTROL_EN,
+                                      tdev->tsensor[i].base +
+                                      KUNPENG_TSENSOR_CONTROL);

Is it a problem if the sensor is enabled twice? Does firmware initialise this sensor? I suggest getting rid of the check and just enable it again in the driver.

Quoted 46 lines
drivers/thermal/kunpeng_thermal.c new file +43 -1
+       }
+
+       thermal_zone = thermal_zone_device_register("kunpeng_thermal", 0, 0,
+                                                   tdev, &ops, NULL, 0, 0);
+       if (IS_ERR(thermal_zone)) {
+               dev_err(&pdev->dev, "Fail to register to thermal subsystem\n");
+               return PTR_ERR(thermal_zone);
+       }
+
+       platform_set_drvdata(pdev, thermal_zone);
+
+       return 0;
+}
+
+static int kunpeng_thermal_remove(struct platform_device *pdev)
+{
+       struct thermal_zone_device *thermal_zone = platform_get_drvdata(pdev);
+
+       thermal_zone_device_unregister(thermal_zone);
+
+       return 0;
+}
+
+static const struct acpi_device_id kunpeng_thermal_acpi_match[] = {
+       { "HISI0371", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(acpi, kunpeng_thermal_acpi_match);
+
+static struct platform_driver kunpeng_thermal_driver = {
+       .probe          = kunpeng_thermal_probe,
+       .remove         = kunpeng_thermal_remove,
+       .driver         = {
+               .name   = "kunpeng_thermal",
+               .acpi_match_table = ACPI_PTR(kunpeng_thermal_acpi_match),
+       },
+};
+
+module_platform_driver(kunpeng_thermal_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Yang Shen <[email protected]>");
+MODULE_DESCRIPTION("HiSilicon Kunpeng thermal driver");
--

2.7.4

#3 lore raw

Re: [PATCH V2 1/2] thermal: Add HiSilicon Kunpeng thermal driver

Hi Amit,

Thanks a lot for your review!

Yang

Quoted 25 lines · Amit Kucheria

Hi Yang,

Quoted 22 lines · Yang Shen

Support HiSilicon Kunpeng tsensor. the driver will report the max temperature for each core.

---
 drivers/thermal/Kconfig           |   8 ++
 drivers/thermal/Makefile          |   1 +
 drivers/thermal/kunpeng_thermal.c | 219 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/thermal/kunpeng_thermal.c
drivers/thermal/Kconfig +0 -0
index 5a05db5..7611b5d 100644
@@ -239,6 +239,14 @@ config HISI_THERMAL
          thermal framework. cpufreq is used as the cooling device to throttle
          CPUs when the passive trip is crossed.
 
Quoted 6 lines

drivers/thermal/Kconfig config HISI_THERMAL · line 244

Quoted 3 lines
drivers/thermal/Kconfig +3 -0
+config KUNPENG_THERMAL
+       tristate "HiSilicon kunpeng thermal driver"
+       depends on ARM64 || COMPILE_TEST

Please make this depend on your SoC, not all of ARM64. Perhaps ARCH_HISI?

This driver depend on ARM64 only.

Quoted 36 lines
Quoted 36 lines
drivers/thermal/Kconfig +5 -0
+       help
+         Enable this to plug HiSilicon kunpeng's thermal sensors driver into
+         the Linux thermal framework, which supports to get the highest
+         temperature of one Kunpeng SoC.
+
 config IMX_THERMAL
        tristate "Temperature sensor driver for Freescale i.MX SoCs"
        depends on ARCH_MXC || COMPILE_TEST
drivers/thermal/Makefile +1 -0
index 9fb88e2..88ffca5 100644
@@ -57,3 +57,4 @@ obj-$(CONFIG_GENERIC_ADC_THERMAL)     += thermal-generic-adc.o
 obj-$(CONFIG_ZX2967_THERMAL)   += zx2967_thermal.o
 obj-$(CONFIG_UNIPHIER_THERMAL) += uniphier_thermal.o
 obj-$(CONFIG_AMLOGIC_THERMAL)     += amlogic_thermal.o
+obj-$(CONFIG_KUNPENG_THERMAL)     += kunpeng_thermal.o
drivers/thermal/kunpeng_thermal.c new file +13 -0
new file mode 100644
index 0000000..5b5df82
@@ -0,0 +1,219 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2020 HiSilicon Limited. */
+
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
Quoted 9 lines

drivers/thermal/kunpeng_thermal.c line 19

Quoted 6 lines
drivers/thermal/kunpeng_thermal.c new file +6 -0
+#define KUNPENG_TSENSOR_CONTROL                        0x20D0
+#define KUNPENG_TSENSOR_ST                     0x60D0
+#define KUNPENG_TSENSOR_SAMPLE                 0x60D4
+#define KUNPENG_TSENSOR_CONTROL_EN             BIT(0)
+
+#define KUNPENG_TSENSOR_IS_ENABLE(reg)         ((reg) & 0x1)

Typo: ENABLED

I'll fix this in next version, thanks!

Quoted 49 lines
Quoted 49 lines
drivers/thermal/kunpeng_thermal.c new file +49 -0
+#define KUNPENG_TSENSOR_IS_READY(reg)          (((reg) >> 12) & 0x1)
+#define KUNPENG_TSENSOR_IS_VALID(reg)          (((reg) >> 31) & 0x1)
+#define KUNPENG_TSENSOR_TRIM_HIGH(reg)         (((reg) >> 15) & 0x7FF)
+#define KUNPENG_TSENSOR_TRIM_LOW(reg)          ((reg) & 0x7FF)
+#define KUNPENG_TSENSOR_TEMP_VAL(reg)          ((reg) & 0x3FF)
+#define KUNPENG_TSENSOR_BASE_NUM(num)          (2 * (num))
+#define KUNPENG_TSENSOR_TRIM_NUM(num)          (2 * (num) + 1)
+
+#define KUNPENG_TSENSOR_RD_INTVRL_US           5
+#define KUNPENG_TSENSOR_RD_TMOUT_US            2000
+#define KUNPENG_TSENSOR_BASIC_TMP              25000
+#define KUNPENG_TSENSOR_BASIC_TRIM_RANGE       80000
+
+struct kunpeng_tsensor {
+       void __iomem *base;
+       void __iomem *trim_register;
+};
+
+struct kunpeng_thermal_dev {
+       u32 num_tsensors;
+       struct kunpeng_tsensor tsensor[];
+};
+
+static int kunpeng_thermal_temp_correct(u32 tmp, u32 trim)
+{
+       int trim_high = KUNPENG_TSENSOR_TRIM_HIGH(trim);
+       int trim_low = KUNPENG_TSENSOR_TRIM_LOW(trim);
+       int val = KUNPENG_TSENSOR_TEMP_VAL(tmp);
+
+       if (trim_high == trim_low)
+               return INT_MIN;
+
+       /* temperature of tsensor needs to be calibrated */
+       return KUNPENG_TSENSOR_BASIC_TRIM_RANGE * (val - trim_low)
+              / (trim_high - trim_low) + KUNPENG_TSENSOR_BASIC_TMP;
+}
+
+static int kunpeng_thermal_get_temp(struct thermal_zone_device *thermal,
+                                   int *temp)
+{
+       struct kunpeng_thermal_dev *tdev = thermal->devdata;
+       int tempmax = INT_MIN;
+       u32 i, reg, tmp, trim;
+       int ret;
+
+       for (i = 0; i < tdev->num_tsensors; i++) {
+               /* Waiting for tsensor ready */
+               ret = readl_relaxed_poll_timeout(tdev->tsensor[i].base +
+                                                KUNPENG_TSENSOR_ST, reg,
Quoted 9 lines

drivers/thermal/kunpeng_thermal.c line 73

Quoted 5 lines
drivers/thermal/kunpeng_thermal.c new file +5 -0
+                                                KUNPENG_TSENSOR_IS_READY(reg),
+                                                KUNPENG_TSENSOR_RD_INTVRL_US,
+                                                KUNPENG_TSENSOR_RD_TMOUT_US);
+               if (ret) {
+                       dev_err(&thermal->device,

dev_dbg? If it's an error, you probably want to return here. No point in flooding the console with messages.

Thanks. But our SoC have more than one sensor. In this function, even if some of sensors don't work normal, I want to return the max temperature of the working sensors and tell the user which one has problem.

Quoted 8 lines

drivers/thermal/kunpeng_thermal.c line 78

Quoted 5 lines
drivers/thermal/kunpeng_thermal.c new file +5 -0
+                               "Tsensor%u isn't ready!\n", i);
+                       continue;
+               }
+
+               /* checking if tsensors are valid */

s/tsensors/temperature/ ?

I'll fix this in next version, thanks!

Quoted 7 lines

drivers/thermal/kunpeng_thermal.c line 82

Quoted 4 lines
drivers/thermal/kunpeng_thermal.c new file +4 -0
+               tmp = readl_relaxed(tdev->tsensor[i].base
+                                   + KUNPENG_TSENSOR_SAMPLE);
+               if (!KUNPENG_TSENSOR_IS_VALID(tmp)) {
+                       dev_err(&thermal->device,

dev_dbg?

the same as above

Quoted 12 lines

drivers/thermal/kunpeng_thermal.c line 91

Quoted 9 lines
drivers/thermal/kunpeng_thermal.c new file +9 -0
+                               "Tsensor%u temperature is invalid!\n", i);
+                       continue;
+               }
+
+               trim = readl_relaxed(tdev->tsensor[i].trim_register);
+
+               ret = kunpeng_thermal_temp_correct(tmp, trim);
+               if (ret == INT_MIN) {
+                       dev_err(&thermal->device,

dev_dbg?

the same as above

Quoted 25 lines
Quoted 25 lines
drivers/thermal/kunpeng_thermal.c new file +25 -0
+                               "Tsensor%u trim value is invalid!\n", i);
+                       continue;
+               }
+
+               tempmax = max(ret, tempmax);
+       }
+
+       if (tempmax == INT_MIN)
+               return -EINVAL;
+
+       *temp = tempmax;
+
+       return 0;
+}
+
+static struct thermal_zone_device_ops ops = {
+       .get_temp       = kunpeng_thermal_get_temp,
+};
+
+static int kunpeng_thermal_get_iobase(struct platform_device *pdev,
+                                     struct kunpeng_tsensor *tsensor,
+                                     u32 resource_num)
+{
+       struct resource *res;
+       void __iomem *base;
Quoted 9 lines

drivers/thermal/kunpeng_thermal.c line 122

Quoted 6 lines
drivers/thermal/kunpeng_thermal.c new file +6 -0
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, resource_num);
+       if (!res)
+               return -EINVAL;
+
+       base = devm_ioremap(&pdev->dev, res->start, resource_size(res));

Consider using devm_ioremap_resource()

In this driver, one sensor device needs two types register to work. One is used to control device, and the other provides temperature calibration value.
But here is a question that sensors distributed on C die and IO die have different register offset address. The two types of sensor registers on IO die are distributed on the same page, but those on C die are distributed on different pages.
For compatibility reasons,the ACPI provides two resource for one sensor. The first one is used to map control register, and the second one is used to map temperature calibration value register which will lead to mapping conflicts when using devm_ioremap_resource() to map the device register on IO die.

Quoted 9 lines
Quoted 9 lines
drivers/thermal/kunpeng_thermal.c new file +9 -0
+       if (IS_ERR(base))
+               return -EINVAL;
+
+       if (resource_num & 1)
+               tsensor->trim_register = base;
+       else
+               tsensor->base = base;
+
+       return 0;
Quoted 9 lines

drivers/thermal/kunpeng_thermal.c line 137

Quoted 6 lines
drivers/thermal/kunpeng_thermal.c new file +6 -0
+}
+
+/**
+ * kunpeng_thermal_probe() - Enable tsensors. And register device to thermal.
+ *
+ * This driver and IMU share tsensor devices. This funciton only enable the

Typo: function

Sorry, I'll fix this.

Quoted 5 lines

drivers/thermal/kunpeng_thermal.c line 138

Quoted 1 line
drivers/thermal/kunpeng_thermal.c new file +1 -0
+ * devices but never change configure or disable them.

Probe functions typically only enable the device. I don't think you need to put that into comments.

Here I don't do any operation to devices on driver remove function. I'm afraid that users are confused about this, so I've added a comment here. Maybe moving this to the front of the remove function is a little better.

Quoted 26 lines
Quoted 26 lines
drivers/thermal/kunpeng_thermal.c new file +26 -0
+ */
+static int kunpeng_thermal_probe(struct platform_device *pdev)
+{
+       u32 num_tsensors = pdev->num_resources >> 1;
+       struct thermal_zone_device *thermal_zone;
+       struct kunpeng_thermal_dev *tdev;
+       u32 i, reg;
+       int ret;
+
+       tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev) + sizeof(*tdev->tsensor) *
+                           num_tsensors, GFP_KERNEL);
+       if (!tdev)
+               return -ENOMEM;
+
+       tdev->num_tsensors = num_tsensors;
+
+       for (i = 0; i < num_tsensors; i++) {
+               ret = kunpeng_thermal_get_iobase(pdev, &tdev->tsensor[i],
+                                                KUNPENG_TSENSOR_BASE_NUM(i));
+               if (ret) {
+                       dev_err(&pdev->dev, "Fail to ioremap base!\n");
+                       return ret;
+               }
+
+               ret = kunpeng_thermal_get_iobase(pdev, &tdev->tsensor[i],
+                                                KUNPENG_TSENSOR_TRIM_NUM(i));
Quoted 9 lines

drivers/thermal/kunpeng_thermal.c line 170

Quoted 6 lines
drivers/thermal/kunpeng_thermal.c new file +6 -0
+               if (ret) {
+                       dev_err(&pdev->dev, "Fail to ioremap trim register!\n");
+                       return ret;
+               }
+
+               /* Enable thermal sensors when devices are disable */

Get rid of this comment

OK, I'll fix this in next version.

Quoted 7 lines

drivers/thermal/kunpeng_thermal.c line 176

Quoted 6 lines
drivers/thermal/kunpeng_thermal.c new file +6 -0
+               reg = readl_relaxed(tdev->tsensor[i].base +
+                                   KUNPENG_TSENSOR_CONTROL);
+               if (!KUNPENG_TSENSOR_IS_ENABLE(reg))
+                       writel_relaxed(reg | KUNPENG_TSENSOR_CONTROL_EN,
+                                      tdev->tsensor[i].base +
+                                      KUNPENG_TSENSOR_CONTROL);
Quoted 5 lines

Is it a problem if the sensor is enabled twice? Does firmware initialise this sensor? I suggest getting rid of the check and just enable it again in the driver.

I'll fix this in next version, thanks!

Quoted 49 lines
Quoted 44 lines
drivers/thermal/kunpeng_thermal.c new file +43 -1
+       }
+
+       thermal_zone = thermal_zone_device_register("kunpeng_thermal", 0, 0,
+                                                   tdev, &ops, NULL, 0, 0);
+       if (IS_ERR(thermal_zone)) {
+               dev_err(&pdev->dev, "Fail to register to thermal subsystem\n");
+               return PTR_ERR(thermal_zone);
+       }
+
+       platform_set_drvdata(pdev, thermal_zone);
+
+       return 0;
+}
+
+static int kunpeng_thermal_remove(struct platform_device *pdev)
+{
+       struct thermal_zone_device *thermal_zone = platform_get_drvdata(pdev);
+
+       thermal_zone_device_unregister(thermal_zone);
+
+       return 0;
+}
+
+static const struct acpi_device_id kunpeng_thermal_acpi_match[] = {
+       { "HISI0371", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(acpi, kunpeng_thermal_acpi_match);
+
+static struct platform_driver kunpeng_thermal_driver = {
+       .probe          = kunpeng_thermal_probe,
+       .remove         = kunpeng_thermal_remove,
+       .driver         = {
+               .name   = "kunpeng_thermal",
+               .acpi_match_table = ACPI_PTR(kunpeng_thermal_acpi_match),
+       },
+};
+
+module_platform_driver(kunpeng_thermal_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Yang Shen <[email protected]>");
+MODULE_DESCRIPTION("HiSilicon Kunpeng thermal driver");
--
Quoted 2 lines

2.7.4

.

author
#4 lore raw

PATCH v2 2/2 MAINTAINERS: Add maintainers for kunpeng thermal

In reply to Yang Shen

Add Yang Shen and Zhou Wang as maintainers for kunpeng thermal

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index cc1d18c..b7d4af4 100644
@@ -7602,6 +7602,13 @@ F:	drivers/crypto/hisilicon/sgl.c
 F:	drivers/crypto/hisilicon/zip/
 F:	Documentation/ABI/testing/debugfs-hisi-zip
 
+HISILICON KUNPENG TSENSOR DRIVER
+M:	Yang Shen <[email protected]>
+M:	Zhou Wang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/thermal/kunpeng_thermal.c
+
 HMM - Heterogeneous Memory Management
 M:	Jérôme Glisse <[email protected]>
 L:	[email protected]
Signature · 1 line
2.7.4
Reviewed-by on v2 2/2
#5 lore raw

Re: [PATCH V2 2/2] MAINTAINERS: Add maintainers for kunpeng thermal

Quoted 5 lines · Yang Shen

Add Yang Shen and Zhou Wang as maintainers for kunpeng thermal

Quoted 25 lines
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -1
index cc1d18c..b7d4af4 100644
@@ -7602,6 +7602,13 @@ F:       drivers/crypto/hisilicon/sgl.c
 F:     drivers/crypto/hisilicon/zip/
 F:     Documentation/ABI/testing/debugfs-hisi-zip
 
+HISILICON KUNPENG TSENSOR DRIVER
+M:     Yang Shen <[email protected]>
+M:     Zhou Wang <[email protected]>
+L:     [email protected]
+S:     Maintained
+F:     drivers/thermal/kunpeng_thermal.c
+
 HMM - Heterogeneous Memory Management
 M:     Jérôme Glisse <[email protected]>
 L:     [email protected]
--

2.7.4

#6 lore raw

Re: [PATCH V2 2/2] MAINTAINERS: Add maintainers for kunpeng thermal

Quoted 9 lines · Amit Kucheria
Quoted 5 lines · Yang Shen

Add Yang Shen and Zhou Wang as maintainers for kunpeng thermal

Okay, thanks!

Quoted 27 lines
Quoted 25 lines
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -1
index cc1d18c..b7d4af4 100644
@@ -7602,6 +7602,13 @@ F:       drivers/crypto/hisilicon/sgl.c
 F:     drivers/crypto/hisilicon/zip/
 F:     Documentation/ABI/testing/debugfs-hisi-zip
 
+HISILICON KUNPENG TSENSOR DRIVER
+M:     Yang Shen <[email protected]>
+M:     Zhou Wang <[email protected]>
+L:     [email protected]
+S:     Maintained
+F:     drivers/thermal/kunpeng_thermal.c
+
 HMM - Heterogeneous Memory Management
 M:     Jérôme Glisse <[email protected]>
 L:     [email protected]
--

2.7.4

author
#7 lore raw
In reply to Yang Shen
Quoted 17 lines · Yang Shen

Add HiSilicon Kunpeng thermal driver and Maintainers.

Changelog:
v2:
* fix sizeof(* tdev) and sizeof(* tdev->tsensor)

Yang Shen (2):
thermal: Add HiSilicon Kunpeng thermal driver
MAINTAINERS: Add maintainers for kunpeng thermal

 MAINTAINERS                       |   7 ++
 drivers/thermal/Kconfig           |   8 ++
 drivers/thermal/Makefile          |   1 +
 drivers/thermal/kunpeng_thermal.c | 219 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 235 insertions(+)
 create mode 100644 drivers/thermal/kunpeng_thermal.c
Quoted 6 lines

--
2.7.4

.

Any comments?

#8 lore raw
Quoted 20 lines · Yang Shen
Quoted 17 lines · Yang Shen

Add HiSilicon Kunpeng thermal driver and Maintainers.

Changelog:
v2:
* fix sizeof(* tdev) and sizeof(* tdev->tsensor)

Yang Shen (2):
thermal: Add HiSilicon Kunpeng thermal driver
MAINTAINERS: Add maintainers for kunpeng thermal

 MAINTAINERS                       |   7 ++
 drivers/thermal/Kconfig           |   8 ++
 drivers/thermal/Makefile          |   1 +
 drivers/thermal/kunpeng_thermal.c | 219 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 235 insertions(+)
 create mode 100644 drivers/thermal/kunpeng_thermal.c
Quoted 8 lines
Quoted 6 lines

--
2.7.4

.

Any comments?

Yes. But for the moment, we are busy preparing the merge window.

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog