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/dwc/if_dwc.h> 46 #include <dev/dwc/if_dwcvar.h> 47 #include <dev/ofw/ofw_bus.h> 48 #include <dev/ofw/ofw_bus_subr.h> 49 50 #include "if_dwc_if.h" 51 52 static int 53 if_dwc_socfpga_probe(device_t dev) 54 { 55 56 if (!ofw_bus_status_okay(dev)) 57 return (ENXIO); 58 59 if (!ofw_bus_is_compatible(dev, "altr,socfpga-stmmac")) 60 return (ENXIO); 61 62 device_set_desc(dev, "Altera SOCFPGA Ethernet MAC"); 63 64 return (BUS_PROBE_DEFAULT); 65 } 66 67 static int 68 if_dwc_socfpga_init(device_t dev) 69 { 70 71 return (0); 72 } 73 74 static int 75 if_dwc_socfpga_mac_type(device_t dev) 76 { 77 78 return (DWC_GMAC_EXT_DESC); 79 } 80 81 static int 82 if_dwc_socfpga_mii_clk(device_t dev) 83 { 84 phandle_t root; 85 86 root = OF_finddevice("/"); 87 88 if (ofw_bus_node_is_compatible(root, "altr,socfpga-stratix10")) 89 return (GMAC_MII_CLK_35_60M_DIV26); 90 91 /* Default value. */ 92 return (GMAC_MII_CLK_25_35M_DIV16); 93 } 94 95 static device_method_t dwc_socfpga_methods[] = { 96 DEVMETHOD(device_probe, if_dwc_socfpga_probe), 97 98 DEVMETHOD(if_dwc_init, if_dwc_socfpga_init), 99 DEVMETHOD(if_dwc_mac_type, if_dwc_socfpga_mac_type), 100 DEVMETHOD(if_dwc_mii_clk, if_dwc_socfpga_mii_clk), 101 102 DEVMETHOD_END 103 }; 104 105 extern driver_t dwc_driver; 106 107 DEFINE_CLASS_1(dwc, dwc_socfpga_driver, dwc_socfpga_methods, 108 sizeof(struct dwc_softc), dwc_driver); 109 EARLY_DRIVER_MODULE(dwc_socfpga, simplebus, dwc_socfpga_driver, 0, 0, 110 BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE); 111 112 MODULE_DEPEND(dwc_socfpga, dwc, 1, 1, 1); 113