Lines Matching +full:hw +full:- +full:device +full:- +full:address
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 2007-2008 Semihalf, Rafal Jaworowski
5 * Copyright (C) 2006-2007 Semihalf, Piotr Kruszynski
28 * From: FreeBSD: head/sys/dev/tsec/if_tsec_ocp.c 188712 2009-02-17 14:59:47Z raj
32 * FDT 'simple-bus' attachment for Freescale TSEC controller.
80 /* Device interface */
125 * Device trees with "fsl,etsec2" compatible nodes don't have a reg in tsec_fdt_probe()
126 * property, as it's been relegated to the queue-group children. in tsec_fdt_probe()
129 sc->is_etsec = 1; in tsec_fdt_probe()
131 sc->sc_rrid = 0; in tsec_fdt_probe()
132 sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rrid, in tsec_fdt_probe()
134 if (sc->sc_rres == NULL) in tsec_fdt_probe()
137 sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres); in tsec_fdt_probe()
138 sc->sc_bas.bst = rman_get_bustag(sc->sc_rres); in tsec_fdt_probe()
142 sc->is_etsec = ((id >> 16) == TSEC_ETSEC_ID) ? 1 : 0; in tsec_fdt_probe()
145 bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid, sc->sc_rres); in tsec_fdt_probe()
153 if (sc->is_etsec) in tsec_fdt_probe()
154 device_set_desc(dev, "Enhanced Three-Speed Ethernet Controller"); in tsec_fdt_probe()
156 device_set_desc(dev, "Three-Speed Ethernet Controller"); in tsec_fdt_probe()
171 sc->dev = dev; in tsec_fdt_attach()
172 sc->node = ofw_bus_get_node(dev); in tsec_fdt_attach()
174 if (fdt_addrsize_cells(sc->node, &acells, &scells) != 0) { in tsec_fdt_attach()
185 child = OF_child(sc->node); in tsec_fdt_attach()
190 /* Get phy address from fdt */ in tsec_fdt_attach()
191 if (OF_getencprop(sc->node, "phy-handle", &phy, sizeof(phy)) <= 0) { in tsec_fdt_attach()
192 device_printf(dev, "PHY not found in device tree"); in tsec_fdt_attach()
198 OF_decode_addr(mdio, 0, &sc->phy_bst, &sc->phy_bsh, NULL); in tsec_fdt_attach()
199 OF_getencprop(phy, "reg", &sc->phyaddr, sizeof(sc->phyaddr)); in tsec_fdt_attach()
202 * etsec2 MDIO nodes are given the MDIO module base address, so we need in tsec_fdt_attach()
205 if (ofw_bus_node_is_compatible(mdio, "fsl,etsec2-mdio")) in tsec_fdt_attach()
206 sc->phy_regoff = TSEC_REG_MIIBASE; in tsec_fdt_attach()
209 callout_init(&sc->tsec_callout, 1); in tsec_fdt_attach()
212 mtx_init(&sc->transmit_lock, device_get_nameunit(dev), "TSEC TX lock", in tsec_fdt_attach()
214 mtx_init(&sc->receive_lock, device_get_nameunit(dev), "TSEC RX lock", in tsec_fdt_attach()
216 mtx_init(&sc->ic_lock, device_get_nameunit(dev), "TSEC IC lock", in tsec_fdt_attach()
220 sc->sc_rrid = 0; in tsec_fdt_attach()
221 sc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_rrid, in tsec_fdt_attach()
223 if (sc->sc_rres == NULL) { in tsec_fdt_attach()
227 sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres); in tsec_fdt_attach()
228 sc->sc_bas.bst = rman_get_bustag(sc->sc_rres); in tsec_fdt_attach()
237 sc->sc_transmit_irid = TSEC_RID_TXIRQ; in tsec_fdt_attach()
238 error = tsec_setup_intr(sc, &sc->sc_transmit_ires, in tsec_fdt_attach()
239 &sc->sc_transmit_ihand, &sc->sc_transmit_irid, in tsec_fdt_attach()
244 sc->sc_receive_irid = TSEC_RID_RXIRQ; in tsec_fdt_attach()
245 error = tsec_setup_intr(sc, &sc->sc_receive_ires, in tsec_fdt_attach()
246 &sc->sc_receive_ihand, &sc->sc_receive_irid, in tsec_fdt_attach()
251 sc->sc_error_irid = TSEC_RID_ERRIRQ; in tsec_fdt_attach()
252 error = tsec_setup_intr(sc, &sc->sc_error_ires, in tsec_fdt_attach()
253 &sc->sc_error_ihand, &sc->sc_error_irid, in tsec_fdt_attach()
261 tsec_release_intr(sc, sc->sc_receive_ires, sc->sc_receive_ihand, in tsec_fdt_attach()
262 sc->sc_receive_irid, "RX"); in tsec_fdt_attach()
264 tsec_release_intr(sc, sc->sc_transmit_ires, sc->sc_transmit_ihand, in tsec_fdt_attach()
265 sc->sc_transmit_irid, "TX"); in tsec_fdt_attach()
267 bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid, sc->sc_rres); in tsec_fdt_attach()
269 mtx_destroy(&sc->receive_lock); in tsec_fdt_attach()
270 mtx_destroy(&sc->transmit_lock); in tsec_fdt_attach()
280 *ires = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, irid, RF_ACTIVE); in tsec_setup_intr()
282 device_printf(sc->dev, "could not allocate %s IRQ\n", iname); in tsec_setup_intr()
285 error = bus_setup_intr(sc->dev, *ires, INTR_TYPE_NET | INTR_MPSAFE, in tsec_setup_intr()
288 device_printf(sc->dev, "failed to set up %s IRQ\n", iname); in tsec_setup_intr()
289 if (bus_release_resource(sc->dev, SYS_RES_IRQ, *irid, *ires)) in tsec_setup_intr()
290 device_printf(sc->dev, "could not release %s IRQ\n", iname); in tsec_setup_intr()
306 error = bus_teardown_intr(sc->dev, ires, ihand); in tsec_release_intr()
308 device_printf(sc->dev, "bus_teardown_intr() failed for %s intr" in tsec_release_intr()
311 error = bus_release_resource(sc->dev, SYS_RES_IRQ, irid, ires); in tsec_release_intr()
313 device_printf(sc->dev, "bus_release_resource() failed for %s " in tsec_release_intr()
326 callout_drain(&sc->tsec_callout); in tsec_fdt_detach()
329 tsec_release_intr(sc, sc->sc_transmit_ires, sc->sc_transmit_ihand, in tsec_fdt_detach()
330 sc->sc_transmit_irid, "TX"); in tsec_fdt_detach()
331 tsec_release_intr(sc, sc->sc_receive_ires, sc->sc_receive_ihand, in tsec_fdt_detach()
332 sc->sc_receive_irid, "RX"); in tsec_fdt_detach()
333 tsec_release_intr(sc, sc->sc_error_ires, sc->sc_error_ihand, in tsec_fdt_detach()
334 sc->sc_error_irid, "ERR"); in tsec_fdt_detach()
340 if (sc->sc_rres) { in tsec_fdt_detach()
341 error = bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_rrid, in tsec_fdt_detach()
342 sc->sc_rres); in tsec_fdt_detach()
349 mtx_destroy(&sc->receive_lock); in tsec_fdt_detach()
350 mtx_destroy(&sc->transmit_lock); in tsec_fdt_detach()
351 mtx_destroy(&sc->ic_lock); in tsec_fdt_detach()
361 } hw; in tsec_get_hwaddr() local
364 hw.reg[0] = hw.reg[1] = 0; in tsec_get_hwaddr()
366 /* Retrieve the hardware address from the device tree. */ in tsec_get_hwaddr()
367 i = OF_getprop(sc->node, "local-mac-address", (void *)hw.addr, 6); in tsec_get_hwaddr()
368 if (i == 6 && (hw.reg[0] != 0 || hw.reg[1] != 0)) { in tsec_get_hwaddr()
369 bcopy(hw.addr, addr, 6); in tsec_get_hwaddr()
373 /* Also try the mac-address property, which is second-best */ in tsec_get_hwaddr()
374 i = OF_getprop(sc->node, "mac-address", (void *)hw.addr, 6); in tsec_get_hwaddr()
375 if (i == 6 && (hw.reg[0] != 0 || hw.reg[1] != 0)) { in tsec_get_hwaddr()
376 bcopy(hw.addr, addr, 6); in tsec_get_hwaddr()
381 * Fall back -- use the currently programmed address in the hope that in tsec_get_hwaddr()
384 hw.reg[0] = TSEC_READ(sc, TSEC_REG_MACSTNADDR1); in tsec_get_hwaddr()
385 hw.reg[1] = TSEC_READ(sc, TSEC_REG_MACSTNADDR2); in tsec_get_hwaddr()
387 addr[5-i] = hw.addr[i]; in tsec_get_hwaddr()