1 /* $NetBSD: becc_button.c,v 1.4 2012/02/12 16:31:01 matt 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.4 2012/02/12 16:31:01 matt 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 device_t sc_dev;
64 struct sysmon_pswitch sc_smpsw;
65 void *sc_ih;
66 };
67
68 static void
beccbut_pressed_event(void * arg)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
beccbut_intr(void * arg)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", device_xname(sc->sc_dev), rv);
86
87 return (1);
88 }
89
90 static int
beccbut_match(device_t parent,cfdata_t match,void * aux)91 beccbut_match(device_t parent, cfdata_t match, void *aux)
92 {
93
94 return (beccbut_attached == 0);
95 }
96
97 static void
beccbut_attach(device_t parent,device_t self,void * aux)98 beccbut_attach(device_t parent, device_t self, void *aux)
99 {
100 struct beccbut_softc *sc = device_private(self);
101
102 aprint_normal(": Reset button\n");
103 aprint_naive(": Reset button\n");
104
105 beccbut_attached = 1;
106 sc->sc_dev = self;
107
108 sysmon_task_queue_init();
109
110 sc->sc_smpsw.smpsw_name = device_xname(sc->sc_dev);
111 sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_RESET;
112
113 if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) {
114 aprint_error_dev(sc->sc_dev,
115 "unable to register with sysmon\n");
116 return;
117 }
118
119 sc->sc_ih = becc_intr_establish(ICU_PUSHBUTTON, IPL_TTY,
120 beccbut_intr, sc);
121 if (sc->sc_ih == NULL)
122 aprint_error_dev(sc->sc_dev,
123 "unable to establish interrupt handler\n");
124 }
125
126 CFATTACH_DECL_NEW(beccbut, sizeof(struct beccbut_softc),
127 beccbut_match, beccbut_attach, NULL, NULL);
128