Exemplo n.º 1
0
/*
 * Attach hardware to driver, attach hardware driver to audio
 * pseudo-device driver .
 */
void
ad1848_attach(struct ad1848_softc *sc)
{
	static struct ad1848_volume vol_mid = {220, 220};
	static struct ad1848_volume vol_0   = {0, 0};
	int i;
	int timeout;

	/* Initialize the ad1848... */
	for (i = 0; i < 0x10; i++) {
		ad_write(sc, i, ad1848_init_values[i]);
		timeout = 100000;
		while (timeout > 0 && ADREAD(sc, AD1848_IADDR) & SP_IN_INIT)
			timeout--;
	}
	/* ...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 = 100000;
				while (timeout > 0 &&
				       ADREAD(sc, AD1848_IADDR) & SP_IN_INIT)
					timeout--;
			}
	}
	ad1848_reset(sc);

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

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

	printf(": %s", sc->chip_name);
}
Exemplo n.º 2
0
int
ad_read(struct ad1848_softc *sc, int reg)
{
	int x;

	ADWRITE(sc, AD1848_IADDR, (reg & 0xff) | sc->MCE_bit);
	x = ADREAD(sc, AD1848_IDATA);
	/*  printf("(%02x<-%02x) ", reg|sc->MCE_bit, x); */
	return x;
}
Exemplo n.º 3
0
void sample_replay(int mode)
     /* 録音または再生を行う関数 */
     /*   mode: PLAY, SAMPLE     */
{
   bufptr = 0;                             /* バッファポインタを初期化  */
	 if (mode == PLAY){                      /* 再生モードの処理 */
    /* ここにスピーカをスピーカとして使用する命令 */
    speaker_switch(SPEAKER);
    lcd_init();
		lcd_cursor(0,0);
		lcd_printstr(" Push * or # key");
		lcd_cursor(0,1);
		lcd_printstr(" Now Playing... ");
		
    /* 音声出力処理内容を記述する */
    while(bufptr <= TIME){            /*   データ出力を繰り返す    */
			da_out( 0, databuf[bufptr]);    /* ◎D/Aにデータを出力    */
			bufptr++;                       /* ◎バッファポインタを +1   */
    }   
  }
  if (mode == INVERSE){                    /* 再生モードの処理 */
    /* ここにスピーカをスピーカとして使用する命令 */
    speaker_switch(SPEAKER);
    lcd_init();
		lcd_cursor(0,0);
		lcd_printstr(" Push * or 5 key");
		lcd_cursor(0,1);
		lcd_printstr(" Now Inverse... ");
		
    /* 音声出力処理内容を記述する */
    while(bufptr <= TIME){             /*   データ出力を繰り返す    */
			da_out( 0, databuf[TIME-bufptr]);/* ◎D/Aにデータを出力    */
			bufptr++;                        /* ◎バッファポインタを +1   */
    }   
  }
  if (mode == SAMPLE){                              /* 録音モードの処理 */
    /* ここにスピーカをマイクとして使用する命令 */
    speaker_switch(MIC);
		lcd_init();
		lcd_cursor(0,0);
		lcd_printstr(" Push * or 5 key");
		lcd_cursor(0,1);
		lcd_printstr(" Now Sampling...");
		
    /* 音声取込処理内容を記述する */
    while(bufptr <= TIME){          /*   データ読込を繰り返す     */
			ad_start( 0, 0);              /* ◎A/D変換スタート       */
			while(ADSTATUS() == 0);			  /* ◎A/D変換終了待ち 約5us */
			databuf[bufptr] = ADREAD();	  /* ◎変換データを格納     */
			bufptr++;										  /* ◎バッファポインタを +1    */
    }
  }
  speaker_switch(MIC);      /* スピーカーオフ   */
}
Exemplo n.º 4
0
int
ad_xread(struct ad1848_softc *sc, int reg)
{
	int x;

	ADWRITE(sc, AD1848_IADDR, CS_XREG | sc->MCE_bit);
	ADWRITE(sc, AD1848_IDATA, (reg | ALT_F3_XRAE) & 0xff);
	x = ADREAD(sc, AD1848_IDATA);

	return x;
}
Exemplo n.º 5
0
static void
wait_for_calibration(struct ad1848_softc *sc)
{
	int timeout;

	DPRINTF(("ad1848: Auto calibration started.\n"));
	/*
	 * Wait until the auto calibration process has finished.
	 *
	 * 1) Wait until the chip becomes ready (reads don't return SP_IN_INIT).
	 * 2) Wait until the ACI bit of I11 goes hi and then lo.
	 *   a) With AD1848 alike, ACI goes hi within 5 sample cycles
	 *	  and remains hi for ~384 sample periods.
	 *   b) With CS4231 alike, ACI goes hi immediately and remains
	 *	  hi for at least 168 sample periods.
	 */
	timeout = AD1848_TIMO;
	while (timeout > 0 && ADREAD(sc, AD1848_IADDR) == SP_IN_INIT)
		timeout--;

	if (ADREAD(sc, AD1848_IADDR) == SP_IN_INIT)
		DPRINTF(("ad1848: Auto calibration timed out(1).\n"));

	if (!(sc->sc_flags & AD1848_FLAG_32REGS)) {
		timeout = AD1848_TIMO;
		while (timeout > 0 &&
	 	    !(ad_read(sc, SP_TEST_AND_INIT) & AUTO_CAL_IN_PROG))
			timeout--;

		if (!(ad_read(sc, SP_TEST_AND_INIT) & AUTO_CAL_IN_PROG)) {
			DPRINTF(("ad1848: Auto calibration timed out(2).\n"));
		}
	}

	timeout = AD1848_TIMO;
	while (timeout > 0 && ad_read(sc, SP_TEST_AND_INIT) & AUTO_CAL_IN_PROG)
		timeout--;
	if (ad_read(sc, SP_TEST_AND_INIT) & AUTO_CAL_IN_PROG)
		DPRINTF(("ad1848: Auto calibration timed out(3).\n"));
}
Exemplo n.º 6
0
void
ad1848_dump_regs(struct ad1848_softc *sc)
{
	int i;
	u_char r;
	
	printf("ad1848 status=%02x", ADREAD(sc, AD1848_STATUS));
	printf(" regs: ");
	for (i = 0; i < 16; i++) {
		r = ad_read(sc, i);
		printf("%02x ", r);
	}
	if (sc->mode == 2) {
		for (i = 16; i < 32; i++) {
			r = ad_read(sc, i);
			printf("%02x ", r);
		}
	}
	printf("\n");
}
Exemplo n.º 7
0
/*
 * Probe for the ad1848 chip
 */
int
ad1848_isa_probe(struct ad1848_isa_softc *isc)
{
	struct ad1848_softc *sc;
	u_char tmp, tmp1 = 0xff, tmp2 = 0xff;
	int i, t;

	sc = &isc->sc_ad1848;
	sc->sc_readreg = ad1848_isa_read;
	sc->sc_writereg = ad1848_isa_write;

	/* Is there an ad1848 chip ? */
	sc->MCE_bit = MODE_CHANGE_ENABLE;
	sc->mode = 1;	/* MODE 1 = original ad1848/ad1846/cs4248 */

	/*
	 * Check that the I/O address is in use.
	 *
	 * The SP_IN_INIT bit of the base I/O port is known to be 0 after the
	 * chip has performed its power-on initialization. Just assume
	 * this has happened before the OS is starting.
	 *
	 * If the I/O address is unused, inb() typically returns 0xff.
	 */
	tmp = ADREAD(sc, AD1848_IADDR);
	if (tmp & SP_IN_INIT) { /* Not a AD1848 */
		DPRINTF(("ad_detect_A %x\n", tmp));
		goto bad;
	}

	/*
	 * Test if it's possible to change contents of the indirect registers.
	 * Registers 0 and 1 are ADC volume registers.  The bit 0x10 is read
	 * only so try to avoid using it.  The bit 0x20 is the mic preamp
	 * enable; on some chips it is always the same in both registers, so
	 * we avoid tests where they are different.
	 */
	ad_write(sc, 0, 0x8a);
	ad_write(sc, 1, 0x45);	/* 0x55 with bit 0x10 clear */
	tmp1 = ad_read(sc, 0);
	tmp2 = ad_read(sc, 1);

	if (tmp1 != 0x8a || tmp2 != 0x45) {
		DPRINTF(("ad_detect_B (%x/%x)\n", tmp1, tmp2));
		goto bad;
	}

	ad_write(sc, 0, 0x65);
	ad_write(sc, 1, 0xaa);
	tmp1 = ad_read(sc, 0);
	tmp2 = ad_read(sc, 1);

	if (tmp1 != 0x65 || tmp2 != 0xaa) {
		DPRINTF(("ad_detect_C (%x/%x)\n", tmp1, tmp2));
		goto bad;
	}

	/*
	 * The indirect register I12 has some read only bits. Lets
	 * try to change them.
	 */
	tmp = ad_read(sc, SP_MISC_INFO);
	ad_write(sc, SP_MISC_INFO, (~tmp) & 0x0f);

	/* Here, AD1845 may sometimes be busy.  Wait til it becomes ready. */
	for (t = 0; t < 100000 && ADREAD(sc, AD1848_IADDR) & SP_IN_INIT; t++)
		;
#ifdef AUDIO_DEBUG
	if (t)
		DPRINTF(("ad1848_isa_probe: t %d\n", t));
#endif

	if ((tmp & 0x0f) != ((tmp1 = ad_read(sc, SP_MISC_INFO)) & 0x0f)) {
		DPRINTF(("ad_detect_D (%x)\n", tmp1));
		goto bad;
	}

	/*
	 * MSB and 4 LSBs of the reg I12 tell the chip revision.
	 *
	 * A preliminary version of the AD1846 data sheet stated that it
	 * used an ID field of 0x0B.  The current version, however,
	 * states that the AD1846 uses ID 0x0A, just like the AD1848K.
	 *
	 * this switch statement will need updating as newer clones arrive....
	 */
	switch (tmp1 & 0x8f) {
	case 0x09:
		sc->chip_name = "AD1848J";
		break;
	case 0x0A:
		sc->chip_name = "AD1848K";
		break;
#if 0	/* See above */
	case 0x0B:
		sc->chip_name = "AD1846";
		break;
#endif
	case 0x81:
		sc->chip_name = "CS4248revB"; /* or CS4231 rev B; see below */
		break;
	case 0x89:
		sc->chip_name = "CS4248";
		break;
	case 0x8A:
		sc->chip_name = "broken"; /* CS4231/AD1845; see below */
		break;
	default:
		sc->chip_name = "unknown";
		DPRINTF(("ad1848: unknown codec version 0x%02x\n",
			 tmp1 & 0x8f));
		break;
	}

	/*
	 * The original AD1848/CS4248 has just 16 indirect registers. This
	 * means that I0 and I16 should return the same value (etc.).
	 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test
	 * fails with CS4231, AD1845, etc.
	 */
	ad_write(sc, SP_MISC_INFO, 0);	/* Mode2 = disabled */

	for (i = 0; i < 16; i++)
		if ((tmp1 = ad_read(sc, i)) != (tmp2 = ad_read(sc, i + 16))) {
			if (i != SP_TEST_AND_INIT) {
				DPRINTF(("ad_detect_F(%d/%x/%x)\n", i, tmp1, tmp2));
				goto bad;
			}
		}

	/*
	 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit
	 * The bit 0x80 is always 1 in CS4248, CS4231, and AD1845.
	 */
	ad_write(sc, SP_MISC_INFO, MODE2);	/* Set mode2, clear 0x80 */

	tmp1 = ad_read(sc, SP_MISC_INFO);
	if ((tmp1 & 0xc0) == (0x80 | MODE2)) {
		/*
		 *      CS4231 or AD1845 detected - is it?
		 *
		 *	Verify that setting I2 doesn't change I18.
		 */
		ad_write(sc, 18, 0x88); /* Set I18 to known value */

		ad_write(sc, 2, 0x45);
		if ((tmp2 = ad_read(sc, 18)) != 0x45) { /* No change -> CS4231? */
			ad_write(sc, 2, 0xaa);
			if ((tmp2 = ad_read(sc, 18)) == 0xaa) {     /* Rotten bits? */
				DPRINTF(("ad_detect_H(%x)\n", tmp2));
				goto bad;
			}

			sc->mode = 2;

			/*
			 *  It's a CS4231, or another clone with 32 registers.
			 *  Let's find out which by checking I25.
			 */
			if ((tmp1 & 0x8f) == 0x8a) {
				tmp1 = ad_read(sc, CS_VERSION_ID);
				switch (tmp1 & 0xe7) {
				case 0xA0:
					sc->chip_name = "CS4231A";
					break;
				case 0x80:
					/*  XXX I25 no good, AD1845 same as CS4231 */
					/*
					 * XXX
					 * This test is correct only after reset
					 */
					if (ad_read(sc, 17) & 0xf0) {
						sc->chip_name = "AD1845";
						sc->is_ad1845 = 1;
					} else
						sc->chip_name = "CS4231";
					break;
				case 0x82:
					sc->chip_name = "CS4232";
					break;
				case 0xa2:
					sc->chip_name = "CS4232C";
					break;
				case 0x03:
				case 0x83:
					sc->chip_name = "CS4236";

					/*
					 * Try to switch to mode3 (CS4236B or
					 * CS4237B) by setting CMS to 3.  A
					 * plain CS4236 will not react to
					 * LLBM settings.
					 */
					ad_write(sc, SP_MISC_INFO, MODE3);

					tmp1 = ad_read(sc, CS_LEFT_LINE_CONTROL);
					ad_write(sc, CS_LEFT_LINE_CONTROL, 0xe0);
					tmp2 = ad_read(sc, CS_LEFT_LINE_CONTROL);
					if (tmp2 == 0xe0) {
						/*
						 * it's a CS4237B or another
						 * clone supporting mode 3.
						 * Let's determine which by
						 * enabling extended registers
						 * and checking X25.
						 */
						tmp2 = ad_xread(sc, CS_X_CHIP_VERSION);
						switch (tmp2 & X_CHIP_VERSIONF_CID) {
						case X_CHIP_CID_CS4236BB:
							sc->chip_name = "CS4236BrevB";
							break;
						case X_CHIP_CID_CS4236B:
							sc->chip_name = "CS4236B";
							break;
						case X_CHIP_CID_CS4237B:
							sc->chip_name = "CS4237B";
							break;
						default:
							sc->chip_name = "CS4236B compatible";
							DPRINTF(("cs4236: unknown mode 3 compatible codec, version 0x%02x\n", tmp2));
							break;
						}
						sc->mode = 3;
					}

					/* restore volume control information */
					ad_write(sc, CS_LEFT_LINE_CONTROL, tmp1);
					break;
				}
			}
		}
	}

	/* Wait for 1848 to init */
	while (ADREAD(sc, AD1848_IADDR) & SP_IN_INIT)
		;

	/* Wait for 1848 to autocal */
	ADWRITE(sc, AD1848_IADDR, SP_TEST_AND_INIT);
	while (ADREAD(sc, AD1848_IDATA) & AUTO_CAL_IN_PROG)
		;

	return 1;
bad:
	return 0;
}
Exemplo n.º 8
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);
}
Exemplo n.º 9
0
/*
 * Probe for the ad1848 chip
 */
int
ad1848_probe(struct ad1848_softc *sc)
{
	u_char tmp, tmp1 = 0xff, tmp2 = 0xff;
#if 0
	int i;
#endif

	/* Is there an ad1848 chip ? */
	sc->MCE_bit = MODE_CHANGE_ENABLE;
	sc->mode = 1;	/* MODE 1 = original ad1848/ad1846/cs4248 */
	sc->sc_flags = 0;

	/*
	 * Check that the I/O address is in use.
	 *
	 * The SP_IN_INIT bit of the base I/O port is known to be 0 after the
	 * chip has performed its power-on initialization. Just assume
	 * this has happened before the OS is starting.
	 *
	 * If the I/O address is unused, inb() typically returns 0xff.
	 */
	tmp = ADREAD(sc, AD1848_IADDR);
	if (tmp & SP_IN_INIT) { /* Not a AD1848 */
#if 0
		DPRINTF(("ad_detect_A %x\n", tmp));
#endif
		goto bad;
	}

	/*
	 * Test if it's possible to change contents of the indirect registers.
	 * Registers 0 and 1 are ADC volume registers. The bit 0x10 is read
	 * only so try to avoid using it.
	 */
	ad_write(sc, 0, 0xaa);
	ad_write(sc, 1, 0x45);	/* 0x55 with bit 0x10 clear */

	if ((tmp1 = ad_read(sc, 0)) != 0xaa ||
	    (tmp2 = ad_read(sc, 1)) != 0x45) {
		DPRINTF(("ad_detect_B (%x/%x)\n", tmp1, tmp2));
		goto bad;
	}

	ad_write(sc, 0, 0x45);
	ad_write(sc, 1, 0xaa);

	if ((tmp1 = ad_read(sc, 0)) != 0x45 ||
	    (tmp2 = ad_read(sc, 1)) != 0xaa) {
		DPRINTF(("ad_detect_C (%x/%x)\n", tmp1, tmp2));
		goto bad;
	}

	/*
	 * The indirect register I12 has some read only bits. Lets
	 * try to change them.
	 */
	tmp = ad_read(sc, SP_MISC_INFO);
	ad_write(sc, SP_MISC_INFO, (~tmp) & 0x0f);

	if ((tmp & 0x0f) != ((tmp1 = ad_read(sc, SP_MISC_INFO)) & 0x0f)) {
		DPRINTF(("ad_detect_D (%x)\n", tmp1));
		goto bad;
	}

	/*
	 * MSB and 4 LSBs of the reg I12 tell the chip revision.
	 *
	 * A preliminary version of the AD1846 data sheet stated that it
	 * used an ID field of 0x0B.  The current version, however,
	 * states that the AD1846 uses ID 0x0A, just like the AD1848K.
	 *
	 * this switch statement will need updating as newer clones arrive....
	 */
	switch (tmp1 & 0x8f) {
	case 0x09:
		sc->chip_name = "AD1848J";
		break;
	case 0x0A:
		sc->chip_name = "AD1848K";
		break;
#if 0	/* See above */
	case 0x0B:
		sc->chip_name = "AD1846";
		break;
#endif
	case 0x81:
		sc->chip_name = "CS4248revB"; /* or CS4231 rev B; see below */
		break;
	case 0x89:
		sc->chip_name = "CS4248";
		break;
	case 0x8A:
		sc->chip_name = "broken"; /* CS4231/AD1845; see below */
		break;
	default:
		sc->chip_name = "unknown";
		DPRINTF(("ad1848: unknown codec version %#02X\n", (tmp1 & 0x8f)));
	}	

#if 0
	/*
	 * XXX I don't know why, but this probe fails on an otherwise
	 * well-working AW35/pro card, so I'll just take it out for now.
	 * [[email protected]]
	 */

	/*
	 * The original AD1848/CS4248 has just 16 indirect registers. This
	 * means that I0 and I16 should return the same value (etc.).
	 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test
	 * fails with CS4231, AD1845, etc.
	 */
	ad_write(sc, SP_MISC_INFO, 0);	/* Mode2 = disabled */

	for (i = 0; i < 16; i++) {
		if ((tmp1 = ad_read(sc, i)) != (tmp2 = ad_read(sc, i + 16))) {
			if (i != SP_TEST_AND_INIT) {
				DPRINTF(("ad_detect_F(%d/%x/%x)\n", i, tmp1, tmp2));
				goto bad;
			}
		}
	}
#endif

	/*
	 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit
	 * The bit 0x80 is always 1 in CS4248, CS4231, and AD1845.
	 */
	ad_write(sc, SP_MISC_INFO, MODE2);	/* Set mode2, clear 0x80 */

	tmp1 = ad_read(sc, SP_MISC_INFO);
	if ((tmp1 & 0xc0) == (0x80 | MODE2)) {
		/*
		 *	CS4231 or AD1845 detected - is it?
		 *
		 *	Verify that setting I2 doesn't change I18.
		 */
		ad_write(sc, 18, 0x88); /* Set I18 to known value */

		ad_write(sc, 2, 0x45);
		if ((tmp2 = ad_read(sc, 18)) != 0x45) {
			/* No change -> CS4231? */
			ad_write(sc, 2, 0xaa);
			if ((tmp2 = ad_read(sc, 18)) == 0xaa) {
				/* Rotten bits? */
				DPRINTF(("ad_detect_H(%x)\n", tmp2));
				goto bad;
			}

			/*
			 *  It's a CS4231, or another clone with 32 registers.
			 *  Let's find out which by checking I25.
			 */
			if ((tmp1 & 0x8f) == 0x8a) {
				tmp1 = ad_read(sc, CS_VERSION_ID);
				switch (tmp1 & 0xe7) {
				case 0xA0:
					sc->chip_name = "CS4231A";
					break;
				case 0x80:
					/* I25 no good, AD1845 same as CS4231 */
					sc->chip_name = "CS4231 or AD1845";
					break;
				case 0x82:
					sc->chip_name = "CS4232";
					break;
				case 0xa2:
					sc->chip_name = "CS4232C";
					break;
				case 0x03:
					sc->chip_name = "CS4236/CS4236B";
					break;
				}
			}
			sc->mode = 2;
			sc->sc_flags |= AD1848_FLAG_32REGS;
		}
	}

	/* Wait for 1848 to init */
	while(ADREAD(sc, AD1848_IADDR) & SP_IN_INIT)
		;

	/* Wait for 1848 to autocal */
	ADWRITE(sc, AD1848_IADDR, SP_TEST_AND_INIT);
	while(ADREAD(sc, AD1848_IDATA) & AUTO_CAL_IN_PROG)
		;

	return 1;
bad:
	return 0;
}
Exemplo n.º 10
0
/*
 * Lower-level routines
 */
int
ad1848_commit_settings(void *addr)
{
	struct ad1848_softc *sc = addr;
	int timeout;
	u_char fs;
	int s;

	if (!sc->need_commit)
		return 0;

	s = splaudio();

	ad1848_mute_monitor(sc, 1);

	/* Enables changes to the format select reg */
	ad_set_MCE(sc, 1);

	fs = sc->speed_bits | sc->format_bits;

	if (sc->channels == 2)
		fs |= FMT_STEREO;

	ad_write(sc, SP_CLOCK_DATA_FORMAT, fs);

	/*
	 * If mode == 2 (CS4231), set I28 also. It's the capture format
	 * register.
	 */
	if (sc->mode == 2) {
		/* Gravis Ultrasound MAX SDK sources says something about
		 * errata sheets, with the implication that these inb()s
		 * are necessary.
		 */
		(void)ADREAD(sc, AD1848_IDATA);
		(void)ADREAD(sc, AD1848_IDATA);

		/*
		 * Write to I8 starts resynchronization. Wait until it
		 * completes.
		 */
		timeout = AD1848_TIMO;
		while (timeout > 0 && ADREAD(sc, AD1848_IADDR) == SP_IN_INIT)
			timeout--;

		ad_write(sc, CS_REC_FORMAT, fs);
		/* Gravis Ultrasound MAX SDK sources says something about
		 * errata sheets, with the implication that these inb()s
		 * are necessary.
		 */
		(void)ADREAD(sc, AD1848_IDATA);
		(void)ADREAD(sc, AD1848_IDATA);
		/* Now wait for resync for capture side of the house */
	}
	/*
	 * Write to I8 starts resynchronization. Wait until it completes.
	 */
	timeout = AD1848_TIMO;
	while (timeout > 0 && ADREAD(sc, AD1848_IADDR) == SP_IN_INIT)
		timeout--;

	if (ADREAD(sc, AD1848_IADDR) == SP_IN_INIT)
		printf("ad1848_commit: Auto calibration timed out\n");

	/*
	 * Starts the calibration process and enters playback mode after it.
	 */
	ad_set_MCE(sc, 0);
	wait_for_calibration(sc);

	ad1848_mute_monitor(sc, 0);

	splx(s);
	
	sc->need_commit = 0;

	return 0;
}
Exemplo n.º 11
0
static void
wait_for_calibration(struct ad1848_softc *sc)
{
	int timeout;

	DPRINTF(("ad1848: Auto calibration started.\n"));
	/*
	 * Wait until the auto calibration process has finished.
	 *
	 * 1) Wait until the chip becomes ready (reads don't return 0x80).
	 * 2) Wait until the ACI bit of I11 gets on and then off.
	 *    Because newer chips are fast we may never see the ACI
	 *    bit go on.  Just delay a little instead.
	 */
	timeout = 10000;
	while (timeout > 0 && ADREAD(sc, AD1848_IADDR) == SP_IN_INIT) {
		delay(10);
		timeout--;
	}
	if (timeout <= 0) {
		DPRINTF(("ad1848: Auto calibration timed out(1).\n"));
	}

	/* Set register addr */
	ADWRITE(sc, AD1848_IADDR, SP_TEST_AND_INIT);
	/* Wait for address to appear when read back. */
	timeout = 100000;
	while (timeout > 0 &&
	       (ADREAD(sc, AD1848_IADDR)&SP_IADDR_MASK) != SP_TEST_AND_INIT) {
		delay(10);
		timeout--;
	}
	if (timeout <= 0) {
		DPRINTF(("ad1848: Auto calibration timed out(1.5).\n"));
	}

	if (!(ad_read(sc, SP_TEST_AND_INIT) & AUTO_CAL_IN_PROG)) {
		if (sc->mode > 1) {
			/* A new chip, just delay a little. */
			delay(100);	/* XXX what should it be? */
		} else {
			timeout = 10000;
			while (timeout > 0 &&
			       !(ad_read(sc, SP_TEST_AND_INIT) &
				 AUTO_CAL_IN_PROG)) {
				delay(10);
				timeout--;
			}
			if (timeout <= 0) {
				DPRINTF(("ad1848: Auto calibration timed out(2).\n"));
			}
		}
	}

	timeout = 10000;
	while (timeout > 0 &&
	       ad_read(sc, SP_TEST_AND_INIT) & AUTO_CAL_IN_PROG) {
		delay(10);
		timeout--;
	}
	if (timeout <= 0) {
		DPRINTF(("ad1848: Auto calibration timed out(3).\n"));
	}
}