drivers: net: ethernet: phy: use DEVICE_API_GET

use DEVICE_API_GET in phy.h

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
Fin Maaß 2025-06-13 11:24:57 +02:00 committed by Anas Nashif
commit 42a81d9ef0

View file

@ -233,9 +233,7 @@ __subsystem struct ethphy_driver_api {
static inline int phy_configure_link(const struct device *dev, enum phy_link_speed speeds, static inline int phy_configure_link(const struct device *dev, enum phy_link_speed speeds,
enum phy_cfg_link_flag flags) enum phy_cfg_link_flag flags)
{ {
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api; if (DEVICE_API_GET(ethphy, dev)->cfg_link == NULL) {
if (api->cfg_link == NULL) {
return -ENOSYS; return -ENOSYS;
} }
@ -244,7 +242,7 @@ static inline int phy_configure_link(const struct device *dev, enum phy_link_spe
return -EINVAL; return -EINVAL;
} }
return api->cfg_link(dev, speeds, flags); return DEVICE_API_GET(ethphy, dev)->cfg_link(dev, speeds, flags);
} }
/** /**
@ -262,13 +260,11 @@ static inline int phy_configure_link(const struct device *dev, enum phy_link_spe
*/ */
static inline int phy_get_link_state(const struct device *dev, struct phy_link_state *state) static inline int 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; if (DEVICE_API_GET(ethphy, dev)->get_link == NULL) {
if (api->get_link == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->get_link(dev, state); return DEVICE_API_GET(ethphy, dev)->get_link(dev, state);
} }
/** /**
@ -292,13 +288,11 @@ static inline int phy_get_link_state(const struct device *dev, struct phy_link_s
static inline int phy_link_callback_set(const struct device *dev, phy_callback_t callback, static inline int phy_link_callback_set(const struct device *dev, phy_callback_t callback,
void *user_data) void *user_data)
{ {
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api; if (DEVICE_API_GET(ethphy, dev)->link_cb_set == NULL) {
if (api->link_cb_set == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->link_cb_set(dev, callback, user_data); return DEVICE_API_GET(ethphy, dev)->link_cb_set(dev, callback, user_data);
} }
/** /**
@ -315,13 +309,11 @@ static inline int phy_link_callback_set(const struct device *dev, phy_callback_t
*/ */
static inline int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t *value) static inline int 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; if (DEVICE_API_GET(ethphy, dev)->read == NULL) {
if (api->read == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->read(dev, reg_addr, value); return DEVICE_API_GET(ethphy, dev)->read(dev, reg_addr, value);
} }
/** /**
@ -338,13 +330,11 @@ static inline int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t
*/ */
static inline int phy_write(const struct device *dev, uint16_t reg_addr, uint32_t value) static inline int 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; if (DEVICE_API_GET(ethphy, dev)->write == NULL) {
if (api->write == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->write(dev, reg_addr, value); return DEVICE_API_GET(ethphy, dev)->write(dev, reg_addr, value);
} }
/** /**
@ -363,13 +353,11 @@ static inline int phy_write(const struct device *dev, uint16_t reg_addr, uint32_
static inline int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t regad, static inline int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t regad,
uint16_t *data) uint16_t *data)
{ {
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api; if (DEVICE_API_GET(ethphy, dev)->read_c45 == NULL) {
if (api->read_c45 == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->read_c45(dev, devad, regad, data); return DEVICE_API_GET(ethphy, dev)->read_c45(dev, devad, regad, data);
} }
/** /**
@ -388,13 +376,11 @@ static inline int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t
static inline int phy_write_c45(const struct device *dev, uint8_t devad, uint16_t regad, static inline int phy_write_c45(const struct device *dev, uint8_t devad, uint16_t regad,
uint16_t data) uint16_t data)
{ {
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api; if (DEVICE_API_GET(ethphy, dev)->write_c45 == NULL) {
if (api->write_c45 == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->write_c45(dev, devad, regad, data); return DEVICE_API_GET(ethphy, dev)->write_c45(dev, devad, regad, data);
} }
/** /**
@ -410,13 +396,11 @@ static inline int phy_write_c45(const struct device *dev, uint8_t devad, uint16_
*/ */
static inline int phy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg) static inline int phy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
{ {
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api; if (DEVICE_API_GET(ethphy, dev)->set_plca_cfg == NULL) {
if (api->set_plca_cfg == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->set_plca_cfg(dev, plca_cfg); return DEVICE_API_GET(ethphy, dev)->set_plca_cfg(dev, plca_cfg);
} }
/** /**
@ -432,13 +416,11 @@ static inline int phy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg
*/ */
static inline int phy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg) static inline int phy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
{ {
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api; if (DEVICE_API_GET(ethphy, dev)->get_plca_cfg == NULL) {
if (api->get_plca_cfg == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->get_plca_cfg(dev, plca_cfg); return DEVICE_API_GET(ethphy, dev)->get_plca_cfg(dev, plca_cfg);
} }
/** /**
@ -454,13 +436,11 @@ static inline int phy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg
*/ */
static inline int phy_get_plca_sts(const struct device *dev, bool *plca_status) static inline int phy_get_plca_sts(const struct device *dev, bool *plca_status)
{ {
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api; if (DEVICE_API_GET(ethphy, dev)->get_plca_sts == NULL) {
if (api->get_plca_sts == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->get_plca_sts(dev, plca_status); return DEVICE_API_GET(ethphy, dev)->get_plca_sts(dev, plca_status);
} }
#ifdef __cplusplus #ifdef __cplusplus