Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp6674482rwb; Wed, 18 Jan 2023 08:04:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXtmzraIudJerd/v7chzpPirvXFdQ/qogKcJCHHjId+A12FgQApOuYOj/4yLPeCzkeDogv18 X-Received: by 2002:a05:6a20:e687:b0:b8:2e85:da0a with SMTP id mz7-20020a056a20e68700b000b82e85da0amr7622348pzb.24.1674057846937; Wed, 18 Jan 2023 08:04:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674057846; cv=none; d=google.com; s=arc-20160816; b=YErAWObLyXpYKRU8C3vsTxsc3sNGC7SLCLxZlgvJYoHtjqN3AleGKqBulkLWcCupmq 5UIZExmATkTHX7sAlgWni6SU2n+8o5XKn8tYVYCCXdA8WNISAuiigbGVDpNXtYSRNSfx se7pTkAviQKcXrLIiVHgxFYG9EnUMsrKa++kDHWImwXjYoEh/9KrMTUHbNndMx33e6qm eS6EVsoh64ky9Vx6ztXmkJEQ3zqlgMSt4H2XBde8Gouc4AjFILzleefBqSKgIRa6J4nT Vdulx1ADhspAi5GDQdWl98WGGq18zNz5O6X7FhPdBYQx7gkP5I03l7wUreCSE/LNwHyR HX2w== 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=o78476BCBNeXUUh8dYtk1P5K0AodHpMpcG8B/jLfRgU=; b=kcgzklotmQVWyBXVI0HfN3kQ9JeOF2A5gJd7+zo7t+zGgd6xOdiOaSqGjcSFPzOlvN PEmQrheBhGEIzeuPIy/Ma63sJvHb913qcam6Qw73zoRBgOt2akRxSZOnUCKrVRrE8zAm Qn0nwO7uJ1kPgjMJnQK/OiZ9i75kDTFJgWtl/435gTn8Qz3AtyFS/f8F2PWBkccA+L1X gdn5ylt3x/+uVBJofgLLYNHLl8E7pkpygUlMuRQ1w5W3BKJjVubqBDVVGL2WaUjVqvk+ LqdBpDmo3g5aCW0JYkN36jvyuA7wBOnIZKhaFiT4VLLxi03xx82WHyHeK05vmOhgGafJ WjHA== 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 p6-20020a63e646000000b00476c9add60bsi35834736pgj.404.2023.01.18.08.04.01; Wed, 18 Jan 2023 08:04:06 -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 S230212AbjARPku (ORCPT + 46 others); Wed, 18 Jan 2023 10:40:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230183AbjARPks (ORCPT ); Wed, 18 Jan 2023 10:40:48 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC0BE6A6F; Wed, 18 Jan 2023 07:40:46 -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 1pIAYP-0007gi-0q; Wed, 18 Jan 2023 16:40:45 +0100 Date: Wed, 18 Jan 2023 15:40:39 +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 Subject: [PATCH v5 1/2] thermal/drivers/mtk: use function pointer for raw_to_mcelsius Message-ID: <69c17529e8418da3eec703dde31e1b01e5b0f7e8.1674055882.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. Reviewed-by: AngeloGioacchino Del Regno 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