usb: Runtime search the i2c path
The paths of sysfs nodes are different on multiple build targets and are also different between the old kernel (5.10) and newer kernel (6.1). Since usb HAL code is shared by those targets and different kernel versions, Runtime search the correct paths. Bug: 317946158 Change-Id: I676455145232fd71db1578bb7a9801fed7bb327f Signed-off-by: Kyle Tso <kyletso@google.com>
This commit is contained in:
parent
7d2aafad34
commit
9bafd5f134
4 changed files with 79 additions and 86 deletions
|
@ -17,7 +17,6 @@
|
||||||
#define LOG_TAG "android.hardware.usb.gadget.aidl-service"
|
#define LOG_TAG "android.hardware.usb.gadget.aidl-service"
|
||||||
|
|
||||||
#include "UsbGadget.h"
|
#include "UsbGadget.h"
|
||||||
#include <dirent.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
|
@ -29,6 +28,7 @@
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
|
|
||||||
#include <aidl/android/frameworks/stats/IStats.h>
|
#include <aidl/android/frameworks/stats/IStats.h>
|
||||||
|
#include <pixelusb/I2cHelper.h>
|
||||||
|
|
||||||
namespace aidl {
|
namespace aidl {
|
||||||
namespace android {
|
namespace android {
|
||||||
|
@ -37,39 +37,19 @@ namespace usb {
|
||||||
namespace gadget {
|
namespace gadget {
|
||||||
|
|
||||||
using ::android::base::GetBoolProperty;
|
using ::android::base::GetBoolProperty;
|
||||||
|
using ::android::hardware::google::pixel::usb::getI2cClientPath;
|
||||||
using ::android::hardware::google::pixel::usb::kUvcEnabled;
|
using ::android::hardware::google::pixel::usb::kUvcEnabled;
|
||||||
|
|
||||||
string enabledPath;
|
string enabledPath;
|
||||||
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d60000.hsi2c";
|
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d60000.hsi2c";
|
||||||
constexpr char kI2CPath[] = "/sys/devices/platform/10d60000.hsi2c/i2c-";
|
constexpr char kTcpcDevName[] = "i2c-max77759tcpc";
|
||||||
constexpr char kAccessoryLimitCurrent[] = "i2c-max77759tcpc/usb_limit_accessory_current";
|
constexpr char kI2cClientId[] = "0025";
|
||||||
constexpr char kAccessoryLimitCurrentEnable[] = "i2c-max77759tcpc/usb_limit_accessory_enable";
|
constexpr char kAccessoryLimitCurrent[] = "usb_limit_accessory_current";
|
||||||
constexpr char kUpdateSdpEnumTimeout[] = "i2c-max77759tcpc/update_sdp_enum_timeout";
|
constexpr char kAccessoryLimitCurrentEnable[] = "usb_limit_accessory_enable";
|
||||||
|
constexpr char kUpdateSdpEnumTimeout[] = "update_sdp_enum_timeout";
|
||||||
|
|
||||||
Status getI2cBusHelper(string *name) {
|
UsbGadget::UsbGadget() : mGadgetIrqPath(""),
|
||||||
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();
|
||||||
|
@ -389,14 +369,16 @@ ScopedAStatus UsbGadget::reset(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsbGadget::updateSdpEnumTimeout() {
|
void UsbGadget::updateSdpEnumTimeout() {
|
||||||
string i2c_node, update_sdp_enum_timeout_path;
|
string update_sdp_enum_timeout_path;
|
||||||
|
|
||||||
Status status = getI2cBusHelper(&i2c_node);
|
if (mI2cClientPath.empty()) {
|
||||||
if (status != Status::SUCCESS) {
|
mI2cClientPath = getI2cClientPath(kHsi2cPath, kTcpcDevName, kI2cClientId);
|
||||||
|
if (mI2cClientPath.empty()) {
|
||||||
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_sdp_enum_timeout_path = kI2CPath + i2c_node + "/" + kUpdateSdpEnumTimeout;
|
update_sdp_enum_timeout_path = mI2cClientPath + 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 {
|
||||||
|
@ -494,15 +476,20 @@ ScopedAStatus UsbGadget::setCurrentUsbFunctions(long functions,
|
||||||
std::unique_lock<std::mutex> lk(mLockSetCurrentFunction);
|
std::unique_lock<std::mutex> lk(mLockSetCurrentFunction);
|
||||||
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;
|
||||||
|
std::string accessoryCurrentLimitEnablePath, accessoryCurrentLimitPath;
|
||||||
string accessoryCurrentLimitEnablePath, accessoryCurrentLimitPath, path;
|
|
||||||
|
|
||||||
mCurrentUsbFunctions = functions;
|
mCurrentUsbFunctions = functions;
|
||||||
mCurrentUsbFunctionsApplied = false;
|
mCurrentUsbFunctionsApplied = false;
|
||||||
|
|
||||||
getI2cBusHelper(&path);
|
if (mI2cClientPath.empty()) {
|
||||||
accessoryCurrentLimitPath = kI2CPath + path + "/" + kAccessoryLimitCurrent;
|
mI2cClientPath = getI2cClientPath(kHsi2cPath, kTcpcDevName, kI2cClientId);
|
||||||
accessoryCurrentLimitEnablePath = kI2CPath + path + "/" + kAccessoryLimitCurrentEnable;
|
if (mI2cClientPath.empty()) {
|
||||||
|
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
accessoryCurrentLimitPath = mI2cClientPath + kAccessoryLimitCurrent;
|
||||||
|
accessoryCurrentLimitEnablePath = mI2cClientPath + kAccessoryLimitCurrentEnable;
|
||||||
|
|
||||||
// Get the gadget IRQ number before tearDownGadget()
|
// Get the gadget IRQ number before tearDownGadget()
|
||||||
if (mGadgetIrqPath.empty())
|
if (mGadgetIrqPath.empty())
|
||||||
|
|
|
@ -118,6 +118,7 @@ struct UsbGadget : public BnUsbGadget {
|
||||||
// Indicates to the kernel that the gadget service is ready and the kernel can
|
// Indicates to the kernel that the gadget service is ready and the kernel can
|
||||||
// set SDP timeout to a lower value.
|
// set SDP timeout to a lower value.
|
||||||
void updateSdpEnumTimeout();
|
void updateSdpEnumTimeout();
|
||||||
|
std::string mI2cClientPath;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Status tearDownGadget();
|
Status tearDownGadget();
|
||||||
|
|
|
@ -43,8 +43,9 @@
|
||||||
|
|
||||||
#include <aidl/android/frameworks/stats/IStats.h>
|
#include <aidl/android/frameworks/stats/IStats.h>
|
||||||
#include <android_hardware_usb_flags.h>
|
#include <android_hardware_usb_flags.h>
|
||||||
#include <pixelusb/UsbGadgetAidlCommon.h>
|
|
||||||
#include <pixelstats/StatsHelper.h>
|
#include <pixelstats/StatsHelper.h>
|
||||||
|
#include <pixelusb/I2cHelper.h>
|
||||||
|
#include <pixelusb/UsbGadgetAidlCommon.h>
|
||||||
|
|
||||||
namespace usb_flags = android::hardware::usb::flags;
|
namespace usb_flags = android::hardware::usb::flags;
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ using android::base::Trim;
|
||||||
using android::hardware::google::pixel::getStatsService;
|
using android::hardware::google::pixel::getStatsService;
|
||||||
using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat;
|
using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat;
|
||||||
using android::hardware::google::pixel::reportUsbPortOverheat;
|
using android::hardware::google::pixel::reportUsbPortOverheat;
|
||||||
|
using android::hardware::google::pixel::usb::getI2cClientPath;
|
||||||
using android::String8;
|
using android::String8;
|
||||||
using android::Vector;
|
using android::Vector;
|
||||||
|
|
||||||
|
@ -67,18 +69,19 @@ volatile bool destroyThread;
|
||||||
|
|
||||||
string enabledPath;
|
string enabledPath;
|
||||||
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d60000.hsi2c";
|
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d60000.hsi2c";
|
||||||
constexpr char kI2CPath[] = "/sys/devices/platform/10d60000.hsi2c/i2c-";
|
constexpr char kTcpcDevName[] = "i2c-max77759tcpc";
|
||||||
|
constexpr char kI2cClientId[] = "0025";
|
||||||
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 kComplianceWarningInputPowerLimited[] = "input_power_limited";
|
constexpr char kComplianceWarningInputPowerLimited[] = "input_power_limited";
|
||||||
constexpr char kContaminantDetectionPath[] = "i2c-max77759tcpc/contaminant_detection";
|
constexpr char kContaminantDetectionPath[] = "contaminant_detection";
|
||||||
constexpr char kStatusPath[] = "i2c-max77759tcpc/contaminant_detection_status";
|
constexpr char kStatusPath[] = "contaminant_detection_status";
|
||||||
constexpr char kSinkLimitEnable[] = "i2c-max77759tcpc/usb_limit_sink_enable";
|
constexpr char kSinkLimitEnable[] = "usb_limit_sink_enable";
|
||||||
constexpr char kSourceLimitEnable[] = "i2c-max77759tcpc/usb_limit_source_enable";
|
constexpr char kSourceLimitEnable[] = "usb_limit_source_enable";
|
||||||
constexpr char kSinkLimitCurrent[] = "i2c-max77759tcpc/usb_limit_sink_current";
|
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/";
|
||||||
|
@ -245,31 +248,9 @@ ScopedAStatus Usb::resetUsbPort(const std::string& in_portName, int64_t in_trans
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status getI2cBusHelper(string *name) {
|
Status queryMoistureDetectionStatus(android::hardware::usb::Usb *usb,
|
||||||
DIR *dp;
|
std::vector<PortStatus> *currentPortStatus) {
|
||||||
|
string enabled, status, DetectedPath;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status queryMoistureDetectionStatus(std::vector<PortStatus> *currentPortStatus) {
|
|
||||||
string enabled, status, path, DetectedPath;
|
|
||||||
|
|
||||||
(*currentPortStatus)[0].supportedContaminantProtectionModes
|
(*currentPortStatus)[0].supportedContaminantProtectionModes
|
||||||
.push_back(ContaminantProtectionMode::FORCE_DISABLE);
|
.push_back(ContaminantProtectionMode::FORCE_DISABLE);
|
||||||
|
@ -278,8 +259,15 @@ Status queryMoistureDetectionStatus(std::vector<PortStatus> *currentPortStatus)
|
||||||
(*currentPortStatus)[0].supportsEnableContaminantPresenceDetection = true;
|
(*currentPortStatus)[0].supportsEnableContaminantPresenceDetection = true;
|
||||||
(*currentPortStatus)[0].supportsEnableContaminantPresenceProtection = false;
|
(*currentPortStatus)[0].supportsEnableContaminantPresenceProtection = false;
|
||||||
|
|
||||||
getI2cBusHelper(&path);
|
if (usb->mI2cClientPath.empty()) {
|
||||||
enabledPath = kI2CPath + path + "/" + kContaminantDetectionPath;
|
usb->mI2cClientPath = getI2cClientPath(kHsi2cPath, kTcpcDevName, kI2cClientId);
|
||||||
|
if (usb->mI2cClientPath.empty()) {
|
||||||
|
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
||||||
|
return Status::ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enabledPath = usb->mI2cClientPath + 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;
|
||||||
|
@ -287,7 +275,7 @@ Status queryMoistureDetectionStatus(std::vector<PortStatus> *currentPortStatus)
|
||||||
|
|
||||||
enabled = Trim(enabled);
|
enabled = Trim(enabled);
|
||||||
if (enabled == "1") {
|
if (enabled == "1") {
|
||||||
DetectedPath = kI2CPath + path + "/" + kStatusPath;
|
DetectedPath = usb->mI2cClientPath + 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;
|
||||||
|
@ -562,7 +550,8 @@ Usb::Usb()
|
||||||
ThrottlingSeverity::NONE)}, kSamplingIntervalSec),
|
ThrottlingSeverity::NONE)}, kSamplingIntervalSec),
|
||||||
mUsbDataEnabled(true),
|
mUsbDataEnabled(true),
|
||||||
mUsbHubVendorCmdValue(GL852G_VENDOR_CMD_VALUE_DEFAULT),
|
mUsbHubVendorCmdValue(GL852G_VENDOR_CMD_VALUE_DEFAULT),
|
||||||
mUsbHubVendorCmdIndex(GL852G_VENDOR_CMD_INDEX_DEFAULT) {
|
mUsbHubVendorCmdIndex(GL852G_VENDOR_CMD_INDEX_DEFAULT),
|
||||||
|
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));
|
||||||
|
@ -650,12 +639,19 @@ 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 path, sinkLimitEnablePath, currentLimitPath, sourceLimitEnablePath;
|
string sinkLimitEnablePath, currentLimitPath, sourceLimitEnablePath;
|
||||||
|
|
||||||
getI2cBusHelper(&path);
|
if (mI2cClientPath.empty()) {
|
||||||
sinkLimitEnablePath = kI2CPath + path + "/" + kSinkLimitEnable;
|
mI2cClientPath = getI2cClientPath(kHsi2cPath, kTcpcDevName, kI2cClientId);
|
||||||
currentLimitPath = kI2CPath + path + "/" + kSinkLimitCurrent;
|
if (mI2cClientPath.empty()) {
|
||||||
sourceLimitEnablePath = kI2CPath + path + "/" + kSourceLimitEnable;
|
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
||||||
|
return ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sinkLimitEnablePath = mI2cClientPath + kSinkLimitEnable;
|
||||||
|
currentLimitPath = mI2cClientPath + kSinkLimitCurrent;
|
||||||
|
sourceLimitEnablePath = mI2cClientPath + kSourceLimitEnable;
|
||||||
|
|
||||||
pthread_mutex_lock(&mLock);
|
pthread_mutex_lock(&mLock);
|
||||||
if (in_limit) {
|
if (in_limit) {
|
||||||
|
@ -695,11 +691,19 @@ ScopedAStatus Usb::limitPowerTransfer(const string& in_portName, bool in_limit,
|
||||||
return ScopedAStatus::ok();
|
return ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status queryPowerTransferStatus(std::vector<PortStatus> *currentPortStatus) {
|
Status queryPowerTransferStatus(android::hardware::usb::Usb *usb,
|
||||||
string limitedPath, enabled, path;
|
std::vector<PortStatus> *currentPortStatus) {
|
||||||
|
string limitedPath, enabled;
|
||||||
|
|
||||||
getI2cBusHelper(&path);
|
if (usb->mI2cClientPath.empty()) {
|
||||||
limitedPath = kI2CPath + path + "/" + kSinkLimitEnable;
|
usb->mI2cClientPath = getI2cClientPath(kHsi2cPath, kTcpcDevName, kI2cClientId);
|
||||||
|
if (usb->mI2cClientPath.empty()) {
|
||||||
|
ALOGE("%s: Unable to locate i2c bus node", __func__);
|
||||||
|
return Status::ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
limitedPath = usb->mI2cClientPath + 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;
|
||||||
|
@ -953,8 +957,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(currentPortStatus);
|
queryMoistureDetectionStatus(usb, currentPortStatus);
|
||||||
queryPowerTransferStatus(currentPortStatus);
|
queryPowerTransferStatus(usb, currentPortStatus);
|
||||||
queryNonCompliantChargerStatus(currentPortStatus);
|
queryNonCompliantChargerStatus(currentPortStatus);
|
||||||
queryUsbDataSession(usb, currentPortStatus);
|
queryUsbDataSession(usb, currentPortStatus);
|
||||||
if (usb->mCallback != NULL) {
|
if (usb->mCallback != NULL) {
|
||||||
|
|
|
@ -99,6 +99,7 @@ struct Usb : public BnUsb {
|
||||||
// Usb hub vendor command settings for JK level tuning
|
// Usb hub vendor command settings for JK level tuning
|
||||||
int mUsbHubVendorCmdValue;
|
int mUsbHubVendorCmdValue;
|
||||||
int mUsbHubVendorCmdIndex;
|
int mUsbHubVendorCmdIndex;
|
||||||
|
std::string mI2cClientPath;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pthread_t mPoll;
|
pthread_t mPoll;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue