xref: /freebsd/sys/dev/dwc/if_dwc_socfpga.c (revision 608da65de9552d5678c1000776ed69da04a45983)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2019 Ruslan Bukin <br@bsdpad.com>
5  *
6  * This software was developed by SRI International and the University of
7  * Cambridge Computer Laboratory (Department of Computer Science and
8  * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
9  * DARPA SSITH research programme.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/bus.h>
37 #include <sys/kernel.h>
38 #include <sys/socket.h>
39 #include <sys/module.h>
40 
41 #include <net/if.h>
42 
43 #include <machine/bus.h>
44 
45 #include <dev/ofw/ofw_bus.h>
46 #include <dev/ofw/ofw_bus_subr.h>
47 
48 #include <dev/extres/clk/clk.h>
49 #include <dev/extres/hwreset/hwreset.h>
50 
51 #include <dev/dwc/if_dwcvar.h>
52 #include <dev/dwc/dwc1000_reg.h>
53 
54 #include "if_dwc_if.h"
55 
56 static int
57 if_dwc_socfpga_probe(device_t dev)
58 {
59 
60 	if (!ofw_bus_status_okay(dev))
61 		return (ENXIO);
62 
63 	if (!ofw_bus_is_compatible(dev, "altr,socfpga-stmmac"))
64 		return (ENXIO);
65 
66 	device_set_desc(dev, "Altera SOCFPGA Ethernet MAC");
67 
68 	return (BUS_PROBE_DEFAULT);
69 }
70 
71 static int
72 if_dwc_socfpga_init(device_t dev)
73 {
74 
75 	return (0);
76 }
77 
78 static int
79 if_dwc_socfpga_mii_clk(device_t dev)
80 {
81 	phandle_t root;
82 
83 	root = OF_finddevice("/");
84 
85 	if (ofw_bus_node_is_compatible(root, "altr,socfpga-stratix10"))
86 		return (GMAC_MII_CLK_35_60M_DIV26);
87 
88 	/* Default value. */
89 	return (GMAC_MII_CLK_25_35M_DIV16);
90 }
91 
92 static device_method_t dwc_socfpga_methods[] = {
93 	DEVMETHOD(device_probe,		if_dwc_socfpga_probe),
94 
95 	DEVMETHOD(if_dwc_init,		if_dwc_socfpga_init),
96 	DEVMETHOD(if_dwc_mii_clk,	if_dwc_socfpga_mii_clk),
97 
98 	DEVMETHOD_END
99 };
100 
101 extern driver_t dwc_driver;
102 
103 DEFINE_CLASS_1(dwc, dwc_socfpga_driver, dwc_socfpga_methods,
104     sizeof(struct dwc_softc), dwc_driver);
105 EARLY_DRIVER_MODULE(dwc_socfpga, simplebus, dwc_socfpga_driver, 0, 0,
106     BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE);
107 
108 MODULE_DEPEND(dwc_socfpga, dwc, 1, 1, 1);
109