From 3e5d6cb230ef01212e9fc6946af19f7a49ef9b04 Mon Sep 17 00:00:00 2001 From: "huan.biao" Date: Thu, 8 Feb 2018 14:32:18 +0800 Subject: [PATCH] thermal: G12A: update thermal driver. PD#156734: tsensor: update temp to reg calc. cooldev: add cpufreq driver check. Change-Id: I534716247908dd066c6dd8fe1680f977c5972b5a Signed-off-by: huan.biao --- drivers/amlogic/thermal/meson_cooldev.c | 8 ++++++++ drivers/amlogic/thermal/meson_tsensor.c | 18 +++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/amlogic/thermal/meson_cooldev.c b/drivers/amlogic/thermal/meson_cooldev.c index 66c53834bb28..e89578cd8f43 100644 --- a/drivers/amlogic/thermal/meson_cooldev.c +++ b/drivers/amlogic/thermal/meson_cooldev.c @@ -310,6 +310,7 @@ static int meson_cooldev_probe(struct platform_device *pdev) int cpu, i, c_id; struct cool_dev *cool; struct meson_cooldev *mcooldev; + struct cpufreq_policy *policy; pr_info("meson_cdev probe\n"); mcooldev = devm_kzalloc(&pdev->dev, sizeof(struct meson_cooldev), @@ -319,6 +320,13 @@ static int meson_cooldev_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mcooldev); mutex_init(&mcooldev->lock); + policy = cpufreq_cpu_get(0); + if (!policy || !policy->freq_table) { + dev_info(&pdev->dev, + "Frequency policy not init. Deferring probe...\n"); + return -EPROBE_DEFER; + } + for_each_possible_cpu(cpu) { if (mc_capable()) c_id = topology_physical_package_id(cpu); diff --git a/drivers/amlogic/thermal/meson_tsensor.c b/drivers/amlogic/thermal/meson_tsensor.c index b343759fb22e..d08a5eab0ac9 100644 --- a/drivers/amlogic/thermal/meson_tsensor.c +++ b/drivers/amlogic/thermal/meson_tsensor.c @@ -98,7 +98,7 @@ #define MCELSIUS 1000 #define MAX_TS_NUM 3 #define TS_DEF_RTEMP 125 - +#define TEMP_CAL 1 enum soc_type { SOC_ARCH_TS_R1P0 = 1, @@ -212,7 +212,7 @@ static void meson_report_trigger(struct meson_tsensor_data *p) * tsensor treats temperature as a mapped temperature code. * The temperature is converted differently depending on the calibration type. */ -static u32 temp_to_code(struct meson_tsensor_data *data, int temp) +static u32 temp_to_code(struct meson_tsensor_data *data, int temp, bool trend) { struct meson_tsensor_platform_data *pdata = data->pdata; long long int sensor_code; @@ -242,7 +242,11 @@ static u32 temp_to_code(struct meson_tsensor_data *data, int temp) } sensor_code = (sensor_code * 100 / (cal_b - cal_a * sensor_code / (1 << 16))); - reg_code = (sensor_code >> 0x4) & R1P1_TS_TEMP_MASK; + if (trend) + reg_code = ((sensor_code >> 0x4) & R1P1_TS_TEMP_MASK) + + TEMP_CAL; + else + reg_code = ((sensor_code >> 0x4) & R1P1_TS_TEMP_MASK) break; default: pr_info("Cal_type not supported\n"); @@ -378,7 +382,7 @@ static int r1p1_tsensor_initialize(struct platform_device *pdev) /*r1p1 init the ts reboot soc function*/ reboot_temp = pdata->reboot_temp; - reboot_reg = temp_to_code(data, reboot_temp / MCELSIUS); + reboot_reg = temp_to_code(data, reboot_temp / MCELSIUS, true); con = (readl(data->base_c + R1P1_TS_CFG_REG2) | (reboot_reg << 4)); con |= (R1P1_TS_HITEMP_EN | R1P1_TS_REBOOT_ALL_EN); con |= (R1P1_TS_REBOOT_TIME); @@ -416,7 +420,7 @@ static int r1p1_tsensor_initialize(struct platform_device *pdev) temp_hist = temp - (temp_hist / MCELSIUS); /* Set 12-bit temperature code for rising threshold levels */ - threshold_code = temp_to_code(data, temp); + threshold_code = temp_to_code(data, temp, true); rising_threshold = readl(data->base_c + R1P1_TS_CFG_REG4 + reg_off); rising_threshold &= ~(R1P1_TS_TEMP_MASK << (12 * bit_off)); @@ -425,7 +429,7 @@ static int r1p1_tsensor_initialize(struct platform_device *pdev) data->base_c + R1P1_TS_CFG_REG4 + reg_off); /* Set 12-bit temperature code for falling threshold levels */ - threshold_code = temp_to_code(data, temp_hist); + threshold_code = temp_to_code(data, temp_hist, false); falling_threshold = readl(data->base_c + R1P1_TS_CFG_REG6 + reg_off); falling_threshold &= ~(R1P1_TS_TEMP_MASK << (12 * bit_off)); @@ -493,7 +497,7 @@ static void r1p1_tsensor_update_irqs(struct meson_tsensor_data *data) /* Find the level for which trip happened */ for (i = 0; i < of_thermal_get_ntrips(tz); i++) { tz->ops->get_trip_temp(tz, i, &temp); - if (tz->last_temperature < (temp - 1000)) + if (tz->last_temperature < temp) break; }