Skip to content

Commit b72ba67

Browse files
metiulekmdlezcano
authored andcommitted
thermal/drivers/exynos: Split initialization of TMU and the thermal zone
This will be needed in the future, as the thermal zone subsystem might call our callbacks right after devm_thermal_of_zone_register. Currently we just make get_temp return EAGAIN in such case, but this will not be possible with state-modifying callbacks, for instance set_trips. Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Signed-off-by: Mateusz Majewski <m.majewski2@samsung.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20231201095625.301884-8-m.majewski2@samsung.com
1 parent d7a5b43 commit b72ba67

File tree

1 file changed

+50
-34
lines changed

1 file changed

+50
-34
lines changed

drivers/thermal/samsung/exynos_tmu.c

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,47 @@ static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info)
251251
static int exynos_tmu_initialize(struct platform_device *pdev)
252252
{
253253
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);
256254
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+
278+
static 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);
257283
int ret = 0, temp;
258284

259285
ret = thermal_zone_get_crit_temp(tzd, &temp);
286+
260287
if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */
261288
dev_err(&pdev->dev,
262289
"No CRITICAL trip point defined in device tree!\n");
263290
goto out;
264291
}
265292

293+
mutex_lock(&data->lock);
294+
266295
if (num_trips > data->ntrip) {
267296
dev_info(&pdev->dev,
268297
"More trip points than supported by this TMU.\n");
@@ -271,41 +300,26 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
271300
num_trips - data->ntrip);
272301
}
273302

274-
mutex_lock(&data->lock);
275303
clk_enable(data->clk);
276-
if (!IS_ERR(data->clk_sec))
277-
clk_enable(data->clk_sec);
278-
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);
285-
286-
data->tmu_initialize(pdev);
287304

288-
/* Write temperature code for rising and falling threshold */
289-
for (i = 0; i < ntrips; i++) {
305+
num_trips = min_t(int, num_trips, data->ntrip);
290306

291-
struct thermal_trip trip;
307+
/* Write temperature code for rising and falling threshold */
308+
for (i = 0; i < num_trips; i++) {
309+
struct thermal_trip trip;
292310

293-
ret = thermal_zone_get_trip(tzd, i, &trip);
294-
if (ret)
295-
goto err;
311+
ret = thermal_zone_get_trip(tzd, i, &trip);
312+
if (ret)
313+
goto err;
296314

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);
303318
}
319+
304320
err:
305321
clk_disable(data->clk);
306322
mutex_unlock(&data->lock);
307-
if (!IS_ERR(data->clk_sec))
308-
clk_disable(data->clk_sec);
309323
out:
310324
return ret;
311325
}
@@ -1044,10 +1058,12 @@ static int exynos_tmu_probe(struct platform_device *pdev)
10441058
break;
10451059
}
10461060

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+
10511067
data->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, data,
10521068
&exynos_sensor_ops);
10531069
if (IS_ERR(data->tzd)) {
@@ -1058,9 +1074,9 @@ static int exynos_tmu_probe(struct platform_device *pdev)
10581074
goto err_sclk;
10591075
}
10601076

1061-
ret = exynos_tmu_initialize(pdev);
1077+
ret = exynos_thermal_zone_configure(pdev);
10621078
if (ret) {
1063-
dev_err(&pdev->dev, "Failed to initialize TMU\n");
1079+
dev_err(&pdev->dev, "Failed to configure the thermal zone\n");
10641080
goto err_sclk;
10651081
}
10661082

0 commit comments

Comments
 (0)