xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Generic DWMAC platform driver
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2007-2011  STMicroelectronics Ltd
5*4882a593Smuzhiyun  * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * This file is licensed under the terms of the GNU General Public
8*4882a593Smuzhiyun  * License version 2. This program is licensed "as is" without any
9*4882a593Smuzhiyun  * warranty of any kind, whether express or implied.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/module.h>
13*4882a593Smuzhiyun #include <linux/of.h>
14*4882a593Smuzhiyun #include <linux/platform_device.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include "stmmac.h"
17*4882a593Smuzhiyun #include "stmmac_platform.h"
18*4882a593Smuzhiyun 
dwmac_generic_probe(struct platform_device * pdev)19*4882a593Smuzhiyun static int dwmac_generic_probe(struct platform_device *pdev)
20*4882a593Smuzhiyun {
21*4882a593Smuzhiyun 	struct plat_stmmacenet_data *plat_dat;
22*4882a593Smuzhiyun 	struct stmmac_resources stmmac_res;
23*4882a593Smuzhiyun 	int ret;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun 	ret = stmmac_get_platform_resources(pdev, &stmmac_res);
26*4882a593Smuzhiyun 	if (ret)
27*4882a593Smuzhiyun 		return ret;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	if (pdev->dev.of_node) {
30*4882a593Smuzhiyun 		plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
31*4882a593Smuzhiyun 		if (IS_ERR(plat_dat)) {
32*4882a593Smuzhiyun 			dev_err(&pdev->dev, "dt configuration failed\n");
33*4882a593Smuzhiyun 			return PTR_ERR(plat_dat);
34*4882a593Smuzhiyun 		}
35*4882a593Smuzhiyun 	} else {
36*4882a593Smuzhiyun 		plat_dat = dev_get_platdata(&pdev->dev);
37*4882a593Smuzhiyun 		if (!plat_dat) {
38*4882a593Smuzhiyun 			dev_err(&pdev->dev, "no platform data provided\n");
39*4882a593Smuzhiyun 			return  -EINVAL;
40*4882a593Smuzhiyun 		}
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 		/* Set default value for multicast hash bins */
43*4882a593Smuzhiyun 		plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 		/* Set default value for unicast filter entries */
46*4882a593Smuzhiyun 		plat_dat->unicast_filter_entries = 1;
47*4882a593Smuzhiyun 	}
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 	/* Custom initialisation (if needed) */
50*4882a593Smuzhiyun 	if (plat_dat->init) {
51*4882a593Smuzhiyun 		ret = plat_dat->init(pdev, plat_dat->bsp_priv);
52*4882a593Smuzhiyun 		if (ret)
53*4882a593Smuzhiyun 			goto err_remove_config_dt;
54*4882a593Smuzhiyun 	}
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
57*4882a593Smuzhiyun 	if (ret)
58*4882a593Smuzhiyun 		goto err_exit;
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun 	return 0;
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun err_exit:
63*4882a593Smuzhiyun 	if (plat_dat->exit)
64*4882a593Smuzhiyun 		plat_dat->exit(pdev, plat_dat->bsp_priv);
65*4882a593Smuzhiyun err_remove_config_dt:
66*4882a593Smuzhiyun 	if (pdev->dev.of_node)
67*4882a593Smuzhiyun 		stmmac_remove_config_dt(pdev, plat_dat);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	return ret;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun static const struct of_device_id dwmac_generic_match[] = {
73*4882a593Smuzhiyun 	{ .compatible = "st,spear600-gmac"},
74*4882a593Smuzhiyun 	{ .compatible = "snps,dwmac-3.40a"},
75*4882a593Smuzhiyun 	{ .compatible = "snps,dwmac-3.50a"},
76*4882a593Smuzhiyun 	{ .compatible = "snps,dwmac-3.610"},
77*4882a593Smuzhiyun 	{ .compatible = "snps,dwmac-3.70a"},
78*4882a593Smuzhiyun 	{ .compatible = "snps,dwmac-3.710"},
79*4882a593Smuzhiyun 	{ .compatible = "snps,dwmac-4.00"},
80*4882a593Smuzhiyun 	{ .compatible = "snps,dwmac-4.10a"},
81*4882a593Smuzhiyun 	{ .compatible = "snps,dwmac"},
82*4882a593Smuzhiyun 	{ .compatible = "snps,dwxgmac-2.10"},
83*4882a593Smuzhiyun 	{ .compatible = "snps,dwxgmac"},
84*4882a593Smuzhiyun 	{ }
85*4882a593Smuzhiyun };
86*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, dwmac_generic_match);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun static struct platform_driver dwmac_generic_driver = {
89*4882a593Smuzhiyun 	.probe  = dwmac_generic_probe,
90*4882a593Smuzhiyun 	.remove = stmmac_pltfr_remove,
91*4882a593Smuzhiyun 	.driver = {
92*4882a593Smuzhiyun 		.name           = STMMAC_RESOURCE_NAME,
93*4882a593Smuzhiyun 		.pm		= &stmmac_pltfr_pm_ops,
94*4882a593Smuzhiyun 		.of_match_table = of_match_ptr(dwmac_generic_match),
95*4882a593Smuzhiyun 	},
96*4882a593Smuzhiyun };
97*4882a593Smuzhiyun module_platform_driver(dwmac_generic_driver);
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun MODULE_DESCRIPTION("Generic dwmac driver");
100*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
101