10aeed3e9SJustin Hibbits /*- 20aeed3e9SJustin Hibbits * Copyright (c) 2012 Semihalf. 30aeed3e9SJustin Hibbits * All rights reserved. 40aeed3e9SJustin Hibbits * 50aeed3e9SJustin Hibbits * Redistribution and use in source and binary forms, with or without 60aeed3e9SJustin Hibbits * modification, are permitted provided that the following conditions 70aeed3e9SJustin Hibbits * are met: 80aeed3e9SJustin Hibbits * 1. Redistributions of source code must retain the above copyright 90aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer. 100aeed3e9SJustin Hibbits * 2. Redistributions in binary form must reproduce the above copyright 110aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer in the 120aeed3e9SJustin Hibbits * documentation and/or other materials provided with the distribution. 130aeed3e9SJustin Hibbits * 140aeed3e9SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 150aeed3e9SJustin Hibbits * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 160aeed3e9SJustin Hibbits * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 170aeed3e9SJustin Hibbits * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 180aeed3e9SJustin Hibbits * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 190aeed3e9SJustin Hibbits * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 200aeed3e9SJustin Hibbits * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 210aeed3e9SJustin Hibbits * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 220aeed3e9SJustin Hibbits * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 230aeed3e9SJustin Hibbits * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 240aeed3e9SJustin Hibbits * SUCH DAMAGE. 250aeed3e9SJustin Hibbits */ 260aeed3e9SJustin Hibbits 270aeed3e9SJustin Hibbits #include <sys/cdefs.h> 280aeed3e9SJustin Hibbits __FBSDID("$FreeBSD$"); 290aeed3e9SJustin Hibbits 300aeed3e9SJustin Hibbits #include <sys/param.h> 310aeed3e9SJustin Hibbits #include <sys/systm.h> 320aeed3e9SJustin Hibbits #include <sys/kernel.h> 330aeed3e9SJustin Hibbits #include <sys/bus.h> 340aeed3e9SJustin Hibbits #include <sys/module.h> 350aeed3e9SJustin Hibbits 3647cabd04SJustin Hibbits #include <dev/fdt/simplebus.h> 370aeed3e9SJustin Hibbits #include <dev/ofw/ofw_bus.h> 380aeed3e9SJustin Hibbits #include <dev/ofw/ofw_bus_subr.h> 390aeed3e9SJustin Hibbits 400aeed3e9SJustin Hibbits #include <contrib/ncsw/inc/ncsw_ext.h> 410aeed3e9SJustin Hibbits #include <contrib/ncsw/inc/enet_ext.h> 420aeed3e9SJustin Hibbits 430aeed3e9SJustin Hibbits #include "fman.h" 440aeed3e9SJustin Hibbits 450aeed3e9SJustin Hibbits #define FFMAN_DEVSTR "Freescale Frame Manager" 460aeed3e9SJustin Hibbits 470aeed3e9SJustin Hibbits static int fman_fdt_probe(device_t dev); 480aeed3e9SJustin Hibbits 490aeed3e9SJustin Hibbits static device_method_t fman_methods[] = { 500aeed3e9SJustin Hibbits /* Device interface */ 510aeed3e9SJustin Hibbits DEVMETHOD(device_probe, fman_fdt_probe), 520aeed3e9SJustin Hibbits DEVMETHOD(device_attach, fman_attach), 530aeed3e9SJustin Hibbits DEVMETHOD(device_detach, fman_detach), 540aeed3e9SJustin Hibbits 550aeed3e9SJustin Hibbits DEVMETHOD(device_shutdown, fman_shutdown), 560aeed3e9SJustin Hibbits DEVMETHOD(device_suspend, fman_suspend), 57852ba100SJustin Hibbits DEVMETHOD(device_resume, fman_resume_dev), 580aeed3e9SJustin Hibbits 59a32b5435SJustin Hibbits DEVMETHOD(bus_alloc_resource, fman_alloc_resource), 60a32b5435SJustin Hibbits DEVMETHOD(bus_activate_resource, fman_activate_resource), 61a32b5435SJustin Hibbits DEVMETHOD(bus_release_resource, fman_release_resource), 620aeed3e9SJustin Hibbits { 0, 0 } 630aeed3e9SJustin Hibbits }; 640aeed3e9SJustin Hibbits 6547cabd04SJustin Hibbits DEFINE_CLASS_1(fman, fman_driver, fman_methods, 6647cabd04SJustin Hibbits sizeof(struct fman_softc), simplebus_driver); 67*d1524801SJohn Baldwin EARLY_DRIVER_MODULE(fman, simplebus, fman_driver, 0, 0, 680aeed3e9SJustin Hibbits BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); 690aeed3e9SJustin Hibbits 700aeed3e9SJustin Hibbits 710aeed3e9SJustin Hibbits static int 720aeed3e9SJustin Hibbits fman_fdt_probe(device_t dev) 730aeed3e9SJustin Hibbits { 740aeed3e9SJustin Hibbits 750aeed3e9SJustin Hibbits if (!ofw_bus_is_compatible(dev, "fsl,fman")) 760aeed3e9SJustin Hibbits return (ENXIO); 770aeed3e9SJustin Hibbits 780aeed3e9SJustin Hibbits device_set_desc(dev, FFMAN_DEVSTR); 790aeed3e9SJustin Hibbits 800aeed3e9SJustin Hibbits return (BUS_PROBE_DEFAULT); 810aeed3e9SJustin Hibbits } 820aeed3e9SJustin Hibbits 830aeed3e9SJustin Hibbits uint32_t 840aeed3e9SJustin Hibbits fman_get_clock(struct fman_softc *sc) 850aeed3e9SJustin Hibbits { 860aeed3e9SJustin Hibbits device_t dev; 870aeed3e9SJustin Hibbits phandle_t node; 880aeed3e9SJustin Hibbits pcell_t fman_clock; 890aeed3e9SJustin Hibbits 9047cabd04SJustin Hibbits dev = sc->sc_base.dev; 910aeed3e9SJustin Hibbits node = ofw_bus_get_node(dev); 920aeed3e9SJustin Hibbits 930aeed3e9SJustin Hibbits if ((OF_getprop(node, "clock-frequency", &fman_clock, 940aeed3e9SJustin Hibbits sizeof(fman_clock)) <= 0) || (fman_clock == 0)) { 950aeed3e9SJustin Hibbits device_printf(dev, "could not acquire correct frequency " 960aeed3e9SJustin Hibbits "from DTS\n"); 970aeed3e9SJustin Hibbits 980aeed3e9SJustin Hibbits return (0); 990aeed3e9SJustin Hibbits } 1000aeed3e9SJustin Hibbits 1010aeed3e9SJustin Hibbits return ((uint32_t)fman_clock); 1020aeed3e9SJustin Hibbits } 1030aeed3e9SJustin Hibbits 104