From patchwork Mon Mar 19 06:17:39 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: 7344 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 6A39223E01 for ; Mon, 19 Mar 2012 06:18: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 319E9A1869C for ; Mon, 19 Mar 2012 06:18:11 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so12002286iag.11 for ; Sun, 18 Mar 2012 23:18:11 -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=p8re2ASA/7J7Gvx3q8NmTjCTq2BQJJhvMNouszibsOg=; b=Q6ChZAlKSbsd3yPrh8QubeXmR0PLp7m8MO6MbdzyjvVr4u6/niI8OVSzp3i6wzM21L W5RnRZu65ZzqGnG+S6mKql9yAShGlvZADo5ACIAumyUi+vy8N1EjM946HhQUTx0fzRuU MCZbQWcgsc+QN3wVGTT7BbDuxuSNGL6WOgwDqoCgz6793QC0KhTOXD24xQfvKcLG61CJ ifKIG/yTeIjommM+M+ZvU//4whPY2OFeylUlE+NB2TZ1qFI23jKlXeifE5rwKS0VKJwD xz7kJS1XQX63smOK8g1+BYqpjFP7gEA158FvGA1v/l/BEsYR0jVDSakqDFhCaR9QZIj9 bGgA== Received: by 10.50.155.229 with SMTP id vz5mr5134637igb.12.1332137890977; Sun, 18 Mar 2012 23:18:10 -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.203.79 with SMTP id fh15csp64768ibb; Sun, 18 Mar 2012 23:18:10 -0700 (PDT) Received: by 10.68.74.74 with SMTP id r10mr37777269pbv.83.1332137889901; Sun, 18 Mar 2012 23:18:09 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id j5si11545116pbl.242.2012.03.18.23.18.09 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 18 Mar 2012 23:18:09 -0700 (PDT) Received-SPF: pass (google.com: domain of amitdanielk@gmail.com designates 209.85.160.50 as permitted sender) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of amitdanielk@gmail.com designates 209.85.160.50 as permitted sender) smtp.mail=amitdanielk@gmail.com; dkim=pass header.i=@gmail.com Received: by pbcxa12 with SMTP id xa12so1170408pbc.37 for ; Sun, 18 Mar 2012 23:18:09 -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=p8re2ASA/7J7Gvx3q8NmTjCTq2BQJJhvMNouszibsOg=; b=RKqALWMpNdz+lRRptFq5pkOOhAu7iGvrAKEHPavRYIH9Yth6fA/YRbemXZECkwmaQg f7YA0km5ihO40fdkC2nFu8MjusbOjJc5C7IlEeJreO7nh5ZUDH+ZYqnMiI/MYoJ+70eJ 4XtMGlSCyMXVfHbqL3kJNCyMRpStAGJQNB2epVb0n9Rxdmbb/RIB8icS7L/MetZYgw9u JRYEYTj3QuJ5kXm1rZEvlxcm9d0i0cd195Xe9aJhBI+eVuUPAHC/coA2RHOZium/9fBE fl1Rqxso232/jKk+9qt6pvYK4td/5Jz5HN1gujqzxFVnws3jS5yc2MmIkj7y8EOwu5ZU yf4A== Received: by 10.68.216.229 with SMTP id ot5mr31126193pbc.148.1332137889032; Sun, 18 Mar 2012 23:18:09 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id h10sm10589640pbe.12.2012.03.18.23.18.04 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 18 Mar 2012 23:18:08 -0700 (PDT) Sender: amit kachhap From: Amit Daniel Kachhap To: linux-pm@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mjg59@srcf.ucam.org, linux-acpi@vger.kernel.org, lenb@kernel.org, linaro-dev@lists.linaro.org, lm-sensors@lm-sensors.org, amit.kachhap@linaro.org, patches@linaro.org, eduardo.valentin@ti.com, durgadoss.r@intel.com Subject: [PATCH V2 1/6] thermal: Add a new trip type to use cooling device instance number Date: Mon, 19 Mar 2012 11:47:39 +0530 Message-Id: <1332137864-12943-2-git-send-email-amit.kachhap@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1332137864-12943-1-git-send-email-amit.kachhap@linaro.org> References: <1332137864-12943-1-git-send-email-amit.kachhap@linaro.org> X-Gm-Message-State: ALoCoQmDGMHlKfs10QGCpKDf/VV4W2RK1miHYpe8vFxxxJNOd5hNiS+YJNTtw0Ovw5lwPo/E/QaY 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. 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..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 220ce7e..9fc2150 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_INSTANCE: + return sprintf(buf, "state-instance\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_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, 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 {