xref: /openbmc/linux/drivers/net/ethernet/amd/xgbe/xgbe-platform.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1bd8255d8SLendacky, Thomas /*
2bd8255d8SLendacky, Thomas  * AMD 10Gb Ethernet driver
3bd8255d8SLendacky, Thomas  *
4bd8255d8SLendacky, Thomas  * This file is available to you under your choice of the following two
5bd8255d8SLendacky, Thomas  * licenses:
6bd8255d8SLendacky, Thomas  *
7bd8255d8SLendacky, Thomas  * License 1: GPLv2
8bd8255d8SLendacky, Thomas  *
9bd8255d8SLendacky, Thomas  * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
10bd8255d8SLendacky, Thomas  *
11bd8255d8SLendacky, Thomas  * This file is free software; you may copy, redistribute and/or modify
12bd8255d8SLendacky, Thomas  * it under the terms of the GNU General Public License as published by
13bd8255d8SLendacky, Thomas  * the Free Software Foundation, either version 2 of the License, or (at
14bd8255d8SLendacky, Thomas  * your option) any later version.
15bd8255d8SLendacky, Thomas  *
16bd8255d8SLendacky, Thomas  * This file is distributed in the hope that it will be useful, but
17bd8255d8SLendacky, Thomas  * WITHOUT ANY WARRANTY; without even the implied warranty of
18bd8255d8SLendacky, Thomas  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19bd8255d8SLendacky, Thomas  * General Public License for more details.
20bd8255d8SLendacky, Thomas  *
21bd8255d8SLendacky, Thomas  * You should have received a copy of the GNU General Public License
22bd8255d8SLendacky, Thomas  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23bd8255d8SLendacky, Thomas  *
24bd8255d8SLendacky, Thomas  * This file incorporates work covered by the following copyright and
25bd8255d8SLendacky, Thomas  * permission notice:
26bd8255d8SLendacky, Thomas  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
27bd8255d8SLendacky, Thomas  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28bd8255d8SLendacky, Thomas  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
29bd8255d8SLendacky, Thomas  *     and you.
30bd8255d8SLendacky, Thomas  *
31bd8255d8SLendacky, Thomas  *     The Software IS NOT an item of Licensed Software or Licensed Product
32bd8255d8SLendacky, Thomas  *     under any End User Software License Agreement or Agreement for Licensed
33bd8255d8SLendacky, Thomas  *     Product with Synopsys or any supplement thereto.  Permission is hereby
34bd8255d8SLendacky, Thomas  *     granted, free of charge, to any person obtaining a copy of this software
35bd8255d8SLendacky, Thomas  *     annotated with this license and the Software, to deal in the Software
36bd8255d8SLendacky, Thomas  *     without restriction, including without limitation the rights to use,
37bd8255d8SLendacky, Thomas  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38bd8255d8SLendacky, Thomas  *     of the Software, and to permit persons to whom the Software is furnished
39bd8255d8SLendacky, Thomas  *     to do so, subject to the following conditions:
40bd8255d8SLendacky, Thomas  *
41bd8255d8SLendacky, Thomas  *     The above copyright notice and this permission notice shall be included
42bd8255d8SLendacky, Thomas  *     in all copies or substantial portions of the Software.
43bd8255d8SLendacky, Thomas  *
44bd8255d8SLendacky, Thomas  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45bd8255d8SLendacky, Thomas  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46bd8255d8SLendacky, Thomas  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47bd8255d8SLendacky, Thomas  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48bd8255d8SLendacky, Thomas  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49bd8255d8SLendacky, Thomas  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50bd8255d8SLendacky, Thomas  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51bd8255d8SLendacky, Thomas  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52bd8255d8SLendacky, Thomas  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53bd8255d8SLendacky, Thomas  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54bd8255d8SLendacky, Thomas  *     THE POSSIBILITY OF SUCH DAMAGE.
55bd8255d8SLendacky, Thomas  *
56bd8255d8SLendacky, Thomas  *
57bd8255d8SLendacky, Thomas  * License 2: Modified BSD
58bd8255d8SLendacky, Thomas  *
59bd8255d8SLendacky, Thomas  * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
60bd8255d8SLendacky, Thomas  * All rights reserved.
61bd8255d8SLendacky, Thomas  *
62bd8255d8SLendacky, Thomas  * Redistribution and use in source and binary forms, with or without
63bd8255d8SLendacky, Thomas  * modification, are permitted provided that the following conditions are met:
64bd8255d8SLendacky, Thomas  *     * Redistributions of source code must retain the above copyright
65bd8255d8SLendacky, Thomas  *       notice, this list of conditions and the following disclaimer.
66bd8255d8SLendacky, Thomas  *     * Redistributions in binary form must reproduce the above copyright
67bd8255d8SLendacky, Thomas  *       notice, this list of conditions and the following disclaimer in the
68bd8255d8SLendacky, Thomas  *       documentation and/or other materials provided with the distribution.
69bd8255d8SLendacky, Thomas  *     * Neither the name of Advanced Micro Devices, Inc. nor the
70bd8255d8SLendacky, Thomas  *       names of its contributors may be used to endorse or promote products
71bd8255d8SLendacky, Thomas  *       derived from this software without specific prior written permission.
72bd8255d8SLendacky, Thomas  *
73bd8255d8SLendacky, Thomas  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74bd8255d8SLendacky, Thomas  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75bd8255d8SLendacky, Thomas  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76bd8255d8SLendacky, Thomas  * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77bd8255d8SLendacky, Thomas  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78bd8255d8SLendacky, Thomas  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79bd8255d8SLendacky, Thomas  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80bd8255d8SLendacky, Thomas  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81bd8255d8SLendacky, Thomas  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82bd8255d8SLendacky, Thomas  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83bd8255d8SLendacky, Thomas  *
84bd8255d8SLendacky, Thomas  * This file incorporates work covered by the following copyright and
85bd8255d8SLendacky, Thomas  * permission notice:
86bd8255d8SLendacky, Thomas  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
87bd8255d8SLendacky, Thomas  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88bd8255d8SLendacky, Thomas  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
89bd8255d8SLendacky, Thomas  *     and you.
90bd8255d8SLendacky, Thomas  *
91bd8255d8SLendacky, Thomas  *     The Software IS NOT an item of Licensed Software or Licensed Product
92bd8255d8SLendacky, Thomas  *     under any End User Software License Agreement or Agreement for Licensed
93bd8255d8SLendacky, Thomas  *     Product with Synopsys or any supplement thereto.  Permission is hereby
94bd8255d8SLendacky, Thomas  *     granted, free of charge, to any person obtaining a copy of this software
95bd8255d8SLendacky, Thomas  *     annotated with this license and the Software, to deal in the Software
96bd8255d8SLendacky, Thomas  *     without restriction, including without limitation the rights to use,
97bd8255d8SLendacky, Thomas  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98bd8255d8SLendacky, Thomas  *     of the Software, and to permit persons to whom the Software is furnished
99bd8255d8SLendacky, Thomas  *     to do so, subject to the following conditions:
100bd8255d8SLendacky, Thomas  *
101bd8255d8SLendacky, Thomas  *     The above copyright notice and this permission notice shall be included
102bd8255d8SLendacky, Thomas  *     in all copies or substantial portions of the Software.
103bd8255d8SLendacky, Thomas  *
104bd8255d8SLendacky, Thomas  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105bd8255d8SLendacky, Thomas  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106bd8255d8SLendacky, Thomas  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107bd8255d8SLendacky, Thomas  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108bd8255d8SLendacky, Thomas  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109bd8255d8SLendacky, Thomas  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110bd8255d8SLendacky, Thomas  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111bd8255d8SLendacky, Thomas  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112bd8255d8SLendacky, Thomas  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113bd8255d8SLendacky, Thomas  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114bd8255d8SLendacky, Thomas  *     THE POSSIBILITY OF SUCH DAMAGE.
115bd8255d8SLendacky, Thomas  */
116bd8255d8SLendacky, Thomas 
117bd8255d8SLendacky, Thomas #include <linux/module.h>
118bd8255d8SLendacky, Thomas #include <linux/device.h>
119bd8255d8SLendacky, Thomas #include <linux/platform_device.h>
120bd8255d8SLendacky, Thomas #include <linux/spinlock.h>
121bd8255d8SLendacky, Thomas #include <linux/netdevice.h>
122bd8255d8SLendacky, Thomas #include <linux/etherdevice.h>
123bd8255d8SLendacky, Thomas #include <linux/io.h>
124bd8255d8SLendacky, Thomas #include <linux/of.h>
125bd8255d8SLendacky, Thomas #include <linux/of_net.h>
126bd8255d8SLendacky, Thomas #include <linux/of_address.h>
127bd8255d8SLendacky, Thomas #include <linux/of_platform.h>
128bd8255d8SLendacky, Thomas #include <linux/of_device.h>
129bd8255d8SLendacky, Thomas #include <linux/clk.h>
130bd8255d8SLendacky, Thomas #include <linux/property.h>
131bd8255d8SLendacky, Thomas #include <linux/acpi.h>
132bd8255d8SLendacky, Thomas #include <linux/mdio.h>
133bd8255d8SLendacky, Thomas 
134bd8255d8SLendacky, Thomas #include "xgbe.h"
135bd8255d8SLendacky, Thomas #include "xgbe-common.h"
136bd8255d8SLendacky, Thomas 
137bd8255d8SLendacky, Thomas #ifdef CONFIG_ACPI
138bd8255d8SLendacky, Thomas static const struct acpi_device_id xgbe_acpi_match[];
139bd8255d8SLendacky, Thomas 
xgbe_acpi_vdata(struct xgbe_prv_data * pdata)140bd8255d8SLendacky, Thomas static struct xgbe_version_data *xgbe_acpi_vdata(struct xgbe_prv_data *pdata)
141bd8255d8SLendacky, Thomas {
142bd8255d8SLendacky, Thomas 	const struct acpi_device_id *id;
143bd8255d8SLendacky, Thomas 
144bd8255d8SLendacky, Thomas 	id = acpi_match_device(xgbe_acpi_match, pdata->dev);
145bd8255d8SLendacky, Thomas 
146bd8255d8SLendacky, Thomas 	return id ? (struct xgbe_version_data *)id->driver_data : NULL;
147bd8255d8SLendacky, Thomas }
148bd8255d8SLendacky, Thomas 
xgbe_acpi_support(struct xgbe_prv_data * pdata)149bd8255d8SLendacky, Thomas static int xgbe_acpi_support(struct xgbe_prv_data *pdata)
150bd8255d8SLendacky, Thomas {
151bd8255d8SLendacky, Thomas 	struct device *dev = pdata->dev;
152bd8255d8SLendacky, Thomas 	u32 property;
153bd8255d8SLendacky, Thomas 	int ret;
154bd8255d8SLendacky, Thomas 
155bd8255d8SLendacky, Thomas 	/* Obtain the system clock setting */
156bd8255d8SLendacky, Thomas 	ret = device_property_read_u32(dev, XGBE_ACPI_DMA_FREQ, &property);
157bd8255d8SLendacky, Thomas 	if (ret) {
158bd8255d8SLendacky, Thomas 		dev_err(dev, "unable to obtain %s property\n",
159bd8255d8SLendacky, Thomas 			XGBE_ACPI_DMA_FREQ);
160bd8255d8SLendacky, Thomas 		return ret;
161bd8255d8SLendacky, Thomas 	}
162bd8255d8SLendacky, Thomas 	pdata->sysclk_rate = property;
163bd8255d8SLendacky, Thomas 
164bd8255d8SLendacky, Thomas 	/* Obtain the PTP clock setting */
165bd8255d8SLendacky, Thomas 	ret = device_property_read_u32(dev, XGBE_ACPI_PTP_FREQ, &property);
166bd8255d8SLendacky, Thomas 	if (ret) {
167bd8255d8SLendacky, Thomas 		dev_err(dev, "unable to obtain %s property\n",
168bd8255d8SLendacky, Thomas 			XGBE_ACPI_PTP_FREQ);
169bd8255d8SLendacky, Thomas 		return ret;
170bd8255d8SLendacky, Thomas 	}
171bd8255d8SLendacky, Thomas 	pdata->ptpclk_rate = property;
172bd8255d8SLendacky, Thomas 
173bd8255d8SLendacky, Thomas 	return 0;
174bd8255d8SLendacky, Thomas }
175bd8255d8SLendacky, Thomas #else   /* CONFIG_ACPI */
xgbe_acpi_vdata(struct xgbe_prv_data * pdata)176bd8255d8SLendacky, Thomas static struct xgbe_version_data *xgbe_acpi_vdata(struct xgbe_prv_data *pdata)
177bd8255d8SLendacky, Thomas {
178bd8255d8SLendacky, Thomas 	return NULL;
179bd8255d8SLendacky, Thomas }
180bd8255d8SLendacky, Thomas 
xgbe_acpi_support(struct xgbe_prv_data * pdata)181bd8255d8SLendacky, Thomas static int xgbe_acpi_support(struct xgbe_prv_data *pdata)
182bd8255d8SLendacky, Thomas {
183bd8255d8SLendacky, Thomas 	return -EINVAL;
184bd8255d8SLendacky, Thomas }
185bd8255d8SLendacky, Thomas #endif  /* CONFIG_ACPI */
186bd8255d8SLendacky, Thomas 
187bd8255d8SLendacky, Thomas #ifdef CONFIG_OF
188bd8255d8SLendacky, Thomas static const struct of_device_id xgbe_of_match[];
189bd8255d8SLendacky, Thomas 
xgbe_of_vdata(struct xgbe_prv_data * pdata)190bd8255d8SLendacky, Thomas static struct xgbe_version_data *xgbe_of_vdata(struct xgbe_prv_data *pdata)
191bd8255d8SLendacky, Thomas {
192bd8255d8SLendacky, Thomas 	const struct of_device_id *id;
193bd8255d8SLendacky, Thomas 
194bd8255d8SLendacky, Thomas 	id = of_match_device(xgbe_of_match, pdata->dev);
195bd8255d8SLendacky, Thomas 
196bd8255d8SLendacky, Thomas 	return id ? (struct xgbe_version_data *)id->data : NULL;
197bd8255d8SLendacky, Thomas }
198bd8255d8SLendacky, Thomas 
xgbe_of_support(struct xgbe_prv_data * pdata)199bd8255d8SLendacky, Thomas static int xgbe_of_support(struct xgbe_prv_data *pdata)
200bd8255d8SLendacky, Thomas {
201bd8255d8SLendacky, Thomas 	struct device *dev = pdata->dev;
202bd8255d8SLendacky, Thomas 
203bd8255d8SLendacky, Thomas 	/* Obtain the system clock setting */
204bd8255d8SLendacky, Thomas 	pdata->sysclk = devm_clk_get(dev, XGBE_DMA_CLOCK);
205bd8255d8SLendacky, Thomas 	if (IS_ERR(pdata->sysclk)) {
206bd8255d8SLendacky, Thomas 		dev_err(dev, "dma devm_clk_get failed\n");
207bd8255d8SLendacky, Thomas 		return PTR_ERR(pdata->sysclk);
208bd8255d8SLendacky, Thomas 	}
209bd8255d8SLendacky, Thomas 	pdata->sysclk_rate = clk_get_rate(pdata->sysclk);
210bd8255d8SLendacky, Thomas 
211bd8255d8SLendacky, Thomas 	/* Obtain the PTP clock setting */
212bd8255d8SLendacky, Thomas 	pdata->ptpclk = devm_clk_get(dev, XGBE_PTP_CLOCK);
213bd8255d8SLendacky, Thomas 	if (IS_ERR(pdata->ptpclk)) {
214bd8255d8SLendacky, Thomas 		dev_err(dev, "ptp devm_clk_get failed\n");
215bd8255d8SLendacky, Thomas 		return PTR_ERR(pdata->ptpclk);
216bd8255d8SLendacky, Thomas 	}
217bd8255d8SLendacky, Thomas 	pdata->ptpclk_rate = clk_get_rate(pdata->ptpclk);
218bd8255d8SLendacky, Thomas 
219bd8255d8SLendacky, Thomas 	return 0;
220bd8255d8SLendacky, Thomas }
221bd8255d8SLendacky, Thomas 
xgbe_of_get_phy_pdev(struct xgbe_prv_data * pdata)222bd8255d8SLendacky, Thomas static struct platform_device *xgbe_of_get_phy_pdev(struct xgbe_prv_data *pdata)
223bd8255d8SLendacky, Thomas {
224bd8255d8SLendacky, Thomas 	struct device *dev = pdata->dev;
225bd8255d8SLendacky, Thomas 	struct device_node *phy_node;
226bd8255d8SLendacky, Thomas 	struct platform_device *phy_pdev;
227bd8255d8SLendacky, Thomas 
228bd8255d8SLendacky, Thomas 	phy_node = of_parse_phandle(dev->of_node, "phy-handle", 0);
229bd8255d8SLendacky, Thomas 	if (phy_node) {
230bd8255d8SLendacky, Thomas 		/* Old style device tree:
231bd8255d8SLendacky, Thomas 		 *   The XGBE and PHY resources are separate
232bd8255d8SLendacky, Thomas 		 */
233bd8255d8SLendacky, Thomas 		phy_pdev = of_find_device_by_node(phy_node);
234bd8255d8SLendacky, Thomas 		of_node_put(phy_node);
235bd8255d8SLendacky, Thomas 	} else {
236bd8255d8SLendacky, Thomas 		/* New style device tree:
237bd8255d8SLendacky, Thomas 		 *   The XGBE and PHY resources are grouped together with
238bd8255d8SLendacky, Thomas 		 *   the PHY resources listed last
239bd8255d8SLendacky, Thomas 		 */
240bd8255d8SLendacky, Thomas 		get_device(dev);
241bd8255d8SLendacky, Thomas 		phy_pdev = pdata->platdev;
242bd8255d8SLendacky, Thomas 	}
243bd8255d8SLendacky, Thomas 
244bd8255d8SLendacky, Thomas 	return phy_pdev;
245bd8255d8SLendacky, Thomas }
246bd8255d8SLendacky, Thomas #else   /* CONFIG_OF */
xgbe_of_vdata(struct xgbe_prv_data * pdata)247bd8255d8SLendacky, Thomas static struct xgbe_version_data *xgbe_of_vdata(struct xgbe_prv_data *pdata)
248bd8255d8SLendacky, Thomas {
249bd8255d8SLendacky, Thomas 	return NULL;
250bd8255d8SLendacky, Thomas }
251bd8255d8SLendacky, Thomas 
xgbe_of_support(struct xgbe_prv_data * pdata)252bd8255d8SLendacky, Thomas static int xgbe_of_support(struct xgbe_prv_data *pdata)
253bd8255d8SLendacky, Thomas {
254bd8255d8SLendacky, Thomas 	return -EINVAL;
255bd8255d8SLendacky, Thomas }
256bd8255d8SLendacky, Thomas 
xgbe_of_get_phy_pdev(struct xgbe_prv_data * pdata)257bd8255d8SLendacky, Thomas static struct platform_device *xgbe_of_get_phy_pdev(struct xgbe_prv_data *pdata)
258bd8255d8SLendacky, Thomas {
259bd8255d8SLendacky, Thomas 	return NULL;
260bd8255d8SLendacky, Thomas }
261bd8255d8SLendacky, Thomas #endif  /* CONFIG_OF */
262bd8255d8SLendacky, Thomas 
xgbe_resource_count(struct platform_device * pdev,unsigned int type)263bd8255d8SLendacky, Thomas static unsigned int xgbe_resource_count(struct platform_device *pdev,
264bd8255d8SLendacky, Thomas 					unsigned int type)
265bd8255d8SLendacky, Thomas {
266bd8255d8SLendacky, Thomas 	unsigned int count;
267bd8255d8SLendacky, Thomas 	int i;
268bd8255d8SLendacky, Thomas 
269bd8255d8SLendacky, Thomas 	for (i = 0, count = 0; i < pdev->num_resources; i++) {
270bd8255d8SLendacky, Thomas 		struct resource *res = &pdev->resource[i];
271bd8255d8SLendacky, Thomas 
272bd8255d8SLendacky, Thomas 		if (type == resource_type(res))
273bd8255d8SLendacky, Thomas 			count++;
274bd8255d8SLendacky, Thomas 	}
275bd8255d8SLendacky, Thomas 
276bd8255d8SLendacky, Thomas 	return count;
277bd8255d8SLendacky, Thomas }
278bd8255d8SLendacky, Thomas 
xgbe_get_phy_pdev(struct xgbe_prv_data * pdata)279bd8255d8SLendacky, Thomas static struct platform_device *xgbe_get_phy_pdev(struct xgbe_prv_data *pdata)
280bd8255d8SLendacky, Thomas {
281bd8255d8SLendacky, Thomas 	struct platform_device *phy_pdev;
282bd8255d8SLendacky, Thomas 
283bd8255d8SLendacky, Thomas 	if (pdata->use_acpi) {
284bd8255d8SLendacky, Thomas 		get_device(pdata->dev);
285bd8255d8SLendacky, Thomas 		phy_pdev = pdata->platdev;
286bd8255d8SLendacky, Thomas 	} else {
287bd8255d8SLendacky, Thomas 		phy_pdev = xgbe_of_get_phy_pdev(pdata);
288bd8255d8SLendacky, Thomas 	}
289bd8255d8SLendacky, Thomas 
290bd8255d8SLendacky, Thomas 	return phy_pdev;
291bd8255d8SLendacky, Thomas }
292bd8255d8SLendacky, Thomas 
xgbe_get_vdata(struct xgbe_prv_data * pdata)293bd8255d8SLendacky, Thomas static struct xgbe_version_data *xgbe_get_vdata(struct xgbe_prv_data *pdata)
294bd8255d8SLendacky, Thomas {
295bd8255d8SLendacky, Thomas 	return pdata->use_acpi ? xgbe_acpi_vdata(pdata)
296bd8255d8SLendacky, Thomas 			       : xgbe_of_vdata(pdata);
297bd8255d8SLendacky, Thomas }
298bd8255d8SLendacky, Thomas 
xgbe_platform_probe(struct platform_device * pdev)299bd8255d8SLendacky, Thomas static int xgbe_platform_probe(struct platform_device *pdev)
300bd8255d8SLendacky, Thomas {
301bd8255d8SLendacky, Thomas 	struct xgbe_prv_data *pdata;
302bd8255d8SLendacky, Thomas 	struct device *dev = &pdev->dev;
303bd8255d8SLendacky, Thomas 	struct platform_device *phy_pdev;
304bd8255d8SLendacky, Thomas 	const char *phy_mode;
305bd8255d8SLendacky, Thomas 	unsigned int phy_memnum, phy_irqnum;
306bd8255d8SLendacky, Thomas 	unsigned int dma_irqnum, dma_irqend;
307bd8255d8SLendacky, Thomas 	enum dev_dma_attr attr;
308bd8255d8SLendacky, Thomas 	int ret;
309bd8255d8SLendacky, Thomas 
310bd8255d8SLendacky, Thomas 	pdata = xgbe_alloc_pdata(dev);
311bd8255d8SLendacky, Thomas 	if (IS_ERR(pdata)) {
312bd8255d8SLendacky, Thomas 		ret = PTR_ERR(pdata);
313bd8255d8SLendacky, Thomas 		goto err_alloc;
314bd8255d8SLendacky, Thomas 	}
315bd8255d8SLendacky, Thomas 
316bd8255d8SLendacky, Thomas 	pdata->platdev = pdev;
317bd8255d8SLendacky, Thomas 	pdata->adev = ACPI_COMPANION(dev);
318bd8255d8SLendacky, Thomas 	platform_set_drvdata(pdev, pdata);
319bd8255d8SLendacky, Thomas 
320bd8255d8SLendacky, Thomas 	/* Check if we should use ACPI or DT */
321bd8255d8SLendacky, Thomas 	pdata->use_acpi = dev->of_node ? 0 : 1;
322bd8255d8SLendacky, Thomas 
323bd8255d8SLendacky, Thomas 	/* Get the version data */
324bd8255d8SLendacky, Thomas 	pdata->vdata = xgbe_get_vdata(pdata);
325bd8255d8SLendacky, Thomas 
326bd8255d8SLendacky, Thomas 	phy_pdev = xgbe_get_phy_pdev(pdata);
327bd8255d8SLendacky, Thomas 	if (!phy_pdev) {
328bd8255d8SLendacky, Thomas 		dev_err(dev, "unable to obtain phy device\n");
329bd8255d8SLendacky, Thomas 		ret = -EINVAL;
330bd8255d8SLendacky, Thomas 		goto err_phydev;
331bd8255d8SLendacky, Thomas 	}
332bd8255d8SLendacky, Thomas 	pdata->phy_platdev = phy_pdev;
333bd8255d8SLendacky, Thomas 	pdata->phy_dev = &phy_pdev->dev;
334bd8255d8SLendacky, Thomas 
335bd8255d8SLendacky, Thomas 	if (pdev == phy_pdev) {
336bd8255d8SLendacky, Thomas 		/* New style device tree or ACPI:
337bd8255d8SLendacky, Thomas 		 *   The XGBE and PHY resources are grouped together with
338bd8255d8SLendacky, Thomas 		 *   the PHY resources listed last
339bd8255d8SLendacky, Thomas 		 */
340bd8255d8SLendacky, Thomas 		phy_memnum = xgbe_resource_count(pdev, IORESOURCE_MEM) - 3;
341*884c65e4SJean-Philippe Brucker 		phy_irqnum = platform_irq_count(pdev) - 1;
342bd8255d8SLendacky, Thomas 		dma_irqnum = 1;
343bd8255d8SLendacky, Thomas 		dma_irqend = phy_irqnum;
344bd8255d8SLendacky, Thomas 	} else {
345bd8255d8SLendacky, Thomas 		/* Old style device tree:
346bd8255d8SLendacky, Thomas 		 *   The XGBE and PHY resources are separate
347bd8255d8SLendacky, Thomas 		 */
348bd8255d8SLendacky, Thomas 		phy_memnum = 0;
349bd8255d8SLendacky, Thomas 		phy_irqnum = 0;
350bd8255d8SLendacky, Thomas 		dma_irqnum = 1;
351*884c65e4SJean-Philippe Brucker 		dma_irqend = platform_irq_count(pdev);
352bd8255d8SLendacky, Thomas 	}
353bd8255d8SLendacky, Thomas 
354bd8255d8SLendacky, Thomas 	/* Obtain the mmio areas for the device */
355eba39fd6SYueHaibing 	pdata->xgmac_regs = devm_platform_ioremap_resource(pdev, 0);
356bd8255d8SLendacky, Thomas 	if (IS_ERR(pdata->xgmac_regs)) {
357bd8255d8SLendacky, Thomas 		dev_err(dev, "xgmac ioremap failed\n");
358bd8255d8SLendacky, Thomas 		ret = PTR_ERR(pdata->xgmac_regs);
359bd8255d8SLendacky, Thomas 		goto err_io;
360bd8255d8SLendacky, Thomas 	}
361bd8255d8SLendacky, Thomas 	if (netif_msg_probe(pdata))
362bd8255d8SLendacky, Thomas 		dev_dbg(dev, "xgmac_regs = %p\n", pdata->xgmac_regs);
363bd8255d8SLendacky, Thomas 
364eba39fd6SYueHaibing 	pdata->xpcs_regs = devm_platform_ioremap_resource(pdev, 1);
365bd8255d8SLendacky, Thomas 	if (IS_ERR(pdata->xpcs_regs)) {
366bd8255d8SLendacky, Thomas 		dev_err(dev, "xpcs ioremap failed\n");
367bd8255d8SLendacky, Thomas 		ret = PTR_ERR(pdata->xpcs_regs);
368bd8255d8SLendacky, Thomas 		goto err_io;
369bd8255d8SLendacky, Thomas 	}
370bd8255d8SLendacky, Thomas 	if (netif_msg_probe(pdata))
371bd8255d8SLendacky, Thomas 		dev_dbg(dev, "xpcs_regs  = %p\n", pdata->xpcs_regs);
372bd8255d8SLendacky, Thomas 
373eba39fd6SYueHaibing 	pdata->rxtx_regs = devm_platform_ioremap_resource(phy_pdev,
374eba39fd6SYueHaibing 							  phy_memnum++);
375bd8255d8SLendacky, Thomas 	if (IS_ERR(pdata->rxtx_regs)) {
376bd8255d8SLendacky, Thomas 		dev_err(dev, "rxtx ioremap failed\n");
377bd8255d8SLendacky, Thomas 		ret = PTR_ERR(pdata->rxtx_regs);
378bd8255d8SLendacky, Thomas 		goto err_io;
379bd8255d8SLendacky, Thomas 	}
380bd8255d8SLendacky, Thomas 	if (netif_msg_probe(pdata))
381bd8255d8SLendacky, Thomas 		dev_dbg(dev, "rxtx_regs  = %p\n", pdata->rxtx_regs);
382bd8255d8SLendacky, Thomas 
383eba39fd6SYueHaibing 	pdata->sir0_regs = devm_platform_ioremap_resource(phy_pdev,
384eba39fd6SYueHaibing 							  phy_memnum++);
385bd8255d8SLendacky, Thomas 	if (IS_ERR(pdata->sir0_regs)) {
386bd8255d8SLendacky, Thomas 		dev_err(dev, "sir0 ioremap failed\n");
387bd8255d8SLendacky, Thomas 		ret = PTR_ERR(pdata->sir0_regs);
388bd8255d8SLendacky, Thomas 		goto err_io;
389bd8255d8SLendacky, Thomas 	}
390bd8255d8SLendacky, Thomas 	if (netif_msg_probe(pdata))
391bd8255d8SLendacky, Thomas 		dev_dbg(dev, "sir0_regs  = %p\n", pdata->sir0_regs);
392bd8255d8SLendacky, Thomas 
393eba39fd6SYueHaibing 	pdata->sir1_regs = devm_platform_ioremap_resource(phy_pdev,
394eba39fd6SYueHaibing 							  phy_memnum++);
395bd8255d8SLendacky, Thomas 	if (IS_ERR(pdata->sir1_regs)) {
396bd8255d8SLendacky, Thomas 		dev_err(dev, "sir1 ioremap failed\n");
397bd8255d8SLendacky, Thomas 		ret = PTR_ERR(pdata->sir1_regs);
398bd8255d8SLendacky, Thomas 		goto err_io;
399bd8255d8SLendacky, Thomas 	}
400bd8255d8SLendacky, Thomas 	if (netif_msg_probe(pdata))
401bd8255d8SLendacky, Thomas 		dev_dbg(dev, "sir1_regs  = %p\n", pdata->sir1_regs);
402bd8255d8SLendacky, Thomas 
403bd8255d8SLendacky, Thomas 	/* Retrieve the MAC address */
404bd8255d8SLendacky, Thomas 	ret = device_property_read_u8_array(dev, XGBE_MAC_ADDR_PROPERTY,
405bd8255d8SLendacky, Thomas 					    pdata->mac_addr,
406bd8255d8SLendacky, Thomas 					    sizeof(pdata->mac_addr));
407bd8255d8SLendacky, Thomas 	if (ret || !is_valid_ether_addr(pdata->mac_addr)) {
408bd8255d8SLendacky, Thomas 		dev_err(dev, "invalid %s property\n", XGBE_MAC_ADDR_PROPERTY);
409bd8255d8SLendacky, Thomas 		if (!ret)
410bd8255d8SLendacky, Thomas 			ret = -EINVAL;
411bd8255d8SLendacky, Thomas 		goto err_io;
412bd8255d8SLendacky, Thomas 	}
413bd8255d8SLendacky, Thomas 
414bd8255d8SLendacky, Thomas 	/* Retrieve the PHY mode - it must be "xgmii" */
415bd8255d8SLendacky, Thomas 	ret = device_property_read_string(dev, XGBE_PHY_MODE_PROPERTY,
416bd8255d8SLendacky, Thomas 					  &phy_mode);
417bd8255d8SLendacky, Thomas 	if (ret || strcmp(phy_mode, phy_modes(PHY_INTERFACE_MODE_XGMII))) {
418bd8255d8SLendacky, Thomas 		dev_err(dev, "invalid %s property\n", XGBE_PHY_MODE_PROPERTY);
419bd8255d8SLendacky, Thomas 		if (!ret)
420bd8255d8SLendacky, Thomas 			ret = -EINVAL;
421bd8255d8SLendacky, Thomas 		goto err_io;
422bd8255d8SLendacky, Thomas 	}
423bd8255d8SLendacky, Thomas 	pdata->phy_mode = PHY_INTERFACE_MODE_XGMII;
424bd8255d8SLendacky, Thomas 
425bd8255d8SLendacky, Thomas 	/* Check for per channel interrupt support */
4264c70dd8aSLendacky, Thomas 	if (device_property_present(dev, XGBE_DMA_IRQS_PROPERTY)) {
427bd8255d8SLendacky, Thomas 		pdata->per_channel_irq = 1;
4284c70dd8aSLendacky, Thomas 		pdata->channel_irq_mode = XGBE_IRQ_MODE_EDGE;
4294c70dd8aSLendacky, Thomas 	}
430bd8255d8SLendacky, Thomas 
431bd8255d8SLendacky, Thomas 	/* Obtain device settings unique to ACPI/OF */
432bd8255d8SLendacky, Thomas 	if (pdata->use_acpi)
433bd8255d8SLendacky, Thomas 		ret = xgbe_acpi_support(pdata);
434bd8255d8SLendacky, Thomas 	else
435bd8255d8SLendacky, Thomas 		ret = xgbe_of_support(pdata);
436bd8255d8SLendacky, Thomas 	if (ret)
437bd8255d8SLendacky, Thomas 		goto err_io;
438bd8255d8SLendacky, Thomas 
439bd8255d8SLendacky, Thomas 	/* Set the DMA coherency values */
440bd8255d8SLendacky, Thomas 	attr = device_get_dma_attr(dev);
441bd8255d8SLendacky, Thomas 	if (attr == DEV_DMA_NOT_SUPPORTED) {
442bd8255d8SLendacky, Thomas 		dev_err(dev, "DMA is not supported");
443bd8255d8SLendacky, Thomas 		ret = -ENODEV;
444bd8255d8SLendacky, Thomas 		goto err_io;
445bd8255d8SLendacky, Thomas 	}
446bd8255d8SLendacky, Thomas 	pdata->coherent = (attr == DEV_DMA_COHERENT);
447bd8255d8SLendacky, Thomas 	if (pdata->coherent) {
4489916716aSLendacky, Thomas 		pdata->arcr = XGBE_DMA_OS_ARCR;
4499916716aSLendacky, Thomas 		pdata->awcr = XGBE_DMA_OS_AWCR;
450bd8255d8SLendacky, Thomas 	} else {
4519916716aSLendacky, Thomas 		pdata->arcr = XGBE_DMA_SYS_ARCR;
4529916716aSLendacky, Thomas 		pdata->awcr = XGBE_DMA_SYS_AWCR;
453bd8255d8SLendacky, Thomas 	}
454bd8255d8SLendacky, Thomas 
455bd8255d8SLendacky, Thomas 	/* Set the maximum fifo amounts */
456bd8255d8SLendacky, Thomas 	pdata->tx_max_fifo_size = pdata->vdata->tx_max_fifo_size;
457bd8255d8SLendacky, Thomas 	pdata->rx_max_fifo_size = pdata->vdata->rx_max_fifo_size;
458bd8255d8SLendacky, Thomas 
459bd8255d8SLendacky, Thomas 	/* Set the hardware channel and queue counts */
460bd8255d8SLendacky, Thomas 	xgbe_set_counts(pdata);
461bd8255d8SLendacky, Thomas 
46247f164deSLendacky, Thomas 	/* Always have XGMAC and XPCS (auto-negotiation) interrupts */
46347f164deSLendacky, Thomas 	pdata->irq_count = 2;
46447f164deSLendacky, Thomas 
465bd8255d8SLendacky, Thomas 	/* Get the device interrupt */
466bd8255d8SLendacky, Thomas 	ret = platform_get_irq(pdev, 0);
467d1a55841SStephen Boyd 	if (ret < 0)
468bd8255d8SLendacky, Thomas 		goto err_io;
469bd8255d8SLendacky, Thomas 	pdata->dev_irq = ret;
470bd8255d8SLendacky, Thomas 
471bd8255d8SLendacky, Thomas 	/* Get the per channel DMA interrupts */
472bd8255d8SLendacky, Thomas 	if (pdata->per_channel_irq) {
473bd8255d8SLendacky, Thomas 		unsigned int i, max = ARRAY_SIZE(pdata->channel_irq);
474bd8255d8SLendacky, Thomas 
475bd8255d8SLendacky, Thomas 		for (i = 0; (i < max) && (dma_irqnum < dma_irqend); i++) {
476bd8255d8SLendacky, Thomas 			ret = platform_get_irq(pdata->platdev, dma_irqnum++);
477d1a55841SStephen Boyd 			if (ret < 0)
478bd8255d8SLendacky, Thomas 				goto err_io;
479bd8255d8SLendacky, Thomas 
480bd8255d8SLendacky, Thomas 			pdata->channel_irq[i] = ret;
481bd8255d8SLendacky, Thomas 		}
48247f164deSLendacky, Thomas 
48347f164deSLendacky, Thomas 		pdata->channel_irq_count = max;
48447f164deSLendacky, Thomas 
48547f164deSLendacky, Thomas 		pdata->irq_count += max;
486bd8255d8SLendacky, Thomas 	}
487bd8255d8SLendacky, Thomas 
488bd8255d8SLendacky, Thomas 	/* Get the auto-negotiation interrupt */
489bd8255d8SLendacky, Thomas 	ret = platform_get_irq(phy_pdev, phy_irqnum++);
490d1a55841SStephen Boyd 	if (ret < 0)
491bd8255d8SLendacky, Thomas 		goto err_io;
492bd8255d8SLendacky, Thomas 	pdata->an_irq = ret;
493bd8255d8SLendacky, Thomas 
494bd8255d8SLendacky, Thomas 	/* Configure the netdev resource */
495bd8255d8SLendacky, Thomas 	ret = xgbe_config_netdev(pdata);
496bd8255d8SLendacky, Thomas 	if (ret)
497bd8255d8SLendacky, Thomas 		goto err_io;
498bd8255d8SLendacky, Thomas 
499bd8255d8SLendacky, Thomas 	netdev_notice(pdata->netdev, "net device enabled\n");
500bd8255d8SLendacky, Thomas 
501bd8255d8SLendacky, Thomas 	return 0;
502bd8255d8SLendacky, Thomas 
503bd8255d8SLendacky, Thomas err_io:
504bd8255d8SLendacky, Thomas 	platform_device_put(phy_pdev);
505bd8255d8SLendacky, Thomas 
506bd8255d8SLendacky, Thomas err_phydev:
507bd8255d8SLendacky, Thomas 	xgbe_free_pdata(pdata);
508bd8255d8SLendacky, Thomas 
509bd8255d8SLendacky, Thomas err_alloc:
510bd8255d8SLendacky, Thomas 	dev_notice(dev, "net device not enabled\n");
511bd8255d8SLendacky, Thomas 
512bd8255d8SLendacky, Thomas 	return ret;
513bd8255d8SLendacky, Thomas }
514bd8255d8SLendacky, Thomas 
xgbe_platform_remove(struct platform_device * pdev)515bd8255d8SLendacky, Thomas static int xgbe_platform_remove(struct platform_device *pdev)
516bd8255d8SLendacky, Thomas {
517bd8255d8SLendacky, Thomas 	struct xgbe_prv_data *pdata = platform_get_drvdata(pdev);
518bd8255d8SLendacky, Thomas 
519bd8255d8SLendacky, Thomas 	xgbe_deconfig_netdev(pdata);
520bd8255d8SLendacky, Thomas 
521bd8255d8SLendacky, Thomas 	platform_device_put(pdata->phy_platdev);
522bd8255d8SLendacky, Thomas 
523bd8255d8SLendacky, Thomas 	xgbe_free_pdata(pdata);
524bd8255d8SLendacky, Thomas 
525bd8255d8SLendacky, Thomas 	return 0;
526bd8255d8SLendacky, Thomas }
527bd8255d8SLendacky, Thomas 
5282745529aSDavid S. Miller #ifdef CONFIG_PM_SLEEP
xgbe_platform_suspend(struct device * dev)529bd8255d8SLendacky, Thomas static int xgbe_platform_suspend(struct device *dev)
530bd8255d8SLendacky, Thomas {
531bd8255d8SLendacky, Thomas 	struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
532bd8255d8SLendacky, Thomas 	struct net_device *netdev = pdata->netdev;
533bd8255d8SLendacky, Thomas 	int ret = 0;
534bd8255d8SLendacky, Thomas 
535bd8255d8SLendacky, Thomas 	DBGPR("-->xgbe_suspend\n");
536bd8255d8SLendacky, Thomas 
537bd8255d8SLendacky, Thomas 	if (netif_running(netdev))
538bd8255d8SLendacky, Thomas 		ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT);
539bd8255d8SLendacky, Thomas 
540bd8255d8SLendacky, Thomas 	pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
541bd8255d8SLendacky, Thomas 	pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER;
542bd8255d8SLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
543bd8255d8SLendacky, Thomas 
544bd8255d8SLendacky, Thomas 	DBGPR("<--xgbe_suspend\n");
545bd8255d8SLendacky, Thomas 
546bd8255d8SLendacky, Thomas 	return ret;
547bd8255d8SLendacky, Thomas }
548bd8255d8SLendacky, Thomas 
xgbe_platform_resume(struct device * dev)549bd8255d8SLendacky, Thomas static int xgbe_platform_resume(struct device *dev)
550bd8255d8SLendacky, Thomas {
551bd8255d8SLendacky, Thomas 	struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
552bd8255d8SLendacky, Thomas 	struct net_device *netdev = pdata->netdev;
553bd8255d8SLendacky, Thomas 	int ret = 0;
554bd8255d8SLendacky, Thomas 
555bd8255d8SLendacky, Thomas 	DBGPR("-->xgbe_resume\n");
556bd8255d8SLendacky, Thomas 
557bd8255d8SLendacky, Thomas 	pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER;
558bd8255d8SLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
559bd8255d8SLendacky, Thomas 
560bd8255d8SLendacky, Thomas 	if (netif_running(netdev)) {
561bd8255d8SLendacky, Thomas 		ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT);
562bd8255d8SLendacky, Thomas 
563bd8255d8SLendacky, Thomas 		/* Schedule a restart in case the link or phy state changed
564bd8255d8SLendacky, Thomas 		 * while we were powered down.
565bd8255d8SLendacky, Thomas 		 */
566bd8255d8SLendacky, Thomas 		schedule_work(&pdata->restart_work);
567bd8255d8SLendacky, Thomas 	}
568bd8255d8SLendacky, Thomas 
569bd8255d8SLendacky, Thomas 	DBGPR("<--xgbe_resume\n");
570bd8255d8SLendacky, Thomas 
571bd8255d8SLendacky, Thomas 	return ret;
572bd8255d8SLendacky, Thomas }
5732745529aSDavid S. Miller #endif /* CONFIG_PM_SLEEP */
574bd8255d8SLendacky, Thomas 
575bd8255d8SLendacky, Thomas static const struct xgbe_version_data xgbe_v1 = {
576bd8255d8SLendacky, Thomas 	.init_function_ptrs_phy_impl	= xgbe_init_function_ptrs_phy_v1,
577bd8255d8SLendacky, Thomas 	.xpcs_access			= XGBE_XPCS_ACCESS_V1,
578bd8255d8SLendacky, Thomas 	.tx_max_fifo_size		= 81920,
579bd8255d8SLendacky, Thomas 	.rx_max_fifo_size		= 81920,
580aba9777aSLendacky, Thomas 	.tx_tstamp_workaround		= 1,
581bd8255d8SLendacky, Thomas };
582bd8255d8SLendacky, Thomas 
583bd8255d8SLendacky, Thomas #ifdef CONFIG_ACPI
584bd8255d8SLendacky, Thomas static const struct acpi_device_id xgbe_acpi_match[] = {
585bd8255d8SLendacky, Thomas 	{ .id = "AMDI8001",
586bd8255d8SLendacky, Thomas 	  .driver_data = (kernel_ulong_t)&xgbe_v1 },
587bd8255d8SLendacky, Thomas 	{},
588bd8255d8SLendacky, Thomas };
589bd8255d8SLendacky, Thomas 
590bd8255d8SLendacky, Thomas MODULE_DEVICE_TABLE(acpi, xgbe_acpi_match);
591bd8255d8SLendacky, Thomas #endif
592bd8255d8SLendacky, Thomas 
593bd8255d8SLendacky, Thomas #ifdef CONFIG_OF
594bd8255d8SLendacky, Thomas static const struct of_device_id xgbe_of_match[] = {
595bd8255d8SLendacky, Thomas 	{ .compatible = "amd,xgbe-seattle-v1a",
596bd8255d8SLendacky, Thomas 	  .data = &xgbe_v1 },
597bd8255d8SLendacky, Thomas 	{},
598bd8255d8SLendacky, Thomas };
599bd8255d8SLendacky, Thomas 
600bd8255d8SLendacky, Thomas MODULE_DEVICE_TABLE(of, xgbe_of_match);
601bd8255d8SLendacky, Thomas #endif
602bd8255d8SLendacky, Thomas 
603bd8255d8SLendacky, Thomas static SIMPLE_DEV_PM_OPS(xgbe_platform_pm_ops,
604bd8255d8SLendacky, Thomas 			 xgbe_platform_suspend, xgbe_platform_resume);
605bd8255d8SLendacky, Thomas 
606bd8255d8SLendacky, Thomas static struct platform_driver xgbe_driver = {
607bd8255d8SLendacky, Thomas 	.driver = {
60847f164deSLendacky, Thomas 		.name = XGBE_DRV_NAME,
609bd8255d8SLendacky, Thomas #ifdef CONFIG_ACPI
610bd8255d8SLendacky, Thomas 		.acpi_match_table = xgbe_acpi_match,
611bd8255d8SLendacky, Thomas #endif
612bd8255d8SLendacky, Thomas #ifdef CONFIG_OF
613bd8255d8SLendacky, Thomas 		.of_match_table = xgbe_of_match,
614bd8255d8SLendacky, Thomas #endif
615bd8255d8SLendacky, Thomas 		.pm = &xgbe_platform_pm_ops,
616bd8255d8SLendacky, Thomas 	},
617bd8255d8SLendacky, Thomas 	.probe = xgbe_platform_probe,
618bd8255d8SLendacky, Thomas 	.remove = xgbe_platform_remove,
619bd8255d8SLendacky, Thomas };
620bd8255d8SLendacky, Thomas 
xgbe_platform_init(void)621bd8255d8SLendacky, Thomas int xgbe_platform_init(void)
622bd8255d8SLendacky, Thomas {
623bd8255d8SLendacky, Thomas 	return platform_driver_register(&xgbe_driver);
624bd8255d8SLendacky, Thomas }
625bd8255d8SLendacky, Thomas 
xgbe_platform_exit(void)626bd8255d8SLendacky, Thomas void xgbe_platform_exit(void)
627bd8255d8SLendacky, Thomas {
628bd8255d8SLendacky, Thomas 	platform_driver_unregister(&xgbe_driver);
629bd8255d8SLendacky, Thomas }
630