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:275687235 Test: Check `update_sdp_enum_timeout` is written into after usb gadget is pulled up. Verify that the alarm timeout lowers. Change-Id: Id3ae7e7a20b236cec6604414a7f81860e868bdd0 Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
This commit is contained in:
parent
3644ca07e8
commit
d8e2a02998
3 changed files with 66 additions and 23 deletions
|
@ -44,6 +44,30 @@ constexpr char kHsi2cPath[] = "/sys/devices/platform/10d60000.hsi2c";
|
||||||
constexpr char kI2CPath[] = "/sys/devices/platform/10d60000.hsi2c/i2c-";
|
constexpr char kI2CPath[] = "/sys/devices/platform/10d60000.hsi2c/i2c-";
|
||||||
constexpr char kAccessoryLimitCurrent[] = "i2c-max77759tcpc/usb_limit_accessory_current";
|
constexpr char kAccessoryLimitCurrent[] = "i2c-max77759tcpc/usb_limit_accessory_current";
|
||||||
constexpr char kAccessoryLimitCurrentEnable[] = "i2c-max77759tcpc/usb_limit_accessory_enable";
|
constexpr char kAccessoryLimitCurrentEnable[] = "i2c-max77759tcpc/usb_limit_accessory_enable";
|
||||||
|
constexpr char kUpdateSdpEnumTimeout[] = "i2c-max77759tcpc/update_sdp_enum_timeout";
|
||||||
|
|
||||||
|
Status getI2cBusHelper(string *name) {
|
||||||
|
DIR *dp;
|
||||||
|
|
||||||
|
dp = opendir(kHsi2cPath);
|
||||||
|
if (dp != NULL) {
|
||||||
|
struct dirent *ep;
|
||||||
|
|
||||||
|
while ((ep = readdir(dp))) {
|
||||||
|
if (ep->d_type == DT_DIR) {
|
||||||
|
if (string::npos != string(ep->d_name).find("i2c-")) {
|
||||||
|
std::strtok(ep->d_name, "-");
|
||||||
|
*name = std::strtok(NULL, "-");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dp);
|
||||||
|
return Status::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALOGE("Failed to open %s", kHsi2cPath);
|
||||||
|
return Status::ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
UsbGadget::UsbGadget() : mGadgetIrqPath("") {
|
UsbGadget::UsbGadget() : mGadgetIrqPath("") {
|
||||||
if (access(OS_DESC_PATH, R_OK) != 0) {
|
if (access(OS_DESC_PATH, R_OK) != 0) {
|
||||||
|
@ -97,6 +121,7 @@ Status UsbGadget::getUsbGadgetIrqPath() {
|
||||||
void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) {
|
void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) {
|
||||||
UsbGadget *gadget = (UsbGadget *)payload;
|
UsbGadget *gadget = (UsbGadget *)payload;
|
||||||
gadget->mCurrentUsbFunctionsApplied = functionsApplied;
|
gadget->mCurrentUsbFunctionsApplied = functionsApplied;
|
||||||
|
gadget->updateSdpEnumTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
|
ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
|
@ -363,6 +388,22 @@ ScopedAStatus UsbGadget::reset(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
return ScopedAStatus::ok();
|
return ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UsbGadget::updateSdpEnumTimeout() {
|
||||||
|
string i2c_node, update_sdp_enum_timeout_path;
|
||||||
|
|
||||||
|
Status status = getI2cBusHelper(&i2c_node);
|
||||||
|
if (status != Status::SUCCESS) {
|
||||||
|
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
||||||
|
}
|
||||||
|
|
||||||
|
update_sdp_enum_timeout_path = kI2CPath + i2c_node + "/" + 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,
|
Status UsbGadget::setupFunctions(long functions,
|
||||||
const shared_ptr<IUsbGadgetCallback> &callback, uint64_t timeout,
|
const shared_ptr<IUsbGadgetCallback> &callback, uint64_t timeout,
|
||||||
int64_t in_transactionId) {
|
int64_t in_transactionId) {
|
||||||
|
@ -421,6 +462,7 @@ Status UsbGadget::setupFunctions(long functions,
|
||||||
mCurrentUsbFunctionsApplied = true;
|
mCurrentUsbFunctionsApplied = true;
|
||||||
if (callback)
|
if (callback)
|
||||||
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
|
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
|
||||||
|
updateSdpEnumTimeout();
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,29 +487,6 @@ Status UsbGadget::setupFunctions(long functions,
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status getI2cBusHelper(string *name) {
|
|
||||||
DIR *dp;
|
|
||||||
|
|
||||||
dp = opendir(kHsi2cPath);
|
|
||||||
if (dp != NULL) {
|
|
||||||
struct dirent *ep;
|
|
||||||
|
|
||||||
while ((ep = readdir(dp))) {
|
|
||||||
if (ep->d_type == DT_DIR) {
|
|
||||||
if (string::npos != string(ep->d_name).find("i2c-")) {
|
|
||||||
std::strtok(ep->d_name, "-");
|
|
||||||
*name = std::strtok(NULL, "-");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dp);
|
|
||||||
return Status::SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALOGE("Failed to open %s", kHsi2cPath);
|
|
||||||
return Status::ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
|
ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
|
||||||
const shared_ptr<IUsbGadgetCallback> &callback,
|
const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
int64_t timeout,
|
int64_t timeout,
|
||||||
|
|
|
@ -115,6 +115,10 @@ struct UsbGadget : public BnUsbGadget {
|
||||||
|
|
||||||
ScopedAStatus setVidPid(const char *vid,const char *pid);
|
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();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Status tearDownGadget();
|
Status tearDownGadget();
|
||||||
Status getUsbGadgetIrqPath();
|
Status getUsbGadgetIrqPath();
|
||||||
|
|
|
@ -68,6 +68,16 @@ on post-fs
|
||||||
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_source_enable
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_source_enable
|
||||||
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-8/i2c-max77759tcpc/usb_limit_source_enable
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-8/i2c-max77759tcpc/usb_limit_source_enable
|
||||||
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-9/i2c-max77759tcpc/usb_limit_source_enable
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-9/i2c-max77759tcpc/usb_limit_source_enable
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-0/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-1/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-2/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-3/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-4/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-5/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-6/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-7/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-8/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chown root system /sys/devices/platform/10d60000.hsi2c/i2c-9/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
chmod 664 /sys/class/typec/port0/power_role
|
chmod 664 /sys/class/typec/port0/power_role
|
||||||
chmod 664 /sys/class/typec/port0/data_role
|
chmod 664 /sys/class/typec/port0/data_role
|
||||||
chmod 664 /sys/class/typec/port0/port_type
|
chmod 664 /sys/class/typec/port0/port_type
|
||||||
|
@ -131,3 +141,13 @@ on post-fs
|
||||||
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_source_enable
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_source_enable
|
||||||
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-8/i2c-max77759tcpc/usb_limit_source_enable
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-8/i2c-max77759tcpc/usb_limit_source_enable
|
||||||
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-9/i2c-max77759tcpc/usb_limit_source_enable
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-9/i2c-max77759tcpc/usb_limit_source_enable
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-0/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-1/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-2/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-3/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-4/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-5/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-6/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-7/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-8/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
chmod 664 /sys/devices/platform/10d60000.hsi2c/i2c-9/i2c-max77759tcpc/update_sdp_enum_timeout
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue