From patchwork Mon May 13 20:03:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 10941705 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1807A14DB for ; Mon, 13 May 2019 20:04:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07D2C283C3 for ; Mon, 13 May 2019 20:04:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F08272841D; Mon, 13 May 2019 20:04:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B23A283CA for ; Mon, 13 May 2019 20:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726233AbfEMUEO (ORCPT ); Mon, 13 May 2019 16:04:14 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43500 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725928AbfEMUEN (ORCPT ); Mon, 13 May 2019 16:04:13 -0400 Received: by mail-pf1-f194.google.com with SMTP id c6so7762706pfa.10; Mon, 13 May 2019 13:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kohCOyVtYT/37SXICTY60qowJFgNNpE4dJPKwqxFQI4=; b=DEE1mLA2YcaVr5H9RFmEJi0u32DKMlTK8ecX+WEeE/efUSF4xZTsS3bvmjLTjZUXey hCGwY/UOOgSDlE7lSKl8Y0sfFpy6xJ2547J+3SmR2bfwNKsbgbLyCtREuvwYlPwscpCT nyD8SNCYBgqIKmx5hYq1kC/Nzcg0GdOSQ45RDi8Ih5jwYsTae/aX8wHRJYUnUt60QRU1 wG/tB0qbEXxXAOGGHKCeLypIFljnMorJ7JGOLVbd83/hCcoYJJ++W6TKXen/7c7ROmsq XJczR2ApsS14jhOSuhwBPEs7db4Aj6nGLDEAI6hk1o2CrE87kSMNdUrVQEUyRPyW5sP3 V34A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kohCOyVtYT/37SXICTY60qowJFgNNpE4dJPKwqxFQI4=; b=fkY94C9ZhrXfZkRdyaYUrvxT80CmYfhu8yx7pNLEelWMlMN23IGklSCIKUZ+cLNuT/ Cn0X/SIdjLqsPbZaWXt6gt5Jhr19pOwkGFNh8tZSzv3gcXJj46+Z4rerikAI+9glHUtn bwG9zjnR5Erf5PHeogad2wZrEkn8inSD6E7+X3soodWpt7q/o8QNq+QY61uNPYE4hYwK rDcoLKcPSLqb+WPDOHYrbxqtCZo9rVMEBDm/I55zCQNA3rL0c2A12A+EuGJ2WkAnPdvp kS/+mJKO2iV29RlYdZNhWYjrpmpEt4f9tpCC2MIg1Ffi8SE2xiRNRFI8a9bz3/ZBNSTO 3T7w== X-Gm-Message-State: APjAAAVXwfIq/wj82lL2v/Bl0beY1A1Eby6kSMJFdyTpxVsIkyWoIuY6 Qaued25nQVEwkp33gThrW2ak6V0y X-Google-Smtp-Source: APXvYqyiVYHtDDyhZAgZtTuYWU1mPVzi2rMHI+6YpfHiCRF9r8hfbL8GxW+XCJfZJQCR2cPYyFUzLw== X-Received: by 2002:a63:6647:: with SMTP id a68mr18125002pgc.292.1557777852952; Mon, 13 May 2019 13:04:12 -0700 (PDT) Received: from localhost.localdomain (KD118155013174.ppp-bb.dion.ne.jp. [118.155.13.174]) by smtp.gmail.com with ESMTPSA id y3sm19167506pfe.9.2019.05.13.13.04.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 May 2019 13:04:12 -0700 (PDT) From: Yoshihiro Kaneko To: linux-pm@vger.kernel.org Cc: Zhang Rui , Eduardo Valentin , Rob Herring , Simon Horman , Magnus Damm , linux-renesas-soc@vger.kernel.org Subject: [PATCH/RFT v3 1/3] thermal: rcar_gen3_thermal: Update value of Tj_1 Date: Tue, 14 May 2019 05:03:53 +0900 Message-Id: <1557777835-19454-2-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1557777835-19454-1-git-send-email-ykaneko0929@gmail.com> References: <1557777835-19454-1-git-send-email-ykaneko0929@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As evaluation of hardware team, temperature calculation formula of M3-W is difference from all other SoCs as below: - M3-W: Tj_1: 116 (so Tj_1 - Tj_3 = 157) - Others: Tj_1: 126 (so Tj_1 - Tj_3 = 167) Signed-off-by: Yoshihiro Kaneko --- drivers/thermal/rcar_gen3_thermal.c | 41 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index 88fa41c..265ff6d 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -124,11 +124,11 @@ static inline void rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc, #define RCAR3_THERMAL_GRAN 500 /* mili Celsius */ /* no idea where these constants come from */ -#define TJ_1 116 #define TJ_3 -41 static void rcar_gen3_thermal_calc_coefs(struct equation_coefs *coef, - int *ptat, int *thcode) + int *ptat, int *thcode, + int ths_tj_1) { int tj_2; @@ -139,15 +139,15 @@ static void rcar_gen3_thermal_calc_coefs(struct equation_coefs *coef, * the dividend (4095 * 4095 << 14 > INT_MAX) so keep it unscaled */ tj_2 = (FIXPT_INT((ptat[1] - ptat[2]) * 157) - / (ptat[0] - ptat[2])) - FIXPT_INT(41); + / (ptat[0] - ptat[2])) + FIXPT_INT(TJ_3); coef->a1 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]), tj_2 - FIXPT_INT(TJ_3)); coef->b1 = FIXPT_INT(thcode[2]) - coef->a1 * TJ_3; coef->a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), - tj_2 - FIXPT_INT(TJ_1)); - coef->b2 = FIXPT_INT(thcode[0]) - coef->a2 * TJ_1; + tj_2 - FIXPT_INT(ths_tj_1)); + coef->b2 = FIXPT_INT(thcode[0]) - coef->a2 * ths_tj_1; } static int rcar_gen3_thermal_round(int temp) @@ -318,12 +318,29 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_tsc *tsc) usleep_range(1000, 2000); } +static const int rcar_gen3_ths_tj_1 = 126; +static const int rcar_gen3_ths_tj_1_m3_w = 116; static const struct of_device_id rcar_gen3_thermal_dt_ids[] = { - { .compatible = "renesas,r8a774a1-thermal", }, - { .compatible = "renesas,r8a7795-thermal", }, - { .compatible = "renesas,r8a7796-thermal", }, - { .compatible = "renesas,r8a77965-thermal", }, - { .compatible = "renesas,r8a77980-thermal", }, + { + .compatible = "renesas,r8a774a1-thermal", + .data = &rcar_gen3_ths_tj_1_m3_w, + }, + { + .compatible = "renesas,r8a7795-thermal", + .data = &rcar_gen3_ths_tj_1, + }, + { + .compatible = "renesas,r8a7796-thermal", + .data = &rcar_gen3_ths_tj_1_m3_w, + }, + { + .compatible = "renesas,r8a77965-thermal", + .data = &rcar_gen3_ths_tj_1, + }, + { + .compatible = "renesas,r8a77980-thermal", + .data = &rcar_gen3_ths_tj_1, + }, {}, }; MODULE_DEVICE_TABLE(of, rcar_gen3_thermal_dt_ids); @@ -349,6 +366,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) { struct rcar_gen3_thermal_priv *priv; struct device *dev = &pdev->dev; + const int *rcar_gen3_ths_tj_1 = of_device_get_match_data(dev); struct resource *res; struct thermal_zone_device *zone; int ret, irq, i; @@ -422,7 +440,8 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) priv->tscs[i] = tsc; priv->thermal_init(tsc); - rcar_gen3_thermal_calc_coefs(&tsc->coef, ptat, thcode[i]); + rcar_gen3_thermal_calc_coefs(&tsc->coef, ptat, thcode[i], + *rcar_gen3_ths_tj_1); zone = devm_thermal_zone_of_sensor_register(dev, i, tsc, &rcar_gen3_tz_of_ops); From patchwork Mon May 13 20:03:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 10941709 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26EF014DB for ; Mon, 13 May 2019 20:04:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19A6D283C3 for ; Mon, 13 May 2019 20:04:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DB182841D; Mon, 13 May 2019 20:04:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A86A0283CA for ; Mon, 13 May 2019 20:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726241AbfEMUER (ORCPT ); Mon, 13 May 2019 16:04:17 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40017 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725928AbfEMUER (ORCPT ); Mon, 13 May 2019 16:04:17 -0400 Received: by mail-pf1-f195.google.com with SMTP id u17so7767633pfn.7; Mon, 13 May 2019 13:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SydvbyyQhG9l+iV51oR0mTsbiib4ordz8eglryY7UWQ=; b=lYFBRhVDFUhWWfIfI+VLAoqC7hGTMz62vqT5OyZuszgmi0Q4RdQztJ01f2dhWcMzIL /blFmpP3eZvJUW06hr/ypXyXF9LcxopqJitouSD9q2UM/uror2jb9W+go24EwhSZEQvv WQmF6GALppHwAn8VKzFXiUMg2aUPifKbx497HwtuVsW0TyUwtZCkHmEscK9bO8wI4gTG swIsUmuFqs+xqMTGVhvNs1LbB9HD6U+fSeChg9j96ZBXDZ3lpFLVTIP2zK2dGyMyhnll 0VnqQ1Z8H4cjbYEHFrNcxYZOXy52I/eaSSqrJn3XRZGfBCGk+EzlMTj18bCbi5Pl2qZZ 9q9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SydvbyyQhG9l+iV51oR0mTsbiib4ordz8eglryY7UWQ=; b=cmgxabUj6W0yxsVjGTL21q0KyQQn95nFfCbStUfKVAAWnYiTJr7bZHdQSZlXMcGjWR r6dA6pixYRAqHeCwxGYFyLknd17+QtXg47PYaquSEsHvWIDc3eWTB7z+AG2miaI8RLUG 6qKbeIGVDQ2WMM6Ac3He1spXY5+8IrIls9FeNFlRqECBDZyvtfcpGUABMlBBvls77yPa bUmEFxfRhZzYtrFwFWuXgDV+qP9B3ELS7NzR5J7ja3cqp1n0lYZZomdlpZQzgWHszY+R 9A1CMNTziEVPdFZ2k624do3CQY78oDJ3xDxvjzYw59TvbSK111xGf62w/XwPBc1ujHNR L2mg== X-Gm-Message-State: APjAAAU/5oZLylNIMNB78gaVXp25jwoO9VvJEjIJXXvSXS2gNJa0g5WT oumH+Q/NFCJRKYMKQcr0m+o+8824 X-Google-Smtp-Source: APXvYqyqi3KTPUPXr/kXdZFQ4xZj4K7vI3QOLSgy+8pqmv+EypHdt5wIbseBUcrS4szHK0F2RUNW9g== X-Received: by 2002:a63:5964:: with SMTP id j36mr33869785pgm.384.1557777856235; Mon, 13 May 2019 13:04:16 -0700 (PDT) Received: from localhost.localdomain (KD118155013174.ppp-bb.dion.ne.jp. [118.155.13.174]) by smtp.gmail.com with ESMTPSA id y3sm19167506pfe.9.2019.05.13.13.04.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 May 2019 13:04:15 -0700 (PDT) From: Yoshihiro Kaneko To: linux-pm@vger.kernel.org Cc: Zhang Rui , Eduardo Valentin , Rob Herring , Simon Horman , Magnus Damm , linux-renesas-soc@vger.kernel.org Subject: [PATCH/RFT v3 2/3] thermal: rcar_gen3_thermal: Update calculation formula of IRQTEMP Date: Tue, 14 May 2019 05:03:54 +0900 Message-Id: <1557777835-19454-3-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1557777835-19454-1-git-send-email-ykaneko0929@gmail.com> References: <1557777835-19454-1-git-send-email-ykaneko0929@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Update the formula to calculate CTEMP: Currently, the CTEMP is average of val1 (is calculated by formula 1) and val2 (is calculated by formula 2). But, as description in HWM (chapter 10A.3.1.1 Setting of Normal Mode) If (STEMP < Tj_T) CTEMP value should be val1. If (STEMP > Tj_T) CTEMP value should be val2. Signed-off-by: Yoshihiro Kaneko --- drivers/thermal/rcar_gen3_thermal.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index 265ff6d..a2873e7 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -77,6 +77,7 @@ struct rcar_gen3_thermal_tsc { struct equation_coefs coef; int low; int high; + int tj_t; }; struct rcar_gen3_thermal_priv { @@ -126,28 +127,26 @@ static inline void rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc, /* no idea where these constants come from */ #define TJ_3 -41 -static void rcar_gen3_thermal_calc_coefs(struct equation_coefs *coef, +static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc, int *ptat, int *thcode, int ths_tj_1) { - int tj_2; - /* TODO: Find documentation and document constant calculation formula */ /* * Division is not scaled in BSP and if scaled it might overflow * the dividend (4095 * 4095 << 14 > INT_MAX) so keep it unscaled */ - tj_2 = (FIXPT_INT((ptat[1] - ptat[2]) * 157) - / (ptat[0] - ptat[2])) + FIXPT_INT(TJ_3); + tsc->tj_t = (FIXPT_INT((ptat[1] - ptat[2]) * 157) + / (ptat[0] - ptat[2])) + FIXPT_INT(TJ_3); - coef->a1 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]), - tj_2 - FIXPT_INT(TJ_3)); - coef->b1 = FIXPT_INT(thcode[2]) - coef->a1 * TJ_3; + tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]), + tsc->tj_t - FIXPT_INT(TJ_3)); + tsc->coef.b1 = FIXPT_INT(thcode[2]) - tsc->coef.a1 * TJ_3; - coef->a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), - tj_2 - FIXPT_INT(ths_tj_1)); - coef->b2 = FIXPT_INT(thcode[0]) - coef->a2 * ths_tj_1; + tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), + tsc->tj_t - FIXPT_INT(ths_tj_1)); + tsc->coef.b2 = FIXPT_INT(thcode[0]) - tsc->coef.a2 * ths_tj_1; } static int rcar_gen3_thermal_round(int temp) @@ -186,13 +185,15 @@ static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc, int mcelsius) { - int celsius, val1, val2; + int celsius, val; celsius = DIV_ROUND_CLOSEST(mcelsius, 1000); - val1 = celsius * tsc->coef.a1 + tsc->coef.b1; - val2 = celsius * tsc->coef.a2 + tsc->coef.b2; + if (celsius <= INT_FIXPT(tsc->tj_t)) + val = celsius * tsc->coef.a1 + tsc->coef.b1; + else + val = celsius * tsc->coef.a2 + tsc->coef.b2; - return INT_FIXPT((val1 + val2) / 2); + return INT_FIXPT(val); } static int rcar_gen3_thermal_set_trips(void *devdata, int low, int high) @@ -440,7 +441,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) priv->tscs[i] = tsc; priv->thermal_init(tsc); - rcar_gen3_thermal_calc_coefs(&tsc->coef, ptat, thcode[i], + rcar_gen3_thermal_calc_coefs(tsc, ptat, thcode[i], *rcar_gen3_ths_tj_1); zone = devm_thermal_zone_of_sensor_register(dev, i, tsc, From patchwork Mon May 13 20:03:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 10941713 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 720B614DB for ; Mon, 13 May 2019 20:04:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62637283C3 for ; Mon, 13 May 2019 20:04:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 569302841D; Mon, 13 May 2019 20:04:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFEDD283CA for ; Mon, 13 May 2019 20:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726251AbfEMUEU (ORCPT ); Mon, 13 May 2019 16:04:20 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40887 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725928AbfEMUEU (ORCPT ); Mon, 13 May 2019 16:04:20 -0400 Received: by mail-pg1-f195.google.com with SMTP id d31so7314161pgl.7; Mon, 13 May 2019 13:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=647q/9btvZL+BLiFNB10S0rDzh+440L2Fuda1o7ZvI0=; b=Tg6Ss2JZzkUeANxlGA35bnhZ5wWeMKKfDWvlZ17+Ufjyz266q3eaOxE6VJtitRJlVt IaPPnj8/Fyq633p3RnFuJRBzAs/7CYHk48ppy7LhJv7izP93DoRUIl+DDzM+5TML6H0B ha+cG4bDUWSGwBgsYmyPInxu2TtGMq4FVNlmip1mJlgCDaPrA9kU1D8Qew0RX96X4LvP TFg2yuscs88xoSHgpsXo2psVWKnh1bubHdsYUvXZUo8yuhbpmQ6r5Mh1D4R8xfrCdAJN jauI8ONuWUlvTxZZssXFS8F+pzYuximQbdPU6WWmJqJe8OhjbvTZdUUFwjxy8Fwbh/S0 JByA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=647q/9btvZL+BLiFNB10S0rDzh+440L2Fuda1o7ZvI0=; b=uBW8p9563p7u3A8Wgjzv7gO5Br8WhfJ5ZSYANQ+94ZQjDecegPb/Q2kOKvgRM93p2Y oQC3XoqShnixPPN4WfBU6VSfPqoIqk2PHl51yMK0eztE9Vf32ZuIosiHIv3gY6HHjkfL e6ewczHVObAxpXZv+eD5xukZ6QjeGndlTAhC4XboEmcNoc+pxO9FMB7sle0n6Y/7w4t1 X1z+/fUrni12HoBKR14Y3jI6WliqT0yanuPP+scWqmzTkAe4QldNkdErap43noIe4as0 X+MeOTd7MsEHd6X2Yb36QeHtKIjxLRmaPzEJdipsBW2OqqTHJSk8pP8SD48wpuXceRYE Lpxg== X-Gm-Message-State: APjAAAX/XuqF2eP20zLkhsa3Ij9IXdXK/XM3Nz7KU7K9rYG4767GT1RK ViFKEFCEXJ1prPrRNED3ETd5BtYr X-Google-Smtp-Source: APXvYqz4EQThvJcH9VflMuI03PjfB8orVz6VT/I2RgSG8By4opEd3Komtsprx/pq7y8hOuAxMarULQ== X-Received: by 2002:a63:1820:: with SMTP id y32mr33396629pgl.287.1557777859289; Mon, 13 May 2019 13:04:19 -0700 (PDT) Received: from localhost.localdomain (KD118155013174.ppp-bb.dion.ne.jp. [118.155.13.174]) by smtp.gmail.com with ESMTPSA id y3sm19167506pfe.9.2019.05.13.13.04.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 May 2019 13:04:18 -0700 (PDT) From: Yoshihiro Kaneko To: linux-pm@vger.kernel.org Cc: Zhang Rui , Eduardo Valentin , Rob Herring , Simon Horman , Magnus Damm , linux-renesas-soc@vger.kernel.org Subject: [PATCH/RFT v3 3/3] thermal: rcar_gen3_thermal: Update temperature conversion method Date: Tue, 14 May 2019 05:03:55 +0900 Message-Id: <1557777835-19454-4-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1557777835-19454-1-git-send-email-ykaneko0929@gmail.com> References: <1557777835-19454-1-git-send-email-ykaneko0929@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Update the formula to calculate temperature: Currently, current TEMP is calculated as average of val1 (is calculated by formula 1) and val2 (is calculated by formula 2). But, as description in HWM (chapter 10A.3.1.2 Normal Mode.) If (TEMP_CODE < THCODE2[11:0]) CTEMP value should be val1. If (TEMP_CODE > THCODE2[11:0]) CTEMP value should be val2. Signed-off-by: Yoshihiro Kaneko --- drivers/thermal/rcar_gen3_thermal.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index a2873e7..661b36c 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -63,6 +63,13 @@ #define TSC_MAX_NUM 3 +/* default THCODE values if FUSEs are missing */ +static const int thcode[TSC_MAX_NUM][3] = { + { 3397, 2800, 2221 }, + { 3393, 2795, 2216 }, + { 3389, 2805, 2237 }, +}; + /* Structure for thermal temperature calculation */ struct equation_coefs { int a1; @@ -78,6 +85,7 @@ struct rcar_gen3_thermal_tsc { int low; int high; int tj_t; + int id; /* thermal channel id */ }; struct rcar_gen3_thermal_priv { @@ -128,7 +136,7 @@ static inline void rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc, #define TJ_3 -41 static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc, - int *ptat, int *thcode, + int *ptat, const int *thcode, int ths_tj_1) { /* TODO: Find documentation and document constant calculation formula */ @@ -162,15 +170,19 @@ static int rcar_gen3_thermal_round(int temp) static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) { struct rcar_gen3_thermal_tsc *tsc = devdata; - int mcelsius, val1, val2; + int mcelsius, val; u32 reg; /* Read register and convert to mili Celsius */ reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK; - val1 = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, tsc->coef.a1); - val2 = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, tsc->coef.a2); - mcelsius = FIXPT_TO_MCELSIUS((val1 + val2) / 2); + if (reg <= thcode[tsc->id][1]) + val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, + tsc->coef.a1); + else + val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, + tsc->coef.a2); + mcelsius = FIXPT_TO_MCELSIUS(val); /* Make sure we are inside specifications */ if ((mcelsius < MCELSIUS(-40)) || (mcelsius > MCELSIUS(125))) @@ -376,11 +388,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) /* default values if FUSEs are missing */ /* TODO: Read values from hardware on supported platforms */ int ptat[3] = { 2631, 1509, 435 }; - int thcode[TSC_MAX_NUM][3] = { - { 3397, 2800, 2221 }, - { 3393, 2795, 2216 }, - { 3389, 2805, 2237 }, - }; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -437,6 +444,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(tsc->base); goto error_unregister; } + tsc->id = i; priv->tscs[i] = tsc;