d7896dbd60a7a5b023fb8e084824cd16d772a53a
[openwrt/staging/neocturne.git] /
1 From 227d1856924ec00a4f5bdf5afcf77bc7f3f04e86 Mon Sep 17 00:00:00 2001
2 From: Kang Chen <void0red@hust.edu.cn>
3 Date: Wed, 19 Apr 2023 10:07:49 +0800
4 Subject: [PATCH 19/42] thermal/drivers/mediatek: Change clk_prepare_enable to
5 devm_clk_get_enabled in mtk_thermal_probe
6
7 Use devm_clk_get_enabled to do automatic resource management.
8 Meanwhile, remove error handling labels in the probe function and
9 the whole remove function.
10
11 Signed-off-by: Kang Chen <void0red@hust.edu.cn>
12 Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
13 Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
14 Link: https://lore.kernel.org/r/20230419020749.621257-2-void0red@hust.edu.cn
15 ---
16 drivers/thermal/mediatek/auxadc_thermal.c | 44 +++++------------------
17 1 file changed, 9 insertions(+), 35 deletions(-)
18
19 --- a/drivers/thermal/mediatek/auxadc_thermal.c
20 +++ b/drivers/thermal/mediatek/auxadc_thermal.c
21 @@ -1206,14 +1206,6 @@ static int mtk_thermal_probe(struct plat
22
23 mt->conf = of_device_get_match_data(&pdev->dev);
24
25 - mt->clk_peri_therm = devm_clk_get(&pdev->dev, "therm");
26 - if (IS_ERR(mt->clk_peri_therm))
27 - return PTR_ERR(mt->clk_peri_therm);
28 -
29 - mt->clk_auxadc = devm_clk_get(&pdev->dev, "auxadc");
30 - if (IS_ERR(mt->clk_auxadc))
31 - return PTR_ERR(mt->clk_auxadc);
32 -
33 mt->thermal_base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
34 if (IS_ERR(mt->thermal_base))
35 return PTR_ERR(mt->thermal_base);
36 @@ -1272,16 +1264,18 @@ static int mtk_thermal_probe(struct plat
37 if (ret)
38 return ret;
39
40 - ret = clk_prepare_enable(mt->clk_auxadc);
41 - if (ret) {
42 + mt->clk_auxadc = devm_clk_get_enabled(&pdev->dev, "auxadc");
43 + if (IS_ERR(mt->clk_auxadc)) {
44 + ret = PTR_ERR(mt->clk_auxadc);
45 dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret);
46 return ret;
47 }
48
49 - ret = clk_prepare_enable(mt->clk_peri_therm);
50 - if (ret) {
51 + mt->clk_peri_therm = devm_clk_get_enabled(&pdev->dev, "therm");
52 + if (IS_ERR(mt->clk_peri_therm)) {
53 + ret = PTR_ERR(mt->clk_peri_therm);
54 dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret);
55 - goto err_disable_clk_auxadc;
56 + return ret;
57 }
58
59 mtk_thermal_turn_on_buffer(mt, apmixed_base);
60 @@ -1305,38 +1299,18 @@ static int mtk_thermal_probe(struct plat
61
62 tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt,
63 &mtk_thermal_ops);
64 - if (IS_ERR(tzdev)) {
65 - ret = PTR_ERR(tzdev);
66 - goto err_disable_clk_peri_therm;
67 - }
68 + if (IS_ERR(tzdev))
69 + return PTR_ERR(tzdev);
70
71 ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, tzdev);
72 if (ret)
73 dev_warn(&pdev->dev, "error in thermal_add_hwmon_sysfs");
74
75 return 0;
76 -
77 -err_disable_clk_peri_therm:
78 - clk_disable_unprepare(mt->clk_peri_therm);
79 -err_disable_clk_auxadc:
80 - clk_disable_unprepare(mt->clk_auxadc);
81 -
82 - return ret;
83 -}
84 -
85 -static int mtk_thermal_remove(struct platform_device *pdev)
86 -{
87 - struct mtk_thermal *mt = platform_get_drvdata(pdev);
88 -
89 - clk_disable_unprepare(mt->clk_peri_therm);
90 - clk_disable_unprepare(mt->clk_auxadc);
91 -
92 - return 0;
93 }
94
95 static struct platform_driver mtk_thermal_driver = {
96 .probe = mtk_thermal_probe,
97 - .remove = mtk_thermal_remove,
98 .driver = {
99 .name = "mtk-thermal",
100 .of_match_table = mtk_thermal_of_match,