Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
phy.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2021 IP-Logix Inc.
9 * Copyright 2022 NXP
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13#ifndef ZEPHYR_INCLUDE_DRIVERS_PHY_H_
14#define ZEPHYR_INCLUDE_DRIVERS_PHY_H_
15
22#include <zephyr/types.h>
23#include <zephyr/device.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
43};
44
52#define PHY_LINK_IS_FULL_DUPLEX(x) (x & (BIT(1) | BIT(3) | BIT(5)))
53
61#define PHY_LINK_IS_SPEED_1000M(x) (x & (BIT(4) | BIT(5)))
62
70#define PHY_LINK_IS_SPEED_100M(x) (x & (BIT(2) | BIT(3)))
71
77 bool is_up;
78};
79
89typedef void (*phy_callback_t)(const struct device *dev,
90 struct phy_link_state *state,
91 void *user_data);
92
99__subsystem struct ethphy_driver_api {
101 int (*get_link)(const struct device *dev,
102 struct phy_link_state *state);
103
105 int (*cfg_link)(const struct device *dev,
106 enum phy_link_speed adv_speeds);
107
109 int (*link_cb_set)(const struct device *dev, phy_callback_t cb,
110 void *user_data);
111
113 int (*read)(const struct device *dev, uint16_t reg_addr,
114 uint32_t *data);
115
117 int (*write)(const struct device *dev, uint16_t reg_addr,
118 uint32_t data);
119};
136static inline int phy_configure_link(const struct device *dev,
137 enum phy_link_speed speeds)
138{
139 const struct ethphy_driver_api *api =
140 (const struct ethphy_driver_api *)dev->api;
141
142 return api->cfg_link(dev, speeds);
143}
144
158static inline int phy_get_link_state(const struct device *dev,
159 struct phy_link_state *state)
160{
161 const struct ethphy_driver_api *api =
162 (const struct ethphy_driver_api *)dev->api;
163
164 return api->get_link(dev, state);
165}
166
181static inline int phy_link_callback_set(const struct device *dev,
182 phy_callback_t callback,
183 void *user_data)
184{
185 const struct ethphy_driver_api *api =
186 (const struct ethphy_driver_api *)dev->api;
187
188 return api->link_cb_set(dev, callback, user_data);
189}
190
203static inline int phy_read(const struct device *dev, uint16_t reg_addr,
204 uint32_t *value)
205{
206 const struct ethphy_driver_api *api =
207 (const struct ethphy_driver_api *)dev->api;
208
209 return api->read(dev, reg_addr, value);
210}
211
224static inline int phy_write(const struct device *dev, uint16_t reg_addr,
225 uint32_t value)
226{
227 const struct ethphy_driver_api *api =
228 (const struct ethphy_driver_api *)dev->api;
229
230 return api->write(dev, reg_addr, value);
231}
232
233
234#ifdef __cplusplus
235}
236#endif
237
242#endif /* ZEPHYR_INCLUDE_DRIVERS_PHY_H_ */
static int phy_link_callback_set(const struct device *dev, phy_callback_t callback, void *user_data)
Set link state change callback.
Definition: phy.h:181
static int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t *value)
Read PHY registers.
Definition: phy.h:203
static int phy_get_link_state(const struct device *dev, struct phy_link_state *state)
Get PHY link state.
Definition: phy.h:158
static int phy_write(const struct device *dev, uint16_t reg_addr, uint32_t value)
Write PHY register.
Definition: phy.h:224
phy_link_speed
Ethernet link speeds.
Definition: phy.h:30
void(* phy_callback_t)(const struct device *dev, struct phy_link_state *state, void *user_data)
Define the callback function signature for phy_link_callback_set() function.
Definition: phy.h:89
static int phy_configure_link(const struct device *dev, enum phy_link_speed speeds)
Configure PHY link.
Definition: phy.h:136
@ LINK_HALF_100BASE_T
100Base-T Half-Duplex
Definition: phy.h:36
@ LINK_HALF_10BASE_T
10Base-T Half-Duplex
Definition: phy.h:32
@ LINK_FULL_1000BASE_T
1000Base-T Full-Duplex
Definition: phy.h:42
@ LINK_FULL_10BASE_T
10Base-T Full-Duplex
Definition: phy.h:34
@ LINK_FULL_100BASE_T
100Base-T Full-Duplex
Definition: phy.h:38
@ LINK_HALF_1000BASE_T
1000Base-T Half-Duplex
Definition: phy.h:40
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
state
Definition: parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition: device.h:399
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:405