• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  button.c - ACPI Button Driver
4  *
5  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7  */
8 
9 #define pr_fmt(fmt) "ACPI: button: " fmt
10 
11 #include <linux/compiler.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/types.h>
16 #include <linux/proc_fs.h>
17 #include <linux/seq_file.h>
18 #include <linux/input.h>
19 #include <linux/slab.h>
20 #include <linux/acpi.h>
21 #include <linux/dmi.h>
22 #include <acpi/button.h>
23 
24 #define PREFIX "ACPI: "
25 
26 #define ACPI_BUTTON_CLASS		"button"
27 #define ACPI_BUTTON_FILE_INFO		"info"
28 #define ACPI_BUTTON_FILE_STATE		"state"
29 #define ACPI_BUTTON_TYPE_UNKNOWN	0x00
30 #define ACPI_BUTTON_NOTIFY_STATUS	0x80
31 
32 #define ACPI_BUTTON_SUBCLASS_POWER	"power"
33 #define ACPI_BUTTON_HID_POWER		"PNP0C0C"
34 #define ACPI_BUTTON_DEVICE_NAME_POWER	"Power Button"
35 #define ACPI_BUTTON_TYPE_POWER		0x01
36 
37 #define ACPI_BUTTON_SUBCLASS_SLEEP	"sleep"
38 #define ACPI_BUTTON_HID_SLEEP		"PNP0C0E"
39 #define ACPI_BUTTON_DEVICE_NAME_SLEEP	"Sleep Button"
40 #define ACPI_BUTTON_TYPE_SLEEP		0x03
41 
42 #define ACPI_BUTTON_SUBCLASS_LID	"lid"
43 #define ACPI_BUTTON_HID_LID		"PNP0C0D"
44 #define ACPI_BUTTON_DEVICE_NAME_LID	"Lid Switch"
45 #define ACPI_BUTTON_TYPE_LID		0x05
46 
47 #define ACPI_BUTTON_LID_INIT_IGNORE	0x00
48 #define ACPI_BUTTON_LID_INIT_OPEN	0x01
49 #define ACPI_BUTTON_LID_INIT_METHOD	0x02
50 
51 #define _COMPONENT		ACPI_BUTTON_COMPONENT
52 ACPI_MODULE_NAME("button");
53 
54 MODULE_AUTHOR("Paul Diefenbaugh");
55 MODULE_DESCRIPTION("ACPI Button Driver");
56 MODULE_LICENSE("GPL");
57 
58 static const struct acpi_device_id button_device_ids[] = {
59 	{ACPI_BUTTON_HID_LID,    0},
60 	{ACPI_BUTTON_HID_SLEEP,  0},
61 	{ACPI_BUTTON_HID_SLEEPF, 0},
62 	{ACPI_BUTTON_HID_POWER,  0},
63 	{ACPI_BUTTON_HID_POWERF, 0},
64 	{"", 0},
65 };
66 MODULE_DEVICE_TABLE(acpi, button_device_ids);
67 
68 /*
69  * Some devices which don't even have a lid in anyway have a broken _LID
70  * method (e.g. pointing to a floating gpio pin) causing spurious LID events.
71  */
72 static const struct dmi_system_id lid_blacklst[] = {
73 	{
74 		/* GP-electronic T701 */
75 		.matches = {
76 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
77 			DMI_MATCH(DMI_PRODUCT_NAME, "T701"),
78 			DMI_MATCH(DMI_BIOS_VERSION, "BYT70A.YNCHENG.WIN.007"),
79 		},
80 	},
81 	{
82 		/*
83 		 * Medion Akoya E2215T, notification of the LID device only
84 		 * happens on close, not on open and _LID always returns closed.
85 		 */
86 		.matches = {
87 			DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
88 			DMI_MATCH(DMI_PRODUCT_NAME, "E2215T MD60198"),
89 		},
90 		.driver_data = (void *)(long)ACPI_BUTTON_LID_INIT_OPEN,
91 	},
92 	{}
93 };
94 
95 static int acpi_button_add(struct acpi_device *device);
96 static int acpi_button_remove(struct acpi_device *device);
97 static void acpi_button_notify(struct acpi_device *device, u32 event);
98 
99 #ifdef CONFIG_PM_SLEEP
100 static int acpi_button_suspend(struct device *dev);
101 static int acpi_button_resume(struct device *dev);
102 #else
103 #define acpi_button_suspend NULL
104 #define acpi_button_resume NULL
105 #endif
106 static SIMPLE_DEV_PM_OPS(acpi_button_pm, acpi_button_suspend, acpi_button_resume);
107 
108 static struct acpi_driver acpi_button_driver = {
109 	.name = "button",
110 	.class = ACPI_BUTTON_CLASS,
111 	.ids = button_device_ids,
112 	.ops = {
113 		.add = acpi_button_add,
114 		.remove = acpi_button_remove,
115 		.notify = acpi_button_notify,
116 	},
117 	.drv.pm = &acpi_button_pm,
118 };
119 
120 struct acpi_button {
121 	unsigned int type;
122 	struct input_dev *input;
123 	char phys[32];			/* for input device */
124 	unsigned long pushed;
125 	int last_state;
126 	ktime_t last_time;
127 	bool suspended;
128 };
129 
130 static BLOCKING_NOTIFIER_HEAD(acpi_lid_notifier);
131 static struct acpi_device *lid_device;
132 static u8 lid_init_state = ACPI_BUTTON_LID_INIT_METHOD;
133 
134 static unsigned long lid_report_interval __read_mostly = 500;
135 module_param(lid_report_interval, ulong, 0644);
136 MODULE_PARM_DESC(lid_report_interval, "Interval (ms) between lid key events");
137 
138 /* --------------------------------------------------------------------------
139                               FS Interface (/proc)
140    -------------------------------------------------------------------------- */
141 
142 static struct proc_dir_entry *acpi_button_dir;
143 static struct proc_dir_entry *acpi_lid_dir;
144 
acpi_lid_evaluate_state(struct acpi_device * device)145 static int acpi_lid_evaluate_state(struct acpi_device *device)
146 {
147 	unsigned long long lid_state;
148 	acpi_status status;
149 
150 	status = acpi_evaluate_integer(device->handle, "_LID", NULL, &lid_state);
151 	if (ACPI_FAILURE(status))
152 		return -ENODEV;
153 
154 	return lid_state ? 1 : 0;
155 }
156 
acpi_lid_notify_state(struct acpi_device * device,int state)157 static int acpi_lid_notify_state(struct acpi_device *device, int state)
158 {
159 	struct acpi_button *button = acpi_driver_data(device);
160 	int ret;
161 	ktime_t next_report;
162 	bool do_update;
163 
164 	/*
165 	 * In lid_init_state=ignore mode, if user opens/closes lid
166 	 * frequently with "open" missing, and "last_time" is also updated
167 	 * frequently, "close" cannot be delivered to the userspace.
168 	 * So "last_time" is only updated after a timeout or an actual
169 	 * switch.
170 	 */
171 	if (lid_init_state != ACPI_BUTTON_LID_INIT_IGNORE ||
172 	    button->last_state != !!state)
173 		do_update = true;
174 	else
175 		do_update = false;
176 
177 	next_report = ktime_add(button->last_time,
178 				ms_to_ktime(lid_report_interval));
179 	if (button->last_state == !!state &&
180 	    ktime_after(ktime_get(), next_report)) {
181 		/* Complain the buggy firmware */
182 		pr_warn_once("The lid device is not compliant to SW_LID.\n");
183 
184 		/*
185 		 * Send the unreliable complement switch event:
186 		 *
187 		 * On most platforms, the lid device is reliable. However
188 		 * there are exceptions:
189 		 * 1. Platforms returning initial lid state as "close" by
190 		 *    default after booting/resuming:
191 		 *     https://bugzilla.kernel.org/show_bug.cgi?id=89211
192 		 *     https://bugzilla.kernel.org/show_bug.cgi?id=106151
193 		 * 2. Platforms never reporting "open" events:
194 		 *     https://bugzilla.kernel.org/show_bug.cgi?id=106941
195 		 * On these buggy platforms, the usage model of the ACPI
196 		 * lid device actually is:
197 		 * 1. The initial returning value of _LID may not be
198 		 *    reliable.
199 		 * 2. The open event may not be reliable.
200 		 * 3. The close event is reliable.
201 		 *
202 		 * But SW_LID is typed as input switch event, the input
203 		 * layer checks if the event is redundant. Hence if the
204 		 * state is not switched, the userspace cannot see this
205 		 * platform triggered reliable event. By inserting a
206 		 * complement switch event, it then is guaranteed that the
207 		 * platform triggered reliable one can always be seen by
208 		 * the userspace.
209 		 */
210 		if (lid_init_state == ACPI_BUTTON_LID_INIT_IGNORE) {
211 			do_update = true;
212 			/*
213 			 * Do generate complement switch event for "close"
214 			 * as "close" is reliable and wrong "open" won't
215 			 * trigger unexpected behaviors.
216 			 * Do not generate complement switch event for
217 			 * "open" as "open" is not reliable and wrong
218 			 * "close" will trigger unexpected behaviors.
219 			 */
220 			if (!state) {
221 				input_report_switch(button->input,
222 						    SW_LID, state);
223 				input_sync(button->input);
224 			}
225 		}
226 	}
227 	/* Send the platform triggered reliable event */
228 	if (do_update) {
229 		acpi_handle_debug(device->handle, "ACPI LID %s\n",
230 				  state ? "open" : "closed");
231 		input_report_switch(button->input, SW_LID, !state);
232 		input_sync(button->input);
233 		button->last_state = !!state;
234 		button->last_time = ktime_get();
235 	}
236 
237 	ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device);
238 	if (ret == NOTIFY_DONE)
239 		ret = blocking_notifier_call_chain(&acpi_lid_notifier, state,
240 						   device);
241 	if (ret == NOTIFY_DONE || ret == NOTIFY_OK) {
242 		/*
243 		 * It is also regarded as success if the notifier_chain
244 		 * returns NOTIFY_OK or NOTIFY_DONE.
245 		 */
246 		ret = 0;
247 	}
248 	return ret;
249 }
250 
acpi_button_state_seq_show(struct seq_file * seq,void * offset)251 static int __maybe_unused acpi_button_state_seq_show(struct seq_file *seq,
252 						     void *offset)
253 {
254 	struct acpi_device *device = seq->private;
255 	int state;
256 
257 	state = acpi_lid_evaluate_state(device);
258 	seq_printf(seq, "state:      %s\n",
259 		   state < 0 ? "unsupported" : (state ? "open" : "closed"));
260 	return 0;
261 }
262 
acpi_button_add_fs(struct acpi_device * device)263 static int acpi_button_add_fs(struct acpi_device *device)
264 {
265 	struct acpi_button *button = acpi_driver_data(device);
266 	struct proc_dir_entry *entry = NULL;
267 	int ret = 0;
268 
269 	/* procfs I/F for ACPI lid device only */
270 	if (button->type != ACPI_BUTTON_TYPE_LID)
271 		return 0;
272 
273 	if (acpi_button_dir || acpi_lid_dir) {
274 		printk(KERN_ERR PREFIX "More than one Lid device found!\n");
275 		return -EEXIST;
276 	}
277 
278 	/* create /proc/acpi/button */
279 	acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
280 	if (!acpi_button_dir)
281 		return -ENODEV;
282 
283 	/* create /proc/acpi/button/lid */
284 	acpi_lid_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
285 	if (!acpi_lid_dir) {
286 		ret = -ENODEV;
287 		goto remove_button_dir;
288 	}
289 
290 	/* create /proc/acpi/button/lid/LID/ */
291 	acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), acpi_lid_dir);
292 	if (!acpi_device_dir(device)) {
293 		ret = -ENODEV;
294 		goto remove_lid_dir;
295 	}
296 
297 	/* create /proc/acpi/button/lid/LID/state */
298 	entry = proc_create_single_data(ACPI_BUTTON_FILE_STATE, S_IRUGO,
299 			acpi_device_dir(device), acpi_button_state_seq_show,
300 			device);
301 	if (!entry) {
302 		ret = -ENODEV;
303 		goto remove_dev_dir;
304 	}
305 
306 done:
307 	return ret;
308 
309 remove_dev_dir:
310 	remove_proc_entry(acpi_device_bid(device),
311 			  acpi_lid_dir);
312 	acpi_device_dir(device) = NULL;
313 remove_lid_dir:
314 	remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
315 	acpi_lid_dir = NULL;
316 remove_button_dir:
317 	remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
318 	acpi_button_dir = NULL;
319 	goto done;
320 }
321 
acpi_button_remove_fs(struct acpi_device * device)322 static int acpi_button_remove_fs(struct acpi_device *device)
323 {
324 	struct acpi_button *button = acpi_driver_data(device);
325 
326 	if (button->type != ACPI_BUTTON_TYPE_LID)
327 		return 0;
328 
329 	remove_proc_entry(ACPI_BUTTON_FILE_STATE,
330 			  acpi_device_dir(device));
331 	remove_proc_entry(acpi_device_bid(device),
332 			  acpi_lid_dir);
333 	acpi_device_dir(device) = NULL;
334 	remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
335 	acpi_lid_dir = NULL;
336 	remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
337 	acpi_button_dir = NULL;
338 
339 	return 0;
340 }
341 
342 /* --------------------------------------------------------------------------
343                                 Driver Interface
344    -------------------------------------------------------------------------- */
acpi_lid_notifier_register(struct notifier_block * nb)345 int acpi_lid_notifier_register(struct notifier_block *nb)
346 {
347 	return blocking_notifier_chain_register(&acpi_lid_notifier, nb);
348 }
349 EXPORT_SYMBOL(acpi_lid_notifier_register);
350 
acpi_lid_notifier_unregister(struct notifier_block * nb)351 int acpi_lid_notifier_unregister(struct notifier_block *nb)
352 {
353 	return blocking_notifier_chain_unregister(&acpi_lid_notifier, nb);
354 }
355 EXPORT_SYMBOL(acpi_lid_notifier_unregister);
356 
acpi_lid_open(void)357 int acpi_lid_open(void)
358 {
359 	if (!lid_device)
360 		return -ENODEV;
361 
362 	return acpi_lid_evaluate_state(lid_device);
363 }
364 EXPORT_SYMBOL(acpi_lid_open);
365 
acpi_lid_update_state(struct acpi_device * device,bool signal_wakeup)366 static int acpi_lid_update_state(struct acpi_device *device,
367 				 bool signal_wakeup)
368 {
369 	int state;
370 
371 	state = acpi_lid_evaluate_state(device);
372 	if (state < 0)
373 		return state;
374 
375 	if (state && signal_wakeup)
376 		acpi_pm_wakeup_event(&device->dev);
377 
378 	return acpi_lid_notify_state(device, state);
379 }
380 
acpi_lid_initialize_state(struct acpi_device * device)381 static void acpi_lid_initialize_state(struct acpi_device *device)
382 {
383 	switch (lid_init_state) {
384 	case ACPI_BUTTON_LID_INIT_OPEN:
385 		(void)acpi_lid_notify_state(device, 1);
386 		break;
387 	case ACPI_BUTTON_LID_INIT_METHOD:
388 		(void)acpi_lid_update_state(device, false);
389 		break;
390 	case ACPI_BUTTON_LID_INIT_IGNORE:
391 	default:
392 		break;
393 	}
394 }
395 
acpi_button_notify(struct acpi_device * device,u32 event)396 static void acpi_button_notify(struct acpi_device *device, u32 event)
397 {
398 	struct acpi_button *button = acpi_driver_data(device);
399 	struct input_dev *input;
400 	int users;
401 
402 	switch (event) {
403 	case ACPI_FIXED_HARDWARE_EVENT:
404 		event = ACPI_BUTTON_NOTIFY_STATUS;
405 		/* fall through */
406 	case ACPI_BUTTON_NOTIFY_STATUS:
407 		input = button->input;
408 		if (button->type == ACPI_BUTTON_TYPE_LID) {
409 			mutex_lock(&button->input->mutex);
410 			users = button->input->users;
411 			mutex_unlock(&button->input->mutex);
412 			if (users)
413 				acpi_lid_update_state(device, true);
414 		} else {
415 			int keycode;
416 
417 			acpi_pm_wakeup_event(&device->dev);
418 			if (button->suspended)
419 				break;
420 
421 			keycode = test_bit(KEY_SLEEP, input->keybit) ?
422 						KEY_SLEEP : KEY_POWER;
423 			input_report_key(input, keycode, 1);
424 			input_sync(input);
425 			input_report_key(input, keycode, 0);
426 			input_sync(input);
427 
428 			acpi_bus_generate_netlink_event(
429 					device->pnp.device_class,
430 					dev_name(&device->dev),
431 					event, ++button->pushed);
432 		}
433 		break;
434 	default:
435 		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
436 				  "Unsupported event [0x%x]\n", event));
437 		break;
438 	}
439 }
440 
441 #ifdef CONFIG_PM_SLEEP
acpi_button_suspend(struct device * dev)442 static int acpi_button_suspend(struct device *dev)
443 {
444 	struct acpi_device *device = to_acpi_device(dev);
445 	struct acpi_button *button = acpi_driver_data(device);
446 
447 	button->suspended = true;
448 	return 0;
449 }
450 
acpi_button_resume(struct device * dev)451 static int acpi_button_resume(struct device *dev)
452 {
453 	struct acpi_device *device = to_acpi_device(dev);
454 	struct acpi_button *button = acpi_driver_data(device);
455 
456 	button->suspended = false;
457 	if (button->type == ACPI_BUTTON_TYPE_LID && button->input->users) {
458 		button->last_state = !!acpi_lid_evaluate_state(device);
459 		button->last_time = ktime_get();
460 		acpi_lid_initialize_state(device);
461 	}
462 	return 0;
463 }
464 #endif
465 
acpi_lid_input_open(struct input_dev * input)466 static int acpi_lid_input_open(struct input_dev *input)
467 {
468 	struct acpi_device *device = input_get_drvdata(input);
469 	struct acpi_button *button = acpi_driver_data(device);
470 
471 	button->last_state = !!acpi_lid_evaluate_state(device);
472 	button->last_time = ktime_get();
473 	acpi_lid_initialize_state(device);
474 
475 	return 0;
476 }
477 
acpi_button_add(struct acpi_device * device)478 static int acpi_button_add(struct acpi_device *device)
479 {
480 	struct acpi_button *button;
481 	struct input_dev *input;
482 	const char *hid = acpi_device_hid(device);
483 	char *name, *class;
484 	int error;
485 
486 	if (!strcmp(hid, ACPI_BUTTON_HID_LID) && dmi_check_system(lid_blacklst))
487 		return -ENODEV;
488 
489 	button = kzalloc(sizeof(struct acpi_button), GFP_KERNEL);
490 	if (!button)
491 		return -ENOMEM;
492 
493 	device->driver_data = button;
494 
495 	button->input = input = input_allocate_device();
496 	if (!input) {
497 		error = -ENOMEM;
498 		goto err_free_button;
499 	}
500 
501 	name = acpi_device_name(device);
502 	class = acpi_device_class(device);
503 
504 	if (!strcmp(hid, ACPI_BUTTON_HID_POWER) ||
505 	    !strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
506 		button->type = ACPI_BUTTON_TYPE_POWER;
507 		strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER);
508 		sprintf(class, "%s/%s",
509 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
510 	} else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEP) ||
511 		   !strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) {
512 		button->type = ACPI_BUTTON_TYPE_SLEEP;
513 		strcpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP);
514 		sprintf(class, "%s/%s",
515 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
516 	} else if (!strcmp(hid, ACPI_BUTTON_HID_LID)) {
517 		button->type = ACPI_BUTTON_TYPE_LID;
518 		strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
519 		sprintf(class, "%s/%s",
520 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
521 		input->open = acpi_lid_input_open;
522 	} else {
523 		printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid);
524 		error = -ENODEV;
525 		goto err_free_input;
526 	}
527 
528 	error = acpi_button_add_fs(device);
529 	if (error)
530 		goto err_free_input;
531 
532 	snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
533 
534 	input->name = name;
535 	input->phys = button->phys;
536 	input->id.bustype = BUS_HOST;
537 	input->id.product = button->type;
538 	input->dev.parent = &device->dev;
539 
540 	switch (button->type) {
541 	case ACPI_BUTTON_TYPE_POWER:
542 		input_set_capability(input, EV_KEY, KEY_POWER);
543 		break;
544 
545 	case ACPI_BUTTON_TYPE_SLEEP:
546 		input_set_capability(input, EV_KEY, KEY_SLEEP);
547 		break;
548 
549 	case ACPI_BUTTON_TYPE_LID:
550 		input_set_capability(input, EV_SW, SW_LID);
551 		break;
552 	}
553 
554 	input_set_drvdata(input, device);
555 	error = input_register_device(input);
556 	if (error)
557 		goto err_remove_fs;
558 	if (button->type == ACPI_BUTTON_TYPE_LID) {
559 		/*
560 		 * This assumes there's only one lid device, or if there are
561 		 * more we only care about the last one...
562 		 */
563 		lid_device = device;
564 	}
565 
566 	device_init_wakeup(&device->dev, true);
567 	printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device));
568 	return 0;
569 
570  err_remove_fs:
571 	acpi_button_remove_fs(device);
572  err_free_input:
573 	input_free_device(input);
574  err_free_button:
575 	kfree(button);
576 	return error;
577 }
578 
acpi_button_remove(struct acpi_device * device)579 static int acpi_button_remove(struct acpi_device *device)
580 {
581 	struct acpi_button *button = acpi_driver_data(device);
582 
583 	acpi_button_remove_fs(device);
584 	input_unregister_device(button->input);
585 	kfree(button);
586 	return 0;
587 }
588 
param_set_lid_init_state(const char * val,const struct kernel_param * kp)589 static int param_set_lid_init_state(const char *val,
590 				    const struct kernel_param *kp)
591 {
592 	int result = 0;
593 
594 	if (!strncmp(val, "open", sizeof("open") - 1)) {
595 		lid_init_state = ACPI_BUTTON_LID_INIT_OPEN;
596 		pr_info("Notify initial lid state as open\n");
597 	} else if (!strncmp(val, "method", sizeof("method") - 1)) {
598 		lid_init_state = ACPI_BUTTON_LID_INIT_METHOD;
599 		pr_info("Notify initial lid state with _LID return value\n");
600 	} else if (!strncmp(val, "ignore", sizeof("ignore") - 1)) {
601 		lid_init_state = ACPI_BUTTON_LID_INIT_IGNORE;
602 		pr_info("Do not notify initial lid state\n");
603 	} else
604 		result = -EINVAL;
605 	return result;
606 }
607 
param_get_lid_init_state(char * buffer,const struct kernel_param * kp)608 static int param_get_lid_init_state(char *buffer,
609 				    const struct kernel_param *kp)
610 {
611 	switch (lid_init_state) {
612 	case ACPI_BUTTON_LID_INIT_OPEN:
613 		return sprintf(buffer, "open");
614 	case ACPI_BUTTON_LID_INIT_METHOD:
615 		return sprintf(buffer, "method");
616 	case ACPI_BUTTON_LID_INIT_IGNORE:
617 		return sprintf(buffer, "ignore");
618 	default:
619 		return sprintf(buffer, "invalid");
620 	}
621 	return 0;
622 }
623 
624 module_param_call(lid_init_state,
625 		  param_set_lid_init_state, param_get_lid_init_state,
626 		  NULL, 0644);
627 MODULE_PARM_DESC(lid_init_state, "Behavior for reporting LID initial state");
628 
acpi_button_register_driver(struct acpi_driver * driver)629 static int acpi_button_register_driver(struct acpi_driver *driver)
630 {
631 	/*
632 	 * Modules such as nouveau.ko and i915.ko have a link time dependency
633 	 * on acpi_lid_open(), and would therefore not be loadable on ACPI
634 	 * capable kernels booted in non-ACPI mode if the return value of
635 	 * acpi_bus_register_driver() is returned from here with ACPI disabled
636 	 * when this driver is built as a module.
637 	 */
638 	if (acpi_disabled)
639 		return 0;
640 
641 	return acpi_bus_register_driver(driver);
642 }
643 
acpi_button_unregister_driver(struct acpi_driver * driver)644 static void acpi_button_unregister_driver(struct acpi_driver *driver)
645 {
646 	if (!acpi_disabled)
647 		acpi_bus_unregister_driver(driver);
648 }
649 
650 module_driver(acpi_button_driver, acpi_button_register_driver,
651 	       acpi_button_unregister_driver);
652