summaryrefslogtreecommitdiff
path: root/usb
diff options
context:
space:
mode:
authorAlbert Wang <albertccwang@google.com>2021-03-21 19:42:00 +0800
committerAlbert Wang <albertccwang@google.com>2021-03-21 19:42:00 +0800
commitffc5885ebd57c69432ac3db1931284b83088009c (patch)
tree29df2139647004d7327d6d5dd0c4b17e13cea525 /usb
parentf9083c098a02dc8f18efaab0af4584442cc69d41 (diff)
Update USB HAL to V1.3 implementation
Supports to enable/disable USB data signaling Bug: 161414036 Test: Pass USB V1.3 HIDL tests Signed-off-by: Albert Wang <albertccwang@google.com> Change-Id: I965f2bbb268f21020185a21d5dc36fad1c503afb
Diffstat (limited to 'usb')
-rw-r--r--usb/Android.bp7
-rw-r--r--usb/Usb.cpp61
-rw-r--r--usb/Usb.h20
-rw-r--r--usb/android.hardware.usb@1.2-service.bonito.rc12
-rw-r--r--usb/android.hardware.usb@1.3-service.bonito.rc20
-rw-r--r--usb/android.hardware.usb@1.3-service.bonito.xml (renamed from usb/android.hardware.usb@1.2-service.bonito.xml)2
-rw-r--r--usb/service.cpp6
7 files changed, 92 insertions, 36 deletions
diff --git a/usb/Android.bp b/usb/Android.bp
index 7cee21de..03e69b71 100644
--- a/usb/Android.bp
+++ b/usb/Android.bp
@@ -17,11 +17,11 @@ package {
}
cc_binary {
- name: "android.hardware.usb@1.2-service.bonito",
+ name: "android.hardware.usb@1.3-service.bonito",
relative_install_path: "hw",
- init_rc: ["android.hardware.usb@1.2-service.bonito.rc"],
+ init_rc: ["android.hardware.usb@1.3-service.bonito.rc"],
vintf_fragments: [
- "android.hardware.usb@1.2-service.bonito.xml",
+ "android.hardware.usb@1.3-service.bonito.xml",
"android.hardware.usb.gadget@1.2-service.bonito.xml",
],
srcs: ["service.cpp", "Usb.cpp", "UsbGadget.cpp"],
@@ -34,6 +34,7 @@ cc_binary {
"android.hardware.usb@1.0",
"android.hardware.usb@1.1",
"android.hardware.usb@1.2",
+ "android.hardware.usb@1.3",
"android.hardware.usb.gadget@1.0",
"android.hardware.usb.gadget@1.1",
"android.hardware.usb.gadget@1.2",
diff --git a/usb/Usb.cpp b/usb/Usb.cpp
index dd5ba268..1413a01d 100644
--- a/usb/Usb.cpp
+++ b/usb/Usb.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_TAG "android.hardware.usb@1.2-service.bonito"
+#define LOG_TAG "android.hardware.usb@1.3-service.crosshatch"
#include <android-base/file.h>
#include <android-base/logging.h>
@@ -37,13 +37,54 @@
#include <utils/StrongPointer.h>
#include "Usb.h"
+#include "UsbGadget.h"
namespace android {
namespace hardware {
namespace usb {
-namespace V1_2 {
+namespace V1_3 {
namespace implementation {
+Return<bool> Usb::enableUsbDataSignal(bool enable) {
+ bool result = true;
+
+ ALOGI("Userspace turn %s USB data signaling", enable ? "on" : "off");
+
+ if (enable) {
+ if (!WriteStringToFile("1", USB_DATA_PATH)) {
+ ALOGE("Not able to turn on usb connection notification");
+ result = false;
+ }
+
+ if (!WriteStringToFile(gadget::V1_2::implementation::kGadgetName, PULLUP_PATH)) {
+ ALOGE("Gadget cannot be pulled up");
+ 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 (!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;
+ }
+ }
+
+ return result;
+}
+
// Set by the signal handler to destroy the thread
volatile bool destroyThread;
@@ -84,13 +125,10 @@ Status queryMoistureDetectionStatus(hidl_vec<PortStatus> *currentPortStatus_1_2)
(*currentPortStatus_1_2)[0].contaminantProtectionStatus =
V1_2::ContaminantProtectionStatus::NONE;
(*currentPortStatus_1_2)[0].contaminantDetectionStatus =
- V1_2::ContaminantDetectionStatus::DISABLED;
+ V1_2::ContaminantDetectionStatus::NOT_DETECTED;
(*currentPortStatus_1_2)[0].supportsEnableContaminantPresenceDetection = false;
(*currentPortStatus_1_2)[0].supportsEnableContaminantPresenceProtection = false;
- (*currentPortStatus_1_2)[0].contaminantDetectionStatus =
- V1_2::ContaminantDetectionStatus::NOT_DETECTED;
-
ALOGI("ContaminantDetectionStatus:%d ContaminantProtectionStatus:%d",
(*currentPortStatus_1_2)[0].contaminantDetectionStatus,
(*currentPortStatus_1_2)[0].contaminantProtectionStatus);
@@ -503,7 +541,8 @@ done:
return Status::ERROR;
}
-void queryVersionHelper(Usb *usb, hidl_vec<PortStatus> *currentPortStatus_1_2) {
+void queryVersionHelper(android::hardware::usb::V1_3::implementation::Usb *usb,
+ hidl_vec<PortStatus> *currentPortStatus_1_2) {
hidl_vec<V1_1::PortStatus_1_1> currentPortStatus_1_1;
hidl_vec<V1_0::PortStatus> currentPortStatus;
Status status;
@@ -571,7 +610,7 @@ Return<void> Usb::enableContaminantPresenceProtection(const hidl_string & /*port
/* uevent_event() data that is persistent across uevents. */
struct data {
int uevent_fd;
- android::hardware::usb::V1_2::implementation::Usb *usb;
+ android::hardware::usb::V1_3::implementation::Usb *usb;
};
// Report connection & disconnection of devices into the USB-C connector.
@@ -643,7 +682,7 @@ void *work(void *param) {
}
payload.uevent_fd = uevent_fd;
- payload.usb = (android::hardware::usb::V1_2::implementation::Usb *)param;
+ payload.usb = (android::hardware::usb::V1_3::implementation::Usb *)param;
fcntl(uevent_fd, F_SETFL, O_NONBLOCK);
@@ -756,7 +795,7 @@ Return<void> Usb::setCallback(const sp<V1_0::IUsbCallback> &callback) {
}
} // namespace implementation
-} // namespace V1_2
+} // namespace V1_3
} // namespace usb
} // namespace hardware
} // namespace android
diff --git a/usb/Usb.h b/usb/Usb.h
index 03990b1b..fa5c85ba 100644
--- a/usb/Usb.h
+++ b/usb/Usb.h
@@ -1,8 +1,9 @@
#pragma once
-#include <android/hardware/usb/1.2/IUsb.h>
+#include <android-base/file.h>
#include <android/hardware/usb/1.2/IUsbCallback.h>
#include <android/hardware/usb/1.2/types.h>
+#include <android/hardware/usb/1.3/IUsb.h>
#include <hidl/Status.h>
#include <utils/Log.h>
@@ -16,10 +17,11 @@
namespace android {
namespace hardware {
namespace usb {
-namespace V1_2 {
+namespace V1_3 {
namespace implementation {
using ::android::sp;
+using ::android::base::WriteStringToFile;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
@@ -33,22 +35,28 @@ using ::android::hardware::usb::V1_0::PortRoleType;
using ::android::hardware::usb::V1_0::Status;
using ::android::hardware::usb::V1_1::PortMode_1_1;
using ::android::hardware::usb::V1_1::PortStatus_1_1;
-using ::android::hardware::usb::V1_2::IUsb;
using ::android::hardware::usb::V1_2::IUsbCallback;
using ::android::hardware::usb::V1_2::PortStatus;
+using ::android::hardware::usb::V1_3::IUsb;
using ::android::hidl::base::V1_0::DebugInfo;
using ::android::hidl::base::V1_0::IBase;
-enum class HALVersion { V1_0, V1_1, V1_2 };
+#define SOC_PATH "/sys/devices/platform/soc/a600000.ssusb/"
+#define VBUS_PATH SOC_PATH "id"
+#define ID_PATH SOC_PATH "b_sess"
+#define USB_DATA_PATH SOC_PATH "usb_data_enabled"
+
+enum class HALVersion { V1_0, V1_1, V1_2, V1_3 };
struct Usb : public IUsb {
Usb();
- Return<void> switchRole(const hidl_string& portName, const V1_0::PortRole& role) override;
+ Return<void> switchRole(const hidl_string &portName, const PortRole &role) override;
Return<void> setCallback(const sp<V1_0::IUsbCallback>& callback) override;
Return<void> queryPortStatus() override;
Return<void> enableContaminantPresenceDetection(const hidl_string &portName, bool enable);
Return<void> enableContaminantPresenceProtection(const hidl_string &portName, bool enable);
+ Return<bool> enableUsbDataSignal(bool enable) override;
sp<V1_0::IUsbCallback> mCallback_1_0;
// Protects mCallback variable
@@ -67,7 +75,7 @@ struct Usb : public IUsb {
};
} // namespace implementation
-} // namespace V1_2
+} // namespace V1_3
} // namespace usb
} // namespace hardware
} // namespace android
diff --git a/usb/android.hardware.usb@1.2-service.bonito.rc b/usb/android.hardware.usb@1.2-service.bonito.rc
deleted file mode 100644
index 306c01f8..00000000
--- a/usb/android.hardware.usb@1.2-service.bonito.rc
+++ /dev/null
@@ -1,12 +0,0 @@
-service vendor.usb-hal-1-2 /vendor/bin/hw/android.hardware.usb@1.2-service.bonito
- class hal
- user root
- group root system shell mtp
-
-on boot
- chown root system /sys/class/typec/port0/power_role
- chown root system /sys/class/typec/port0/data_role
- chown root system /sys/class/typec/port0/port_type
- chmod 664 /sys/class/typec/port0/power_role
- chmod 664 /sys/class/typec/port0/data_role
- chmod 664 /sys/class/typec/port0/port_type
diff --git a/usb/android.hardware.usb@1.3-service.bonito.rc b/usb/android.hardware.usb@1.3-service.bonito.rc
new file mode 100644
index 00000000..7b531dbd
--- /dev/null
+++ b/usb/android.hardware.usb@1.3-service.bonito.rc
@@ -0,0 +1,20 @@
+service vendor.usb-hal-1-3 /vendor/bin/hw/android.hardware.usb@1.3-service.bonito
+ class hal
+ user root
+ group root system shell mtp
+
+on boot
+ chown root system /sys/class/typec/port0/power_role
+ chown root system /sys/class/typec/port0/data_role
+ chown root system /sys/class/typec/port0/port_type
+ chmod 664 /sys/class/typec/port0/power_role
+ chmod 664 /sys/class/typec/port0/data_role
+ chmod 664 /sys/class/typec/port0/port_type
+
+on post-fs
+ chown root system /sys/devices/platform/soc/a600000.ssusb/b_sess
+ chown root system /sys/devices/platform/soc/a600000.ssusb/id
+ chown root system /sys/devices/platform/soc/a600000.ssusb/usb_data_enabled
+ chmod 664 /sys/devices/platform/soc/a600000.ssusb/b_sess
+ chmod 664 /sys/devices/platform/soc/a600000.ssusb/id
+ chmod 664 /sys/devices/platform/soc/a600000.ssusb/usb_data_enabled
diff --git a/usb/android.hardware.usb@1.2-service.bonito.xml b/usb/android.hardware.usb@1.3-service.bonito.xml
index 25ecf65a..cd542687 100644
--- a/usb/android.hardware.usb@1.2-service.bonito.xml
+++ b/usb/android.hardware.usb@1.3-service.bonito.xml
@@ -2,7 +2,7 @@
<hal format="hidl">
<name>android.hardware.usb</name>
<transport>hwbinder</transport>
- <version>1.2</version>
+ <version>1.3</version>
<interface>
<name>IUsb</name>
<instance>default</instance>
diff --git a/usb/service.cpp b/usb/service.cpp
index fe9be45d..7a70e507 100644
--- a/usb/service.cpp
+++ b/usb/service.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_TAG "android.hardware.usb@1.2-service.bonito"
+#define LOG_TAG "android.hardware.usb@1.3-service.bonito"
#include <hidl/HidlTransportSupport.h>
#include "Usb.h"
@@ -29,8 +29,8 @@ using android::hardware::joinRpcThreadpool;
// Generated HIDL files
using android::hardware::usb::gadget::V1_2::IUsbGadget;
using android::hardware::usb::gadget::V1_2::implementation::UsbGadget;
-using android::hardware::usb::V1_2::IUsb;
-using android::hardware::usb::V1_2::implementation::Usb;
+using android::hardware::usb::V1_3::IUsb;
+using android::hardware::usb::V1_3::implementation::Usb;
using android::OK;
using android::status_t;