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

cancel
Showing results for 
Search instead for 
Did you mean: 

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

400 Views
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.

Labels (2)
Tags (1)
0 Kudos
3 Replies

146 Views
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.

146 Views
xrz_lam
Contributor I

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

0 Kudos

146 Views
FrankLi1z
NXP Employee
NXP Employee

Do you enable clock?

0 Kudos