2 * Copyright (c) 2012 Semihalf.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/socket.h>
37 #include <powerpc/mpc85xx/mpc85xx.h>
40 #include <net/if_media.h>
42 #include <dev/mii/mii.h>
43 #include <dev/mii/miivar.h>
45 #include <dev/fdt/fdt_common.h>
46 #include <dev/ofw/ofw_bus.h>
47 #include <dev/ofw/ofw_bus_subr.h>
48 #include <dev/ofw/openfirm.h>
50 #include "miibus_if.h"
52 #include <contrib/ncsw/inc/Peripherals/fm_port_ext.h>
53 #include <contrib/ncsw/inc/xx_ext.h>
58 static int dtsec_fdt_probe(device_t dev);
59 static int dtsec_fdt_attach(device_t dev);
61 static device_method_t dtsec_methods[] = {
62 /* Device interface */
63 DEVMETHOD(device_probe, dtsec_fdt_probe),
64 DEVMETHOD(device_attach, dtsec_fdt_attach),
65 DEVMETHOD(device_detach, dtsec_detach),
67 DEVMETHOD(device_shutdown, dtsec_shutdown),
68 DEVMETHOD(device_suspend, dtsec_suspend),
69 DEVMETHOD(device_resume, dtsec_resume),
72 DEVMETHOD(bus_print_child, bus_generic_print_child),
73 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
76 DEVMETHOD(miibus_readreg, dtsec_miibus_readreg),
77 DEVMETHOD(miibus_writereg, dtsec_miibus_writereg),
78 DEVMETHOD(miibus_statchg, dtsec_miibus_statchg),
83 static driver_t dtsec_driver = {
86 sizeof(struct dtsec_softc),
89 static devclass_t dtsec_devclass;
90 DRIVER_MODULE(dtsec, dpaa, dtsec_driver, dtsec_devclass, 0, 0);
91 DRIVER_MODULE(miibus, dtsec, miibus_driver, miibus_devclass, 0, 0);
92 MODULE_DEPEND(dtsec, ether, 1, 1, 1);
93 MODULE_DEPEND(dtsec, miibus, 1, 1, 1);
96 dtsec_fdt_probe(device_t dev)
99 if (!ofw_bus_is_compatible(dev, "fsl,dpa-ethernet"))
102 device_set_desc(dev, "Freescale Data Path Triple Speed Ethernet "
105 return (BUS_PROBE_DEFAULT);
109 dtsec_fdt_attach(device_t dev)
111 struct dtsec_softc *sc;
112 phandle_t node, enet_node, phy_node;
113 phandle_t fman_rxtx_node[2];
116 sc = device_get_softc(dev);
117 node = ofw_bus_get_node(dev);
119 if (OF_getprop(node, "fsl,fman-mac", (void *)&enet_node,
120 sizeof(enet_node)) == -1) {
121 device_printf(dev, "Could not load fsl,fman-mac property "
126 enet_node = OF_instance_to_package(enet_node);
128 if (OF_getprop(enet_node, "local-mac-address",
129 (void *)sc->sc_mac_addr, 6) == -1) {
130 if (device_get_unit(dev) != 0) {
132 "Could not load local-mac-addr property "
136 sc->sc_hidden = true;
140 if (fdt_is_compatible(enet_node, "fsl,fman-1g-mac") != 0)
141 sc->sc_eth_dev_type = ETH_DTSEC;
142 else if (fdt_is_compatible(enet_node, "fsl,fman-10g-mac") != 0)
143 sc->sc_eth_dev_type = ETH_10GSEC;
147 /* Get MAC memory offset in SoC */
148 if (OF_getprop(enet_node, "reg", (void *)&sc->sc_mac_mem_offset,
149 sizeof(sc->sc_mac_mem_offset)) <= 0)
152 /* Get PHY address */
153 if (OF_getprop(enet_node, "phy-handle", (void *)&phy_node,
154 sizeof(phy_node)) <= 0)
157 phy_node = OF_instance_to_package(phy_node);
159 if (OF_getprop(phy_node, "reg", (void *)&sc->sc_phy_addr,
160 sizeof(sc->sc_phy_addr)) <= 0)
163 /* Get PHY connection type */
164 if (OF_getprop(enet_node, "phy-connection-type", (void *)phy_type,
165 sizeof(phy_type)) <= 0)
168 if (!strcmp(phy_type, "sgmii"))
169 sc->sc_mac_enet_mode = e_ENET_MODE_SGMII_1000;
170 else if (!strcmp(phy_type, "rgmii"))
171 sc->sc_mac_enet_mode = e_ENET_MODE_RGMII_1000;
172 else if (!strcmp(phy_type, "xgmii"))
173 /* We set 10 Gigabit mode flag however we don't support it */
174 sc->sc_mac_enet_mode = e_ENET_MODE_XGMII_10000;
178 /* Get RX/TX port handles */
179 if (OF_getprop(enet_node, "fsl,port-handles", (void *)fman_rxtx_node,
180 sizeof(fman_rxtx_node)) <= 0)
183 if (fman_rxtx_node[0] == 0)
186 if (fman_rxtx_node[1] == 0)
189 fman_rxtx_node[0] = OF_instance_to_package(fman_rxtx_node[0]);
190 fman_rxtx_node[1] = OF_instance_to_package(fman_rxtx_node[1]);
192 if (fdt_is_compatible(fman_rxtx_node[0], "fsl,fman-port-1g-rx") == 0)
195 if (fdt_is_compatible(fman_rxtx_node[1], "fsl,fman-port-1g-tx") == 0)
198 /* Get RX port HW id */
199 if (OF_getprop(fman_rxtx_node[0], "reg", (void *)&sc->sc_port_rx_hw_id,
200 sizeof(sc->sc_port_rx_hw_id)) <= 0)
203 /* Get TX port HW id */
204 if (OF_getprop(fman_rxtx_node[1], "reg", (void *)&sc->sc_port_tx_hw_id,
205 sizeof(sc->sc_port_tx_hw_id)) <= 0)
208 /* Get QMan channel */
209 if (OF_getprop(fman_rxtx_node[1], "fsl,qman-channel-id",
210 (void *)&sc->sc_port_tx_qman_chan,
211 sizeof(sc->sc_port_tx_qman_chan)) <= 0)
214 return (dtsec_attach(dev));