123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- #ifndef ZEPHYR_INCLUDE_DRIVERS_PHY_H_
- #define ZEPHYR_INCLUDE_DRIVERS_PHY_H_
- #include <zephyr/types.h>
- #include <device.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- enum phy_link_speed {
-
- LINK_HALF_10BASE_T = BIT(0),
-
- LINK_FULL_10BASE_T = BIT(1),
-
- LINK_HALF_100BASE_T = BIT(2),
-
- LINK_FULL_100BASE_T = BIT(3),
- };
- #define PHY_LINK_IS_FULL_DUPLEX(x) (x & (BIT(1) | BIT(3)))
- #define PHY_LINK_IS_SPEED_100M(x) (x & (BIT(2) | BIT(3)))
- struct phy_link_state {
-
- enum phy_link_speed speed;
-
- bool is_up;
- };
- typedef void (*phy_callback_t)(const struct device *dev,
- struct phy_link_state *state,
- void *user_data);
- __subsystem struct ethphy_driver_api {
-
- int (*get_link)(const struct device *dev,
- struct phy_link_state *state);
-
- int (*cfg_link)(const struct device *dev,
- enum phy_link_speed adv_speeds);
-
- int (*link_cb_set)(const struct device *dev, phy_callback_t cb,
- void *user_data);
-
- int (*read)(const struct device *dev, uint16_t reg_addr,
- uint32_t *data);
-
- int (*write)(const struct device *dev, uint16_t reg_addr,
- uint32_t data);
- };
- __syscall int phy_configure_link(const struct device *dev,
- enum phy_link_speed speeds);
- static inline int z_impl_phy_configure_link(const struct device *dev,
- enum phy_link_speed speeds)
- {
- const struct ethphy_driver_api *api =
- (const struct ethphy_driver_api *)dev->api;
- return api->cfg_link(dev, speeds);
- }
- __syscall int phy_get_link_state(const struct device *dev,
- struct phy_link_state *state);
- static inline int z_impl_phy_get_link_state(const struct device *dev,
- struct phy_link_state *state)
- {
- const struct ethphy_driver_api *api =
- (const struct ethphy_driver_api *)dev->api;
- return api->get_link(dev, state);
- }
- __syscall int phy_link_callback_set(const struct device *dev,
- phy_callback_t callback,
- void *user_data);
- static inline int z_impl_phy_link_callback_set(const struct device *dev,
- phy_callback_t callback,
- void *user_data)
- {
- const struct ethphy_driver_api *api =
- (const struct ethphy_driver_api *)dev->api;
- return api->link_cb_set(dev, callback, user_data);
- }
- __syscall int phy_read(const struct device *dev, uint16_t reg_addr,
- uint32_t *value);
- static inline int z_impl_phy_read(const struct device *dev, uint16_t reg_addr,
- uint32_t *value)
- {
- const struct ethphy_driver_api *api =
- (const struct ethphy_driver_api *)dev->api;
- return api->read(dev, reg_addr, value);
- }
- __syscall int phy_write(const struct device *dev, uint16_t reg_addr,
- uint32_t value);
- static inline int z_impl_phy_write(const struct device *dev, uint16_t reg_addr,
- uint32_t value)
- {
- const struct ethphy_driver_api *api =
- (const struct ethphy_driver_api *)dev->api;
- return api->write(dev, reg_addr, value);
- }
- #ifdef __cplusplus
- }
- #endif
- #include <syscalls/phy.h>
- #endif
|