1 /* $NetBSD: adb_bus.c,v 1.8 2008/04/29 06:53:02 martin Exp $ */
4 * Copyright (c) 2009 Michael Lorenz
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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: adb_bus.c,v 1.8 2008/04/29 06:53:02 martin Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/device.h>
37 #include <sys/kthread.h>
41 #include <dev/sysmon/sysmonvar.h>
42 #include <dev/sysmon/sysmon_taskq.h>
44 #include <machine/autoconf.h>
45 #include <machine/machtype.h>
47 #include <sgimips/ioc/iocreg.h>
48 #include <sgimips/hpc/hpcvar.h>
49 #include <sgimips/hpc/hpcreg.h>
53 struct sysmon_pswitch sc_pbutton
;
54 bus_space_tag_t sc_tag
;
55 bus_space_handle_t sc_hreg
;
56 int sc_last
, sc_fired
;
59 static int panel_match(device_t
, cfdata_t
, void *);
60 static void panel_attach(device_t
, device_t
, void *);
62 static int panel_intr(void *);
63 static void panel_powerbutton(void *);
65 CFATTACH_DECL_NEW(panel
, sizeof(struct panel_softc
),
72 panel_match(device_t parent
, cfdata_t match
, void *aux
)
74 if (mach_type
== MACH_SGI_IP22
)
81 panel_attach(device_t parent
, device_t self
, void *aux
)
83 struct panel_softc
*sc
;
84 struct hpc_attach_args
*haa
;
86 sc
= device_private(self
);
89 sc
->sc_tag
= haa
->ha_st
;
93 if (bus_space_subregion(haa
->ha_st
, haa
->ha_sh
, haa
->ha_devoff
,
94 0x1, /* just a single register */
96 aprint_error(": unable to map panel register\n");
100 if ((cpu_intr_establish(haa
->ha_irq
, IPL_BIO
,
101 panel_intr
, sc
)) == NULL
) {
102 printf(": unable to establish interrupt!\n");
108 sysmon_task_queue_init();
109 memset(&sc
->sc_pbutton
, 0, sizeof(struct sysmon_pswitch
));
110 sc
->sc_pbutton
.smpsw_name
= device_xname(sc
->sc_dev
);
111 sc
->sc_pbutton
.smpsw_type
= PSWITCH_TYPE_POWER
;
112 if (sysmon_pswitch_register(&sc
->sc_pbutton
) != 0)
113 aprint_error_dev(sc
->sc_dev
,
114 "unable to register power button with sysmon\n");
115 pmf_device_register(self
, NULL
, NULL
);
119 panel_intr(void *cookie
)
121 struct panel_softc
*sc
= cookie
;
124 reg
= bus_space_read_1(sc
->sc_tag
, sc
->sc_hreg
, 0);
125 bus_space_write_1(sc
->sc_tag
, sc
->sc_hreg
, 0,
126 IOC_PANEL_VDOWN_IRQ
| IOC_PANEL_VUP_IRQ
| IOC_PANEL_POWER_IRQ
);
127 if ((reg
& IOC_PANEL_POWER_IRQ
) == 0) {
129 sysmon_task_queue_sched(0, panel_powerbutton
, sc
);
132 if (time_second
== sc
->sc_last
)
134 sc
->sc_last
= time_second
;
135 if ((reg
& IOC_PANEL_VDOWN_HOLD
) == 0)
136 pmf_event_inject(NULL
, PMFE_AUDIO_VOLUME_DOWN
);
137 if ((reg
& IOC_PANEL_VUP_HOLD
) == 0)
138 pmf_event_inject(NULL
, PMFE_AUDIO_VOLUME_UP
);
144 panel_powerbutton(void *cookie
)
146 struct panel_softc
*sc
= cookie
;
148 sysmon_pswitch_event(&sc
->sc_pbutton
, PSWITCH_EVENT_PRESSED
);