No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / landisk / dev / pwrsw_obio.c
blob7c40ad8fcd886e5816fe1a2559ff9b2239210e7c
1 /* $NetBSD: pwrsw_obio.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */
3 /*-
4 * Copyright (c) 2005 NONAKA Kimihiro
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include "btn_obio.h"
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: pwrsw_obio.c,v 1.1 2006/09/01 21:26:18 uwe Exp $");
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/malloc.h>
39 #include <sys/conf.h>
40 #include <sys/ioctl.h>
42 #include <dev/sysmon/sysmonvar.h>
43 #include <dev/sysmon/sysmon_taskq.h>
45 #include <sh3/devreg.h>
47 #include <landisk/landisk/landiskreg.h>
48 #include <landisk/dev/obiovar.h>
50 struct pwrsw_obio_softc {
51 device_t sc_dev;
52 void *sc_ih;
54 struct sysmon_pswitch sc_smpsw; /* our sysmon glue */
56 int sc_flags;
57 #define SYSMON_ATTACHED 1
60 static int pwrsw_obio_probe(device_t, cfdata_t, void *);
61 static void pwrsw_obio_attach(device_t, device_t, void *);
63 static int pwrsw_intr(void *aux);
64 static void pwrsw_pressed_event(void *arg);
66 CFATTACH_DECL_NEW(pwrsw_obio, sizeof(struct pwrsw_obio_softc),
67 pwrsw_obio_probe, pwrsw_obio_attach, NULL, NULL);
69 static struct pwrsw_obio_softc *pwrsw_softc;
71 static int
72 pwrsw_obio_probe(device_t parent, cfdata_t cfp, void *aux)
74 struct obio_attach_args *oa = aux;
76 if (pwrsw_softc)
77 return (0);
79 oa->oa_nio = 0;
80 oa->oa_niomem = 0;
81 oa->oa_nirq = 1;
82 oa->oa_irq[0].or_irq = LANDISK_INTR_PWRSW;
84 return (1);
87 static void
88 pwrsw_obio_attach(device_t parent, device_t self, void *aux)
90 struct pwrsw_obio_softc *sc;
92 aprint_naive("\n");
93 aprint_normal(": Power Switch\n");
95 sc = device_private(self);
96 sc->sc_dev = self;
98 pwrsw_softc = sc;
100 sc->sc_smpsw.smpsw_name = device_xname(self);
101 sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER;
103 sc->sc_ih = extintr_establish(LANDISK_INTR_PWRSW, IPL_TTY,
104 pwrsw_intr, sc);
105 if (sc->sc_ih == NULL) {
106 aprint_error_dev(self, "unable to establish interrupt");
107 panic("extintr_establish");
110 if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) {
111 aprint_error_dev(self, "unable to register with sysmon\n");
112 return;
114 sc->sc_flags |= SYSMON_ATTACHED;
117 static int
118 pwrsw_intr(void *arg)
120 struct pwrsw_obio_softc *sc = arg;
121 int status;
123 status = (int8_t)_reg_read_1(LANDISK_BTNSTAT);
124 if (status == -1) {
125 return (0);
128 status = ~status;
129 if (status & BTN_POWER_BIT) {
130 if (sc->sc_flags & SYSMON_ATTACHED) {
131 sysmon_task_queue_sched(0, pwrsw_pressed_event, sc);
132 extintr_disable(sc->sc_ih);
133 #if NBTN_OBIO > 0
134 extintr_disable_by_num(LANDISK_INTR_BTN);
135 #endif
136 } else {
137 aprint_normal_dev(sc->sc_dev, "pressed\n");
139 _reg_write_1(LANDISK_PWRSW_INTCLR, 1);
140 return (1);
142 return (0);
145 static void
146 pwrsw_pressed_event(void *arg)
148 struct pwrsw_obio_softc *sc = arg;
150 sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED);