ff6084fe6a8a202d38defaf6c101285b6c92c61f
[openwrt/staging/neocturne.git] /
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.
5 Thanks Dorian
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 BCM270x: Move thermal sensor to Device Tree
11
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.
15
16 Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
17 ---
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
23
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.
29
30 +config THERMAL_BCM2835
31 + depends on RASPBERRYPI_FIRMWARE
32 + tristate "BCM2835 Thermal Driver"
33 + help
34 + This will enable temperature monitoring for the Broadcom BCM2835
35 + chip. If built as a module, it will be called 'bcm2835-thermal'.
36 +
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 @@ -41,6 +41,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
50 --- /dev/null
51 +++ b/drivers/thermal/bcm2835-thermal.c
52 @@ -0,0 +1,109 @@
53 +/*****************************************************************************
54 +* Copyright 2011 Broadcom Corporation. All rights reserved.
55 +*
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").
60 +*
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
64 +* consent.
65 +*****************************************************************************/
66 +
67 +#include <linux/module.h>
68 +#include <linux/platform_device.h>
69 +#include <linux/thermal.h>
70 +#include <soc/bcm2835/raspberrypi-firmware.h>
71 +
72 +static int bcm2835_thermal_get_property(struct thermal_zone_device *tz,
73 + int *temp, u32 tag)
74 +{
75 + struct rpi_firmware *fw = tz->devdata;
76 + struct {
77 + u32 id;
78 + u32 val;
79 + } packet;
80 + int ret;
81 +
82 + *temp = 0;
83 + packet.id = 0;
84 + ret = rpi_firmware_property(fw, tag, &packet, sizeof(packet));
85 + if (ret) {
86 + dev_err(&tz->device, "Failed to get temperature\n");
87 + return ret;
88 + }
89 +
90 + *temp = packet.val;
91 + dev_dbg(&tz->device, "%stemp=%d\n",
92 + tag == RPI_FIRMWARE_GET_MAX_TEMPERATURE ? "max" : "", *temp);
93 +
94 + return 0;
95 +}
96 +
97 +static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz,
98 + int *temp)
99 +{
100 + return bcm2835_thermal_get_property(tz, temp,
101 + RPI_FIRMWARE_GET_TEMPERATURE);
102 +}
103 +
104 +static struct thermal_zone_device_ops ops = {
105 + .get_temp = bcm2835_thermal_get_temp,
106 +};
107 +
108 +static int bcm2835_thermal_probe(struct platform_device *pdev)
109 +{
110 + struct device_node *fw_np;
111 + struct rpi_firmware *fw;
112 + struct thermal_zone_device *tz;
113 +
114 + fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
115 + if (!fw_np) {
116 + dev_err(&pdev->dev, "Missing firmware node\n");
117 + return -ENOENT;
118 + }
119 + fw = rpi_firmware_get(fw_np);
120 + if (!fw)
121 + return -EPROBE_DEFER;
122 +
123 + tz = thermal_zone_device_register("bcm2835_thermal", 0, 0, fw, &ops,
124 + NULL, 0, 0);
125 + if (IS_ERR(tz)) {
126 + dev_err(&pdev->dev, "Failed to register the thermal device\n");
127 + return PTR_ERR(tz);
128 + }
129 +
130 + platform_set_drvdata(pdev, tz);
131 +
132 + return 0;
133 +}
134 +
135 +static int bcm2835_thermal_remove(struct platform_device *pdev)
136 +{
137 + thermal_zone_device_unregister(platform_get_drvdata(pdev));
138 +
139 + return 0;
140 +}
141 +
142 +static const struct of_device_id bcm2835_thermal_of_match_table[] = {
143 + { .compatible = "brcm,bcm2835-thermal", },
144 + {},
145 +};
146 +MODULE_DEVICE_TABLE(of, bcm2835_thermal_of_match_table);
147 +
148 +static struct platform_driver bcm2835_thermal_driver = {
149 + .probe = bcm2835_thermal_probe,
150 + .remove = bcm2835_thermal_remove,
151 + .driver = {
152 + .name = "bcm2835_thermal",
153 + .of_match_table = bcm2835_thermal_of_match_table,
154 + },
155 +};
156 +module_platform_driver(bcm2835_thermal_driver);
157 +
158 +MODULE_AUTHOR("Dorian Peake");
159 +MODULE_AUTHOR("Noralf Trønnes");
160 +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
161 +MODULE_LICENSE("GPL");