Commit graph

72 commits

Author SHA1 Message Date
Roy Luo
7fb2864005 usb: fix usb state path in host mode
USB_DUMMY_HCD is disabled in kernel 6.1, modify the usb state path in
host mode accordingly.

Bug: 388367091
Test: test on oriole
Flag: EXEMPT trivial bug fix
Change-Id: If85077fddcadd25d15777d4b1ff5be2a0528c253
2025-02-05 20:25:29 -08:00
Roy Luo
e61b680408 usb: migrate UsbDataSessionMonitor to libpixelusb
Use the libpixelusb version of UsbDataSessionMonitor.

Bug: 388367091
Test: test on oriole
Flag: EXEMPT CP
Change-Id: I93b74fc9bb63c260e900ee5af73e66fb1559142d
2025-02-05 20:25:29 -08:00
Kuen-Han Tsai
7ed8a55835 Usb: Add status check to prevent NPE
This patch prevents a Null Pointer Exception in
queryMoistureDetectionStatus() when getPortStatusHelper() fails to open
the /sys/class/typec file. The failure results in an empty
currentPortStatus vector, causing the NPE when accessing its first
element.

Bug: 361097811
Flag: EXEMPT bugfix
Test: NPE does not occur when getPortStatusHelper() fails
Change-Id: Id6886283d6f2f9179b3a9c5d535646874e9f277b
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
2024-10-09 15:14:38 +08:00
Roy Luo
2e1fd91321 Use absolute path for udc device
Avoid search in /sys/class/udc directory

Bug: 339241080
Test: tested on gs101
Flag: EXEMPT bugfix
Change-Id: Iad74cae0d6ad6887d79d705dc8478f1b44532503
2024-07-09 03:03:33 +00:00
Kyle Tso
c5a560160f 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>
(cherry picked from commit d17fdff5f81cff76adaa75d50f26318be8048123)
2024-06-13 17:12:20 +08:00
Kyle Tso
744c86c49a usb: Add retry on role switch
Bug: 341996696
Change-Id: I8caa65288af1588d24fea4aa6c5768d45d69bbd5
Signed-off-by: Kyle Tso <kyletso@google.com>
(cherry picked from commit ef5856a4474002cc35a51377adffddd4cb239796)
2024-06-13 17:12:10 +08:00
Dennis Shen
1b51d6b798 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: Ieab46eb2561f910be2bf016fe4c63062a4e31a66
2024-06-06 13:47:09 +00:00
Roy Luo
291642b702 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
(cherry picked from commit 9164eae7cdee032381d8bf045fbbed33f62b00bf)
2024-01-10 11:47:27 +00:00
Roy Luo
1376a71a65 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:33:58 +00:00
Roy Luo
350dc9f41a 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:33:49 +00:00
Roy Luo
bedb8beca9 Revert^2 "usb: introduce UsbDataSessionMonitor class"
1aad6b6b31

Bug: 297224564
Bug: 296119135
Change-Id: I9ecf85f4e4b22d7d3bf2402c7f7299b38582bde9
2023-12-09 00:22:03 +00:00
Qian-Hao Huang
1aad6b6b31 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: I6070b8bf441cc84e0744e2f0ecf454d4245cb686
2023-12-05 17:13:31 +00:00
Roy Luo
67556c182a 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
(cherry picked from commit ea65ca11f6fbb6f13b89ef9ed03015f47ec1cedb)
2023-12-01 16:43:41 +00:00
Roy Luo
725438e40e usb: update usb hal version to v3
Bug: 308700954
Test: atest vts_treble_vintf_vendor_test
Change-Id: Ifa30881c9c2ed3a4d0064511a955edec3f7c5fe6
2023-11-14 20:44:30 +00:00
Roy Luo
f23c69b257 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 22:55:07 +00:00
Roy Luo
653f31663d 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.
This is a direct CP from ag/24816727

Bug: 297224564
Test: Trigger metric upload for both host and device mode and
      verify it by statsd_testdrive
Change-Id: I823ae8712b7914cfc7f6c6379acb3749d13c0974
(cherry picked from commit ccb35c81ff0bbfb013136bae7a572280b196bd1a)
2023-10-05 23:49:40 +00:00
Roy Luo
bf5ca96192 usb: upgrade stats AIDL to v2
Upgrade stats AIDL to v2 following pixelstats lib.

Bug: 297224564
Test: Build
Change-Id: I3b68c8ed3ff7ff96c185c8f990b03acabb64e3ad
2023-10-03 20:49:32 +00:00
Will McVicker
b54d8f91e3 usb: Update Usb and UsbGadget i2c logic
Update the logic to find the i2c bus number to use either the named i2c
devices or the static i2c bus numbers. This allows us to support both
cases -- v5.10 uses i2c-<devname> while v6.1 uses <i2c-bus#>-<reg>.

Bug: 291606723
Test: verify no errors from the usb services with v5.10 and v6.1
Change-Id: I6d41ac041ead68e72a3766e03d491bcd478468d3
2023-10-02 16:28:59 +00:00
Will McVicker
b1662cade2 init: update i2c bus numbers and move initialization to ueventd
Update the i2c bus numbers to use the statically assigned numbers
configured in the kernel device tree. In addition, use ueventd to set
the ACL for the i2c devices.

Bug: 291606723
Test: performance boot testing
Test: verify selinux labelling with ls -Z on the modified device nodes
Change-Id: Ib412510e4b6c086c978ad5487486323685732cae
2023-10-02 16:28:59 +00:00
Roy Luo
7bd4fdd98f Revert "init: update i2c bus numbers and move initialization to ..."
Revert submission 24855741-gs101-i2c-bus-fixes

Reason for revert: DroidMonitor-triggered revert due to breakage https://android-build.corp.google.com/builds/quarterdeck?branch=git_main&target=bluejay-trunk_food-userdebug&lkgb=10876543&lkbb=10876988&fkbb=10876587, bug b/302549624.

Reverted changes: /q/submissionid:24855741-gs101-i2c-bus-fixes

Change-Id: I1c87ea91d0a2eaf441c554b8f4729cefd0eca068
BUG: 302549624
2023-09-28 18:00:06 +00:00
Roy Luo
dae6f56edd Revert "usb: Update Usb and UsbGadget i2c logic"
Revert submission 24855741-gs101-i2c-bus-fixes

Reason for revert: DroidMonitor-triggered revert due to breakage https://android-build.corp.google.com/builds/quarterdeck?branch=git_main&target=bluejay-trunk_food-userdebug&lkgb=10876543&lkbb=10876988&fkbb=10876587, bug b/302549624.

Reverted changes: /q/submissionid:24855741-gs101-i2c-bus-fixes

Change-Id: I63de07348d45bd1a75e73da01f8ee402982cac30
BUG: 302549624
2023-09-28 18:00:07 +00:00
Will McVicker
901548943c usb: Update Usb and UsbGadget i2c logic
Update the logic to find the i2c bus number to use either the named i2c
devices or the static i2c bus numbers. This allows us to support both
cases -- v5.10 uses i2c-<devname> while v6.1 uses <i2c-bus#>-<reg>.

Bug: 291606723
Test: verify no errors from the usb services with v5.10 and v6.1
Change-Id: Ia68c424a3b6579457be6cfd0d07788e9da44a86e
2023-09-28 16:08:00 +00:00
Will McVicker
d9c462fc17 init: update i2c bus numbers and move initialization to ueventd
Update the i2c bus numbers to use the statically assigned numbers
configured in the kernel device tree. In addition, use ueventd to set
the ACL for the i2c devices.

Bug: 291606723
Test: performance boot testing
Test: verify selinux labelling with ls -Z on the modified device nodes
Change-Id: I579143fa38bc2e9b3bf7dc618b10e63001263e2e
2023-09-28 16:08:00 +00:00
Kuen-Han Tsai
0c36feb52e Usb.cpp: Fix typos when unable to disable USB data am: b6dd753059 am: 46915051db
Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs101/+/24797931

Change-Id: I4a7d6a96cde3e3fb14d9464c82326b8dc222e459
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-21 11:31:00 +00:00
Kuen-Han Tsai
b6dd753059 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: I0c5b7c4dc5bfe21ba17058536b5014eb5d69d1f3
2023-09-21 09:54:59 +00:00
Amit Sunil Dhamne
6426420d08 UsbGadget: Update SDP enum timeout when gadget is pulled up am: ed622856fc am: 00a104bf12
Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs101/+/24805164

Change-Id: Ib12e1725b92ea2fa30350e584fcecf3ae0b1f270
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-20 18:38:06 +00:00
Amit Sunil Dhamne
ed622856fc 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-20 16:24:59 +00:00
Roy Luo
381adb1243 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-23 19:38:58 +00:00
Badhri Jagan Sridharan
cac33c008f 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
(cherry picked from commit 47e1400c8fef8af1aea985795d7adfe3ff16871b)
2023-05-17 23:45:55 +00:00
Badhri Jagan Sridharan
4c74d00f98 Revert "usb: Temporarily disable compliance warning"
This reverts commit f178319b4a.

Bug: 279251052
Change-Id: Ic67b94da213357af05a5c6e14e15946a02af7fba
2023-05-17 23:45:55 +00:00
Kyle Tso
f178319b4a usb: Temporarily disable compliance warning
Revert me once the issue is fixed.

Bug: 278018111
Change-Id: I198c4a42aa8b64fef90817474710295d68497dda
Signed-off-by: Kyle Tso <kyletso@google.com>
2023-04-22 10:04:39 +00:00
Chien Kun Niu
6ef77dd8f0 usb: hal: add all the i2c nodes for tcpc functions
This change is to add all the possible i2c nodes for tcpc functions with the correct permission, due to the path may change with different android version.

Bug: 273391794
Test: limit 1.3A work when connect to Head Unit
Change-Id: Iefb44f37c5b42ae5579e928477efc927d270b724
2023-03-21 05:14:33 +00:00
Xiang Wang
bc295aae91 Move thermal utils to hardware/interfaces
Bug: b/269370789
Test: m
Change-Id: I49b3b4ebabf124093851ad768ff106e9bdf30873
Merged-In: I49b3b4ebabf124093851ad768ff106e9bdf30873
2023-02-23 04:29:33 +00:00
Xiang Wang
db54aa1217 Update USB HAL clients to use Thermal stable AIDL
Bug: b/264594715
Test: boot test
Change-Id: I0d633a83224d928c888e53e54b375fcd5c3d4010
2023-02-14 22:24:23 +00:00
Badhri Jagan Sridharan
38a132ae24 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>
2023-02-13 23:12:04 +00:00
Ricky Niu
744f214f40 Add resetCb
Add the resetCb to complete asynchronous

Bug: 267252826
Test: Boot to home and function work
Change-Id: I9d6624cbe15c86c63e28f8f176d7c560aed8446f
2023-02-09 02:02:50 +00:00
Ricky Niu
b77191c0fa Fix up open bugs from gs101 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
2023-02-07 07:30:48 +00:00
Avichal Rakesh
eafdae6687 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: I5ba45ebb11d265b843dfde21407bc5bab1d070c9
2023-02-06 21:20:59 +00:00
Ricky Niu
5b86b2fb5f Use AIDL utils in GadgetHAL
Test: Built locally, and logcat confirms the new implementation is used
Bug: 218791946
Change-Id: I4122450326864de268f3908d920a1ffa472f3d7d
2023-01-19 17:40:18 -08:00
Ricky Niu
6b863d5b74 Migrate IUsbGadget implementation to AIDL am: d6d0b7d2ca am: a912032b9d am: 7d8c7aa768
Original change: https://android-review.googlesource.com/c/device/google/gs101/+/2361897

Change-Id: I5a35d64da039e377cb77d984fc752ffca9d6464e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-01-12 08:30:04 +00:00
Ricky Niu
d6d0b7d2ca Migrate IUsbGadget implementation to AIDL
This change migrates IUsbGadget implementation to AIDL.

Bug: 261027750
Test: USB function switch success and AIDL service is running.
Change-Id: I7cc7070d875c26bc42f99aef84d5e5a41606223f
Signed-off-by: Ricky Niu <rickyniu@google.com>
2023-01-07 15:39:44 +08:00
Chien Kun Niu
3507989979 Revert "Migrate IUsbGadget implementation to AIDL"
This reverts commit bbcd013c41.

Reason for revert: Increase the boot time to cause the below bug.
b/261027750 | P0 | Broken test: v2/android-perfetto-dev-team/apct/perfetto/perfetto_integrationtests on git_master on oriole_hwasan-userdebug at 9355690

Change-Id: Idba7322ca86e70cf5d8e170936696586caa8c1c2
2022-12-07 03:56:16 +00:00
Ricky Niu
bbcd013c41 Migrate IUsbGadget implementation to AIDL
This change migrates IUsbGadget implementation to AIDL.

Bug: 218791946
Test: USB function switch success and AIDL service is running.
Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: Ib2cff64e75608572a005933bc94ecaf128b85559
2022-12-01 04:30:22 +00:00
RD Babiera
96ccf93453 Usb non-compliant port partner gs101 implementation
Adds vendor code for non-compliant charger feature. Currently
updates service version.

Test: atest VtsAidlUsbTargetTest
Bug: 236322506
Change-Id: Ie1a48b1acaaae9a53f3b9bfebcfee7a2f4814810
2022-11-30 01:39:11 +00:00
badhri
803bb5c4f4 Set powerBrickStatus to not connected when sourcing power
Bug: 239755044
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: I7720bfaa5876c058643c52525b488ba22b3e5121
2022-07-22 02:31:35 +00:00
Jimmy Hu
11f2c88795 Write the pullup value only if new value applied
Bug: 226018845
Test: build, boot
Signed-off-by: Jimmy Hu <hhhuuu@google.com>
Change-Id: I64a964753fc89a29d278f1c426b2746abc2a2b12
2022-05-26 02:42:33 +00:00
Ricky Niu
ebd7fca53a usb: limit the current to 1.3A when connect to accessory
For imporve USB stability, limit the current to 1.3A,
when connect to accessory.

Bug: 206635552
Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I2c1091aa7111e6242cc949923fbc86f27e54e976
2022-05-21 15:35:34 +00:00
Ray Chi
ba3dc9b3da tune usb irq (dwc3) in usb gadget hal
Since affinity permission is changed from root to system, original
permission change by script can't be used. Therefore, this patch
will move the functionality to usb gadget hal.

Bug: 224699556
Test: dwc3 irq could be located in medium/big cores after USB function switch
Change-Id: Id993db9fc303e85a9a6337a0e41b1dfd6fc9a86a
Merged-In: Id993db9fc303e85a9a6337a0e41b1dfd6fc9a86a
(cherry picked from commit f363704a92fd7611cf01c8b3bcaf6e8913255207)
2022-05-05 07:08:19 +00:00
Ray Chi
7da5d4f43f usb: move the permission change to usb rc
Since permission change in hal rc may be late, gadget
hal would enable USB function failed. The solution will
change the permission before USB gadget hal starts.

Bug: 224699556
Test: build pass and verified pass
Change-Id: I45c1318f647220480fa03ba3b813a81b21393d71
Merged-In: I45c1318f647220480fa03ba3b813a81b21393d71
(cherry picked from commit b30924e3599f2e92aeae498a6ae15d3b9a397930)
2022-05-05 07:08:19 +00:00
chungkai
deca07793f init: modify path of i2c peripherals
add potential paths when enable parpllel module loading

Test: build pass
Bug: 228181404
Signed-off-by: chungkai <chungkai@google.com>
Change-Id: I929669a2ddc9155ad4dac1f40f808ffcb4c914f2
2022-04-07 09:33:25 +00:00