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 Kachhap X-Patchwork-Id: 4262961 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D12BD9F333 for ; Thu, 29 May 2014 08:18:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D74522034A for ; Thu, 29 May 2014 08:18:50 +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 D3961200C1 for ; Thu, 29 May 2014 08:18:49 +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 1WpvWN-000601-Am; Thu, 29 May 2014 08:17:07 +0000 Received: from mail-pa0-x22d.google.com ([2607:f8b0:400e:c03::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WpvVm-0005dp-Bs for linux-arm-kernel@lists.infradead.org; Thu, 29 May 2014 08:16:31 +0000 Received: by mail-pa0-f45.google.com with SMTP id ey11so12441641pad.18 for ; Thu, 29 May 2014 01:16: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:in-reply-to:references; bh=cZAVmFmjsuh8m0Ycy5t8yJHMPKTgsBmuZgwQ0wihFWM=; b=CnJMvK3iSZKjkFqkLa+a7w6wSdRDXBhEUmhM1c83IZ79KiEHcgReScR2+DWwcX19NN IbxUQs/yj2pgtH1V3b73N+xyYUTmGI5zeVmWxPyityyurvmiUfir/MadlHmyqIzGm994 jifyUxQkYn9pU9ZmXkk8+uhdejOFAaXOZPCJJUZJ19qNUVXlRKa8ZQTx/BXkGGW8x0r2 c+ldYrFyTg0XobMNeX/c7mwAJGVQyToPdp3XIX1nlXcO1qylOxi9o/1keMaRS2CPCcFn sQ3UOpAQmwPk4eyg6m8+3Mux2T/5Kd+Z5KACCkouGnM+3zmCNvHZBpsXAa3IG0cCShrA MUuA== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140529_011630_467440_074B2FF9 X-CRM114-Status: GOOD ( 19.81 ) X-Spam-Score: 0.0 (/) Cc: amit.kachhap@gmail.com, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, edubezval@gmail.com, Zhang Rui , linux-arm-kernel@lists.infradead.org, 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 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; }