Skip to content

Commit c55277f

Browse files
maass-hamburgnashif
authored andcommitted
drivers: mdio: use DEVICE_API_GET
use DEVICE_API_GET in mdio.h Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
1 parent cf8049a commit c55277f

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

include/zephyr/drivers/mdio.h

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ __syscall void mdio_bus_enable(const struct device *dev);
7070

7171
static inline void z_impl_mdio_bus_enable(const struct device *dev)
7272
{
73-
const struct mdio_driver_api *api =
74-
(const struct mdio_driver_api *)dev->api;
75-
76-
if (api->bus_enable != NULL) {
77-
api->bus_enable(dev);
73+
if (DEVICE_API_GET(mdio, dev)->bus_enable != NULL) {
74+
DEVICE_API_GET(mdio, dev)->bus_enable(dev);
7875
}
7976
}
8077

@@ -88,11 +85,8 @@ __syscall void mdio_bus_disable(const struct device *dev);
8885

8986
static inline void z_impl_mdio_bus_disable(const struct device *dev)
9087
{
91-
const struct mdio_driver_api *api =
92-
(const struct mdio_driver_api *)dev->api;
93-
94-
if (api->bus_disable != NULL) {
95-
api->bus_disable(dev);
88+
if (DEVICE_API_GET(mdio, dev)->bus_disable != NULL) {
89+
DEVICE_API_GET(mdio, dev)->bus_disable(dev);
9690
}
9791
}
9892

@@ -118,14 +112,11 @@ __syscall int mdio_read(const struct device *dev, uint8_t prtad, uint8_t regad,
118112
static inline int z_impl_mdio_read(const struct device *dev, uint8_t prtad,
119113
uint8_t regad, uint16_t *data)
120114
{
121-
const struct mdio_driver_api *api =
122-
(const struct mdio_driver_api *)dev->api;
123-
124-
if (api->read == NULL) {
115+
if (DEVICE_API_GET(mdio, dev)->read == NULL) {
125116
return -ENOSYS;
126117
}
127118

128-
return api->read(dev, prtad, regad, data);
119+
return DEVICE_API_GET(mdio, dev)->read(dev, prtad, regad, data);
129120
}
130121

131122

@@ -151,14 +142,11 @@ __syscall int mdio_write(const struct device *dev, uint8_t prtad, uint8_t regad,
151142
static inline int z_impl_mdio_write(const struct device *dev, uint8_t prtad,
152143
uint8_t regad, uint16_t data)
153144
{
154-
const struct mdio_driver_api *api =
155-
(const struct mdio_driver_api *)dev->api;
156-
157-
if (api->write == NULL) {
145+
if (DEVICE_API_GET(mdio, dev)->write == NULL) {
158146
return -ENOSYS;
159147
}
160148

161-
return api->write(dev, prtad, regad, data);
149+
return DEVICE_API_GET(mdio, dev)->write(dev, prtad, regad, data);
162150
}
163151

164152
/**
@@ -185,14 +173,11 @@ static inline int z_impl_mdio_read_c45(const struct device *dev, uint8_t prtad,
185173
uint8_t devad, uint16_t regad,
186174
uint16_t *data)
187175
{
188-
const struct mdio_driver_api *api =
189-
(const struct mdio_driver_api *)dev->api;
190-
191-
if (api->read_c45 == NULL) {
176+
if (DEVICE_API_GET(mdio, dev)->read_c45 == NULL) {
192177
return -ENOSYS;
193178
}
194179

195-
return api->read_c45(dev, prtad, devad, regad, data);
180+
return DEVICE_API_GET(mdio, dev)->read_c45(dev, prtad, devad, regad, data);
196181
}
197182

198183
/**
@@ -219,14 +204,11 @@ static inline int z_impl_mdio_write_c45(const struct device *dev, uint8_t prtad,
219204
uint8_t devad, uint16_t regad,
220205
uint16_t data)
221206
{
222-
const struct mdio_driver_api *api =
223-
(const struct mdio_driver_api *)dev->api;
224-
225-
if (api->write_c45 == NULL) {
207+
if (DEVICE_API_GET(mdio, dev)->write_c45 == NULL) {
226208
return -ENOSYS;
227209
}
228210

229-
return api->write_c45(dev, prtad, devad, regad, data);
211+
return DEVICE_API_GET(mdio, dev)->write_c45(dev, prtad, devad, regad, data);
230212
}
231213

232214
#ifdef __cplusplus

0 commit comments

Comments
 (0)