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 Kachhap X-Patchwork-Id: 4136861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 124BFBFF02 for ; Thu, 8 May 2014 14:40:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2869A20270 for ; Thu, 8 May 2014 14:40:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A250A20279 for ; Thu, 8 May 2014 14:40:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WiPT0-0001Fi-9D; Thu, 08 May 2014 14:38:34 +0000 Received: from mail-pa0-x22b.google.com ([2607:f8b0:400e:c03::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WiPSm-00011Y-OI for linux-arm-kernel@lists.infradead.org; Thu, 08 May 2014 14:38:21 +0000 Received: by mail-pa0-f43.google.com with SMTP id hz1so2973678pad.30 for ; Thu, 08 May 2014 07:37:59 -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:in-reply-to:references; bh=MrO+1G+s5e+gIrfm6fjbvNwyKtVcsCIYHK9S6iCi5Iw=; b=bMnYBlBAHto3CD0zzsTPxULIxW9fcdTqgiFLhVV2pxH6rVaBqZMXfzvjU79xAkgyr0 epRtiJDF2dcmtZKwVIx8grCHpN/igdpiJCoR0/7UfGFwsZVlZN0Vj5wHjEIKgJSDSkJE lFoczurpq7mLBKuihw7y0FHDhYq21Til/aA5vdkAo2gNCQCsrfNAD1A59CL2SxxP7NT9 oqTFuWNC//jFzwV2PuB6sqQS2nUj5M3+4ixrN7oeRImhQ5ZxoofdXwsGCL0qtmcd5Ysh Jn7dCjebMQ7VEe6AivtfQpGRzO5G3d/2wf8hqgbM7L6Eow9dWqLdnnTc7Zab5ttqFSsF T9yQ== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140508_073820_850159_860D0F38 X-CRM114-Status: GOOD ( 19.61 ) X-Spam-Score: 0.0 (/) Cc: eduardo.valentin@ti.com, rui.zhang@intel.com, rjw@rjwysocki.net, lenb@kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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.