From patchwork Wed Jan 25 09:50:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amjad Ouled-Ameur X-Patchwork-Id: 48083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp189697wrn; Wed, 25 Jan 2023 01:57:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXtgCTOGwiOPUBZz4TlflP6SAwTBxMqk1GcYVQT1LDlwezdVEAEh2HCYoyRyUe34q8gdsCE8 X-Received: by 2002:a17:902:7144:b0:194:9e86:ffee with SMTP id u4-20020a170902714400b001949e86ffeemr25446622plm.44.1674640627594; Wed, 25 Jan 2023 01:57:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674640627; cv=none; d=google.com; s=arc-20160816; b=QrDZfilgqj2j+tF36VJssSY8cg2c1hP4K+NxmX91FoptZ1alA2SyFJzgb2CtkELglk KlZ2hovNgfKYFTMqQEvs2GdkiSBOWAcTRVmduG87vQT3UM8UiOwN6DULq7/v/vrpg/2l 41VId58a65t+C8qMiRwNm6EjnmhQJ0K47bBbXF0qjOASuhbfZK9y+IvNKesELWfUT6NI 5NjRa1dTfpqLPQl8eppFoaiEqdyJgjxQLi7y1mZAPcQak0CvC/zn7D5UfXNcPu+oB7xT j1MZLBbvstOYAlHISc9l+LE5p+OYCF3zkCLD1hapmLt8fxkEhHOWHB0gRJB7LmZftoUv 73EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=iFVYW1O2xATTJriM1RmoRREy/G+c337SmUDoCitpzco=; b=anWyvO653vOI79NoBuH9iiFcFxjEFIx584LWaSnWGNLCqxbvN7U3JRrc3Xbzb1TWqy pYWtgD9TWC7Ld4Wl8314m2fNdGc+BCy1/gN6QwSPhLd5uvMToCEcB73andl/r06o5hM1 DpKm9aZqardkdWFf2pgBxx6VB4npBJ4mE5bz8QmjJjCWnN5i2VXtOvGvdZxlxRwPFSbF kYbWrDsQ8OK8mRFbab+5/coc9YWTjNUbXT099i26nTS+dVZwS+GsVuQmKe/XbQDK0oSY GLR5UQlHseKqD2mA8/lL9ZNPIistTWHi+0ZIcmtSy1huFjZTNhdSx/A1IG9tzSEkGZCw kedA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=kHYJJNAh; 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 jc18-20020a17090325d200b0019282cb9cf1si5092843plb.201.2023.01.25.01.56.55; Wed, 25 Jan 2023 01:57:07 -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; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=kHYJJNAh; 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 S235462AbjAYJvY (ORCPT + 99 others); Wed, 25 Jan 2023 04:51:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235401AbjAYJvI (ORCPT ); Wed, 25 Jan 2023 04:51:08 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0984D2D59 for ; Wed, 25 Jan 2023 01:51:07 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id e19-20020a05600c439300b003db1cac0c1fso812547wmn.5 for ; Wed, 25 Jan 2023 01:51:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=iFVYW1O2xATTJriM1RmoRREy/G+c337SmUDoCitpzco=; b=kHYJJNAhyMxJs8rkZvXLxWwfNTqjAfmgeTQtNCp+pVmtiHt3Btxu1d51Qr9n5mnFP4 AEVq9BdfmEOyr2Z5LFxjbteGEHhVu39IkOS1Js+eLiU15JOQEQvVPQcpih8Tq4VZ9Buy AxTyr9W6afzaSmaZhNSSNJRXlamcFEi92QU9UrWUd7O0Sd+7+CRkV7WgTMw4HdtcgWHB DlmkE1v+nySG8zIJ3ISUVWqIFgTQSzd/1OgGNclv/5bld3QHriKJ+oJ9BtuUg6VED7Ac A3VmR0eflI6+PAGi51W9ERZtd/1qH5k26oAfqdgM3RoHATBOnm2cyxoSJejkRUdcHQWd nGmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iFVYW1O2xATTJriM1RmoRREy/G+c337SmUDoCitpzco=; b=Rrz+nIhQjbTJa3lqmwKhV/QH0ZHz/i1B0/Gb4e12wtqbn0ju7XRyGODWwwne8dANXa sWVFlW4BWfTGjP098H2rX0dNXQJNGQumsAQ3v+FlES6eqm4VndsMwrhDHdmyw7Oytio/ pt2JqTwj/0Azj4loF4DDuSD6SE8FLlIfst+ABEjbuLxJ3O9JJRxdttm/iZTEJmvvluYQ Z3YHODQWSUaDrJ+I2amK2YJCFBxfntknq8A05k0hC1XdkeunjMXpP9AgXHbgjnXdcdaQ QEElcnIISOj1KfDf77LB+bW3w1lhVqIfFr4EGZFsj9ilYrZWiSZ45odsur4obSlo7XSq EImA== X-Gm-Message-State: AFqh2kphl7M4dmNCSc7yUeCyCZa7ULOi2t0nHlCTYGp2zIuz8bu+Q9pf 3XDszdPOPDMY89nWCvEF+q7RrQ== X-Received: by 2002:a05:600c:3d8d:b0:3d2:bca5:10a2 with SMTP id bi13-20020a05600c3d8d00b003d2bca510a2mr30621063wmb.22.1674640265478; Wed, 25 Jan 2023 01:51:05 -0800 (PST) Received: from [127.0.1.1] (62.213.132.195.rev.sfr.net. [195.132.213.62]) by smtp.googlemail.com with ESMTPSA id j26-20020a5d453a000000b002bdf3809f59sm3955072wra.38.2023.01.25.01.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 01:51:05 -0800 (PST) From: Amjad Ouled-Ameur Date: Wed, 25 Jan 2023 10:50:32 +0100 Subject: [PATCH v8 4/5] thermal: mediatek: add callback for raw to mcelsius conversion MIME-Version: 1.0 Message-Id: <20221018-up-i350-thermal-bringup-v8-4-23e8fbb08837@baylibre.com> References: <20221018-up-i350-thermal-bringup-v8-0-23e8fbb08837@baylibre.com> In-Reply-To: <20221018-up-i350-thermal-bringup-v8-0-23e8fbb08837@baylibre.com> To: "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Rob Herring , Krzysztof Kozlowski Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Matthias Brugger , AngeloGioacchino Del Regno , Rob Herring , Markus Schneider-Pargmann , Hsin-Yi Wang , Amjad Ouled-Ameur , Michael Kao X-Mailer: b4 0.11.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1674640259; l=1727; i=aouledameur@baylibre.com; s=20220920; h=from:subject:message-id; bh=oneS0GOcwyJu/jpresdHeaeVd8flLXASRISr19OSr48=; b=ZV5aCgX9PkZJa0Sypvo2hM4krEb1MLQZDO4q5TsQiehLB9e0NmzlMDH9KDCXcuqTkcNTPHu0QxdJ +O/VpQoWAYxYvRvjtEkQUXuX7tCJB33JiSrJaQOk25Vd5W+U1S1h X-Developer-Key: i=aouledameur@baylibre.com; a=ed25519; pk=HgYWawSL4qLGPx+RzJ+Cuu+V8Pi/KQnDDm1wjWPMOFE= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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?1755987970726557387?= X-GMAIL-MSGID: =?utf-8?q?1755987970726557387?= Set a callback at probe time instead of checking the version at each get_sensor_temp(). Signed-off-by: Amjad Ouled-Ameur Reviewed-by: AngeloGioacchino Del Regno --- drivers/thermal/mtk_thermal.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index 3a5df1440822..b8e06f6c7c42 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -307,6 +307,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 */ @@ -726,13 +728,7 @@ 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, i, raw); /* * The first read of a sensor often contains very high bogus @@ -1150,6 +1146,9 @@ static int mtk_thermal_probe(struct platform_device *pdev) mtk_thermal_turn_on_buffer(mt, apmixed_base); + mt->raw_to_mcelsius = (mt->conf->version == MTK_THERMAL_V1) ? + raw_to_mcelsius_v1 : raw_to_mcelsius_v2; + if (mt->conf->version == MTK_THERMAL_V2) { mtk_thermal_release_periodic_ts(mt, auxadc_base); }