Revert "usb: Update Usb and UsbGadget i2c logic"
Revert submission 24855741-gs101-i2c-bus-fixes Reason for revert: DroidMonitor-triggered revert due to breakage https://android-build.corp.google.com/builds/quarterdeck?branch=git_main&target=bluejay-trunk_food-userdebug&lkgb=10876543&lkbb=10876988&fkbb=10876587, bug b/302549624. Reverted changes: /q/submissionid:24855741-gs101-i2c-bus-fixes Change-Id: I63de07348d45bd1a75e73da01f8ee402982cac30 BUG: 302549624
This commit is contained in:
parent
901548943c
commit
dae6f56edd
4 changed files with 84 additions and 220 deletions
|
@ -38,18 +38,38 @@ namespace gadget {
|
||||||
|
|
||||||
string enabledPath;
|
string enabledPath;
|
||||||
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c";
|
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c";
|
||||||
constexpr char kMax77759TcpcDevName[] = "i2c-max77759tcpc";
|
constexpr char kI2CPath[] = "/sys/devices/platform/10d50000.hsi2c/i2c-";
|
||||||
constexpr unsigned int kMax77759TcpcClientId = 0x25;
|
constexpr char kAccessoryLimitCurrent[] = "i2c-max77759tcpc/usb_limit_accessory_current";
|
||||||
constexpr char kAccessoryLimitCurrent[] = "usb_limit_accessory_current";
|
constexpr char kAccessoryLimitCurrentEnable[] = "i2c-max77759tcpc/usb_limit_accessory_enable";
|
||||||
constexpr char kAccessoryLimitCurrentEnable[] = "usb_limit_accessory_enable";
|
constexpr char kUpdateSdpEnumTimeout[] = "i2c-max77759tcpc/update_sdp_enum_timeout";
|
||||||
constexpr char kUpdateSdpEnumTimeout[] = "update_sdp_enum_timeout";
|
|
||||||
|
|
||||||
using ::android::base::GetBoolProperty;
|
using ::android::base::GetBoolProperty;
|
||||||
using ::android::hardware::google::pixel::usb::kUvcEnabled;
|
using ::android::hardware::google::pixel::usb::kUvcEnabled;
|
||||||
|
|
||||||
UsbGadget::UsbGadget() : mGadgetIrqPath(""),
|
Status getI2cBusHelper(string *name) {
|
||||||
mI2cBusNumber(-1),
|
DIR *dp;
|
||||||
mI2cClientPath("") {
|
|
||||||
|
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("") {
|
||||||
if (access(OS_DESC_PATH, R_OK) != 0) {
|
if (access(OS_DESC_PATH, R_OK) != 0) {
|
||||||
ALOGE("configfs setup not done yet");
|
ALOGE("configfs setup not done yet");
|
||||||
abort();
|
abort();
|
||||||
|
@ -369,16 +389,14 @@ ScopedAStatus UsbGadget::reset(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsbGadget::updateSdpEnumTimeout() {
|
void UsbGadget::updateSdpEnumTimeout() {
|
||||||
string update_sdp_enum_timeout_path;
|
string i2c_node, update_sdp_enum_timeout_path;
|
||||||
std::string_view i2cPath;
|
|
||||||
|
|
||||||
i2cPath = getI2cClientPath();
|
Status status = getI2cBusHelper(&i2c_node);
|
||||||
if (i2cPath.empty()) {
|
if (status != Status::SUCCESS) {
|
||||||
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update_sdp_enum_timeout_path = std::string{i2cPath} + "/" + kUpdateSdpEnumTimeout;
|
update_sdp_enum_timeout_path = kI2CPath + i2c_node + "/" + kUpdateSdpEnumTimeout;
|
||||||
if (!WriteStringToFile("1", update_sdp_enum_timeout_path)) {
|
if (!WriteStringToFile("1", update_sdp_enum_timeout_path)) {
|
||||||
ALOGE("%s: Unable to write to %s.", __func__, update_sdp_enum_timeout_path.c_str());
|
ALOGE("%s: Unable to write to %s.", __func__, update_sdp_enum_timeout_path.c_str());
|
||||||
} else {
|
} else {
|
||||||
|
@ -465,75 +483,6 @@ Status UsbGadget::setupFunctions(long functions,
|
||||||
return Status::SUCCESS;
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UsbGadget::getI2cBusNumber() {
|
|
||||||
DIR *dp;
|
|
||||||
unsigned int busNumber;
|
|
||||||
|
|
||||||
// Since the i2c bus number doesn't change after boot, we only need to get
|
|
||||||
// it once.
|
|
||||||
if (mI2cBusNumber >= 0) {
|
|
||||||
return mI2cBusNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
dp = opendir(kHsi2cPath);
|
|
||||||
if (dp != NULL) {
|
|
||||||
struct dirent *ep;
|
|
||||||
|
|
||||||
while ((ep = readdir(dp))) {
|
|
||||||
if (ep->d_type == DT_DIR) {
|
|
||||||
if (sscanf(ep->d_name, "i2c-%u", &busNumber) == 1) {
|
|
||||||
mI2cBusNumber = busNumber;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mI2cBusNumber < 0) {
|
|
||||||
ALOGE("Failed to open %s", kHsi2cPath);
|
|
||||||
}
|
|
||||||
return mI2cBusNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string_view UsbGadget::getI2cClientPath() {
|
|
||||||
DIR *dp;
|
|
||||||
char i2cClientPathLabeled[PATH_MAX];
|
|
||||||
char i2cClientPathUnLabeled[PATH_MAX];
|
|
||||||
|
|
||||||
// Since the I2C client path doesn't change after boot, we only need to get
|
|
||||||
// it once.
|
|
||||||
if (!mI2cClientPath.empty()) {
|
|
||||||
return mI2cClientPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getI2cBusNumber() < 0) {
|
|
||||||
return std::string_view{""};
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(i2cClientPathLabeled, sizeof(i2cClientPathLabeled),
|
|
||||||
"%s/i2c-%d/%s", kHsi2cPath, mI2cBusNumber, kMax77759TcpcDevName);
|
|
||||||
snprintf(i2cClientPathUnLabeled, sizeof(i2cClientPathUnLabeled),
|
|
||||||
"%s/i2c-%d/%d-%04x", kHsi2cPath, mI2cBusNumber, mI2cBusNumber,
|
|
||||||
kMax77759TcpcClientId);
|
|
||||||
|
|
||||||
dp = opendir(i2cClientPathLabeled);
|
|
||||||
if (dp != NULL) {
|
|
||||||
mI2cClientPath.assign(i2cClientPathLabeled);
|
|
||||||
closedir(dp);
|
|
||||||
return mI2cClientPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
dp = opendir(i2cClientPathUnLabeled);
|
|
||||||
if (dp != NULL) {
|
|
||||||
mI2cClientPath.assign(i2cClientPathUnLabeled);
|
|
||||||
closedir(dp);
|
|
||||||
return mI2cClientPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALOGE("Failed to find the i2c client path under %s", kHsi2cPath);
|
|
||||||
return std::string_view{""};
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
|
ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
|
||||||
const shared_ptr<IUsbGadgetCallback> &callback,
|
const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
|
@ -543,19 +492,14 @@ ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
|
||||||
std::string current_usb_power_operation_mode, current_usb_type;
|
std::string current_usb_power_operation_mode, current_usb_type;
|
||||||
std::string usb_limit_sink_enable;
|
std::string usb_limit_sink_enable;
|
||||||
|
|
||||||
string accessoryCurrentLimitEnablePath, accessoryCurrentLimitPath;
|
string accessoryCurrentLimitEnablePath, accessoryCurrentLimitPath, path;
|
||||||
std::string_view i2cPath;
|
|
||||||
|
|
||||||
mCurrentUsbFunctions = functions;
|
mCurrentUsbFunctions = functions;
|
||||||
mCurrentUsbFunctionsApplied = false;
|
mCurrentUsbFunctionsApplied = false;
|
||||||
|
|
||||||
i2cPath = getI2cClientPath();
|
getI2cBusHelper(&path);
|
||||||
if (!i2cPath.empty()) {
|
accessoryCurrentLimitPath = kI2CPath + path + "/" + kAccessoryLimitCurrent;
|
||||||
accessoryCurrentLimitPath = std::string{i2cPath} + "/" + kAccessoryLimitCurrent;
|
accessoryCurrentLimitEnablePath = kI2CPath + path + "/" + kAccessoryLimitCurrentEnable;
|
||||||
accessoryCurrentLimitEnablePath = std::string{i2cPath} + "/" + kAccessoryLimitCurrentEnable;
|
|
||||||
} else {
|
|
||||||
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the gadget IRQ number before tearDownGadget()
|
// Get the gadget IRQ number before tearDownGadget()
|
||||||
if (mGadgetIrqPath.empty())
|
if (mGadgetIrqPath.empty())
|
||||||
|
@ -616,17 +560,15 @@ ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
|
||||||
current_usb_type == "Unknown SDP [CDP] DCP" &&
|
current_usb_type == "Unknown SDP [CDP] DCP" &&
|
||||||
(current_usb_power_operation_mode == "default" ||
|
(current_usb_power_operation_mode == "default" ||
|
||||||
current_usb_power_operation_mode == "1.5A")) {
|
current_usb_power_operation_mode == "1.5A")) {
|
||||||
if (accessoryCurrentLimitPath.empty() || !WriteStringToFile("1300000", accessoryCurrentLimitPath)) {
|
if (!WriteStringToFile("1300000", accessoryCurrentLimitPath)) {
|
||||||
ALOGI("Write 1.3A to limit current fail");
|
ALOGI("Write 1.3A to limit current fail");
|
||||||
} else {
|
} else {
|
||||||
if (accessoryCurrentLimitEnablePath.empty() ||
|
if (!WriteStringToFile("1", accessoryCurrentLimitEnablePath)) {
|
||||||
!WriteStringToFile("1", accessoryCurrentLimitEnablePath)) {
|
|
||||||
ALOGI("Enable limit current fail");
|
ALOGI("Enable limit current fail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (accessoryCurrentLimitEnablePath.empty() ||
|
if (!WriteStringToFile("0", accessoryCurrentLimitEnablePath))
|
||||||
!WriteStringToFile("0", accessoryCurrentLimitEnablePath))
|
|
||||||
ALOGI("unvote accessory limit current failed");
|
ALOGI("unvote accessory limit current failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,12 +119,7 @@ struct UsbGadget : public BnUsbGadget {
|
||||||
// set SDP timeout to a lower value.
|
// set SDP timeout to a lower value.
|
||||||
void updateSdpEnumTimeout();
|
void updateSdpEnumTimeout();
|
||||||
|
|
||||||
int getI2cBusNumber();
|
|
||||||
std::string_view getI2cClientPath();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mI2cBusNumber;
|
|
||||||
std::string mI2cClientPath;
|
|
||||||
Status tearDownGadget();
|
Status tearDownGadget();
|
||||||
Status getUsbGadgetIrqPath();
|
Status getUsbGadgetIrqPath();
|
||||||
Status setupFunctions(long functions, const shared_ptr<IUsbGadgetCallback> &callback,
|
Status setupFunctions(long functions, const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
|
|
159
usb/usb/Usb.cpp
159
usb/usb/Usb.cpp
|
@ -59,18 +59,17 @@ volatile bool destroyThread;
|
||||||
|
|
||||||
string enabledPath;
|
string enabledPath;
|
||||||
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c";
|
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c";
|
||||||
|
constexpr char kI2CPath[] = "/sys/devices/platform/10d50000.hsi2c/i2c-";
|
||||||
constexpr char kComplianceWarningsPath[] = "device/non_compliant_reasons";
|
constexpr char kComplianceWarningsPath[] = "device/non_compliant_reasons";
|
||||||
constexpr char kComplianceWarningBC12[] = "bc12";
|
constexpr char kComplianceWarningBC12[] = "bc12";
|
||||||
constexpr char kComplianceWarningDebugAccessory[] = "debug-accessory";
|
constexpr char kComplianceWarningDebugAccessory[] = "debug-accessory";
|
||||||
constexpr char kComplianceWarningMissingRp[] = "missing_rp";
|
constexpr char kComplianceWarningMissingRp[] = "missing_rp";
|
||||||
constexpr char kComplianceWarningOther[] = "other";
|
constexpr char kComplianceWarningOther[] = "other";
|
||||||
constexpr char kMax77759TcpcDevName[] = "i2c-max77759tcpc";
|
constexpr char kContaminantDetectionPath[] = "i2c-max77759tcpc/contaminant_detection";
|
||||||
constexpr unsigned int kMax77759TcpcClientId = 0x25;
|
constexpr char kStatusPath[] = "i2c-max77759tcpc/contaminant_detection_status";
|
||||||
constexpr char kContaminantDetectionPath[] = "contaminant_detection";
|
constexpr char kSinkLimitEnable[] = "i2c-max77759tcpc/usb_limit_sink_enable";
|
||||||
constexpr char kStatusPath[] = "contaminant_detection_status";
|
constexpr char kSourceLimitEnable[] = "i2c-max77759tcpc/usb_limit_source_enable";
|
||||||
constexpr char kSinkLimitEnable[] = "usb_limit_sink_enable";
|
constexpr char kSinkLimitCurrent[] = "i2c-max77759tcpc/usb_limit_sink_current";
|
||||||
constexpr char kSourceLimitEnable[] = "usb_limit_source_enable";
|
|
||||||
constexpr char kSinkLimitCurrent[] = "usb_limit_sink_current";
|
|
||||||
constexpr char kTypecPath[] = "/sys/class/typec";
|
constexpr char kTypecPath[] = "/sys/class/typec";
|
||||||
constexpr char kDisableContatminantDetection[] = "vendor.usb.contaminantdisable";
|
constexpr char kDisableContatminantDetection[] = "vendor.usb.contaminantdisable";
|
||||||
constexpr char kOverheatStatsPath[] = "/sys/devices/platform/google,usbc_port_cooling_dev/";
|
constexpr char kOverheatStatsPath[] = "/sys/devices/platform/google,usbc_port_cooling_dev/";
|
||||||
|
@ -221,15 +220,8 @@ ScopedAStatus Usb::resetUsbPort(const std::string& in_portName, int64_t in_trans
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Usb::getI2cBusNumber() {
|
Status getI2cBusHelper(string *name) {
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
unsigned int busNumber;
|
|
||||||
|
|
||||||
// Since the i2c bus number doesn't change after boot, we only need to get
|
|
||||||
// it once.
|
|
||||||
if (mI2cBusNumber >= 0) {
|
|
||||||
return mI2cBusNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
dp = opendir(kHsi2cPath);
|
dp = opendir(kHsi2cPath);
|
||||||
if (dp != NULL) {
|
if (dp != NULL) {
|
||||||
|
@ -237,65 +229,22 @@ int Usb::getI2cBusNumber() {
|
||||||
|
|
||||||
while ((ep = readdir(dp))) {
|
while ((ep = readdir(dp))) {
|
||||||
if (ep->d_type == DT_DIR) {
|
if (ep->d_type == DT_DIR) {
|
||||||
if (sscanf(ep->d_name, "i2c-%u", &busNumber) == 1) {
|
if (string::npos != string(ep->d_name).find("i2c-")) {
|
||||||
mI2cBusNumber = busNumber;
|
std::strtok(ep->d_name, "-");
|
||||||
break;
|
*name = std::strtok(NULL, "-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
|
return Status::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mI2cBusNumber < 0) {
|
ALOGE("Failed to open %s", kHsi2cPath);
|
||||||
ALOGE("Failed to open %s", kHsi2cPath);
|
return Status::ERROR;
|
||||||
}
|
|
||||||
return mI2cBusNumber;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view Usb::getI2cClientPath() {
|
Status queryMoistureDetectionStatus(std::vector<PortStatus> *currentPortStatus) {
|
||||||
DIR *dp;
|
string enabled, status, path, DetectedPath;
|
||||||
char i2cClientPathLabeled[PATH_MAX];
|
|
||||||
char i2cClientPathUnLabeled[PATH_MAX];
|
|
||||||
|
|
||||||
// Since the I2C client path doesn't change after boot, we only need to get
|
|
||||||
// it once.
|
|
||||||
if (!mI2cClientPath.empty()) {
|
|
||||||
return mI2cClientPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getI2cBusNumber() < 0) {
|
|
||||||
return std::string_view{""};
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(i2cClientPathLabeled, sizeof(i2cClientPathLabeled),
|
|
||||||
"%s/i2c-%d/%s", kHsi2cPath, mI2cBusNumber, kMax77759TcpcDevName);
|
|
||||||
snprintf(i2cClientPathUnLabeled, sizeof(i2cClientPathUnLabeled),
|
|
||||||
"%s/i2c-%d/%d-%04x", kHsi2cPath, mI2cBusNumber, mI2cBusNumber,
|
|
||||||
kMax77759TcpcClientId);
|
|
||||||
|
|
||||||
dp = opendir(i2cClientPathLabeled);
|
|
||||||
if (dp != NULL) {
|
|
||||||
mI2cClientPath.assign(i2cClientPathLabeled);
|
|
||||||
closedir(dp);
|
|
||||||
return mI2cClientPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
dp = opendir(i2cClientPathUnLabeled);
|
|
||||||
if (dp != NULL) {
|
|
||||||
mI2cClientPath.assign(i2cClientPathUnLabeled);
|
|
||||||
closedir(dp);
|
|
||||||
return mI2cClientPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALOGE("Failed to find the i2c client path under %s", kHsi2cPath);
|
|
||||||
return std::string_view{""};
|
|
||||||
}
|
|
||||||
|
|
||||||
Status queryMoistureDetectionStatus(android::hardware::usb::Usb *usb,
|
|
||||||
std::vector<PortStatus> *currentPortStatus)
|
|
||||||
{
|
|
||||||
string enabled, status, DetectedPath;
|
|
||||||
std::string_view i2cPath;
|
|
||||||
|
|
||||||
(*currentPortStatus)[0].supportedContaminantProtectionModes
|
(*currentPortStatus)[0].supportedContaminantProtectionModes
|
||||||
.push_back(ContaminantProtectionMode::FORCE_DISABLE);
|
.push_back(ContaminantProtectionMode::FORCE_DISABLE);
|
||||||
|
@ -304,12 +253,8 @@ Status queryMoistureDetectionStatus(android::hardware::usb::Usb *usb,
|
||||||
(*currentPortStatus)[0].supportsEnableContaminantPresenceDetection = true;
|
(*currentPortStatus)[0].supportsEnableContaminantPresenceDetection = true;
|
||||||
(*currentPortStatus)[0].supportsEnableContaminantPresenceProtection = false;
|
(*currentPortStatus)[0].supportsEnableContaminantPresenceProtection = false;
|
||||||
|
|
||||||
i2cPath = usb->getI2cClientPath();
|
getI2cBusHelper(&path);
|
||||||
if (i2cPath.empty()) {
|
enabledPath = kI2CPath + path + "/" + kContaminantDetectionPath;
|
||||||
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
|
||||||
return Status::ERROR;
|
|
||||||
}
|
|
||||||
enabledPath = std::string{i2cPath} + "/" + kContaminantDetectionPath;
|
|
||||||
if (!ReadFileToString(enabledPath, &enabled)) {
|
if (!ReadFileToString(enabledPath, &enabled)) {
|
||||||
ALOGE("Failed to open moisture_detection_enabled");
|
ALOGE("Failed to open moisture_detection_enabled");
|
||||||
return Status::ERROR;
|
return Status::ERROR;
|
||||||
|
@ -317,7 +262,7 @@ Status queryMoistureDetectionStatus(android::hardware::usb::Usb *usb,
|
||||||
|
|
||||||
enabled = Trim(enabled);
|
enabled = Trim(enabled);
|
||||||
if (enabled == "1") {
|
if (enabled == "1") {
|
||||||
DetectedPath = std::string{i2cPath} + "/" + kStatusPath;
|
DetectedPath = kI2CPath + path + "/" + kStatusPath;
|
||||||
if (!ReadFileToString(DetectedPath, &status)) {
|
if (!ReadFileToString(DetectedPath, &status)) {
|
||||||
ALOGE("Failed to open moisture_detected");
|
ALOGE("Failed to open moisture_detected");
|
||||||
return Status::ERROR;
|
return Status::ERROR;
|
||||||
|
@ -515,9 +460,7 @@ Usb::Usb()
|
||||||
ThrottlingSeverity::NONE),
|
ThrottlingSeverity::NONE),
|
||||||
ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadSecondary2,
|
ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadSecondary2,
|
||||||
ThrottlingSeverity::NONE)}, kSamplingIntervalSec),
|
ThrottlingSeverity::NONE)}, kSamplingIntervalSec),
|
||||||
mUsbDataEnabled(true),
|
mUsbDataEnabled(true) {
|
||||||
mI2cBusNumber(-1),
|
|
||||||
mI2cClientPath("") {
|
|
||||||
pthread_condattr_t attr;
|
pthread_condattr_t attr;
|
||||||
if (pthread_condattr_init(&attr)) {
|
if (pthread_condattr_init(&attr)) {
|
||||||
ALOGE("pthread_condattr_init failed: %s", strerror(errno));
|
ALOGE("pthread_condattr_init failed: %s", strerror(errno));
|
||||||
|
@ -596,38 +539,32 @@ ScopedAStatus Usb::limitPowerTransfer(const string& in_portName, bool in_limit,
|
||||||
int64_t in_transactionId) {
|
int64_t in_transactionId) {
|
||||||
bool sessionFail = false, success;
|
bool sessionFail = false, success;
|
||||||
std::vector<PortStatus> currentPortStatus;
|
std::vector<PortStatus> currentPortStatus;
|
||||||
string sinkLimitEnablePath, currentLimitPath, sourceLimitEnablePath;
|
string path, sinkLimitEnablePath, currentLimitPath, sourceLimitEnablePath;
|
||||||
std::string_view i2cPath;
|
|
||||||
|
getI2cBusHelper(&path);
|
||||||
|
sinkLimitEnablePath = kI2CPath + path + "/" + kSinkLimitEnable;
|
||||||
|
sourceLimitEnablePath = kI2CPath + path + "/" + kSourceLimitEnable;
|
||||||
|
currentLimitPath = kI2CPath + path + "/" + kSinkLimitCurrent;
|
||||||
|
|
||||||
pthread_mutex_lock(&mLock);
|
pthread_mutex_lock(&mLock);
|
||||||
i2cPath = getI2cClientPath();
|
if (in_limit) {
|
||||||
if (!i2cPath.empty()) {
|
success = WriteStringToFile("0", currentLimitPath);
|
||||||
sinkLimitEnablePath = std::string{i2cPath} + "/" + kSinkLimitEnable;
|
|
||||||
sourceLimitEnablePath = std::string{i2cPath} + "/" + kSourceLimitEnable;
|
|
||||||
currentLimitPath = std::string{i2cPath} + "/" + kSinkLimitCurrent;
|
|
||||||
|
|
||||||
if (in_limit) {
|
|
||||||
success = WriteStringToFile("0", currentLimitPath);
|
|
||||||
if (!success) {
|
|
||||||
ALOGE("Failed to set sink current limit");
|
|
||||||
sessionFail = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
success = WriteStringToFile(in_limit ? "1" : "0", sinkLimitEnablePath);
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
ALOGE("Failed to %s sink current limit: %s", in_limit ? "enable" : "disable",
|
ALOGE("Failed to set sink current limit");
|
||||||
sinkLimitEnablePath.c_str());
|
|
||||||
sessionFail = true;
|
sessionFail = true;
|
||||||
}
|
}
|
||||||
success = WriteStringToFile(in_limit ? "1" : "0", sourceLimitEnablePath);
|
}
|
||||||
if (!success) {
|
success = WriteStringToFile(in_limit ? "1" : "0", sinkLimitEnablePath);
|
||||||
ALOGE("Failed to %s source current limit: %s", in_limit ? "enable" : "disable",
|
if (!success) {
|
||||||
sourceLimitEnablePath.c_str());
|
ALOGE("Failed to %s sink current limit: %s", in_limit ? "enable" : "disable",
|
||||||
sessionFail = true;
|
sinkLimitEnablePath.c_str());
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sessionFail = true;
|
sessionFail = true;
|
||||||
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
}
|
||||||
|
success = WriteStringToFile(in_limit ? "1" : "0", sourceLimitEnablePath);
|
||||||
|
if (!success) {
|
||||||
|
ALOGE("Failed to %s source current limit: %s", in_limit ? "enable" : "disable",
|
||||||
|
sourceLimitEnablePath.c_str());
|
||||||
|
sessionFail = true;
|
||||||
}
|
}
|
||||||
ALOGI("limitPowerTransfer limit:%c opId:%ld", in_limit ? 'y' : 'n', in_transactionId);
|
ALOGI("limitPowerTransfer limit:%c opId:%ld", in_limit ? 'y' : 'n', in_transactionId);
|
||||||
if (mCallback != NULL && in_transactionId >= 0) {
|
if (mCallback != NULL && in_transactionId >= 0) {
|
||||||
|
@ -646,17 +583,11 @@ ScopedAStatus Usb::limitPowerTransfer(const string& in_portName, bool in_limit,
|
||||||
return ScopedAStatus::ok();
|
return ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status queryPowerTransferStatus(android::hardware::usb::Usb *usb,
|
Status queryPowerTransferStatus(std::vector<PortStatus> *currentPortStatus) {
|
||||||
std::vector<PortStatus> *currentPortStatus) {
|
string limitedPath, enabled, path;
|
||||||
string limitedPath, enabled;
|
|
||||||
std::string_view i2cPath;
|
|
||||||
|
|
||||||
i2cPath = usb->getI2cClientPath();
|
getI2cBusHelper(&path);
|
||||||
if (i2cPath.empty()) {
|
limitedPath = kI2CPath + path + "/" + kSinkLimitEnable;
|
||||||
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
|
||||||
return Status::ERROR;
|
|
||||||
}
|
|
||||||
limitedPath = std::string{i2cPath} + "/" + kSinkLimitEnable;
|
|
||||||
if (!ReadFileToString(limitedPath, &enabled)) {
|
if (!ReadFileToString(limitedPath, &enabled)) {
|
||||||
ALOGE("Failed to open limit_sink_enable");
|
ALOGE("Failed to open limit_sink_enable");
|
||||||
return Status::ERROR;
|
return Status::ERROR;
|
||||||
|
@ -892,8 +823,8 @@ void queryVersionHelper(android::hardware::usb::Usb *usb,
|
||||||
Status status;
|
Status status;
|
||||||
pthread_mutex_lock(&usb->mLock);
|
pthread_mutex_lock(&usb->mLock);
|
||||||
status = getPortStatusHelper(usb, currentPortStatus);
|
status = getPortStatusHelper(usb, currentPortStatus);
|
||||||
queryMoistureDetectionStatus(usb, currentPortStatus);
|
queryMoistureDetectionStatus(currentPortStatus);
|
||||||
queryPowerTransferStatus(usb, currentPortStatus);
|
queryPowerTransferStatus(currentPortStatus);
|
||||||
queryNonCompliantChargerStatus(currentPortStatus);
|
queryNonCompliantChargerStatus(currentPortStatus);
|
||||||
if (usb->mCallback != NULL) {
|
if (usb->mCallback != NULL) {
|
||||||
ScopedAStatus ret = usb->mCallback->notifyPortStatusChange(*currentPortStatus,
|
ScopedAStatus ret = usb->mCallback->notifyPortStatusChange(*currentPortStatus,
|
||||||
|
|
|
@ -111,13 +111,9 @@ struct Usb : public BnUsb {
|
||||||
std::function<void(uint32_t)> cb;
|
std::function<void(uint32_t)> cb;
|
||||||
};
|
};
|
||||||
std::map<std::string, struct epollEntry> mEpollEntries;
|
std::map<std::string, struct epollEntry> mEpollEntries;
|
||||||
int getI2cBusNumber();
|
|
||||||
std::string_view getI2cClientPath();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pthread_t mPoll;
|
pthread_t mPoll;
|
||||||
int mI2cBusNumber;
|
|
||||||
std::string mI2cClientPath;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace usb
|
} // namespace usb
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue