Skip to content

Commit

Permalink
Merge branch 'ns2-amac'
Browse files Browse the repository at this point in the history
Jon Mason says:

====================
add NS2 support to bgmac

Changes in v6:
* Use a common bgmac_phy_connect_direct (per Rafal Milecki)
* Rebased on latest net-next
* Added Reviewed-by to the relevant patches

Changes in v5:
* Change a pr_err to netdev_err (per Scott Branden)
* Reword the lane swap binding documentation (per Andrew Lunn)

Changes in v4:
* Actually send out the lane swap binding doc patch (Per Scott Branden)
* Remove unused #define (Per Andrew Lunn)

Changes in v3:
* Clean-up the bgmac DT binding doc (per Rob Herring)
* Document the lane swap binding and make it generic (Per Andrew Lunn)

Changes in v2:
* Remove the PHY power-on (per Andrew Lunn)
* Misc PHY clean-ups regarding comments and #defines (per Andrew Lunn)
  This results on none of the original PHY code from Vikas being
  present.  So, I'm removing him as an author and giving him
  "Inspired-by" credit.
* Move PHY lane swapping to PHY driver (per Andrew Lunn and Florian
  Fainelli)
* Remove bgmac sleep (per Florian Fainelli)
* Re-add bgmac chip reset (per Florian Fainelli and Ray Jui)
* Rebased on latest net-next
* Added patch for bcm54xx_auxctl_read, which is used in the BCM54810
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Nov 7, 2016
2 parents 94edc86 + dddc3c9 commit 0ca6e00
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 32 deletions.
16 changes: 11 additions & 5 deletions Documentation/devicetree/bindings/net/brcm,amac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ Broadcom AMAC Ethernet Controller Device Tree Bindings
-------------------------------------------------------------

Required properties:
- compatible: "brcm,amac" or "brcm,nsp-amac"
- reg: Address and length of the GMAC registers,
Address and length of the GMAC IDM registers
- reg-names: Names of the registers. Must have both "amac_base" and
"idm_base"
- compatible: "brcm,amac"
"brcm,nsp-amac"
"brcm,ns2-amac"
- reg: Address and length of the register set for the device. It
contains the information of registers in the same order as
described by reg-names
- reg-names: Names of the registers.
"amac_base": Address and length of the GMAC registers
"idm_base": Address and length of the GMAC IDM registers
"nicpm_base": Address and length of the NIC Port Manager
registers (required for Northstar2)
- interrupts: Interrupt number

Optional properties:
Expand Down
4 changes: 4 additions & 0 deletions Documentation/devicetree/bindings/net/phy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Optional Properties:
- broken-turn-around: If set, indicates the PHY device does not correctly
release the turn around line low at the end of a MDIO transaction.

- enet-phy-lane-swap: If set, indicates the PHY will swap the TX/RX lanes to
compensate for the board being designed with the lanes swapped.


Example:

ethernet-phy@0 {
Expand Down
5 changes: 5 additions & 0 deletions arch/arm64/boot/dts/broadcom/ns2-svk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
};
};

&enet {
status = "ok";
};

&pci_phy0 {
status = "ok";
};
Expand Down Expand Up @@ -174,6 +178,7 @@
&mdio_mux_iproc {
mdio@10 {
gphy0: eth-phy@10 {
enet-phy-lane-swap;
reg = <0x10>;
};
};
Expand Down
12 changes: 12 additions & 0 deletions arch/arm64/boot/dts/broadcom/ns2.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@

#include "ns2-clock.dtsi"

enet: ethernet@61000000 {
compatible = "brcm,ns2-amac";
reg = <0x61000000 0x1000>,
<0x61090000 0x1000>,
<0x61030000 0x100>;
reg-names = "amac_base", "idm_base", "nicpm_base";
interrupts = <GIC_SPI 341 IRQ_TYPE_LEVEL_HIGH>;
phy-handle = <&gphy0>;
phy-mode = "rgmii";
status = "disabled";
};

dma0: dma@61360000 {
compatible = "arm,pl330", "arm,primecell";
reg = <0x61360000 0x1000>;
Expand Down
22 changes: 22 additions & 0 deletions drivers/net/ethernet/broadcom/bgmac-bcma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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[] = {
BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT,
BCMA_ANY_REV, BCMA_ANY_CLASS),
Expand Down Expand Up @@ -275,6 +293,10 @@ static int bgmac_probe(struct bcma_device *core)
bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset;
bgmac->get_bus_clock = bcma_bgmac_get_bus_clock;
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);
if (err)
Expand Down
74 changes: 73 additions & 1 deletion drivers/net/ethernet/broadcom/bgmac-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/bcma/bcma.h>
#include <linux/brcmphy.h>
#include <linux/etherdevice.h>
#include <linux/of_address.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
#include "bgmac.h"

#define NICPM_IOMUX_CTRL 0x00000008

#define NICPM_IOMUX_CTRL_INIT_VAL 0x3196e000
#define NICPM_IOMUX_CTRL_SPD_SHIFT 10
#define NICPM_IOMUX_CTRL_SPD_10M 0
#define NICPM_IOMUX_CTRL_SPD_100M 1
#define NICPM_IOMUX_CTRL_SPD_1000M 2

static u32 platform_bgmac_read(struct bgmac *bgmac, u16 offset)
{
return readl(bgmac->plat.base + offset);
Expand Down Expand Up @@ -86,6 +96,54 @@ static void platform_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset,
WARN_ON(1);
}

static void bgmac_nicpm_speed_set(struct net_device *net_dev)
{
struct bgmac *bgmac = netdev_priv(net_dev);
u32 val;

if (!bgmac->plat.nicpm_base)
return;

val = NICPM_IOMUX_CTRL_INIT_VAL;
switch (bgmac->net_dev->phydev->speed) {
default:
netdev_err(net_dev, "Unsupported speed. Defaulting to 1000Mb\n");
case SPEED_1000:
val |= NICPM_IOMUX_CTRL_SPD_1000M << NICPM_IOMUX_CTRL_SPD_SHIFT;
break;
case SPEED_100:
val |= NICPM_IOMUX_CTRL_SPD_100M << NICPM_IOMUX_CTRL_SPD_SHIFT;
break;
case SPEED_10:
val |= NICPM_IOMUX_CTRL_SPD_10M << NICPM_IOMUX_CTRL_SPD_SHIFT;
break;
}

writel(val, bgmac->plat.nicpm_base + NICPM_IOMUX_CTRL);

bgmac_adjust_link(bgmac->net_dev);
}

static int platform_phy_connect(struct bgmac *bgmac)
{
struct phy_device *phy_dev;

if (bgmac->plat.nicpm_base)
phy_dev = of_phy_get_and_connect(bgmac->net_dev,
bgmac->dev->of_node,
bgmac_nicpm_speed_set);
else
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)
{
struct device_node *np = pdev->dev.of_node;
Expand All @@ -102,7 +160,6 @@ static int bgmac_probe(struct platform_device *pdev)
/* Set the features of the 4707 family */
bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
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_TX_MASK_SETUP;
bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
Expand Down Expand Up @@ -142,6 +199,14 @@ static int bgmac_probe(struct platform_device *pdev)
if (IS_ERR(bgmac->plat.idm_base))
return PTR_ERR(bgmac->plat.idm_base);

regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nicpm_base");
if (regs) {
bgmac->plat.nicpm_base = devm_ioremap_resource(&pdev->dev,
regs);
if (IS_ERR(bgmac->plat.nicpm_base))
return PTR_ERR(bgmac->plat.nicpm_base);
}

bgmac->read = platform_bgmac_read;
bgmac->write = platform_bgmac_write;
bgmac->idm_read = platform_bgmac_idm_read;
Expand All @@ -151,6 +216,12 @@ static int bgmac_probe(struct platform_device *pdev)
bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
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);
}
Expand All @@ -167,6 +238,7 @@ static int bgmac_remove(struct platform_device *pdev)
static const struct of_device_id bgmac_of_enet_match[] = {
{.compatible = "brcm,amac",},
{.compatible = "brcm,nsp-amac",},
{.compatible = "brcm,ns2-amac",},
{},
};

Expand Down
32 changes: 8 additions & 24 deletions drivers/net/ethernet/broadcom/bgmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,9 @@ static void bgmac_enable(struct bgmac *bgmac)
/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipinit */
static void bgmac_chip_init(struct bgmac *bgmac)
{
/* Clear any erroneously pending interrupts */
bgmac_write(bgmac, BGMAC_INT_STATUS, ~0);

/* 1 interrupt per received frame */
bgmac_write(bgmac, BGMAC_INT_RECV_LAZY, 1 << BGMAC_IRL_FC_SHIFT);

Expand Down Expand Up @@ -1388,7 +1391,7 @@ static const struct ethtool_ops bgmac_ethtool_ops = {
* 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 phy_device *phy_dev = net_dev->phydev;
Expand All @@ -1411,8 +1414,9 @@ static void bgmac_adjust_link(struct net_device *net_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 = {
.link = 1,
Expand All @@ -1437,24 +1441,7 @@ static int bgmac_phy_connect_direct(struct bgmac *bgmac)

return err;
}

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;
}
EXPORT_SYMBOL_GPL(bgmac_phy_connect_direct);

int bgmac_enet_probe(struct bgmac *info)
{
Expand Down Expand Up @@ -1507,10 +1494,7 @@ int bgmac_enet_probe(struct bgmac *info)

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) {
dev_err(bgmac->dev, "Cannot connect to phy\n");
goto err_dma_free;
Expand Down
9 changes: 9 additions & 0 deletions drivers/net/ethernet/broadcom/bgmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ struct bgmac {
struct {
void *base;
void *idm_base;
void *nicpm_base;
} plat;
struct {
struct bcma_device *core;
Expand Down Expand Up @@ -513,10 +514,13 @@ struct bgmac {
u32 (*get_bus_clock)(struct bgmac *bgmac);
void (*cmn_maskset32)(struct bgmac *bgmac, u16 offset, u32 mask,
u32 set);
int (*phy_connect)(struct bgmac *bgmac);
};

int bgmac_enet_probe(struct bgmac *info);
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);
void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
Expand Down Expand Up @@ -583,4 +587,9 @@ static inline void bgmac_set(struct bgmac *bgmac, u16 offset, u32 set)
{
bgmac_maskset(bgmac, offset, ~0, set);
}

static inline int bgmac_phy_connect(struct bgmac *bgmac)
{
return bgmac->phy_connect(bgmac);
}
#endif /* _BGMAC_H */
2 changes: 1 addition & 1 deletion drivers/net/phy/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ config BROADCOM_PHY
select BCM_NET_PHYLIB
---help---
Currently supports the BCM5411, BCM5421, BCM5461, BCM54616S, BCM5464,
BCM5481 and BCM5482 PHYs.
BCM5481, BCM54810 and BCM5482 PHYs.

config CICADA_PHY
tristate "Cicada PHYs"
Expand Down
Loading

0 comments on commit 0ca6e00

Please sign in to comment.