cros_ec_cmd_xfer_status() is the only exported function that calls
static function cros_ec_map_error().
Add Kunit test for cros_ec_map_error() through calling
cros_ec_cmd_xfer_status().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220622041040.202737-3-tzungbi@kernel.org
cros_ec_cmd_xfer_status() calls cros_ec_cmd_xfer() and cros_ec_map_error().
Given that there are already test cases for cros_ec_cmd_xfer(), only add
basic Kunit tests for cros_ec_cmd_xfer_status().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220622041040.202737-2-tzungbi@kernel.org
cros_ec_wait_until_complete() sends EC_CMD_GET_COMMS_STATUS which expects
to receive sizeof(struct ec_response_get_comms_status) from
cros_ec_xfer_command().
Add Kunit test and expect to receive an error code when
cros_ec_xfer_command() returns 0.
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220718050914.2267370-10-tzungbi@kernel.org
While EC_COMMS_STATUS_PROCESSING flag is still on after it tries
EC_COMMAND_RETRIES times for sending EC_CMD_GET_COMMS_STATUS,
cros_ec_wait_until_complete() doesn't return an error code.
Return -EAGAIN in the case instead.
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220718050914.2267370-9-tzungbi@kernel.org
While EC_COMMS_STATUS_PROCESSING flag is still on after it tries
EC_COMMAND_RETRIES times for sending EC_CMD_GET_COMMS_STATUS,
cros_ec_wait_until_complete() doesn't return an error code.
Change the expectation to an error code.
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220718050914.2267370-8-tzungbi@kernel.org
EC returns EC_RES_IN_PROGRESS if the host command needs more time to
complete. Whenever receives the return code, cros_ec_send_command()
sends EC_CMD_GET_COMMS_STATUS to query the command status.
Separate cros_ec_wait_until_complete() from cros_ec_send_command().
It sends EC_CMD_GET_COMMS_STATUS and waits until the previous command
was completed, or encountered error, or timed out.
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220718050914.2267370-7-tzungbi@kernel.org
cros_ec_send_command() has extra logic to handle EC_RES_IN_PROGRESS.
Separate the command transfer part into cros_ec_xfer_command() so
that other functions can re-use it.
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220718050914.2267370-6-tzungbi@kernel.org
cros_ec_cmd_xfer() is the only exported function that calls static
function cros_ec_send_command().
Add Kunit tests for cros_ec_send_command() through calling
cros_ec_cmd_xfer().
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220718050914.2267370-5-tzungbi@kernel.org
cros_ec_cmd_xfer() transfers the given command and data if any. It
performs some sanity checks and calls cros_ec_send_command().
Add Kunit tests for cros_ec_cmd_xfer().
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220718050914.2267370-4-tzungbi@kernel.org
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
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
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>
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
`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
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
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
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
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
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
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
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
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
-----BEGIN PGP SIGNATURE-----
iQJOBAABCAA4FiEEbt46xwy6kEcDOXoUeZbBVTGwZHAFAmKUhm4aHHRzYm9nZW5k
QGFscGhhLmZyYW5rZW4uZGUACgkQeZbBVTGwZHDDZRAAlIU5WIgXsCNb4AhzyE+W
ALU8/bA1scMBNBlClSwm3QeSn2PhaKZWV4jlSgLZito7vwQZg/97NaCCZoRalIoA
CjhGxw/Bc2SYnj3nR3D3LMYOyu7vIjupKEwZc40WMCT8gVQOXC/K/5cFH2hWVlQs
8xRz55TyXga2s+RwbIaml2HbvOWBkw9SYrrwgeRBgHpLfRD3IB5bbhR+X/lt4AnX
o+ViyvnX8e9Hq2Zt3HFN2MYtnmJ+CPoiMzt9ONMO/6gISYffh3d1CMXLGRD7p2KO
VsEcf3NgXgV5SulnK5inNqext3bUh0GFGMF3dwlqsJ2jtqLz8gAbtjeAqP8PcOm9
zT2vpdxFpgIVRIpSeimL5K3ypTzcUFoH3tHTH6yGjRHkAHNkJYZZGbEPNn3zm4U+
7gRbss0x+sYz4Wm3urPkyhuniO3vVGSI2Xmb0PZqOLPKlO9ihfRjxs+I17UVQbY1
CdNkVQmCldvhDmI7BAbWwa0jByaSRFWyu2XEiliQ4zom+cKQ4bjUZJuDOheyYKcK
jMgqZBPT7HN4ilM3TN7hFxbAFr8oNwA6Eqh8W2Qt6PX0QatvflQ6wvyhmyEDgnP7
AbnjPtkFBQeis8H3Hyv2UyVcpCDCNMFFonYqDqCQwNOThqgurPwlnjF4E5tDb5rG
q1A8JIq3BVa6rsgXisfwaF4=
=hTzI
-----END PGP SIGNATURE-----
Merge tag 'mips_5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux
Pull MIPS updates from Thomas Bogendoerfer:
"Cleanups and fixes"
* tag 'mips_5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux: (38 commits)
MIPS: RALINK: Define pci_remap_iospace under CONFIG_PCI_DRIVERS_GENERIC
MIPS: Use memblock_add_node() in early_parse_mem() under CONFIG_NUMA
MIPS: Return -EINVAL if mem parameter is empty in early_parse_mem()
MIPS: Kconfig: Fix indentation and add endif comment
MIPS: bmips: Fix compiler warning observed on W=1 build
MIPS: Rewrite `csum_tcpudp_nofold' in plain C
mips: setup: use strscpy to replace strlcpy
MIPS: Octeon: add SNIC10E board
MIPS: Ingenic: Refresh defconfig for CU1000-Neo and CU1830-Neo.
MIPS: Ingenic: Refresh device tree for Ingenic SoCs and boards.
MIPS: Ingenic: Add PWM nodes for X1830.
MIPS: Octeon: fix typo in comment
MIPS: loongson32: Kconfig: Remove extra space
MIPS: Sibyte: remove unnecessary return variable
MIPS: Use NOKPROBE_SYMBOL() instead of __kprobes annotation
selftests/ftrace: Save kprobe_events to test log
MIPS: tools: no need to initialise statics to 0
MIPS: Loongson: Use hwmon_device_register_with_groups() to register hwmon
MIPS: VR41xx: Drop redundant spinlock initialization
MIPS: smp: optimization for flush_tlb_mm when exiting
...