11.4Smatt/* $NetBSD: becc_button.c,v 1.4 2012/02/12 16:31:01 matt Exp $ */ 21.1Sthorpej 31.1Sthorpej/* 41.1Sthorpej * Copyright (c) 2003 Wasabi Systems, Inc. 51.1Sthorpej * All rights reserved. 61.1Sthorpej * 71.1Sthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc. 81.1Sthorpej * 91.1Sthorpej * Redistribution and use in source and binary forms, with or without 101.1Sthorpej * modification, are permitted provided that the following conditions 111.1Sthorpej * are met: 121.1Sthorpej * 1. Redistributions of source code must retain the above copyright 131.1Sthorpej * notice, this list of conditions and the following disclaimer. 141.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 151.1Sthorpej * notice, this list of conditions and the following disclaimer in the 161.1Sthorpej * documentation and/or other materials provided with the distribution. 171.1Sthorpej * 3. All advertising materials mentioning features or use of this software 181.1Sthorpej * must display the following acknowledgement: 191.1Sthorpej * This product includes software developed for the NetBSD Project by 201.1Sthorpej * Wasabi Systems, Inc. 211.1Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse 221.1Sthorpej * or promote products derived from this software without specific prior 231.1Sthorpej * written permission. 241.1Sthorpej * 251.1Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 261.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 271.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 281.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 291.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 321.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 331.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 341.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 351.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 361.1Sthorpej */ 371.1Sthorpej 381.1Sthorpej/* 391.1Sthorpej * Driver for the reset button on the ADI Engineering, Inc. Big Endian 401.1Sthorpej * Companion Chip. 411.1Sthorpej * 421.1Sthorpej * When pressed for two seconds, the reset button performs a hard reset 431.1Sthorpej * of the system. Shorter presses result in an interrupt being generated, 441.1Sthorpej * which the operating system can use to trigger a graceful reboot. 451.1Sthorpej */ 461.2Slukem 471.2Slukem#include <sys/cdefs.h> 481.4Smatt__KERNEL_RCSID(0, "$NetBSD: becc_button.c,v 1.4 2012/02/12 16:31:01 matt Exp $"); 491.1Sthorpej 501.1Sthorpej#include <sys/param.h> 511.1Sthorpej#include <sys/systm.h> 521.1Sthorpej#include <sys/device.h> 531.1Sthorpej 541.1Sthorpej#include <arm/xscale/beccreg.h> 551.1Sthorpej#include <arm/xscale/beccvar.h> 561.1Sthorpej 571.1Sthorpej#include <dev/sysmon/sysmonvar.h> 581.1Sthorpej#include <dev/sysmon/sysmon_taskq.h> 591.1Sthorpej 601.1Sthorpejstatic int beccbut_attached; /* there can be only one */ 611.1Sthorpej 621.1Sthorpejstruct beccbut_softc { 631.4Smatt device_t sc_dev; 641.1Sthorpej struct sysmon_pswitch sc_smpsw; 651.1Sthorpej void *sc_ih; 661.1Sthorpej}; 671.1Sthorpej 681.1Sthorpejstatic void 691.1Sthorpejbeccbut_pressed_event(void *arg) 701.1Sthorpej{ 711.1Sthorpej struct beccbut_softc *sc = arg; 721.1Sthorpej 731.1Sthorpej sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED); 741.1Sthorpej} 751.1Sthorpej 761.1Sthorpejstatic int 771.1Sthorpejbeccbut_intr(void *arg) 781.1Sthorpej{ 791.1Sthorpej struct beccbut_softc *sc = arg; 801.1Sthorpej int rv; 811.1Sthorpej 821.1Sthorpej rv = sysmon_task_queue_sched(0, beccbut_pressed_event, sc); 831.1Sthorpej if (rv != 0) 841.1Sthorpej printf("%s: WARNING: unable to queue button pressed " 851.4Smatt "callback: %d\n", device_xname(sc->sc_dev), rv); 861.1Sthorpej 871.1Sthorpej return (1); 881.1Sthorpej} 891.1Sthorpej 901.1Sthorpejstatic int 911.4Smattbeccbut_match(device_t parent, cfdata_t match, void *aux) 921.1Sthorpej{ 931.1Sthorpej 941.1Sthorpej return (beccbut_attached == 0); 951.1Sthorpej} 961.1Sthorpej 971.1Sthorpejstatic void 981.4Smattbeccbut_attach(device_t parent, device_t self, void *aux) 991.1Sthorpej{ 1001.4Smatt struct beccbut_softc *sc = device_private(self); 1011.1Sthorpej 1021.4Smatt aprint_normal(": Reset button\n"); 1031.4Smatt aprint_naive(": Reset button\n"); 1041.1Sthorpej 1051.1Sthorpej beccbut_attached = 1; 1061.4Smatt sc->sc_dev = self; 1071.1Sthorpej 1081.1Sthorpej sysmon_task_queue_init(); 1091.1Sthorpej 1101.4Smatt sc->sc_smpsw.smpsw_name = device_xname(sc->sc_dev); 1111.1Sthorpej sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_RESET; 1121.1Sthorpej 1131.1Sthorpej if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) { 1141.4Smatt aprint_error_dev(sc->sc_dev, 1151.4Smatt "unable to register with sysmon\n"); 1161.1Sthorpej return; 1171.1Sthorpej } 1181.1Sthorpej 1191.1Sthorpej sc->sc_ih = becc_intr_establish(ICU_PUSHBUTTON, IPL_TTY, 1201.1Sthorpej beccbut_intr, sc); 1211.1Sthorpej if (sc->sc_ih == NULL) 1221.4Smatt aprint_error_dev(sc->sc_dev, 1231.4Smatt "unable to establish interrupt handler\n"); 1241.1Sthorpej} 1251.1Sthorpej 1261.4SmattCFATTACH_DECL_NEW(beccbut, sizeof(struct beccbut_softc), 1271.1Sthorpej beccbut_match, beccbut_attach, NULL, NULL); 128