1 /* $NetBSD: joy_eap.c,v 1.11 2009/05/06 09:32:52 cegger Exp $ */
4 __KERNEL_RCSID(0, "$NetBSD: joy_eap.c,v 1.11 2009/05/06 09:32:52 cegger Exp $");
8 #include <sys/kernel.h>
9 #include <sys/device.h>
10 #include <sys/audioio.h>
11 #include <dev/audio_if.h>
14 #include <dev/pci/eapreg.h>
15 #include <dev/pci/eapvar.h>
16 #include <dev/ic/joyvar.h>
19 struct audio_attach_args aa_aaa
;
20 bus_space_tag_t aa_iot
;
21 bus_space_handle_t aa_ioh
;
25 eap_joy_attach(device_t eapdev
, struct eap_gameport_args
*gpa
)
28 bus_space_handle_t ioh
;
34 * There are 4 possible locations. Just try to map one of them.
35 * XXX This is questionable for 2 reasons:
36 * - We don't know whether these addresses are usable on our
37 * PCI bus (might be a secondary one).
38 * - PCI probing is early. ISA devices might conflict.
40 for (i
= 0; i
< 4; i
++) {
41 if (bus_space_map(gpa
->gpa_iot
, 0x200 + i
* 8, 1,
48 printf("%s: enabling gameport at legacy io port 0x%x\n",
49 device_xname(eapdev
), 0x200 + i
* 8);
51 /* enable gameport on eap */
52 icsc
= bus_space_read_4(gpa
->gpa_iot
, gpa
->gpa_ioh
, EAP_ICSC
);
53 icsc
&= ~E1371_JOY_ASELBITS
;
54 icsc
|= EAP_JYSTK_EN
| E1371_JOY_ASEL(i
);
55 bus_space_write_4(gpa
->gpa_iot
, gpa
->gpa_ioh
, EAP_ICSC
, icsc
);
57 aa
.aa_aaa
.type
= AUDIODEV_TYPE_AUX
;
58 aa
.aa_iot
= gpa
->gpa_iot
;
60 joydev
= config_found(eapdev
, &aa
, 0);
61 /* this cannot fail */
62 KASSERT(joydev
!= NULL
);
68 eap_joy_detach(device_t joydev
, struct eap_gameport_args
*gpa
)
71 struct joy_softc
*sc
= device_private(joydev
);
74 res
= config_detach(joydev
, 0);
78 /* disable gameport on eap */
79 icsc
= bus_space_read_4(gpa
->gpa_iot
, gpa
->gpa_ioh
, EAP_ICSC
);
80 icsc
&= ~EAP_JYSTK_EN
;
81 bus_space_write_4(gpa
->gpa_iot
, gpa
->gpa_ioh
, EAP_ICSC
, icsc
);
83 bus_space_unmap(sc
->sc_iot
, sc
->sc_ioh
, 1);
88 joy_eap_match(device_t parent
, cfdata_t match
, void *aux
)
90 struct joy_eap_aa
*eaa
= aux
;
92 if (eaa
->aa_aaa
.type
!= AUDIODEV_TYPE_AUX
)
98 joy_eap_attach(device_t parent
, device_t self
, void *aux
)
100 struct joy_softc
*sc
= device_private(self
);
101 struct joy_eap_aa
*eaa
= aux
;
105 sc
->sc_iot
= eaa
->aa_iot
;
106 sc
->sc_ioh
= eaa
->aa_ioh
;
113 joy_eap_detach(device_t self
, int flags
)
116 return joydetach(device_private(self
), flags
);
119 CFATTACH_DECL_NEW(joy_eap
, sizeof (struct joy_softc
),
120 joy_eap_match
, joy_eap_attach
, joy_eap_detach
, NULL
);