From 4dcbadda9fc9ac1e0e9af19824c24017dcf4db3d Mon Sep 17 00:00:00 2001 From: Anson Huang Date: Fri, 16 Jan 2015 21:16:35 +0800 Subject: [PATCH] MLK-10106 thermal: imx: correct clk enable and thermal sensor init sequence thermal sensor's irq init should be done after clk enabled, also, the low alarm value should be set correctly before clearing its irq status. Signed-off-by: Anson Huang Signed-off-by: Bai Ping --- drivers/thermal/imx_thermal.c | 51 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index bf886c4a7f90..37f3be286335 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -538,31 +538,39 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata = of_id->data; + data->thermal_clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(data->thermal_clk)) { + dev_warn(&pdev->dev, "failed to get thermal clk!\n"); + } else { + /* + * Thermal sensor needs clk on to get correct value, normally + * we should enable its clk before taking measurement and disable + * clk after measurement is done, but if alarm function is enabled, + * hardware will auto measure the temperature periodically, so we + * need to keep the clk always on for alarm function. + */ + ret = clk_prepare_enable(data->thermal_clk); + if (ret) + dev_warn(&pdev->dev, "failed to enable thermal clk: %d\n", ret); + } + /* make sure the IRQ flag is clear before enable irq */ regmap_write(map, MISC1 + REG_CLR, MISC1_IRQ_TEMPHIGH); if (data->socdata->version == TEMPMON_V2) { - regmap_write(map, MISC1 + REG_CLR, MISC1_IRQ_TEMPLOW | - MISC1_IRQ_TEMPPANIC); /* * reset value of LOW ALARM is incorrect, set it to lowest * value to avoid false trigger of low alarm. */ regmap_write(map, TEMPSENSE2 + REG_SET, TEMPSENSE2_LOW_VALUE_MASK); + regmap_write(map, MISC1 + REG_CLR, MISC1_IRQ_TEMPLOW | + MISC1_IRQ_TEMPPANIC); } data->irq = platform_get_irq(pdev, 0); if (data->irq < 0) return data->irq; - ret = devm_request_threaded_irq(&pdev->dev, data->irq, - imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, - 0, "imx_thermal", data); - if (ret < 0) { - dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); - return ret; - } - platform_set_drvdata(pdev, data); ret = imx_get_sensor_data(pdev); @@ -610,22 +618,6 @@ static int imx_thermal_probe(struct platform_device *pdev) return ret; } - data->thermal_clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(data->thermal_clk)) { - dev_warn(&pdev->dev, "failed to get thermal clk!\n"); - } else { - /* - * Thermal sensor needs clk on to get correct value, normally - * we should enable its clk before taking measurement and disable - * clk after measurement is done, but if alarm function is enabled, - * hardware will auto measure the temperature periodically, so we - * need to keep the clk always on for alarm function. - */ - ret = clk_prepare_enable(data->thermal_clk); - if (ret) - dev_warn(&pdev->dev, "failed to enable thermal clk: %d\n", ret); - } - /* Enable measurements at ~ 10 Hz */ regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */ @@ -638,6 +630,13 @@ static int imx_thermal_probe(struct platform_device *pdev) regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); + ret = devm_request_threaded_irq(&pdev->dev, data->irq, + imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, + 0, "imx_thermal", data); + if (ret < 0) { + dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); + return ret; + } data->irq_enabled = true; data->mode = THERMAL_DEVICE_ENABLED; /* register the busfreq notifier called in low bus freq */ -- 2.39.2