exynos_tmu.c (8131a246600f0c34a71cbe1a2e4a19af7e9bc887) | exynos_tmu.c (ddb31d43cb20222f929b0d242bdb516de51b6c23) |
---|---|
1/* 2 * exynos_tmu.c - Samsung EXYNOS TMU (Thermal Management Unit) 3 * 4 * Copyright (C) 2011 Samsung Electronics 5 * Donggeun Kim <dg77.kim@samsung.com> 6 * Amit Daniel Kachhap <amit.kachhap@linaro.org> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 63 unchanged lines hidden (view full) --- 72 * TMU treats temperature as a mapped temperature code. 73 * The temperature is converted differently depending on the calibration type. 74 */ 75static int temp_to_code(struct exynos_tmu_data *data, u8 temp) 76{ 77 struct exynos_tmu_platform_data *pdata = data->pdata; 78 int temp_code; 79 | 1/* 2 * exynos_tmu.c - Samsung EXYNOS TMU (Thermal Management Unit) 3 * 4 * Copyright (C) 2011 Samsung Electronics 5 * Donggeun Kim <dg77.kim@samsung.com> 6 * Amit Daniel Kachhap <amit.kachhap@linaro.org> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 63 unchanged lines hidden (view full) --- 72 * TMU treats temperature as a mapped temperature code. 73 * The temperature is converted differently depending on the calibration type. 74 */ 75static int temp_to_code(struct exynos_tmu_data *data, u8 temp) 76{ 77 struct exynos_tmu_platform_data *pdata = data->pdata; 78 int temp_code; 79 |
80 if (data->soc == SOC_ARCH_EXYNOS4210) 81 /* temp should range between 25 and 125 */ 82 if (temp < 25 || temp > 125) { 83 temp_code = -EINVAL; 84 goto out; 85 } 86 | |
87 switch (pdata->cal_type) { 88 case TYPE_TWO_POINT_TRIMMING: 89 temp_code = (temp - pdata->first_point_trim) * 90 (data->temp_error2 - data->temp_error1) / 91 (pdata->second_point_trim - pdata->first_point_trim) + 92 data->temp_error1; 93 break; 94 case TYPE_ONE_POINT_TRIMMING: 95 temp_code = temp + data->temp_error1 - pdata->first_point_trim; 96 break; 97 default: 98 temp_code = temp + pdata->default_temp_offset; 99 break; 100 } | 80 switch (pdata->cal_type) { 81 case TYPE_TWO_POINT_TRIMMING: 82 temp_code = (temp - pdata->first_point_trim) * 83 (data->temp_error2 - data->temp_error1) / 84 (pdata->second_point_trim - pdata->first_point_trim) + 85 data->temp_error1; 86 break; 87 case TYPE_ONE_POINT_TRIMMING: 88 temp_code = temp + data->temp_error1 - pdata->first_point_trim; 89 break; 90 default: 91 temp_code = temp + pdata->default_temp_offset; 92 break; 93 } |
101out: | 94 |
102 return temp_code; 103} 104 105/* 106 * Calculate a temperature value from a temperature code. 107 * The unit of the temperature is degree Celsius. 108 */ 109static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code) 110{ 111 struct exynos_tmu_platform_data *pdata = data->pdata; 112 int temp; 113 | 95 return temp_code; 96} 97 98/* 99 * Calculate a temperature value from a temperature code. 100 * The unit of the temperature is degree Celsius. 101 */ 102static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code) 103{ 104 struct exynos_tmu_platform_data *pdata = data->pdata; 105 int temp; 106 |
114 if (data->soc == SOC_ARCH_EXYNOS4210) 115 /* temp_code should range between 75 and 175 */ 116 if (temp_code < 75 || temp_code > 175) { 117 temp = -ENODATA; 118 goto out; 119 } 120 | |
121 switch (pdata->cal_type) { 122 case TYPE_TWO_POINT_TRIMMING: 123 temp = (temp_code - data->temp_error1) * 124 (pdata->second_point_trim - pdata->first_point_trim) / 125 (data->temp_error2 - data->temp_error1) + 126 pdata->first_point_trim; 127 break; 128 case TYPE_ONE_POINT_TRIMMING: 129 temp = temp_code - data->temp_error1 + pdata->first_point_trim; 130 break; 131 default: 132 temp = temp_code - pdata->default_temp_offset; 133 break; 134 } | 107 switch (pdata->cal_type) { 108 case TYPE_TWO_POINT_TRIMMING: 109 temp = (temp_code - data->temp_error1) * 110 (pdata->second_point_trim - pdata->first_point_trim) / 111 (data->temp_error2 - data->temp_error1) + 112 pdata->first_point_trim; 113 break; 114 case TYPE_ONE_POINT_TRIMMING: 115 temp = temp_code - data->temp_error1 + pdata->first_point_trim; 116 break; 117 default: 118 temp = temp_code - pdata->default_temp_offset; 119 break; 120 } |
135out: | 121 |
136 return temp; 137} 138 139static int exynos_tmu_initialize(struct platform_device *pdev) 140{ 141 struct exynos_tmu_data *data = platform_get_drvdata(pdev); 142 struct exynos_tmu_platform_data *pdata = data->pdata; 143 const struct exynos_tmu_registers *reg = pdata->registers; --- 197 unchanged lines hidden (view full) --- 341 const struct exynos_tmu_registers *reg = pdata->registers; 342 u8 temp_code; 343 int temp; 344 345 mutex_lock(&data->lock); 346 clk_enable(data->clk); 347 348 temp_code = readb(data->base + reg->tmu_cur_temp); | 122 return temp; 123} 124 125static int exynos_tmu_initialize(struct platform_device *pdev) 126{ 127 struct exynos_tmu_data *data = platform_get_drvdata(pdev); 128 struct exynos_tmu_platform_data *pdata = data->pdata; 129 const struct exynos_tmu_registers *reg = pdata->registers; --- 197 unchanged lines hidden (view full) --- 327 const struct exynos_tmu_registers *reg = pdata->registers; 328 u8 temp_code; 329 int temp; 330 331 mutex_lock(&data->lock); 332 clk_enable(data->clk); 333 334 temp_code = readb(data->base + reg->tmu_cur_temp); |
349 temp = code_to_temp(data, temp_code); | |
350 | 335 |
336 if (data->soc == SOC_ARCH_EXYNOS4210) 337 /* temp_code should range between 75 and 175 */ 338 if (temp_code < 75 || temp_code > 175) { 339 temp = -ENODATA; 340 goto out; 341 } 342 343 temp = code_to_temp(data, temp_code); 344out: |
|
351 clk_disable(data->clk); 352 mutex_unlock(&data->lock); 353 354 return temp; 355} 356 357#ifdef CONFIG_THERMAL_EMULATION 358static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) --- 406 unchanged lines hidden --- | 345 clk_disable(data->clk); 346 mutex_unlock(&data->lock); 347 348 return temp; 349} 350 351#ifdef CONFIG_THERMAL_EMULATION 352static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) --- 406 unchanged lines hidden --- |