1 From 3c847bc6c9d6f4115c82943c869c55244b39a5c4 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 | 109 ++++++++++++++++++++++++++++++++++++++
21 3 files changed, 117 insertions(+)
22 create mode 100644 drivers/thermal/bcm2835-thermal.c
24 --- a/drivers/thermal/Kconfig
25 +++ b/drivers/thermal/Kconfig
26 @@ -302,6 +302,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 @@ -42,6 +42,7 @@ obj-$(CONFIG_MAX77620_THERMAL) += max776
43 obj-$(CONFIG_QORIQ_THERMAL) += qoriq_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 struct thermal_zone_device_ops ops = {
105 + .get_temp = bcm2835_thermal_get_temp,
108 +static int bcm2835_thermal_probe(struct platform_device *pdev)
110 + struct device_node *fw_np;
111 + struct rpi_firmware *fw;
112 + struct thermal_zone_device *tz;
114 + fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
116 + dev_err(&pdev->dev, "Missing firmware node\n");
119 + fw = rpi_firmware_get(fw_np);
121 + return -EPROBE_DEFER;
123 + tz = thermal_zone_device_register("bcm2835_thermal", 0, 0, fw, &ops,
126 + dev_err(&pdev->dev, "Failed to register the thermal device\n");
127 + return PTR_ERR(tz);
130 + platform_set_drvdata(pdev, tz);
135 +static int bcm2835_thermal_remove(struct platform_device *pdev)
137 + thermal_zone_device_unregister(platform_get_drvdata(pdev));
142 +static const struct of_device_id bcm2835_thermal_of_match_table[] = {
143 + { .compatible = "brcm,bcm2835-thermal", },
146 +MODULE_DEVICE_TABLE(of, bcm2835_thermal_of_match_table);
148 +static struct platform_driver bcm2835_thermal_driver = {
149 + .probe = bcm2835_thermal_probe,
150 + .remove = bcm2835_thermal_remove,
152 + .name = "bcm2835_thermal",
153 + .of_match_table = bcm2835_thermal_of_match_table,
156 +module_platform_driver(bcm2835_thermal_driver);
158 +MODULE_AUTHOR("Dorian Peake");
159 +MODULE_AUTHOR("Noralf Trønnes");
160 +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
161 +MODULE_LICENSE("GPL");