Commit graph

42 commits

Author SHA1 Message Date
Jordan Yates 07870934e3 everywhere: replace double words
Treewide search and replace on a range of double word combinations:
    * `the the`
    * `to to`
    * `if if`
    * `that that`
    * `on on`
    * `is is`
    * `from from`

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-22 05:40:22 -04:00
Michał Barnaś 0b4365ef29 usbc: add support for TCPC control of vbus sourcing
Adds calls to the set_src_ctrl of TCPC driver to enable and disable
the VBUS sourcing. If the TCPC doesn't support these functions,
no errors should be printed.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2024-06-12 18:17:17 -04:00
Fin Maaß 7d83a8a68a lib: smf: constant number of arguments for SMF_CREATE_STATE()
This sets the number of arguments for SMF_CREATE_STATE() to always
be the same, independent of the selected Kconfig options.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-05-07 17:46:21 +02:00
Fabio Baltieri 1c9be802bc usbc: fix shadowed declaration build error
Fixes:

/__w/zephyr/zephyr/subsys/usb/usb_c/usbc_tc_src_states.c:260:21: error:
declaration of 'ret' shadows a previous local [-Werror=shadow]

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-18 11:28:54 +00:00
Michał Barnaś 551c7654f5 usbc: integrate the PPC with the USB-C stack
Add calls to the PPC API that enables and disables the sink and source
paths in the appropriate USB-C stack states.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2024-01-18 10:53:53 +01:00
Michał Barnaś 6fc22462a3 usbc: add sleep prevention in places that may require it
Add sleep prevention in crucial USB-C stack functions to make
state transitions faster and to send responses faster.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-23 10:33:38 +02:00
Michał Barnaś 2aabcabad3 usbc: add function that prevents the USB-C stack from sleep
Add internal function that prevents one sleep of the USB-C stack.
It can allow to have longer sleep times to conserve more power, while
still having possibility to respond in the required time and
set specific registers.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-23 10:33:38 +02:00
Michał Barnaś 3848e4c023 usbc: add checks for results of TCPC functions
This commit adds checks for results and in case of error, handles it.
The failed initialization of the TCPC can postpone initialization in
case the TCPC needs more time after powering up. Otherwise if other
error happened, the Type-C Layer will be disabled.
Errors in other places of the USB-C stack, like communication errors,
moves the state machine to the error recovery, restarting the
communication with parner.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-20 14:57:32 +02:00
Michał Barnaś fe0b6af337 usbc: merge the is_rx and get_rx_pending_msg functions
These two functions are used together so there is no need for
splitting them into two functions. This commit also makes this
function required to be implemented by the TCPC driver.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-20 14:57:32 +02:00
Michał Barnaś 793d29d23f usbc: check if setting the CC and VCONN was successful
This commit adds check in cc_open entry state and logs if setting
either of the values were unsuccessful.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-20 14:57:32 +02:00
Michał Barnaś cff8bb2687 usbc: check if sampling CC lines were successful
When the get_cc function returns error, the CC lines should be
considered as open. It may happen either due to some chip malfunction
or chip going into sleep mode and needing time to reinitialize.
TCPC should only go to sleep if there is no partner attaches, so
in case of this error, the lines should be considered as disconnected.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-20 14:57:32 +02:00
Michał Barnaś 0f4eb42c97 usbc: check if message is pending before trying to receive it
If TCPC supports checking for pending messages, it should be done
instead of forcefully trying to read the message and getting no-data
result. This helps with powereficiency for chips that go to sleep
when there is no message pending. Trying to read the message can
wake up the chip providing higher power usage.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-20 14:57:32 +02:00
Michał Barnaś 216bc4db73 usbc: add check if tcpc initialization was successful
The TCPC driver initialization can be unsuccessful and it should be
checked and logged if that's the case.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-20 14:57:32 +02:00
Michał Barnaś 88b6fc62d5 usbc: change type for functions that may return error code
TCPC API functions should be able to inform the caller if the function
is supported and successfully executed. Bool values doesn't allow this
so it is needed to change the type to int.
For is_rx_pending_msg function the return code should conform to
existing error codes, so in case of function being not supported,
the -ENOSYS should be returned. In case of successful execution,
if there is no pending message, the -ENODATA should be returned and
in case of message pending, the value of 0.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-10-20 14:57:32 +02:00
Michał Barnaś 9608c8f667 usbc: fix conflicting Kconfigs for USB-C related init priority
There was a new Kconfig for USB-C init priority that is conflicting
with currently used Kconfig for init of VBUS and TCPC.
This commit changes the names to more specific related to the subsystem
they belong to.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-09-20 11:26:40 +01:00
Gerard Marull-Paretas 011321f0cf usb: usb_c: use POST_KERNEL level
Usage of application level for device drivers needs to be avoided. Also
introduced a new init level, with default to 90 as other dependencies of
USB-C run at priority 80.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-09-15 16:04:19 +02:00
Madhurima Paruchuri a19d905cc4 USB-C: genVIF: Cleanup and add support to pick static data from input
Removed few VIF properties which are being hardcoded
Updated the script to parse source VIF XML and add information to
the output
Added optional Kconfig option to configure custom source VIF XML path
Cleaned up the code

Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
2023-05-26 13:54:43 -04:00
Sam Hurst 0056249a13 usb-c: Add USB-C Subsystem Source PD Support
Add USB-C Power Delivery Source Support to USB-C
Subsystem

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-04-28 10:06:01 +02:00
Sam Hurst cb9a250579 usb-c: Refactor soft reset code
Refactor soft reset code

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-04-28 10:06:01 +02:00
Sam Hurst 3851d3648d usb-c: Properly detect reception of first AMS message
Detect and flag the reception of the first AMS mesage

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-04-28 10:06:01 +02:00
Sam Hurst d1cf8148cc usb_c: Transmit Error are not Protocol Errors
Transmit errors must be treated differently than Protocol Errors.
This change sets a flag that informs the stack of a Message
Transmit error.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-04-28 10:06:01 +02:00
Michał Barnaś e0fbd35fc0 usbc: explicitly declare sizes of state machines arrays
The asserts in the USB-C stack functions were causing compilation
errors when asserts were enabled in Kconfig.
This was caused because the asserts checked if the functions
parameters were within limits specified by the state machine arrays.
At the position of these asserts, these arrays were only declared
without specifying the size of them, what prohibited the asserts from
knowing the size of arrays and checking if specified value is within
limit of it.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-03-03 09:17:11 +01:00
Sam Hurst df117e563a usb_c: Add super state to handle Sender Response Timer
Any Power Delivery message state that expects a reply must
start a sender response timer. This change addes a super
state that implements the Sender Response Timer
functionality, from which Power Deleiver messages states
can inherit from.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-02-21 18:04:04 -05:00
Sam Hurst 2d510fef8d usb_c: Notify DPM of Unsupported message reception
Notify the Device Policy Manager when an unsupported
message is received.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-02-20 11:24:07 +01:00
Sam Hurst ee9903005a usb_c: Refactor Sink common code
Move non-sink specific code into common code

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-20 12:17:44 +01:00
Sam Hurst d9c4ec31fc usb_c: Fix comments before "else" statements
Move comments that precede an "else" into the "else"
statement.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-11 18:55:18 +01:00
Sam Hurst f84ee58abd usb_c: Add protocol error flag
Use a flag to report a protocol error to the states. This keeps
state specific actions in the state. Currently, those state
specific actions are handled in the pe_report_error function.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-11 18:55:18 +01:00
Sam Hurst 983b693198 usb_c: Stop chunking_not_supported timer on exit
Stop chunking_not_supported timer on exit

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 0ed5c886c9 usb_c: Remove unnecessary PE_FLAGS_PROTOCOL_ERROR flag
Remove unnecessary PE_FLAGS_PROTOCOL_ERROR flag

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 77c7a51e4d usb_c: Remove unnecessary code from PE_Send_Soft_Reset
Remove unnecessary code from PE_Send_Soft_Reset

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 3af2752680 usb_c: Transition to Sink Ready on sender response timeout
Transition to pe_snk_ready state from pe_drs_send_swap_run,
on sender response timeout

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 24e18d46f1 usb_c: Properly handle Protocol Errors during DRS
From 8.3.3.4.2.1 PE_SNK_Send_Soft_Reset State, Error Recovery
should be performed if a Protocol Error happens during a Data
Role Swap.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst c27a3a31d3 usb_c: Fix DPM request handlers
Processing the common DPM request handler in the
Sink DPM request handler.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst f04da7f7ab usb_c: Check state machine array of states
Build time check that the number of states initialized
in the state machine array matches the number of enums
used to index said array.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 5b3155ff90 usb_c: Use atomic arrays for PE flags
Use atomic arrays for PE flags because the total number
of Policy Engine flags could exceed 32

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 914fed36d5 usb_c: run clang-format
Run clang-format

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Sam Hurst 7910c617be usb-c: Refactor USB-C Subsystem Sink
Refactor USB-C Subsystem Sink so that Power Delivery
Source support and be easily added.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2023-01-05 10:34:06 +01:00
Madhurima Paruchuri fa738b0f74 usb-c: Generate USB-C connector VIF policies XML file
Generates XML file containing VIF policies by reading the device tree
using EDT.pickle generated during build
This script writes a subset of general and sink-pdo VIF policies in
output file
This script gets invoked during build if enabled through kconfig
The generated XML containing USB-C VIF policies could be used by
USB PD/Type-C analysers/testers to understand USB-C properties and
perform tests accordingly

Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
2022-12-02 08:46:04 -06:00
Sam Hurst 37e6f15f34 usb-c: Fix unsupported message reporting
When operating in PD2.x mode, PD_CTRL_REJECT should be
transmitted to the port partner when an unsupported message
is received.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2022-11-08 10:46:40 +01:00
Sam Hurst c2677cef57 usb-c: Correct spelling error in comment
Correct spelling error in comment

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2022-10-27 11:00:14 +02:00
Sam Hurst cc393f24af usb-c: Fix policy callback function assertion
Fix the assertion check that's performed on a non-existing
callback.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2022-10-27 11:00:14 +02:00
Sam Hurst e90f1b66d8 usb-c: Add USB-C Subsystem with Sink PD Support
This USB-C Subsystem enables an application to include
USB-C Power Delivery Sink functionality.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
2022-10-22 18:38:35 -04:00