bool musb_is_host(void) { u8 devctl = 0; DBG(0,"will mask PMIC charger detection\n"); upmu_interrupt_chrdet_int_en(0); musb_platform_enable(mtk_musb); //musb_set_vbus(mtk_musb,FALSE); //mt65xx_eint_mask(EINT_CHR_DET_NUM); devctl = musb_readb(mtk_musb->mregs,MUSB_DEVCTL); DBG(0, "devctl = %x before end session\n", devctl); devctl &= ~MUSB_DEVCTL_SESSION; // this will cause A-device change back to B-device after A-cable plug out musb_writeb(mtk_musb->mregs, MUSB_DEVCTL, devctl); msleep(delay_time); devctl = musb_readb(mtk_musb->mregs, MUSB_DEVCTL); DBG(0,"devctl = %x before set session\n",devctl); devctl |= MUSB_DEVCTL_SESSION; //musb_set_vbus(mtk_musb,TRUE); musb_writeb(mtk_musb->mregs, MUSB_DEVCTL, devctl); msleep(delay_time1); devctl = musb_readb(mtk_musb->mregs, MUSB_DEVCTL); DBG(0, "devclt = %x\n", devctl); if (devctl & MUSB_DEVCTL_BDEVICE) { usb_is_host = FALSE; DBG(0,"will unmask PMIC charger detection\n"); upmu_interrupt_chrdet_int_en(1); return FALSE; } else { usb_is_host = TRUE; return TRUE; } }
int musb_otg_env_init(void){ u8 power; //u8 intrusb; //step1: mask the PMU/PMIC EINT mtk_musb->usb_if = true; mtk_musb->is_host = true;//workaround for PMIC charger detection //mt65xx_eint_mask(EINT_CHR_DET_NUM); upmu_interrupt_chrdet_int_en(0); #ifndef MTK_FAN5405_SUPPORT #ifndef MTK_NCP1851_SUPPORT #ifndef MTK_BQ24196_SUPPORT #ifndef MTK_BQ24158_SUPPORT //set the drvvbus mode as drvvbus(mode 6) #if !(defined(CONFIG_MT6585_FPGA) || defined(CONFIG_MT6577_FPGA) || defined(CONFIG_MT6589_FPGA) || defined(CONFIG_MT6582_FPGA)) mt_set_gpio_mode(GPIO_OTG_DRVVBUS_PIN,6); #endif #endif #endif #endif #endif //step5: make sure to power on the USB module if(mtk_musb->power) mtk_musb->power = FALSE; musb_platform_enable(mtk_musb); //step6: clear session bit musb_writeb(mtk_musb->mregs,MUSB_DEVCTL,0); //step7: disable and enable usb interrupt usb_l1intm_store = musb_readl(mtk_musb->mregs,USB_L1INTM); usb_intrrxe_store = musb_readw(mtk_musb->mregs,MUSB_INTRRXE); usb_intrtxe_store = musb_readw(mtk_musb->mregs,MUSB_INTRTXE); usb_intrusbe_store = musb_readb(mtk_musb->mregs,MUSB_INTRUSBE); musb_writel(mtk_musb->mregs,USB_L1INTM,0); musb_writew(mtk_musb->mregs,MUSB_INTRRXE,0); musb_writew(mtk_musb->mregs,MUSB_INTRTXE,0); musb_writeb(mtk_musb->mregs,MUSB_INTRUSBE,0); musb_writew(mtk_musb->mregs,MUSB_INTRRX,0xffff); musb_writew(mtk_musb->mregs,MUSB_INTRTX,0xffff); musb_writeb(mtk_musb->mregs,MUSB_INTRUSB,0xff); free_irq (mtk_musb->nIrq, mtk_musb); musb_writel(mtk_musb->mregs,USB_L1INTM,0x105); musb_writew(mtk_musb->mregs,MUSB_INTRTXE,1); musb_writeb(mtk_musb->mregs,MUSB_INTRUSBE,0xf7); //setp8: set the index to 0 for ep0, maybe no need. Designers said it is better not to use the index register. musb_writeb(mtk_musb->mregs, MUSB_INDEX, 0); //setp9: init message g_otg_message.msg = 0; spin_lock_init(&g_otg_message.lock); init_completion(&stop_event); #ifdef DX_DBG power = musb_readb(mtk_musb->mregs,MUSB_POWER); DBG(0,"start the USB-IF test in EM,power=0x%x!\n",power); #endif return 0; }
int musb_otg_env_exit(void){ DBG(0,"stop the USB-IF test in EM!\n"); musb_writel(mtk_musb->mregs,USB_L1INTM,0); musb_writew(mtk_musb->mregs,MUSB_INTRRXE,0); musb_writew(mtk_musb->mregs,MUSB_INTRTXE,0); musb_writeb(mtk_musb->mregs,MUSB_INTRUSBE,0); musb_writew(mtk_musb->mregs,MUSB_INTRRX,0xffff); musb_writew(mtk_musb->mregs,MUSB_INTRTX,0xffff); musb_writeb(mtk_musb->mregs,MUSB_INTRUSB,0xff); musb_writel(mtk_musb->mregs,USB_L1INTM,usb_l1intm_store); musb_writew(mtk_musb->mregs,MUSB_INTRRXE,usb_intrrxe_store); musb_writew(mtk_musb->mregs,MUSB_INTRTXE,usb_intrtxe_store); musb_writeb(mtk_musb->mregs,MUSB_INTRUSBE,usb_intrusbe_store); mtk_musb->usb_if = false; mtk_musb->is_host = false; upmu_interrupt_chrdet_int_en(1); return 0; }