Skip to content

Commit

Permalink
thermal: rcar_gen3_thermal: Generate interrupt when temperature changes
Browse files Browse the repository at this point in the history
The desired behavior of the driver is to generate an interrupt and call
thermal_zone_device_update() as soon as the temperature have changed
more then one degree.

When the set_trips operation was implemented it was believed that the
trip window set by the framework would move around the current
temperature and the hysteresis value described in devicetree. The
behavior of the framework is however to set a window based on the trip
points described in devicetree.

Remove the set_trips operation which was not used correctly and update
the temperatures that triggers interrupts directly from the interrupt
handler.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20200212224917.737314-1-niklas.soderlund+renesas@ragnatech.se
  • Loading branch information
Niklas Söderlund authored and Daniel Lezcano committed Mar 12, 2020
1 parent d543c84 commit 267c4d8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions drivers/thermal/rcar_gen3_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ struct rcar_gen3_thermal_tsc {
void __iomem *base;
struct thermal_zone_device *zone;
struct equation_coefs coef;
int low;
int high;
int tj_t;
int id; /* thermal channel id */
};
Expand Down Expand Up @@ -204,28 +202,26 @@ static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc,
return INT_FIXPT(val);
}

static int rcar_gen3_thermal_set_trips(void *devdata, int low, int high)
static int rcar_gen3_thermal_update_range(struct rcar_gen3_thermal_tsc *tsc)
{
struct rcar_gen3_thermal_tsc *tsc = devdata;
int temperature, low, high;

rcar_gen3_thermal_get_temp(tsc, &temperature);

low = clamp_val(low, -40000, 120000);
high = clamp_val(high, -40000, 120000);
low = temperature - MCELSIUS(1);
high = temperature + MCELSIUS(1);

rcar_gen3_thermal_write(tsc, REG_GEN3_IRQTEMP1,
rcar_gen3_thermal_mcelsius_to_temp(tsc, low));

rcar_gen3_thermal_write(tsc, REG_GEN3_IRQTEMP2,
rcar_gen3_thermal_mcelsius_to_temp(tsc, high));

tsc->low = low;
tsc->high = high;

return 0;
}

static const struct thermal_zone_of_device_ops rcar_gen3_tz_of_ops = {
.get_temp = rcar_gen3_thermal_get_temp,
.set_trips = rcar_gen3_thermal_set_trips,
};

static void rcar_thermal_irq_set(struct rcar_gen3_thermal_priv *priv, bool on)
Expand All @@ -246,9 +242,11 @@ static irqreturn_t rcar_gen3_thermal_irq(int irq, void *data)
for (i = 0; i < priv->num_tscs; i++) {
status = rcar_gen3_thermal_read(priv->tscs[i], REG_GEN3_IRQSTR);
rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQSTR, 0);
if (status)
if (status) {
rcar_gen3_thermal_update_range(priv->tscs[i]);
thermal_zone_device_update(priv->tscs[i]->zone,
THERMAL_EVENT_UNSPECIFIED);
}
}

return IRQ_HANDLED;
Expand Down Expand Up @@ -453,6 +451,8 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
if (ret < 0)
goto error_unregister;

rcar_gen3_thermal_update_range(tsc);

dev_info(dev, "TSC%d: Loaded %d trip points\n", i, ret);
}

Expand Down Expand Up @@ -491,7 +491,7 @@ static int __maybe_unused rcar_gen3_thermal_resume(struct device *dev)
struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i];

priv->thermal_init(tsc);
rcar_gen3_thermal_set_trips(tsc, tsc->low, tsc->high);
rcar_gen3_thermal_update_range(tsc);
}

rcar_thermal_irq_set(priv, true);
Expand Down

0 comments on commit 267c4d8

Please sign in to comment.