kernel: bgmac: add support for BCM53573
[openwrt/openwrt.git] / target / linux / generic / patches-4.4 / 171-net-bgmac-support-Ethernet-core-on-BCM53573-SoCs.patch
1 From 7d9acff816e15f7d8a51f912bc663373f1d31e7b Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Wed, 17 Aug 2016 22:47:22 +0200
4 Subject: [PATCH net-next] net: bgmac: support Ethernet core on BCM53573 SoCs
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 BCM53573 is a new series of Broadcom's SoCs. It's based on ARM and can
10 be found in two packages (versions): BCM53573 and BCM47189. It shares
11 some code with the Northstar family, but also requires some new quirks.
12
13 First of all there can be up to 2 Ethernet cores on this SoC. If that is
14 the case, they are connected to two different switch ports allowing some
15 more complex/optimized setups. It seems the second unit doesn't come
16 fully configured and requires some IRQ quirk.
17
18 Other than that only the first core is connected to the PHY. For the
19 second one we have to register fixed PHY (similarly to the Northstar),
20 otherwise generic PHY driver would get some invalid info.
21
22 This has been successfully tested on Tenda AC9 (BCM47189B0).
23
24 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
25 ---
26 drivers/net/ethernet/broadcom/bgmac-bcma.c | 19 ++++++++++++++++++-
27 drivers/net/ethernet/broadcom/bgmac.c | 25 +++++++++++++++++++++++++
28 drivers/net/ethernet/broadcom/bgmac.h | 19 +++++++++++++++++++
29 include/linux/bcma/bcma.h | 3 +++
30 include/linux/bcma/bcma_regs.h | 1 +
31 5 files changed, 66 insertions(+), 1 deletion(-)
32
33 --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
34 +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
35 @@ -92,6 +92,7 @@ MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl
36 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipattach */
37 static int bgmac_probe(struct bcma_device *core)
38 {
39 + struct bcma_chipinfo *ci = &core->bus->chipinfo;
40 struct ssb_sprom *sprom = &core->bus->sprom;
41 struct mii_bus *mii_bus;
42 struct bgmac *bgmac;
43 @@ -157,7 +158,8 @@ static int bgmac_probe(struct bcma_devic
44 dev_info(bgmac->dev, "Found PHY addr: %d%s\n", bgmac->phyaddr,
45 bgmac->phyaddr == BGMAC_PHY_NOREGS ? " (NOREGS)" : "");
46
47 - if (!bgmac_is_bcm4707_family(core)) {
48 + if (!bgmac_is_bcm4707_family(core) &&
49 + !(ci->id == BCMA_CHIP_ID_BCM53573 && core->core_unit == 1)) {
50 mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
51 if (IS_ERR(mii_bus)) {
52 err = PTR_ERR(mii_bus);
53 @@ -230,6 +232,21 @@ static int bgmac_probe(struct bcma_devic
54 bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
55 bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
56 break;
57 + case BCMA_CHIP_ID_BCM53573:
58 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
59 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
60 + if (ci->pkg == BCMA_PKG_ID_BCM47189)
61 + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
62 + if (core->core_unit == 0) {
63 + bgmac->feature_flags |= BGMAC_FEAT_CC4_IF_SW_TYPE;
64 + if (ci->pkg == BCMA_PKG_ID_BCM47189)
65 + bgmac->feature_flags |=
66 + BGMAC_FEAT_CC4_IF_SW_TYPE_RGMII;
67 + } else if (core->core_unit == 1) {
68 + bgmac->feature_flags |= BGMAC_FEAT_IRQ_ID_OOB_6;
69 + bgmac->feature_flags |= BGMAC_FEAT_CC7_IF_TYPE_RGMII;
70 + }
71 + break;
72 default:
73 bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
74 bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
75 --- a/drivers/net/ethernet/broadcom/bgmac.c
76 +++ b/drivers/net/ethernet/broadcom/bgmac.c
77 @@ -940,6 +940,27 @@ static void bgmac_chip_reset(struct bgma
78 bgmac_cco_ctl_maskset(bgmac, 1, ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK |
79 BGMAC_CHIPCTL_1_SW_TYPE_MASK),
80 sw_type);
81 + } else if (bgmac->feature_flags & BGMAC_FEAT_CC4_IF_SW_TYPE) {
82 + u32 sw_type = BGMAC_CHIPCTL_4_IF_TYPE_MII |
83 + BGMAC_CHIPCTL_4_SW_TYPE_EPHY;
84 + u8 et_swtype = 0;
85 + char buf[4];
86 +
87 + if (bcm47xx_nvram_getenv("et_swtype", buf, sizeof(buf)) > 0) {
88 + if (kstrtou8(buf, 0, &et_swtype))
89 + dev_err(bgmac->dev, "Failed to parse et_swtype (%s)\n",
90 + buf);
91 + sw_type = (et_swtype & 0x0f) << 12;
92 + } else if (bgmac->feature_flags & BGMAC_FEAT_CC4_IF_SW_TYPE_RGMII) {
93 + sw_type = BGMAC_CHIPCTL_4_IF_TYPE_RGMII |
94 + BGMAC_CHIPCTL_4_SW_TYPE_RGMII;
95 + }
96 + bgmac_cco_ctl_maskset(bgmac, 4, ~(BGMAC_CHIPCTL_4_IF_TYPE_MASK |
97 + BGMAC_CHIPCTL_4_SW_TYPE_MASK),
98 + sw_type);
99 + } else if (bgmac->feature_flags & BGMAC_FEAT_CC7_IF_TYPE_RGMII) {
100 + bgmac_cco_ctl_maskset(bgmac, 7, ~BGMAC_CHIPCTL_7_IF_TYPE_MASK,
101 + BGMAC_CHIPCTL_7_IF_TYPE_RGMII);
102 }
103
104 if (iost & BGMAC_BCMA_IOST_ATTACHED && !bgmac->has_robosw)
105 @@ -1483,6 +1504,10 @@ int bgmac_enet_probe(struct bgmac *info)
106 */
107 bgmac_clk_enable(bgmac, 0);
108
109 + /* This seems to be fixing IRQ by assigning OOB #6 to the core */
110 + if (bgmac->feature_flags & BGMAC_FEAT_IRQ_ID_OOB_6)
111 + bgmac_idm_write(bgmac, BCMA_OOB_SEL_OUT_A30, 0x86);
112 +
113 bgmac_chip_reset(bgmac);
114
115 err = bgmac_dma_alloc(bgmac);
116 --- a/drivers/net/ethernet/broadcom/bgmac.h
117 +++ b/drivers/net/ethernet/broadcom/bgmac.h
118 @@ -369,6 +369,21 @@
119 #define BGMAC_CHIPCTL_1_SW_TYPE_RGMII 0x000000C0
120 #define BGMAC_CHIPCTL_1_RXC_DLL_BYPASS 0x00010000
121
122 +#define BGMAC_CHIPCTL_4_IF_TYPE_MASK 0x00003000
123 +#define BGMAC_CHIPCTL_4_IF_TYPE_RMII 0x00000000
124 +#define BGMAC_CHIPCTL_4_IF_TYPE_MII 0x00001000
125 +#define BGMAC_CHIPCTL_4_IF_TYPE_RGMII 0x00002000
126 +#define BGMAC_CHIPCTL_4_SW_TYPE_MASK 0x0000C000
127 +#define BGMAC_CHIPCTL_4_SW_TYPE_EPHY 0x00000000
128 +#define BGMAC_CHIPCTL_4_SW_TYPE_EPHYMII 0x00004000
129 +#define BGMAC_CHIPCTL_4_SW_TYPE_EPHYRMII 0x00008000
130 +#define BGMAC_CHIPCTL_4_SW_TYPE_RGMII 0x0000C000
131 +
132 +#define BGMAC_CHIPCTL_7_IF_TYPE_MASK 0x000000C0
133 +#define BGMAC_CHIPCTL_7_IF_TYPE_RMII 0x00000000
134 +#define BGMAC_CHIPCTL_7_IF_TYPE_MII 0x00000040
135 +#define BGMAC_CHIPCTL_7_IF_TYPE_RGMII 0x00000080
136 +
137 #define BGMAC_WEIGHT 64
138
139 #define ETHER_MAX_LEN 1518
140 @@ -390,6 +405,10 @@
141 #define BGMAC_FEAT_NO_CLR_MIB BIT(13)
142 #define BGMAC_FEAT_FORCE_SPEED_2500 BIT(14)
143 #define BGMAC_FEAT_CMDCFG_SR_REV4 BIT(15)
144 +#define BGMAC_FEAT_IRQ_ID_OOB_6 BIT(16)
145 +#define BGMAC_FEAT_CC4_IF_SW_TYPE BIT(17)
146 +#define BGMAC_FEAT_CC4_IF_SW_TYPE_RGMII BIT(18)
147 +#define BGMAC_FEAT_CC7_IF_TYPE_RGMII BIT(19)
148
149 struct bgmac_slot_info {
150 union {
151 --- a/include/linux/bcma/bcma_regs.h
152 +++ b/include/linux/bcma/bcma_regs.h
153 @@ -23,6 +23,7 @@
154 #define BCMA_CLKCTLST_4328A0_HAVEALP 0x00020000 /* 4328a0 has reversed bits */
155
156 /* Agent registers (common for every core) */
157 +#define BCMA_OOB_SEL_OUT_A30 0x0100
158 #define BCMA_IOCTL 0x0408 /* IO control */
159 #define BCMA_IOCTL_CLK 0x0001
160 #define BCMA_IOCTL_FGC 0x0002