]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/suse-2.6.27.31/patches.arch/acpi-bay-remove-useless-code.patch
Merge branch 'master' of git://git.ipfire.org/ipfire-2.x
[people/teissler/ipfire-2.x.git] / src / patches / suse-2.6.27.31 / patches.arch / acpi-bay-remove-useless-code.patch
1 From: Shaohua Li <shaohua.li@intel.com>
2 Subject: remove useless code
3 Patch-mainline: submitted 2008-08-28
4 References: fate#304731,bnc#401740
5
6 Bay driver is replaced by dock driver, remove it.
7
8 Signed-off-by: Shaohua Li <shaohua.li@intel.com>
9 Signed-off-by: Holger Macht <hmacht@suse.de>
10 ---
11
12 --- linux-2.6.26.orig/drivers/acpi/bay.c 2008-07-13 23:51:29.000000000 +0200
13 +++ linux-2.6.26/drivers/acpi/bay.c 1970-01-01 01:00:00.000000000 +0100
14 @@ -1,411 +0,0 @@
15 -/*
16 - * bay.c - ACPI removable drive bay driver
17 - *
18 - * Copyright (C) 2006 Kristen Carlson Accardi <kristen.c.accardi@intel.com>
19 - *
20 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 - *
22 - * This program is free software; you can redistribute it and/or modify
23 - * it under the terms of the GNU General Public License as published by
24 - * the Free Software Foundation; either version 2 of the License, or (at
25 - * your option) any later version.
26 - *
27 - * This program is distributed in the hope that it will be useful, but
28 - * WITHOUT ANY WARRANTY; without even the implied warranty of
29 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 - * General Public License for more details.
31 - *
32 - * You should have received a copy of the GNU General Public License along
33 - * with this program; if not, write to the Free Software Foundation, Inc.,
34 - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
35 - *
36 - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 - */
38 -#include <linux/kernel.h>
39 -#include <linux/module.h>
40 -#include <linux/init.h>
41 -#include <linux/types.h>
42 -#include <linux/notifier.h>
43 -#include <acpi/acpi_bus.h>
44 -#include <acpi/acpi_drivers.h>
45 -#include <linux/seq_file.h>
46 -#include <asm/uaccess.h>
47 -#include <linux/platform_device.h>
48 -
49 -ACPI_MODULE_NAME("bay");
50 -MODULE_AUTHOR("Kristen Carlson Accardi");
51 -MODULE_DESCRIPTION("ACPI Removable Drive Bay Driver");
52 -MODULE_LICENSE("GPL");
53 -#define ACPI_BAY_CLASS "bay"
54 -#define ACPI_BAY_COMPONENT 0x10000000
55 -#define _COMPONENT ACPI_BAY_COMPONENT
56 -#define bay_dprintk(h,s) {\
57 - char prefix[80] = {'\0'};\
58 - struct acpi_buffer buffer = {sizeof(prefix), prefix};\
59 - acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\
60 - printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); }
61 -static void bay_notify(acpi_handle handle, u32 event, void *data);
62 -
63 -static const struct acpi_device_id bay_device_ids[] = {
64 - {"LNXIOBAY", 0},
65 - {"", 0},
66 -};
67 -MODULE_DEVICE_TABLE(acpi, bay_device_ids);
68 -
69 -struct bay {
70 - acpi_handle handle;
71 - char *name;
72 - struct list_head list;
73 - struct platform_device *pdev;
74 -};
75 -
76 -static LIST_HEAD(drive_bays);
77 -
78 -
79 -/*****************************************************************************
80 - * Drive Bay functions *
81 - *****************************************************************************/
82 -/**
83 - * is_ejectable - see if a device is ejectable
84 - * @handle: acpi handle of the device
85 - *
86 - * If an acpi object has a _EJ0 method, then it is ejectable
87 - */
88 -static int is_ejectable(acpi_handle handle)
89 -{
90 - acpi_status status;
91 - acpi_handle tmp;
92 -
93 - status = acpi_get_handle(handle, "_EJ0", &tmp);
94 - if (ACPI_FAILURE(status))
95 - return 0;
96 - return 1;
97 -}
98 -
99 -/**
100 - * bay_present - see if the bay device is present
101 - * @bay: the drive bay
102 - *
103 - * execute the _STA method.
104 - */
105 -static int bay_present(struct bay *bay)
106 -{
107 - unsigned long long sta;
108 - acpi_status status;
109 -
110 - if (bay) {
111 - status = acpi_evaluate_integer(bay->handle, "_STA", NULL, &sta);
112 - if (ACPI_SUCCESS(status) && sta)
113 - return 1;
114 - }
115 - return 0;
116 -}
117 -
118 -/**
119 - * eject_device - respond to an eject request
120 - * @handle - the device to eject
121 - *
122 - * Call this devices _EJ0 method.
123 - */
124 -static void eject_device(acpi_handle handle)
125 -{
126 - struct acpi_object_list arg_list;
127 - union acpi_object arg;
128 -
129 - bay_dprintk(handle, "Ejecting device");
130 -
131 - arg_list.count = 1;
132 - arg_list.pointer = &arg;
133 - arg.type = ACPI_TYPE_INTEGER;
134 - arg.integer.value = 1;
135 -
136 - if (ACPI_FAILURE(acpi_evaluate_object(handle, "_EJ0",
137 - &arg_list, NULL)))
138 - pr_debug("Failed to evaluate _EJ0!\n");
139 -}
140 -
141 -/*
142 - * show_present - read method for "present" file in sysfs
143 - */
144 -static ssize_t show_present(struct device *dev,
145 - struct device_attribute *attr, char *buf)
146 -{
147 - struct bay *bay = dev_get_drvdata(dev);
148 - return snprintf(buf, PAGE_SIZE, "%d\n", bay_present(bay));
149 -
150 -}
151 -static DEVICE_ATTR(present, S_IRUGO, show_present, NULL);
152 -
153 -/*
154 - * write_eject - write method for "eject" file in sysfs
155 - */
156 -static ssize_t write_eject(struct device *dev, struct device_attribute *attr,
157 - const char *buf, size_t count)
158 -{
159 - struct bay *bay = dev_get_drvdata(dev);
160 -
161 - if (!count)
162 - return -EINVAL;
163 -
164 - eject_device(bay->handle);
165 - return count;
166 -}
167 -static DEVICE_ATTR(eject, S_IWUSR, NULL, write_eject);
168 -
169 -/**
170 - * is_ata - see if a device is an ata device
171 - * @handle: acpi handle of the device
172 - *
173 - * If an acpi object has one of 4 ATA ACPI methods defined,
174 - * then it is an ATA device
175 - */
176 -static int is_ata(acpi_handle handle)
177 -{
178 - acpi_handle tmp;
179 -
180 - if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
181 - (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
182 - (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
183 - (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
184 - return 1;
185 -
186 - return 0;
187 -}
188 -
189 -/**
190 - * parent_is_ata(acpi_handle handle)
191 - *
192 - */
193 -static int parent_is_ata(acpi_handle handle)
194 -{
195 - acpi_handle phandle;
196 -
197 - if (acpi_get_parent(handle, &phandle))
198 - return 0;
199 -
200 - return is_ata(phandle);
201 -}
202 -
203 -/**
204 - * is_ejectable_bay - see if a device is an ejectable drive bay
205 - * @handle: acpi handle of the device
206 - *
207 - * If an acpi object is ejectable and has one of the ACPI ATA
208 - * methods defined, then we can safely call it an ejectable
209 - * drive bay
210 - */
211 -static int is_ejectable_bay(acpi_handle handle)
212 -{
213 - if ((is_ata(handle) || parent_is_ata(handle)) && is_ejectable(handle))
214 - return 1;
215 - return 0;
216 -}
217 -
218 -#if 0
219 -/**
220 - * eject_removable_drive - try to eject this drive
221 - * @dev : the device structure of the drive
222 - *
223 - * If a device is a removable drive that requires an _EJ0 method
224 - * to be executed in order to safely remove from the system, do
225 - * it. ATM - always returns success
226 - */
227 -int eject_removable_drive(struct device *dev)
228 -{
229 - acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
230 -
231 - if (handle) {
232 - bay_dprintk(handle, "Got device handle");
233 - if (is_ejectable_bay(handle))
234 - eject_device(handle);
235 - } else {
236 - printk("No acpi handle for device\n");
237 - }
238 -
239 - /* should I return an error code? */
240 - return 0;
241 -}
242 -EXPORT_SYMBOL_GPL(eject_removable_drive);
243 -#endif /* 0 */
244 -
245 -static int acpi_bay_add_fs(struct bay *bay)
246 -{
247 - int ret;
248 - struct device *dev = &bay->pdev->dev;
249 -
250 - ret = device_create_file(dev, &dev_attr_present);
251 - if (ret)
252 - goto add_fs_err;
253 - ret = device_create_file(dev, &dev_attr_eject);
254 - if (ret) {
255 - device_remove_file(dev, &dev_attr_present);
256 - goto add_fs_err;
257 - }
258 - return 0;
259 -
260 - add_fs_err:
261 - bay_dprintk(bay->handle, "Error adding sysfs files\n");
262 - return ret;
263 -}
264 -
265 -static void acpi_bay_remove_fs(struct bay *bay)
266 -{
267 - struct device *dev = &bay->pdev->dev;
268 -
269 - /* cleanup sysfs */
270 - device_remove_file(dev, &dev_attr_present);
271 - device_remove_file(dev, &dev_attr_eject);
272 -}
273 -
274 -static int bay_is_dock_device(acpi_handle handle)
275 -{
276 - acpi_handle parent;
277 -
278 - acpi_get_parent(handle, &parent);
279 -
280 - /* if the device or it's parent is dependent on the
281 - * dock, then we are a dock device
282 - */
283 - return (is_dock_device(handle) || is_dock_device(parent));
284 -}
285 -
286 -static int bay_add(acpi_handle handle, int id)
287 -{
288 - acpi_status status;
289 - struct bay *new_bay;
290 - struct platform_device *pdev;
291 - struct acpi_buffer nbuffer = {ACPI_ALLOCATE_BUFFER, NULL};
292 - acpi_get_name(handle, ACPI_FULL_PATHNAME, &nbuffer);
293 -
294 - bay_dprintk(handle, "Adding notify handler");
295 -
296 - /*
297 - * Initialize bay device structure
298 - */
299 - new_bay = kzalloc(sizeof(*new_bay), GFP_ATOMIC);
300 - INIT_LIST_HEAD(&new_bay->list);
301 - new_bay->handle = handle;
302 - new_bay->name = (char *)nbuffer.pointer;
303 -
304 - /* initialize platform device stuff */
305 - pdev = platform_device_register_simple(ACPI_BAY_CLASS, id, NULL, 0);
306 - if (IS_ERR(pdev)) {
307 - printk(KERN_ERR PREFIX "Error registering bay device\n");
308 - goto bay_add_err;
309 - }
310 - new_bay->pdev = pdev;
311 - platform_set_drvdata(pdev, new_bay);
312 -
313 - /*
314 - * we want the bay driver to be able to send uevents
315 - */
316 - pdev->dev.uevent_suppress = 0;
317 -
318 - /* register for events on this device */
319 - status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
320 - bay_notify, new_bay);
321 - if (ACPI_FAILURE(status)) {
322 - printk(KERN_INFO PREFIX "Error installing bay notify handler\n");
323 - platform_device_unregister(new_bay->pdev);
324 - goto bay_add_err;
325 - }
326 -
327 - if (acpi_bay_add_fs(new_bay)) {
328 - acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
329 - bay_notify);
330 - platform_device_unregister(new_bay->pdev);
331 - goto bay_add_err;
332 - }
333 -
334 - /* if we are on a dock station, we should register for dock
335 - * notifications.
336 - */
337 - if (bay_is_dock_device(handle)) {
338 - bay_dprintk(handle, "Is dependent on dock\n");
339 - register_hotplug_dock_device(handle, bay_notify, new_bay);
340 - }
341 - list_add(&new_bay->list, &drive_bays);
342 - printk(KERN_INFO PREFIX "Bay [%s] Added\n", new_bay->name);
343 - return 0;
344 -
345 -bay_add_err:
346 - kfree(new_bay->name);
347 - kfree(new_bay);
348 - return -ENODEV;
349 -}
350 -
351 -/**
352 - * bay_notify - act upon an acpi bay notification
353 - * @handle: the bay handle
354 - * @event: the acpi event
355 - * @data: our driver data struct
356 - *
357 - */
358 -static void bay_notify(acpi_handle handle, u32 event, void *data)
359 -{
360 - struct bay *bay_dev = (struct bay *)data;
361 - struct device *dev = &bay_dev->pdev->dev;
362 - char event_string[12];
363 - char *envp[] = { event_string, NULL };
364 -
365 - bay_dprintk(handle, "Bay event");
366 - sprintf(event_string, "BAY_EVENT=%d", event);
367 - kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
368 -}
369 -
370 -static acpi_status
371 -find_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
372 -{
373 - int *count = (int *)context;
374 -
375 - /*
376 - * there could be more than one ejectable bay.
377 - * so, just return AE_OK always so that every object
378 - * will be checked.
379 - */
380 - if (is_ejectable_bay(handle)) {
381 - bay_dprintk(handle, "found ejectable bay");
382 - if (!bay_add(handle, *count))
383 - (*count)++;
384 - }
385 - return AE_OK;
386 -}
387 -
388 -static int __init bay_init(void)
389 -{
390 - int bays = 0;
391 -
392 - INIT_LIST_HEAD(&drive_bays);
393 -
394 - if (acpi_disabled)
395 - return -ENODEV;
396 -
397 - /* look for dockable drive bays */
398 - acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
399 - ACPI_UINT32_MAX, find_bay, &bays, NULL);
400 -
401 - if (!bays)
402 - return -ENODEV;
403 -
404 - return 0;
405 -}
406 -
407 -static void __exit bay_exit(void)
408 -{
409 - struct bay *bay, *tmp;
410 -
411 - list_for_each_entry_safe(bay, tmp, &drive_bays, list) {
412 - if (is_dock_device(bay->handle))
413 - unregister_hotplug_dock_device(bay->handle);
414 - acpi_bay_remove_fs(bay);
415 - acpi_remove_notify_handler(bay->handle, ACPI_SYSTEM_NOTIFY,
416 - bay_notify);
417 - platform_device_unregister(bay->pdev);
418 - kfree(bay->name);
419 - kfree(bay);
420 - }
421 -}
422 -
423 -postcore_initcall(bay_init);
424 -module_exit(bay_exit);
425 -