Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Usb otg in Linux Kernel

Other Parts Discussed in Thread: AM3505

Hello. I have am3505.  I use kernel 2.6.37(musb driver)

Switch to the periphery and return back to work correctly.(modprobe g_file_storage)

I want by default when I inserted the usb otg cable with the device, otg port worked as ahost and a device defined in the system

I  set up Otg mode. But, when my board start, and i insert Otg cable, nothing happens. I did research and found out, that hub driver not loaded, not called musb_start, interrupts are not initialized.

"echo F > musb_hdrc.0" also did not help, because interrupts are not initialized.

1)My first question is how to initialize otg mode correctly and is it capable of mine operation in these driver?

***

At this moment I corrected the driver so that it loads by default as a usb host, and if the cable is inserted into the device, the device is defined in the system. But if I do not have otg cable in the moment when the driver is loaded, the bit SESSION in devctl reset, and when I insert the device, it is not defined.

2)Bit SESSION is cleared in software or by controller in this situation ?

When the device is defined in the system, it is powered from the controller.
But even when the device and the cable is disconnected from the bus, the bus remains power on. 

3)This is normal operation for the OTG controller?  

4)And what happens if at this moment we connect any other usb host and make "modprobe g_file_storage"

  • When driver is in OTG mode then you need to insert gadget module to complete initialization which also includes adding musb HCD to linux stack. So make sure to insert the gadget module after bootup before trying to use the port either in host or device mode.

    => 2)Bit SESSION is cleared in software or by controller in this situation ?

    When no cable is connected (mini-A and device or mini-B to PC) then even if you set SESSION bit , it gets cleared by hardware.

    Ajay

  • Hi Alexandr,

    We were also looking the same functionality on AM3505 since long.

    Yesterday, I manged to get USB OTG (host and gadget both modes with static kernel) working in automatic mode. I did few changes in the USB subsystem (musb_core.c and am3505 specific file).

    If you want to check my solution, I can post the patch by next Tuesday (on a vacation till then) .

    Regards,

    Krunal

  • Krunal, It would be interesting to explore your experience, thank you

  • Ajaey,

    When driver is in OTG mode then you need to insert gadget module to complete initialization which also includes adding musb HCD to linux stack. So make sure to insert the gadget module after bootup before trying to use the port either in host or device mode.

    What concrete module do you mean(musb_gadget.c ?)?. I should get it through modeprobe or as something different?

  • It can be any gadget driver, say g_file_storage.ko or g_ether.ko.

    Ajay

  • Ajay,

    It can be any gadget driver, say g_file_storage.ko or g_ether.ko.

    When i load g_ether.ko and cable inside, everything is working properly(usb flash difined in my linux). But when the module is loaded without a OTG cable, the device(usb flash) is not defined. 

    # cat musb_hdrc.0
    Status: MHDRC, Mode=Peripheral (Power=e0, DevCtl=80)
    OTG state: a_idle; inactive
    Options: ?dma?, otg (peripheral+host), debug=0 [eps=16]
    Peripheral address: 01
    Root port status: 00000100
    CPPI: txcr=0 txsrc=0 txena=0; rxcr=0 rxsrc=0 rxena=0
    Gadget driver: g_ether

    ep0 (hw0): 1buf, csr 0000 maxp 0000
    (queue empty)

    How to make so that the device is determined at any time?

  • Are you saying that device is not getting detected even after module inserted. please send output of "cat musb_hdrc.0" when cable is connected to PC.

    Ajay

  • I don`t undestand you. I should connect my device to PC? Now I testing host mode of my board.

     If I insert the OTG  cable with usb flash after the module g_ether.ko is loaded,  command "cat musb_hdrc.0" output

    # cd /proc/driver
    # cat musb_hdrc.0
    Status: MHDRC, Mode=Peripheral (Power=e0, DevCtl=80)
    OTG state: a_idle; inactive
    Options: ?dma?, otg (peripheral+host), debug=0 [eps=16]
    Peripheral address: 01
    Root port status: 00000100
    CPPI: txcr=0 txsrc=0 txena=0; rxcr=0 rxsrc=0 rxena=0
    Gadget driver: g_ether
    
    
    If i write echo F > musb_hdrc.0 after insert OTG cable with usb flash, all work propertly.
    But how make that  flash determined after insertion(OTG cable with flash) without write echo command.


  • I understand it now. Below steps doesn't work for you.

    1. Device is not connected through OTG cable

    2. Perform "echo F > musb_hdrc.0"

    3. Connect device through otg cable

    4. Device not detected .

    This is expected behavior as you need to follow the steps below for the same:

    1. Connect device through otg cable

    2. Perform "echo F > musb_hdrc.0"

    2. Device gets enumerated .

    If you don;t want to use "echo F " at all then you can refer below patch which is done for AM335x on v3.2 kernel and need to be ported back for AM35x (v2.6.37). (Copy changes from drivers/usb/musb/am335x.c to drivers/usb/musb/am35x.c)

    http://arago-project.org/git/projects/?p=linux-am33x.git;a=commitdiff;h=5b20494150d8c045f152f06bee57da2e64dc4964

    Ajay

  • I made your patch.   I use load g_ether modul when board is start. Host mode work properly. I insertt OTG cable with flash and and flash detected.

     But when I connect my board with PC,  unload g_either and load g_file_storage for Device mode, my board not detected in PC.

    This is "cat musb_hdrc.0"  output in this situation:

    # cat musb_hdrc.0
    Status: MHDRC, Mode=Peripheral (Power=f0, DevCtl=99)
    OTG state: b_idle; inactive
    Options: ?dma?, otg (peripheral+host), debug=0 [eps=16]
    Peripheral address: 01
    Root port status: 00000000
    CPPI: txcr=0 txsrc=0 txena=0; rxcr=0 rxsrc=0 rxena=0
    Gadget driver: g_file_storage
    If I reboot my board and not test Host mode(not insert OTG cable with flash), and immediately 
    connect my board to PC, unload g_either, load g_file_storage,
     then Device mode work propertly. 
    Why Device mode don`t work after use Host mode. 
  • If I load g_zero modul, when my board start and connected to PC, the following message appears:

                                    musb_g_ep0_irq 707: SetupEnd came in a wrong ep0stage setup   

    and then unload g_zero modul, the following error appears:

    [ 62.934295] irq 71: nobody cared (try booting with the "irqpoll" option) 
    [ 62.941955] handlers:
    [ 62.944305] [<bf0aa588>] (am35x_musb_interrupt+0x0/0x34c [am35x])
    [ 62.950653] Disabling IRQ #71
    dmesg mes:
    295] irq 71: nobody cared (try booting with the "irqpoll" option) 
    [ 62.941314] [<c003c5a4>] (unwind_backtrace+0x0/0xec) from [<c008a914>] (__report_bad_irq+0x30/0x88)
    [ 62.941345] [<c008a914>] (__report_bad_irq+0x30/0x88) from [<c008aab8>] (note_interrupt+0x14c/0x1d0)
    [ 62.941375] [<c008aab8>] (note_interrupt+0x14c/0x1d0) from [<c008b6c0>] (handle_level_irq+0xc4/0x114)
    [ 62.941436] [<c008b6c0>] (handle_level_irq+0xc4/0x114) from [<c002c074>] (asm_do_IRQ+0x74/0x98)
    [ 62.941467] [<c002c074>] (asm_do_IRQ+0x74/0x98) from [<c0036634>] (__irq_svc+0x34/0x80)
    [ 62.941497] Exception stack(0xc623be50 to 0xc623be98)
    [ 62.941528] be40: 00000020 c033f5a4 00000000 c0376340
    [ 62.941528] be60: c623a000 00000000 00000000 00000002 bf117b98 0000000a c6081004 00000000
    [ 62.941558] be80: 00000018 c623be98 c0062f24 c0062e24 20000113 ffffffff
    [ 62.941589] [<c0036634>] (__irq_svc+0x34/0x80) from [<c0062e24>] (__do_softirq+0x3c/0xfc)
    [ 62.941619] [<c0062e24>] (__do_softirq+0x3c/0xfc) from [<c0062f24>] (irq_exit+0x40/0x8c)
    [ 62.941650] [<c0062f24>] (irq_exit+0x40/0x8c) from [<c002c078>] (asm_do_IRQ+0x78/0x98)
    [ 62.941680] [<c002c078>] (asm_do_IRQ+0x78/0x98) from [<c0036634>] (__irq_svc+0x34/0x80)
    [ 62.941711] Exception stack(0xc623bed8 to 0xc623bf20)
    [ 62.941711] bec0: ffffffed 00000000
    [ 62.941741] bee0: c614e440 00000000 c60800dc c6080fe4 00000010 a0000013 bf117b98 bf117b98
    [ 62.941772] bf00: c6081004 00000000 00000000 c623bf20 bf08e8e0 bf08e908 80000013 ffffffff
    [ 62.941833] [<c0036634>] (__irq_svc+0x34/0x80) from [<bf08e908>] (usb_gadget_unregister_driver+0x180/0x214)
    [ 62.941894] [<bf08e908>] (usb_gadget_unregister_driver+0x180/0x214 [musb_hdrc]) from [<c0085e14>] (sys_del)
    [ 62.941925] [<c0085e14>] (sys_delete_module+0x1c8/0x234) from [<c0036a80>] (ret_fast_syscall+0x0/0x30)
    [ 62.941955] handlers:
    [ 62.944305] [<bf0aa588>] (am35x_musb_interrupt+0x0/0x34c [am35x])
    [ 62.950653] Disabling IRQ #71
    [ 62.953826] musb-hdrc musb-hdrc.0: remove, state 1
    [ 62.953887] usb usb2: USB disconnect, address 1
    [ 62.964996] musb-hdrc musb-hdrc.0: USB bus 2 deregistered
    
    
    And anyway, I noticed that if the device is connected to a PC, and  g_zerol module is loaded, device mode 
    no longer works properly, and sometimes the program falls out.
    How can I make to be able to switch to device mode when needed.