usb: limit the current to 1.3A when connect to accessory am: ebd7fca53a
Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs101/+/18282022 Change-Id: I3b1fcae87f348543234c1dc583bdf8d756aae21d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
0b393b743a
3 changed files with 82 additions and 0 deletions
|
@ -33,6 +33,12 @@ namespace gadget {
|
||||||
namespace V1_2 {
|
namespace V1_2 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
|
string enabledPath;
|
||||||
|
constexpr char kHsi2cPath[] = "/sys/devices/platform/10d50000.hsi2c";
|
||||||
|
constexpr char kI2CPath[] = "/sys/devices/platform/10d50000.hsi2c/i2c-";
|
||||||
|
constexpr char kAccessoryLimitCurrent[] = "i2c-max77759tcpc/usb_limit_accessory_current";
|
||||||
|
constexpr char kAccessoryLimitCurrentEnable[] = "i2c-max77759tcpc/usb_limit_accessory_enable";
|
||||||
|
|
||||||
UsbGadget::UsbGadget() : mGadgetIrqPath("") {
|
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");
|
||||||
|
@ -380,14 +386,45 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t 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;
|
||||||
|
}
|
||||||
|
|
||||||
Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
||||||
const sp<V1_0::IUsbGadgetCallback> &callback,
|
const sp<V1_0::IUsbGadgetCallback> &callback,
|
||||||
uint64_t timeout) {
|
uint64_t timeout) {
|
||||||
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 usb_limit_sink_enable;
|
||||||
|
|
||||||
|
string accessoryCurrentLimitEnablePath, accessoryCurrentLimitPath, path;
|
||||||
|
|
||||||
mCurrentUsbFunctions = functions;
|
mCurrentUsbFunctions = functions;
|
||||||
mCurrentUsbFunctionsApplied = false;
|
mCurrentUsbFunctionsApplied = false;
|
||||||
|
|
||||||
|
getI2cBusHelper(&path);
|
||||||
|
accessoryCurrentLimitPath = kI2CPath + path + "/" + kAccessoryLimitCurrent;
|
||||||
|
accessoryCurrentLimitEnablePath = kI2CPath + path + "/" + kAccessoryLimitCurrentEnable;
|
||||||
|
|
||||||
// Get the gadget IRQ number before tearDownGadget()
|
// Get the gadget IRQ number before tearDownGadget()
|
||||||
if (mGadgetIrqPath.empty())
|
if (mGadgetIrqPath.empty())
|
||||||
getUsbGadgetIrqPath();
|
getUsbGadgetIrqPath();
|
||||||
|
@ -435,6 +472,28 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ReadFileToString(CURRENT_USB_TYPE_PATH, ¤t_usb_type))
|
||||||
|
current_usb_type = Trim(current_usb_type);
|
||||||
|
|
||||||
|
if (ReadFileToString(CURRENT_USB_POWER_OPERATION_MODE_PATH, ¤t_usb_power_operation_mode))
|
||||||
|
current_usb_power_operation_mode = Trim(current_usb_power_operation_mode);
|
||||||
|
|
||||||
|
if (functions & GadgetFunction::ACCESSORY &&
|
||||||
|
current_usb_type == "Unknown SDP [CDP] DCP" &&
|
||||||
|
(current_usb_power_operation_mode == "default" ||
|
||||||
|
current_usb_power_operation_mode == "1.5A")) {
|
||||||
|
if (!WriteStringToFile("1300000", accessoryCurrentLimitPath)) {
|
||||||
|
ALOGI("Write 1.3A to limit current fail");
|
||||||
|
} else {
|
||||||
|
if (!WriteStringToFile("1", accessoryCurrentLimitEnablePath)) {
|
||||||
|
ALOGI("Enable limit current fail");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!WriteStringToFile("0", accessoryCurrentLimitEnablePath))
|
||||||
|
ALOGI("unvote accessory limit current failed");
|
||||||
|
}
|
||||||
|
|
||||||
ALOGI("Usb Gadget setcurrent functions called successfully");
|
ALOGI("Usb Gadget setcurrent functions called successfully");
|
||||||
return Void();
|
return Void();
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,13 @@ static MonitorFfs monitorFfs(kGadgetName);
|
||||||
#define BIG_CORE "6"
|
#define BIG_CORE "6"
|
||||||
#define MEDIUM_CORE "4"
|
#define MEDIUM_CORE "4"
|
||||||
|
|
||||||
|
#define POWER_SUPPLY_PATH "/sys/class/power_supply/usb/"
|
||||||
|
#define USB_PORT0_PATH "/sys/class/typec/port0/"
|
||||||
|
|
||||||
|
#define CURRENT_MAX_PATH POWER_SUPPLY_PATH "current_max"
|
||||||
|
#define CURRENT_USB_TYPE_PATH POWER_SUPPLY_PATH "usb_type"
|
||||||
|
#define CURRENT_USB_POWER_OPERATION_MODE_PATH USB_PORT0_PATH "power_operation_mode"
|
||||||
|
|
||||||
struct UsbGadget : public IUsbGadget {
|
struct UsbGadget : public IUsbGadget {
|
||||||
UsbGadget();
|
UsbGadget();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,14 @@ on post-fs
|
||||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/contaminant_detection
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/contaminant_detection
|
||||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/contaminant_detection
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/contaminant_detection
|
||||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-8/i2c-max77759tcpc/contaminant_detection
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-8/i2c-max77759tcpc/contaminant_detection
|
||||||
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_accessory_current
|
||||||
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_accessory_current
|
||||||
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_accessory_current
|
||||||
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-8/i2c-max77759tcpc/usb_limit_accessory_current
|
||||||
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||||
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||||
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||||
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-8/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_current
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_current
|
||||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_sink_current
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_sink_current
|
||||||
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_sink_current
|
chown root system /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_sink_current
|
||||||
|
@ -38,6 +46,14 @@ on post-fs
|
||||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/contaminant_detection
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/contaminant_detection
|
||||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/contaminant_detection
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/contaminant_detection
|
||||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-8/i2c-max77759tcpc/contaminant_detection
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-8/i2c-max77759tcpc/contaminant_detection
|
||||||
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_accessory_current
|
||||||
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_accessory_current
|
||||||
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_accessory_current
|
||||||
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-8/i2c-max77759tcpc/usb_limit_accessory_current
|
||||||
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||||
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||||
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||||
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-8/i2c-max77759tcpc/usb_limit_accessory_enable
|
||||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_current
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-5/i2c-max77759tcpc/usb_limit_sink_current
|
||||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_sink_current
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-6/i2c-max77759tcpc/usb_limit_sink_current
|
||||||
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_sink_current
|
chmod 664 /sys/devices/platform/10d50000.hsi2c/i2c-7/i2c-max77759tcpc/usb_limit_sink_current
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue