Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp360941rdh; Tue, 13 Feb 2024 21:30:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUJ5Q+1xixA7kpBWiTlAnNOfeflozI0YDhznqbkMwT3hwKXu1x5dai1NAfhmjJwKKvotXjbS7xmysUI3uVNs1lyriqHcuTo5NtYvXpjFw== X-Google-Smtp-Source: AGHT+IHqlLd9CH3RplOep5BQnajoiD85ffmXzdJSKN5M64yefTU5CjHfXYAYDgzlRsQmMwkMkr63 X-Received: by 2002:ac8:5882:0:b0:42c:85f0:4b23 with SMTP id t2-20020ac85882000000b0042c85f04b23mr1700586qta.27.1707888657043; Tue, 13 Feb 2024 21:30:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707888657; cv=pass; d=google.com; s=arc-20160816; b=t4P4WP34h3HfRAc+FcTZn7KBvGNU2XlgIg3gGCFT/zYpokGnxjmvEMBFaipdX/F2b5 t95oo/HtCeXFadCMy8MciBtTyscX2i9KTXEb2Cg133qi7uLg49mIyB2uqE0H7h6c2CTz s0IC/KG+JfX5ggHgLep2tPMCHRMjD98RaYpSR2ZXNuiLCYJxH4O8+k+ChcWdVsOc1IKX YT/CzHElVMiVjabGBuM2yWmsTkxyknpK9+LrdD7O78mwVn3LnNJZw4iiUbjIIsXga6JN S+nDeJ4vIhL2ywkMogMxVBQ1HMQwT3JfyRSwY3vCswoSjCokaBnwuI/lCc1Y3iYWZWGN a4TQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=c/sbBk2n6W8ORZ7uhudihLLqVzHuUrsjy8h+SricNyE=; fh=G/5botcAVq5E48OlaTUFDG3CBK2mBoMFMWxcAQieVRw=; b=gtqVLcqkPkZrZymYXRd6b1lSBWQLRT6VW553E7H7FXuM0LktffmnNAZneniVw5RJLb GFu7K1MLF3gx4LF2FVNDeJR4v5QZxrAnNmtrFiGJ3C0nzAf+vg3xN9RPGuB1KInPAg/f ur3o8KIYwKM+9ZpL8IbFuc0WwkbS1dGbSXOqVv+DLbv1QotAjy+VPUuuuZf0e46BPqTi z8tZROHkh0TBw8WNqbrXyh7/fu3QILi+hQMHyZSZroC2or0y77/QjIF2CNJJDHAGJRBj tBovsLX29yWfbAVUiaPava6sGZYIPfrKqUEwlqzoYesbt0DT14pMD6ulaEbuvhn4l9HE ujpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OOi8IsD0; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-64750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64750-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCXFxzKm3QhQGOshqlIPZAW7S6AjYdnCJe1/b4j/0CBOj4//mkxwqrYmatAJDczvoY53Dl57JFgps+4RUMdO6R1o7sHGiC4QDhq5+ivUhw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b18-20020ac85bd2000000b0042c5d53c544si5091115qtb.347.2024.02.13.21.30.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 21:30:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OOi8IsD0; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-64750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64750-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 461C21C23BA7 for ; Wed, 14 Feb 2024 05:30:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3222D26D; Wed, 14 Feb 2024 05:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OOi8IsD0" Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A0A811183; Wed, 14 Feb 2024 05:30:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707888645; cv=none; b=iphRUd73/7m/2wr7m8nlOKu5jo3KjI93JIZ7Y0jpqmrwHx2JUpbFW2WDfesJHhFC8pHyZkOttrIwk0zw9NnYIh83n1spQVJXvAsYJZhr+Dfil7HJsWeJIo5WA5dfG0XLwMSSlSY3DjYvCDbSReHXaMQT0Kx381NzqISGpPqr6cM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707888645; c=relaxed/simple; bh=Dpo6g6sxK3vAauBoF3mHDOYKnH0CVdQFwl2a9oAlRUI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RGl+z62INSQ9cnByZEFIu0VlASNcsNXN0Fspd6PRxJtIudBawAYQipqt5A4ARvXS0J091notYr7W8UJjpG62IkXMW+BpvYednyswtbdKO4c0GwUckXsG/KGyKxFYCnfbzoV8EgWoHhhI9bVOP0i0zOz3Glm3rdRKrnXR17fra2g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OOi8IsD0; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d73066880eso46650105ad.3; Tue, 13 Feb 2024 21:30:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707888643; x=1708493443; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=c/sbBk2n6W8ORZ7uhudihLLqVzHuUrsjy8h+SricNyE=; b=OOi8IsD0OZuAUn/KY4NoADB25luspoF+oblrtWDyiQ8ew5HEqH6V6k0v3GxTx9zjrr YhAn4kyzx9GTzNPV3sWRm4h8FMBfN0ajKCP6p8jaV51jrKq4SZdOrq8J52898xIQiybe gIOAUzNLU1iUHTJSLE+RwDvDnZBiuPtV9yVC/H1b3kTVUv/vByp0lMbbWHxT5yCC7UZw 4bxflHE9XWnBnpJnHc4aLdrsd1AenNtb6yGXFRk/fG/F7Zrz387mBDeYvFLpwB0yx2Q8 wyOD4HMOx2CsbHOt16MTa7swQEoXmTRJQPM8GKqXhtdaYiscPwYtqk6TBwa9R0i9Ke5i tSWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707888643; x=1708493443; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=c/sbBk2n6W8ORZ7uhudihLLqVzHuUrsjy8h+SricNyE=; b=AMhBnr8ddIvGdzunOKj7osjRKM3x+k/vV1whrSjYhL5HlJLHZXE8AxtFO15WR6h6Ow zS3BtcaLeJpzSuE9vUbg7GCyDrHWpPXAeoLg0krR/Ms92VpcjJYNwgoRXgHV1412AdDh 21Uf1vUglDe+plEdHf2lOdI7q+MdOa+ss73zqD12Oj8UnvZxAWl0zHDHDt10sm+HY57x RouKy7WSKoxceLtVEvYqIIJwPx+O08kU4Zfq92Zyh0Vdy2lA9eUROYhvWRp50SnFadQM pkKUYhQ3eJWPmCiRvyuihxGT8jX+GP/HobKmSF2TnRES51OINhhJPaP9vgHFyWzC5oZL praA== X-Forwarded-Encrypted: i=1; AJvYcCXQq/owylw5S170OrqKadsOXNPNZQS9fre+Srw6ldavZqAvRKXbPFmpNOmW8LSTf9U8YW95VlMQ+H2WDiRgCm0x0QzhOo96aDFrs4Hv X-Gm-Message-State: AOJu0YxNvHgeSgt0TPV28eviehedZ8jAAihliHni3s9m47Ud9BqUv0+p qOZ38TCdGLtk8oaemPQ+TeVH2P3X5AHxo5JWlaSL9/Iudg+NAkwo X-Received: by 2002:a17:903:183:b0:1d8:ee41:de89 with SMTP id z3-20020a170903018300b001d8ee41de89mr1954970plg.69.1707888642529; Tue, 13 Feb 2024 21:30:42 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVVvyB7fcy9Fhfykt0RRukcrKwI7zTE91Tt8Tmoicvt5ndF7ZDWLDNv4seZGzgyPeHrU9RKCaXX6wAgVJ+B6phrDlfhr2HSbvdbYZ0gc3G2B8RiGXFNzn5DDNVG2jlC5Lm4EiKD33Pf8C2+v4S95K8xXFzJTRysLwUKZkSm1GKhs7eP5HZ7NqpCSkGAfzGQgJDdXf7qM4IoTZO7yX1Ck3ToIWbmUxf3TMel4NCrTdM3KsjmnJjilO3ceQFSUpJfkVxGfeXT05CmPQ== Received: from ares2-ThinkPad-L13-Yoga-Gen-2.. ([2400:2410:b9a0:8400:93ae:f463:289c:d6c5]) by smtp.googlemail.com with ESMTPSA id ll5-20020a170903090500b001da186aa72csm2921904plb.17.2024.02.13.21.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 21:30:42 -0800 (PST) From: Vishnu Sankar To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, mpearson-lenovo@squebb.ca, vsankar@lenovo.com, Vishnu Sankar , Ilpo Jarvinen Subject: [PATCH 1/2] platform/x86: thinkpad_acpi: Simplify thermal mode checking Date: Wed, 14 Feb 2024 14:29:58 +0900 Message-Id: <20240214052959.8550-1-vishnuocv@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a thermal_read_mode_check helper function to make the code simpler during init. This helps particularly when the new TPEC_12 mode is added in the next patch. Suggested-by: Ilpo Jarvinen Signed-off-by: Vishnu Sankar --- drivers/platform/x86/thinkpad_acpi.c | 136 +++++++++++++-------------- 1 file changed, 66 insertions(+), 70 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index c4895e9bc714..2428c8bd0fa2 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -6147,6 +6147,71 @@ struct ibm_thermal_sensors_struct { static enum thermal_access_mode thermal_read_mode; static bool thermal_use_labels; +/* Function to check thermal read mode */ +static enum thermal_access_mode thermal_read_mode_check(void) +{ + u8 t, ta1, ta2, ver = 0; + int i; + + if (thinkpad_id.ec_model) { + /* + * Direct EC access mode: sensors at registers + * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for + * non-implemented, thermal sensors return 0x80 when + * not available + * The above rule is unfortunately flawed. This has been seen with + * 0xC2 (power supply ID) causing thermal control problems. + * The EC version can be determined by offset 0xEF and at least for + * version 3 the Lenovo firmware team confirmed that registers 0xC0-0xC7 + * are not thermal registers. + */ + if (!acpi_ec_read(TP_EC_FUNCREV, &ver)) + pr_warn("Thinkpad ACPI EC unable to access EC version\n"); + + ta1 = ta2 = 0; + for (i = 0; i < 8; i++) { + if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { + ta1 |= t; + } else { + ta1 = 0; + break; + } + if (ver < 3) { + if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { + ta2 |= t; + } else { + ta1 = 0; + break; + } + } + } + + if (ta1 == 0) { + pr_err("ThinkPad ACPI EC access misbehaving, disabling thermal sensors access\n"); + return TPACPI_THERMAL_NONE; + } + + if (ver >= 3) { + thermal_use_labels = true; + return TPACPI_THERMAL_TPEC_8; + } + + return (ta2 != 0) ? TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; + } + + if (acpi_evalf(ec_handle, NULL, "TMP7", "qv")) { + if (tpacpi_is_ibm() && + acpi_evalf(ec_handle, NULL, "UPDT", "qv")) + /* 600e/x, 770e, 770x */ + return TPACPI_THERMAL_ACPI_UPDT; + /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */ + return TPACPI_THERMAL_ACPI_TMP07; + } + + /* temperatures not supported on 570, G4x, R30, R31, R32 */ + return TPACPI_THERMAL_NONE; +} + /* idx is zero-based */ static int thermal_get_sensor(int idx, s32 *value) { @@ -6375,78 +6440,9 @@ static const struct attribute_group temp_label_attr_group = { static int __init thermal_init(struct ibm_init_struct *iibm) { - u8 t, ta1, ta2, ver = 0; - int i; - int acpi_tmp7; - vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); - acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); - - if (thinkpad_id.ec_model) { - /* - * Direct EC access mode: sensors at registers - * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for - * non-implemented, thermal sensors return 0x80 when - * not available - * The above rule is unfortunately flawed. This has been seen with - * 0xC2 (power supply ID) causing thermal control problems. - * The EC version can be determined by offset 0xEF and at least for - * version 3 the Lenovo firmware team confirmed that registers 0xC0-0xC7 - * are not thermal registers. - */ - if (!acpi_ec_read(TP_EC_FUNCREV, &ver)) - pr_warn("Thinkpad ACPI EC unable to access EC version\n"); - - ta1 = ta2 = 0; - for (i = 0; i < 8; i++) { - if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { - ta1 |= t; - } else { - ta1 = 0; - break; - } - if (ver < 3) { - if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { - ta2 |= t; - } else { - ta1 = 0; - break; - } - } - } - if (ta1 == 0) { - /* This is sheer paranoia, but we handle it anyway */ - if (acpi_tmp7) { - pr_err("ThinkPad ACPI EC access misbehaving, falling back to ACPI TMPx access mode\n"); - thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; - } else { - pr_err("ThinkPad ACPI EC access misbehaving, disabling thermal sensors access\n"); - thermal_read_mode = TPACPI_THERMAL_NONE; - } - } else { - if (ver >= 3) { - thermal_read_mode = TPACPI_THERMAL_TPEC_8; - thermal_use_labels = true; - } else { - thermal_read_mode = - (ta2 != 0) ? - TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; - } - } - } else if (acpi_tmp7) { - if (tpacpi_is_ibm() && - acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { - /* 600e/x, 770e, 770x */ - thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; - } else { - /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */ - thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; - } - } else { - /* temperatures not supported on 570, G4x, R30, R31, R32 */ - thermal_read_mode = TPACPI_THERMAL_NONE; - } + thermal_read_mode = thermal_read_mode_check(); vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), -- 2.34.1