1 /*
2  * Copyright (c) 2023 PHOENIX CONTACT Electronics GmbH
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_DRIVERS_ETH_ADIN2111_H__
8 #define ZEPHYR_INCLUDE_DRIVERS_ETH_ADIN2111_H__
9 
10 #include <stdint.h>
11 #include <zephyr/kernel.h>
12 #include <zephyr/device.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /**
19  * @brief Locks device access
20  *
21  * @param[in] dev ADIN2111 device.
22  * @param timeout Waiting period to lock the device,
23  *                or one of the special values K_NO_WAIT and
24  *                K_FOREVER.
25  *
26  * @retval 0 Device locked.
27  * @retval -EBUSY Returned without waiting.
28  * @retval -EAGAIN Waiting period timed out.
29  */
30 int eth_adin2111_lock(const struct device *dev, k_timeout_t timeout);
31 
32 /**
33  * @brief Unlocks device access
34  *
35  * @param[in] dev ADIN2111 device.
36  *
37  * @retval 0 Device unlocked.
38  * @retval -EPERM The current thread does not own the device lock.
39  * @retval -EINVAL The device is not locked.
40  */
41 int eth_adin2111_unlock(const struct device *dev);
42 
43 /**
44  * @brief Writes host MAC interface register over SPI
45  *
46  * @note The caller is responsible for device lock.
47  *       Shall not be called from ISR.
48  *
49  * @param[in] dev ADIN2111 device.
50  * @param reg Register address.
51  * @param val Value to write.
52  *
53  * @retval 0 Successful write.
54  * @retval <0 Error, a negative errno code.
55  */
56 int eth_adin2111_reg_write(const struct device *dev, const uint16_t reg, uint32_t val);
57 
58 /**
59  * @brief Reads host MAC interface register over SPI
60  *
61  * @note The caller is responsible for device lock.
62  *       Shall not be called from ISR.
63  *
64  * @param[in] dev ADIN2111 device.
65  * @param reg Register address.
66  * @param[out] val Read value output.
67  *
68  * @retval 0 Successful write.
69  * @retval <0 Error, a negative errno code.
70  */
71 int eth_adin2111_reg_read(const struct device *dev, const uint16_t reg, uint32_t *val);
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif /* ZEPHYR_INCLUDE_DRIVERS_ETH_ADIN2111_H__ */
78