From patchwork Thu May 29 08:15:32 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: 31103 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7D6E6203E6 for ; Thu, 29 May 2014 08:17:32 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id ma3sf57242517pbc.7 for ; Thu, 29 May 2014 01:17:32 -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=Qs7ejX1qO2H2+gN1Wa0YB7KO1/jfnEbRCgMkNweDKWk=; b=FFOGBP10kFRRZRFAQdPbcUMPikfXW0bTT/d8fi0m+lAuREKKWnyXD05JOzWsY46bb3 dU+1XRAY+9VXYbcYBXUYrwuWHZLLaymf5VJEb95UfgOAZgUnJoKjGo9waIor8YEHAsbd Ac7MNR0/Z+ye/32zJpm0g30s388cJcBPygonMxajYZPytvF69ZVR9U/X2xbXCpNnLXsO p22tysPN+aoLn0NihY1JhpMiIliaJ0cBXhAAGB8I8fPCR/bnMEptpdiBPlaFuvZuWQFT 9XW9vPK4ZxhS+aZIDX9JOKsUvzhol/20qLcUfrYFLD9JBdy4kqNcstWj/BHuVCmdEPKV 8Dsg== X-Gm-Message-State: ALoCoQlAemJ4W/lHPJiqpkzu21JFiTJep5kTe290CSRMm/jX6qP2K5LC5g76SsCv3aN0fs1EOh1B X-Received: by 10.66.169.231 with SMTP id ah7mr2427624pac.40.1401351452151; Thu, 29 May 2014 01:17:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.86.100 with SMTP id o91ls479496qgd.30.gmail; Thu, 29 May 2014 01:17:32 -0700 (PDT) X-Received: by 10.52.255.98 with SMTP id ap2mr4142980vdd.3.1401351451974; Thu, 29 May 2014 01:17:31 -0700 (PDT) Received: from mail-vc0-x234.google.com (mail-vc0-x234.google.com [2607:f8b0:400c:c03::234]) by mx.google.com with ESMTPS id u17si12668142vew.74.2014.05.29.01.17.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 May 2014 01:17:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::234 as permitted sender) client-ip=2607:f8b0:400c:c03::234; Received: by mail-vc0-f180.google.com with SMTP id hy4so13618962vcb.39 for ; Thu, 29 May 2014 01:17:31 -0700 (PDT) X-Received: by 10.221.51.77 with SMTP id vh13mr104712vcb.41.1401351451861; Thu, 29 May 2014 01:17:31 -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 ib8csp9535vcb; Thu, 29 May 2014 01:17:31 -0700 (PDT) X-Received: by 10.66.148.70 with SMTP id tq6mr6699951pab.56.1401351451098; Thu, 29 May 2014 01:17:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xc7si27399575pab.107.2014.05.29.01.17.30 for ; Thu, 29 May 2014 01:17:30 -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 S933892AbaE2IRV (ORCPT + 27 others); Thu, 29 May 2014 04:17:21 -0400 Received: from mail-pb0-f53.google.com ([209.85.160.53]:36106 "EHLO mail-pb0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932560AbaE2IQJ (ORCPT ); Thu, 29 May 2014 04:16:09 -0400 Received: by mail-pb0-f53.google.com with SMTP id md12so12608610pbc.12 for ; Thu, 29 May 2014 01:16:09 -0700 (PDT) X-Received: by 10.68.161.101 with SMTP id xr5mr6559824pbb.168.1401351369205; Thu, 29 May 2014 01:16:09 -0700 (PDT) Received: from localhost.localdomain ([14.140.216.146]) by mx.google.com with ESMTPSA id ee5sm5006897pbc.47.2014.05.29.01.16.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 29 May 2014 01:16:08 -0700 (PDT) From: Amit Daniel Kachhap To: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Zhang Rui , linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, edubezval@gmail.com, rjw@rjwysocki.net, linux-arm-kernel@lists.infradead.org, lenb@kernel.org Subject: [PATCH v1 4/6] thermal: cpu_cooling: Add support to find up/low frequency levels. Date: Thu, 29 May 2014 13:45:32 +0530 Message-Id: <1401351334-11210-5-git-send-email-amit.daniel@samsung.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1401351334-11210-1-git-send-email-amit.daniel@samsung.com> References: <1401351334-11210-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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::234 as permitted sender) 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 support 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 --- Documentation/thermal/cpu-cooling-api.txt | 15 +++++++++ drivers/thermal/cpu_cooling.c | 39 +++++++++++++++++------ drivers/thermal/samsung/exynos_thermal_common.c | 3 +- include/linux/cpu_cooling.h | 13 ++++++- 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/Documentation/thermal/cpu-cooling-api.txt b/Documentation/thermal/cpu-cooling-api.txt index aaa07c6..a1f93b8 100644 --- a/Documentation/thermal/cpu-cooling-api.txt +++ b/Documentation/thermal/cpu-cooling-api.txt @@ -31,3 +31,18 @@ the user. The registration APIs returns the cooling device pointer. This interface function unregisters the "thermal-cpufreq-%x" cooling device. cdev: Cooling device pointer which has to be unregistered. + +1.1.3 unsigned long cpufreq_cooling_get_level(unsigned int cpu, + unsigned int freq, enum cpufreq_cooling_property) + + This interface gets the frequency level for the absolute frequency by + matching in grequency table. + + cpu: cpu for which the frequency level is expected. + freq: absolute input frequency as found in cpu freq table. + cpufreq_cooling_property: + .GET_LEVEL_CEIL: returns the ceil of the frequency level. + .GET_LEVEL_FLOOR: returns the floor of the frequency level. + .GET_LEVEL_EXACT: returns the exact frequency level if found. + .GET_MAXL: returns the max frequency level. + diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 6d145d5..4ce8803 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -120,11 +120,7 @@ cpufreq_cooling_get_info(struct thermal_cooling_device *cdev) return cpufreq_dev; } -enum cpufreq_cooling_property { - GET_LEVEL, - GET_FREQ, - GET_MAXL, -}; +#define GET_FREQ (sizeof(enum cpufreq_cooling_property) + 1) /** * get_property - fetch a property of interest for a give cpu. @@ -207,15 +203,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++; } @@ -234,11 +252,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 aaef7d8..dba52c9 100644 --- a/include/linux/cpu_cooling.h +++ b/include/linux/cpu_cooling.h @@ -28,6 +28,13 @@ #include #include +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. @@ -61,7 +68,8 @@ 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); +unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq, + enum cpufreq_cooling_property); #else /* !CONFIG_CPU_THERMAL */ static inline struct thermal_cooling_device * cpufreq_cooling_register(const struct cpumask *clip_cpus, void *devdata) @@ -80,7 +88,8 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) return; } static inline -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) { return THERMAL_CSTATE_INVALID; }