1 From d49649e2dcf0d5775e92677d37e229e0387fe82a Mon Sep 17 00:00:00 2001
2 From: Stefan Wahren <wahrenst@gmx.net>
3 Date: Sat, 18 May 2019 12:26:11 +0200
4 Subject: [PATCH] thermal: brcmstb_thermal: Add BCM2838 support
6 The BCM2838 has an AVS TMON hardware block. This adds the necessary
7 support to the brcmstb_thermal driver ( no trip handling ).
9 Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
11 drivers/thermal/broadcom/Kconfig | 2 +-
12 drivers/thermal/broadcom/brcmstb_thermal.c | 65 +++++++++++++++++++---
13 2 files changed, 58 insertions(+), 9 deletions(-)
15 --- a/drivers/thermal/broadcom/Kconfig
16 +++ b/drivers/thermal/broadcom/Kconfig
17 @@ -8,7 +8,7 @@ config BCM2835_THERMAL
19 config BRCMSTB_THERMAL
20 tristate "Broadcom STB AVS TMON thermal driver"
21 - depends on ARCH_BRCMSTB || COMPILE_TEST
22 + depends on ARCH_BRCMSTB || ARCH_BCM2835 || COMPILE_TEST
24 Enable this driver if you have a Broadcom STB SoC and would like
25 thermal framework support.
26 --- a/drivers/thermal/broadcom/brcmstb_thermal.c
27 +++ b/drivers/thermal/broadcom/brcmstb_thermal.c
29 #define pr_fmt(fmt) DRV_NAME ": " fmt
31 #include <linux/bitops.h>
32 +#include <linux/clk.h>
33 #include <linux/device.h>
34 #include <linux/err.h>
37 #include <linux/thermal.h>
39 #define AVS_TMON_STATUS 0x00
40 - #define AVS_TMON_STATUS_valid_msk BIT(11)
41 - #define AVS_TMON_STATUS_data_msk GENMASK(10, 1)
42 - #define AVS_TMON_STATUS_data_shift 1
44 #define AVS_TMON_EN_OVERTEMP_RESET 0x04
45 #define AVS_TMON_EN_OVERTEMP_RESET_msk BIT(0)
46 @@ -111,10 +109,19 @@ static struct avs_tmon_trip avs_tmon_tri
50 +struct brcmstb_thermal_of_data {
51 + const struct thermal_zone_of_device_ops *of_ops;
52 + u32 status_valid_mask;
53 + u32 status_data_mask;
54 + u32 status_data_shift;
57 struct brcmstb_thermal_priv {
58 void __iomem *tmon_base;
60 struct thermal_zone_device *thermal;
62 + const struct brcmstb_thermal_of_data *socdata;
65 /* Convert a HW code to a temperature reading (millidegree celsius) */
66 @@ -151,17 +158,18 @@ static inline u32 avs_tmon_temp_to_code(
67 static int brcmstb_get_temp(void *data, int *temp)
69 struct brcmstb_thermal_priv *priv = data;
70 + const struct brcmstb_thermal_of_data *socdata = priv->socdata;
74 val = __raw_readl(priv->tmon_base + AVS_TMON_STATUS);
76 - if (!(val & AVS_TMON_STATUS_valid_msk)) {
77 + if (!(val & socdata->status_valid_mask)) {
78 dev_err(priv->dev, "reading not valid\n");
82 - val = (val & AVS_TMON_STATUS_data_msk) >> AVS_TMON_STATUS_data_shift;
83 + val = (val & socdata->status_data_mask) >> socdata->status_data_shift;
85 t = avs_tmon_code_to_temp(priv->thermal, val);
87 @@ -286,13 +294,34 @@ static int brcmstb_set_trips(void *data,
91 -static struct thermal_zone_of_device_ops of_ops = {
92 +static const struct thermal_zone_of_device_ops bcm7445_thermal_of_ops = {
93 .get_temp = brcmstb_get_temp,
94 .set_trips = brcmstb_set_trips,
97 +static const struct thermal_zone_of_device_ops bcm2838_thermal_of_ops = {
98 + .get_temp = brcmstb_get_temp,
101 +static const struct brcmstb_thermal_of_data bcm7445_thermal_of_data = {
102 + .of_ops = &bcm7445_thermal_of_ops,
103 + .status_valid_mask = BIT(11),
104 + .status_data_mask = GENMASK(10, 1),
105 + .status_data_shift = 1,
108 +static const struct brcmstb_thermal_of_data bcm2838_thermal_of_data = {
109 + .of_ops = &bcm2838_thermal_of_ops,
110 + .status_valid_mask = BIT(10),
111 + .status_data_mask = GENMASK(9, 0),
112 + .status_data_shift = 0,
115 static const struct of_device_id brcmstb_thermal_id_table[] = {
116 - { .compatible = "brcm,avs-tmon" },
117 + { .compatible = "brcm,avs-tmon",
118 + .data = &bcm7445_thermal_of_data },
119 + { .compatible = "brcm,avs-tmon-bcm2838",
120 + .data = &bcm2838_thermal_of_data },
123 MODULE_DEVICE_TABLE(of, brcmstb_thermal_id_table);
124 @@ -313,10 +342,27 @@ static int brcmstb_thermal_probe(struct
125 if (IS_ERR(priv->tmon_base))
126 return PTR_ERR(priv->tmon_base);
128 + priv->socdata = of_device_get_match_data(&pdev->dev);
129 + if (!priv->socdata) {
130 + dev_err(&pdev->dev, "no device match found\n");
134 + priv->clk = devm_clk_get(&pdev->dev, NULL);
135 + if (IS_ERR(priv->clk) && PTR_ERR(priv->clk) == -EPROBE_DEFER)
136 + return -EPROBE_DEFER;
138 + if (!IS_ERR(priv->clk)) {
139 + ret = clk_prepare_enable(priv->clk);
144 priv->dev = &pdev->dev;
145 platform_set_drvdata(pdev, priv);
147 - thermal = thermal_zone_of_sensor_register(&pdev->dev, 0, priv, &of_ops);
148 + thermal = thermal_zone_of_sensor_register(&pdev->dev, 0, priv,
149 + priv->socdata->of_ops);
150 if (IS_ERR(thermal)) {
151 ret = PTR_ERR(thermal);
152 dev_err(&pdev->dev, "could not register sensor: %d\n", ret);
153 @@ -356,6 +402,9 @@ static int brcmstb_thermal_exit(struct p
155 thermal_zone_of_sensor_unregister(&pdev->dev, priv->thermal);
157 + if (!IS_ERR(priv->clk))
158 + clk_disable_unprepare(priv->clk);