^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * container.c - ACPI Generic Container Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2004 Anil S Keshavamurthy (anil.s.keshavamurthy@intel.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2004 Keiichiro Tokunaga (tokunaga.keiich@jp.fujitsu.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2004 Motoyuki Ito (motoyuki@soft.fujitsu.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2004 FUJITSU LIMITED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2004, 2013 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/container.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static const struct acpi_device_id container_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {"ACPI0004", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {"PNP0A05", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {"PNP0A06", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #ifdef CONFIG_ACPI_CONTAINER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int acpi_container_offline(struct container_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct acpi_device *adev = ACPI_COMPANION(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct acpi_device *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* Check all of the dependent devices' physical companions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) list_for_each_entry(child, &adev->children, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (!acpi_scan_is_offline(child, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void acpi_container_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) kfree(to_container_dev(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int container_device_attach(struct acpi_device *adev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) const struct acpi_device_id *not_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct container_dev *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (adev->flags.is_dock_station)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (!cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) cdev->offline = acpi_container_offline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) dev = &cdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) dev->bus = &container_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) dev_set_name(dev, "%s", dev_name(&adev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ACPI_COMPANION_SET(dev, adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) dev->release = acpi_container_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ret = device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) adev->driver_data = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static void container_device_detach(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct device *dev = acpi_driver_data(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) adev->driver_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) device_unregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void container_device_online(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct device *dev = acpi_driver_data(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) kobject_uevent(&dev->kobj, KOBJ_ONLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static struct acpi_scan_handler container_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .ids = container_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .attach = container_device_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .detach = container_device_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .hotplug = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .enabled = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .demand_offline = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .notify_online = container_device_online,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void __init acpi_container_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) acpi_scan_add_handler(&container_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static struct acpi_scan_handler container_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .ids = container_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void __init acpi_container_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) acpi_scan_add_handler_with_hotplug(&container_handler, "container");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #endif /* CONFIG_ACPI_CONTAINER */