Commit Graph

85 Commits

Author SHA1 Message Date
Heikki Krogerus 3524fe3153 usb: typec: mux: Remove alt mode parameters from the API
The alt mode descriptor parameters are not used anymore.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Tested-by: Bjorn Andersson <andersson@kernel.org>
Acked-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20230526131434.46920-3-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-05-29 15:17:52 +01:00
Colin Ian King b0d8a67715 platform/chrome: cros_ec_typec: Fix spelling mistake
There is a spelling mistake in a dev_warn message, make it lower case
and fix the spelling.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20230207091443.143995-1-colin.i.king@gmail.com
Signed-off-by: Prashant Malani <pmalani@chromium.org>
[pmalani fixed up commit message based on tzungbi comment]
2023-02-08 18:21:03 +00:00
Prashant Malani f54c013e7e platform/chrome: cros_typec_vdm: Add Attention support
Add support to retrieve VDM attention messages and forward them to the
appropriate alt mode driver.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20230126205620.3714994-2-pmalani@chromium.org
2023-01-31 18:12:18 +00:00
Victor Ding 13aba1e532 platform/chrome: cros_ec_typec: allow deferred probe of switch handles
`fwnode_typec_{retimer,mux,switch}_get()` could return `-EPROBE_DEFER`,
which is called from `cros_typec_get_switch_handles`. When this happens,
it does not indicate absence of switches; instead, it only hints that
probing of switches should occur at a later time.

Progagate `-EPROBE_DEFER` to upper layer logic so that they can re-try
probing switches as a better time.

Signed-off-by: Victor Ding <victording@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20230124075555.v3.1.I6c0a089123fdf143f94ef4cca8677639031856cf@changeid
Signed-off-by: Prashant Malani <pmalani@chromium.org>
2023-01-24 19:02:38 +00:00
Prashant Malani 50ed638bbc platform/chrome: cros_typec_vdm: Add VDM reply support
Handle response VDMs which are sent by the partner (replying to VDMs
sent by the host system itself). These get forwarded to the altmode
driver.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20221228004648.793339-10-pmalani@chromium.org
2023-01-09 20:32:54 +00:00
Prashant Malani 493e699b99 platform/chrome: cros_ec_typec: Add initial VDM support
Add ops to support USB PD VDM (Vendor Defined Message) from the port
driver. This enables the port driver to interface with alternate mode
drivers and communicate with connected peripherals.

The initial support just contains an implementation of the Enter
Mode command.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
[pmalani: Fixed trivial conflict in Makefile]
Reviewed-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20221228004648.793339-9-pmalani@chromium.org
2023-01-09 20:32:53 +00:00
Prashant Malani 6905809651 platform/chrome: cros_ec_typec: Move structs to header
Move ChromeOS Type-C structs into their own header, so they can be
referenced by other files which can be added to the same module.

No functional changes introduced by this patch.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20221228004648.793339-7-pmalani@chromium.org
2023-01-09 20:32:53 +00:00
Prashant Malani 8d2b28df6c platform/chrome: cros_ec_typec: Update port DP VDO
The port advertising DP support is a Type-C receptacle. Fix the port's
DisplayPort VDO to reflect this.

Fixes: 1903adae04 ("platform/chrome: cros_ec_typec: Add bit offset for DP VDO")
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20221228004648.793339-6-pmalani@chromium.org
2023-01-09 20:32:53 +00:00
Prashant Malani c856e3ff98 platform/chrome: cros_ec_typec: Set port alt mode drvdata
Save the ChromeOS-specific Type-C port info in the port altmodes' driver
data. This makes communication with the ChromeOS EC (Embedded
Controller) easier when alt mode drivers need to send messages to
peripherals.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20221228004648.793339-5-pmalani@chromium.org
2023-01-09 20:32:53 +00:00
Prashant Malani 4dc9355cef platform/chrome: cros_ec_typec: Stash port driver info
Stash port number and a pointer to the driver-specific struct in the
local typec port struct.

These can be useful to the port driver to figure out how to communicate
with the Chrome EC when an altmode-driver related callback is invoked
from the Type-C class code.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20221228004648.793339-4-pmalani@chromium.org
2023-01-09 20:32:53 +00:00
Linus Torvalds 58bcac11fd USB/Thunderbolt driver changes for 6.2-rc1
Here is the large set of USB and Thunderbolt driver changes for 6.2-rc1.
 Overall, thanks to the removal of a driver, more lines were removed than
 added, a nice change.  Highlights include:
   - removal of the sisusbvga driver that was not used by anyone anymore
   - minor thunderbolt driver changes and tweaks
   - chipidea driver updates
   - usual set of typec driver features and hardware support added
   - musb minor driver fixes
   - fotg210 driver fixes, bringing that hardware back from the "dead"
   - minor dwc3 driver updates
   - addition, and then removal, of a list.h helper function for many USB
     and other subsystem drivers, that ended up breaking the build.  That
     will come back for 6.3-rc1, it missed this merge window.
   - usual xhci updates and enhancements
   - usb-serial driver updates and support for new devices
   - other minor USB driver updates
 
 All of these have been in linux-next for a while with no reported
 problems.
 
 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 -----BEGIN PGP SIGNATURE-----
 
 iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCY5wvYg8cZ3JlZ0Brcm9h
 aC5jb20ACgkQMUfUDdst+yl5DACgssl/ag4zDePHpfoiG5zEGEzH8XsAoMFrzvzu
 d43hsH3qsfDGSZRkJJMu
 =ORDd
 -----END PGP SIGNATURE-----

Merge tag 'usb-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB and Thunderbolt driver updates from Greg KH:
 "Here is the large set of USB and Thunderbolt driver changes for
  6.2-rc1. Overall, thanks to the removal of a driver, more lines were
  removed than added, a nice change. Highlights include:

   - removal of the sisusbvga driver that was not used by anyone anymore

   - minor thunderbolt driver changes and tweaks

   - chipidea driver updates

   - usual set of typec driver features and hardware support added

   - musb minor driver fixes

   - fotg210 driver fixes, bringing that hardware back from the "dead"

   - minor dwc3 driver updates

   - addition, and then removal, of a list.h helper function for many
     USB and other subsystem drivers, that ended up breaking the build.
     That will come back for 6.3-rc1, it missed this merge window.

   - usual xhci updates and enhancements

   - usb-serial driver updates and support for new devices

   - other minor USB driver updates

  All of these have been in linux-next for a while with no reported
  problems"

* tag 'usb-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (153 commits)
  usb: gadget: uvc: Rename bmInterfaceFlags -> bmInterlaceFlags
  usb: dwc2: power on/off phy for peripheral mode in dual-role mode
  usb: dwc2: disable lpm feature on Rockchip SoCs
  dt-bindings: usb: mtk-xhci: add support for mt7986
  usb: dwc3: core: defer probe on ulpi_read_id timeout
  usb: ulpi: defer ulpi_register on ulpi_read_id timeout
  usb: misc: onboard_usb_hub: add Genesys Logic GL850G hub support
  dt-bindings: usb: Add binding for Genesys Logic GL850G hub controller
  dt-bindings: vendor-prefixes: add Genesys Logic
  usb: fotg210-udc: fix potential memory leak in fotg210_udc_probe()
  usb: typec: tipd: Set mode of operation for USB Type-C connector
  usb: gadget: udc: drop obsolete dependencies on COMPILE_TEST
  usb: musb: remove extra check in musb_gadget_vbus_draw
  usb: gadget: uvc: Prevent buffer overflow in setup handler
  usb: dwc3: qcom: Fix memory leak in dwc3_qcom_interconnect_init
  usb: typec: wusb3801: fix fwnode refcount leak in wusb3801_probe()
  usb: storage: Add check for kcalloc
  USB: sisusbvga: use module_usb_driver()
  USB: sisusbvga: rename sisusb.c to sisusbvga.c
  USB: sisusbvga: remove console support
  ...
2022-12-16 03:22:53 -08:00
Victor Ding 9a8aadcf0b platform/chrome: cros_ec_typec: zero out stale pointers
`cros_typec_get_switch_handles` allocates four pointers when obtaining
type-c switch handles. These pointers are all freed if failing to obtain
any of them; therefore, pointers in `port` become stale. The stale
pointers eventually cause use-after-free or double free in later code
paths. Zeroing out all pointer fields after freeing to eliminate these
stale pointers.

Fixes: f28adb41da ("platform/chrome: cros_ec_typec: Register Type C switches")
Fixes: 1a8912caba ("platform/chrome: cros_ec_typec: Get retimer handle")
Signed-off-by: Victor Ding <victording@chromium.org>
Acked-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20221207093924.v2.1.I1864b6a7ee98824118b93677868d22d3750f439b@changeid
2022-12-08 09:44:48 +08:00
Prashant Malani ab3593eeef platform/chrome: cros_ec_typec: Set parent of partner PD object
In order to tell what Type-C device a PD object belongs to, its parent
needs to be set. Use the Type-C partner USB PD registration wrapper
to set the parent appropriately for PD objects which are created for
connected Type-C partners.

Cc: Benson Leung <bleung@chromium.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20221122220538.2991775-3-pmalani@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-11-29 08:56:09 +01:00
Prashant Malani 348a2e8c93 platform/chrome: cros_ec_typec: Register partner PDOs
The ChromeOS EC exports partner source/sink cap PDOs (Power Data
Objects) to the application processor (AP). Use this information
to register USB PD (Power Delivery) capabilities with the
USB Type-C Power Delivery device class.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20220830202018.1884851-1-pmalani@chromium.org
[pmalani: Remove extra newline nit from original patch]
2022-09-07 18:02:57 +00:00
Prashant Malani 4e477663e3 platform/chrome: cros_ec_typec: Correct alt mode index
Alt mode indices used by USB PD (Power Delivery) start with 1, not 0.

Update the alt mdoe registration code to factor this in to the alt mode
descriptor.

Fixes: de0f49487d ("platform/chrome: cros_ec_typec: Register partner altmodes")
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220819190807.1275937-3-pmalani@chromium.org
2022-08-26 22:34:02 +00:00
Prashant Malani 1903adae04 platform/chrome: cros_ec_typec: Add bit offset for DP VDO
Use the right macro while constructing the DP_PORT_VDO to ensure the Pin
Assignment offsets are correct.

Fixes: 1ff5d97f07 ("platform/chrome: cros_ec_typec: Register port altmodes")
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220819190807.1275937-2-pmalani@chromium.org
2022-08-26 22:34:02 +00:00
Prashant Malani 1a8912caba platform/chrome: cros_ec_typec: Get retimer handle
Where available, obtain the handle to retimer switch specified via
firmware, and update the mux configuration callsites to add retimer
support for supported modes.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220816214857.2088914-8-pmalani@chromium.org
2022-08-18 22:20:36 +00:00
Prashant Malani d5f66527db platform/chrome: cros_ec_typec: Cleanup switch handle return paths
Some of the return paths for the cros_typec_get_switch_handles()
aren't necessary. Clean up the return paths to only undo the handle
get's which succeeded.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220816214857.2088914-7-pmalani@chromium.org
2022-08-18 22:20:36 +00:00
Prashant Malani 1ff5d97f07 platform/chrome: cros_ec_typec: Register port altmodes
Instead of using manually managed altmode structs, register the port's
altmodes with the Type-C framework. This facilitates matching them to
partner altmodes later.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20220712210318.2671292-2-pmalani@chromium.org
2022-07-18 19:13:03 +00:00
Prashant Malani a47bc5a0c4 platform/chrome: cros_ec_typec: Rename port altmode array
Rename "p_altmode" to "port_altmode" which is a less ambiguous name for
the port_altmode struct array.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20220712210318.2671292-1-pmalani@chromium.org
2022-07-18 19:13:02 +00:00
Nícolas F. R. A. Prado ce838f7dc7 platform/chrome: cros_ec_typec: Use dev_err_probe on port register fail
The typec_register_port() can fail with EPROBE_DEFER if the endpoint
node hasn't probed yet. In order to avoid spamming the log with errors
in that case, log using dev_err_probe().

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20220712214554.545035-1-nfraprado@collabora.com
Signed-off-by: Prashant Malani <pmalani@chromium.org>
2022-07-13 17:28:17 +00:00
Prashant Malani b1d288d9c3 platform/chrome: cros_ec_proto: Rename cros_ec_command function
cros_ec_command() is the name of a function as well as a struct, as such
it can confuse indexing tools (like ctags). Avoid this by renaming it to
cros_ec_cmd(). Update all the callsites to use the new name.

This patch is a find-and-replace, so should not introduce any functional
changes.

Suggested-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220606201825.763788-3-pmalani@chromium.org
2022-06-08 08:14:53 +00:00
Akihiko Odaki 7464ff8bf2 platform/chrome: cros_ec_typec: Check for EC driver
The EC driver may not be initialized when cros_typec_probe is called,
particulary when CONFIG_CROS_EC_CHARDEV=m.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220404041101.6276-1-akihiko.odaki@gmail.com
Signed-off-by: Prashant Malani <pmalani@chromium.org>
2022-05-10 22:47:40 +00:00
Prashant Malani b579f139e4 platform/chrome: cros_ec_typec: Update mux flags during partner removal
In cros_typec_remove_partner(), we call
cros_typec_usb_disconnect_state() which sets the switches/muxes to be in
a disconnected state. This also happens in cros_typec_configure_mux().
However, unlike there, here the mux_flags variable hasn't been updated
to reflect that a disconnection has occurred. Update the flag here
accordingly.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Tzung-Bi Shih <tzungbi@google.com>
Link: https://lore.kernel.org/chrome-platform/20220208184721.1697194-5-pmalani@chromium.org/
2022-02-15 19:50:30 +00:00
Prashant Malani af34f115b3 platform/chrome: cros_ec_typec: Configure muxes at start of port update
There are situations where the mux state reported by the Embedded
Controller (EC), might lag the partner "connected" state. So, the mux
state might still suggest that a partner is connected, while the PD
"connected" state, being in Try.SNK (for example) suggests that the
partner is disconnected.

In such a scenario, we will end up sending a disconnect command to the
mux driver, followed by a connect command, since the mux is configured
later. Avoid this by configuring the mux before
registering/disconnecting a partner.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Link: https://lore.kernel.org/chrome-platform/20220208184721.1697194-4-pmalani@chromium.org/
2022-02-15 19:50:04 +00:00
Prashant Malani 0d8495dc03 platform/chrome: cros_ec_typec: Get mux state inside configure_mux
Move the function which gets current mux state inside the
cros_typec_configure_mux() function. It is better to group those
bits of functionality together, and it makes it easier to move around
cros_typec_configure_mux() later.

While we are doing this, also inline the cros_typec_get_mux_info() inside
of cros_typec_configure_mux().

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Tzung-Bi Shih <tzungbi@google.com>
Link: https://lore.kernel.org/chrome-platform/20220208184721.1697194-3-pmalani@chromium.org/
2022-02-15 19:49:49 +00:00
Prashant Malani 53a0023c64 platform/chrome: cros_ec_typec: Move mux flag checks
Move mux and role flag checks inside of cros_typec_configure_mux(),
which is a more logical location for them.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Tzung-Bi Shih <tzungbi@google.com>
Link: https://lore.kernel.org/chrome-platform/20220208184721.1697194-2-pmalani@chromium.org/
2022-02-15 19:49:20 +00:00
Prashant Malani ffebd90532
platform/chrome: cros_ec_typec: Check for EC device
The Type C ACPI device on older Chromebooks is not generated correctly
(since their EC firmware doesn't support the new commands required). In
such cases, the crafted ACPI device doesn't have an EC parent, and it is
therefore not useful (it shouldn't be generated in the first place since
the EC firmware doesn't support any of the Type C commands).

To handle devices which use these older firmware revisions, check for
the parent EC device handle, and fail the probe if it's not found.

Fixes: fdc6b21e24 ("platform/chrome: Add Type C connector class driver")
Reported-by: Alyssa Ross <hi@alyssa.is>
Reviewed-by: Tzung-Bi Shih <tzungbi@google.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Alyssa Ross <hi@alyssa.is>
Tested-by: Alyssa Ross <hi@alyssa.is>
Link: https://lore.kernel.org/r/20220126190219.3095419-1-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2022-02-01 09:54:39 -08:00
Prashant Malani 53eeb07381 platform/chrome: cros_ec_typec: Make try power role optional
Some boards prefer not to specify a try-power-role. Update the port
property parsing logic to not error out in case a try-power-role is not
specified.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/chrome-platform/20220127191659.3560810-1-pmalani@chromium.org/
2022-01-31 21:19:29 +00:00
Prashant Malani fb75686bed platform/chrome: cros_ec_typec: Use cros_ec_command()
Re-use the existing cros_ec_command() instead of relying on a duplicate
version.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210930022403.3358070-6-pmalani@chromium.org
2021-09-30 10:09:47 +02:00
Prashant Malani 73eff8602a platform/chrome: cros-ec-typec: Cleanup use of check_features
cros_ec_check_features() now returns a boolean. Remove the double NOT
operator since it's not required anymore.

No functional changes are expected with this patch.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210923200321.3623222-1-pmalani@chromium.org
2021-09-24 08:47:36 +02:00
Prashant Malani a8db7a3f8a
platform/chrome: cros_ec_typec: Use existing feature check
Replace the cros_typec_feature_supported() function with the
pre-existing cros_ec_check_features() function which does the same
thing.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20210803173619.91539-2-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-08-23 10:24:46 -07:00
Prashant Malani c5bb32f57b platform/chrome: cros_ec_typec: Add DP mode check
There are certain transitional situations where the dp_mode field in the
PD_CONTROL response might not be populated with the right DP pin
assignment value yet. Add a check for that to avoid sending an invalid
value to the Type C mode switch.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210421042108.2002-1-pmalani@chromium.org
2021-04-21 09:33:35 +02:00
Prashant Malani 944b3a6395 platform/chrome: cros_ec_typec: Handle hard reset
The Chrome Embedded Controller (EC) generates a hard reset type C event
when a USB Power Delivery (PD) hard reset is encountered. Handle this
event by unregistering the partner and cable on the associated port and
clearing the event flag.

Cc: Benson Leung <bleung@chromium.org>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210420171617.3830902-2-pmalani@chromium.org
2021-04-20 19:35:42 +02:00
Prashant Malani 670160fea2 platform/chrome: cros_ec_typec: Track port role
Stash the currently reported port role in the port struct and add a
check for that too while determining whether to re-configure on-board
Type C switches (this deals with cases like role swaps where the mux
flags don't change, but the port role does).

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Suggested-by: Nikunj A. Dadhania <nikunj.dadhania@intel.com>
Tested-by: Deepti Deshatty <deepti.deshatty@intel.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210420171008.3829549-1-pmalani@chromium.org
2021-04-20 19:35:42 +02:00
Arnd Bergmann c6e939c63c platform/chrome: cros_ec_typec: fix clang -Wformat warning
Clang warns about using the %h format modifier to truncate an
integer:

drivers/platform/chrome/cros_ec_typec.c:1031:3: error: format specifies type 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]
                typec->pd_ctrl_ver);
                ^~~~~~~~~~~~~~~~~~
include/linux/dev_printk.h:131:47: note: expanded from macro 'dev_dbg'
                dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
                                                    ~~~     ^~~~~~~~~~~

Use an explicit bit mask to limit the number to its lower eight bits
instead.

Fixes: ad7c0510c9 ("platform/chrome: cros_ec_typec: Update port info from EC")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210322115602.4003221-1-arnd@kernel.org
2021-03-30 18:28:50 +02:00
Prashant Malani 639ff208cb platform/chrome: cros_ec_typec: Check for device within remove function
In a couple of call sites, we use the same pattern of checking for a
partner or cable device before attempting to remove it. Simplify this by
moving those checks into the remove functions.

Cc: Benson Leung <bleung@chromium.org>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210319015103.3751672-1-pmalani@chromium.org
2021-03-30 18:25:22 +02:00
Linus Torvalds b996c10e0f chrome platform changes for 5.12
Lots of changes to the cros_ec_typec driver for 5.12.
 A portion of this this set of cros_ec_typec driver's changes
 (up to 8553a979fc  platform/chrome: cros_ec_typec: Send mux configuration acknowledgment to EC)
 was merged through GregKH's USB tree in immutable branch
 tag-ib-usb-typec-chrome-platform-cros-ec-typec-changes-for-5.12
 in order to satisfy cros_ec_typec driver and typec connector class subsystem
 dependencies of subsequent changes. Please see greg's usb-5.12-rc1.
 
 cros_ec_typec:
 * Registration of cable plug information
 * Support for SOP' plug registration and altmodes
 * Support for reporting number of altmodes supported by partners and plugs
 * Send mux configuration ack to EC via a new host command
 * Support mux control with no port partner present
 * Decouple cable removal from partner removal
 
 cros_ec misc:
 * Fix some event masking in cros_ec_proto.
 * Gwendal reworked cros_ec's top and bottom half for consistency in ishtp and
   rpmsg
 * Constify static attribute_group structs
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCYC3jIgAKCRBzbaomhzOw
 wpNqAQCTtcpgAVit937B11VSjjJmT+Cb4evb5ny7BgFSzdCjtwD+Kg2AlJWGri5z
 2AdFurQNqBu5FxlegXZbYa2tONVHqwE=
 =3NuV
 -----END PGP SIGNATURE-----

Merge tag 'tag-chrome-platform-for-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux

Pull chrome platform updates from Benson Leung:
 "Lots of changes to the cros_ec_typec driver for 5.12.

  A portion of this this set of cros_ec_typec driver's changes was
  merged through GregKH's USB tree in order to satisfy cros_ec_typec
  driver and typec connector class subsystem dependencies of subsequent
  changes.

  Summary:

  cros_ec_typec:
   - Registration of cable plug information
   - Support for SOP' plug registration and altmodes
   - Support for reporting number of altmodes supported by partners and
     plugs
   - Send mux configuration ack to EC via a new host command
   - Support mux control with no port partner present
   - Decouple cable removal from partner removal

  cros_ec misc:
   - Fix some event masking in cros_ec_proto.
   - Gwendal reworked cros_ec's top and bottom half for consistency in
     ishtp and rpmsg
   - Constify static attribute_group structs"

* tag 'tag-chrome-platform-for-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
  platform/chrome: cros_ec_typec: Flush pending work
  platform/chrome: cros_ec_types: Support disconnect events without partners
  platform/chrome: cros_ec_typec: Skip port partner check in configure_mux()
  platform/chrome: cros_ec_typec: Decouple partner removal
  platform/chrome: cros_ec: Call interrupt bottom half at probe time
  platform/chrome: cros_ec: Call interrupt bottom half in ISH or RPMSG mode
  platform/chrome: cros_ec_sysfs: Add cold-ap-off to sysfs reboot.
  platform/chrome: cros_ec_commands: Add host command to keep AP off after EC reset.
  platform/chrome: Constify static attribute_group structs
  platform/chrome: cros_ec_proto: Add LID and BATTERY to default mask
  platform/chrome: cros_ec_proto: Use EC_HOST_EVENT_MASK not BIT
2021-02-22 09:36:23 -08:00
Prashant Malani a59e12218c
platform/chrome: cros_ec_typec: Flush pending work
When a PD notifier event arrives, a new work event won't be enqueued if
the current one hasn't completed. This could lead to dropped events.

So, flush any pending work before scheduling the new instance.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20210211193221.610867-1-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-02-11 13:18:46 -08:00
Rajmohan Mani b4b06c9772
platform/chrome: cros_ec_types: Support disconnect events without partners
There are certain scenarios, where a disconnect event might
occur on a Type-C port with no port partners. This is required
to enable communication to Burnside Bridge USB4 retimers.

Signed-off-by: Rajmohan Mani <rajmohan.mani@intel.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20210205195113.20277-3-rajmohan.mani@intel.com
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-02-05 16:43:09 -08:00
Rajmohan Mani 38f56061c8
platform/chrome: cros_ec_typec: Skip port partner check in configure_mux()
For certain needs like updating the USB4 retimer firmware when no
device are connected, the Type-C ports require mux configuration,
to be able to communicate with the retimer. So removed the above
check to allow for mux configuration of Type-C ports, to enable
retimer communication.

Signed-off-by: Rajmohan Mani <rajmohan.mani@intel.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20210205195113.20277-2-rajmohan.mani@intel.com
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-02-05 16:41:00 -08:00
Prashant Malani c8ec21c6d2
platform/chrome: cros_ec_typec: Clear Type C disc events
Clear USB Type C discovery events from the Chrome EC once they've been
successfully handled.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reported-by: Benson Leung <bleung@chromium.org>
Tested-by: Benson Leung <bleung@chromium.org>
Link: https://lore.kernel.org/r/20210203021539.745239-2-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-02-04 10:29:30 -08:00
Prashant Malani d9f12f9e6c
platform/chrome: cros_ec_typec: Decouple partner removal
Currently, we return if there is no partner present when
!PD_CTRL_RESP_ENABLED_CONNECTED, without proceeding further. This ties
partner removal to cable removal, whereas the two should be independent.

Update the check to remove a partner if one was registered, but continue
after that instead of returning.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20210202224001.3810274-1-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-02-02 15:00:45 -08:00
Benson Leung 64eaa0fa66 platform/chrome: cros_ec_typec: Fix call to typec_partner_set_pd_revision
typec_partner_set_pd_revision returns void now.

Fixes: cefc011f8d ("platform/chrome: cros_ec_typec: Set Partner PD revision from status")
Signed-off-by: Benson Leung <bleung@chromium.org>
Link: https://lore.kernel.org/r/20210202164531.3982778-1-bleung@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-02-02 19:42:52 +01:00
Benson Leung 0371616d8b
platform/chrome: cros_ec_typec: Set opmode to PD on SOP connected
When SOP Discovery is done, set the opmode to PD if status indicates
SOP is connected.

SOP connected indicates a PD contract is in place, and is a solid
indication we have transitioned to PD power negotiation, either as
source or sink.

Signed-off-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20210129061406.2680146-7-bleung@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-02-01 23:49:54 -08:00
Benson Leung cefc011f8d
platform/chrome: cros_ec_typec: Set Partner PD revision from status
Status provides sop_revision. Process it, and set it using the new
setter in the typec class.

Signed-off-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Prashant Malani <pmalani@chomium.org>
Link: https://lore.kernel.org/r/20210129061406.2680146-6-bleung@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-02-01 23:49:54 -08:00
Benson Leung 3b3dd1f0db
platform/chrome: cros_ec_typec: Report SOP' PD revision from status
cros_typec_handle_sop_prime_disc now takes the PD revision provided
by the EC_CMD_TYPEC_STATUS command response for the SOP'.

Attach the properly formatted pd_revision to the cable desc before
registering the cable.

Signed-off-by: Benson Leung <bleung@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20210129061406.2680146-5-bleung@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-02-01 23:49:54 -08:00
Utkarsh Patel 8553a979fc
platform/chrome: cros_ec_typec: Send mux configuration acknowledgment to EC
In some corner cases downgrade of the superspeed typec device(e.g. Dell
typec Dock, apple dongle) was seen because before the SOC mux configuration
finishes, EC starts configuring the next mux state.

With this change, once the SOC mux is configured, kernel will send an
acknowledgment to EC via Host command EC_CMD_USB_PD_MUX_ACK [1].
After sending the host event EC will wait for the acknowledgment from
kernel before starting the PD negotiation for the next mux state. This
helps to have a framework to build better error handling along with the
synchronization of timing sensitive mux states.

This change also brings in corresponding EC header updates from the EC code
base [1].

[1]:
https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/master/include/ec_commands.h

Signed-off-by: Utkarsh Patel <utkarsh.h.patel@intel.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Benson Leung <bleung@chromium.org>
Link: https://lore.kernel.org/r/20201210060903.2205-3-utkarsh.h.patel@intel.com
2021-01-05 12:57:15 -08:00
Utkarsh Patel ba8ce51545
platform/chrome: cros_ec_typec: Parameterize cros_typec_cmds_supported()
cros_typec_cmds_supported() is currently being used to check only one
feature flag.
Add a new feature parameter to it so that it can be used to check
multiple feature flags supported in cros_ec.
Rename cros_typec_cmds_supported() to cros_typec_feature_supported().

Signed-off-by: Utkarsh Patel <utkarsh.h.patel@intel.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Benson Leung <bleung@chromium.org>
Link: https://lore.kernel.org/r/20201210060903.2205-2-utkarsh.h.patel@intel.com
2021-01-05 12:57:15 -08:00
Prashant Malani 1563090965
platform/chrome: cros_ec_typec: Register plug altmodes
Modify the altmode registration (and unregistration) code so that it
can be used by both partners and plugs.

Then, add code to register plug altmodes using the newly parameterized
function. Also set the number of alternate modes for the plug using the
associated Type C connector class function
typec_plug_set_num_altmodes().

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Benson Leung <bleung@chromium.org>
Link: https://lore.kernel.org/r/20201116201150.2919178-12-pmalani@chromium.org
2021-01-05 11:07:40 -08:00