Home | History | Annotate | Line # | Download | only in pci
joy_eap.c revision 1.6.28.1
      1  1.6.28.1    bouyer /* $NetBSD: joy_eap.c,v 1.6.28.1 2007/10/25 22:39:10 bouyer Exp $ */
      2       1.1  drochner 
      3       1.1  drochner #include <sys/param.h>
      4       1.1  drochner #include <sys/systm.h>
      5       1.1  drochner #include <sys/kernel.h>
      6       1.1  drochner #include <sys/device.h>
      7       1.1  drochner #include <sys/audioio.h>
      8       1.1  drochner #include <dev/audio_if.h>
      9  1.6.28.1    bouyer #include <sys/bus.h>
     10       1.1  drochner 
     11       1.1  drochner #include <dev/pci/eapreg.h>
     12       1.1  drochner #include <dev/pci/eapvar.h>
     13       1.1  drochner #include <dev/ic/joyvar.h>
     14       1.1  drochner 
     15       1.1  drochner struct joy_eap_aa {
     16       1.1  drochner 	struct audio_attach_args aa_aaa;
     17       1.1  drochner 	bus_space_tag_t aa_iot;
     18       1.1  drochner 	bus_space_handle_t aa_ioh;
     19       1.1  drochner };
     20       1.1  drochner 
     21       1.1  drochner struct device *
     22       1.1  drochner eap_joy_attach(struct device *eapdev, struct eap_gameport_args *gpa)
     23       1.1  drochner {
     24       1.1  drochner 	int i;
     25       1.1  drochner 	bus_space_handle_t ioh;
     26       1.1  drochner 	u_int32_t icsc;
     27       1.1  drochner 	struct joy_eap_aa aa;
     28       1.1  drochner 	struct device *joydev;
     29       1.1  drochner 
     30       1.1  drochner 	/*
     31       1.1  drochner 	 * There are 4 possible locations. Just try to map one of them.
     32       1.1  drochner 	 * XXX This is questionable for 2 reasons:
     33       1.1  drochner 	 * - We don't know whether these addresses are usable on our
     34       1.1  drochner 	 *   PCI bus (might be a secondary one).
     35       1.1  drochner 	 * - PCI probing is early. ISA devices might conflict.
     36       1.1  drochner 	 */
     37       1.1  drochner 	for (i = 0; i < 4; i++) {
     38       1.1  drochner 		if (bus_space_map(gpa->gpa_iot, 0x200 + i * 8, 1,
     39       1.1  drochner 		    0, &ioh) == 0)
     40       1.1  drochner 			break;
     41       1.1  drochner 	}
     42       1.1  drochner 	if (i == 4)
     43       1.1  drochner 		return (0);
     44       1.1  drochner 
     45       1.1  drochner 	printf("%s: enabling gameport at legacy io port 0x%x\n",
     46       1.1  drochner 		eapdev->dv_xname, 0x200 + i * 8);
     47       1.1  drochner 
     48       1.1  drochner 	/* enable gameport on eap */
     49       1.1  drochner 	icsc = bus_space_read_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC);
     50       1.1  drochner 	icsc &= ~E1371_JOY_ASELBITS;
     51       1.1  drochner 	icsc |= EAP_JYSTK_EN | E1371_JOY_ASEL(i);
     52       1.1  drochner 	bus_space_write_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC, icsc);
     53       1.1  drochner 
     54       1.1  drochner 	aa.aa_aaa.type = AUDIODEV_TYPE_AUX;
     55       1.1  drochner 	aa.aa_iot = gpa->gpa_iot;
     56       1.1  drochner 	aa.aa_ioh = ioh;
     57       1.1  drochner 	joydev = config_found(eapdev, &aa, 0);
     58       1.1  drochner 	/* this cannot fail */
     59       1.1  drochner 	KASSERT(joydev != NULL);
     60       1.1  drochner 
     61       1.1  drochner 	return (joydev);
     62       1.1  drochner }
     63       1.1  drochner 
     64       1.1  drochner int
     65       1.1  drochner eap_joy_detach(struct device *joydev, struct eap_gameport_args *gpa)
     66       1.1  drochner {
     67       1.1  drochner 	int res;
     68       1.1  drochner 	struct joy_softc *sc = (struct joy_softc *)joydev;
     69       1.1  drochner 	u_int32_t icsc;
     70       1.1  drochner 
     71       1.1  drochner 	res = config_detach(joydev, 0);
     72       1.1  drochner 	if (res)
     73       1.1  drochner 		return (res);
     74       1.1  drochner 
     75       1.1  drochner 	/* disable gameport on eap */
     76       1.1  drochner 	icsc = bus_space_read_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC);
     77       1.1  drochner 	icsc &= ~EAP_JYSTK_EN;
     78       1.1  drochner 	bus_space_write_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC, icsc);
     79       1.1  drochner 
     80       1.1  drochner 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, 1);
     81       1.1  drochner 	return (0);
     82       1.1  drochner }
     83       1.1  drochner 
     84       1.3   thorpej static int
     85       1.6  christos joy_eap_match(struct device *parent, struct cfdata *match,
     86       1.5  christos     void *aux)
     87       1.1  drochner {
     88       1.1  drochner 	struct joy_eap_aa *eaa = aux;
     89       1.1  drochner 
     90       1.1  drochner 	if (eaa->aa_aaa.type != AUDIODEV_TYPE_AUX)
     91       1.1  drochner 		return (0);
     92       1.1  drochner 	return (1);
     93       1.1  drochner }
     94       1.1  drochner 
     95       1.3   thorpej static void
     96       1.6  christos joy_eap_attach(struct device *parent, struct device *self, void *aux)
     97       1.1  drochner {
     98       1.1  drochner 	struct joy_softc *sc = (struct joy_softc *)self;
     99       1.1  drochner 	struct joy_eap_aa *eaa = aux;
    100       1.1  drochner 
    101       1.1  drochner 	printf("\n");
    102       1.1  drochner 
    103       1.1  drochner 	sc->sc_iot = eaa->aa_iot;
    104       1.1  drochner 	sc->sc_ioh = eaa->aa_ioh;
    105       1.1  drochner 
    106       1.1  drochner 	joyattach(sc);
    107       1.1  drochner }
    108       1.1  drochner 
    109       1.3   thorpej static int
    110       1.1  drochner joy_eap_detach(struct device *self, int flags)
    111       1.1  drochner {
    112       1.1  drochner 
    113       1.2  drochner 	return (joydetach((struct joy_softc *)self, flags));
    114       1.1  drochner }
    115       1.3   thorpej 
    116       1.3   thorpej CFATTACH_DECL(joy_eap, sizeof (struct joy_softc),
    117       1.3   thorpej 	joy_eap_match, joy_eap_attach, joy_eap_detach, NULL);
    118