Commit 0ef7791e 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:
 "Several new things coming up. Specifics:

   - Rework of tsens and hisi thermal drivers

   - OF-thermal now allows sharing multiple cooling devices on maps

   - Added support for r8a7744 and R8A77970 on rcar thermal driver

   - Added support for r8a774a1 on rcar_gen3 thermal driver

   - New thermal driver stm32

   - Fixes on multiple thermal drivers: of-thermal, imx, qoriq, armada,
     qcom-spmi, rcar, da9062/61"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal: (41 commits)
  thermal: da9062/61: Prevent hardware access during system suspend
  thermal: rcar_thermal: Prevent doing work after unbind
  thermal: rcar_thermal: Prevent hardware access during system suspend
  thermal: rcar_gen3_thermal: add R8A77980 support
  dt-bindings: thermal: rcar-gen3-thermal: document R8A77980 bindings
  thermal: add stm32 thermal driver
  dt-bindings: stm32-thermal: add binding documentation
  thermal: rcar_thermal: add R8A77970 support
  dt-bindings: thermal: rcar-thermal: document R8A77970 bindings
  thermal: rcar_thermal: fix duplicate IRQ request
  dt-bindings: thermal: rcar: Add device tree support for r8a7744
  thermal/drivers/hisi: Add the dual clusters sensors for hi3660
  thermal/drivers/hisi: Add more sensors channel
  thermal/drivers/hisi: Remove pointless irq field
  thermal/drivers/hisi: Use platform_get_irq_byname
  thermal/drivers/hisi: Replace macro name with relevant sensor location
  thermal/drivers/hisi: Add multiple sensors support
  thermal/drivers/hisi: Prepare to support multiple sensors
  thermal/drivers/hisi: Factor out the probe functions
  thermal/drivers/hisi: Set the thermal zone private data to the sensor pointer
  ...
parents befa9363 760eea43
......@@ -6,8 +6,7 @@ interrupt signal and status register to identify high PMIC die temperature.
Required properties:
- compatible: Should contain "qcom,spmi-temp-alarm".
- reg: Specifies the SPMI address and length of the controller's
registers.
- reg: Specifies the SPMI address.
- interrupts: PMIC temperature alarm interrupt.
- #thermal-sensor-cells: Should be 0. See thermal.txt for a description.
......@@ -20,7 +19,7 @@ Example:
pm8941_temp: thermal-alarm@2400 {
compatible = "qcom,spmi-temp-alarm";
reg = <0x2400 0x100>;
reg = <0x2400>;
interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>;
#thermal-sensor-cells = <0>;
......@@ -36,19 +35,14 @@ Example:
thermal-sensors = <&pm8941_temp>;
trips {
passive {
temperature = <1050000>;
stage1 {
temperature = <105000>;
hysteresis = <2000>;
type = "passive";
};
alert {
stage2 {
temperature = <125000>;
hysteresis = <2000>;
type = "hot";
};
crit {
temperature = <145000>;
hysteresis = <2000>;
type = "critical";
};
};
......
* Thermal Monitoring Unit (TMU) on Freescale QorIQ SoCs
Required properties:
- compatible : Must include "fsl,qoriq-tmu". The version of the device is
determined by the TMU IP Block Revision Register (IPBRR0) at
offset 0x0BF8.
- compatible : Must include "fsl,qoriq-tmu" or "fsl,imx8mq-tmu". The
version of the device is determined by the TMU IP Block Revision
Register (IPBRR0) at offset 0x0BF8.
Table of correspondences between IPBRR0 values and example chips:
Value Device
---------- -----
......
......@@ -7,9 +7,11 @@ inside the LSI.
Required properties:
- compatible : "renesas,<soctype>-thermal",
Examples with soctypes are:
- "renesas,r8a774a1-thermal" (RZ/G2M)
- "renesas,r8a7795-thermal" (R-Car H3)
- "renesas,r8a7796-thermal" (R-Car M3-W)
- "renesas,r8a77965-thermal" (R-Car M3-N)
- "renesas,r8a77980-thermal" (R-Car V3H)
- reg : Address ranges of the thermal registers. Each sensor
needs one address range. Sorting must be done in
increasing order according to datasheet, i.e.
......@@ -19,7 +21,8 @@ Required properties:
Optional properties:
- interrupts : interrupts routed to the TSC (3 for H3, M3-W and M3-N)
- interrupts : interrupts routed to the TSC (3 for H3, M3-W, M3-N,
and V3H)
- power-domain : Must contain a reference to the power domain. This
property is mandatory if the thermal sensor instance
is part of a controllable power domain.
......
......@@ -4,15 +4,17 @@ Required properties:
- compatible : "renesas,thermal-<soctype>",
"renesas,rcar-gen2-thermal" (with thermal-zone) or
"renesas,rcar-thermal" (without thermal-zone) as
fallback except R-Car D3.
fallback except R-Car V3M/D3.
Examples with soctypes are:
- "renesas,thermal-r8a73a4" (R-Mobile APE6)
- "renesas,thermal-r8a7743" (RZ/G1M)
- "renesas,thermal-r8a7744" (RZ/G1N)
- "renesas,thermal-r8a7779" (R-Car H1)
- "renesas,thermal-r8a7790" (R-Car H2)
- "renesas,thermal-r8a7791" (R-Car M2-W)
- "renesas,thermal-r8a7792" (R-Car V2H)
- "renesas,thermal-r8a7793" (R-Car M2-N)
- "renesas,thermal-r8a77970" (R-Car V3M)
- "renesas,thermal-r8a77995" (R-Car D3)
- reg : Address range of the thermal registers.
The 1st reg will be recognized as common register
......@@ -21,7 +23,7 @@ Required properties:
Option properties:
- interrupts : If present should contain 3 interrupts for
R-Car D3 or 1 interrupt otherwise.
R-Car V3M/D3 or 1 interrupt otherwise.
Example (non interrupt support):
......
Binding for Thermal Sensor for STMicroelectronics STM32 series of SoCs.
On STM32 SoCs, the Digital Temperature Sensor (DTS) is in charge of managing an
analog block which delivers a frequency depending on the internal SoC's
temperature. By using a reference frequency, DTS is able to provide a sample
number which can be translated into a temperature by the user.
DTS provides interrupt notification mechanism by threshold. This mechanism
offers two temperature trip points: passive and critical. The first is intended
for passive cooling notification while the second is used for over-temperature
reset.
Required parameters:
-------------------
compatible: Should be "st,stm32-thermal"
reg: This should be the physical base address and length of the
sensor's registers.
clocks: Phandle of the clock used by the thermal sensor.
See: Documentation/devicetree/bindings/clock/clock-bindings.txt
clock-names: Should be "pclk" for register access clock and reference clock.
See: Documentation/devicetree/bindings/resource-names.txt
#thermal-sensor-cells: Should be 0. See ./thermal.txt for a description.
interrupts: Standard way to define interrupt number.
Example:
thermal-zones {
cpu_thermal: cpu-thermal {
polling-delay-passive = <0>;
polling-delay = <0>;
thermal-sensors = <&thermal>;
trips {
cpu_alert1: cpu-alert1 {
temperature = <85000>;
hysteresis = <0>;
type = "passive";
};
cpu-crit: cpu-crit {
temperature = <120000>;
hysteresis = <0>;
type = "critical";
};
};
cooling-maps {
};
};
};
thermal: thermal@50028000 {
compatible = "st,stm32-thermal";
reg = <0x50028000 0x100>;
clocks = <&rcc TMPSENS>;
clock-names = "pclk";
#thermal-sensor-cells = <0>;
interrupts = <GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>;
};
......@@ -152,7 +152,7 @@ Optional property:
Elem size: one cell the sensors listed in the thermal-sensors property.
Elem type: signed Coefficients defaults to 1, in case this property
is not specified. A simple linear polynomial is used:
Z = c0 * x0 + c1 + x1 + ... + c(n-1) * x(n-1) + cn.
Z = c0 * x0 + c1 * x1 + ... + c(n-1) * x(n-1) + cn.
The coefficients are ordered and they match with sensors
by means of sensor ID. Additional coefficients are
......
......@@ -432,7 +432,7 @@ source "drivers/thermal/samsung/Kconfig"
endmenu
menu "STMicroelectronics thermal drivers"
depends on ARCH_STI && OF
depends on (ARCH_STI || ARCH_STM32) && OF
source "drivers/thermal/st/Kconfig"
endmenu
......
......@@ -53,7 +53,7 @@ obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
obj-$(CONFIG_INT340X_THERMAL) += int340x_thermal/
obj-$(CONFIG_INTEL_BXT_PMIC_THERMAL) += intel_bxt_pmic_thermal.o
obj-$(CONFIG_INTEL_PCH_THERMAL) += intel_pch_thermal.o
obj-$(CONFIG_ST_THERMAL) += st/
obj-y += st/
obj-$(CONFIG_QCOM_TSENS) += qcom/
obj-y += tegra/
obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
......
......@@ -526,8 +526,8 @@ static int armada_thermal_probe_legacy(struct platform_device *pdev,
/* First memory region points towards the status register */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (IS_ERR(res))
return PTR_ERR(res);
if (!res)
return -EIO;
/*
* Edit the resource start address and length to map over all the
......
......@@ -106,7 +106,7 @@ static void da9062_thermal_poll_on(struct work_struct *work)
THERMAL_EVENT_UNSPECIFIED);
delay = msecs_to_jiffies(thermal->zone->passive_delay);
schedule_delayed_work(&thermal->work, delay);
queue_delayed_work(system_freezable_wq, &thermal->work, delay);
return;
}
......@@ -125,7 +125,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data)
struct da9062_thermal *thermal = data;
disable_irq_nosync(thermal->irq);
schedule_delayed_work(&thermal->work, 0);
queue_delayed_work(system_freezable_wq, &thermal->work, 0);
return IRQ_HANDLED;
}
......
This diff is collapsed.
......@@ -725,7 +725,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
} else {
ret = imx_init_from_tempmon_data(pdev);
if (ret) {
dev_err(&pdev->dev, "failed to init from from fsl,tempmon-data\n");
dev_err(&pdev->dev, "failed to init from fsl,tempmon-data\n");
return ret;
}
}
......@@ -762,9 +762,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
if (ret != -EPROBE_DEFER)
dev_err(&pdev->dev,
"failed to get thermal clk: %d\n", ret);
cpufreq_cooling_unregister(data->cdev);
cpufreq_cpu_put(data->policy);
return ret;
goto cpufreq_put;
}
/*
......@@ -777,9 +775,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
ret = clk_prepare_enable(data->thermal_clk);
if (ret) {
dev_err(&pdev->dev, "failed to enable thermal clk: %d\n", ret);
cpufreq_cooling_unregister(data->cdev);
cpufreq_cpu_put(data->policy);
return ret;
goto cpufreq_put;
}
data->tz = thermal_zone_device_register("imx_thermal_zone",
......@@ -792,10 +788,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
ret = PTR_ERR(data->tz);
dev_err(&pdev->dev,
"failed to register thermal zone device %d\n", ret);
clk_disable_unprepare(data->thermal_clk);
cpufreq_cooling_unregister(data->cdev);
cpufreq_cpu_put(data->policy);
return ret;
goto clk_disable;
}
dev_info(&pdev->dev, "%s CPU temperature grade - max:%dC"
......@@ -827,14 +820,20 @@ static int imx_thermal_probe(struct platform_device *pdev)
0, "imx_thermal", data);
if (ret < 0) {
dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret);
clk_disable_unprepare(data->thermal_clk);
thermal_zone_device_unregister(data->tz);
cpufreq_cooling_unregister(data->cdev);
cpufreq_cpu_put(data->policy);
return ret;
goto thermal_zone_unregister;
}
return 0;
thermal_zone_unregister:
thermal_zone_device_unregister(data->tz);
clk_disable:
clk_disable_unprepare(data->thermal_clk);
cpufreq_put:
cpufreq_cooling_unregister(data->cdev);
cpufreq_cpu_put(data->policy);
return ret;
}
static int imx_thermal_remove(struct platform_device *pdev)
......
......@@ -19,22 +19,33 @@
/*** Private data structures to represent thermal device tree data ***/
/**
* struct __thermal_bind_param - a match between trip and cooling device
* struct __thermal_cooling_bind_param - a cooling device for a trip point
* @cooling_device: a pointer to identify the referred cooling device
* @trip_id: the trip point index
* @usage: the percentage (from 0 to 100) of cooling contribution
* @min: minimum cooling state used at this trip point
* @max: maximum cooling state used at this trip point
*/
struct __thermal_bind_params {
struct __thermal_cooling_bind_param {
struct device_node *cooling_device;
unsigned int trip_id;
unsigned int usage;
unsigned long min;
unsigned long max;
};
/**
* struct __thermal_bind_param - a match between trip and cooling device
* @tcbp: a pointer to an array of cooling devices
* @count: number of elements in array
* @trip_id: the trip point index
* @usage: the percentage (from 0 to 100) of cooling contribution
*/
struct __thermal_bind_params {
struct __thermal_cooling_bind_param *tcbp;
unsigned int count;
unsigned int trip_id;
unsigned int usage;
};
/**
* struct __thermal_zone - internal representation of a thermal zone
* @mode: current thermal zone device mode (enabled/disabled)
......@@ -192,25 +203,31 @@ static int of_thermal_bind(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev)
{
struct __thermal_zone *data = thermal->devdata;
int i;
struct __thermal_bind_params *tbp;
struct __thermal_cooling_bind_param *tcbp;
int i, j;
if (!data || IS_ERR(data))
return -ENODEV;
/* find where to bind */
for (i = 0; i < data->num_tbps; i++) {
struct __thermal_bind_params *tbp = data->tbps + i;
tbp = data->tbps + i;
if (tbp->cooling_device == cdev->np) {
int ret;
for (j = 0; j < tbp->count; j++) {
tcbp = tbp->tcbp + j;
ret = thermal_zone_bind_cooling_device(thermal,
if (tcbp->cooling_device == cdev->np) {
int ret;
ret = thermal_zone_bind_cooling_device(thermal,
tbp->trip_id, cdev,
tbp->max,
tbp->min,
tcbp->max,
tcbp->min,
tbp->usage);
if (ret)
return ret;
if (ret)
return ret;
}
}
}
......@@ -221,22 +238,28 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev)
{
struct __thermal_zone *data = thermal->devdata;
int i;
struct __thermal_bind_params *tbp;
struct __thermal_cooling_bind_param *tcbp;
int i, j;
if (!data || IS_ERR(data))
return -ENODEV;
/* find where to unbind */
for (i = 0; i < data->num_tbps; i++) {
struct __thermal_bind_params *tbp = data->tbps + i;
tbp = data->tbps + i;
for (j = 0; j < tbp->count; j++) {
tcbp = tbp->tcbp + j;
if (tbp->cooling_device == cdev->np) {
int ret;
if (tcbp->cooling_device == cdev->np) {
int ret;
ret = thermal_zone_unbind_cooling_device(thermal,
tbp->trip_id, cdev);
if (ret)
return ret;
ret = thermal_zone_unbind_cooling_device(thermal,
tbp->trip_id, cdev);
if (ret)
return ret;
}
}
}
......@@ -486,8 +509,8 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data,
if (sensor_specs.args_count >= 1) {
id = sensor_specs.args[0];
WARN(sensor_specs.args_count > 1,
"%s: too many cells in sensor specifier %d\n",
sensor_specs.np->name, sensor_specs.args_count);
"%pOFn: too many cells in sensor specifier %d\n",
sensor_specs.np, sensor_specs.args_count);
} else {
id = 0;
}
......@@ -655,8 +678,9 @@ static int thermal_of_populate_bind_params(struct device_node *np,
int ntrips)
{
struct of_phandle_args cooling_spec;
struct __thermal_cooling_bind_param *__tcbp;
struct device_node *trip;
int ret, i;
int ret, i, count;
u32 prop;
/* Default weight. Usage is optional */
......@@ -683,20 +707,44 @@ static int thermal_of_populate_bind_params(struct device_node *np,
goto end;
}
ret = of_parse_phandle_with_args(np, "cooling-device", "#cooling-cells",
0, &cooling_spec);
if (ret < 0) {
pr_err("missing cooling_device property\n");
count = of_count_phandle_with_args(np, "cooling-device",
"#cooling-cells");
if (!count) {
pr_err("Add a cooling_device property with at least one device\n");
goto end;
}
__tbp->cooling_device = cooling_spec.np;
if (cooling_spec.args_count >= 2) { /* at least min and max */
__tbp->min = cooling_spec.args[0];
__tbp->max = cooling_spec.args[1];
} else {
pr_err("wrong reference to cooling device, missing limits\n");
__tcbp = kcalloc(count, sizeof(*__tcbp), GFP_KERNEL);
if (!__tcbp)
goto end;
for (i = 0; i < count; i++) {
ret = of_parse_phandle_with_args(np, "cooling-device",
"#cooling-cells", i, &cooling_spec);
if (ret < 0) {
pr_err("Invalid cooling-device entry\n");
goto free_tcbp;
}
__tcbp[i].cooling_device = cooling_spec.np;
if (cooling_spec.args_count >= 2) { /* at least min and max */
__tcbp[i].min = cooling_spec.args[0];
__tcbp[i].max = cooling_spec.args[1];
} else {
pr_err("wrong reference to cooling device, missing limits\n");
}
}
__tbp->tcbp = __tcbp;
__tbp->count = count;
goto end;
free_tcbp:
for (i = i - 1; i >= 0; i--)
of_node_put(__tcbp[i].cooling_device);
kfree(__tcbp);
end:
of_node_put(trip);
......@@ -903,8 +951,16 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
return tz;
free_tbps:
for (i = i - 1; i >= 0; i--)
of_node_put(tz->tbps[i].cooling_device);
for (i = i - 1; i >= 0; i--) {
struct __thermal_bind_params *tbp = tz->tbps + i;
int j;
for (j = 0; j < tbp->count; j++)
of_node_put(tbp->tcbp[j].cooling_device);
kfree(tbp->tcbp);
}
kfree(tz->tbps);
free_trips:
for (i = 0; i < tz->ntrips; i++)
......@@ -920,10 +976,18 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
static inline void of_thermal_free_zone(struct __thermal_zone *tz)
{
int i;
struct __thermal_bind_params *tbp;
int i, j;
for (i = 0; i < tz->num_tbps; i++) {
tbp = tz->tbps + i;
for (j = 0; j < tbp->count; j++)
of_node_put(tbp->tcbp[j].cooling_device);
kfree(tbp->tcbp);
}
for (i = 0; i < tz->num_tbps; i++)
of_node_put(tz->tbps[i].cooling_device);
kfree(tz->tbps);
for (i = 0; i < tz->ntrips; i++)
of_node_put(tz->trips[i].np);
......@@ -963,8 +1027,8 @@ int __init of_parse_thermal_zones(void)
tz = thermal_of_build_thermal_zone(child);
if (IS_ERR(tz)) {
pr_err("failed to build thermal zone %s: %ld\n",
child->name,
pr_err("failed to build thermal zone %pOFn: %ld\n",
child,
PTR_ERR(tz));
continue;
}
......@@ -998,7 +1062,7 @@ int __init of_parse_thermal_zones(void)
tz->passive_delay,
tz->polling_delay);
if (IS_ERR(zone)) {
pr_err("Failed to build %s zone %ld\n", child->name,
pr_err("Failed to build %pOFn zone %ld\n", child,
PTR_ERR(zone));
kfree(tzp);
kfree(ops);
......
......@@ -23,6 +23,8 @@
#include <linux/regmap.h>
#include <linux/thermal.h>
#include "thermal_core.h"
#define QPNP_TM_REG_TYPE 0x04
#define QPNP_TM_REG_SUBTYPE 0x05
#define QPNP_TM_REG_STATUS 0x08
......@@ -37,9 +39,11 @@
#define STATUS_GEN2_STATE_MASK GENMASK(6, 4)
#define STATUS_GEN2_STATE_SHIFT 4
#define SHUTDOWN_CTRL1_OVERRIDE_MASK GENMASK(7, 6)
#define SHUTDOWN_CTRL1_OVERRIDE_S2 BIT(6)
#define SHUTDOWN_CTRL1_THRESHOLD_MASK GENMASK(1, 0)
#define SHUTDOWN_CTRL1_RATE_25HZ BIT(3)
#define ALARM_CTRL_FORCE_ENABLE BIT(7)
/*
......@@ -56,12 +60,19 @@
#define TEMP_THRESH_STEP 5000 /* Threshold step: 5 C */
#define THRESH_MIN 0
#define THRESH_MAX 3
/* Stage 2 Threshold Min: 125 C */
#define STAGE2_THRESHOLD_MIN 125000
/* Stage 2 Threshold Max: 140 C */
#define STAGE2_THRESHOLD_MAX 140000
/* Temperature in Milli Celsius reported during stage 0 if no ADC is present */
#define DEFAULT_TEMP 37000
struct qpnp_tm_chip {
struct regmap *map;
struct device *dev;
struct thermal_zone_device *tz_dev;
unsigned int subtype;
long temp;
......@@ -69,6 +80,10 @@ struct qpnp_tm_chip {
unsigned int stage;
unsigned int prev_stage;
unsigned int base;
/* protects .thresh, .stage and chip registers */
struct mutex lock;
bool initialized;
struct iio_channel *adc;
};
......@@ -125,6 +140,8 @@ static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip)
unsigned int stage, stage_new, stage_old;
int ret;
WARN_ON(!mutex_is_locked(&chip->lock));
ret = qpnp_tm_get_temp_stage(chip);
if (ret < 0)
return ret;
......@@ -163,8 +180,15 @@ static int qpnp_tm_get_temp(void *data, int *temp)
if (!temp)
return -EINVAL;
if (!chip->initialized) {
*temp = DEFAULT_TEMP;
return 0;
}
if (!chip->adc) {
mutex_lock(&chip->lock);
ret = qpnp_tm_update_temp_no_adc(chip);
mutex_unlock(&chip->lock);
if (ret < 0)
return ret;
} else {
......@@ -180,8 +204,72 @@ static int qpnp_tm_get_temp(void *data, int *temp)
return 0;
}
static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
int temp)
{
u8 reg;
bool disable_s2_shutdown = false;
WARN_ON(!mutex_is_locked(&chip->lock));
/*
* Default: S2 and S3 shutdown enabled, thresholds at
* 105C/125C/145C, monitoring at 25Hz
*/
reg = SHUTDOWN_CTRL1_RATE_25HZ;
if (temp == THERMAL_TEMP_INVALID ||
temp < STAGE2_THRESHOLD_MIN) {
chip->thresh = THRESH_MIN;
goto skip;
}
if (temp <= STAGE2_THRESHOLD_MAX) {
chip->thresh = THRESH_MAX -
((STAGE2_THRESHOLD_MAX - temp) /
TEMP_THRESH_STEP);
disable_s2_shutdown = true;
} else {
chip->thresh = THRESH_MAX;
if (chip->adc)
disable_s2_shutdown = true;
else
dev_warn(chip->dev,
"No ADC is configured and critical temperature is above the maximum stage 2 threshold of 140 C! Configuring stage 2 shutdown at 140 C.\n");
}
skip:
reg |= chip->thresh;
if (disable_s2_shutdown)
reg |= SHUTDOWN_CTRL1_OVERRIDE_S2;
return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg);
}
static int qpnp_tm_set_trip_temp(void *data, int trip, int temp)
{
struct qpnp_tm_chip *chip = data;
const struct thermal_trip *trip_points;
int ret;
trip_points = of_thermal_get_trip_points(chip->tz_dev);
if (!trip_points)
return -EINVAL;
if (trip_points[trip].type != THERMAL_TRIP_CRITICAL)
return 0;
mutex_lock(&chip->lock);
ret = qpnp_tm_update_critical_trip_temp(chip, temp);
mutex_unlock(&chip->lock);
return ret;
}
static const struct thermal_zone_of_device_ops qpnp_tm_sensor_ops = {
.get_temp = qpnp_tm_get_temp,
.set_trip_temp = qpnp_tm_set_trip_temp,
};
static irqreturn_t qpnp_tm_isr(int irq, void *data)
......@@ -193,6 +281,29 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data)
return IRQ_HANDLED;
}
static int qpnp_tm_get_critical_trip_temp(struct qpnp_tm_chip *chip)
{
int ntrips;
const struct thermal_trip *trips;
int i;
ntrips = of_thermal_get_ntrips(chip->tz_dev);
if (ntrips <= 0)
return THERMAL_TEMP_INVALID;
trips = of_thermal_get_trip_points(chip->tz_dev);
if (!trips)
return THERMAL_TEMP_INVALID;
for (i = 0; i < ntrips; i++) {
if (of_thermal_is_trip_valid(chip->tz_dev, i) &&
trips[i].type == THERMAL_TRIP_CRITICAL)
return trips[i].temperature;
}
return THERMAL_TEMP_INVALID;
}
/*
* This function initializes the internal temp value based on only the
* current thermal stage and threshold. Setup threshold control and
......@@ -203,17 +314,20 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip)
unsigned int stage;