Commit Graph

586 Commits

Author SHA1 Message Date
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
Jiang Jian 3de7203115 platform/chrome: wilco_ec: event: Fix typo in comment
Drop the redundant word 'the'.

Signed-off-by: Jiang Jian <jiangjian@cdjrlc.com>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220622061442.18242-1-jiangjian@cdjrlc.com
2022-06-24 04:01:13 +00:00
Stephen Boyd 74bb746407 platform/chrome: cros_ec: Always expose last resume result
The last resume result exposing logic in cros_ec_sleep_event()
incorrectly requires S0ix support, which doesn't work on ARM based
systems where S0ix doesn't exist. That's because cros_ec_sleep_event()
only reports the last resume result when the EC indicates the last sleep
event was an S0ix resume. On ARM systems, the last sleep event is always
S3 resume, but the EC can still detect sleep hang events in case some
other part of the AP is blocking sleep.

Always expose the last resume result if the EC supports it so that this
works on all devices regardless of S0ix support. This fixes sleep hang
detection on ARM based chromebooks like Trogdor.

Cc: Rajat Jain <rajatja@chromium.org>
Cc: Matthias Kaehlcke <mka@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Reviewed-by: Evan Green <evgreen@chromium.org>
Fixes: 7235560ac7 ("platform/chrome: Add support for v1 of host sleep event")
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220614075726.2729987-1-swboyd@chromium.org
2022-06-14 08:18:18 +00:00
Colin Ian King 203b2aff47 platform/chrome: cros_ec_proto: Fix spelling mistake "unknwon" -> "unknown"
There is a spelling mistake in a dev_dbg message. Fix it.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220614064909.47804-1-colin.i.king@gmail.com
2022-06-14 07:01:24 +00:00
Tzung-Bi Shih cfed691b80 platform/chrome: cros_ec_proto: handle empty payload in getting wake mask
cros_ec_get_host_event_wake_mask() expects to receive
sizeof(struct ec_response_host_event_mask) from send_command().  The
payload is valid only if the return value is positive.

Return -EPROTO if send_command() returns 0 in
cros_ec_get_host_event_wake_mask().

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-22-tzungbi@kernel.org
2022-06-10 02:31:44 +00:00
Tzung-Bi Shih e437722942 platform/chrome: cros_ec_proto: add Kunit test for getting wake mask
cros_ec_get_host_event_wake_mask() expects to receive
sizeof(struct ec_response_host_event_mask) from send_command().
The payload is valid only if the return value is positive.

Add Kunit tests for returning 0 from send_command() in
cros_ec_get_host_event_wake_mask().

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-21-tzungbi@kernel.org
2022-06-10 02:31:44 +00:00
Tzung-Bi Shih d65da5f9bb platform/chrome: cros_ec_proto: return 0 on getting wake mask success
cros_ec_get_host_event_wake_mask() used to return value from
send_command() which is number of bytes for input payload on success
(i.e. sizeof(struct ec_response_host_event_mask)).

However, the callers don't need to know how many bytes are available.

Don't return number of available bytes.  Instead, return 0 on success;
otherwise, negative integers on error.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-20-tzungbi@kernel.org
2022-06-10 02:31:44 +00:00
Tzung-Bi Shih aac29b04dc platform/chrome: cros_ec_proto: handle empty payload in getting cmd mask
cros_ec_get_host_command_version_mask() expects to receive
sizeof(struct ec_response_get_cmd_versions) from send_command().  The
payload is valid only if the return value is positive.

Return -EPROTO if send_command() returns 0 in
cros_ec_get_host_command_version_mask().

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-19-tzungbi@kernel.org
2022-06-10 02:31:44 +00:00
Tzung-Bi Shih 8120febafc platform/chrome: cros_ec_proto: add Kunit tests for getting cmd mask
cros_ec_get_host_command_version_mask() expects to receive
sizeof(struct ec_response_get_cmd_versions) from send_command().
The payload is valid only if the return value is positive.

Add Kunit tests for returning 0 from send_command() in
cros_ec_get_host_command_version_mask().

Note that because the 2 cros_ec_get_host_command_version_mask() use the
same `ver_mask`.  cros_ec_proto_test_query_all_no_host_sleep_return0()
polluates the `ver_mask` and returns 0 on the second send_command() to
make sure the second cros_ec_get_host_command_version_mask() doesn't
take the garbage from the previous call.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-18-tzungbi@kernel.org
2022-06-10 02:31:44 +00:00
Tzung-Bi Shih ec51348993 platform/chrome: cros_ec_proto: check `msg->result` in getting cmd mask
cros_ec_get_host_command_version_mask() should check if EC wasn't happy
by checking `msg->result`.

Use cros_ec_map_error() and return the error code if any.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-17-tzungbi@kernel.org
2022-06-10 02:31:44 +00:00
Tzung-Bi Shih a8f77c63ba platform/chrome: cros_ec_proto: add Kunit test for getting cmd mask error
cros_ec_query_all() uses cros_ec_get_host_command_version_mask() to
query the supported MKBP version; cros_ec_get_host_command_version_mask()
uses send_command() for transferring the host command.

Returning >=0 from send_command() only denotes the transfer was success.
cros_ec_get_host_command_version_mask() should check if EC wasn't happy
by checking `msg->result`.

Add a Kunit test for returning error in `msg->result` in
cros_ec_get_host_command_version_mask().  For the case,
cros_ec_query_all() should find the EC device doesn't support MKBP.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-16-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih f91183aa45 platform/chrome: cros_ec_proto: return 0 on getting cmd mask success
cros_ec_get_host_command_version_mask() used to return value from
send_command() which is number of available bytes for input payload on
success (i.e. sizeof(struct ec_response_get_cmd_versions)).

However, the callers don't need to know how many bytes are available.

Don't return number of available bytes.  Instead, return 0 on success;
otherwise, negative integers on error.

Also remove the unneeded `ver_mask` initialization as the callers should
take it only if cros_ec_get_host_command_version_mask() returns 0.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-15-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih b36f0643ff platform/chrome: cros_ec_proto: don't show MKBP version if unsupported
It wrongly showed the following message when it doesn't support MKBP:
"MKBP support version 4294967295".

Fix it.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-14-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih d394ab5c06 platform/chrome: cros_ec_proto: handle empty payload in getting info legacy
cros_ec_get_proto_info_legacy() expects to receive
sizeof(struct ec_response_hello) from send_command().  The payload is
valid only if the return value is positive.

Return -EPROTO if send_command() returns 0 in
cros_ec_get_proto_info_legacy().

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-13-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih cce5d55180 platform/chrome: cros_ec_proto: add Kunit test for getting legacy info
cros_ec_get_proto_info_legacy() expects to receive
sizeof(struct ec_response_hello) from send_command().  The payload is
valid only if the return value is positive.

Add a Kunit test for returning 0 from send_command() in
cros_ec_get_proto_info_legacy().

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-12-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih a88f79666d platform/chrome: cros_ec_proto: separate cros_ec_get_proto_info_legacy()
Rename cros_ec_host_command_proto_query_v2() to
cros_ec_get_proto_info_legacy() and make it responsible for setting
`ec_dev` fields for EC protocol v2.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-11-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih 878c36f6ca platform/chrome: cros_ec_proto: handle empty payload in getting proto info
cros_ec_get_proto_info() expects to receive
sizeof(struct ec_response_get_protocol_info) from send_command().  The
payload is valid only if the return value is positive.

Return -EPROTO if send_command() returns 0 in cros_ec_get_proto_info().

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-10-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih 3e97581ed9 platform/chrome: cros_ec_proto: add Kunit tests for getting proto info
cros_ec_get_proto_info() expects to receive
sizeof(struct ec_response_get_protocol_info) from send_command().  The
payload is valid only if the return value is positive.

Add Kunit tests for returning 0 from send_command() in
cros_ec_get_proto_info().

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-9-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih b4d0836e81 platform/chrome: cros_ec_proto: separate cros_ec_get_proto_info()
Rename cros_ec_host_command_proto_query() to cros_ec_get_proto_info()
and make it responsible for setting `ec_dev` fields according to the
response protocol info.

Also make cros_ec_get_host_event_wake_mask() allocate its own message
buffer.  It was lucky that size of `struct ec_response_host_event_mask`
is less than `struct ec_response_get_protocol_info`.  Thus, the buffer
wasn't overflow.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-8-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih 93bea2faed platform/chrome: cros_ec_proto: use cros_ec_map_error()
Use cros_ec_map_error() in cros_ec_get_host_event_wake_mask().

The behavior of cros_ec_get_host_event_wake_mask() slightly changed.  It
is acceptable because the caller only needs it returns negative integers
for indicating errors.  Especially, the EC_RES_INVALID_COMMAND still
maps to -EOPNOTSUPP.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-7-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih 8e3991610b platform/chrome: cros_ec_proto: remove redundant NULL check
send_command() already checks if `ec_dev->pkt_xfer` is NULL.  Remove the
redundant check.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-6-tzungbi@kernel.org
2022-06-10 02:31:43 +00:00
Tzung-Bi Shih e796c0c4b1 platform/chrome: cros_ec_proto: assign buffer size from protocol info
`din_size` is calculated from `ec_dev->max_response`.
`ec_dev->max_response` is further calculated from the protocol info.

To make it clear, assign `din_size` and `dout_size` from protocol info
directly.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-5-tzungbi@kernel.org
2022-06-10 02:31:42 +00:00
Tzung-Bi Shih 3db0c9e5de platform/chrome: use macros for passthru indexes
Move passthru indexes for EC and PD devices to common header.  Also use
them instead of literal constants.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-4-tzungbi@kernel.org
2022-06-10 02:31:42 +00:00
Tzung-Bi Shih b99eb596ef platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_query_all()
cros_ec_query_all() sends multiple host commands to EC for querying
supported protocols and settings.

Add required mock for interacting with cros_ec_query_all() and Kunit
tests.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-3-tzungbi@kernel.org
2022-06-10 02:31:42 +00:00
Tzung-Bi Shih 40f5814374 platform/chrome: cros_kbd_led_backlight: support EC PWM backend
EC PWM backend uses EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT and
EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT for setting and getting the brightness
respectively.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Tested-by: Matthias Kaehlcke <mka@chromium.org>
Link: https://lore.kernel.org/r/20220523090822.3035189-6-tzungbi@kernel.org
2022-06-10 02:31:42 +00:00
Tzung-Bi Shih fd1e8054ff platform/chrome: cros_kbd_led_backlight: support OF match
For letting device tree based machines to use the driver, support OF match.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Link: https://lore.kernel.org/r/20220523090822.3035189-5-tzungbi@kernel.org
2022-06-10 02:31:42 +00:00
Tzung-Bi Shih 6b1e5ba39c platform/chrome: cros_kbd_led_backlight: separate ACPI backend
cros_kbd_led_backlight uses ACPI_KEYBOARD_BACKLIGHT_WRITE and
ACPI_KEYBOARD_BACKLIGHT_READ for setting and getting the brightness
respectively.

Separate ACPI operations for preparing the driver to support other
backends.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220523090822.3035189-3-tzungbi@kernel.org
2022-06-10 02:31:42 +00:00
Tzung-Bi Shih 337eac8f84 platform/chrome: cros_kbd_led_backlight: sort headers alphabetically
To be neat and reduce conflict possibility, sort the headers
alphabetically.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220523090822.3035189-2-tzungbi@kernel.org
2022-06-10 02:31:42 +00:00
Prashant Malani f87e15fbf6 platform/chrome: cros_ec_proto: Update size arg types
cros_ec_cmd() takes 2 size arguments. Update them to be of the more
appropriate type size_t.

Suggested-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Prashant Malani <pmalani@chromium.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-4-pmalani@chromium.org
2022-06-08 08:14:54 +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
Tzung-Bi Shih 4319cbd4ed platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result()
cros_ec_check_result() is used to check if the EC communication success but
EC responded EC_RES_IN_PROGRESS.  It should return 0 even if EC wasn't
happy about the host command.

Add Kunit tests for cros_ec_check_result().

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220518091814.2028579-5-tzungbi@kernel.org
2022-06-06 03:11:37 +00:00
Tzung-Bi Shih 97b11dd635 platform/chrome: cros_ec_proto: update cros_ec_check_result() comment
At first glance, cros_ec_check_result() is quite like cros_ec_map_error().
They check for `ec_msg->result` and return corresponding errors.  However,
as calling from `pkt_xfer` and `cmd_xfer`, cros_ec_check_result() should
not report furthermore errors.  -EAGAIN is the only exception.

See [1][2][3] for some known userland programs' code.  The return code
from ioctl only denotes the EC communication status.  Userland programs
would further analyze the `result` in struct cros_ec_command* for
follow-up actions (e.g. [4]).

To clarify, update the function comment.

[1]: https://crrev.com/54400e93a75ef440a83d6eaac2cec066daf99cf0/util/comm-dev.c#154
[2]: https://crrev.com/fe32670a89bf59e1aff84bba9dd3295657b85e9b/cros_ec_dev.c#296
[3]: https://crrev.com/4e19eb1d89de0422ff1bbd3f7260b131c761098c/drivers/google/cros_ec_dev.c#120
[4]: https://crrev.com/54400e93a75ef440a83d6eaac2cec066daf99cf0/util/comm-dev.c#164

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220518091814.2028579-4-tzungbi@kernel.org
2022-06-06 03:11:37 +00:00
Tzung-Bi Shih 23a34e3a9d platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx()
cros_ec_prepare_tx() mixed the code for both versions.  To be neat and to
make it clear, factor the legacy part out as a separate function, rename
the function, and update the comments.

Specifically,
- prepare_tx(), for current protocol version (i.e. 3).
- prepare_tx_legacy(), for protocol version <= 2.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220518091814.2028579-3-tzungbi@kernel.org
2022-06-06 03:11:37 +00:00
Tzung-Bi Shih db681eaf71 platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_prepare_tx()
cros_ec_prepare_tx() is used to fill the protocol headers according to
the requested protocol version.

Add Kunit tests cros_ec_prepare_tx() for each version.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220518091814.2028579-2-tzungbi@kernel.org
2022-06-06 03:11:37 +00:00
Tzung-Bi Shih bbd43a37ec platform/chrome: cros_ec_spi: drop BUG_ON() if `din` isn't large enough
It is overkill to crash the kernel if the `din` buffer is going to full
or overflow.

Drop the BUG_ON() and return -EINVAL instead.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-8-tzungbi@kernel.org
2022-05-16 10:01:52 +08:00
Tzung-Bi Shih ddec8e9e90 platform/chrome: cros_ec_spi: drop unneeded BUG_ON()
In the context, the following conditions are always false:

- `todo` < 0
Suppose that EC_SPI_FRAME_START is found at the last byte of transfer.

In the case, `ptr` == `end` - 1.  As a result, `todo` must be 0.

- `todo` > `ec_dev->din_size`
Suppose that there is no preamble bytes.  EC_SPI_FRAME_START is found at
the first byte of transfer.

In the case, `end` == `ptr` + EC_MSG_PREAMBLE_COUNT.
As a result, `todo` == EC_MSG_PREAMBLE_COUNT - 1.
However, it already checked `ec_dev->din_size` < EC_MSG_PREAMBLE_COUNT at
the beginning of function.

Drop the unneeded BUG_ON().

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-7-tzungbi@kernel.org
2022-05-16 10:01:51 +08:00
Tzung-Bi Shih 8bff946c41 platform/chrome: cros_ec_i2c: drop BUG_ON() in cros_ec_pkt_xfer_i2c()
It is overkill to crash the kernel if the given message is oversize.

Drop the BUG_ON() and return -EINVAL instead.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-6-tzungbi@kernel.org
2022-05-16 10:01:51 +08:00
Tzung-Bi Shih 20a264c97b platform/chrome: cros_ec_proto: drop BUG_ON() in cros_ec_get_host_event()
It is overkill to crash the kernel if the `ec_dev` doesn't support MKBP
event but gets called into cros_ec_get_host_event().

Drop the BUG_ON() and return error (0 in the case) instead.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-5-tzungbi@kernel.org
2022-05-16 10:01:51 +08:00
Tzung-Bi Shih c2dcb1b060 platform/chrome: cros_ec_proto: drop BUG_ON() in cros_ec_prepare_tx()
It is overkill to crash the kernel if the given message is oversize.

Drop the BUG_ON() and return -EINVAL instead.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-4-tzungbi@kernel.org
2022-05-16 10:01:51 +08:00
Tzung-Bi Shih 71d3ae7fb6 platform/chrome: correct cros_ec_prepare_tx() usage
cros_ec_prepare_tx() returns either:
- >= 0 for number of prepared bytes.
- < 0 for -errno.

Correct the comment and make sure all callers check the return code.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-3-tzungbi@kernel.org
2022-05-16 10:01:51 +08:00
Tzung-Bi Shih 42701e7c0c platform/chrome: cros_ec_proto: drop unneeded BUG_ON() in prepare_packet()
prepare_packet() gets called if `ec_dev->proto_version` > 2.  For now, it
must be equivalent to EC_HOST_REQUEST_VERSION.

Drop the BUG_ON().

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-2-tzungbi@kernel.org
2022-05-16 10:01:51 +08:00
Enric Balletbo i Serra 0a4cad9c11 platform/chrome: Add ChromeOS ACPI device driver
The x86 Chromebooks have the ChromeOS ACPI device. This driver attaches
to the ChromeOS ACPI device and exports the values reported by ACPI in a
sysfs directory. This data isn't present in ACPI tables when read
through ACPI tools, hence a driver is needed to do it. The driver gets
data from firmware using the ACPI component of the kernel. The ACPI values
are presented in string form (numbers as decimal values) or binary
blobs, and can be accessed as the contents of the appropriate read only
files in the standard ACPI device's sysfs directory tree. This data is
consumed by the ChromeOS user space.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Co-developed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/Yn4OKYrtV35Dv+nd@debian-BULLSEYE-live-builder-AMD64
2022-05-13 19:42:30 +08: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
Dustin L. Howett c9bc1a0ef9 platform/chrome: cros_ec_lpcs: reserve the MEC LPC I/O ports first
Some ChromeOS EC devices (such as the Framework Laptop) only map I/O
ports 0x800-0x807. Making the larger reservation required by the non-MEC
LPC (the 0xFF ports for the memory map, and the 0xFF ports for the
parameter region) is non-viable on these devices.

Since we probe the MEC EC first, we can get away with a smaller
reservation that covers the MEC EC ports. If we fall back to classic
LPC, we can grow the reservation to cover the memory map and the
parameter region.

cros_ec_lpc_probe also interacted with I/O ports 0x800-0x807 without a
reservation. Restructuring the code to request the MEC LPC region first
obviates the need to do so.

Signed-off-by: Dustin L. Howett <dustin@howett.net>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220217165930.15081-3-dustin@howett.net
2022-05-03 13:43:21 +08:00
Dustin L. Howett 6a5d778eda platform/chrome: cros_ec_lpcs: detect the Framework Laptop
The Framework Laptop identifies itself in DMI with manufacturer
"Framework" and product "Laptop".

Signed-off-by: Dustin L. Howett <dustin@howett.net>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220217165930.15081-2-dustin@howett.net
2022-05-03 13:43:20 +08:00
Guenter Roeck 57b888ca25 platform/chrome: Re-introduce cros_ec_cmd_xfer and use it for ioctls
Commit 413dda8f2c ("platform/chrome: cros_ec_chardev: Use
cros_ec_cmd_xfer_status helper") inadvertendly changed the userspace ABI.
Previously, cros_ec ioctls would only report errors if the EC communication
failed, and otherwise return success and the result of the EC
communication. An EC command execution failure was reported in the EC
response field. The above mentioned commit changed this behavior, and the
ioctl itself would fail. This breaks userspace commands trying to analyze
the EC command execution error since the actual EC command response is no
longer reported to userspace.

Fix the problem by re-introducing the cros_ec_cmd_xfer() helper, and use it
to handle ioctl messages.

Fixes: 413dda8f2c ("platform/chrome: cros_ec_chardev: Use cros_ec_cmd_xfer_status helper")
Cc: Daisuke Nojiri <dnojiri@chromium.org>
Cc: Rob Barnes <robbarnes@google.com>
Cc: Rajat Jain <rajatja@google.com>
Cc: Brian Norris <briannorris@chromium.org>
Cc: Parth Malkan <parthmalkan@google.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
2022-04-19 11:27:20 +08:00
Tzung-Bi Shih 8d4668064c platform/chrome: cros_ec: append newline to all logs
To be consistent, append newline ("\n") to all logs.

Reviewed-by: Guenter Roeck <groeck@google.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
2022-04-18 15:39:27 +08:00
Tzung-Bi Shih 5781a33098 platform/chrome: cros_ec: sort header inclusion alphabetically
Sort header inclusion alphabetically.

Reviewed-by: Guenter Roeck <groeck@google.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
2022-04-18 15:39:27 +08:00
Tzung-Bi Shih 9fbe967d4e platform/chrome: cros_ec: determine `wake_enabled` in cros_ec_suspend()
`wake_enabled` indicates cros_ec_resume() needs to call
disable_irq_wake() to undo enable_irq_wake() in cros_ec_suspend().

Determine `wake_enabled` in cros_ec_suspend() instead of
reset-after-used in cros_ec_resume().

Reviewed-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
2022-04-18 15:39:27 +08:00
Tzung-Bi Shih f47a6113f4 platform/chrome: cros_ec: remove unused variable `was_wake_device`
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
2022-04-18 15:39:27 +08:00
Tzung-Bi Shih 2cd01bd6b1 platform/chrome: cros_ec: fix error handling in cros_ec_register()
Fix cros_ec_register() to unregister platform devices if
blocking_notifier_chain_register() fails.

Also use the single exit path to handle the platform device
unregistration.

Fixes: 42cd0ab476 ("platform/chrome: cros_ec: Query EC protocol version if EC transitions between RO/RW")
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
2022-04-18 15:39:27 +08:00
Linus Torvalds 02d4f8a3e0 chrome platform changes for 5.18
cros_ec_typec:
 * platform/chrome: cros_ec_typec: Check for EC device - Fix a crash when using
   the cros_ec_typec driver on older hardware not capable of typec commands.
 * Make try power role optional.
 * Mux configuration reorganization series from Prashant.
 
 cros_ec_debugfs:
 * Fix use after free. Thanks Tzung-bi.
 
 sensorhub:
 * cros_ec_sensorhub fixup - Split trace include file
 
 misc:
 * Add new mailing list for chrome-platform development.
   chrome-platform@lists.linux.dev. Now with patchwork!
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCYkZBeAAKCRBzbaomhzOw
 wuUbAP9GaC3906dMf4zucME+icojYFQSeQFMJfS0kMdKBtJROAEArsEilx5aFf7Q
 PlyoaaJ7aWpLO3pnUdUNwQM0hJPLGwo=
 =me9M
 -----END PGP SIGNATURE-----

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

Pull chrome platform updates from Benson Leung:
 "cros_ec_typec:

   - Check for EC device - Fix a crash when using the cros_ec_typec
     driver on older hardware not capable of typec commands

   - Make try power role optional

   - Mux configuration reorganization series from Prashant

  cros_ec_debugfs:

   - Fix use after free. Thanks Tzung-bi

  sensorhub:

   - cros_ec_sensorhub fixup - Split trace include file

  misc:

   - Add new mailing list for chrome-platform development:

	chrome-platform@lists.linux.dev

     Now with patchwork!"

* tag 'tag-chrome-platform-for-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
  platform/chrome: cros_ec_debugfs: detach log reader wq from devm
  platform: chrome: Split trace include file
  platform/chrome: cros_ec_typec: Update mux flags during partner removal
  platform/chrome: cros_ec_typec: Configure muxes at start of port update
  platform/chrome: cros_ec_typec: Get mux state inside configure_mux
  platform/chrome: cros_ec_typec: Move mux flag checks
  platform/chrome: cros_ec_typec: Check for EC device
  platform/chrome: cros_ec_typec: Make try power role optional
  MAINTAINERS: platform-chrome: Add new chrome-platform@lists.linux.dev list
2022-04-02 10:44:18 -07:00
Tzung-Bi Shih 0e8eb5e8ac
platform/chrome: cros_ec_debugfs: detach log reader wq from devm
Debugfs console_log uses devm memory (e.g. debug_info in
cros_ec_console_log_poll()).  However, lifecycles of device and debugfs
are independent.  An use-after-free issue is observed if userland
program operates the debugfs after the memory has been freed.

The call trace:
 do_raw_spin_lock
 _raw_spin_lock_irqsave
 remove_wait_queue
 ep_unregister_pollwait
 ep_remove
 do_epoll_ctl

A Python example to reproduce the issue:
... import select
... p = select.epoll()
... f = open('/sys/kernel/debug/cros_scp/console_log')
... p.register(f, select.POLLIN)
... p.poll(1)
[(4, 1)]                    # 4=fd, 1=select.POLLIN

[ shutdown cros_scp at the point ]

... p.poll(1)
[(4, 16)]                   # 4=fd, 16=select.POLLHUP
... p.unregister(f)

An use-after-free issue raises here.  It called epoll_ctl with
EPOLL_CTL_DEL which in turn to use the workqueue in the devm (i.e.
log_wq).

Detaches log reader's workqueue from devm to make sure it is persistent
even if the device has been removed.

Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
Reviewed-by: Guenter Roeck <groeck@google.com>
Link: https://lore.kernel.org/r/20220209051130.386175-1-tzungbi@google.com
Signed-off-by: Benson Leung <bleung@chromium.org>
2022-03-31 16:56:48 -07:00
Gwendal Grignou eabd9a3807
platform: chrome: Split trace include file
cros_ec_trace.h defined 5 tracing events, 2 for cros_ec_proto and
3 for cros_ec_sensorhub_ring.
These 2 files are in different kernel modules, the traces are defined
twice in the kernel which leads to problem enabling only some traces.

Move sensorhub traces from cros_ec_trace.h to cros_ec_sensorhub_trace.h
and enable them only in cros_ec_sensorhub kernel module.

Check we can now enable any single traces: without this patch,
we can only enable all sensorhub traces or none.

Fixes: d453ceb654 ("platform/chrome: sensorhub: Add trace events for sample")

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20220122001301.640337-1-gwendal@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2022-03-31 16:56:29 -07:00
Linus Torvalds b14ffae378 drm for 5.18-rc1
dma-buf:
 - rename dma-buf-map to iosys-map
 
 core:
 - move buddy allocator to core
 - add pci/platform init macros
 - improve EDID parser deep color handling
 - EDID timing type 7 support
 - add GPD Win Max quirk
 - add yes/no helpers to string_helpers
 - flatten syncobj chains
 - add nomodeset support to lots of drivers
 - improve fb-helper clipping support
 - add default property value interface
 
 fbdev:
 - improve fbdev ops speed
 
 ttm:
 - add a backpointer from ttm bo->ttm resource
 
 dp:
 - move displayport headers
 - add a dp helper module
 
 bridge:
 - anx7625 atomic support, HDCP support
 
 panel:
 - split out panel-lvds and lvds bindings
 - find panels in OF subnodes
 
 privacy:
 - add chromeos privacy screen support
 
 fb:
 - hot unplug fw fb on forced removal
 
 simpledrm:
 - request region instead of marking ioresource busy
 - add panel oreintation property
 
 udmabuf:
 - fix oops with 0 pages
 
 amdgpu:
 - power management code cleanup
 - Enable freesync video mode by default
 - RAS code cleanup
 - Improve VRAM access for debug using SDMA
 - SR-IOV rework special register access and fixes
 - profiling power state request ioctl
 - expose IP discovery via sysfs
 - Cyan skillfish updates
 - GC 10.3.7, SDMA 5.2.7, DCN 3.1.6 updates
 - expose benchmark tests via debugfs
 - add module param to disable XGMI for testing
 - GPU reset debugfs register dumping support
 
 amdkfd:
 - CRIU support
 - SDMA queue fixes
 
 radeon:
 - UVD suspend fix
 - iMac backlight fix
 
 i915:
 - minimal parallel submission for execlists
 - DG2-G12 subplatform added
 - DG2 programming workarounds
 - DG2 accelerated migration support
 - flat CCS and CCS engine support for XeHP
 - initial small BAR support
 - drop fake LMEM support
 - ADL-N PCH support
 - bigjoiner updates
 - introduce VMA resources and async unbinding
 - register definitions cleanups
 - multi-FBC refactoring
 - DG1 OPROM over SPI support
 - ADL-N platform enabling
 - opregion mailbox #5 support
 - DP MST ESI improvements
 - drm device based logging
 - async flip optimisation for DG2
 - CPU arch abstraction fixes
 - improve GuC ADS init to work on aarch64
 - tweak TTM LRU priority hint
 - GuC 69.0.3 support
 - remove short term execbuf pins
 
 nouveau:
 - higher DP/eDP bitrates
 - backlight fixes
 
 msm:
 - dpu + dp support for sc8180x
 - dp support for sm8350
 - dpu + dsi support for qcm2290
 - 10nm dsi phy tuning support
 - bridge support for dp encoder
 - gpu support for additional 7c3 SKUs
 
 ingenic:
 - HDMI support for JZ4780
 - aux channel EDID support
 
 ast:
 - AST2600 support
 - add wide screen support
 - create DP/DVI connectors
 
 omapdrm:
 - fix implicit dma_buf fencing
 
 vc4:
 - add CSC + full range support
 - better display firmware handoff
 
 panfrost:
 - add initial dual-core GPU support
 
 stm:
 - new revision support
 - fb handover support
 
 mediatek:
 - transfer display binding document to yaml format.
 - add mt8195 display device binding.
 - allow commands to be sent during video mode.
 - add wait_for_event for crtc disable by cmdq.
 
 tegra:
 - YUV format support
 
 rcar-du:
 - LVDS support for M3-W+ (R8A77961)
 
 exynos:
 - BGR pixel format for FIMD device
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEEKbZHaGwW9KfbeusDHTzWXnEhr4FAmI71h4ACgkQDHTzWXnE
 hr6wKg//SvKFiEOhptua8Ao8XYkhXpg1/tgdAs4D7bZ0YgJyF4Im0RuFOKMmF3mN
 0Y8AwguqrsmrOAFbK8B1WEysB66DmGlZN/V2Q75X7fui8xs4uGF2Fcxyr+265zhf
 vONPwAoxYr+KXqwOI1p1BP2QEL6bJTdu+nrXRsXIBIrWnw8ehXJlw3fDhgvG5QBn
 RPdbU7lQnd47hdYxkbe5SiZvWnPC46dJmpqsRJir0xjskR6juU36f34C4IKhTGwO
 NDPeWVgusVXtIC/F4X6RebCWG0f66h+CUFa9zeYIleI/2/5yZWXfcw6Obx8HgPkt
 gieiI0R4TpkVxeHCApCQ5UpxWgfSOXdoDoyw172bKQw7JCHVEkSwenyMEEwNet6r
 SCJrRmlB1PBI/iTWmhm9qgrU46ZZyAnQoTlCsXGzJncdP3hzGlA1embl00yfEl7f
 wzM35N20qd5T4VKUEF8QYF0fLZYmKw4cWVASu4hQ3qmGal6frilphz2J8JK8hQNq
 KhFqNbVTnZsQNr9LBCbrf0kOPaMzpmW+2vQG9ApdAb1N3gNPZT7ctti0Xq5N2OUR
 AipWFAsDPS2NPADKmBtDU55PgFH9MqUIsoHHXLV4Qi76dvCqYoN68qRQxrL7rpSu
 b0gr0YKU2QcIB/uytjOPHcgtI5Xvrh+q8JPz/dJ38/Esgjmk4wo=
 =uRsT
 -----END PGP SIGNATURE-----

Merge tag 'drm-next-2022-03-24' of git://anongit.freedesktop.org/drm/drm

Pull drm updates from Dave Airlie:
 "Lots of work all over, Intel improving DG2 support, amdkfd CRIU
  support, msm new hw support, and faster fbdev support.

  dma-buf:
   - rename dma-buf-map to iosys-map

  core:
   - move buddy allocator to core
   - add pci/platform init macros
   - improve EDID parser deep color handling
   - EDID timing type 7 support
   - add GPD Win Max quirk
   - add yes/no helpers to string_helpers
   - flatten syncobj chains
   - add nomodeset support to lots of drivers
   - improve fb-helper clipping support
   - add default property value interface

  fbdev:
   - improve fbdev ops speed

  ttm:
   - add a backpointer from ttm bo->ttm resource

  dp:
   - move displayport headers
   - add a dp helper module

  bridge:
   - anx7625 atomic support, HDCP support

  panel:
   - split out panel-lvds and lvds bindings
   - find panels in OF subnodes

  privacy:
   - add chromeos privacy screen support

  fb:
   - hot unplug fw fb on forced removal

  simpledrm:
   - request region instead of marking ioresource busy
   - add panel oreintation property

  udmabuf:
   - fix oops with 0 pages

  amdgpu:
   - power management code cleanup
   - Enable freesync video mode by default
   - RAS code cleanup
   - Improve VRAM access for debug using SDMA
   - SR-IOV rework special register access and fixes
   - profiling power state request ioctl
   - expose IP discovery via sysfs
   - Cyan skillfish updates
   - GC 10.3.7, SDMA 5.2.7, DCN 3.1.6 updates
   - expose benchmark tests via debugfs
   - add module param to disable XGMI for testing
   - GPU reset debugfs register dumping support

  amdkfd:
   - CRIU support
   - SDMA queue fixes

  radeon:
   - UVD suspend fix
   - iMac backlight fix

  i915:
   - minimal parallel submission for execlists
   - DG2-G12 subplatform added
   - DG2 programming workarounds
   - DG2 accelerated migration support
   - flat CCS and CCS engine support for XeHP
   - initial small BAR support
   - drop fake LMEM support
   - ADL-N PCH support
   - bigjoiner updates
   - introduce VMA resources and async unbinding
   - register definitions cleanups
   - multi-FBC refactoring
   - DG1 OPROM over SPI support
   - ADL-N platform enabling
   - opregion mailbox #5 support
   - DP MST ESI improvements
   - drm device based logging
   - async flip optimisation for DG2
   - CPU arch abstraction fixes
   - improve GuC ADS init to work on aarch64
   - tweak TTM LRU priority hint
   - GuC 69.0.3 support
   - remove short term execbuf pins

  nouveau:
   - higher DP/eDP bitrates
   - backlight fixes

  msm:
   - dpu + dp support for sc8180x
   - dp support for sm8350
   - dpu + dsi support for qcm2290
   - 10nm dsi phy tuning support
   - bridge support for dp encoder
   - gpu support for additional 7c3 SKUs

  ingenic:
   - HDMI support for JZ4780
   - aux channel EDID support

  ast:
   - AST2600 support
   - add wide screen support
   - create DP/DVI connectors

  omapdrm:
   - fix implicit dma_buf fencing

  vc4:
   - add CSC + full range support
   - better display firmware handoff

  panfrost:
   - add initial dual-core GPU support

  stm:
   - new revision support
   - fb handover support

  mediatek:
   - transfer display binding document to yaml format.
   - add mt8195 display device binding.
   - allow commands to be sent during video mode.
   - add wait_for_event for crtc disable by cmdq.

  tegra:
   - YUV format support

  rcar-du:
   - LVDS support for M3-W+ (R8A77961)

  exynos:
   - BGR pixel format for FIMD device"

* tag 'drm-next-2022-03-24' of git://anongit.freedesktop.org/drm/drm: (1529 commits)
  drm/i915/display: Do not re-enable PSR after it was marked as not reliable
  drm/i915/display: Fix HPD short pulse handling for eDP
  drm/amdgpu: Use drm_mode_copy()
  drm/radeon: Use drm_mode_copy()
  drm/amdgpu: Use ternary operator in `vcn_v1_0_start()`
  drm/amdgpu: Remove pointless on stack mode copies
  drm/amd/pm: fix indenting in __smu_cmn_reg_print_error()
  drm/amdgpu/dc: fix typos in comments
  drm/amdgpu: fix typos in comments
  drm/amd/pm: fix typos in comments
  drm/amdgpu: Add stolen reserved memory for MI25 SRIOV.
  drm/amdgpu: Merge get_reserved_allocation to get_vbios_allocations.
  drm/amdkfd: evict svm bo worker handle error
  drm/amdgpu/vcn: fix vcn ring test failure in igt reload test
  drm/amdgpu: only allow secure submission on rings which support that
  drm/amdgpu: fixed the warnings reported by kernel test robot
  drm/amd/display: 3.2.177
  drm/amd/display: [FW Promotion] Release 0.0.108.0
  drm/amd/display: Add save/restore PANEL_PWRSEQ_REF_DIV2
  drm/amd/display: Wait for hubp read line for Pollock
  ...
2022-03-24 16:19:43 -07: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
Uwe Kleine-König a0386bba70
spi: make remove callback a void function
The value returned by an spi driver's remove function is mostly ignored.
(Only an error message is printed if the value is non-zero that the
error is ignored.)

So change the prototype of the remove function to return no value. This
way driver authors are not tempted to assume that passing an error to
the upper layer is a good idea. All drivers are adapted accordingly.
There is no intended change of behaviour, all callbacks were prepared to
return 0 before.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Claudius Heine <ch@denx.de>
Acked-by: Stefan Schmidt <stefan@datenfreihafen.org>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # For MMC
Acked-by: Marcus Folkesson <marcus.folkesson@gmail.com>
Acked-by: Łukasz Stelmach <l.stelmach@samsung.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/20220123175201.34839-6-u.kleine-koenig@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2022-02-09 13:00:45 +00:00
Uwe Kleine-König afb0a80e63
platform/chrome: cros_ec: Make cros_ec_unregister() return void
Up to now cros_ec_unregister() returns zero unconditionally. Make it
return void instead which makes it easier to see in the callers that
there is no error to handle.

Also the return value of i2c, platform and spi remove callbacks is
ignored anyway.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20211020071753.wltjslmimb6wtlp5@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Lee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/20220123175201.34839-5-u.kleine-koenig@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2022-02-09 13:00:43 +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
Rajat Jain 3fb57847f6 platform/chrome: Add driver for ChromeOS privacy-screen
This adds the ACPI driver for the ChromeOS privacy screen that is
present on some chromeos devices.

Note that ideally, we'd want this privacy screen driver to be probed
BEFORE the drm probe in order to avoid a drm probe deferral:
https://hansdegoede.livejournal.com/25948.html

In practise, I found that ACPI drivers are bound to their devices AFTER
the drm probe on chromebooks. So on chromebooks with privacy-screen,
this patch along with the other one in this series results in a probe
deferral of about 250ms for i915 driver. However, it did not result in
any user noticeable delay of splash screen in my personal experience.

In future if this probe deferral turns out to be an issue, we can
consider turning this ACPI driver into something that is probed
earlier than the drm drivers.

Signed-off-by: Rajat Jain <rajatja@google.com>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Benson Leung <bleung@chromium.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220107190208.95479-2-rajatja@google.com
2022-01-10 12:17:37 +01:00
Linus Torvalds 740bebf421 Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
Pull HID fixes from Jiri Kosina:

 - fix for Intel-ISH driver to make sure it gets aoutoloaded only on
   matching devices and not universally (Thomas Weißschuh)

 - fix for Wacom driver reporting invalid contact under certain
   circumstances (Jason Gerecke)

 - probing fix for ft260 dirver (Michael Zaidman)

 - fix for generic keycode remapping (Thomas Weißschuh)

 - fix for division by zero in hid-magicmouse (Claudia Pellegrino)

 - other tiny assorted fixes and new device IDs

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid:
  HID: multitouch: Fix Iiyama ProLite T1931SAW (0eef:0001 again!)
  HID: nintendo: eliminate dead datastructures in !CONFIG_NINTENDO_FF case
  HID: magicmouse: prevent division by 0 on scroll
  HID: thrustmaster: fix sparse warnings
  HID: Ignore battery for Elan touchscreen on HP Envy X360 15-eu0xxx
  HID: input: set usage type to key on keycode remap
  HID: input: Fix parsing of HID_CP_CONSUMER_CONTROL fields
  HID: ft260: fix i2c probing for hwmon devices
  Revert "HID: hid-asus.c: Maps key 0x35 (display off) to KEY_SCREENLOCK"
  HID: intel-ish-hid: fix module device-id handling
  mod_devicetable: fix kdocs for ishtp_device_id
  HID: wacom: Use "Confidence" flag to prevent reporting invalid contacts
  HID: nintendo: unlock on error in joycon_leds_create()
  platform/x86: isthp_eclite: only load for matching devices
  platform/chrome: chros_ec_ishtp: only load for matching devices
  HID: intel-ish-hid: hid-client: only load for matching devices
  HID: intel-ish-hid: fw-loader: only load for matching devices
  HID: intel-ish-hid: use constants for modaliases
  HID: intel-ish-hid: add support for MODULE_DEVICE_TABLE()
2021-11-24 09:44:13 -08:00
Arnd Bergmann bf9167a8b4 HID: intel-ish-hid: fix module device-id handling
A late addititon to the intel-ish-hid framework caused a build failure
with clang, and introduced an ABI to the module loader that stops working
if any driver ever needs to bind to more than one UUID:

drivers/hid/intel-ish-hid/ishtp-fw-loader.c:1067:4: error: initializer element is not a compile-time constant

Change the ishtp_device_id to have correct documentation and a driver_data
field like all the other ones, and change the drivers to use the ID table
as the primary identification in a way that works with all compilers
and avoids duplciating the identifiers.

Fixes: f155dfeaa4 ("platform/x86: isthp_eclite: only load for matching devices")
Fixes: facfe0a4fd ("platform/chrome: chros_ec_ishtp: only load for matching devices")
Fixes: 0d0cccc0fd ("HID: intel-ish-hid: hid-client: only load for matching devices")
Fixes: 44e2a58cb8 ("HID: intel-ish-hid: fw-loader: only load for matching devices")
Fixes: cb1a2c6847 ("HID: intel-ish-hid: use constants for modaliases")
Fixes: fa443bc3c1 ("HID: intel-ish-hid: add support for MODULE_DEVICE_TABLE()")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
[jkosina@suse.cz: fix ecl_ishtp_cl_driver.id initialization]
[jkosina@suse.cz: fix conflict with already fixed kerneldoc]
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2021-11-11 22:45:40 +01:00
Thomas Weißschuh facfe0a4fd platform/chrome: chros_ec_ishtp: only load for matching devices
Previously it was loaded for all ISHTP devices.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2021-11-09 11:41:47 +01:00
Prashant Malani 297d34e73d
platform/chrome: cros_ec_proto: Use ec_command for check_features
Use the existing cros_ec_command() for cros_ec_check_features(). This
eliminates an unnecessary duplication of the memory allocation/free and
memory copy code.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20211004170716.86601-2-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-10-31 15:52:55 -07:00
Prashant Malani 7ff22787ba
platform/chrome: cros_ec_proto: Use EC struct for features
The Chrome EC's features are returned through an
ec_response_get_features struct, but they are stored in an independent
array. Although the two are effectively the same at present (2 unsigned
32 bit ints), there is the possibility that they could go out of sync.
Avoid this by only using the EC struct to store the features.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20211004170716.86601-1-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-10-31 15:52:39 -07: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 4f1406396e platform/chrome: cros_ec_proto: Add version for ec_command
Add a version parameter to cros_ec_command() for callers that may want
to specify which version of the host command they would like to use.

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-5-pmalani@chromium.org
2021-09-30 10:09:47 +02:00
Prashant Malani 5d122256f4 platform/chrome: cros_ec_proto: Make data pointers void
Convert the input and output data pointers for cros_ec_command() to
void pointers so that the callers don't have to cast their custom
structs to uint8_t *.

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-4-pmalani@chromium.org
2021-09-30 10:09:47 +02:00
Prashant Malani 7101c83950 platform/chrome: cros_usbpd_notify: Move ec_command()
cros_ec_command() can be used by other modules too. So, move it to a
common location and export it.

This patch does not introduce any functional changes.

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-3-pmalani@chromium.org
2021-09-30 10:09:47 +02:00
Prashant Malani 67ea0239fb platform/chrome: cros_usbpd_notify: Rename cros_ec_pd_command()
Rename cros_ec_pd_command()_to cros_ec_command() since it can be used
for sending any host command, and not just PD related ones.

This patch does not introduce any functional changes.

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-2-pmalani@chromium.org
2021-09-30 10:09:47 +02:00
Colin Ian King eb057514cc platform/chrome: cros_ec: Fix spelling mistake "responsed" -> "response"
There are spelling mistakes in dev_warn messages. Fix them.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210925171743.173219-1-colin.king@canonical.com
2021-09-30 10:09:47 +02:00
Wolfram Sang f11c35e181 platform/chrome: cros_ec_sensorhub: simplify getting .driver_data
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210920090522.23784-9-wsa+renesas@sang-engineering.com
2021-09-27 09:18:58 +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 d50497c4a0 platform/chrome: cros_ec_proto: Fix check_features ret val
The kerneldoc for cros_ec_check_features() states that it returns 1 or 0
depedending on whether a feature is supported or not, but it instead
returns a negative error number in one case, and a non-1 bitmask in
other cases.

Since all call-sites only check for a 1 or 0 return value, update
the function to return boolean values.

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/20210916014632.2662612-1-pmalani@chromium.org
2021-09-23 17:41:30 +02:00
Gwendal Grignou 4665584888
platform/chrome: cros_ec_trace: Fix format warnings
Fix printf format issues in new tracing events.

Fixes: 8143182426 ("platform/chrome: cros_ec_trace: Add fields to command traces")

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Link: https://lore.kernel.org/r/20210830180050.2077261-1-gwendal@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-08-30 17:46:55 -07: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
Patryk Duda 3abc16af57
platform/chrome: cros_ec_proto: Send command again when timeout occurs
Sometimes kernel is trying to probe Fingerprint MCU (FPMCU) when it
hasn't initialized SPI yet. This can happen because FPMCU is restarted
during system boot and kernel can send message in short window
eg. between sysjump to RW and SPI initialization.

Cc: <stable@vger.kernel.org> # 4.4+
Signed-off-by: Patryk Duda <pdk@semihalf.com>
Link: https://lore.kernel.org/r/20210518140758.29318-1-pdk@semihalf.com
Signed-off-by: Benson Leung <bleung@chromium.org>
2021-07-26 16:15:55 -07:00
Gwendal Grignou d453ceb654 platform/chrome: sensorhub: Add trace events for sample
Add trace event to report samples and their timestamp coming from the
EC. It allows to check if the timestamps are correct and the filter is
working correctly without introducing too much latency.

To enable these events:

cd /sys/kernel/debug/tracing/
echo 1 > events/cros_ec/enable
echo 0 > events/cros_ec/cros_ec_request_start/enable
echo 0 > events/cros_ec/cros_ec_request_done/enable
echo 1 > tracing_on
cat trace_pipe
Observe event flowing:
irq/105-chromeo-95      [000] ....   613.659758: cros_ec_sensorhub_timestamp: ...
irq/105-chromeo-95      [000] ....   613.665219: cros_ec_sensorhub_filter: dx: ...

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2021-07-26 13:24:46 +02:00
Jiri Kosina 33197bd3e8 Merge branch 'for-5.14/intel-ish' into for-linus
- support for ISH DMA on EHL platform from Even Xu
- various code style fixes and cleanups from Lee Jones and Uwe Kleine-König
2021-06-30 09:06:53 +02:00
Linus Torvalds dd860052c9 chrome platform changes for 5.13
cros_ec_typec:
 * Changes around DP mode check, hard reset, tracking port change.
 
 cros_ec misc:
 * wilco_ec: Convert stream-like files from nonseekable to stream open
 * cros_usbpd_notify: Listen to EC_HSOT_EVENT_USB_MUX host event
 * fix format warning in cros_ec_typec
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCYJWylAAKCRBzbaomhzOw
 ws4SAQD9Alp6FpY6ne62JRHCyQBdEHwDWGQGBvE8NRkHSRcSWAD8C5vgBLGX7Zx8
 wLfzrZ6x3BKGkOJuuk3+zhVu8He7WQQ=
 =caTR
 -----END PGP SIGNATURE-----

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

Pull chrome platform updates from Benson Leung:
 "cros_ec_typec:

   - Changes around DP mode check, hard reset, tracking port change.

  cros_ec misc:

   - wilco_ec: Convert stream-like files from nonseekable to stream open

   - cros_usbpd_notify: Listen to EC_HSOT_EVENT_USB_MUX host event

   - fix format warning in cros_ec_typec"

* tag 'tag-chrome-platform-for-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
  platform/chrome: cros_ec_lpc: Use DEFINE_MUTEX() for mutex lock
  platform/chrome: cros_usbpd_notify: Listen to EC_HOST_EVENT_USB_MUX host event
  platform/chrome: cros_ec_typec: Add DP mode check
  platform/chrome: cros_ec_typec: Handle hard reset
  platform/chrome: cros_ec: Add Type C hard reset
  platform/chrome: cros_ec_typec: Track port role
  platform/chrome: cros_ec_typec: fix clang -Wformat warning
  platform/chrome: cros_ec_typec: Check for device within remove function
  platform/chrome: wilco_ec: convert stream-like files from nonseekable_open -> stream_open
2021-05-07 14:49:18 -07:00
Ye Bin d61b3f9b91 platform/chrome: cros_ec_lpc: Use DEFINE_MUTEX() for mutex lock
mutex lock can be initialized automatically with DEFINE_MUTEX()
rather than explicitly calling mutex_init().

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Ye Bin <yebin10@huawei.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210409095138.2293869-1-yebin10@huawei.com
2021-04-21 10:00:30 +02:00
Pi-Hsun Shih 4423ee65f7 platform/chrome: cros_usbpd_notify: Listen to EC_HOST_EVENT_USB_MUX host event
On system that use ACPI, cros_usbpd_notify gets notifications of USB MUX
host event same as PD host events [1]. But currently on system that use
DT, the driver only listen on EC_HOST_EVENT_PD_MCU.

Add EC_HOST_EVENT_USB_MUX to the list of host events, so we have same
behavior on all platforms.

[1]: https://chromium.googlesource.com/chromiumos/third_party/coreboot/+/refs/heads/chromeos-2016.05/src/ec/google/chromeec/acpi/ec.asl#382

Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210414064524.2450908-1-pihsun@chromium.org
2021-04-21 09:40:37 +02: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
Heikki Krogerus 2c02f65985 platform/chrome: chromeos_laptop - Prepare complete software nodes
The older device property API is going to be removed soon
and that will affect also I2C subystem. Supplying complete
software nodes instead of only the properties in them for
the I2C devices.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
2021-04-10 21:43:02 +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
Yang Li dbc334fb41 platform/chrome: wilco_ec: convert stream-like files from nonseekable_open -> stream_open
Eliminate the following coccicheck warning:
./drivers/platform/chrome/wilco_ec/telemetry.c:259:1-17: WARNING:
telem_fops: .read() and .write() have stream semantic; safe to change
nonseekable_open -> stream_open.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/1612688918-63132-1-git-send-email-yang.lee@linux.alibaba.com
2021-03-30 18:25:22 +02:00
Uwe Kleine-König e71da1fd0e HID: intel-ish-hid: Make remove callback return void
The driver core ignores the return value of struct bus_type::remove()
because there is only little that can be done. To simplify the quest to
make this function return void, let struct ishtp_cl_driver::remove() return
void, too. All users already unconditionally return 0, this commit makes
it obvious that returning an error value is a bad idea.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2021-03-08 17:16:03 +01: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
Gwendal Grignou 4daeb395f1 platform/chrome: cros_ec: Call interrupt bottom half at probe time
While the AP was powered off, the EC may have send messages.
If the message is not serviced within 3s, the EC stops sending message.
Unlock the EC by purging stale messages at probe time.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210122054637.1422289-3-gwendal@chromium.org
2021-01-22 08:50:27 +01:00
Gwendal Grignou 24c69043be platform/chrome: cros_ec: Call interrupt bottom half in ISH or RPMSG mode
Call the same bottom half for all EC protocols (threaded code).

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210122054637.1422289-2-gwendal@chromium.org
2021-01-22 08:50:27 +01:00
Pi-Hsun Shih 4c2e9b3e18 platform/chrome: cros_ec_sysfs: Add cold-ap-off to sysfs reboot.
Add cold-ap-off to ChromeOS EC sysfs reboot file option, corresponds to
the EC_REBOOT_COLD_AP_OFF flag, that will reset EC and keep AP off.

Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20201221041231.14516-2-pihsun@chromium.org
2021-01-20 16:19:17 +01:00
Rikard Falkeborn d7c1fef7fd platform/chrome: Constify static attribute_group structs
The only usage of these is to print their name in a dev_err-message, and
to pass their address to sysfs_create_group() and sysfs_remove_group(),
both which takes pointers to const. Make them const to allow the compiler
to put them in read-only memory.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210109001748.58036-1-rikard.falkeborn@gmail.com
2021-01-20 16:19:17 +01:00
Evan Benn 852405d8ef platform/chrome: cros_ec_proto: Add LID and BATTERY to default mask
After 'platform/chrome: cros_ec_proto: Use EC_HOST_EVENT_MASK not BIT'
some of the flags are not quite correct.
LID_CLOSED is used to suspend the device, so it makes sense to ignore that.
BATTERY events are also frequent and causing spurious wakes on elm/hana
mt8173 devices.

Fixes: c214e564ac ("platform/chrome: cros_ec_proto: ignore unnecessary wakeups on old ECs")
Signed-off-by: Evan Benn <evanbenn@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20201209220306.2.I3291bf83e4884c206b097ede34780e014fa3e265@changeid
2021-01-20 16:19:17 +01:00
Evan Benn 0944ea07ba platform/chrome: cros_ec_proto: Use EC_HOST_EVENT_MASK not BIT
The host_event_code enum is 1-based, use EC_HOST_EVENT_MASK not BIT to
generate the intended mask. This patch changes the behaviour of the
mask, a following patch will restore the intended behaviour:
'Add LID and BATTERY to default mask'

Fixes: c214e564ac ("platform/chrome: cros_ec_proto: ignore unnecessary wakeups on old ECs")
Signed-off-by: Evan Benn <evanbenn@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20201209220306.1.I6133572c0ab3c6b95426f804bac2d3833e24acb1@changeid
2021-01-20 16:19:17 +01: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
Prashant Malani f4edab68e1
platform/chrome: cros_ec_typec: Register SOP' cable plug
In order to register cable alternate modes, we need to first register a
plug object. Use the Type C connector class framework to register a SOP'
plug for this purpose.

Since a cable and plug go hand in hand, we can handle the registration
and removal together.

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-11-pmalani@chromium.org
2021-01-05 11:06:26 -08:00
Prashant Malani 5992297639
platform/chrome: cros_ec_typec: Set partner num_altmodes
Set the number of altmodes available for a registered partner using the
Type C connector class framework routine.

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>
Signed-off-by: Benson Leung <bleung@chromium.org>
Link: https://lore.kernel.org/r/20201116201150.2919178-10-pmalani@chromium.org
2021-01-05 11:05:50 -08:00
Prashant Malani 72d6e32bd8
platform/chrome: cros_ec_typec: Store cable plug type
Use the PD VDO Type C cable plug type macro to retrieve and store the
cable plug type in the cable descriptor.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.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-9-pmalani@chromium.org
2021-01-05 11:04:09 -08:00
Prashant Malani 8b46a212ad
platform/chrome: cros_ec_typec: Register cable
When the Chrome Embedded Controller notifies the driver that SOP'
discovery is complete, retrieve the PD discovery data and register a
cable object with the Type C connector class framework.

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.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-8-pmalani@chromium.org
2021-01-05 11:03:49 -08:00
Prashant Malani c097f229b7
platform/chrome: cros_ec_typec: Rename discovery struct
Rename the sop_disc data struct which is used to store PD discovery data
to the more generic name of disc_data. It can then be re-used to store
and process cable discovery data.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.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-7-pmalani@chromium.org
2021-01-05 11:03:02 -08:00
Prashant Malani 8fab275519
platform/chrome: cros_ec_typec: Factor out PD identity parsing
Factor out the PD identity parsing code into a separate function. This
way it can be re-used for Cable PD identity parsing in future patches.

No functional changes are introduced by this patch.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.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-6-pmalani@chromium.org
2021-01-05 11:01:51 -08:00
Prashant Malani a906f45d14
platform/chrome: cros_ec_typec: Make disc_done flag partner-only
Change the disc_done flag, which indicates whether PD discovery is
complete, to sop_disc_done instead, since we will process SOP and SOP'
discovery data separately.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.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-5-pmalani@chromium.org
2021-01-05 10:58:59 -08:00
Linus Torvalds a088159675 chrome platform changes for 5.11
cros_ec_typec:
 * A series from Prashant for Type-C to implement TYPEC_STATUS, parsing USB PD
   Partner ID VDOs, and registering partner altmodes.
 
 cros_ec misc:
 * Don't treat RTC events as wakeup sources in cros_ec_proto
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCX+JsPAAKCRBzbaomhzOw
 woHeAQD0j6D+m38NgLKr3mwVqkSwaHW7/NNmDIdXBikrRgiw0AD/c/kMZzSzwCGV
 hgSOjg3A4uPq1gyDAW+wYmjngylv3g0=
 =hT9E
 -----END PGP SIGNATURE-----

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

Pull chrome platform updates from Benson Leung:
 "cros_ec_typec:

   - A series from Prashant for Type-C to implement TYPEC_STATUS,
     parsing USB PD Partner ID VDOs, and registering partner altmodes.

  cros_ec misc:

   - Don't treat RTC events as wakeup sources in cros_ec_proto"

* tag 'tag-chrome-platform-for-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
  platform/chrome: cros_ec_typec: Tolerate unrecognized mux flags
  platform/chrome: cros_ec_typec: Register partner altmodes
  platform/chrome: cros_ec_typec: Parse partner PD ID VDOs
  platform/chrome: cros_ec_typec: Introduce TYPEC_STATUS
  platform/chrome: cros_ec: Import Type C host commands
  platform/chrome: cros_ec_typec: Clear partner identity on device removal
  platform/chrome: cros_ec_typec: Fix remove partner logic
  platform/chrome: cros_ec_typec: Relocate set_port_params_v*() functions
  platform/chrome: Don't treat RTC events as wakeup sources
2020-12-23 15:06:22 -08:00
Linus Torvalds 605ea5aafe spi: Updates for v5.11
The big change this release has been some excellent work from Lukas
 Wunner which closes a bunch of holes in the cleanup paths for drivers,
 mainly introduced as a result of devm conversions causing bad
 interactions with the support SPI has for allocating the bus and driver
 data together.  Together with some of the other work done it feels like
 we've turned the corner on several long standing pain points with the
 API.
 
  - Many cleanups around probe/remove and error handling from Lukas
    Wunner and Uwe Kleine-König, and further fixes around PM from Zhang
    Qilong.
  - Provide a mask for which bits of the mode can safely be configured by
    drivers and use that to fix an issue with the ADS7846 driver.
  - Documentation of the expected interactions between SPI and GPIO level
    chip select polarity configuration from H. Nikolaus Schaller,
    hopefully we're pretty much at the end of sorting out the
    interactions there.  Thanks to Nikolaus, Sven Van Asbroeck and Linus
    Walleij for this.
  - DMA support for Allwinner sun6i controllers.
  - Support for Canaan K210 Designware implementations and Intel Adler Lake.
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAl/Xeg4ACgkQJNaLcl1U
 h9BbXQf8DwmtP/biVsB0yxag11Ac9xxDL2OdMXia/DBQZsVSxqGld4l7Bwl8CMVi
 TISCmzO1f53l3KZK5wu1C5mV8tXgCu4zrsPErEsrK2V2+s+4lWy10MOfAHqq/lBR
 L2kifZ/uoeMBaPvJqpRimM8tv2uPXPHOKsdy2G82LzMdk0OhE5p9IkL5Nc5JbKOl
 X1iWTAxtUsDb8+B57AwHSMnL4R3pb/01N0PguJJ8DGol7Oj6VcDf7nh/tqvVkEot
 Ku731oCBQwBhkZKOqd7mvQAjPyoJiFPI8nofC4Bj+a1BDlr+pRcILQ4469zaIAWT
 nPV6BoHTu/tVV63j8YhuamjWYAsS0g==
 =ezV7
 -----END PGP SIGNATURE-----

Merge tag 'spi-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi

Pull spi updates from Mark Brown:
 "The big change this release has been some excellent work from Lukas
  Wunner which closes a bunch of holes in the cleanup paths for drivers,
  mainly introduced as a result of devm conversions causing bad
  interactions with the support SPI has for allocating the bus and
  driver data together.

  Together with some of the other work done it feels like we've turned
  the corner on several long standing pain points with the API.

  Summary:

   - Many cleanups around probe/remove and error handling from Lukas
     Wunner and Uwe Kleine-König, and further fixes around PM from Zhang
     Qilong.

   - Provide a mask for which bits of the mode can safely be configured
     by drivers and use that to fix an issue with the ADS7846 driver.

   - Documentation of the expected interactions between SPI and GPIO
     level chip select polarity configuration from H. Nikolaus Schaller,
     hopefully we're pretty much at the end of sorting out the
     interactions there. Thanks to Nikolaus, Sven Van Asbroeck and Linus
     Walleij for this.

   - DMA support for Allwinner sun6i controllers.

   - Support for Canaan K210 Designware implementations and Intel Adler
     Lake"

* tag 'spi-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (69 commits)
  spi: dt-bindings: clarify CS behavior for spi-cs-high and gpio descriptors
  spi: Limit the spi device max speed to controller's max speed
  spi: spi-geni-qcom: Use the new method of gpio CS control
  platform/chrome: cros_ec_spi: Drop bits_per_word assignment
  platform/chrome: cros_ec_spi: Don't overwrite spi::mode
  spi: dw: Add support for the Canaan K210 SoC SPI
  spi: dw: Add support for 32-bits max xfer size
  dt-bindings: spi: dw-apb-ssi: Add Canaan K210 SPI controller
  spi: Update DT binding docs to support SiFive FU740 SoC
  spi: atmel-quadspi: Fix use-after-free on unbind
  spi: npcm-fiu: Disable clock in probe error path
  spi: ar934x: Don't leak SPI master in probe error path
  spi: mt7621: Don't leak SPI master in probe error path
  spi: mt7621: Disable clock in probe error path
  media: netup_unidvb: Don't leak SPI master in probe error path
  spi: sc18is602: Don't leak SPI master in probe error path
  spi: rb4xx: Don't leak SPI master in probe error path
  spi: gpio: Don't leak SPI master in probe error path
  spi: spi-mtk-nor: Don't leak SPI master in probe error path
  spi: mxic: Don't leak SPI master in probe error path
  ...
2020-12-15 15:51:10 -08:00
Prashant Malani 6ae9b5ffca
platform/chrome: cros_ec_typec: Tolerate unrecognized mux flags
On occasion, the Chrome Embedded Controller (EC) can send a mux
configuration which doesn't map to a particular data mode. For instance,
dedicated Type C chargers, when connected, may cause only
USB_PD_MUX_POLARITY_INVERTED to be set. This is a valid flag combination
and should not lead to a driver abort.

Modify the mux configuration handling to not return an error when an
unrecognized mux flag combination is encountered. Concordantly, make the
ensuing print a debug level print so as to not pollute the kernel logs.

Cc: Keith Short <keithshort@chromium.org>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Benson Leung <bleung@chromium.org>
Link: https://lore.kernel.org/r/20201106020305.767202-1-pmalani@chromium.org
2020-12-10 13:05:16 -08:00
Stephen Boyd 7a5172b799
platform/chrome: cros_ec_spi: Drop bits_per_word assignment
This is already handed by default in spi_setup() if the bits_per_word is
0, so just drop it to shave off a line.

Cc: Simon Glass <sjg@chromium.org>
Cc: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Alexandru M Stan <amstan@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20201204193540.3047030-3-swboyd@chromium.org
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-09 16:52:09 +00:00
Stephen Boyd 74639cbf51
platform/chrome: cros_ec_spi: Don't overwrite spi::mode
There isn't any need to overwrite the mode here in the driver with what
has been detected by the firmware, such as DT or ACPI. In fact, if we
use the SPI CS gpio descriptor feature we will overwrite the mode with
SPI_MODE_0 where it already contains SPI_MODE_0 and more importantly
SPI_CS_HIGH. Clearing the SPI_CS_HIGH bit causes the CS line to toggle
when the device is probed when it shouldn't change, confusing the driver
and making it fail to probe. Drop the assignment and let the spi core
take care of it.

Fixes: a17d94f0b6 ("mfd: Add ChromeOS EC SPI driver")
Cc: Simon Glass <sjg@chromium.org>
Cc: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Alexandru M Stan <amstan@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20201204193540.3047030-2-swboyd@chromium.org
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-09 16:52:08 +00:00
Utkarsh Patel 5384cffd7b platform/chrome: cros_ec_typec: Correct the Thunderbolt rounded/non-rounded cable support
Thunderbolt rounded/non-rounded cable support is two bits value. Correcting
it as per the Thunderbolt 3 cable discover mode VDO changes done in the
Thunderbolt 3 alternate mode header.

Signed-off-by: Utkarsh Patel <utkarsh.h.patel@intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
--
Changes in v2:
- Removed the fixes tag as there is no functional implication.
--
Link: https://lore.kernel.org/r/20201113202503.6559-3-utkarsh.h.patel@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-11-18 12:53:45 +01:00
Prashant Malani de0f49487d platform/chrome: cros_ec_typec: Register partner altmodes
Use the discovery data from the Chrome EC to register parter altmodes
with the Type C Connector Class framework. Also introduce a node
struct to keep track of the list of registered alt modes.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20201029222738.482366-8-pmalani@chromium.org
2020-11-12 21:32:09 +01:00
Prashant Malani f6f6681189 platform/chrome: cros_ec_typec: Parse partner PD ID VDOs
Use EC_CMD_TYPE_DISCOVERY to retrieve and store the discovery data for
the port partner. With that data, update the PD Identity VDO values for
the partner, which were earlier not initialized.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20201029222738.482366-7-pmalani@chromium.org
2020-11-12 21:32:09 +01:00
Prashant Malani 80f8cef60d platform/chrome: cros_ec_typec: Introduce TYPEC_STATUS
Make a call to the newly introduced EC_CMD_TYPEC_STATUS command.
Currently we just check to see if the SOP (port-partner) discovery was
done and emit a debug level print for it.

Subsequent patches will retrieve and parse the discovery data and fill
out the Type C connector class data structures.

Also check the EC_FEATURE_TYPEC_CMD feature flag at probe, and only call
the new TYPEC_STATUS command if the feature flag is supported.

Reported-by: kernel test robot <lkp@intel.com>
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/20201029222738.482366-6-pmalani@chromium.org
2020-11-12 21:32:09 +01:00
Prashant Malani 514acf1cef platform/chrome: cros_ec_typec: Clear partner identity on device removal
The partner identity struct isn't reset when a partner is removed,
meaning a subsequent partner can inherit an old partner's identity VDOs
before discovery is complete. So, clear that struct when a partner
removal is detected.

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/20201029222738.482366-4-pmalani@chromium.org
2020-11-12 21:32:09 +01:00
Prashant Malani 7ab5a673f4 platform/chrome: cros_ec_typec: Fix remove partner logic
The cros_unregister_ports() function can be called in situations where
the partner has not been registered yet, and so its related data
structures would not have been initialized. Calling
cros_typec_remove_partner() in such a situation can lead to null pointer
dereferences. So, only call cros_typec_remove_partner() if there is a
valid registered partner pointer.

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/20201029222738.482366-3-pmalani@chromium.org
2020-11-12 21:32:08 +01:00
Prashant Malani 0498710be0 platform/chrome: cros_ec_typec: Relocate set_port_params_v*() functions
Move the cros_typec_set_port_params_v0/v1() functions closer to the
place where they are called, cros_typec_port_update().

While we are performing the relocation, also move cros_typec_get_mux_info()
closer to its call-site.

No functional changes are introduced by this commit.

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/20201029222738.482366-2-pmalani@chromium.org
2020-11-12 21:32:08 +01:00
Stephen Boyd 853c1a789f platform/chrome: Don't treat RTC events as wakeup sources
The EC sends an RTC host event when the RTC fires, but we don't need to
treat that as a wakeup event here. The RTC class already properly
handles activating and deactivating a wakeup source in rtc_update_irq()
by calling pm_stay_awake() at the start of processing and pm_relax()
once all expired RTC timers have been processed. This reduces one wakeup
increment but not much else. I noticed this while debugging RTC wakeups
and how they always incremented the wakeup count by two instead of one
because this is duplicated.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Guenter Roeck <groeck@chromium.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: <linux-rtc@vger.kernel.org>
Link: https://lore.kernel.org/r/20201030232523.2654478-1-swboyd@chromium.org
2020-11-12 21:24:04 +01:00
Wang Qing 9aa7bd452a platform/chrome: Use kobj_to_dev() instead of container_of()
Use kobj_to_dev() instead of container_of().

Signed-off-by: Wang Qing <wangqing@vivo.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-09-29 10:08:44 +02:00
Prashant Malani 6b194ee986 platform/chrome: cros_ec_proto: Drop cros_ec_cmd_xfer()
Since cros_ec_cmd_xfer_status() now returns Linux error codes and all
other files use that command, remove the now-unused function
cros_ec_cmd_xfer().

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-09-21 10:51:58 +02:00
Prashant Malani 64b02e54e5 platform/chrome: cros_ec_proto: Update cros_ec_cmd_xfer() call-sites
Since all the other call-sites of cros_ec_cmd_xfer() have been converted
to use cros_ec_cmd_xfer_status() instead, update the remaining
call-sites to prepare for the merge of cros_ec_cmd_xfer() into
cros_ec_cmd_xfer_status().

As part of this update, change the error handling inside
cros_ec_get_sensor_count() such that the legacy LPC interface is tried
on all error values, not just when msg->result != EC_RESULT_SUCCESS.

Note that there is a slight change in API in cros_ec_get_sensor_count():
it will return a negative number of sensors when there are no sensors
on arm platform when MOTIONSENSE_CMD_DUMP is not supported (typical for
sensorless chromebook) instead of 0. However, this is not a problem when
probing the EC as we ignore errors only looking for cros_ec_get_sensor_count()
returning a positive number of sensors.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-09-21 10:51:58 +02:00
Enric Balletbo i Serra dd92f7dfe1 platform/chrome: Kconfig: Remove the transitional MFD_CROS_EC config
The MFD_CROS_EC config was a transitional Kconfig option to not break
current defconfigs in the kernel. Now, this is not required anymore
because all the defconfigs have been removed this option and migrated to
enable the CrOS EC parts individually.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
2020-09-04 09:30:04 +02:00
Gwendal Grignou 1e7913ff5f platform/chrome: cros_ec_lightbar: Reduce ligthbar get version command
By default, the lightbar commands are set to the biggest lightbar command
and response. That length is greater than 128 bytes and may not work on
all machines. But all EC are probed for lightbar by sending a get version
request. Set that request size precisely.

Before the command would be:

  cros_ec_cmd: version: 0, command: EC_CMD_LIGHTBAR_CMD, outsize: 194, insize: 128, result: 0

Afer:

  cros_ec_cmd: version: 0, command: EC_CMD_LIGHTBAR_CMD, outsize: 1, insize: 8, result: 0

Fixes: a841178445 ("mfd: cros_ec: Use a zero-length array for command data")
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-09-04 09:30:04 +02:00
Gwendal Grignou 8143182426 platform/chrome: cros_ec_trace: Add fields to command traces
In ftrace, add more fields to the cros_ec command event:

  - Add size of commands to check if they are properly set.
  - Add offset (in case an EC is cascaded being another EC),
    to allow proper command output

With:

  echo 1 > events/cros_ec/cros_ec_cmd/enable

We now have (on samus)

Invalid command for the sensor stack:

  ectool-6942  [002] ....  3082.783116: cros_ec_request_done: version: 3,
  offset: 0, command: EC_CMD_MOTION_SENSE_CMD, outsize: 2, insize: 19,
  ec result: EC_RES_INVALID_PARAM, retval: 0

Powerd accessing PD EC being the main EC:

  powerd-1272  [002] ....    40.644026: cros_ec_request_done: version: 0,
  offset: 1, command: EC_CMD_USB_PD_POWER_INFO, outsize: 1, insize: 16,
  ec result: EC_RES_SUCCESS, retval: 16

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Acked-by: Raul E Rangel <rrangel@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-31 12:14:45 +02:00
Azhar Shaikh a772336596 platform/chrome: cros_ec_typec: Re-order connector configuration steps
As per USB Type-C Spec R2.0 section 4.5.1.2 (Connecting Sources and Sinks)
and section 4.5.2.2 (Connection State Machine Requirements), the typical
flow for configuring a device connected to a typeC port is as below:

1. Source/sink detection
2. Orientation
3. Data role
4. VCONN
5. VBUS (USB Type-C currents)
6. The connector is now configured. We can start the PD communication
   that should lead into configuration of the mux if we enter a mode.

But in existing code data role was set after the connector and mux are
already configured. So fix this by following the spec to set the data
role before the connector and mux are configured.

Signed-off-by: Azhar Shaikh <azhar.shaikh@intel.com>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-24 12:45:56 +02:00
Azhar Shaikh b12e4fd5f3 platform/chrome: cros_ec_typec: Avoid setting usb role twice during disconnect
On disconnect port partner is removed and usb role is set to NONE.
But then in cros_typec_port_update() the role is set again.
Avoid this by moving usb_role_switch_set_role() to
cros_typec_configure_mux().

Suggested-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Azhar Shaikh <azhar.shaikh@intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-24 12:45:56 +02:00
Azhar Shaikh 5381b0ed54 platform/chrome: cros_ec_typec: Send enum values to usb_role_switch_set_role()
usb_role_switch_set_role() has the second argument as enum for usb_role.
Currently depending upon the data role i.e. UFP(0) or DFP(1) is sent.
This eventually translates to USB_ROLE_NONE in case of UFP and
USB_ROLE_DEVICE in case of DFP. Correct this by sending correct enum
values as USB_ROLE_DEVICE in case of UFP and USB_ROLE_HOST in case of
DFP.

Fixes: 7e7def15fa ("platform/chrome: cros_ec_typec: Add USB mux control")
Signed-off-by: Azhar Shaikh <azhar.shaikh@intel.com>
Cc: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-24 12:45:56 +02:00
Heikki Krogerus 46c5bbd2df platform/chrome: cros_ec_typec: USB4 support
With USB4 mode the mux driver needs the Enter_USB Data
Object (EUDO) that was used when the USB mode was entered.
Though the object is not available in the driver, it is
possible to construct it from the information we have.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-24 11:37:34 +02:00
Guenter Roeck 0d080459e8 platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes
The EC reports a variety of error codes. Most of those, with the exception
of EC_RES_INVALID_VERSION, are converted to -EPROTO. As result, the actual
EC error code gets lost. Introduce cros_ec_map_error() to map EC error
codes to Linux error codes, and use it in cros_ec_cmd_xfer_status() to
report more meaningful errors to the caller. With this change, callers of
cros_ec_cmd_xfer_status() can implement a more distinguished action without
having to rely on the EC error code. At the same time, debugging is improved
in situations where the Linux error code is reported to userspace and/or in
the kernel log.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-24 11:37:34 +02:00
Guenter Roeck b4e452b5e9 platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT
-ENOTSUPP is not a SUSV4 error code and should not be used. Use
-ENOPROTOOPT instead to report EC_RES_INVALID_VERSION responses
from the EC. This matches match the NFS response for unsupported
protocol versions.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-24 11:37:34 +02:00
Guenter Roeck b646e7db1c platform/chrome: cros_ec_sysfs: Report range of error codes from EC
Since commit c5cd2b47b2 ("platform/chrome: cros_ec_proto: Report command
not supported") we can no longer assume that cros_ec_cmd_xfer_status()
reports -EPROTO for all errors returned by the EC itself. A follow-up
patch will change cros_ec_cmd_xfer_status() to report additional errors
reported by the EC as distinguished Linux error codes.

Prepare for this change by always reporting both the Linux error code
and the EC error code in sysfs attributes.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-24 11:37:34 +02:00
Guenter Roeck 064df8851f cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status
Since commit c5cd2b47b2 ("platform/chrome: cros_ec_proto: Report command
not supported") we can no longer assume that cros_ec_cmd_xfer_status()
reports -EPROTO for all errors returned by the EC itself. A follow-up
patch will change cros_ec_cmd_xfer_status() to report additional errors
reported by the EC as distinguished Linux error codes.

Handle this change by no longer assuming that -EPROTO is used to report
all errors returned by the EC itself. Since errors reported by the EC are
already reported in text form through sysfs attributes, extend this form
of error reporting to all errors reported by cros_ec_cmd_xfer_status().

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
2020-08-24 11:37:34 +02:00
Linus Torvalds fb893de323 chrome platform changes for 5.9
* cros_ec_typec
 - Add support for switch control and alternate modes to the Chrome EC Type C
   port driver
 - Add basic suspend/resume support
 
 * sensorhub:
 - Fix timestamp overflow issue
 - Fix legacy timestamp spreading on Nami systems
 
 * cros_ec_proto:
 - After removing all users of, stop exporting cros_ec_cmd_xfer
 - Check for missing EC_CMD_HOST_EVENT_GET_WAKE_MASK and ignore wakeups on old
   ECs
 
 * misc:
 - Documentation warning cleanup.
 - Fix double unlock issue in ishtp
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCXzG3VwAKCRBzbaomhzOw
 wkRMAQCjvqZwbMJ+jNXsgqb5+78WN6i4PC5e7lzjPofHEdE6sAEAm4FiTpcEc/Kk
 qnti54fb3O15I/x8sXWceznXbdFAigw=
 =zFfw
 -----END PGP SIGNATURE-----

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

Pull chrome platform updates from Benson Leung:
 "cros_ec_typec:

   - Add support for switch control and alternate modes to the Chrome EC
     Type C port driver

   - Add basic suspend/resume support

  sensorhub:

   - Fix timestamp overflow issue

   - Fix legacy timestamp spreading on Nami systems

  cros_ec_proto:

   - After removing all users of, stop exporting cros_ec_cmd_xfer

   - Check for missing EC_CMD_HOST_EVENT_GET_WAKE_MASK and ignore
     wakeups on old ECs

  misc:

   - Documentation warning cleanup

   - Fix double unlock issue in ishtp"

* tag 'tag-chrome-platform-for-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux: (21 commits)
  platform/chrome: cros_ec_proto: check for missing EC_CMD_HOST_EVENT_GET_WAKE_MASK
  platform/chrome: cros_ec_proto: ignore unnecessary wakeups on old ECs
  platform/chrome: cros_ec_sensorhub: Simplify legacy timestamp spreading
  platform/chrome: cros_ec_proto: Do not export cros_ec_cmd_xfer()
  platform/chrome: cros_ec_typec: Unregister partner on error
  platform/chrome: cros_ec_sensorhub: Fix EC timestamp overflow
  platform/chrome: cros_ec_typec: Add PM support
  platform/chrome: cros_ec_typec: Use workqueue for port update
  platform/chrome: cros_ec_typec: Add a dependency on USB_ROLE_SWITCH
  platform/chrome: cros_ec_ishtp: Fix a double-unlock issue
  platform/chrome: cros_ec_rpmsg: Document missing struct parameters
  platform/chrome: cros_ec_spi: Document missing function parameters
  platform/chrome: cros_ec_typec: Add TBT compat support
  platform/chrome: cros_ec: Add TBT pd_ctrl fields
  platform/chrome: cros_ec_typec: Make configure_mux static
  platform/chrome: cros_ec_typec: Support DP alt mode
  platform/chrome: cros_ec_typec: Add USB mux control
  platform/chrome: cros_ec_typec: Register PD CTRL cmd v2
  platform/chrome: cros_ec: Update mux state bits
  platform/chrome: cros_ec_typec: Register Type C switches
  ...
2020-08-11 17:28:32 -07:00