From patchwork Thu May 11 19:22:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 92843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4620545vqo; Thu, 11 May 2023 12:35:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7WBw5A51y0KmaFTBysdPJBs1MDdxKnVlkUq/3uhbvq3tJYmfvxcIU+AO6+1hXMCQbBTB9O X-Received: by 2002:a05:6a20:3c93:b0:100:ed92:7d49 with SMTP id b19-20020a056a203c9300b00100ed927d49mr17727008pzj.21.1683833752116; Thu, 11 May 2023 12:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683833752; cv=none; d=google.com; s=arc-20160816; b=Y1mq8VITGO2zvzYx+ZmEs5mtsEhuhZ8UlShodjbFYTNAGhF2YCvJ0LgIaoE8hIeuBN nrbr5gpvdnuJmbpQ5qH6Myp/1GYyrh5xuAaL2+0oiYeEsge3LJqE0dOWozRQ+PH2De6p XmQbc2BiVvYEH595iHyUtsuoFBGefrL4UIcGLEq2P4RwcWU6UHf5kvAkJyV7sMoQnWv5 rpQK89R0kFKvMZWBSVRbUjQOYFMYad208Me4X1y9DxDz6yj66ACM96wSwjaQ2/TvmIaM 4vvDVak5ibo4UPYhQO3brmZ77PyqHei0lmKsTmMgUBSRSSpscgIoiFeAlUiuZR2uFq43 ogCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=65GX3y66oWKkSHnCpdXB9diCpwRfCFw9OqNGjcrxt7A=; b=ZH71e08aEW39A5tsKuJz9BavRBfvk75YIYAkwtFB+b6LMCKXtGalN1ce6VDBa0XJAL Jy94d7nmyvAJJWkWeYbPGlN+cVf3m6rTyYPpzJ+71jSztcxEwZuPdScGXMeum8Mi3JR1 TmHj33uHHRaMlXgZr5GhTOvkIlTYUfr6DjvSBHxGzlvt2aV1FhwYxnz7xohT+S6E2kaa +M53XmuomOq/i5dZWK+eMI6fFmg1nQKziikeTnW3N4//rgiWGIudfQ22xd0cQwYYP8O7 /a7D+MBOWTPPvhbDIMSG+EbmdQW+uLf/8eTopXhnqbGshcHrKHC14RFJ14d/zl18AfGb HzeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@sang-engineering.com header.s=k1 header.b=dXCwErlu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q192-20020a632ac9000000b005133c334fe9si7228214pgq.847.2023.05.11.12.35.37; Thu, 11 May 2023 12:35:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@sang-engineering.com header.s=k1 header.b=dXCwErlu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239185AbjEKTWi (ORCPT + 99 others); Thu, 11 May 2023 15:22:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239116AbjEKTWd (ORCPT ); Thu, 11 May 2023 15:22:33 -0400 Received: from mail.zeus03.de (www.zeus03.de [194.117.254.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A13A7DBF for ; Thu, 11 May 2023 12:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=sang-engineering.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=k1; bh=L 2X4kYWD+K5Hff6OCrdzdHuu9Uc5LjUy9EemkAlKgG4=; b=dXCwErluJ3uVcrjx8 JQCpF4FkG4/eiBxwpDNMuoGPFznqCAktZa1HL98MRPTV3CsRQ2lBvC2logGNrPpH YioDjeBx/moNjL/fbdCHGINtGHWy1eaBMCdLGtfkAQ48TPog9K/x47WQHuSc30O5 RibS0wbgH3a1nV6KdFs7wN3MG4= Received: (qmail 2935211 invoked from network); 11 May 2023 21:22:29 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 11 May 2023 21:22:29 +0200 X-UD-Smtp-Session: l3s3148p1@2hvM6G/7cuAujnsI From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , =?utf-8?q?Niklas_S?= =?utf-8?q?=C3=B6derlund?= , =?utf-8?q?Niklas_S=C3=B6derlund?= , "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFT v3 2/3] drivers/thermal/rcar_gen3_thermal: refactor reading fuses into seprarate function Date: Thu, 11 May 2023 21:22:18 +0200 Message-Id: <20230511192220.7523-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230511192220.7523-1-wsa+renesas@sang-engineering.com> References: <20230511192220.7523-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765627660863978362?= X-GMAIL-MSGID: =?utf-8?q?1765627660863978362?= Gen4 will be very different, so refactor Gen3 access into separate call first. Signed-off-by: Wolfram Sang Reviewed-by: Niklas Söderlund --- drivers/thermal/rcar_gen3_thermal.c | 60 +++++++++++++++++------------ 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index e9b0aa0a2016..39b382ee08c8 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -66,8 +66,11 @@ struct equation_coefs { int b2; }; +struct rcar_gen3_thermal_priv; + struct rcar_thermal_info { int ths_tj_1; + void (*read_fuses)(struct rcar_gen3_thermal_priv *priv); }; struct rcar_gen3_thermal_tsc { @@ -241,6 +244,34 @@ static irqreturn_t rcar_gen3_thermal_irq(int irq, void *data) return IRQ_HANDLED; } +static void rcar_gen3_thermal_read_fuses_gen3(struct rcar_gen3_thermal_priv *priv) +{ + unsigned int i; + + /* + * Set the pseudo calibration points with fused values. + * PTAT is shared between all TSCs but only fused for the first + * TSC while THCODEs are fused for each TSC. + */ + priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT1) & + GEN3_FUSE_MASK; + priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT2) & + GEN3_FUSE_MASK; + priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT3) & + GEN3_FUSE_MASK; + + for (i = 0; i < priv->num_tscs; i++) { + struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; + + tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE1) & + GEN3_FUSE_MASK; + tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE2) & + GEN3_FUSE_MASK; + tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE3) & + GEN3_FUSE_MASK; + } +} + static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv) { unsigned int i; @@ -248,7 +279,8 @@ static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv) /* If fuses are not set, fallback to pseudo values. */ thscp = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_THSCP); - if ((thscp & THSCP_COR_PARA_VLD) != THSCP_COR_PARA_VLD) { + if (!priv->info->read_fuses || + (thscp & THSCP_COR_PARA_VLD) != THSCP_COR_PARA_VLD) { /* Default THCODE values in case FUSEs are not set. */ static const int thcodes[TSC_MAX_NUM][3] = { { 3397, 2800, 2221 }, @@ -273,29 +305,7 @@ static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv) return false; } - /* - * Set the pseudo calibration points with fused values. - * PTAT is shared between all TSCs but only fused for the first - * TSC while THCODEs are fused for each TSC. - */ - priv->ptat[0] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT1) & - GEN3_FUSE_MASK; - priv->ptat[1] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT2) & - GEN3_FUSE_MASK; - priv->ptat[2] = rcar_gen3_thermal_read(priv->tscs[0], REG_GEN3_PTAT3) & - GEN3_FUSE_MASK; - - for (i = 0; i < priv->num_tscs; i++) { - struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; - - tsc->thcode[0] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE1) & - GEN3_FUSE_MASK; - tsc->thcode[1] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE2) & - GEN3_FUSE_MASK; - tsc->thcode[2] = rcar_gen3_thermal_read(tsc, REG_GEN3_THCODE3) & - GEN3_FUSE_MASK; - } - + priv->info->read_fuses(priv); return true; } @@ -325,10 +335,12 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_priv *priv, static const struct rcar_thermal_info rcar_m3w_thermal_info = { .ths_tj_1 = 116, + .read_fuses = rcar_gen3_thermal_read_fuses_gen3, }; static const struct rcar_thermal_info rcar_gen3_thermal_info = { .ths_tj_1 = 126, + .read_fuses = rcar_gen3_thermal_read_fuses_gen3, }; static const struct of_device_id rcar_gen3_thermal_dt_ids[] = {