becc_button.c revision 1.1
1/*	$NetBSD: becc_button.c,v 1.1 2003/04/20 20:50:50 thorpej 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/param.h>
48#include <sys/systm.h>
49#include <sys/device.h>
50
51#include <arm/xscale/beccreg.h>
52#include <arm/xscale/beccvar.h>
53
54#include <dev/sysmon/sysmonvar.h>
55#include <dev/sysmon/sysmon_taskq.h>
56
57static int beccbut_attached;	/* there can be only one */
58
59struct beccbut_softc {
60	struct device sc_dev;
61	struct sysmon_pswitch sc_smpsw;
62	void *sc_ih;
63};
64
65static void
66beccbut_pressed_event(void *arg)
67{
68	struct beccbut_softc *sc = arg;
69
70	sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED);
71}
72
73static int
74beccbut_intr(void *arg)
75{
76	struct beccbut_softc *sc = arg;
77	int rv;
78
79	rv = sysmon_task_queue_sched(0, beccbut_pressed_event, sc);
80	if (rv != 0)
81		printf("%s: WARNING: unable to queue button pressed "
82		    "callback: %d\n", sc->sc_dev.dv_xname, rv);
83
84	return (1);
85}
86
87static int
88beccbut_match(struct device *parent, struct cfdata *match, void *aux)
89{
90
91	return (beccbut_attached == 0);
92}
93
94static void
95beccbut_attach(struct device *parent, struct device *self, void *aux)
96{
97	struct beccbut_softc *sc = (void *) self;
98
99	printf(": Reset button\n");
100
101	beccbut_attached = 1;
102
103	sysmon_task_queue_init();
104
105	sc->sc_smpsw.smpsw_name = sc->sc_dev.dv_xname;
106	sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_RESET;
107
108	if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) {
109		printf("%s: unable to register with sysmon\n",
110		    sc->sc_dev.dv_xname);
111		return;
112	}
113
114	sc->sc_ih = becc_intr_establish(ICU_PUSHBUTTON, IPL_TTY,
115	    beccbut_intr, sc);
116	if (sc->sc_ih == NULL)
117		printf("%s: unable to establish interrupt handler\n",
118		    sc->sc_dev.dv_xname);
119}
120
121CFATTACH_DECL(beccbut, sizeof(struct beccbut_softc),
122    beccbut_match, beccbut_attach, NULL, NULL);
123