1198090Srdivacky/*- 2198090Srdivacky * SPDX-License-Identifier: BSD-2-Clause 3198090Srdivacky * 4198090Srdivacky * Copyright (C) 2002 Benno Rice. 5198090Srdivacky * All rights reserved. 6198090Srdivacky * 7198090Srdivacky * Redistribution and use in source and binary forms, with or without 8198090Srdivacky * modification, are permitted provided that the following conditions 9198090Srdivacky * are met: 10198090Srdivacky * 1. Redistributions of source code must retain the above copyright 11198090Srdivacky * notice, this list of conditions and the following disclaimer. 12198090Srdivacky * 2. Redistributions in binary form must reproduce the above copyright 13198090Srdivacky * notice, this list of conditions and the following disclaimer in the 14198090Srdivacky * documentation and/or other materials provided with the distribution. 15198090Srdivacky * 16198090Srdivacky * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR 17198090Srdivacky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18198090Srdivacky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19198090Srdivacky * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20198090Srdivacky * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21198090Srdivacky * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22198090Srdivacky * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23198090Srdivacky * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24198090Srdivacky * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25198090Srdivacky * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26198090Srdivacky */ 27198090Srdivacky 28198090Srdivacky#include "opt_ddb.h" 29198090Srdivacky 30198090Srdivacky#include <sys/param.h> 31198090Srdivacky#include <sys/systm.h> 32198090Srdivacky#include <sys/kdb.h> 33198090Srdivacky#include <sys/kernel.h> 34198090Srdivacky#include <sys/module.h> 35#include <sys/malloc.h> 36#include <sys/bus.h> 37#include <machine/bus.h> 38#include <sys/rman.h> 39 40#include <machine/resource.h> 41 42#include <dev/ofw/ofw_bus.h> 43#include <dev/ofw/openfirm.h> 44 45#include <powerpc/powermac/maciovar.h> 46 47struct pswitch_softc { 48 int sc_irq_rid; 49 struct resource *sc_irq; 50 void *sc_ih; 51}; 52 53static int pswitch_probe(device_t); 54static int pswitch_attach(device_t); 55 56static int pswitch_intr(void *); 57 58static device_method_t pswitch_methods[] = { 59 /* Device interface */ 60 DEVMETHOD(device_probe, pswitch_probe), 61 DEVMETHOD(device_attach, pswitch_attach), 62 { 0, 0 } 63}; 64 65static driver_t pswitch_driver = { 66 "pswitch", 67 pswitch_methods, 68 sizeof(struct pswitch_softc) 69}; 70 71EARLY_DRIVER_MODULE(pswitch, macgpio, pswitch_driver, 0, 0, BUS_PASS_RESOURCE); 72 73static int 74pswitch_probe(device_t dev) 75{ 76 const char *type = ofw_bus_get_type(dev); 77 78 if (strcmp(type, "programmer-switch") != 0) 79 return (ENXIO); 80 81 device_set_desc(dev, "GPIO Programmer's Switch"); 82 return (0); 83} 84 85static int 86pswitch_attach(device_t dev) 87{ 88 struct pswitch_softc *sc; 89 90 sc = device_get_softc(dev); 91 92 sc->sc_irq_rid = 0; 93 sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, 94 &sc->sc_irq_rid, RF_ACTIVE); 95 if (sc->sc_irq == NULL) { 96 device_printf(dev, "could not allocate interrupt\n"); 97 return (ENXIO); 98 } 99 100 if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_EXCL, 101 pswitch_intr, NULL, dev, &sc->sc_ih) != 0) { 102 device_printf(dev, "could not setup interrupt\n"); 103 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irq_rid, 104 sc->sc_irq); 105 return (ENXIO); 106 } 107 108 return (0); 109} 110 111static int 112pswitch_intr(void *arg) 113{ 114 device_t dev; 115 116 dev = (device_t)arg; 117 118 kdb_enter(KDB_WHY_POWERPC, device_get_nameunit(dev)); 119 return (FILTER_HANDLED); 120} 121