xref: /freebsd-src/sys/dev/dwc/if_dwc_socfpga.c (revision 1f469a9fc498c3d406ef7c4e347232678f49da0a)
1432ae724SEmmanuel Vadot /*-
2432ae724SEmmanuel Vadot  * SPDX-License-Identifier: BSD-2-Clause
3432ae724SEmmanuel Vadot  *
4432ae724SEmmanuel Vadot  * Copyright (c) 2019 Ruslan Bukin <br@bsdpad.com>
5432ae724SEmmanuel Vadot  *
6432ae724SEmmanuel Vadot  * This software was developed by SRI International and the University of
7432ae724SEmmanuel Vadot  * Cambridge Computer Laboratory (Department of Computer Science and
8432ae724SEmmanuel Vadot  * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
9432ae724SEmmanuel Vadot  * DARPA SSITH research programme.
10432ae724SEmmanuel Vadot  *
11432ae724SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
12432ae724SEmmanuel Vadot  * modification, are permitted provided that the following conditions
13432ae724SEmmanuel Vadot  * are met:
14432ae724SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
15432ae724SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
16432ae724SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
17432ae724SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
18432ae724SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
19432ae724SEmmanuel Vadot  *
20432ae724SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21432ae724SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22432ae724SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23432ae724SEmmanuel Vadot  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24432ae724SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25432ae724SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26432ae724SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27432ae724SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28432ae724SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29432ae724SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30432ae724SEmmanuel Vadot  * SUCH DAMAGE.
31432ae724SEmmanuel Vadot  */
32432ae724SEmmanuel Vadot 
33432ae724SEmmanuel Vadot #include <sys/param.h>
34432ae724SEmmanuel Vadot #include <sys/systm.h>
35432ae724SEmmanuel Vadot #include <sys/bus.h>
36432ae724SEmmanuel Vadot #include <sys/kernel.h>
37432ae724SEmmanuel Vadot #include <sys/socket.h>
38432ae724SEmmanuel Vadot #include <sys/module.h>
39432ae724SEmmanuel Vadot 
40432ae724SEmmanuel Vadot #include <net/if.h>
41432ae724SEmmanuel Vadot 
42432ae724SEmmanuel Vadot #include <machine/bus.h>
43432ae724SEmmanuel Vadot 
44c36125f6SEmmanuel Vadot #include <dev/ofw/ofw_bus.h>
45c36125f6SEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h>
46c36125f6SEmmanuel Vadot 
47be82b3a0SEmmanuel Vadot #include <dev/clk/clk.h>
48*1f469a9fSEmmanuel Vadot #include <dev/hwreset/hwreset.h>
4950059a60SEmmanuel Vadot 
50432ae724SEmmanuel Vadot #include <dev/dwc/if_dwcvar.h>
51c36125f6SEmmanuel Vadot #include <dev/dwc/dwc1000_reg.h>
52432ae724SEmmanuel Vadot 
53432ae724SEmmanuel Vadot #include "if_dwc_if.h"
54432ae724SEmmanuel Vadot 
55432ae724SEmmanuel Vadot static int
if_dwc_socfpga_probe(device_t dev)56432ae724SEmmanuel Vadot if_dwc_socfpga_probe(device_t dev)
57432ae724SEmmanuel Vadot {
58432ae724SEmmanuel Vadot 
59432ae724SEmmanuel Vadot 	if (!ofw_bus_status_okay(dev))
60432ae724SEmmanuel Vadot 		return (ENXIO);
61432ae724SEmmanuel Vadot 
62432ae724SEmmanuel Vadot 	if (!ofw_bus_is_compatible(dev, "altr,socfpga-stmmac"))
63432ae724SEmmanuel Vadot 		return (ENXIO);
64432ae724SEmmanuel Vadot 
65432ae724SEmmanuel Vadot 	device_set_desc(dev, "Altera SOCFPGA Ethernet MAC");
66432ae724SEmmanuel Vadot 
67432ae724SEmmanuel Vadot 	return (BUS_PROBE_DEFAULT);
68432ae724SEmmanuel Vadot }
69432ae724SEmmanuel Vadot 
70432ae724SEmmanuel Vadot static int
if_dwc_socfpga_init(device_t dev)71432ae724SEmmanuel Vadot if_dwc_socfpga_init(device_t dev)
72432ae724SEmmanuel Vadot {
73432ae724SEmmanuel Vadot 
74432ae724SEmmanuel Vadot 	return (0);
75432ae724SEmmanuel Vadot }
76432ae724SEmmanuel Vadot 
77432ae724SEmmanuel Vadot static int
if_dwc_socfpga_mii_clk(device_t dev)78432ae724SEmmanuel Vadot if_dwc_socfpga_mii_clk(device_t dev)
79432ae724SEmmanuel Vadot {
80432ae724SEmmanuel Vadot 	phandle_t root;
81432ae724SEmmanuel Vadot 
82432ae724SEmmanuel Vadot 	root = OF_finddevice("/");
83432ae724SEmmanuel Vadot 
84432ae724SEmmanuel Vadot 	if (ofw_bus_node_is_compatible(root, "altr,socfpga-stratix10"))
85432ae724SEmmanuel Vadot 		return (GMAC_MII_CLK_35_60M_DIV26);
86432ae724SEmmanuel Vadot 
87432ae724SEmmanuel Vadot 	/* Default value. */
88432ae724SEmmanuel Vadot 	return (GMAC_MII_CLK_25_35M_DIV16);
89432ae724SEmmanuel Vadot }
90432ae724SEmmanuel Vadot 
91432ae724SEmmanuel Vadot static device_method_t dwc_socfpga_methods[] = {
92432ae724SEmmanuel Vadot 	DEVMETHOD(device_probe,		if_dwc_socfpga_probe),
93432ae724SEmmanuel Vadot 
94432ae724SEmmanuel Vadot 	DEVMETHOD(if_dwc_init,		if_dwc_socfpga_init),
95432ae724SEmmanuel Vadot 	DEVMETHOD(if_dwc_mii_clk,	if_dwc_socfpga_mii_clk),
96432ae724SEmmanuel Vadot 
97432ae724SEmmanuel Vadot 	DEVMETHOD_END
98432ae724SEmmanuel Vadot };
99432ae724SEmmanuel Vadot 
100432ae724SEmmanuel Vadot extern driver_t dwc_driver;
101432ae724SEmmanuel Vadot 
102432ae724SEmmanuel Vadot DEFINE_CLASS_1(dwc, dwc_socfpga_driver, dwc_socfpga_methods,
103432ae724SEmmanuel Vadot     sizeof(struct dwc_softc), dwc_driver);
104432ae724SEmmanuel Vadot EARLY_DRIVER_MODULE(dwc_socfpga, simplebus, dwc_socfpga_driver, 0, 0,
105432ae724SEmmanuel Vadot     BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE);
106432ae724SEmmanuel Vadot 
107432ae724SEmmanuel Vadot MODULE_DEPEND(dwc_socfpga, dwc, 1, 1, 1);
108