From patchwork Thu Feb 26 09:48:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haschka X-Patchwork-Id: 443879 X-Patchwork-Delegate: benh@kernel.crashing.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5C8C31400B6 for ; Thu, 26 Feb 2015 20:48:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=Ud39+vx7; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 333581A0374 for ; Thu, 26 Feb 2015 20:48:54 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=Ud39+vx7; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-we0-x22b.google.com (mail-we0-x22b.google.com [IPv6:2a00:1450:400c:c03::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id EEBA01A002B for ; Thu, 26 Feb 2015 20:47:31 +1100 (AEDT) Received: by wesq59 with SMTP id q59so8908205wes.1 for ; Thu, 26 Feb 2015 01:47:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=D1prAB+ceK70G0TKM3I3Bg0RyWlRCEUAAeQDcOsMX4o=; b=Ud39+vx7jYuol56CrLfVfUNa5qoa/RvMtbO15n3HLV7n9LfGLb6PMEjm+JefcTLqCL mn5j/gi3l9lXpAwl7diajF4YZVC91SHac6Lm7XWhGmTmkGGwpFG0Fhc/9IE1Hp3glIFO 6ONrvBREnLd/+03Uf0fCeedppJ/86kwHX7k/I0GTOJqyY0aCz6/AZGism3D/znVCtVG1 M3z2N26bnOL5rk5HZZEgKJ40RG2gBF5PiiOzz3ggRyZlXYT5u3iFz+aKeO4jNJkao9j5 wCoNUqI19Nqz9ORTxsZ22VSb6QRIWn4KNw39XVa890MdwfWLITDrBBI6Grikd+9nD/LL ufQw== X-Received: by 10.194.236.200 with SMTP id uw8mr14665825wjc.10.1424944046775; Thu, 26 Feb 2015 01:47:26 -0800 (PST) Received: from gmail.com (LCaen-656-1-174-253.w80-15.abo.wanadoo.fr. [80.15.161.253]) by mx.google.com with ESMTPSA id lj13sm1996849wic.9.2015.02.26.01.47.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Feb 2015 01:47:25 -0800 (PST) Date: Thu, 26 Feb 2015 10:48:05 +0100 From: Thomas Haschka To: Benjamin Herrenschmidt Subject: Re: [PATCH 1/1]: thermal driver therm_adt746.c Message-ID: <20150226094805.GA1009@gmail.com> References: <1424726318.12891.1.camel@kernel.crashing.org> <20150225112457.GA3491@gmail.com> <1424898763.12891.77.camel@kernel.crashing.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1424898763.12891.77.camel@kernel.crashing.org> User-Agent: Mutt/1.5.22 (2013-10-16) Cc: linuxppc-dev@lists.ozlabs.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Hello, I hope I get it correct this time, thanks again. Just to recapitulate, here's a quick list of the changes made: 1. changes in sensors limits, we are down from 70, 50, 70 to 45, 50, 70, where the first value is the environement sensor that is located on the bottumside of the Harddrive. Empirical testing shows that this speeds up the Fan almoast in the same moment as in OS X 2. A function has been added in order to take the environement sensor into account on SingleFan Apple Notebooks (i.e. those that have air inlets next to the harddrive and that are cooling, besides other components using the single fan in these machines. 3. Output values in /sys/devices/temperatures/ etc.. have been changed. First: All three sensors can be monitored right now instead of only the GPU and CPU sensors. Second: The units have been changed in order to correspond to the units given by other temperature sensors, such as the coretemp (intel) sensor. This allows to monitor them using several applications, notably xosview. cheers, Signed-off-by: Thomas Haschka --- drivers/macintosh/therm_adt746x.c | 118 +++++++++++++++++++++++++++++++++++--- 1 file changed, 109 insertions(+), 9 deletions(-) diff --git a/drivers/macintosh/therm_adt746x.c b/drivers/macintosh/therm_adt746x.c index f433521..3ade51a 100644 --- a/drivers/macintosh/therm_adt746x.c +++ b/drivers/macintosh/therm_adt746x.c @@ -1,7 +1,8 @@ /* * Device driver for the i2c thermostat found on the iBook G4, Albook G4 * - * Copyright (C) 2003, 2004 Colin Leroy, Rasmus Rohde, Benjamin Herrenschmidt + * Copyright (C) 2003, 2004, 2015 + * Colin Leroy, Rasmus Rohde, Benjamin Herrenschmidt, Thomas Haschka * * Documentation from 115254175ADT7467_pra.pdf and 3686221171167ADT7460_b.pdf * http://www.onsemi.com/PowerSolutions/product.do?id=ADT7467 @@ -45,8 +46,10 @@ static u8 REM_CONTROL[2] = {0x00, 0x40}; static u8 FAN_SPEED[2] = {0x28, 0x2a}; static u8 FAN_SPD_SET[2] = {0x30, 0x31}; -static u8 default_limits_local[3] = {70, 50, 70}; /* local, sensor1, sensor2 */ -static u8 default_limits_chip[3] = {80, 65, 80}; /* local, sensor1, sensor2 */ +/* Local sensor is down to 45 in order to assure stable harddrive and + * components temperature on single fan machines */ +static u8 default_limits_local[3] = {45, 50, 70}; /* local, sensor1, sensor2 */ +static u8 default_limits_chip[3] = {80, 65, 80}; /* local, sensor1, sensor2 */ static const char *sensor_location[3] = { "?", "?", "?" }; static int limit_adjust; @@ -223,7 +226,7 @@ static void display_stats(struct thermostat *th) } #endif -static void update_fans_speed (struct thermostat *th) +static void update_fans_speed_multifan (struct thermostat *th) { int lastvar = 0; /* last variation, for iBook */ int i = 0; @@ -278,6 +281,83 @@ static void update_fans_speed (struct thermostat *th) } } +static void update_fans_speed_singlefan (struct thermostat *th) { + + /* Single Fan Laptops i.e. 12 inch Powerbook, Ibook etc. + * Necessites the readout of all three thermal sensors + * in order to avoid the harddisk and other components to overheat + * in the case of cold CPU. */ + + int lastvar = 0; /* last variation, for iBook */ + int i = 0; + int var = 0; + int var_sensor[3]; + int started = 0; + int fan_number = 0; + for (i = 0; i < 3; i++) { + var_sensor[i] = th->temps[i] - th->limits[i]; + } + var = var_sensor[0]; + for (i = 1; i < 3; i++) { + if (var_sensor[i] > var) { + var = var_sensor[i]; + } + } + if (var > -1) { + int step = (255 - fan_speed) / 7; + int new_speed = 0; + /* hysteresis : change fan speed only if variation is + * more than two degrees */ + if (abs(var - th->last_var[fan_number]) > 2) { + + started = 1; + new_speed = fan_speed + ((var-1)*step); + + if (new_speed < fan_speed) + new_speed = fan_speed; + if (new_speed > 255) + new_speed = 255; + + if (verbose) + printk(KERN_DEBUG "adt746x:" + " Setting fans speed to %d " + "(limit exceeded by %d on %s)\n", + new_speed, var, + sensor_location[fan_number+1]); + write_both_fan_speed(th, new_speed); + th->last_var[fan_number] = var; + } + } else if (var < -2) { + /* don't stop fan if sensor2 is cold and sensor1 is not + * so cold (lastvar >= -1) */ + if (i == 2 && lastvar < -1) { + if (th->last_speed[fan_number] != 0) + if (verbose) + printk(KERN_DEBUG "adt746x:" + " Stopping " + "fans.\n"); + write_both_fan_speed(th, 0); + } + } + + lastvar = var; + + if (started) + return; /* we don't want to re-stop the fan + * if sensor1 is heating and sensor2 is not */ +} + +static void update_fans_speed(struct thermostat *th) { + + if (th->type == ADT7460) { + /* Multifan Laptops */ + update_fans_speed_multifan(th); + } else { + /* Singlefan Laptops i.e. 12 inch Powerbook, Ibook etc. */ + update_fans_speed_singlefan(th); + } +} + static int monitor_task(void *arg) { struct thermostat* th = arg; @@ -371,10 +451,18 @@ static ssize_t store_##name(struct device *dev, struct device_attribute *attr, c return n; \ } -BUILD_SHOW_FUNC_INT(sensor1_temperature, (read_reg(th, TEMP_REG[1]))) -BUILD_SHOW_FUNC_INT(sensor2_temperature, (read_reg(th, TEMP_REG[2]))) -BUILD_SHOW_FUNC_INT(sensor1_limit, th->limits[1]) -BUILD_SHOW_FUNC_INT(sensor2_limit, th->limits[2]) +/* Several nits are multiplied by 1000 in order to have + * coherent readings with other + * temperature sensors such as intel coretemp. This further + * allows programs such as xosview to read these sensors correctly */ + +BUILD_SHOW_FUNC_INT(sensor0_temperature, (read_reg(th, TEMP_REG[0]))*1000) +BUILD_SHOW_FUNC_INT(sensor1_temperature, (read_reg(th, TEMP_REG[1]))*1000) +BUILD_SHOW_FUNC_INT(sensor2_temperature, (read_reg(th, TEMP_REG[2]))*1000) +BUILD_SHOW_FUNC_INT(sensor0_limit, (th->limits[0])*1000) +BUILD_SHOW_FUNC_INT(sensor1_limit, (th->limits[1])*1000) +BUILD_SHOW_FUNC_INT(sensor2_limit, (th->limits[2])*1000) +BUILD_SHOW_FUNC_STR(sensor0_location, sensor_location[0]) BUILD_SHOW_FUNC_STR(sensor1_location, sensor_location[1]) BUILD_SHOW_FUNC_STR(sensor2_location, sensor_location[2]) @@ -387,14 +475,20 @@ BUILD_SHOW_FUNC_FAN(sensor2_fan_speed, 1) BUILD_SHOW_FUNC_INT_LITE(limit_adjust, limit_adjust) BUILD_STORE_FUNC_DEG(limit_adjust, th) +static DEVICE_ATTR(sensor0_temperature, S_IRUGO, + show_sensor0_temperature,NULL); static DEVICE_ATTR(sensor1_temperature, S_IRUGO, show_sensor1_temperature,NULL); static DEVICE_ATTR(sensor2_temperature, S_IRUGO, show_sensor2_temperature,NULL); +static DEVICE_ATTR(sensor0_limit, S_IRUGO, + show_sensor0_limit, NULL); static DEVICE_ATTR(sensor1_limit, S_IRUGO, show_sensor1_limit, NULL); static DEVICE_ATTR(sensor2_limit, S_IRUGO, show_sensor2_limit, NULL); +static DEVICE_ATTR(sensor0_location, S_IRUGO, + show_sensor0_location, NULL); static DEVICE_ATTR(sensor1_location, S_IRUGO, show_sensor1_location, NULL); static DEVICE_ATTR(sensor2_location, S_IRUGO, @@ -426,10 +520,13 @@ static void thermostat_create_files(struct thermostat *th) return; dev = &th->pdev->dev; dev_set_drvdata(dev, th); - err = device_create_file(dev, &dev_attr_sensor1_temperature); + err = device_create_file(dev, &dev_attr_sensor0_temperature); + err |= device_create_file(dev, &dev_attr_sensor1_temperature); err |= device_create_file(dev, &dev_attr_sensor2_temperature); + err |= device_create_file(dev, &dev_attr_sensor0_limit); err |= device_create_file(dev, &dev_attr_sensor1_limit); err |= device_create_file(dev, &dev_attr_sensor2_limit); + err |= device_create_file(dev, &dev_attr_sensor0_location); err |= device_create_file(dev, &dev_attr_sensor1_location); err |= device_create_file(dev, &dev_attr_sensor2_location); err |= device_create_file(dev, &dev_attr_limit_adjust); @@ -449,10 +546,13 @@ static void thermostat_remove_files(struct thermostat *th) if (!th->pdev) return; dev = &th->pdev->dev; + device_remove_file(dev, &dev_attr_sensor0_temperature); device_remove_file(dev, &dev_attr_sensor1_temperature); device_remove_file(dev, &dev_attr_sensor2_temperature); + device_remove_file(dev, &dev_attr_sensor0_limit); device_remove_file(dev, &dev_attr_sensor1_limit); device_remove_file(dev, &dev_attr_sensor2_limit); + device_remove_file(dev, &dev_attr_sensor0_location); device_remove_file(dev, &dev_attr_sensor1_location); device_remove_file(dev, &dev_attr_sensor2_location); device_remove_file(dev, &dev_attr_limit_adjust);