power.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * acpi_power.c - ACPI Bus Power Management ($Revision: 39 $)
  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. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. /*
  26. * ACPI power-managed devices may be controlled in two ways:
  27. * 1. via "Device Specific (D-State) Control"
  28. * 2. via "Power Resource Control".
  29. * This module is used to manage devices relying on Power Resource Control.
  30. *
  31. * An ACPI "power resource object" describes a software controllable power
  32. * plane, clock plane, or other resource used by a power managed device.
  33. * A device may rely on multiple power resources, and a power resource
  34. * may be shared by multiple devices.
  35. */
  36. #include <linux/kernel.h>
  37. #include <linux/module.h>
  38. #include <linux/init.h>
  39. #include <linux/types.h>
  40. #include <linux/slab.h>
  41. #include <linux/pm_runtime.h>
  42. #include <acpi/acpi_bus.h>
  43. #include <acpi/acpi_drivers.h>
  44. #include "sleep.h"
  45. #include "internal.h"
  46. #define PREFIX "ACPI: "
  47. #define _COMPONENT ACPI_POWER_COMPONENT
  48. ACPI_MODULE_NAME("power");
  49. #define ACPI_POWER_CLASS "power_resource"
  50. #define ACPI_POWER_DEVICE_NAME "Power Resource"
  51. #define ACPI_POWER_FILE_INFO "info"
  52. #define ACPI_POWER_FILE_STATUS "state"
  53. #define ACPI_POWER_RESOURCE_STATE_OFF 0x00
  54. #define ACPI_POWER_RESOURCE_STATE_ON 0x01
  55. #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
  56. struct acpi_power_dependent_device {
  57. struct list_head node;
  58. struct acpi_device *adev;
  59. struct work_struct work;
  60. };
  61. struct acpi_power_resource {
  62. struct acpi_device device;
  63. struct list_head list_node;
  64. struct list_head dependent;
  65. char *name;
  66. u32 system_level;
  67. u32 order;
  68. unsigned int ref_count;
  69. struct mutex resource_lock;
  70. };
  71. static LIST_HEAD(acpi_power_resource_list);
  72. static DEFINE_MUTEX(power_resource_list_lock);
  73. /* --------------------------------------------------------------------------
  74. Power Resource Management
  75. -------------------------------------------------------------------------- */
  76. static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle)
  77. {
  78. struct acpi_device *device;
  79. if (acpi_bus_get_device(handle, &device))
  80. return NULL;
  81. return container_of(device, struct acpi_power_resource, device);
  82. }
  83. static int acpi_power_get_state(acpi_handle handle, int *state)
  84. {
  85. acpi_status status = AE_OK;
  86. unsigned long long sta = 0;
  87. char node_name[5];
  88. struct acpi_buffer buffer = { sizeof(node_name), node_name };
  89. if (!handle || !state)
  90. return -EINVAL;
  91. status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
  92. if (ACPI_FAILURE(status))
  93. return -ENODEV;
  94. *state = (sta & 0x01)?ACPI_POWER_RESOURCE_STATE_ON:
  95. ACPI_POWER_RESOURCE_STATE_OFF;
  96. acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
  97. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n",
  98. node_name,
  99. *state ? "on" : "off"));
  100. return 0;
  101. }
  102. static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
  103. {
  104. int cur_state;
  105. int i = 0;
  106. if (!list || !state)
  107. return -EINVAL;
  108. /* The state of the list is 'on' IFF all resources are 'on'. */
  109. for (i = 0; i < list->count; i++) {
  110. struct acpi_power_resource *resource;
  111. acpi_handle handle = list->handles[i];
  112. int result;
  113. resource = acpi_power_get_context(handle);
  114. if (!resource)
  115. return -ENODEV;
  116. mutex_lock(&resource->resource_lock);
  117. result = acpi_power_get_state(handle, &cur_state);
  118. mutex_unlock(&resource->resource_lock);
  119. if (result)
  120. return result;
  121. if (cur_state != ACPI_POWER_RESOURCE_STATE_ON)
  122. break;
  123. }
  124. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource list is %s\n",
  125. cur_state ? "on" : "off"));
  126. *state = cur_state;
  127. return 0;
  128. }
  129. static void acpi_power_resume_dependent(struct work_struct *work)
  130. {
  131. struct acpi_power_dependent_device *dep;
  132. struct acpi_device_physical_node *pn;
  133. struct acpi_device *adev;
  134. int state;
  135. dep = container_of(work, struct acpi_power_dependent_device, work);
  136. adev = dep->adev;
  137. if (acpi_power_get_inferred_state(adev, &state))
  138. return;
  139. if (state > ACPI_STATE_D0)
  140. return;
  141. mutex_lock(&adev->physical_node_lock);
  142. list_for_each_entry(pn, &adev->physical_node_list, node)
  143. pm_request_resume(pn->dev);
  144. list_for_each_entry(pn, &adev->power_dependent, node)
  145. pm_request_resume(pn->dev);
  146. mutex_unlock(&adev->physical_node_lock);
  147. }
  148. static int __acpi_power_on(struct acpi_power_resource *resource)
  149. {
  150. acpi_status status = AE_OK;
  151. status = acpi_evaluate_object(resource->device.handle, "_ON", NULL, NULL);
  152. if (ACPI_FAILURE(status))
  153. return -ENODEV;
  154. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
  155. resource->name));
  156. return 0;
  157. }
  158. static int acpi_power_on(acpi_handle handle)
  159. {
  160. int result = 0;
  161. struct acpi_power_resource *resource;
  162. resource = acpi_power_get_context(handle);
  163. if (!resource)
  164. return -ENODEV;
  165. mutex_lock(&resource->resource_lock);
  166. if (resource->ref_count++) {
  167. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  168. "Power resource [%s] already on",
  169. resource->name));
  170. } else {
  171. result = __acpi_power_on(resource);
  172. if (result) {
  173. resource->ref_count--;
  174. } else {
  175. struct acpi_power_dependent_device *dep;
  176. list_for_each_entry(dep, &resource->dependent, node)
  177. schedule_work(&dep->work);
  178. }
  179. }
  180. mutex_unlock(&resource->resource_lock);
  181. return result;
  182. }
  183. static int acpi_power_off(acpi_handle handle)
  184. {
  185. int result = 0;
  186. acpi_status status = AE_OK;
  187. struct acpi_power_resource *resource;
  188. resource = acpi_power_get_context(handle);
  189. if (!resource)
  190. return -ENODEV;
  191. mutex_lock(&resource->resource_lock);
  192. if (!resource->ref_count) {
  193. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  194. "Power resource [%s] already off",
  195. resource->name));
  196. goto unlock;
  197. }
  198. if (--resource->ref_count) {
  199. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  200. "Power resource [%s] still in use\n",
  201. resource->name));
  202. goto unlock;
  203. }
  204. status = acpi_evaluate_object(resource->device.handle, "_OFF", NULL, NULL);
  205. if (ACPI_FAILURE(status))
  206. result = -ENODEV;
  207. else
  208. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  209. "Power resource [%s] turned off\n",
  210. resource->name));
  211. unlock:
  212. mutex_unlock(&resource->resource_lock);
  213. return result;
  214. }
  215. static void __acpi_power_off_list(struct acpi_handle_list *list, int num_res)
  216. {
  217. int i;
  218. for (i = num_res - 1; i >= 0 ; i--)
  219. acpi_power_off(list->handles[i]);
  220. }
  221. static void acpi_power_off_list(struct acpi_handle_list *list)
  222. {
  223. __acpi_power_off_list(list, list->count);
  224. }
  225. static int acpi_power_on_list(struct acpi_handle_list *list)
  226. {
  227. int result = 0;
  228. int i;
  229. for (i = 0; i < list->count; i++) {
  230. result = acpi_power_on(list->handles[i]);
  231. if (result) {
  232. __acpi_power_off_list(list, i);
  233. break;
  234. }
  235. }
  236. return result;
  237. }
  238. static void acpi_power_add_dependent(acpi_handle rhandle,
  239. struct acpi_device *adev)
  240. {
  241. struct acpi_power_dependent_device *dep;
  242. struct acpi_power_resource *resource;
  243. if (!rhandle || !adev)
  244. return;
  245. resource = acpi_power_get_context(rhandle);
  246. if (!resource)
  247. return;
  248. mutex_lock(&resource->resource_lock);
  249. list_for_each_entry(dep, &resource->dependent, node)
  250. if (dep->adev == adev)
  251. goto out;
  252. dep = kzalloc(sizeof(*dep), GFP_KERNEL);
  253. if (!dep)
  254. goto out;
  255. dep->adev = adev;
  256. INIT_WORK(&dep->work, acpi_power_resume_dependent);
  257. list_add_tail(&dep->node, &resource->dependent);
  258. out:
  259. mutex_unlock(&resource->resource_lock);
  260. }
  261. static void acpi_power_remove_dependent(acpi_handle rhandle,
  262. struct acpi_device *adev)
  263. {
  264. struct acpi_power_dependent_device *dep;
  265. struct acpi_power_resource *resource;
  266. struct work_struct *work = NULL;
  267. if (!rhandle || !adev)
  268. return;
  269. resource = acpi_power_get_context(rhandle);
  270. if (!resource)
  271. return;
  272. mutex_lock(&resource->resource_lock);
  273. list_for_each_entry(dep, &resource->dependent, node)
  274. if (dep->adev == adev) {
  275. list_del(&dep->node);
  276. work = &dep->work;
  277. break;
  278. }
  279. mutex_unlock(&resource->resource_lock);
  280. if (work) {
  281. cancel_work_sync(work);
  282. kfree(dep);
  283. }
  284. }
  285. void acpi_power_add_remove_device(struct acpi_device *adev, bool add)
  286. {
  287. if (adev->power.flags.power_resources) {
  288. struct acpi_device_power_state *ps;
  289. int j;
  290. ps = &adev->power.states[ACPI_STATE_D0];
  291. for (j = 0; j < ps->resources.count; j++) {
  292. acpi_handle rhandle = ps->resources.handles[j];
  293. if (add)
  294. acpi_power_add_dependent(rhandle, adev);
  295. else
  296. acpi_power_remove_dependent(rhandle, adev);
  297. }
  298. }
  299. }
  300. /* --------------------------------------------------------------------------
  301. Device Power Management
  302. -------------------------------------------------------------------------- */
  303. /**
  304. * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in
  305. * ACPI 3.0) _PSW (Power State Wake)
  306. * @dev: Device to handle.
  307. * @enable: 0 - disable, 1 - enable the wake capabilities of the device.
  308. * @sleep_state: Target sleep state of the system.
  309. * @dev_state: Target power state of the device.
  310. *
  311. * Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
  312. * State Wake) for the device, if present. On failure reset the device's
  313. * wakeup.flags.valid flag.
  314. *
  315. * RETURN VALUE:
  316. * 0 if either _DSW or _PSW has been successfully executed
  317. * 0 if neither _DSW nor _PSW has been found
  318. * -ENODEV if the execution of either _DSW or _PSW has failed
  319. */
  320. int acpi_device_sleep_wake(struct acpi_device *dev,
  321. int enable, int sleep_state, int dev_state)
  322. {
  323. union acpi_object in_arg[3];
  324. struct acpi_object_list arg_list = { 3, in_arg };
  325. acpi_status status = AE_OK;
  326. /*
  327. * Try to execute _DSW first.
  328. *
  329. * Three agruments are needed for the _DSW object:
  330. * Argument 0: enable/disable the wake capabilities
  331. * Argument 1: target system state
  332. * Argument 2: target device state
  333. * When _DSW object is called to disable the wake capabilities, maybe
  334. * the first argument is filled. The values of the other two agruments
  335. * are meaningless.
  336. */
  337. in_arg[0].type = ACPI_TYPE_INTEGER;
  338. in_arg[0].integer.value = enable;
  339. in_arg[1].type = ACPI_TYPE_INTEGER;
  340. in_arg[1].integer.value = sleep_state;
  341. in_arg[2].type = ACPI_TYPE_INTEGER;
  342. in_arg[2].integer.value = dev_state;
  343. status = acpi_evaluate_object(dev->handle, "_DSW", &arg_list, NULL);
  344. if (ACPI_SUCCESS(status)) {
  345. return 0;
  346. } else if (status != AE_NOT_FOUND) {
  347. printk(KERN_ERR PREFIX "_DSW execution failed\n");
  348. dev->wakeup.flags.valid = 0;
  349. return -ENODEV;
  350. }
  351. /* Execute _PSW */
  352. arg_list.count = 1;
  353. in_arg[0].integer.value = enable;
  354. status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL);
  355. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  356. printk(KERN_ERR PREFIX "_PSW execution failed\n");
  357. dev->wakeup.flags.valid = 0;
  358. return -ENODEV;
  359. }
  360. return 0;
  361. }
  362. /*
  363. * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
  364. * 1. Power on the power resources required for the wakeup device
  365. * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
  366. * State Wake) for the device, if present
  367. */
  368. int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
  369. {
  370. int i, err = 0;
  371. if (!dev || !dev->wakeup.flags.valid)
  372. return -EINVAL;
  373. mutex_lock(&acpi_device_lock);
  374. if (dev->wakeup.prepare_count++)
  375. goto out;
  376. /* Open power resource */
  377. for (i = 0; i < dev->wakeup.resources.count; i++) {
  378. int ret = acpi_power_on(dev->wakeup.resources.handles[i]);
  379. if (ret) {
  380. printk(KERN_ERR PREFIX "Transition power state\n");
  381. dev->wakeup.flags.valid = 0;
  382. err = -ENODEV;
  383. goto err_out;
  384. }
  385. }
  386. /*
  387. * Passing 3 as the third argument below means the device may be placed
  388. * in arbitrary power state afterwards.
  389. */
  390. err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
  391. err_out:
  392. if (err)
  393. dev->wakeup.prepare_count = 0;
  394. out:
  395. mutex_unlock(&acpi_device_lock);
  396. return err;
  397. }
  398. /*
  399. * Shutdown a wakeup device, counterpart of above method
  400. * 1. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
  401. * State Wake) for the device, if present
  402. * 2. Shutdown down the power resources
  403. */
  404. int acpi_disable_wakeup_device_power(struct acpi_device *dev)
  405. {
  406. int i, err = 0;
  407. if (!dev || !dev->wakeup.flags.valid)
  408. return -EINVAL;
  409. mutex_lock(&acpi_device_lock);
  410. if (--dev->wakeup.prepare_count > 0)
  411. goto out;
  412. /*
  413. * Executing the code below even if prepare_count is already zero when
  414. * the function is called may be useful, for example for initialisation.
  415. */
  416. if (dev->wakeup.prepare_count < 0)
  417. dev->wakeup.prepare_count = 0;
  418. err = acpi_device_sleep_wake(dev, 0, 0, 0);
  419. if (err)
  420. goto out;
  421. /* Close power resource */
  422. for (i = 0; i < dev->wakeup.resources.count; i++) {
  423. int ret = acpi_power_off(dev->wakeup.resources.handles[i]);
  424. if (ret) {
  425. printk(KERN_ERR PREFIX "Transition power state\n");
  426. dev->wakeup.flags.valid = 0;
  427. err = -ENODEV;
  428. goto out;
  429. }
  430. }
  431. out:
  432. mutex_unlock(&acpi_device_lock);
  433. return err;
  434. }
  435. int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
  436. {
  437. int result = 0;
  438. struct acpi_handle_list *list = NULL;
  439. int list_state = 0;
  440. int i = 0;
  441. if (!device || !state)
  442. return -EINVAL;
  443. /*
  444. * We know a device's inferred power state when all the resources
  445. * required for a given D-state are 'on'.
  446. */
  447. for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
  448. list = &device->power.states[i].resources;
  449. if (list->count < 1)
  450. continue;
  451. result = acpi_power_get_list_state(list, &list_state);
  452. if (result)
  453. return result;
  454. if (list_state == ACPI_POWER_RESOURCE_STATE_ON) {
  455. *state = i;
  456. return 0;
  457. }
  458. }
  459. *state = ACPI_STATE_D3;
  460. return 0;
  461. }
  462. int acpi_power_on_resources(struct acpi_device *device, int state)
  463. {
  464. if (!device || state < ACPI_STATE_D0 || state > ACPI_STATE_D3)
  465. return -EINVAL;
  466. return acpi_power_on_list(&device->power.states[state].resources);
  467. }
  468. int acpi_power_transition(struct acpi_device *device, int state)
  469. {
  470. int result = 0;
  471. if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
  472. return -EINVAL;
  473. if (device->power.state == state)
  474. return 0;
  475. if ((device->power.state < ACPI_STATE_D0)
  476. || (device->power.state > ACPI_STATE_D3_COLD))
  477. return -ENODEV;
  478. /* TBD: Resources must be ordered. */
  479. /*
  480. * First we reference all power resources required in the target list
  481. * (e.g. so the device doesn't lose power while transitioning). Then,
  482. * we dereference all power resources used in the current list.
  483. */
  484. if (state < ACPI_STATE_D3_COLD)
  485. result = acpi_power_on_list(
  486. &device->power.states[state].resources);
  487. if (!result && device->power.state < ACPI_STATE_D3_COLD)
  488. acpi_power_off_list(
  489. &device->power.states[device->power.state].resources);
  490. /* We shouldn't change the state unless the above operations succeed. */
  491. device->power.state = result ? ACPI_STATE_UNKNOWN : state;
  492. return result;
  493. }
  494. static void acpi_release_power_resource(struct device *dev)
  495. {
  496. struct acpi_device *device = to_acpi_device(dev);
  497. struct acpi_power_resource *resource;
  498. resource = container_of(device, struct acpi_power_resource, device);
  499. mutex_lock(&power_resource_list_lock);
  500. list_del(&resource->list_node);
  501. mutex_unlock(&power_resource_list_lock);
  502. acpi_free_ids(device);
  503. kfree(resource);
  504. }
  505. void acpi_add_power_resource(acpi_handle handle)
  506. {
  507. struct acpi_power_resource *resource;
  508. struct acpi_device *device = NULL;
  509. union acpi_object acpi_object;
  510. struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object };
  511. acpi_status status;
  512. int state, result = -ENODEV;
  513. acpi_bus_get_device(handle, &device);
  514. if (device)
  515. return;
  516. resource = kzalloc(sizeof(*resource), GFP_KERNEL);
  517. if (!resource)
  518. return;
  519. device = &resource->device;
  520. acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER,
  521. ACPI_STA_DEFAULT);
  522. mutex_init(&resource->resource_lock);
  523. INIT_LIST_HEAD(&resource->dependent);
  524. resource->name = device->pnp.bus_id;
  525. strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
  526. strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
  527. device->power.state = ACPI_STATE_UNKNOWN;
  528. /* Evalute the object to get the system level and resource order. */
  529. status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
  530. if (ACPI_FAILURE(status))
  531. goto err;
  532. resource->system_level = acpi_object.power_resource.system_level;
  533. resource->order = acpi_object.power_resource.resource_order;
  534. result = acpi_power_get_state(handle, &state);
  535. if (result)
  536. goto err;
  537. printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device),
  538. acpi_device_bid(device), state ? "on" : "off");
  539. device->flags.match_driver = true;
  540. result = acpi_device_register(device, acpi_release_power_resource);
  541. if (result)
  542. goto err;
  543. mutex_lock(&power_resource_list_lock);
  544. list_add(&resource->list_node, &acpi_power_resource_list);
  545. mutex_unlock(&power_resource_list_lock);
  546. return;
  547. err:
  548. acpi_release_power_resource(&device->dev);
  549. }
  550. #ifdef CONFIG_ACPI_SLEEP
  551. void acpi_resume_power_resources(void)
  552. {
  553. struct acpi_power_resource *resource;
  554. mutex_lock(&power_resource_list_lock);
  555. list_for_each_entry(resource, &acpi_power_resource_list, list_node) {
  556. int result, state;
  557. mutex_lock(&resource->resource_lock);
  558. result = acpi_power_get_state(resource->device.handle, &state);
  559. if (!result && state == ACPI_POWER_RESOURCE_STATE_OFF
  560. && resource->ref_count) {
  561. dev_info(&resource->device.dev, "Turning ON\n");
  562. __acpi_power_on(resource);
  563. }
  564. mutex_unlock(&resource->resource_lock);
  565. }
  566. mutex_unlock(&power_resource_list_lock);
  567. }
  568. #endif