Skip to content

Commit 42a81d9

Browse files
maass-hamburgnashif
authored andcommitted
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>
1 parent c55277f commit 42a81d9

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

include/zephyr/net/phy.h

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ __subsystem struct ethphy_driver_api {
233233
static inline int phy_configure_link(const struct device *dev, enum phy_link_speed speeds,
234234
enum phy_cfg_link_flag flags)
235235
{
236-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
237-
238-
if (api->cfg_link == NULL) {
236+
if (DEVICE_API_GET(ethphy, dev)->cfg_link == NULL) {
239237
return -ENOSYS;
240238
}
241239

@@ -244,7 +242,7 @@ static inline int phy_configure_link(const struct device *dev, enum phy_link_spe
244242
return -EINVAL;
245243
}
246244

247-
return api->cfg_link(dev, speeds, flags);
245+
return DEVICE_API_GET(ethphy, dev)->cfg_link(dev, speeds, flags);
248246
}
249247

250248
/**
@@ -262,13 +260,11 @@ static inline int phy_configure_link(const struct device *dev, enum phy_link_spe
262260
*/
263261
static inline int phy_get_link_state(const struct device *dev, struct phy_link_state *state)
264262
{
265-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
266-
267-
if (api->get_link == NULL) {
263+
if (DEVICE_API_GET(ethphy, dev)->get_link == NULL) {
268264
return -ENOSYS;
269265
}
270266

271-
return api->get_link(dev, state);
267+
return DEVICE_API_GET(ethphy, dev)->get_link(dev, state);
272268
}
273269

274270
/**
@@ -292,13 +288,11 @@ static inline int phy_get_link_state(const struct device *dev, struct phy_link_s
292288
static inline int phy_link_callback_set(const struct device *dev, phy_callback_t callback,
293289
void *user_data)
294290
{
295-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
296-
297-
if (api->link_cb_set == NULL) {
291+
if (DEVICE_API_GET(ethphy, dev)->link_cb_set == NULL) {
298292
return -ENOSYS;
299293
}
300294

301-
return api->link_cb_set(dev, callback, user_data);
295+
return DEVICE_API_GET(ethphy, dev)->link_cb_set(dev, callback, user_data);
302296
}
303297

304298
/**
@@ -315,13 +309,11 @@ static inline int phy_link_callback_set(const struct device *dev, phy_callback_t
315309
*/
316310
static inline int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t *value)
317311
{
318-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
319-
320-
if (api->read == NULL) {
312+
if (DEVICE_API_GET(ethphy, dev)->read == NULL) {
321313
return -ENOSYS;
322314
}
323315

324-
return api->read(dev, reg_addr, value);
316+
return DEVICE_API_GET(ethphy, dev)->read(dev, reg_addr, value);
325317
}
326318

327319
/**
@@ -338,13 +330,11 @@ static inline int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t
338330
*/
339331
static inline int phy_write(const struct device *dev, uint16_t reg_addr, uint32_t value)
340332
{
341-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
342-
343-
if (api->write == NULL) {
333+
if (DEVICE_API_GET(ethphy, dev)->write == NULL) {
344334
return -ENOSYS;
345335
}
346336

347-
return api->write(dev, reg_addr, value);
337+
return DEVICE_API_GET(ethphy, dev)->write(dev, reg_addr, value);
348338
}
349339

350340
/**
@@ -363,13 +353,11 @@ static inline int phy_write(const struct device *dev, uint16_t reg_addr, uint32_
363353
static inline int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t regad,
364354
uint16_t *data)
365355
{
366-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
367-
368-
if (api->read_c45 == NULL) {
356+
if (DEVICE_API_GET(ethphy, dev)->read_c45 == NULL) {
369357
return -ENOSYS;
370358
}
371359

372-
return api->read_c45(dev, devad, regad, data);
360+
return DEVICE_API_GET(ethphy, dev)->read_c45(dev, devad, regad, data);
373361
}
374362

375363
/**
@@ -388,13 +376,11 @@ static inline int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t
388376
static inline int phy_write_c45(const struct device *dev, uint8_t devad, uint16_t regad,
389377
uint16_t data)
390378
{
391-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
392-
393-
if (api->write_c45 == NULL) {
379+
if (DEVICE_API_GET(ethphy, dev)->write_c45 == NULL) {
394380
return -ENOSYS;
395381
}
396382

397-
return api->write_c45(dev, devad, regad, data);
383+
return DEVICE_API_GET(ethphy, dev)->write_c45(dev, devad, regad, data);
398384
}
399385

400386
/**
@@ -410,13 +396,11 @@ static inline int phy_write_c45(const struct device *dev, uint8_t devad, uint16_
410396
*/
411397
static inline int phy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
412398
{
413-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
414-
415-
if (api->set_plca_cfg == NULL) {
399+
if (DEVICE_API_GET(ethphy, dev)->set_plca_cfg == NULL) {
416400
return -ENOSYS;
417401
}
418402

419-
return api->set_plca_cfg(dev, plca_cfg);
403+
return DEVICE_API_GET(ethphy, dev)->set_plca_cfg(dev, plca_cfg);
420404
}
421405

422406
/**
@@ -432,13 +416,11 @@ static inline int phy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg
432416
*/
433417
static inline int phy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
434418
{
435-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
436-
437-
if (api->get_plca_cfg == NULL) {
419+
if (DEVICE_API_GET(ethphy, dev)->get_plca_cfg == NULL) {
438420
return -ENOSYS;
439421
}
440422

441-
return api->get_plca_cfg(dev, plca_cfg);
423+
return DEVICE_API_GET(ethphy, dev)->get_plca_cfg(dev, plca_cfg);
442424
}
443425

444426
/**
@@ -454,13 +436,11 @@ static inline int phy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg
454436
*/
455437
static inline int phy_get_plca_sts(const struct device *dev, bool *plca_status)
456438
{
457-
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
458-
459-
if (api->get_plca_sts == NULL) {
439+
if (DEVICE_API_GET(ethphy, dev)->get_plca_sts == NULL) {
460440
return -ENOSYS;
461441
}
462442

463-
return api->get_plca_sts(dev, plca_status);
443+
return DEVICE_API_GET(ethphy, dev)->get_plca_sts(dev, plca_status);
464444
}
465445

466446
#ifdef __cplusplus

0 commit comments

Comments
 (0)