Lines Matching +full:on +full:- +full:device

1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Surface System Aggregator Module (SSAM) bus and client-device subsystem.
5 * Main interface for the surface-aggregator bus, surface-aggregator client
6 * devices, and respective drivers building on top of the SSAM controller.
7 * Provides support for non-platform/non-ACPI SSAM clients via dedicated
10 * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
16 #include <linux/device.h>
24 /* -- Surface System Aggregator Module bus. --------------------------------- */
27 * enum ssam_device_domain - SAM device domain.
28 * @SSAM_DOMAIN_VIRTUAL: Virtual device.
29 * @SSAM_DOMAIN_SERIALHUB: Physical device connected via Surface Serial Hub.
37 * enum ssam_virtual_tc - Target categories for the virtual SAM domain.
38 * @SSAM_VIRTUAL_TC_HUB: Device hub category.
45 * struct ssam_device_uid - Unique identifier for SSAM device.
46 * @domain: Domain of the device.
47 * @category: Target category of the device.
48 * @target: Target ID of the device.
49 * @instance: Instance ID of the device.
50 * @function: Sub-function of the device. This field can be used to split a
51 * single SAM device into multiple virtual subdevices to separate
52 * different functionality of that device and allow one driver per
64 * Special values for device matching.
68 * match_flags member of the device ID structure. Do not use them directly
76 * SSAM_DEVICE() - Initialize a &struct ssam_device_id with the given
78 * @d: Domain of the device.
79 * @cat: Target category of the device.
80 * @tid: Target ID of the device.
81 * @iid: Instance ID of the device.
82 * @fun: Sub-function of the device.
87 * matching should ignore target ID, instance ID, and/or sub-function,
88 * respectively. This macro initializes the ``match_flags`` field based on the
93 * %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values are not
107 * SSAM_VDEV() - Initialize a &struct ssam_device_id as virtual device with
109 * @cat: Target category of the device.
110 * @tid: Target ID of the device.
111 * @iid: Instance ID of the device.
112 * @fun: Sub-function of the device.
118 * instance ID, and/or sub-function, respectively. This macro initializes the
119 * ``match_flags`` field based on the given parameters.
123 * %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values are not
130 * SSAM_SDEV() - Initialize a &struct ssam_device_id as physical SSH device
132 * @cat: Target category of the device.
133 * @tid: Target ID of the device.
134 * @iid: Instance ID of the device.
135 * @fun: Sub-function of the device.
141 * ID, instance ID, and/or sub-function, respectively. This macro initializes
142 * the ``match_flags`` field based on the given parameters.
146 * %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values
153 * enum ssam_device_flags - Flags for SSAM client devices.
155 * The device has been hot-removed. Further communication with it may time
163 * struct ssam_device - SSAM client device.
164 * @dev: Driver model representation of the device.
165 * @ctrl: SSAM controller managing this device.
166 * @uid: UID identifying the device.
167 * @flags: Device state flags, see &enum ssam_device_flags.
170 struct device dev;
179 * struct ssam_device_driver - SSAM client device driver.
182 * @probe: Called when the driver is being bound to a device.
183 * @remove: Called when the driver is being unbound from the device.
200 * is_ssam_device() - Check if the given device is a SSAM client device.
201 * @d: The device to test the type of.
203 * Return: Returns %true if the specified device is of type &struct
204 * ssam_device, i.e. the device type points to %ssam_device_type, and %false
207 static inline bool is_ssam_device(struct device *d) in is_ssam_device()
209 return d->type == &ssam_device_type; in is_ssam_device()
214 static inline bool is_ssam_device(struct device *d) in is_ssam_device()
222 * to_ssam_device() - Casts the given device to a SSAM client device.
223 * @d: The device to cast.
225 * Casts the given &struct device to a &struct ssam_device. The caller has to
226 * ensure that the given device is actually enclosed in a &struct ssam_device,
230 * device @d.
235 * to_ssam_device_driver() - Casts the given device driver to a SSAM client
236 * device driver.
244 * given device driver @d.
262 * ssam_device_mark_hot_removed() - Mark the given device as hot-removed.
263 * @sdev: The device to mark as hot-removed.
265 * Mark the device as having been hot-removed. This signals drivers using the
266 * device that communication with the device should be avoided and may lead to
271 dev_dbg(&sdev->dev, "marking device as hot-removed\n"); in ssam_device_mark_hot_removed()
272 set_bit(SSAM_DEVICE_HOT_REMOVED_BIT, &sdev->flags); in ssam_device_mark_hot_removed()
276 * ssam_device_is_hot_removed() - Check if the given device has been
277 * hot-removed.
278 * @sdev: The device to check.
280 * Checks if the given device has been marked as hot-removed. See
283 * Return: Returns ``true`` if the device has been marked as hot-removed.
287 return test_bit(SSAM_DEVICE_HOT_REMOVED_BIT, &sdev->flags); in ssam_device_is_hot_removed()
291 * ssam_device_get() - Increment reference count of SSAM client device.
292 * @sdev: The device to increment the reference count of.
294 * Increments the reference count of the given SSAM client device by
295 * incrementing the reference count of the enclosed &struct device via
298 * See ssam_device_put() for the counter-part of this function.
300 * Return: Returns the device provided as input.
304 return sdev ? to_ssam_device(get_device(&sdev->dev)) : NULL; in ssam_device_get()
308 * ssam_device_put() - Decrement reference count of SSAM client device.
309 * @sdev: The device to decrement the reference count of.
311 * Decrements the reference count of the given SSAM client device by
312 * decrementing the reference count of the enclosed &struct device via
315 * See ssam_device_get() for the counter-part of this function.
320 put_device(&sdev->dev); in ssam_device_put()
324 * ssam_device_get_drvdata() - Get driver-data of SSAM client device.
325 * @sdev: The device to get the driver-data from.
327 * Return: Returns the driver-data of the given device, previously set via
332 return dev_get_drvdata(&sdev->dev); in ssam_device_get_drvdata()
336 * ssam_device_set_drvdata() - Set driver-data of SSAM client device.
337 * @sdev: The device to set the driver-data of.
338 * @data: The data to set the device's driver-data pointer to.
342 dev_set_drvdata(&sdev->dev, data); in ssam_device_set_drvdata()
349 * ssam_device_driver_register() - Register a SSAM client device driver.
356 * module_ssam_device_driver() - Helper macro for SSAM device driver
360 * Helper macro to register a SSAM device driver via module_init() and
369 /* -- Helpers for controller and hub devices. ------------------------------- */
373 int __ssam_register_clients(struct device *parent, struct ssam_controller *ctrl,
375 void ssam_remove_clients(struct device *dev);
379 static inline int __ssam_register_clients(struct device *parent, struct ssam_controller *ctrl, in __ssam_register_clients()
385 static inline void ssam_remove_clients(struct device *dev) {} in ssam_remove_clients()
390 * ssam_register_clients() - Register all client devices defined under the
391 * given parent device.
392 * @dev: The parent device under which clients should be registered.
396 * of the given (parent) device. The respective child firmware nodes will be
402 * Return: Returns zero on success, nonzero on failure.
404 static inline int ssam_register_clients(struct device *dev, struct ssam_controller *ctrl) in ssam_register_clients()
410 * ssam_device_register_clients() - Register all client devices defined under
411 * the given SSAM parent device.
412 * @sdev: The parent device under which clients should be registered.
415 * of the given (parent) device. The respective child firmware nodes will be
418 * The controller used by the parent device will be used to instantiate the new
421 * Return: Returns zero on success, nonzero on failure.
425 return ssam_register_clients(&sdev->dev, sdev->ctrl); in ssam_device_register_clients()
429 /* -- Helpers for client-device requests. ----------------------------------- */
432 * SSAM_DEFINE_SYNC_REQUEST_CL_N() - Define synchronous client-device SAM
438 * @spec, with the request having neither argument nor return value. Device
439 * specifying parameters are not hard-coded, but instead are provided via the
440 * client device, specifically its UID, supplied when calling this function.
444 * allocated on the stack.
447 * *sdev)``, returning the status of the request, which is zero on success and
448 * negative on failure. The ``sdev`` parameter specifies both the target
449 * device of the request and by association the controller via which the
452 * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
459 return __raw_##name(sdev->ctrl, sdev->uid.target, \
460 sdev->uid.instance); \
464 * SSAM_DEFINE_SYNC_REQUEST_CL_W() - Define synchronous client-device SAM
472 * return value. Device specifying parameters are not hard-coded, but instead
473 * are provided via the client device, specifically its UID, supplied when
477 * transport buffer will be allocated on the stack.
481 * zero on success and negative on failure. The ``sdev`` parameter specifies
482 * both the target device of the request and by association the controller via
486 * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
493 return __raw_##name(sdev->ctrl, sdev->uid.target, \
494 sdev->uid.instance, arg); \
498 * SSAM_DEFINE_SYNC_REQUEST_CL_R() - Define synchronous client-device SAM
506 * type @rtype. Device specifying parameters are not hard-coded, but instead
507 * are provided via the client device, specifically its UID, supplied when
511 * transport buffer will be allocated on the stack.
514 * *sdev, rtype *ret)``, returning the status of the request, which is zero on
515 * success and negative on failure. The ``sdev`` parameter specifies both the
516 * target device of the request and by association the controller via which
520 * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
527 return __raw_##name(sdev->ctrl, sdev->uid.target, \
528 sdev->uid.instance, ret); \
532 * SSAM_DEFINE_SYNC_REQUEST_CL_WR() - Define synchronous client-device SAM
541 * of type @rtype. Device specifying parameters are not hard-coded, but instead
542 * are provided via the client device, specifically its UID, supplied when
546 * transport buffer will be allocated on the stack.
550 * which is zero on success and negative on failure. The ``sdev`` parameter
551 * specifies both the target device of the request and by association the
556 * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
563 return __raw_##name(sdev->ctrl, sdev->uid.target, \
564 sdev->uid.instance, arg, ret); \
568 /* -- Helpers for client-device notifiers. ---------------------------------- */
571 * ssam_device_notifier_register() - Register an event notifier for the
572 * specified client device.
573 * @sdev: The device the notifier should be registered on.
586 * Return: Returns zero on success, %-ENOSPC if there have already been
588 * registered, %-ENOMEM if the corresponding event entry could not be
589 * allocated, %-ENODEV if the device is marked as hot-removed. If this is the
591 * event, returns the status of the event-enable EC-command.
598 * hot-removal could happen at any point and we can't protect against in ssam_device_notifier_register()
599 * it. Nevertheless, if we can detect hot-removal, bail early to avoid in ssam_device_notifier_register()
603 return -ENODEV; in ssam_device_notifier_register()
605 return ssam_notifier_register(sdev->ctrl, n); in ssam_device_notifier_register()
609 * ssam_device_notifier_unregister() - Unregister an event notifier for the
610 * specified client device.
611 * @sdev: The device the notifier has been registered on.
618 * In case the device has been marked as hot-removed, the event will not be
619 * disabled on the EC, as in those cases any attempt at doing so may time out.
621 * Return: Returns zero on success, %-ENOENT if the given notifier block has
622 * not been registered on the controller. If the given notifier block was the
624 * event-disable EC-command.
629 return __ssam_notifier_unregister(sdev->ctrl, n, in ssam_device_notifier_unregister()