From patchwork Mon Jan 30 19:03:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 50432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2348730wrn; Mon, 30 Jan 2023 11:09:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXvGNfnbu2SBv2LOrv9LizG9RfQhsMlTPLxBcI/44lG+TLzoVaH/QVkY4aP0pZuCtf5jlOXe X-Received: by 2002:a05:6a20:c198:b0:b8:ca86:d1e8 with SMTP id bg24-20020a056a20c19800b000b8ca86d1e8mr57171337pzb.14.1675105776271; Mon, 30 Jan 2023 11:09:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675105776; cv=none; d=google.com; s=arc-20160816; b=vg43DixDr0A3ibAMrjSE/iS24YQvwPKRgLniB0YYwIV4iRDYMcCoZYzxlXADf+ma45 plkRPz9/YxMeBZ/sEZ1HOjiRosw/TiHvGwFz8RxrJTvC2bOEpTNvfLyurjwjFV9Ypxdw 7oXmEe/fAOjpCkooAeuREwQNMd38kV+k66U1jXLuPHO4ypxW4rqoVFES9czhnpktjtlB R8nTCsIgokGXi22/su3nIns5B3phjgZ5nmPJ5sPyz76idaUbW4tsAkVwZzhefoXoi2Cy I41q4fYMscB5ViK9oy6FCSnSXt2X/ma6B1oq7W+6dgH1NG98a35jHrDfRZs4L7EfL+vR OQTA== 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; bh=suAiXHFT++hwJ0GQ2mEvUXDPvh206oPYUv1xaqiydVM=; b=EtlDVvkiTbbQifexMgduXceiLqoXG8dWOX7d1U+rQZSnIcsqX9RWbJNQ2wA+ESIhU9 IN5Wigp0p1v+Uyx4V913gXi54bDydlNrAeJ9QH1DAKuvW1O2C+6jzWyM1Zpx52a+36qz aWAN+UZzLtKAuXxByGHBWUCnQ7pXsd+RkavY1XoSer9r81M/Men4ElK4nJyvZX9QJVZj U3l/aTKX9VYvDlM0ZiupQwtpBcm/MMqaEhTU9R9av8QkwzvAIXs53pxQlL1XGS5CtmpG I0PcTOv/xOeXsxByLYSAm6p/wcTsM9ownjf+5hkDl2q5S+tgz2uE1g5Qkxby/vWW6A4F Ah3Q== 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 h191-20020a636cc8000000b004e2da688d23si9345908pgc.534.2023.01.30.11.09.23; Mon, 30 Jan 2023 11:09:36 -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 S238083AbjA3THo (ORCPT + 99 others); Mon, 30 Jan 2023 14:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238103AbjA3THe (ORCPT ); Mon, 30 Jan 2023 14:07:34 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A9838B62; Mon, 30 Jan 2023 11:07:33 -0800 (PST) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.1.0) id 6014c07e825ce42e; Mon, 30 Jan 2023 20:07:31 +0100 Received: from kreacher.localnet (unknown [213.134.169.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id A943F2528287; Mon, 30 Jan 2023 20:07:30 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: Zhang Rui , Srinivas Pandruvada , Linux ACPI , LKML , David Box Subject: [PATCH v1 5/8] thermal: intel: intel_pch: Fold two functions into their callers Date: Mon, 30 Jan 2023 20:03:11 +0100 Message-ID: <3662399.MHq7AAxBmi@kreacher> In-Reply-To: <1751684.VLH7GnMWUR@kreacher> References: <1751684.VLH7GnMWUR@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 213.134.169.112 X-CLIENT-HOSTNAME: 213.134.169.112 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrudefvddguddvfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepvddufedrudefgedrudeiledrudduvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvudefrddufeegrdduieelrdduuddvpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehsrhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdho rhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrvhhiugdrvgdrsghogieslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 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?1756475714313527325?= X-GMAIL-MSGID: =?utf-8?q?1756475714313527325?= From: Rafael J. Wysocki Fold two functions, pch_hw_init() and pch_get_temp(), that each have only one caller, into their respective callers to make the code somewhat easier to follow. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano --- drivers/thermal/intel/intel_pch_thermal.c | 98 ++++++++++++------------------ 1 file changed, 42 insertions(+), 56 deletions(-) Index: linux-pm/drivers/thermal/intel/intel_pch_thermal.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/intel_pch_thermal.c +++ linux-pm/drivers/thermal/intel/intel_pch_thermal.c @@ -117,57 +117,6 @@ static int pch_wpt_add_acpi_psv_trip(str } #endif -static int pch_hw_init(struct pch_thermal_device *ptd) -{ - int nr_trips = 0; - u16 trip_temp; - u8 tsel; - - /* Check if BIOS has already enabled thermal sensor */ - if (WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL)) { - ptd->bios_enabled = true; - goto read_trips; - } - - tsel = readb(ptd->hw_base + WPT_TSEL); - /* - * When TSEL's Policy Lock-Down bit is 1, TSEL become RO. - * If so, thermal sensor cannot enable. Bail out. - */ - if (tsel & WPT_TSEL_PLDB) { - dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n"); - return -ENODEV; - } - - writeb(tsel|WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL); - if (!(WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL))) { - dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n"); - return -ENODEV; - } - -read_trips: - trip_temp = readw(ptd->hw_base + WPT_CTT); - trip_temp &= 0x1FF; - if (trip_temp) { - ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp); - ptd->trips[nr_trips++].type = THERMAL_TRIP_CRITICAL; - } - - trip_temp = readw(ptd->hw_base + WPT_PHL); - trip_temp &= 0x1FF; - if (trip_temp) { - ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp); - ptd->trips[nr_trips++].type = THERMAL_TRIP_HOT; - } - - return nr_trips + pch_wpt_add_acpi_psv_trip(ptd, nr_trips); -} - -static int pch_get_temp(struct pch_thermal_device *ptd) -{ - return GET_WPT_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP)); -} - /* Cool the PCH when it's overheat in .suspend_noirq phase */ static int pch_suspend(struct pch_thermal_device *ptd) { @@ -254,7 +203,7 @@ static int pch_thermal_get_temp(struct t { struct pch_thermal_device *ptd = tzd->devdata; - *temp = pch_get_temp(ptd); + *temp = GET_WPT_TEMP(WPT_TEMP_TSR & readw(ptd->hw_base + WPT_TEMP)); return 0; } @@ -310,8 +259,10 @@ static int intel_pch_thermal_probe(struc enum board_ids board_id = id->driver_data; const struct board_info *bi = &board_info[board_id]; struct pch_thermal_device *ptd; - int err; + u16 trip_temp; int nr_trips; + u8 tsel; + int err; ptd = devm_kzalloc(&pdev->dev, sizeof(*ptd), GFP_KERNEL); if (!ptd) @@ -339,12 +290,47 @@ static int intel_pch_thermal_probe(struc goto error_release; } - nr_trips = pch_hw_init(ptd); - if (nr_trips < 0) { - err = nr_trips; + /* Check if BIOS has already enabled thermal sensor */ + if (WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL)) { + ptd->bios_enabled = true; + goto read_trips; + } + + tsel = readb(ptd->hw_base + WPT_TSEL); + /* + * When TSEL's Policy Lock-Down bit is 1, TSEL become RO. + * If so, thermal sensor cannot enable. Bail out. + */ + if (tsel & WPT_TSEL_PLDB) { + dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n"); + err = -ENODEV; goto error_cleanup; } + writeb(tsel|WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL); + if (!(WPT_TSEL_ETS & readb(ptd->hw_base + WPT_TSEL))) { + dev_err(&ptd->pdev->dev, "Sensor can't be enabled\n"); + err = -ENODEV; + goto error_cleanup; + } + +read_trips: + trip_temp = readw(ptd->hw_base + WPT_CTT); + trip_temp &= 0x1FF; + if (trip_temp) { + ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp); + ptd->trips[nr_trips++].type = THERMAL_TRIP_CRITICAL; + } + + trip_temp = readw(ptd->hw_base + WPT_PHL); + trip_temp &= 0x1FF; + if (trip_temp) { + ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp); + ptd->trips[nr_trips++].type = THERMAL_TRIP_HOT; + } + + nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips); + ptd->tzd = thermal_zone_device_register_with_trips(bi->name, ptd->trips, nr_trips, 0, ptd, &tzd_ops, NULL, 0, 0);