How to check the usb connect/disconnect state in uboot?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to check the usb connect/disconnect state in uboot?

1,238 次查看
xrz_lam
Contributor I

   I want to read the register value for check the USB connect/disconnect state in uboot,here is my codes but I found it can't work it

uboot,I think it was address error. Can you help me to check this codes and tell me how to find the register address in uboot, thanks.

int mx6sl_evk_charger_check(void)

{

  u32 vbus;

  int i=0;

#define  CHARGER_ADDR  0xf40c8000

//#define  CHARGER_ADDR  0x20C81D0

  printf("%s %s %d \n",__FILE__,__func__,__LINE__);

  /* Enable the vdd3p0 curret limiter */

  writel(BM_ANADIG_REG_3P0_ENABLE_LINREG |

  BM_ANADIG_REG_3P0_ENABLE_ILIMIT,

  CHARGER_ADDR + HW_ANADIG_REG_3P0_SET);

  /* check if vbus is valid */

  if (!(readl(CHARGER_ADDR + HW_ANADIG_USB1_VBUS_DET_STAT) &

  BM_ANADIG_USB1_VBUS_DET_STAT_VBUS_VALID)) {

  printf( "vbus is error\n");

  vbus = 0;

  return vbus;

  }

  /* Enable charger detector */

  writel(BM_ANADIG_USB1_CHRG_DETECT_EN_B,

  CHARGER_ADDR + HW_ANADIG_USB1_CHRG_DETECT_CLR);

  /*

  * - Do not check whether a charger is connected to the USB port

  * - Check whether the USB plug has been in contact with each other

  */

  writel(BM_ANADIG_USB1_CHRG_DETECT_CHK_CONTACT

  | BM_ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B,

  CHARGER_ADDR + HW_ANADIG_USB1_CHRG_DETECT_SET);

  udelay(200000);

for (i = 0; i < 1000; i = i + 1) {

  if( (readl(CHARGER_ADDR + HW_ANADIG_USB1_CHRG_DET_STAT) &

       /*BM_ANADIG_USB1_CHRG_DET_STAT_CHRG_DETECTED*/

        BM_ANADIG_USB1_CHRG_DET_STAT_PLUG_CONTACT)

     ||(readl(CHARGER_ADDR + HW_ANADIG_USB1_CHRG_DET_STAT) &

        BM_ANADIG_USB1_CHRG_DET_STAT_DP_STATE)

    ){

      printf( "Plug Contact = 1\n");

      vbus =1;

      break;

    }else if(i > 800){

         printf( "VBUS is coming from a dedicated power supply.\n");

         vbus =0;

        return vbus; 

    }else{

      udelay(1000);

  }

}

return vbus;

}

BTW,I had tested this codes in kernel,and it works well.

标签 (2)
标记 (1)
0 项奖励
回复
3 回复数

984 次查看
PeterChan
NXP Employee
NXP Employee

Your register base address is wrong. You should use 0x20C8000 or ANATOP_BASE_ADDR instead of the unknown address 0xf40c8000 in your u-boot code.

984 次查看
xrz_lam
Contributor I

Thanks for your help,I had changed this address and it had worked.

0 项奖励
回复

984 次查看
FrankLi1z
NXP Employee
NXP Employee

Do you enable clock?

0 项奖励
回复