Lines Matching +full:tx +full:- +full:use +full:- +full:rgmii +full:- +full:clk
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2014-2024 Broadcom
24 #include <linux/platform_data/mdio-bcm-unimac.h>
31 struct phy_device *phydev = dev->phydev; in bcmgenet_mac_config()
36 if (phydev->speed == SPEED_1000) in bcmgenet_mac_config()
38 else if (phydev->speed == SPEED_100) in bcmgenet_mac_config()
45 if (phydev->duplex != DUPLEX_FULL) { in bcmgenet_mac_config()
50 if (priv->autoneg_pause) { in bcmgenet_mac_config()
53 if (phydev->autoneg) in bcmgenet_mac_config()
63 if (!priv->rx_pause) in bcmgenet_mac_config()
65 if (!priv->tx_pause) in bcmgenet_mac_config()
69 /* Program UMAC and RGMII block based on established in bcmgenet_mac_config()
71 * umac->cmd tell RGMII block which clock to use for in bcmgenet_mac_config()
72 * transmit -- 25MHz(100Mbps) or 125MHz(1Gbps). in bcmgenet_mac_config()
79 spin_lock_bh(&priv->reg_lock); in bcmgenet_mac_config()
92 spin_unlock_bh(&priv->reg_lock); in bcmgenet_mac_config()
96 priv->eee.eee_enabled && active, in bcmgenet_mac_config()
97 priv->eee.tx_lpi_enabled); in bcmgenet_mac_config()
101 * update UMAC and RGMII block when link up
106 struct phy_device *phydev = dev->phydev; in bcmgenet_mii_setup()
109 if (phydev->link) { in bcmgenet_mii_setup()
127 if (dev && dev->phydev && status) { in bcmgenet_fixed_phy_link_update()
130 status->link = !!(reg & MODE_LINK_STATUS); in bcmgenet_fixed_phy_link_update()
136 void bcmgenet_phy_pause_set(struct net_device *dev, bool rx, bool tx) in bcmgenet_phy_pause_set() argument
138 struct phy_device *phydev = dev->phydev; in bcmgenet_phy_pause_set()
140 linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->advertising, rx); in bcmgenet_phy_pause_set()
141 linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->advertising, in bcmgenet_phy_pause_set()
142 rx | tx); in bcmgenet_phy_pause_set()
145 mutex_lock(&phydev->lock); in bcmgenet_phy_pause_set()
146 if (phydev->link) in bcmgenet_phy_pause_set()
148 mutex_unlock(&phydev->lock); in bcmgenet_phy_pause_set()
157 if (GENET_IS_V4(priv) || priv->ephy_16nm) { in bcmgenet_phy_power_set()
187 if (priv->hw_params->flags & GENET_HAS_MOCA_LINK_DET) in bcmgenet_moca_phy_setup()
188 fixed_phy_set_link_update(priv->dev->phydev, in bcmgenet_moca_phy_setup()
195 struct phy_device *phydev = dev->phydev; in bcmgenet_mii_config()
196 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_config()
202 switch (priv->phy_interface) { in bcmgenet_mii_config()
233 /* of_mdiobus_register took care of reading the 'max-speed' in bcmgenet_mii_config()
235 * capabilities, use that knowledge to also configure the in bcmgenet_mii_config()
239 dev->phydev->supported)) in bcmgenet_mii_config()
247 * (requires PCB or receiver-side delay) in bcmgenet_mii_config()
251 phy_name = "external RGMII (no delay)"; in bcmgenet_mii_config()
258 phy_name = "external RGMII (TX delay)"; in bcmgenet_mii_config()
263 phy_name = "external RGMII (RX delay)"; in bcmgenet_mii_config()
267 dev_err(kdev, "unknown phy mode: %d\n", priv->phy_interface); in bcmgenet_mii_config()
268 return -EINVAL; in bcmgenet_mii_config()
273 priv->ext_phy = !priv->internal_phy && in bcmgenet_mii_config()
274 (priv->phy_interface != PHY_INTERFACE_MODE_MOCA); in bcmgenet_mii_config()
276 /* This is an external PHY (xMII), so we need to enable the RGMII in bcmgenet_mii_config()
278 * Out-of-band disable since we do not need it. in bcmgenet_mii_config()
280 mutex_lock(&phydev->lock); in bcmgenet_mii_config()
283 if (priv->ext_phy) { in bcmgenet_mii_config()
292 mutex_unlock(&phydev->lock); in bcmgenet_mii_config()
303 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_probe()
304 struct device_node *dn = kdev->of_node; in bcmgenet_mii_probe()
305 phy_interface_t phy_iface = priv->phy_interface; in bcmgenet_mii_probe()
313 if (priv->internal_phy) in bcmgenet_mii_probe()
314 phy_flags = priv->gphy_rev; in bcmgenet_mii_probe()
320 * When the Generic PHY driver is in use either the PHY has been in bcmgenet_mii_probe()
324 * Now when a dedicated PHY driver is in use, we need to reverse the in bcmgenet_mii_probe()
334 * Note that internal PHY, MoCA and fixed-link configurations are not in bcmgenet_mii_probe()
335 * affected because they use different phy_interface_t values or the in bcmgenet_mii_probe()
338 switch (priv->phy_interface) { in bcmgenet_mii_probe()
350 phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup, in bcmgenet_mii_probe()
354 return -ENODEV; in bcmgenet_mii_probe()
361 snprintf(mdio_bus_id, MII_BUS_ID_SIZE, "%s-%d", in bcmgenet_mii_probe()
362 UNIMAC_MDIO_DRV_NAME, priv->pdev->id); in bcmgenet_mii_probe()
367 return -ENODEV; in bcmgenet_mii_probe()
370 put_device(&unimacbus->dev); in bcmgenet_mii_probe()
373 return -ENODEV; in bcmgenet_mii_probe()
376 phydev = dev->phydev; in bcmgenet_mii_probe()
378 phydev->dev_flags = phy_flags; in bcmgenet_mii_probe()
384 return -ENODEV; in bcmgenet_mii_probe()
389 * reading the 'max-speed' property determines the maximum supported in bcmgenet_mii_probe()
395 phy_disconnect(dev->phydev); in bcmgenet_mii_probe()
405 if (priv->internal_phy && !GENET_IS_V5(priv)) in bcmgenet_mii_probe()
406 dev->phydev->irq = PHY_MAC_INTERRUPT; in bcmgenet_mii_probe()
409 dev->phydev->mac_managed_pm = true; in bcmgenet_mii_probe()
416 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_of_find_mdio()
417 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_of_find_mdio()
420 compat = kasprintf(GFP_KERNEL, "brcm,genet-mdio-v%d", priv->version); in bcmgenet_mii_of_find_mdio()
424 priv->mdio_dn = of_get_compatible_child(dn, compat); in bcmgenet_mii_of_find_mdio()
426 if (!priv->mdio_dn) { in bcmgenet_mii_of_find_mdio()
431 return priv->mdio_dn; in bcmgenet_mii_of_find_mdio()
437 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_pdata_init()
438 struct bcmgenet_platform_data *pd = kdev->platform_data; in bcmgenet_mii_pdata_init()
440 if (pd->phy_interface != PHY_INTERFACE_MODE_MOCA && pd->mdio_enabled) { in bcmgenet_mii_pdata_init()
444 if (pd->phy_address >= 0 && pd->phy_address < PHY_MAX_ADDR) in bcmgenet_mii_pdata_init()
445 ppd->phy_mask = 1 << pd->phy_address; in bcmgenet_mii_pdata_init()
447 ppd->phy_mask = 0; in bcmgenet_mii_pdata_init()
455 wait_event_timeout(priv->wq, in bcmgenet_mii_wait()
464 struct platform_device *pdev = priv->pdev; in bcmgenet_mii_register()
465 struct bcmgenet_platform_data *pdata = pdev->dev.platform_data; in bcmgenet_mii_register()
466 struct device_node *dn = pdev->dev.of_node; in bcmgenet_mii_register()
474 dev_err(&pdev->dev, "Invalid resource\n"); in bcmgenet_mii_register()
475 return -EINVAL; in bcmgenet_mii_register()
486 ppd.clk = priv->clk; in bcmgenet_mii_register()
489 * and is 2 * 32-bits word long, 8 bytes total. in bcmgenet_mii_register()
491 res.start = pres->start + GENET_UMAC_OFF + UMAC_MDIO_CMD; in bcmgenet_mii_register()
498 id = pdev->id; in bcmgenet_mii_register()
502 return -ENOMEM; in bcmgenet_mii_register()
505 priv->mii_pdev = ppdev; in bcmgenet_mii_register()
506 ppdev->dev.parent = &pdev->dev; in bcmgenet_mii_register()
508 ppdev->dev.of_node = bcmgenet_mii_of_find_mdio(priv); in bcmgenet_mii_register()
534 struct device *kdev = &priv->pdev->dev; in bcmgenet_phy_interface_init()
542 priv->phy_interface = phy_mode; in bcmgenet_phy_interface_init()
549 if (priv->phy_interface == PHY_INTERFACE_MODE_INTERNAL) in bcmgenet_phy_interface_init()
550 priv->internal_phy = true; in bcmgenet_phy_interface_init()
557 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_of_init()
562 priv->phy_dn = of_parse_phandle(dn, "phy-handle", 0); in bcmgenet_mii_of_init()
567 if (!priv->phy_dn && of_phy_is_fixed_link(dn)) { in bcmgenet_mii_of_init()
572 priv->phy_dn = of_node_get(dn); in bcmgenet_mii_of_init()
581 if (priv->phy_interface == PHY_INTERFACE_MODE_MOCA) { in bcmgenet_mii_of_init()
584 phydev->link = 0; in bcmgenet_mii_of_init()
585 put_device(&phydev->mdio.dev); in bcmgenet_mii_of_init()
594 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_pd_init()
595 struct bcmgenet_platform_data *pd = kdev->platform_data; in bcmgenet_mii_pd_init()
600 snprintf(mdio_bus_id, MII_BUS_ID_SIZE, "%s-%d", in bcmgenet_mii_pd_init()
601 UNIMAC_MDIO_DRV_NAME, priv->pdev->id); in bcmgenet_mii_pd_init()
603 if (pd->phy_interface != PHY_INTERFACE_MODE_MOCA && pd->mdio_enabled) { in bcmgenet_mii_pd_init()
605 mdio_bus_id, pd->phy_address); in bcmgenet_mii_pd_init()
610 phydev = phy_attach(priv->dev, phy_name, pd->phy_interface); in bcmgenet_mii_pd_init()
618 * Use fixed PHY to represent the link layer. in bcmgenet_mii_pd_init()
622 .speed = pd->phy_speed, in bcmgenet_mii_pd_init()
623 .duplex = pd->phy_duplex, in bcmgenet_mii_pd_init()
635 phydev->link = 0; in bcmgenet_mii_pd_init()
639 priv->phy_interface = pd->phy_interface; in bcmgenet_mii_pd_init()
646 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_bus_init()
647 struct device_node *dn = kdev->of_node; in bcmgenet_mii_bus_init()
680 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_exit()
684 of_node_put(priv->phy_dn); in bcmgenet_mii_exit()
685 platform_device_unregister(priv->mii_pdev); in bcmgenet_mii_exit()