Lines Matching +full:init +full:- +full:mdio +full:- +full:phy

3  * SPDX-License-Identifier: Apache-2.0
7 #include <zephyr/net/phy.h>
10 #include <zephyr/drivers/mdio.h>
18 #define SMSC_LOCK(sc) k_mutex_lock(&(sc)->lock, K_FOREVER)
19 #define SMSC_UNLOCK(sc) k_mutex_unlock(&(sc)->lock)
91 sys_write16(bank & BSR_BANK_MASK, sc->smsc_reg + BSR); in smsc_select_bank()
96 return FIELD_GET(BSR_BANK_MASK, sys_read16(sc->smsc_reg + BSR)); in smsc_current_bank()
102 while (sys_read16(sc->smsc_reg + MMUCR) & MMUCR_BUSY) { in smsc_mmu_wait()
109 return sys_read8(sc->smsc_reg + offset); in smsc_read_1()
114 return sys_read16(sc->smsc_reg + offset); in smsc_read_2()
120 while (count--) { in smsc_read_multi_2()
121 *datap++ = sys_read16(sc->smsc_reg + offset); in smsc_read_multi_2()
127 sys_write8(val, sc->smsc_reg + offset); in smsc_write_1()
132 sys_write16(val, sc->smsc_reg + offset); in smsc_write_2()
138 while (count--) { in smsc_write_multi_2()
139 sys_write16(*datap++, sc->smsc_reg + offset); in smsc_write_multi_2()
189 for (i = 1 << (nbits - 1); i != 0; i >>= 1) { in smsc_miibus_sendbits()
202 static int smsc_miibus_readreg(struct smsc_data *sc, int phy, int reg) in smsc_miibus_readreg() argument
206 irq_disable(sc->irq); in smsc_miibus_readreg()
215 smsc_miibus_sendbits(sc, phy, 5); in smsc_miibus_readreg()
218 /* Switch direction to PHY -> host */ in smsc_miibus_readreg()
233 /* Read data prior to clock low-high transition. */ in smsc_miibus_readreg()
242 /* Set direction to host -> PHY, without a clock transition. */ in smsc_miibus_readreg()
246 irq_enable(sc->irq); in smsc_miibus_readreg()
251 static void smsc_miibus_writereg(struct smsc_data *sc, int phy, int reg, uint16_t val) in smsc_miibus_writereg() argument
253 irq_disable(sc->irq); in smsc_miibus_writereg()
262 smsc_miibus_sendbits(sc, phy, 5); in smsc_miibus_writereg()
270 irq_enable(sc->irq); in smsc_miibus_writereg()
323 * Set up the receive/PHY control register. in smsc_enable()
347 sc->smsc_mask = RCV_INT; in smsc_enable()
348 smsc_write_1(sc, MSK, sc->smsc_mask); in smsc_enable()
358 return -ENODEV; in smsc_check()
365 return -ENODEV; in smsc_check()
373 return -ENODEV; in smsc_check()
383 struct smsc_data *sc = &data->sc; in smsc_recv_pkt()
406 len -= PKT_CTRL_DATA_LEN; in smsc_recv_pkt()
437 rx_buffer[len - 1] = smsc_read_1(sc, DATA0); in smsc_recv_pkt()
440 pkt = net_pkt_rx_alloc_with_buffer(data->iface, len, AF_UNSPEC, 0, in smsc_recv_pkt()
454 ret = net_recv_data(data->iface, pkt); in smsc_recv_pkt()
472 sc->smsc_mask |= RCV_INT; in smsc_recv_pkt()
473 smsc_write_1(sc, MSK, sc->smsc_mask); in smsc_recv_pkt()
492 for (polling_count = TX_ALLOC_WAIT_TIME; polling_count > 0; polling_count--) { in smsc_send_pkt()
503 return -1; in smsc_send_pkt()
510 return -1; in smsc_send_pkt()
528 smsc_write_2(sc, DATA0, (CTRL_ODD << 8) | buf[len - 1]); in smsc_send_pkt()
542 sc->smsc_mask |= (TX_EMPTY_INT | TX_INT); in smsc_send_pkt()
543 smsc_write_1(sc, MSK, sc->smsc_mask); in smsc_send_pkt()
571 status &= sc->smsc_mask; in smsc_isr_task()
627 sc->smsc_mask &= ~TX_EMPTY_INT; in smsc_isr_task()
632 smsc_write_1(sc, MSK, sc->smsc_mask); in smsc_isr_task()
653 sc->smsc_chip = FIELD_GET(REV_CHIP_MASK, val); in smsc_init()
654 sc->smsc_rev = FIELD_GET(REV_REV_MASK, val); in smsc_init()
657 sc->mac[0] = smsc_read_1(sc, IAR0); in smsc_init()
658 sc->mac[1] = smsc_read_1(sc, IAR1); in smsc_init()
659 sc->mac[2] = smsc_read_1(sc, IAR2); in smsc_init()
660 sc->mac[3] = smsc_read_1(sc, IAR3); in smsc_init()
661 sc->mac[4] = smsc_read_1(sc, IAR4); in smsc_init()
662 sc->mac[5] = smsc_read_1(sc, IAR5); in smsc_init()
669 const struct eth_config *cfg = dev->config; in eth_get_phy()
671 return cfg->phy_dev; in eth_get_phy()
678 struct eth_context *data = dev->data; in phy_link_state_changed()
680 if (state->is_up) { in phy_link_state_changed()
681 net_eth_carrier_on(data->iface); in phy_link_state_changed()
683 net_eth_carrier_off(data->iface); in phy_link_state_changed()
701 struct eth_context *data = dev->data; in eth_tx()
702 struct smsc_data *sc = &data->sc; in eth_tx()
708 return -1; in eth_tx()
723 struct eth_context *data = dev->data; in eth_smsc_set_config()
724 struct smsc_data *sc = &data->sc; in eth_smsc_set_config()
730 if (config->promisc_mode && !(reg_val & RCR_PRMS)) { in eth_smsc_set_config()
732 } else if (!config->promisc_mode && (reg_val & RCR_PRMS)) { in eth_smsc_set_config()
735 ret = -EALREADY; in eth_smsc_set_config()
742 ret = -ENOTSUP; in eth_smsc_set_config()
752 struct eth_context *data = dev->data; in eth_initialize()
753 const struct eth_config *cfg = dev->config; in eth_initialize()
754 const struct device *phy_dev = cfg->phy_dev; in eth_initialize()
755 struct smsc_data *sc = &data->sc; in eth_initialize()
764 LOG_INF("MAC %02x:%02x:%02x:%02x:%02x:%02x", sc->mac[0], sc->mac[1], sc->mac[2], sc->mac[3], in eth_initialize()
765 sc->mac[4], sc->mac[5]); in eth_initialize()
767 net_if_set_link_addr(iface, sc->mac, sizeof(sc->mac), NET_LINK_ETHERNET); in eth_initialize()
768 data->iface = iface; in eth_initialize()
773 LOG_ERR("PHY device not ready"); in eth_initialize()
778 .iface_api.init = eth_initialize,
787 struct eth_context *data = dev->data; in eth_smsc_isr()
788 struct smsc_data *sc = &data->sc; in eth_smsc_isr()
800 k_work_submit(&(sc->isr_work)); in eth_smsc_isr()
805 struct eth_context *data = (struct eth_context *)dev->data; in eth_init()
806 struct smsc_data *sc = &data->sc; in eth_init()
809 ret = k_mutex_init(&sc->lock); in eth_init()
814 k_work_init(&sc->isr_work, smsc_isr_task); in eth_init()
820 sc->smsc_reg = DEVICE_MMIO_GET(dev); in eth_init()
821 sc->irq = DT_INST_IRQN(0); in eth_init()
861 const struct mdio_smsc_config *cfg = dev->config; in mdio_smsc_read()
862 const struct device *eth_dev = cfg->eth_dev; in mdio_smsc_read()
863 struct eth_context *eth_data = eth_dev->data; in mdio_smsc_read()
864 struct smsc_data *sc = &eth_data->sc; in mdio_smsc_read()
873 const struct mdio_smsc_config *cfg = dev->config; in mdio_smsc_write()
874 const struct device *eth_dev = cfg->eth_dev; in mdio_smsc_write()
875 struct eth_context *eth_data = eth_dev->data; in mdio_smsc_write()
876 struct smsc_data *sc = &eth_data->sc; in mdio_smsc_write()
883 static DEVICE_API(mdio, mdio_smsc_api) = {