1 From a94cb7eeecc4104a6874339f90c5d0647359c102 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Mon, 3 Apr 2017 17:48:29 +0200
4 Subject: [PATCH] thermal: broadcom: add Northstar thermal driver
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Northstar is a SoC family commonly used in home routers. This commit
10 adds a driver for checking CPU temperature. As Northstar Plus seems to
11 also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.
13 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
14 Signed-off-by: Jon Mason <jon.mason@broadcom.com>
15 Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
17 drivers/thermal/Kconfig | 5 ++
18 drivers/thermal/Makefile | 1 +
19 drivers/thermal/broadcom/Kconfig | 8 +++
20 drivers/thermal/broadcom/Makefile | 1 +
21 drivers/thermal/broadcom/ns-thermal.c | 105 ++++++++++++++++++++++++++++++++++
22 5 files changed, 120 insertions(+)
23 create mode 100644 drivers/thermal/broadcom/Kconfig
24 create mode 100644 drivers/thermal/broadcom/Makefile
25 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
27 --- a/drivers/thermal/Kconfig
28 +++ b/drivers/thermal/Kconfig
29 @@ -365,6 +365,11 @@ config INTEL_PCH_THERMAL
30 Thermal reporting device will provide temperature reading,
31 programmable trip points and other information.
33 +menu "Broadcom thermal drivers"
34 +depends on ARCH_BCM || COMPILE_TEST
35 +source "drivers/thermal/broadcom/Kconfig"
38 menu "Texas Instruments thermal drivers"
39 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
40 source "drivers/thermal/ti-soc-thermal/Kconfig"
41 --- a/drivers/thermal/Makefile
42 +++ b/drivers/thermal/Makefile
43 @@ -26,6 +26,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL) += c
44 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
46 # platform thermal drivers
48 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o
49 obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o
50 obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o
52 +++ b/drivers/thermal/broadcom/Kconfig
54 +config BCM_NS_THERMAL
55 + tristate "Northstar thermal driver"
56 + depends on ARCH_BCM_IPROC || COMPILE_TEST
58 + Northstar is a family of SoCs that includes e.g. BCM4708, BCM47081,
59 + BCM4709 and BCM47094. It contains DMU (Device Management Unit) block
60 + with a thermal sensor that allows checking CPU temperature. This
61 + driver provides support for it.
63 +++ b/drivers/thermal/broadcom/Makefile
65 +obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o
67 +++ b/drivers/thermal/broadcom/ns-thermal.c
70 + * Copyright (C) 2017 Rafał Miłecki <rafal@milecki.pl>
72 + * This program is free software; you can redistribute it and/or modify
73 + * it under the terms of the GNU General Public License version 2 as
74 + * published by the Free Software Foundation.
77 +#include <linux/module.h>
78 +#include <linux/of_address.h>
79 +#include <linux/platform_device.h>
80 +#include <linux/thermal.h>
82 +#define PVTMON_CONTROL0 0x00
83 +#define PVTMON_CONTROL0_SEL_MASK 0x0000000e
84 +#define PVTMON_CONTROL0_SEL_TEMP_MONITOR 0x00000000
85 +#define PVTMON_CONTROL0_SEL_TEST_MODE 0x0000000e
86 +#define PVTMON_STATUS 0x08
89 + struct thermal_zone_device *tz;
90 + void __iomem *pvtmon;
93 +static int ns_thermal_get_temp(void *data, int *temp)
95 + struct ns_thermal *ns_thermal = data;
96 + int offset = thermal_zone_get_offset(ns_thermal->tz);
97 + int slope = thermal_zone_get_slope(ns_thermal->tz);
100 + val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
101 + if ((val & PVTMON_CONTROL0_SEL_MASK) != PVTMON_CONTROL0_SEL_TEMP_MONITOR) {
102 + /* Clear current mode selection */
103 + val &= ~PVTMON_CONTROL0_SEL_MASK;
105 + /* Set temp monitor mode (it's the default actually) */
106 + val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;
108 + writel(val, ns_thermal->pvtmon + PVTMON_CONTROL0);
111 + val = readl(ns_thermal->pvtmon + PVTMON_STATUS);
112 + *temp = slope * val + offset;
117 +static const struct thermal_zone_of_device_ops ns_thermal_ops = {
118 + .get_temp = ns_thermal_get_temp,
121 +static int ns_thermal_probe(struct platform_device *pdev)
123 + struct device *dev = &pdev->dev;
124 + struct ns_thermal *ns_thermal;
126 + ns_thermal = devm_kzalloc(dev, sizeof(*ns_thermal), GFP_KERNEL);
130 + ns_thermal->pvtmon = of_iomap(dev_of_node(dev), 0);
131 + if (WARN_ON(!ns_thermal->pvtmon))
134 + ns_thermal->tz = devm_thermal_zone_of_sensor_register(dev, 0,
137 + if (IS_ERR(ns_thermal->tz)) {
138 + iounmap(ns_thermal->pvtmon);
139 + return PTR_ERR(ns_thermal->tz);
142 + platform_set_drvdata(pdev, ns_thermal);
147 +static int ns_thermal_remove(struct platform_device *pdev)
149 + struct ns_thermal *ns_thermal = platform_get_drvdata(pdev);
151 + iounmap(ns_thermal->pvtmon);
156 +static const struct of_device_id ns_thermal_of_match[] = {
157 + { .compatible = "brcm,ns-thermal", },
160 +MODULE_DEVICE_TABLE(of, ns_thermal_of_match);
162 +static struct platform_driver ns_thermal_driver = {
163 + .probe = ns_thermal_probe,
164 + .remove = ns_thermal_remove,
166 + .name = "ns-thermal",
167 + .of_match_table = ns_thermal_of_match,
170 +module_platform_driver(ns_thermal_driver);
172 +MODULE_DESCRIPTION("Northstar thermal driver");
173 +MODULE_LICENSE("GPL v2");