summaryrefslogtreecommitdiff
path: root/usb
diff options
context:
space:
mode:
authorJimmy Hu <hhhuuu@google.com>2022-05-25 02:21:54 +0000
committerMichael Bestas <mkbestas@lineageos.org>2022-09-20 01:10:07 +0300
commitd60b7982df1cd82e9b083d41a334da042d5d1352 (patch)
treea42f2a16b7a15cb675ac1654016e0145f012c4b3 /usb
parent2a5b79ad1a9347e00cc8a9fcf34a34cef7889b7a (diff)
Write the pullup value only if new value applied
Also, remove the non-existing paths and set the initial value of mUsbDataEnabled. Bug: 221009551 Test: build, boot Signed-off-by: Jimmy Hu <hhhuuu@google.com> Change-Id: I30033a9dc5e2ccfd1fe1dcc5fe8a7796c56fce75
Diffstat (limited to 'usb')
-rw-r--r--usb/usb/Usb.cpp40
-rw-r--r--usb/usb/Usb.h2
2 files changed, 21 insertions, 21 deletions
diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp
index 218a3d9e..c26caafc 100644
--- a/usb/usb/Usb.cpp
+++ b/usb/usb/Usb.cpp
@@ -57,40 +57,41 @@ ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable,
int64_t in_transactionId) {
bool result = true;
std::vector<PortStatus> currentPortStatus;
+ string pullup;
ALOGI("Userspace turn %s USB data signaling. opID:%ld", in_enable ? "on" : "off",
in_transactionId);
if (in_enable) {
- if (!WriteStringToFile("1", USB_DATA_PATH)) {
- ALOGE("Not able to turn on usb connection notification");
- result = false;
+ if (ReadFileToString(PULLUP_PATH, &pullup)) {
+ pullup = Trim(pullup);
+ if (pullup != kGadgetName) {
+ if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
+ ALOGE("Gadget cannot be pulled up");
+ result = false;
+ }
+ }
}
- if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
- ALOGE("Gadget cannot be pulled up");
+ if (!WriteStringToFile("1", USB_DATA_PATH)) {
+ ALOGE("Not able to turn on usb connection notification");
result = false;
}
} else {
- if (!WriteStringToFile("1", ID_PATH)) {
- ALOGE("Not able to turn off host mode");
- result = false;
- }
-
- if (!WriteStringToFile("0", VBUS_PATH)) {
- ALOGE("Not able to set Vbus state");
- result = false;
+ if (ReadFileToString(PULLUP_PATH, &pullup)) {
+ pullup = Trim(pullup);
+ if (pullup == kGadgetName) {
+ if (!WriteStringToFile("none", PULLUP_PATH)) {
+ ALOGE("Gadget cannot be pulled down");
+ result = false;
+ }
+ }
}
if (!WriteStringToFile("0", USB_DATA_PATH)) {
ALOGE("Not able to turn on usb connection notification");
result = false;
}
-
- if (!WriteStringToFile("none", PULLUP_PATH)) {
- ALOGE("Gadget cannot be pulled down");
- result = false;
- }
}
if (result) {
@@ -322,7 +323,8 @@ Usb::Usb()
: mLock(PTHREAD_MUTEX_INITIALIZER),
mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER),
mPartnerLock(PTHREAD_MUTEX_INITIALIZER),
- mPartnerUp(false) {
+ mPartnerUp(false),
+ mUsbDataEnabled(true) {
pthread_condattr_t attr;
if (pthread_condattr_init(&attr)) {
ALOGE("pthread_condattr_init failed: %s", strerror(errno));
diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h
index 0cd9699a..8f00b886 100644
--- a/usb/usb/Usb.h
+++ b/usb/usb/Usb.h
@@ -43,11 +43,9 @@ using ::std::shared_ptr;
using ::std::string;
constexpr char kGadgetName[] = "a600000.dwc3";
-#define ID_PATH SOC_PATH "id"
#define PULLUP_PATH "/config/usb_gadget/g1/UDC"
#define SOC_PATH "/sys/devices/platform/soc/a600000.ssusb/"
#define USB_DATA_PATH SOC_PATH "usb_data_enabled"
-#define VBUS_PATH SOC_PATH "b_sess"
struct Usb : public BnUsb {
Usb();