Skip to content

Commit 0ca6e00

Browse files
committed
Merge branch 'ns2-amac'
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 <[email protected]>
2 parents 94edc86 + dddc3c9 commit 0ca6e00

File tree

11 files changed

+222
-32
lines changed

11 files changed

+222
-32
lines changed

Documentation/devicetree/bindings/net/brcm,amac.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ Broadcom AMAC Ethernet Controller Device Tree Bindings
22
-------------------------------------------------------------
33

44
Required properties:
5-
- compatible: "brcm,amac" or "brcm,nsp-amac"
6-
- reg: Address and length of the GMAC registers,
7-
Address and length of the GMAC IDM registers
8-
- reg-names: Names of the registers. Must have both "amac_base" and
9-
"idm_base"
5+
- compatible: "brcm,amac"
6+
"brcm,nsp-amac"
7+
"brcm,ns2-amac"
8+
- reg: Address and length of the register set for the device. It
9+
contains the information of registers in the same order as
10+
described by reg-names
11+
- reg-names: Names of the registers.
12+
"amac_base": Address and length of the GMAC registers
13+
"idm_base": Address and length of the GMAC IDM registers
14+
"nicpm_base": Address and length of the NIC Port Manager
15+
registers (required for Northstar2)
1016
- interrupts: Interrupt number
1117

1218
Optional properties:

Documentation/devicetree/bindings/net/phy.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Optional Properties:
3535
- broken-turn-around: If set, indicates the PHY device does not correctly
3636
release the turn around line low at the end of a MDIO transaction.
3737

38+
- enet-phy-lane-swap: If set, indicates the PHY will swap the TX/RX lanes to
39+
compensate for the board being designed with the lanes swapped.
40+
41+
3842
Example:
3943

4044
ethernet-phy@0 {

arch/arm64/boot/dts/broadcom/ns2-svk.dts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
};
5757
};
5858

59+
&enet {
60+
status = "ok";
61+
};
62+
5963
&pci_phy0 {
6064
status = "ok";
6165
};
@@ -174,6 +178,7 @@
174178
&mdio_mux_iproc {
175179
mdio@10 {
176180
gphy0: eth-phy@10 {
181+
enet-phy-lane-swap;
177182
reg = <0x10>;
178183
};
179184
};

arch/arm64/boot/dts/broadcom/ns2.dtsi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@
191191

192192
#include "ns2-clock.dtsi"
193193

194+
enet: ethernet@61000000 {
195+
compatible = "brcm,ns2-amac";
196+
reg = <0x61000000 0x1000>,
197+
<0x61090000 0x1000>,
198+
<0x61030000 0x100>;
199+
reg-names = "amac_base", "idm_base", "nicpm_base";
200+
interrupts = <GIC_SPI 341 IRQ_TYPE_LEVEL_HIGH>;
201+
phy-handle = <&gphy0>;
202+
phy-mode = "rgmii";
203+
status = "disabled";
204+
};
205+
194206
dma0: dma@61360000 {
195207
compatible = "arm,pl330", "arm,primecell";
196208
reg = <0x61360000 0x1000>;

drivers/net/ethernet/broadcom/bgmac-bcma.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ static void bcma_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, u32 mask,
8080
bcma_maskset32(bgmac->bcma.cmn, offset, mask, set);
8181
}
8282

83+
static int bcma_phy_connect(struct bgmac *bgmac)
84+
{
85+
struct phy_device *phy_dev;
86+
char bus_id[MII_BUS_ID_SIZE + 3];
87+
88+
/* Connect to the PHY */
89+
snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id,
90+
bgmac->phyaddr);
91+
phy_dev = phy_connect(bgmac->net_dev, bus_id, bgmac_adjust_link,
92+
PHY_INTERFACE_MODE_MII);
93+
if (IS_ERR(phy_dev)) {
94+
dev_err(bgmac->dev, "PHY connection failed\n");
95+
return PTR_ERR(phy_dev);
96+
}
97+
98+
return 0;
99+
}
100+
83101
static const struct bcma_device_id bgmac_bcma_tbl[] = {
84102
BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT,
85103
BCMA_ANY_REV, BCMA_ANY_CLASS),
@@ -275,6 +293,10 @@ static int bgmac_probe(struct bcma_device *core)
275293
bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset;
276294
bgmac->get_bus_clock = bcma_bgmac_get_bus_clock;
277295
bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32;
296+
if (bgmac->mii_bus)
297+
bgmac->phy_connect = bcma_phy_connect;
298+
else
299+
bgmac->phy_connect = bgmac_phy_connect_direct;
278300

279301
err = bgmac_enet_probe(bgmac);
280302
if (err)

drivers/net/ethernet/broadcom/bgmac-platform.c

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@
1414
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1515

1616
#include <linux/bcma/bcma.h>
17+
#include <linux/brcmphy.h>
1718
#include <linux/etherdevice.h>
1819
#include <linux/of_address.h>
20+
#include <linux/of_mdio.h>
1921
#include <linux/of_net.h>
2022
#include "bgmac.h"
2123

24+
#define NICPM_IOMUX_CTRL 0x00000008
25+
26+
#define NICPM_IOMUX_CTRL_INIT_VAL 0x3196e000
27+
#define NICPM_IOMUX_CTRL_SPD_SHIFT 10
28+
#define NICPM_IOMUX_CTRL_SPD_10M 0
29+
#define NICPM_IOMUX_CTRL_SPD_100M 1
30+
#define NICPM_IOMUX_CTRL_SPD_1000M 2
31+
2232
static u32 platform_bgmac_read(struct bgmac *bgmac, u16 offset)
2333
{
2434
return readl(bgmac->plat.base + offset);
@@ -86,6 +96,54 @@ static void platform_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset,
8696
WARN_ON(1);
8797
}
8898

99+
static void bgmac_nicpm_speed_set(struct net_device *net_dev)
100+
{
101+
struct bgmac *bgmac = netdev_priv(net_dev);
102+
u32 val;
103+
104+
if (!bgmac->plat.nicpm_base)
105+
return;
106+
107+
val = NICPM_IOMUX_CTRL_INIT_VAL;
108+
switch (bgmac->net_dev->phydev->speed) {
109+
default:
110+
netdev_err(net_dev, "Unsupported speed. Defaulting to 1000Mb\n");
111+
case SPEED_1000:
112+
val |= NICPM_IOMUX_CTRL_SPD_1000M << NICPM_IOMUX_CTRL_SPD_SHIFT;
113+
break;
114+
case SPEED_100:
115+
val |= NICPM_IOMUX_CTRL_SPD_100M << NICPM_IOMUX_CTRL_SPD_SHIFT;
116+
break;
117+
case SPEED_10:
118+
val |= NICPM_IOMUX_CTRL_SPD_10M << NICPM_IOMUX_CTRL_SPD_SHIFT;
119+
break;
120+
}
121+
122+
writel(val, bgmac->plat.nicpm_base + NICPM_IOMUX_CTRL);
123+
124+
bgmac_adjust_link(bgmac->net_dev);
125+
}
126+
127+
static int platform_phy_connect(struct bgmac *bgmac)
128+
{
129+
struct phy_device *phy_dev;
130+
131+
if (bgmac->plat.nicpm_base)
132+
phy_dev = of_phy_get_and_connect(bgmac->net_dev,
133+
bgmac->dev->of_node,
134+
bgmac_nicpm_speed_set);
135+
else
136+
phy_dev = of_phy_get_and_connect(bgmac->net_dev,
137+
bgmac->dev->of_node,
138+
bgmac_adjust_link);
139+
if (!phy_dev) {
140+
dev_err(bgmac->dev, "PHY connection failed\n");
141+
return -ENODEV;
142+
}
143+
144+
return 0;
145+
}
146+
89147
static int bgmac_probe(struct platform_device *pdev)
90148
{
91149
struct device_node *np = pdev->dev.of_node;
@@ -102,7 +160,6 @@ static int bgmac_probe(struct platform_device *pdev)
102160
/* Set the features of the 4707 family */
103161
bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
104162
bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
105-
bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
106163
bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4;
107164
bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP;
108165
bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
@@ -142,6 +199,14 @@ static int bgmac_probe(struct platform_device *pdev)
142199
if (IS_ERR(bgmac->plat.idm_base))
143200
return PTR_ERR(bgmac->plat.idm_base);
144201

202+
regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nicpm_base");
203+
if (regs) {
204+
bgmac->plat.nicpm_base = devm_ioremap_resource(&pdev->dev,
205+
regs);
206+
if (IS_ERR(bgmac->plat.nicpm_base))
207+
return PTR_ERR(bgmac->plat.nicpm_base);
208+
}
209+
145210
bgmac->read = platform_bgmac_read;
146211
bgmac->write = platform_bgmac_write;
147212
bgmac->idm_read = platform_bgmac_idm_read;
@@ -151,6 +216,12 @@ static int bgmac_probe(struct platform_device *pdev)
151216
bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
152217
bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
153218
bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32;
219+
if (of_parse_phandle(np, "phy-handle", 0)) {
220+
bgmac->phy_connect = platform_phy_connect;
221+
} else {
222+
bgmac->phy_connect = bgmac_phy_connect_direct;
223+
bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
224+
}
154225

155226
return bgmac_enet_probe(bgmac);
156227
}
@@ -167,6 +238,7 @@ static int bgmac_remove(struct platform_device *pdev)
167238
static const struct of_device_id bgmac_of_enet_match[] = {
168239
{.compatible = "brcm,amac",},
169240
{.compatible = "brcm,nsp-amac",},
241+
{.compatible = "brcm,ns2-amac",},
170242
{},
171243
};
172244

drivers/net/ethernet/broadcom/bgmac.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,9 @@ static void bgmac_enable(struct bgmac *bgmac)
10821082
/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipinit */
10831083
static void bgmac_chip_init(struct bgmac *bgmac)
10841084
{
1085+
/* Clear any erroneously pending interrupts */
1086+
bgmac_write(bgmac, BGMAC_INT_STATUS, ~0);
1087+
10851088
/* 1 interrupt per received frame */
10861089
bgmac_write(bgmac, BGMAC_INT_RECV_LAZY, 1 << BGMAC_IRL_FC_SHIFT);
10871090

@@ -1388,7 +1391,7 @@ static const struct ethtool_ops bgmac_ethtool_ops = {
13881391
* MII
13891392
**************************************************/
13901393

1391-
static void bgmac_adjust_link(struct net_device *net_dev)
1394+
void bgmac_adjust_link(struct net_device *net_dev)
13921395
{
13931396
struct bgmac *bgmac = netdev_priv(net_dev);
13941397
struct phy_device *phy_dev = net_dev->phydev;
@@ -1411,8 +1414,9 @@ static void bgmac_adjust_link(struct net_device *net_dev)
14111414
phy_print_status(phy_dev);
14121415
}
14131416
}
1417+
EXPORT_SYMBOL_GPL(bgmac_adjust_link);
14141418

1415-
static int bgmac_phy_connect_direct(struct bgmac *bgmac)
1419+
int bgmac_phy_connect_direct(struct bgmac *bgmac)
14161420
{
14171421
struct fixed_phy_status fphy_status = {
14181422
.link = 1,
@@ -1437,24 +1441,7 @@ static int bgmac_phy_connect_direct(struct bgmac *bgmac)
14371441

14381442
return err;
14391443
}
1440-
1441-
static int bgmac_phy_connect(struct bgmac *bgmac)
1442-
{
1443-
struct phy_device *phy_dev;
1444-
char bus_id[MII_BUS_ID_SIZE + 3];
1445-
1446-
/* Connect to the PHY */
1447-
snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id,
1448-
bgmac->phyaddr);
1449-
phy_dev = phy_connect(bgmac->net_dev, bus_id, &bgmac_adjust_link,
1450-
PHY_INTERFACE_MODE_MII);
1451-
if (IS_ERR(phy_dev)) {
1452-
dev_err(bgmac->dev, "PHY connection failed\n");
1453-
return PTR_ERR(phy_dev);
1454-
}
1455-
1456-
return 0;
1457-
}
1444+
EXPORT_SYMBOL_GPL(bgmac_phy_connect_direct);
14581445

14591446
int bgmac_enet_probe(struct bgmac *info)
14601447
{
@@ -1507,10 +1494,7 @@ int bgmac_enet_probe(struct bgmac *info)
15071494

15081495
netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT);
15091496

1510-
if (!bgmac->mii_bus)
1511-
err = bgmac_phy_connect_direct(bgmac);
1512-
else
1513-
err = bgmac_phy_connect(bgmac);
1497+
err = bgmac_phy_connect(bgmac);
15141498
if (err) {
15151499
dev_err(bgmac->dev, "Cannot connect to phy\n");
15161500
goto err_dma_free;

drivers/net/ethernet/broadcom/bgmac.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ struct bgmac {
463463
struct {
464464
void *base;
465465
void *idm_base;
466+
void *nicpm_base;
466467
} plat;
467468
struct {
468469
struct bcma_device *core;
@@ -513,10 +514,13 @@ struct bgmac {
513514
u32 (*get_bus_clock)(struct bgmac *bgmac);
514515
void (*cmn_maskset32)(struct bgmac *bgmac, u16 offset, u32 mask,
515516
u32 set);
517+
int (*phy_connect)(struct bgmac *bgmac);
516518
};
517519

518520
int bgmac_enet_probe(struct bgmac *info);
519521
void bgmac_enet_remove(struct bgmac *bgmac);
522+
void bgmac_adjust_link(struct net_device *net_dev);
523+
int bgmac_phy_connect_direct(struct bgmac *bgmac);
520524

521525
struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
522526
void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
@@ -583,4 +587,9 @@ static inline void bgmac_set(struct bgmac *bgmac, u16 offset, u32 set)
583587
{
584588
bgmac_maskset(bgmac, offset, ~0, set);
585589
}
590+
591+
static inline int bgmac_phy_connect(struct bgmac *bgmac)
592+
{
593+
return bgmac->phy_connect(bgmac);
594+
}
586595
#endif /* _BGMAC_H */

drivers/net/phy/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ config BROADCOM_PHY
217217
select BCM_NET_PHYLIB
218218
---help---
219219
Currently supports the BCM5411, BCM5421, BCM5461, BCM54616S, BCM5464,
220-
BCM5481 and BCM5482 PHYs.
220+
BCM5481, BCM54810 and BCM5482 PHYs.
221221

222222
config CICADA_PHY
223223
tristate "Cicada PHYs"

0 commit comments

Comments
 (0)