2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012,2013 Bjoern A. Zeeb
7 * This software was developed by SRI International and the University of
8 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-11-C-0249)
9 * ("MRC2"), as part of the DARPA MRC research programme.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include "opt_device_polling.h"
38 #include <sys/param.h>
39 #include <sys/kernel.h>
41 #include <sys/module.h>
43 #include <sys/socket.h>
44 #include <sys/types.h>
46 #include <machine/bus.h>
47 #include <machine/resource.h>
49 #include <net/ethernet.h>
51 #include <net/if_media.h>
52 #include <net/if_var.h>
54 #include <dev/mii/mii.h>
55 #include <dev/mii/miivar.h>
57 #include <dev/altera/atse/if_atsereg.h>
59 /* "device miibus" required. See GENERIC if you get errors here. */
60 #include "miibus_if.h"
62 MODULE_DEPEND(atse, ether, 1, 1, 1);
63 MODULE_DEPEND(atse, miibus, 1, 1, 1);
66 * Device routines for interacting with nexus (probe, attach, detach) & helpers.
67 * XXX We should add suspend/resume later.
70 atse_resource_int(device_t dev, const char *resname, int *v)
74 error = resource_int_value(device_get_name(dev), device_get_unit(dev),
77 /* If it does not exist, we fail, so not ingoring ENOENT. */
78 device_printf(dev, "could not fetch '%s' hint\n", resname);
86 atse_resource_long(device_t dev, const char *resname, long *v)
90 error = resource_long_value(device_get_name(dev), device_get_unit(dev),
93 /* If it does not exist, we fail, so not ingoring ENOENT. */
94 device_printf(dev, "could not fetch '%s' hint\n", resname);
102 atse_probe_nexus(device_t dev)
105 device_set_desc(dev, "Altera Triple-Speed Ethernet MegaCore");
107 return (BUS_PROBE_NOWILDCARD);
111 atse_attach_nexus(device_t dev)
113 struct atse_softc *sc;
116 sc = device_get_softc(dev);
118 sc->atse_unit = device_get_unit(dev);
120 /* Avalon-MM, atse management register region. */
121 sc->atse_mem_rid = 0;
122 sc->atse_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
123 &sc->atse_mem_rid, RF_ACTIVE);
124 if (sc->atse_mem_res == NULL) {
125 device_printf(dev, "failed to map memory for ctrl region\n");
129 error = atse_attach(dev);
132 atse_detach_resources(dev);
139 static device_method_t atse_methods_nexus[] = {
140 /* Device interface */
141 DEVMETHOD(device_probe, atse_probe_nexus),
142 DEVMETHOD(device_attach, atse_attach_nexus),
143 DEVMETHOD(device_detach, atse_detach_dev),
146 DEVMETHOD(miibus_readreg, atse_miibus_readreg),
147 DEVMETHOD(miibus_writereg, atse_miibus_writereg),
148 DEVMETHOD(miibus_statchg, atse_miibus_statchg),
153 static driver_t atse_driver_nexus = {
156 sizeof(struct atse_softc)
159 DRIVER_MODULE(atse, nexus, atse_driver_nexus, atse_devclass, 0, 0);
160 DRIVER_MODULE(miibus, atse, miibus_driver, miibus_devclass, 0, 0);