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()
94 if (!adev->hp) in dock_hotplug_event()
100 fixup = adev->hp->fixup; in dock_hotplug_event()
109 uevent = adev->hp->uevent; in dock_hotplug_event()
118 notify = adev->hp->notify; in dock_hotplug_event()
130 static struct dock_station *find_dock_station(acpi_handle handle) in find_dock_station() argument
135 if (ds->handle == handle) in find_dock_station()
142 * find_dock_dependent_device - get a device dependent on this dock
144 * @adev: ACPI device object to find.
146 * iterate over the dependent device list for this dock. If the
147 * dependent device matches the handle, return.
154 list_for_each_entry(dd, &ds->dependent_devices, list) in find_dock_dependent_device()
155 if (adev == dd->adev) in find_dock_dependent_device()
175 * is_dock_device - see if a device is on a dock station
176 * @adev: ACPI device object to check.
178 * If this device is either the dock station itself,
179 * or is a device dependent on the dock station, then it
180 * is a dock device
189 if (acpi_dock_match(adev->handle)) in is_dock_device()
201 * dock_present - see if the dock station is present.
213 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta); in dock_present()
221 * hot_remove_dock_devices - Remove dock station devices.
233 list_for_each_entry_reverse(dd, &ds->dependent_devices, list) in hot_remove_dock_devices()
237 list_for_each_entry_reverse(dd, &ds->dependent_devices, list) in hot_remove_dock_devices()
238 acpi_bus_trim(dd->adev); in hot_remove_dock_devices()
242 * hotplug_dock_devices - Insert devices on a dock station.
244 * @event: either bus check or device check request
255 /* Call driver specific post-dock fixups. */ in hotplug_dock_devices()
256 list_for_each_entry(dd, &ds->dependent_devices, list) in hotplug_dock_devices()
260 list_for_each_entry(dd, &ds->dependent_devices, list) in hotplug_dock_devices()
266 * attached to device objects or acpi_drivers to be stopped/started if in hotplug_dock_devices()
269 list_for_each_entry(dd, &ds->dependent_devices, list) { in hotplug_dock_devices()
270 struct acpi_device *adev = dd->adev; in hotplug_dock_devices()
273 int ret = acpi_bus_scan(adev->handle); in hotplug_dock_devices()
276 dev_dbg(&adev->dev, "scan error %d\n", -ret); in hotplug_dock_devices()
283 struct device *dev = &ds->dock_device->dev; in dock_event()
298 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); in dock_event()
300 list_for_each_entry(dd, &ds->dependent_devices, list) in dock_event()
304 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); in dock_event()
308 * handle_dock - handle a dock event
310 * @dock: to dock, or undock - that is the question
321 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking"); in handle_dock()
328 status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value); in handle_dock()
330 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n", in handle_dock()
346 ds->flags |= DOCK_DOCKING; in begin_dock()
351 ds->flags &= ~(DOCK_DOCKING); in complete_dock()
352 ds->last_dock_time = jiffies; in complete_dock()
357 ds->flags |= DOCK_UNDOCKING; in begin_undock()
362 ds->flags &= ~(DOCK_UNDOCKING); in complete_undock()
366 * dock_in_progress - see if we are in the middle of handling a dock event
375 if ((ds->flags & DOCK_DOCKING) || in dock_in_progress()
376 time_before(jiffies, (ds->last_dock_time + HZ))) in dock_in_progress()
382 * handle_eject_request - handle an undock request checking for error conditions
384 * Check to make sure the dock device is still present, then undock and
390 return -EBUSY; in handle_eject_request()
395 * so that the device struct still exists. in handle_eject_request()
397 * device is not present anymore in handle_eject_request()
403 acpi_evaluate_lck(ds->handle, 0); in handle_eject_request()
404 acpi_evaluate_ej0(ds->handle); in handle_eject_request()
406 acpi_handle_err(ds->handle, "Unable to undock!\n"); in handle_eject_request()
407 return -EBUSY; in handle_eject_request()
414 * dock_notify - Handle ACPI dock notification.
415 * @adev: Dock station's ACPI device object.
424 acpi_handle handle = adev->handle; in dock_notify() local
425 struct dock_station *ds = find_dock_station(handle); in dock_notify()
429 return -ENODEV; in dock_notify()
436 if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK) in dock_notify()
440 * dock station: BUS_CHECK - docked or surprise removal in dock_notify()
441 * DEVICE_CHECK - undocked in dock_notify()
442 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal in dock_notify()
444 * To simplify event handling, dock dependent device handler always in dock_notify()
455 acpi_handle_err(handle, "Unable to dock!\n"); in dock_notify()
462 acpi_evaluate_lck(ds->handle, 1); in dock_notify()
475 if ((immediate_undock && !(ds->flags & DOCK_IS_ATA)) in dock_notify()
486 * show_docked - read method for "docked" file in sysfs
488 static ssize_t docked_show(struct device *dev, in docked_show()
491 struct dock_station *dock_station = dev->platform_data; in docked_show()
492 struct acpi_device *adev = acpi_fetch_acpi_dev(dock_station->handle); in docked_show()
499 * show_flags - read method for flags file in sysfs
501 static ssize_t flags_show(struct device *dev, in flags_show()
504 struct dock_station *dock_station = dev->platform_data; in flags_show()
506 return sysfs_emit(buf, "%d\n", dock_station->flags); in flags_show()
512 * write_undock - write method for "undock" file in sysfs
514 static ssize_t undock_store(struct device *dev, struct device_attribute *attr, in undock_store()
518 struct dock_station *dock_station = dev->platform_data; in undock_store()
521 return -EINVAL; in undock_store()
532 * show_dock_uid - read method for "uid" file in sysfs
534 static ssize_t uid_show(struct device *dev, in uid_show()
538 struct dock_station *dock_station = dev->platform_data; in uid_show()
540 acpi_status status = acpi_evaluate_integer(dock_station->handle, in uid_show()
549 static ssize_t type_show(struct device *dev, in type_show()
552 struct dock_station *dock_station = dev->platform_data; in type_show()
555 if (dock_station->flags & DOCK_IS_DOCK) in type_show()
557 else if (dock_station->flags & DOCK_IS_ATA) in type_show()
559 else if (dock_station->flags & DOCK_IS_BAT) in type_show()
582 * acpi_dock_add - Add a new dock station
583 * @adev: Dock station ACPI device object.
585 * allocated and initialize a new dock station device.
591 acpi_handle handle = adev->handle; in acpi_dock_add() local
605 dock_station = dd->dev.platform_data; in acpi_dock_add()
607 dock_station->handle = handle; in acpi_dock_add()
608 dock_station->dock_device = dd; in acpi_dock_add()
609 dock_station->last_dock_time = jiffies - HZ; in acpi_dock_add()
611 INIT_LIST_HEAD(&dock_station->sibling); in acpi_dock_add()
612 INIT_LIST_HEAD(&dock_station->dependent_devices); in acpi_dock_add()
614 /* we want the dock device to send uevents */ in acpi_dock_add()
615 dev_set_uevent_suppress(&dd->dev, 0); in acpi_dock_add()
617 if (acpi_dock_match(handle)) in acpi_dock_add()
618 dock_station->flags |= DOCK_IS_DOCK; in acpi_dock_add()
619 if (acpi_ata_match(handle)) in acpi_dock_add()
620 dock_station->flags |= DOCK_IS_ATA; in acpi_dock_add()
622 dock_station->flags |= DOCK_IS_BAT; in acpi_dock_add()
624 ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group); in acpi_dock_add()
628 /* add the dock station as a device dependent on itself */ in acpi_dock_add()
634 list_add(&dock_station->sibling, &dock_stations); in acpi_dock_add()
635 adev->flags.is_dock_station = true; in acpi_dock_add()
636 dev_info(&adev->dev, "ACPI dock station (docks/bays count: %d)\n", in acpi_dock_add()
641 sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group); in acpi_dock_add()
645 acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret); in acpi_dock_add()