usb: typec: fusb302: Fix fusb302_handle_togdone_src Ra handling
authorHans de Goede <hdegoede@redhat.com>
Mon, 11 Mar 2019 10:48:15 +0000 (11:48 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Mar 2019 14:06:12 +0000 (15:06 +0100)
commit702ad49fb8d2d5c8f3ddd22e4119d9e507e5c1a2
tree881bcba190348673979847611faf44fe2741abb3
parent32a155b1a83d6659e2272e8e1eec199667b1897e
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>
drivers/usb/typec/tcpm/fusb302.c