Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable hwmon for thermal zones #3307

Merged
merged 9 commits into from
May 28, 2020
45 changes: 45 additions & 0 deletions Documentation/devicetree/bindings/thermal/brcm,avs-ro-thermal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/thermal/brcm,avs-ro-thermal.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Broadcom AVS ring oscillator thermal

maintainers:
- Stefan Wahren <wahrenst@gmx.net>

description: |+
The thermal node should be the child of a syscon node with the
required property:

- compatible: Should be one of the following:
"brcm,bcm2711-avs-monitor", "syscon", "simple-mfd"

Refer to the the bindings described in
Documentation/devicetree/bindings/mfd/syscon.txt

properties:
compatible:
const: brcm,bcm2711-thermal

reg:
maxItems: 1

required:
- compatible
- reg

examples:
- |
avs-monitor@7d5d2000 {
compatible = "brcm,bcm2711-avs-monitor",
"syscon", "simple-mfd";
reg = <0x7d5d2000 0xf00>;

thermal: thermal {
compatible = "brcm,bcm2711-thermal";
#thermal-sensor-cells = <0>;
};
};
...
14 changes: 0 additions & 14 deletions arch/arm/boot/dts/bcm2711-rpi.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@
};

&soc {
thermal: thermal@7d5d2200 {
compatible = "brcm,avs-tmon-bcm2711";
reg = <0x7d5d2200 0x2c>;
interrupts = <GIC_SPI 137 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "tmon";
clocks = <&clocks BCM2835_CLOCK_TSENS>;
#thermal-sensor-cells = <0>;
status = "okay";
};

/delete-node/ audio;
};

Expand Down Expand Up @@ -192,10 +182,6 @@
<GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH>;
};

&cpu_thermal {
thermal-sensors = <&thermal>;
};

&genet {
compatible = "brcm,bcm2711-genet-v5", "brcm,genet-v5";
};
12 changes: 12 additions & 0 deletions arch/arm/boot/dts/bcm2711.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@
IRQ_TYPE_LEVEL_HIGH)>;
};

avs_monitor: avs-monitor@7d5d2000 {
compatible = "brcm,bcm2711-avs-monitor",
"syscon", "simple-mfd";
reg = <0x7d5d2000 0xf00>;

thermal: thermal {
compatible = "brcm,bcm2711-thermal";
#thermal-sensor-cells = <0>;
};
};

dma: dma@7e007000 {
compatible = "brcm,bcm2835-dma";
reg = <0x7e007000 0xb00>;
Expand Down Expand Up @@ -514,6 +525,7 @@

&cpu_thermal {
coefficients = <(-487) 410040>;
thermal-sensors = <&thermal>;
};

&dsi0 {
Expand Down
1 change: 0 additions & 1 deletion arch/arm/configs/bcm2709_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,6 @@ CONFIG_POWER_RESET_GPIO=y
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_BATTERY_GAUGE_LTC2941=m
CONFIG_HWMON=m
CONFIG_SENSORS_DS1621=m
CONFIG_SENSORS_GPIO_FAN=m
CONFIG_SENSORS_JC42=m
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/configs/bcm2711_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,6 @@ CONFIG_POWER_RESET_GPIO=y
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_BATTERY_GAUGE_LTC2941=m
CONFIG_HWMON=m
CONFIG_SENSORS_DS1621=m
CONFIG_SENSORS_GPIO_FAN=m
CONFIG_SENSORS_JC42=m
Expand All @@ -731,13 +730,14 @@ CONFIG_SENSORS_SHTC1=m
CONFIG_SENSORS_INA2XX=m
CONFIG_SENSORS_TMP102=m
CONFIG_THERMAL=y
CONFIG_BCM2711_THERMAL=y
CONFIG_BCM2835_THERMAL=y
CONFIG_BRCMSTB_THERMAL=y
CONFIG_WATCHDOG=y
CONFIG_GPIO_WATCHDOG=m
CONFIG_BCM2835_WDT=y
CONFIG_MFD_STMPE=y
CONFIG_STMPE_SPI=y
CONFIG_MFD_SYSCON=y
CONFIG_MFD_ARIZONA_I2C=m
CONFIG_MFD_ARIZONA_SPI=m
CONFIG_MFD_WM5102=y
Expand Down
1 change: 0 additions & 1 deletion arch/arm/configs/bcmrpi_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,6 @@ CONFIG_POWER_RESET_GPIO=y
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_BATTERY_GAUGE_LTC2941=m
CONFIG_HWMON=m
CONFIG_SENSORS_DS1621=m
CONFIG_SENSORS_GPIO_FAN=m
CONFIG_SENSORS_JC42=m
Expand Down
1 change: 1 addition & 0 deletions arch/arm/configs/multi_v7_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ CONFIG_IMX_THERMAL=y
CONFIG_ROCKCHIP_THERMAL=y
CONFIG_RCAR_THERMAL=y
CONFIG_ARMADA_THERMAL=y
CONFIG_BCM2711_THERMAL=m
CONFIG_BCM2835_THERMAL=m
CONFIG_BRCMSTB_THERMAL=m
CONFIG_ST_THERMAL_MEMMAP=y
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/configs/bcm2711_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ CONFIG_POWER_RESET_GPIO=y
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_BATTERY_GAUGE_LTC2941=m
CONFIG_HWMON=m
CONFIG_SENSORS_DS1621=m
CONFIG_SENSORS_GPIO_FAN=m
CONFIG_SENSORS_JC42=m
Expand All @@ -725,13 +724,14 @@ CONFIG_SENSORS_SHTC1=m
CONFIG_SENSORS_INA2XX=m
CONFIG_SENSORS_TMP102=m
CONFIG_THERMAL=y
CONFIG_BCM2711_THERMAL=y
CONFIG_BCM2835_THERMAL=y
CONFIG_BRCMSTB_THERMAL=y
CONFIG_WATCHDOG=y
CONFIG_GPIO_WATCHDOG=m
CONFIG_BCM2835_WDT=y
CONFIG_MFD_STMPE=y
CONFIG_STMPE_SPI=y
CONFIG_MFD_SYSCON=y
CONFIG_MFD_ARIZONA_I2C=m
CONFIG_MFD_ARIZONA_SPI=m
CONFIG_MFD_WM5102=y
Expand Down
1 change: 0 additions & 1 deletion arch/arm64/configs/bcmrpi3_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ CONFIG_W1_SLAVE_DS28E17=m
CONFIG_POWER_RESET_GPIO=y
CONFIG_BATTERY_DS2760=m
CONFIG_BATTERY_MAX17040=m
CONFIG_HWMON=m
CONFIG_SENSORS_LM75=m
CONFIG_SENSORS_SHT21=m
CONFIG_SENSORS_SHTC1=m
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/configs/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ CONFIG_ROCKCHIP_THERMAL=m
CONFIG_RCAR_THERMAL=y
CONFIG_RCAR_GEN3_THERMAL=y
CONFIG_ARMADA_THERMAL=y
CONFIG_BCM2711_THERMAL=m
CONFIG_BCM2835_THERMAL=m
CONFIG_BRCMSTB_THERMAL=m
CONFIG_EXYNOS_THERMAL=y
Expand Down
9 changes: 8 additions & 1 deletion drivers/thermal/broadcom/Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# SPDX-License-Identifier: GPL-2.0-only
config BCM2711_THERMAL
tristate "Broadcom AVS RO thermal sensor driver"
depends on ARCH_BCM2835 || COMPILE_TEST
depends on THERMAL_OF && MFD_SYSCON
help
Support for thermal sensors on Broadcom BCM2711 SoCs.

config BCM2835_THERMAL
tristate "Thermal sensors on bcm2835 SoC"
depends on ARCH_BCM2835 || COMPILE_TEST
Expand All @@ -9,7 +16,7 @@ config BCM2835_THERMAL

config BRCMSTB_THERMAL
tristate "Broadcom STB AVS TMON thermal driver"
depends on ARCH_BRCMSTB || ARCH_BCM2835 || COMPILE_TEST
depends on ARCH_BRCMSTB || COMPILE_TEST
help
Enable this driver if you have a Broadcom STB SoC and would like
thermal framework support.
Expand Down
1 change: 1 addition & 0 deletions drivers/thermal/broadcom/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_BCM2711_THERMAL) += bcm2711_thermal.o
obj-$(CONFIG_BCM2835_THERMAL) += bcm2835_thermal.o
obj-$(CONFIG_BRCMSTB_THERMAL) += brcmstb_thermal.o
obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o
Expand Down
123 changes: 123 additions & 0 deletions drivers/thermal/broadcom/bcm2711_thermal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Broadcom AVS RO thermal sensor driver
*
* based on brcmstb_thermal
*
* Copyright (C) 2020 Stefan Wahren
*/

#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
#include <linux/regmap.h>
#include <linux/thermal.h>

#include "../thermal_hwmon.h"

#define AVS_RO_TEMP_STATUS 0x200
#define AVS_RO_TEMP_STATUS_VALID_MSK (BIT(16) | BIT(10))
#define AVS_RO_TEMP_STATUS_DATA_MSK GENMASK(9, 0)

struct bcm2711_thermal_priv {
struct regmap *regmap;
struct thermal_zone_device *thermal;
};

static int bcm2711_get_temp(void *data, int *temp)
{
struct bcm2711_thermal_priv *priv = data;
int slope = thermal_zone_get_slope(priv->thermal);
int offset = thermal_zone_get_offset(priv->thermal);
u32 val;
int ret;
long t;

ret = regmap_read(priv->regmap, AVS_RO_TEMP_STATUS, &val);
if (ret)
return ret;

if (!(val & AVS_RO_TEMP_STATUS_VALID_MSK))
return -EIO;

val &= AVS_RO_TEMP_STATUS_DATA_MSK;

/* Convert a HW code to a temperature reading (millidegree celsius) */
t = slope * val + offset;

*temp = t < 0 ? 0 : t;

return 0;
}

static const struct thermal_zone_of_device_ops bcm2711_thermal_of_ops = {
.get_temp = bcm2711_get_temp,
};

static const struct of_device_id bcm2711_thermal_id_table[] = {
{ .compatible = "brcm,bcm2711-thermal" },
{},
};
MODULE_DEVICE_TABLE(of, bcm2711_thermal_id_table);

static int bcm2711_thermal_probe(struct platform_device *pdev)
{
struct thermal_zone_device *thermal;
struct bcm2711_thermal_priv *priv;
struct device *dev = &pdev->dev;
struct device_node *parent;
struct regmap *regmap;
int ret;

priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;

/* get regmap from syscon node */
parent = of_get_parent(dev->of_node); /* parent should be syscon node */
regmap = syscon_node_to_regmap(parent);
of_node_put(parent);
if (IS_ERR(regmap)) {
ret = PTR_ERR(regmap);
dev_err(dev, "failed to get regmap: %d\n", ret);
return ret;
}
priv->regmap = regmap;

thermal = devm_thermal_zone_of_sensor_register(dev, 0, priv,
&bcm2711_thermal_of_ops);
if (IS_ERR(thermal)) {
ret = PTR_ERR(thermal);
dev_err(dev, "could not register sensor: %d\n", ret);
return ret;
}

priv->thermal = thermal;

thermal->tzp->no_hwmon = false;
ret = thermal_add_hwmon_sysfs(thermal);
if (ret)
return ret;

return 0;
}

static struct platform_driver bcm2711_thermal_driver = {
.probe = bcm2711_thermal_probe,
.driver = {
.name = "bcm2711_thermal",
.of_match_table = bcm2711_thermal_id_table,
},
};
module_platform_driver(bcm2711_thermal_driver);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Stefan Wahren");
MODULE_DESCRIPTION("Broadcom AVS RO thermal sensor driver");
Loading