button.c 18 KB

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