diff mbox series

[v3,5/7] net: stmmac: Add glue layer for StarFive JH7110 SoCs

Message ID 20230106030001.1952-6-yanhong.wang@starfivetech.com (mailing list archive)
State Superseded
Headers show
Series Add Ethernet driver for StarFive JH7110 SoC | expand

Checks

Context Check Description
conchuod/tree_selection fail Failed to apply to next/pending-fixes or riscv/for-next

Commit Message

yanhong wang Jan. 6, 2023, 2:59 a.m. UTC
This adds StarFive dwmac driver support on the StarFive JH7110 SoCs.

Signed-off-by: Yanhong Wang <yanhong.wang@starfivetech.com>
Co-developed-by: Emil Renner Berthing <kernel@esmil.dk>
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---
 MAINTAINERS                                   |   1 +
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 ++
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../stmicro/stmmac/dwmac-starfive-plat.c      | 123 ++++++++++++++++++
 4 files changed, 137 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-plat.c

Comments

Arun Ramadoss Jan. 8, 2023, 11:11 a.m. UTC | #1
Hi Yanhong,

On Fri, 2023-01-06 at 10:59 +0800, Yanhong Wang wrote:
> This adds StarFive dwmac driver support on the StarFive JH7110 SoCs.
> 
> Signed-off-by: Yanhong Wang <yanhong.wang@starfivetech.com>
> Co-developed-by: Emil Renner Berthing <kernel@esmil.dk>
> Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
> ---
>  MAINTAINERS                                   |   1 +
>  drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 ++
>  drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
>  .../stmicro/stmmac/dwmac-starfive-plat.c      | 123
> ++++++++++++++++++
>  4 files changed, 137 insertions(+)
>  create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-
> starfive-plat.c
> 
> 
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-
> plat.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-plat.c
> new file mode 100644
> index 000000000000..910095b10fe4
> --- /dev/null
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-plat.c
> @@ -0,0 +1,123 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * StarFive DWMAC platform driver
> + *
> + * Copyright(C) 2022 StarFive Technology Co., Ltd.
> + *
> + */
> +
> +#include <linux/of_device.h>

Blank line between header with <  > and " "

> +#include "stmmac_platform.h"
> +
> +struct starfive_dwmac {
> +	struct device *dev;
> +	struct clk *clk_tx;
> +	struct clk *clk_gtx;
> +	struct clk *clk_gtxc;
> +};
> +
> +static void starfive_eth_plat_fix_mac_speed(void *priv, unsigned int
> speed)
> +{
> +	struct starfive_dwmac *dwmac = priv;
> +	unsigned long rate;
> +	int err;
> +
> +	switch (speed) {
> +	case SPEED_1000:
> +		rate = 125000000;
> +		break;
> +	case SPEED_100:
> +		rate = 25000000;
> +		break;
> +	case SPEED_10:
> +		rate = 2500000;
> +		break;
> +	default:
> +		dev_err(dwmac->dev, "invalid speed %u\n", speed);
> +		return;

Do we need to return value, since it is invalid speed. But the return
value of function is void.

> +	}
> +
> +	err = clk_set_rate(dwmac->clk_gtx, rate);
> +	if (err)
> +		dev_err(dwmac->dev, "failed to set tx rate %lu\n",
> rate);
> +}
> +
> +static int starfive_eth_plat_probe(struct platform_device *pdev)
> +{
> +	struct plat_stmmacenet_data *plat_dat;
> +	struct stmmac_resources stmmac_res;
> +	struct starfive_dwmac *dwmac;
> +	int (*syscon_init)(struct device *dev);

Reverse christmas tree.

> +	int err;
> +
> +	err = stmmac_get_platform_resources(pdev, &stmmac_res);
> +	if (err)
> +		return err;
> +
> +	plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
> +	if (IS_ERR(plat_dat)) {
> +		dev_err(&pdev->dev, "dt configuration failed\n");
> +		return PTR_ERR(plat_dat);
> +	}
> +
> +	dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
> +	if (!dwmac)
> +		return -ENOMEM;
> +
> +	syscon_init = of_device_get_match_data(&pdev->dev);
> +	if (syscon_init) {
> +		err = syscon_init(&pdev->dev);
> +		if (err)
> +			return err;
> +	}
> +
> +	dwmac->clk_tx = devm_clk_get_enabled(&pdev->dev, "tx");
> +	if (IS_ERR(dwmac->clk_tx))
> +		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac-
> >clk_tx),
> +						"error getting tx
> clock\n");
> +
> +	dwmac->clk_gtx = devm_clk_get_enabled(&pdev->dev, "gtx");
> +	if (IS_ERR(dwmac->clk_gtx))
> +		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac-
> >clk_gtx),
> +						"error getting gtx
> clock\n");
> +
> +	dwmac->clk_gtxc = devm_clk_get_enabled(&pdev->dev, "gtxc");
> +	if (IS_ERR(dwmac->clk_gtxc))
> +		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac-
> >clk_gtxc),
> +						"error getting gtxc
> clock\n");
> +
> +	dwmac->dev = &pdev->dev;
> +	plat_dat->fix_mac_speed = starfive_eth_plat_fix_mac_speed;
> +	plat_dat->init = NULL;
> +	plat_dat->bsp_priv = dwmac;
> +	plat_dat->dma_cfg->dche = true;
> +
> +	err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
> +	if (err) {
> +		stmmac_remove_config_dt(pdev, plat_dat);
> +		return err;
> +	}
> +
> +	return 0;
> +}
> +
yanhong wang Jan. 9, 2023, 1:13 a.m. UTC | #2
On 2023/1/8 19:11, Arun.Ramadoss@microchip.com wrote:
> Hi Yanhong,
> 
> On Fri, 2023-01-06 at 10:59 +0800, Yanhong Wang wrote:
>> This adds StarFive dwmac driver support on the StarFive JH7110 SoCs.
>> 
>> Signed-off-by: Yanhong Wang <yanhong.wang@starfivetech.com>
>> Co-developed-by: Emil Renner Berthing <kernel@esmil.dk>
>> Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
>> ---
>>  MAINTAINERS                                   |   1 +
>>  drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 ++
>>  drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
>>  .../stmicro/stmmac/dwmac-starfive-plat.c      | 123
>> ++++++++++++++++++
>>  4 files changed, 137 insertions(+)
>>  create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-
>> starfive-plat.c
>> 
>> 
>> 
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-
>> plat.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-plat.c
>> new file mode 100644
>> index 000000000000..910095b10fe4
>> --- /dev/null
>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-plat.c
>> @@ -0,0 +1,123 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * StarFive DWMAC platform driver
>> + *
>> + * Copyright(C) 2022 StarFive Technology Co., Ltd.
>> + *
>> + */
>> +
>> +#include <linux/of_device.h>
> 
> Blank line between header with <  > and " "
> 

Thanks, i will fix.

>> +#include "stmmac_platform.h"
>> +
>> +struct starfive_dwmac {
>> +	struct device *dev;
>> +	struct clk *clk_tx;
>> +	struct clk *clk_gtx;
>> +	struct clk *clk_gtxc;
>> +};
>> +
>> +static void starfive_eth_plat_fix_mac_speed(void *priv, unsigned int
>> speed)
>> +{
>> +	struct starfive_dwmac *dwmac = priv;
>> +	unsigned long rate;
>> +	int err;
>> +
>> +	switch (speed) {
>> +	case SPEED_1000:
>> +		rate = 125000000;
>> +		break;
>> +	case SPEED_100:
>> +		rate = 25000000;
>> +		break;
>> +	case SPEED_10:
>> +		rate = 2500000;
>> +		break;
>> +	default:
>> +		dev_err(dwmac->dev, "invalid speed %u\n", speed);
>> +		return;
> 
> Do we need to return value, since it is invalid speed. But the return
> value of function is void.
> 

I will fix.

>> +	}
>> +
>> +	err = clk_set_rate(dwmac->clk_gtx, rate);
>> +	if (err)
>> +		dev_err(dwmac->dev, "failed to set tx rate %lu\n",
>> rate);
>> +}
>> +
>> +static int starfive_eth_plat_probe(struct platform_device *pdev)
>> +{
>> +	struct plat_stmmacenet_data *plat_dat;
>> +	struct stmmac_resources stmmac_res;
>> +	struct starfive_dwmac *dwmac;
>> +	int (*syscon_init)(struct device *dev);
> 
> Reverse christmas tree.
> 

I will delete the unused variable syscon_init.

>> +	int err;
>> +
>> +	err = stmmac_get_platform_resources(pdev, &stmmac_res);
>> +	if (err)
>> +		return err;
>> +
>> +	plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
>> +	if (IS_ERR(plat_dat)) {
>> +		dev_err(&pdev->dev, "dt configuration failed\n");
>> +		return PTR_ERR(plat_dat);
>> +	}
>> +
>> +	dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
>> +	if (!dwmac)
>> +		return -ENOMEM;
>> +
>> +	syscon_init = of_device_get_match_data(&pdev->dev);
>> +	if (syscon_init) {
>> +		err = syscon_init(&pdev->dev);
>> +		if (err)
>> +			return err;
>> +	}
>> +
>> +	dwmac->clk_tx = devm_clk_get_enabled(&pdev->dev, "tx");
>> +	if (IS_ERR(dwmac->clk_tx))
>> +		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac-
>> >clk_tx),
>> +						"error getting tx
>> clock\n");
>> +
>> +	dwmac->clk_gtx = devm_clk_get_enabled(&pdev->dev, "gtx");
>> +	if (IS_ERR(dwmac->clk_gtx))
>> +		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac-
>> >clk_gtx),
>> +						"error getting gtx
>> clock\n");
>> +
>> +	dwmac->clk_gtxc = devm_clk_get_enabled(&pdev->dev, "gtxc");
>> +	if (IS_ERR(dwmac->clk_gtxc))
>> +		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac-
>> >clk_gtxc),
>> +						"error getting gtxc
>> clock\n");
>> +
>> +	dwmac->dev = &pdev->dev;
>> +	plat_dat->fix_mac_speed = starfive_eth_plat_fix_mac_speed;
>> +	plat_dat->init = NULL;
>> +	plat_dat->bsp_priv = dwmac;
>> +	plat_dat->dma_cfg->dche = true;
>> +
>> +	err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
>> +	if (err) {
>> +		stmmac_remove_config_dt(pdev, plat_dat);
>> +		return err;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 56be59bb09f7..5b50b52d3dbb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19609,6 +19609,7 @@  F:	include/dt-bindings/clock/starfive*
 STARFIVE DWMAC GLUE LAYER
 M:	Yanhong Wang <yanhong.wang@starfivetech.com>
 S:	Maintained
+F:	Documentation/devicetree/bindings/net/dwmac-starfive-plat.c
 F:	Documentation/devicetree/bindings/net/starfive,jh7110-dwmac.yaml
 
 STARFIVE PINCTRL DRIVER
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index 31ff35174034..f9a4ad4abd54 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -235,6 +235,18 @@  config DWMAC_INTEL_PLAT
 	  the stmmac device driver. This driver is used for the Intel Keem Bay
 	  SoC.
 
+config DWMAC_STARFIVE_PLAT
+	tristate "StarFive dwmac support"
+	depends on OF && COMMON_CLK
+	depends on STMMAC_ETH
+	default SOC_STARFIVE
+	help
+	  Support for ethernet controllers on StarFive RISC-V SoCs
+
+	  This selects the StarFive platform specific glue layer support for
+	  the stmmac device driver. This driver is used for StarFive JH7110
+	  ethernet controller.
+
 config DWMAC_VISCONTI
 	tristate "Toshiba Visconti DWMAC support"
 	default ARCH_VISCONTI
diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index d4e12e9ace4f..a63ab0ab5071 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -31,6 +31,7 @@  obj-$(CONFIG_DWMAC_DWC_QOS_ETH)	+= dwmac-dwc-qos-eth.o
 obj-$(CONFIG_DWMAC_INTEL_PLAT)	+= dwmac-intel-plat.o
 obj-$(CONFIG_DWMAC_GENERIC)	+= dwmac-generic.o
 obj-$(CONFIG_DWMAC_IMX8)	+= dwmac-imx.o
+obj-$(CONFIG_DWMAC_STARFIVE_PLAT)	+= dwmac-starfive-plat.o
 obj-$(CONFIG_DWMAC_VISCONTI)	+= dwmac-visconti.o
 stmmac-platform-objs:= stmmac_platform.o
 dwmac-altr-socfpga-objs := altr_tse_pcs.o dwmac-socfpga.o
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-plat.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-plat.c
new file mode 100644
index 000000000000..910095b10fe4
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive-plat.c
@@ -0,0 +1,123 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * StarFive DWMAC platform driver
+ *
+ * Copyright(C) 2022 StarFive Technology Co., Ltd.
+ *
+ */
+
+#include <linux/of_device.h>
+#include "stmmac_platform.h"
+
+struct starfive_dwmac {
+	struct device *dev;
+	struct clk *clk_tx;
+	struct clk *clk_gtx;
+	struct clk *clk_gtxc;
+};
+
+static void starfive_eth_plat_fix_mac_speed(void *priv, unsigned int speed)
+{
+	struct starfive_dwmac *dwmac = priv;
+	unsigned long rate;
+	int err;
+
+	switch (speed) {
+	case SPEED_1000:
+		rate = 125000000;
+		break;
+	case SPEED_100:
+		rate = 25000000;
+		break;
+	case SPEED_10:
+		rate = 2500000;
+		break;
+	default:
+		dev_err(dwmac->dev, "invalid speed %u\n", speed);
+		return;
+	}
+
+	err = clk_set_rate(dwmac->clk_gtx, rate);
+	if (err)
+		dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate);
+}
+
+static int starfive_eth_plat_probe(struct platform_device *pdev)
+{
+	struct plat_stmmacenet_data *plat_dat;
+	struct stmmac_resources stmmac_res;
+	struct starfive_dwmac *dwmac;
+	int (*syscon_init)(struct device *dev);
+	int err;
+
+	err = stmmac_get_platform_resources(pdev, &stmmac_res);
+	if (err)
+		return err;
+
+	plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
+	if (IS_ERR(plat_dat)) {
+		dev_err(&pdev->dev, "dt configuration failed\n");
+		return PTR_ERR(plat_dat);
+	}
+
+	dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
+	if (!dwmac)
+		return -ENOMEM;
+
+	syscon_init = of_device_get_match_data(&pdev->dev);
+	if (syscon_init) {
+		err = syscon_init(&pdev->dev);
+		if (err)
+			return err;
+	}
+
+	dwmac->clk_tx = devm_clk_get_enabled(&pdev->dev, "tx");
+	if (IS_ERR(dwmac->clk_tx))
+		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac->clk_tx),
+						"error getting tx clock\n");
+
+	dwmac->clk_gtx = devm_clk_get_enabled(&pdev->dev, "gtx");
+	if (IS_ERR(dwmac->clk_gtx))
+		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac->clk_gtx),
+						"error getting gtx clock\n");
+
+	dwmac->clk_gtxc = devm_clk_get_enabled(&pdev->dev, "gtxc");
+	if (IS_ERR(dwmac->clk_gtxc))
+		return dev_err_probe(&pdev->dev, PTR_ERR(dwmac->clk_gtxc),
+						"error getting gtxc clock\n");
+
+	dwmac->dev = &pdev->dev;
+	plat_dat->fix_mac_speed = starfive_eth_plat_fix_mac_speed;
+	plat_dat->init = NULL;
+	plat_dat->bsp_priv = dwmac;
+	plat_dat->dma_cfg->dche = true;
+
+	err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
+	if (err) {
+		stmmac_remove_config_dt(pdev, plat_dat);
+		return err;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id starfive_eth_plat_match[] = {
+	{ .compatible = "starfive,jh7110-dwmac"	},
+	{ }
+};
+
+static struct platform_driver starfive_eth_plat_driver = {
+	.probe  = starfive_eth_plat_probe,
+	.remove = stmmac_pltfr_remove,
+	.driver = {
+		.name = "starfive-eth-plat",
+		.pm = &stmmac_pltfr_pm_ops,
+		.of_match_table = starfive_eth_plat_match,
+	},
+};
+
+module_platform_driver(starfive_eth_plat_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("StarFive DWMAC platform driver");
+MODULE_AUTHOR("Yanhong Wang <yanhong.wang@starfivetech.com>");