From patchwork Fri Jan 19 20:47:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 10175971 X-Patchwork-Delegate: andy.shevchenko@gmail.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70A1A60392 for ; Fri, 19 Jan 2018 20:47:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 653B9286E2 for ; Fri, 19 Jan 2018 20:47:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5987228702; Fri, 19 Jan 2018 20:47:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC416286E2 for ; Fri, 19 Jan 2018 20:47:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756463AbeASUrW (ORCPT ); Fri, 19 Jan 2018 15:47:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51958 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754267AbeASUrU (ORCPT ); Fri, 19 Jan 2018 15:47:20 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B216785376; Fri, 19 Jan 2018 20:47:19 +0000 (UTC) Received: from dhcp-44-202.space.revspace.nl.com (ovpn-116-61.ams2.redhat.com [10.36.116.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE09960BE3; Fri, 19 Jan 2018 20:47:17 +0000 (UTC) From: Hans de Goede To: Darren Hart , Andy Shevchenko Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, James Subject: [PATCH 2/3] platform/x86: GPD pocket fan: Use a min-speed of 2 while charging Date: Fri, 19 Jan 2018 21:47:08 +0100 Message-Id: <20180119204709.16240-2-hdegoede@redhat.com> In-Reply-To: <20180119204709.16240-1-hdegoede@redhat.com> References: <20180119204709.16240-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 19 Jan 2018 20:47:19 +0000 (UTC) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Newer versions of the GPD pocket BIOS set the fan-speed to 2 when a charger gets plugged in while the device is off. Mirror this in our fan driver and use a minimum speed of 2 while charging, Cc: James Suggested-by: James Signed-off-by: Hans de Goede --- drivers/platform/x86/gpd-pocket-fan.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/gpd-pocket-fan.c b/drivers/platform/x86/gpd-pocket-fan.c index 1fdf2205730d..f7b4980c0aa6 100644 --- a/drivers/platform/x86/gpd-pocket-fan.c +++ b/drivers/platform/x86/gpd-pocket-fan.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -25,6 +26,11 @@ module_param(hysteresis, int, 0444); MODULE_PARM_DESC(hysteresis, "Hysteresis in milli-celcius before lowering the fan speed"); +static int speed_on_ac = 2; +module_param(speed_on_ac, int, 0444); +MODULE_PARM_DESC(speed_on_ac, + "minimum fan speed to allow when system is powered by AC"); + struct gpd_pocket_fan_data { struct device *dev; struct thermal_zone_device *dts0; @@ -46,11 +52,19 @@ static void gpd_pocket_fan_set_speed(struct gpd_pocket_fan_data *fan, int speed) fan->last_speed = speed; } +static int gpd_pocket_fan_min_speed(void) +{ + if (power_supply_is_system_supplied()) + return speed_on_ac; + else + return 0; +} + static void gpd_pocket_fan_worker(struct work_struct *work) { struct gpd_pocket_fan_data *fan = container_of(work, struct gpd_pocket_fan_data, work.work); - int t0, t1, temp, speed, i; + int t0, t1, temp, speed, min_speed, i; if (thermal_zone_get_temp(fan->dts0, &t0) || thermal_zone_get_temp(fan->dts1, &t1)) { @@ -62,9 +76,10 @@ static void gpd_pocket_fan_worker(struct work_struct *work) temp = max(t0, t1); speed = fan->last_speed; + min_speed = gpd_pocket_fan_min_speed(); /* Determine minimum speed */ - for (i = 0; i < ARRAY_SIZE(temp_limits); i++) { + for (i = min_speed; i < ARRAY_SIZE(temp_limits); i++) { if (temp < temp_limits[i]) break; } @@ -72,7 +87,7 @@ static void gpd_pocket_fan_worker(struct work_struct *work) speed = i; /* Use hysteresis before lowering speed again */ - for (i = 0; i < ARRAY_SIZE(temp_limits); i++) { + for (i = min_speed; i < ARRAY_SIZE(temp_limits); i++) { if (temp <= (temp_limits[i] - hysteresis)) break; } @@ -113,6 +128,11 @@ static int gpd_pocket_fan_probe(struct platform_device *pdev) hysteresis); return -EINVAL; } + if (speed_on_ac < 0 || speed_on_ac > MAX_SPEED) { + dev_err(&pdev->dev, "Invalid speed_on_ac %d (must be between 0 and 3)\n", + speed_on_ac); + return -EINVAL; + } fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL); if (!fan) @@ -157,7 +177,7 @@ static int gpd_pocket_fan_suspend(struct device *dev) { struct gpd_pocket_fan_data *fan = dev_get_drvdata(dev); - gpd_pocket_fan_set_speed(fan, 0); + gpd_pocket_fan_set_speed(fan, gpd_pocket_fan_min_speed()); return 0; }