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