static void hs_slew_rate_cal(void) { unsigned long data; unsigned long x; unsigned char value; unsigned long start_time, timeout; unsigned int timeout_flag = 0; /* 4 s1:enable usb ring oscillator. */ USBPHY_SET8(0x15, 0x80); /* 4 s2:wait 1us. */ udelay(1); /* 4 s3:enable free run clock */ USBPHY_SET8(0xf00 - 0x800 + 0x11, 0x01); /* 4 s4:setting cyclecnt. */ USBPHY_SET8(0xf00 - 0x800 + 0x01, 0x04); /* 4 s5:enable frequency meter */ USBPHY_SET8(0xf00 - 0x800 + 0x03, 0x01); /* 4 s6:wait for frequency valid. */ start_time = jiffies; timeout = jiffies + 3 * HZ; while (!(USBPHY_READ8(0xf00 - 0x800 + 0x10) & 0x1)) { if (time_after(jiffies, timeout)) { timeout_flag = 1; break; } } /* 4 s7: read result. */ if (timeout_flag) { DBG(0, "[USBPHY] Slew Rate Calibration: Timeout\n"); value = 0x4; } else { data = USBPHY_READ32(0xf00 - 0x800 + 0x0c); x = ((1024 * FRA * PARA) / data); value = (unsigned char)(x / 1000); if ((x - value * 1000) / 100 >= 5) value += 1; DBG(0, "[USBPHY]slew calibration:FM_OUT =%lu,x=%lu,value=%d\n", data, x, value); } /* 4 s8: disable Frequency and run clock. */ USBPHY_CLR8(0xf00 - 0x800 + 0x03, 0x01); USBPHY_CLR8(0xf00 - 0x800 + 0x11, 0x01); /* 4 s9: */ #define MSK_RG_USB20_HSTX_SRCTRL 0x7 /* all clr first then set */ USBPHY_CLR8(0x15, MSK_RG_USB20_HSTX_SRCTRL << 4); USBPHY_SET8(0x15, (value & MSK_RG_USB20_HSTX_SRCTRL) << 4); /* 4 s10:disable usb ring oscillator. */ USBPHY_CLR8(0x15, 0x80); }
static void hs_slew_rate_cal(void){ unsigned long data; unsigned long x; unsigned char value; unsigned long start_time, timeout; unsigned int timeout_flag = 0; //4 s1:enable usb ring oscillator. USBPHY_WRITE8(0x15,0x80); //4 s2:wait 1us. udelay(1); //4 s3:enable free run clock USBPHY_WRITE8 (0xf00-0x800+0x11,0x01); //4 s4:setting cyclecnt. USBPHY_WRITE8 (0xf00-0x800+0x01,0x04); //4 s5:enable frequency meter USBPHY_SET8 (0xf00-0x800+0x03,0x01); //4 s6:wait for frequency valid. start_time = jiffies; timeout = jiffies + 3 * HZ; while(!(USBPHY_READ8(0xf00-0x800+0x10)&0x1)){ if(time_after(jiffies, timeout)){ timeout_flag = 1; break; } } //4 s7: read result. if(timeout_flag){ printk("[USBPHY] Slew Rate Calibration: Timeout\n"); value = 0x4; } else{ data = USBPHY_READ32 (0xf00-0x800+0x0c); x = ((1024*FRA*PARA)/data); value = (unsigned char)(x/1000); if((x-value*1000)/100>=5) value += 1; printk("[USBPHY]slew calibration:FM_OUT =%lu,x=%lu,value=%d\n",data,x,value); } //4 s8: disable Frequency and run clock. USBPHY_CLR8 (0xf00-0x800+0x03,0x01);//disable frequency meter USBPHY_CLR8 (0xf00-0x800+0x11,0x01);//disable free run clock //4 s9: USBPHY_WRITE8(0x15,value<<4); //4 s10:disable usb ring oscillator. USBPHY_CLR8(0x15,0x80); }
bool usb_phy_check_in_uart_mode() { UINT8 usb_port_mode; usb_enable_clock(true); udelay(50); usb_port_mode = USBPHY_READ8(0x6B); usb_enable_clock(false); if ((usb_port_mode == 0x5C) || (usb_port_mode == 0x5E)) return true; else return false; }
bool usb_phy_check_in_uart_mode() { bool ret; //usb_enable_clock(true); if ((USBPHY_READ8(0x6B)&0x5C) == 0x5C) { cur_usb_mode = UART_MODE; ret = true; } else { ret = false; } //usb_enable_clock(false); return ret; }
bool usb_phy_check_in_uart_mode(void) { UINT8 usb_port_mode; usb_enable_clock(true); udelay(50); usb_port_mode = USBPHY_READ8(0x6B); usb_enable_clock(false); if ((usb_port_mode == 0x5C) || (usb_port_mode == 0x5E)) { DBG(0, "%s:%d - IN UART MODE : 0x%x\n", __func__, __LINE__, usb_port_mode); DBG(0, "Mask PMIC charger detection in UART mode.\n"); pmic_chrdet_int_en(0); in_uart_mode = true; } else { DBG(0, "%s:%d - NOT IN UART MODE : 0x%x\n", __func__, __LINE__, usb_port_mode); in_uart_mode = false; } return in_uart_mode; }
void hs_slew_rate_cal(void){ unsigned long data; unsigned long x; unsigned char value; unsigned long start_time, timeout; unsigned int timeout_flag = 0; //s1: USBPHY_WRITE8(0x12,0x81); //s2: USBPHY_WRITE8 (0xf00-0x800+0x11,0x01); USBPHY_WRITE8 (0xf00-0x800+0x01,0x04); USBPHY_SET8 (0xf00-0x800+0x03,0x01); //s3: start_time = jiffies; timeout = jiffies + 3 * HZ; while(!(USBPHY_READ8(0xf00-0x800+0x10)&0x1)){ if(time_after(jiffies, timeout)){ timeout_flag = 1; break; } } //s4: if(timeout_flag){ printk("[USBPHY] Slew Rate Calibration: Timeout\n"); value = 0x4; } else{ data = USBPHY_READ32 (0xf00-0x800+0x0c); x = ((1024*FRA*PARA)/data); value = (unsigned char)(x/1000); if((x-value*1000)/100>=5) value += 1; //printk("[USBPHY]slew calibration:x=%d,value=%d\n",x,value); } //s5: USBPHY_CLR8 (0xf00-0x800+0x03,0x01);//disable frequency meter USBPHY_CLR8 (0xf00-0x800+0x11,0x01);//disable free run clock USBPHY_WRITE8(0x12,value); }
void usb_phy_poweron(void){ #ifdef MTK_UART_USB_SWITCH if (usb_phy_check_in_uart_mode()) return; #endif //4 s1: enable USB MAC clock. usb_enable_clock(true); //4 s2: wait 50 usec for PHY3.3v/1.8v stable. udelay(50); //4 s3: swtich to USB function. (system register, force ip into usb mode. USBPHY_CLR8(0x6b, 0x04); USBPHY_CLR8(0x6e, 0x01); //4 s4: RG_USB20_BC11_SW_EN 1'b0 USBPHY_CLR8(0x1a, 0x80); //RG_USB20_INTR_CAL[4:0] 5'b01101 Internal R selection USBPHY_WRITE8(0x06,((USBPHY_READ8(0x06)&0x7)|0x68)); //5 s5: RG_USB20_DP_100K_EN 1'b0, RG_USB20_DM_100K_EN 1'b0 USBPHY_CLR8(0x22, 0x03); //6 s6: release force suspendm. USBPHY_CLR8(0x6a, 0x04); //7 s7: wait for 800 usec. udelay(800); // force enter device mode USBPHY_CLR8(0x6c, 0x10); USBPHY_SET8(0x6c, 0x2E); USBPHY_SET8(0x6d, 0x3E); printk("usb power on success\n"); }
void usb_phy_recover(){ //turn on USB reference clock. usb_enable_clock(true); if (usb_phy_check_in_uart_mode()) return; //wait 50 usec. udelay(50); /* force_uart_en = 1'b0 */ USBPHY_CLR8(0x6b, 0x04); /* RG_UART_EN = 1'b0 */ USBPHY_CLR8(0x6e, 0x01); /* force_uart_en = 1'b0 */ USBPHY_CLR8(0x6a, 0x04); /* RG_DPPULLDOWN./RG_DMPULLDOWN. */ /* RG_XCVRSEL[1:0] = 2'b00 */ /* RG_TERMSEL = 1'b0 */ USBPHY_CLR8(0x68, 0xf4); /* RG_DATAIN[3:0] = 4'b0000 */ USBPHY_CLR8(0x69, 0x3c); /* * force_dp_pulldown, force_dm_pulldown, * force_xcversel, force_termsel. */ USBPHY_CLR8(0x6a, 0xba); /* RG_USB20_BC11_SW_EN = 1'b0 */ USBPHY_CLR8(0x1a, 0x80); /* RG_USB20_OTG_VBUSSCMP_EN = 1'b1 */ USBPHY_SET8(0x1a, 0x10); udelay(800); // force enter device mode USBPHY_CLR8(0x6c, 0x10); USBPHY_SET8(0x6c, 0x2E); USBPHY_SET8(0x6d, 0x3E); hs_slew_rate_cal(); //RG_USB20_VRT_VREF_SEL[2:0]=5 (ori:4) (0x11110804[14:12]) USBPHY_SET8(0x05, 0x10); //RG_USB20_TERM_VREF_SEL[2:0]=5 (ori:4) (0x11110804[10:8]) USBPHY_SET8(0x05, 0x01); printk("USB HW reg: index18=0x%x, index7=0x%x\n", get_devinfo_with_index(18), get_devinfo_with_index(7)); if (get_devinfo_with_index(18) & (0x01<<14)) { USBPHY_CLR8(0x00, 0x20); printk("USB HW reg: write RG_USB20_INTR_EN 0x%x\n", USBPHY_READ8(0x00)); } if (get_devinfo_with_index(7) & (0x07<<8)) { //RG_USB20_VRT_VREF_SEL[2:0]=5 (ori:4) (0x11110804[14:12]) USBPHY_CLR8(0x05, 0x70); USBPHY_SET8(0x05, ((get_devinfo_with_index(7)>>8)<<4)&0x70); printk("USB HW reg: overwrite RG_USB20_VRT_VREF_SEL 0x%x\n", USBPHY_READ8(0x05)); }
static void musb_id_pin_work(struct work_struct *data) { u8 devctl = 0; unsigned long flags; spin_lock_irqsave(&mtk_musb->lock, flags); musb_generic_disable(mtk_musb); spin_unlock_irqrestore(&mtk_musb->lock, flags); down(&mtk_musb->musb_lock); DBG(0, "work start, is_host=%d\n", mtk_musb->is_host); if(mtk_musb->in_ipo_off) { DBG(0, "do nothing due to in_ipo_off\n"); goto out; } mtk_musb ->is_host = musb_is_host(); DBG(0,"musb is as %s\n",mtk_musb->is_host?"host":"device"); switch_set_state((struct switch_dev *)&otg_state, mtk_musb->is_host); if (mtk_musb->is_host) { //setup fifo for host mode ep_config_from_table_for_host(mtk_musb); wake_lock(&mtk_musb->usb_lock); musb_platform_set_vbus(mtk_musb, 1); /* for no VBUS sensing IP*/ #if 1 /* wait VBUS ready */ msleep(100); /* clear session*/ devctl = musb_readb(mtk_musb->mregs,MUSB_DEVCTL); musb_writeb(mtk_musb->mregs, MUSB_DEVCTL, (devctl&(~MUSB_DEVCTL_SESSION))); /* USB MAC OFF*/ /* VBUSVALID=0, AVALID=0, BVALID=0, SESSEND=1, IDDIG=X */ USBPHY_SET8(0x6c, 0x10); USBPHY_CLR8(0x6c, 0x2e); USBPHY_SET8(0x6d, 0x3e); DBG(0,"force PHY to idle, 0x6d=%x, 0x6c=%x\n",USBPHY_READ8(0x6d), USBPHY_READ8(0x6c)); /* wait */ msleep(5); /* restart session */ devctl = musb_readb(mtk_musb->mregs,MUSB_DEVCTL); musb_writeb(mtk_musb->mregs, MUSB_DEVCTL, (devctl| MUSB_DEVCTL_SESSION)); /* USB MAC ONand Host Mode*/ /* VBUSVALID=1, AVALID=1, BVALID=1, SESSEND=0, IDDIG=0 */ USBPHY_CLR8(0x6c, 0x10); USBPHY_SET8(0x6c, 0x2c); USBPHY_SET8(0x6d, 0x3e); DBG(0,"force PHY to host mode, 0x6d=%x, 0x6c=%x\n",USBPHY_READ8(0x6d), USBPHY_READ8(0x6c)); #endif musb_start(mtk_musb); MUSB_HST_MODE(mtk_musb); switch_int_to_device(mtk_musb); } else { DBG(0,"devctl is %x\n",musb_readb(mtk_musb->mregs,MUSB_DEVCTL)); musb_writeb(mtk_musb->mregs,MUSB_DEVCTL,0); if (wake_lock_active(&mtk_musb->usb_lock)) wake_unlock(&mtk_musb->usb_lock); musb_platform_set_vbus(mtk_musb, 0); /* for no VBUS sensing IP */ #if 1 /* USB MAC OFF*/ /* VBUSVALID=0, AVALID=0, BVALID=0, SESSEND=1, IDDIG=X */ USBPHY_SET8(0x6c, 0x10); USBPHY_CLR8(0x6c, 0x2e); USBPHY_SET8(0x6d, 0x3e); DBG(0,"force PHY to idle, 0x6d=%x, 0x6c=%x\n", USBPHY_READ8(0x6d), USBPHY_READ8(0x6c)); #endif musb_stop(mtk_musb); //ALPS00849138 mtk_musb->xceiv->state = OTG_STATE_B_IDLE; MUSB_DEV_MODE(mtk_musb); switch_int_to_host(mtk_musb); } out: DBG(0, "work end, is_host=%d\n", mtk_musb->is_host); up(&mtk_musb->musb_lock); }
void usb_phy_recover(void){ //4 1. turn on USB reference clock. usb_enable_clock(true); //4 2. wait 50 usec. udelay(50); #ifdef MTK_UART_USB_SWITCH if (!usb_phy_check_in_uart_mode()) { // clean PUPD_BIST_EN // PUPD_BIST_EN = 1'b0 // PMIC will use it to detect charger type USBPHY_CLR8(0x1d, 0x10); //4 3. force_uart_en = 1'b0 USBPHY_CLR8(0x6b, 0x04); //4 4. RG_UART_EN = 1'b0 USBPHY_CLR8(0x6e, 0x1); //4 5. release force suspendm. USBPHY_CLR8(0x6a, 0x04); skipDisableUartMode = false; } else { if (!skipDisableUartMode) return; } #else // clean PUPD_BIST_EN // PUPD_BIST_EN = 1'b0 // PMIC will use it to detect charger type USBPHY_CLR8(0x1d, 0x10); //4 3. force_uart_en = 1'b0 USBPHY_CLR8(0x6b, 0x04); //4 4. RG_UART_EN = 1'b0 USBPHY_CLR8(0x6e, 0x1); //4 5. force_uart_en = 1'b0 USBPHY_CLR8(0x6a, 0x04); #endif //4 6. RG_DPPULLDOWN = 1'b0 USBPHY_CLR8(0x68, 0x40); //4 7. RG_DMPULLDOWN = 1'b0 USBPHY_CLR8(0x68, 0x80); //4 8. RG_XCVRSEL = 2'b00 USBPHY_CLR8(0x68, 0x30); //4 9. RG_TERMSEL = 1'b0 USBPHY_CLR8(0x68, 0x04); //4 10. RG_DATAIN[3:0] = 4'b0000 USBPHY_CLR8(0x69, 0x3c); //4 11. force_dp_pulldown = 1b'0 USBPHY_CLR8(0x6a, 0x10); //4 12. force_dm_pulldown = 1b'0 USBPHY_CLR8(0x6a, 0x20); //4 13. force_xcversel = 1b'0 USBPHY_CLR8(0x6a, 0x08); //4 14. force_termsel = 1b'0 USBPHY_CLR8(0x6a, 0x02); //4 15. force_datain = 1b'0 USBPHY_CLR8(0x6a, 0x80); //4 16. RG_USB20_BC11_SW_EN 1'b0 USBPHY_CLR8(0x1a, 0x80); //RG_USB20_INTR_CAL[4:0] 5'b01101 Internal R selection if (get_devinfo_with_index(19) & (0xF80)) { //printk("USB HW reg: read RG_USB20_INTR_CAL 0x%x\n", USBPHY_READ8(0x06)); USBPHY_WRITE8(0x06,((USBPHY_READ8(0x06)&0x7)|((get_devinfo_with_index(19)&0xF80)>>4))); printk("USB HW reg: write RG_USB20_INTR_CAL 0x%x\n", USBPHY_READ8(0x06)); }
static void usb_phy_savecurrent_internal(void){ //4 1. swtich to USB function. (system register, force ip into usb mode. #ifdef MTK_UART_USB_SWITCH if (!usb_phy_check_in_uart_mode()) { //4 s1: enable USB MAC clock. usb_enable_clock(true); //4 s2: wait 50 usec for PHY3.3v/1.8v stable. udelay(50); USBPHY_CLR8(0x6b, 0x04); USBPHY_CLR8(0x6e, 0x01); //4 2. release force suspendm. USBPHY_CLR8(0x6a, 0x04); usb_enable_clock(false); } else { if (skipDisableUartMode) skipDisableUartMode = false; else return; } #else USBPHY_CLR8(0x6b, 0x04); USBPHY_CLR8(0x6e, 0x01); //4 2. release force suspendm. USBPHY_CLR8(0x6a, 0x04); #endif //4 3. RG_DPPULLDOWN./RG_DMPULLDOWN. USBPHY_SET8(0x68, 0xc0); //4 4. RG_XCVRSEL[1:0] =2'b01. USBPHY_CLR8(0x68, 0x30); USBPHY_SET8(0x68, 0x10); //4 5. RG_TERMSEL = 1'b1 USBPHY_SET8(0x68, 0x04); //4 6. RG_DATAIN[3:0]=4'b0000 USBPHY_CLR8(0x69, 0x3c); //4 7.force_dp_pulldown, force_dm_pulldown, force_xcversel,force_termsel. USBPHY_SET8(0x6a, 0xba); //4 8.RG_USB20_BC11_SW_EN 1'b0 USBPHY_CLR8(0x1a, 0x80); //RG_USB20_INTR_CAL[4:0] 5'b01101 Internal R selection USBPHY_WRITE8(0x06,((USBPHY_READ8(0x06)&0x7)|0x68)); //4 9.RG_USB20_OTG_VBUSSCMP_EN 1'b0 USBPHY_CLR8(0x1a, 0x10); //4 10. delay 800us. udelay(800); //4 11. rg_usb20_pll_stable = 1 USBPHY_SET8(0x63, 0x02); //ALPS00427972, implement the analog register formula printk("%s: USBPHY_READ8(0x05) = 0x%x \n", __func__, USBPHY_READ8(0x05)); printk("%s: USBPHY_READ8(0x07) = 0x%x \n", __func__, USBPHY_READ8(0x07)); //ALPS00427972, implement the analog register formula udelay(1); //4 12. force suspendm = 1. USBPHY_SET8(0x6a, 0x04); //4 13. wait 1us udelay(1); // force enter device mode USBPHY_CLR8(0x6c, 0x10); USBPHY_SET8(0x6c, 0x2E); USBPHY_SET8(0x6d, 0x3E); }
void mt_usb_phy_calibraion (int case_set, int input_reg) { int temp_added=0; int temp_test=0; int temp_mask; print("%s: case_set %d, input_reg = 0x%x \n", __func__, case_set, input_reg); switch(case_set) { case 1: //case 1 //If M_HW_RES3[15:13] !=0 //RG_USB20_TERM_VREF_SEL[2:0] <= RG_USB20_TERM_VREF_SEL[2:0] + M_HW_RES3[15:13] temp_mask = 0x07; temp_test = USBPHY_READ8(0x05); print("%s: temp_test = 0x%x \n", __func__, temp_test); temp_added = (USBPHY_READ8(0x05)& temp_mask) + input_reg; print("%s: temp_added = 0x%x \n", __func__, temp_added); temp_added &= 0x07; print("%s: temp_added = 0x%x \n", __func__, temp_added); USBPHY_CLR8(0x05, temp_mask); USBPHY_SET8(0x05, temp_added); temp_test = USBPHY_READ8(0x05); print("%s: final temp_test = 0x%x \n", __func__, temp_test); break; case 2: //case 2 //If M_HW_RES3[12:10] !=0 //RG_USB20_CLKREF_REF[2:0]<= RG_USB20_CLKREF_REF[2:0]+ M_HW_RES3[12:10] temp_mask = 0x07; temp_test = USBPHY_READ8(0x07); print("%s: temp_test = 0x%x \n", __func__, temp_test); temp_added = (USBPHY_READ8(0x07)& temp_mask) + input_reg; print("%s: temp_added = 0x%x \n", __func__, temp_added); temp_added &= 0x07; print("%s: temp_added = 0x%x \n", __func__, temp_added); USBPHY_CLR8(0x07, temp_mask); USBPHY_SET8(0x07, temp_added); temp_test = USBPHY_READ8(0x07); print("%s: final temp_test = 0x%x \n", __func__, temp_test); break; case 3: //case 3 //If M_HW_RES3[9:7] !=0 //RG_USB20_VRT_VREF_SEL[2:0]<=RG_USB20_VRT_VREF_SEL[2:0]+ M_HW_RES3[9:7] temp_mask = 0x70; temp_test = USBPHY_READ8(0x05); print("%s: temp_test = 0x%x \n", __func__, temp_test); temp_added = (USBPHY_READ8(0x05)& temp_mask) >> 4; print("%s: temp_added = 0x%x \n", __func__, temp_added); temp_added += input_reg; print("%s: temp_added = 0x%x \n", __func__, temp_added); temp_added &= 0x07; print("%s: temp_added = 0x%x \n", __func__, temp_added); USBPHY_CLR8(0x05, temp_mask); USBPHY_SET8(0x05, temp_added<<4); temp_test = USBPHY_READ8(0x05); print("%s: final temp_test = 0x%x \n", __func__, temp_test); break; } return; }