Пример #1
0
/* Enable DMA */
int
atppc_isadma_setup(struct atppc_softc * lsc, isa_chipset_tag_t ic, int drq)
{
	int error = 1;

	/* Reserve DRQ */
	if (isa_drq_alloc(ic, drq)) {
		ATPPC_DPRINTF(("%s(%s): cannot reserve DRQ line.\n", __func__,
			device_xname(lsc->sc_dev)));
		return error;
	}

	/* Get maximum DMA size for isa bus */
	lsc->sc_dma_maxsize = isa_dmamaxsize(ic, drq);

	/* Create dma mapping */
	error = isa_dmamap_create(ic, drq, lsc->sc_dma_maxsize,
		BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW);

	return error;
}
Пример #2
0
void
satlinkattach(device_t parent, device_t self, void *aux)
{
	struct satlink_softc *sc = device_private(self);
	struct isa_attach_args *ia = aux;
	bus_space_tag_t iot = ia->ia_iot;
	bus_space_handle_t ioh;
	bus_addr_t ringaddr;

	printf("\n");

	/* Map the card. */
	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SATLINK_IOSIZE, 0, &ioh)) {
		aprint_error_dev(self, "can't map i/o space\n");
		return;
	}

	sc->sc_iot = iot;
	sc->sc_ioh = ioh;
	sc->sc_ic = ia->ia_ic;
	sc->sc_drq = ia->ia_drq[0].ir_drq;

	/* Reset the card. */
	bus_space_write_1(iot, ioh, SATLINK_COMMAND, SATLINK_CMD_RESET);

	/* Read ID from the card. */
	sc->sc_id.sid_mfrid =
	    bus_space_read_1(iot, ioh, SATLINK_MFRID_L) |
	    (bus_space_read_1(iot, ioh, SATLINK_MFRID_H) << 8);
	sc->sc_id.sid_grpid = bus_space_read_1(iot, ioh, SATLINK_GRPID);
	sc->sc_id.sid_userid =
	    bus_space_read_1(iot, ioh, SATLINK_USERID_L) |
	    (bus_space_read_1(iot, ioh, SATLINK_USERID_H) << 8);
	sc->sc_id.sid_serial =
	    bus_space_read_1(iot, ioh, SATLINK_SER_L) |
	    (bus_space_read_1(iot, ioh, SATLINK_SER_M0) << 8) |
	    (bus_space_read_1(iot, ioh, SATLINK_SER_M1) << 16) |
	    (bus_space_read_1(iot, ioh, SATLINK_SER_H) << 24);

	printf("%s: mfrid 0x%x, grpid 0x%x, userid 0x%x, serial %d\n",
	    device_xname(self), sc->sc_id.sid_mfrid,
	    sc->sc_id.sid_grpid, sc->sc_id.sid_userid,
	    sc->sc_id.sid_serial);

	callout_init(&sc->sc_ch, 0);
	selinit(&sc->sc_selq);

	sc->sc_bufsize = isa_dmamaxsize(sc->sc_ic, sc->sc_drq);

	/* Allocate and map the ring buffer. */
	if (isa_dmamem_alloc(sc->sc_ic, sc->sc_drq, sc->sc_bufsize,
	    &ringaddr, BUS_DMA_NOWAIT)) {
		aprint_error_dev(self, "can't allocate ring buffer\n");
		return;
	}
	if (isa_dmamem_map(sc->sc_ic, sc->sc_drq, ringaddr, sc->sc_bufsize,
	    &sc->sc_buf, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
		aprint_error_dev(self, "can't map ring buffer\n");
		isa_dmamem_free(sc->sc_ic, sc->sc_drq, ringaddr,
		    sc->sc_bufsize);
		return;
	}

	if (isa_drq_alloc(sc->sc_ic, sc->sc_drq) != 0) {
		aprint_error_dev(self, "can't reserve drq %d\n",
		    sc->sc_drq);
		isa_dmamem_unmap(sc->sc_ic, sc->sc_drq, sc->sc_buf,
		    sc->sc_bufsize);
		isa_dmamem_free(sc->sc_ic, sc->sc_drq, ringaddr,
		    sc->sc_bufsize);
		return;
	}

	/* Create the DMA map. */
	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq, sc->sc_bufsize,
	    BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
		aprint_error_dev(self, "can't create DMA map\n");
		isa_dmamem_unmap(sc->sc_ic, sc->sc_drq, sc->sc_buf,
		    sc->sc_bufsize);
		isa_dmamem_free(sc->sc_ic, sc->sc_drq, ringaddr,
		    sc->sc_bufsize);
		return;
	}
}
Пример #3
0
/*
 * Attach hardware to driver, attach hardware driver to audio
 * pseudo-device driver .
 */
void
ad1848_attach(struct ad1848_softc *sc)
{
	int i;
	struct ad1848_volume vol_mid = {220, 220};
	struct ad1848_volume vol_0   = {0, 0};
	struct audio_params pparams, rparams;
	int timeout;

	sc->sc_playrun = 0;
	sc->sc_recrun = 0;

	if (sc->sc_drq != -1) {
		if (isa_dmamap_create(sc->sc_isa, sc->sc_drq, MAX_ISADMA,
		    BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
			printf("ad1848_attach: can't create map for drq %d\n",
			    sc->sc_drq);
			return;
		}
	}
	if (sc->sc_recdrq != -1 && sc->sc_recdrq != sc->sc_drq) {
		if (isa_dmamap_create(sc->sc_isa, sc->sc_recdrq, MAX_ISADMA,
		    BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
			printf("ad1848_attach: can't create map for second drq %d\n",
			    sc->sc_recdrq);
			return;
		}
	}

	/* Initialize the ad1848... */
	for (i = 0; i < 0x10; i++) {
		ad_write(sc, i, ad1848_init_values[i]);
		timeout = AD1848_TIMO;
		while (timeout > 0 && ADREAD(sc, AD1848_IADDR) & SP_IN_INIT)
			timeout--;
	}
	/* need 2 separate drqs for mode 2 */
	if ((sc->mode == 2) &&
	    ((sc->sc_recdrq == -1) || (sc->sc_recdrq == sc->sc_drq))) {
		ad_write(sc, SP_MISC_INFO, ad_read(sc, SP_MISC_INFO) & ~MODE2);
		if (!(ad_read(sc, SP_MISC_INFO) & MODE2))
			sc->mode = 1;
	}
	/* ...and additional CS4231 stuff too */
	if (sc->mode == 2) {
		ad_write(sc, SP_INTERFACE_CONFIG, 0); /* disable SINGLE_DMA */
		for (i = 0x10; i < 0x20; i++) {
			if (ad1848_init_values[i] != 0) {
				ad_write(sc, i, ad1848_init_values[i]);
				timeout = AD1848_TIMO;
				while (timeout > 0 && 
				    ADREAD(sc, AD1848_IADDR) & SP_IN_INIT)
					timeout--;
			}
		}
	}
	ad1848_reset(sc);

	pparams = audio_default;
	rparams = audio_default;
	(void) ad1848_set_params(sc, AUMODE_RECORD|AUMODE_PLAY, 0,
	    &pparams, &rparams);

	/* Set default gains */
	(void) ad1848_set_rec_gain(sc, &vol_mid);
	(void) ad1848_set_channel_gain(sc, AD1848_DAC_CHANNEL, &vol_mid);
	(void) ad1848_set_channel_gain(sc, AD1848_MONITOR_CHANNEL, &vol_0);
	/* CD volume */
	(void) ad1848_set_channel_gain(sc, AD1848_AUX1_CHANNEL, &vol_mid);
	if (sc->mode == 2) {
		 /* CD volume */
		(void) ad1848_set_channel_gain(sc, AD1848_AUX2_CHANNEL, &vol_mid);
		(void) ad1848_set_channel_gain(sc, AD1848_LINE_CHANNEL, &vol_mid);
		(void) ad1848_set_channel_gain(sc, AD1848_MONO_CHANNEL, &vol_0);
		sc->mute[AD1848_MONO_CHANNEL] = MUTE_ALL;
	} else
		(void) ad1848_set_channel_gain(sc, AD1848_AUX2_CHANNEL, &vol_0);

	/* Set default port */
	(void) ad1848_set_rec_port(sc, MIC_IN_PORT);

	if (sc->chip_name)
		printf(": %s", sc->chip_name);
}