Skip to content

Commit d825612

Browse files
jpintodavem330
authored andcommitted
stmmac: adding new glue driver dwmac-dwc-qos-eth
This patch adds a new glue driver called dwmac-dwc-qos-eth which was based in the dwc_eth_qos as is. To assure retro-compatibility a slight tweak was also added to stmmac_platform. Signed-off-by: Joao Pinto <jpinto@synopsys.com> Tested-by: Niklas Cassel <niklas.cassel@axis.com> Reviewed-by: Lars Persson <larper@axis.com> Acked-by: Alexandre TORGUE <alexandre.torgue@st.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f573c0b commit d825612

File tree

5 files changed

+227
-3
lines changed

5 files changed

+227
-3
lines changed

Documentation/devicetree/bindings/net/snps,dwc-qos-ethernet.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
* Synopsys DWC Ethernet QoS IP version 4.10 driver (GMAC)
22

3+
This binding is deprecated, but it continues to be supported, but new
4+
features should be preferably added to the stmmac binding document.
5+
36
This binding supports the Synopsys Designware Ethernet QoS (Quality Of Service)
47
IP block. The IP supports multiple options for bus type, clocking and reset
58
structure, and feature list. Consequently, a number of properties and list

drivers/net/ethernet/stmicro/stmmac/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ config STMMAC_PLATFORM
2929

3030
if STMMAC_PLATFORM
3131

32+
config DWMAC_DWC_QOS_ETH
33+
tristate "Support for snps,dwc-qos-ethernet.txt DT binding."
34+
select PHYLIB
35+
select CRC32
36+
select MII
37+
depends on OF && HAS_DMA
38+
help
39+
Support for chips using the snps,dwc-qos-ethernet.txt DT binding.
40+
3241
config DWMAC_GENERIC
3342
tristate "Generic driver for DWMAC"
3443
default STMMAC_PLATFORM

drivers/net/ethernet/stmicro/stmmac/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-altr-socfpga.o
1616
obj-$(CONFIG_DWMAC_STI) += dwmac-sti.o
1717
obj-$(CONFIG_DWMAC_STM32) += dwmac-stm32.o
1818
obj-$(CONFIG_DWMAC_SUNXI) += dwmac-sunxi.o
19+
obj-$(CONFIG_DWMAC_DWC_QOS_ETH) += dwmac-dwc-qos-eth.o
1920
obj-$(CONFIG_DWMAC_GENERIC) += dwmac-generic.o
2021
stmmac-platform-objs:= stmmac_platform.o
2122
dwmac-altr-socfpga-objs := altr_tse_pcs.o dwmac-socfpga.o
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/*
2+
* Synopsys DWC Ethernet Quality-of-Service v4.10a linux driver
3+
*
4+
* Copyright (C) 2016 Joao Pinto <jpinto@synopsys.com>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*
10+
* You should have received a copy of the GNU General Public License
11+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
12+
*/
13+
14+
#include <linux/clk.h>
15+
#include <linux/clk-provider.h>
16+
#include <linux/device.h>
17+
#include <linux/ethtool.h>
18+
#include <linux/io.h>
19+
#include <linux/ioport.h>
20+
#include <linux/module.h>
21+
#include <linux/of_net.h>
22+
#include <linux/mfd/syscon.h>
23+
#include <linux/platform_device.h>
24+
#include <linux/stmmac.h>
25+
26+
#include "stmmac_platform.h"
27+
28+
static int dwc_eth_dwmac_config_dt(struct platform_device *pdev,
29+
struct plat_stmmacenet_data *plat_dat)
30+
{
31+
struct device_node *np = pdev->dev.of_node;
32+
u32 burst_map = 0;
33+
u32 bit_index = 0;
34+
u32 a_index = 0;
35+
36+
if (!plat_dat->axi) {
37+
plat_dat->axi = kzalloc(sizeof(struct stmmac_axi), GFP_KERNEL);
38+
39+
if (!plat_dat->axi)
40+
return -ENOMEM;
41+
}
42+
43+
plat_dat->axi->axi_lpi_en = of_property_read_bool(np, "snps,en-lpi");
44+
if (of_property_read_u32(np, "snps,write-requests",
45+
&plat_dat->axi->axi_wr_osr_lmt)) {
46+
/**
47+
* Since the register has a reset value of 1, if property
48+
* is missing, default to 1.
49+
*/
50+
plat_dat->axi->axi_wr_osr_lmt = 1;
51+
} else {
52+
/**
53+
* If property exists, to keep the behavior from dwc_eth_qos,
54+
* subtract one after parsing.
55+
*/
56+
plat_dat->axi->axi_wr_osr_lmt--;
57+
}
58+
59+
if (of_property_read_u32(np, "read,read-requests",
60+
&plat_dat->axi->axi_rd_osr_lmt)) {
61+
/**
62+
* Since the register has a reset value of 1, if property
63+
* is missing, default to 1.
64+
*/
65+
plat_dat->axi->axi_rd_osr_lmt = 1;
66+
} else {
67+
/**
68+
* If property exists, to keep the behavior from dwc_eth_qos,
69+
* subtract one after parsing.
70+
*/
71+
plat_dat->axi->axi_rd_osr_lmt--;
72+
}
73+
of_property_read_u32(np, "snps,burst-map", &burst_map);
74+
75+
/* converts burst-map bitmask to burst array */
76+
for (bit_index = 0; bit_index < 7; bit_index++) {
77+
if (burst_map & (1 << bit_index)) {
78+
switch (bit_index) {
79+
case 0:
80+
plat_dat->axi->axi_blen[a_index] = 4; break;
81+
case 1:
82+
plat_dat->axi->axi_blen[a_index] = 8; break;
83+
case 2:
84+
plat_dat->axi->axi_blen[a_index] = 16; break;
85+
case 3:
86+
plat_dat->axi->axi_blen[a_index] = 32; break;
87+
case 4:
88+
plat_dat->axi->axi_blen[a_index] = 64; break;
89+
case 5:
90+
plat_dat->axi->axi_blen[a_index] = 128; break;
91+
case 6:
92+
plat_dat->axi->axi_blen[a_index] = 256; break;
93+
default:
94+
break;
95+
}
96+
a_index++;
97+
}
98+
}
99+
100+
/* dwc-qos needs GMAC4, AAL, TSO and PMT */
101+
plat_dat->has_gmac4 = 1;
102+
plat_dat->dma_cfg->aal = 1;
103+
plat_dat->tso_en = 1;
104+
plat_dat->pmt = 1;
105+
106+
return 0;
107+
}
108+
109+
static int dwc_eth_dwmac_probe(struct platform_device *pdev)
110+
{
111+
struct plat_stmmacenet_data *plat_dat;
112+
struct stmmac_resources stmmac_res;
113+
struct resource *res;
114+
int ret;
115+
116+
memset(&stmmac_res, 0, sizeof(struct stmmac_resources));
117+
118+
/**
119+
* Since stmmac_platform supports name IRQ only, basic platform
120+
* resource initialization is done in the glue logic.
121+
*/
122+
stmmac_res.irq = platform_get_irq(pdev, 0);
123+
if (stmmac_res.irq < 0) {
124+
if (stmmac_res.irq != -EPROBE_DEFER)
125+
dev_err(&pdev->dev,
126+
"IRQ configuration information not found\n");
127+
128+
return stmmac_res.irq;
129+
}
130+
stmmac_res.wol_irq = stmmac_res.irq;
131+
132+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
133+
stmmac_res.addr = devm_ioremap_resource(&pdev->dev, res);
134+
if (IS_ERR(stmmac_res.addr))
135+
return PTR_ERR(stmmac_res.addr);
136+
137+
plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
138+
if (IS_ERR(plat_dat))
139+
return PTR_ERR(plat_dat);
140+
141+
plat_dat->stmmac_clk = devm_clk_get(&pdev->dev, "apb_pclk");
142+
if (IS_ERR(plat_dat->stmmac_clk)) {
143+
dev_err(&pdev->dev, "apb_pclk clock not found.\n");
144+
ret = PTR_ERR(plat_dat->stmmac_clk);
145+
plat_dat->stmmac_clk = NULL;
146+
goto err_remove_config_dt;
147+
}
148+
clk_prepare_enable(plat_dat->stmmac_clk);
149+
150+
plat_dat->pclk = devm_clk_get(&pdev->dev, "phy_ref_clk");
151+
if (IS_ERR(plat_dat->pclk)) {
152+
dev_err(&pdev->dev, "phy_ref_clk clock not found.\n");
153+
ret = PTR_ERR(plat_dat->pclk);
154+
plat_dat->pclk = NULL;
155+
goto err_out_clk_dis_phy;
156+
}
157+
clk_prepare_enable(plat_dat->pclk);
158+
159+
ret = dwc_eth_dwmac_config_dt(pdev, plat_dat);
160+
if (ret)
161+
goto err_out_clk_dis_aper;
162+
163+
ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
164+
if (ret)
165+
goto err_out_clk_dis_aper;
166+
167+
return 0;
168+
169+
err_out_clk_dis_aper:
170+
clk_disable_unprepare(plat_dat->pclk);
171+
err_out_clk_dis_phy:
172+
clk_disable_unprepare(plat_dat->stmmac_clk);
173+
err_remove_config_dt:
174+
stmmac_remove_config_dt(pdev, plat_dat);
175+
176+
return ret;
177+
}
178+
179+
static int dwc_eth_dwmac_remove(struct platform_device *pdev)
180+
{
181+
return stmmac_pltfr_remove(pdev);
182+
}
183+
184+
static const struct of_device_id dwc_eth_dwmac_match[] = {
185+
{ .compatible = "snps,dwc-qos-ethernet-4.10", },
186+
{ }
187+
};
188+
MODULE_DEVICE_TABLE(of, dwc_eth_dwmac_match);
189+
190+
static struct platform_driver dwc_eth_dwmac_driver = {
191+
.probe = dwc_eth_dwmac_probe,
192+
.remove = dwc_eth_dwmac_remove,
193+
.driver = {
194+
.name = "dwc-eth-dwmac",
195+
.of_match_table = dwc_eth_dwmac_match,
196+
},
197+
};
198+
module_platform_driver(dwc_eth_dwmac_driver);
199+
200+
MODULE_AUTHOR("Joao Pinto <jpinto@synopsys.com>");
201+
MODULE_DESCRIPTION("Synopsys DWC Ethernet Quality-of-Service v4.10a driver");
202+
MODULE_LICENSE("GPL v2");

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,19 @@ static int stmmac_dt_phy(struct plat_stmmacenet_data *plat,
180180
mdio = false;
181181
}
182182

183-
/* If snps,dwmac-mdio is passed from DT, always register the MDIO */
184-
for_each_child_of_node(np, plat->mdio_node) {
185-
if (of_device_is_compatible(plat->mdio_node, "snps,dwmac-mdio"))
183+
/* exception for dwmac-dwc-qos-eth glue logic */
184+
if (of_device_is_compatible(np, "snps,dwc-qos-ethernet-4.10")) {
185+
plat->mdio_node = of_get_child_by_name(np, "mdio");
186+
} else {
187+
/**
188+
* If snps,dwmac-mdio is passed from DT, always register
189+
* the MDIO
190+
*/
191+
for_each_child_of_node(np, plat->mdio_node) {
192+
if (of_device_is_compatible(plat->mdio_node,
193+
"snps,dwmac-mdio"))
186194
break;
195+
}
187196
}
188197

189198
if (plat->mdio_node) {

0 commit comments

Comments
 (0)