From patchwork Tue Jun 25 11:39:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kachhap X-Patchwork-Id: 2776121 Return-Path: X-Original-To: patchwork-linux-samsung-soc@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 0463FC0AB1 for ; Tue, 25 Jun 2013 11:39:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 02FAA201CD for ; Tue, 25 Jun 2013 11:39:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97062201D6 for ; Tue, 25 Jun 2013 11:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751261Ab3FYLjk (ORCPT ); Tue, 25 Jun 2013 07:39:40 -0400 Received: from mail-pb0-f48.google.com ([209.85.160.48]:42878 "EHLO mail-pb0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750864Ab3FYLjj (ORCPT ); Tue, 25 Jun 2013 07:39:39 -0400 Received: by mail-pb0-f48.google.com with SMTP id ma3so12372519pbc.7 for ; Tue, 25 Jun 2013 04:39:38 -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=c1FZnhYldPCkrXcv9iSVKGqcQGbWc4B2NuGXktsDDh0=; b=k/NSNp9PNajyQ/OlZmUtPoDt5AEyou32BH2ZrdzHjzxv8tWWiTZNimGx8RpmwpUSRQ Atf1Y11tm6N2hIyKaaReeyXiM59iT9rvRUfbdEb4NUGGP/cPsLBOie6yG7f8dTsZYgTy OeVGmRfN0BauHuuiHCxwBxOFliFkcwTJ0eQvHpLgDTdAyEDj1989+rns/DzDTyGfxS3s /qFOqKyJ1rOK8QN3/HBRvAgS8LDTLLZpKKOHWpf5K9IJyI+QeGuvLd3yRP3VMvuGY7x/ +C6PvpIeCXwHwkt1F910OaxPhXUvYsmfyeo6VJ7vB8RNLdfI7IWWjq8ICEjUBy3abJEM 1xHQ== X-Received: by 10.66.178.174 with SMTP id cz14mr4637799pac.136.1372160378603; Tue, 25 Jun 2013 04:39:38 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPSA id p2sm24785455pag.22.2013.06.25.04.39.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 25 Jun 2013 04:39:37 -0700 (PDT) From: Amit Daniel Kachhap To: linux-pm@vger.kernel.org, Zhang Rui , Eduardo Valentin Cc: linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, Kukjin Kim Subject: [PATCH RESEND V7 16/30] thermal: exynos: Make the zone handling use trip information Date: Tue, 25 Jun 2013 17:09:19 +0530 Message-Id: <1372160359-14504-1-git-send-email-amit.daniel@samsung.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1372071051-3167-17-git-send-email-amit.daniel@samsung.com> References: <1372071051-3167-17-git-send-email-amit.daniel@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 code simplifies the zone handling to use the trip information passed by the TMU driver and not the hardcoded macros. This also helps in adding more zone support. Acked-by: Kukjin Kim Acked-by: Jonghwa Lee Signed-off-by: Amit Daniel Kachhap Acked-by: Eduardo Valentin --- drivers/thermal/samsung/exynos_thermal_common.c | 67 ++++++++++++++--------- drivers/thermal/samsung/exynos_thermal_common.h | 3 +- drivers/thermal/samsung/exynos_tmu.c | 5 ++- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c index 99318e5..ecf95da 100644 --- a/drivers/thermal/samsung/exynos_thermal_common.c +++ b/drivers/thermal/samsung/exynos_thermal_common.c @@ -79,17 +79,24 @@ static int exynos_set_mode(struct thermal_zone_device *thermal, static int exynos_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { - switch (GET_ZONE(trip)) { - case MONITOR_ZONE: - case WARN_ZONE: - *type = THERMAL_TRIP_ACTIVE; - break; - case PANIC_ZONE: + struct exynos_thermal_zone *th_zone = thermal->devdata; + int max_trip = th_zone->sensor_conf->trip_data.trip_count; + int trip_type; + + if (trip < 0 || trip >= max_trip) + return -EINVAL; + + trip_type = th_zone->sensor_conf->trip_data.trip_type[trip]; + + if (trip_type == SW_TRIP) *type = THERMAL_TRIP_CRITICAL; - break; - default: + else if (trip_type == THROTTLE_ACTIVE) + *type = THERMAL_TRIP_ACTIVE; + else if (trip_type == THROTTLE_PASSIVE) + *type = THERMAL_TRIP_PASSIVE; + else return -EINVAL; - } + return 0; } @@ -98,8 +105,9 @@ static int exynos_get_trip_temp(struct thermal_zone_device *thermal, int trip, unsigned long *temp) { struct exynos_thermal_zone *th_zone = thermal->devdata; + int max_trip = th_zone->sensor_conf->trip_data.trip_count; - if (trip < GET_TRIP(MONITOR_ZONE) || trip > GET_TRIP(PANIC_ZONE)) + if (trip < 0 || trip >= max_trip) return -EINVAL; *temp = th_zone->sensor_conf->trip_data.trip_val[trip]; @@ -113,10 +121,10 @@ static int exynos_get_trip_temp(struct thermal_zone_device *thermal, int trip, static int exynos_get_crit_temp(struct thermal_zone_device *thermal, unsigned long *temp) { - int ret; - /* Panic zone */ - ret = exynos_get_trip_temp(thermal, GET_TRIP(PANIC_ZONE), temp); - return ret; + struct exynos_thermal_zone *th_zone = thermal->devdata; + int max_trip = th_zone->sensor_conf->trip_data.trip_count; + /* Get the temp of highest trip*/ + return exynos_get_trip_temp(thermal, max_trip - 1, temp); } /* Bind callback functions for thermal zone */ @@ -348,19 +356,28 @@ int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf) return -ENOMEM; th_zone->sensor_conf = sensor_conf; - cpumask_set_cpu(0, &mask_val); - th_zone->cool_dev[0] = cpufreq_cooling_register(&mask_val); - if (IS_ERR(th_zone->cool_dev[0])) { - pr_err("Failed to register cpufreq cooling device\n"); - ret = -EINVAL; - goto err_unregister; + /* + * TODO: 1) Handle multiple cooling devices in a thermal zone + * 2) Add a flag/name in cooling info to map to specific + * sensor + */ + if (sensor_conf->cooling_data.freq_clip_count > 0) { + cpumask_set_cpu(0, &mask_val); + th_zone->cool_dev[th_zone->cool_dev_size] = + cpufreq_cooling_register(&mask_val); + if (IS_ERR(th_zone->cool_dev[th_zone->cool_dev_size])) { + pr_err("Failed to register cpufreq cooling device\n"); + ret = -EINVAL; + goto err_unregister; + } + th_zone->cool_dev_size++; } - th_zone->cool_dev_size++; - th_zone->therm_dev = thermal_zone_device_register(sensor_conf->name, - EXYNOS_ZONE_COUNT, 0, th_zone, &exynos_dev_ops, NULL, 0, - sensor_conf->trip_data.trigger_falling ? - 0 : IDLE_INTERVAL); + th_zone->therm_dev = thermal_zone_device_register( + sensor_conf->name, sensor_conf->trip_data.trip_count, + 0, th_zone, &exynos_dev_ops, NULL, 0, + sensor_conf->trip_data.trigger_falling ? 0 : + IDLE_INTERVAL); if (IS_ERR(th_zone->therm_dev)) { pr_err("Failed to register thermal zone device\n"); diff --git a/drivers/thermal/samsung/exynos_thermal_common.h b/drivers/thermal/samsung/exynos_thermal_common.h index 6ca3096..bfcf69e 100644 --- a/drivers/thermal/samsung/exynos_thermal_common.h +++ b/drivers/thermal/samsung/exynos_thermal_common.h @@ -42,8 +42,6 @@ #define GET_ZONE(trip) (trip + 2) #define GET_TRIP(zone) (zone - 2) -#define EXYNOS_ZONE_COUNT 3 - enum trigger_type { THROTTLE_ACTIVE = 1, THROTTLE_PASSIVE, @@ -69,6 +67,7 @@ struct freq_clip_table { struct thermal_trip_point_conf { int trip_val[MAX_TRIP_COUNT]; + int trip_type[MAX_TRIP_COUNT]; int trip_count; unsigned char trigger_falling; }; diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index 40e0cfd..acbd295 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -509,9 +509,12 @@ static int exynos_tmu_probe(struct platform_device *pdev) pdata->trigger_enable[1] + pdata->trigger_enable[2]+ pdata->trigger_enable[3]; - for (i = 0; i < exynos_sensor_conf.trip_data.trip_count; i++) + for (i = 0; i < exynos_sensor_conf.trip_data.trip_count; i++) { exynos_sensor_conf.trip_data.trip_val[i] = pdata->threshold + pdata->trigger_levels[i]; + exynos_sensor_conf.trip_data.trip_type[i] = + pdata->trigger_type[i]; + } exynos_sensor_conf.trip_data.trigger_falling = pdata->threshold_falling;