thermal: cpu_cooling: check for the readiness of cpufreq layer
[linux-2.6-microblaze.git] / drivers / thermal / db8500_cpufreq_cooling.c
1 /*
2  * db8500_cpufreq_cooling.c - DB8500 cpufreq works as cooling device.
3  *
4  * Copyright (C) 2012 ST-Ericsson
5  * Copyright (C) 2012 Linaro Ltd.
6  *
7  * Author: Hongbo Zhang <hongbo.zhang@linaro.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  */
19
20 #include <linux/cpu_cooling.h>
21 #include <linux/err.h>
22 #include <linux/module.h>
23 #include <linux/of.h>
24 #include <linux/platform_device.h>
25 #include <linux/slab.h>
26
27 static int db8500_cpufreq_cooling_probe(struct platform_device *pdev)
28 {
29         struct thermal_cooling_device *cdev;
30         struct cpumask mask_val;
31
32         cpumask_set_cpu(0, &mask_val);
33         cdev = cpufreq_cooling_register(&mask_val);
34
35         if (IS_ERR(cdev)) {
36                 dev_err(&pdev->dev, "Failed to register cooling device\n");
37                 return PTR_ERR(cdev);
38         }
39
40         platform_set_drvdata(pdev, cdev);
41
42         dev_info(&pdev->dev, "Cooling device registered: %s\n", cdev->type);
43
44         return 0;
45 }
46
47 static int db8500_cpufreq_cooling_remove(struct platform_device *pdev)
48 {
49         struct thermal_cooling_device *cdev = platform_get_drvdata(pdev);
50
51         cpufreq_cooling_unregister(cdev);
52
53         return 0;
54 }
55
56 static int db8500_cpufreq_cooling_suspend(struct platform_device *pdev,
57                 pm_message_t state)
58 {
59         return -ENOSYS;
60 }
61
62 static int db8500_cpufreq_cooling_resume(struct platform_device *pdev)
63 {
64         return -ENOSYS;
65 }
66
67 #ifdef CONFIG_OF
68 static const struct of_device_id db8500_cpufreq_cooling_match[] = {
69         { .compatible = "stericsson,db8500-cpufreq-cooling" },
70         {},
71 };
72 #endif
73
74 static struct platform_driver db8500_cpufreq_cooling_driver = {
75         .driver = {
76                 .owner = THIS_MODULE,
77                 .name = "db8500-cpufreq-cooling",
78                 .of_match_table = of_match_ptr(db8500_cpufreq_cooling_match),
79         },
80         .probe = db8500_cpufreq_cooling_probe,
81         .suspend = db8500_cpufreq_cooling_suspend,
82         .resume = db8500_cpufreq_cooling_resume,
83         .remove = db8500_cpufreq_cooling_remove,
84 };
85
86 static int __init db8500_cpufreq_cooling_init(void)
87 {
88         return platform_driver_register(&db8500_cpufreq_cooling_driver);
89 }
90
91 static void __exit db8500_cpufreq_cooling_exit(void)
92 {
93         platform_driver_unregister(&db8500_cpufreq_cooling_driver);
94 }
95
96 /* Should be later than db8500_cpufreq_register */
97 late_initcall(db8500_cpufreq_cooling_init);
98 module_exit(db8500_cpufreq_cooling_exit);
99
100 MODULE_AUTHOR("Hongbo Zhang <hongbo.zhang@stericsson.com>");
101 MODULE_DESCRIPTION("DB8500 cpufreq cooling driver");
102 MODULE_LICENSE("GPL");