1d1d3233eSRafal Jaworowski /*- 2718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3718cf2ccSPedro F. Giffuni * 4d1d3233eSRafal Jaworowski * Copyright (c) 2006 Juniper Networks. 5d1d3233eSRafal Jaworowski * All rights reserved. 6d1d3233eSRafal Jaworowski * 7d1d3233eSRafal Jaworowski * Redistribution and use in source and binary forms, with or without 8d1d3233eSRafal Jaworowski * modification, are permitted provided that the following conditions 9d1d3233eSRafal Jaworowski * are met: 10d1d3233eSRafal Jaworowski * 1. Redistributions of source code must retain the above copyright 11d1d3233eSRafal Jaworowski * notice, this list of conditions and the following disclaimer. 12d1d3233eSRafal Jaworowski * 2. Redistributions in binary form must reproduce the above copyright 13d1d3233eSRafal Jaworowski * notice, this list of conditions and the following disclaimer in the 14d1d3233eSRafal Jaworowski * documentation and/or other materials provided with the distribution. 15d1d3233eSRafal Jaworowski * 3. The name of the author may not be used to endorse or promote products 16d1d3233eSRafal Jaworowski * derived from this software without specific prior written permission. 17d1d3233eSRafal Jaworowski * 18d1d3233eSRafal Jaworowski * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19d1d3233eSRafal Jaworowski * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20d1d3233eSRafal Jaworowski * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21d1d3233eSRafal Jaworowski * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22d1d3233eSRafal Jaworowski * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23d1d3233eSRafal Jaworowski * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24d1d3233eSRafal Jaworowski * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25d1d3233eSRafal Jaworowski * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26d1d3233eSRafal Jaworowski * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27d1d3233eSRafal Jaworowski * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28d1d3233eSRafal Jaworowski * SUCH DAMAGE. 29d1d3233eSRafal Jaworowski */ 30d1d3233eSRafal Jaworowski 31d1d3233eSRafal Jaworowski #include <sys/cdefs.h> 32d1d3233eSRafal Jaworowski __FBSDID("$FreeBSD$"); 33d1d3233eSRafal Jaworowski 34d1d3233eSRafal Jaworowski #include <sys/param.h> 35d1d3233eSRafal Jaworowski #include <sys/systm.h> 36d1d3233eSRafal Jaworowski #include <sys/bus.h> 37d1d3233eSRafal Jaworowski #include <sys/conf.h> 38d1d3233eSRafal Jaworowski #include <sys/kernel.h> 39d1d3233eSRafal Jaworowski #include <sys/lock.h> 40d1d3233eSRafal Jaworowski #include <sys/malloc.h> 41d1d3233eSRafal Jaworowski #include <sys/module.h> 42d1d3233eSRafal Jaworowski #include <sys/rman.h> 43d1d3233eSRafal Jaworowski #include <machine/bus.h> 44d1d3233eSRafal Jaworowski 45d1d3233eSRafal Jaworowski #include <dev/ofw/ofw_bus.h> 46d1d3233eSRafal Jaworowski #include <dev/ofw/ofw_bus_subr.h> 47d1d3233eSRafal Jaworowski #include <dev/quicc/quicc_bfe.h> 48d1d3233eSRafal Jaworowski 49d1d3233eSRafal Jaworowski static int quicc_fdt_probe(device_t dev); 50d1d3233eSRafal Jaworowski 51d1d3233eSRafal Jaworowski static device_method_t quicc_fdt_methods[] = { 52d1d3233eSRafal Jaworowski /* Device interface */ 53d1d3233eSRafal Jaworowski DEVMETHOD(device_probe, quicc_fdt_probe), 54d1d3233eSRafal Jaworowski DEVMETHOD(device_attach, quicc_bfe_attach), 55d1d3233eSRafal Jaworowski DEVMETHOD(device_detach, quicc_bfe_detach), 56d1d3233eSRafal Jaworowski 57d1d3233eSRafal Jaworowski DEVMETHOD(bus_alloc_resource, quicc_bus_alloc_resource), 58d1d3233eSRafal Jaworowski DEVMETHOD(bus_release_resource, quicc_bus_release_resource), 59d1d3233eSRafal Jaworowski DEVMETHOD(bus_get_resource, quicc_bus_get_resource), 60d1d3233eSRafal Jaworowski DEVMETHOD(bus_read_ivar, quicc_bus_read_ivar), 61d1d3233eSRafal Jaworowski DEVMETHOD(bus_setup_intr, quicc_bus_setup_intr), 62d1d3233eSRafal Jaworowski DEVMETHOD(bus_teardown_intr, quicc_bus_teardown_intr), 63d1d3233eSRafal Jaworowski 644b7ec270SMarius Strobl DEVMETHOD_END 65d1d3233eSRafal Jaworowski }; 66d1d3233eSRafal Jaworowski 67d1d3233eSRafal Jaworowski static driver_t quicc_fdt_driver = { 68d1d3233eSRafal Jaworowski quicc_driver_name, 69d1d3233eSRafal Jaworowski quicc_fdt_methods, 70d1d3233eSRafal Jaworowski sizeof(struct quicc_softc), 71d1d3233eSRafal Jaworowski }; 72d1d3233eSRafal Jaworowski 73d1d3233eSRafal Jaworowski static int 74d1d3233eSRafal Jaworowski quicc_fdt_probe(device_t dev) 75d1d3233eSRafal Jaworowski { 76d1d3233eSRafal Jaworowski phandle_t par; 77d1d3233eSRafal Jaworowski pcell_t clock; 78d1d3233eSRafal Jaworowski 79add35ed5SIan Lepore if (!ofw_bus_status_okay(dev)) 80add35ed5SIan Lepore return (ENXIO); 81add35ed5SIan Lepore 82d1d3233eSRafal Jaworowski if (!ofw_bus_is_compatible(dev, "fsl,cpm2")) 83d1d3233eSRafal Jaworowski return (ENXIO); 84d1d3233eSRafal Jaworowski 85d1d3233eSRafal Jaworowski par = OF_parent(ofw_bus_get_node(dev)); 86d1d3233eSRafal Jaworowski if (OF_getprop(par, "bus-frequency", &clock, sizeof(clock)) <= 0) 87d1d3233eSRafal Jaworowski clock = 0; 88d1d3233eSRafal Jaworowski 89d1d3233eSRafal Jaworowski return (quicc_bfe_probe(dev, (uintptr_t)clock)); 90d1d3233eSRafal Jaworowski } 91d1d3233eSRafal Jaworowski 92*28140529SJohn Baldwin DRIVER_MODULE(quicc, simplebus, quicc_fdt_driver, 0, 0); 93