Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 3 | * http://www.samsung.com |
| 4 | * Akshay Saraswat <akshay.s@samsung.com> |
| 5 | * |
| 6 | * EXYNOS - Thermal Management Unit |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 17 | * MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | #include <common.h> |
| 21 | #include <errno.h> |
| 22 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 23 | #include <log.h> |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 24 | #include <tmu.h> |
| 25 | #include <asm/arch/tmu.h> |
Akshay Saraswat | b9fa8c1 | 2013-02-25 01:13:06 +0000 | [diff] [blame] | 26 | #include <asm/arch/power.h> |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 27 | |
| 28 | #define TRIMINFO_RELOAD 1 |
| 29 | #define CORE_EN 1 |
Akshay Saraswat | b9fa8c1 | 2013-02-25 01:13:06 +0000 | [diff] [blame] | 30 | #define THERM_TRIP_EN (1 << 12) |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 31 | |
| 32 | #define INTEN_RISE0 1 |
| 33 | #define INTEN_RISE1 (1 << 4) |
| 34 | #define INTEN_RISE2 (1 << 8) |
| 35 | #define INTEN_FALL0 (1 << 16) |
| 36 | #define INTEN_FALL1 (1 << 20) |
| 37 | #define INTEN_FALL2 (1 << 24) |
| 38 | |
| 39 | #define TRIM_INFO_MASK 0xff |
| 40 | |
| 41 | #define INTCLEAR_RISE0 1 |
| 42 | #define INTCLEAR_RISE1 (1 << 4) |
| 43 | #define INTCLEAR_RISE2 (1 << 8) |
| 44 | #define INTCLEAR_FALL0 (1 << 16) |
| 45 | #define INTCLEAR_FALL1 (1 << 20) |
| 46 | #define INTCLEAR_FALL2 (1 << 24) |
| 47 | #define INTCLEARALL (INTCLEAR_RISE0 | INTCLEAR_RISE1 | \ |
| 48 | INTCLEAR_RISE2 | INTCLEAR_FALL0 | \ |
| 49 | INTCLEAR_FALL1 | INTCLEAR_FALL2) |
| 50 | |
| 51 | /* Tmeperature threshold values for various thermal events */ |
| 52 | struct temperature_params { |
| 53 | /* minimum value in temperature code range */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 54 | unsigned min_val; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 55 | /* maximum value in temperature code range */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 56 | unsigned max_val; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 57 | /* temperature threshold to start warning */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 58 | unsigned start_warning; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 59 | /* temperature threshold CPU tripping */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 60 | unsigned start_tripping; |
Akshay Saraswat | b9fa8c1 | 2013-02-25 01:13:06 +0000 | [diff] [blame] | 61 | /* temperature threshold for HW tripping */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 62 | unsigned hardware_tripping; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /* Pre-defined values and thresholds for calibration of current temperature */ |
| 66 | struct tmu_data { |
| 67 | /* pre-defined temperature thresholds */ |
| 68 | struct temperature_params ts; |
| 69 | /* pre-defined efuse range minimum value */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 70 | unsigned efuse_min_value; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 71 | /* pre-defined efuse value for temperature calibration */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 72 | unsigned efuse_value; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 73 | /* pre-defined efuse range maximum value */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 74 | unsigned efuse_max_value; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 75 | /* current temperature sensing slope */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 76 | unsigned slope; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /* TMU device specific details and status */ |
| 80 | struct tmu_info { |
| 81 | /* base Address for the TMU */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 82 | struct exynos5_tmu_reg *tmu_base; |
Naveen Krishna Chatradhi | b3d364f | 2013-04-05 15:21:39 -0700 | [diff] [blame] | 83 | /* mux Address for the TMU */ |
| 84 | int tmu_mux; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 85 | /* pre-defined values for calibration and thresholds */ |
| 86 | struct tmu_data data; |
| 87 | /* value required for triminfo_25 calibration */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 88 | unsigned te1; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 89 | /* value required for triminfo_85 calibration */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 90 | unsigned te2; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 91 | /* Value for measured data calibration */ |
| 92 | int dc_value; |
| 93 | /* enum value indicating status of the TMU */ |
| 94 | int tmu_state; |
| 95 | }; |
| 96 | |
| 97 | /* Global struct tmu_info variable to store init values */ |
| 98 | static struct tmu_info gbl_info; |
| 99 | |
| 100 | /* |
| 101 | * Get current temperature code from register, |
| 102 | * then calculate and calibrate it's value |
| 103 | * in degree celsius. |
| 104 | * |
| 105 | * @return current temperature of the chip as sensed by TMU |
| 106 | */ |
| 107 | static int get_cur_temp(struct tmu_info *info) |
| 108 | { |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 109 | struct exynos5_tmu_reg *reg = info->tmu_base; |
| 110 | ulong start; |
| 111 | int cur_temp = 0; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * Temperature code range between min 25 and max 125. |
| 115 | * May run more than once for first call as initial sensing |
| 116 | * has not yet happened. |
| 117 | */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 118 | if (info->tmu_state == TMU_STATUS_NORMAL) { |
| 119 | start = get_timer(0); |
| 120 | do { |
| 121 | cur_temp = readl(®->current_temp) & 0xff; |
| 122 | } while ((cur_temp == 0) || (get_timer(start) > 100)); |
| 123 | } |
| 124 | |
| 125 | if (cur_temp == 0) |
| 126 | return cur_temp; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 127 | |
| 128 | /* Calibrate current temperature */ |
| 129 | cur_temp = cur_temp - info->te1 + info->dc_value; |
| 130 | |
| 131 | return cur_temp; |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Monitors status of the TMU device and exynos temperature |
| 136 | * |
| 137 | * @param temp pointer to the current temperature value |
| 138 | * @return enum tmu_status_t value, code indicating event to execute |
| 139 | */ |
| 140 | enum tmu_status_t tmu_monitor(int *temp) |
| 141 | { |
| 142 | int cur_temp; |
| 143 | struct tmu_data *data = &gbl_info.data; |
| 144 | |
| 145 | if (gbl_info.tmu_state == TMU_STATUS_INIT) |
| 146 | return TMU_STATUS_INIT; |
| 147 | |
| 148 | /* Read current temperature of the SOC */ |
| 149 | cur_temp = get_cur_temp(&gbl_info); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 150 | |
| 151 | if (!cur_temp) |
| 152 | goto out; |
| 153 | |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 154 | *temp = cur_temp; |
| 155 | |
| 156 | /* Temperature code lies between min 25 and max 125 */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 157 | if ((cur_temp >= data->ts.start_tripping) && |
| 158 | (cur_temp <= data->ts.max_val)) |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 159 | return TMU_STATUS_TRIPPED; |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 160 | |
| 161 | if (cur_temp >= data->ts.start_warning) |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 162 | return TMU_STATUS_WARNING; |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 163 | |
| 164 | if ((cur_temp < data->ts.start_warning) && |
| 165 | (cur_temp >= data->ts.min_val)) |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 166 | return TMU_STATUS_NORMAL; |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 167 | |
| 168 | out: |
| 169 | /* Temperature code does not lie between min 25 and max 125 */ |
| 170 | gbl_info.tmu_state = TMU_STATUS_INIT; |
| 171 | debug("EXYNOS_TMU: Thermal reading failed\n"); |
| 172 | return TMU_STATUS_INIT; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* |
| 176 | * Get TMU specific pre-defined values from FDT |
| 177 | * |
| 178 | * @param info pointer to the tmu_info struct |
| 179 | * @param blob FDT blob |
| 180 | * @return int value, 0 for success |
| 181 | */ |
| 182 | static int get_tmu_fdt_values(struct tmu_info *info, const void *blob) |
| 183 | { |
Masahiro Yamada | 366b24f | 2015-08-12 07:31:55 +0900 | [diff] [blame] | 184 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 185 | fdt_addr_t addr; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 186 | int node; |
| 187 | int error = 0; |
| 188 | |
| 189 | /* Get the node from FDT for TMU */ |
| 190 | node = fdtdec_next_compatible(blob, 0, |
| 191 | COMPAT_SAMSUNG_EXYNOS_TMU); |
| 192 | if (node < 0) { |
| 193 | debug("EXYNOS_TMU: No node for tmu in device tree\n"); |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 194 | return -ENODEV; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Get the pre-defined TMU specific values from FDT. |
| 199 | * All of these are expected to be correct otherwise |
| 200 | * miscalculation of register values in tmu_setup_parameters |
| 201 | * may result in misleading current temperature. |
| 202 | */ |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 203 | addr = fdtdec_get_addr(blob, node, "reg"); |
| 204 | if (addr == FDT_ADDR_T_NONE) { |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 205 | debug("%s: Missing tmu-base\n", __func__); |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 206 | return -ENODEV; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 207 | } |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 208 | info->tmu_base = (struct exynos5_tmu_reg *)addr; |
| 209 | |
Naveen Krishna Chatradhi | b3d364f | 2013-04-05 15:21:39 -0700 | [diff] [blame] | 210 | /* Optional field. */ |
| 211 | info->tmu_mux = fdtdec_get_int(blob, |
| 212 | node, "samsung,mux", -1); |
| 213 | /* Take default value as per the user manual b(110) */ |
| 214 | if (info->tmu_mux == -1) |
| 215 | info->tmu_mux = 0x6; |
| 216 | |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 217 | info->data.ts.min_val = fdtdec_get_int(blob, |
| 218 | node, "samsung,min-temp", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 219 | error |= (info->data.ts.min_val == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 220 | info->data.ts.max_val = fdtdec_get_int(blob, |
| 221 | node, "samsung,max-temp", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 222 | error |= (info->data.ts.max_val == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 223 | info->data.ts.start_warning = fdtdec_get_int(blob, |
| 224 | node, "samsung,start-warning", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 225 | error |= (info->data.ts.start_warning == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 226 | info->data.ts.start_tripping = fdtdec_get_int(blob, |
| 227 | node, "samsung,start-tripping", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 228 | error |= (info->data.ts.start_tripping == -1); |
Akshay Saraswat | b9fa8c1 | 2013-02-25 01:13:06 +0000 | [diff] [blame] | 229 | info->data.ts.hardware_tripping = fdtdec_get_int(blob, |
| 230 | node, "samsung,hw-tripping", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 231 | error |= (info->data.ts.hardware_tripping == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 232 | info->data.efuse_min_value = fdtdec_get_int(blob, |
| 233 | node, "samsung,efuse-min-value", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 234 | error |= (info->data.efuse_min_value == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 235 | info->data.efuse_value = fdtdec_get_int(blob, |
| 236 | node, "samsung,efuse-value", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 237 | error |= (info->data.efuse_value == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 238 | info->data.efuse_max_value = fdtdec_get_int(blob, |
| 239 | node, "samsung,efuse-max-value", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 240 | error |= (info->data.efuse_max_value == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 241 | info->data.slope = fdtdec_get_int(blob, |
| 242 | node, "samsung,slope", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 243 | error |= (info->data.slope == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 244 | info->dc_value = fdtdec_get_int(blob, |
| 245 | node, "samsung,dc-value", -1); |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 246 | error |= (info->dc_value == -1); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 247 | |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 248 | if (error) { |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 249 | debug("fail to get tmu node properties\n"); |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 250 | return -EINVAL; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 251 | } |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 252 | #else |
| 253 | /* Non DT support may never be added. Just in case */ |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 254 | return -ENODEV; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 255 | #endif |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | /* |
| 261 | * Calibrate and calculate threshold values and |
| 262 | * enable interrupt levels |
| 263 | * |
| 264 | * @param info pointer to the tmu_info struct |
| 265 | */ |
| 266 | static void tmu_setup_parameters(struct tmu_info *info) |
| 267 | { |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 268 | unsigned te_code, con; |
| 269 | unsigned warning_code, trip_code, hwtrip_code; |
| 270 | unsigned cooling_temp; |
| 271 | unsigned rising_value; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 272 | struct tmu_data *data = &info->data; |
Naveen Krishna Chatradhi | 09ffe60 | 2013-04-05 15:21:38 -0700 | [diff] [blame] | 273 | struct exynos5_tmu_reg *reg = info->tmu_base; |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 274 | |
| 275 | /* Must reload for reading efuse value from triminfo register */ |
| 276 | writel(TRIMINFO_RELOAD, ®->triminfo_control); |
| 277 | |
| 278 | /* Get the compensation parameter */ |
| 279 | te_code = readl(®->triminfo); |
| 280 | info->te1 = te_code & TRIM_INFO_MASK; |
| 281 | info->te2 = ((te_code >> 8) & TRIM_INFO_MASK); |
| 282 | |
| 283 | if ((data->efuse_min_value > info->te1) || |
| 284 | (info->te1 > data->efuse_max_value) |
| 285 | || (info->te2 != 0)) |
| 286 | info->te1 = data->efuse_value; |
| 287 | |
| 288 | /* Get RISING & FALLING Threshold value */ |
| 289 | warning_code = data->ts.start_warning |
| 290 | + info->te1 - info->dc_value; |
| 291 | trip_code = data->ts.start_tripping |
| 292 | + info->te1 - info->dc_value; |
Akshay Saraswat | b9fa8c1 | 2013-02-25 01:13:06 +0000 | [diff] [blame] | 293 | hwtrip_code = data->ts.hardware_tripping |
| 294 | + info->te1 - info->dc_value; |
| 295 | |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 296 | cooling_temp = 0; |
| 297 | |
Akshay Saraswat | b9fa8c1 | 2013-02-25 01:13:06 +0000 | [diff] [blame] | 298 | rising_value = ((warning_code << 8) | |
| 299 | (trip_code << 16) | |
| 300 | (hwtrip_code << 24)); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 301 | |
| 302 | /* Set interrupt level */ |
| 303 | writel(rising_value, ®->threshold_temp_rise); |
| 304 | writel(cooling_temp, ®->threshold_temp_fall); |
| 305 | |
| 306 | /* |
| 307 | * Init TMU control tuning parameters |
| 308 | * [28:24] VREF - Voltage reference |
| 309 | * [15:13] THERM_TRIP_MODE - Tripping mode |
| 310 | * [12] THERM_TRIP_EN - Thermal tripping enable |
| 311 | * [11:8] BUF_SLOPE_SEL - Gain of amplifier |
| 312 | * [6] THERM_TRIP_BY_TQ_EN - Tripping by TQ pin |
| 313 | */ |
| 314 | writel(data->slope, ®->tmu_control); |
| 315 | |
| 316 | writel(INTCLEARALL, ®->intclear); |
| 317 | |
| 318 | /* TMU core enable */ |
| 319 | con = readl(®->tmu_control); |
Naveen Krishna Chatradhi | b3d364f | 2013-04-05 15:21:39 -0700 | [diff] [blame] | 320 | con |= THERM_TRIP_EN | CORE_EN | (info->tmu_mux << 20); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 321 | |
| 322 | writel(con, ®->tmu_control); |
| 323 | |
Akshay Saraswat | b9fa8c1 | 2013-02-25 01:13:06 +0000 | [diff] [blame] | 324 | /* Enable HW thermal trip */ |
| 325 | set_hw_thermal_trip(); |
| 326 | |
| 327 | /* LEV1 LEV2 interrupt enable */ |
| 328 | writel(INTEN_RISE1 | INTEN_RISE2, ®->inten); |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /* |
| 332 | * Initialize TMU device |
| 333 | * |
| 334 | * @param blob FDT blob |
| 335 | * @return int value, 0 for success |
| 336 | */ |
| 337 | int tmu_init(const void *blob) |
| 338 | { |
| 339 | gbl_info.tmu_state = TMU_STATUS_INIT; |
| 340 | if (get_tmu_fdt_values(&gbl_info, blob) < 0) |
| 341 | goto ret; |
| 342 | |
| 343 | tmu_setup_parameters(&gbl_info); |
| 344 | gbl_info.tmu_state = TMU_STATUS_NORMAL; |
| 345 | ret: |
Akshay Saraswat | 32e61e2 | 2013-02-25 01:13:00 +0000 | [diff] [blame] | 346 | return gbl_info.tmu_state; |
| 347 | } |