aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/typec (follow)
AgeCommit message (Collapse)AuthorFilesLines
2018-04-22staging: typec: rt1711h typec chip driverShuFan Lee4-0/+322
Richtek RT1711H Type-C chip driver that works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. Add definition of TCPC_CC_STATUS_TOGGLING. Signed-off-by: ShuFan Lee <shufan_lee@richtek.com> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-12staging: typec: modify parameter of tcpci_irqShuFan Lee2-3/+2
The parameter, dev_id, of tcpci_irq should be tcpci_chip. Remove definition of TCPC_CC_STATUS_DRPRST in tcpci.h. Fixes: 8f9439022648("staging: typec: handle vendor defined part and modify drp toggling flow") Signed-off-by: ShuFan Lee <shufan_lee@richtek.com> Reviewed-by: Li Jun <jun.li@nxp.com> Tested-by: Li Jun <jun.li@nxp.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-09staging: typec: handle vendor defined part and modify drp toggling flowShuFan Lee2-26/+116
Handle vendor defined behavior in tcpci_init, tcpci_set_vconn, tcpci_start_drp_toggling and export tcpci_irq. More operations can be extended in tcpci_data if needed. According to TCPCI specification, 4.4.5.2 ROLE_CONTROL, TCPC shall not start DRP toggling until subsequently the TCPM writes to the COMMAND register to start DRP toggling. DRP toggling flow is changed as following: - Write DRP = 1, Rp level and RC.CCx to Rd/Rd or Rp/Rp - Set LOOK4CONNECTION command Signed-off-by: ShuFan Lee <shufan_lee@richtek.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-01-15staging: typec: remove redundant license textGreg Kroah-Hartman2-20/+0
Now that the SPDX tag is in all drivers/staging/typec/ files, that identifies the license in a specific and legally-defined manner. So the extra GPL text wording can be removed as it is no longer needed at all. This is done on a quest to remove the 700+ different ways that files in the kernel describe the GPL license text. And there's unneeded stuff like the address (sometimes incorrect) for the FSF which is never needed. No copyright headers or other non-license-description text was removed. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-01-15staging: typec: add SPDX identifier.Greg Kroah-Hartman2-0/+2
It's good to have SPDX identifiers in all files to make it easier to audit the kernel tree for correct licenses. Fix up the drivers/staging/typec/ files to have a proper SPDX identifier, based on the license text in the file itself. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This work is based on a script and data from Thomas Gleixner, Philippe Ombredanne, and Kate Stewart. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Kate Stewart <kstewart@linuxfoundation.org> Cc: Philippe Ombredanne <pombredanne@nexb.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-12-19staging: typec: fix endianness mismatch identified by sparseGabriel L. Somlo1-7/+10
Eliminate the following sparse warnings: tcpci.c:291:38: warning: incorrect type in argument 1 (different base types) tcpci.c:291:38: expected unsigned short [unsigned] [usertype] header tcpci.c:291:38: got restricted __le16 const [usertype] header tcpci.c:296:16: warning: incorrect type in assignment (different base types) tcpci.c:296:16: expected unsigned int [unsigned] header tcpci.c:296:16: got restricted __le16 tcpci.c:394:28: warning: incorrect type in assignment (different base types) tcpci.c:394:28: expected restricted __le16 [usertype] header tcpci.c:394:28: got unsigned int [unsigned] [addressable] reg Signed-off-by: Gabriel Somlo <gsomlo@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-10-18staging: typec: tcpci: mark expected switch fall-through in tcpci_to_typec_ccGustavo A. R. Silva1-0/+1
In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through. Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-18usb: typec: fusb302: Move out of stagingGuenter Roeck7-2154/+0
The driver is in good enough shape to be moved out of staging. Do it. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-18typec: tcpm: Move out of stagingGuenter Roeck10-4423/+4
Move tcpm (USB Type-C Port Manager) out of staging. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-18staging: typec: pd: Document struct pd_messageGuenter Roeck1-0/+5
struct pd_message is the format of a PD message as seen on the wire. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-18staging: typec: tcpm: Document data structuresGuenter Roeck1-7/+50
Document struct tcpc_config and struct tcpc_dev. Drop unused TCPC_USB_SWITCH_RESTORE. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-18staging: typec: tcpm: Drop commented out codeGuenter Roeck1-36/+1
Commented out code can be added as needed. Drop it. Also drop TODO and an obsolete XXX comment. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-01staging: typec: fusb302: make structure fusb302_psy_desc staticColin Ian King1-1/+1
The const structure fusb302_psy_desc is local to the source and does not need to be in global scope, so make it static. Cleans up sparse warnings symbol 'fusb302_psy_desc' was not declared. Should it be static? Signed-off-by: Colin Ian King <colin.king@canonical.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-31staging: typec: fusb302: Export current-limit through a power_supply class devHans de Goede2-3/+62
The fusb302 Type-C port-controller cannot control the current-limit directly, so we need to exported the limit so that another driver (e.g. the charger driver) can pick the limit up and configure the system accordingly. The power-supply subsys already provides infrastructure for this, power-supply devices have the notion of being supplied by another power-supply and have properties through which we can export the current-limit. Register a power_supply and export the current-limit through the power_supply's current-max property. Cc: "Yueyao (Nathan) Zhu" <yueyao@google.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-31staging: typec: fusb302: Add support for USB2 charger detection through extconHans de Goede1-0/+49
The fusb302 port-controller relies on an external device doing USB2 charger-type detection. The Intel Whiskey Cove PMIC with which the fusb302 is combined on some X86/ACPI platforms already has a charger-type detection driver which uses extcon to communicate the detected charger-type. Rather then inventing a new API for USB2 charger-type detection specifically for use with the tcpm code, this commit simply re-uses the existing extcon API and uses that do USB2 charger detection. Note that the "fcs,extcon-name" property name is only for kernel internal use by X86/ACPI platform code and as such is NOT documented in the fusb302 devicetree bindings. Cc: "Yueyao (Nathan) Zhu" <yueyao@google.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-31staging: typec: fusb302: Use client->irq as irq if setHans de Goede1-3/+7
The fusb302 is also used on x86 systems where the platform code sets the irq in client->irq and there is no gpio named fcs,int_n. Cc: "Yueyao (Nathan) Zhu" <yueyao@google.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-31staging: typec: fusb302: Get max snk mv/ma/mw from device-propertiesHans de Goede2-1/+21
This is board specific info so it should come from board config, such as devicetree. I've chosen to prefix these with "fcs," treating them as fusb302 driver specific for now. We may want to revisit this and replace these with properties which are part of a (to be written) generic type-c controller devicetree binding. Since this commit adds new dt-properties it also adds devicetree-bindings documentation (which so far was absent for the fusb302 driver). Cc: Rob Herring <robh+dt@kernel.org> Cc: Frank Rowand <frowand.list@gmail.com> Cc: devicetree@vger.kernel.org Cc: "Yueyao (Nathan) Zhu" <yueyao@google.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Rob Herring <robh@kernel.org> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-31staging: typec: fusb302: Set max supply voltage to 5VHans de Goede1-2/+2
Anything higher then 5V may damage hardware not capable of it, so the only sane default here is 5V. If a board is able to handle a higher voltage that should come from board specific data such as device-tree and not be hard coded into the fusb302 code. Cc: "Yueyao (Nathan) Zhu" <yueyao@google.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-31staging: typec: tcpm: Add get_current_limit tcpc_dev callbackHans de Goede2-1/+11
A Rp signalling the default current limit indicates that we're possibly connected to an USB2 power-source. In some cases the type-c port-controller may provide the capability to detect the current-limit in this case, through e.g. BC1.2 detection. This commit adds an optional get_current_limit tcpc_dev callback which allows the port-controller to provide current-limit detection for when the CC pin is pulled up with Rp. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: Switch to PORT_RESET instead of SNK_UNATTACHEDBadhri Jagan Sridharan1-1/+1
When VBUS is not discovered within PD_T_PS_SOURCE_ON although Rp is detected on CC, TCPM switches the port to SNK_UNATTACHED state. SNK_UNATTACHED, however does not force TYPEC_CC_OPEN which makes the partner(source) to think that it is connected. To overcome this issue, force the port into PORT_RESET state to make sure the CC lines are open. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: Do not send PING msgs in TCPMBadhri Jagan Sridharan1-7/+4
PING messages are used to monitor the connect/disconnect. However, when PD is carried over CC, so this is not required. Also, the spec does not clearly say if PD is possible when Type-c is connected to Type-A/B. So, removing sending PING messages altogether. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: typec: tcpm: Wait for CC debounce before PD excgBadhri Jagan Sridharan2-3/+24
Once, Rp or Rd is switched, wait for PD_T_CC_DEBOUNCE. If not the PS_RDY message transmitted might result in failure. Also, Only wait for PD_T_SRCSWAPSTDBY while in PR_SWAP_SRC_SNK_TRANSITION_OFF. PD_T_PS_SOURCE_OFF is the overall time after which the initial sink would issue hard reset. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: add cc change handling in src statesBadhri Jagan Sridharan1-2/+4
In the case that the lower layer driver reports a cc change directly from SINK state to SOURCE state, TCPM doesn't handle these cc change in SRC_SEND_CAPABILITIES, SRC_READY states. And with SRC_ATTACHED state, the change is not handled as the port is still considered connected. [49606.131672] state change DRP_TOGGLING -> SRC_ATTACH_WAIT [49606.131701] pending state change SRC_ATTACH_WAIT -> SRC_ATTACHED @ 200 ms [49606.329952] state change SRC_ATTACH_WAIT -> SRC_ATTACHED [delayed 200 ms] [49606.329978] polarity 0 [49606.329989] Requesting mux mode 1, config 0, polarity 0 [49606.349416] vbus:=1 charge=0 [49606.372274] pending state change SRC_ATTACHED -> SRC_UNATTACHED @ 480 ms [49606.372431] VBUS on [49606.372488] state change SRC_ATTACHED -> SRC_STARTUP ... (the lower layer driver reports a direct change from source to sink) [49606.536927] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [49606.547244] CC1: 2 -> 5, CC2: 0 -> 0 [state SRC_SEND_CAPABILITIES, polarity 0, connected] This can happen when the lower layer driver and/or the hardware handles a portion of the Type-C state machine work, and quietly goes through the unattached state. Originally-from: Yueyao Zhu <yueyao@google.com> Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: Consider port_type while determining unattached_stateBadhri Jagan Sridharan1-3/+9
While performing PORT_RESET, upon receiving the cc disconnect signal from the underlaying tcpc device, TCPM transitions into unattached state. Consider the current type of port while determining the unattached state. In the below logs, although the port_type was set to sink, TCPM transitioned into SRC_UNATTACHED. [ 762.290654] state change SRC_READY -> PORT_RESET [ 762.324531] Setting voltage/current limit 0 mV 0 mA [ 762.327912] polarity 0 [ 762.334864] cc:=0 [ 762.347193] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [ 762.347200] VBUS off [ 762.347203] CC1: 2 -> 0, CC2: 0 -> 0 [state PORT_RESET, polarity 0, disconnected] [ 762.347206] state change PORT_RESET -> SRC_UNATTACHED Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: Comply with TryWait.SNK StateBadhri Jagan Sridharan1-28/+30
According to the spec: "4.5.2.2.10.2 Exiting from TryWait.SNK State The port shall transition to Attached.SNK after tCCDebounce if or when VBUS is detected. Note the Source may initiate USB PD communications which will cause brief periods of the SNK.Open state on both the CC1 and CC2 pins, but this event will not exceed tPDDebounce. The port shall transition to Unattached.SNK when the state of both of the CC1 and CC2 pins is SNK.Open for at least tPDDebounce." Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: Follow Try.SRC exit requirementsBadhri Jagan Sridharan1-5/+28
According to spec: " 4.5.2.2.9.2 Exiting from Try.SRC State: The port shall transition to Attached.SRC when the SRC.Rd state is detected on exactly one of the CC1 or CC2 pins for at least tPDDebounce. The port shall transition to TryWait.SNK after tDRPTry and the SRC.Rd state has not been detected." Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: Check for Rp for tPDDebounceBadhri Jagan Sridharan1-44/+24
According the spec, the following is the conditions for exiting Try.SNK state: "The port shall wait for tDRPTry and only then begin monitoring the CC1 and CC2 pins for the SNK.Rp state. The port shall then transition to Attached.SNK when the SNK.Rp state is detected on exactly one of the CC1 or CC2 pins for at least tPDDebounce and V BUS is detected. Alternatively, the port shall transition to TryWait.SRC if SNK.Rp state is not detected for tPDDebounce." Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: Prevent TCPM from looping in SRC_TRYWAITBadhri Jagan Sridharan1-16/+29
According to the spec the following is the condition for exiting TryWait.SRC: "The port shall transition to Attached.SRC when V BUS is at vSafe0V and the SRC.Rd state is detected on exactly one of the CC pins for at least tCCDebounce. The port shall transition to Unattached.SNK after tDRPTry if neither of the CC1 or CC2 pins are in the SRC.Rd state" TCPM at present keeps re-entering the SRC_TRYWAIT and keeps restarting tDRPTry if the CC presents Rp and disconnects within tCCDebounce. For example: [ 447.164308] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms [ 447.164386] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, disconnected] [ 447.164406] state change SRC_TRYWAIT -> SRC_TRYWAIT [ 447.164573] cc:=3 [ 447.191408] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [ 447.191478] CC1: 0 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, disconnected] [ 447.207261] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, connected] [ 447.207306] state change SRC_TRYWAIT -> SRC_TRYWAIT [ 447.207485] cc:=3 [ 447.237283] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms [ 447.237357] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, disconnected] [ 447.237379] state change SRC_TRYWAIT -> SRC_TRYWAIT [ 447.237532] cc:=3 [ 447.263219] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [ 447.263289] CC1: 0 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, disconnected] [ 447.280926] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, connected] [ 447.280970] state change SRC_TRYWAIT -> SRC_TRYWAIT [ 447.281158] cc:=3 [ 447.307767] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms [ 447.307838] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, disconnected] [ 447.307858] state change SRC_TRYWAIT -> SRC_TRYWAIT In TCPM, tDRPTry is set tp 100ms (min 75ms and max 150ms) and tCCdebounce is set to 200ms (min 100ms and max 200ms). To overcome the issue, record the time at which the port enters TryWait.SRC(SRC_TRYWAIT) and re-enter SRC_TRYWAIT only when CC keeps debouncing within tDRPTry. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: Check for port type for Try.SRC/Try.SNKBadhri Jagan Sridharan1-2/+4
Enable Try.SRC or Try.SNK only when port_type is DRP. Try.SRC or Try.SNK state machines are not valid for SRC only or SNK only ports. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-29staging: typec: tcpm: set port type callbackBadhri Jagan Sridharan1-11/+41
The port type callback call enquires the tcpc_dev if the requested port type is supported. If supported, then performs a tcpm reset if required after setting the tcpm internal port_type variable. Check against the tcpm port_type instead of checking against caps.type as port_type reflects the current configuration. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-28staging: typec: Add __printf verificationJoe Perches1-0/+5
Adding __printf verification can help avoid format/argument mismatches. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-22staging: typec: tcpm: make function tcpm_get_pwr_opmodeColin Ian King1-1/+1
The function pointer tcpm_get_pwr_opmode is local to the source and does not need to be in global scope, so make it static. Cleans up sparse warning: symbol 'tcpm_get_pwr_opmode' was not declared. Should it be static? Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: explicit_contract is always establishedBadhri Jagan Sridharan1-3/+7
While in SNK_READY state, the explicit_contract seems to be set to true irrespective of whether an explicit contract was established for the current connection. TCPM also seems to report the pwr_opmode as TYPEC_PWR_MODE_PD always once the port gets into SNK_READY state. This isn't completely true as port gets into the SNK_READY state for non-pd type-c ports as well. This patch sets the explicit_contract flag only when the PS_READY message is received and the vbus has been detected by the port controller. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: Report right typec_pwr_opmodeBadhri Jagan Sridharan1-2/+19
At present, TCPM does not take into account the actual resistor value presented in the CC line and therefore reports TYPEC_PWR_MODE_USB irrespective of the power_op_mode it is in. This patch makes TCPM consider the actual value of Rp. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: Check cc status before entering SRC_TRY_DEBOUCEBadhri Jagan Sridharan1-1/+2
[ 130.893355] state change SNK_DEBOUNCED -> SRC_TRY [ 130.893363] cc:=3 [ 130.893490] pending state change SRC_TRY -> SNK_TRYWAIT @ 100 ms [ 130.895602] CC1: 3 -> 0, CC2: 0 -> 0 [state SRC_TRY, polarity 0, disconnected] [ 130.895613] state change SRC_TRY -> SRC_TRY_DEBOUNCE [ 130.895621] pending state change SRC_TRY_DEBOUNCE -> SRC_ATTACHED @ 20 ms [ 130.916843] state change SRC_TRY_DEBOUNCE -> SRC_ATTACHED [delayed 20 ms] Although the CC state was changing to TYPEC_CC_OPEN, the port entered SRC_TRY_DEBOUNCE from SRC_TRY. The port must enter SRC_TRY_DEBOUNCE only if the CC state is TYPEC_CC_RD. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> [groeck: Wording] Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: Improve role swap with non PD capable partnersGuenter Roeck1-26/+34
If the partner is not PD capable, we can not use a power role set request to swap roles. Use the data role set request instead. Also, if a partner is not PD capable, it does not really make sense to send a PD message to trigger a role swap. On top of that, we should really wait for the attempted role change to complete. Otherwise, it may well be that user space requests another role change immediately afterwards which will fail because the port is not yet in ready state. Trigger the role swap from data role change requests and introduce new state PORT_RESET and use it to solve the problem. This new state is mostly identical to ERROR_RECOVERY, only it does not cause a pending role change to fail. Use this new state also when initializing the driver. Rename ERROR_RECOVERY_WAIT_OFF to PORT_RESET_WAIT_OFF to better reflect its new meaning. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: Add timeout when waiting for role swap completionGuenter Roeck2-7/+17
The Type-C protocol manager state machine could fail, which might result in role swap requests from user space to hang forever. Add a generous timeout when waiting for role swaps to complete to avoid this situation. Originally-from: Badhri Jagan Sridharan <badhri@google.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: Select default state based on port typeBadhri Jagan Sridharan1-5/+10
tcpm_default_state wasn't considering the port type when determining the default role. This change makes tcpm_default_state to consider port type as well. tcpm_default_state would return the following based on the port type: TYPEC_PORT_UFP - SNK_UNATTACHED TYPEC_PORT_DFP - SRC_UNATTACHED TYPEC_PORT_DRP - based on the preferred_role setting Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> [groeck: Reworded description; minor formatting changes] Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: Set default state after error recovery based on port typeBadhri Jagan Sridharan1-4/+1
While exiting ERROR_RECOVERY, choose default state based on the port type instead of current power role. Quoting from specification: 4.5.2.2.2 ErrorRecovery State This state appears in Figure 4-12, Figure 4-13, Figure 4-14, Figure 4-15, Figure 4-16 and Figure 4-17. The ErrorRecovery state is where the port removes the terminations from the CC1 and CC2 pins for tErrorRecovery followed by transitioning to the appropriate Unattached.SNK or Unattached.SRC state based on port type. This is the equivalent of forcing a detach event and looking for a new attach. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: Report role swap complete after entering READY stateGuenter Roeck1-7/+2
Role swap requests fail unless the current role is either SRC_READY or SNK_READY. This works fine for VCONN and data role swaps, where we immediately enter READY state after reporting a successful role swap to user space. However, on power role changes, the role swap is currently reported as successful while power negotiation is still in process. User space does not know this, and may request another role swap immediately after a power role swap is reported to be complete. This second role swap will fail with -EAGAIN. To fix the problem, report role swap completion after power negotiation is complete and the state machine enters SRC_READY or SNK_READY state. This is better anyway since it captures errors due to failed power negotiations. It also simplifies the code since the number of calls needed to report successful role swaps is reduced. Reported-by: Howard Yen <howard_yen@htc.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-18staging: typec: tcpm: Constify alternate modesGuenter Roeck2-2/+2
Constify alternate mode configuration data which won't be touched by the driver. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-07-16staging: typec: Fix endianness warning discovered by sparseThomas Gardner1-2/+1
The below warning is resolved by removing the cpu_to_le32() call. This call was redundant; vdm_run_state_machine() ensures that SVDM responses have the correct endianness before sending. typec/tcpm.c:1019:49: warning: incorrect type in assignment (different base types) typec/tcpm.c:1019:49: expected unsigned int [unsigned] [usertype] <noident> typec/tcpm.c:1019:49: got restricted __le32 [usertype] <noident> Signed-off-by: Thomas Gardner <tmg@fastmail.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-06-23staging: fusb302: don't bitshift __le16 typeFrans Klaver1-2/+2
The header field in struct pd_message is declared as an __le16 type. The data in the message is supposed to be little endian. This means we don't have to go and shift the individual bytes into position when we're filling the buffer, we can just copy the contents right away. As an added benefit we don't get fishy results on big endian systems anymore. Signed-off-by: Frans Klaver <fransklaver@gmail.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-16staging: typec: fusb302: refactor resume retry mechanismRui Miguel Silva1-34/+36
The i2c functions need to test the pm_suspend state and do, if needed, some retry before i2c operations. This code was repeated 4x. To isolate this, create a new function to check suspend state and call it in every need place. As at it, move the error message from pr_err to dev_err. Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com> Acked-by: Yueyao Zhu <yueyao.zhu@gmail.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-16staging: typec: fusb302: reset i2c_busy state in errorRui Miguel Silva1-2/+4
Fix reset of i2c_busy flag if an error occurs during the i2c block read. Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com> Acked-by: Yueyao Zhu <yueyao.zhu@gmail.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-15staging: typec: Fix sparse warnings about incorrect typesGuru Das Srinagesh1-2/+2
Fix the following sparse warnings about incorrect type usage: fusb302.c:1028:32: warning: incorrect type in argument 1 (different base types) fusb302.c:1028:32: expected unsigned short [unsigned] [usertype] header fusb302.c:1028:32: got restricted __le16 const [usertype] header fusb302.c:1484:32: warning: incorrect type in argument 1 (different base types) fusb302.c:1484:32: expected unsigned short [unsigned] [usertype] header fusb302.c:1484:32: got restricted __le16 [usertype] header Signed-off-by: Guru Das Srinagesh <gurooodas@gmail.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-15staging: typec: fusb302: do not free gpio from managed resourceRui Miguel Silva1-2/+0
When allocating a gpio using the managed resource devm_, we can avoid freeing it manually. But even if we did it we should use devm_gpio_free. So, just remove the free of the gpio in the error path. Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com> Acked-by: Yueyao Zhu <yueyao.zhu@gmail.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-15staging: typec: tcpm: Fix Port Power Role field in PS_RDY messagesGuenter Roeck1-2/+16
PS_RDY messages sent during power swap sequences are expected to reflect the new power role. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-15staging: typec: tcpm: Respond to Discover Identity commandsGuenter Roeck3-1/+33
If the lower level driver provided a list of VDOs in its configuration data, send it to the partner as response to a Discover Identity command if in device mode (UFP). Cc: Yueyao Zhu <yueyao.zhu@gmail.com> Originally-from: Puma Hsu <puma_hsu@htc.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-15staging: typec: tcpm: Set correct flags in PD request messagesGuenter Roeck1-2/+1
We do support USB PD communication, and devices supported by this driver typically use USB power for purposes other than USB communication. Originally-from: Puma Hsu <puma_hsu@htc.com> Cc: Yueyao Zhu <yueyao.zhu@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>