power.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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/proc_fs.h>
  41. #include <linux/seq_file.h>
  42. #include <acpi/acpi_bus.h>
  43. #include <acpi/acpi_drivers.h>
  44. #define _COMPONENT ACPI_POWER_COMPONENT
  45. ACPI_MODULE_NAME("power");
  46. #define ACPI_POWER_COMPONENT 0x00800000
  47. #define ACPI_POWER_CLASS "power_resource"
  48. #define ACPI_POWER_DEVICE_NAME "Power Resource"
  49. #define ACPI_POWER_FILE_INFO "info"
  50. #define ACPI_POWER_FILE_STATUS "state"
  51. #define ACPI_POWER_RESOURCE_STATE_OFF 0x00
  52. #define ACPI_POWER_RESOURCE_STATE_ON 0x01
  53. #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
  54. static int acpi_power_add(struct acpi_device *device);
  55. static int acpi_power_remove(struct acpi_device *device, int type);
  56. static int acpi_power_resume(struct acpi_device *device);
  57. static int acpi_power_open_fs(struct inode *inode, struct file *file);
  58. static struct acpi_device_id power_device_ids[] = {
  59. {ACPI_POWER_HID, 0},
  60. {"", 0},
  61. };
  62. MODULE_DEVICE_TABLE(acpi, power_device_ids);
  63. static struct acpi_driver acpi_power_driver = {
  64. .name = "power",
  65. .class = ACPI_POWER_CLASS,
  66. .ids = power_device_ids,
  67. .ops = {
  68. .add = acpi_power_add,
  69. .remove = acpi_power_remove,
  70. .resume = acpi_power_resume,
  71. },
  72. };
  73. struct acpi_power_reference {
  74. struct list_head node;
  75. struct acpi_device *device;
  76. };
  77. struct acpi_power_resource {
  78. struct acpi_device * device;
  79. acpi_bus_id name;
  80. u32 system_level;
  81. u32 order;
  82. struct mutex resource_lock;
  83. struct list_head reference;
  84. };
  85. static struct list_head acpi_power_resource_list;
  86. static const struct file_operations acpi_power_fops = {
  87. .owner = THIS_MODULE,
  88. .open = acpi_power_open_fs,
  89. .read = seq_read,
  90. .llseek = seq_lseek,
  91. .release = single_release,
  92. };
  93. /* --------------------------------------------------------------------------
  94. Power Resource Management
  95. -------------------------------------------------------------------------- */
  96. static int
  97. acpi_power_get_context(acpi_handle handle,
  98. struct acpi_power_resource **resource)
  99. {
  100. int result = 0;
  101. struct acpi_device *device = NULL;
  102. if (!resource)
  103. return -ENODEV;
  104. result = acpi_bus_get_device(handle, &device);
  105. if (result) {
  106. printk(KERN_WARNING PREFIX "Getting context [%p]\n", handle);
  107. return result;
  108. }
  109. *resource = acpi_driver_data(device);
  110. if (!*resource)
  111. return -ENODEV;
  112. return 0;
  113. }
  114. static int acpi_power_get_state(struct acpi_power_resource *resource, int *state)
  115. {
  116. acpi_status status = AE_OK;
  117. unsigned long sta = 0;
  118. if (!resource || !state)
  119. return -EINVAL;
  120. status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta);
  121. if (ACPI_FAILURE(status))
  122. return -ENODEV;
  123. *state = (sta & 0x01)?ACPI_POWER_RESOURCE_STATE_ON:
  124. ACPI_POWER_RESOURCE_STATE_OFF;
  125. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n",
  126. resource->name, state ? "on" : "off"));
  127. return 0;
  128. }
  129. static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
  130. {
  131. int result = 0, state1;
  132. struct acpi_power_resource *resource = NULL;
  133. u32 i = 0;
  134. if (!list || !state)
  135. return -EINVAL;
  136. /* The state of the list is 'on' IFF all resources are 'on'. */
  137. for (i = 0; i < list->count; i++) {
  138. result = acpi_power_get_context(list->handles[i], &resource);
  139. if (result)
  140. return result;
  141. result = acpi_power_get_state(resource, &state1);
  142. if (result)
  143. return result;
  144. *state = state1;
  145. if (*state != ACPI_POWER_RESOURCE_STATE_ON)
  146. break;
  147. }
  148. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource list is %s\n",
  149. *state ? "on" : "off"));
  150. return result;
  151. }
  152. static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
  153. {
  154. int result = 0, state;
  155. int found = 0;
  156. acpi_status status = AE_OK;
  157. struct acpi_power_resource *resource = NULL;
  158. struct list_head *node, *next;
  159. struct acpi_power_reference *ref;
  160. result = acpi_power_get_context(handle, &resource);
  161. if (result)
  162. return result;
  163. mutex_lock(&resource->resource_lock);
  164. list_for_each_safe(node, next, &resource->reference) {
  165. ref = container_of(node, struct acpi_power_reference, node);
  166. if (dev->handle == ref->device->handle) {
  167. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] already referenced by resource [%s]\n",
  168. dev->pnp.bus_id, resource->name));
  169. found = 1;
  170. break;
  171. }
  172. }
  173. if (!found) {
  174. ref = kmalloc(sizeof (struct acpi_power_reference),
  175. irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL);
  176. if (!ref) {
  177. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "kmalloc() failed\n"));
  178. mutex_unlock(&resource->resource_lock);
  179. return -ENOMEM;
  180. }
  181. list_add_tail(&ref->node, &resource->reference);
  182. ref->device = dev;
  183. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] added to resource [%s] references\n",
  184. dev->pnp.bus_id, resource->name));
  185. }
  186. mutex_unlock(&resource->resource_lock);
  187. status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
  188. if (ACPI_FAILURE(status))
  189. return -ENODEV;
  190. result = acpi_power_get_state(resource, &state);
  191. if (result)
  192. return result;
  193. if (state != ACPI_POWER_RESOURCE_STATE_ON)
  194. return -ENOEXEC;
  195. /* Update the power resource's _device_ power state */
  196. resource->device->power.state = ACPI_STATE_D0;
  197. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n",
  198. resource->name));
  199. return 0;
  200. }
  201. static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
  202. {
  203. int result = 0, state;
  204. acpi_status status = AE_OK;
  205. struct acpi_power_resource *resource = NULL;
  206. struct list_head *node, *next;
  207. struct acpi_power_reference *ref;
  208. result = acpi_power_get_context(handle, &resource);
  209. if (result)
  210. return result;
  211. mutex_lock(&resource->resource_lock);
  212. list_for_each_safe(node, next, &resource->reference) {
  213. ref = container_of(node, struct acpi_power_reference, node);
  214. if (dev->handle == ref->device->handle) {
  215. list_del(&ref->node);
  216. kfree(ref);
  217. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] removed from resource [%s] references\n",
  218. dev->pnp.bus_id, resource->name));
  219. break;
  220. }
  221. }
  222. if (!list_empty(&resource->reference)) {
  223. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cannot turn resource [%s] off - resource is in use\n",
  224. resource->name));
  225. mutex_unlock(&resource->resource_lock);
  226. return 0;
  227. }
  228. mutex_unlock(&resource->resource_lock);
  229. status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL);
  230. if (ACPI_FAILURE(status))
  231. return -ENODEV;
  232. result = acpi_power_get_state(resource, &state);
  233. if (result)
  234. return result;
  235. if (state != ACPI_POWER_RESOURCE_STATE_OFF)
  236. return -ENOEXEC;
  237. /* Update the power resource's _device_ power state */
  238. resource->device->power.state = ACPI_STATE_D3;
  239. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n",
  240. resource->name));
  241. return 0;
  242. }
  243. /*
  244. * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
  245. * 1. Power on the power resources required for the wakeup device
  246. * 2. Enable _PSW (power state wake) for the device if present
  247. */
  248. int acpi_enable_wakeup_device_power(struct acpi_device *dev)
  249. {
  250. union acpi_object arg = { ACPI_TYPE_INTEGER };
  251. struct acpi_object_list arg_list = { 1, &arg };
  252. acpi_status status = AE_OK;
  253. int i;
  254. int ret = 0;
  255. if (!dev || !dev->wakeup.flags.valid)
  256. return -1;
  257. arg.integer.value = 1;
  258. /* Open power resource */
  259. for (i = 0; i < dev->wakeup.resources.count; i++) {
  260. ret = acpi_power_on(dev->wakeup.resources.handles[i], dev);
  261. if (ret) {
  262. printk(KERN_ERR PREFIX "Transition power state\n");
  263. dev->wakeup.flags.valid = 0;
  264. return -1;
  265. }
  266. }
  267. /* Execute PSW */
  268. status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL);
  269. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  270. printk(KERN_ERR PREFIX "Evaluate _PSW\n");
  271. dev->wakeup.flags.valid = 0;
  272. ret = -1;
  273. }
  274. return ret;
  275. }
  276. /*
  277. * Shutdown a wakeup device, counterpart of above method
  278. * 1. Disable _PSW (power state wake)
  279. * 2. Shutdown down the power resources
  280. */
  281. int acpi_disable_wakeup_device_power(struct acpi_device *dev)
  282. {
  283. union acpi_object arg = { ACPI_TYPE_INTEGER };
  284. struct acpi_object_list arg_list = { 1, &arg };
  285. acpi_status status = AE_OK;
  286. int i;
  287. int ret = 0;
  288. if (!dev || !dev->wakeup.flags.valid)
  289. return -1;
  290. arg.integer.value = 0;
  291. /* Execute PSW */
  292. status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL);
  293. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  294. printk(KERN_ERR PREFIX "Evaluate _PSW\n");
  295. dev->wakeup.flags.valid = 0;
  296. return -1;
  297. }
  298. /* Close power resource */
  299. for (i = 0; i < dev->wakeup.resources.count; i++) {
  300. ret = acpi_power_off_device(dev->wakeup.resources.handles[i], dev);
  301. if (ret) {
  302. printk(KERN_ERR PREFIX "Transition power state\n");
  303. dev->wakeup.flags.valid = 0;
  304. return -1;
  305. }
  306. }
  307. return ret;
  308. }
  309. /* --------------------------------------------------------------------------
  310. Device Power Management
  311. -------------------------------------------------------------------------- */
  312. int acpi_power_get_inferred_state(struct acpi_device *device)
  313. {
  314. int result = 0;
  315. struct acpi_handle_list *list = NULL;
  316. int list_state = 0;
  317. int i = 0;
  318. if (!device)
  319. return -EINVAL;
  320. device->power.state = ACPI_STATE_UNKNOWN;
  321. /*
  322. * We know a device's inferred power state when all the resources
  323. * required for a given D-state are 'on'.
  324. */
  325. for (i = ACPI_STATE_D0; i < ACPI_STATE_D3; i++) {
  326. list = &device->power.states[i].resources;
  327. if (list->count < 1)
  328. continue;
  329. result = acpi_power_get_list_state(list, &list_state);
  330. if (result)
  331. return result;
  332. if (list_state == ACPI_POWER_RESOURCE_STATE_ON) {
  333. device->power.state = i;
  334. return 0;
  335. }
  336. }
  337. device->power.state = ACPI_STATE_D3;
  338. return 0;
  339. }
  340. int acpi_power_transition(struct acpi_device *device, int state)
  341. {
  342. int result = 0;
  343. struct acpi_handle_list *cl = NULL; /* Current Resources */
  344. struct acpi_handle_list *tl = NULL; /* Target Resources */
  345. int i = 0;
  346. if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
  347. return -EINVAL;
  348. if ((device->power.state < ACPI_STATE_D0)
  349. || (device->power.state > ACPI_STATE_D3))
  350. return -ENODEV;
  351. cl = &device->power.states[device->power.state].resources;
  352. tl = &device->power.states[state].resources;
  353. if (!cl->count && !tl->count) {
  354. result = -ENODEV;
  355. goto end;
  356. }
  357. /* TBD: Resources must be ordered. */
  358. /*
  359. * First we reference all power resources required in the target list
  360. * (e.g. so the device doesn't lose power while transitioning).
  361. */
  362. for (i = 0; i < tl->count; i++) {
  363. result = acpi_power_on(tl->handles[i], device);
  364. if (result)
  365. goto end;
  366. }
  367. if (device->power.state == state) {
  368. goto end;
  369. }
  370. /*
  371. * Then we dereference all power resources used in the current list.
  372. */
  373. for (i = 0; i < cl->count; i++) {
  374. result = acpi_power_off_device(cl->handles[i], device);
  375. if (result)
  376. goto end;
  377. }
  378. end:
  379. if (result)
  380. device->power.state = ACPI_STATE_UNKNOWN;
  381. else {
  382. /* We shouldn't change the state till all above operations succeed */
  383. device->power.state = state;
  384. }
  385. return result;
  386. }
  387. /* --------------------------------------------------------------------------
  388. FS Interface (/proc)
  389. -------------------------------------------------------------------------- */
  390. static struct proc_dir_entry *acpi_power_dir;
  391. static int acpi_power_seq_show(struct seq_file *seq, void *offset)
  392. {
  393. int count = 0;
  394. int result = 0, state;
  395. struct acpi_power_resource *resource = NULL;
  396. struct list_head *node, *next;
  397. struct acpi_power_reference *ref;
  398. resource = seq->private;
  399. if (!resource)
  400. goto end;
  401. result = acpi_power_get_state(resource, &state);
  402. if (result)
  403. goto end;
  404. seq_puts(seq, "state: ");
  405. switch (state) {
  406. case ACPI_POWER_RESOURCE_STATE_ON:
  407. seq_puts(seq, "on\n");
  408. break;
  409. case ACPI_POWER_RESOURCE_STATE_OFF:
  410. seq_puts(seq, "off\n");
  411. break;
  412. default:
  413. seq_puts(seq, "unknown\n");
  414. break;
  415. }
  416. mutex_lock(&resource->resource_lock);
  417. list_for_each_safe(node, next, &resource->reference) {
  418. ref = container_of(node, struct acpi_power_reference, node);
  419. count++;
  420. }
  421. mutex_unlock(&resource->resource_lock);
  422. seq_printf(seq, "system level: S%d\n"
  423. "order: %d\n"
  424. "reference count: %d\n",
  425. resource->system_level,
  426. resource->order, count);
  427. end:
  428. return 0;
  429. }
  430. static int acpi_power_open_fs(struct inode *inode, struct file *file)
  431. {
  432. return single_open(file, acpi_power_seq_show, PDE(inode)->data);
  433. }
  434. static int acpi_power_add_fs(struct acpi_device *device)
  435. {
  436. struct proc_dir_entry *entry = NULL;
  437. if (!device)
  438. return -EINVAL;
  439. if (!acpi_device_dir(device)) {
  440. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  441. acpi_power_dir);
  442. if (!acpi_device_dir(device))
  443. return -ENODEV;
  444. }
  445. /* 'status' [R] */
  446. entry = proc_create_data(ACPI_POWER_FILE_STATUS,
  447. S_IRUGO, acpi_device_dir(device),
  448. &acpi_power_fops, acpi_driver_data(device));
  449. if (!entry)
  450. return -EIO;
  451. return 0;
  452. }
  453. static int acpi_power_remove_fs(struct acpi_device *device)
  454. {
  455. if (acpi_device_dir(device)) {
  456. remove_proc_entry(ACPI_POWER_FILE_STATUS,
  457. acpi_device_dir(device));
  458. remove_proc_entry(acpi_device_bid(device), acpi_power_dir);
  459. acpi_device_dir(device) = NULL;
  460. }
  461. return 0;
  462. }
  463. /* --------------------------------------------------------------------------
  464. Driver Interface
  465. -------------------------------------------------------------------------- */
  466. static int acpi_power_add(struct acpi_device *device)
  467. {
  468. int result = 0, state;
  469. acpi_status status = AE_OK;
  470. struct acpi_power_resource *resource = NULL;
  471. union acpi_object acpi_object;
  472. struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object };
  473. if (!device)
  474. return -EINVAL;
  475. resource = kzalloc(sizeof(struct acpi_power_resource), GFP_KERNEL);
  476. if (!resource)
  477. return -ENOMEM;
  478. resource->device = device;
  479. mutex_init(&resource->resource_lock);
  480. INIT_LIST_HEAD(&resource->reference);
  481. strcpy(resource->name, device->pnp.bus_id);
  482. strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
  483. strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
  484. acpi_driver_data(device) = resource;
  485. /* Evalute the object to get the system level and resource order. */
  486. status = acpi_evaluate_object(device->handle, NULL, NULL, &buffer);
  487. if (ACPI_FAILURE(status)) {
  488. result = -ENODEV;
  489. goto end;
  490. }
  491. resource->system_level = acpi_object.power_resource.system_level;
  492. resource->order = acpi_object.power_resource.resource_order;
  493. result = acpi_power_get_state(resource, &state);
  494. if (result)
  495. goto end;
  496. switch (state) {
  497. case ACPI_POWER_RESOURCE_STATE_ON:
  498. device->power.state = ACPI_STATE_D0;
  499. break;
  500. case ACPI_POWER_RESOURCE_STATE_OFF:
  501. device->power.state = ACPI_STATE_D3;
  502. break;
  503. default:
  504. device->power.state = ACPI_STATE_UNKNOWN;
  505. break;
  506. }
  507. result = acpi_power_add_fs(device);
  508. if (result)
  509. goto end;
  510. printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device),
  511. acpi_device_bid(device), state ? "on" : "off");
  512. end:
  513. if (result)
  514. kfree(resource);
  515. return result;
  516. }
  517. static int acpi_power_remove(struct acpi_device *device, int type)
  518. {
  519. struct acpi_power_resource *resource = NULL;
  520. struct list_head *node, *next;
  521. if (!device || !acpi_driver_data(device))
  522. return -EINVAL;
  523. resource = acpi_driver_data(device);
  524. acpi_power_remove_fs(device);
  525. mutex_lock(&resource->resource_lock);
  526. list_for_each_safe(node, next, &resource->reference) {
  527. struct acpi_power_reference *ref = container_of(node, struct acpi_power_reference, node);
  528. list_del(&ref->node);
  529. kfree(ref);
  530. }
  531. mutex_unlock(&resource->resource_lock);
  532. kfree(resource);
  533. return 0;
  534. }
  535. static int acpi_power_resume(struct acpi_device *device)
  536. {
  537. int result = 0, state;
  538. struct acpi_power_resource *resource = NULL;
  539. struct acpi_power_reference *ref;
  540. if (!device || !acpi_driver_data(device))
  541. return -EINVAL;
  542. resource = (struct acpi_power_resource *)acpi_driver_data(device);
  543. result = acpi_power_get_state(resource, &state);
  544. if (result)
  545. return result;
  546. mutex_lock(&resource->resource_lock);
  547. if (state == ACPI_POWER_RESOURCE_STATE_OFF &&
  548. !list_empty(&resource->reference)) {
  549. ref = container_of(resource->reference.next, struct acpi_power_reference, node);
  550. mutex_unlock(&resource->resource_lock);
  551. result = acpi_power_on(device->handle, ref->device);
  552. return result;
  553. }
  554. mutex_unlock(&resource->resource_lock);
  555. return 0;
  556. }
  557. static int __init acpi_power_init(void)
  558. {
  559. int result = 0;
  560. if (acpi_disabled)
  561. return 0;
  562. INIT_LIST_HEAD(&acpi_power_resource_list);
  563. acpi_power_dir = proc_mkdir(ACPI_POWER_CLASS, acpi_root_dir);
  564. if (!acpi_power_dir)
  565. return -ENODEV;
  566. result = acpi_bus_register_driver(&acpi_power_driver);
  567. if (result < 0) {
  568. remove_proc_entry(ACPI_POWER_CLASS, acpi_root_dir);
  569. return -ENODEV;
  570. }
  571. return 0;
  572. }
  573. subsys_initcall(acpi_power_init);