From patchwork Tue Aug 25 13:21:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 11735721 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E524E1751 for ; Tue, 25 Aug 2020 13:41:58 +0000 (UTC) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C69E2076C for ; Tue, 25 Aug 2020 13:41:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=lists.cip-project.org header.i=@lists.cip-project.org header.b="mFFiwbqW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C69E2076C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bp.renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=bounce+64572+5243+4520428+8129116@lists.cip-project.org X-Received: by 127.0.0.2 with SMTP id i4ewYY4521763xEX4xRKze7U; Tue, 25 Aug 2020 06:41:57 -0700 X-Received: from relmlie6.idc.renesas.com (relmlie6.idc.renesas.com []) by mx.groups.io with SMTP id smtpd.web12.13293.1598361720422412146 for ; Tue, 25 Aug 2020 06:22:05 -0700 X-IronPort-AV: E=Sophos;i="5.76,352,1592838000"; d="scan'208";a="55269194" X-Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 25 Aug 2020 22:22:04 +0900 X-Received: from localhost.localdomain (unknown [172.29.51.65]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 4FA404004950; Tue, 25 Aug 2020 22:22:03 +0900 (JST) From: Biju Das To: cip-dev@lists.cip-project.org, Nobuhiro Iwamatsu , Pavel Machek Cc: Chris Paterson , Biju Das , Prabhakar Mahadev Lad Subject: [cip-dev] [PATCH 4.19.y-cip 03/10] thermal: rcar_gen3_thermal: Generate interrupt when temperature changes Date: Tue, 25 Aug 2020 14:21:49 +0100 Message-Id: <20200825132156.7839-4-biju.das.jz@bp.renesas.com> In-Reply-To: <20200825132156.7839-1-biju.das.jz@bp.renesas.com> References: <20200825132156.7839-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: cip-dev@lists.cip-project.org List-Id: Mailing-List: list cip-dev@lists.cip-project.org; contact cip-dev+owner@lists.cip-project.org Delivered-To: mailing list cip-dev@lists.cip-project.org Reply-To: cip-dev@lists.cip-project.org X-Gm-Message-State: 4R6NYhyyhtAlZ88QmD5I9Bm8x4520428AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.cip-project.org; q=dns/txt; s=20140610; t=1598362917; bh=WQrmgbVuDkdlqZelqiSXjo/5tn49R2pyP03ZWCXx3p4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=mFFiwbqWzzMwDWC85p/B8lba8U2y9q3BaTZ+Zrm+0oLmqr3EGd6bh6iI5uO2GpRarYd p7v5uFKqj80Z0cuup3xXF3KR2vqhhX/J2z4dSp8FNriUwJ3opl4ibRIBqSDmurqsY/h3x E7AQ2LnGPMON+fPYg1QCIt/BVZ9GKIGC3qg= From: Niklas Söderlund commit 267c4d8d132c8646fc90a58d40e3117656a4e9b5 upstream. 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 Reviewed-by: Yoshihiro Shimoda Reviewed-by: Kieran Bingham Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20200212224917.737314-1-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Biju Das --- drivers/thermal/rcar_gen3_thermal.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index e7a0c7fc9897..166cadf4bf02 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -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 */ }; @@ -204,12 +202,14 @@ 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)); @@ -217,15 +217,11 @@ static int rcar_gen3_thermal_set_trips(void *devdata, int low, int high) 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) @@ -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; @@ -451,6 +449,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); } @@ -489,7 +489,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);