Commit graph

59 commits

Author SHA1 Message Date
Kyle Tso
d17fdff5f8 usb: Log for retry on role switch
Add a log for the retry. Also define the sleep time in the header file.

Bug: 341996696
Change-Id: Ib3cc0c6ad576e7cda26b7f50cdc61d52e6349c78
Signed-off-by: Kyle Tso <kyletso@google.com>
2024-06-13 16:54:37 +08:00
Kyle Tso
ef5856a447 usb: Add retry on role switch
Bug: 341996696
Change-Id: I8caa65288af1588d24fea4aa6c5768d45d69bbd5
Signed-off-by: Kyle Tso <kyletso@google.com>
2024-06-12 09:16:17 +00:00
Dennis Shen
1b3d66a9fb switch over to use new storage read api instead of
server_configurable_flags, this new read api lib will be needed for new
codegened aconfig flag lib.

Bug: 321077378
Test m and avd

Change-Id: I99307a4ad8f133232cfd8b47058f936445cb7cce
2024-06-07 13:07:42 +00:00
RD Babiera
523717b768 usb: handle displayport debounce timer empty reads
If the device is unplugged then plugged before
mDisplayPortDebounceTimer triggers, then the new
displayPortPollWork could process the trigger
in the intial epoll handling loop. Because the
timer can be rearmed, the timerfd read results
in -EAGAIN because no data is ready, but stale
data was ready to begin with.

Disarm the debounce timer when displayPortPollWork
closes to prevent new work threads from reading
timer when not ready. Also log debounce read
errors as a warning and not an error.

Test: manual test on device
Bug: 328553922
(cherry-picked from 94c9c1ac86f398c22ddc446f17bd7ab3fddb675c)
Change-Id: Icf3dbe929eb9f0520941a4efe3dcea79a71d46c3
Signed-off-by: RD Babiera <rdbabiera@google.com>
2024-03-19 18:35:19 +00:00
Sergey Volk
b5769ac1f1 Fix permissions for dp_hotplug_error_code sysfs node
DisplayPort kernel driver passes error code/status to hardware composer
via the dp_hotplug_error_code sysfs file. When HWC receives/consumes
the error, it will write "0" into that file to reset the error code. So
this file must be readable and writable by the HWC code running with
"system" user/group permissions.
Previously we used to set the ownership to system:system, but in order
to be more consistent with the rest of sysfs files in that directory,
we can use root:graphics instead with permissions 0664. HWC runs
under the "graphics" group, so this should allow HWC write access.

Bug: 324953626
Test: checked permissions of dp_hotplug_error_code sysfs
Change-Id: Idf65acc12d158a78565c41f4e2aea24362e2cdff
2024-02-14 00:58:35 +00:00
RD Babiera
10c5df0b97 Merge "usb: report displayport capable port partner disconnect to drm" into main 2024-01-23 17:42:41 +00:00
Roy Luo
9164eae7cd usb: dump flag value in the constructor
Dump flag value in the construtor for easier debugging. Feature flags
are not expected to change in runtime, dumping the value once should
be enough.

Bug: 296119135
Test: manual test
Change-Id: Ie5aca2dff23e59704fb306833cde0e592b9f430d
2024-01-10 08:50:07 +00:00
Roy Luo
bbb322e73a usb: adjust heuristics for flaky connection warning
The state count requirement is very specific to the case where the
signal integrity is the culprit of flaky connection. However,
there could be other cases such as bad receptacles causing data pins
to disconnect randomly.
Remove the state count requirement to cover more cases.

Bug: 296119135
Test: manually trigger the warnings
Change-Id: Ic2ae376ad6062d9930614381503f44e4a5ac760f
(cherry picked from commit 5e14ba01be9acc31d3df0f506b4287eea0bf9583)
2023-12-26 22:26:13 +00:00
Roy Luo
88f3ee90d9 usb: implement heuristics to flag data compliance warnings
Support flagging enum failure and flaky connection in device mode,
flagging enum failure and missing data lines in host mode.
No warning would be flagged until 5 secs after the data session
starts to give ample time for the connection to stabilize, a timer
is added to support it.

Bug: 296119135
Test: manually trigger the warnings
Change-Id: I25f08657e328913946add192b5ecb9ee50c3a1a8
(cherry picked from commit 42020dc4585442bd7ca88f183ba29a18834af197)
2023-12-26 22:25:25 +00:00
RD Babiera
3082aa7f48 usb: report displayport capable port partner disconnect to drm
On port-partner remove, write to drm's usbc_cable_disconnect
node if setupDisplayPortPoll() had run previously in the
connection, flagged by mPartnerSupportsDisplayPort.

Test: manual test on device
Bug: 303820069
Change-Id: I3478f2f027540972647044716a1a3e832ae1b152
Signed-off-by: RD Babiera <rdbabiera@google.com>
2023-12-11 22:34:53 +00:00
Roy Luo
09f98e2ed6 Revert^2 "usb: introduce UsbDataSessionMonitor class"
3e5743c521

Bug: 297224564
Bug: 296119135
Change-Id: I4fc7da8c628292bb2c702c6fd3f059202e6ca82b
2023-12-08 20:15:27 +00:00
Qian-Hao Huang
3e5743c521 Revert "usb: introduce UsbDataSessionMonitor class"
Revert submission 25524752-usbDataSessionMonitor

Reason for revert: Test for gs101/gs201 boot blocking issue (b/314904288)

Reverted changes: /q/submissionid:25524752-usbDataSessionMonitor

Change-Id: I8265d57152460693fe668c2d9d188037dec6e692
2023-12-05 09:36:10 +00:00
Roy Luo
ea65ca11f6 usb: introduce UsbDataSessionMonitor class
Migrate the usb data session event functions to the class with the
following additional functionalities;
- Support detecting gadget soft pulldown (usually done during configfs
  function switch) and report usb data session correctly.
- Support reporting usb data compliance warnings to the class USB
  by providing getDataComplianceWarnings call.
- Use boot_clock instead of steady_clock to measure time correctly in
  the case of system suspend.

UsbDataSessionMonitor is self-contained and can be migrated to pixel usb
library after feature maturation.

Bug: 297224564
Bug: 296119135
Test: usb data session upload in device and host mode
Change-Id: Iba001933e193935d64cf5fd0a1257d02a4274fb1
2023-11-30 21:43:04 +00:00
RD Babiera
c92ee8d02a Merge "usb: reattempt to enter displayport alt mode if driver entry process fails" into main 2023-11-17 22:12:05 +00:00
RD Babiera
04d1e94d10 usb: reattempt to enter displayport alt mode if driver entry process fails
In the kernel, it is possible for the DisplayPort Alt Mode
driver to queue an Enter Mode message to the tcpm and have
that message be interupted by a Power Role or Vconn swap,
which results in the Port Partner never entering Alt Mode.

Add a debounce that checks to make sure that the port partner
enters Alt Mode when DisplayPort Alt Mode is active on the
port. On trigger, reattempt to send Enter Mode through the
tcpm up to 2 times.

Test: Manual test on device - put device into Preferred
      Source role, test to see if Alt Mode reentry triggers
      when original entry is interrupted by PR Swap from
      monitor.
Bug: 308383356
Change-Id: I96563c9900a01e428850e4873371bcdb0225aa07
Signed-off-by: RD Babiera <rdbabiera@google.com>
2023-11-15 22:08:36 +00:00
Roy Luo
c55415c1e2 usb: update usb hal version to v3
Bug: 308700954
Test: atest vts_treble_vintf_vendor_test
Change-Id: I724a170a1403dec7eecbc33d7f532471f09b559f
2023-11-14 20:41:47 +00:00
Roy Luo
398ceca7a9 usb: update incompatible charger warning reason
Report COMPLIANCE_WARNING_INPUT_POWER_LIMITED instead of
COMPLIANCE_WARNING_OTHER to flag incompatible chargers. The underlying
logic that generates the warning remains the same, what's changed is
the enum that's being used.
The purpose of the change is to have a warning type that better
represents what actually happens and free up COMPLIANCE_WARNING_OTHER
that was intended to act as a fallback reason code.
The flag enable_input_power_limited_warning controls whether to switch
to the new enum, while the flag enable_usb_data_compliance_warning
controls the new enums that are added as FlaggedApi in the framework.
Both flags need to be on to enable the change.

Bug: 308700954
Test: manual tests with local flag override
Change-Id: I6595706d1b83d533fc2d3e29086773270e045ede
2023-11-09 19:11:32 +00:00
Jacky Liu
a3772510e6 Update i2c pathes with new static i2c bus numbers
Bug: 305242309
Test: Boot to home
Change-Id: I87687b2e3a479a166257ad958ddd07af7967f416
2023-10-23 14:17:22 +08:00
RD Babiera
5cc2bfebf4 Merge "usb: enable/disable displayport alt mode through enableUsbData" into main 2023-10-13 21:23:38 +00:00
RD Babiera
9233142080 Merge "usb: check for port partner Thunderbolt capability" into main 2023-10-05 23:09:55 +00:00
Roy Luo
ccb35c81ff Usb: capture and upload Suez metric VendorUsbDataSessionEvent
Upload metrics for the last data session that just ends upon
data role changes. The change is purely metric collection and
does not change any business logic.

Bug: 297224564
Test: Trigger metric upload for both host and device mode and
      verify it by statsd_testdrive
Change-Id: I823ae8712b7914cfc7f6c6379acb3749d13c0974
2023-10-04 20:01:38 +00:00
Roy Luo
03fd3d9a37 Merge "usb: upgrade stats AIDL to v2" into main 2023-10-03 20:49:36 +00:00
Roy Luo
5aa4f0519f usb: upgrade stats AIDL to v2
Upgrade stats AIDL to v2 following pixelstats lib.

Bug: 297224564
Test: Build
Change-Id: Ia9837a8ea568c788a1a6044ff37c05172c019c2d
2023-10-02 18:53:56 +00:00
RD Babiera
873766c6f0 usb: check for port partner Thunderbolt capability
Query the port partner's SVIDs when the DisplayPort driver sysfs
is not recognized so that the USB HAL can identify whether or not
the port partner supports Thunderbolt.

Test: manual verification on device - test to see that cableStatus
is set to NOT_CAPABLE on hub that supports Thunderbolt but not
DisplayPort Alt Mode. Then verify that device not capable of being
a DisplayPort sink but does support Thunderbolt does not trigger
this status.
Bug: 288150501
Change-Id: Iaba60ecc5510acecee1e1d3241611906c738a263
Signed-off-by: RD Babiera <rdbabiera@google.com>
2023-09-21 18:28:50 +00:00
Treehugger Robot
2c8f57245a Merge "Usb.cpp: Fix typos when unable to disable USB data" into udc-qpr-dev am: 16d00110ec am: 05f20fefad
Original change: https://googleplex-android-review.googlesource.com/c/device/google/zuma/+/24799970

Change-Id: Ifd028d32242e88a8c9e327f303bdbd2c75df8dab
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-21 11:31:00 +00:00
Treehugger Robot
16d00110ec Merge "Usb.cpp: Fix typos when unable to disable USB data" into udc-qpr-dev 2023-09-21 09:55:00 +00:00
RD Babiera
05cedc1314 usb: enable/disable displayport alt mode through enableUsbData
Adds functionality for enabling and disabling DisplayPort Alt Mode
on the port through enableUsbData in the USB HAL to comply with USB
restrictions for heightened security mode.

Test: manual test on device - use enableUsbData dumpsys command to
      turn off DisplayPort and then turn it back on while connected to a
      partner sink.
Bug: 297208252
Change-Id: I9f071bce802b728f2229abc08efb2204e4c2505a
Signed-off-by: RD Babiera <rdbabiera@google.com>
2023-09-20 19:52:07 +00:00
Amit Sunil Dhamne
5454adc8dc Merge "UsbGadget: Update SDP enum timeout when gadget is pulled up" into udc-qpr-dev am: 5d78a3f43b am: e4486f9834
Original change: https://googleplex-android-review.googlesource.com/c/device/google/zuma/+/24805490

Change-Id: I51613d9969e34619e433479e7fe2eae42ec5a88b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-20 18:38:16 +00:00
Amit Sunil Dhamne
e683802386 UsbGadget: Update SDP enum timeout when gadget is pulled up
Indicate to the kernel that the usb gadget is pulled up
by writing to `update_sdp_enum_timeout` sysfs node. Write
to this node will inform the kernel that it can lower the SDP
timeout alarm value which is used to detect an SDP port
vs a DCP.

(ported from c5c5b127a7ed0db559d286284fe77b656bef6945)

Bug:275687235
Test: Check `update_sdp_enum_timeout` is written into after usb
     gadget is pulled up. Verify that the alarm timeout lowers.
Change-Id: Id3ae7e7a20b236cec6604414a7f81860e868bdd0
Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
2023-09-19 13:45:30 -07:00
Kuen-Han Tsai
3ce6a5fe2e Usb.cpp: Fix typos when unable to disable USB data
If Usb.cpp cannot write a zero value to the USB_DATA_PATH file, display
the message of "Not able to turn off usb connection notification".

Test: refactoring CL. Existing tests still pass.
Bug: 301016122
Change-Id: I5d2c24154bd1d2c20810bcb4db0a3b2cc575fcfe
2023-09-19 17:03:16 +08:00
Jayant Chowdhary
969c01c3f2 Merge changes from topic "webcam-shusky" into udc-qpr-dev
* changes:
  usb gadget: Add config for UVC in init
  UsbGadget: Add support for UVC function
2023-09-07 19:38:53 +00:00
Avichal Rakesh
b75f286a74 UsbGadget: Add support for UVC function
UVC is a new USB function supported in Android. This CL adds UVC as a
valid function and gives it a new pid of 0x4ee[de]. UVC function is
guarded by the property `ro.usb.uvc.enabled`. When this property is set
to false, UVC won't be considered as a valid gadget function.

Bug: 242344221

Test: Manually tested that the UVC function is successfully configured

Merged-In: I5c2040a84ee8360b16c955403478d908fe109121
Change-Id: I5c2040a84ee8360b16c955403478d908fe109121
Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
2023-09-06 20:51:36 +00:00
Avichal Rakesh
5749b85397 UsbGadget: Add support for UVC function
UVC is a new USB function supported in Android. This CL adds UVC as a
valid function and gives it a new pid of 0x4ee[de]. UVC function is
guarded by the property `ro.usb.uvc.enabled`. When this property is set
to false, UVC won't be considered as a valid gadget function.

Bug: 242344221
Test: Manually tested that the UVC function is successfully configured
Change-Id: I5c2040a84ee8360b16c955403478d908fe109121
2023-09-06 13:33:49 -07:00
RD Babiera
c2c37bf3a8 usb: populate USB aidl hal AltModeData
Populates AltModeData within PortStatus with DisplayPort
Alt Mode statuses for pin assignment, hpd, link training
status, and port partner capability.

Test: manual test on device
Bug: 277466852
Change-Id: I52a56f7090ed6dbef6211f19d6350cecac58e4fa
Merged-In: I52a56f7090ed6dbef6211f19d6350cecac58e4fa
2023-09-02 00:07:22 +00:00
RD Babiera
cabe846a1f usb: populate USB aidl hal AltModeData
Populates AltModeData within PortStatus with DisplayPort
Alt Mode statuses for pin assignment, hpd, link training
status, and port partner capability.

Test: manual test on device
Bug: 277466852
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:24f5f802bd37040e62de4f111b4c4f73c2ae8db4)
Change-Id: I52a56f7090ed6dbef6211f19d6350cecac58e4fa
2023-09-01 23:51:27 +00:00
Roy Luo
a6462edbe3 Usb: Listen to USB sysfs attribute for device state
Poll the sysfs attributes that represents usb device state in
either of the following states: not attached, powered, default,
addressed, configured.
The information is useful in detecting non compliant USB cable,
which will be supported in later patch sets. This patch lays
the ground work to monitor the sysfs attributes in both device
and host modes.
The thread to poll uevent is re-used to poll sysfs because this
serialize type-C port events and usb device state changes, hence
prevent potential races.
Added a thin abstration layer and a map to keep epoll data so
that it's easier to dynamically add/delete files to epoll, which
is needed for usb devices in host mode.

Bug: 285199434
Test: trigger usb device state changes in device and host mode
Change-Id: Ie5389d051deb28dbb486c2f27319b3cc9e89312f
2023-08-08 23:14:37 +00:00
RD Babiera
78f6294e38 Usb: shutdown old displayport poll thread when multiple start up
Better enforces that only one DisplayPort poll thread should be
active at once. If a new call to setup is made from additional
bind uevents before a disconnect occurs, tells the old thread
to shutdown and awaits signaling before a new worker thread spins
up.

Test: manual testing on device
Bug: 286593610
Change-Id: I1707970c500915fd4abb161d0b3a424bbb2bddca
2023-06-15 23:26:09 +00:00
Badhri Jagan Sridharan
574d046bd7 Usb: Check for displayport when booting
When booting check whether displayport driver has been probed and
signal hpd events as needed. Pin config and orientation needs to
be queried before signalling hpd.

Bug: 282223693
Change-Id: Iddb0921b363e49c41c0f6f635887b4daf4d19561
2023-06-15 23:23:01 +00:00
Badhri Jagan Sridharan
378b155ab6 Merge "Usb: Signal irq_hpd to drm stack" into udc-d1-dev 2023-05-25 19:46:52 +00:00
Badhri Jagan Sridharan
412f31194c Usb: Signal irq_hpd to drm stack
Monitor typec stack for irq_hpd events and signal irq_hpd when the
irq_hpd counter value read is not the same as the previously cached
value.

Bug: 278307874
Change-Id: Id4a72afcf85550cabbc2f9469bb0ccb92cd02ad2
2023-05-25 04:36:06 +00:00
Badhri Jagan Sridharan
47e1400c8f Usb: Populate UsbDataStatus only when not populated
Do not override UsbDataStatus when already populated.
Compliance warnings such as missing Rp do not populate
UsbDataStatus and the port partner is detected.
Populate UsbDataStatus only when not populated.

Bug: 279251052
Change-Id: Ibe71bdd5c521ba90c124d89bd56af90087c0df18
2023-05-16 05:51:50 +00:00
Badhri Jagan Sridharan
e707356f6a Usb: Set connected status when connected to non compliant port partners
Set mode, power role and data role when connected to non compliant
port partners.

Bug: 268584498
Change-Id: I6c3e7df09a61e26f3b976a86bd65cb646edd653d
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
(cherry picked from commit 7c2d62aafc219af11252dabf49d84d84b7ccfa57)
2023-05-16 03:58:34 +00:00
RD Babiera
005049d207 Usb non-compliant port partner implementation
Adds vendor code for non-compliant charger feature. Currently
updates service version.

Minor port of  commit 96ccf93453583642a15dd96b1e4d6bf0645fc10b

Test: atest VtsAidlUsbTargetTest
Bug: 236322506
Change-Id: Ie1a48b1acaaae9a53f3b9bfebcfee7a2f4814810
(cherry picked from commit 96ccf93453583642a15dd96b1e4d6bf0645fc10b)
2023-05-16 03:58:30 +00:00
RD Babiera
4e29924d3d usb: Fix HAL build warnings related to DisplayPort
Adds proper error handling go-to points to remove warnings arising
from uninitialized variables, and removes unused
queryDisplayPortStatus() method.

Test: manual test on device, verify compiler warnings
Bug: 278951278
Change-Id: I54f7b710a0805b32c894d741e473d64814200134
2023-04-24 21:45:17 +00:00
RD Babiera
cc50d99508 usb: provide usb reference to DisplayPort shutdown thread
Passes usb object reference to thread creation of
mDisplayPortShutdownHelper so that it can properly call DisplayPort
shutdown method instead of calling on NULL reference.

Test: manual test on device
Bug: 278395605
Change-Id: Ie4dabb5e3ae9065f57cc0fbf2593fbe399097472
2023-04-17 22:43:31 +00:00
Treehugger Robot
5aa6158425 [conflict] Merge "usb: add all i2c number" into udc-d1-dev am: 6f1e1dca4a
Original change: https://googleplex-android-review.googlesource.com/c/device/google/zuma/+/22122384

Change-Id: I0a4b28d87efdfeb7629d0c3a36fde232f45cc3ec
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-04-11 04:24:17 +00:00
Chien Kun Niu
5bda84b517 usb: add all i2c number
Add all I2c number to change the permission

Bug: 273391794
Test: limit 1.3A work
Change-Id: Iefb44f37c5b42ae5579e928477efc927d270b724
2023-04-07 15:26:49 +08:00
RD Babiera
de0fc9d220 Port dp changes to drm sysfs
Write pin assignment, hpd, and orientation from type-c class to
drmdp platform device attributes using epoll when displayport
driver binds to device, and determine whether or not to shut down
epoll on displayport driver change uevents.

Test: manual testing with form factor device
Bug: 260915739
Change-Id: Iec9fc76166481a4611bb2fc023aea044b497f2c0
2023-04-03 22:16:17 +00:00
Chien Kun Niu
7946bd55e7 Merge changes If0925a61,I9d6624cb,I7cc7070d,I2c1091aa into udc-dev
* changes:
  Fix up open bugs from gs201 AIDL migration
  Add resetCb
  Migrate IUsbGadget implementation to AIDL
  usb: limit the current to 1.3A when connect to accessory
2023-03-02 06:59:25 +00:00
Ricky Niu
704316d8ba Fix up open bugs from gs201 AIDL migration
1. Remove unused group "wakelock".
2. Correct the right return value on setCurrentUsbFunctions.

Bug: 266694076
Test: Boot to home and function work
Change-Id: If0925a61e481e4deca560dc8dfc1be80a76c148f
(cherry picked from commit 5c7e338667a7f21c27f5789c16a4781dcbbe8755)
2023-02-22 06:50:55 +00:00