Lines Matching +full:rx +full:- +full:internal +full:- +full:delay

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2014-2017 Broadcom
10 #include <linux/delay.h>
24 #include <linux/platform_data/mdio-bcm-unimac.h>
31 struct phy_device *phydev = dev->phydev; in bcmgenet_mac_config()
35 if (phydev->speed == SPEED_1000) in bcmgenet_mac_config()
37 else if (phydev->speed == SPEED_100) in bcmgenet_mac_config()
44 if (phydev->duplex != DUPLEX_FULL) { in bcmgenet_mac_config()
49 if (priv->autoneg_pause) { in bcmgenet_mac_config()
52 if (phydev->autoneg) in bcmgenet_mac_config()
62 if (!priv->rx_pause) in bcmgenet_mac_config()
64 if (!priv->tx_pause) in bcmgenet_mac_config()
70 * umac->cmd tell RGMII block which clock to use for in bcmgenet_mac_config()
71 * transmit -- 25MHz(100Mbps) or 125MHz(1Gbps). in bcmgenet_mac_config()
98 struct phy_device *phydev = dev->phydev; in bcmgenet_mii_setup()
100 if (phydev->link) in bcmgenet_mii_setup()
112 if (dev && dev->phydev && status) { in bcmgenet_fixed_phy_link_update()
115 status->link = !!(reg & MODE_LINK_STATUS); in bcmgenet_fixed_phy_link_update()
121 void bcmgenet_phy_pause_set(struct net_device *dev, bool rx, bool tx) in bcmgenet_phy_pause_set() argument
123 struct phy_device *phydev = dev->phydev; in bcmgenet_phy_pause_set()
125 linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->advertising, rx); in bcmgenet_phy_pause_set()
126 linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->advertising, in bcmgenet_phy_pause_set()
127 rx | tx); in bcmgenet_phy_pause_set()
130 mutex_lock(&phydev->lock); in bcmgenet_phy_pause_set()
131 if (phydev->link) in bcmgenet_phy_pause_set()
133 mutex_unlock(&phydev->lock); in bcmgenet_phy_pause_set()
142 if (GENET_IS_V4(priv) || priv->ephy_16nm) { in bcmgenet_phy_power_set()
181 if (priv->hw_params->flags & GENET_HAS_MOCA_LINK_DET) in bcmgenet_moca_phy_setup()
182 fixed_phy_set_link_update(priv->dev->phydev, in bcmgenet_moca_phy_setup()
189 struct phy_device *phydev = dev->phydev; in bcmgenet_mii_config()
190 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_config()
196 switch (priv->phy_interface) { in bcmgenet_mii_config()
198 phy_name = "internal PHY"; in bcmgenet_mii_config()
202 * 1000) GENETv4 only has an internal GPHY so we will just end in bcmgenet_mii_config()
225 /* of_mdiobus_register took care of reading the 'max-speed' in bcmgenet_mii_config()
231 dev->phydev->supported)) in bcmgenet_mii_config()
239 * (requires PCB or receiver-side delay) in bcmgenet_mii_config()
243 phy_name = "external RGMII (no delay)"; in bcmgenet_mii_config()
249 /* RGMII_TXID: Add 2ns delay on TXC (90 degree shift) */ in bcmgenet_mii_config()
250 phy_name = "external RGMII (TX delay)"; in bcmgenet_mii_config()
255 phy_name = "external RGMII (RX delay)"; in bcmgenet_mii_config()
259 dev_err(kdev, "unknown phy mode: %d\n", priv->phy_interface); in bcmgenet_mii_config()
260 return -EINVAL; in bcmgenet_mii_config()
265 priv->ext_phy = !priv->internal_phy && in bcmgenet_mii_config()
266 (priv->phy_interface != PHY_INTERFACE_MODE_MOCA); in bcmgenet_mii_config()
271 if (priv->ext_phy) { in bcmgenet_mii_config()
291 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_probe()
292 struct device_node *dn = kdev->of_node; in bcmgenet_mii_probe()
293 phy_interface_t phy_iface = priv->phy_interface; in bcmgenet_mii_probe()
301 if (priv->internal_phy) in bcmgenet_mii_probe()
302 phy_flags = priv->gphy_rev; in bcmgenet_mii_probe()
322 * Note that internal PHY, MoCA and fixed-link configurations are not in bcmgenet_mii_probe()
326 switch (priv->phy_interface) { in bcmgenet_mii_probe()
338 phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup, in bcmgenet_mii_probe()
342 return -ENODEV; in bcmgenet_mii_probe()
349 snprintf(mdio_bus_id, MII_BUS_ID_SIZE, "%s-%d", in bcmgenet_mii_probe()
350 UNIMAC_MDIO_DRV_NAME, priv->pdev->id); in bcmgenet_mii_probe()
355 return -ENODEV; in bcmgenet_mii_probe()
358 put_device(&unimacbus->dev); in bcmgenet_mii_probe()
361 return -ENODEV; in bcmgenet_mii_probe()
364 phydev = dev->phydev; in bcmgenet_mii_probe()
366 phydev->dev_flags = phy_flags; in bcmgenet_mii_probe()
372 return -ENODEV; in bcmgenet_mii_probe()
377 * reading the 'max-speed' property determines the maximum supported in bcmgenet_mii_probe()
383 phy_disconnect(dev->phydev); in bcmgenet_mii_probe()
387 /* The internal PHY has its link interrupts routed to the in bcmgenet_mii_probe()
393 if (priv->internal_phy && !GENET_IS_V5(priv)) in bcmgenet_mii_probe()
394 dev->phydev->irq = PHY_MAC_INTERRUPT; in bcmgenet_mii_probe()
397 dev->phydev->mac_managed_pm = true; in bcmgenet_mii_probe()
404 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_of_find_mdio()
405 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_of_find_mdio()
408 compat = kasprintf(GFP_KERNEL, "brcm,genet-mdio-v%d", priv->version); in bcmgenet_mii_of_find_mdio()
412 priv->mdio_dn = of_get_compatible_child(dn, compat); in bcmgenet_mii_of_find_mdio()
414 if (!priv->mdio_dn) { in bcmgenet_mii_of_find_mdio()
419 return priv->mdio_dn; in bcmgenet_mii_of_find_mdio()
425 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_pdata_init()
426 struct bcmgenet_platform_data *pd = kdev->platform_data; in bcmgenet_mii_pdata_init()
428 if (pd->phy_interface != PHY_INTERFACE_MODE_MOCA && pd->mdio_enabled) { in bcmgenet_mii_pdata_init()
430 * Internal or external PHY with MDIO access in bcmgenet_mii_pdata_init()
432 if (pd->phy_address >= 0 && pd->phy_address < PHY_MAX_ADDR) in bcmgenet_mii_pdata_init()
433 ppd->phy_mask = 1 << pd->phy_address; in bcmgenet_mii_pdata_init()
435 ppd->phy_mask = 0; in bcmgenet_mii_pdata_init()
443 wait_event_timeout(priv->wq, in bcmgenet_mii_wait()
452 struct platform_device *pdev = priv->pdev; in bcmgenet_mii_register()
453 struct bcmgenet_platform_data *pdata = pdev->dev.platform_data; in bcmgenet_mii_register()
454 struct device_node *dn = pdev->dev.of_node; in bcmgenet_mii_register()
462 dev_err(&pdev->dev, "Invalid resource\n"); in bcmgenet_mii_register()
463 return -EINVAL; in bcmgenet_mii_register()
473 * and is 2 * 32-bits word long, 8 bytes total. in bcmgenet_mii_register()
475 res.start = pres->start + GENET_UMAC_OFF + UMAC_MDIO_CMD; in bcmgenet_mii_register()
482 id = pdev->id; in bcmgenet_mii_register()
486 return -ENOMEM; in bcmgenet_mii_register()
489 priv->mii_pdev = ppdev; in bcmgenet_mii_register()
490 ppdev->dev.parent = &pdev->dev; in bcmgenet_mii_register()
492 ppdev->dev.of_node = bcmgenet_mii_of_find_mdio(priv); in bcmgenet_mii_register()
518 struct device *kdev = &priv->pdev->dev; in bcmgenet_phy_interface_init()
526 priv->phy_interface = phy_mode; in bcmgenet_phy_interface_init()
529 * internal or not *before* we even try to probe the PHY driver in bcmgenet_phy_interface_init()
530 * over MDIO as we may have shut down the internal PHY for power in bcmgenet_phy_interface_init()
533 if (priv->phy_interface == PHY_INTERFACE_MODE_INTERNAL) in bcmgenet_phy_interface_init()
534 priv->internal_phy = true; in bcmgenet_phy_interface_init()
541 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_of_init()
546 priv->phy_dn = of_parse_phandle(dn, "phy-handle", 0); in bcmgenet_mii_of_init()
551 if (!priv->phy_dn && of_phy_is_fixed_link(dn)) { in bcmgenet_mii_of_init()
556 priv->phy_dn = of_node_get(dn); in bcmgenet_mii_of_init()
565 if (priv->phy_interface == PHY_INTERFACE_MODE_MOCA) { in bcmgenet_mii_of_init()
568 phydev->link = 0; in bcmgenet_mii_of_init()
569 put_device(&phydev->mdio.dev); in bcmgenet_mii_of_init()
578 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_pd_init()
579 struct bcmgenet_platform_data *pd = kdev->platform_data; in bcmgenet_mii_pd_init()
584 snprintf(mdio_bus_id, MII_BUS_ID_SIZE, "%s-%d", in bcmgenet_mii_pd_init()
585 UNIMAC_MDIO_DRV_NAME, priv->pdev->id); in bcmgenet_mii_pd_init()
587 if (pd->phy_interface != PHY_INTERFACE_MODE_MOCA && pd->mdio_enabled) { in bcmgenet_mii_pd_init()
589 mdio_bus_id, pd->phy_address); in bcmgenet_mii_pd_init()
592 * Internal or external PHY with MDIO access in bcmgenet_mii_pd_init()
594 phydev = phy_attach(priv->dev, phy_name, pd->phy_interface); in bcmgenet_mii_pd_init()
606 .speed = pd->phy_speed, in bcmgenet_mii_pd_init()
607 .duplex = pd->phy_duplex, in bcmgenet_mii_pd_init()
615 return -ENODEV; in bcmgenet_mii_pd_init()
619 phydev->link = 0; in bcmgenet_mii_pd_init()
623 priv->phy_interface = pd->phy_interface; in bcmgenet_mii_pd_init()
630 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_bus_init()
631 struct device_node *dn = kdev->of_node; in bcmgenet_mii_bus_init()
664 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_exit()
668 of_node_put(priv->phy_dn); in bcmgenet_mii_exit()
669 platform_device_unregister(priv->mii_pdev); in bcmgenet_mii_exit()