aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/scan.c
diff options
context:
space:
mode:
authorThomas Renninger <trenn@suse.de>2007-07-23 08:43:51 -0400
committerLen Brown <len.brown@intel.com>2007-07-23 13:56:16 -0400
commit29b71a1ca74491fab9fed09e9d835d840d042690 (patch)
treee46dc9c53e4b6266703dedc21925875cea9e4abc /drivers/acpi/scan.c
parent8c8eb78f673c07b60f31751e1e47ac367c60c6b7 (diff)
ACPI: autoload modules - Create ACPI alias interface
Modify modpost (file2alias.c) to add acpi*:XYZ0001: alias in modules.alias like: grep acpi /lib/modules/2.6.22-rc4-default/modules.alias alias acpi*:SNY5001:* sony_laptop alias acpi*:SNY6001:* sony_laptop for e.g. the sony_laptop module. This module matches against all ACPI devices with a HID or CID of SNY5001 or SNY6001 Export an uevent and modalias sysfs file containing the string: [MODALIAS=]acpi:PNP0C0C: additional CIDs are concatenated at the end. Signed-off-by: Thomas Renninger <trenn@suse.de> Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r--drivers/acpi/scan.c156
1 files changed, 111 insertions, 45 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 6b3b8a522476..be74347d1354 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -16,7 +16,7 @@ ACPI_MODULE_NAME("scan");
16extern struct acpi_device *acpi_root; 16extern struct acpi_device *acpi_root;
17 17
18#define ACPI_BUS_CLASS "system_bus" 18#define ACPI_BUS_CLASS "system_bus"
19#define ACPI_BUS_HID "ACPI_BUS" 19#define ACPI_BUS_HID "LNXSYBUS"
20#define ACPI_BUS_DEVICE_NAME "System Bus" 20#define ACPI_BUS_DEVICE_NAME "System Bus"
21 21
22static LIST_HEAD(acpi_device_list); 22static LIST_HEAD(acpi_device_list);
@@ -29,6 +29,62 @@ struct acpi_device_bus_id{
29 unsigned int instance_no; 29 unsigned int instance_no;
30 struct list_head node; 30 struct list_head node;
31}; 31};
32
33/*
34 * Creates hid/cid(s) string needed for modalias and uevent
35 * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get:
36 * char *modalias: "acpi:IBM0001:ACPI0001"
37*/
38int create_modalias(struct acpi_device *acpi_dev, char *modalias, int size){
39
40 int len;
41
42 if (!acpi_dev->flags.hardware_id)
43 return -ENODEV;
44
45 len = snprintf(modalias, size, "acpi:%s:",
46 acpi_dev->pnp.hardware_id);
47 if (len < 0 || len >= size)
48 return -EINVAL;
49 size -= len;
50
51 if (acpi_dev->flags.compatible_ids) {
52 struct acpi_compatible_id_list *cid_list;
53 int i;
54 int count;
55
56 cid_list = acpi_dev->pnp.cid_list;
57 for (i = 0; i < cid_list->count; i++) {
58 count = snprintf(&modalias[len], size, "%s:",
59 cid_list->id[i].value);
60 if (count < 0 || count >= size) {
61 printk(KERN_ERR "acpi: %s cid[%i] exceeds event buffer size",
62 acpi_dev->pnp.device_name, i);
63 break;
64 }
65 len += count;
66 size -= count;
67 }
68 }
69
70 modalias[len] = '\0';
71 return len;
72}
73
74static ssize_t
75acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
76 struct acpi_device *acpi_dev = to_acpi_device(dev);
77 int len;
78
79 /* Device has no HID and no CID or string is >1024 */
80 len = create_modalias(acpi_dev, buf, 1024);
81 if (len <= 0)
82 return 0;
83 buf[len++] = '\n';
84 return len;
85}
86static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
87
32static int acpi_eject_operation(acpi_handle handle, int lockable) 88static int acpi_eject_operation(acpi_handle handle, int lockable)
33{ 89{
34 struct acpi_object_list arg_list; 90 struct acpi_object_list arg_list;
@@ -154,6 +210,12 @@ static int acpi_device_setup_files(struct acpi_device *dev)
154 goto end; 210 goto end;
155 } 211 }
156 212
213 if (dev->flags.hardware_id || dev->flags.compatible_ids){
214 result = device_create_file(&dev->dev, &dev_attr_modalias);
215 if(result)
216 goto end;
217 }
218
157 /* 219 /*
158 * If device has _EJ0, 'eject' file is created that is used to trigger 220 * If device has _EJ0, 'eject' file is created that is used to trigger
159 * hot-removal function from userland. 221 * hot-removal function from userland.
@@ -178,6 +240,9 @@ static void acpi_device_remove_files(struct acpi_device *dev)
178 if (ACPI_SUCCESS(status)) 240 if (ACPI_SUCCESS(status))
179 device_remove_file(&dev->dev, &dev_attr_eject); 241 device_remove_file(&dev->dev, &dev_attr_eject);
180 242
243 if (dev->flags.hardware_id || dev->flags.compatible_ids)
244 device_remove_file(&dev->dev, &dev_attr_modalias);
245
181 if(dev->flags.hardware_id) 246 if(dev->flags.hardware_id)
182 device_remove_file(&dev->dev, &dev_attr_hid); 247 device_remove_file(&dev->dev, &dev_attr_hid);
183 if(dev->handle) 248 if(dev->handle)
@@ -186,6 +251,37 @@ static void acpi_device_remove_files(struct acpi_device *dev)
186/* -------------------------------------------------------------------------- 251/* --------------------------------------------------------------------------
187 ACPI Bus operations 252 ACPI Bus operations
188 -------------------------------------------------------------------------- */ 253 -------------------------------------------------------------------------- */
254
255int acpi_match_device_ids(struct acpi_device *device,
256 const struct acpi_device_id *ids)
257{
258 const struct acpi_device_id *id;
259
260 if (device->flags.hardware_id) {
261 for (id = ids; id->id[0]; id++) {
262 if (!strcmp((char*)id->id, device->pnp.hardware_id))
263 return 0;
264 }
265 }
266
267 if (device->flags.compatible_ids) {
268 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
269 int i;
270
271 for (id = ids; id->id[0]; id++) {
272 /* compare multiple _CID entries against driver ids */
273 for (i = 0; i < cid_list->count; i++) {
274 if (!strcmp((char*)id->id,
275 cid_list->id[i].value))
276 return 0;
277 }
278 }
279 }
280
281 return -ENOENT;
282}
283EXPORT_SYMBOL(acpi_match_device_ids);
284
189static void acpi_device_release(struct device *dev) 285static void acpi_device_release(struct device *dev)
190{ 286{
191 struct acpi_device *acpi_dev = to_acpi_device(dev); 287 struct acpi_device *acpi_dev = to_acpi_device(dev);
@@ -219,37 +315,19 @@ static int acpi_bus_match(struct device *dev, struct device_driver *drv)
219 struct acpi_device *acpi_dev = to_acpi_device(dev); 315 struct acpi_device *acpi_dev = to_acpi_device(dev);
220 struct acpi_driver *acpi_drv = to_acpi_driver(drv); 316 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
221 317
222 return !acpi_match_ids(acpi_dev, acpi_drv->ids); 318 return !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
223} 319}
224 320
225static int acpi_device_uevent(struct device *dev, char **envp, int num_envp, 321static int acpi_device_uevent(struct device *dev, char **envp, int num_envp,
226 char *buffer, int buffer_size) 322 char *buffer, int buffer_size)
227{ 323{
228 struct acpi_device *acpi_dev = to_acpi_device(dev); 324 struct acpi_device *acpi_dev = to_acpi_device(dev);
229 int i = 0, length = 0, ret = 0;
230
231 if (acpi_dev->flags.hardware_id)
232 ret = add_uevent_var(envp, num_envp, &i,
233 buffer, buffer_size, &length,
234 "HWID=%s", acpi_dev->pnp.hardware_id);
235 if (ret)
236 return -ENOMEM;
237 if (acpi_dev->flags.compatible_ids) {
238 int j;
239 struct acpi_compatible_id_list *cid_list;
240 325
241 cid_list = acpi_dev->pnp.cid_list; 326 strcpy(buffer, "MODALIAS=");
242 327 if (create_modalias(acpi_dev, buffer + 9, buffer_size - 9) > 0) {
243 for (j = 0; j < cid_list->count; j++) { 328 envp[0] = buffer;
244 ret = add_uevent_var(envp, num_envp, &i, buffer, 329 envp[1] = NULL;
245 buffer_size, &length, "COMPTID=%s",
246 cid_list->id[j].value);
247 if (ret)
248 return -ENOMEM;
249 }
250 } 330 }
251
252 envp[i] = NULL;
253 return 0; 331 return 0;
254} 332}
255 333
@@ -543,25 +621,6 @@ void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
543 return; 621 return;
544} 622}
545 623
546int acpi_match_ids(struct acpi_device *device, char *ids)
547{
548 if (device->flags.hardware_id)
549 if (strstr(ids, device->pnp.hardware_id))
550 return 0;
551
552 if (device->flags.compatible_ids) {
553 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
554 int i;
555
556 /* compare multiple _CID entries against driver ids */
557 for (i = 0; i < cid_list->count; i++) {
558 if (strstr(ids, cid_list->id[i].value))
559 return 0;
560 }
561 }
562 return -ENOENT;
563}
564
565static int acpi_bus_get_perf_flags(struct acpi_device *device) 624static int acpi_bus_get_perf_flags(struct acpi_device *device)
566{ 625{
567 device->performance.state = ACPI_STATE_UNKNOWN; 626 device->performance.state = ACPI_STATE_UNKNOWN;
@@ -624,6 +683,13 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
624 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 683 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
625 union acpi_object *package = NULL; 684 union acpi_object *package = NULL;
626 685
686 struct acpi_device_id button_device_ids[] = {
687 {"PNP0C0D", 0},
688 {"PNP0C0C", 0},
689 {"PNP0C0E", 0},
690 {"", 0},
691 };
692
627 693
628 /* _PRW */ 694 /* _PRW */
629 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); 695 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
@@ -643,7 +709,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
643 709
644 device->wakeup.flags.valid = 1; 710 device->wakeup.flags.valid = 1;
645 /* Power button, Lid switch always enable wakeup */ 711 /* Power button, Lid switch always enable wakeup */
646 if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E")) 712 if (!acpi_match_device_ids(device, button_device_ids))
647 device->wakeup.flags.run_wake = 1; 713 device->wakeup.flags.run_wake = 1;
648 714
649 end: 715 end: