Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / evbarm / nslu2 / nslu2_buttons.c
blob80e100acbf8b1944e992256352a0ca496943955f
1 /* $NetBSD: nslu2_buttons.c,v 1.2 2006/03/01 21:02:50 scw Exp $ */
3 /*-
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: nslu2_buttons.c,v 1.2 2006/03/01 21:02:50 scw Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
39 #include <dev/sysmon/sysmonvar.h>
40 #include <dev/sysmon/sysmon_taskq.h>
42 #include <arm/xscale/ixp425reg.h>
43 #include <arm/xscale/ixp425var.h>
45 #include <evbarm/nslu2/nslu2reg.h>
47 struct slugbutt_softc {
48 struct device sc_dev;
49 struct sysmon_pswitch sc_smpwr;
50 struct sysmon_pswitch sc_smrst;
53 static int slugbutt_attached;
55 #define SLUGBUTT_PWR_BIT (1u << GPIO_BUTTON_PWR)
56 #define SLUGBUTT_RST_BIT (1u << GPIO_BUTTON_RST)
58 static void
59 power_event(void *arg)
61 struct slugbutt_softc *sc = arg;
63 sysmon_pswitch_event(&sc->sc_smpwr, PSWITCH_EVENT_PRESSED);
66 static int
67 power_intr(void *arg)
69 struct slugbutt_softc *sc = arg;
70 int rv;
72 GPIO_CONF_WRITE_4(ixp425_softc, IXP425_GPIO_GPISR, SLUGBUTT_PWR_BIT);
74 rv = sysmon_task_queue_sched(0, power_event, sc);
75 if (rv) {
76 printf("%s: WARNING: unable to queue power button "
77 "callback: %d\n", sc->sc_dev.dv_xname, rv);
80 return (1);
83 static void
84 reset_event(void *arg)
86 struct slugbutt_softc *sc = arg;
88 sysmon_pswitch_event(&sc->sc_smrst, PSWITCH_EVENT_PRESSED);
91 static int
92 reset_intr(void *arg)
94 struct slugbutt_softc *sc = arg;
95 int rv;
97 GPIO_CONF_WRITE_4(ixp425_softc, IXP425_GPIO_GPISR, SLUGBUTT_RST_BIT);
99 rv = sysmon_task_queue_sched(0, reset_event, sc);
100 if (rv) {
101 printf("%s: WARNING: unable to queue reset button "
102 "callback: %d\n", sc->sc_dev.dv_xname, rv);
105 return (1);
108 static void
109 slugbutt_deferred(struct device *self)
111 struct slugbutt_softc *sc = (struct slugbutt_softc *) self;
112 struct ixp425_softc *ixsc = ixp425_softc;
113 uint32_t reg;
115 /* Configure the GPIO pins as inputs */
116 reg = GPIO_CONF_READ_4(ixsc, IXP425_GPIO_GPOER);
117 reg |= SLUGBUTT_PWR_BIT | SLUGBUTT_RST_BIT;
118 GPIO_CONF_WRITE_4(ixsc, IXP425_GPIO_GPOER, reg);
120 /* Configure the input type: Falling edge */
121 reg = GPIO_CONF_READ_4(ixsc, GPIO_TYPE_REG(GPIO_BUTTON_PWR));
122 reg &= ~GPIO_TYPE(GPIO_BUTTON_PWR, GPIO_TYPE_MASK);
123 reg |= GPIO_TYPE(GPIO_BUTTON_PWR, GPIO_TYPE_EDG_FALLING);
124 GPIO_CONF_WRITE_4(ixsc, GPIO_TYPE_REG(GPIO_BUTTON_PWR), reg);
126 reg = GPIO_CONF_READ_4(ixsc, GPIO_TYPE_REG(GPIO_BUTTON_RST));
127 reg &= ~GPIO_TYPE(GPIO_BUTTON_RST, GPIO_TYPE_MASK);
128 reg |= GPIO_TYPE(GPIO_BUTTON_RST, GPIO_TYPE_EDG_FALLING);
129 GPIO_CONF_WRITE_4(ixsc, GPIO_TYPE_REG(GPIO_BUTTON_RST), reg);
131 /* Clear any existing interrupt */
132 GPIO_CONF_WRITE_4(ixsc, IXP425_GPIO_GPISR, SLUGBUTT_PWR_BIT |
133 SLUGBUTT_RST_BIT);
135 sysmon_task_queue_init();
137 sc->sc_smpwr.smpsw_name = sc->sc_dev.dv_xname;
138 sc->sc_smpwr.smpsw_type = PSWITCH_TYPE_POWER;
140 if (sysmon_pswitch_register(&sc->sc_smpwr) != 0) {
141 printf("%s: unable to register power button with sysmon\n",
142 sc->sc_dev.dv_xname);
143 return;
146 sc->sc_smrst.smpsw_name = sc->sc_dev.dv_xname;
147 sc->sc_smrst.smpsw_type = PSWITCH_TYPE_RESET;
149 if (sysmon_pswitch_register(&sc->sc_smrst) != 0) {
150 printf("%s: unable to register reset button with sysmon\n",
151 sc->sc_dev.dv_xname);
152 return;
155 /* Hook the interrupts */
156 ixp425_intr_establish(BUTTON_PWR_INT, IPL_TTY, power_intr, sc);
157 ixp425_intr_establish(BUTTON_RST_INT, IPL_TTY, reset_intr, sc);
161 static int
162 slugbutt_match(struct device *parent, struct cfdata *cf, void *arg)
165 return (slugbutt_attached == 0);
168 static void
169 slugbutt_attach(struct device *parent, struct device *self, void *arg)
172 slugbutt_attached = 1;
174 aprint_normal(": Power and Reset buttons\n");
176 /* Defer, to ensure ixp425_softc has been initialised */
177 config_interrupts(self, slugbutt_deferred);
180 CFATTACH_DECL(slugbutt, sizeof(struct slugbutt_softc),
181 slugbutt_match, slugbutt_attach, NULL, NULL);