File Index
Files and directories
Sign in
FILE

dwmac-lpc18xx.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c C
 1/*
 2 * DWMAC glue for NXP LPC18xx/LPC43xx Ethernet
 3 *
 4 * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
 5 *
 6 * This file is licensed under the terms of the GNU General Public
 7 * License version 2. This program is licensed "as is" without any
 8 * warranty of any kind, whether express or implied.
 9 */
10
11#include <linux/mfd/syscon.h>
12#include <linux/module.h>
13#include <linux/of.h>
14#include <linux/of_net.h>
15#include <linux/phy.h>
16#include <linux/platform_device.h>
17#include <linux/regmap.h>
18#include <linux/stmmac.h>
19
20#include "stmmac_platform.h"
21
22/* Register defines for CREG syscon */
23#define LPC18XX_CREG_CREG6			0x12c
24# define LPC18XX_CREG_CREG6_ETHMODE_MASK	GENMASK(2, 0)
25
26static int lpc18xx_set_phy_intf_sel(void *bsp_priv, u8 phy_intf_sel)
27{
28	struct regmap *reg = bsp_priv;
29
30	if (phy_intf_sel != PHY_INTF_SEL_GMII_MII &&
31	    phy_intf_sel != PHY_INTF_SEL_RMII)
32		return -EINVAL;
33
34	regmap_update_bits(reg, LPC18XX_CREG_CREG6,
35			   LPC18XX_CREG_CREG6_ETHMODE_MASK,
36			   FIELD_PREP(LPC18XX_CREG_CREG6_ETHMODE_MASK,
37				      phy_intf_sel));
38
39	return 0;
40}
41
42static int lpc18xx_dwmac_probe(struct platform_device *pdev)
43{
44	struct plat_stmmacenet_data *plat_dat;
45	struct stmmac_resources stmmac_res;
46	struct regmap *regmap;
47	int ret;
48
49	ret = stmmac_get_platform_resources(pdev, &stmmac_res);
50	if (ret)
51		return ret;
52
53	plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
54	if (IS_ERR(plat_dat))
55		return PTR_ERR(plat_dat);
56
57	plat_dat->core_type = DWMAC_CORE_GMAC;
58
59	regmap = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
60	if (IS_ERR(regmap)) {
61		dev_err(&pdev->dev, "syscon lookup failed\n");
62		return PTR_ERR(regmap);
63	}
64
65	plat_dat->bsp_priv = regmap;
66	plat_dat->set_phy_intf_sel = lpc18xx_set_phy_intf_sel;
67
68	return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
69}
70
71static const struct of_device_id lpc18xx_dwmac_match[] = {
72	{ .compatible = "nxp,lpc1850-dwmac" },
73	{ }
74};
75MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
76
77static struct platform_driver lpc18xx_dwmac_driver = {
78	.probe  = lpc18xx_dwmac_probe,
79	.remove = stmmac_pltfr_remove,
80	.driver = {
81		.name           = "lpc18xx-dwmac",
82		.pm		= &stmmac_pltfr_pm_ops,
83		.of_match_table = lpc18xx_dwmac_match,
84	},
85};
86module_platform_driver(lpc18xx_dwmac_driver);
87
88MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
89MODULE_DESCRIPTION("DWMAC glue for LPC18xx/43xx Ethernet");
90MODULE_LICENSE("GPL v2");
~/ Read-only file preview.