sleep.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. /*
  2. * sleep.c - ACPI sleep support.
  3. *
  4. * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
  5. * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
  6. * Copyright (c) 2000-2003 Patrick Mochel
  7. * Copyright (c) 2003 Open Source Development Lab
  8. *
  9. * This file is released under the GPLv2.
  10. *
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/irq.h>
  14. #include <linux/dmi.h>
  15. #include <linux/device.h>
  16. #include <linux/suspend.h>
  17. #include <linux/reboot.h>
  18. #include <asm/io.h>
  19. #include <acpi/acpi_bus.h>
  20. #include <acpi/acpi_drivers.h>
  21. #include "internal.h"
  22. #include "sleep.h"
  23. u8 sleep_states[ACPI_S_STATE_COUNT];
  24. static void acpi_sleep_tts_switch(u32 acpi_state)
  25. {
  26. union acpi_object in_arg = { ACPI_TYPE_INTEGER };
  27. struct acpi_object_list arg_list = { 1, &in_arg };
  28. acpi_status status = AE_OK;
  29. in_arg.integer.value = acpi_state;
  30. status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL);
  31. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  32. /*
  33. * OS can't evaluate the _TTS object correctly. Some warning
  34. * message will be printed. But it won't break anything.
  35. */
  36. printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
  37. }
  38. }
  39. static int tts_notify_reboot(struct notifier_block *this,
  40. unsigned long code, void *x)
  41. {
  42. acpi_sleep_tts_switch(ACPI_STATE_S5);
  43. return NOTIFY_DONE;
  44. }
  45. static struct notifier_block tts_notifier = {
  46. .notifier_call = tts_notify_reboot,
  47. .next = NULL,
  48. .priority = 0,
  49. };
  50. static int acpi_sleep_prepare(u32 acpi_state)
  51. {
  52. #ifdef CONFIG_ACPI_SLEEP
  53. /* do we have a wakeup address for S2 and S3? */
  54. if (acpi_state == ACPI_STATE_S3) {
  55. if (!acpi_wakeup_address) {
  56. return -EFAULT;
  57. }
  58. acpi_set_firmware_waking_vector(
  59. (acpi_physical_address)acpi_wakeup_address);
  60. }
  61. ACPI_FLUSH_CPU_CACHE();
  62. acpi_enable_wakeup_device_prep(acpi_state);
  63. #endif
  64. printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
  65. acpi_state);
  66. acpi_enter_sleep_state_prep(acpi_state);
  67. return 0;
  68. }
  69. #ifdef CONFIG_ACPI_SLEEP
  70. static u32 acpi_target_sleep_state = ACPI_STATE_S0;
  71. /*
  72. * According to the ACPI specification the BIOS should make sure that ACPI is
  73. * enabled and SCI_EN bit is set on wake-up from S1 - S3 sleep states. Still,
  74. * some BIOSes don't do that and therefore we use acpi_enable() to enable ACPI
  75. * on such systems during resume. Unfortunately that doesn't help in
  76. * particularly pathological cases in which SCI_EN has to be set directly on
  77. * resume, although the specification states very clearly that this flag is
  78. * owned by the hardware. The set_sci_en_on_resume variable will be set in such
  79. * cases.
  80. */
  81. static bool set_sci_en_on_resume;
  82. void __init acpi_set_sci_en_on_resume(void)
  83. {
  84. set_sci_en_on_resume = true;
  85. }
  86. /*
  87. * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
  88. * user to request that behavior by using the 'acpi_old_suspend_ordering'
  89. * kernel command line option that causes the following variable to be set.
  90. */
  91. static bool old_suspend_ordering;
  92. void __init acpi_old_suspend_ordering(void)
  93. {
  94. old_suspend_ordering = true;
  95. }
  96. /**
  97. * acpi_pm_disable_gpes - Disable the GPEs.
  98. */
  99. static int acpi_pm_disable_gpes(void)
  100. {
  101. acpi_disable_all_gpes();
  102. return 0;
  103. }
  104. /**
  105. * __acpi_pm_prepare - Prepare the platform to enter the target state.
  106. *
  107. * If necessary, set the firmware waking vector and do arch-specific
  108. * nastiness to get the wakeup code to the waking vector.
  109. */
  110. static int __acpi_pm_prepare(void)
  111. {
  112. int error = acpi_sleep_prepare(acpi_target_sleep_state);
  113. if (error)
  114. acpi_target_sleep_state = ACPI_STATE_S0;
  115. return error;
  116. }
  117. /**
  118. * acpi_pm_prepare - Prepare the platform to enter the target sleep
  119. * state and disable the GPEs.
  120. */
  121. static int acpi_pm_prepare(void)
  122. {
  123. int error = __acpi_pm_prepare();
  124. if (!error)
  125. acpi_disable_all_gpes();
  126. return error;
  127. }
  128. /**
  129. * acpi_pm_finish - Instruct the platform to leave a sleep state.
  130. *
  131. * This is called after we wake back up (or if entering the sleep state
  132. * failed).
  133. */
  134. static void acpi_pm_finish(void)
  135. {
  136. u32 acpi_state = acpi_target_sleep_state;
  137. if (acpi_state == ACPI_STATE_S0)
  138. return;
  139. printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
  140. acpi_state);
  141. acpi_disable_wakeup_device(acpi_state);
  142. acpi_leave_sleep_state(acpi_state);
  143. /* reset firmware waking vector */
  144. acpi_set_firmware_waking_vector((acpi_physical_address) 0);
  145. acpi_target_sleep_state = ACPI_STATE_S0;
  146. }
  147. /**
  148. * acpi_pm_end - Finish up suspend sequence.
  149. */
  150. static void acpi_pm_end(void)
  151. {
  152. /*
  153. * This is necessary in case acpi_pm_finish() is not called during a
  154. * failing transition to a sleep state.
  155. */
  156. acpi_target_sleep_state = ACPI_STATE_S0;
  157. acpi_sleep_tts_switch(acpi_target_sleep_state);
  158. }
  159. #else /* !CONFIG_ACPI_SLEEP */
  160. #define acpi_target_sleep_state ACPI_STATE_S0
  161. #endif /* CONFIG_ACPI_SLEEP */
  162. #ifdef CONFIG_SUSPEND
  163. extern void do_suspend_lowlevel(void);
  164. static u32 acpi_suspend_states[] = {
  165. [PM_SUSPEND_ON] = ACPI_STATE_S0,
  166. [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
  167. [PM_SUSPEND_MEM] = ACPI_STATE_S3,
  168. [PM_SUSPEND_MAX] = ACPI_STATE_S5
  169. };
  170. /**
  171. * acpi_suspend_begin - Set the target system sleep state to the state
  172. * associated with given @pm_state, if supported.
  173. */
  174. static int acpi_suspend_begin(suspend_state_t pm_state)
  175. {
  176. u32 acpi_state = acpi_suspend_states[pm_state];
  177. int error = 0;
  178. if (sleep_states[acpi_state]) {
  179. acpi_target_sleep_state = acpi_state;
  180. acpi_sleep_tts_switch(acpi_target_sleep_state);
  181. } else {
  182. printk(KERN_ERR "ACPI does not support this state: %d\n",
  183. pm_state);
  184. error = -ENOSYS;
  185. }
  186. return error;
  187. }
  188. /**
  189. * acpi_suspend_enter - Actually enter a sleep state.
  190. * @pm_state: ignored
  191. *
  192. * Flush caches and go to sleep. For STR we have to call arch-specific
  193. * assembly, which in turn call acpi_enter_sleep_state().
  194. * It's unfortunate, but it works. Please fix if you're feeling frisky.
  195. */
  196. static int acpi_suspend_enter(suspend_state_t pm_state)
  197. {
  198. acpi_status status = AE_OK;
  199. unsigned long flags = 0;
  200. u32 acpi_state = acpi_target_sleep_state;
  201. ACPI_FLUSH_CPU_CACHE();
  202. /* Do arch specific saving of state. */
  203. if (acpi_state == ACPI_STATE_S3) {
  204. int error = acpi_save_state_mem();
  205. if (error)
  206. return error;
  207. }
  208. local_irq_save(flags);
  209. acpi_enable_wakeup_device(acpi_state);
  210. switch (acpi_state) {
  211. case ACPI_STATE_S1:
  212. barrier();
  213. status = acpi_enter_sleep_state(acpi_state);
  214. break;
  215. case ACPI_STATE_S3:
  216. do_suspend_lowlevel();
  217. break;
  218. }
  219. /* If ACPI is not enabled by the BIOS, we need to enable it here. */
  220. if (set_sci_en_on_resume)
  221. acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
  222. else
  223. acpi_enable();
  224. /* Reprogram control registers and execute _BFS */
  225. acpi_leave_sleep_state_prep(acpi_state);
  226. /* ACPI 3.0 specs (P62) says that it's the responsibility
  227. * of the OSPM to clear the status bit [ implying that the
  228. * POWER_BUTTON event should not reach userspace ]
  229. */
  230. if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
  231. acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
  232. /*
  233. * Disable and clear GPE status before interrupt is enabled. Some GPEs
  234. * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
  235. * acpi_leave_sleep_state will reenable specific GPEs later
  236. */
  237. acpi_disable_all_gpes();
  238. local_irq_restore(flags);
  239. printk(KERN_DEBUG "Back to C!\n");
  240. /* restore processor state */
  241. if (acpi_state == ACPI_STATE_S3)
  242. acpi_restore_state_mem();
  243. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  244. }
  245. static int acpi_suspend_state_valid(suspend_state_t pm_state)
  246. {
  247. u32 acpi_state;
  248. switch (pm_state) {
  249. case PM_SUSPEND_ON:
  250. case PM_SUSPEND_STANDBY:
  251. case PM_SUSPEND_MEM:
  252. acpi_state = acpi_suspend_states[pm_state];
  253. return sleep_states[acpi_state];
  254. default:
  255. return 0;
  256. }
  257. }
  258. static struct platform_suspend_ops acpi_suspend_ops = {
  259. .valid = acpi_suspend_state_valid,
  260. .begin = acpi_suspend_begin,
  261. .prepare_late = acpi_pm_prepare,
  262. .enter = acpi_suspend_enter,
  263. .wake = acpi_pm_finish,
  264. .end = acpi_pm_end,
  265. };
  266. /**
  267. * acpi_suspend_begin_old - Set the target system sleep state to the
  268. * state associated with given @pm_state, if supported, and
  269. * execute the _PTS control method. This function is used if the
  270. * pre-ACPI 2.0 suspend ordering has been requested.
  271. */
  272. static int acpi_suspend_begin_old(suspend_state_t pm_state)
  273. {
  274. int error = acpi_suspend_begin(pm_state);
  275. if (!error)
  276. error = __acpi_pm_prepare();
  277. return error;
  278. }
  279. /*
  280. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  281. * been requested.
  282. */
  283. static struct platform_suspend_ops acpi_suspend_ops_old = {
  284. .valid = acpi_suspend_state_valid,
  285. .begin = acpi_suspend_begin_old,
  286. .prepare_late = acpi_pm_disable_gpes,
  287. .enter = acpi_suspend_enter,
  288. .wake = acpi_pm_finish,
  289. .end = acpi_pm_end,
  290. .recover = acpi_pm_finish,
  291. };
  292. static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
  293. {
  294. old_suspend_ordering = true;
  295. return 0;
  296. }
  297. static int __init init_set_sci_en_on_resume(const struct dmi_system_id *d)
  298. {
  299. set_sci_en_on_resume = true;
  300. return 0;
  301. }
  302. static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
  303. {
  304. .callback = init_old_suspend_ordering,
  305. .ident = "Abit KN9 (nForce4 variant)",
  306. .matches = {
  307. DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
  308. DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
  309. },
  310. },
  311. {
  312. .callback = init_old_suspend_ordering,
  313. .ident = "HP xw4600 Workstation",
  314. .matches = {
  315. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  316. DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
  317. },
  318. },
  319. {
  320. .callback = init_set_sci_en_on_resume,
  321. .ident = "Apple MacBook 1,1",
  322. .matches = {
  323. DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
  324. DMI_MATCH(DMI_PRODUCT_NAME, "MacBook1,1"),
  325. },
  326. },
  327. {
  328. .callback = init_set_sci_en_on_resume,
  329. .ident = "Apple MacMini 1,1",
  330. .matches = {
  331. DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
  332. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  333. },
  334. },
  335. {
  336. .callback = init_old_suspend_ordering,
  337. .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
  338. .matches = {
  339. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
  340. DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
  341. },
  342. },
  343. {
  344. .callback = init_set_sci_en_on_resume,
  345. .ident = "Toshiba Satellite L300",
  346. .matches = {
  347. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  348. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite L300"),
  349. },
  350. },
  351. {
  352. .callback = init_set_sci_en_on_resume,
  353. .ident = "Hewlett-Packard HP G7000 Notebook PC",
  354. .matches = {
  355. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  356. DMI_MATCH(DMI_PRODUCT_NAME, "HP G7000 Notebook PC"),
  357. },
  358. },
  359. {
  360. .callback = init_set_sci_en_on_resume,
  361. .ident = "Hewlett-Packard HP Pavilion dv3 Notebook PC",
  362. .matches = {
  363. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  364. DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv3 Notebook PC"),
  365. },
  366. },
  367. {
  368. .callback = init_set_sci_en_on_resume,
  369. .ident = "Hewlett-Packard Pavilion dv4",
  370. .matches = {
  371. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  372. DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv4"),
  373. },
  374. },
  375. {
  376. .callback = init_set_sci_en_on_resume,
  377. .ident = "Hewlett-Packard Pavilion dv7",
  378. .matches = {
  379. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  380. DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv7"),
  381. },
  382. },
  383. {
  384. .callback = init_set_sci_en_on_resume,
  385. .ident = "Hewlett-Packard Compaq Presario C700 Notebook PC",
  386. .matches = {
  387. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  388. DMI_MATCH(DMI_PRODUCT_NAME, "Compaq Presario C700 Notebook PC"),
  389. },
  390. },
  391. {
  392. .callback = init_set_sci_en_on_resume,
  393. .ident = "Hewlett-Packard Compaq Presario CQ40 Notebook PC",
  394. .matches = {
  395. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  396. DMI_MATCH(DMI_PRODUCT_NAME, "Compaq Presario CQ40 Notebook PC"),
  397. },
  398. },
  399. {
  400. .callback = init_set_sci_en_on_resume,
  401. .ident = "Lenovo ThinkPad T410",
  402. .matches = {
  403. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  404. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T410"),
  405. },
  406. },
  407. {
  408. .callback = init_set_sci_en_on_resume,
  409. .ident = "Lenovo ThinkPad T510",
  410. .matches = {
  411. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  412. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T510"),
  413. },
  414. },
  415. {
  416. .callback = init_set_sci_en_on_resume,
  417. .ident = "Lenovo ThinkPad W510",
  418. .matches = {
  419. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  420. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad W510"),
  421. },
  422. },
  423. {
  424. .callback = init_set_sci_en_on_resume,
  425. .ident = "Lenovo ThinkPad X201",
  426. .matches = {
  427. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  428. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201"),
  429. },
  430. },
  431. {
  432. .callback = init_set_sci_en_on_resume,
  433. .ident = "Lenovo ThinkPad X201",
  434. .matches = {
  435. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  436. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
  437. },
  438. },
  439. {
  440. .callback = init_set_sci_en_on_resume,
  441. .ident = "Lenovo ThinkPad T410",
  442. .matches = {
  443. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  444. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T410"),
  445. },
  446. },
  447. {
  448. .callback = init_set_sci_en_on_resume,
  449. .ident = "Lenovo ThinkPad T510",
  450. .matches = {
  451. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  452. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T510"),
  453. },
  454. },
  455. {
  456. .callback = init_set_sci_en_on_resume,
  457. .ident = "Lenovo ThinkPad W510",
  458. .matches = {
  459. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  460. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad W510"),
  461. },
  462. },
  463. {
  464. .callback = init_set_sci_en_on_resume,
  465. .ident = "Lenovo ThinkPad X201",
  466. .matches = {
  467. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  468. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201"),
  469. },
  470. },
  471. {
  472. .callback = init_set_sci_en_on_resume,
  473. .ident = "Lenovo ThinkPad X201",
  474. .matches = {
  475. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  476. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
  477. },
  478. },
  479. {
  480. .callback = init_set_sci_en_on_resume,
  481. .ident = "Lenovo ThinkPad T410",
  482. .matches = {
  483. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  484. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T410"),
  485. },
  486. },
  487. {
  488. .callback = init_set_sci_en_on_resume,
  489. .ident = "Lenovo ThinkPad T510",
  490. .matches = {
  491. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  492. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T510"),
  493. },
  494. },
  495. {
  496. .callback = init_set_sci_en_on_resume,
  497. .ident = "Lenovo ThinkPad W510",
  498. .matches = {
  499. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  500. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad W510"),
  501. },
  502. },
  503. {
  504. .callback = init_set_sci_en_on_resume,
  505. .ident = "Lenovo ThinkPad X201",
  506. .matches = {
  507. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  508. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201"),
  509. },
  510. },
  511. {
  512. .callback = init_set_sci_en_on_resume,
  513. .ident = "Lenovo ThinkPad X201",
  514. .matches = {
  515. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  516. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
  517. },
  518. },
  519. {
  520. .callback = init_old_suspend_ordering,
  521. .ident = "Panasonic CF51-2L",
  522. .matches = {
  523. DMI_MATCH(DMI_BOARD_VENDOR,
  524. "Matsushita Electric Industrial Co.,Ltd."),
  525. DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
  526. },
  527. },
  528. {},
  529. };
  530. #endif /* CONFIG_SUSPEND */
  531. #ifdef CONFIG_HIBERNATION
  532. /*
  533. * The ACPI specification wants us to save NVS memory regions during hibernation
  534. * and to restore them during the subsequent resume. However, it is not certain
  535. * if this mechanism is going to work on all machines, so we allow the user to
  536. * disable this mechanism using the 'acpi_sleep=s4_nonvs' kernel command line
  537. * option.
  538. */
  539. static bool s4_no_nvs;
  540. void __init acpi_s4_no_nvs(void)
  541. {
  542. s4_no_nvs = true;
  543. }
  544. static unsigned long s4_hardware_signature;
  545. static struct acpi_table_facs *facs;
  546. static bool nosigcheck;
  547. void __init acpi_no_s4_hw_signature(void)
  548. {
  549. nosigcheck = true;
  550. }
  551. static int acpi_hibernation_begin(void)
  552. {
  553. int error;
  554. error = s4_no_nvs ? 0 : hibernate_nvs_alloc();
  555. if (!error) {
  556. acpi_target_sleep_state = ACPI_STATE_S4;
  557. acpi_sleep_tts_switch(acpi_target_sleep_state);
  558. }
  559. return error;
  560. }
  561. static int acpi_hibernation_pre_snapshot(void)
  562. {
  563. int error = acpi_pm_prepare();
  564. if (!error)
  565. hibernate_nvs_save();
  566. return error;
  567. }
  568. static int acpi_hibernation_enter(void)
  569. {
  570. acpi_status status = AE_OK;
  571. unsigned long flags = 0;
  572. ACPI_FLUSH_CPU_CACHE();
  573. local_irq_save(flags);
  574. acpi_enable_wakeup_device(ACPI_STATE_S4);
  575. /* This shouldn't return. If it returns, we have a problem */
  576. status = acpi_enter_sleep_state(ACPI_STATE_S4);
  577. /* Reprogram control registers and execute _BFS */
  578. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  579. local_irq_restore(flags);
  580. return ACPI_SUCCESS(status) ? 0 : -EFAULT;
  581. }
  582. static void acpi_hibernation_finish(void)
  583. {
  584. hibernate_nvs_free();
  585. acpi_pm_finish();
  586. }
  587. static void acpi_hibernation_leave(void)
  588. {
  589. /*
  590. * If ACPI is not enabled by the BIOS and the boot kernel, we need to
  591. * enable it here.
  592. */
  593. acpi_enable();
  594. /* Reprogram control registers and execute _BFS */
  595. acpi_leave_sleep_state_prep(ACPI_STATE_S4);
  596. /* Check the hardware signature */
  597. if (facs && s4_hardware_signature != facs->hardware_signature) {
  598. printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
  599. "cannot resume!\n");
  600. panic("ACPI S4 hardware signature mismatch");
  601. }
  602. /* Restore the NVS memory area */
  603. hibernate_nvs_restore();
  604. }
  605. static int acpi_pm_pre_restore(void)
  606. {
  607. acpi_disable_all_gpes();
  608. acpi_os_wait_events_complete(NULL);
  609. acpi_ec_suspend_transactions();
  610. return 0;
  611. }
  612. static void acpi_pm_restore_cleanup(void)
  613. {
  614. acpi_ec_resume_transactions();
  615. acpi_enable_all_runtime_gpes();
  616. }
  617. static struct platform_hibernation_ops acpi_hibernation_ops = {
  618. .begin = acpi_hibernation_begin,
  619. .end = acpi_pm_end,
  620. .pre_snapshot = acpi_hibernation_pre_snapshot,
  621. .finish = acpi_hibernation_finish,
  622. .prepare = acpi_pm_prepare,
  623. .enter = acpi_hibernation_enter,
  624. .leave = acpi_hibernation_leave,
  625. .pre_restore = acpi_pm_pre_restore,
  626. .restore_cleanup = acpi_pm_restore_cleanup,
  627. };
  628. /**
  629. * acpi_hibernation_begin_old - Set the target system sleep state to
  630. * ACPI_STATE_S4 and execute the _PTS control method. This
  631. * function is used if the pre-ACPI 2.0 suspend ordering has been
  632. * requested.
  633. */
  634. static int acpi_hibernation_begin_old(void)
  635. {
  636. int error;
  637. /*
  638. * The _TTS object should always be evaluated before the _PTS object.
  639. * When the old_suspended_ordering is true, the _PTS object is
  640. * evaluated in the acpi_sleep_prepare.
  641. */
  642. acpi_sleep_tts_switch(ACPI_STATE_S4);
  643. error = acpi_sleep_prepare(ACPI_STATE_S4);
  644. if (!error) {
  645. if (!s4_no_nvs)
  646. error = hibernate_nvs_alloc();
  647. if (!error)
  648. acpi_target_sleep_state = ACPI_STATE_S4;
  649. }
  650. return error;
  651. }
  652. static int acpi_hibernation_pre_snapshot_old(void)
  653. {
  654. int error = acpi_pm_disable_gpes();
  655. if (!error)
  656. hibernate_nvs_save();
  657. return error;
  658. }
  659. /*
  660. * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
  661. * been requested.
  662. */
  663. static struct platform_hibernation_ops acpi_hibernation_ops_old = {
  664. .begin = acpi_hibernation_begin_old,
  665. .end = acpi_pm_end,
  666. .pre_snapshot = acpi_hibernation_pre_snapshot_old,
  667. .finish = acpi_hibernation_finish,
  668. .prepare = acpi_pm_disable_gpes,
  669. .enter = acpi_hibernation_enter,
  670. .leave = acpi_hibernation_leave,
  671. .pre_restore = acpi_pm_pre_restore,
  672. .restore_cleanup = acpi_pm_restore_cleanup,
  673. .recover = acpi_pm_finish,
  674. };
  675. #endif /* CONFIG_HIBERNATION */
  676. int acpi_suspend(u32 acpi_state)
  677. {
  678. suspend_state_t states[] = {
  679. [1] = PM_SUSPEND_STANDBY,
  680. [3] = PM_SUSPEND_MEM,
  681. [5] = PM_SUSPEND_MAX
  682. };
  683. if (acpi_state < 6 && states[acpi_state])
  684. return pm_suspend(states[acpi_state]);
  685. if (acpi_state == 4)
  686. return hibernate();
  687. return -EINVAL;
  688. }
  689. #ifdef CONFIG_PM_SLEEP
  690. /**
  691. * acpi_pm_device_sleep_state - return preferred power state of ACPI device
  692. * in the system sleep state given by %acpi_target_sleep_state
  693. * @dev: device to examine; its driver model wakeup flags control
  694. * whether it should be able to wake up the system
  695. * @d_min_p: used to store the upper limit of allowed states range
  696. * Return value: preferred power state of the device on success, -ENODEV on
  697. * failure (ie. if there's no 'struct acpi_device' for @dev)
  698. *
  699. * Find the lowest power (highest number) ACPI device power state that
  700. * device @dev can be in while the system is in the sleep state represented
  701. * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
  702. * able to wake up the system from this sleep state. If @d_min_p is set,
  703. * the highest power (lowest number) device power state of @dev allowed
  704. * in this system sleep state is stored at the location pointed to by it.
  705. *
  706. * The caller must ensure that @dev is valid before using this function.
  707. * The caller is also responsible for figuring out if the device is
  708. * supposed to be able to wake up the system and passing this information
  709. * via @wake.
  710. */
  711. int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
  712. {
  713. acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
  714. struct acpi_device *adev;
  715. char acpi_method[] = "_SxD";
  716. unsigned long long d_min, d_max;
  717. if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
  718. printk(KERN_DEBUG "ACPI handle has no context!\n");
  719. return -ENODEV;
  720. }
  721. acpi_method[2] = '0' + acpi_target_sleep_state;
  722. /*
  723. * If the sleep state is S0, we will return D3, but if the device has
  724. * _S0W, we will use the value from _S0W
  725. */
  726. d_min = ACPI_STATE_D0;
  727. d_max = ACPI_STATE_D3;
  728. /*
  729. * If present, _SxD methods return the minimum D-state (highest power
  730. * state) we can use for the corresponding S-states. Otherwise, the
  731. * minimum D-state is D0 (ACPI 3.x).
  732. *
  733. * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
  734. * provided -- that's our fault recovery, we ignore retval.
  735. */
  736. if (acpi_target_sleep_state > ACPI_STATE_S0)
  737. acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
  738. /*
  739. * If _PRW says we can wake up the system from the target sleep state,
  740. * the D-state returned by _SxD is sufficient for that (we assume a
  741. * wakeup-aware driver if wake is set). Still, if _SxW exists
  742. * (ACPI 3.x), it should return the maximum (lowest power) D-state that
  743. * can wake the system. _S0W may be valid, too.
  744. */
  745. if (acpi_target_sleep_state == ACPI_STATE_S0 ||
  746. (device_may_wakeup(dev) && adev->wakeup.state.enabled &&
  747. adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
  748. acpi_status status;
  749. acpi_method[3] = 'W';
  750. status = acpi_evaluate_integer(handle, acpi_method, NULL,
  751. &d_max);
  752. if (ACPI_FAILURE(status)) {
  753. d_max = d_min;
  754. } else if (d_max < d_min) {
  755. /* Warn the user of the broken DSDT */
  756. printk(KERN_WARNING "ACPI: Wrong value from %s\n",
  757. acpi_method);
  758. /* Sanitize it */
  759. d_min = d_max;
  760. }
  761. }
  762. if (d_min_p)
  763. *d_min_p = d_min;
  764. return d_max;
  765. }
  766. /**
  767. * acpi_pm_device_sleep_wake - enable or disable the system wake-up
  768. * capability of given device
  769. * @dev: device to handle
  770. * @enable: 'true' - enable, 'false' - disable the wake-up capability
  771. */
  772. int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
  773. {
  774. acpi_handle handle;
  775. struct acpi_device *adev;
  776. int error;
  777. if (!device_can_wakeup(dev))
  778. return -EINVAL;
  779. handle = DEVICE_ACPI_HANDLE(dev);
  780. if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
  781. dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
  782. return -ENODEV;
  783. }
  784. if (enable) {
  785. error = acpi_enable_wakeup_device_power(adev,
  786. acpi_target_sleep_state);
  787. if (!error)
  788. acpi_enable_gpe(adev->wakeup.gpe_device,
  789. adev->wakeup.gpe_number,
  790. ACPI_GPE_TYPE_WAKE);
  791. } else {
  792. acpi_disable_gpe(adev->wakeup.gpe_device, adev->wakeup.gpe_number,
  793. ACPI_GPE_TYPE_WAKE);
  794. error = acpi_disable_wakeup_device_power(adev);
  795. }
  796. if (!error)
  797. dev_info(dev, "wake-up capability %s by ACPI\n",
  798. enable ? "enabled" : "disabled");
  799. return error;
  800. }
  801. #endif
  802. static void acpi_power_off_prepare(void)
  803. {
  804. /* Prepare to power off the system */
  805. acpi_sleep_prepare(ACPI_STATE_S5);
  806. acpi_disable_all_gpes();
  807. }
  808. static void acpi_power_off(void)
  809. {
  810. /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
  811. printk(KERN_DEBUG "%s called\n", __func__);
  812. local_irq_disable();
  813. acpi_enable_wakeup_device(ACPI_STATE_S5);
  814. acpi_enter_sleep_state(ACPI_STATE_S5);
  815. }
  816. /*
  817. * ACPI 2.0 created the optional _GTS and _BFS,
  818. * but industry adoption has been neither rapid nor broad.
  819. *
  820. * Linux gets into trouble when it executes poorly validated
  821. * paths through the BIOS, so disable _GTS and _BFS by default,
  822. * but do speak up and offer the option to enable them.
  823. */
  824. void __init acpi_gts_bfs_check(void)
  825. {
  826. acpi_handle dummy;
  827. if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__GTS, &dummy)))
  828. {
  829. printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
  830. printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
  831. "please notify linux-acpi@vger.kernel.org\n");
  832. }
  833. if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__BFS, &dummy)))
  834. {
  835. printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
  836. printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
  837. "please notify linux-acpi@vger.kernel.org\n");
  838. }
  839. }
  840. int __init acpi_sleep_init(void)
  841. {
  842. acpi_status status;
  843. u8 type_a, type_b;
  844. #ifdef CONFIG_SUSPEND
  845. int i = 0;
  846. dmi_check_system(acpisleep_dmi_table);
  847. #endif
  848. if (acpi_disabled)
  849. return 0;
  850. sleep_states[ACPI_STATE_S0] = 1;
  851. printk(KERN_INFO PREFIX "(supports S0");
  852. #ifdef CONFIG_SUSPEND
  853. for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
  854. status = acpi_get_sleep_type_data(i, &type_a, &type_b);
  855. if (ACPI_SUCCESS(status)) {
  856. sleep_states[i] = 1;
  857. printk(" S%d", i);
  858. }
  859. }
  860. suspend_set_ops(old_suspend_ordering ?
  861. &acpi_suspend_ops_old : &acpi_suspend_ops);
  862. #endif
  863. #ifdef CONFIG_HIBERNATION
  864. status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
  865. if (ACPI_SUCCESS(status)) {
  866. hibernation_set_ops(old_suspend_ordering ?
  867. &acpi_hibernation_ops_old : &acpi_hibernation_ops);
  868. sleep_states[ACPI_STATE_S4] = 1;
  869. printk(" S4");
  870. if (!nosigcheck) {
  871. acpi_get_table(ACPI_SIG_FACS, 1,
  872. (struct acpi_table_header **)&facs);
  873. if (facs)
  874. s4_hardware_signature =
  875. facs->hardware_signature;
  876. }
  877. }
  878. #endif
  879. status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
  880. if (ACPI_SUCCESS(status)) {
  881. sleep_states[ACPI_STATE_S5] = 1;
  882. printk(" S5");
  883. pm_power_off_prepare = acpi_power_off_prepare;
  884. pm_power_off = acpi_power_off;
  885. }
  886. printk(")\n");
  887. /*
  888. * Register the tts_notifier to reboot notifier list so that the _TTS
  889. * object can also be evaluated when the system enters S5.
  890. */
  891. register_reboot_notifier(&tts_notifier);
  892. acpi_gts_bfs_check();
  893. return 0;
  894. }