1 /*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
13 *****************************************************************************/
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/thermal.h>
18 #include <soc/bcm2835/raspberrypi-firmware.h>
20 static int bcm2835_thermal_get_property(struct thermal_zone_device
*tz
,
23 struct rpi_firmware
*fw
= tz
->devdata
;
32 ret
= rpi_firmware_property(fw
, tag
, &packet
, sizeof(packet
));
34 dev_err(&tz
->device
, "Failed to get temperature\n");
39 dev_dbg(&tz
->device
, "%stemp=%d\n",
40 tag
== RPI_FIRMWARE_GET_MAX_TEMPERATURE
? "max" : "", *temp
);
45 static int bcm2835_thermal_get_temp(struct thermal_zone_device
*tz
,
48 return bcm2835_thermal_get_property(tz
, temp
,
49 RPI_FIRMWARE_GET_TEMPERATURE
);
52 static struct thermal_zone_device_ops ops
= {
53 .get_temp
= bcm2835_thermal_get_temp
,
56 static int bcm2835_thermal_probe(struct platform_device
*pdev
)
58 struct device_node
*fw_np
;
59 struct rpi_firmware
*fw
;
60 struct thermal_zone_device
*tz
;
62 fw_np
= of_parse_phandle(pdev
->dev
.of_node
, "firmware", 0);
64 dev_err(&pdev
->dev
, "Missing firmware node\n");
67 fw
= rpi_firmware_get(fw_np
);
71 tz
= thermal_zone_device_register("bcm2835_thermal", 0, 0, fw
, &ops
,
74 dev_err(&pdev
->dev
, "Failed to register the thermal device\n");
78 platform_set_drvdata(pdev
, tz
);
83 static int bcm2835_thermal_remove(struct platform_device
*pdev
)
85 thermal_zone_device_unregister(platform_get_drvdata(pdev
));
90 static const struct of_device_id bcm2835_thermal_of_match_table
[] = {
91 { .compatible
= "brcm,bcm2835-thermal", },
94 MODULE_DEVICE_TABLE(of
, bcm2835_thermal_of_match_table
);
96 static struct platform_driver bcm2835_thermal_driver
= {
97 .probe
= bcm2835_thermal_probe
,
98 .remove
= bcm2835_thermal_remove
,
100 .name
= "bcm2835_thermal",
101 .of_match_table
= bcm2835_thermal_of_match_table
,
104 module_platform_driver(bcm2835_thermal_driver
);
106 MODULE_AUTHOR("Dorian Peake");
107 MODULE_AUTHOR("Noralf Trønnes");
108 MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
109 MODULE_LICENSE("GPL");