arm: tegra: power: Tegra Thermal refactoring
Joshua Primero [Fri, 14 Oct 2011 00:49:20 +0000 (17:49 -0700)]
Refactored Thermal module so that thermal device
drivers themselves are agnostic of the thermal
framework.  Also separated throttle limit constraints
from EDP table.

Reviewed-on: http://git-master/r/57990
Reviewed-on: http://git-master/r/63338

Cherry-picked from 8d0610bdd03c3490b718f11bc2108f45cd868533.

Change-Id: I4f87889c9cdc88daac1e6173043bab1f2e7cebfd
Signed-off-by: Joshua Primero <jprimero@nvidia.com>
Reviewed-on: http://git-master/r/66551
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

Rebase-Id: R48ab4360228620638d8e2af6b27f6d0edcaa4b93

arch/arm/mach-tegra/board-cardhu-sensors.c
arch/arm/mach-tegra/board-cardhu.c
arch/arm/mach-tegra/board-cardhu.h

index 45fedd8..c512821 100644 (file)
@@ -51,6 +51,7 @@
 #include <linux/bq27x00.h>
 #include <mach/gpio.h>
 #include <mach/edp.h>
+#include <mach/thermal.h>
 
 #include "gpio-names.h"
 #include "board-cardhu.h"
@@ -569,6 +570,58 @@ static struct i2c_board_info cardhu_i2c8_board_info[] = {
        },
 };
 
+#ifndef CONFIG_TEGRA_INTERNAL_TSENSOR_EDP_SUPPORT
+static int nct_get_temp(void *_data, long *temp)
+{
+       struct nct1008_data *data = _data;
+       return nct1008_thermal_get_temp(data, temp);
+}
+
+static int nct_set_limits(void *_data,
+                       long lo_limit_milli,
+                       long hi_limit_milli)
+{
+       struct nct1008_data *data = _data;
+       return nct1008_thermal_set_limits(data,
+                                       lo_limit_milli,
+                                       hi_limit_milli);
+}
+
+static int nct_set_alert(void *_data,
+                               void (*alert_func)(void *),
+                               void *alert_data)
+{
+       struct nct1008_data *data = _data;
+       return nct1008_thermal_set_alert(data, alert_func, alert_data);
+}
+
+static int nct_set_shutdown_temp(void *_data, long shutdown_temp)
+{
+       struct nct1008_data *data = _data;
+       return nct1008_thermal_set_shutdown_temp(data, shutdown_temp);
+}
+static void nct1008_probe_callback(struct nct1008_data *data)
+{
+       struct tegra_thermal_device *thermal_device;
+
+       thermal_device = kzalloc(sizeof(struct tegra_thermal_device),
+                                       GFP_KERNEL);
+       if (!thermal_device) {
+               pr_err("unable to allocate thermal device\n");
+               return;
+       }
+
+       thermal_device->data = data;
+       thermal_device->offset = TDIODE_OFFSET;
+       thermal_device->get_temp = nct_get_temp;
+       thermal_device->set_limits = nct_set_limits;
+       thermal_device->set_alert = nct_set_alert;
+       thermal_device->set_shutdown_temp = nct_set_shutdown_temp;
+
+       tegra_thermal_set_device(thermal_device);
+}
+#endif
+
 static struct nct1008_platform_data cardhu_nct1008_pdata = {
        .supported_hwrev = true,
        .ext_range = true,
@@ -579,6 +632,9 @@ static struct nct1008_platform_data cardhu_nct1008_pdata = {
        .shutdown_local_limit = 90,
        .throttling_ext_limit = 85,
        .alarm_fn = tegra_throttling_enable,
+#ifndef CONFIG_TEGRA_INTERNAL_TSENSOR_EDP_SUPPORT
+       .probe_callback = nct1008_probe_callback,
+#endif
 };
 
 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
@@ -595,7 +651,6 @@ static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
        }
 };
 
-
 static int cardhu_nct1008_init(void)
 {
        int nct1008_port = -1;
index da4b14c..bc9b49f 100644 (file)
@@ -52,6 +52,7 @@
 #include <asm/mach/arch.h>
 #include <mach/usb_phy.h>
 #include <linux/nfc/pn544.h>
+#include <mach/thermal.h>
 
 #include "board.h"
 #include "clock.h"
 #include "pm.h"
 #include "baseband-xmm-power.h"
 
+/* All units are in millicelsius */
+static struct tegra_thermal_data thermal_data = {
+       .temp_throttle = 85000,
+       .temp_shutdown = 90000,
+       .temp_offset = TDIODE_OFFSET, /* temps based on tdiode */
+       .edp_offset = TDIODE_OFFSET,  /* edp based on tdiode */
+#ifndef CONFIG_TEGRA_THERMAL_SYSFS
+       .hysteresis_throttle = 1000,
+#endif
+       .hysteresis_edp = 3000,
+};
 
 /* !!!TODO: Change for cardhu (Taken from Ventana) */
 static struct tegra_utmip_config utmi_phy_config[] = {
@@ -893,6 +905,7 @@ static void cardhu_sata_init(void) { }
 
 static void __init tegra_cardhu_init(void)
 {
+       tegra_thermal_init(&thermal_data);
        tegra_clk_init_from_table(cardhu_clk_init_table);
        cardhu_pinmux_init();
        cardhu_i2c_init();
index 15641a0..5c8dcb4 100644 (file)
@@ -226,4 +226,6 @@ void __init cardhu_tsensor_init(void);
 #define XMM_GPIO_IPC_BB_WAKE           BB_GPIO_AWR
 #define XMM_GPIO_IPC_AP_WAKE           BB_GPIO_CWR
 
+#define TDIODE_OFFSET  (10000) /* in millicelsius */
+
 #endif