2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 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 <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
41 #include <sys/socket.h>
42 #include <sys/systm.h>
44 #include <machine/bus.h>
45 #include <machine/resource.h>
47 #include <net/ethernet.h>
49 #include <net/if_media.h>
50 #include <net/if_var.h>
52 #include <dev/mii/mii.h>
53 #include <dev/mii/miivar.h>
55 #include <dev/fdt/fdt_common.h>
56 #include <dev/ofw/openfirm.h>
57 #include <dev/ofw/ofw_bus.h>
58 #include <dev/ofw/ofw_bus_subr.h>
60 #include <dev/altera/atse/if_atsereg.h>
62 /* "device miibus" required. See GENERIC if you get errors here. */
63 #include "miibus_if.h"
66 atse_probe_fdt(device_t dev)
69 if (!ofw_bus_status_okay(dev))
72 if (!ofw_bus_is_compatible(dev, "altera,atse")) {
76 device_set_desc(dev, "Altera Triple-Speed Ethernet MegaCore");
78 return (BUS_PROBE_DEFAULT);
82 atse_attach_fdt(device_t dev)
84 struct atse_softc *sc;
87 sc = device_get_softc(dev);
89 sc->atse_unit = device_get_unit(dev);
92 * FDT has the list of our resources. Given we are using multiple
93 * memory regions and possibly multiple interrupts, we need to attach
94 * them in the order specified in .dts:
95 * MAC, RX and RXC FIFO, TX and TXC FIFO; RX INTR, TX INTR.
98 /* MAC: Avalon-MM, atse management register region. */
100 sc->atse_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
101 &sc->atse_mem_rid, RF_ACTIVE);
102 if (sc->atse_mem_res == NULL) {
103 device_printf(dev, "failed to map memory for ctrl region\n");
105 atse_detach_resources(dev);
110 device_printf(sc->atse_dev, "MAC ctrl region at mem %p-%p\n",
111 (void *)rman_get_start(sc->atse_mem_res),
112 (void *)(rman_get_start(sc->atse_mem_res) +
113 rman_get_size(sc->atse_mem_res)));
115 error = atse_attach(dev);
118 atse_detach_resources(dev);
126 static device_method_t atse_methods_fdt[] = {
127 /* Device interface */
128 DEVMETHOD(device_probe, atse_probe_fdt),
129 DEVMETHOD(device_attach, atse_attach_fdt),
130 DEVMETHOD(device_detach, atse_detach_dev),
133 DEVMETHOD(miibus_readreg, atse_miibus_readreg),
134 DEVMETHOD(miibus_writereg, atse_miibus_writereg),
135 DEVMETHOD(miibus_statchg, atse_miibus_statchg),
140 static driver_t atse_driver_fdt = {
143 sizeof(struct atse_softc)
146 DRIVER_MODULE(atse, simplebus, atse_driver_fdt, atse_devclass, 0, 0);
147 DRIVER_MODULE(miibus, atse, miibus_driver, miibus_devclass, 0, 0);