From 7f688ffd2877aecf4bebb11f47ed5ee9642cba42 Mon Sep 17 00:00:00 2001 From: Amit Sunil Dhamne Date: Fri, 16 Aug 2024 00:46:36 -0700 Subject: [PATCH 1/2] UsbGadget: Update SDP enum timeout when gadget is pulled up Indicate to the kernel that the usb gadget is pulled up by writing to `update_sdp_enum_timeout` sysfs node. Write to this node will inform the kernel that it can lower the SDP timeout alarm value which is used to detect an SDP port vs a DCP. Bug:356685367 Test: Check `update_sdp_enum_timeout` is written into after usb gadget is pulled up. Verify that the alarm timeout lowers. Flag: EXEMPT bugfix Change-Id: Id3ae7e7a20b236cec6604414a7f81860e868bdd0 (ported from commit d8e2a02998fc1db9be00dab69a213378fb3caede) Signed-off-by: Amit Sunil Dhamne --- usb/gadget/UsbGadget.cpp | 25 +++++++++++++++++++ usb/gadget/UsbGadget.h | 3 +++ usb/usb/android.hardware.usb-service-i2c11.rc | 2 ++ usb/usb/android.hardware.usb-service-i2c6.rc | 2 ++ 4 files changed, 32 insertions(+) diff --git a/usb/gadget/UsbGadget.cpp b/usb/gadget/UsbGadget.cpp index 5dbf304..3f243ae 100644 --- a/usb/gadget/UsbGadget.cpp +++ b/usb/gadget/UsbGadget.cpp @@ -49,6 +49,7 @@ constexpr char kTcpcDevName[] = "i2c-max77759tcpc"; constexpr char kI2cClientId[] = "0025"; constexpr char kAccessoryLimitCurrent[] = "usb_limit_accessory_current"; constexpr char kAccessoryLimitCurrentEnable[] = "usb_limit_accessory_enable"; +constexpr char kUpdateSdpEnumTimeout[] = "update_sdp_enum_timeout"; UsbGadget::UsbGadget() : mGadgetIrqPath(""), mI2cClientPath("") { @@ -103,6 +104,7 @@ Status UsbGadget::getUsbGadgetIrqPath() { void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) { UsbGadget *gadget = (UsbGadget *)payload; gadget->mCurrentUsbFunctionsApplied = functionsApplied; + gadget->updateSdpEnumTimeout(); } ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr &callback, @@ -369,6 +371,28 @@ ScopedAStatus UsbGadget::reset(const shared_ptr &callback, return ScopedAStatus::ok(); } +void UsbGadget::updateSdpEnumTimeout() { + string update_sdp_enum_timeout_path; + + if (mI2cClientPath.empty()) { + for (int i = 0; i < NUM_HSI2C_PATHS; ++i) { + mI2cClientPath = getI2cClientPath(kHsi2cPaths[i], kTcpcDevName, kI2cClientId); + if (mI2cClientPath.empty()) { + ALOGE("%s: Unable to locate i2c bus node", __func__); + } else { + break; + } + } + } + + update_sdp_enum_timeout_path = mI2cClientPath + kUpdateSdpEnumTimeout; + if (!WriteStringToFile("1", update_sdp_enum_timeout_path)) { + ALOGE("%s: Unable to write to %s.", __func__, update_sdp_enum_timeout_path.c_str()); + } else { + ALOGI("%s: Updated SDP enumeration timeout value.", __func__); + } +} + Status UsbGadget::setupFunctions(long functions, const shared_ptr &callback, uint64_t timeout, int64_t in_transactionId) { @@ -427,6 +451,7 @@ Status UsbGadget::setupFunctions(long functions, mCurrentUsbFunctionsApplied = true; if (callback) callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId); + updateSdpEnumTimeout(); return Status::SUCCESS; } diff --git a/usb/gadget/UsbGadget.h b/usb/gadget/UsbGadget.h index 7f2d230..94a8d8d 100644 --- a/usb/gadget/UsbGadget.h +++ b/usb/gadget/UsbGadget.h @@ -115,6 +115,9 @@ struct UsbGadget : public BnUsbGadget { ScopedAStatus setVidPid(const char *vid,const char *pid); + // Indicates to the kernel that the gadget service is ready and the kernel can + // set SDP timeout to a lower value. + void updateSdpEnumTimeout(); std::string mI2cClientPath; private: diff --git a/usb/usb/android.hardware.usb-service-i2c11.rc b/usb/usb/android.hardware.usb-service-i2c11.rc index ba3e657..dd4b86b 100644 --- a/usb/usb/android.hardware.usb-service-i2c11.rc +++ b/usb/usb/android.hardware.usb-service-i2c11.rc @@ -15,6 +15,7 @@ on post-fs chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_sink_current chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_sink_enable chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_source_enable + chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/update_sdp_enum_timeout chown root graphics /sys/devices/platform/110f0000.drmdp/drm-displayport/dp_hotplug_error_code chown root system /sys/devices/platform/110f0000.drmdp/drm-displayport/hpd chown root system /sys/devices/platform/110f0000.drmdp/drm-displayport/irq_hpd @@ -39,6 +40,7 @@ on post-fs chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_sink_current chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_sink_enable chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_source_enable + chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/update_sdp_enum_timeout chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/dp_hotplug_error_code chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/hpd chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/irq_hpd diff --git a/usb/usb/android.hardware.usb-service-i2c6.rc b/usb/usb/android.hardware.usb-service-i2c6.rc index 5caed19..fac08b3 100644 --- a/usb/usb/android.hardware.usb-service-i2c6.rc +++ b/usb/usb/android.hardware.usb-service-i2c6.rc @@ -15,6 +15,7 @@ on post-fs chown root system /sys/devices/platform/108d0000.hsi2c/i2c-6/6-0025/usb_limit_sink_current chown root system /sys/devices/platform/108d0000.hsi2c/i2c-6/6-0025/usb_limit_sink_enable chown root system /sys/devices/platform/108d0000.hsi2c/i2c-6/6-0025/usb_limit_source_enable + chown root system /sys/devices/platform/108d0000.hsi2c/i2c-6/6-0025/update_sdp_enum_timeout chown root graphics /sys/devices/platform/110f0000.drmdp/drm-displayport/dp_hotplug_error_code chown root system /sys/devices/platform/110f0000.drmdp/drm-displayport/hpd chown root system /sys/devices/platform/110f0000.drmdp/drm-displayport/irq_hpd @@ -39,6 +40,7 @@ on post-fs chmod 664 /sys/devices/platform/108d0000.hsi2c/i2c-6/6-0025/usb_limit_sink_current chmod 664 /sys/devices/platform/108d0000.hsi2c/i2c-6/6-0025/usb_limit_sink_enable chmod 664 /sys/devices/platform/108d0000.hsi2c/i2c-6/6-0025/usb_limit_source_enable + chmod 664 /sys/devices/platform/108d0000.hsi2c/i2c-6/6-0025/update_sdp_enum_timeout chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/dp_hotplug_error_code chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/hpd chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/irq_hpd From b171f02f9566a4c0e3a09d647503d876d40fe3f8 Mon Sep 17 00:00:00 2001 From: Amit Sunil Dhamne Date: Fri, 16 Aug 2024 17:48:10 -0700 Subject: [PATCH 2/2] usb: Modify sdp enumeration timeout value in charger mode Write to /sys/class/typec/port<...>/device/update_sdp_enum_timeout to reduce SDP enumeration timeout value when device is in charger mode. This will enable faster detection of a DCP port. Test: Validate (in charger mode) that the sysfs attribute is 1 (meaning lower sdp timeout value is being used). Read dmesg to see print showing timeout value is 5000ms. Bug: 356685367 Flag: EXEMPT bugfix Change-Id: I1bc872911d7f1eab26e62fe6f12fba05608e0f83 (porter from commit 3644ca07e87069fd2bed99f9f1fe13862ad43f62) Signed-off-by: Amit Sunil Dhamne --- conf/init.zumapro.usb.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/init.zumapro.usb.rc b/conf/init.zumapro.usb.rc index ae67506..53d4137 100644 --- a/conf/init.zumapro.usb.rc +++ b/conf/init.zumapro.usb.rc @@ -291,6 +291,7 @@ on property:sys.usb.config=charger && property:sys.usb.configfs=1 write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "midi" symlink /config/usb_gadget/g1/functions/midi.gs5 /config/usb_gadget/g1/configs/b.1/f1 write /config/usb_gadget/g1/UDC ${sys.usb.controller} + write /sys/class/typec/port0/device/update_sdp_enum_timeout 0x1 setprop sys.usb.state ${sys.usb.config} on property:ro.bootmode=usbuwb