1 /* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
10 * Implement a hwspinlock uclass.
11 * Hardware spinlocks are used to perform hardware protection of
12 * critical sections and synchronisation between multiprocessors.
18 * struct hwspinlock - A handle to (allowing control of) a single hardware
21 * @dev: The device which implements the hardware spinlock.
22 * @id: The hardware spinlock ID within the provider.
29 #if CONFIG_IS_ENABLED(DM_HWSPINLOCK)
32 * hwspinlock_get_by_index - Get a hardware spinlock by integer index
34 * This looks up and request a hardware spinlock. The index is relative to the
35 * client device; each device is assumed to have n hardware spinlock associated
36 * with it somehow, and this function finds and requests one of them.
38 * @dev: The client device.
39 * @index: The index of the hardware spinlock to request, within the
40 * client's list of hardware spinlock.
41 * @hws: A pointer to a hardware spinlock struct to initialize.
42 * @return 0 if OK, or a negative error code.
44 int hwspinlock_get_by_index(struct udevice *dev,
45 int index, struct hwspinlock *hws);
48 * Lock the hardware spinlock
50 * @hws: A hardware spinlock struct that previously requested by
51 * hwspinlock_get_by_index
52 * @timeout: Timeout value in msecs
53 * @return: 0 if OK, -ETIMEDOUT if timeout, -ve on other errors
55 int hwspinlock_lock_timeout(struct hwspinlock *hws, unsigned int timeout);
58 * Unlock the hardware spinlock
60 * @hws: A hardware spinlock struct that previously requested by
61 * hwspinlock_get_by_index
62 * @return: 0 if OK, -ve on error
64 int hwspinlock_unlock(struct hwspinlock *hws);
68 static inline int hwspinlock_get_by_index(struct udevice *dev,
70 struct hwspinlock *hws)
75 static inline int hwspinlock_lock_timeout(struct hwspinlock *hws,
81 static inline int hwspinlock_unlock(struct hwspinlock *hws)
86 #endif /* CONFIG_DM_HWSPINLOCK */
88 struct ofnode_phandle_args;
91 * struct hwspinlock_ops - Driver model hwspinlock operations
93 * The uclass interface is implemented by all hwspinlock devices which use
96 struct hwspinlock_ops {
98 * of_xlate - Translate a client's device-tree (OF) hardware specifier.
100 * The hardware core calls this function as the first step in
101 * implementing a client's hwspinlock_get_by_*() call.
103 * @hws: The hardware spinlock struct to hold the translation
105 * @args: The hardware spinlock specifier values from device tree.
106 * @return 0 if OK, or a negative error code.
108 int (*of_xlate)(struct hwspinlock *hws,
109 struct ofnode_phandle_args *args);
112 * Lock the hardware spinlock
114 * @dev: hwspinlock Device
115 * @index: index of the lock to be used
116 * @return 0 if OK, -ve on error
118 int (*lock)(struct udevice *dev, int index);
121 * Unlock the hardware spinlock
123 * @dev: hwspinlock Device
124 * @index: index of the lock to be unlocked
125 * @return 0 if OK, -ve on error
127 int (*unlock)(struct udevice *dev, int index);
131 * Platform-specific relax method, called by hwspinlock core
132 * while spinning on a lock, between two successive call to
135 * @dev: hwspinlock Device
137 void (*relax)(struct udevice *dev);
140 #endif /* _HWSPINLOCK_H_ */