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