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.

Linux/AM3352: how to dynamically switch USB role between host and device in application level

Part Number: AM3352

Tool/software: Linux

A TYPE A USB port is required to sometimes act as a host reading USB-stick, and some other times act as a device to connect to PC as a virtual serial.

The USB1_ID pin is connected directly to DGND.

I changed IDDIG and IDDIG_MUX of USB1MODE register(0x474018E8) and SESSION of devctl register (0x47401C60)  in application level, but it failed to switch the role from host to device.

Does anyone know how to dynamically switch USB role between host and device in application level?

  • Please post the Linux version you use.
  • Linux version 3.12.10
  • Hi,

    To do usb host/device mode role switching, you will use micro-AB receptacle for the down stream port, connect the USB1_ID pin to the ID pin of the micro-AB receptacle, then the role switching is controlled by attaching micro-A or micro-B cable.

    Please refer to the AM335x GP EVM USB0 port design.
  • The board will hardly be modified. It's already used for other products.

    There is a description in manual.

    "Similarly, for a USB host configuration the user has the option of using the cable end to select the role by
    attaching the mini or micro a side of the cable (can consider this as a h/w option) or use the optional
    method where the firmware is required to program the respective USB Mode Register IDDIG bit field with
    a value of ‘0’ value prior to the USB controller going into session (can consider this as a s/w option). "

    I tried modify the corresponding registers, but failed. 

    My operations should have some problem .  But I don't know what it is.

    Could you help to describe the correct operations in details?

    Thanks!

  • Hi,

    What the TRM describes is how the hardware (the USB controller) can switching the operational mode via software control. But the Linux kernel MUSB driver doesn't support this function.
  • 1. Do you have a plan to support this function for ti Linux kernel branch?

    2. Can you give us a non-Linux example to have a test?

    In the user manual of spruh73p.pdf, it mentioned below 

    Two registers, USB0 Mode Register at offset 10E8h and USB1 Mode Register at offset 18E8h, are used

    for a user to select the role the USB controller assumes. The user is required to program the
    corresponding register prior to the USB controller is in session

    8 IDDIG R/W 1h MGC input value for iddig
    0=A type
    1=B type
    7 IDDIG_MUX R/W 0h Multiplexer control for IDDIG signal going to the controller.
    0 = IDDIG is from PHY0.
    1 = IDDIG is from bit 8 (IDDIG) of this USB0MODE register.

    I think it is not clear, please give me an example to do this work in am335x-evm board.

    when finishing this work, I will have  a pull request in your ti-Linux kernel maintenance branch  

  • Hi,

    #1, I can add this requirement to my TODO list, but given the planed work I have now, I am currently unable to promise when the implementation of this function will be done.

    #2, sorry, I don't have an non-Linux example for you.
    Yes, the USB Mode register you mentioned is the one to switch the mode. If the register is set to 0x80, Turning on the session will put the musb controller to host mode; If the register is set to 0x180, then connect the musb port to a usb host port, the musb controller will go to device mode.

    It is such simple for the hardware (the musb controller), but the problem is in the Linux driver - the software state. When transition from one mode to another, the driver has to tear down the current state (host or device mode) then start the other state (device or host). And there are many corner cases to be considered when implementing this mode switching function.
  • Dear Liu,

    I don't care what running os on it, and just care how did you test and verify this function, and give your example when you did this test.

    thanks

    rick

  • Hi,

    user4607835 said:
    I don't care what running os on it, and just care how did you test and verify this function, and give your example when you did this test.

    I am not sure I understand your query. As I said dynamic role switching is not supported in Linux. This is nothing I can test.