exynos_tmu.c (d7a5b431911c5d9da7fbff852433e6f99a4c6616) | exynos_tmu.c (b72ba67baec1d8ff67edc6e70c371ab6b2f7d31c) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * exynos_tmu.c - Samsung Exynos TMU (Thermal Management Unit) 4 * 5 * Copyright (C) 2014 Samsung Electronics 6 * Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> 7 * Lukasz Majewski <l.majewski@samsung.com> 8 * --- 237 unchanged lines hidden (view full) --- 246 data->temp_error2 = 247 (data->efuse_value >> EXYNOS_TRIMINFO_85_SHIFT) & 248 EXYNOS_TMU_TEMP_MASK; 249} 250 251static int exynos_tmu_initialize(struct platform_device *pdev) 252{ 253 struct exynos_tmu_data *data = platform_get_drvdata(pdev); | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * exynos_tmu.c - Samsung Exynos TMU (Thermal Management Unit) 4 * 5 * Copyright (C) 2014 Samsung Electronics 6 * Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> 7 * Lukasz Majewski <l.majewski@samsung.com> 8 * --- 237 unchanged lines hidden (view full) --- 246 data->temp_error2 = 247 (data->efuse_value >> EXYNOS_TRIMINFO_85_SHIFT) & 248 EXYNOS_TMU_TEMP_MASK; 249} 250 251static int exynos_tmu_initialize(struct platform_device *pdev) 252{ 253 struct exynos_tmu_data *data = platform_get_drvdata(pdev); |
254 struct thermal_zone_device *tzd = data->tzd; 255 int num_trips = thermal_zone_get_num_trips(tzd); | |
256 unsigned int status; | 254 unsigned int status; |
255 int ret = 0; 256 257 mutex_lock(&data->lock); 258 clk_enable(data->clk); 259 if (!IS_ERR(data->clk_sec)) 260 clk_enable(data->clk_sec); 261 262 status = readb(data->base + EXYNOS_TMU_REG_STATUS); 263 if (!status) { 264 ret = -EBUSY; 265 } else { 266 data->tmu_initialize(pdev); 267 data->tmu_clear_irqs(data); 268 } 269 270 if (!IS_ERR(data->clk_sec)) 271 clk_disable(data->clk_sec); 272 clk_disable(data->clk); 273 mutex_unlock(&data->lock); 274 275 return ret; 276} 277 278static int exynos_thermal_zone_configure(struct platform_device *pdev) 279{ 280 struct exynos_tmu_data *data = platform_get_drvdata(pdev); 281 struct thermal_zone_device *tzd = data->tzd; 282 int i, num_trips = thermal_zone_get_num_trips(tzd); |
|
257 int ret = 0, temp; 258 259 ret = thermal_zone_get_crit_temp(tzd, &temp); | 283 int ret = 0, temp; 284 285 ret = thermal_zone_get_crit_temp(tzd, &temp); |
286 |
|
260 if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */ 261 dev_err(&pdev->dev, 262 "No CRITICAL trip point defined in device tree!\n"); 263 goto out; 264 } 265 | 287 if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */ 288 dev_err(&pdev->dev, 289 "No CRITICAL trip point defined in device tree!\n"); 290 goto out; 291 } 292 |
293 mutex_lock(&data->lock); 294 |
|
266 if (num_trips > data->ntrip) { 267 dev_info(&pdev->dev, 268 "More trip points than supported by this TMU.\n"); 269 dev_info(&pdev->dev, 270 "%d trip points should be configured in polling mode.\n", 271 num_trips - data->ntrip); 272 } 273 | 295 if (num_trips > data->ntrip) { 296 dev_info(&pdev->dev, 297 "More trip points than supported by this TMU.\n"); 298 dev_info(&pdev->dev, 299 "%d trip points should be configured in polling mode.\n", 300 num_trips - data->ntrip); 301 } 302 |
274 mutex_lock(&data->lock); | |
275 clk_enable(data->clk); | 303 clk_enable(data->clk); |
276 if (!IS_ERR(data->clk_sec)) 277 clk_enable(data->clk_sec); | |
278 | 304 |
279 status = readb(data->base + EXYNOS_TMU_REG_STATUS); 280 if (!status) { 281 ret = -EBUSY; 282 } else { 283 int i, ntrips = 284 min_t(int, num_trips, data->ntrip); | 305 num_trips = min_t(int, num_trips, data->ntrip); |
285 | 306 |
286 data->tmu_initialize(pdev); | 307 /* Write temperature code for rising and falling threshold */ 308 for (i = 0; i < num_trips; i++) { 309 struct thermal_trip trip; |
287 | 310 |
288 /* Write temperature code for rising and falling threshold */ 289 for (i = 0; i < ntrips; i++) { | 311 ret = thermal_zone_get_trip(tzd, i, &trip); 312 if (ret) 313 goto err; |
290 | 314 |
291 struct thermal_trip trip; 292 293 ret = thermal_zone_get_trip(tzd, i, &trip); 294 if (ret) 295 goto err; 296 297 data->tmu_set_trip_temp(data, i, trip.temperature / MCELSIUS); 298 data->tmu_set_trip_hyst(data, i, trip.temperature / MCELSIUS, 299 trip.hysteresis / MCELSIUS); 300 } 301 302 data->tmu_clear_irqs(data); | 315 data->tmu_set_trip_temp(data, i, trip.temperature / MCELSIUS); 316 data->tmu_set_trip_hyst(data, i, trip.temperature / MCELSIUS, 317 trip.hysteresis / MCELSIUS); |
303 } | 318 } |
319 |
|
304err: 305 clk_disable(data->clk); 306 mutex_unlock(&data->lock); | 320err: 321 clk_disable(data->clk); 322 mutex_unlock(&data->lock); |
307 if (!IS_ERR(data->clk_sec)) 308 clk_disable(data->clk_sec); | |
309out: 310 return ret; 311} 312 313static u32 get_con_reg(struct exynos_tmu_data *data, u32 con) 314{ 315 if (data->soc == SOC_ARCH_EXYNOS4412 || 316 data->soc == SOC_ARCH_EXYNOS3250) --- 722 unchanged lines hidden (view full) --- 1039 goto err_clk; 1040 } 1041 } 1042 break; 1043 default: 1044 break; 1045 } 1046 | 323out: 324 return ret; 325} 326 327static u32 get_con_reg(struct exynos_tmu_data *data, u32 con) 328{ 329 if (data->soc == SOC_ARCH_EXYNOS4412 || 330 data->soc == SOC_ARCH_EXYNOS3250) --- 722 unchanged lines hidden (view full) --- 1053 goto err_clk; 1054 } 1055 } 1056 break; 1057 default: 1058 break; 1059 } 1060 |
1047 /* 1048 * data->tzd must be registered before calling exynos_tmu_initialize(), 1049 * requesting irq and calling exynos_tmu_control(). 1050 */ | 1061 ret = exynos_tmu_initialize(pdev); 1062 if (ret) { 1063 dev_err(&pdev->dev, "Failed to initialize TMU\n"); 1064 goto err_sclk; 1065 } 1066 |
1051 data->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, data, 1052 &exynos_sensor_ops); 1053 if (IS_ERR(data->tzd)) { 1054 ret = PTR_ERR(data->tzd); 1055 if (ret != -EPROBE_DEFER) 1056 dev_err(&pdev->dev, "Failed to register sensor: %d\n", 1057 ret); 1058 goto err_sclk; 1059 } 1060 | 1067 data->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, data, 1068 &exynos_sensor_ops); 1069 if (IS_ERR(data->tzd)) { 1070 ret = PTR_ERR(data->tzd); 1071 if (ret != -EPROBE_DEFER) 1072 dev_err(&pdev->dev, "Failed to register sensor: %d\n", 1073 ret); 1074 goto err_sclk; 1075 } 1076 |
1061 ret = exynos_tmu_initialize(pdev); | 1077 ret = exynos_thermal_zone_configure(pdev); |
1062 if (ret) { | 1078 if (ret) { |
1063 dev_err(&pdev->dev, "Failed to initialize TMU\n"); | 1079 dev_err(&pdev->dev, "Failed to configure the thermal zone\n"); |
1064 goto err_sclk; 1065 } 1066 1067 ret = devm_request_threaded_irq(&pdev->dev, data->irq, NULL, 1068 exynos_tmu_threaded_irq, 1069 IRQF_TRIGGER_RISING 1070 | IRQF_SHARED | IRQF_ONESHOT, 1071 dev_name(&pdev->dev), data); --- 71 unchanged lines hidden --- | 1080 goto err_sclk; 1081 } 1082 1083 ret = devm_request_threaded_irq(&pdev->dev, data->irq, NULL, 1084 exynos_tmu_threaded_irq, 1085 IRQF_TRIGGER_RISING 1086 | IRQF_SHARED | IRQF_ONESHOT, 1087 dev_name(&pdev->dev), data); --- 71 unchanged lines hidden --- |