hongbo.zhang | aa1acb0 | 2012-11-15 18:56:42 +0800 | [diff] [blame] | 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/cpufreq.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/module.h> |
Sachin Kamat | c076fc4 | 2012-12-19 14:20:59 +0530 | [diff] [blame] | 24 | #include <linux/of.h> |
hongbo.zhang | aa1acb0 | 2012-11-15 18:56:42 +0800 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/slab.h> |
| 27 | |
| 28 | static int db8500_cpufreq_cooling_probe(struct platform_device *pdev) |
| 29 | { |
| 30 | struct thermal_cooling_device *cdev; |
| 31 | struct cpumask mask_val; |
| 32 | |
| 33 | /* make sure cpufreq driver has been initialized */ |
| 34 | if (!cpufreq_frequency_get_table(0)) |
| 35 | return -EPROBE_DEFER; |
| 36 | |
| 37 | cpumask_set_cpu(0, &mask_val); |
| 38 | cdev = cpufreq_cooling_register(&mask_val); |
| 39 | |
Eduardo Valentin | 70d23b2 | 2013-04-25 14:13:34 +0000 | [diff] [blame] | 40 | if (IS_ERR(cdev)) { |
hongbo.zhang | aa1acb0 | 2012-11-15 18:56:42 +0800 | [diff] [blame] | 41 | dev_err(&pdev->dev, "Failed to register cooling device\n"); |
| 42 | return PTR_ERR(cdev); |
| 43 | } |
| 44 | |
| 45 | platform_set_drvdata(pdev, cdev); |
| 46 | |
| 47 | dev_info(&pdev->dev, "Cooling device registered: %s\n", cdev->type); |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int db8500_cpufreq_cooling_remove(struct platform_device *pdev) |
| 53 | { |
| 54 | struct thermal_cooling_device *cdev = platform_get_drvdata(pdev); |
| 55 | |
| 56 | cpufreq_cooling_unregister(cdev); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static int db8500_cpufreq_cooling_suspend(struct platform_device *pdev, |
| 62 | pm_message_t state) |
| 63 | { |
| 64 | return -ENOSYS; |
| 65 | } |
| 66 | |
| 67 | static int db8500_cpufreq_cooling_resume(struct platform_device *pdev) |
| 68 | { |
| 69 | return -ENOSYS; |
| 70 | } |
| 71 | |
| 72 | #ifdef CONFIG_OF |
| 73 | static const struct of_device_id db8500_cpufreq_cooling_match[] = { |
| 74 | { .compatible = "stericsson,db8500-cpufreq-cooling" }, |
| 75 | {}, |
| 76 | }; |
hongbo.zhang | aa1acb0 | 2012-11-15 18:56:42 +0800 | [diff] [blame] | 77 | #endif |
| 78 | |
| 79 | static struct platform_driver db8500_cpufreq_cooling_driver = { |
| 80 | .driver = { |
| 81 | .owner = THIS_MODULE, |
| 82 | .name = "db8500-cpufreq-cooling", |
Sachin Kamat | c076fc4 | 2012-12-19 14:20:59 +0530 | [diff] [blame] | 83 | .of_match_table = of_match_ptr(db8500_cpufreq_cooling_match), |
hongbo.zhang | aa1acb0 | 2012-11-15 18:56:42 +0800 | [diff] [blame] | 84 | }, |
| 85 | .probe = db8500_cpufreq_cooling_probe, |
| 86 | .suspend = db8500_cpufreq_cooling_suspend, |
| 87 | .resume = db8500_cpufreq_cooling_resume, |
| 88 | .remove = db8500_cpufreq_cooling_remove, |
| 89 | }; |
| 90 | |
| 91 | static int __init db8500_cpufreq_cooling_init(void) |
| 92 | { |
| 93 | return platform_driver_register(&db8500_cpufreq_cooling_driver); |
| 94 | } |
| 95 | |
| 96 | static void __exit db8500_cpufreq_cooling_exit(void) |
| 97 | { |
| 98 | platform_driver_unregister(&db8500_cpufreq_cooling_driver); |
| 99 | } |
| 100 | |
| 101 | /* Should be later than db8500_cpufreq_register */ |
| 102 | late_initcall(db8500_cpufreq_cooling_init); |
| 103 | module_exit(db8500_cpufreq_cooling_exit); |
| 104 | |
| 105 | MODULE_AUTHOR("Hongbo Zhang <hongbo.zhang@stericsson.com>"); |
| 106 | MODULE_DESCRIPTION("DB8500 cpufreq cooling driver"); |
| 107 | MODULE_LICENSE("GPL"); |