xref: /freebsd/sys/dev/dwc/if_dwc_socfpga.c (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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/param.h>
34 #include <sys/systm.h>
35 #include <sys/bus.h>
36 #include <sys/kernel.h>
37 #include <sys/socket.h>
38 #include <sys/module.h>
39 
40 #include <net/if.h>
41 
42 #include <machine/bus.h>
43 
44 #include <dev/ofw/ofw_bus.h>
45 #include <dev/ofw/ofw_bus_subr.h>
46 
47 #include <dev/extres/clk/clk.h>
48 #include <dev/extres/hwreset/hwreset.h>
49 
50 #include <dev/dwc/if_dwcvar.h>
51 #include <dev/dwc/dwc1000_reg.h>
52 
53 #include "if_dwc_if.h"
54 
55 static int
56 if_dwc_socfpga_probe(device_t dev)
57 {
58 
59 	if (!ofw_bus_status_okay(dev))
60 		return (ENXIO);
61 
62 	if (!ofw_bus_is_compatible(dev, "altr,socfpga-stmmac"))
63 		return (ENXIO);
64 
65 	device_set_desc(dev, "Altera SOCFPGA Ethernet MAC");
66 
67 	return (BUS_PROBE_DEFAULT);
68 }
69 
70 static int
71 if_dwc_socfpga_init(device_t dev)
72 {
73 
74 	return (0);
75 }
76 
77 static int
78 if_dwc_socfpga_mii_clk(device_t dev)
79 {
80 	phandle_t root;
81 
82 	root = OF_finddevice("/");
83 
84 	if (ofw_bus_node_is_compatible(root, "altr,socfpga-stratix10"))
85 		return (GMAC_MII_CLK_35_60M_DIV26);
86 
87 	/* Default value. */
88 	return (GMAC_MII_CLK_25_35M_DIV16);
89 }
90 
91 static device_method_t dwc_socfpga_methods[] = {
92 	DEVMETHOD(device_probe,		if_dwc_socfpga_probe),
93 
94 	DEVMETHOD(if_dwc_init,		if_dwc_socfpga_init),
95 	DEVMETHOD(if_dwc_mii_clk,	if_dwc_socfpga_mii_clk),
96 
97 	DEVMETHOD_END
98 };
99 
100 extern driver_t dwc_driver;
101 
102 DEFINE_CLASS_1(dwc, dwc_socfpga_driver, dwc_socfpga_methods,
103     sizeof(struct dwc_softc), dwc_driver);
104 EARLY_DRIVER_MODULE(dwc_socfpga, simplebus, dwc_socfpga_driver, 0, 0,
105     BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE);
106 
107 MODULE_DEPEND(dwc_socfpga, dwc, 1, 1, 1);
108