From patchwork Wed Feb 22 10:14:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 6876 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 7D08223E48 for ; Wed, 22 Feb 2012 10:16:11 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 43B54A1867E for ; Wed, 22 Feb 2012 10:16:11 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id z7so14190952iab.11 for ; Wed, 22 Feb 2012 02:16:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:x-forwarded-to:x-forwarded-for:delivered-to :received-spf:dkim-signature:sender:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=AEwiae+1gksExV5WlC7KLHn8khIqJSN0inynEUzFyNM=; b=BzREGSzVCRqWwda0a8sPmeFAOJffeWeef6J61wJJGM15UDpwBe5uDMMAB9hZv56EXh F+aUCULvbPIN5XRUZ/GqSdhL88C3OWKWDSCjdPl13ReWUyKj+Kv2Ro3EXFSzrRf/zX+h GQbxfCr4EfLdIR1EKKOtsoTNtLFtDAvso8Il4= MIME-Version: 1.0 Received: by 10.50.89.232 with SMTP id br8mr20332145igb.30.1329905771049; Wed, 22 Feb 2012 02:16:11 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.11.10 with SMTP id r10csp130291ibr; Wed, 22 Feb 2012 02:16:10 -0800 (PST) Received: by 10.68.240.100 with SMTP id vz4mr29826140pbc.78.1329905769783; Wed, 22 Feb 2012 02:16:09 -0800 (PST) Received: from mail-pw0-f53.google.com (mail-pw0-f53.google.com [209.85.160.53]) by mx.google.com with ESMTPS id g9si28222995pbd.101.2012.02.22.02.16.08 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Feb 2012 02:16:09 -0800 (PST) Received-SPF: pass (google.com: domain of amitdanielk@gmail.com designates 209.85.160.53 as permitted sender) client-ip=209.85.160.53; Authentication-Results: mx.google.com; spf=pass (google.com: domain of amitdanielk@gmail.com designates 209.85.160.53 as permitted sender) smtp.mail=amitdanielk@gmail.com; dkim=pass header.i=@gmail.com Received: by pbbrq13 with SMTP id rq13so10009753pbb.12 for ; Wed, 22 Feb 2012 02:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=AEwiae+1gksExV5WlC7KLHn8khIqJSN0inynEUzFyNM=; b=uVCY5tvmgf2dY7a0mruPo9OqInwzbKBzcT3hmLqsTWgeD/WBz978UbsUwuGiKuq9k9 3vpnOADGQdt0hZrVXzC06dh3oFXq4n9acLz/jHIwFJwnlv/b5bpo7Ip9fU2R8V26hwMl TM20eo9ncFEG7EK8THSV3YK0Zbb1cZNLB3J4I= Received: by 10.68.233.36 with SMTP id tt4mr6634420pbc.67.1329905768731; Wed, 22 Feb 2012 02:16:08 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id r10sm30178210pbs.12.2012.02.22.02.16.04 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Feb 2012 02:16:08 -0800 (PST) Sender: amit kachhap From: Amit Daniel Kachhap To: linux-pm@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, mjg59@srcf.ucam.org, linux-acpi@vger.kernel.org, lenb@kernel.org, linaro-dev@lists.linaro.org, amit.kachhap@linaro.org, durgadoss.r@intel.com, rob.lee@linaro.org, patches@linaro.org Subject: [PATCH 1/4] thermal: Add a new trip type to use cooling device instance number Date: Wed, 22 Feb 2012 15:44:07 +0530 Message-Id: <1329905650-30161-2-git-send-email-amit.kachhap@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1329905650-30161-1-git-send-email-amit.kachhap@linaro.org> References: <1329905650-30161-1-git-send-email-amit.kachhap@linaro.org> X-Gm-Message-State: ALoCoQnUHZf+CfsCYSljjXXrlsWT7R5PYP8SSq+2FIVcAKcWklbTEfPRDspWIyvIEg4UIjeEPnoN This patch adds a new trip type THERMAL_TRIP_STATE_ACTIVE. This trip behaves same as THERMAL_TRIP_ACTIVE but also passes the cooling device instance number. This helps the cooling device registered as different instances to perform appropriate cooling action decision in the set_cur_state call back function. Also since the trip temperature's are in ascending order so some logic is put in place to skip the un-necessary checks. Signed-off-by: Amit Daniel Kachhap --- Documentation/thermal/sysfs-api.txt | 4 +- drivers/thermal/thermal_sys.c | 45 ++++++++++++++++++++++++++++++++-- include/linux/thermal.h | 1 + 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt index 1733ab9..7a0c080 100644 --- a/Documentation/thermal/sysfs-api.txt +++ b/Documentation/thermal/sysfs-api.txt @@ -184,8 +184,8 @@ trip_point_[0-*]_temp trip_point_[0-*]_type Strings which indicate the type of the trip point. - E.g. it can be one of critical, hot, passive, active[0-*] for ACPI - thermal zone. + E.g. it can be one of critical, hot, passive, active[0-1], + state-active[0-*] for ACPI thermal zone. RO, Optional cdev[0-*] diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c index 220ce7e..d4c9b20 100644 --- a/drivers/thermal/thermal_sys.c +++ b/drivers/thermal/thermal_sys.c @@ -192,6 +192,8 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr, return sprintf(buf, "passive\n"); case THERMAL_TRIP_ACTIVE: return sprintf(buf, "active\n"); + case THERMAL_TRIP_STATE_ACTIVE: + return sprintf(buf, "state-active\n"); default: return sprintf(buf, "unknown\n"); } @@ -1034,10 +1036,10 @@ EXPORT_SYMBOL(thermal_cooling_device_unregister); void thermal_zone_device_update(struct thermal_zone_device *tz) { - int count, ret = 0; - long temp, trip_temp; + int count, ret = 0, inst_id; + long temp, trip_temp, max_state, last_trip_change = 0; enum thermal_trip_type trip_type; - struct thermal_cooling_device_instance *instance; + struct thermal_cooling_device_instance *instance, *state_instance; struct thermal_cooling_device *cdev; mutex_lock(&tz->lock); @@ -1086,6 +1088,43 @@ void thermal_zone_device_update(struct thermal_zone_device *tz) cdev->ops->set_cur_state(cdev, 0); } break; + case THERMAL_TRIP_STATE_ACTIVE: + list_for_each_entry(instance, &tz->cooling_devices, + node) { + if (instance->trip != count) + continue; + + if (temp <= last_trip_change) + continue; + + inst_id = 0; + /* + *For this instance how many instance of same + *cooling device occured before + */ + + list_for_each_entry(state_instance, + &tz->cooling_devices, node) { + if (instance->cdev == + state_instance->cdev) + inst_id++; + if (state_instance->trip == count) + break; + } + + cdev = instance->cdev; + cdev->ops->get_max_state(cdev, &max_state); + + if ((temp >= trip_temp) && + (inst_id <= max_state)) + cdev->ops->set_cur_state(cdev, inst_id); + else if ((temp < trip_temp) && + (--inst_id <= max_state)) + cdev->ops->set_cur_state(cdev, inst_id); + + last_trip_change = trip_temp; + } + break; case THERMAL_TRIP_PASSIVE: if (temp >= trip_temp || tz->passive) thermal_zone_device_passive(tz, temp, diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 796f1ff..8df901f 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -42,6 +42,7 @@ enum thermal_trip_type { THERMAL_TRIP_PASSIVE, THERMAL_TRIP_HOT, THERMAL_TRIP_CRITICAL, + THERMAL_TRIP_STATE_ACTIVE, }; struct thermal_zone_device_ops {