1 Index: linux-3.10/drivers/hwmon/bcm2835-hwmon.c
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ linux-3.10/drivers/hwmon/bcm2835-hwmon.c 2013-07-09 20:25:51.309324091 +0100
6 +/*****************************************************************************
7 +* Copyright 2011 Broadcom Corporation. All rights reserved.
9 +* Unless you and Broadcom execute a separate written software license
10 +* agreement governing use of this software, this software is licensed to you
11 +* under the terms of the GNU General Public License version 2, available at
12 +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
14 +* Notwithstanding the above, under no circumstances may you combine this
15 +* software in any way with any other Broadcom software provided under a
16 +* license other than the GPL, without Broadcom's express prior written
18 +*****************************************************************************/
20 +#include <linux/kernel.h>
21 +#include <linux/module.h>
22 +#include <linux/init.h>
23 +#include <linux/hwmon.h>
24 +#include <linux/hwmon-sysfs.h>
25 +#include <linux/platform_device.h>
26 +#include <linux/sysfs.h>
27 +#include <mach/vcio.h>
28 +#include <linux/slab.h>
29 +#include <linux/err.h>
31 +#define MODULE_NAME "bcm2835_hwmon"
33 +/*#define HWMON_DEBUG_ENABLE*/
35 +#ifdef HWMON_DEBUG_ENABLE
36 +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
38 +#define print_debug(fmt,...)
40 +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
41 +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
43 +#define VC_TAG_GET_TEMP 0x00030006
44 +#define VC_TAG_GET_MAX_TEMP 0x0003000A
46 +/* --- STRUCTS --- */
47 +struct bcm2835_hwmon_data {
48 + struct device *hwmon_dev;
51 +/* tag part of the message */
53 + uint32_t tag_id; /* the tag ID for the temperature */
54 + uint32_t buffer_size; /* size of the buffer (should be 8) */
55 + uint32_t request_code; /* identifies message as a request (should be 0) */
56 + uint32_t id; /* extra ID field (should be 0) */
57 + uint32_t val; /* returned value of the temperature */
60 +/* message structure to be sent to videocore */
62 + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
63 + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
64 + struct vc_msg_tag tag; /* the tag structure above to make */
65 + uint32_t end_tag; /* an end identifier, should be set to NULL */
73 +/* --- PROTOTYPES --- */
74 +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
75 +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
77 +/* --- GLOBALS --- */
79 +static struct bcm2835_hwmon_data *bcm2835_data;
80 +static struct platform_driver bcm2835_hwmon_driver;
82 +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
83 +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
84 +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
86 +static struct attribute* bcm2835_attributes[] = {
87 + &sensor_dev_attr_name.dev_attr.attr,
88 + &sensor_dev_attr_temp1_input.dev_attr.attr,
89 + &sensor_dev_attr_temp1_max.dev_attr.attr,
93 +static struct attribute_group bcm2835_attr_group = {
94 + .attrs = bcm2835_attributes,
97 +/* --- FUNCTIONS --- */
99 +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
101 + return sprintf(buf,"bcm2835_hwmon\n");
104 +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
109 + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
113 + /* wipe all previous message data */
114 + memset(&msg, 0, sizeof msg);
116 + /* determine the message type */
118 + msg.tag.tag_id = VC_TAG_GET_TEMP;
119 + else if (index == MAX_TEMP)
120 + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
123 + print_debug("Unknown temperature message!");
127 + msg.msg_size = sizeof msg;
128 + msg.tag.buffer_size = 8;
130 + /* send the message */
131 + result = bcm_mailbox_property(&msg, sizeof msg);
133 + /* check if it was all ok and return the rate in milli degrees C */
134 + if (result == 0 && (msg.request_code & 0x80000000))
135 + temp = (uint)msg.tag.val;
136 + #ifdef HWMON_DEBUG_ENABLE
138 + print_debug("Failed to get temperature!");
140 + print_debug("Got temperature as %u",temp);
141 + print_debug("OUT");
142 + return sprintf(buf, "%u\n", temp);
146 +static int bcm2835_hwmon_probe(struct platform_device *pdev)
151 + print_debug("HWMON Driver has been probed!");
153 + /* check that the device isn't null!*/
156 + print_debug("Platform device is empty!");
160 + /* allocate memory for neccessary data */
161 + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
164 + print_debug("Unable to allocate memory for hwmon data!");
166 + goto kzalloc_error;
169 + /* create the sysfs files */
170 + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
172 + print_debug("Unable to create sysfs files!");
177 + /* register the hwmon device */
178 + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
179 + if (IS_ERR(bcm2835_data->hwmon_dev))
181 + err = PTR_ERR(bcm2835_data->hwmon_dev);
184 + print_debug("OUT");
189 + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
192 + kfree(bcm2835_data);
200 +static int bcm2835_hwmon_remove(struct platform_device *pdev)
203 + hwmon_device_unregister(bcm2835_data->hwmon_dev);
205 + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
206 + print_debug("OUT");
211 +static struct platform_driver bcm2835_hwmon_driver = {
212 + .probe = bcm2835_hwmon_probe,
213 + .remove = bcm2835_hwmon_remove,
215 + .name = "bcm2835_hwmon",
216 + .owner = THIS_MODULE,
220 +MODULE_LICENSE("GPL");
221 +MODULE_AUTHOR("Dorian Peake");
222 +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
224 +module_platform_driver(bcm2835_hwmon_driver);
225 Index: linux-3.10/drivers/hwmon/Kconfig
226 ===================================================================
227 --- linux-3.10.orig/drivers/hwmon/Kconfig 2013-07-09 20:25:51.321324159 +0100
228 +++ linux-3.10/drivers/hwmon/Kconfig 2013-07-09 20:25:51.313324108 +0100
229 @@ -1537,6 +1537,16 @@
231 Support for the A/D converter on MC13783 and MC13892 PMIC.
233 +config SENSORS_BCM2835
234 + depends on THERMAL_BCM2835=n
235 + tristate "Broadcom BCM2835 HWMON Driver"
237 + If you say yes here you get support for the hardware
238 + monitoring features of the BCM2835 Chip
240 + This driver can also be built as a module. If so, the module
241 + will be called bcm2835-hwmon.
245 comment "ACPI drivers"
246 Index: linux-3.10/drivers/hwmon/Makefile
247 ===================================================================
248 --- linux-3.10.orig/drivers/hwmon/Makefile 2013-07-09 20:25:51.321324159 +0100
249 +++ linux-3.10/drivers/hwmon/Makefile 2013-07-09 20:26:07.361403698 +0100
251 obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
252 obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
253 obj-$(CONFIG_SENSORS_GSC) += gsc.o
254 +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
256 obj-$(CONFIG_PMBUS) += pmbus/