Skip to content

Commit 59b7813

Browse files
lategoodbyedlezcano
authored andcommitted
thermal: Add BCM2711 thermal driver
This adds the thermal sensor driver for the Broadcom BCM2711 SoC, which is placed on the Raspberry Pi 4. The driver only provides SoC temperature reading so far. Signed-off-by: Stefan Wahren <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Nicolas Saenz Julienne <[email protected]> Tested-by: Nicolas Saenz Julienne <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ee31ff3 commit 59b7813

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

drivers/thermal/broadcom/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2+
config BCM2711_THERMAL
3+
tristate "Broadcom AVS RO thermal sensor driver"
4+
depends on ARCH_BCM2835 || COMPILE_TEST
5+
depends on THERMAL_OF && MFD_SYSCON
6+
help
7+
Support for thermal sensors on Broadcom BCM2711 SoCs.
8+
29
config BCM2835_THERMAL
310
tristate "Thermal sensors on bcm2835 SoC"
411
depends on ARCH_BCM2835 || COMPILE_TEST

drivers/thermal/broadcom/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2+
obj-$(CONFIG_BCM2711_THERMAL) += bcm2711_thermal.o
23
obj-$(CONFIG_BCM2835_THERMAL) += bcm2835_thermal.o
34
obj-$(CONFIG_BRCMSTB_THERMAL) += brcmstb_thermal.o
45
obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Broadcom AVS RO thermal sensor driver
4+
*
5+
* based on brcmstb_thermal
6+
*
7+
* Copyright (C) 2020 Stefan Wahren
8+
*/
9+
10+
#include <linux/bitops.h>
11+
#include <linux/clk.h>
12+
#include <linux/device.h>
13+
#include <linux/err.h>
14+
#include <linux/io.h>
15+
#include <linux/kernel.h>
16+
#include <linux/mfd/syscon.h>
17+
#include <linux/module.h>
18+
#include <linux/platform_device.h>
19+
#include <linux/of_device.h>
20+
#include <linux/regmap.h>
21+
#include <linux/thermal.h>
22+
23+
#include "../thermal_hwmon.h"
24+
25+
#define AVS_RO_TEMP_STATUS 0x200
26+
#define AVS_RO_TEMP_STATUS_VALID_MSK (BIT(16) | BIT(10))
27+
#define AVS_RO_TEMP_STATUS_DATA_MSK GENMASK(9, 0)
28+
29+
struct bcm2711_thermal_priv {
30+
struct regmap *regmap;
31+
struct thermal_zone_device *thermal;
32+
};
33+
34+
static int bcm2711_get_temp(void *data, int *temp)
35+
{
36+
struct bcm2711_thermal_priv *priv = data;
37+
int slope = thermal_zone_get_slope(priv->thermal);
38+
int offset = thermal_zone_get_offset(priv->thermal);
39+
u32 val;
40+
int ret;
41+
long t;
42+
43+
ret = regmap_read(priv->regmap, AVS_RO_TEMP_STATUS, &val);
44+
if (ret)
45+
return ret;
46+
47+
if (!(val & AVS_RO_TEMP_STATUS_VALID_MSK))
48+
return -EIO;
49+
50+
val &= AVS_RO_TEMP_STATUS_DATA_MSK;
51+
52+
/* Convert a HW code to a temperature reading (millidegree celsius) */
53+
t = slope * val + offset;
54+
55+
*temp = t < 0 ? 0 : t;
56+
57+
return 0;
58+
}
59+
60+
static const struct thermal_zone_of_device_ops bcm2711_thermal_of_ops = {
61+
.get_temp = bcm2711_get_temp,
62+
};
63+
64+
static const struct of_device_id bcm2711_thermal_id_table[] = {
65+
{ .compatible = "brcm,bcm2711-thermal" },
66+
{},
67+
};
68+
MODULE_DEVICE_TABLE(of, bcm2711_thermal_id_table);
69+
70+
static int bcm2711_thermal_probe(struct platform_device *pdev)
71+
{
72+
struct thermal_zone_device *thermal;
73+
struct bcm2711_thermal_priv *priv;
74+
struct device *dev = &pdev->dev;
75+
struct device_node *parent;
76+
struct regmap *regmap;
77+
int ret;
78+
79+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
80+
if (!priv)
81+
return -ENOMEM;
82+
83+
/* get regmap from syscon node */
84+
parent = of_get_parent(dev->of_node); /* parent should be syscon node */
85+
regmap = syscon_node_to_regmap(parent);
86+
of_node_put(parent);
87+
if (IS_ERR(regmap)) {
88+
ret = PTR_ERR(regmap);
89+
dev_err(dev, "failed to get regmap: %d\n", ret);
90+
return ret;
91+
}
92+
priv->regmap = regmap;
93+
94+
thermal = devm_thermal_zone_of_sensor_register(dev, 0, priv,
95+
&bcm2711_thermal_of_ops);
96+
if (IS_ERR(thermal)) {
97+
ret = PTR_ERR(thermal);
98+
dev_err(dev, "could not register sensor: %d\n", ret);
99+
return ret;
100+
}
101+
102+
priv->thermal = thermal;
103+
104+
thermal->tzp->no_hwmon = false;
105+
ret = thermal_add_hwmon_sysfs(thermal);
106+
if (ret)
107+
return ret;
108+
109+
return 0;
110+
}
111+
112+
static struct platform_driver bcm2711_thermal_driver = {
113+
.probe = bcm2711_thermal_probe,
114+
.driver = {
115+
.name = "bcm2711_thermal",
116+
.of_match_table = bcm2711_thermal_id_table,
117+
},
118+
};
119+
module_platform_driver(bcm2711_thermal_driver);
120+
121+
MODULE_LICENSE("GPL");
122+
MODULE_AUTHOR("Stefan Wahren");
123+
MODULE_DESCRIPTION("Broadcom AVS RO thermal sensor driver");

0 commit comments

Comments
 (0)