From patchwork Wed Jan 18 03:55:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 44956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2128465wrn; Tue, 17 Jan 2023 19:56:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXuNDoMkMyfiYWwEp7S/sAqA9BY72+U5Fa03bq2WUkjKeYrsrmaSy2LuSTAfVCBuI13R1/RS X-Received: by 2002:a17:902:8c94:b0:193:ab5:39c7 with SMTP id t20-20020a1709028c9400b001930ab539c7mr6355325plo.11.1674014181690; Tue, 17 Jan 2023 19:56:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674014181; cv=none; d=google.com; s=arc-20160816; b=DL2UDNcj0TXHKyrEanb5ZbE/XPaPK/Iq78ce9TnhGjeHf9v/GY4H5EbOTqB01zqkuv 37lMBPFUE7qcjrtNq5paf4ErLY5MxIEYgwQQRJ78pqxyOuunk5ln2Xb/N5xkeXx2iqL6 BEJZDNWmhHLNNoJjU1tQFTF4wml3CkFjtIHTr1Ws+kgg5wizd3ivhk6rR05r22HMUg4e tTs1grx4qvHnwcZiZI6Y2JQon2zoyUgC36TIycjb535itz2xtl2LrQdwhy+Sqvix2WXt spvGDC/PHJoIkmo0anxfiYMcJs3PI/D96P6H/5phukAvvZi34bF22ELAvXYJ63KYowNh F7Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=9fNcwcyqeCTP7AtXCBd3m7Qb7ImNpCK5iJ5vh8zaihA=; b=lD7kcpcecbNfPYURCQ1ToEs6yAqWRSXY+zJXGPq5iUtiCEP2p0reLhXYekWQR/9C8s rX9kmHh7wVPm83gMarFQ6ilWPYo/TDjrxFclCFADvG/sjSQYhqJzqU3HHKR6UzwYZrtJ JNQRpf1itGjFCmXGph/R2A9EzBTesOFl0h2vq9B0cge+IC5zvX7m053Z9ZAqpa3Z3SGn LNFfDY32y7kTgKjLGO5YTqk533Zu2JRvYjYHQR5O5r1q6hwEEH9LVDja3MzvonCYKVJk /36TB4izUsZ9x5iZlHnveg+MhdYUeJS058QHkxMZvqIM7fmtRBacvs9QahBTF58r63JR FgFQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d8-20020a170903230800b00176b3c7d158si36881390plh.99.2023.01.17.19.56.09; Tue, 17 Jan 2023 19:56:21 -0800 (PST) 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; 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 S229722AbjARDzr (ORCPT + 99 others); Tue, 17 Jan 2023 22:55:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbjARDzi (ORCPT ); Tue, 17 Jan 2023 22:55:38 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A7EB54B22; Tue, 17 Jan 2023 19:55:30 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pHzXs-00032R-2C; Wed, 18 Jan 2023 04:55:28 +0100 Date: Wed, 18 Jan 2023 03:55:22 +0000 From: Daniel Golle To: AngeloGioacchino Del Regno , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Matthias Brugger , Rob Herring Cc: Steven Liu , Henry Yen , Chad Monroe , John Crispin , Frank Wunderlich Subject: [PATCH v4 1/2] thermal: mediatek: use function pointer for raw_to_mcelsius Message-ID: <69c17529e8418da3eec703dde31e1b01e5b0f7e8.1674012985.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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?1755331094511823677?= X-GMAIL-MSGID: =?utf-8?q?1755331094511823677?= Instead of having if-else logic selecting either raw_to_mcelsius_v1 or raw_to_mcelsius_v2 in mtk_thermal_bank_temperature introduce a function pointer raw_to_mcelsius to struct mtk_thermal which is initialized in the probe function. Signed-off-by: Daniel Golle Reviewed-by: AngeloGioacchino Del Regno --- drivers/thermal/mtk_thermal.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index 0084b76493d9a..992750ee09e62 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -292,6 +292,8 @@ struct mtk_thermal { const struct mtk_thermal_data *conf; struct mtk_thermal_bank banks[MAX_NUM_ZONES]; + + int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw); }; /* MT8183 thermal sensor data */ @@ -656,13 +658,9 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank) for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) { raw = readl(mt->thermal_base + conf->msr[i]); - if (mt->conf->version == MTK_THERMAL_V1) { - temp = raw_to_mcelsius_v1( - mt, conf->bank_data[bank->id].sensors[i], raw); - } else { - temp = raw_to_mcelsius_v2( - mt, conf->bank_data[bank->id].sensors[i], raw); - } + temp = mt->raw_to_mcelsius( + mt, conf->bank_data[bank->id].sensors[i], raw); + /* * The first read of a sensor often contains very high bogus @@ -1075,6 +1073,11 @@ static int mtk_thermal_probe(struct platform_device *pdev) mtk_thermal_release_periodic_ts(mt, auxadc_base); } + if (mt->conf->version == MTK_THERMAL_V1) + mt->raw_to_mcelsius = raw_to_mcelsius_v1; + else + mt->raw_to_mcelsius = raw_to_mcelsius_v2; + for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++) for (i = 0; i < mt->conf->num_banks; i++) mtk_thermal_init_bank(mt, i, apmixed_phys_base,