From patchwork Sun Apr 5 19:58:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "larsh@apache.org" X-Patchwork-Id: 11474859 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 846C8159A for ; Sun, 5 Apr 2020 19:58:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 586B620644 for ; Sun, 5 Apr 2020 19:58:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="Y52eNq6t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726887AbgDET6t (ORCPT ); Sun, 5 Apr 2020 15:58:49 -0400 Received: from sonic310-14.consmr.mail.bf2.yahoo.com ([74.6.135.124]:33236 "EHLO sonic310-14.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726678AbgDET6t (ORCPT ); Sun, 5 Apr 2020 15:58:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1586116727; bh=rlCNfbSK3obcC2sPUMDiX98whU0f+1oa/G9JoaL7nqQ=; h=Date:From:To:Cc:Subject:References:From:Subject; b=Y52eNq6t/km7sw5J5aT0hlHmqnfqdbpO4Vx6FdTbsR1JP9rMnUIplU+12gRJU8NXYFa/on+Pj6g/ZEh7pHg1rUbC8wIZnvDAmSM11LQVImqG/saBk4SCzdrdmW+0a4ia2kIRNmUFzf8cjb8k+TIYUVKDk8esMKOGKDB/kU5Ne9vP7Y6q91adfoh1UUaPCC1opawUIXhmyzO+7Bdzj4XYK4uLaPLOPOW1rHYsJMWRTxgwo8+G+yLidA74Ij/LVwRCQDa0iw2mUlSvwI1WMGj6jvBLhIziy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OcV0hXGXdOxPRk_JR50qZ9YmGt.yvwmR3c90wKH1n kBxKGYOkYZPjE9zV0GkS4tsENFvwSIwm7iy1cyCpPGB.K80VrUPEkBDtuSkeIy2lZ9EyPQ1yNChn Tqq.750cDDGkBCdQIOx2EGGFsBBZNmEB.Ps1e335baUkeptgbC1A8LBgeylK9JyOscUThVpg2CdS a1bgegHqPJaEULae.rJfwgZb7rRuqSSqZEga7b1KWbaPNof8ei8VfW5B_nBevfjlFz5SUHN9CH50 F9JzN880gJFBh.Zhsyl_kdTVTLeHnzaYcb_oSolS73L7.hPH_fVNPru9eBHTqHQnSn_a5N0t1TMH N8dkL383tV12auI2UScNWQzWzEwuzRgK26Iwfub68 Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.bf2.yahoo.com with HTTP; Sun, 5 Apr 2020 19:58:47 +0000 Date: Sun, 5 Apr 2020 19:58:46 +0000 (UTC) From: "larsh@apache.org" To: "ibm-acpi@hmh.eng.br" Cc: "ibm-acpi-devel@lists.sourceforge.net" , platform-driver-x86@vger.kernel.org Message-ID: <970969929.574750.1586116726988@mail.yahoo.com> Subject: [PATCH] thinkpad_acpi: Add support for dual fan control on select models MIME-Version: 1.0 References: <970969929.574750.1586116726988.ref@mail.yahoo.com> X-Mailer: WebService/1.1.15620 YMailNorrin Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org This patch allows controlling multiple fans as if they were a single fan. This adds P52, P72, X1E, and X1E gen to dual fan quirks. Both fans are controlled together. Tested on an X1 Extreme Gen2. The patch is defensive, it adds only specific supported machines, and falls back to the old behavior if both fans cannot be controlled. It does attempt single fan control for all previously white-listed Thinkpads. Background: I tested the BIOS default behavior on my X1E gen2 and both fans are always changed together. So rather than adding controls for each fan, this controls both fans together as the BIOS would do. This was inspired by a discussion on dual fan support for the thinkfan tool (https://github.com/vmatare/thinkfan/issues/58). (Thanks to Github users voidworker, and civic9.) The BIOS ids for P52/P72 and X1E are taken from there. The X1E gen2 id is verified on my machine. Signed-off-by: Lars Hofhansl diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index da794dcfdd92..8d46b4c2bde8 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -8325,11 +8325,20 @@ static int fan_set_level(int level)        switch (fan_control_access_mode) {      case TPACPI_FAN_WR_ACPI_SFAN: -        if (level >= 0 && level <= 7) { -            if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) -                return -EIO; -        } else +        if (((level < 0) || (level > 7)))              return -EINVAL; + +        if (tp_features.second_fan) { +            if (!fan_select_fan2() || +                !acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) { +                fan_select_fan1(); +                pr_warn("Couldn't set 2nd fan level, disabling support\n"); +                tp_features.second_fan = 0; +            } +            fan_select_fan1(); +        } +        if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) +            return -EIO;          break;        case TPACPI_FAN_WR_ACPI_FANS: @@ -8346,6 +8355,16 @@ static int fan_set_level(int level)          else if (level & TP_EC_FAN_AUTO)              level |= 4;    /* safety min speed 4 */   +        if (tp_features.second_fan) { +            if (!fan_select_fan2() || +                !acpi_ec_write(fan_status_offset, level)) { +                fan_select_fan1(); +                pr_warn("Couldn't set 2nd fan level, disabling support\n"); +                tp_features.second_fan = 0; +            } +            fan_select_fan1(); + +        }          if (!acpi_ec_write(fan_status_offset, level))              return -EIO;          else @@ -8772,6 +8791,9 @@ static const struct tpacpi_quirk fan_quirk_table[] __initconst = {      TPACPI_QEC_IBM('7', '0', TPACPI_FAN_Q1),      TPACPI_QEC_LNV('7', 'M', TPACPI_FAN_2FAN),      TPACPI_Q_LNV('N', '1', TPACPI_FAN_2FAN), +    TPACPI_Q_LNV3('N', '2', 'C', TPACPI_FAN_2FAN),    /* P52 / P72 */ +    TPACPI_Q_LNV3('N', '2', 'E', TPACPI_FAN_2FAN),    /* X1 Extreme (1st gen) */ +    TPACPI_Q_LNV3('N', '2', 'O', TPACPI_FAN_2FAN),    /* X1 Extreme (2nd gen) */  };    static int __init fan_init(struct ibm_init_struct *iibm) @@ -8813,8 +8835,7 @@ static int __init fan_init(struct ibm_init_struct *iibm)                  fan_quirk1_setup();              if (quirks & TPACPI_FAN_2FAN) {                  tp_features.second_fan = 1; -                dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, -                    "secondary fan support enabled\n"); +                pr_info("secondary fan support enabled\n");              }          } else {              pr_err("ThinkPad ACPI EC access misbehaving, fan status and control unavailable\n");