Blame view

drivers/acpi/fan.c 5.42 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  /*
   *  acpi_fan.c - ACPI Fan Driver ($Revision: 29 $)
   *
   *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
   *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
   *
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or (at
   *  your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful, but
   *  WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   *  General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License along
   *  with this program; if not, write to the Free Software Foundation, Inc.,
   *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
   *
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   */
  
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/types.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  #include <asm/uaccess.h>
05a83d972   Zhang Rui   ACPI: register AC...
31
  #include <linux/thermal.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
  #include <acpi/acpi_bus.h>
  #include <acpi/acpi_drivers.h>
a192a9580   Len Brown   ACPI: Move defini...
34
  #define PREFIX "ACPI: "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
  #define ACPI_FAN_CLASS			"fan"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
  #define ACPI_FAN_FILE_STATE		"state"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
  
  #define _COMPONENT		ACPI_FAN_COMPONENT
f52fd66d2   Len Brown   ACPI: clean up AC...
39
  ACPI_MODULE_NAME("fan");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40

f52fd66d2   Len Brown   ACPI: clean up AC...
41
  MODULE_AUTHOR("Paul Diefenbaugh");
7cda93e00   Len Brown   ACPI: delete extr...
42
  MODULE_DESCRIPTION("ACPI Fan Driver");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  MODULE_LICENSE("GPL");
4be44fcd3   Len Brown   [ACPI] Lindent al...
44
  static int acpi_fan_add(struct acpi_device *device);
51fac8388   Rafael J. Wysocki   ACPI: Remove usel...
45
  static int acpi_fan_remove(struct acpi_device *device);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46

1ba90e3a8   Thomas Renninger   ACPI: autoload mo...
47
48
49
50
51
  static const struct acpi_device_id fan_device_ids[] = {
  	{"PNP0C0B", 0},
  	{"", 0},
  };
  MODULE_DEVICE_TABLE(acpi, fan_device_ids);
906924048   Rafael J. Wysocki   ACPI / PM: Fix un...
52
  #ifdef CONFIG_PM_SLEEP
62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
53
54
  static int acpi_fan_suspend(struct device *dev);
  static int acpi_fan_resume(struct device *dev);
906924048   Rafael J. Wysocki   ACPI / PM: Fix un...
55
  #endif
62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
56
  static SIMPLE_DEV_PM_OPS(acpi_fan_pm, acpi_fan_suspend, acpi_fan_resume);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
  static struct acpi_driver acpi_fan_driver = {
c2b6705b7   Len Brown   ACPI: fix acpi_dr...
58
  	.name = "fan",
4be44fcd3   Len Brown   [ACPI] Lindent al...
59
  	.class = ACPI_FAN_CLASS,
1ba90e3a8   Thomas Renninger   ACPI: autoload mo...
60
  	.ids = fan_device_ids,
4be44fcd3   Len Brown   [ACPI] Lindent al...
61
62
63
64
  	.ops = {
  		.add = acpi_fan_add,
  		.remove = acpi_fan_remove,
  		},
62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
65
  	.drv.pm = &acpi_fan_pm,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
  };
05a83d972   Zhang Rui   ACPI: register AC...
67
  /* thermal cooling device callbacks */
6503e5df0   Matthew Garrett   thermal: use inte...
68
69
  static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
  			     *state)
05a83d972   Zhang Rui   ACPI: register AC...
70
71
  {
  	/* ACPI fan device only support two states: ON/OFF */
6503e5df0   Matthew Garrett   thermal: use inte...
72
73
  	*state = 1;
  	return 0;
05a83d972   Zhang Rui   ACPI: register AC...
74
  }
6503e5df0   Matthew Garrett   thermal: use inte...
75
76
  static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
  			     *state)
05a83d972   Zhang Rui   ACPI: register AC...
77
78
  {
  	struct acpi_device *device = cdev->devdata;
05a83d972   Zhang Rui   ACPI: register AC...
79
  	int result;
6503e5df0   Matthew Garrett   thermal: use inte...
80
  	int acpi_state;
05a83d972   Zhang Rui   ACPI: register AC...
81
82
83
  
  	if (!device)
  		return -EINVAL;
488a76c52   Rafael J. Wysocki   ACPI / Fan: Rewor...
84
  	result = acpi_bus_update_power(device->handle, &acpi_state);
05a83d972   Zhang Rui   ACPI: register AC...
85
86
  	if (result)
  		return result;
6503e5df0   Matthew Garrett   thermal: use inte...
87
88
89
  	*state = (acpi_state == ACPI_STATE_D3 ? 0 :
  		 (acpi_state == ACPI_STATE_D0 ? 1 : -1));
  	return 0;
05a83d972   Zhang Rui   ACPI: register AC...
90
91
92
  }
  
  static int
6503e5df0   Matthew Garrett   thermal: use inte...
93
  fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
05a83d972   Zhang Rui   ACPI: register AC...
94
95
96
97
98
99
100
101
102
103
104
105
  {
  	struct acpi_device *device = cdev->devdata;
  	int result;
  
  	if (!device || (state != 0 && state != 1))
  		return -EINVAL;
  
  	result = acpi_bus_set_power(device->handle,
  				state ? ACPI_STATE_D0 : ACPI_STATE_D3);
  
  	return result;
  }
9c8b04be4   Vasiliy Kulikov   ACPI: constify op...
106
  static const struct thermal_cooling_device_ops fan_cooling_ops = {
05a83d972   Zhang Rui   ACPI: register AC...
107
108
109
110
  	.get_max_state = fan_get_max_state,
  	.get_cur_state = fan_get_cur_state,
  	.set_cur_state = fan_set_cur_state,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
  /* --------------------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
113
                                   Driver Interface
     -------------------------------------------------------------------------- */
4be44fcd3   Len Brown   [ACPI] Lindent al...
114
  static int acpi_fan_add(struct acpi_device *device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
116
  	int result = 0;
05a83d972   Zhang Rui   ACPI: register AC...
117
  	struct thermal_cooling_device *cdev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
119
  
  	if (!device)
d550d98d3   Patrick Mochel   ACPI: delete trac...
120
  		return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121

c65ade4dc   Pavel Machek   [ACPI] whitespace
122
  	strcpy(acpi_device_name(device), "Fan");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
  	strcpy(acpi_device_class(device), ACPI_FAN_CLASS);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124

488a76c52   Rafael J. Wysocki   ACPI / Fan: Rewor...
125
  	result = acpi_bus_update_power(device->handle, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
  	if (result) {
488a76c52   Rafael J. Wysocki   ACPI / Fan: Rewor...
127
128
  		printk(KERN_ERR PREFIX "Setting initial power state
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
  		goto end;
  	}
05a83d972   Zhang Rui   ACPI: register AC...
131
132
  	cdev = thermal_cooling_device_register("Fan", device,
  						&fan_cooling_ops);
19b36780e   Thomas Sujith   ACPI fan: extract...
133
134
135
136
  	if (IS_ERR(cdev)) {
  		result = PTR_ERR(cdev);
  		goto end;
  	}
9030062f3   Julia Lawall   ACPI: elide a non...
137

13c411570   Mike Travis   ACPI: Remove repe...
138
139
  	dev_dbg(&device->dev, "registered as cooling_device%d
  ", cdev->id);
9030062f3   Julia Lawall   ACPI: elide a non...
140

db89b4f0d   Pavel Machek   ACPI: catch calls...
141
  	device->driver_data = cdev;
9030062f3   Julia Lawall   ACPI: elide a non...
142
143
144
145
  	result = sysfs_create_link(&device->dev.kobj,
  				   &cdev->device.kobj,
  				   "thermal_cooling");
  	if (result)
fc3a8828b   Greg Kroah-Hartman   driver core: fix ...
146
147
148
  		dev_err(&device->dev, "Failed to create sysfs link "
  			"'thermal_cooling'
  ");
9030062f3   Julia Lawall   ACPI: elide a non...
149
150
151
152
153
  
  	result = sysfs_create_link(&cdev->device.kobj,
  				   &device->dev.kobj,
  				   "device");
  	if (result)
fc3a8828b   Greg Kroah-Hartman   driver core: fix ...
154
155
156
  		dev_err(&device->dev, "Failed to create sysfs link "
  			"'device'
  ");
05a83d972   Zhang Rui   ACPI: register AC...
157

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
158
159
  	printk(KERN_INFO PREFIX "%s [%s] (%s)
  ",
4be44fcd3   Len Brown   [ACPI] Lindent al...
160
161
  	       acpi_device_name(device), acpi_device_bid(device),
  	       !device->power.state ? "on" : "off");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162

4be44fcd3   Len Brown   [ACPI] Lindent al...
163
        end:
d550d98d3   Patrick Mochel   ACPI: delete trac...
164
  	return result;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
  }
51fac8388   Rafael J. Wysocki   ACPI: Remove usel...
166
  static int acpi_fan_remove(struct acpi_device *device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
167
  {
05a83d972   Zhang Rui   ACPI: register AC...
168
169
170
  	struct thermal_cooling_device *cdev = acpi_driver_data(device);
  
  	if (!device || !cdev)
d550d98d3   Patrick Mochel   ACPI: delete trac...
171
  		return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172

05a83d972   Zhang Rui   ACPI: register AC...
173
174
175
  	sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
  	sysfs_remove_link(&cdev->device.kobj, "device");
  	thermal_cooling_device_unregister(cdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176

d550d98d3   Patrick Mochel   ACPI: delete trac...
177
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
  }
906924048   Rafael J. Wysocki   ACPI / PM: Fix un...
179
  #ifdef CONFIG_PM_SLEEP
62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
180
  static int acpi_fan_suspend(struct device *dev)
ec68373c0   Len Brown   Revert "ACPI: Fan...
181
  {
62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
182
  	if (!dev)
ec68373c0   Len Brown   Revert "ACPI: Fan...
183
  		return -EINVAL;
62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
184
  	acpi_bus_set_power(to_acpi_device(dev)->handle, ACPI_STATE_D0);
ec68373c0   Len Brown   Revert "ACPI: Fan...
185
186
187
  
  	return AE_OK;
  }
62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
188
  static int acpi_fan_resume(struct device *dev)
ec68373c0   Len Brown   Revert "ACPI: Fan...
189
  {
488a76c52   Rafael J. Wysocki   ACPI / Fan: Rewor...
190
  	int result;
ec68373c0   Len Brown   Revert "ACPI: Fan...
191

62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
192
  	if (!dev)
ec68373c0   Len Brown   Revert "ACPI: Fan...
193
  		return -EINVAL;
62fcbdd95   Rafael J. Wysocki   ACPI: Use struct ...
194
  	result = acpi_bus_update_power(to_acpi_device(dev)->handle, NULL);
488a76c52   Rafael J. Wysocki   ACPI / Fan: Rewor...
195
196
197
  	if (result)
  		printk(KERN_ERR PREFIX "Error updating fan power state
  ");
ec68373c0   Len Brown   Revert "ACPI: Fan...
198
199
200
  
  	return result;
  }
906924048   Rafael J. Wysocki   ACPI / PM: Fix un...
201
  #endif
ec68373c0   Len Brown   Revert "ACPI: Fan...
202

d8014c4b2   Mika Westerberg   ACPI/fan: convert...
203
  module_acpi_driver(acpi_fan_driver);