Skip to content

Commit c96f236

Browse files
ndrs-pstkartben
authored andcommitted
drivers: ethernet: ksz8081: simplify gpio reset logic in reset
Simplifies GPIO reset logic in `phy_mc_ksz8081_reset()` by introducing a dedicated function, `phy_ksz8081_reset_gpio`. If this function returns `-ENODEV`, it will fall back to using a command-based reset instead. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent 38ef52b commit c96f236

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

drivers/ethernet/phy/phy_microchip_ksz8081.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,30 +263,19 @@ static int phy_mc_ksz8081_static_cfg(const struct device *dev)
263263
return 0;
264264
}
265265

266-
static int phy_mc_ksz8081_reset(const struct device *dev)
267-
{
268266
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
269-
const struct mc_ksz8081_config *config = dev->config;
270-
#endif /* DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios) */
271-
struct mc_ksz8081_data *data = dev->data;
267+
static int phy_ksz8081_reset_gpio(const struct mc_ksz8081_config *config)
268+
{
272269
int ret;
273270

274-
/* Lock mutex */
275-
ret = k_mutex_lock(&data->mutex, K_FOREVER);
276-
if (ret) {
277-
LOG_ERR("PHY mutex lock error");
278-
return ret;
279-
}
280-
281-
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
282271
if (!config->reset_gpio.port) {
283-
goto skip_reset_gpio;
272+
return -ENODEV;
284273
}
285274

286275
/* Start reset */
287276
ret = gpio_pin_set_dt(&config->reset_gpio, 0);
288277
if (ret) {
289-
goto done;
278+
return ret;
290279
}
291280

292281
/* Wait for at least 500 us as specified by datasheet */
@@ -298,9 +287,35 @@ static int phy_mc_ksz8081_reset(const struct device *dev)
298287
/* After deasserting reset, must wait at least 100 us to use programming interface */
299288
k_busy_wait(200);
300289

301-
goto done;
302-
skip_reset_gpio:
290+
return ret;
291+
}
292+
#else
293+
static int phy_ksz8081_reset_gpio(const struct mc_ksz8081_config *config)
294+
{
295+
ARG_UNUSED(config);
296+
297+
return -ENODEV;
298+
}
303299
#endif /* DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios) */
300+
301+
static int phy_mc_ksz8081_reset(const struct device *dev)
302+
{
303+
const struct mc_ksz8081_config *config = dev->config;
304+
struct mc_ksz8081_data *data = dev->data;
305+
int ret;
306+
307+
/* Lock mutex */
308+
ret = k_mutex_lock(&data->mutex, K_FOREVER);
309+
if (ret) {
310+
LOG_ERR("PHY mutex lock error");
311+
return ret;
312+
}
313+
314+
ret = phy_ksz8081_reset_gpio(config);
315+
if (ret != -ENODEV) { /* On -ENODEV, attempt command-based reset */
316+
goto done;
317+
}
318+
304319
ret = phy_mc_ksz8081_write(dev, MII_BMCR, MII_BMCR_RESET);
305320
if (ret) {
306321
goto done;

0 commit comments

Comments
 (0)