mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-18 18:59:44 +00:00
3a6c994f38
On x86 platforms the EC provides a way to read 'switches', which are on/off values determined by the EC. Add a new driver method for this and implement it for LPC. Signed-off-by: Simon Glass <sjg@chromium.org>
103 lines
2.6 KiB
C
103 lines
2.6 KiB
C
// 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);
|
|
|
|
static int dm_test_cros_ec_sku_id(struct unit_test_state *uts)
|
|
{
|
|
struct udevice *dev;
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
|
|
ut_asserteq(1234, cros_ec_get_sku_id(dev));
|
|
|
|
/* try the command */
|
|
console_record_reset();
|
|
ut_assertok(run_command("crosec sku", 0));
|
|
ut_assert_nextline("1234");
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
}
|
|
DM_TEST(dm_test_cros_ec_sku_id, UT_TESTF_SCAN_FDT);
|
|
|
|
static int dm_test_cros_ec_features(struct unit_test_state *uts)
|
|
{
|
|
struct udevice *dev;
|
|
u64 feat;
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
|
|
ut_assertok(cros_ec_get_features(dev, &feat));
|
|
ut_asserteq_64(1U << EC_FEATURE_FLASH | 1U << EC_FEATURE_I2C |
|
|
1ULL << EC_FEATURE_UNIFIED_WAKE_MASKS | 1ULL << EC_FEATURE_ISH,
|
|
feat);
|
|
|
|
ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_I2C));
|
|
ut_asserteq(false, cros_ec_check_feature(dev, EC_FEATURE_MOTION_SENSE));
|
|
ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_ISH));
|
|
|
|
/* try the command */
|
|
console_record_reset();
|
|
ut_assertok(run_command("crosec features", 0));
|
|
ut_assert_nextline("flash");
|
|
ut_assert_nextline("i2c");
|
|
ut_assert_nextline("unified_wake_masks");
|
|
ut_assert_nextline("ish");
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
}
|
|
DM_TEST(dm_test_cros_ec_features, UT_TESTF_SCAN_FDT);
|
|
|
|
static int dm_test_cros_ec_switches(struct unit_test_state *uts)
|
|
{
|
|
struct udevice *dev;
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
|
|
ut_asserteq(0, cros_ec_get_switches(dev));
|
|
|
|
/* try the command */
|
|
console_record_reset();
|
|
ut_assertok(run_command("crosec switches", 0));
|
|
ut_assert_console_end();
|
|
|
|
/* Open the lid and check the switch changes */
|
|
sandbox_cros_ec_set_test_flags(dev, CROSECT_LID_OPEN);
|
|
ut_asserteq(EC_SWITCH_LID_OPEN, cros_ec_get_switches(dev));
|
|
|
|
/* try the command */
|
|
console_record_reset();
|
|
ut_assertok(run_command("crosec switches", 0));
|
|
ut_assert_nextline("lid open");
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
}
|
|
DM_TEST(dm_test_cros_ec_switches, UT_TESTF_SCAN_FDT);
|