1 From 688fec3024a2648a48396168a73ada00131682e1 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Tue, 26 Mar 2013 19:24:24 +0000
4 Subject: [PATCH] Added hwmon/thermal driver for reporting core temperature.
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 BCM270x: Move thermal sensor to Device Tree
12 Add Device Tree support to bcm2835-thermal driver.
13 Add thermal sensor device to Device Tree.
14 Don't add platform device when booting in DT mode.
16 Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
18 drivers/thermal/Kconfig | 7 ++
19 drivers/thermal/Makefile | 1 +
20 drivers/thermal/bcm2835-thermal.c | 141 ++++++++++++++++++++++++++++++++++++++
21 3 files changed, 149 insertions(+)
22 create mode 100644 drivers/thermal/bcm2835-thermal.c
24 --- a/drivers/thermal/Kconfig
25 +++ b/drivers/thermal/Kconfig
26 @@ -285,6 +285,13 @@ config INTEL_POWERCLAMP
27 enforce idle time which results in more package C-state residency. The
28 user interface is exposed via generic thermal framework.
30 +config THERMAL_BCM2835
31 + depends on RASPBERRYPI_FIRMWARE
32 + tristate "BCM2835 Thermal Driver"
34 + This will enable temperature monitoring for the Broadcom BCM2835
35 + chip. If built as a module, it will be called 'bcm2835-thermal'.
37 config X86_PKG_TEMP_THERMAL
38 tristate "X86 package temperature thermal driver"
39 depends on X86_THERMAL_VECTOR
40 --- a/drivers/thermal/Makefile
41 +++ b/drivers/thermal/Makefile
42 @@ -38,6 +38,7 @@ obj-$(CONFIG_ARMADA_THERMAL) += armada_t
43 obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
44 obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
45 obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
46 +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
47 obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
48 obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.o
49 obj-$(CONFIG_INTEL_SOC_DTS_THERMAL) += intel_soc_dts_thermal.o
51 +++ b/drivers/thermal/bcm2835-thermal.c
53 +/*****************************************************************************
54 +* Copyright 2011 Broadcom Corporation. All rights reserved.
56 +* Unless you and Broadcom execute a separate written software license
57 +* agreement governing use of this software, this software is licensed to you
58 +* under the terms of the GNU General Public License version 2, available at
59 +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
61 +* Notwithstanding the above, under no circumstances may you combine this
62 +* software in any way with any other Broadcom software provided under a
63 +* license other than the GPL, without Broadcom's express prior written
65 +*****************************************************************************/
67 +#include <linux/module.h>
68 +#include <linux/platform_device.h>
69 +#include <linux/thermal.h>
70 +#include <soc/bcm2835/raspberrypi-firmware.h>
72 +static int bcm2835_thermal_get_property(struct thermal_zone_device *tz,
75 + struct rpi_firmware *fw = tz->devdata;
84 + ret = rpi_firmware_property(fw, tag, &packet, sizeof(packet));
86 + dev_err(&tz->device, "Failed to get temperature\n");
91 + dev_dbg(&tz->device, "%stemp=%d\n",
92 + tag == RPI_FIRMWARE_GET_MAX_TEMPERATURE ? "max" : "", *temp);
97 +static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz,
100 + return bcm2835_thermal_get_property(tz, temp,
101 + RPI_FIRMWARE_GET_TEMPERATURE);
104 +static int bcm2835_thermal_get_max_temp(struct thermal_zone_device *tz,
105 + int trip, int *temp)
108 + * The maximum safe temperature of the SoC.
109 + * Overclock may be disabled above this temperature.
111 + return bcm2835_thermal_get_property(tz, temp,
112 + RPI_FIRMWARE_GET_MAX_TEMPERATURE);
115 +static int bcm2835_thermal_get_trip_type(struct thermal_zone_device *tz,
116 + int trip, enum thermal_trip_type *type)
118 + *type = THERMAL_TRIP_HOT;
123 +static int bcm2835_thermal_get_mode(struct thermal_zone_device *tz,
124 + enum thermal_device_mode *mode)
126 + *mode = THERMAL_DEVICE_ENABLED;
131 +static struct thermal_zone_device_ops ops = {
132 + .get_temp = bcm2835_thermal_get_temp,
133 + .get_trip_temp = bcm2835_thermal_get_max_temp,
134 + .get_trip_type = bcm2835_thermal_get_trip_type,
135 + .get_mode = bcm2835_thermal_get_mode,
138 +static int bcm2835_thermal_probe(struct platform_device *pdev)
140 + struct device_node *fw_np;
141 + struct rpi_firmware *fw;
142 + struct thermal_zone_device *tz;
144 + fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
145 +/* Remove comment when booting without Device Tree is no longer supported
147 + dev_err(&pdev->dev, "Missing firmware node\n");
151 + fw = rpi_firmware_get(fw_np);
153 + return -EPROBE_DEFER;
155 + tz = thermal_zone_device_register("bcm2835_thermal", 1, 0, fw, &ops,
158 + dev_err(&pdev->dev, "Failed to register the thermal device\n");
159 + return PTR_ERR(tz);
162 + platform_set_drvdata(pdev, tz);
167 +static int bcm2835_thermal_remove(struct platform_device *pdev)
169 + thermal_zone_device_unregister(platform_get_drvdata(pdev));
174 +static const struct of_device_id bcm2835_thermal_of_match_table[] = {
175 + { .compatible = "brcm,bcm2835-thermal", },
178 +MODULE_DEVICE_TABLE(of, bcm2835_thermal_of_match_table);
180 +static struct platform_driver bcm2835_thermal_driver = {
181 + .probe = bcm2835_thermal_probe,
182 + .remove = bcm2835_thermal_remove,
184 + .name = "bcm2835_thermal",
185 + .of_match_table = bcm2835_thermal_of_match_table,
188 +module_platform_driver(bcm2835_thermal_driver);
190 +MODULE_AUTHOR("Dorian Peake");
191 +MODULE_AUTHOR("Noralf Trønnes");
192 +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
193 +MODULE_LICENSE("GPL");