diff options
Diffstat (limited to 'drivers/thermal/imx_thermal.c')
-rw-r--r-- | drivers/thermal/imx_thermal.c | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 461bf3d033a0..5a1f1070b702 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c | |||
@@ -459,6 +459,10 @@ static int imx_thermal_probe(struct platform_device *pdev) | |||
459 | int measure_freq; | 459 | int measure_freq; |
460 | int ret; | 460 | int ret; |
461 | 461 | ||
462 | if (!cpufreq_get_current_driver()) { | ||
463 | dev_dbg(&pdev->dev, "no cpufreq driver!"); | ||
464 | return -EPROBE_DEFER; | ||
465 | } | ||
462 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | 466 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
463 | if (!data) | 467 | if (!data) |
464 | return -ENOMEM; | 468 | return -ENOMEM; |
@@ -521,6 +525,30 @@ static int imx_thermal_probe(struct platform_device *pdev) | |||
521 | return ret; | 525 | return ret; |
522 | } | 526 | } |
523 | 527 | ||
528 | data->thermal_clk = devm_clk_get(&pdev->dev, NULL); | ||
529 | if (IS_ERR(data->thermal_clk)) { | ||
530 | ret = PTR_ERR(data->thermal_clk); | ||
531 | if (ret != -EPROBE_DEFER) | ||
532 | dev_err(&pdev->dev, | ||
533 | "failed to get thermal clk: %d\n", ret); | ||
534 | cpufreq_cooling_unregister(data->cdev); | ||
535 | return ret; | ||
536 | } | ||
537 | |||
538 | /* | ||
539 | * Thermal sensor needs clk on to get correct value, normally | ||
540 | * we should enable its clk before taking measurement and disable | ||
541 | * clk after measurement is done, but if alarm function is enabled, | ||
542 | * hardware will auto measure the temperature periodically, so we | ||
543 | * need to keep the clk always on for alarm function. | ||
544 | */ | ||
545 | ret = clk_prepare_enable(data->thermal_clk); | ||
546 | if (ret) { | ||
547 | dev_err(&pdev->dev, "failed to enable thermal clk: %d\n", ret); | ||
548 | cpufreq_cooling_unregister(data->cdev); | ||
549 | return ret; | ||
550 | } | ||
551 | |||
524 | data->tz = thermal_zone_device_register("imx_thermal_zone", | 552 | data->tz = thermal_zone_device_register("imx_thermal_zone", |
525 | IMX_TRIP_NUM, | 553 | IMX_TRIP_NUM, |
526 | BIT(IMX_TRIP_PASSIVE), data, | 554 | BIT(IMX_TRIP_PASSIVE), data, |
@@ -531,26 +559,11 @@ static int imx_thermal_probe(struct platform_device *pdev) | |||
531 | ret = PTR_ERR(data->tz); | 559 | ret = PTR_ERR(data->tz); |
532 | dev_err(&pdev->dev, | 560 | dev_err(&pdev->dev, |
533 | "failed to register thermal zone device %d\n", ret); | 561 | "failed to register thermal zone device %d\n", ret); |
562 | clk_disable_unprepare(data->thermal_clk); | ||
534 | cpufreq_cooling_unregister(data->cdev); | 563 | cpufreq_cooling_unregister(data->cdev); |
535 | return ret; | 564 | return ret; |
536 | } | 565 | } |
537 | 566 | ||
538 | data->thermal_clk = devm_clk_get(&pdev->dev, NULL); | ||
539 | if (IS_ERR(data->thermal_clk)) { | ||
540 | dev_warn(&pdev->dev, "failed to get thermal clk!\n"); | ||
541 | } else { | ||
542 | /* | ||
543 | * Thermal sensor needs clk on to get correct value, normally | ||
544 | * we should enable its clk before taking measurement and disable | ||
545 | * clk after measurement is done, but if alarm function is enabled, | ||
546 | * hardware will auto measure the temperature periodically, so we | ||
547 | * need to keep the clk always on for alarm function. | ||
548 | */ | ||
549 | ret = clk_prepare_enable(data->thermal_clk); | ||
550 | if (ret) | ||
551 | dev_warn(&pdev->dev, "failed to enable thermal clk: %d\n", ret); | ||
552 | } | ||
553 | |||
554 | /* Enable measurements at ~ 10 Hz */ | 567 | /* Enable measurements at ~ 10 Hz */ |
555 | regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); | 568 | regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); |
556 | measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */ | 569 | measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */ |