diff options
author | Maxim Devaev <[email protected]> | 2021-08-28 19:01:13 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2021-08-28 19:01:13 +0300 |
commit | 2db0656df3ecd7c1f4502591c1a734905613e7ec (patch) | |
tree | 7ccf1cbd9a2e09ca12710302b6bc8fb3dc6b729e /kvmd/apps | |
parent | 08dad87fea9cd3b5ced5642864c5e8c359e8b1cc (diff) |
unified udc code and automatic driver detection
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/otg/__init__.py | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py index 791705be..ab9f5b51 100644 --- a/kvmd/apps/otg/__init__.py +++ b/kvmd/apps/otg/__init__.py @@ -38,6 +38,7 @@ from ...yamlconf import Section from ...validators import ValidatorError from ... import env +from ... import usb from .. import init @@ -88,18 +89,6 @@ def _write_bytes(path: str, data: bytes) -> None: param_file.write(data) -def _find_udc(udc: str) -> str: - candidates = sorted(os.listdir(f"{env.SYSFS_PREFIX}/sys/class/udc")) - if not udc: - if len(candidates) == 0: - raise RuntimeError("Can't find any UDC") - udc = candidates[0] - elif udc not in candidates: - raise RuntimeError(f"Can't find selected UDC: {udc}") - get_logger().info("Using UDC %s", udc) - return udc - - def _check_config(config: Section) -> None: if ( not config.otg.devices.serial.enabled @@ -176,7 +165,8 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements _check_config(config) - udc = _find_udc(config.otg.udc) + (udc, usb_driver) = usb.find_udc(config.otg.udc) + logger.info("Using UDC %s", udc) logger.info("Creating gadget %r ...", config.otg.gadget) gadget_path = join(f"{env.SYSFS_PREFIX}/sys/kernel/config/usb_gadget", config.otg.gadget) @@ -239,8 +229,8 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements _write(join(gadget_path, "UDC"), udc) time.sleep(config.otg.init_delay) - logger.info("Setting DWC2 bind permissions ...") - driver_path = f"{env.SYSFS_PREFIX}/sys/bus/platform/drivers/dwc2" + logger.info("Setting %s bind permissions ...", usb_driver) + driver_path = f"{env.SYSFS_PREFIX}/sys/bus/platform/drivers/{usb_driver}" _chown(join(driver_path, "bind"), config.otg.user) _chown(join(driver_path, "unbind"), config.otg.user) |