• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef ANDROID_HARDWARE_USB_V1_1_USB_H
2 #define ANDROID_HARDWARE_USB_V1_1_USB_H
3 
4 #include <android/hardware/usb/1.1/IUsb.h>
5 #include <android/hardware/usb/1.1/types.h>
6 #include <android/hardware/usb/1.1/IUsbCallback.h>
7 #include <hidl/Status.h>
8 #include <utils/Log.h>
9 
10 #define UEVENT_MSG_LEN 2048
11 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd.
12 // The -partner directory would not be created until this is done.
13 // Having a margin of ~3 secs for the directory and other related bookeeping
14 // structures created and uvent fired.
15 #define PORT_TYPE_TIMEOUT 8
16 
17 namespace android {
18 namespace hardware {
19 namespace usb {
20 namespace V1_1 {
21 namespace implementation {
22 
23 using ::android::hardware::usb::V1_0::PortRole;
24 using ::android::hardware::usb::V1_0::PortRoleType;
25 using ::android::hardware::usb::V1_0::PortDataRole;
26 using ::android::hardware::usb::V1_0::PortPowerRole;
27 using ::android::hardware::usb::V1_0::Status;
28 using ::android::hardware::usb::V1_1::IUsb;
29 using ::android::hardware::usb::V1_1::IUsbCallback;
30 using ::android::hardware::usb::V1_1::PortMode_1_1;
31 using ::android::hardware::usb::V1_1::PortStatus_1_1;
32 using ::android::hidl::base::V1_0::DebugInfo;
33 using ::android::hidl::base::V1_0::IBase;
34 using ::android::hardware::hidl_array;
35 using ::android::hardware::hidl_memory;
36 using ::android::hardware::hidl_string;
37 using ::android::hardware::hidl_vec;
38 using ::android::hardware::Return;
39 using ::android::hardware::Void;
40 using ::android::sp;
41 
42 struct Usb : public IUsb {
43     Usb();
44 
45     Return<void> switchRole(const hidl_string& portName, const V1_0::PortRole& role) override;
46     Return<void> setCallback(const sp<V1_0::IUsbCallback>& callback) override;
47     Return<void> queryPortStatus() override;
48 
49 
50     sp<V1_0::IUsbCallback> mCallback_1_0;
51     // Protects mCallback variable
52     pthread_mutex_t mLock;
53     // Protects roleSwitch operation
54     pthread_mutex_t mRoleSwitchLock;
55     // Threads waiting for the partner to come back wait here
56     pthread_cond_t mPartnerCV;
57     // lock protecting mPartnerCV
58     pthread_mutex_t mPartnerLock;
59     // Variable to signal partner coming back online after type switch
60     bool mPartnerUp;
61 
62     private:
63         pthread_t mPoll;
64 };
65 
66 }  // namespace implementation
67 }  // namespace V1_0
68 }  // namespace usb
69 }  // namespace hardware
70 }  // namespace android
71 
72 #endif  // ANDROID_HARDWARE_USB_V1_1_USB_H
73