From patchwork Tue Apr 16 17:44:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 10903587 X-Patchwork-Delegate: geert@linux-m68k.org 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 1469114DB for ; Tue, 16 Apr 2019 17:44:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEA572785D for ; Tue, 16 Apr 2019 17:44:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1B1328468; Tue, 16 Apr 2019 17:44:34 +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=ham 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 7D1BD2785D for ; Tue, 16 Apr 2019 17:44:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729909AbfDPRoe (ORCPT ); Tue, 16 Apr 2019 13:44:34 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40827 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727180AbfDPRoe (ORCPT ); Tue, 16 Apr 2019 13:44:34 -0400 Received: by mail-pg1-f195.google.com with SMTP id d31so10681774pgl.7; Tue, 16 Apr 2019 10:44:33 -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=jsbPM1PB6pp7nEXaKWf2/ssPsShBgfDSwohisCd8xh8=; b=pzGS2NHLrVrBBiLrA7ZA0HXqROoysmpFQOhhVcmN7jZ0EOPP4zZ0BIwfnwsaCKqmqB 8moqkcY7Wzw63vJoK9ee+UUrHq51Kwyc6ivkRU1x54Iu+K+bPK19a7Ges3mcj0fMS7Rc /8upUBYfZmq2MirpaOhQZiOUbcnO4dQOeNp8TbDK8tcD1XsPBomAYzr81UW7c2FNwl+c POUIRJ830f/5cIc7qT8iM+UVMw+uki+tSBD45MnDSvJ98yykrLqzoYyW+nd4VhUSfd+L 45mVRHZ+er5oZyRNh7I1VlAIyVcRYuJIQFdyT6kk6saK9BSOZBXiJi+iEOhzJEikYYtl 1ICA== 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=jsbPM1PB6pp7nEXaKWf2/ssPsShBgfDSwohisCd8xh8=; b=j+oxMPfN9wVY9runH8CApFmT74q1iY8ouSGFWRthK01MjXsKKKLIn86HylQofIlAmf Y2qf1J6Og6jZKMheuELjpABEROVucbXOl0E7YzgX8KvyPbSuvVcBKnLKCqxd2X0jr3ej MFOPnZVBFIqiHiXLsJhUu7gRSJyVsTxmDqNTHZ5B20h+AhwJwZ/mCfFhGAcA+lqusU/z xaKIiyOe9TWRsTxqgmIsLQZgrT4/P+vFQMkodNy5TKVxgh1RPIBS2lZClZkNYMLxZS8y kbfFZp2w0nnA35LGagPD2uxDGUY1a/e6N6q4e7rYQ4tyUzySp1KbFQTHtGKlygvMTv5n A4wQ== X-Gm-Message-State: APjAAAU+ENDKMWJ/gi9BwDPVQQRd46zTK3o83PD+3K9rPNJNBnDPzOKr wRJSyWOSJho4e7iYQsYWeSZtO6nA X-Google-Smtp-Source: APXvYqzAtcxJ+4tOmt2aIYIaIP07OGFMS6Q1FNLWGap7qok+ner47haamRUOqonhnhGzr24fZ+UHcw== X-Received: by 2002:a62:69c2:: with SMTP id e185mr83456661pfc.119.1555436673141; Tue, 16 Apr 2019 10:44:33 -0700 (PDT) Received: from localhost.localdomain (KD118155013174.ppp-bb.dion.ne.jp. [118.155.13.174]) by smtp.gmail.com with ESMTPSA id f20sm39763791pff.176.2019.04.16.10.44.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Apr 2019 10:44:32 -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 v2 1/3] thermal: rcar_gen3_thermal: Update value of Tj_1 Date: Wed, 17 Apr 2019 02:44:13 +0900 Message-Id: <1555436655-5262-2-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555436655-5262-1-git-send-email-ykaneko0929@gmail.com> References: <1555436655-5262-1-git-send-email-ykaneko0929@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@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..a2fd0fd 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, + unsigned 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 unsigned int rcar_gen3_ths_tj_1 = 126; +static const unsigned 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 unsigned 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 Tue Apr 16 17:44:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 10903591 X-Patchwork-Delegate: geert@linux-m68k.org 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 A0184922 for ; Tue, 16 Apr 2019 17:44:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87EBB2785D for ; Tue, 16 Apr 2019 17:44:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BCA328468; Tue, 16 Apr 2019 17:44:37 +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=ham 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 15D0F2785D for ; Tue, 16 Apr 2019 17:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730019AbfDPRog (ORCPT ); Tue, 16 Apr 2019 13:44:36 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37790 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727180AbfDPRog (ORCPT ); Tue, 16 Apr 2019 13:44:36 -0400 Received: by mail-pg1-f194.google.com with SMTP id e6so10691634pgc.4; Tue, 16 Apr 2019 10:44:36 -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=uXqJwGYbWPvLuqN2q64M5FrfdD3hYmhiNr9td7M0BAg=; b=tNexly5HdIEvp+ZfwKznG1et5SguN04ex8CB9WBcDz4/IhKEySo/meJEWbX1Vc9Q/7 m9ckkoM7NajxEnQY/dODcxDxxRMS3/1jXhsXtzkRf/1XKxeVSqgLlLF1LqZIPyTL3mWC Q9NZ6aoS7ft0+d3Lgzveyb1Q4WYfF1Pi5sWse7I873NhCebaKm3fQFWmqqUFIkepaJD7 A2BJ+nyg8F/Pym4J5RPUIR5lNkDQspvXXhfyarWsPmNRu8oPubp3PUuqiqWmTgJ/VrBJ 8aXu4tsyH5v0SWpcuaovV4w8LZcvcMEtGvNtHjrAW4J153IvR1zxYs7C7LXm4XOU+dsX DhvA== 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=uXqJwGYbWPvLuqN2q64M5FrfdD3hYmhiNr9td7M0BAg=; b=AciscVSIyQjNBAaPVFu/UyzhZHVHvVa2pGtsRcsLEn/q6vmORMFrzgy7W/yPfJ/+EH poUslPLVNGqvXIeY00sLSjhUKCfJup8cSxpexHRgGKRpr5V6JVM466nqsrv+WodOCo3v o15nU3RMTRvIkhn5yiPB0hiew6xrTBdfA8oIuk94gmC9YJ184W3rd4Ftwr5WRiziCsTp Dw/5Dhaf+WhGfDGLVWoYp2Wpv593db3PIYNbCTHOFovV5I1JsPC2FRrcnP/cYyxDG9UO Oh3NghUtChpUyId59p1mWmOMfO4tf7druVioSG3ngwFzjdn5zFhP7v6nWc/s7ybp81RB M3kA== X-Gm-Message-State: APjAAAViBKl6Xsa2drHs2DDXnB5HameAhMp4aEBbwbts5rqM1l6f1OV/ nH1zbHoxE+/8Gz0AnTws5hF6GTaV X-Google-Smtp-Source: APXvYqyuuqIaedYQkb6OkOPf60Wj20j2wkX2XgoDjvvzoMQGy5HddxoIAYs1aMiaWvZxbsV9ijaG3Q== X-Received: by 2002:a63:b48:: with SMTP id a8mr69383607pgl.368.1555436675738; Tue, 16 Apr 2019 10:44:35 -0700 (PDT) Received: from localhost.localdomain (KD118155013174.ppp-bb.dion.ne.jp. [118.155.13.174]) by smtp.gmail.com with ESMTPSA id f20sm39763791pff.176.2019.04.16.10.44.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Apr 2019 10:44:34 -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 v2 2/3] thermal: rcar_gen3_thermal: Update calculation formula of IRQTEMP Date: Wed, 17 Apr 2019 02:44:14 +0900 Message-Id: <1555436655-5262-3-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555436655-5262-1-git-send-email-ykaneko0929@gmail.com> References: <1555436655-5262-1-git-send-email-ykaneko0929@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@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 | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index a2fd0fd..97cf3cd 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_2; }; struct rcar_gen3_thermal_priv { @@ -126,28 +127,27 @@ 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, unsigned 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_2 = (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_2 - 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_2 - 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 +186,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_2)) + 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 +442,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 Tue Apr 16 17:44:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 10903595 X-Patchwork-Delegate: geert@linux-m68k.org 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 286C8922 for ; Tue, 16 Apr 2019 17:44:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DCBB1FF62 for ; Tue, 16 Apr 2019 17:44:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0105B28468; Tue, 16 Apr 2019 17:44:39 +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=ham 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 90E6E283AD for ; Tue, 16 Apr 2019 17:44:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730046AbfDPRoj (ORCPT ); Tue, 16 Apr 2019 13:44:39 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:44112 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728468AbfDPRoj (ORCPT ); Tue, 16 Apr 2019 13:44:39 -0400 Received: by mail-pf1-f193.google.com with SMTP id y13so10743179pfm.11; Tue, 16 Apr 2019 10:44:38 -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=/u94BtNlhqIi/IfQiSta23HVk4c4bD4ErFZeKAzdc0g=; b=lFyhsuGV41/RhIhbwDHFY3aRRnojfdWbgskHeyfOa/qH/xmE1KmanKE/jT7oiBM3q9 nX2CDWWGwujipPACwv/vkm0WxPJFq2DqYZt56bKD8DUgB06kDXhymokKpGtaQXWhuPEW VAj1UJt9zfmbyT818qF0ww5ukFHYw149BjU77my8IBDXTkmONBfrD67Nxn6rWbjEMKVd SafIJsSZf9go/cnDJoT4Y9uvXIGElgbsf1/Vraf2dT/T1/62PdT0kTd38UVFgikyJuwE Qhw+pI/j65kEiqUi1sCGFrfIE0zYg+iY7ONh1DcbGzAOSOVjFu0IdQxDBXrh3rCcdmvj FQUg== 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=/u94BtNlhqIi/IfQiSta23HVk4c4bD4ErFZeKAzdc0g=; b=jPyNosaG4UyQxY69d3+Og6UVEXJZ3btxVd6jrZ1orgCCtmd6tNM1njM7LRX6vbs7gk wwc/lKkWPZ4z86KN0jkaVDhZbe05ec3+6uNI1EHYRXa3fzT2qXBglZmmkdNXWXUyA66D PicfEQrHgY3I1Oc9AA0wxjhFhMS+fBwPBDtF63UtWK+FVVjBp90Yyi8e1x66pHFIRvqe w1avxDhiw3IAA/3l65T7HZ1C3LQFg7glRAKu6X6JKpkc8PayDzyaVC1yTQ1OQ+4fFiGa wpgOeGtCFMxhcPN7BWIf4TdXs6P4riltHqlJNwdgd6fuPvqzCAMLsC3ZMBdGKqPoXMtz t7zQ== X-Gm-Message-State: APjAAAVRWKUl+Dpcw/qh993J8mijOzbB4gCWttr7jXzOlkdXXtcpeKeR ZhcPEQYeebwvzRYxFCu2YD/aV5ig X-Google-Smtp-Source: APXvYqye2Th6RRXevYuCBagjjx9jIetRVgGwvP0WbrD4TuLXC3tM/nRrKxqgb+lReAUpFL2w73u47Q== X-Received: by 2002:a63:fc5a:: with SMTP id r26mr74341625pgk.97.1555436678241; Tue, 16 Apr 2019 10:44:38 -0700 (PDT) Received: from localhost.localdomain (KD118155013174.ppp-bb.dion.ne.jp. [118.155.13.174]) by smtp.gmail.com with ESMTPSA id f20sm39763791pff.176.2019.04.16.10.44.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Apr 2019 10:44:37 -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 v2 3/3] thermal: rcar_gen3_thermal: Update temperature conversion method Date: Wed, 17 Apr 2019 02:44:15 +0900 Message-Id: <1555436655-5262-4-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555436655-5262-1-git-send-email-ykaneko0929@gmail.com> References: <1555436655-5262-1-git-send-email-ykaneko0929@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@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 97cf3cd..9b95263 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_2; + int id; /* thermal channel id */ }; struct rcar_gen3_thermal_priv { @@ -129,7 +137,7 @@ static inline void rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc, static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc, - int *ptat, int *thcode, + int *ptat, const int *thcode, unsigned int ths_tj_1) { /* TODO: Find documentation and document constant calculation formula */ @@ -163,15 +171,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))) @@ -377,11 +389,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) @@ -438,6 +445,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;