1*0aeed3e9SJustin Hibbits /*- 2*0aeed3e9SJustin Hibbits * Copyright (c) 2012 Semihalf. 3*0aeed3e9SJustin Hibbits * All rights reserved. 4*0aeed3e9SJustin Hibbits * 5*0aeed3e9SJustin Hibbits * Redistribution and use in source and binary forms, with or without 6*0aeed3e9SJustin Hibbits * modification, are permitted provided that the following conditions 7*0aeed3e9SJustin Hibbits * are met: 8*0aeed3e9SJustin Hibbits * 1. Redistributions of source code must retain the above copyright 9*0aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer. 10*0aeed3e9SJustin Hibbits * 2. Redistributions in binary form must reproduce the above copyright 11*0aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer in the 12*0aeed3e9SJustin Hibbits * documentation and/or other materials provided with the distribution. 13*0aeed3e9SJustin Hibbits * 14*0aeed3e9SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*0aeed3e9SJustin Hibbits * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*0aeed3e9SJustin Hibbits * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*0aeed3e9SJustin Hibbits * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*0aeed3e9SJustin Hibbits * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*0aeed3e9SJustin Hibbits * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*0aeed3e9SJustin Hibbits * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*0aeed3e9SJustin Hibbits * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*0aeed3e9SJustin Hibbits * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*0aeed3e9SJustin Hibbits * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*0aeed3e9SJustin Hibbits * SUCH DAMAGE. 25*0aeed3e9SJustin Hibbits */ 26*0aeed3e9SJustin Hibbits 27*0aeed3e9SJustin Hibbits #include <sys/cdefs.h> 28*0aeed3e9SJustin Hibbits __FBSDID("$FreeBSD$"); 29*0aeed3e9SJustin Hibbits 30*0aeed3e9SJustin Hibbits #include <sys/param.h> 31*0aeed3e9SJustin Hibbits #include <sys/systm.h> 32*0aeed3e9SJustin Hibbits #include <sys/kernel.h> 33*0aeed3e9SJustin Hibbits #include <sys/bus.h> 34*0aeed3e9SJustin Hibbits #include <sys/module.h> 35*0aeed3e9SJustin Hibbits 36*0aeed3e9SJustin Hibbits #include <dev/ofw/ofw_bus.h> 37*0aeed3e9SJustin Hibbits #include <dev/ofw/ofw_bus_subr.h> 38*0aeed3e9SJustin Hibbits 39*0aeed3e9SJustin Hibbits #include <contrib/ncsw/inc/ncsw_ext.h> 40*0aeed3e9SJustin Hibbits #include <contrib/ncsw/inc/enet_ext.h> 41*0aeed3e9SJustin Hibbits 42*0aeed3e9SJustin Hibbits #include "fman.h" 43*0aeed3e9SJustin Hibbits 44*0aeed3e9SJustin Hibbits #define FFMAN_DEVSTR "Freescale Frame Manager" 45*0aeed3e9SJustin Hibbits 46*0aeed3e9SJustin Hibbits static int fman_fdt_probe(device_t dev); 47*0aeed3e9SJustin Hibbits 48*0aeed3e9SJustin Hibbits static device_method_t fman_methods[] = { 49*0aeed3e9SJustin Hibbits /* Device interface */ 50*0aeed3e9SJustin Hibbits DEVMETHOD(device_probe, fman_fdt_probe), 51*0aeed3e9SJustin Hibbits DEVMETHOD(device_attach, fman_attach), 52*0aeed3e9SJustin Hibbits DEVMETHOD(device_detach, fman_detach), 53*0aeed3e9SJustin Hibbits 54*0aeed3e9SJustin Hibbits DEVMETHOD(device_shutdown, fman_shutdown), 55*0aeed3e9SJustin Hibbits DEVMETHOD(device_suspend, fman_suspend), 56*0aeed3e9SJustin Hibbits DEVMETHOD(device_resume, fman_resume), 57*0aeed3e9SJustin Hibbits 58*0aeed3e9SJustin Hibbits { 0, 0 } 59*0aeed3e9SJustin Hibbits }; 60*0aeed3e9SJustin Hibbits 61*0aeed3e9SJustin Hibbits static driver_t fman_driver = { 62*0aeed3e9SJustin Hibbits "fman", 63*0aeed3e9SJustin Hibbits fman_methods, 64*0aeed3e9SJustin Hibbits sizeof(struct fman_softc), 65*0aeed3e9SJustin Hibbits }; 66*0aeed3e9SJustin Hibbits 67*0aeed3e9SJustin Hibbits static devclass_t fman_devclass; 68*0aeed3e9SJustin Hibbits EARLY_DRIVER_MODULE(fman, simplebus, fman_driver, fman_devclass, 0, 0, 69*0aeed3e9SJustin Hibbits BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); 70*0aeed3e9SJustin Hibbits 71*0aeed3e9SJustin Hibbits 72*0aeed3e9SJustin Hibbits static int 73*0aeed3e9SJustin Hibbits fman_fdt_probe(device_t dev) 74*0aeed3e9SJustin Hibbits { 75*0aeed3e9SJustin Hibbits 76*0aeed3e9SJustin Hibbits if (!ofw_bus_is_compatible(dev, "fsl,fman")) 77*0aeed3e9SJustin Hibbits return (ENXIO); 78*0aeed3e9SJustin Hibbits 79*0aeed3e9SJustin Hibbits device_set_desc(dev, FFMAN_DEVSTR); 80*0aeed3e9SJustin Hibbits 81*0aeed3e9SJustin Hibbits return (BUS_PROBE_DEFAULT); 82*0aeed3e9SJustin Hibbits } 83*0aeed3e9SJustin Hibbits 84*0aeed3e9SJustin Hibbits uint32_t 85*0aeed3e9SJustin Hibbits fman_get_clock(struct fman_softc *sc) 86*0aeed3e9SJustin Hibbits { 87*0aeed3e9SJustin Hibbits device_t dev; 88*0aeed3e9SJustin Hibbits phandle_t node; 89*0aeed3e9SJustin Hibbits pcell_t fman_clock; 90*0aeed3e9SJustin Hibbits 91*0aeed3e9SJustin Hibbits dev = sc->dev; 92*0aeed3e9SJustin Hibbits node = ofw_bus_get_node(dev); 93*0aeed3e9SJustin Hibbits 94*0aeed3e9SJustin Hibbits if ((OF_getprop(node, "clock-frequency", &fman_clock, 95*0aeed3e9SJustin Hibbits sizeof(fman_clock)) <= 0) || (fman_clock == 0)) { 96*0aeed3e9SJustin Hibbits device_printf(dev, "could not acquire correct frequency " 97*0aeed3e9SJustin Hibbits "from DTS\n"); 98*0aeed3e9SJustin Hibbits 99*0aeed3e9SJustin Hibbits return (0); 100*0aeed3e9SJustin Hibbits } 101*0aeed3e9SJustin Hibbits 102*0aeed3e9SJustin Hibbits return ((uint32_t)fman_clock); 103*0aeed3e9SJustin Hibbits } 104*0aeed3e9SJustin Hibbits 105