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 /**
74  * @brief Update host MAC interface register over SPI
75  *
76  * @note The caller is responsible for device lock.
77  *       Shall not be called from ISR.
78  *
79  * @param[in] dev ADIN2111 device.
80  * @param reg Register address.
81  * @param mask Bitmask for bits that may be modified.
82  * @param data Data to apply in the masked range.
83  *
84  * @retval 0 Successful write.
85  * @retval <0 Error, a negative errno code.
86  */
87 int eth_adin2111_reg_update(const struct device *dev, const uint16_t reg,
88 			    uint32_t mask, uint32_t data);
89 
90 /**
91  * @brief Reset both the MAC and PHY.
92  *
93  * @param[in] dev ADIN2111 device.
94  * @param delay Delay in milliseconds.
95  *
96  * @note The caller is responsible for device lock.
97  *       Shall not be called from ISR.
98  *
99  * @retval 0 Successful write.
100  * @retval <0 Error, a negative errno code.
101  */
102 int eth_adin2111_sw_reset(const struct device *dev, uint16_t delay);
103 
104 /**
105  * @brief Reset the MAC device. Note that PHY 1 must be out of software power-down for the MAC
106  *        subsystem reset to take effect.
107  *
108  * @note The caller is responsible for device lock.
109  *       Shall not be called from ISR.
110  *
111  * @param[in] dev ADIN2111 device.
112  *
113  * @retval 0 Successful write.
114  * @retval <0 Error, a negative errno code.
115  */
116 int eth_adin2111_mac_reset(const struct device *dev);
117 
118 /**
119  * @brief Enable/disable the forwarding (to host) of broadcast frames. Frames who's DA
120  *        doesn't match are dropped.
121  *
122  * @note The caller is responsible for device lock.
123  *       Shall not be called from ISR.
124  *
125  * @param[in] dev ADIN2111 device.
126  * @param enable Set to 0 to disable and to nonzero to enable.
127  *
128  * @retval 0 Successful write.
129  * @retval <0 Error, a negative errno code.
130  */
131 int eth_adin2111_broadcast_filter(const struct device *dev, bool enable);
132 
133 /**
134  * @brief Get the port-related net_if reference.
135  *
136  * @param[in] dev ADIN2111 device.
137  * @param port_idx Port index.
138  *
139  * @retval a struct net_if pointer, or NULL on error.
140  */
141 struct net_if *eth_adin2111_get_iface(const struct device *dev, const uint16_t port_idx);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* ZEPHYR_INCLUDE_DRIVERS_ETH_ADIN2111_H__ */
148