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