Some platforms doesn't support PD3.0 as source and only
PD2.0 needs to be supported as source. Else might see dp over
usb functionality not working as expected. Fix this by adding
support for PD2.0 only as source.
Change-Id: I39d5f008871e0914c4ca757e03fa4938f5d574a0
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Consider a case where the device has initiated dr_swap to
the connected PD charger to support type-C headset and charging
concurrently. If the charger got disconnected at the same time
when the driver was trying to change the data role then
send_dr_swap flag will be set during disconnect. Upon next connect,
since the flag is already set, the driver will not set the current_pr
to sink and the PD state machine will not kick in causing the charger
to be detected as DCP. Fix this by resetting the pd protocol during
cable disconnect which will clear the flags.
Change-Id: I282986b9d6df37a74d65eb80c1ebc5510add7fe9
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
Consider a scenario where a connected PD partner has sent an
alert message to the device and driver marked send_get_status
to true and queued usbpd_sm work with a delay of 150ms. Now,
if the cable gets disconnected before the start of usbpd_sm
work then send_get_status flag will not get cleared anywhere.
On the next cable plug-in, in PE_SNK_READY driver will
unnecessarily send Get_Status again which is incorrect and
may lead to soft/hard reset causing the PD partner to disconnect.
Fix this by clearing the send_get_status flag in the protocol reset.
Change-Id: I4747b0a25a0870e83ff78e0b9ccd7e3fd91ed9e6
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
It is required to restart usb host mode in high speed on platforms not
supporting usb3 ss and DP concurrency. Hence add required support to
restart host mode in high speed for those platforms, when dp is
detected through discovery of svids.
Change-Id: I1bbd9679b9354828d751ed74ef5d99cb8541e698
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
After soft reset is done from PE_SRC_SEND_CAPABILITIES use
break to exit from the switch case instead of returning from
the function.
Change-Id: I36e3f34cf90b6620dd6ac8b9c9a503cf336e47c5
Signed-off-by: Rohith Kollalsi <rkollals@codeaurora.org>
When receiving an SVDM with an unsupported version, we should
still send a response with the highest version we support,
rather than dropping the packet outright. Also update the
outgoing SVDM version field to 1 (2.0) if operating in PD3 mode.
Change-Id: I0bafb619e0ac16bc45064ef699870b0c03b52b47
Signed-off-by: Jack Pham <jackp@codeaurora.org>
If connected to a sink that we already know is PD capable, the
next time Source Capabilities is sent, whether due to reset or
in response Get_Source_Capabilities, upon failure should not
retry for nCapsCount times. Instead, simply issue a Soft Reset.
Change-Id: Ia45600f013555814c008edf60e0daf599d9f9dee
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
Signed-off-by: Rohith Kollalsi <rkollals@codeaurora.org>
In a scenario where the device has failed to send ACCEPT
for a DR_SWAP request within tSenderResponse, it's port
partner does not swap it's own role. But this device goes
ahead and sends ACCEPT and also swaps it's data role
leading to an invalid state where both the port partners
are in the same data role. And the port partner treats
this ACCEPT as an invalid message and issues a soft
reset.
Fix this by not sending an ACCEPT after the tSenderResponse
(with a buffer) from receiving a DR_SWAP request and
preventing from switching the data role.
Change-Id: I77a48acd876459b64b97ae18515069ae6218e8b6
Signed-off-by: Sriharsha Allenki <sallenki@codeaurora.org>
The flag was introduced to support board designs where the PMIC's
VCONN input was connected directly to VBUS, and to prevent damage
to the Type-C connector if VBUS was greater than 5V. This is no
longer recommended to do in current and future board designs, so
remove this flag and associated checks as we are safe to enable
VCONN independently of what VBUS is operating at.
Change-Id: I7697947e590f9e1eaf6958ebd157dbc41a8c5cdc
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Signed-off-by: Chandana Kishori Chiluveru <cchiluve@codeaurora.org>
Currently, charger daemon requesting get_src_cap_ext request back to back,
resulting in too many PD messages from userspace to handle get_src_cap_ext.
There is a case where phy_msg_received() for SOURCE_CAPABILITIES_EXTENDED
and sm_work is queued to handle the response. Meanwhile userspace daemon
requested for select_pdo which will set the pd->send_request flag and
queue another sm_work immediately. But there is a possibility that
usbpd_sm work is still in running state to handle previous rx_msg received
for src_cap_ext. It will further checks for any pending out going requests
and try to handle it from from the same work hence state transition
to select_capability. In this state it will send the pd_msg for
SNK_SELECT_CAPABILITY and wait for response.
In this case the next sm_work has a deliberate delay such as waiting
for minimum 26msec of SENDER_RESPONSE_TIME, but the delay is effectively
eliminated and usbpd_sm gets executed immediately again which can cause
the state machine to think that timeout occurred and
will result in hard reset.
Hence fix this issue by exit the work after complete of src_ext_cap
so that it won't handle other pending outgoing requests from the
same work. Also handle this for other possible cases like PPS_Status,
Status, Battery_Capabilities and Battery_Status.
Change-Id: I586fbf50837c81b856eb30176564013e9bcde90f
Signed-off-by: Chandana Kishori Chiluveru <cchiluve@codeaurora.org>
Some Type-C multi-port adapters which do not support usb connection
are advertising the multi-functionality in DP alt mode. If
multi-functionality is preferred, the DP driver assumes the adapter
supports usb connection and USB phy driver will program the PHY mode
to DP+USB.
In source mode, usb PD driver checks for the peer_usb_connection
of the adapter. If it does not support usb then it will stop usb stack
and update the PHY MODE to USB only mode from phy_suspend path.
The result is, usb may program the combo PHY to usb only mode when DP
is already connected. This is causing AUX read/write timeouts when DP
is trying to access the phy registers.
To fix this issue, a flag in SVID connect handler in usbpd driver to
notify peer_usb_comm support to the DP driver. DP driver will read this
flag and program the phy mode.
Change-Id: I0164b239bf2832d480795d90f5e9fc221bcc12ba
Signed-off-by: Chandana Kishori Chiluveru <cchiluve@codeaurora.org>
Signed-off-by: Sankeerth Billakanti <sbillaka@codeaurora.org>
PD state transitions call kick_sm which can either queue the
workqueue immediately or with some delay. Both phy_msg_received()
and psy_changed() also call this when receiving a message or
Type-C event. But there is a possibility that usbpd_sm is already
executing due to a previous state transition and hence an extra
queue_work() is called from these events. If the next transition
has a deliberate delay such as waiting for SENDER_RESPONSE_TIME,
the delay is effectively eliminated and usbpd_sm gets executed
immediately again which can cause the state machine to think that
timeout occurred and will result in soft or hard reset. Avoid this
by adding a work_busy check for usbpd_sm work so that is is not
queued twice without any delay.
Change-Id: I9d5f478e8e0abe5609c80979b3158db16373dc52
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
In the case we get error code from devm_regulator_get() instead
of regulator pointer, pd->vbus will be assigned to error code.
We need to assign NULL to pd->vbus after checking the return
value.
Change-Id: Ibcbdf75b8aa05db5148ed138fb15e60ab60a0182
Signed-off-by: Liangliang Lu <luliang@codeaurora.org>
After handling incoming events in PE_SRC/SNK_READY, if the state
has not changed, allow pending outgoing requests (e.g. PR/DR
swap) to be sent without needing to wait for the next
invocation of the state machine.
Change-Id: I247e1093464e355ae7b6174ab06d41ce599d87e5
Signed-off-by: Jack Pham <jackp@codeaurora.org>
We call this notifier on the dual_role_usb class instance to
report any changes in state such as data role and power role.
But if we are already in explicit contract and return to either
PE_SRC_Ready or PE_SNK_Ready states, then that means the power
role has not changed, so there is no need to update the dual_role
instance. This will avoid a 2 second system wakeup timer which
will delay allowing the system to suspend.
Change-Id: I0ba6dc8903b7a010735be4e73e609e7aefa19d96
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Currently -EINVAL is returned both when a select_pdo string is
improperly formulated as well as when an RDO request is
successfully sent but outright rejected or otherwise failed
to enter a new contract. To allow userspace to differentiate
these two failures, instead return -ECONNREFUSED in the latter
case.
Change-Id: I74378b469745d0ef414f8cae228f79741d4846a5
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Currently user requested operations such as select_pdo,
get_src_cap_ext, DR/PR swap when done in sink mode will get
rejected simply because the current Rp state is SinkTxNG. But
since these APIs' semantics effectively queue the request to
be handled in usbpd_sm(), and there is already a check within
PE_SNK_Ready to send only during SinkTxOK, the requests don't
need to be rejected and should still be allowed. Since there
is a blocking wait, if the Source relinquishes Rp and allows
for the AMS, then the operation should be able to go through.
Change-Id: I79e78d3f28fdbb3d8e43017181981a78d3decf84
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Add an API to allow a VDM client (e.g. DisplayPort) to indicate
that the system is entering suspend but that an incoming VDM
message is expected. If a VDM is then received, it will bypass
kick_sm() which would otherwise abort the suspend and instead
be handed to the client VDM handler directly.
The flag can be reset either explicitly, if a soft/hard reset
occur, or if a VDM TX is requested, as those situations would
require the state machine to run in the worker thread normally.
Change-Id: I8af7e13abad766f9e4245149da9457f1c62a25d5
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Since PD is not supported with microUSB connector,
do not register dual_role_instance if connector type is
microUSB as charger driver will take care of it.
Change-Id: Ib7d145dd353fa15828617a2cd5b70aae95e0703b
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
When performing VDM message discovery each VDM initiator and
response exchange is considered an interruptible AMS. Hence
as a PD 3.0 source, relinquish Rp to SinkTxOk to allow the
sink a chance to initiate an AMS as soon as the response is
received. In particular this fixes some DisplayPort use cases
with a PD 3.0 sink in which incoming Attention messages are
blocked due to SinkTxNG while DP Configure message is being
handled.
Change-Id: I5edf298b7244352659b9d41a6e65e934e99a9c24
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Currently USB driver tries to set power role as none in mode
change and waits for disconnect followed by connect notifications
to set new mode. But there is a chance that it might fail if other
device is not dual-role capable.
When device connected to window host pc and try data role swap.
Device trying to change the mode and setting the power role none.
But host PC does not support this and device never switching back
to original role and device enumeration does not happening with
host pc connected.
Fix it by having timeouts in mode setting. Setting it to dual-role and
bail out in case of timeout happens.
Change-Id: Iaac671f46070f756243b93a27ab99ddbbdff8ffa
Signed-off-by: Chandana Kishori Chiluveru <cchiluve@codeaurora.org>
The pd_timeout() timer callback function is used quite often
in scheduling state machine delays and serves multiple purposes
such as waiting for a response, delaying before executing power
supply transitions, etc. As such, the log message is sometimes
misconstrued as an error condition and may confuse the reader.
Instead, move the log print to kick_sm() in case the state
machine is queued with a delay.
Change-Id: I3879aecd39f44eb7a3c5135f086096261316c64d
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Currently when a VDM message arrives, any pending VDM TX message
queued will be aborted. But this will inadvertently discard an
initiated Discover Identity if an incoming message such as
Attention arrives just before it. Since there is no TX response
to Attention, the engine should have just been able to resume
the Discover ID message. In general, only discard VDM TX messages
when attempting to queue a new outgoing VDM.
Change-Id: Ife42a19b8f909b0550b6bd44ed470e87a922d6e3
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Commit 25bdeb88e6 ("usb: pd: Don't retry sending Source Capabilities
if PD capable") added a Soft Reset signal to the sink device that we
already know is PD capable if send Source Capabilities fail instead of
retrying for nCapsCount times. This change was initially made to fix
HARD RESET compliance failure but later it got fixed in the compliance
SW. Revert this since it leads to re-enumeration failure of Multiport
adapter when Hard Reset signal comes if adapter is already connected.
Change-Id: I46a407ddc7ee3e8845e480940a8f966c9083f04d
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
Allow USB controller to update its self-powered and bMaxPower
status whenever Rp changes dynamically. The source has a
responsiblity to reset the USB data connection in case Rp changes
to cause the sink to change its status, so make DWC3 driver
re-query for this each time it gets a connect done event.
Change-Id: If3b3ddc353d88599d70580c95175806f14e42096
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Handle sending of hard reset directly in usbpd_set_state() rather
than deferring it to the usbpd_sm worker, since all uses of it
will always be from a process context anyway. Consolidate sink
and source handling together.
Change-Id: I61e9f2b8c6b70deef1d59b7162f1c37657a6d1af
Signed-off-by: Jack Pham <jackp@codeaurora.org>
In PE_SNK_DISCOVERY, if a message is received make sure to update
the current state to PE_SNK_WAIT_FOR_CAPABILITIES before falling
through the switch case to handle it. Otherwise, when psy_changed()
is notified that vbus_present rises it may end up queuing the
state machine if it thinks it is still in PE_SNK_DISCOVERY. This
would cause the state machine to be reinvoked immediately when
it needs to instead wait for the Accept response. As a result,
it would prematurely send a hard reset.
Change-Id: Ib28c1da88324d2ab64cc943476f050f163112801
Signed-off-by: Jack Pham <jackp@codeaurora.org>
The PD 2.0 compliance tests TD.PD.VDMD.E2 (tVDMSenderResponse
Timeout) and TD.PD.VDMD.E3 (Incorrect Identity Fields) check
that a DFP should drop untimely or invalid responses to SVDM
Discovery messages.
Add a timing marker from the time an SVDM is initiated in
order to track if a response is later than SENDER_RESPONSE_TIME,
and if so, drop it. Also add additional fields checking in
handle_vdm_rx() to determine if the response is well-formed,
otherwise drop it.
Change-Id: I341fcd79abae1b35c0f3105dbb7d30d350ea56be
Signed-off-by: Jack Pham <jackp@codeaurora.org>
In case of DR_Swap, update the PHY DR role immediately after
accepting the request (or receiving an accept from the peer)
so as to have the correct roles sent out by the Auto-GoodCRC
mechanism. This is in case another message is received while
still busy handling the extcon notifications to stop/start
the host/peripheral stack.
Change-Id: I93197583a88c9ad0c291e3756f96c4858f591392
Signed-off-by: Jack Pham <jackp@codeaurora.org>
The Not_Supported message was added in PD 3.0. This should
be sent in response to the following:
- Unhandled Unstructured VDM messages
- Unsupported Structured VDM messages; whereas in PD 2.0 these
are responded with a NAK
- Unhandled messages in the PE_SRC_Ready and PE_SNK_Ready states;
whereas in PD 2.0 a Reject is sent
Also for unexpected messages (e.g. an unsolicited Accept message
not in response to any request), these need to be handled with
a Soft_Reset.
Change-Id: Ie401c1eac7120ac55242826318c4088b2722d9cb
Signed-off-by: Jack Pham <jackp@codeaurora.org>
For several PD 3.0 Compliance Source tests, if the device is
declared as having a battery, it is required to support the
Source_Capabilities_Extended, Battery_Capabilities and
Battery_Status messages. Add handling for these by reading
from the battery and bms power_supply objects so that these
fields can be populated and returned in response to the
respective Get_* messages.
Change-Id: I3bf1f0ddb1b3fdbacee448f0efed1c3272133b40
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Get_Battery_Cap is a PD 3.0 extended message but has the same
MessageID as a BIST data message. Currently the handling for
the latter mistakenly treats Get_Battery_Cap as a BIST and
does not pass it up to the policy engine. Fix this by adding
a check for the 15th bit of the message header which indicates
it is an extended message.
Change-Id: I5ebe4dc3c765303a570b48e47dfb2e40750b3843
Signed-off-by: Jack Pham <jackp@codeaurora.org>
As the PD PHY hardware now fully supports sending and receiving
of all PD 3.0 messages, add support for PD 3.0 source mode and
remove the sink-only limitation to fully support dual-role.
When operating in PD 3.0 source mode, the value of the Rp pullup
resistance must be adjusted between SinkTxOk (3A) and SinkTxNG
(1.5A) to indicate when a sink can initiate an atomic message
sequence (AMS) as a collision avoidance scheme. Use the new usb
power_supply property to change the source Rp value to implement
helper functions that can mark the start/end of an AMS at various
stages in the PE_SRC_READY state.
Change-Id: I2bec1d0cb5244fcb5a0fbf13985545d84e0f0b17
Signed-off-by: Jack Pham <jackp@codeaurora.org>
If connected to a sink that we already know is PD capable, the
next time Source Capabilities is sent, whether due to reset or
in response Get_Source_Capabilities, upon failure should not
retry for nCapsCount times. Instead, simply issue a Soft Reset.
Change-Id: I5a53073f5473575e7206e1fdd344b8f14affddc2
Signed-off-by: Jack Pham <jackp@codeaurora.org>
In general receiving a PD message should preempt a message
transmission in progress or about to be sent. Improve this
behavior by moving the check for any newly received messages
into pd_send_msg(). Also within the PD PHY driver, try to catch
scenarios in which an RX message arrives after pd_phy_write()
has been called but just before the TX register write operation
by checking the rx_msg_cnt counter to see if it changed since
the start of the function call.
Change-Id: I4084d18940b36df1f6eab8b0256ef30a81369884
Signed-off-by: Jack Pham <jackp@codeaurora.org>
There is no known usage or requirement for our response to
Discover Identity VDM when a UFP, which currently uses hard-
coded values, nor is the XID a field we have use for. Instead
simply respond with a NAK. This requires the VIF to be updated
with 'Responds_To_Discov_SOP_UFP=NO'.
Change-Id: I3033054e2b7b511515d5f11ba17ff68f11465902
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Now that there is the potential for cable discovery being
performed before starting to send Source_Capabilities, the
additional delay may push it beyond the spec max of
tFirstSourceCap (250ms). Decrease the FIRST_SOURCE_CAP_TIME
delay to 100ms to give some more room.
Change-Id: I2b92b31ebf966f549b2182aea594e02993217e9a
Signed-off-by: Jack Pham <jackp@codeaurora.org>
An outgoing SOP'/SOP'' message header has different meaning for
the data/power role fields used for SOP. These should be 0.
Change-Id: Iac44320a55ed9d814112bb9ae6ca20cc4e898f04
Signed-off-by: Jack Pham <jackp@codeaurora.org>
The charger driver recently updated to run APSD type detection
concurrently with initial PD communication. In the case of a
non-PD SDP source, the type detection will be completed as the
sink state machine is attempting to do a hard reset. Add a check
in SNK_STARTUP to determine if it is SDP/CDP and start the USB
peripheral stack then.
In the case a PD source is connected and the USB Communication
bit is set in the capabilities message, wait until after setting
PD_ACTIVE to the charger before starting the USB peripheral stack.
This ensures that the charger will be done using D+/D- for charger
detection and won't conflict with USB data signaling. In this
case the USB Communication capable bit supersedes the charger type
detection.
Change-Id: If068046e1ba959eb31ec2233159313e642442e00
Signed-off-by: Jack Pham <jackp@codeaurora.org>
In case of DR Swap where USB peripheral is stopped and USB host
is started, the VDM discovery process can lead to DisplayPort
link being brought up without guarantee that starting of USB host
has completed execution. The result is that USB may end up
resetting the combo PHY while DP is already in use. Fix this by
synchronizing after USB host is started before initiating the VDM
exchange.
Additionally, in dwc3-msm.c, replace flush_delayed_work() with
drain_workqueue(), since the stop_peripheral() and start_host()
will end up with back-to-back invocations of the dwc3 sm_work,
so make sure that all are completed before returning from the
blocking sync.
Change-Id: I38264c8d4c5ffaad1f831ffda0677fdc8b41b4d1
Signed-off-by: Jack Pham <jackp@codeaurora.org>
When hard reset is in progress, the pd state machine restarts
from PE_UNKNOWN state. If a Type-C disconnect notification
is received during the same time, the current_pr is set to
PR_NONE. Because of this we bail out of the usbpd_sm
assuming it is in disconnected state even though the
disconnect was not processed.
Fix this by validating the current_dr as well to confirm
that the state machine is actually in disconnected state.
Change-Id: Iea59a857c6826f65fef8b0c9a8ee6e2488683864
Signed-off-by: Sriharsha Allenki <sallenki@codeaurora.org>
We only expect to receive SOP' messages if we have enabled
VCONN and are communicating to the cable. Initialize the PD PHY
to enable SOP' reception accordingly during PE_SRC/SNK_Startup
based on whether VCONN is enabled or not.
Change-Id: If08d37a896d706886566ee2d784af50393d9e604
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Currently driver probe gets defered if vbus or vconn is
not present but in case of uAB connector smb driver will
not expose these regulators which will cause dwc3 driver
probe failure. Fix this by fetching these regulators at
the time of regulator enablement.
Change-Id: I69f13947da521c694318f98bb217a3fa69adca67
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
It is required to notify device as selfpowered and bmaxpower as zero
even for non PD capable devices based on Type C current. Hence notify
as selfpowerer in bMattributes of configuation descriptor in case of
medium or high Type C current.
Change-Id: Ie552560d93a8195f4c69fdaf6086ef3a52b31d39
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Convert restart_usb_host_mode() into a generic blocking_sync()
callback which simply ensures that any pending role switches are
fully flushed before proceeding with the next extcon_set_state()
call. Move the responsibility of stopping/restarting host mode
with the speed to the PD policy engine instead.
This fixes a couple of possible race scenarios:
1) stopping host mode needs to be fully completed before allowing
DisplayPort to initialize as it may require exclusive use of
the PHY.
2) data role swap followed by entering DisplayPort alt mode in
which it determines it needs 4-lane configuration. The
back-to-back start peripheral, stop peripheral and start
host may overlap if they are not serialized.
Change-Id: Ic29b74ae3e22f69f67e73aba59d211b81eb70de0
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Remove check for uAB connector in PD driver probe to
support dynamic detection of uAB device. If we fail
PD driver probe in case of uAB connector then our
current handling of extcon handles in dwc3 driver will
keep on defering probe until PD driver get probed successfully.
Change-Id: I5197b05a240a01416e388e81b5770276348de95e
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
A fixed sink PDO request includes both operating current and
max current. Although the max current requested may be greater
than the available source advertisement, as per spec only the
operating current request needs to be considered. The sink will
likely have also set the Capability Mismatch bit as well. Hence,
don't reject the request otherwise the sink will keep
re-requesting and never enter a contract.
Change-Id: Ia15e2e17abe43f2bcbc1fe7011b70ab0e0f5d9eb
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Rearrange handling of received messages in PE_SNK_READY state
such that certain status payloads (Source_Cap_Ext, Status,
PPS_Status, et al) do not terminate. This allows pending request
messages to be handled in the same context and sent out before
exiting the usbpd_sm() worker, avoiding a need to reschedule.
This fixes an issue where an Alert message is received triggering
a Get_Status request to be sent but causes a pending power
Request to be preempted and never scheduled to be sent again.
Change-Id: I1c2b7f126e24a93095028c93b210d89b514183d0
Signed-off-by: Jack Pham <jackp@codeaurora.org>