From patchwork Thu May 8 14:37:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 29843 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6B442202DD for ; Thu, 8 May 2014 14:39:01 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kx10sf11877177pab.10 for ; Thu, 08 May 2014 07:39:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=vc7yC+h4jfK+QnyNHCqNv5d/Ft6xISN2XTTsA0Vw15M=; b=gYEpMrcRuAegwr0CfUTW9+H8ssjMbMwQvpiSza+nYWftHlWnzhmv0oPpLKjneQK/wB TW+UTgUP7kRG4XXMQN1PyYB5cHhRN7Cq3ZyZgLukWZq+lztZfynce1zrC/0NxXZTPgV+ uSSI7drfTN/jAOORBpXwFH9h5bf/HiSdrXd18pP6O7p/Y9/m68FE3NoLWkDurDVekalg XWeEYbX4u0kR6LkGO8yy74+hM2H/srVEf+7VeYUTLTFzvYpwWxPzNb5wJLBTE3irI7re PXFyIqmUh4doCiK/TGWVSTLTi+ZX88UFTRM841TYr40vK5AfU4sxB68CP9ZXCgfCyRKe 4f6Q== X-Gm-Message-State: ALoCoQmz2Tc8L+YkzTXhhUBsgco9Q6bn4vp7/HlqzBRECmqFAZrwIxWezY+L9HrV++RVuTa3EMnB X-Received: by 10.67.4.202 with SMTP id cg10mr7502368pad.42.1399559940282; Thu, 08 May 2014 07:39:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.131 with SMTP id d3ls3932401qge.52.gmail; Thu, 08 May 2014 07:39:00 -0700 (PDT) X-Received: by 10.220.105.4 with SMTP id r4mr3243997vco.27.1399559940132; Thu, 08 May 2014 07:39:00 -0700 (PDT) Received: from mail-vc0-x231.google.com (mail-vc0-x231.google.com [2607:f8b0:400c:c03::231]) by mx.google.com with ESMTPS id a8si204919vej.179.2014.05.08.07.39.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 08 May 2014 07:39:00 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=2607:f8b0:400c:c03::231; Received: by mail-vc0-f177.google.com with SMTP id if11so3345078vcb.8 for ; Thu, 08 May 2014 07:39:00 -0700 (PDT) X-Received: by 10.52.227.138 with SMTP id sa10mr2721850vdc.25.1399559940052; Thu, 08 May 2014 07:39:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp409780vcb; Thu, 8 May 2014 07:38:59 -0700 (PDT) X-Received: by 10.221.36.73 with SMTP id sz9mr1015462vcb.62.1399559939337; Thu, 08 May 2014 07:38:59 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ek4si635384pbc.38.2014.05.08.07.38.58; Thu, 08 May 2014 07:38:58 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754644AbaEHOiF (ORCPT + 27 others); Thu, 8 May 2014 10:38:05 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:52375 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754609AbaEHOh7 (ORCPT ); Thu, 8 May 2014 10:37:59 -0400 Received: by mail-pa0-f51.google.com with SMTP id kq14so2935610pab.38 for ; Thu, 08 May 2014 07:37:59 -0700 (PDT) X-Received: by 10.66.254.234 with SMTP id al10mr8085381pad.137.1399559879127; Thu, 08 May 2014 07:37:59 -0700 (PDT) Received: from localhost.localdomain ([14.140.216.146]) by mx.google.com with ESMTPSA id vf9sm2357141pbc.94.2014.05.08.07.37.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 08 May 2014 07:37:58 -0700 (PDT) From: Amit Daniel Kachhap To: linux-pm@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org Cc: lenb@kernel.org, rui.zhang@intel.com, eduardo.valentin@ti.com, rjw@rjwysocki.net Subject: [RFC PATCH 3/5] thermal: cpu_cooling: Add support to find nearby frequency levels. Date: Thu, 8 May 2014 20:07:58 +0530 Message-Id: <1399559880-20562-4-git-send-email-amit.daniel@samsung.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1399559880-20562-1-git-send-email-amit.daniel@samsung.com> References: <1399559880-20562-1-git-send-email-amit.daniel@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: amit.daniel@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@ Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds suuport to get P state ceil/floor level for nearest frequency. This will be used for consolidating ACPI cpufreq cooling via the generic cpu cooling framework. Signed-off-by: Amit Daniel Kachhap --- drivers/thermal/cpu_cooling.c | 42 +++++++++++++++++------ drivers/thermal/samsung/exynos_thermal_common.c | 3 +- include/linux/cpu_cooling.h | 23 ++++++++++++- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index e2aeb36..6f5430e 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -120,12 +120,7 @@ static int is_cpufreq_valid(int cpu) return !cpufreq_get_policy(&policy, cpu); } -enum cpufreq_cooling_property { - GET_LEVEL, - GET_FREQ, - GET_MAXL, -}; - +#define GET_FREQ (GET_MAXL + 1) /** * get_property - fetch a property of interest for a give cpu. * @cpu: cpu for which the property is required @@ -207,15 +202,37 @@ static int get_property(unsigned int cpu, unsigned long input, /* now we have a valid frequency entry */ freq = table[i].frequency; - if (property == GET_LEVEL && (unsigned int)input == freq) { + if (property == GET_LEVEL_EXACT && + (unsigned int)input == freq) { /* get level by frequency */ *output = descend ? j : (max_level - j); return 0; - } - if (property == GET_FREQ && level == j) { + } else if (property == GET_FREQ && level == j) { /* get frequency by level */ *output = freq; return 0; + } else if (property == GET_LEVEL_FLOOR) { + /* get minimum possible level by frequency */ + if (descend && freq <= input) { + *output = j; + return 0; + } else if (!descend) { + if (freq <= input) + *output = (max_level - j); + else + return 0; + } + } else if (property == GET_LEVEL_CEIL) { + /* get maximum possible level by frequency */ + if (!descend && freq >= input) { + *output = (max_level - j); + return 0; + } else if (descend) { + if (freq >= input) + *output = j; + else + return 0; + } } j++; } @@ -227,6 +244,8 @@ static int get_property(unsigned int cpu, unsigned long input, * cpufreq_cooling_get_level - for a give cpu, return the cooling level. * @cpu: cpu for which the level is required * @freq: the frequency of interest + * @property: can be GET_LEVEL_CEIL, GET_LEVEL_FLOOR, GET_LEVEL_EXACT or + * GET_MAXL * * This function will match the cooling level corresponding to the * requested @freq and return it. @@ -234,11 +253,12 @@ static int get_property(unsigned int cpu, unsigned long input, * Return: The matched cooling level on success or THERMAL_CSTATE_INVALID * otherwise. */ -unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) +unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq, + enum cpufreq_cooling_property property) { unsigned int val; - if (get_property(cpu, (unsigned long)freq, &val, GET_LEVEL)) + if (get_property(cpu, (unsigned long)freq, &val, property)) return THERMAL_CSTATE_INVALID; return (unsigned long)val; diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c index a7306fa..aa4696b 100644 --- a/drivers/thermal/samsung/exynos_thermal_common.c +++ b/drivers/thermal/samsung/exynos_thermal_common.c @@ -156,7 +156,8 @@ static int exynos_bind(struct thermal_zone_device *thermal, /* Bind the thermal zone to the cpufreq cooling device */ for (i = 0; i < tab_size; i++) { clip_data = (struct freq_clip_table *)&(tab_ptr[i]); - level = cpufreq_cooling_get_level(0, clip_data->freq_clip_max); + level = cpufreq_cooling_get_level(0, clip_data->freq_clip_max, + GET_LEVEL_EXACT); if (level == THERMAL_CSTATE_INVALID) return 0; switch (GET_ZONE(i)) { diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h index f786935..f4d2b0e 100644 --- a/include/linux/cpu_cooling.h +++ b/include/linux/cpu_cooling.h @@ -44,6 +44,13 @@ struct cpufreq_cooling_status { void *devdata; }; +enum cpufreq_cooling_property { + GET_LEVEL_CEIL, + GET_LEVEL_FLOOR, + GET_LEVEL_EXACT, + GET_MAXL, +}; + #ifdef CONFIG_CPU_THERMAL /** * cpufreq_cooling_register - function to create cpufreq cooling device. @@ -77,7 +84,21 @@ of_cpufreq_cooling_register(struct device_node *np, */ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev); -unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq); +/** + * cpufreq_cooling_get_level - for a give cpu, return the cooling level. + * @cpu: cpu for which the level is required + * @freq: the frequency of interest + * @property: can be GET_LEVEL_CEIL, GET_LEVEL_FLOOR, GET_LEVEL_EXACT or + * GET_MAXL + * + * This function will match the cooling level corresponding to the + * requested @freq and return it. + * + * Return: The matched cooling level on success or THERMAL_CSTATE_INVALID + * otherwise. + */ +unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq, + enum cpufreq_cooling_property); /** * cpufreq_cooling_register_notifier - register a driver with cpufreq cooling.