udev knows by netlink to mount such as usb disk and knows to invoke usb garget as device.
How udev know that is the way you know that and the answer for your question.
The basic knowledge is netlink of linux. the dmesg is also by netlink link udev. if you write down a netlink program you will get such as usb disk add remove message as udev does.
From the sysfs /sys/class, it also can know the usb role.
It is linux question not a question for i.MX Processors community.
It is too big topic, suggest you to learn the netlink, udev mechanism first.
We use BSP 3.14*.
The board boots up without any problem - it is already a product for years. Now we want to add some new feature - do something when a USB device/host is connected to the OTG port. But we need to way to detect that a USB device/host is connected.
I want to set USB as host or device only when a USB host/device is connected - that goes back to my original question: How to detect that there is a USB device/host currently connected. It does not make sense to set anything if nothing is connected, right?
udev knows by netlink to mount such as usb disk and knows to invoke usb garget as device.
How udev know that is the way you know that and the answer for your question.
The basic knowledge is netlink of linux. the dmesg is also by netlink link udev. if you write down a netlink program you will get such as usb disk add remove message as udev does.
From the sysfs /sys/class, it also can know the usb role.
It is linux question not a question for i.MX Processors community.
It is too big topic, suggest you to learn the netlink, udev mechanism first.