4 * Copyright (c) 2005, 2006 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
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD$");
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 #include <sys/malloc.h>
37 #include <sys/kernel.h>
39 #include <sys/ioctl.h>
40 #include <sys/callout.h>
42 #include <arm/xscale/i80321var.h>
44 #include <machine/bus.h>
45 #include <machine/intr.h>
47 #include <dev/sysmon/sysmonvar.h>
48 #include <dev/sysmon/sysmon_taskq.h>
50 #include <evbarm/hdl_g/hdlgreg.h>
51 #include <evbarm/hdl_g/obiovar.h>
53 struct btn_obio_softc
{
55 bus_space_tag_t sc_iot
;
56 bus_space_handle_t sc_ioh
;
59 struct sysmon_pswitch sc_smpsw
[2];
64 static int btn_obio_match(struct device
*, struct cfdata
*, void *);
65 static void btn_obio_attach(struct device
*, struct device
*, void *);
67 static int btn_intr(void *aux
);
68 static void btn_sysmon_pressed_event(void *arg
);
70 CFATTACH_DECL(btn_obio
, sizeof(struct btn_obio_softc
),
71 btn_obio_match
, btn_obio_attach
, NULL
, NULL
);
74 btn_obio_match(struct device
*parent
, struct cfdata
*cfp
, void *aux
)
77 /* We take it on faith that the device is there. */
82 btn_obio_attach(struct device
*parent
, struct device
*self
, void *aux
)
84 struct obio_attach_args
*oba
= aux
;
85 struct btn_obio_softc
*sc
= (void *)self
;
88 sc
->sc_iot
= oba
->oba_st
;
89 error
= bus_space_map(sc
->sc_iot
, oba
->oba_addr
, 1, 0, &sc
->sc_ioh
);
91 aprint_error(": failed to map registers: %d\n", error
);
95 sysmon_power_settype("landisk");
96 sysmon_task_queue_init();
99 sc
->sc_smpsw
[0].smpsw_name
= device_xname(&sc
->sc_dev
);
100 sc
->sc_smpsw
[0].smpsw_type
= PSWITCH_TYPE_POWER
;
101 if (sysmon_pswitch_register(&sc
->sc_smpsw
[0]) != 0) {
102 aprint_error(": unable to register power button with sysmon\n");
105 sc
->sc_mask
|= BTNSTAT_POWER
;
106 hdlg_enable_pldintr(INTEN_PWRSW
);
109 sc
->sc_smpsw
[1].smpsw_name
= device_xname(&sc
->sc_dev
);
110 sc
->sc_smpsw
[1].smpsw_type
= PSWITCH_TYPE_RESET
;
111 if (sysmon_pswitch_register(&sc
->sc_smpsw
[1]) != 0) {
112 aprint_error(": unable to register reset button with sysmon\n");
115 sc
->sc_mask
|= BTNSTAT_RESET
;
117 sc
->sc_ih
= i80321_intr_establish(oba
->oba_irq
, IPL_TTY
, btn_intr
, sc
);
118 if (sc
->sc_ih
== NULL
) {
119 aprint_error(": couldn't establish intr handler");
122 hdlg_enable_pldintr(INTEN_BUTTON
);
130 struct btn_obio_softc
*sc
= (void *)arg
;
134 status
= (int8_t)bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, 0);
141 if (status
& BTNSTAT_POWER
) {
142 if (sc
->sc_mask
& BTNSTAT_POWER
) {
143 hdlg_disable_pldintr(INTEN_PWRSW
|INTEN_BUTTON
);
144 i80321_intr_disestablish(sc
->sc_ih
);
146 sysmon_task_queue_sched(0, btn_sysmon_pressed_event
,
149 aprint_error("%s: power button pressed\n",
150 device_xname(&sc
->sc_dev
));
153 } else if (status
& BTNSTAT_RESET
) {
154 if (sc
->sc_mask
& BTNSTAT_RESET
) {
155 hdlg_disable_pldintr(INTEN_PWRSW
|INTEN_BUTTON
);
156 i80321_intr_disestablish(sc
->sc_ih
);
158 sysmon_task_queue_sched(0, btn_sysmon_pressed_event
,
161 aprint_error("%s: reset button pressed\n",
162 device_xname(&sc
->sc_dev
));
171 btn_sysmon_pressed_event(void *arg
)
173 struct sysmon_pswitch
*smpsw
= (void *)arg
;
175 sysmon_pswitch_event(smpsw
, PSWITCH_EVENT_PRESSED
);