usb detection based on usb otg id pin

cancel
Showing results for 
Search instead for 
Did you mean: 

usb detection based on usb otg id pin

4,530 Views
Contributor I

hi,

   I need to detect the usb based on usb otg id pin on imx6q saberauto platfrom.

   how do i need kernel configure for this purpose or any gpio mux setting.

   currently i am using MX6Q_PAD_ENET_RX_ER__ANATOP_USBOTG_ID in gpio mode but i am not get interrupt based on this, do i missing any thing???

Thanks

Anurag

Labels (1)
0 Kudos
18 Replies

82 Views
Senior Contributor IV

Anurag

This discussion is closed since no activity. If you still need help, please feel free to reply with an update to this discussion, or create another discussion.

Thanks,

Yixing

0 Kudos

82 Views
Senior Contributor IV

Anurag

Had your issue got resolved? If yes, we are going to close the discussion in 3 days. If you still need help, please feel

free to reply with an update to this discussion.

Thanks,
Yixing

0 Kudos

82 Views
Senior Contributor I

  I think you misunderstanding USBOTG ID detection on MX6. Please don't use it in GPIO mode but to using OTGID mode.

  Meanwhile you must set IOMUX GPR1[13] bit for your OTGID selection .  For sabreauto platform,please see following board init

routine:

static void __init imx6q_sabreauto_init_usb(void)

{

  int ret = 0;

  imx_otg_base = MX6_IO_ADDRESS(MX6Q_USB_OTG_BASE_ADDR);

  ret = gpio_request(SABREAUTO_USB_OTG_OC, "otg-oc");

  if (ret) {

  printk(KERN_ERR"failed to get GPIO SABREAUTO_USB_OTG_OC:"

  " %d\n", ret);

  return;

  }

  gpio_direction_input(SABREAUTO_USB_OTG_OC);

  ret = gpio_request(SABREAUTO_USB_HOST1_OC, "usbh1-oc");

  if (ret) {

  printk(KERN_ERR"failed to get SABREAUTO_USB_HOST1_OC:"

  " %d\n", ret);

  return;

  }

  gpio_direction_input(SABREAUTO_USB_HOST1_OC);

  mxc_iomux_set_gpr_register(1, 13, 1, 0);  //0 means use ENET_RX_ER,1 means use GPIO_1.

  mx6_set_otghost_vbus_func(imx6q_sabreauto_usbotg_vbus);

  mx6_set_host1_vbus_func(imx6q_sabreauto_usbhost1_vbus);

#ifdef CONFIG_USB_EHCI_ARC_HSIC

  mx6_usb_h2_init();

  mx6_usb_h3_init();

#endif

}

0 Kudos

82 Views
Contributor I

hi Raymond wang,

0 Kudos

82 Views
Senior Contributor I

Could you please give more details on your design?

On my board, we use GPIO1 as OTGID. I list some code snippet related to my OTG .

//OTGID pin config

MX6Q_PAD_GPIO_1__USBOTG_ID,

static void __init imx6q_qpad_init_usb(void)

{

  int ret = 0;

  imx_otg_base = MX6_IO_ADDRESS(MX6Q_USB_OTG_BASE_ADDR);

  /* disable external charger detect,

  * or it will affect signal quality at dp .

  */

  ret = gpio_request(QPAD_USB_OTG_PWR, "otg-vbus");

  if (ret) {

  pr_err("failed to get GPIO otg-vbus: %d\n",

  ret);

  return;

  }

  gpio_direction_output(QPAD_USB_OTG_PWR, 0);

  /*

  *

  *OTG ID daisy chain set

  * 0: ENET_RX_ER as USB_OTG_ID

  * 1: GPIO_1 as USB_OTG_ID

  */

  mxc_iomux_set_gpr_register(1, 13, 1, 1);

  mx6_set_otghost_vbus_func(qpad_usbotg_vbus);

  mx6_set_host1_vbus_func(qpad_host1_vbus);

}

Hope this can help you!

0 Kudos

82 Views
Contributor I

Hi Raymond Wang,

I am a friend of Anurag,who posted this discussion.I took over the issue.Below is the code snipped of my board file.I changed the line number 866 to set IOMUX GPR1[13] bit and in my arch  arcotg_udc.c(code snippet below) file ,where i am handling the interrupt is as follow.Still i am not getting the interrupt.Please give some points on this.

static void __init imx6q_sabreauto_init_usb(void)
846 {
847     int ret = 0;
848     imx_otg_base = MX6_IO_ADDRESS(MX6Q_USB_OTG_BASE_ADDR);
849
850     ret = gpio_request(SABREAUTO_USB_OTG_OC, "otg-oc");
851     if (ret) {
852         printk(KERN_ERR"failed to get GPIO SABREAUTO_USB_OTG_OC:"
853             " %d\n", ret);
854         return;
855     }
856     gpio_direction_input(SABREAUTO_USB_OTG_OC);
857
858     ret = gpio_request(SABREAUTO_USB_HOST1_OC, "usbh1-oc");
859     if (ret) {
860         printk(KERN_ERR"failed to get SABREAUTO_USB_HOST1_OC:"
861             " %d\n", ret);
862         return;
863     }
864     gpio_direction_input(SABREAUTO_USB_HOST1_OC);
865
866     mxc_iomux_set_gpr_register(1, 13, 1, 1);
867     mx6_set_otghost_vbus_func(imx6q_sabreauto_usbotg_vbus);
868     mx6_set_host1_vbus_func(imx6q_sabreauto_usbhost1_vbus);
869 #ifdef CONFIG_USB_EHCI_ARC_HSIC
870     mx6_usb_h2_init();
871     mx6_usb_h3_init();

         

arcotg_udc.c

  67 #define ALLGO_USB_OTGID_PIN_GPIO IMX_GPIO_NR(1,3)

          usb_otg_id_irq_num = gpio_to_irq(ALLGO_USB_OTGID_PIN_GPIO);
3368
3369     int otg_return = request_irq(usb_otg_id_irq_num,allgo_usbotgid_handler , IRQF_SHARED , "otg_id" , udc_controller);
3370
3371     if( otg_return == 0)
3372     {
3373          printk("###############usb otg id interrupt registered successfully irq number = %d\n",usb_otg_id_irq_num);
3374     }
3375     else
3376     {
3377         printk("usb otg id interrupt Could not be registered otg_return = %d \n",otg_return);
3378     }

Regards,

Bhanu Shankar D G

0 Kudos

82 Views
Contributor I

Adding to previous post,I have enabled this pin MX6Q_PAD_GPIO_1__USBOTG_ID in the board header file and the arguments for IMX_GPIO_NR 1,3 are correct?

Our board is IMX.6q sabreauto .

Regards,

Bhanu Shankar D G

0 Kudos

82 Views
Senior Contributor I

Yes,your usb otg code snippet should be right.

I don't know why you change file arcotg_udc.c on OTGID.

in file drivers/usb/otg/fsl_otg.c function

int usb_otg_start(struct platform_device *pdev)

{

...

/* request irq */

  if (pdata->id_gpio == 0) {  //this is default option,

  p_otg->irq = platform_get_irq(pdev, 0);

  status = request_irq(p_otg->irq, fsl_otg_isr,

IRQF_SHARED, driver_name, p_otg);  //SHARED IRQ of OTGID interrupt

  } else {

  status = request_irq(gpio_to_irq(pdata->id_gpio),

  fsl_otg_isr_gpio,

  IRQF_SHARED, driver_name, pdata);

  }

}

So you don't need to care about OTGID alternate GPIO because it don't use GPIO as OTGID (even it's similar).

BTW,you can dump file  /proc/driver/isp1504_otg  to check if your OTGID value is right or not. With default device

mode,OTGID has a internal pullup ,its value is 1(high), With host mode,it should be connected to ground then its

value is 0.

I list the otg dump data of mine here.

$cat /proc/driver/isp1504_otg                                 

Freescale USB OTG Driver

fsl_usb2_otg version: $Revision: 1.55 $

OTGSC reg: 09202f20

PORTSC reg: 10401805

USBMODE reg: 0000000a

USBCMD reg: 00080001

USBSTS reg: 00000081

OTG state: UNDEFINED

a_bus_req: 1

b_bus_req: 1

a_bus_resume: 0

a_bus_suspend: 0

a_conn: 0

a_sess_vld: 0

a_srp_det: 0

a_vbus_vld: 1

b_bus_resume: 0

b_bus_suspend: 0

b_conn: 0

b_se0_srp: 0

b_sess_end: 0

b_sess_vld: 0

id: 1 //1 means otg as device currently.

0 Kudos

82 Views
Contributor I

Hi Raymond Wang,

I am getting this fsl_otg_isr interrupt service routine but thing is it keeps coming and if a put a print ,i am getting this print so many times and its not stopping.My purpose is to get the interrup once  when we connect through otg pin and once when we disconnect the device.But here it keeps on coming.What might be the reason?

Regards,

Bhanu Shankar D G

0 Kudos

82 Views
Senior Contributor I

From FSL code,drivers/usb/otg/fsl_otg.c

/* OTG Initialization*/

int usb_otg_start(struct platform_device *pdev)

{

..

/* disable all interrupt and clear all OTGSC status */

  temp = readl(&p_otg->dr_mem_map->otgsc);

  temp &= ~OTGSC_INTERRUPT_ENABLE_BITS_MASK;

  temp |= OTGSC_INTERRUPT_STATUS_BITS_MASK;

  if (pdata->need_discharge_vbus)

  temp |= OTGSC_CTRL_VBUS_DISCHARGE;

  writel(temp, &p_otg->dr_mem_map->otgsc);

  ...

DBG("initial ID pin=%d\n", p_otg->fsm.id);

/*From here we know only OTG ID interrupt enabled.

* I don't know what you mean on printing many times???

*/

/* enable OTG ID pin interrupt */

  temp = readl(&p_otg->dr_mem_map->otgsc);

  if (!pdata->id_gpio)

  temp |= OTGSC_INTR_USB_ID_EN;

  temp &= ~OTGSC_INTR_1MS_TIMER_EN;

  if (pdata->need_discharge_vbus)

  temp &= ~OTGSC_CTRL_VBUS_DISCHARGE;

  writel(temp, &p_otg->dr_mem_map->otgsc);

  return 0;

}

Normally,OTGID interrupt will print ID value (each OTGID change will print once)

printk(KERN_DEBUG "ID int (ID is %d)\n", fotg->fsm.id);

  If you found this will be printed many times,Please check your OTGID pin connection(Probably hardware rework required ). As I pointed out in last commit,

the OTGID pin level is sensitive for OTG working in device or host mode.

0 Kudos

82 Views
Contributor I

By printing many times ,i meant if we put some print in the interrupt service routine ,in this case  irqreturn_t fsl_otg_isr(int irq, void *dev_id) .This will be printed infinite number of times.

Regards,

Bhanu Shankar D G

0 Kudos

82 Views
Contributor I

In this case as i mentioned earlier printk(KERN_DEBUG "ID int (ID is %d)\n", fotg->fsm.id); will keep on printing many times with ID value as 1.


Regards,

Bhanu Shankar D G

0 Kudos

82 Views
Contributor I

Actually I have 3 imx6q sabreauto boards.I have checked in all of them and i still see printk(KERN_DEBUG "ID int (ID is %d)\n", fotg->fsm.id);  prints coming for sometime with OTG ID as 1 in two boards and ID 0 as in another board.I am using same SD card for my testing . Do you think all of the boards have hardware issue?

Regards,

Bhanu Shankar D G

0 Kudos

82 Views
Senior Contributor I

Or if your board design is based on sabreauto, OTG_ID pin should not be changed. Use default setting is fine.

0 Kudos

82 Views
Contributor I

I changed the OTG ID pin to MX6Q_PAD_ENET_RX_ER__ANATOP_USBOTG_ID  and used

mxc_iomux_set_gpr_register(1, 13, 1, 0);  //0 means use ENET_RX_ER


Still i get the prints continiously for some time.(printk(KERN_DEBUG "ID int (ID is %d)\n", fotg->fsm.id);)


Regards,

Bhanu Shankar D G

0 Kudos

82 Views
Senior Contributor I

Still that, I insist on your board OTG_ID status is not stable. I don't think all of your 3 boards damaged if they are bought from FSL.

If these boards is your design based on SabreAuto, you should check your OTG circuit part carefully.

  In my hand, I tested my SabreSD board and our board (based on SabreSD but use MX6Q_PAD_GPIO_1__USBOTG_ID). Both of

them can work very well with OTG detection.

0 Kudos

82 Views
Senior Contributor I

FSL sabreauto use pin ENET_RX_ER as OTGID pin. MX6Q_PAD_ENET_RX_ER__ANATOP_USBOTG_ID.

I am confused about that. If you use FSL sabreauto board, default usb otg code should work.

  Please specify which pin as OTGID pin on your sabreauto board.

  BTW,  If you do not insert any cable on OTG port,the default OTGID pin status should be 1.

0 Kudos

82 Views
Senior Contributor I

Well,I think you should check your OTGID pin status with hardware engineer assist.

0 Kudos