Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5859296rwb; Tue, 17 Jan 2023 20:30:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXvul2JMWgqz1RuUVUAmji245h7I9LcGeCaK1h3NAbWqewLMIApnUm8ldoKPENc0x1gnIYPC X-Received: by 2002:a05:6a20:2a10:b0:b8:54ef:632b with SMTP id e16-20020a056a202a1000b000b854ef632bmr4885103pzh.49.1674016232268; Tue, 17 Jan 2023 20:30:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674016232; cv=none; d=google.com; s=arc-20160816; b=HKmygY2cD4/t67szq1R5iIYyUHSWsUxxqC4+oyFomBUjWnBXUXTU2OsW7SJNXGxfoa /467HeNasJoPxLruqLI60rb0Bwu4kEKzrK2o8lI5xM27iu/KF9NUxrNzkBVKY48om89X YbbOfode8gGnGtnLnzw890w6rzeo9v5bpNaES8QzjUvwYjLSarQYWl3e/X8gJibYZJNg NTbqYn2YzKUAU5Sb/KEIupW/7ycVjCGLOWULBO3PEn5wMuEoj4ASnyEblVYs1SOU0oh5 OnHOp/soNUL1NVU4wtx7uVibo6VODhVlaZ1xQgZ3v65i0iGeOhsiCCsAlLr98dnaupwh kDKg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q15-20020a63f94f000000b0047917a0efb5si35084459pgk.230.2023.01.17.20.30.26; Tue, 17 Jan 2023 20:30:32 -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 + 46 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-Type: text/plain; charset=us-ascii 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 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 --- 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, -- 2.39.1