aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/ac.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/ac.c')
-rw-r--r--drivers/acpi/ac.c63
1 files changed, 23 insertions, 40 deletions
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 7839b831df94..36ca365bcead 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -84,20 +84,18 @@ static int acpi_ac_get_state(struct acpi_ac *ac)
84{ 84{
85 acpi_status status = AE_OK; 85 acpi_status status = AE_OK;
86 86
87 ACPI_FUNCTION_TRACE("acpi_ac_get_state");
88 87
89 if (!ac) 88 if (!ac)
90 return_VALUE(-EINVAL); 89 return -EINVAL;
91 90
92 status = acpi_evaluate_integer(ac->handle, "_PSR", NULL, &ac->state); 91 status = acpi_evaluate_integer(ac->handle, "_PSR", NULL, &ac->state);
93 if (ACPI_FAILURE(status)) { 92 if (ACPI_FAILURE(status)) {
94 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 93 ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state"));
95 "Error reading AC Adapter state\n"));
96 ac->state = ACPI_AC_STATUS_UNKNOWN; 94 ac->state = ACPI_AC_STATUS_UNKNOWN;
97 return_VALUE(-ENODEV); 95 return -ENODEV;
98 } 96 }
99 97
100 return_VALUE(0); 98 return 0;
101} 99}
102 100
103/* -------------------------------------------------------------------------- 101/* --------------------------------------------------------------------------
@@ -110,14 +108,13 @@ static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
110{ 108{
111 struct acpi_ac *ac = (struct acpi_ac *)seq->private; 109 struct acpi_ac *ac = (struct acpi_ac *)seq->private;
112 110
113 ACPI_FUNCTION_TRACE("acpi_ac_seq_show");
114 111
115 if (!ac) 112 if (!ac)
116 return_VALUE(0); 113 return 0;
117 114
118 if (acpi_ac_get_state(ac)) { 115 if (acpi_ac_get_state(ac)) {
119 seq_puts(seq, "ERROR: Unable to read AC Adapter state\n"); 116 seq_puts(seq, "ERROR: Unable to read AC Adapter state\n");
120 return_VALUE(0); 117 return 0;
121 } 118 }
122 119
123 seq_puts(seq, "state: "); 120 seq_puts(seq, "state: ");
@@ -133,7 +130,7 @@ static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
133 break; 130 break;
134 } 131 }
135 132
136 return_VALUE(0); 133 return 0;
137} 134}
138 135
139static int acpi_ac_open_fs(struct inode *inode, struct file *file) 136static int acpi_ac_open_fs(struct inode *inode, struct file *file)
@@ -145,13 +142,12 @@ static int acpi_ac_add_fs(struct acpi_device *device)
145{ 142{
146 struct proc_dir_entry *entry = NULL; 143 struct proc_dir_entry *entry = NULL;
147 144
148 ACPI_FUNCTION_TRACE("acpi_ac_add_fs");
149 145
150 if (!acpi_device_dir(device)) { 146 if (!acpi_device_dir(device)) {
151 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 147 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
152 acpi_ac_dir); 148 acpi_ac_dir);
153 if (!acpi_device_dir(device)) 149 if (!acpi_device_dir(device))
154 return_VALUE(-ENODEV); 150 return -ENODEV;
155 acpi_device_dir(device)->owner = THIS_MODULE; 151 acpi_device_dir(device)->owner = THIS_MODULE;
156 } 152 }
157 153
@@ -159,21 +155,18 @@ static int acpi_ac_add_fs(struct acpi_device *device)
159 entry = create_proc_entry(ACPI_AC_FILE_STATE, 155 entry = create_proc_entry(ACPI_AC_FILE_STATE,
160 S_IRUGO, acpi_device_dir(device)); 156 S_IRUGO, acpi_device_dir(device));
161 if (!entry) 157 if (!entry)
162 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 158 return -ENODEV;
163 "Unable to create '%s' fs entry\n",
164 ACPI_AC_FILE_STATE));
165 else { 159 else {
166 entry->proc_fops = &acpi_ac_fops; 160 entry->proc_fops = &acpi_ac_fops;
167 entry->data = acpi_driver_data(device); 161 entry->data = acpi_driver_data(device);
168 entry->owner = THIS_MODULE; 162 entry->owner = THIS_MODULE;
169 } 163 }
170 164
171 return_VALUE(0); 165 return 0;
172} 166}
173 167
174static int acpi_ac_remove_fs(struct acpi_device *device) 168static int acpi_ac_remove_fs(struct acpi_device *device)
175{ 169{
176 ACPI_FUNCTION_TRACE("acpi_ac_remove_fs");
177 170
178 if (acpi_device_dir(device)) { 171 if (acpi_device_dir(device)) {
179 remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device)); 172 remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device));
@@ -182,7 +175,7 @@ static int acpi_ac_remove_fs(struct acpi_device *device)
182 acpi_device_dir(device) = NULL; 175 acpi_device_dir(device) = NULL;
183 } 176 }
184 177
185 return_VALUE(0); 178 return 0;
186} 179}
187 180
188/* -------------------------------------------------------------------------- 181/* --------------------------------------------------------------------------
@@ -194,13 +187,12 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
194 struct acpi_ac *ac = (struct acpi_ac *)data; 187 struct acpi_ac *ac = (struct acpi_ac *)data;
195 struct acpi_device *device = NULL; 188 struct acpi_device *device = NULL;
196 189
197 ACPI_FUNCTION_TRACE("acpi_ac_notify");
198 190
199 if (!ac) 191 if (!ac)
200 return_VOID; 192 return;
201 193
202 if (acpi_bus_get_device(ac->handle, &device)) 194 if (acpi_bus_get_device(ac->handle, &device))
203 return_VOID; 195 return;
204 196
205 switch (event) { 197 switch (event) {
206 case ACPI_AC_NOTIFY_STATUS: 198 case ACPI_AC_NOTIFY_STATUS:
@@ -213,7 +205,7 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
213 break; 205 break;
214 } 206 }
215 207
216 return_VOID; 208 return;
217} 209}
218 210
219static int acpi_ac_add(struct acpi_device *device) 211static int acpi_ac_add(struct acpi_device *device)
@@ -222,14 +214,13 @@ static int acpi_ac_add(struct acpi_device *device)
222 acpi_status status = AE_OK; 214 acpi_status status = AE_OK;
223 struct acpi_ac *ac = NULL; 215 struct acpi_ac *ac = NULL;
224 216
225 ACPI_FUNCTION_TRACE("acpi_ac_add");
226 217
227 if (!device) 218 if (!device)
228 return_VALUE(-EINVAL); 219 return -EINVAL;
229 220
230 ac = kmalloc(sizeof(struct acpi_ac), GFP_KERNEL); 221 ac = kmalloc(sizeof(struct acpi_ac), GFP_KERNEL);
231 if (!ac) 222 if (!ac)
232 return_VALUE(-ENOMEM); 223 return -ENOMEM;
233 memset(ac, 0, sizeof(struct acpi_ac)); 224 memset(ac, 0, sizeof(struct acpi_ac));
234 225
235 ac->handle = device->handle; 226 ac->handle = device->handle;
@@ -249,8 +240,6 @@ static int acpi_ac_add(struct acpi_device *device)
249 ACPI_DEVICE_NOTIFY, acpi_ac_notify, 240 ACPI_DEVICE_NOTIFY, acpi_ac_notify,
250 ac); 241 ac);
251 if (ACPI_FAILURE(status)) { 242 if (ACPI_FAILURE(status)) {
252 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
253 "Error installing notify handler\n"));
254 result = -ENODEV; 243 result = -ENODEV;
255 goto end; 244 goto end;
256 } 245 }
@@ -265,7 +254,7 @@ static int acpi_ac_add(struct acpi_device *device)
265 kfree(ac); 254 kfree(ac);
266 } 255 }
267 256
268 return_VALUE(result); 257 return result;
269} 258}
270 259
271static int acpi_ac_remove(struct acpi_device *device, int type) 260static int acpi_ac_remove(struct acpi_device *device, int type)
@@ -273,55 +262,49 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
273 acpi_status status = AE_OK; 262 acpi_status status = AE_OK;
274 struct acpi_ac *ac = NULL; 263 struct acpi_ac *ac = NULL;
275 264
276 ACPI_FUNCTION_TRACE("acpi_ac_remove");
277 265
278 if (!device || !acpi_driver_data(device)) 266 if (!device || !acpi_driver_data(device))
279 return_VALUE(-EINVAL); 267 return -EINVAL;
280 268
281 ac = (struct acpi_ac *)acpi_driver_data(device); 269 ac = (struct acpi_ac *)acpi_driver_data(device);
282 270
283 status = acpi_remove_notify_handler(ac->handle, 271 status = acpi_remove_notify_handler(ac->handle,
284 ACPI_DEVICE_NOTIFY, acpi_ac_notify); 272 ACPI_DEVICE_NOTIFY, acpi_ac_notify);
285 if (ACPI_FAILURE(status))
286 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
287 "Error removing notify handler\n"));
288 273
289 acpi_ac_remove_fs(device); 274 acpi_ac_remove_fs(device);
290 275
291 kfree(ac); 276 kfree(ac);
292 277
293 return_VALUE(0); 278 return 0;
294} 279}
295 280
296static int __init acpi_ac_init(void) 281static int __init acpi_ac_init(void)
297{ 282{
298 int result = 0; 283 int result = 0;
299 284
300 ACPI_FUNCTION_TRACE("acpi_ac_init");
301 285
302 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir); 286 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
303 if (!acpi_ac_dir) 287 if (!acpi_ac_dir)
304 return_VALUE(-ENODEV); 288 return -ENODEV;
305 acpi_ac_dir->owner = THIS_MODULE; 289 acpi_ac_dir->owner = THIS_MODULE;
306 290
307 result = acpi_bus_register_driver(&acpi_ac_driver); 291 result = acpi_bus_register_driver(&acpi_ac_driver);
308 if (result < 0) { 292 if (result < 0) {
309 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); 293 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
310 return_VALUE(-ENODEV); 294 return -ENODEV;
311 } 295 }
312 296
313 return_VALUE(0); 297 return 0;
314} 298}
315 299
316static void __exit acpi_ac_exit(void) 300static void __exit acpi_ac_exit(void)
317{ 301{
318 ACPI_FUNCTION_TRACE("acpi_ac_exit");
319 302
320 acpi_bus_unregister_driver(&acpi_ac_driver); 303 acpi_bus_unregister_driver(&acpi_ac_driver);
321 304
322 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); 305 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
323 306
324 return_VOID; 307 return;
325} 308}
326 309
327module_init(acpi_ac_init); 310module_init(acpi_ac_init);