Lines Matching +full:max +full:- +full:link +full:- +full:speed

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2014-2017 Broadcom
24 #include <linux/platform_data/mdio-bcm-unimac.h>
28 /* setup netdev link state when PHY link status change and
29 * update UMAC and RGMII block when link up
34 struct phy_device *phydev = dev->phydev; in bcmgenet_mii_setup()
38 if (priv->old_link != phydev->link) { in bcmgenet_mii_setup()
40 priv->old_link = phydev->link; in bcmgenet_mii_setup()
43 if (phydev->link) { in bcmgenet_mii_setup()
44 /* check speed/duplex/pause changes */ in bcmgenet_mii_setup()
45 if (priv->old_speed != phydev->speed) { in bcmgenet_mii_setup()
47 priv->old_speed = phydev->speed; in bcmgenet_mii_setup()
50 if (priv->old_duplex != phydev->duplex) { in bcmgenet_mii_setup()
52 priv->old_duplex = phydev->duplex; in bcmgenet_mii_setup()
55 if (priv->old_pause != phydev->pause) { in bcmgenet_mii_setup()
57 priv->old_pause = phydev->pause; in bcmgenet_mii_setup()
64 /* speed */ in bcmgenet_mii_setup()
65 if (phydev->speed == SPEED_1000) in bcmgenet_mii_setup()
67 else if (phydev->speed == SPEED_100) in bcmgenet_mii_setup()
74 if (phydev->duplex != DUPLEX_FULL) in bcmgenet_mii_setup()
78 if (!phydev->pause) in bcmgenet_mii_setup()
83 * link speed, duplex, and pause. The speed set in in bcmgenet_mii_setup()
84 * umac->cmd tell RGMII block which clock to use for in bcmgenet_mii_setup()
85 * transmit -- 25MHz(100Mbps) or 125MHz(1Gbps). in bcmgenet_mii_setup()
110 /* needed for MoCA fixed PHY to reflect correct link status */ in bcmgenet_mii_setup()
124 if (dev && dev->phydev && status) { in bcmgenet_fixed_phy_link_update()
127 status->link = !!(reg & MODE_LINK_STATUS); in bcmgenet_fixed_phy_link_update()
171 /* Speed settings are set in bcmgenet_mii_setup() */ in bcmgenet_moca_phy_setup()
177 if (priv->hw_params->flags & GENET_HAS_MOCA_LINK_DET) in bcmgenet_moca_phy_setup()
178 fixed_phy_set_link_update(priv->dev->phydev, in bcmgenet_moca_phy_setup()
185 struct phy_device *phydev = dev->phydev; in bcmgenet_mii_config()
186 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_config()
192 switch (priv->phy_interface) { in bcmgenet_mii_config()
197 /* Irrespective of the actually configured PHY speed (100 or in bcmgenet_mii_config()
221 /* of_mdiobus_register took care of reading the 'max-speed' in bcmgenet_mii_config()
227 dev->phydev->supported)) in bcmgenet_mii_config()
235 * (requires PCB or receiver-side delay) in bcmgenet_mii_config()
255 dev_err(kdev, "unknown phy mode: %d\n", priv->phy_interface); in bcmgenet_mii_config()
256 return -EINVAL; in bcmgenet_mii_config()
261 priv->ext_phy = !priv->internal_phy && in bcmgenet_mii_config()
262 (priv->phy_interface != PHY_INTERFACE_MODE_MOCA); in bcmgenet_mii_config()
267 if (priv->ext_phy) { in bcmgenet_mii_config()
287 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_probe()
288 struct device_node *dn = kdev->of_node; in bcmgenet_mii_probe()
294 if (priv->internal_phy) in bcmgenet_mii_probe()
295 phy_flags = priv->gphy_rev; in bcmgenet_mii_probe()
297 /* Initialize link state variables that bcmgenet_mii_setup() uses */ in bcmgenet_mii_probe()
298 priv->old_link = -1; in bcmgenet_mii_probe()
299 priv->old_speed = -1; in bcmgenet_mii_probe()
300 priv->old_duplex = -1; in bcmgenet_mii_probe()
301 priv->old_pause = -1; in bcmgenet_mii_probe()
304 phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup, in bcmgenet_mii_probe()
305 phy_flags, priv->phy_interface); in bcmgenet_mii_probe()
308 return -ENODEV; in bcmgenet_mii_probe()
315 snprintf(mdio_bus_id, MII_BUS_ID_SIZE, "%s-%d", in bcmgenet_mii_probe()
316 UNIMAC_MDIO_DRV_NAME, priv->pdev->id); in bcmgenet_mii_probe()
321 return -ENODEV; in bcmgenet_mii_probe()
324 put_device(&unimacbus->dev); in bcmgenet_mii_probe()
327 return -ENODEV; in bcmgenet_mii_probe()
330 phydev = dev->phydev; in bcmgenet_mii_probe()
332 phydev->dev_flags = phy_flags; in bcmgenet_mii_probe()
335 priv->phy_interface); in bcmgenet_mii_probe()
338 return -ENODEV; in bcmgenet_mii_probe()
343 * reading the 'max-speed' property determines the maximum supported in bcmgenet_mii_probe()
344 * PHY speed which is needed for bcmgenet_mii_config() to configure in bcmgenet_mii_probe()
349 phy_disconnect(dev->phydev); in bcmgenet_mii_probe()
353 linkmode_copy(phydev->advertising, phydev->supported); in bcmgenet_mii_probe()
355 /* The internal PHY has its link interrupts routed to the in bcmgenet_mii_probe()
357 * that prevents the signaling of link UP interrupts when in bcmgenet_mii_probe()
358 * the link operates at 10Mbps, so fallback to polling for in bcmgenet_mii_probe()
361 if (priv->internal_phy && !GENET_IS_V5(priv)) in bcmgenet_mii_probe()
362 dev->phydev->irq = PHY_IGNORE_INTERRUPT; in bcmgenet_mii_probe()
369 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_of_find_mdio()
370 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_of_find_mdio()
373 compat = kasprintf(GFP_KERNEL, "brcm,genet-mdio-v%d", priv->version); in bcmgenet_mii_of_find_mdio()
377 priv->mdio_dn = of_get_compatible_child(dn, compat); in bcmgenet_mii_of_find_mdio()
379 if (!priv->mdio_dn) { in bcmgenet_mii_of_find_mdio()
384 return priv->mdio_dn; in bcmgenet_mii_of_find_mdio()
390 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_pdata_init()
391 struct bcmgenet_platform_data *pd = kdev->platform_data; in bcmgenet_mii_pdata_init()
393 if (pd->phy_interface != PHY_INTERFACE_MODE_MOCA && pd->mdio_enabled) { in bcmgenet_mii_pdata_init()
397 if (pd->phy_address >= 0 && pd->phy_address < PHY_MAX_ADDR) in bcmgenet_mii_pdata_init()
398 ppd->phy_mask = 1 << pd->phy_address; in bcmgenet_mii_pdata_init()
400 ppd->phy_mask = 0; in bcmgenet_mii_pdata_init()
408 wait_event_timeout(priv->wq, in bcmgenet_mii_wait()
417 struct platform_device *pdev = priv->pdev; in bcmgenet_mii_register()
418 struct bcmgenet_platform_data *pdata = pdev->dev.platform_data; in bcmgenet_mii_register()
419 struct device_node *dn = pdev->dev.of_node; in bcmgenet_mii_register()
434 * and is 2 * 32-bits word long, 8 bytes total. in bcmgenet_mii_register()
436 res.start = pres->start + GENET_UMAC_OFF + UMAC_MDIO_CMD; in bcmgenet_mii_register()
443 id = pdev->id; in bcmgenet_mii_register()
447 return -ENOMEM; in bcmgenet_mii_register()
450 priv->mii_pdev = ppdev; in bcmgenet_mii_register()
451 ppdev->dev.parent = &pdev->dev; in bcmgenet_mii_register()
453 ppdev->dev.of_node = bcmgenet_mii_of_find_mdio(priv); in bcmgenet_mii_register()
479 struct device *kdev = &priv->pdev->dev; in bcmgenet_phy_interface_init()
487 priv->phy_interface = phy_mode; in bcmgenet_phy_interface_init()
494 if (priv->phy_interface == PHY_INTERFACE_MODE_INTERNAL) in bcmgenet_phy_interface_init()
495 priv->internal_phy = true; in bcmgenet_phy_interface_init()
502 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_of_init()
507 priv->phy_dn = of_parse_phandle(dn, "phy-handle", 0); in bcmgenet_mii_of_init()
512 if (!priv->phy_dn && of_phy_is_fixed_link(dn)) { in bcmgenet_mii_of_init()
517 priv->phy_dn = of_node_get(dn); in bcmgenet_mii_of_init()
520 /* Get the link mode */ in bcmgenet_mii_of_init()
525 /* Make sure we initialize MoCA PHYs with a link down */ in bcmgenet_mii_of_init()
526 if (priv->phy_interface == PHY_INTERFACE_MODE_MOCA) { in bcmgenet_mii_of_init()
529 phydev->link = 0; in bcmgenet_mii_of_init()
530 put_device(&phydev->mdio.dev); in bcmgenet_mii_of_init()
539 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_pd_init()
540 struct bcmgenet_platform_data *pd = kdev->platform_data; in bcmgenet_mii_pd_init()
545 snprintf(mdio_bus_id, MII_BUS_ID_SIZE, "%s-%d", in bcmgenet_mii_pd_init()
546 UNIMAC_MDIO_DRV_NAME, priv->pdev->id); in bcmgenet_mii_pd_init()
548 if (pd->phy_interface != PHY_INTERFACE_MODE_MOCA && pd->mdio_enabled) { in bcmgenet_mii_pd_init()
550 mdio_bus_id, pd->phy_address); in bcmgenet_mii_pd_init()
555 phydev = phy_attach(priv->dev, phy_name, pd->phy_interface); in bcmgenet_mii_pd_init()
558 return -ENODEV; in bcmgenet_mii_pd_init()
563 * Use fixed PHY to represent the link layer. in bcmgenet_mii_pd_init()
566 .link = 1, in bcmgenet_mii_pd_init()
567 .speed = pd->phy_speed, in bcmgenet_mii_pd_init()
568 .duplex = pd->phy_duplex, in bcmgenet_mii_pd_init()
576 return -ENODEV; in bcmgenet_mii_pd_init()
579 /* Make sure we initialize MoCA PHYs with a link down */ in bcmgenet_mii_pd_init()
580 phydev->link = 0; in bcmgenet_mii_pd_init()
584 priv->phy_interface = pd->phy_interface; in bcmgenet_mii_pd_init()
591 struct device *kdev = &priv->pdev->dev; in bcmgenet_mii_bus_init()
592 struct device_node *dn = kdev->of_node; in bcmgenet_mii_bus_init()
625 struct device_node *dn = priv->pdev->dev.of_node; in bcmgenet_mii_exit()
629 of_node_put(priv->phy_dn); in bcmgenet_mii_exit()
630 platform_device_unregister(priv->mii_pdev); in bcmgenet_mii_exit()