@@ -251,18 +251,47 @@ static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info)
251
251
static int exynos_tmu_initialize (struct platform_device * pdev )
252
252
{
253
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
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
+
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 );
257
283
int ret = 0 , temp ;
258
284
259
285
ret = thermal_zone_get_crit_temp (tzd , & temp );
286
+
260
287
if (ret && data -> soc != SOC_ARCH_EXYNOS5433 ) { /* FIXME */
261
288
dev_err (& pdev -> dev ,
262
289
"No CRITICAL trip point defined in device tree!\n" );
263
290
goto out ;
264
291
}
265
292
293
+ mutex_lock (& data -> lock );
294
+
266
295
if (num_trips > data -> ntrip ) {
267
296
dev_info (& pdev -> dev ,
268
297
"More trip points than supported by this TMU.\n" );
@@ -271,41 +300,26 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
271
300
num_trips - data -> ntrip );
272
301
}
273
302
274
- mutex_lock (& data -> lock );
275
303
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 );
287
304
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 );
290
306
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 ;
292
310
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 ;
296
314
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
+
304
320
err :
305
321
clk_disable (data -> clk );
306
322
mutex_unlock (& data -> lock );
307
- if (!IS_ERR (data -> clk_sec ))
308
- clk_disable (data -> clk_sec );
309
323
out :
310
324
return ret ;
311
325
}
@@ -1044,10 +1058,12 @@ static int exynos_tmu_probe(struct platform_device *pdev)
1044
1058
break ;
1045
1059
}
1046
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
1067
data -> tzd = devm_thermal_of_zone_register (& pdev -> dev , 0 , data ,
1052
1068
& exynos_sensor_ops );
1053
1069
if (IS_ERR (data -> tzd )) {
@@ -1058,9 +1074,9 @@ static int exynos_tmu_probe(struct platform_device *pdev)
1058
1074
goto err_sclk ;
1059
1075
}
1060
1076
1061
- ret = exynos_tmu_initialize (pdev );
1077
+ ret = exynos_thermal_zone_configure (pdev );
1062
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
1080
goto err_sclk ;
1065
1081
}
1066
1082
0 commit comments