add: LOG(("interrupt not working, using a kernel thread for polling\n"));
context: init_driver(void){	status_t rv;	bigtime_t start;		TRACE(("init_driver\n"));	TRACE((VERSION));		ASSERT(sizeof(ich_bd) == 8);		rv = probe_device();	if (rv != B_OK) {		TRACE(("hardware not found\n"));		return B_ERROR;	}	dprintf("ich-ac97: " VERSION "\n");	dprintf("ich-ac97: found %s, IRQ = %ld, NAMBAR = %#lX, NABMBAR = %#lX, MMBAR = %#lX, MBBAR = %#lX\n",config->name,config->irq,config->nambar,config->nabmbar,config->mmbar,config->mbbar);	/* before doing anything else, map the IO memory */	rv = map_io_memory();	if (rv != B_OK) {		dprintf("ich-ac97: mapping of memory IO space failed\n");		return B_ERROR;	}		TRACE(("GLOB_CNT = %#08x\n",ich_reg_read_32(ICH_REG_GLOB_CNT)));	TRACE(("GLOB_STA = %#08x\n",ich_reg_read_32(ICH_REG_GLOB_STA)));	TRACE(("PO ICH_REG_X_LVI = %d\n",ich_reg_read_8(ICH_REG_X_LVI)));	/* do a cold reset */	TRACE(("cold reset\n"));	ich_reg_write_32(ICH_REG_GLOB_CNT, 0);	snooze(50000); // 50 ms	ich_reg_write_32(ICH_REG_GLOB_CNT, CNT_COLD | CNT_PRIE);	TRACE(("cold reset finished\n"));	rv = ich_reg_read_32(ICH_REG_GLOB_CNT);	if ((rv & CNT_COLD) == 0) {		TRACE(("cold reset failed\n"));	}	/* wait until a codec is ready */	start = system_time();	while ((system_time() - start) < 1000000) {		rv = ich_reg_read_32(ICH_REG_GLOB_STA);		if ((rv & STA_PCR) != 0)			break;		snooze(50000);	}	if ((rv & STA_PCR)) {		TRACE(("primary codec ready after %Ld us\n",(system_time() - start)));	} else {		TRACE(("primary codec not ready after %Ld us\n",(system_time() - start)));	}	while ((system_time() - start) < 1000000) {		rv = ich_reg_read_32(ICH_REG_GLOB_STA);		if ((rv & STA_SCR) != 0)			break;		snooze(50000);	}	if ((rv & STA_SCR)) {		TRACE(("secondary codec ready after %Ld us\n",(system_time() - start)));	} else {		TRACE(("secondary codec not ready after %Ld us\n",(system_time() - start)));	}	if ((rv & (STA_PCR | STA_SCR)) == 0) {		dprintf("ich-ac97: compatible chipset found, but no codec ready!\n");		unmap_io_memory();		return B_ERROR;	}	if ((rv & STA_PCR) == 0 && (rv & STA_SCR) != 0) {		TRACE(("using secondary codec!\n"));		config->nambar += 0x80;	}	/* allocate memory for channel info struct */	chan_pi = (ich_chan *) malloc(sizeof(ich_chan));	chan_po = (ich_chan *) malloc(sizeof(ich_chan));	chan_mc = (ich_chan *) malloc(sizeof(ich_chan));	if (0 == chan_pi || 0 == chan_po || 0 == chan_mc) {		dprintf("ich-ac97: couldn't allocate memory for channel descriptors!\n");		chan_free_resources();		unmap_io_memory();		return B_ERROR;		}	/* allocate memory for buffer descriptors */	chan_po->bd_area = alloc_mem(&chan_po->bd_phy_base, &chan_po->bd_log_base, ICH_BD_COUNT * sizeof(ich_bd), "ich_ac97 po buf desc");	chan_pi->bd_area = alloc_mem(&chan_pi->bd_phy_base, &chan_pi->bd_log_base, ICH_BD_COUNT * sizeof(ich_bd), "ich_ac97 pi buf desc");	chan_mc->bd_area = alloc_mem(&chan_mc->bd_phy_base, &chan_mc->bd_log_base, ICH_BD_COUNT * sizeof(ich_bd), "ich_ac97 mc buf desc");	/* allocate memory buffers */	chan_po->buffer_area = alloc_mem(&chan_po->buffer_phy_base, &chan_po->buffer_log_base, BUFFER_COUNT * BUFFER_SIZE, "ich_ac97 po buf");	chan_pi->buffer_area = alloc_mem(&chan_pi->buffer_phy_base, &chan_pi->buffer_log_base, BUFFER_COUNT * BUFFER_SIZE, "ich_ac97 pi buf");	chan_mc->buffer_area = alloc_mem(&chan_mc->buffer_phy_base, &chan_mc->buffer_log_base, BUFFER_COUNT * BUFFER_SIZE, "ich_ac97 mc buf");	/* allocate memory exported userland buffers */	chan_po->userbuffer_area = alloc_mem(NULL, &chan_po->userbuffer_base, BUFFER_COUNT * BUFFER_SIZE, "ich_ac97 po user buf");	chan_pi->userbuffer_area = alloc_mem(NULL, &chan_pi->userbuffer_base, BUFFER_COUNT * BUFFER_SIZE, "ich_ac97 pi user buf");	chan_mc->userbuffer_area = alloc_mem(NULL, &chan_mc->userbuffer_base, BUFFER_COUNT * BUFFER_SIZE, "ich_ac97 mc user buf");	if (  chan_po->bd_area < B_OK || chan_po->buffer_area < B_OK || chan_po->userbuffer_area < B_OK ||		  chan_pi->bd_area < B_OK || chan_pi->buffer_area < B_OK || chan_pi->userbuffer_area < B_OK ||		  chan_mc->bd_area < B_OK || chan_mc->buffer_area < B_OK || chan_mc->userbuffer_area < B_OK) {		dprintf("ich-ac97: couldn't allocate memory for DMA buffers!\n");		chan_free_resources();		unmap_io_memory();		return B_ERROR;		}	/* allocate all semaphores */	chan_po->buffer_ready_sem = create_sem(0,"po buffer ready");			/* pcm out buffer available */	chan_pi->buffer_ready_sem = create_sem(0,"pi buffer ready");			/* 0 available pcm in buffers */	chan_mc->buffer_ready_sem = create_sem(0,"mc buffer ready");			/* 0 available mic in buffers */		if (chan_po->buffer_ready_sem < B_OK || chan_pi->buffer_ready_sem < B_OK || chan_mc->buffer_ready_sem < B_OK) {		dprintf("ich-ac97: couldn't semaphores!\n");		chan_free_resources();		unmap_io_memory();		return B_ERROR;		}	/* setup channel register base address */	chan_pi->regbase = ICH_REG_PI_BASE;	chan_po->regbase = ICH_REG_PO_BASE;	chan_mc->regbase = ICH_REG_MC_BASE;	/* reset the (primary?) codec */		TRACE(("codec reset\n"));	ich_codec_write(0x00, 0x0000);	snooze(50000); // 50 ms	TRACE(("reading codec\n"));	TRACE(("codec = %#04x\n",ich_codec_read(0x00)));	/* reset all channels */	reset_chan(chan_pi);	reset_chan(chan_po);	reset_chan(chan_mc);	/* init channels */	init_chan(chan_pi);	init_chan(chan_po);	init_chan(chan_mc);		/* first test if interrupts are working, on some Laptops they don't work :-( */	if (config->irq != 0 && false == interrupt_test()) {		TRACE(("interrupt not working, using a kernel thread for polling\n"));		config->irq = 0; /* don't use interrupts */	}	/* install interrupt or polling thread */	if (config->irq != 0) {		install_io_interrupt_handler(config->irq,ich_int,0,0);	} else {		int_thread_id = spawn_kernel_thread(int_thread, "ich_ac97 interrupt poller", B_REAL_TIME_PRIORITY, 0);		resume_thread(int_thread_id);	}	/* enable master output */	ich_codec_write(0x02, 0x0000);	/* enable pcm output */	ich_codec_write(0x18, 0x0404);#if 0	/* enable pcm input */	ich_codec_write(0x10, 0x0000);	/* enable mic input */	/* ich_codec_write(0x0E, 0x0000); */	/* select pcm input record */	ich_codec_write(0x1A, 4 | (4 << 8));	/* enable PCM record */	ich_codec_write(0x1C, 0x0000);	/* enable mic record */	/* ich_codec_write(0x1E, 0x0000); */#endif	TRACE(("init_driver finished!\n"));	return B_OK;}