Commit Graph

31 Commits

Author SHA1 Message Date
Hans de Goede 48242e3053 usb: typec: fusb302: Revert "Resolve fixed power role contract setup"
Some tcpc device-drivers need to explicitly be told to watch for connection
events, otherwise the tcpc will not generate any TCPM_CC_EVENTs and devices
being plugged into the Type-C port will not be noticed.

For dual-role ports tcpm_start_drp_toggling() is used to tell the tcpc to
watch for connection events. But for single-role ports we've so far been
falling back to just calling tcpm_set_cc(). For some tcpc-s such as the
fusb302 this is not enough and no TCPM_CC_EVENT will be generated.

Commit ea3b4d5523 ("usb: typec: fusb302: Resolve fixed power role
contract setup") fixed SRPs not working because of this by making the
fusb302 driver start connection detection on every tcpm_set_cc() call.
It turns out this breaks src->snk power-role swapping because during the
swap we first set the Cc pins to Rp, calling set_cc, and then send a PS_RDY
message. But the fusb302 cannot send PD messages while its toggling engine
is active, so sending the PS_RDY message fails.

Struct tcpc_dev now has a new start_srp_connection_detect callback and
fusb302.c now implements this. This callback gets called when we the
fusb302 needs to start connection detection, fixing fusb302 SRPs not
seeing connected devices.

This allows us to revert the changes to fusb302's set_cc implementation,
making it once again purely setup the Cc-s and matching disconnect
detection, fixing src->snk power-role swapping no longer working.

Note that since the code was refactored in between, codewise this is not a
straight forward revert. Functionality wise this is a straight revert and
the original functionality is fully restored.

Fixes: ea3b4d5523 ("usb: typec: fusb302: Resolve fixed power role ...")
Cc: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Tested-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-19 14:23:34 +02:00
Hans de Goede 6258db14d7 usb: typec: fusb302: Implement start_toggling for all port-types
When in single-role port mode, we must start single-role toggling to
get an interrupt when a device / cable gets plugged into the port.

This commit modifies the fusb302 start_toggling implementation to
start toggling for all port-types, so that connection-detection works
on single-role ports too.

Fixes: ea3b4d5523bc("usb: typec: fusb302: Resolve fixed power role ...")
Cc: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Tested-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-19 14:23:34 +02:00
Hans de Goede 7893f9e1c2 usb: typec: tcpm: Notify the tcpc to start connection-detection for SRPs
Some tcpc device-drivers need to explicitly be told to watch for connection
events, otherwise the tcpc will not generate any TCPM_CC_EVENTs and devices
being plugged into the Type-C port will not be noticed.

For dual-role ports tcpm_start_drp_toggling() is used to tell the tcpc to
watch for connection events. Sofar we lack a similar callback to the tcpc
for single-role ports. With some tcpc-s such as the fusb302 this means
no TCPM_CC_EVENTs will be generated when the port is configured as a
single-role port.

This commit renames start_drp_toggling to start_toggling and since the
device-properties are parsed by the tcpm-core, adds a port_type parameter
to the start_toggling callback so that the tcpc_dev driver knows the
port-type and can act accordingly when it starts toggling.

The new start_toggling callback now always gets called if defined, instead
of only being called for DRP ports.

To avoid this causing undesirable functional changes all existing
start_drp_toggling implementations are not only renamed to start_toggling,
but also get a port_type check added and return -EOPNOTSUPP when port_type
is not DRP.

Fixes: ea3b4d5523bc("usb: typec: fusb302: Resolve fixed power role ...")
Cc: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Tested-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-19 14:23:34 +02:00
Greg Kroah-Hartman 8cdfd068c1 Merge 5.1-rc3 into usb-next
We want the USB fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-01 07:42:04 +02:00
YueHaibing 2a738137b4 usb: typec: fusb302: Make fusb302_irq_work static
Fix sparse warning:

drivers/usb/typec/tcpm/fusb302.c:1454:6: warning:
 symbol 'fusb302_irq_work' was not declared. Should it be static?

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-26 16:42:53 +09:00
Heikki Krogerus 4c912bff46 usb: typec: wcove: Provide fwnode for the port
By registering a software fwnode for the port, we can supply
the connector capabilities to the tcpm using the common USB
connector device properties instead of relying on platform
data (struct tcpc_config).

Signed-off-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>
2019-03-26 16:42:53 +09:00
Hans de Goede bb31b35251 usb: typec: fusb302: Add __printf attribute to fusb302_log function
Add __printf attribute to fusb302_log function, so that we get
compiler warnings when specifying wrong vararg parameters.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-19 15:06:12 +01:00
Hans de Goede 207338ec5a usb: typec: fusb302: Improve suspend/resume handling
Remove the code which avoids doing i2c-transfers while our parent
i2c-adapter may be suspended by busy-waiting for our resume handler
to be called.

Instead move the interrupt handling from a threaded interrupt handler
to a work-queue and install a non-threaded interrupt handler which
normally queues the new interrupt handling work directly.

When our suspend handler gets called we set a flag which makes the new
non-threaded interrupt handler skip queueing the work before our parent
i2c-adapter is ready, instead the new non-threaded handler will record an
interrupt has happened during suspend and then our resume handler will
queue the work (at which point our parent will be ready).

Note normally i2c drivers solve the problem of not being able to access
the i2c bus until the i2c-controller is resumed by simply disabling their
irq from the suspend handler and re-enabling it on resume.

That is not possible with the fusb302 since the irq is a wakeup source
(it must be a wakeup source so that we can do PD negotiation when a
charger gets plugged in while suspended).

Besides avoiding the ugly busy-wait, this also fixes the following errors
which were logged by the busy-wait code when woken from suspend by plugging
in a Type-C device:

fusb302: i2c: pm suspend, retry 1 / 10
fusb302: i2c: pm suspend, retry 2 / 10
etc.

This commit also changes the devm_request_irq to a regular request_irq
+ free_irq, so that the work can be properly stopped. While at it also
properly disable the wake setting on the irq and also properly stop the
delayed work for bcl handling.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-19 15:06:12 +01:00
Hans de Goede 7511c9a9d3 usb: typec: fusb302: 2 small misc. fixes
Fix a copy and paste error in an error message and a spelling error
in a comment.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-19 15:06:12 +01:00
Hans de Goede 702ad49fb8 usb: typec: fusb302: Fix fusb302_handle_togdone_src Ra handling
The FUSB302 will stop toggling with a FUSB_REG_STATUS1A_TOGSS_SRC? status,
as soon as it sees either Ra or Rd on a CC pin.

Before this commit fusb302_handle_togdone_src would assume that the toggle-
engine always stopped at the CC pin indicating the polarity, IOW it assumed
that it stopped at the pin connected to Rd. It did check the CC-status of
that pin, but it did not expect to get a CC-status of Ra and therefore
treated this as CC-open. This lead to the following 2 problems:

1) If a powered cable/adapter gets plugged in with Ra on CC1 and Rd on CC2
then 4 of 5 times when plugged in toggling will stop with a togdone_result
of FUSB_REG_STATUS1A_TOGSS_SRC1.  3/5th of the time the toggle-engine is
testing for being connected as a sink and after that it tests 1/5th of the
time for connected as a src through CC1 before finally testing the last
1/5th of the time for being a src connected through CC2.

This was a problem because we would only check the CC pin status for the
pin on which the toggling stopped which in this polarity 4 out of 5
times would be the Ra pin. The code before this commit would treat Ra as
CC-open and then restart toggling. Once toggling is restarted we are
guaranteed to end with FUSB_REG_STATUS1A_TOGSS_SRC1 as CC1 is tested first,
leading to a CC-status of Ra again and an infinite restart toggling loop.
So 4 out of 5 times when plugged in in this polarity a powered adapter
will not work.

2) Even if we happen to have the right polarity or 1/5th of the time in
the polarity with problem 1), we would report the non Rd pin as CC-open
rather then as Ra, resulting in the tcpm.c code not enabling Vconn which
is a problem for some adapters.

This commit fixes this by getting the CC-status of *both* pins and then
determining the polarity based on that, rather then on where the toggling
stopped.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-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>
2019-03-19 15:06:12 +01:00
Hans de Goede 32a155b1a8 usb: typec: fusb302: Check vconn is off when we start toggling
The datasheet says the vconn MUST be off when we start toggling. The
tcpm.c state-machine is responsible to make sure vconn is off, but lets
add a WARN to catch any cases where vconn is not off for some reason.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-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>
2019-03-19 15:06:12 +01:00
Hans de Goede 4995bb15ad usb: typec: fusb302: Fold fusb302_set_cc_pull into tcpm_set_cc
After the recent cleanups, tcpm_set_cc is the only caller of
fusb302_set_cc_pull, fold fusb302_set_cc_pull directly into
tcpm_set_cc for a nice cleanup.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-19 15:06:12 +01:00
Hans de Goede daf81d0137 usb: typec: fusb302: Refactor / simplify tcpm_set_cc()
After commit ea3b4d5523 ("usb: typec: fusb302: Resolve fixed power role
contract setup"), tcpm_set_cc always calls fusb302_set_toggling.

Before this refactor tcpm_set_cc does the following:

1) fusb302_set_toggling(TOGGLING_MODE_OFF),
   this sets both FUSB_REG_MASK_BC_LVL and FUSB_REG_MASK_COMP_CHNG.
2) fusb302_set_cc_pull(...).
3) "reset cc status".
4) if pull-up fusb302_set_src_current(...).
5) if pull-up or pull-down enable bc-lvl resp comp-chng irq.
6) fusb302_set_toggling(new-toggling-mode), which again
   sets both FUSB_REG_MASK_BC_LVL and FUSB_REG_MASK_COMP_CHNG disabling
   the just enabled irq. fusb302_set_toggling is skipped when the new
   toggling mode is TOGGLING_MODE_OFF because this is already done in 1,
   note in this case 5) is a no-op.

When we are toggling the bits set by fusb302_set_cc_pull will be ignored
until we turn toggling off, so we can safely move the fusb302_set_cc_pull
call to before setting TOGGLING_MODE_OFF.

Either we are not toggling yet, or the src-current has already been set,
so we can also safely set the src-current earlier, allowing us to do the
fusb302_set_toggling(TOGGLING_MODE_OFF) call at the same time as we
set the other toggling modes. Also setting the src-current is a no-op
when not enabling pull-ups, so we can drop the if.

And since the second fusb302_set_toggling undoes the effects of step 5,
we can skip step 5, the bc-lvl resp comp-chng irq wil be enabled by
fusb302_handle_togdone_snk resp. fusb302_handle_togdone_src when toggling
is done.

Together this allows us to simplify things to:

1) fusb302_set_cc_pull(...)
2) "reset cc status"
3) fusb302_set_src_current(...)
4) fusb302_set_toggling(new-toggling-mode)

This commit does this, leading to a nice cleanup.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-19 15:06:12 +01:00
Hans de Goede 31df7fadf5 usb: typec: fusb302: Make fusb302_set_cc_polarity also set pull ups / downs
The 2 callers of fusb302_set_cc_polarity both call fusb302_set_cc_pull
directly before calling fusb302_set_cc_polarity, this is not ideal for
2 reasons:

1) fusb302_set_cc_pull uses the cached polarity when applying the pull-ups,
which maybe changed immediately afterwards, to fix this set_cc_polarity
already does the pull-up setting.

2) Both touch the SWITCHES0 register in a r-w-modify cycle, this leads to
read reg, write reg, read reg, write reg. If we fold the setting of
the pull-downs into fusb302_set_cc_polarity then not only can we avoid
doing the reads / writes twice, at this point we set all bits, so we
can skip the read, turning 4 (slowish) i2c-transfers into 1.

Doing this also avoids the need to cache the pull_up state in
struct fusb302_chip.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-19 15:06:11 +01:00
Hans de Goede 976daf9d11 usb: typec: tcpm: Try PD-2.0 if sink does not respond to 3.0 source-caps
PD 2.0 sinks are supposed to accept src-capabilities with a 3.0 header and
simply ignore any src PDOs which the sink does not understand such as PPS
but some 2.0 sinks instead ignore the entire PD_DATA_SOURCE_CAP message,
causing contract negotiation to fail.

This commit fixes such sinks not working by re-trying the contract
negotiation with PD-2.0 source-caps messages if we don't have a contract
after PD_N_HARD_RESET_COUNT hard-reset attempts.

The problem fixed by this commit was noticed with a Type-C to VGA dongle.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-19 14:57:31 +01:00
Gustavo A. R. Silva e82adc1074 usb: typec: Fix unchecked return value
Currently there is no check on platform_get_irq() return value
in case it fails, hence never actually reporting any errors and
causing unexpected behavior when using such value as argument
for function regmap_irq_get_virq().

Fix this by adding a proper check, a message error and return
*irq* in case platform_get_irq() fails.

Addresses-Coverity-ID: 1443899 ("Improper use of negative value")
Fixes: d2061f9cc3 ("usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-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>
2019-03-19 14:57:31 +01:00
Guenter Roeck c17c7cf147 usb: typec: tcpm: Remove unused functions
tcpm_update_source_capabilities() and tcpm_update_sink_capabilities()
are not used anywhere, and I don't recall why I introduced those functions
in the first place. Effectively that means that we don't know if they even
work, or ever did. Lets remove them.

Reported-by: Kyle Tso <kyletso@google.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Kyle Tso <kyletso@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-13 19:40:20 +01:00
Greg Kroah-Hartman 15e99b13b4 Merge 5.0-rc6 into usb-next
We need the USB fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-11 09:28:39 +01:00
Kyle Tso a07ddce4df usb: typec: tcpm: Correct the PPS out_volt calculation
When Sink negotiates PPS, the voltage range of selected PPS APDO might
not cover the previous voltage (out_volt). If the previous out_volt is
lower than the new min_volt, the output voltage in RDO might be set to
an invalid value. For instance, supposed that the previous voltage is
5V, and the new voltage range in the APDO is 7V-12V. Then the output
voltage in the RDO should not be set to 5V which is lower than the
possible min_volt 7V.

Fix this by choosing the maximal value between the previous voltage and
the new min_volt first. And ensure that this value will not exceed the
new max_volt. The new out_volt will fall within the new voltage range
while being the closest value compared to the previous out_volt.

Signed-off-by: Kyle Tso <kyletso@google.com>
Reviewed-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Fixes: c710d0bb76 ("usb: typec: tcpm: Extend the matching rules on PPS APDO selection")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-31 09:14:00 +01:00
Jun Li 9997ab35f4 usb: typec: tpcm: improve error handling of tcpm_register_port
Remove debugfs if tcpm register port fails.

Signed-off-by: Li Jun <jun.li@nxp.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-25 10:02:50 +01:00
Greg Kroah-Hartman cae8dc3b68 USB: add missing SPDX lines to Kconfig and Makefiles
There are a few remaining drivers/usb/ files that do not have SPDX
identifiers in them, all of these are either Kconfig or Makefiles.  Add
the correct GPL-2.0 identifier to them to make scanning tools happy.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-22 09:08:17 +01:00
Kyle Tso c710d0bb76 usb: typec: tcpm: Extend the matching rules on PPS APDO selection
Current matching rules ensure that the voltage range of selected Source
Capability is entirely within the range defined in one of the Sink
Capabilities. This is reasonable but not practical because Sink may not
support wide range of voltage when sinking power while Source could
advertise its capabilities in relatively wider range. For example, a
Source PDO advertising 3.3V-11V@3A (9V Prog of Fixed Nominal Voltage)
will not be selected if the Sink requires 5V-12V@3A PPS power. However,
the Sink could work well if the requested voltage range in RDOs is
5V-11V@3A.

Currently accepted:
		|--------- source -----|
	|----------- sink ---------------|

Currently not accepted:
			|--------- source -----|
	|----------- sink ---------------|

	|--------- source -----|
		|----------- sink ---------------|

	|--------- source -----------------|
		|------ sink -------|

To improve the usability, change the matching rules to what listed
below:
a. The Source PDO is selectable if any portion of the voltage range
   overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
   selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
   maximum current defined in the selected Source PDO
d. Select the Source PDO with the highest maximum power

Signed-off-by: Kyle Tso <kyletso@google.com>
Acked-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-19 08:13:26 +01:00
Andy Shevchenko 440da5a30e staging: typec: fusb302: Rename fcs,extcon-name to linux,extcon-name
Since we are going to use the same in Designware USB 3 driver,
rename the property to be consistent across the drivers.

No functional change intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-05 10:25:43 +01:00
Badhri Jagan Sridharan 157c0f2f64 usb: typec: tcpm: charge current handling for sink during hard reset
During the initial connect to a non-pd port, sink would hard reset
twice before deeming that the port partner is non-pd. TCPM sets the
the charge path to false during the hard reset. This causes unnecessary
connects/disconnects of charge path and makes port take longer to
charge from the non-pd ports. Avoid this by not setting the charge path
to false unless the partner has already identified to be pd capable.

When partner is a pd port, set the charge path to false in
SNK_HARD_RESET_SINK_OFF. Set the current limits to default value based
of CC pull up and resume the charge path when port enters
SNK_HARD_RESET_SINK_ON.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

--------
Changes in V3:
Rebase on top of usb-next

Changes in V2:
Based on feedback of jackp@codeaurora.org
- vsafe_5v_hard_reset flag from tcpc_config is removed
- Patch only differentiates between pd port partner and non-pd port
partner

V1 version of the patch is here:
https://lkml.org/lkml/2018/9/14/11
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07 13:20:39 +01:00
Badhri Jagan Sridharan 23b5f73266 usb: typec: tcpm: Do not disconnect link for self powered devices
During HARD_RESET the data link is disconnected.
For self powered device, the spec is advising against doing that.

>From USB_PD_R3_0
7.1.5 Response to Hard Resets
Device operation during and after a Hard Reset is defined as follows:
Self-powered devices Should Not disconnect from USB during a Hard Reset
(see Section 9.1.2).
Bus powered devices will disconnect from USB during a Hard Reset due to the
loss of their power source.

Tackle this by letting TCPM know whether the device is self or bus powered.

This overcomes unnecessary port disconnections from hard reset.
Also, speeds up the enumeration time when connected to Type-A ports.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---------
Version history:
V3:
Rebase on top of usb-next

V2:
Based on feedback from heikki.krogerus@linux.intel.com
- self_powered added to the struct tcpm_port which is populated from
  a. "connector" node of the device tree in tcpm_fw_get_caps()
  b. "self_powered" node of the tcpc_config in tcpm_copy_caps

Based on feedbase from linux@roeck-us.net
- Code was refactored
- SRC_HARD_RESET_VBUS_OFF sets the link state to false based
  on self_powered flag

V1 located here:
https://lkml.org/lkml/2018/9/13/94
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07 13:20:39 +01:00
Adam Thomson 554fab6dbf usb: typec: tcpm: Report back negotiated PPS voltage and current
Currently when requesting a specific voltage or current through
the psy interface, for PPS, when reading back from that interface
the values will always be the same as previously given, if the
request was successful. However PPS only allows for 20mV voltage
steps and 50mA current steps, and the psy class expects microvolt
and micro amp requests, so inbetween values can be provided through
this interface. Really when reading back the true values negotiated
should be given, and not the ones originally asked for.

To report the actual values negotiated with the Source, the values
stored are now rounded down to the relevant step units prior to
building the PPS request, so that those values are later correctly
reported through the psy interface. In addition this improves the
adjustments made to meet the operating power requirements of the
platform, which previously could have been slightly out due to not
using valid PPS units of voltage and current.

Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09 16:05:41 +02:00
YueHaibing 8e4657c60c usb: typec: remove set but not used variables 'snk_ma, min_mv'
Fixes gcc '-Wunused-but-set-variable' warning:

drivers/usb/typec/tcpm/tcpm.c: In function 'tcpm_pd_select_pps_apdo':
drivers/usb/typec/tcpm/tcpm.c:2212:39: warning:
 variable 'snk_ma' set but not used [-Wunused-but-set-variable]

drivers/usb/typec/tcpm/tcpm.c: In function 'tcpm_pd_build_pps_request':
drivers/usb/typec/tcpm/tcpm.c:2405:37: warning:
 variable 'min_mv' set but not used [-Wunused-but-set-variable]

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-02 12:05:30 -07:00
Adam Thomson 1b6af2f58c usb: typec: tcpm: Fix APDO PPS order checking to be based on voltage
Current code mistakenly checks against max current to determine
order but this should be max voltage. This commit fixes the issue
so order is correctly determined, thus avoiding failure based on
a higher voltage PPS APDO having a lower maximum current output,
which is actually valid.

Fixes: 2eadc33f40 ("typec: tcpm: Add core support for sink side PPS")
Cc: <stable@vger.kernel.org>
Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.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-10-02 12:05:30 -07:00
Adam Thomson ea3b4d5523 usb: typec: fusb302: Resolve fixed power role contract setup
When the controller is configured for a fixed power role (Source
only or Sink only), attach does not proceed within the TCPM state
machine as there is no CC event generated by this driver to update
the CC line status.

To rectify this, when CC is configured as Source or Sink we now
make use of the hardware's automatic fixed Source or Sink
toggling mechanism, which detects attaches in the same way as for
DRP toggling. In this way the result of toggling is handled in the
same way by the 'fusb302_handle_togdone()' function, and CC events
are generated as expected for TCPM allowing a contract to be
established.

Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-28 15:08:09 +02:00
Adam Thomson 40326e857c usb: typec: fusb302: Correct spelling mistake for toggling state
There's a typo in the enum name of the 'OFF' state for toggling
(TOGGLINE instead of TOGGLING). This commit resolves that trivial
spelling inconsistency.

Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-28 15:08:09 +02:00
Heikki Krogerus ae8a2ca8a2 usb: typec: Group all TCPCI/TCPM code together
Moving all the drivers that depend on the Port Controller
Manager under a new directory drivers/usb/typec/tcpm/ and
making Guenter Roeck the designated reviewer of that code.

Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-20 13:37:29 +02:00