Skip to content

Commit

Permalink
Merge "Write the pullup value only if new value applied" into tm-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Wang authored and Android (Google) Code Review committed May 26, 2022
2 parents fd09ee9 + 2331d8b commit d8fc93a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
45 changes: 23 additions & 22 deletions usb/usb/Usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,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) {
Expand Down Expand Up @@ -367,7 +368,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));
Expand Down Expand Up @@ -612,7 +614,7 @@ Status getPortStatusHelper(android::hardware::usb::Usb *usb,
} else {
(*currentPortStatus)[i].usbDataStatus.push_back(UsbDataStatus::ENABLED);
}
(*currentPortStatus)[i].powerBrickStatus = PowerBrickStatus::UNKNOWN;
(*currentPortStatus)[i].powerBrickStatus = PowerBrickStatus::UNKNOWN;

ALOGI("%d:%s connected:%d canChangeMode:%d canChagedata:%d canChangePower:%d "
"usbDataEnabled:%d",
Expand All @@ -627,6 +629,7 @@ Status getPortStatusHelper(android::hardware::usb::Usb *usb,
done:
return Status::ERROR;
}

Status queryPowerTransferStatus(std::vector<PortStatus> *currentPortStatus) {
string enabled;

Expand Down Expand Up @@ -731,8 +734,6 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
pthread_cond_signal(&payload->usb->mPartnerCV);
pthread_mutex_unlock(&payload->usb->mPartnerLock);
} else if (!strncmp(cp, "DEVTYPE=typec_", strlen("DEVTYPE=typec_")) ||
!strncmp(cp, "DRIVER=max77759tcpc",
strlen("DRIVER=max77759tcpc")) ||
!strncmp(cp, "POWER_SUPPLY_MOISTURE_DETECTED",
strlen("POWER_SUPPLY_MOISTURE_DETECTED"))) {
std::vector<PortStatus> currentPortStatus;
Expand Down
2 changes: 0 additions & 2 deletions usb/usb/Usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

#define USB_POWER_LIMIT_PATH "/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-00/c440000.qcom,spmi:qcom,pm6150@0:qcom,usb-pdphy@1700/usbpd0/"
#define SINK_CURRENT_LIMIT_PATH USB_POWER_LIMIT_PATH "usb_limit_sink_current"
Expand Down

0 comments on commit d8fc93a

Please sign in to comment.