static int BT_open(struct inode *inode, struct file *file)
{
    BT_INFO_FUNC("%s: major %d minor %d (pid %d)\n", __func__,
        imajor(inode),
        iminor(inode),
        current->pid
        );

#if 1 /* GeorgeKuo: turn on function before check stp ready */
     /* turn on BT */
    if (MTK_WCN_BOOL_FALSE == mtk_wcn_wmt_func_on(WMTDRV_TYPE_BT)) {
        BT_WARN_FUNC("WMT turn on BT fail!\n");
        return -ENODEV;
    }else{
        retflag = 0;
        mtk_wcn_wmt_msgcb_reg(WMTDRV_TYPE_BT, bt_cdev_rst_cb);
        BT_INFO_FUNC("WMT register BT rst cb!\n");
    }
#endif

    if (mtk_wcn_stp_is_ready()) {
#if 0 /* GeorgeKuo: turn on function before check stp ready */
         /* turn on BT */
        if (MTK_WCN_BOOL_FALSE == mtk_wcn_wmt_func_on(WMTDRV_TYPE_BT)) {
            BT_WARN_FUNC("WMT turn on BT fail!\n");
            return -ENODEV;
        }
#endif
        mtk_wcn_stp_set_bluez(0);

        BT_INFO_FUNC("Now it's in MTK Bluetooth Mode\n");
        BT_INFO_FUNC("WMT turn on BT OK!\n");
        BT_INFO_FUNC("STP is ready!\n");
        platform_load_nvram_data(BT_NVRAM_CUSTOM_NAME,
            (char *)&g_nvram_btdata, sizeof(g_nvram_btdata));

        BT_INFO_FUNC("Read NVRAM : BD address %02x%02x%02x%02x%02x%02x Cap 0x%02x Codec 0x%02x\n",
            g_nvram_btdata[0], g_nvram_btdata[1], g_nvram_btdata[2],
            g_nvram_btdata[3], g_nvram_btdata[4], g_nvram_btdata[5],
            g_nvram_btdata[6], g_nvram_btdata[7]);

        mtk_wcn_stp_register_event_cb(BT_TASK_INDX, BT_event_cb);
		BT_INFO_FUNC("mtk_wcn_stp_register_event_cb finish\n");
    }
    else {
        BT_ERR_FUNC("STP is not ready\n");

        /*return error code*/
        return -ENODEV;
    }

//    init_MUTEX(&wr_mtx);
    sema_init(&wr_mtx, 1);
//    init_MUTEX(&rd_mtx);
    sema_init(&rd_mtx, 1);
	BT_INFO_FUNC("finish\n");

    return 0;
}
Exemplo n.º 2
0
static int BT_open(struct inode *inode, struct file *file)
{
	BT_INFO_FUNC("%s: major %d minor %d pid %d\n", __func__, imajor(inode), iminor(inode), current->pid);
	if (current->pid == 1)
		return 0;

	/* Turn on BT */
	if (MTK_WCN_BOOL_FALSE == mtk_wcn_wmt_func_on(WMTDRV_TYPE_BT)) {
		BT_WARN_FUNC("WMT turn on BT fail!\n");
		return -ENODEV;
	}

	BT_INFO_FUNC("WMT turn on BT OK!\n");
	rstflag = 0;

	if (mtk_wcn_stp_is_ready()) {

		mtk_wcn_stp_set_bluez(0);

		BT_INFO_FUNC("Now it's in MTK Bluetooth Mode\n");
		BT_INFO_FUNC("STP is ready!\n");

		BT_DBG_FUNC("Register BT event callback!\n");
		mtk_wcn_stp_register_event_cb(BT_TASK_INDX, BT_event_cb);
	} else {
		BT_ERR_FUNC("STP is not ready\n");
		mtk_wcn_wmt_func_off(WMTDRV_TYPE_BT);
		return -ENODEV;
	}

	BT_DBG_FUNC("Register BT reset callback!\n");
	mtk_wcn_wmt_msgcb_reg(WMTDRV_TYPE_BT, bt_cdev_rst_cb);

/* init_MUTEX(&wr_mtx); */
	sema_init(&wr_mtx, 1);
/* init_MUTEX(&rd_mtx); */
	sema_init(&rd_mtx, 1);
	BT_INFO_FUNC("%s: finish\n", __func__);

	return 0;
}