11.1Sskrll/* $NetBSD: ti_omapwugen.c,v 1.1 2025/12/16 12:20:22 skrll Exp $ */ 21.1Sskrll 31.1Sskrll/*- 41.1Sskrll * Copyright (c) 2025 Rui-Xiang Guo 51.1Sskrll * All rights reserved. 61.1Sskrll * 71.1Sskrll * Redistribution and use in source and binary forms, with or without 81.1Sskrll * modification, are permitted provided that the following conditions 91.1Sskrll * are met: 101.1Sskrll * 1. Redistributions of source code must retain the above copyright 111.1Sskrll * notice, this list of conditions and the following disclaimer. 121.1Sskrll * 2. Redistributions in binary form must reproduce the above copyright 131.1Sskrll * notice, this list of conditions and the following disclaimer in the 141.1Sskrll * documentation and/or other materials provided with the distribution. 151.1Sskrll * 161.1Sskrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 171.1Sskrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 181.1Sskrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 191.1Sskrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201.1Sskrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 211.1Sskrll * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 221.1Sskrll * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 231.1Sskrll * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 241.1Sskrll * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Sskrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Sskrll * SUCH DAMAGE. 271.1Sskrll */ 281.1Sskrll 291.1Sskrll#include <sys/cdefs.h> 301.1Sskrll__KERNEL_RCSID(0, "$NetBSD: ti_omapwugen.c,v 1.1 2025/12/16 12:20:22 skrll Exp $"); 311.1Sskrll 321.1Sskrll#include <sys/param.h> 331.1Sskrll#include <sys/bus.h> 341.1Sskrll#include <sys/device.h> 351.1Sskrll#include <sys/intr.h> 361.1Sskrll#include <sys/systm.h> 371.1Sskrll#include <sys/kernel.h> 381.1Sskrll 391.1Sskrll#include <dev/fdt/fdtvar.h> 401.1Sskrll 411.1Sskrllstatic int omapwugen_match(device_t, cfdata_t, void *); 421.1Sskrllstatic void omapwugen_attach(device_t, device_t, void *); 431.1Sskrll 441.1Sskrllstatic const struct device_compatible_entry compat_data[] = { 451.1Sskrll { .compat = "ti,omap4-wugen-mpu" }, 461.1Sskrll DEVICE_COMPAT_EOL 471.1Sskrll}; 481.1Sskrll 491.1Sskrllstruct omapwugen_softc { 501.1Sskrll device_t sc_dev; 511.1Sskrll int sc_phandle; 521.1Sskrll}; 531.1Sskrll 541.1Sskrllstatic void * 551.1Sskrllomapwugen_fdt_establish(device_t dev, u_int *specifier, int ipl, int flags, 561.1Sskrll int (*func)(void *), void *arg, const char *xname) 571.1Sskrll{ 581.1Sskrll struct omapwugen_softc * const sc = device_private(dev); 591.1Sskrll 601.1Sskrll const int ihandle = fdtbus_intr_parent(sc->sc_phandle); 611.1Sskrll if (ihandle == -1) { 621.1Sskrll return NULL; 631.1Sskrll } 641.1Sskrll 651.1Sskrll return fdtbus_intr_establish_raw(ihandle, specifier, ipl, 661.1Sskrll flags, func, arg, xname); 671.1Sskrll} 681.1Sskrll 691.1Sskrllstatic void 701.1Sskrllomapwugen_fdt_disestablish(device_t dev, void *ih) 711.1Sskrll{ 721.1Sskrll intr_disestablish(ih); 731.1Sskrll} 741.1Sskrll 751.1Sskrllstatic bool 761.1Sskrllomapwugen_fdt_intrstr(device_t dev, u_int *specifier, char *buf, size_t buflen) 771.1Sskrll{ 781.1Sskrll struct omapwugen_softc * const sc = device_private(dev); 791.1Sskrll 801.1Sskrll const int ihandle = fdtbus_intr_parent(sc->sc_phandle); 811.1Sskrll if (ihandle == -1) { 821.1Sskrll return false; 831.1Sskrll } 841.1Sskrll 851.1Sskrll return fdtbus_intr_str_raw(ihandle, specifier, buf, buflen); 861.1Sskrll} 871.1Sskrll 881.1Sskrllstatic const struct fdtbus_interrupt_controller_func omapwugen_fdt_funcs = { 891.1Sskrll .establish = omapwugen_fdt_establish, 901.1Sskrll .disestablish = omapwugen_fdt_disestablish, 911.1Sskrll .intrstr = omapwugen_fdt_intrstr, 921.1Sskrll}; 931.1Sskrll 941.1Sskrllstatic int 951.1Sskrllomapwugen_match(device_t parent, cfdata_t cf, void *aux) 961.1Sskrll{ 971.1Sskrll struct fdt_attach_args * const faa = aux; 981.1Sskrll 991.1Sskrll return of_compatible_match(faa->faa_phandle, compat_data); 1001.1Sskrll} 1011.1Sskrll 1021.1Sskrllstatic void 1031.1Sskrllomapwugen_attach(device_t parent, device_t self, void *aux) 1041.1Sskrll{ 1051.1Sskrll struct omapwugen_softc * const sc = device_private(self); 1061.1Sskrll struct fdt_attach_args * const faa = aux; 1071.1Sskrll const int phandle = faa->faa_phandle; 1081.1Sskrll int error; 1091.1Sskrll 1101.1Sskrll sc->sc_dev = self; 1111.1Sskrll sc->sc_phandle = phandle; 1121.1Sskrll 1131.1Sskrll aprint_naive("\n"); 1141.1Sskrll aprint_normal("\n"); 1151.1Sskrll 1161.1Sskrll error = fdtbus_register_interrupt_controller(self, phandle, 1171.1Sskrll &omapwugen_fdt_funcs); 1181.1Sskrll if (error) { 1191.1Sskrll aprint_error_dev(self, "couldn't register with fdtbus: %d\n", 1201.1Sskrll error); 1211.1Sskrll return; 1221.1Sskrll } 1231.1Sskrll} 1241.1Sskrll 1251.1SskrllCFATTACH_DECL_NEW(omapwugen, sizeof(struct omapwugen_softc), 1261.1Sskrll omapwugen_match, omapwugen_attach, NULL, NULL); 127