No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / xscale / becc_button.c
blob493c2c30cff5513897e4d7c7e69a31824e8df5f6
1 /* $NetBSD: becc_button.c,v 1.1.2.3 2004/09/21 13:13:42 skrll Exp $ */
3 /*
4 * Copyright (c) 2003 Wasabi Systems, Inc.
5 * All rights reserved.
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
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.
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.
39 * Driver for the reset button on the ADI Engineering, Inc. Big Endian
40 * Companion Chip.
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.
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: becc_button.c,v 1.1.2.3 2004/09/21 13:13:42 skrll Exp $");
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/device.h>
54 #include <arm/xscale/beccreg.h>
55 #include <arm/xscale/beccvar.h>
57 #include <dev/sysmon/sysmonvar.h>
58 #include <dev/sysmon/sysmon_taskq.h>
60 static int beccbut_attached; /* there can be only one */
62 struct beccbut_softc {
63 struct device sc_dev;
64 struct sysmon_pswitch sc_smpsw;
65 void *sc_ih;
68 static void
69 beccbut_pressed_event(void *arg)
71 struct beccbut_softc *sc = arg;
73 sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED);
76 static int
77 beccbut_intr(void *arg)
79 struct beccbut_softc *sc = arg;
80 int rv;
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);
87 return (1);
90 static int
91 beccbut_match(struct device *parent, struct cfdata *match, void *aux)
94 return (beccbut_attached == 0);
97 static void
98 beccbut_attach(struct device *parent, struct device *self, void *aux)
100 struct beccbut_softc *sc = (void *) self;
102 printf(": Reset button\n");
104 beccbut_attached = 1;
106 sysmon_task_queue_init();
108 sc->sc_smpsw.smpsw_name = sc->sc_dev.dv_xname;
109 sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_RESET;
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;
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);
124 CFATTACH_DECL(beccbut, sizeof(struct beccbut_softc),
125 beccbut_match, beccbut_attach, NULL, NULL);