Commit 1676aba5 authored by Jon Mason's avatar Jon Mason Committed by David S. Miller

net: ethernet: bgmac: device tree phy enablement

Change the bgmac driver to allow for phy's defined by the device tree
Signed-off-by: default avatarJon Mason <jon.mason@broadcom.com>
Acked-by: default avatarRafał Miłecki <rafal@milecki.pl>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0086f094
...@@ -80,6 +80,24 @@ static void bcma_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, u32 mask, ...@@ -80,6 +80,24 @@ static void bcma_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, u32 mask,
bcma_maskset32(bgmac->bcma.cmn, offset, mask, set); bcma_maskset32(bgmac->bcma.cmn, offset, mask, set);
} }
static int bcma_phy_connect(struct bgmac *bgmac)
{
struct phy_device *phy_dev;
char bus_id[MII_BUS_ID_SIZE + 3];
/* Connect to the PHY */
snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id,
bgmac->phyaddr);
phy_dev = phy_connect(bgmac->net_dev, bus_id, bgmac_adjust_link,
PHY_INTERFACE_MODE_MII);
if (IS_ERR(phy_dev)) {
dev_err(bgmac->dev, "PHY connection failed\n");
return PTR_ERR(phy_dev);
}
return 0;
}
static const struct bcma_device_id bgmac_bcma_tbl[] = { static const struct bcma_device_id bgmac_bcma_tbl[] = {
BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT,
BCMA_ANY_REV, BCMA_ANY_CLASS), BCMA_ANY_REV, BCMA_ANY_CLASS),
...@@ -275,6 +293,10 @@ static int bgmac_probe(struct bcma_device *core) ...@@ -275,6 +293,10 @@ static int bgmac_probe(struct bcma_device *core)
bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset; bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset;
bgmac->get_bus_clock = bcma_bgmac_get_bus_clock; bgmac->get_bus_clock = bcma_bgmac_get_bus_clock;
bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32; bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32;
if (bgmac->mii_bus)
bgmac->phy_connect = bcma_phy_connect;
else
bgmac->phy_connect = bgmac_phy_connect_direct;
err = bgmac_enet_probe(bgmac); err = bgmac_enet_probe(bgmac);
if (err) if (err)
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/bcma/bcma.h> #include <linux/bcma/bcma.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h> #include <linux/of_net.h>
#include "bgmac.h" #include "bgmac.h"
...@@ -86,6 +87,20 @@ static void platform_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, ...@@ -86,6 +87,20 @@ static void platform_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset,
WARN_ON(1); WARN_ON(1);
} }
static int platform_phy_connect(struct bgmac *bgmac)
{
struct phy_device *phy_dev;
phy_dev = of_phy_get_and_connect(bgmac->net_dev, bgmac->dev->of_node,
bgmac_adjust_link);
if (!phy_dev) {
dev_err(bgmac->dev, "PHY connection failed\n");
return -ENODEV;
}
return 0;
}
static int bgmac_probe(struct platform_device *pdev) static int bgmac_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
...@@ -102,7 +117,6 @@ static int bgmac_probe(struct platform_device *pdev) ...@@ -102,7 +117,6 @@ static int bgmac_probe(struct platform_device *pdev)
/* Set the features of the 4707 family */ /* Set the features of the 4707 family */
bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
bgmac->feature_flags |= BGMAC_FEAT_NO_RESET; bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4; bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4;
bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP; bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP;
bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP; bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
...@@ -151,6 +165,12 @@ static int bgmac_probe(struct platform_device *pdev) ...@@ -151,6 +165,12 @@ static int bgmac_probe(struct platform_device *pdev)
bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset; bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
bgmac->get_bus_clock = platform_bgmac_get_bus_clock; bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32; bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32;
if (of_parse_phandle(np, "phy-handle", 0)) {
bgmac->phy_connect = platform_phy_connect;
} else {
bgmac->phy_connect = bgmac_phy_connect_direct;
bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
}
return bgmac_enet_probe(bgmac); return bgmac_enet_probe(bgmac);
} }
......
...@@ -1388,7 +1388,7 @@ static const struct ethtool_ops bgmac_ethtool_ops = { ...@@ -1388,7 +1388,7 @@ static const struct ethtool_ops bgmac_ethtool_ops = {
* MII * MII
**************************************************/ **************************************************/
static void bgmac_adjust_link(struct net_device *net_dev) void bgmac_adjust_link(struct net_device *net_dev)
{ {
struct bgmac *bgmac = netdev_priv(net_dev); struct bgmac *bgmac = netdev_priv(net_dev);
struct phy_device *phy_dev = net_dev->phydev; struct phy_device *phy_dev = net_dev->phydev;
...@@ -1411,8 +1411,9 @@ static void bgmac_adjust_link(struct net_device *net_dev) ...@@ -1411,8 +1411,9 @@ static void bgmac_adjust_link(struct net_device *net_dev)
phy_print_status(phy_dev); phy_print_status(phy_dev);
} }
} }
EXPORT_SYMBOL_GPL(bgmac_adjust_link);
static int bgmac_phy_connect_direct(struct bgmac *bgmac) int bgmac_phy_connect_direct(struct bgmac *bgmac)
{ {
struct fixed_phy_status fphy_status = { struct fixed_phy_status fphy_status = {
.link = 1, .link = 1,
...@@ -1437,24 +1438,7 @@ static int bgmac_phy_connect_direct(struct bgmac *bgmac) ...@@ -1437,24 +1438,7 @@ static int bgmac_phy_connect_direct(struct bgmac *bgmac)
return err; return err;
} }
EXPORT_SYMBOL_GPL(bgmac_phy_connect_direct);
static int bgmac_phy_connect(struct bgmac *bgmac)
{
struct phy_device *phy_dev;
char bus_id[MII_BUS_ID_SIZE + 3];
/* Connect to the PHY */
snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id,
bgmac->phyaddr);
phy_dev = phy_connect(bgmac->net_dev, bus_id, &bgmac_adjust_link,
PHY_INTERFACE_MODE_MII);
if (IS_ERR(phy_dev)) {
dev_err(bgmac->dev, "PHY connection failed\n");
return PTR_ERR(phy_dev);
}
return 0;
}
int bgmac_enet_probe(struct bgmac *info) int bgmac_enet_probe(struct bgmac *info)
{ {
...@@ -1507,9 +1491,6 @@ int bgmac_enet_probe(struct bgmac *info) ...@@ -1507,9 +1491,6 @@ int bgmac_enet_probe(struct bgmac *info)
netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT); netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT);
if (!bgmac->mii_bus)
err = bgmac_phy_connect_direct(bgmac);
else
err = bgmac_phy_connect(bgmac); err = bgmac_phy_connect(bgmac);
if (err) { if (err) {
dev_err(bgmac->dev, "Cannot connect to phy\n"); dev_err(bgmac->dev, "Cannot connect to phy\n");
......
...@@ -513,10 +513,13 @@ struct bgmac { ...@@ -513,10 +513,13 @@ struct bgmac {
u32 (*get_bus_clock)(struct bgmac *bgmac); u32 (*get_bus_clock)(struct bgmac *bgmac);
void (*cmn_maskset32)(struct bgmac *bgmac, u16 offset, u32 mask, void (*cmn_maskset32)(struct bgmac *bgmac, u16 offset, u32 mask,
u32 set); u32 set);
int (*phy_connect)(struct bgmac *bgmac);
}; };
int bgmac_enet_probe(struct bgmac *info); int bgmac_enet_probe(struct bgmac *info);
void bgmac_enet_remove(struct bgmac *bgmac); void bgmac_enet_remove(struct bgmac *bgmac);
void bgmac_adjust_link(struct net_device *net_dev);
int bgmac_phy_connect_direct(struct bgmac *bgmac);
struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr); struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
void bcma_mdio_mii_unregister(struct mii_bus *mii_bus); void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
...@@ -583,4 +586,9 @@ static inline void bgmac_set(struct bgmac *bgmac, u16 offset, u32 set) ...@@ -583,4 +586,9 @@ static inline void bgmac_set(struct bgmac *bgmac, u16 offset, u32 set)
{ {
bgmac_maskset(bgmac, offset, ~0, set); bgmac_maskset(bgmac, offset, ~0, set);
} }
static inline int bgmac_phy_connect(struct bgmac *bgmac)
{
return bgmac->phy_connect(bgmac);
}
#endif /* _BGMAC_H */ #endif /* _BGMAC_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment