Commit 264c2693 authored by Lad Prabhakar's avatar Lad Prabhakar Committed by Jakub Kicinski
Browse files

net: stmmac: dwmac-renesas-gbeth: Use OF data for configuration



Prepare for adding RZ/T2H SoC support by making the driver configuration
selectable via OF match data. While the RZ/V2H(P) and RZ/T2H use the same
version of the Synopsys DesignWare MAC (version 5.20), the hardware is
synthesized with different options. To accommodate these differences,
introduce a struct holding per-SoC configuration such as clock list,
number of clocks, TX clock rate control, and STMMAC flags, and retrieve
it from the device tree match entry during probe.

Signed-off-by: default avatarLad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Link: https://patch.msgid.link/20250908105901.3198975-3-prabhakar.mahadev-lad.rj@bp.renesas.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d43ce982
Loading
Loading
Loading
Loading
+47 −10
Original line number Diff line number Diff line
@@ -16,12 +16,34 @@
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/reset.h>
#include <linux/types.h>

#include "stmmac_platform.h"

/**
 * struct renesas_gbeth_of_data - OF data for Renesas GBETH
 *
 * @clks: Array of clock names
 * @num_clks: Number of clocks
 * @stmmac_flags: Flags for the stmmac driver
 * @handle_reset: Flag to indicate if reset control is
 *                handled by the glue driver or core driver.
 * @set_clk_tx_rate: Flag to indicate if Tx clock is fixed or
 *                   set_clk_tx_rate is needed.
 */
struct renesas_gbeth_of_data {
	const char * const *clks;
	u8 num_clks;
	u32 stmmac_flags;
	bool handle_reset;
	bool set_clk_tx_rate;
};

struct renesas_gbeth {
	const struct renesas_gbeth_of_data *of_data;
	struct plat_stmmacenet_data *plat_dat;
	struct reset_control *rstc;
	struct device *dev;
@@ -70,6 +92,7 @@ static void renesas_gbeth_exit(struct platform_device *pdev, void *priv)

static int renesas_gbeth_probe(struct platform_device *pdev)
{
	const struct renesas_gbeth_of_data *of_data;
	struct plat_stmmacenet_data *plat_dat;
	struct stmmac_resources stmmac_res;
	struct device *dev = &pdev->dev;
@@ -91,14 +114,17 @@ static int renesas_gbeth_probe(struct platform_device *pdev)
	if (!gbeth)
		return -ENOMEM;

	plat_dat->num_clks = ARRAY_SIZE(renesas_gbeth_clks);
	of_data = of_device_get_match_data(&pdev->dev);
	gbeth->of_data = of_data;

	plat_dat->num_clks = of_data->num_clks;
	plat_dat->clks = devm_kcalloc(dev, plat_dat->num_clks,
				      sizeof(*plat_dat->clks), GFP_KERNEL);
	if (!plat_dat->clks)
		return -ENOMEM;

	for (i = 0; i < plat_dat->num_clks; i++)
		plat_dat->clks[i].id = renesas_gbeth_clks[i];
		plat_dat->clks[i].id = of_data->clks[i];

	err = devm_clk_bulk_get(dev, plat_dat->num_clks, plat_dat->clks);
	if (err < 0)
@@ -109,25 +135,36 @@ static int renesas_gbeth_probe(struct platform_device *pdev)
		return dev_err_probe(dev, -EINVAL,
				     "error finding tx clock\n");

	if (of_data->handle_reset) {
		gbeth->rstc = devm_reset_control_get_exclusive(dev, NULL);
		if (IS_ERR(gbeth->rstc))
			return PTR_ERR(gbeth->rstc);
	}

	gbeth->dev = dev;
	gbeth->plat_dat = plat_dat;
	plat_dat->bsp_priv = gbeth;
	if (of_data->set_clk_tx_rate)
		plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
	plat_dat->init = renesas_gbeth_init;
	plat_dat->exit = renesas_gbeth_exit;
	plat_dat->flags |= STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY |
			   STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP |
			   STMMAC_FLAG_SPH_DISABLE;
	plat_dat->flags |= STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP |
			   gbeth->of_data->stmmac_flags;

	return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
}

static const struct renesas_gbeth_of_data renesas_gbeth_of_data = {
	.clks = renesas_gbeth_clks,
	.num_clks = ARRAY_SIZE(renesas_gbeth_clks),
	.handle_reset = true,
	.set_clk_tx_rate = true,
	.stmmac_flags = STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY |
			STMMAC_FLAG_SPH_DISABLE,
};

static const struct of_device_id renesas_gbeth_match[] = {
	{ .compatible = "renesas,rzv2h-gbeth", },
	{ .compatible = "renesas,rzv2h-gbeth", .data = &renesas_gbeth_of_data },
	{ /* Sentinel */ }
};
MODULE_DEVICE_TABLE(of, renesas_gbeth_match);