button.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/types.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/input.h>
  29. #include <linux/slab.h>
  30. #include <linux/acpi.h>
  31. #include <linux/dmi.h>
  32. #include <acpi/button.h>
  33. #define PREFIX "ACPI: "
  34. #define ACPI_BUTTON_CLASS "button"
  35. #define ACPI_BUTTON_FILE_INFO "info"
  36. #define ACPI_BUTTON_FILE_STATE "state"
  37. #define ACPI_BUTTON_TYPE_UNKNOWN 0x00
  38. #define ACPI_BUTTON_NOTIFY_STATUS 0x80
  39. #define ACPI_BUTTON_SUBCLASS_POWER "power"
  40. #define ACPI_BUTTON_HID_POWER "PNP0C0C"
  41. #define ACPI_BUTTON_DEVICE_NAME_POWER "Power Button"
  42. #define ACPI_BUTTON_TYPE_POWER 0x01
  43. #define ACPI_BUTTON_SUBCLASS_SLEEP "sleep"
  44. #define ACPI_BUTTON_HID_SLEEP "PNP0C0E"
  45. #define ACPI_BUTTON_DEVICE_NAME_SLEEP "Sleep Button"
  46. #define ACPI_BUTTON_TYPE_SLEEP 0x03
  47. #define ACPI_BUTTON_SUBCLASS_LID "lid"
  48. #define ACPI_BUTTON_HID_LID "PNP0C0D"
  49. #define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch"
  50. #define ACPI_BUTTON_TYPE_LID 0x05
  51. #define ACPI_BUTTON_LID_INIT_IGNORE 0x00
  52. #define ACPI_BUTTON_LID_INIT_OPEN 0x01
  53. #define ACPI_BUTTON_LID_INIT_METHOD 0x02
  54. #define _COMPONENT ACPI_BUTTON_COMPONENT
  55. ACPI_MODULE_NAME("button");
  56. MODULE_AUTHOR("Paul Diefenbaugh");
  57. MODULE_DESCRIPTION("ACPI Button Driver");
  58. MODULE_LICENSE("GPL");
  59. static const struct acpi_device_id button_device_ids[] = {
  60. {ACPI_BUTTON_HID_LID, 0},
  61. {ACPI_BUTTON_HID_SLEEP, 0},
  62. {ACPI_BUTTON_HID_SLEEPF, 0},
  63. {ACPI_BUTTON_HID_POWER, 0},
  64. {ACPI_BUTTON_HID_POWERF, 0},
  65. {"", 0},
  66. };
  67. MODULE_DEVICE_TABLE(acpi, button_device_ids);
  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. static int acpi_button_add(struct acpi_device *device);
  84. static int acpi_button_remove(struct acpi_device *device);
  85. static void acpi_button_notify(struct acpi_device *device, u32 event);
  86. #ifdef CONFIG_PM_SLEEP
  87. static int acpi_button_suspend(struct device *dev);
  88. static int acpi_button_resume(struct device *dev);
  89. #else
  90. #define acpi_button_suspend NULL
  91. #define acpi_button_resume NULL
  92. #endif
  93. static SIMPLE_DEV_PM_OPS(acpi_button_pm, acpi_button_suspend, acpi_button_resume);
  94. static struct acpi_driver acpi_button_driver = {
  95. .name = "button",
  96. .class = ACPI_BUTTON_CLASS,
  97. .ids = button_device_ids,
  98. .ops = {
  99. .add = acpi_button_add,
  100. .remove = acpi_button_remove,
  101. .notify = acpi_button_notify,
  102. },
  103. .drv.pm = &acpi_button_pm,
  104. };
  105. struct acpi_button {
  106. unsigned int type;
  107. struct input_dev *input;
  108. char phys[32]; /* for input device */
  109. unsigned long pushed;
  110. int last_state;
  111. ktime_t last_time;
  112. bool suspended;
  113. };
  114. static BLOCKING_NOTIFIER_HEAD(acpi_lid_notifier);
  115. static struct acpi_device *lid_device;
  116. static u8 lid_init_state = ACPI_BUTTON_LID_INIT_METHOD;
  117. static unsigned long lid_report_interval __read_mostly = 500;
  118. module_param(lid_report_interval, ulong, 0644);
  119. MODULE_PARM_DESC(lid_report_interval, "Interval (ms) between lid key events");
  120. /* --------------------------------------------------------------------------
  121. FS Interface (/proc)
  122. -------------------------------------------------------------------------- */
  123. static struct proc_dir_entry *acpi_button_dir;
  124. static struct proc_dir_entry *acpi_lid_dir;
  125. static int acpi_lid_evaluate_state(struct acpi_device *device)
  126. {
  127. unsigned long long lid_state;
  128. acpi_status status;
  129. status = acpi_evaluate_integer(device->handle, "_LID", NULL, &lid_state);
  130. if (ACPI_FAILURE(status))
  131. return -ENODEV;
  132. return lid_state ? 1 : 0;
  133. }
  134. static int acpi_lid_notify_state(struct acpi_device *device, int state)
  135. {
  136. struct acpi_button *button = acpi_driver_data(device);
  137. int ret;
  138. ktime_t next_report;
  139. bool do_update;
  140. /*
  141. * In lid_init_state=ignore mode, if user opens/closes lid
  142. * frequently with "open" missing, and "last_time" is also updated
  143. * frequently, "close" cannot be delivered to the userspace.
  144. * So "last_time" is only updated after a timeout or an actual
  145. * switch.
  146. */
  147. if (lid_init_state != ACPI_BUTTON_LID_INIT_IGNORE ||
  148. button->last_state != !!state)
  149. do_update = true;
  150. else
  151. do_update = false;
  152. next_report = ktime_add(button->last_time,
  153. ms_to_ktime(lid_report_interval));
  154. if (button->last_state == !!state &&
  155. ktime_after(ktime_get(), next_report)) {
  156. /* Complain the buggy firmware */
  157. pr_warn_once("The lid device is not compliant to SW_LID.\n");
  158. /*
  159. * Send the unreliable complement switch event:
  160. *
  161. * On most platforms, the lid device is reliable. However
  162. * there are exceptions:
  163. * 1. Platforms returning initial lid state as "close" by
  164. * default after booting/resuming:
  165. * https://bugzilla.kernel.org/show_bug.cgi?id=89211
  166. * https://bugzilla.kernel.org/show_bug.cgi?id=106151
  167. * 2. Platforms never reporting "open" events:
  168. * https://bugzilla.kernel.org/show_bug.cgi?id=106941
  169. * On these buggy platforms, the usage model of the ACPI
  170. * lid device actually is:
  171. * 1. The initial returning value of _LID may not be
  172. * reliable.
  173. * 2. The open event may not be reliable.
  174. * 3. The close event is reliable.
  175. *
  176. * But SW_LID is typed as input switch event, the input
  177. * layer checks if the event is redundant. Hence if the
  178. * state is not switched, the userspace cannot see this
  179. * platform triggered reliable event. By inserting a
  180. * complement switch event, it then is guaranteed that the
  181. * platform triggered reliable one can always be seen by
  182. * the userspace.
  183. */
  184. if (lid_init_state == ACPI_BUTTON_LID_INIT_IGNORE) {
  185. do_update = true;
  186. /*
  187. * Do generate complement switch event for "close"
  188. * as "close" is reliable and wrong "open" won't
  189. * trigger unexpected behaviors.
  190. * Do not generate complement switch event for
  191. * "open" as "open" is not reliable and wrong
  192. * "close" will trigger unexpected behaviors.
  193. */
  194. if (!state) {
  195. input_report_switch(button->input,
  196. SW_LID, state);
  197. input_sync(button->input);
  198. }
  199. }
  200. }
  201. /* Send the platform triggered reliable event */
  202. if (do_update) {
  203. acpi_handle_debug(device->handle, "ACPI LID %s\n",
  204. state ? "open" : "closed");
  205. input_report_switch(button->input, SW_LID, !state);
  206. input_sync(button->input);
  207. button->last_state = !!state;
  208. button->last_time = ktime_get();
  209. }
  210. if (state)
  211. acpi_pm_wakeup_event(&device->dev);
  212. ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device);
  213. if (ret == NOTIFY_DONE)
  214. ret = blocking_notifier_call_chain(&acpi_lid_notifier, state,
  215. device);
  216. if (ret == NOTIFY_DONE || ret == NOTIFY_OK) {
  217. /*
  218. * It is also regarded as success if the notifier_chain
  219. * returns NOTIFY_OK or NOTIFY_DONE.
  220. */
  221. ret = 0;
  222. }
  223. return ret;
  224. }
  225. static int acpi_button_state_seq_show(struct seq_file *seq, 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. {
  322. int state;
  323. state = acpi_lid_evaluate_state(device);
  324. if (state < 0)
  325. return state;
  326. return acpi_lid_notify_state(device, state);
  327. }
  328. static void acpi_lid_initialize_state(struct acpi_device *device)
  329. {
  330. switch (lid_init_state) {
  331. case ACPI_BUTTON_LID_INIT_OPEN:
  332. (void)acpi_lid_notify_state(device, 1);
  333. break;
  334. case ACPI_BUTTON_LID_INIT_METHOD:
  335. (void)acpi_lid_update_state(device);
  336. break;
  337. case ACPI_BUTTON_LID_INIT_IGNORE:
  338. default:
  339. break;
  340. }
  341. }
  342. static void acpi_button_notify(struct acpi_device *device, u32 event)
  343. {
  344. struct acpi_button *button = acpi_driver_data(device);
  345. struct input_dev *input;
  346. int users;
  347. switch (event) {
  348. case ACPI_FIXED_HARDWARE_EVENT:
  349. event = ACPI_BUTTON_NOTIFY_STATUS;
  350. /* fall through */
  351. case ACPI_BUTTON_NOTIFY_STATUS:
  352. input = button->input;
  353. if (button->type == ACPI_BUTTON_TYPE_LID) {
  354. mutex_lock(&button->input->mutex);
  355. users = button->input->users;
  356. mutex_unlock(&button->input->mutex);
  357. if (users)
  358. acpi_lid_update_state(device);
  359. } else {
  360. int keycode;
  361. acpi_pm_wakeup_event(&device->dev);
  362. if (button->suspended)
  363. break;
  364. keycode = test_bit(KEY_SLEEP, input->keybit) ?
  365. KEY_SLEEP : KEY_POWER;
  366. input_report_key(input, keycode, 1);
  367. input_sync(input);
  368. input_report_key(input, keycode, 0);
  369. input_sync(input);
  370. acpi_bus_generate_netlink_event(
  371. device->pnp.device_class,
  372. dev_name(&device->dev),
  373. event, ++button->pushed);
  374. }
  375. break;
  376. default:
  377. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  378. "Unsupported event [0x%x]\n", event));
  379. break;
  380. }
  381. }
  382. #ifdef CONFIG_PM_SLEEP
  383. static int acpi_button_suspend(struct device *dev)
  384. {
  385. struct acpi_device *device = to_acpi_device(dev);
  386. struct acpi_button *button = acpi_driver_data(device);
  387. button->suspended = true;
  388. return 0;
  389. }
  390. static int acpi_button_resume(struct device *dev)
  391. {
  392. struct acpi_device *device = to_acpi_device(dev);
  393. struct acpi_button *button = acpi_driver_data(device);
  394. button->suspended = false;
  395. if (button->type == ACPI_BUTTON_TYPE_LID && button->input->users)
  396. acpi_lid_initialize_state(device);
  397. return 0;
  398. }
  399. #endif
  400. static int acpi_lid_input_open(struct input_dev *input)
  401. {
  402. struct acpi_device *device = input_get_drvdata(input);
  403. struct acpi_button *button = acpi_driver_data(device);
  404. button->last_state = !!acpi_lid_evaluate_state(device);
  405. button->last_time = ktime_get();
  406. acpi_lid_initialize_state(device);
  407. return 0;
  408. }
  409. static int acpi_button_add(struct acpi_device *device)
  410. {
  411. struct acpi_button *button;
  412. struct input_dev *input;
  413. const char *hid = acpi_device_hid(device);
  414. char *name, *class;
  415. int error;
  416. if (!strcmp(hid, ACPI_BUTTON_HID_LID) && dmi_check_system(lid_blacklst))
  417. return -ENODEV;
  418. button = kzalloc(sizeof(struct acpi_button), GFP_KERNEL);
  419. if (!button)
  420. return -ENOMEM;
  421. device->driver_data = button;
  422. button->input = input = input_allocate_device();
  423. if (!input) {
  424. error = -ENOMEM;
  425. goto err_free_button;
  426. }
  427. name = acpi_device_name(device);
  428. class = acpi_device_class(device);
  429. if (!strcmp(hid, ACPI_BUTTON_HID_POWER) ||
  430. !strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
  431. button->type = ACPI_BUTTON_TYPE_POWER;
  432. strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER);
  433. sprintf(class, "%s/%s",
  434. ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
  435. } else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEP) ||
  436. !strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) {
  437. button->type = ACPI_BUTTON_TYPE_SLEEP;
  438. strcpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP);
  439. sprintf(class, "%s/%s",
  440. ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
  441. } else if (!strcmp(hid, ACPI_BUTTON_HID_LID)) {
  442. button->type = ACPI_BUTTON_TYPE_LID;
  443. strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
  444. sprintf(class, "%s/%s",
  445. ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
  446. input->open = acpi_lid_input_open;
  447. } else {
  448. printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid);
  449. error = -ENODEV;
  450. goto err_free_input;
  451. }
  452. error = acpi_button_add_fs(device);
  453. if (error)
  454. goto err_free_input;
  455. snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
  456. input->name = name;
  457. input->phys = button->phys;
  458. input->id.bustype = BUS_HOST;
  459. input->id.product = button->type;
  460. input->dev.parent = &device->dev;
  461. switch (button->type) {
  462. case ACPI_BUTTON_TYPE_POWER:
  463. input_set_capability(input, EV_KEY, KEY_POWER);
  464. break;
  465. case ACPI_BUTTON_TYPE_SLEEP:
  466. input_set_capability(input, EV_KEY, KEY_SLEEP);
  467. break;
  468. case ACPI_BUTTON_TYPE_LID:
  469. input_set_capability(input, EV_SW, SW_LID);
  470. break;
  471. }
  472. input_set_drvdata(input, device);
  473. error = input_register_device(input);
  474. if (error)
  475. goto err_remove_fs;
  476. if (button->type == ACPI_BUTTON_TYPE_LID) {
  477. /*
  478. * This assumes there's only one lid device, or if there are
  479. * more we only care about the last one...
  480. */
  481. lid_device = device;
  482. }
  483. device_init_wakeup(&device->dev, true);
  484. printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device));
  485. return 0;
  486. err_remove_fs:
  487. acpi_button_remove_fs(device);
  488. err_free_input:
  489. input_free_device(input);
  490. err_free_button:
  491. kfree(button);
  492. return error;
  493. }
  494. static int acpi_button_remove(struct acpi_device *device)
  495. {
  496. struct acpi_button *button = acpi_driver_data(device);
  497. acpi_button_remove_fs(device);
  498. input_unregister_device(button->input);
  499. kfree(button);
  500. return 0;
  501. }
  502. static int param_set_lid_init_state(const char *val,
  503. const struct kernel_param *kp)
  504. {
  505. int result = 0;
  506. if (!strncmp(val, "open", sizeof("open") - 1)) {
  507. lid_init_state = ACPI_BUTTON_LID_INIT_OPEN;
  508. pr_info("Notify initial lid state as open\n");
  509. } else if (!strncmp(val, "method", sizeof("method") - 1)) {
  510. lid_init_state = ACPI_BUTTON_LID_INIT_METHOD;
  511. pr_info("Notify initial lid state with _LID return value\n");
  512. } else if (!strncmp(val, "ignore", sizeof("ignore") - 1)) {
  513. lid_init_state = ACPI_BUTTON_LID_INIT_IGNORE;
  514. pr_info("Do not notify initial lid state\n");
  515. } else
  516. result = -EINVAL;
  517. return result;
  518. }
  519. static int param_get_lid_init_state(char *buffer,
  520. const struct kernel_param *kp)
  521. {
  522. switch (lid_init_state) {
  523. case ACPI_BUTTON_LID_INIT_OPEN:
  524. return sprintf(buffer, "open");
  525. case ACPI_BUTTON_LID_INIT_METHOD:
  526. return sprintf(buffer, "method");
  527. case ACPI_BUTTON_LID_INIT_IGNORE:
  528. return sprintf(buffer, "ignore");
  529. default:
  530. return sprintf(buffer, "invalid");
  531. }
  532. return 0;
  533. }
  534. module_param_call(lid_init_state,
  535. param_set_lid_init_state, param_get_lid_init_state,
  536. NULL, 0644);
  537. MODULE_PARM_DESC(lid_init_state, "Behavior for reporting LID initial state");
  538. static int acpi_button_register_driver(struct acpi_driver *driver)
  539. {
  540. /*
  541. * Modules such as nouveau.ko and i915.ko have a link time dependency
  542. * on acpi_lid_open(), and would therefore not be loadable on ACPI
  543. * capable kernels booted in non-ACPI mode if the return value of
  544. * acpi_bus_register_driver() is returned from here with ACPI disabled
  545. * when this driver is built as a module.
  546. */
  547. if (acpi_disabled)
  548. return 0;
  549. return acpi_bus_register_driver(driver);
  550. }
  551. static void acpi_button_unregister_driver(struct acpi_driver *driver)
  552. {
  553. if (!acpi_disabled)
  554. acpi_bus_unregister_driver(driver);
  555. }
  556. module_driver(acpi_button_driver, acpi_button_register_driver,
  557. acpi_button_unregister_driver);