syscon-reset.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <dm/test.h>
  8. #include <regmap.h>
  9. #include <reset.h>
  10. #include <syscon.h>
  11. #include <test/ut.h>
  12. #include <asm/test.h>
  13. #include <linux/bitops.h>
  14. /* The following values must match the device tree */
  15. #define TEST_RESET_REG 1
  16. #define TEST_RESET_ASSERT_HIGH 0
  17. #define TEST_RESET_ASSERT (TEST_RESET_ASSERT_HIGH ? (u32)-1 : (u32)0)
  18. #define TEST_RESET_DEASSERT (~TEST_RESET_ASSERT)
  19. #define TEST_RESET_VALID 15
  20. #define TEST_RESET_NOMASK 30
  21. #define TEST_RESET_OUTOFRANGE 60
  22. static int dm_test_syscon_reset(struct unit_test_state *uts)
  23. {
  24. struct regmap *map;
  25. struct reset_ctl rst;
  26. struct udevice *reset;
  27. struct udevice *syscon;
  28. struct udevice *syscon_reset;
  29. uint reg;
  30. ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "syscon-reset-test",
  31. &reset));
  32. ut_assertok(uclass_get_device_by_name(UCLASS_SYSCON, "syscon@0",
  33. &syscon));
  34. ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "syscon-reset",
  35. &syscon_reset));
  36. ut_assertok_ptr((map = syscon_get_regmap(syscon)));
  37. ut_asserteq(-EINVAL, reset_get_by_name(reset, "no_mask", &rst));
  38. ut_asserteq(-EINVAL, reset_get_by_name(reset, "out_of_range", &rst));
  39. ut_assertok(reset_get_by_name(reset, "valid", &rst));
  40. sandbox_set_enable_memio(true);
  41. ut_assertok(regmap_write(map, TEST_RESET_REG, TEST_RESET_DEASSERT));
  42. ut_assertok(reset_assert(&rst));
  43. ut_assertok(regmap_read(map, TEST_RESET_REG, &reg));
  44. ut_asserteq(TEST_RESET_DEASSERT ^ BIT(TEST_RESET_VALID), reg);
  45. ut_assertok(reset_deassert(&rst));
  46. ut_assertok(regmap_read(map, TEST_RESET_REG, &reg));
  47. ut_asserteq(TEST_RESET_DEASSERT, reg);
  48. return 0;
  49. }
  50. DM_TEST(dm_test_syscon_reset, UT_TESTF_SCAN_FDT);