diff options
| -rw-r--r-- | drivers/thermal/rcar_gen3_thermal.c | 92 | ||||
| -rw-r--r-- | drivers/thermal/rockchip_thermal.c | 36 | ||||
| -rw-r--r-- | drivers/thermal/tegra/tegra210-soctherm.c | 2 |
3 files changed, 64 insertions, 66 deletions
diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index 83f306265ee1..a56463308694 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c | |||
| @@ -62,6 +62,13 @@ | |||
| 62 | 62 | ||
| 63 | #define TSC_MAX_NUM 3 | 63 | #define TSC_MAX_NUM 3 |
| 64 | 64 | ||
| 65 | /* default THCODE values if FUSEs are missing */ | ||
| 66 | static const int thcode[TSC_MAX_NUM][3] = { | ||
| 67 | { 3397, 2800, 2221 }, | ||
| 68 | { 3393, 2795, 2216 }, | ||
| 69 | { 3389, 2805, 2237 }, | ||
| 70 | }; | ||
| 71 | |||
| 65 | /* Structure for thermal temperature calculation */ | 72 | /* Structure for thermal temperature calculation */ |
| 66 | struct equation_coefs { | 73 | struct equation_coefs { |
| 67 | int a1; | 74 | int a1; |
| @@ -76,6 +83,8 @@ struct rcar_gen3_thermal_tsc { | |||
| 76 | struct equation_coefs coef; | 83 | struct equation_coefs coef; |
| 77 | int low; | 84 | int low; |
| 78 | int high; | 85 | int high; |
| 86 | int tj_t; | ||
| 87 | int id; /* thermal channel id */ | ||
| 79 | }; | 88 | }; |
| 80 | 89 | ||
| 81 | struct rcar_gen3_thermal_priv { | 90 | struct rcar_gen3_thermal_priv { |
| @@ -122,30 +131,28 @@ static inline void rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc, | |||
| 122 | #define RCAR3_THERMAL_GRAN 500 /* mili Celsius */ | 131 | #define RCAR3_THERMAL_GRAN 500 /* mili Celsius */ |
| 123 | 132 | ||
| 124 | /* no idea where these constants come from */ | 133 | /* no idea where these constants come from */ |
| 125 | #define TJ_1 116 | ||
| 126 | #define TJ_3 -41 | 134 | #define TJ_3 -41 |
| 127 | 135 | ||
| 128 | static void rcar_gen3_thermal_calc_coefs(struct equation_coefs *coef, | 136 | static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc, |
| 129 | int *ptat, int *thcode) | 137 | int *ptat, const int *thcode, |
| 138 | int ths_tj_1) | ||
| 130 | { | 139 | { |
| 131 | int tj_2; | ||
| 132 | |||
| 133 | /* TODO: Find documentation and document constant calculation formula */ | 140 | /* TODO: Find documentation and document constant calculation formula */ |
| 134 | 141 | ||
| 135 | /* | 142 | /* |
| 136 | * Division is not scaled in BSP and if scaled it might overflow | 143 | * Division is not scaled in BSP and if scaled it might overflow |
| 137 | * the dividend (4095 * 4095 << 14 > INT_MAX) so keep it unscaled | 144 | * the dividend (4095 * 4095 << 14 > INT_MAX) so keep it unscaled |
| 138 | */ | 145 | */ |
| 139 | tj_2 = (FIXPT_INT((ptat[1] - ptat[2]) * 157) | 146 | tsc->tj_t = (FIXPT_INT((ptat[1] - ptat[2]) * 157) |
| 140 | / (ptat[0] - ptat[2])) - FIXPT_INT(41); | 147 | / (ptat[0] - ptat[2])) + FIXPT_INT(TJ_3); |
| 141 | 148 | ||
| 142 | coef->a1 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]), | 149 | tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]), |
| 143 | tj_2 - FIXPT_INT(TJ_3)); | 150 | tsc->tj_t - FIXPT_INT(TJ_3)); |
| 144 | coef->b1 = FIXPT_INT(thcode[2]) - coef->a1 * TJ_3; | 151 | tsc->coef.b1 = FIXPT_INT(thcode[2]) - tsc->coef.a1 * TJ_3; |
| 145 | 152 | ||
| 146 | coef->a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), | 153 | tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), |
| 147 | tj_2 - FIXPT_INT(TJ_1)); | 154 | tsc->tj_t - FIXPT_INT(ths_tj_1)); |
| 148 | coef->b2 = FIXPT_INT(thcode[0]) - coef->a2 * TJ_1; | 155 | tsc->coef.b2 = FIXPT_INT(thcode[0]) - tsc->coef.a2 * ths_tj_1; |
| 149 | } | 156 | } |
| 150 | 157 | ||
| 151 | static int rcar_gen3_thermal_round(int temp) | 158 | static int rcar_gen3_thermal_round(int temp) |
| @@ -161,15 +168,19 @@ static int rcar_gen3_thermal_round(int temp) | |||
| 161 | static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) | 168 | static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) |
| 162 | { | 169 | { |
| 163 | struct rcar_gen3_thermal_tsc *tsc = devdata; | 170 | struct rcar_gen3_thermal_tsc *tsc = devdata; |
| 164 | int mcelsius, val1, val2; | 171 | int mcelsius, val; |
| 165 | u32 reg; | 172 | u32 reg; |
| 166 | 173 | ||
| 167 | /* Read register and convert to mili Celsius */ | 174 | /* Read register and convert to mili Celsius */ |
| 168 | reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK; | 175 | reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK; |
| 169 | 176 | ||
| 170 | val1 = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, tsc->coef.a1); | 177 | if (reg <= thcode[tsc->id][1]) |
| 171 | val2 = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, tsc->coef.a2); | 178 | val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, |
| 172 | mcelsius = FIXPT_TO_MCELSIUS((val1 + val2) / 2); | 179 | tsc->coef.a1); |
| 180 | else | ||
| 181 | val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, | ||
| 182 | tsc->coef.a2); | ||
| 183 | mcelsius = FIXPT_TO_MCELSIUS(val); | ||
| 173 | 184 | ||
| 174 | /* Make sure we are inside specifications */ | 185 | /* Make sure we are inside specifications */ |
| 175 | if ((mcelsius < MCELSIUS(-40)) || (mcelsius > MCELSIUS(125))) | 186 | if ((mcelsius < MCELSIUS(-40)) || (mcelsius > MCELSIUS(125))) |
| @@ -184,13 +195,15 @@ static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) | |||
| 184 | static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc, | 195 | static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc, |
| 185 | int mcelsius) | 196 | int mcelsius) |
| 186 | { | 197 | { |
| 187 | int celsius, val1, val2; | 198 | int celsius, val; |
| 188 | 199 | ||
| 189 | celsius = DIV_ROUND_CLOSEST(mcelsius, 1000); | 200 | celsius = DIV_ROUND_CLOSEST(mcelsius, 1000); |
| 190 | val1 = celsius * tsc->coef.a1 + tsc->coef.b1; | 201 | if (celsius <= INT_FIXPT(tsc->tj_t)) |
| 191 | val2 = celsius * tsc->coef.a2 + tsc->coef.b2; | 202 | val = celsius * tsc->coef.a1 + tsc->coef.b1; |
| 203 | else | ||
| 204 | val = celsius * tsc->coef.a2 + tsc->coef.b2; | ||
| 192 | 205 | ||
| 193 | return INT_FIXPT((val1 + val2) / 2); | 206 | return INT_FIXPT(val); |
| 194 | } | 207 | } |
| 195 | 208 | ||
| 196 | static int rcar_gen3_thermal_set_trips(void *devdata, int low, int high) | 209 | static int rcar_gen3_thermal_set_trips(void *devdata, int low, int high) |
| @@ -294,12 +307,29 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_tsc *tsc) | |||
| 294 | usleep_range(1000, 2000); | 307 | usleep_range(1000, 2000); |
| 295 | } | 308 | } |
| 296 | 309 | ||
| 310 | static const int rcar_gen3_ths_tj_1 = 126; | ||
| 311 | static const int rcar_gen3_ths_tj_1_m3_w = 116; | ||
| 297 | static const struct of_device_id rcar_gen3_thermal_dt_ids[] = { | 312 | static const struct of_device_id rcar_gen3_thermal_dt_ids[] = { |
| 298 | { .compatible = "renesas,r8a774a1-thermal", }, | 313 | { |
| 299 | { .compatible = "renesas,r8a7795-thermal", }, | 314 | .compatible = "renesas,r8a774a1-thermal", |
| 300 | { .compatible = "renesas,r8a7796-thermal", }, | 315 | .data = &rcar_gen3_ths_tj_1_m3_w, |
| 301 | { .compatible = "renesas,r8a77965-thermal", }, | 316 | }, |
| 302 | { .compatible = "renesas,r8a77980-thermal", }, | 317 | { |
| 318 | .compatible = "renesas,r8a7795-thermal", | ||
| 319 | .data = &rcar_gen3_ths_tj_1, | ||
| 320 | }, | ||
| 321 | { | ||
| 322 | .compatible = "renesas,r8a7796-thermal", | ||
| 323 | .data = &rcar_gen3_ths_tj_1_m3_w, | ||
| 324 | }, | ||
| 325 | { | ||
| 326 | .compatible = "renesas,r8a77965-thermal", | ||
| 327 | .data = &rcar_gen3_ths_tj_1, | ||
| 328 | }, | ||
| 329 | { | ||
| 330 | .compatible = "renesas,r8a77980-thermal", | ||
| 331 | .data = &rcar_gen3_ths_tj_1, | ||
| 332 | }, | ||
| 303 | {}, | 333 | {}, |
| 304 | }; | 334 | }; |
| 305 | MODULE_DEVICE_TABLE(of, rcar_gen3_thermal_dt_ids); | 335 | MODULE_DEVICE_TABLE(of, rcar_gen3_thermal_dt_ids); |
| @@ -328,6 +358,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) | |||
| 328 | { | 358 | { |
| 329 | struct rcar_gen3_thermal_priv *priv; | 359 | struct rcar_gen3_thermal_priv *priv; |
| 330 | struct device *dev = &pdev->dev; | 360 | struct device *dev = &pdev->dev; |
| 361 | const int *rcar_gen3_ths_tj_1 = of_device_get_match_data(dev); | ||
| 331 | struct resource *res; | 362 | struct resource *res; |
| 332 | struct thermal_zone_device *zone; | 363 | struct thermal_zone_device *zone; |
| 333 | int ret, irq, i; | 364 | int ret, irq, i; |
| @@ -336,11 +367,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) | |||
| 336 | /* default values if FUSEs are missing */ | 367 | /* default values if FUSEs are missing */ |
| 337 | /* TODO: Read values from hardware on supported platforms */ | 368 | /* TODO: Read values from hardware on supported platforms */ |
| 338 | int ptat[3] = { 2631, 1509, 435 }; | 369 | int ptat[3] = { 2631, 1509, 435 }; |
| 339 | int thcode[TSC_MAX_NUM][3] = { | ||
| 340 | { 3397, 2800, 2221 }, | ||
| 341 | { 3393, 2795, 2216 }, | ||
| 342 | { 3389, 2805, 2237 }, | ||
| 343 | }; | ||
| 344 | 370 | ||
| 345 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | 371 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 346 | if (!priv) | 372 | if (!priv) |
| @@ -395,11 +421,13 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) | |||
| 395 | ret = PTR_ERR(tsc->base); | 421 | ret = PTR_ERR(tsc->base); |
| 396 | goto error_unregister; | 422 | goto error_unregister; |
| 397 | } | 423 | } |
| 424 | tsc->id = i; | ||
| 398 | 425 | ||
| 399 | priv->tscs[i] = tsc; | 426 | priv->tscs[i] = tsc; |
| 400 | 427 | ||
| 401 | priv->thermal_init(tsc); | 428 | priv->thermal_init(tsc); |
| 402 | rcar_gen3_thermal_calc_coefs(&tsc->coef, ptat, thcode[i]); | 429 | rcar_gen3_thermal_calc_coefs(tsc, ptat, thcode[i], |
| 430 | *rcar_gen3_ths_tj_1); | ||
| 403 | 431 | ||
| 404 | zone = devm_thermal_zone_of_sensor_register(dev, i, tsc, | 432 | zone = devm_thermal_zone_of_sensor_register(dev, i, tsc, |
| 405 | &rcar_gen3_tz_of_ops); | 433 | &rcar_gen3_tz_of_ops); |
diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index bda1ca199abd..7ef9c7efe950 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c | |||
| @@ -172,9 +172,6 @@ struct rockchip_thermal_data { | |||
| 172 | int tshut_temp; | 172 | int tshut_temp; |
| 173 | enum tshut_mode tshut_mode; | 173 | enum tshut_mode tshut_mode; |
| 174 | enum tshut_polarity tshut_polarity; | 174 | enum tshut_polarity tshut_polarity; |
| 175 | struct pinctrl *pinctrl; | ||
| 176 | struct pinctrl_state *gpio_state; | ||
| 177 | struct pinctrl_state *otp_state; | ||
| 178 | }; | 175 | }; |
| 179 | 176 | ||
| 180 | /** | 177 | /** |
| @@ -1283,8 +1280,6 @@ static int rockchip_thermal_probe(struct platform_device *pdev) | |||
| 1283 | return error; | 1280 | return error; |
| 1284 | } | 1281 | } |
| 1285 | 1282 | ||
| 1286 | thermal->chip->control(thermal->regs, false); | ||
| 1287 | |||
| 1288 | error = clk_prepare_enable(thermal->clk); | 1283 | error = clk_prepare_enable(thermal->clk); |
| 1289 | if (error) { | 1284 | if (error) { |
| 1290 | dev_err(&pdev->dev, "failed to enable converter clock: %d\n", | 1285 | dev_err(&pdev->dev, "failed to enable converter clock: %d\n", |
| @@ -1310,30 +1305,6 @@ static int rockchip_thermal_probe(struct platform_device *pdev) | |||
| 1310 | thermal->chip->initialize(thermal->grf, thermal->regs, | 1305 | thermal->chip->initialize(thermal->grf, thermal->regs, |
| 1311 | thermal->tshut_polarity); | 1306 | thermal->tshut_polarity); |
| 1312 | 1307 | ||
| 1313 | if (thermal->tshut_mode == TSHUT_MODE_GPIO) { | ||
| 1314 | thermal->pinctrl = devm_pinctrl_get(&pdev->dev); | ||
| 1315 | if (IS_ERR(thermal->pinctrl)) { | ||
| 1316 | dev_err(&pdev->dev, "failed to find thermal pinctrl\n"); | ||
| 1317 | return PTR_ERR(thermal->pinctrl); | ||
| 1318 | } | ||
| 1319 | |||
| 1320 | thermal->gpio_state = pinctrl_lookup_state(thermal->pinctrl, | ||
| 1321 | "gpio"); | ||
| 1322 | if (IS_ERR_OR_NULL(thermal->gpio_state)) { | ||
| 1323 | dev_err(&pdev->dev, "failed to find thermal gpio state\n"); | ||
| 1324 | return -EINVAL; | ||
| 1325 | } | ||
| 1326 | |||
| 1327 | thermal->otp_state = pinctrl_lookup_state(thermal->pinctrl, | ||
| 1328 | "otpout"); | ||
| 1329 | if (IS_ERR_OR_NULL(thermal->otp_state)) { | ||
| 1330 | dev_err(&pdev->dev, "failed to find thermal otpout state\n"); | ||
| 1331 | return -EINVAL; | ||
| 1332 | } | ||
| 1333 | |||
| 1334 | pinctrl_select_state(thermal->pinctrl, thermal->otp_state); | ||
| 1335 | } | ||
| 1336 | |||
| 1337 | for (i = 0; i < thermal->chip->chn_num; i++) { | 1308 | for (i = 0; i < thermal->chip->chn_num; i++) { |
| 1338 | error = rockchip_thermal_register_sensor(pdev, thermal, | 1309 | error = rockchip_thermal_register_sensor(pdev, thermal, |
| 1339 | &thermal->sensors[i], | 1310 | &thermal->sensors[i], |
| @@ -1404,8 +1375,8 @@ static int __maybe_unused rockchip_thermal_suspend(struct device *dev) | |||
| 1404 | 1375 | ||
| 1405 | clk_disable(thermal->pclk); | 1376 | clk_disable(thermal->pclk); |
| 1406 | clk_disable(thermal->clk); | 1377 | clk_disable(thermal->clk); |
| 1407 | if (thermal->tshut_mode == TSHUT_MODE_GPIO) | 1378 | |
| 1408 | pinctrl_select_state(thermal->pinctrl, thermal->gpio_state); | 1379 | pinctrl_pm_select_sleep_state(dev); |
| 1409 | 1380 | ||
| 1410 | return 0; | 1381 | return 0; |
| 1411 | } | 1382 | } |
| @@ -1450,8 +1421,7 @@ static int __maybe_unused rockchip_thermal_resume(struct device *dev) | |||
| 1450 | for (i = 0; i < thermal->chip->chn_num; i++) | 1421 | for (i = 0; i < thermal->chip->chn_num; i++) |
| 1451 | rockchip_thermal_toggle_sensor(&thermal->sensors[i], true); | 1422 | rockchip_thermal_toggle_sensor(&thermal->sensors[i], true); |
| 1452 | 1423 | ||
| 1453 | if (thermal->tshut_mode == TSHUT_MODE_GPIO) | 1424 | pinctrl_pm_select_default_state(dev); |
| 1454 | pinctrl_select_state(thermal->pinctrl, thermal->otp_state); | ||
| 1455 | 1425 | ||
| 1456 | return 0; | 1426 | return 0; |
| 1457 | } | 1427 | } |
diff --git a/drivers/thermal/tegra/tegra210-soctherm.c b/drivers/thermal/tegra/tegra210-soctherm.c index d31b50050faa..d0ff793f18c5 100644 --- a/drivers/thermal/tegra/tegra210-soctherm.c +++ b/drivers/thermal/tegra/tegra210-soctherm.c | |||
| @@ -208,7 +208,7 @@ static const struct tegra_soctherm_fuse tegra210_soctherm_fuse = { | |||
| 208 | .fuse_spare_realignment = 0, | 208 | .fuse_spare_realignment = 0, |
| 209 | }; | 209 | }; |
| 210 | 210 | ||
| 211 | struct tsensor_group_thermtrips tegra210_tsensor_thermtrips[] = { | 211 | static struct tsensor_group_thermtrips tegra210_tsensor_thermtrips[] = { |
| 212 | {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, | 212 | {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, |
| 213 | {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, | 213 | {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, |
| 214 | {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, | 214 | {.id = TEGRA124_SOCTHERM_SENSOR_NUM}, |
