Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDC convenience function #43

Open
sn00pster opened this issue Aug 14, 2019 · 6 comments
Open

UDC convenience function #43

sn00pster opened this issue Aug 14, 2019 · 6 comments

Comments

@sn00pster
Copy link

You can retrieve the name of the UDC using usbg_get_udc_name which in my case returns "UDC", the content of this file (which you check in some functions) is the real name of the UDC the gadget is attached to, something like 20980000.usb).

A convenience function to get the full "resolved" path to the UDC (i.e the /sys/class/udc/") would be super useful.

p = usbg_get_udc_path(g);

p = "/sys/class/udc/20980000.usb"

I can then use this easily to add a watch on the state file to monitor for the gadget being enumerated and disconnected from a host.

@kopasiak
Copy link
Collaborator

Instead of watch you should rather use udev rules or monitor.

You can check some nice blog post by @andrzejtp how to get this nicely automated with systemd:
https://www.collabora.com/news-and-blog/blog/2019/02/18/modern-usb-gadget-on-linux-and-how-to-integrate-it-with-systemd-part-1/

@sn00pster
Copy link
Author

https://www.collabora.com/news-and-blog/blog/2019/02/18/modern-usb-gadget-on-linux-and-how-to-integrate-it-with-systemd-part-1/

I can't see anything there relevant to this? Have I missed something obvious?

Linux gadgets (or rather their UDC's) don't send udev events on being connected to a host or disconnected from a host, this is my fundamental issue.

@kopasiak
Copy link
Collaborator

Yeah, they just send events when they appear in the system.

The functionality that you are looking for is provided by extcon API so you should subscribe to the extcon events

@sn00pster
Copy link
Author

there’s no references in the dwc2 driver (as used on the bcm2385 based raspberry pi devices) to the extcon API, I also believe the USB PHY is built into the DWC2 IP, so as far as i can tell theres no phy support for extcon either.

I’m not sure if I missed something or it’s just not supported. Theres absolutely no events whatsoever on the system that I can see when a gadget is connected or disconnected from a host.

@kopasiak
Copy link
Collaborator

Probably you should check your board schematics and look for sth like VBUS detection. On my testing platform (Odroid U3+) I use extcon-gpio driver as it has a separate GPIO line for sensing VBUS

@RoganDawes
Copy link

Is there no way to detect/notify when the USB protocol negotiation happens?

For example, my device could be plugged into a phone charger which would trigger VBUS, but would not mean that there was any actual USB protocol negotiation happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants