From: Eduardo Valentin <edubezval-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Tao Wang <kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
Cc: rui.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
mark.rutland-5wv7dgnIgG8@public.gmane.org,
xuwei5-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org,
catalin.marinas-5wv7dgnIgG8@public.gmane.org,
will.deacon-5wv7dgnIgG8@public.gmane.org,
linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
sunzhaosheng-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org,
leo.yan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org
Subject: Re: [Patch v2 2/3] thermal: hisilicon: add thermal sensor driver for Hi3660
Date: Fri, 30 Jun 2017 20:04:28 -0700 [thread overview]
Message-ID: <20170701030426.GA11424@localhost.localdomain> (raw)
In-Reply-To: <1498102923-68481-2-git-send-email-kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
Hey Tao,
On Thu, Jun 22, 2017 at 11:42:02AM +0800, Tao Wang wrote:
> This patch adds the support for thermal sensor of Hi3660 SoC.
> this will register sensors for thermal framework and use device
> tree to bind cooling device.
>
> Signed-off-by: Tao Wang <kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
> Signed-off-by: Leo Yan <leo.yan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> Changes in v2:
> - correct alphabet order
> - correct compatible name
>
> drivers/thermal/Kconfig | 10 ++
> drivers/thermal/Makefile | 1 +
> drivers/thermal/hi3660_thermal.c | 198 ++++++++++++++++++++++++++++++++++++++
> 3 files changed, 209 insertions(+)
> create mode 100644 drivers/thermal/hi3660_thermal.c
>
> diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
> index b5b5fac..ed22a90 100644
> --- a/drivers/thermal/Kconfig
> +++ b/drivers/thermal/Kconfig
> @@ -192,6 +192,16 @@ config THERMAL_EMULATION
> because userland can easily disable the thermal policy by simply
> flooding this sysfs node with low temperature values.
>
> +config HI3660_THERMAL
> + tristate "Hi3660 thermal driver"
> + depends on ARCH_HISI || COMPILE_TEST
> + depends on HAS_IOMEM
> + depends on OF
> + default y
> + help
> + Enable this to plug Hi3660 thermal driver into the Linux thermal
> + framework.
> +
> config HISI_THERMAL
> tristate "Hisilicon thermal driver"
> depends on ARCH_HISI || COMPILE_TEST
> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
> index 094d703..f29d0a5 100644
> --- a/drivers/thermal/Makefile
> +++ b/drivers/thermal/Makefile
> @@ -55,6 +55,7 @@ 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-$(CONFIG_HI3660_THERMAL) += hi3660_thermal.o
> 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/hi3660_thermal.c b/drivers/thermal/hi3660_thermal.c
> new file mode 100644
> index 0000000..68fa9018
> --- /dev/null
> +++ b/drivers/thermal/hi3660_thermal.c
> @@ -0,0 +1,198 @@
> +/*
> + * linux/drivers/thermal/hi3660_thermal.c
> + *
> + * Copyright (c) 2017 Hisilicon Limited.
> + * Copyright (c) 2017 Linaro Limited.
> + *
> + * Author: Tao Wang <kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
> + * Author: Leo Yan <leo.yan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 2 of the License.
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/of.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/thermal.h>
> +
> +#include "thermal_core.h"
> +
> +#define HW_MAX_SENSORS 4
> +#define HISI_MAX_SENSORS 6
> +#define SENSOR_MAX 4
> +#define SENSOR_AVG 5
> +
> +#define ADC_MIN 116
> +#define ADC_MAX 922
> +
> +/* hi3660 Thermal Sensor Dev Structure */
> +struct hi3660_thermal_sensor {
> + struct hi3660_thermal_data *thermal;
> + struct thermal_zone_device *tzd;
> +
> + uint32_t id;
> +};
> +
> +struct hi3660_thermal_data {
> + struct platform_device *pdev;
> + struct hi3660_thermal_sensor sensors[HISI_MAX_SENSORS];
> + void __iomem *thermal_base;
> +};
> +
> +unsigned int sensor_reg_offset[HW_MAX_SENSORS] = { 0x1c, 0x5c, 0x9c, 0xdc };
> +
> +
> +static int hi3660_thermal_get_temp(void *_sensor, int *temp)
> +{
> + struct hi3660_thermal_sensor *sensor = _sensor;
> + struct hi3660_thermal_data *data = sensor->thermal;
> + unsigned int idx;
> + int val, average = 0, max = 0;
> +
> + if (sensor->id < HW_MAX_SENSORS) {
> + val = readl(data->thermal_base + sensor_reg_offset[sensor->id]);
> + val = clamp_val(val, ADC_MIN, ADC_MAX);
> + } else {
> + for (idx = 0; idx < HW_MAX_SENSORS; idx++) {
> + val = readl(data->thermal_base
> + + sensor_reg_offset[idx]);
> + val = clamp_val(val, ADC_MIN, ADC_MAX);
> + average += val;
> + if (val > max)
> + max = val;
> + }
> +
> + if (sensor->id == SENSOR_MAX)
> + val = max;
> + else if (sensor->id == SENSOR_AVG)
> + val = average / HW_MAX_SENSORS;
> + }
> +
> + *temp = ((val - ADC_MIN) * 165000) / (ADC_MAX - ADC_MIN) - 40000;
Where do these constants come from (165000 and 40000) can these some how
be rearranged and described in DT (coefficients) and using the offset and slope fields?
> +
> + return 0;
> +}
> +
> +static struct thermal_zone_of_device_ops hi3660_of_thermal_ops = {
> + .get_temp = hi3660_thermal_get_temp,
> +};
> +
> +static int hi3660_thermal_register_sensor(struct platform_device *pdev,
> + struct hi3660_thermal_data *data,
> + struct hi3660_thermal_sensor *sensor,
> + int index)
> +{
> + int ret = 0;
> +
> + sensor->id = index;
> + sensor->thermal = data;
> +
> + sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev,
> + sensor->id, sensor, &hi3660_of_thermal_ops);
> + if (IS_ERR(sensor->tzd)) {
> + ret = PTR_ERR(sensor->tzd);
> + sensor->tzd = NULL;
> + }
> +
> + return ret;
> +}
> +
> +static void hi3660_thermal_toggle_sensor(struct hi3660_thermal_sensor *sensor,
> + bool on)
> +{
> + struct thermal_zone_device *tzd = sensor->tzd;
> +
> + tzd->ops->set_mode(tzd,
> + on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
> +}
> +
> +static int hi3660_thermal_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct hi3660_thermal_data *data;
> + struct resource *res;
> + int ret = 0;
> + int i;
> +
> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + data->pdev = pdev;
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + data->thermal_base = devm_ioremap_resource(dev, res);
> + if (IS_ERR(data->thermal_base)) {
> + dev_err(dev, "failed get reg base\n");
> + return -ENOMEM;
> + }
> +
> + platform_set_drvdata(pdev, data);
> +
> + for (i = 0; i < HISI_MAX_SENSORS; ++i) {
> + ret = hi3660_thermal_register_sensor(pdev, data,
> + &data->sensors[i], i);
> + if (ret)
> + dev_err(&pdev->dev,
> + "failed to register thermal sensor%d: %d\n",
> + i, ret);
Do you really want to continue if some of the sensors fail to register?
> + else
> + hi3660_thermal_toggle_sensor(&data->sensors[i], true);
> + }
> +
> + dev_info(&pdev->dev, "Thermal Sensor Loaded\n");
Do you really need the above info in the kernel log?
> + return 0;
> +}
> +
> +static int hi3660_thermal_exit(struct platform_device *pdev)
> +{
> + struct hi3660_thermal_data *data = platform_get_drvdata(pdev);
> + int i;
> +
> + for (i = 0; i < HISI_MAX_SENSORS; i++) {
> + struct hi3660_thermal_sensor *sensor = &data->sensors[i];
> +
> + if (!sensor->tzd)
> + continue;
Why are you considering a valid case of not registering all expected
sensors?
> +
> + hi3660_thermal_toggle_sensor(sensor, false);
> + }
> +
> + return 0;
> +}
> +
> +static const struct of_device_id hi3660_thermal_id_table[] = {
> + { .compatible = "hisilicon,hi3660-thermal" },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, hi3660_thermal_id_table);
> +
> +static struct platform_driver hi3660_thermal_driver = {
> + .probe = hi3660_thermal_probe,
> + .remove = hi3660_thermal_exit,
> + .driver = {
> + .name = "hi3660_thermal",
> + .of_match_table = hi3660_thermal_id_table,
> + },
> +};
> +
> +module_platform_driver(hi3660_thermal_driver);
> +
> +MODULE_AUTHOR("Tao Wang <kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>");
> +MODULE_AUTHOR("Leo Yan <leo.yan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>");
> +MODULE_DESCRIPTION("hi3660 thermal driver");
> +MODULE_LICENSE("GPL v2");
> --
> 1.7.9.5
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: edubezval@gmail.com (Eduardo Valentin)
To: linux-arm-kernel@lists.infradead.org
Subject: [Patch v2 2/3] thermal: hisilicon: add thermal sensor driver for Hi3660
Date: Fri, 30 Jun 2017 20:04:28 -0700 [thread overview]
Message-ID: <20170701030426.GA11424@localhost.localdomain> (raw)
In-Reply-To: <1498102923-68481-2-git-send-email-kevin.wangtao@hisilicon.com>
Hey Tao,
On Thu, Jun 22, 2017 at 11:42:02AM +0800, Tao Wang wrote:
> This patch adds the support for thermal sensor of Hi3660 SoC.
> this will register sensors for thermal framework and use device
> tree to bind cooling device.
>
> Signed-off-by: Tao Wang <kevin.wangtao@hisilicon.com>
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
> Changes in v2:
> - correct alphabet order
> - correct compatible name
>
> drivers/thermal/Kconfig | 10 ++
> drivers/thermal/Makefile | 1 +
> drivers/thermal/hi3660_thermal.c | 198 ++++++++++++++++++++++++++++++++++++++
> 3 files changed, 209 insertions(+)
> create mode 100644 drivers/thermal/hi3660_thermal.c
>
> diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
> index b5b5fac..ed22a90 100644
> --- a/drivers/thermal/Kconfig
> +++ b/drivers/thermal/Kconfig
> @@ -192,6 +192,16 @@ config THERMAL_EMULATION
> because userland can easily disable the thermal policy by simply
> flooding this sysfs node with low temperature values.
>
> +config HI3660_THERMAL
> + tristate "Hi3660 thermal driver"
> + depends on ARCH_HISI || COMPILE_TEST
> + depends on HAS_IOMEM
> + depends on OF
> + default y
> + help
> + Enable this to plug Hi3660 thermal driver into the Linux thermal
> + framework.
> +
> config HISI_THERMAL
> tristate "Hisilicon thermal driver"
> depends on ARCH_HISI || COMPILE_TEST
> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
> index 094d703..f29d0a5 100644
> --- a/drivers/thermal/Makefile
> +++ b/drivers/thermal/Makefile
> @@ -55,6 +55,7 @@ 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-$(CONFIG_HI3660_THERMAL) += hi3660_thermal.o
> 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/hi3660_thermal.c b/drivers/thermal/hi3660_thermal.c
> new file mode 100644
> index 0000000..68fa9018
> --- /dev/null
> +++ b/drivers/thermal/hi3660_thermal.c
> @@ -0,0 +1,198 @@
> +/*
> + * linux/drivers/thermal/hi3660_thermal.c
> + *
> + * Copyright (c) 2017 Hisilicon Limited.
> + * Copyright (c) 2017 Linaro Limited.
> + *
> + * Author: Tao Wang <kevin.wangtao@hisilicon.com>
> + * Author: Leo Yan <leo.yan@linaro.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 2 of the License.
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/of.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/thermal.h>
> +
> +#include "thermal_core.h"
> +
> +#define HW_MAX_SENSORS 4
> +#define HISI_MAX_SENSORS 6
> +#define SENSOR_MAX 4
> +#define SENSOR_AVG 5
> +
> +#define ADC_MIN 116
> +#define ADC_MAX 922
> +
> +/* hi3660 Thermal Sensor Dev Structure */
> +struct hi3660_thermal_sensor {
> + struct hi3660_thermal_data *thermal;
> + struct thermal_zone_device *tzd;
> +
> + uint32_t id;
> +};
> +
> +struct hi3660_thermal_data {
> + struct platform_device *pdev;
> + struct hi3660_thermal_sensor sensors[HISI_MAX_SENSORS];
> + void __iomem *thermal_base;
> +};
> +
> +unsigned int sensor_reg_offset[HW_MAX_SENSORS] = { 0x1c, 0x5c, 0x9c, 0xdc };
> +
> +
> +static int hi3660_thermal_get_temp(void *_sensor, int *temp)
> +{
> + struct hi3660_thermal_sensor *sensor = _sensor;
> + struct hi3660_thermal_data *data = sensor->thermal;
> + unsigned int idx;
> + int val, average = 0, max = 0;
> +
> + if (sensor->id < HW_MAX_SENSORS) {
> + val = readl(data->thermal_base + sensor_reg_offset[sensor->id]);
> + val = clamp_val(val, ADC_MIN, ADC_MAX);
> + } else {
> + for (idx = 0; idx < HW_MAX_SENSORS; idx++) {
> + val = readl(data->thermal_base
> + + sensor_reg_offset[idx]);
> + val = clamp_val(val, ADC_MIN, ADC_MAX);
> + average += val;
> + if (val > max)
> + max = val;
> + }
> +
> + if (sensor->id == SENSOR_MAX)
> + val = max;
> + else if (sensor->id == SENSOR_AVG)
> + val = average / HW_MAX_SENSORS;
> + }
> +
> + *temp = ((val - ADC_MIN) * 165000) / (ADC_MAX - ADC_MIN) - 40000;
Where do these constants come from (165000 and 40000) can these some how
be rearranged and described in DT (coefficients) and using the offset and slope fields?
> +
> + return 0;
> +}
> +
> +static struct thermal_zone_of_device_ops hi3660_of_thermal_ops = {
> + .get_temp = hi3660_thermal_get_temp,
> +};
> +
> +static int hi3660_thermal_register_sensor(struct platform_device *pdev,
> + struct hi3660_thermal_data *data,
> + struct hi3660_thermal_sensor *sensor,
> + int index)
> +{
> + int ret = 0;
> +
> + sensor->id = index;
> + sensor->thermal = data;
> +
> + sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev,
> + sensor->id, sensor, &hi3660_of_thermal_ops);
> + if (IS_ERR(sensor->tzd)) {
> + ret = PTR_ERR(sensor->tzd);
> + sensor->tzd = NULL;
> + }
> +
> + return ret;
> +}
> +
> +static void hi3660_thermal_toggle_sensor(struct hi3660_thermal_sensor *sensor,
> + bool on)
> +{
> + struct thermal_zone_device *tzd = sensor->tzd;
> +
> + tzd->ops->set_mode(tzd,
> + on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
> +}
> +
> +static int hi3660_thermal_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct hi3660_thermal_data *data;
> + struct resource *res;
> + int ret = 0;
> + int i;
> +
> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + data->pdev = pdev;
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + data->thermal_base = devm_ioremap_resource(dev, res);
> + if (IS_ERR(data->thermal_base)) {
> + dev_err(dev, "failed get reg base\n");
> + return -ENOMEM;
> + }
> +
> + platform_set_drvdata(pdev, data);
> +
> + for (i = 0; i < HISI_MAX_SENSORS; ++i) {
> + ret = hi3660_thermal_register_sensor(pdev, data,
> + &data->sensors[i], i);
> + if (ret)
> + dev_err(&pdev->dev,
> + "failed to register thermal sensor%d: %d\n",
> + i, ret);
Do you really want to continue if some of the sensors fail to register?
> + else
> + hi3660_thermal_toggle_sensor(&data->sensors[i], true);
> + }
> +
> + dev_info(&pdev->dev, "Thermal Sensor Loaded\n");
Do you really need the above info in the kernel log?
> + return 0;
> +}
> +
> +static int hi3660_thermal_exit(struct platform_device *pdev)
> +{
> + struct hi3660_thermal_data *data = platform_get_drvdata(pdev);
> + int i;
> +
> + for (i = 0; i < HISI_MAX_SENSORS; i++) {
> + struct hi3660_thermal_sensor *sensor = &data->sensors[i];
> +
> + if (!sensor->tzd)
> + continue;
Why are you considering a valid case of not registering all expected
sensors?
> +
> + hi3660_thermal_toggle_sensor(sensor, false);
> + }
> +
> + return 0;
> +}
> +
> +static const struct of_device_id hi3660_thermal_id_table[] = {
> + { .compatible = "hisilicon,hi3660-thermal" },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, hi3660_thermal_id_table);
> +
> +static struct platform_driver hi3660_thermal_driver = {
> + .probe = hi3660_thermal_probe,
> + .remove = hi3660_thermal_exit,
> + .driver = {
> + .name = "hi3660_thermal",
> + .of_match_table = hi3660_thermal_id_table,
> + },
> +};
> +
> +module_platform_driver(hi3660_thermal_driver);
> +
> +MODULE_AUTHOR("Tao Wang <kevin.wangtao@hisilicon.com>");
> +MODULE_AUTHOR("Leo Yan <leo.yan@linaro.org>");
> +MODULE_DESCRIPTION("hi3660 thermal driver");
> +MODULE_LICENSE("GPL v2");
> --
> 1.7.9.5
>
WARNING: multiple messages have this Message-ID (diff)
From: Eduardo Valentin <edubezval@gmail.com>
To: Tao Wang <kevin.wangtao@hisilicon.com>
Cc: rui.zhang@intel.com, robh+dt@kernel.org, mark.rutland@arm.com,
xuwei5@hisilicon.com, catalin.marinas@arm.com,
will.deacon@arm.com, linux-pm@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, sunzhaosheng@hisilicon.com,
leo.yan@linaro.org
Subject: Re: [Patch v2 2/3] thermal: hisilicon: add thermal sensor driver for Hi3660
Date: Fri, 30 Jun 2017 20:04:28 -0700 [thread overview]
Message-ID: <20170701030426.GA11424@localhost.localdomain> (raw)
In-Reply-To: <1498102923-68481-2-git-send-email-kevin.wangtao@hisilicon.com>
Hey Tao,
On Thu, Jun 22, 2017 at 11:42:02AM +0800, Tao Wang wrote:
> This patch adds the support for thermal sensor of Hi3660 SoC.
> this will register sensors for thermal framework and use device
> tree to bind cooling device.
>
> Signed-off-by: Tao Wang <kevin.wangtao@hisilicon.com>
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
> Changes in v2:
> - correct alphabet order
> - correct compatible name
>
> drivers/thermal/Kconfig | 10 ++
> drivers/thermal/Makefile | 1 +
> drivers/thermal/hi3660_thermal.c | 198 ++++++++++++++++++++++++++++++++++++++
> 3 files changed, 209 insertions(+)
> create mode 100644 drivers/thermal/hi3660_thermal.c
>
> diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
> index b5b5fac..ed22a90 100644
> --- a/drivers/thermal/Kconfig
> +++ b/drivers/thermal/Kconfig
> @@ -192,6 +192,16 @@ config THERMAL_EMULATION
> because userland can easily disable the thermal policy by simply
> flooding this sysfs node with low temperature values.
>
> +config HI3660_THERMAL
> + tristate "Hi3660 thermal driver"
> + depends on ARCH_HISI || COMPILE_TEST
> + depends on HAS_IOMEM
> + depends on OF
> + default y
> + help
> + Enable this to plug Hi3660 thermal driver into the Linux thermal
> + framework.
> +
> config HISI_THERMAL
> tristate "Hisilicon thermal driver"
> depends on ARCH_HISI || COMPILE_TEST
> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
> index 094d703..f29d0a5 100644
> --- a/drivers/thermal/Makefile
> +++ b/drivers/thermal/Makefile
> @@ -55,6 +55,7 @@ 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-$(CONFIG_HI3660_THERMAL) += hi3660_thermal.o
> 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/hi3660_thermal.c b/drivers/thermal/hi3660_thermal.c
> new file mode 100644
> index 0000000..68fa9018
> --- /dev/null
> +++ b/drivers/thermal/hi3660_thermal.c
> @@ -0,0 +1,198 @@
> +/*
> + * linux/drivers/thermal/hi3660_thermal.c
> + *
> + * Copyright (c) 2017 Hisilicon Limited.
> + * Copyright (c) 2017 Linaro Limited.
> + *
> + * Author: Tao Wang <kevin.wangtao@hisilicon.com>
> + * Author: Leo Yan <leo.yan@linaro.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 2 of the License.
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/of.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/thermal.h>
> +
> +#include "thermal_core.h"
> +
> +#define HW_MAX_SENSORS 4
> +#define HISI_MAX_SENSORS 6
> +#define SENSOR_MAX 4
> +#define SENSOR_AVG 5
> +
> +#define ADC_MIN 116
> +#define ADC_MAX 922
> +
> +/* hi3660 Thermal Sensor Dev Structure */
> +struct hi3660_thermal_sensor {
> + struct hi3660_thermal_data *thermal;
> + struct thermal_zone_device *tzd;
> +
> + uint32_t id;
> +};
> +
> +struct hi3660_thermal_data {
> + struct platform_device *pdev;
> + struct hi3660_thermal_sensor sensors[HISI_MAX_SENSORS];
> + void __iomem *thermal_base;
> +};
> +
> +unsigned int sensor_reg_offset[HW_MAX_SENSORS] = { 0x1c, 0x5c, 0x9c, 0xdc };
> +
> +
> +static int hi3660_thermal_get_temp(void *_sensor, int *temp)
> +{
> + struct hi3660_thermal_sensor *sensor = _sensor;
> + struct hi3660_thermal_data *data = sensor->thermal;
> + unsigned int idx;
> + int val, average = 0, max = 0;
> +
> + if (sensor->id < HW_MAX_SENSORS) {
> + val = readl(data->thermal_base + sensor_reg_offset[sensor->id]);
> + val = clamp_val(val, ADC_MIN, ADC_MAX);
> + } else {
> + for (idx = 0; idx < HW_MAX_SENSORS; idx++) {
> + val = readl(data->thermal_base
> + + sensor_reg_offset[idx]);
> + val = clamp_val(val, ADC_MIN, ADC_MAX);
> + average += val;
> + if (val > max)
> + max = val;
> + }
> +
> + if (sensor->id == SENSOR_MAX)
> + val = max;
> + else if (sensor->id == SENSOR_AVG)
> + val = average / HW_MAX_SENSORS;
> + }
> +
> + *temp = ((val - ADC_MIN) * 165000) / (ADC_MAX - ADC_MIN) - 40000;
Where do these constants come from (165000 and 40000) can these some how
be rearranged and described in DT (coefficients) and using the offset and slope fields?
> +
> + return 0;
> +}
> +
> +static struct thermal_zone_of_device_ops hi3660_of_thermal_ops = {
> + .get_temp = hi3660_thermal_get_temp,
> +};
> +
> +static int hi3660_thermal_register_sensor(struct platform_device *pdev,
> + struct hi3660_thermal_data *data,
> + struct hi3660_thermal_sensor *sensor,
> + int index)
> +{
> + int ret = 0;
> +
> + sensor->id = index;
> + sensor->thermal = data;
> +
> + sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev,
> + sensor->id, sensor, &hi3660_of_thermal_ops);
> + if (IS_ERR(sensor->tzd)) {
> + ret = PTR_ERR(sensor->tzd);
> + sensor->tzd = NULL;
> + }
> +
> + return ret;
> +}
> +
> +static void hi3660_thermal_toggle_sensor(struct hi3660_thermal_sensor *sensor,
> + bool on)
> +{
> + struct thermal_zone_device *tzd = sensor->tzd;
> +
> + tzd->ops->set_mode(tzd,
> + on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
> +}
> +
> +static int hi3660_thermal_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct hi3660_thermal_data *data;
> + struct resource *res;
> + int ret = 0;
> + int i;
> +
> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + data->pdev = pdev;
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + data->thermal_base = devm_ioremap_resource(dev, res);
> + if (IS_ERR(data->thermal_base)) {
> + dev_err(dev, "failed get reg base\n");
> + return -ENOMEM;
> + }
> +
> + platform_set_drvdata(pdev, data);
> +
> + for (i = 0; i < HISI_MAX_SENSORS; ++i) {
> + ret = hi3660_thermal_register_sensor(pdev, data,
> + &data->sensors[i], i);
> + if (ret)
> + dev_err(&pdev->dev,
> + "failed to register thermal sensor%d: %d\n",
> + i, ret);
Do you really want to continue if some of the sensors fail to register?
> + else
> + hi3660_thermal_toggle_sensor(&data->sensors[i], true);
> + }
> +
> + dev_info(&pdev->dev, "Thermal Sensor Loaded\n");
Do you really need the above info in the kernel log?
> + return 0;
> +}
> +
> +static int hi3660_thermal_exit(struct platform_device *pdev)
> +{
> + struct hi3660_thermal_data *data = platform_get_drvdata(pdev);
> + int i;
> +
> + for (i = 0; i < HISI_MAX_SENSORS; i++) {
> + struct hi3660_thermal_sensor *sensor = &data->sensors[i];
> +
> + if (!sensor->tzd)
> + continue;
Why are you considering a valid case of not registering all expected
sensors?
> +
> + hi3660_thermal_toggle_sensor(sensor, false);
> + }
> +
> + return 0;
> +}
> +
> +static const struct of_device_id hi3660_thermal_id_table[] = {
> + { .compatible = "hisilicon,hi3660-thermal" },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, hi3660_thermal_id_table);
> +
> +static struct platform_driver hi3660_thermal_driver = {
> + .probe = hi3660_thermal_probe,
> + .remove = hi3660_thermal_exit,
> + .driver = {
> + .name = "hi3660_thermal",
> + .of_match_table = hi3660_thermal_id_table,
> + },
> +};
> +
> +module_platform_driver(hi3660_thermal_driver);
> +
> +MODULE_AUTHOR("Tao Wang <kevin.wangtao@hisilicon.com>");
> +MODULE_AUTHOR("Leo Yan <leo.yan@linaro.org>");
> +MODULE_DESCRIPTION("hi3660 thermal driver");
> +MODULE_LICENSE("GPL v2");
> --
> 1.7.9.5
>
next prev parent reply other threads:[~2017-07-01 3:04 UTC|newest]
Thread overview: 113+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-20 3:40 [PATCH 1/3] dt-bindings: Document the hi3660 thermal sensor bindings Tao Wang
2017-06-20 3:40 ` Tao Wang
2017-06-20 3:40 ` Tao Wang
2017-06-20 3:40 ` [PATCH 2/3] thermal: hisilicon: add thermal sensor driver for Hi3660 Tao Wang
2017-06-20 3:40 ` Tao Wang
2017-06-20 3:40 ` Tao Wang
[not found] ` <1497930035-60894-2-git-send-email-kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
2017-06-20 10:31 ` Wei Xu
2017-06-20 10:31 ` Wei Xu
2017-06-20 10:31 ` Wei Xu
[not found] ` <5948F983.5060902-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
2017-06-21 2:21 ` Wangtao (Kevin, Kirin)
2017-06-21 2:21 ` Wangtao (Kevin, Kirin)
2017-06-21 2:21 ` Wangtao (Kevin, Kirin)
2017-06-21 2:21 ` Wangtao (Kevin, Kirin)
2017-06-21 2:29 ` Leo Yan
2017-06-21 2:29 ` Leo Yan
2017-06-21 2:29 ` Leo Yan
2017-06-20 3:40 ` [PATCH 3/3] arm64: dts: register Hi3660's thermal sensor Tao Wang
2017-06-20 3:40 ` Tao Wang
2017-06-20 3:40 ` Tao Wang
2017-06-20 7:38 ` Guodong Xu
2017-06-20 8:32 ` Wangtao (Kevin, Kirin)
2017-06-20 8:32 ` Wangtao (Kevin, Kirin)
2017-06-20 8:32 ` Wangtao (Kevin, Kirin)
[not found] ` <7abe5b01-c728-accd-d6bb-05d9ceee2176-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
2017-06-21 1:58 ` Guodong Xu
2017-06-21 1:58 ` Guodong Xu
2017-06-21 1:58 ` Guodong Xu
2017-06-22 3:42 ` [Patch v2 1/3] dt-bindings: Document the hi3660 thermal sensor bindings Tao Wang
2017-06-22 3:42 ` Tao Wang
2017-06-22 3:42 ` Tao Wang
2017-06-22 3:42 ` [Patch v2 2/3] thermal: hisilicon: add thermal sensor driver for Hi3660 Tao Wang
2017-06-22 3:42 ` Tao Wang
2017-06-22 3:42 ` Tao Wang
[not found] ` <1498102923-68481-2-git-send-email-kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
2017-07-01 3:04 ` Eduardo Valentin [this message]
2017-07-01 3:04 ` Eduardo Valentin
2017-07-01 3:04 ` Eduardo Valentin
2017-07-04 11:24 ` Wangtao (Kevin, Kirin)
2017-07-04 11:24 ` Wangtao (Kevin, Kirin)
2017-06-22 3:42 ` [Patch v2 3/3] arm64: dts: register Hi3660's thermal sensor Tao Wang
2017-06-22 3:42 ` Tao Wang
2017-06-22 3:42 ` Tao Wang
2017-07-01 3:06 ` Eduardo Valentin
2017-07-01 3:06 ` Eduardo Valentin
[not found] ` <20170701030613.GC11424-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2017-07-04 10:50 ` 答复: " Wangtao (Kevin, Kirin)
2017-07-04 10:50 ` Wangtao (Kevin, Kirin)
2017-07-04 10:50 ` Wangtao (Kevin, Kirin)
2017-07-01 3:05 ` [Patch v2 1/3] dt-bindings: Document the hi3660 thermal sensor bindings Eduardo Valentin
2017-07-01 3:05 ` Eduardo Valentin
[not found] ` <20170701030534.GB11424-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2017-07-04 11:03 ` Wangtao (Kevin, Kirin)
2017-07-04 11:03 ` Wangtao (Kevin, Kirin)
2017-07-04 11:03 ` Wangtao (Kevin, Kirin)
2017-08-10 8:32 ` [PATCH v3 0/3] thermal: add thermal sensor driver for Hi3660 Tao Wang
2017-08-10 8:32 ` Tao Wang
2017-08-10 8:32 ` Tao Wang
2017-08-10 8:32 ` [PATCH v3 1/3] dt-bindings: Document the hi3660 thermal sensor bindings Tao Wang
2017-08-10 8:32 ` Tao Wang
2017-08-10 8:32 ` Tao Wang
2017-08-17 15:10 ` Rob Herring
2017-08-17 15:10 ` Rob Herring
2017-08-21 2:17 ` Wangtao (Kevin, Kirin)
2017-08-21 2:17 ` Wangtao (Kevin, Kirin)
2017-08-21 2:17 ` Wangtao (Kevin, Kirin)
2017-08-29 8:17 ` [PATCH v4 0/3] thermal: add thermal sensor driver for Hi3660 Tao Wang
2017-08-29 8:17 ` Tao Wang
2017-08-29 8:17 ` Tao Wang
2017-08-29 8:17 ` [PATCH v4 1/3] dt-bindings: Document the hi3660 thermal sensor bindings Tao Wang
2017-08-29 8:17 ` Tao Wang
2017-08-29 8:17 ` Tao Wang
2017-08-31 18:24 ` Daniel Lezcano
2017-08-31 18:24 ` Daniel Lezcano
2017-09-04 6:39 ` Wangtao (Kevin, Kirin)
2017-09-04 6:39 ` Wangtao (Kevin, Kirin)
2017-09-04 6:39 ` Wangtao (Kevin, Kirin)
[not found] ` <38fdf052-97be-1b54-5e7d-9dd0bc11e9b4-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
2017-09-04 10:36 ` Daniel Lezcano
2017-09-04 10:36 ` Daniel Lezcano
2017-09-04 10:36 ` Daniel Lezcano
2017-08-29 8:17 ` [PATCH v4 2/3] thermal: hisilicon: add thermal sensor driver for Hi3660 Tao Wang
2017-08-29 8:17 ` Tao Wang
2017-08-29 8:17 ` Tao Wang
2017-08-31 21:17 ` Daniel Lezcano
2017-08-31 21:17 ` Daniel Lezcano
2017-08-31 21:17 ` Daniel Lezcano
2017-09-04 7:56 ` Wangtao (Kevin, Kirin)
2017-09-04 7:56 ` Wangtao (Kevin, Kirin)
2017-09-04 7:56 ` Wangtao (Kevin, Kirin)
2017-09-04 11:06 ` Daniel Lezcano
2017-09-04 11:06 ` Daniel Lezcano
[not found] ` <8fe3ad22-59db-40c6-18db-7b6859f05a95-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-09-04 15:06 ` Leo Yan
2017-09-04 15:06 ` Leo Yan
2017-09-04 15:06 ` Leo Yan
2017-09-05 7:56 ` Wangtao (Kevin, Kirin)
2017-09-05 7:56 ` Wangtao (Kevin, Kirin)
2017-09-05 7:56 ` Wangtao (Kevin, Kirin)
2017-08-29 8:17 ` [PATCH v4 3/3] arm64: dts: register Hi3660's thermal sensor Tao Wang
2017-08-29 8:17 ` Tao Wang
2017-08-29 8:17 ` Tao Wang
2017-08-31 21:13 ` Daniel Lezcano
2017-08-31 21:13 ` Daniel Lezcano
2017-09-04 8:11 ` Wangtao (Kevin, Kirin)
2017-09-04 8:11 ` Wangtao (Kevin, Kirin)
2017-09-04 8:11 ` Wangtao (Kevin, Kirin)
[not found] ` <1502353935-92924-1-git-send-email-kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
2017-08-10 8:32 ` [PATCH v3 2/3] thermal: hisilicon: add thermal sensor driver for Hi3660 Tao Wang
2017-08-10 8:32 ` Tao Wang
2017-08-10 8:32 ` Tao Wang
2017-08-10 8:32 ` [PATCH v3 3/3] arm64: dts: register Hi3660's thermal sensor Tao Wang
2017-08-10 8:32 ` Tao Wang
2017-08-10 8:32 ` Tao Wang
2017-06-20 10:27 ` [PATCH 1/3] dt-bindings: Document the hi3660 thermal sensor bindings Wei Xu
2017-06-20 10:27 ` Wei Xu
2017-06-20 10:27 ` Wei Xu
2017-06-21 2:10 ` Wangtao (Kevin, Kirin)
2017-06-21 2:10 ` Wangtao (Kevin, Kirin)
2017-06-21 2:10 ` Wangtao (Kevin, Kirin)
2017-06-21 2:10 ` Wangtao (Kevin, Kirin)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170701030426.GA11424@localhost.localdomain \
--to=edubezval-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=catalin.marinas-5wv7dgnIgG8@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
--cc=leo.yan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=rui.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=sunzhaosheng-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
--cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
--cc=xuwei5-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.