return 0;
}
+int cros_ec_hello(struct udevice *dev, uint *handshakep)
+{
+ struct ec_params_hello req;
+ struct ec_response_hello *resp;
+
+ req.in_data = 0x12345678;
+ if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
+ (uint8_t **)&resp, sizeof(*resp)) < 0)
+ return -EIO;
+ if (resp->out_data != req.in_data + 0x01020304) {
+ printf("Received invalid handshake %x\n", resp->out_data);
+ if (handshakep)
+ *handshakep = req.in_data;
+ return -ENOTSYNC;
+ }
+
+ return 0;
+}
+
int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags)
{
struct ec_params_reboot_ec p;
{
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
struct ec_params_hello req;
- struct ec_response_hello *resp;
struct dm_cros_ec_ops *ops;
int ret;
/* Try sending a version 3 packet */
cdev->protocol_version = 3;
req.in_data = 0;
- if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
- (uint8_t **)&resp, sizeof(*resp)) > 0)
+ ret = cros_ec_hello(dev, NULL);
+ if (!ret || ret == -ENOTSYNC)
return 0;
/* Try sending a version 2 packet */
cdev->protocol_version = 2;
- if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
- (uint8_t **)&resp, sizeof(*resp)) > 0)
+ ret = cros_ec_hello(dev, NULL);
+ if (!ret || ret == -ENOTSYNC)
return 0;
/*
int cros_ec_test(struct udevice *dev)
{
- struct ec_params_hello req;
- struct ec_response_hello *resp;
+ uint out_data;
+ int ret;
- req.in_data = 0x12345678;
- if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
- (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp)) {
+ ret = cros_ec_hello(dev, &out_data);
+ if (ret == -ENOTSYNC) {
+ printf("Received invalid handshake %x\n", out_data);
+ return ret;
+ } else if (ret) {
printf("ec_command_inptr() returned error\n");
- return -1;
- }
- if (resp->out_data != req.in_data + 0x01020304) {
- printf("Received invalid handshake %x\n", resp->out_data);
- return -1;
+ return ret;
}
return 0;
#include <asm/malloc.h>
#include <asm/state.h>
#include <asm/sdl.h>
+#include <asm/test.h>
#include <linux/input.h>
/*
* @matrix: Information about keyboard matrix
* @keyscan: Current keyscan information (bit set for each row/column pressed)
* @recovery_req: Keyboard recovery requested
+ * @test_flags: Flags that control behaviour for tests
*/
struct ec_state {
u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2];
struct ec_keymatrix_entry *matrix; /* the key matrix info */
uint8_t keyscan[KEYBOARD_COLS];
bool recovery_req;
+ uint test_flags;
} s_state, *g_state;
/**
struct ec_response_hello *resp = resp_data;
resp->out_data = req->in_data + 0x01020304;
+ if (ec->test_flags & CROSECT_BREAK_HELLO)
+ resp->out_data++;
len = sizeof(*resp);
break;
}
}
}
+void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags)
+{
+ struct ec_state *ec = dev_get_priv(dev);
+
+ ec->test_flags = flags;
+}
+
int cros_ec_probe(struct udevice *dev)
{
struct ec_state *ec = dev_get_priv(dev);
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2021 Google LLC
+ */
+
+#include <common.h>
+#include <cros_ec.h>
+#include <dm.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+static int dm_test_cros_ec_hello(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ uint val;
+
+ ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
+
+ ut_assertok(cros_ec_hello(dev, NULL));
+
+ val = 0xdead1357;
+ ut_assertok(cros_ec_hello(dev, &val));
+ ut_asserteq(0xdead1357, val);
+
+ sandbox_cros_ec_set_test_flags(dev, CROSECT_BREAK_HELLO);
+ ut_asserteq(-ENOTSYNC, cros_ec_hello(dev, &val));
+ ut_asserteq(0x12345678, val);
+
+ return 0;
+}
+DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT);