aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r--drivers/acpi/scan.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index fe3693de7ba3..f8316a05ede7 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1341,6 +1341,100 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
1341 return_VALUE(result); 1341 return_VALUE(result);
1342} 1342}
1343 1343
1344
1345static inline struct acpi_device * to_acpi_dev(struct device * dev)
1346{
1347 return container_of(dev, struct acpi_device, dev);
1348}
1349
1350
1351static int root_suspend(struct acpi_device * acpi_dev, pm_message_t state)
1352{
1353 struct acpi_device * dev, * next;
1354 int result;
1355
1356 spin_lock(&acpi_device_lock);
1357 list_for_each_entry_safe_reverse(dev, next, &acpi_device_list, g_list) {
1358 if (dev->driver && dev->driver->ops.suspend) {
1359 spin_unlock(&acpi_device_lock);
1360 result = dev->driver->ops.suspend(dev, 0);
1361 if (result) {
1362 printk(KERN_ERR PREFIX "[%s - %s] Suspend failed: %d\n",
1363 acpi_device_name(dev),
1364 acpi_device_bid(dev), result);
1365 }
1366 spin_lock(&acpi_device_lock);
1367 }
1368 }
1369 spin_unlock(&acpi_device_lock);
1370 return 0;
1371}
1372
1373
1374static int acpi_device_suspend(struct device * dev, pm_message_t state)
1375{
1376 struct acpi_device * acpi_dev = to_acpi_dev(dev);
1377
1378 /*
1379 * For now, we should only register 1 generic device -
1380 * the ACPI root device - and from there, we walk the
1381 * tree of ACPI devices to suspend each one using the
1382 * ACPI driver methods.
1383 */
1384 if (acpi_dev->handle == ACPI_ROOT_OBJECT)
1385 root_suspend(acpi_dev, state);
1386 return 0;
1387}
1388
1389
1390
1391static int root_resume(struct acpi_device * acpi_dev)
1392{
1393 struct acpi_device * dev, * next;
1394 int result;
1395
1396 spin_lock(&acpi_device_lock);
1397 list_for_each_entry_safe(dev, next, &acpi_device_list, g_list) {
1398 if (dev->driver && dev->driver->ops.resume) {
1399 spin_unlock(&acpi_device_lock);
1400 result = dev->driver->ops.resume(dev, 0);
1401 if (result) {
1402 printk(KERN_ERR PREFIX "[%s - %s] resume failed: %d\n",
1403 acpi_device_name(dev),
1404 acpi_device_bid(dev), result);
1405 }
1406 spin_lock(&acpi_device_lock);
1407 }
1408 }
1409 spin_unlock(&acpi_device_lock);
1410 return 0;
1411}
1412
1413
1414static int acpi_device_resume(struct device * dev)
1415{
1416 struct acpi_device * acpi_dev = to_acpi_dev(dev);
1417
1418 /*
1419 * For now, we should only register 1 generic device -
1420 * the ACPI root device - and from there, we walk the
1421 * tree of ACPI devices to resume each one using the
1422 * ACPI driver methods.
1423 */
1424 if (acpi_dev->handle == ACPI_ROOT_OBJECT)
1425 root_resume(acpi_dev);
1426 return 0;
1427}
1428
1429
1430struct bus_type acpi_bus_type = {
1431 .name = "acpi",
1432 .suspend = acpi_device_suspend,
1433 .resume = acpi_device_resume,
1434};
1435
1436
1437
1344static int __init acpi_scan_init(void) 1438static int __init acpi_scan_init(void)
1345{ 1439{
1346 int result; 1440 int result;
@@ -1353,6 +1447,12 @@ static int __init acpi_scan_init(void)
1353 1447
1354 kset_register(&acpi_namespace_kset); 1448 kset_register(&acpi_namespace_kset);
1355 1449
1450 result = bus_register(&acpi_bus_type);
1451 if (result) {
1452 /* We don't want to quit even if we failed to add suspend/resume */
1453 printk(KERN_ERR PREFIX "Could not register bus type\n");
1454 }
1455
1356 /* 1456 /*
1357 * Create the root device in the bus's device tree 1457 * Create the root device in the bus's device tree
1358 */ 1458 */
@@ -1362,6 +1462,16 @@ static int __init acpi_scan_init(void)
1362 goto Done; 1462 goto Done;
1363 1463
1364 result = acpi_start_single_object(acpi_root); 1464 result = acpi_start_single_object(acpi_root);
1465 if (result)
1466 goto Done;
1467
1468 acpi_root->dev.bus = &acpi_bus_type;
1469 snprintf(acpi_root->dev.bus_id, BUS_ID_SIZE, "%s", acpi_bus_type.name);
1470 result = device_register(&acpi_root->dev);
1471 if (result) {
1472 /* We don't want to quit even if we failed to add suspend/resume */
1473 printk(KERN_ERR PREFIX "Could not register device\n");
1474 }
1365 1475
1366 /* 1476 /*
1367 * Enumerate devices in the ACPI namespace. 1477 * Enumerate devices in the ACPI namespace.