1 /* $NetBSD: pwrsw_obio.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */
4 * Copyright (c) 2005 NONAKA Kimihiro
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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>
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
{
54 struct sysmon_pswitch sc_smpsw
; /* our sysmon glue */
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
;
72 pwrsw_obio_probe(device_t parent
, cfdata_t cfp
, void *aux
)
74 struct obio_attach_args
*oa
= aux
;
82 oa
->oa_irq
[0].or_irq
= LANDISK_INTR_PWRSW
;
88 pwrsw_obio_attach(device_t parent
, device_t self
, void *aux
)
90 struct pwrsw_obio_softc
*sc
;
93 aprint_normal(": Power Switch\n");
95 sc
= device_private(self
);
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
,
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");
114 sc
->sc_flags
|= SYSMON_ATTACHED
;
118 pwrsw_intr(void *arg
)
120 struct pwrsw_obio_softc
*sc
= arg
;
123 status
= (int8_t)_reg_read_1(LANDISK_BTNSTAT
);
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
);
134 extintr_disable_by_num(LANDISK_INTR_BTN
);
137 aprint_normal_dev(sc
->sc_dev
, "pressed\n");
139 _reg_write_1(LANDISK_PWRSW_INTCLR
, 1);
146 pwrsw_pressed_event(void *arg
)
148 struct pwrsw_obio_softc
*sc
= arg
;
150 sysmon_pswitch_event(&sc
->sc_smpsw
, PSWITCH_EVENT_PRESSED
);