Exemplo n.º 1
0
static int __init str8100_inthandler_init(void)
{
	int ret;
if(debug) printk("%s: \n",__FUNCTION__);

#if 0
    /*
     * Configure system Xtal clock to be output to CLKOUT pin
     */
    HAL_PWRMGT_CONFIGURE_CLOCK_OUT_PIN(0, 0);
#endif

//	HAL_MISC_ENABLE_ALL_SHARED_GPIO_PINS();	
	if(gpio){
		if(debug) printk("%s: registering int handler for gpio int\n",__FUNCTION__);\
//gpio initialization depend on application
#if 0
		HAL_MISC_DISABLE_EXT_INT29_PINS();
		HAL_MISC_DISABLE_EXT_INT30_PINS();

		HAL_PWRMGT_ENABLE_GPIO_CLOCK();

		PWRMGT_SOFTWARE_RESET_CONTROL_REG |=  (0x1 << PWRMGT_GPIO_SOFTWARE_RESET_BIT_INDEX);
		PWRMGT_SOFTWARE_RESET_CONTROL_REG &= ~(0x1 << PWRMGT_GPIO_SOFTWARE_RESET_BIT_INDEX);
		PWRMGT_SOFTWARE_RESET_CONTROL_REG |=  (0x1 << PWRMGT_GPIO_SOFTWARE_RESET_BIT_INDEX);	

		HAL_GPIOA_SET_DIRECTION_INPUT(3);
		HAL_GPIOA_ENABLE_INTERRUPT(3);
		HAL_GPIOA_DISABLE_INTERRUPT_MASK(3);
		HAL_GPIOA_SET_INTERRUPT_EDGE_TRIGGER_MODE(3);
#endif

		str8100_set_interrupt_trigger (INTC_GPIO_EXTERNAL_INT_BIT_INDEX,INTC_LEVEL_TRIGGER,INTC_ACTIVE_HIGH);
		if ((ret=request_irq(INTC_GPIO_EXTERNAL_INT_BIT_INDEX, str8100_gpio_irq_handler, 0, "testing", NULL))){
			if(debug) printk("%s: request_irq failed(ret=0x%x)(-EBUSY=0x%x)\n",__FUNCTION__,ret,-EBUSY);
			return -EBUSY;
		}
	}
#define register_ext_int(_i){\
			if(debug) printk("%s: registering int handler for external int%d\n",__FUNCTION__,_i);\
			HAL_MISC_ENABLE_EXT_INT##_i##_PINS();\
			str8100_set_interrupt_trigger (INTC_EXT_INT##_i##_BIT_INDEX,INTC_LEVEL_TRIGGER,INTC_ACTIVE_LOW);\
			if ((ret=request_irq(INTC_EXT_INT##_i##_BIT_INDEX, str8100_ext_irq_handler, 0, "testing", NULL))){\
				if(debug) printk("%s: request_irq %d failed(ret=0x%x)(-EBUSY=0x%x)\n",__FUNCTION__,INTC_EXT_INT##_i##_BIT_INDEX,ret,-EBUSY);\
				return -EBUSY;\
			}\
		}
	if(ext29) register_ext_int(29);
	if(ext30) register_ext_int(30);

/*	HAL_MISC_ENABLE_EXT_INT30_PINS();
	str8100_set_interrupt_trigger (INTC_EXT_INT30_BIT_INDEX,INTC_IRQ_INTERRUPT,INTC_LEVEL_TRIGGER,INTC_ACTIVE_LOW);
	if ((ret=request_irq(INTC_EXT_INT30_BIT_INDEX, str8100_pm_irq_handler, 0, "testing", NULL))){
		printk("%s: request_irq failed(ret=0x%x)(-EBUSY=0x%x)\n",__FUNCTION__,ret,-EBUSY);
		return -EBUSY;
	}
*/
	return 0;
}
static int __init i2s_init_module(void)
{
	
	u32 ret;
	u32 ii;
	
	printk("%s:\n",__FUNCTION__);

	buffer = pci_alloc_consistent(NULL, BUFSIZE*2, &buffer_p);
	if(!buffer){
		printk("%s: alloc buffer failed.\n",__FUNCTION__);
		goto exit1;
	}
	lbuffer=buffer;
	lbuffer_p=buffer_p;
	rbuffer=lbuffer+BUFSIZE;
	rbuffer_p=lbuffer_p+BUFSIZE;
	
	desc = pci_alloc_consistent(NULL, I2S_WM8772_DMAC_LLP_NUM*sizeof(DMAC_LLP_T)*4 , &desc_p);
	if(!desc){
		printk("%s: alloc buffer for desc failed.\n",__FUNCTION__);
		goto exit1;
	}
	lb_txd=desc;
	lb_txd_p=desc_p;
	lb_rxd=desc+I2S_WM8772_DMAC_LLP_NUM;
	lb_rxd_p=desc_p+I2S_WM8772_DMAC_LLP_NUM;

	rb_txd=desc+I2S_WM8772_DMAC_LLP_NUM*2;
	rb_txd_p=desc_p+I2S_WM8772_DMAC_LLP_NUM*2;
	rb_rxd=desc+I2S_WM8772_DMAC_LLP_NUM*3;
	rb_rxd_p=desc_p+I2S_WM8772_DMAC_LLP_NUM*3;
	

	str8100_set_interrupt_trigger (INTC_I2S_BIT_INDEX,INTC_LEVEL_TRIGGER,INTC_ACTIVE_LOW);
	if ((ret=request_irq(INTC_I2S_BIT_INDEX, str8100_i2s_irq_handler, 0, "i2s", NULL))){
		printk("%s: request_irq %d failed(ret=0x%x)(-EBUSY=0x%x)\n",__FUNCTION__,INTC_I2S_BIT_INDEX,ret,-EBUSY);
		goto exit1;
	}

	str8100_set_interrupt_trigger (INTC_GDMAC_TC_BIT_INDEX,INTC_LEVEL_TRIGGER,INTC_ACTIVE_HIGH);
	if ((ret=request_irq(INTC_GDMAC_TC_BIT_INDEX, str8100_dma_tc_irq_handler, 0, "dma tc", NULL))){
		printk("%s: request_irq %d failed(ret=0x%x)(-EBUSY=0x%x)\n",__FUNCTION__,INTC_GDMAC_TC_BIT_INDEX,ret,-EBUSY);
		goto exit1;
	}
	str8100_set_interrupt_trigger (INTC_GDMAC_ERROR_BIT_INDEX,INTC_LEVEL_TRIGGER,INTC_ACTIVE_HIGH);
	if ((ret=request_irq(INTC_GDMAC_ERROR_BIT_INDEX, str8100_dma_err_irq_handler, 0, "dma error", NULL))){
		printk("%s: request_irq %d failed(ret=0x%x)(-EBUSY=0x%x)\n",__FUNCTION__,INTC_GDMAC_ERROR_BIT_INDEX,ret,-EBUSY);
		goto exit1;
	}

	/*
	 * Initialize GPIO pins for COM1/COM2/COM3
	 */
	I2s_Gpio_SSP_Initialise();

	str8100_i2s_init(sampling_rate,DATA_WIDTH, I2S_MODE, I2S_TIMING, I2S_SCLK_MODE);

	/*
	 * Configure Wolfson's WM8772 ADC/DAC
	 */
	I2s_Configure_WM8772(I2S_TIMING, DATA_WIDTH, I2S_MODE); 
#ifdef I2S_FULL_DUPLEX
	/*
	* To support I2S full duplex mode, GPIOA[3] will be used as I2S_DR pin.
	* It means GPIOA[3] should be as input pin.
	*/
	MISC_GPIOA_PIN_ENABLE_REG &= ~(0x1 << 3);
    
	GPIOA_DIRECTION_REG &= ~(0x1 << 3);
#endif

	I2S_RIGHT_TRANSMIT_DATA_REG=0;
	I2S_LEFT_TRANSMIT_DATA_REG=0;
	ii=I2S_RIGHT_RECEIVE_DATA_REG;
	ii=I2S_LEFT_RECEIVE_DATA_REG;

	/*
	 * Initialize DMAC related configuration
	 */    

	i2s_left_channel_llp_buf[0] = lbuffer_p;
	i2s_right_channel_llp_buf[0] = rbuffer_p;
	memset ((void *)&lbuffer[0], 0x0, I2S_WM8772_BUFFER_SIZE * 4);
	memset ((void *)&rbuffer[0], 0x0, I2S_WM8772_BUFFER_SIZE * 4);
	for (ii = 1; ii < I2S_WM8772_DMAC_LLP_NUM; ii++)
	{
		i2s_left_channel_llp_buf[ii] = i2s_left_channel_llp_buf[ii - 1] + (I2S_WM8772_BUFFER_SIZE * 4);
		i2s_right_channel_llp_buf[ii] = i2s_right_channel_llp_buf[ii - 1] + (I2S_WM8772_BUFFER_SIZE * 4);
		memset ((void *)&lbuffer[ii*I2S_WM8772_BUFFER_SIZE*4], 0x0, I2S_WM8772_BUFFER_SIZE * 4);
		memset ((void *)&rbuffer[ii*I2S_WM8772_BUFFER_SIZE*4], 0x0, I2S_WM8772_BUFFER_SIZE * 4);
	}

	i2s_wm8772_dma_left_tx_channel = 0;
    
	i2s_wm8772_dma_right_tx_channel = 1;
    
	i2s_wm8772_dma_left_rx_channel = 2;
    
	i2s_wm8772_dma_right_rx_channel = 3;


	I2s_Configure_WM8772_DMA_Hardware_Handshake();


	/*
	 * Enable I2S's interrupt sources
	 * Note for DMA hardware handshake, we only need to enable Left/Right Channel's 
	 * Transmit Buffer Underrun.
	 */
	I2S_INTERRUPT_ENABLE_REG |= (I2S_RXBF_R_OR_FLAG | I2S_RXBF_L_OR_FLAG | I2S_TXBF_R_UR_FLAG | I2S_TXBF_L_UR_FLAG);

	// Enable CPU interrupt
	local_irq_enable();
	
	/*
	 * Note DMA must be enabled first before I2S is enabled
	 */
	HAL_DMAC_ENABLE();
	HAL_I2S_ENABLE_I2S();
	printk("%s: exit successfully\n",__FUNCTION__);
	return 0;

exit1:
	HAL_I2S_DISABLE_I2S();
	i2s_exit_module();
	printk("%s: exit errornous\n",__FUNCTION__);
	return -EBUSY;
}