Lines Matching +full:device +full:- +full:handle
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * dock.c - ACPI dock station driver
31 acpi_handle handle; member
62 * Dock Dependent device functions *
65 * add_dock_dependent_device - associate a device with the dock station
67 * @adev: Dependent ACPI device object.
69 * Add the dependent device to the dock's dependent device list.
78 return -ENOMEM; in add_dock_dependent_device()
80 dd->adev = adev; in add_dock_dependent_device()
81 INIT_LIST_HEAD(&dd->list); in add_dock_dependent_device()
82 list_add_tail(&dd->list, &ds->dependent_devices); in add_dock_dependent_device()
90 struct acpi_device *adev = dd->adev; in dock_hotplug_event()
97 if (adev->hp) { in dock_hotplug_event()
99 fixup = adev->hp->fixup; in dock_hotplug_event()
101 uevent = adev->hp->uevent; in dock_hotplug_event()
103 notify = adev->hp->notify; in dock_hotplug_event()
116 static struct dock_station *find_dock_station(acpi_handle handle) in find_dock_station() argument
121 if (ds->handle == handle) in find_dock_station()
128 * find_dock_dependent_device - get a device dependent on this dock
130 * @adev: ACPI device object to find.
132 * iterate over the dependent device list for this dock. If the
133 * dependent device matches the handle, return.
140 list_for_each_entry(dd, &ds->dependent_devices, list) in find_dock_dependent_device()
141 if (adev == dd->adev) in find_dock_dependent_device()
161 * is_dock_device - see if a device is on a dock station
162 * @adev: ACPI device object to check.
164 * If this device is either the dock station itself,
165 * or is a device dependent on the dock station, then it
166 * is a dock device
175 if (acpi_dock_match(adev->handle)) in is_dock_device()
187 * dock_present - see if the dock station is present.
199 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta); in dock_present()
207 * hot_remove_dock_devices - Remove dock station devices.
219 list_for_each_entry_reverse(dd, &ds->dependent_devices, list) in hot_remove_dock_devices()
223 list_for_each_entry_reverse(dd, &ds->dependent_devices, list) in hot_remove_dock_devices()
224 acpi_bus_trim(dd->adev); in hot_remove_dock_devices()
228 * hotplug_dock_devices - Insert devices on a dock station.
230 * @event: either bus check or device check request
241 /* Call driver specific post-dock fixups. */ in hotplug_dock_devices()
242 list_for_each_entry(dd, &ds->dependent_devices, list) in hotplug_dock_devices()
246 list_for_each_entry(dd, &ds->dependent_devices, list) in hotplug_dock_devices()
252 * attached to device objects or acpi_drivers to be stopped/started if in hotplug_dock_devices()
255 list_for_each_entry(dd, &ds->dependent_devices, list) { in hotplug_dock_devices()
256 struct acpi_device *adev = dd->adev; in hotplug_dock_devices()
259 int ret = acpi_bus_scan(adev->handle); in hotplug_dock_devices()
262 dev_dbg(&adev->dev, "scan error %d\n", -ret); in hotplug_dock_devices()
269 struct device *dev = &ds->dock_device->dev; in dock_event()
284 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); in dock_event()
286 list_for_each_entry(dd, &ds->dependent_devices, list) in dock_event()
290 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); in dock_event()
294 * handle_dock - handle a dock event
296 * @dock: to dock, or undock - that is the question
307 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking"); in handle_dock()
314 status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value); in handle_dock()
316 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n", in handle_dock()
332 ds->flags |= DOCK_DOCKING; in begin_dock()
337 ds->flags &= ~(DOCK_DOCKING); in complete_dock()
338 ds->last_dock_time = jiffies; in complete_dock()
343 ds->flags |= DOCK_UNDOCKING; in begin_undock()
348 ds->flags &= ~(DOCK_UNDOCKING); in complete_undock()
352 * dock_in_progress - see if we are in the middle of handling a dock event
361 if ((ds->flags & DOCK_DOCKING) || in dock_in_progress()
362 time_before(jiffies, (ds->last_dock_time + HZ))) in dock_in_progress()
368 * handle_eject_request - handle an undock request checking for error conditions
372 * Check to make sure the dock device is still present, then undock and
378 return -EBUSY; in handle_eject_request()
383 * so that the device struct still exists. in handle_eject_request()
385 * device is not present anymore in handle_eject_request()
391 acpi_evaluate_lck(ds->handle, 0); in handle_eject_request()
392 acpi_evaluate_ej0(ds->handle); in handle_eject_request()
394 acpi_handle_err(ds->handle, "Unable to undock!\n"); in handle_eject_request()
395 return -EBUSY; in handle_eject_request()
402 * dock_notify - Handle ACPI dock notification.
403 * @adev: Dock station's ACPI device object.
412 acpi_handle handle = adev->handle; in dock_notify() local
413 struct dock_station *ds = find_dock_station(handle); in dock_notify()
417 return -ENODEV; in dock_notify()
424 if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK) in dock_notify()
428 * dock station: BUS_CHECK - docked or surprise removal in dock_notify()
429 * DEVICE_CHECK - undocked in dock_notify()
430 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal in dock_notify()
432 * To simplify event handling, dock dependent device handler always in dock_notify()
443 acpi_handle_err(handle, "Unable to dock!\n"); in dock_notify()
450 acpi_evaluate_lck(ds->handle, 1); in dock_notify()
463 if ((immediate_undock && !(ds->flags & DOCK_IS_ATA)) in dock_notify()
474 * show_docked - read method for "docked" file in sysfs
476 static ssize_t docked_show(struct device *dev, in docked_show()
479 struct dock_station *dock_station = dev->platform_data; in docked_show()
480 struct acpi_device *adev = acpi_fetch_acpi_dev(dock_station->handle); in docked_show()
487 * show_flags - read method for flags file in sysfs
489 static ssize_t flags_show(struct device *dev, in flags_show()
492 struct dock_station *dock_station = dev->platform_data; in flags_show()
494 return sysfs_emit(buf, "%d\n", dock_station->flags); in flags_show()
500 * write_undock - write method for "undock" file in sysfs
502 static ssize_t undock_store(struct device *dev, struct device_attribute *attr, in undock_store()
506 struct dock_station *dock_station = dev->platform_data; in undock_store()
509 return -EINVAL; in undock_store()
520 * show_dock_uid - read method for "uid" file in sysfs
522 static ssize_t uid_show(struct device *dev, in uid_show()
526 struct dock_station *dock_station = dev->platform_data; in uid_show()
528 acpi_status status = acpi_evaluate_integer(dock_station->handle, in uid_show()
537 static ssize_t type_show(struct device *dev, in type_show()
540 struct dock_station *dock_station = dev->platform_data; in type_show()
543 if (dock_station->flags & DOCK_IS_DOCK) in type_show()
545 else if (dock_station->flags & DOCK_IS_ATA) in type_show()
547 else if (dock_station->flags & DOCK_IS_BAT) in type_show()
570 * acpi_dock_add - Add a new dock station
571 * @adev: Dock station ACPI device object.
573 * allocated and initialize a new dock station device.
579 acpi_handle handle = adev->handle; in acpi_dock_add() local
593 dock_station = dd->dev.platform_data; in acpi_dock_add()
595 dock_station->handle = handle; in acpi_dock_add()
596 dock_station->dock_device = dd; in acpi_dock_add()
597 dock_station->last_dock_time = jiffies - HZ; in acpi_dock_add()
599 INIT_LIST_HEAD(&dock_station->sibling); in acpi_dock_add()
600 INIT_LIST_HEAD(&dock_station->dependent_devices); in acpi_dock_add()
602 /* we want the dock device to send uevents */ in acpi_dock_add()
603 dev_set_uevent_suppress(&dd->dev, 0); in acpi_dock_add()
605 if (acpi_dock_match(handle)) in acpi_dock_add()
606 dock_station->flags |= DOCK_IS_DOCK; in acpi_dock_add()
607 if (acpi_ata_match(handle)) in acpi_dock_add()
608 dock_station->flags |= DOCK_IS_ATA; in acpi_dock_add()
610 dock_station->flags |= DOCK_IS_BAT; in acpi_dock_add()
612 ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group); in acpi_dock_add()
616 /* add the dock station as a device dependent on itself */ in acpi_dock_add()
622 list_add(&dock_station->sibling, &dock_stations); in acpi_dock_add()
623 adev->flags.is_dock_station = true; in acpi_dock_add()
624 dev_info(&adev->dev, "ACPI dock station (docks/bays count: %d)\n", in acpi_dock_add()
629 sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group); in acpi_dock_add()
633 acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret); in acpi_dock_add()