From patchwork Tue May 8 16:18:13 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: 8470 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 3589923E23 for ; Tue, 8 May 2012 16:18:43 +0000 (UTC) Received: from mail-wg0-f42.google.com (mail-wg0-f42.google.com [74.125.82.42]) by fiordland.canonical.com (Postfix) with ESMTP id 2CAF5A1854F for ; Tue, 8 May 2012 16:18:43 +0000 (UTC) Received: by wgbds11 with SMTP id ds11so784998wgb.5 for ; Tue, 08 May 2012 09:18:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=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:x-gm-message-state; bh=i+gEHaMT+CdSm93rwjlQTwwUcJNoXUvBODm8em5JnRk=; b=MnPjAiQH7DXhxnexu76/wdj+9AOSsPbXPbe/EllaFkx7bzuyfepnfgs9oTbZTpE/N5 q0n2aMoP2y2UWZdQht9v0TIIP7BxmwJ4E+U5BEiMHFNzCCw3g0V5uT2m6lLbfiv6rZUJ G8+pZvp4mD/mVoOMHS1wTdHQfi3koGwS9PwFiikjxUeIIkQP568chn+dGsUr15SCeNNc zwvy81AXm0fVEnN1ZFrZQRBy1eo2CvaLuSb5fbnd1MTse+9qxc6KWaAXCGfpInrf99ZV RASOqwsTgcd9yEdKf5XIbq0VcZqVl0NbE2uE14qaFeriaUcVaA6lFraoqB2oKum8x6CQ FliA== Received: by 10.50.10.225 with SMTP id l1mr11159655igb.1.1336493922502; Tue, 08 May 2012 09:18:42 -0700 (PDT) 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.73.147 with SMTP id q19csp211182ibj; Tue, 8 May 2012 09:18:41 -0700 (PDT) Received: by 10.68.200.201 with SMTP id ju9mr14269985pbc.91.1336493920756; Tue, 08 May 2012 09:18:40 -0700 (PDT) Received: from mail-pz0-f50.google.com (mail-pz0-f50.google.com [209.85.210.50]) by mx.google.com with ESMTPS id wq6si1806598pbc.291.2012.05.08.09.18.39 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 May 2012 09:18:40 -0700 (PDT) Received-SPF: pass (google.com: domain of amitdanielk@gmail.com designates 209.85.210.50 as permitted sender) client-ip=209.85.210.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of amitdanielk@gmail.com designates 209.85.210.50 as permitted sender) smtp.mail=amitdanielk@gmail.com; dkim=pass header.i=@gmail.com Received: by danh15 with SMTP id h15so3701109dan.37 for ; Tue, 08 May 2012 09:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=i+gEHaMT+CdSm93rwjlQTwwUcJNoXUvBODm8em5JnRk=; b=KUA8MQx4xxn0Ca+ZMbuDA2sVqs8gVIuIQXYTv/pmXyFYXAjJOT+EHV26t2XaL3Fa/Z P/9in1ZRRFbW+7Dvc2Hsc1ojQV/pCRMjYk82u/9q3Nr0h2jiaYBQ8CwGa14ZuY02Z6HA IFCpuPRAG5vHdW/5yu9AKh7EjKfAGEboPUvntLOVzC9yMWwZDlXAWmJIClbfwh1vkMUb XceoKr4o8zJgyHEbdECSWhfF8Hzjt2UMcuI+/RmITAdIKrKfRW+wjyEwa6DGghVHdFqR J3s0UI7pN9uQBim+F8TqbQgZAoK6J6Bh+EMTBf5mAR6kvO8tuNj0m3KGN9lM9nbKLwqm 1mBQ== Received: by 10.68.204.2 with SMTP id ku2mr2172105pbc.55.1336493919857; Tue, 08 May 2012 09:18:39 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id oj3sm2833966pbb.20.2012.05.08.09.18.35 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 May 2012 09:18:38 -0700 (PDT) Sender: amit kachhap From: Amit Daniel Kachhap To: akpm@linux-foundation.org, linux-pm@lists.linux-foundation.org Cc: durgadoss.r@intel.com, linux-acpi@vger.kernel.org, lenb@kernel.org, rui.zhang@intel.com, amit.kachhap@linaro.org, linaro-dev@lists.linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, patches@linaro.org Subject: [PATCH v3 1/6] thermal: Add a new trip type to use cooling device instance number Date: Tue, 8 May 2012 21:48:13 +0530 Message-Id: <1336493898-7039-2-git-send-email-amit.kachhap@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1336493898-7039-1-git-send-email-amit.kachhap@linaro.org> References: <1336493898-7039-1-git-send-email-amit.kachhap@linaro.org> X-Gm-Message-State: ALoCoQm1+OSCVlCEIL4RfnXwmoroURvM+dht9gQ0HIihjCBW/5hGpZcATj0kBMGqjYO4R3sGqL/p This patch adds a new trip type THERMAL_TRIP_STATE_INSTANCE. 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 during thermal zone update and return error when failing the ascending order trip point check during thermal zone registration. Signed-off-by: Amit Daniel Kachhap --- Documentation/thermal/sysfs-api.txt | 4 +- drivers/thermal/thermal_sys.c | 62 +++++++++++++++++++++++++++++++++-- include/linux/thermal.h | 1 + 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt index 1733ab9..9a7c69c 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-instance[0-*] for ACPI thermal zone. RO, Optional cdev[0-*] diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c index 022bacb..4ae93fb 100644 --- a/drivers/thermal/thermal_sys.c +++ b/drivers/thermal/thermal_sys.c @@ -190,6 +190,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_INSTANCE: + return sprintf(buf, "state-instance\n"); default: return sprintf(buf, "unknown\n"); } @@ -1013,10 +1015,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); @@ -1063,6 +1065,43 @@ void thermal_zone_device_update(struct thermal_zone_device *tz) cdev->ops->set_cur_state(cdev, 0); } break; + case THERMAL_TRIP_STATE_INSTANCE: + 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, @@ -1117,6 +1156,7 @@ struct thermal_zone_device *thermal_zone_device_register(char *type, int result; int count; int passive = 0; + long first_trip_temp, trip_temp; if (strlen(type) >= THERMAL_NAME_LENGTH) return ERR_PTR(-EINVAL); @@ -1175,6 +1215,7 @@ struct thermal_zone_device *thermal_zone_device_register(char *type, goto unregister; } + first_trip_temp = 0; for (count = 0; count < trips; count++) { result = device_create_file(&tz->device, &trip_point_attrs[count * 2]); @@ -1187,6 +1228,21 @@ struct thermal_zone_device *thermal_zone_device_register(char *type, tz->ops->get_trip_type(tz, count, &trip_type); if (trip_type == THERMAL_TRIP_PASSIVE) passive = 1; + /* + * For THERMAL_TRIP_STATE_INSTANCE trips, thermal zone should + * be in ascending order. + */ + if (trip_type == THERMAL_TRIP_STATE_INSTANCE) { + tz->ops->get_trip_temp(tz, count, &trip_temp); + if (first_trip_temp == 0) + first_trip_temp = trip_temp; + else if (first_trip_temp < trip_temp) + first_trip_temp = trip_temp; + else if (first_trip_temp > trip_temp) { + pr_warn("Zone trip points should be in ascending order\n"); + goto unregister; + } + } } if (!passive) diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 796f1ff..583fbda 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_INSTANCE, }; struct thermal_zone_device_ops {