Commit 9f24a81e authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal

Pull thermal soc updates from Eduardo Valentin:
 "Specifics:

   - mediatek thermal now supports MT8183

   - broadcom thermal now supports Stingray

   - qoirq now supports multiple sensors

   - fixes on different drivers: rcar, tsens, tegra

  Some new drivers are still pending further review and I chose to leave
  them for the next merge window while still sending this material"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal:
  thermal: rcar_gen3_thermal: Register hwmon sysfs interface
  thermal/qcom/tsens-common : fix possible object reference leak
  thermal: tegra: add get_trend ops
  thermal: tegra: fix memory allocation
  thermal: tegra: remove unnecessary warnings
  thermal: mediatek: add support for MT8183
  dt-bindings: thermal: add binding document for mt8183 thermal controller
  thermal: mediatek: add flag for bank selection
  thermal: mediatek: add thermal controller offset
  thermal: mediatek: add calibration item
  thermal: mediatek: add common index of vts settings.
  thermal: mediatek: fix register index error
  thermal: qoriq: add multiple sensors support
  thermal: broadcom: Add Stingray thermal driver
  dt-bindings: thermal: Add binding document for SR thermal
parents 564e7411 6269e9f7
* Broadcom Stingray Thermal
This binding describes thermal sensors that is part of Stingray SoCs.
Required properties:
- compatible : Must be "brcm,sr-thermal"
- reg : Memory where tmon data will be available.
- brcm,tmon-mask: A one cell bit mask of valid TMON sources.
Each bit represents single TMON source.
- #thermal-sensor-cells : Thermal sensor phandler
- polling-delay: Max number of milliseconds to wait between polls.
- thermal-sensors: A list of thermal sensor phandles and specifier.
specifier value is tmon ID and it should be
in correspond with brcm,tmon-mask.
- temperature: trip temperature threshold in millicelsius.
Example:
tmons {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0x0 0x8f100000 0x100>;
tmon: tmon@0 {
compatible = "brcm,sr-thermal";
reg = <0x0 0x40>;
brcm,tmon-mask = <0x3f>;
#thermal-sensor-cells = <1>;
};
};
thermal-zones {
ihost0_thermal: ihost0-thermal {
polling-delay-passive = <0>;
polling-delay = <1000>;
thermal-sensors = <&tmon 0>;
trips {
cpu-crit {
temperature = <105000>;
hysteresis = <0>;
type = "critical";
};
};
};
ihost1_thermal: ihost1-thermal {
polling-delay-passive = <0>;
polling-delay = <1000>;
thermal-sensors = <&tmon 1>;
trips {
cpu-crit {
temperature = <105000>;
hysteresis = <0>;
type = "critical";
};
};
};
ihost2_thermal: ihost2-thermal {
polling-delay-passive = <0>;
polling-delay = <1000>;
thermal-sensors = <&tmon 2>;
trips {
cpu-crit {
temperature = <105000>;
hysteresis = <0>;
type = "critical";
};
};
};
ihost3_thermal: ihost3-thermal {
polling-delay-passive = <0>;
polling-delay = <1000>;
thermal-sensors = <&tmon 3>;
trips {
cpu-crit {
temperature = <105000>;
hysteresis = <0>;
type = "critical";
};
};
};
crmu_thermal: crmu-thermal {
polling-delay-passive = <0>;
polling-delay = <1000>;
thermal-sensors = <&tmon 4>;
trips {
cpu-crit {
temperature = <105000>;
hysteresis = <0>;
type = "critical";
};
};
};
nitro_thermal: nitro-thermal {
polling-delay-passive = <0>;
polling-delay = <1000>;
thermal-sensors = <&tmon 5>;
trips {
cpu-crit {
temperature = <105000>;
hysteresis = <0>;
type = "critical";
};
};
};
};
......@@ -13,6 +13,7 @@ Required properties:
- "mediatek,mt2701-thermal" : For MT2701 family of SoCs
- "mediatek,mt2712-thermal" : For MT2712 family of SoCs
- "mediatek,mt7622-thermal" : For MT7622 SoC
- "mediatek,mt8183-thermal" : For MT8183 family of SoCs
- reg: Address range of the thermal controller
- interrupts: IRQ for the thermal controller
- clocks, clock-names: Clocks needed for the thermal controller. required
......
......@@ -344,7 +344,8 @@ source "drivers/thermal/intel/Kconfig"
endmenu
menu "Broadcom thermal drivers"
depends on ARCH_BCM || ARCH_BRCMSTB || ARCH_BCM2835 || COMPILE_TEST
depends on ARCH_BCM || ARCH_BRCMSTB || ARCH_BCM2835 || ARCH_BCM_IPROC || \
COMPILE_TEST
source "drivers/thermal/broadcom/Kconfig"
endmenu
......
......@@ -22,3 +22,12 @@ config BCM_NS_THERMAL
BCM4708, BCM4709, BCM5301x, BCM95852X, etc). It contains DMU (Device
Management Unit) block with a thermal sensor that allows checking CPU
temperature.
config BCM_SR_THERMAL
tristate "Stingray thermal driver"
depends on ARCH_BCM_IPROC || COMPILE_TEST
default ARCH_BCM_IPROC
help
Support for the Stingray family of SoCs. Its different blocks like
iHost, CRMU and NITRO has thermal sensor that allows checking its
temperature.
obj-$(CONFIG_BCM2835_THERMAL) += bcm2835_thermal.o
obj-$(CONFIG_BRCMSTB_THERMAL) += brcmstb_thermal.o
obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o
obj-$(CONFIG_BCM_SR_THERMAL) += sr-thermal.o
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2018 Broadcom
*/
#include <linux/acpi.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/thermal.h>
/*
* In stingray thermal IO memory,
* Total Number of available TMONs MASK is at offset 0
* temperature registers BASE is at 4 byte offset.
* Each TMON temperature register size is 4.
*/
#define SR_TMON_TEMP_BASE(id) ((id) * 0x4)
#define SR_TMON_MAX_LIST 6
struct sr_tmon {
struct thermal_zone_device *tz;
unsigned int crit_temp;
unsigned int tmon_id;
struct sr_thermal *priv;
};
struct sr_thermal {
void __iomem *regs;
unsigned int max_crit_temp;
struct sr_tmon tmon[SR_TMON_MAX_LIST];
};
static int sr_get_temp(void *data, int *temp)
{
struct sr_tmon *tmon = data;
struct sr_thermal *sr_thermal = tmon->priv;
*temp = readl(sr_thermal->regs + SR_TMON_TEMP_BASE(tmon->tmon_id));
return 0;
}
static const struct thermal_zone_of_device_ops sr_tz_ops = {
.get_temp = sr_get_temp,
};
static int sr_thermal_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct sr_thermal *sr_thermal;
struct sr_tmon *tmon;
struct resource *res;
u32 sr_tmon_list = 0;
unsigned int i;
int ret;
sr_thermal = devm_kzalloc(dev, sizeof(*sr_thermal), GFP_KERNEL);
if (!sr_thermal)
return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
sr_thermal->regs = (void __iomem *)devm_memremap(&pdev->dev, res->start,
resource_size(res),
MEMREMAP_WB);
if (IS_ERR(sr_thermal->regs)) {
dev_err(dev, "failed to get io address\n");
return PTR_ERR(sr_thermal->regs);
}
ret = device_property_read_u32(dev, "brcm,tmon-mask", &sr_tmon_list);
if (ret)
return ret;
tmon = sr_thermal->tmon;
for (i = 0; i < SR_TMON_MAX_LIST; i++, tmon++) {
if (!(sr_tmon_list & BIT(i)))
continue;
/* Flush temperature registers */
writel(0, sr_thermal->regs + SR_TMON_TEMP_BASE(i));
tmon->tmon_id = i;
tmon->priv = sr_thermal;
tmon->tz = devm_thermal_zone_of_sensor_register(dev, i, tmon,
&sr_tz_ops);
if (IS_ERR(tmon->tz))
return PTR_ERR(tmon->tz);
dev_dbg(dev, "thermal sensor %d registered\n", i);
}
platform_set_drvdata(pdev, sr_thermal);
return 0;
}
static const struct of_device_id sr_thermal_of_match[] = {
{ .compatible = "brcm,sr-thermal", },
{},
};
MODULE_DEVICE_TABLE(of, sr_thermal_of_match);
static const struct acpi_device_id sr_thermal_acpi_ids[] = {
{ .id = "BRCM0500" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(acpi, sr_thermal_acpi_ids);
static struct platform_driver sr_thermal_driver = {
.probe = sr_thermal_probe,
.driver = {
.name = "sr-thermal",
.of_match_table = sr_thermal_of_match,
.acpi_match_table = ACPI_PTR(sr_thermal_acpi_ids),
},
};
module_platform_driver(sr_thermal_driver);
MODULE_AUTHOR("Pramod Kumar <pramod.kumar@broadcom.com>");
MODULE_DESCRIPTION("Stingray thermal driver");
MODULE_LICENSE("GPL v2");
This diff is collapsed.
......@@ -144,13 +144,17 @@ int __init init_common(struct tsens_device *tmdev)
tmdev->tm_offset = 0;
res = platform_get_resource(op, IORESOURCE_MEM, 1);
srot_base = devm_ioremap_resource(&op->dev, res);
if (IS_ERR(srot_base))
return PTR_ERR(srot_base);
if (IS_ERR(srot_base)) {
ret = PTR_ERR(srot_base);
goto err_put_device;
}
tmdev->srot_map = devm_regmap_init_mmio(tmdev->dev, srot_base,
&tsens_srot_config);
if (IS_ERR(tmdev->srot_map))
return PTR_ERR(tmdev->srot_map);
if (IS_ERR(tmdev->srot_map)) {
ret = PTR_ERR(tmdev->srot_map);
goto err_put_device;
}
} else {
/* old DTs where SROT and TM were in a contiguous 2K block */
......@@ -159,22 +163,31 @@ int __init init_common(struct tsens_device *tmdev)
res = platform_get_resource(op, IORESOURCE_MEM, 0);
tm_base = devm_ioremap_resource(&op->dev, res);
if (IS_ERR(tm_base))
return PTR_ERR(tm_base);
if (IS_ERR(tm_base)) {
ret = PTR_ERR(tm_base);
goto err_put_device;
}
tmdev->tm_map = devm_regmap_init_mmio(tmdev->dev, tm_base, &tsens_config);
if (IS_ERR(tmdev->tm_map))
return PTR_ERR(tmdev->tm_map);
if (IS_ERR(tmdev->tm_map)) {
ret = PTR_ERR(tmdev->tm_map);
goto err_put_device;
}
if (tmdev->srot_map) {
ret = regmap_read(tmdev->srot_map, ctrl_offset, &code);
if (ret)
return ret;
goto err_put_device;
if (!(code & TSENS_EN)) {
dev_err(tmdev->dev, "tsens device is not enabled\n");
return -ENODEV;
ret = -ENODEV;
goto err_put_device;
}
}
return 0;
err_put_device:
put_device(&op->dev);
return ret;
}
......@@ -59,14 +59,21 @@ struct qoriq_tmu_regs {
u32 ttr3cr; /* Temperature Range 3 Control Register */
};
struct qoriq_tmu_data;
/*
* Thermal zone data
*/
struct qoriq_sensor {
struct thermal_zone_device *tzd;
struct qoriq_tmu_data *qdata;
int id;
};
struct qoriq_tmu_data {
struct thermal_zone_device *tz;
struct qoriq_tmu_regs __iomem *regs;
int sensor_id;
bool little_endian;
struct qoriq_sensor *sensor[SITES_MAX];
};
static void tmu_write(struct qoriq_tmu_data *p, u32 val, void __iomem *addr)
......@@ -87,48 +94,50 @@ static u32 tmu_read(struct qoriq_tmu_data *p, void __iomem *addr)
static int tmu_get_temp(void *p, int *temp)
{
struct qoriq_sensor *qsensor = p;
struct qoriq_tmu_data *qdata = qsensor->qdata;
u32 val;
struct qoriq_tmu_data *data = p;
val = tmu_read(data, &data->regs->site[data->sensor_id].tritsr);
val = tmu_read(qdata, &qdata->regs->site[qsensor->id].tritsr);
*temp = (val & 0xff) * 1000;
return 0;
}
static int qoriq_tmu_get_sensor_id(void)
static const struct thermal_zone_of_device_ops tmu_tz_ops = {
.get_temp = tmu_get_temp,
};
static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev)
{
int ret, id;
struct of_phandle_args sensor_specs;
struct device_node *np, *sensor_np;
struct qoriq_tmu_data *qdata = platform_get_drvdata(pdev);
int id, sites = 0;
np = of_find_node_by_name(NULL, "thermal-zones");
if (!np)
return -ENODEV;
for (id = 0; id < SITES_MAX; id++) {
qdata->sensor[id] = devm_kzalloc(&pdev->dev,
sizeof(struct qoriq_sensor), GFP_KERNEL);
if (!qdata->sensor[id])
return -ENOMEM;
sensor_np = of_get_next_child(np, NULL);
ret = of_parse_phandle_with_args(sensor_np, "thermal-sensors",
"#thermal-sensor-cells",
0, &sensor_specs);
if (ret) {
of_node_put(np);
of_node_put(sensor_np);
return ret;
qdata->sensor[id]->id = id;
qdata->sensor[id]->qdata = qdata;
qdata->sensor[id]->tzd = devm_thermal_zone_of_sensor_register(
&pdev->dev, id, qdata->sensor[id], &tmu_tz_ops);
if (IS_ERR(qdata->sensor[id]->tzd)) {
if (PTR_ERR(qdata->sensor[id]->tzd) == -ENODEV)
continue;
else
return PTR_ERR(qdata->sensor[id]->tzd);
}
if (sensor_specs.args_count >= 1) {
id = sensor_specs.args[0];
WARN(sensor_specs.args_count > 1,
"%pOFn: too many cells in sensor specifier %d\n",
sensor_specs.np, sensor_specs.args_count);
} else {
id = 0;
sites |= 0x1 << (15 - id);
}
of_node_put(np);
of_node_put(sensor_np);
/* Enable monitoring */
if (sites != 0)
tmu_write(qdata, sites | TMR_ME | TMR_ALPF, &qdata->regs->tmr);
return id;
return 0;
}
static int qoriq_tmu_calibration(struct platform_device *pdev)
......@@ -178,16 +187,11 @@ static void qoriq_tmu_init_device(struct qoriq_tmu_data *data)
tmu_write(data, TMR_DISABLE, &data->regs->tmr);
}
static const struct thermal_zone_of_device_ops tmu_tz_ops = {
.get_temp = tmu_get_temp,
};
static int qoriq_tmu_probe(struct platform_device *pdev)
{
int ret;
struct qoriq_tmu_data *data;
struct device_node *np = pdev->dev.of_node;
u32 site;
if (!np) {
dev_err(&pdev->dev, "Device OF-Node is NULL");
......@@ -203,13 +207,6 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
data->little_endian = of_property_read_bool(np, "little-endian");
data->sensor_id = qoriq_tmu_get_sensor_id();
if (data->sensor_id < 0) {
dev_err(&pdev->dev, "Failed to get sensor id\n");
ret = -ENODEV;
goto err_iomap;
}
data->regs = of_iomap(np, 0);
if (!data->regs) {
dev_err(&pdev->dev, "Failed to get memory region\n");
......@@ -223,20 +220,13 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
if (ret < 0)
goto err_tmu;
data->tz = devm_thermal_zone_of_sensor_register(&pdev->dev,
data->sensor_id,
data, &tmu_tz_ops);
if (IS_ERR(data->tz)) {
ret = PTR_ERR(data->tz);
dev_err(&pdev->dev,
"Failed to register thermal zone device %d\n", ret);
goto err_tmu;
ret = qoriq_tmu_register_tmu_zone(pdev);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to register sensors\n");
ret = -ENODEV;
goto err_iomap;
}
/* Enable monitoring */
site = 0x1 << (15 - data->sensor_id);
tmu_write(data, site | TMR_ME | TMR_ALPF, &data->regs->tmr);
return 0;
err_tmu:
......
......@@ -19,6 +19,7 @@
#include <linux/thermal.h>
#include "thermal_core.h"
#include "thermal_hwmon.h"
/* Register offsets */
#define REG_GEN3_IRQSTR 0x04
......@@ -337,6 +338,13 @@ static int rcar_gen3_thermal_remove(struct platform_device *pdev)
return 0;
}
static void rcar_gen3_hwmon_action(void *data)
{
struct thermal_zone_device *zone = data;
thermal_remove_hwmon_sysfs(zone);
}
static int rcar_gen3_thermal_probe(struct platform_device *pdev)
{
struct rcar_gen3_thermal_priv *priv;
......@@ -429,6 +437,17 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
if (ret < 0)
goto error_unregister;
tsc->zone->tzp->no_hwmon = false;
ret = thermal_add_hwmon_sysfs(tsc->zone);
if (ret)
goto error_unregister;
ret = devm_add_action(dev, rcar_gen3_hwmon_action, zone);
if (ret) {
rcar_gen3_hwmon_action(zone);
goto error_unregister;
}
dev_info(dev, "TSC%d: Loaded %d trip points\n", i, ret);
}
......
......@@ -488,9 +488,41 @@ static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp)
return 0;
}
static int tegra_thermctl_get_trend(void *data, int trip,
enum thermal_trend *trend)
{
struct tegra_thermctl_zone *zone = data;
struct thermal_zone_device *tz = zone->tz;
int trip_temp, temp, last_temp, ret;
if (!tz)
return -EINVAL;
ret = tz->ops->get_trip_temp(zone->tz, trip, &trip_temp);
if (ret)
return ret;
temp = READ_ONCE(tz->temperature);
last_temp = READ_ONCE(tz->last_temperature);
if (temp > trip_temp) {
if (temp >= last_temp)
*trend = THERMAL_TREND_RAISING;
else
*trend = THERMAL_TREND_STABLE;
} else if (temp < trip_temp) {
*trend = THERMAL_TREND_DROPPING;
} else {
*trend = THERMAL_TREND_STABLE;
}
return 0;
}
static const struct thermal_zone_of_device_ops tegra_of_thermal_ops = {
.get_temp = tegra_thermctl_get_temp,
.set_trip_temp = tegra_thermctl_set_trip_temp,
.get_trend = tegra_thermctl_get_trend,
};
static int get_hot_temp(struct thermal_zone_device *tz, int *trip, int *temp)
......@@ -569,7 +601,7 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
set_throttle:
ret = get_hot_temp(tz, &trip, &temperature);
if (ret) {
dev_warn(dev, "throttrip: %s: missing hot temperature\n",
dev_info(dev, "throttrip: %s: missing hot temperature\n",
sg->name);
return 0;
}
......@@ -600,7 +632,7 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
}
if (i == THROTTLE_SIZE)
dev_warn(dev, "throttrip: %s: missing throttle cdev\n",
dev_info(dev, "throttrip: %s: missing throttle cdev\n",
sg->name);
return 0;
......@@ -1329,7 +1361,7 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
}
tegra->thermctl_tzs = devm_kcalloc(&pdev->dev,
soc->num_ttgs, sizeof(*z),
soc->num_ttgs, sizeof(z),
GFP_KERNEL);
if (!tegra->thermctl_tzs)
return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment