ACPI / fan: convert to platform driver
[deliverable/linux.git] / drivers / acpi / fan.c
CommitLineData
1da177e4
LT
1/*
2 * acpi_fan.c - ACPI Fan Driver ($Revision: 29 $)
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/types.h>
1da177e4 30#include <asm/uaccess.h>
05a83d97 31#include <linux/thermal.h>
8b48463f 32#include <linux/acpi.h>
19593a1f 33#include <linux/platform_device.h>
1da177e4 34
f52fd66d 35MODULE_AUTHOR("Paul Diefenbaugh");
7cda93e0 36MODULE_DESCRIPTION("ACPI Fan Driver");
1da177e4
LT
37MODULE_LICENSE("GPL");
38
19593a1f
AL
39static int acpi_fan_probe(struct platform_device *pdev);
40static int acpi_fan_remove(struct platform_device *pdev);
1da177e4 41
1ba90e3a
TR
42static const struct acpi_device_id fan_device_ids[] = {
43 {"PNP0C0B", 0},
44 {"", 0},
45};
46MODULE_DEVICE_TABLE(acpi, fan_device_ids);
47
90692404 48#ifdef CONFIG_PM_SLEEP
62fcbdd9
RW
49static int acpi_fan_suspend(struct device *dev);
50static int acpi_fan_resume(struct device *dev);
b9b8515f
AL
51static struct dev_pm_ops acpi_fan_pm = {
52 .resume = acpi_fan_resume,
53 .freeze = acpi_fan_suspend,
54 .thaw = acpi_fan_resume,
55 .restore = acpi_fan_resume,
56};
57#define FAN_PM_OPS_PTR (&acpi_fan_pm)
b108e0ea 58#else
b9b8515f 59#define FAN_PM_OPS_PTR NULL
90692404 60#endif
62fcbdd9 61
19593a1f
AL
62static struct platform_driver acpi_fan_driver = {
63 .probe = acpi_fan_probe,
64 .remove = acpi_fan_remove,
65 .driver = {
66 .name = "acpi-fan",
67 .acpi_match_table = fan_device_ids,
68 .pm = FAN_PM_OPS_PTR,
69 },
1da177e4
LT
70};
71
05a83d97 72/* thermal cooling device callbacks */
6503e5df
MG
73static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
74 *state)
05a83d97
ZR
75{
76 /* ACPI fan device only support two states: ON/OFF */
6503e5df
MG
77 *state = 1;
78 return 0;
05a83d97
ZR
79}
80
6503e5df
MG
81static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
82 *state)
05a83d97
ZR
83{
84 struct acpi_device *device = cdev->devdata;
05a83d97 85 int result;
85eb9827 86 int acpi_state = ACPI_STATE_D0;
05a83d97
ZR
87
88 if (!device)
89 return -EINVAL;
90
2bb3a2bf 91 result = acpi_device_update_power(device, &acpi_state);
05a83d97
ZR
92 if (result)
93 return result;
94
8ad928d5 95 *state = (acpi_state == ACPI_STATE_D3_COLD ? 0 :
6503e5df
MG
96 (acpi_state == ACPI_STATE_D0 ? 1 : -1));
97 return 0;
05a83d97
ZR
98}
99
100static int
6503e5df 101fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
05a83d97
ZR
102{
103 struct acpi_device *device = cdev->devdata;
104 int result;
105
106 if (!device || (state != 0 && state != 1))
107 return -EINVAL;
108
2bb3a2bf 109 result = acpi_device_set_power(device,
8ad928d5 110 state ? ACPI_STATE_D0 : ACPI_STATE_D3_COLD);
05a83d97
ZR
111
112 return result;
113}
114
9c8b04be 115static const struct thermal_cooling_device_ops fan_cooling_ops = {
05a83d97
ZR
116 .get_max_state = fan_get_max_state,
117 .get_cur_state = fan_get_cur_state,
118 .set_cur_state = fan_set_cur_state,
119};
120
1da177e4
LT
121/* --------------------------------------------------------------------------
122 Driver Interface
123 -------------------------------------------------------------------------- */
124
19593a1f 125static int acpi_fan_probe(struct platform_device *pdev)
1da177e4 126{
4be44fcd 127 int result = 0;
05a83d97 128 struct thermal_cooling_device *cdev;
19593a1f 129 struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
1da177e4 130
2bb3a2bf 131 result = acpi_device_update_power(device, NULL);
1da177e4 132 if (result) {
19593a1f 133 dev_err(&pdev->dev, "Setting initial power state\n");
1da177e4
LT
134 goto end;
135 }
136
05a83d97
ZR
137 cdev = thermal_cooling_device_register("Fan", device,
138 &fan_cooling_ops);
19b36780
TS
139 if (IS_ERR(cdev)) {
140 result = PTR_ERR(cdev);
141 goto end;
142 }
9030062f 143
19593a1f 144 dev_dbg(&pdev->dev, "registered as cooling_device%d\n", cdev->id);
9030062f 145
19593a1f
AL
146 platform_set_drvdata(pdev, cdev);
147 result = sysfs_create_link(&pdev->dev.kobj,
9030062f
JL
148 &cdev->device.kobj,
149 "thermal_cooling");
150 if (result)
19593a1f 151 dev_err(&pdev->dev, "Failed to create sysfs link "
fc3a8828 152 "'thermal_cooling'\n");
9030062f
JL
153
154 result = sysfs_create_link(&cdev->device.kobj,
19593a1f 155 &pdev->dev.kobj,
9030062f
JL
156 "device");
157 if (result)
19593a1f 158 dev_err(&pdev->dev, "Failed to create sysfs link "
fc3a8828 159 "'device'\n");
05a83d97 160
19593a1f 161 dev_info(&pdev->dev, "%s [%s] (%s)\n",
4be44fcd
LB
162 acpi_device_name(device), acpi_device_bid(device),
163 !device->power.state ? "on" : "off");
1da177e4 164
568b6ad8 165end:
d550d98d 166 return result;
1da177e4
LT
167}
168
19593a1f 169static int acpi_fan_remove(struct platform_device *pdev)
1da177e4 170{
19593a1f 171 struct thermal_cooling_device *cdev = platform_get_drvdata(pdev);
1da177e4 172
19593a1f 173 sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
05a83d97
ZR
174 sysfs_remove_link(&cdev->device.kobj, "device");
175 thermal_cooling_device_unregister(cdev);
1da177e4 176
d550d98d 177 return 0;
1da177e4
LT
178}
179
90692404 180#ifdef CONFIG_PM_SLEEP
62fcbdd9 181static int acpi_fan_suspend(struct device *dev)
ec68373c 182{
19593a1f 183 acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D0);
ec68373c
LB
184
185 return AE_OK;
186}
187
62fcbdd9 188static int acpi_fan_resume(struct device *dev)
ec68373c 189{
488a76c5 190 int result;
ec68373c 191
19593a1f 192 result = acpi_device_update_power(ACPI_COMPANION(dev), NULL);
488a76c5 193 if (result)
19593a1f 194 dev_err(dev, "Error updating fan power state\n");
ec68373c
LB
195
196 return result;
197}
90692404 198#endif
ec68373c 199
19593a1f 200module_platform_driver(acpi_fan_driver);
This page took 0.824068 seconds and 5 git commands to generate.