Lines Matching +full:device +full:- +full:id
4 * SPDX-License-Identifier: Apache-2.0
9 #include <zephyr/device.h>
27 static inline mem_addr_t get_lock_addr(const struct device *dev, uint32_t id) in get_lock_addr() argument
29 return (mem_addr_t)(DEVICE_MMIO_GET(dev) + id * sizeof(uint32_t)); in get_lock_addr()
33 * To define CPU id, we use the affinity2 and affinity1
43 static int sqn_hwspinlock_trylock(const struct device *dev, uint32_t id) in sqn_hwspinlock_trylock() argument
45 const struct sqn_hwspinlock_config *config = dev->config; in sqn_hwspinlock_trylock()
48 if (id > config->num_locks) { in sqn_hwspinlock_trylock()
49 return -EINVAL; in sqn_hwspinlock_trylock()
60 if (sys_read8(get_lock_addr(dev, id)) == cpuid) { in sqn_hwspinlock_trylock()
64 sys_write8(cpuid, get_lock_addr(dev, id)); in sqn_hwspinlock_trylock()
65 if (sys_read8(get_lock_addr(dev, id)) == cpuid) { in sqn_hwspinlock_trylock()
69 return -EBUSY; in sqn_hwspinlock_trylock()
72 static void sqn_hwspinlock_lock(const struct device *dev, uint32_t id) in sqn_hwspinlock_lock() argument
74 const struct sqn_hwspinlock_config *config = dev->config; in sqn_hwspinlock_lock()
77 if (id > config->num_locks) { in sqn_hwspinlock_lock()
78 LOG_ERR("unsupported hwspinlock id '%d'", id); in sqn_hwspinlock_lock()
89 if (sys_read8(get_lock_addr(dev, id)) == 0) { in sqn_hwspinlock_lock()
90 sys_write8(cpuid, get_lock_addr(dev, id)); in sqn_hwspinlock_lock()
93 while (sys_read8(get_lock_addr(dev, id)) != cpuid) { in sqn_hwspinlock_lock()
95 sys_write8(cpuid, get_lock_addr(dev, id)); in sqn_hwspinlock_lock()
99 static void sqn_hwspinlock_unlock(const struct device *dev, uint32_t id) in sqn_hwspinlock_unlock() argument
101 const struct sqn_hwspinlock_config *config = dev->config; in sqn_hwspinlock_unlock()
104 if (id > config->num_locks) { in sqn_hwspinlock_unlock()
105 LOG_ERR("unsupported hwspinlock id '%d'", id); in sqn_hwspinlock_unlock()
116 sys_write8(cpuid, get_lock_addr(dev, id)); in sqn_hwspinlock_unlock()
119 static uint32_t sqn_hwspinlock_get_max_id(const struct device *dev) in sqn_hwspinlock_get_max_id()
121 const struct sqn_hwspinlock_config *config = dev->config; in sqn_hwspinlock_get_max_id()
123 return config->num_locks; in sqn_hwspinlock_get_max_id()
133 static int sqn_hwspinlock_init(const struct device *dev) in sqn_hwspinlock_init()