1 /* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
9 #include <linux/errno.h>
12 * Implement a hwspinlock uclass.
13 * Hardware spinlocks are used to perform hardware protection of
14 * critical sections and synchronisation between multiprocessors.
20 * struct hwspinlock - A handle to (allowing control of) a single hardware
23 * @dev: The device which implements the hardware spinlock.
24 * @id: The hardware spinlock ID within the provider.
31 #if CONFIG_IS_ENABLED(DM_HWSPINLOCK)
34 * hwspinlock_get_by_index - Get a hardware spinlock by integer index
36 * This looks up and request a hardware spinlock. The index is relative to the
37 * client device; each device is assumed to have n hardware spinlock associated
38 * with it somehow, and this function finds and requests one of them.
40 * @dev: The client device.
41 * @index: The index of the hardware spinlock to request, within the
42 * client's list of hardware spinlock.
43 * @hws: A pointer to a hardware spinlock struct to initialize.
44 * Return: 0 if OK, or a negative error code.
46 int hwspinlock_get_by_index(struct udevice *dev,
47 int index, struct hwspinlock *hws);
50 * Lock the hardware spinlock
52 * @hws: A hardware spinlock struct that previously requested by
53 * hwspinlock_get_by_index
54 * @timeout: Timeout value in msecs
55 * @return: 0 if OK, -ETIMEDOUT if timeout, -ve on other errors
57 int hwspinlock_lock_timeout(struct hwspinlock *hws, unsigned int timeout);
60 * Unlock the hardware spinlock
62 * @hws: A hardware spinlock struct that previously requested by
63 * hwspinlock_get_by_index
64 * @return: 0 if OK, -ve on error
66 int hwspinlock_unlock(struct hwspinlock *hws);
70 static inline int hwspinlock_get_by_index(struct udevice *dev,
72 struct hwspinlock *hws)
77 static inline int hwspinlock_lock_timeout(struct hwspinlock *hws,
83 static inline int hwspinlock_unlock(struct hwspinlock *hws)
88 #endif /* CONFIG_DM_HWSPINLOCK */
90 struct ofnode_phandle_args;
93 * struct hwspinlock_ops - Driver model hwspinlock operations
95 * The uclass interface is implemented by all hwspinlock devices which use
98 struct hwspinlock_ops {
100 * of_xlate - Translate a client's device-tree (OF) hardware specifier.
102 * The hardware core calls this function as the first step in
103 * implementing a client's hwspinlock_get_by_*() call.
105 * @hws: The hardware spinlock struct to hold the translation
107 * @args: The hardware spinlock specifier values from device tree.
108 * @return 0 if OK, or a negative error code.
110 int (*of_xlate)(struct hwspinlock *hws,
111 struct ofnode_phandle_args *args);
114 * Lock the hardware spinlock
116 * @dev: hwspinlock Device
117 * @index: index of the lock to be used
118 * @return 0 if OK, -ve on error
120 int (*lock)(struct udevice *dev, int index);
123 * Unlock the hardware spinlock
125 * @dev: hwspinlock Device
126 * @index: index of the lock to be unlocked
127 * @return 0 if OK, -ve on error
129 int (*unlock)(struct udevice *dev, int index);
133 * Platform-specific relax method, called by hwspinlock core
134 * while spinning on a lock, between two successive call to
137 * @dev: hwspinlock Device
139 void (*relax)(struct udevice *dev);
142 #endif /* _HWSPINLOCK_H_ */