1 /* $NetBSD: becc_button.c,v 1.3 2005/12/11 12:16:51 christos Exp $ */ 2 3 /* 4 * Copyright (c) 2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 /* 39 * Driver for the reset button on the ADI Engineering, Inc. Big Endian 40 * Companion Chip. 41 * 42 * When pressed for two seconds, the reset button performs a hard reset 43 * of the system. Shorter presses result in an interrupt being generated, 44 * which the operating system can use to trigger a graceful reboot. 45 */ 46 47 #include <sys/cdefs.h> 48 __KERNEL_RCSID(0, "$NetBSD: becc_button.c,v 1.3 2005/12/11 12:16:51 christos Exp $"); 49 50 #include <sys/param.h> 51 #include <sys/systm.h> 52 #include <sys/device.h> 53 54 #include <arm/xscale/beccreg.h> 55 #include <arm/xscale/beccvar.h> 56 57 #include <dev/sysmon/sysmonvar.h> 58 #include <dev/sysmon/sysmon_taskq.h> 59 60 static int beccbut_attached; /* there can be only one */ 61 62 struct beccbut_softc { 63 struct device sc_dev; 64 struct sysmon_pswitch sc_smpsw; 65 void *sc_ih; 66 }; 67 68 static void 69 beccbut_pressed_event(void *arg) 70 { 71 struct beccbut_softc *sc = arg; 72 73 sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED); 74 } 75 76 static int 77 beccbut_intr(void *arg) 78 { 79 struct beccbut_softc *sc = arg; 80 int rv; 81 82 rv = sysmon_task_queue_sched(0, beccbut_pressed_event, sc); 83 if (rv != 0) 84 printf("%s: WARNING: unable to queue button pressed " 85 "callback: %d\n", sc->sc_dev.dv_xname, rv); 86 87 return (1); 88 } 89 90 static int 91 beccbut_match(struct device *parent, struct cfdata *match, void *aux) 92 { 93 94 return (beccbut_attached == 0); 95 } 96 97 static void 98 beccbut_attach(struct device *parent, struct device *self, void *aux) 99 { 100 struct beccbut_softc *sc = (void *) self; 101 102 printf(": Reset button\n"); 103 104 beccbut_attached = 1; 105 106 sysmon_task_queue_init(); 107 108 sc->sc_smpsw.smpsw_name = sc->sc_dev.dv_xname; 109 sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_RESET; 110 111 if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) { 112 printf("%s: unable to register with sysmon\n", 113 sc->sc_dev.dv_xname); 114 return; 115 } 116 117 sc->sc_ih = becc_intr_establish(ICU_PUSHBUTTON, IPL_TTY, 118 beccbut_intr, sc); 119 if (sc->sc_ih == NULL) 120 printf("%s: unable to establish interrupt handler\n", 121 sc->sc_dev.dv_xname); 122 } 123 124 CFATTACH_DECL(beccbut, sizeof(struct beccbut_softc), 125 beccbut_match, beccbut_attach, NULL, NULL); 126