2011-11-24 03:07:28 +04:00
|
|
|
/* $NetBSD: joy_eap.c,v 1.13 2011/11/23 23:07:35 jmcneill Exp $ */
|
2007-12-11 14:25:46 +03:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2011-11-24 03:07:28 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: joy_eap.c,v 1.13 2011/11/23 23:07:35 jmcneill Exp $");
|
2004-07-08 23:39:00 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/audioio.h>
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
2004-07-08 23:39:00 +04:00
|
|
|
|
2011-11-24 03:07:28 +04:00
|
|
|
#include <dev/audio_if.h>
|
|
|
|
|
2004-07-08 23:39:00 +04:00
|
|
|
#include <dev/pci/eapreg.h>
|
|
|
|
#include <dev/pci/eapvar.h>
|
2011-11-24 03:07:28 +04:00
|
|
|
|
2004-07-08 23:39:00 +04:00
|
|
|
#include <dev/ic/joyvar.h>
|
|
|
|
|
|
|
|
struct joy_eap_aa {
|
|
|
|
struct audio_attach_args aa_aaa;
|
|
|
|
bus_space_tag_t aa_iot;
|
|
|
|
bus_space_handle_t aa_ioh;
|
|
|
|
};
|
|
|
|
|
2008-03-26 21:27:07 +03:00
|
|
|
device_t
|
|
|
|
eap_joy_attach(device_t eapdev, struct eap_gameport_args *gpa)
|
2004-07-08 23:39:00 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
u_int32_t icsc;
|
|
|
|
struct joy_eap_aa aa;
|
2008-03-26 21:27:07 +03:00
|
|
|
device_t joydev;
|
2004-07-08 23:39:00 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There are 4 possible locations. Just try to map one of them.
|
|
|
|
* XXX This is questionable for 2 reasons:
|
|
|
|
* - We don't know whether these addresses are usable on our
|
|
|
|
* PCI bus (might be a secondary one).
|
|
|
|
* - PCI probing is early. ISA devices might conflict.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (bus_space_map(gpa->gpa_iot, 0x200 + i * 8, 1,
|
|
|
|
0, &ioh) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == 4)
|
2008-03-26 21:27:07 +03:00
|
|
|
return 0;
|
2004-07-08 23:39:00 +04:00
|
|
|
|
|
|
|
printf("%s: enabling gameport at legacy io port 0x%x\n",
|
2008-04-10 23:13:36 +04:00
|
|
|
device_xname(eapdev), 0x200 + i * 8);
|
2004-07-08 23:39:00 +04:00
|
|
|
|
|
|
|
/* enable gameport on eap */
|
|
|
|
icsc = bus_space_read_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC);
|
|
|
|
icsc &= ~E1371_JOY_ASELBITS;
|
|
|
|
icsc |= EAP_JYSTK_EN | E1371_JOY_ASEL(i);
|
|
|
|
bus_space_write_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC, icsc);
|
|
|
|
|
|
|
|
aa.aa_aaa.type = AUDIODEV_TYPE_AUX;
|
|
|
|
aa.aa_iot = gpa->gpa_iot;
|
|
|
|
aa.aa_ioh = ioh;
|
|
|
|
joydev = config_found(eapdev, &aa, 0);
|
|
|
|
/* this cannot fail */
|
|
|
|
KASSERT(joydev != NULL);
|
|
|
|
|
2008-03-26 21:27:07 +03:00
|
|
|
return joydev;
|
2004-07-08 23:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-26 21:27:07 +03:00
|
|
|
eap_joy_detach(device_t joydev, struct eap_gameport_args *gpa)
|
2004-07-08 23:39:00 +04:00
|
|
|
{
|
|
|
|
int res;
|
2009-05-07 11:56:03 +04:00
|
|
|
struct joy_softc *sc = device_private(joydev);
|
2004-07-08 23:39:00 +04:00
|
|
|
u_int32_t icsc;
|
|
|
|
|
|
|
|
res = config_detach(joydev, 0);
|
|
|
|
if (res)
|
2008-03-26 21:27:07 +03:00
|
|
|
return res;
|
2004-07-08 23:39:00 +04:00
|
|
|
|
|
|
|
/* disable gameport on eap */
|
|
|
|
icsc = bus_space_read_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC);
|
|
|
|
icsc &= ~EAP_JYSTK_EN;
|
|
|
|
bus_space_write_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC, icsc);
|
|
|
|
|
|
|
|
bus_space_unmap(sc->sc_iot, sc->sc_ioh, 1);
|
2008-03-26 21:27:07 +03:00
|
|
|
return 0;
|
2004-07-08 23:39:00 +04:00
|
|
|
}
|
|
|
|
|
2005-06-28 04:28:41 +04:00
|
|
|
static int
|
2008-03-26 21:27:07 +03:00
|
|
|
joy_eap_match(device_t parent, cfdata_t match, void *aux)
|
2004-07-08 23:39:00 +04:00
|
|
|
{
|
|
|
|
struct joy_eap_aa *eaa = aux;
|
|
|
|
|
|
|
|
if (eaa->aa_aaa.type != AUDIODEV_TYPE_AUX)
|
2008-03-26 21:27:07 +03:00
|
|
|
return 0;
|
|
|
|
return 1;
|
2004-07-08 23:39:00 +04:00
|
|
|
}
|
|
|
|
|
2005-06-28 04:28:41 +04:00
|
|
|
static void
|
2008-03-26 21:27:07 +03:00
|
|
|
joy_eap_attach(device_t parent, device_t self, void *aux)
|
2004-07-08 23:39:00 +04:00
|
|
|
{
|
2008-03-26 21:27:07 +03:00
|
|
|
struct joy_softc *sc = device_private(self);
|
2011-11-24 03:07:28 +04:00
|
|
|
struct eap_softc *esc = device_private(parent);
|
2004-07-08 23:39:00 +04:00
|
|
|
struct joy_eap_aa *eaa = aux;
|
|
|
|
|
2008-03-26 21:27:07 +03:00
|
|
|
aprint_normal("\n");
|
2004-07-08 23:39:00 +04:00
|
|
|
|
|
|
|
sc->sc_iot = eaa->aa_iot;
|
|
|
|
sc->sc_ioh = eaa->aa_ioh;
|
2008-03-26 21:27:07 +03:00
|
|
|
sc->sc_dev = self;
|
2011-11-24 03:07:28 +04:00
|
|
|
sc->sc_lock = &esc->sc_lock;
|
2004-07-08 23:39:00 +04:00
|
|
|
|
|
|
|
joyattach(sc);
|
|
|
|
}
|
|
|
|
|
2005-06-28 04:28:41 +04:00
|
|
|
static int
|
2008-03-26 21:27:07 +03:00
|
|
|
joy_eap_detach(device_t self, int flags)
|
2004-07-08 23:39:00 +04:00
|
|
|
{
|
|
|
|
|
2009-05-06 13:32:52 +04:00
|
|
|
return joydetach(device_private(self), flags);
|
2004-07-08 23:39:00 +04:00
|
|
|
}
|
2005-06-28 04:28:41 +04:00
|
|
|
|
2008-03-26 21:27:07 +03:00
|
|
|
CFATTACH_DECL_NEW(joy_eap, sizeof (struct joy_softc),
|
2005-06-28 04:28:41 +04:00
|
|
|
joy_eap_match, joy_eap_attach, joy_eap_detach, NULL);
|