Lines Matching +full:no +full:- +full:auto +full:- +full:reset

2  * Copyright (c) 2021 IP-Logix Inc.
5 * SPDX-License-Identifier: Apache-2.0
39 /* Offset to align capabilities bits of 1000BASE-T Control and Status regs */
50 const struct phy_mii_dev_config *const cfg = dev->config; in phy_mii_reg_read()
52 /* if there is no mdio (fixed-link) it is not supported to read */ in phy_mii_reg_read()
53 if (cfg->mdio == NULL) { in phy_mii_reg_read()
54 return -ENOTSUP; in phy_mii_reg_read()
56 return mdio_read(cfg->mdio, cfg->phy_addr, reg_addr, value); in phy_mii_reg_read()
62 const struct phy_mii_dev_config *const cfg = dev->config; in phy_mii_reg_write()
64 /* if there is no mdio (fixed-link) it is not supported to write */ in phy_mii_reg_write()
65 if (cfg->mdio == NULL) { in phy_mii_reg_write()
66 return -ENOTSUP; in phy_mii_reg_write()
68 return mdio_write(cfg->mdio, cfg->phy_addr, reg_addr, value); in phy_mii_reg_write()
77 return -EIO; in is_gigabit_supported()
82 return -EIO; in is_gigabit_supported()
94 static int reset(const struct device *dev) in reset() function
99 /* Issue a soft reset */ in reset()
101 return -EIO; in reset()
104 /* Wait up to 0.6s for the reset sequence to finish. According to in reset()
105 * IEEE 802.3, Section 2, Subsection 22.2.4.1.1 a PHY reset may take in reset()
109 if (timeout-- == 0U) { in reset()
110 return -ETIMEDOUT; in reset()
116 return -EIO; in reset()
128 return -EIO; in get_id()
134 return -EIO; in get_id()
144 const struct phy_mii_dev_config *const cfg = dev->config; in update_link_state()
145 struct phy_mii_dev_data *const data = dev->data; in update_link_state()
157 return -EIO; in update_link_state()
162 /* If there is no change in link state don't proceed. */ in update_link_state()
163 if (link_up == data->state.is_up) { in update_link_state()
164 return -EAGAIN; in update_link_state()
167 data->state.is_up = link_up; in update_link_state()
170 if (data->state.is_up == false) { in update_link_state()
171 LOG_INF("PHY (%d) is down", cfg->phy_addr); in update_link_state()
176 * Perform auto-negotiation sequence. in update_link_state()
178 LOG_DBG("PHY (%d) Starting MII PHY auto-negotiate sequence", in update_link_state()
179 cfg->phy_addr); in update_link_state()
183 return -EIO; in update_link_state()
186 /* Configure and start auto-negotiation process */ in update_link_state()
188 return -EIO; in update_link_state()
195 return -EIO; in update_link_state()
198 /* Wait for the auto-negotiation process to complete */ in update_link_state()
200 if (timeout-- == 0U) { in update_link_state()
201 LOG_DBG("PHY (%d) auto-negotiate timedout", in update_link_state()
202 cfg->phy_addr); in update_link_state()
203 return -ETIMEDOUT; in update_link_state()
212 return -EIO; in update_link_state()
217 return -EIO; in update_link_state()
221 LOG_DBG("PHY (%d) auto-negotiate sequence completed", in update_link_state()
222 cfg->phy_addr); in update_link_state()
226 return -EIO; in update_link_state()
229 if (data->gigabit_supported) { in update_link_state()
231 return -EIO; in update_link_state()
234 return -EIO; in update_link_state()
239 if (data->gigabit_supported && in update_link_state()
241 data->state.speed = LINK_FULL_1000BASE_T; in update_link_state()
242 } else if (data->gigabit_supported && in update_link_state()
244 data->state.speed = LINK_HALF_1000BASE_T; in update_link_state()
246 data->state.speed = LINK_FULL_100BASE_T; in update_link_state()
248 data->state.speed = LINK_HALF_100BASE_T; in update_link_state()
250 data->state.speed = LINK_FULL_10BASE_T; in update_link_state()
252 data->state.speed = LINK_HALF_10BASE_T; in update_link_state()
256 cfg->phy_addr, in update_link_state()
257 PHY_LINK_IS_SPEED_1000M(data->state.speed) ? "1000" : in update_link_state()
258 (PHY_LINK_IS_SPEED_100M(data->state.speed) ? "100" : "10"), in update_link_state()
259 PHY_LINK_IS_FULL_DUPLEX(data->state.speed) ? "full" : "half"); in update_link_state()
266 struct phy_mii_dev_data *const data = dev->data; in invoke_link_cb()
269 if (data->cb == NULL) { in invoke_link_cb()
275 data->cb(data->dev, &state, data->cb_data); in invoke_link_cb()
283 const struct device *dev = data->dev; in monitor_work_handler()
286 k_sem_take(&data->sem, K_FOREVER); in monitor_work_handler()
290 k_sem_give(&data->sem); in monitor_work_handler()
298 k_work_reschedule(&data->monitor_work, in monitor_work_handler()
317 struct phy_mii_dev_data *const data = dev->data; in phy_mii_cfg_link()
323 return -EIO; in phy_mii_cfg_link()
327 return -EIO; in phy_mii_cfg_link()
330 if (data->gigabit_supported) { in phy_mii_cfg_link()
332 return -EIO; in phy_mii_cfg_link()
360 if (data->gigabit_supported) { in phy_mii_cfg_link()
374 return -EIO; in phy_mii_cfg_link()
381 return -EIO; in phy_mii_cfg_link()
385 return -EIO; in phy_mii_cfg_link()
394 struct phy_mii_dev_data *const data = dev->data; in phy_mii_get_link_state()
396 k_sem_take(&data->sem, K_FOREVER); in phy_mii_get_link_state()
398 memcpy(state, &data->state, sizeof(struct phy_link_state)); in phy_mii_get_link_state()
400 k_sem_give(&data->sem); in phy_mii_get_link_state()
408 struct phy_mii_dev_data *const data = dev->data; in phy_mii_link_cb_set()
410 data->cb = cb; in phy_mii_link_cb_set()
411 data->cb_data = user_data; in phy_mii_link_cb_set()
424 const struct phy_mii_dev_config *const cfg = dev->config; in phy_mii_initialize()
425 struct phy_mii_dev_data *const data = dev->data; in phy_mii_initialize()
428 k_sem_init(&data->sem, 1, 1); in phy_mii_initialize()
430 data->dev = dev; in phy_mii_initialize()
431 data->cb = NULL; in phy_mii_initialize()
438 if (cfg->fixed) { in phy_mii_initialize()
448 data->state.speed = speed_to_phy_link_speed[cfg->fixed_speed]; in phy_mii_initialize()
449 data->state.is_up = true; in phy_mii_initialize()
451 data->state.is_up = false; in phy_mii_initialize()
453 mdio_bus_enable(cfg->mdio); in phy_mii_initialize()
455 if (cfg->no_reset == false) { in phy_mii_initialize()
456 reset(dev); in phy_mii_initialize()
461 LOG_ERR("No PHY found at address %d", in phy_mii_initialize()
462 cfg->phy_addr); in phy_mii_initialize()
464 return -EINVAL; in phy_mii_initialize()
467 LOG_INF("PHY (%d) ID %X", cfg->phy_addr, phy_id); in phy_mii_initialize()
470 data->gigabit_supported = is_gigabit_supported(dev); in phy_mii_initialize()
480 k_work_init_delayable(&data->monitor_work, in phy_mii_initialize()
483 monitor_work_handler(&data->monitor_work.work); in phy_mii_initialize()