software/drivers/sd8887/src/bluetooth/bt/bt_main.c
/**
 *  @brief This function adds the card. it will probe the
 *  card, allocate the bt_priv and initialize the device.
 *
 *  @param card    A pointer to card
 *  @return        A pointer to bt_private structure
 */
@brief This function adds the card. it will probe the
card, allocate the bt_priv and initialize the device.

@param card    A pointer to card
@return        A pointer to bt_private structure
@brief This function adds the card . it will probe the card allocate the bt_priv and initialize the device . @param card A pointer to card @return A pointer to bt_private structure
bt_private *
bt_add_card(void *card)
{
	bt_private *priv = NULL;
	int index = 0;
	ENTER();
	priv = bt_alloc_priv();
	if (!priv) {
		PRINTM(FATAL, "Can not allocate priv\n");
		LEAVE();
		return NULL;
	}
	for (index = 0; index < MAX_BT_ADAPTER; index++) {
		if (m_priv[index] == NULL)
			break;
	}
	if (index < MAX_BT_ADAPTER) {
		m_priv[index] = priv;
	} else {
		PRINTM(ERROR, "Exceeded maximum cards supported!\n");
		goto err_kmalloc;
	}
	priv->adapter = kzalloc(sizeof(bt_adapter), GFP_KERNEL);
	if (!priv->adapter) {
		PRINTM(FATAL, "Allocate buffer for bt_adapter failed!\n");
		goto err_kmalloc;
	}
	priv->adapter->tx_buffer =
		kzalloc(MAX_TX_BUF_SIZE + DMA_ALIGNMENT, GFP_KERNEL);
	if (!priv->adapter->tx_buffer) {
		PRINTM(FATAL, "Allocate buffer for transmit\n");
		goto err_kmalloc;
	}
	priv->adapter->tx_buf =
		(u8 *)ALIGN_ADDR(priv->adapter->tx_buffer, DMA_ALIGNMENT);
	priv->adapter->hw_regs_buf =
		kzalloc(SD_BLOCK_SIZE + DMA_ALIGNMENT, GFP_KERNEL);
	if (!priv->adapter->hw_regs_buf) {
		PRINTM(FATAL, "Allocate buffer for INT read buf failed!\n");
		goto err_kmalloc;
	}
	priv->adapter->hw_regs =
		(u8 *)ALIGN_ADDR(priv->adapter->hw_regs_buf, DMA_ALIGNMENT);
	bt_init_adapter(priv);
	PRINTM(INFO, "Starting kthread...\n");
	priv->MainThread.priv = priv;
	spin_lock_init(&priv->driver_lock);
	bt_create_thread(bt_service_main_thread, &priv->MainThread,
			 "bt_main_service");
	while (!priv->MainThread.pid)
		os_sched_timeout(1);
	init_waitqueue_head(&priv->init_user_conf_wait_q);
	priv->bt_dev.card = card;
	((struct sdio_mmc_card *)card)->priv = priv;
	priv->adapter->sd_ireg = 0;
	if (sbi_register_dev(priv) < 0) {
		PRINTM(FATAL, "Failed to register bt device!\n");
		goto err_registerdev;
	}
	if (bt_init_fw(priv)) {
		PRINTM(FATAL, "BT Firmware Init Failed\n");
		goto err_init_fw;
	}
	LEAVE();
	return priv;
err_init_fw:
	clean_up_m_devs(priv);
	bt_proc_remove(priv);
	PRINTM(INFO, "Unregister device\n");
	sbi_unregister_dev(priv);
err_registerdev:
	((struct sdio_mmc_card *)card)->priv = NULL;
	priv->adapter->SurpriseRemoved = TRUE;
	wake_up_interruptible(&priv->MainThread.waitQ);
	while (priv->MainThread.pid)
		os_sched_timeout(1);
err_kmalloc:
	if (priv->adapter)
		bt_free_adapter(priv);
	for (index = 0; index < MAX_BT_ADAPTER; index++) {
		if (m_priv[index] == priv) {
			m_priv[index] = NULL;
			break;
		}
	}
	bt_priv_put(priv);
	LEAVE();
	return NULL;
}
bt_private * bt_add_card ( void * card ) { bt_private * priv = NULL ; int index = 0 ; ENTER ( ) ; priv = bt_alloc_priv ( ) ; if ( ! priv ) { PRINTM ( FATAL , " \n " ) ; LEAVE ( ) ; return NULL ; } for ( index = 0 ; index < MAX_BT_ADAPTER ; index ++ ) { if ( m_priv [ index ] == NULL ) break ; } if ( index < MAX_BT_ADAPTER ) { m_priv [ index ] = priv ; } else { PRINTM ( ERROR , " \n " ) ; goto err_kmalloc ; } priv -> adapter = kzalloc ( sizeof ( bt_adapter ) , GFP_KERNEL ) ; if ( ! priv -> adapter ) { PRINTM ( FATAL , " \n " ) ; goto err_kmalloc ; } priv -> adapter -> tx_buffer = kzalloc ( MAX_TX_BUF_SIZE + DMA_ALIGNMENT , GFP_KERNEL ) ; if ( ! priv -> adapter -> tx_buffer ) { PRINTM ( FATAL , " \n " ) ; goto err_kmalloc ; } priv -> adapter -> tx_buf = ( u8 * ) ALIGN_ADDR ( priv -> adapter -> tx_buffer , DMA_ALIGNMENT ) ; priv -> adapter -> hw_regs_buf = kzalloc ( SD_BLOCK_SIZE + DMA_ALIGNMENT , GFP_KERNEL ) ; if ( ! priv -> adapter -> hw_regs_buf ) { PRINTM ( FATAL , " \n " ) ; goto err_kmalloc ; } priv -> adapter -> hw_regs = ( u8 * ) ALIGN_ADDR ( priv -> adapter -> hw_regs_buf , DMA_ALIGNMENT ) ; bt_init_adapter ( priv ) ; PRINTM ( INFO , " \n " ) ; priv -> MainThread . priv = priv ; spin_lock_init ( & priv -> driver_lock ) ; bt_create_thread ( bt_service_main_thread , & priv -> MainThread , " " ) ; while ( ! priv -> MainThread . pid ) os_sched_timeout ( 1 ) ; init_waitqueue_head ( & priv -> init_user_conf_wait_q ) ; priv -> bt_dev . card = card ; ( ( struct sdio_mmc_card * ) card ) -> priv = priv ; priv -> adapter -> sd_ireg = 0 ; if ( sbi_register_dev ( priv ) < 0 ) { PRINTM ( FATAL , " \n " ) ; goto err_registerdev ; } if ( bt_init_fw ( priv ) ) { PRINTM ( FATAL , " \n " ) ; goto err_init_fw ; } LEAVE ( ) ; return priv ; err_init_fw : clean_up_m_devs ( priv ) ; bt_proc_remove ( priv ) ; PRINTM ( INFO , " \n " ) ; sbi_unregister_dev ( priv ) ; err_registerdev : ( ( struct sdio_mmc_card * ) card ) -> priv = NULL ; priv -> adapter -> SurpriseRemoved = TRUE ; wake_up_interruptible ( & priv -> MainThread . waitQ ) ; while ( priv -> MainThread . pid ) os_sched_timeout ( 1 ) ; err_kmalloc : if ( priv -> adapter ) bt_free_adapter ( priv ) ; for ( index = 0 ; index < MAX_BT_ADAPTER ; index ++ ) { if ( m_priv [ index ] == priv ) { m_priv [ index ] = NULL ; break ; } } bt_priv_put ( priv ) ; LEAVE ( ) ; return NULL ; }
@brief This function adds the card.
@brief This function adds the card .
/* Save the handle */ /* allocate buffer for bt_adapter */ /* wait for mainthread to up */ /** user config file */ /*
	 * Register the device. Fillup the private data structure with
	 * relevant information from the card and request for the required
	 * IRQ.
	 */ /* Stop the thread servicing the interrupts */