tegra_lic.c revision 1.3
11.3Smarty/* $NetBSD: tegra_lic.c,v 1.3 2016/01/05 21:53:48 marty Exp $ */ 21.1Sjmcneill 31.1Sjmcneill/*- 41.1Sjmcneill * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> 51.1Sjmcneill * All rights reserved. 61.1Sjmcneill * 71.1Sjmcneill * Redistribution and use in source and binary forms, with or without 81.1Sjmcneill * modification, are permitted provided that the following conditions 91.1Sjmcneill * are met: 101.1Sjmcneill * 1. Redistributions of source code must retain the above copyright 111.1Sjmcneill * notice, this list of conditions and the following disclaimer. 121.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright 131.1Sjmcneill * notice, this list of conditions and the following disclaimer in the 141.1Sjmcneill * documentation and/or other materials provided with the distribution. 151.1Sjmcneill * 161.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 171.1Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 181.1Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 191.1Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201.1Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 211.1Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 221.1Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 231.1Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 241.1Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Sjmcneill * SUCH DAMAGE. 271.1Sjmcneill */ 281.1Sjmcneill 291.1Sjmcneill#include <sys/cdefs.h> 301.3Smarty__KERNEL_RCSID(0, "$NetBSD: tegra_lic.c,v 1.3 2016/01/05 21:53:48 marty Exp $"); 311.1Sjmcneill 321.1Sjmcneill#include <sys/param.h> 331.1Sjmcneill#include <sys/bus.h> 341.1Sjmcneill#include <sys/device.h> 351.1Sjmcneill#include <sys/intr.h> 361.1Sjmcneill#include <sys/systm.h> 371.1Sjmcneill#include <sys/kernel.h> 381.1Sjmcneill#include <sys/kmem.h> 391.1Sjmcneill 401.1Sjmcneill#include <arm/nvidia/tegra_reg.h> 411.1Sjmcneill#include <arm/nvidia/tegra_var.h> 421.1Sjmcneill 431.1Sjmcneill#include <arm/cortex/gic_intr.h> 441.1Sjmcneill 451.1Sjmcneill#include <dev/fdt/fdtvar.h> 461.1Sjmcneill 471.1Sjmcneillstatic int tegra_lic_match(device_t, cfdata_t, void *); 481.1Sjmcneillstatic void tegra_lic_attach(device_t, device_t, void *); 491.1Sjmcneill 501.3Smartystatic void * tegra_lic_establish(device_t, u_int *, int, int, 511.1Sjmcneill int (*)(void *), void *); 521.1Sjmcneillstatic void tegra_lic_disestablish(device_t, void *); 531.3Smartystatic bool tegra_lic_intrstr(device_t, u_int *, char *, size_t); 541.1Sjmcneill 551.1Sjmcneillstruct fdtbus_interrupt_controller_func tegra_lic_funcs = { 561.1Sjmcneill .establish = tegra_lic_establish, 571.1Sjmcneill .disestablish = tegra_lic_disestablish, 581.1Sjmcneill .intrstr = tegra_lic_intrstr 591.1Sjmcneill}; 601.1Sjmcneill 611.1Sjmcneillstruct tegra_lic_softc { 621.1Sjmcneill device_t sc_dev; 631.1Sjmcneill int sc_phandle; 641.1Sjmcneill}; 651.1Sjmcneill 661.1SjmcneillCFATTACH_DECL_NEW(tegra_lic, sizeof(struct tegra_lic_softc), 671.1Sjmcneill tegra_lic_match, tegra_lic_attach, NULL, NULL); 681.1Sjmcneill 691.1Sjmcneillstatic int 701.1Sjmcneilltegra_lic_match(device_t parent, cfdata_t cf, void *aux) 711.1Sjmcneill{ 721.1Sjmcneill const char * const compatible[] = { "nvidia,tegra124-ictlr", NULL }; 731.1Sjmcneill struct fdt_attach_args * const faa = aux; 741.1Sjmcneill 751.1Sjmcneill return of_match_compatible(faa->faa_phandle, compatible); 761.1Sjmcneill} 771.1Sjmcneill 781.1Sjmcneillstatic void 791.1Sjmcneilltegra_lic_attach(device_t parent, device_t self, void *aux) 801.1Sjmcneill{ 811.1Sjmcneill struct tegra_lic_softc * const sc = device_private(self); 821.1Sjmcneill struct fdt_attach_args * const faa = aux; 831.1Sjmcneill int error; 841.1Sjmcneill 851.1Sjmcneill sc->sc_dev = self; 861.1Sjmcneill sc->sc_phandle = faa->faa_phandle; 871.1Sjmcneill 881.1Sjmcneill error = fdtbus_register_interrupt_controller(self, faa->faa_phandle, 891.1Sjmcneill &tegra_lic_funcs); 901.1Sjmcneill if (error) { 911.1Sjmcneill aprint_error(": couldn't register with fdtbus: %d\n", error); 921.1Sjmcneill return; 931.1Sjmcneill } 941.1Sjmcneill 951.1Sjmcneill aprint_naive("\n"); 961.1Sjmcneill aprint_normal(": LIC\n"); 971.1Sjmcneill} 981.1Sjmcneill 991.1Sjmcneillstatic void * 1001.3Smartytegra_lic_establish(device_t dev, u_int *specifier, int ipl, int flags, 1011.1Sjmcneill int (*func)(void *), void *arg) 1021.1Sjmcneill{ 1031.1Sjmcneill int iflags = (flags & FDT_INTR_MPSAFE) ? IST_MPSAFE : 0; 1041.1Sjmcneill 1051.1Sjmcneill /* 1st cell is the interrupt type; 0 is SPI, 1 is PPI */ 1061.1Sjmcneill /* 2nd cell is the interrupt number */ 1071.1Sjmcneill /* 3rd cell is flags */ 1081.1Sjmcneill 1091.3Smarty const u_int type = be32toh(specifier[0]); 1101.3Smarty const u_int intr = be32toh(specifier[1]); 1111.1Sjmcneill const u_int irq = type == 0 ? IRQ_SPI(intr) : IRQ_PPI(intr); 1121.3Smarty const u_int trig = be32toh(specifier[2]) & 0xf; 1131.1Sjmcneill const u_int level = (trig & 0x3) ? IST_EDGE : IST_LEVEL; 1141.1Sjmcneill 1151.1Sjmcneill return intr_establish(irq, ipl, level | iflags, func, arg); 1161.1Sjmcneill} 1171.1Sjmcneill 1181.1Sjmcneillstatic void 1191.1Sjmcneilltegra_lic_disestablish(device_t dev, void *ih) 1201.1Sjmcneill{ 1211.1Sjmcneill intr_disestablish(ih); 1221.1Sjmcneill} 1231.1Sjmcneill 1241.1Sjmcneillstatic bool 1251.3Smartytegra_lic_intrstr(device_t dev, u_int *specifier, char *buf, 1261.1Sjmcneill size_t buflen) 1271.1Sjmcneill{ 1281.1Sjmcneill /* 1st cell is the interrupt type; 0 is SPI, 1 is PPI */ 1291.1Sjmcneill /* 2nd cell is the interrupt number */ 1301.1Sjmcneill /* 3rd cell is flags */ 1311.1Sjmcneill 1321.3Smarty const u_int type = be32toh(specifier[0]); 1331.3Smarty const u_int intr = be32toh(specifier[1]); 1341.1Sjmcneill const u_int irq = type == 0 ? IRQ_SPI(intr) : IRQ_PPI(intr); 1351.1Sjmcneill 1361.1Sjmcneill snprintf(buf, buflen, "LIC irq %d", irq); 1371.1Sjmcneill 1381.1Sjmcneill return true; 1391.1Sjmcneill} 140