[BPI-R2] OTG-port

Hi,

i’ve got info that USB-OTG driver was included in upstream an added it to my 5.4-main-tree.

now i hang on dts-node…i took node from example of Patch and modified to have no alias/name-problem

otg: usb@11200000 {
        compatible = "mediatek,mt2701-musb",
                     "mediatek,mtk-musb";
        reg = <0 0x11200000 0 0x1000>;
        interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_LOW>;
        interrupt-names = "mc";
        phys = <&u2port2 PHY_TYPE_USB2>;
        dr_mode = "otg";
        clocks = <&pericfg CLK_PERI_USB0>,
                 <&pericfg CLK_PERI_USB0_MCU>,
                 <&pericfg CLK_PERI_USB_SLV>;
        clock-names = "main","mcu","univpll";
        power-domains = <&scpsys MT2701_POWER_DOMAIN_IFR_MSC>;
        usb-role-switch;
        connector{
                compatible = "gpio-usb-b-connector", "usb-b-connector";
                type = "micro";
                id-gpios = <&pio 44 GPIO_ACTIVE_HIGH>;
                vbus-supply = <&usb_vbus>;
        };
};

below the memory node in bpi-r2.dts in 5.4

  DTC     arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dtb
arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts:141.20-161.4: ERROR (phandle_references): /usb@11200000: Reference to non-existent node or label "u2port2"

arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts:155.12-160.5: ERROR (phandle_references): /usb@11200000/connector: Reference to non-existent node or label "usb_vbus"

so i need the u2port2 (the phy?) and usb_vbus nodes. i have u2port0 and u2port1 defined in mt7623.dtsi, but imho these are the “normal” usb-ports. And i have no vbus-node which i can use…

i got some hints from MTK, but need some help to solve it

  1. rename musb phy dts node because it was used by XHCI driver. => which phy is used for otg-port? there are 2 u3phy1 and u3phy2 (5.4-main/mt7623.dtsi#L1136)
  2. check usb VBUS/IDDIG gpio number (cannot use original mt2701 gpio number) => shematics Page 18 => i found gpio45 for NCEB0 but not for NCEB1=IDDIG
  3. check MT7623’s clock-names and power-domains => will look if first 2 are solved

Questions mainly go to @sinovoip / @Jackzeng (if he is still by bpi) and maybe @ray but maybe anybody else can help me here

I don’t remember where I get it, but my info is:

usb-power-supply = <&mt6323_vusb_reg>;

And no PHY links.

Plus, add following into pinctl definitions:

    usb_iddig: iddig_irq_init{
            pins_cmd_dat {
                    pinmux = <MT7623_PIN_44_NCEB1_FUNC_GPIO44>;
                    bias-pull-up ;
            };
    };

    usb_drvvbus: drvvbus_init{
            pins_cmd_dat {
                    pinmux = <MT7623_PIN_237_EXT_SDIO2_FUNC_GPIO237>;
                    output-low;
            };
    };

    usb_drvvbus_low: drvvbus_low{
            pins_cmd_dat {
                    pinmux = <MT7623_PIN_237_EXT_SDIO2_FUNC_GPIO237>;
                    slew-rate = <1>;
                    output-low;
            };
    };

    usb_drvvbus_high: drvvbus_high{
            pins_cmd_dat {
                    pinmux = <MT7623_PIN_237_EXT_SDIO2_FUNC_GPIO237>;
                    output-high;
            };
    };

OTG node overrides:

&usb0 {
    pinctrl-names = "iddig_irq_init", "drvvbus_init",
                    "drvvbus_low", "drvvbus_high";
    pinctrl-0 = <&usb_iddig>;
    pinctrl-1 = <&usb_drvvbus>;
    pinctrl-2 = <&usb_drvvbus_low>;
    pinctrl-3 = <&usb_drvvbus_high>;
    status = "okay";
    drvvbus_gpio = <&pio 237 0>;
    otg-iddig{
            iddig_gpio = <&pio 44 0>;
            interrupt-parent = <&pio>;
            interrupts = <26 IRQ_TYPE_LEVEL_LOW>;
    };
    vbus-detect{
            vbus_gpio = <&pio 102 0>;
            interrupt-parent = <&pio>;
            interrupts = <75 IRQ_TYPE_LEVEL_HIGH>;
    };
};
1 Like

Thank you very much…i will try when i’m at home…can i leave existing usb-nodes (step1 above)?

I don’t know :slight_smile:

ok, try & error :stuck_out_tongue:

how is your usb0 defined? i have only usb1+2

if i get it compiled, lets see what my dmesg say…

have added your info to my otg-node to keep them inside (need to adjust to current driver).

https://github.com/frank-w/BPI-R2-4.14/tree/5.4-otg

at current state i get this:

[   11.188693] musb-mtk 11200000.usb: fail to getting phy -19
[   11.890703] usb-conn-gpio 11200000.usb:connector: GPIO lookup for consumer id
[   11.902251] usb-conn-gpio 11200000.usb:connector: using device tree for GPIO lookup
[   11.914167] of_get_named_gpiod_flags: parsed 'id-gpios' property of node '/usb@11200000/connector[0]' - status (0)
[   11.928895] gpio gpiochip0: Persistence not supported for GPIO 44
[   11.939324] usb-conn-gpio 11200000.usb:connector: GPIO lookup for consumer vbus
[   11.950931] usb-conn-gpio 11200000.usb:connector: using device tree for GPIO lookup
[   11.962929] of_get_named_gpiod_flags: can't parse 'vbus-gpios' property of node '/usb@11200000/connector[0]'
[   11.977133] of_get_named_gpiod_flags: can't parse 'vbus-gpio' property of node '/usb@11200000/connector[0]'
[   11.991179] usb-conn-gpio 11200000.usb:connector: using lookup tables for GPIO lookup
[   12.003361] usb-conn-gpio 11200000.usb:connector: No GPIO consumer vbus found

so it looks i need a phy and vbus is wrong

Maybe i can use u2portX as phy?

added now nodes from mt2701 and got this:

[   11.304642] usb_phy_generic usb_phy_generic.1.auto: usb_phy_generic.1.auto supply vcc not found, using dummy regulator                            
[   11.349465] musb-hdrc musb-hdrc.2.auto: DMA controller not set                                                                                    
[   11.359841] musb-hdrc musb-hdrc.2.auto: musb_init_controller failed with status -19                                                               
[   12.019546] usb-conn-gpio 11200000.usb:connector: GPIO lookup for consumer id                                                                     
[   12.030896] usb-conn-gpio 11200000.usb:connector: using device tree for GPIO lookup                                                               
[   12.030946] of_get_named_gpiod_flags: parsed 'id-gpios' property of node '/usb@11200000/connector[0]' - status (0)                                
[   12.057261] gpio gpiochip0: Persistence not supported for GPIO 44                                                                                 
[   12.068283] usb-conn-gpio 11200000.usb:connector: GPIO lookup for consumer vbus                                                                   
[   12.079854] usb-conn-gpio 11200000.usb:connector: using device tree for GPIO lookup                                                               
[   12.091748] of_get_named_gpiod_flags: can't parse 'vbus-gpios' property of node '/usb@11200000/connector[0]'                                      
[   12.105943] of_get_named_gpiod_flags: can't parse 'vbus-gpio' property of node '/usb@11200000/connector[0]'                                       
[   12.120003] usb-conn-gpio 11200000.usb:connector: using lookup tables for GPIO lookup                                                             
[   12.132175] usb-conn-gpio 11200000.usb:connector: No GPIO consumer vbus found

dma-error points to this (drivers/usb/musb/musb_core.c):

2308 #ifndef CONFIG_MUSB_PIO_ONLY
2309         if (!musb->ops->dma_init || !musb->ops->dma_exit) {
2310                 dev_err(dev, "DMA controller not set\n");
2311                 status = -ENODEV;
2312                 goto fail2;
2313         }
2314         musb_dma_controller_create = musb->ops->dma_init;
2315         musb_dma_controller_destroy = musb->ops->dma_exit;
2316 #endif

maybe i need CONFIG_MUSB_PIO_ONLY set…after adding this i get this:

[   11.170509] usb_phy_generic usb_phy_generic.1.auto: usb_phy_generic.1.auto supply vcc not found, using dummy regulator                            
[   11.248566] musb-hdrc musb-hdrc.2.auto: MUSB HDRC host driver                                                                                     
[   11.258748] musb-hdrc musb-hdrc.2.auto: new USB bus registered, assigned bus number 5                                                             
[   11.313360] hub 5-0:1.0: USB hub found                                                                                                            
[   11.335570] hub 5-0:1.0: 1 port detected                                                                                                          
[   11.511276] musb-hdrc musb-hdrc.2.auto: VBUS_ERROR in a_idle (80, <SessEnd), retry #0, port1 00000104

i’ve found out that otg is also not working in kernel 4.4

[    6.414494] usb_phy_generic.0.auto supply vcc not found, using dummy regulato
r                                                                               
[    6.421967] musb probe                                                       
[    6.424465] musb probe reg: 0xe3758000 ,0xe375a000 , irq: 42                 
[    6.443552] musb core probe done base 0xe375a000                             
[    7.554552] 1a1c0000.usb supply vbus not found, using dummy regulator

so i guess there is something wrong with the iddig/vbus

i get power on otg-port, but no device is connected…so iddig/vbus seems right, but usb not properly initialized

created issue to verify otg in 4.4

and it looks like musb-driver in 4.4 crashes on system-halt

[ 4497.882508] [<c01f0264>] (sysfs_remove_group) from [<c0806ca4>] (usb_remove_hcd+0x
5c/0x1fc)
[ 4497.896930] [<c0806ca4>] (usb_remove_hcd) from [<c06c7d78>] (musb_shutdown+0x1a0/0
x1b0)
[ 4497.911028] [<c06c7d78>] (musb_shutdown) from [<c06966a8>] (platform_drv_shutdown+
0x30/0x40)
[ 4497.925587] [<c06966a8>] (platform_drv_shutdown) from [<c0692488>] (device_shutdow
n+0x1a4/0x230)
[ 4497.940533] [<c0692488>] (device_shutdown) from [<c0057054>] (kernel_halt+0x44/0x6
8)
[ 4497.954466] [<c0057054>] (kernel_halt) from [<c00572dc>] (SyS_reboot+0x18c/0x1e4)
[ 4497.968119] [<c00572dc>] (SyS_reboot) from [<c000fe00>] (ret_fast_syscall+0x0/0x48
)

Just a small update

I got hostmode working,but otg-mode (roleswitch) does not…i see it responds,but hostmode do not work with it.

Traceback on powerdown seems to be a too short wait as it powers down after some time

See 5.14-otg branch

Roleswitch now working too. See 5.14-otg2 branch for a cleaned version.

I also increased wait time for power warning traceback,but this helps only if no device is connected anymore on poweroff. After the traceback board powers off (a 10s wait does not work too). Seems like otg driver blocks power to be shut off.

1 Like

Will your otg work be integrated in 5.15-main?

Sent Patches,but afaik they are added to 5.16

https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

I’ll add dts Patches to 5.15 (if i had not yet added them). And maybe add driver as module

1 Like

I have to say amazing work you do, thank you very much :smile:.

That would be really cool, sry that the only thing I can do is ask :slightly_frowning_face:.

dts-patch is already included in 5.15-main, have added config options, so next build should work