@@ -392,6 +392,11 @@ config MTK_THERMAL
Enable this option if you want to have support for thermal management
controller present in Mediatek SoCs
+menu "Broadcom thermal drivers"
+depends on ARCH_BCM || COMPILE_TEST
+source "drivers/thermal/broadcom/Kconfig"
+endmenu
+
menu "Texas Instruments thermal drivers"
depends on ARCH_HAS_BANDGAP || COMPILE_TEST
depends on HAS_IOMEM
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL) += clock_cooling.o
thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
# platform thermal drivers
+obj-y += broadcom/
obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o
obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o
obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o
new file mode 100644
@@ -0,0 +1,7 @@
+config RASPBERRYPI_THERMAL
+ tristate "Raspberry Pi thermal driver"
+ depends on ARCH_BCM2835 || COMPILE_TEST
+ depends on RASPBERRYPI_FIRMWARE=y
+ help
+ This enables support for the RPi thermal that is part of BCM2835 SoC
+ and can be accessed using firmware interface.
new file mode 100644
@@ -0,0 +1 @@
+obj-$(CONFIG_RASPBERRYPI_THERMAL) += raspberrypi-thermal.o
new file mode 100644
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2017 Rafał Miłecki <rafal@milecki.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
+struct rpi_thermal {
+ struct rpi_firmware *fw;
+};
+
+static int rpi_thermal_get_temp(void *data, int *temp)
+{
+ struct rpi_thermal *rpi_thermal = data;
+ struct {
+ u32 id;
+ u32 temp;
+ } tag_data = {};
+ int err;
+
+ err = rpi_firmware_property(rpi_thermal->fw,
+ RPI_FIRMWARE_GET_TEMPERATURE,
+ &tag_data, sizeof(tag_data));
+ if (!err)
+ *temp = tag_data.temp;
+
+ return err;
+}
+
+const struct thermal_zone_of_device_ops rpi_thermal_ops = {
+ .get_temp = rpi_thermal_get_temp,
+};
+
+static int rpi_thermal_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct rpi_thermal *rpi_thermal;
+ struct device_node *fw_np;
+ struct thermal_zone_device *tzd;
+
+ rpi_thermal = devm_kzalloc(dev, sizeof(*rpi_thermal), GFP_KERNEL);
+ if (!rpi_thermal)
+ return -ENOMEM;
+
+ fw_np = of_parse_phandle(dev->of_node, "firmware", 0);
+ if (!fw_np) {
+ dev_err(dev, "Failed to get firmware phandle\n");
+ return -ENOENT;
+ }
+
+ rpi_thermal->fw = rpi_firmware_get(fw_np);
+ of_node_put(fw_np);
+ if (!rpi_thermal->fw)
+ return -ENODEV;
+
+ tzd = devm_thermal_zone_of_sensor_register(dev, 0, rpi_thermal,
+ &rpi_thermal_ops);
+
+ return PTR_ERR_OR_ZERO(tzd);
+}
+
+static const struct of_device_id rpi_thermal_of_match[] = {
+ { .compatible = "raspberrypi,bcm2835-thermal", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, rpi_thermal_of_match);
+
+static struct platform_driver rpi_thermal_driver = {
+ .probe = rpi_thermal_probe,
+ .driver = {
+ .name = "raspberrypi-thermal",
+ .of_match_table = rpi_thermal_of_match,
+ },
+};
+module_platform_driver(rpi_thermal_driver);
+
+MODULE_DESCRIPTION("Raspberry Pi thermal driver");
+MODULE_LICENSE("GPL v2");