1 diff -urN linux-3.10/drivers/thermal/bcm2835-thermal.c linux-rpi-3.10.y/drivers/thermal/bcm2835-thermal.c
2 --- linux-3.10/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-rpi-3.10.y/drivers/thermal/bcm2835-thermal.c 2013-07-06 15:25:50.000000000 +0100
5 +/*****************************************************************************
6 +* Copyright 2011 Broadcom Corporation. All rights reserved.
8 +* Unless you and Broadcom execute a separate written software license
9 +* agreement governing use of this software, this software is licensed to you
10 +* under the terms of the GNU General Public License version 2, available at
11 +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
13 +* Notwithstanding the above, under no circumstances may you combine this
14 +* software in any way with any other Broadcom software provided under a
15 +* license other than the GPL, without Broadcom's express prior written
17 +*****************************************************************************/
19 +#include <linux/kernel.h>
20 +#include <linux/module.h>
21 +#include <linux/init.h>
22 +#include <linux/platform_device.h>
23 +#include <linux/slab.h>
24 +#include <linux/sysfs.h>
25 +#include <mach/vcio.h>
26 +#include <linux/thermal.h>
29 +/* --- DEFINITIONS --- */
30 +#define MODULE_NAME "bcm2835_thermal"
32 +/*#define THERMAL_DEBUG_ENABLE*/
34 +#ifdef THERMAL_DEBUG_ENABLE
35 +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
37 +#define print_debug(fmt,...)
39 +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
41 +#define VC_TAG_GET_TEMP 0x00030006
42 +#define VC_TAG_GET_MAX_TEMP 0x0003000A
49 +/* --- STRUCTS --- */
50 +/* tag part of the message */
52 + uint32_t tag_id; /* the tag ID for the temperature */
53 + uint32_t buffer_size; /* size of the buffer (should be 8) */
54 + uint32_t request_code; /* identifies message as a request (should be 0) */
55 + uint32_t id; /* extra ID field (should be 0) */
56 + uint32_t val; /* returned value of the temperature */
59 +/* message structure to be sent to videocore */
61 + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
62 + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
63 + struct vc_msg_tag tag; /* the tag structure above to make */
64 + uint32_t end_tag; /* an end identifier, should be set to NULL */
67 +struct bcm2835_thermal_data {
68 + struct thermal_zone_device *thermal_dev;
72 +/* --- GLOBALS --- */
73 +static struct bcm2835_thermal_data bcm2835_data;
75 +/* Thermal Device Operations */
76 +static struct thermal_zone_device_ops ops;
78 +/* --- FUNCTIONS --- */
80 +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
82 + int result = -1, retry = 3;
86 + while (result != 0 && retry-- > 0) {
87 + /* wipe all previous message data */
88 + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
90 + /* prepare message */
91 + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
92 + bcm2835_data.msg.tag.buffer_size = 8;
93 + bcm2835_data.msg.tag.tag_id = tag_id;
95 + /* send the message */
96 + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
97 + print_debug("Got %stemperature as %u (%d,%x)\n", tag_id==VC_TAG_GET_MAX_TEMP ? "max ":"", (uint)bcm2835_data.msg.tag.val, result, bcm2835_data.msg.request_code);
98 + if (!(bcm2835_data.msg.request_code & 0x80000000))
102 + /* check if it was all ok and return the rate in milli degrees C */
104 + *temp = (uint)bcm2835_data.msg.tag.val;
106 + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
107 + print_debug("OUT");
111 +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
113 + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
116 +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
118 + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
121 +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
123 + *trip_type = THERMAL_TRIP_HOT;
128 +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
130 + *dev_mode = THERMAL_DEVICE_ENABLED;
135 +static int bcm2835_thermal_probe(struct platform_device *pdev)
138 + print_debug("THERMAL Driver has been probed!");
140 + /* check that the device isn't null!*/
143 + print_debug("Platform device is empty!");
147 + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
149 + print_debug("Unable to register the thermal device!");
156 +static int bcm2835_thermal_remove(struct platform_device *pdev)
160 + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
162 + print_debug("OUT");
167 +static struct thermal_zone_device_ops ops = {
168 + .get_temp = bcm2835_get_temp,
169 + .get_trip_temp = bcm2835_get_max_temp,
170 + .get_trip_type = bcm2835_get_trip_type,
171 + .get_mode = bcm2835_get_mode,
174 +/* Thermal Driver */
175 +static struct platform_driver bcm2835_thermal_driver = {
176 + .probe = bcm2835_thermal_probe,
177 + .remove = bcm2835_thermal_remove,
179 + .name = "bcm2835_thermal",
180 + .owner = THIS_MODULE,
184 +MODULE_LICENSE("GPL");
185 +MODULE_AUTHOR("Dorian Peake");
186 +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
188 +module_platform_driver(bcm2835_thermal_driver);
189 diff -urN linux-3.10/drivers/thermal/Kconfig linux-rpi-3.10.y/drivers/thermal/Kconfig
190 --- linux-3.10/drivers/thermal/Kconfig 2013-06-30 23:13:29.000000000 +0100
191 +++ linux-rpi-3.10.y/drivers/thermal/Kconfig 2013-07-06 15:25:50.000000000 +0100
193 enforce idle time which results in more package C-state residency. The
194 user interface is exposed via generic thermal framework.
196 +config THERMAL_BCM2835
197 + tristate "BCM2835 Thermal Driver"
199 + This will enable temperature monitoring for the Broadcom BCM2835
200 + chip. If built as a module, it will be called 'bcm2835-thermal'.
204 diff -urN linux-3.10/drivers/thermal/Makefile linux-rpi-3.10.y/drivers/thermal/Makefile
205 --- linux-3.10/drivers/thermal/Makefile 2013-06-30 23:13:29.000000000 +0100
206 +++ linux-rpi-3.10.y/drivers/thermal/Makefile 2013-07-06 15:25:50.000000000 +0100
208 obj-$(CONFIG_ARMADA_THERMAL) += armada_thermal.o
209 obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
210 obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
211 +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o