uboot/test/dm/syscon.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright (C) 2015 Google, Inc
   4 */
   5
   6#include <common.h>
   7#include <dm.h>
   8#include <syscon.h>
   9#include <regmap.h>
  10#include <asm/test.h>
  11#include <dm/test.h>
  12#include <linux/err.h>
  13#include <test/ut.h>
  14
  15/* Base test of system controllers */
  16static int dm_test_syscon_base(struct unit_test_state *uts)
  17{
  18        struct udevice *dev;
  19
  20        ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev));
  21        ut_asserteq(SYSCON0, dev->driver_data);
  22
  23        ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev));
  24        ut_asserteq(SYSCON1, dev->driver_data);
  25
  26        ut_asserteq(-ENODEV, uclass_get_device(UCLASS_SYSCON, 2, &dev));
  27
  28        return 0;
  29}
  30DM_TEST(dm_test_syscon_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  31
  32/* Test system controller finding */
  33static int dm_test_syscon_by_driver_data(struct unit_test_state *uts)
  34{
  35        struct udevice *dev;
  36
  37        ut_assertok(syscon_get_by_driver_data(SYSCON0, &dev));
  38        ut_asserteq(SYSCON0, dev->driver_data);
  39
  40        ut_assertok(syscon_get_by_driver_data(SYSCON1, &dev));
  41        ut_asserteq(SYSCON1, dev->driver_data);
  42
  43        ut_asserteq(-ENODEV, syscon_get_by_driver_data(2, &dev));
  44
  45        return 0;
  46}
  47DM_TEST(dm_test_syscon_by_driver_data, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  48
  49/* Test system controller by phandle */
  50static int dm_test_syscon_by_phandle(struct unit_test_state *uts)
  51{
  52        struct udevice *dev;
  53        struct regmap *map;
  54
  55        ut_assertok(uclass_get_device_by_name(UCLASS_TEST_PROBE, "test4",
  56                                              &dev));
  57
  58        ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev, "first-syscon"));
  59        map = syscon_regmap_lookup_by_phandle(dev, "first-syscon");
  60        ut_assert(map);
  61        ut_assert(!IS_ERR(map));
  62        ut_asserteq(1, map->range_count);
  63
  64        ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev,
  65                                                        "second-sys-ctrl"));
  66        map = syscon_regmap_lookup_by_phandle(dev, "second-sys-ctrl");
  67        ut_assert(map);
  68        ut_assert(!IS_ERR(map));
  69        ut_asserteq(4, map->range_count);
  70
  71        ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev,
  72                                                        "third-syscon"));
  73        map = syscon_regmap_lookup_by_phandle(dev, "third-syscon");
  74        ut_assert(map);
  75        ut_assert(!IS_ERR(map));
  76        ut_asserteq(4, map->range_count);
  77
  78        ut_assert(IS_ERR(syscon_regmap_lookup_by_phandle(dev, "not-present")));
  79
  80        return 0;
  81}
  82DM_TEST(dm_test_syscon_by_phandle, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  83