From 9f8037ea9ca81fc158bc190f7427f329d96ad76c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 21:12:32 -0600 Subject: sandbox: Unprotect DATA regions in bus tests On my Ubuntu 18.04.1 machine two driver-model bus tests have started failing recently. The problem appears to be that the DATA region of the executable is protected. This does not seem correct, but perhaps there is a reason. To work around it, unprotect the regions in these tests before accessing them. Signed-off-by: Simon Glass --- test/dm/bus.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/dm/bus.c b/test/dm/bus.c index e9a4028f047..08137a2216a 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -4,6 +4,9 @@ */ #include +#ifdef CONFIG_SANDBOX +#include +#endif #include #include #include @@ -297,6 +300,11 @@ static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts) ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus)); drv = (struct driver *)bus->driver; size = drv->per_child_auto_alloc_size; + +#ifdef CONFIG_SANDBOX + os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv)); + os_mprotect_allow(drv, sizeof(*drv)); +#endif bus->uclass->uc_drv->per_child_auto_alloc_size = size; drv->per_child_auto_alloc_size = 0; ret = test_bus_parent_data(uts); @@ -440,6 +448,10 @@ static int dm_test_bus_parent_platdata_uclass(struct unit_test_state *uts) ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus)); drv = (struct driver *)bus->driver; size = drv->per_child_platdata_auto_alloc_size; +#ifdef CONFIG_SANDBOX + os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv)); + os_mprotect_allow(drv, sizeof(*drv)); +#endif bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size; drv->per_child_platdata_auto_alloc_size = 0; ret = test_bus_parent_platdata(uts); -- cgit v1.3.1 From 87b05ee3a918145bcf49af91bce3d5c2024e32f4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 21:12:34 -0600 Subject: test/py: Fix unicode handling for log filtering At present the unicode filtering seems to get confused at times with this error: UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 32: ordinal not in range(128) It seems to be due to self._nonprint being interpreted as UTF-8. Fix it by using ordinals instead of characters, changing the string to set. Signed-off-by: Simon Glass Reviewed-by: Stephen Warren Tested-by: Michal Simek --- test/py/multiplexed_log.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py index f23d5dec68c..637a3bd257b 100644 --- a/test/py/multiplexed_log.py +++ b/test/py/multiplexed_log.py @@ -314,8 +314,9 @@ $(document).ready(function () { # The set of characters that should be represented as hexadecimal codes in # the log file. - _nonprint = ('%' + ''.join(chr(c) for c in range(0, 32) if c not in (9, 10)) + - ''.join(chr(c) for c in range(127, 256))) + _nonprint = {ord('%')} + _nonprint.update({c for c in range(0, 32) if c not in (9, 10)}) + _nonprint.update({c for c in range(127, 256)}) def _escape(self, data): """Render data format suitable for inclusion in an HTML document. @@ -331,7 +332,7 @@ $(document).ready(function () { """ data = data.replace(chr(13), '') - data = ''.join((c in self._nonprint) and ('%%%02x' % ord(c)) or + data = ''.join((ord(c) in self._nonprint) and ('%%%02x' % ord(c)) or c for c in data) data = cgi.escape(data) return data -- cgit v1.3.1 From 734f3de9242040d27b7e40ae7f3d980192af5417 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 21:12:37 -0600 Subject: test: Simplify the PATH setup Use 'export' to avoid repeating the path setup for each command. Signed-off-by: Simon Glass --- test/run | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/run b/test/run index d77a1c371b4..6b73813f9bc 100755 --- a/test/run +++ b/test/run @@ -16,23 +16,23 @@ run_test ./test/py/test.py --bd sandbox_spl --build -k test_ofplatdata.py # Run tests for the flat DT version of sandbox ./test/py/test.py --bd sandbox_flattree --build +# Set up a path to dtc (device-tree compiler) and libfdt.py, a library it +# provides and which is built by the sandbox_spl config. DTC_DIR=build-sandbox_spl/scripts/dtc +export PYTHONPATH=${DTC_DIR}/pylibfdt +export DTC=${DTC_DIR}/dtc -PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test \ - ./tools/binman/binman -t +run_test ./tools/binman/binman -t run_test ./tools/patman/patman --test run_test ./tools/buildman/buildman -t -PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test ./tools/dtoc/dtoc -t +run_test ./tools/dtoc/dtoc -t # This needs you to set up Python test coverage tools. # To enable Python test coverage on Debian-type distributions (e.g. Ubuntu): # $ sudo apt-get install python-pytest python-coverage -PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test \ - ./tools/binman/binman -T -PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test \ - ./tools/dtoc/dtoc -T -PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test \ - ./tools/dtoc/test_fdt -T +run_test ./tools/binman/binman -T +run_test ./tools/dtoc/dtoc -T +run_test ./tools/dtoc/test_fdt -T if [ $result == 0 ]; then echo "Tests passed!" -- cgit v1.3.1 From c9adb3559c623c2f1207c17e549059c2d97fc207 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 21:12:38 -0600 Subject: test: Print the name of each test before running it At present the tests are run without any indication of what is running. For the tests which start with a build this is pretty obvious, but for tools it is not. Add a name for each test we run, and print it before starting the test. Signed-off-by: Simon Glass --- test/run | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/run b/test/run index 6b73813f9bc..d9901ae9f72 100755 --- a/test/run +++ b/test/run @@ -1,20 +1,28 @@ #!/bin/bash +# Script to run all U-Boot tests that use sandbox. + +# Runs a test and checks the exit code to decide if it passed +# $1: Test name +# $2 onwards: command line to run run_test() { - $@ + echo -n "$1: " + shift + "$@" [ $? -ne 0 ] && result=$((result+1)) } result=0 # Run all tests that the standard sandbox build can support -run_test ./test/py/test.py --bd sandbox --build +run_test "sandbox" ./test/py/test.py --bd sandbox --build # Run tests which require sandbox_spl -run_test ./test/py/test.py --bd sandbox_spl --build -k test_ofplatdata.py +run_test "sandbox_spl" ./test/py/test.py --bd sandbox_spl --build \ + -k test_ofplatdata.py # Run tests for the flat DT version of sandbox -./test/py/test.py --bd sandbox_flattree --build +run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree --build # Set up a path to dtc (device-tree compiler) and libfdt.py, a library it # provides and which is built by the sandbox_spl config. @@ -22,17 +30,17 @@ DTC_DIR=build-sandbox_spl/scripts/dtc export PYTHONPATH=${DTC_DIR}/pylibfdt export DTC=${DTC_DIR}/dtc -run_test ./tools/binman/binman -t -run_test ./tools/patman/patman --test -run_test ./tools/buildman/buildman -t -run_test ./tools/dtoc/dtoc -t +run_test "binman" ./tools/binman/binman -t +run_test "patman" ./tools/patman/patman --test +run_test "buildman" ./tools/buildman/buildman -t +run_test "dtoc" ./tools/dtoc/dtoc -t # This needs you to set up Python test coverage tools. # To enable Python test coverage on Debian-type distributions (e.g. Ubuntu): # $ sudo apt-get install python-pytest python-coverage -run_test ./tools/binman/binman -T -run_test ./tools/dtoc/dtoc -T -run_test ./tools/dtoc/test_fdt -T +run_test "binman code coverage" ./tools/binman/binman -T +run_test "dtoc code coverage" ./tools/dtoc/dtoc -T +run_test "fdt code coverage" ./tools/dtoc/test_fdt -T if [ $result == 0 ]; then echo "Tests passed!" -- cgit v1.3.1 From 3bc11e818c3ad049a24ba2c2deb27ddd651a6e3b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 21:12:39 -0600 Subject: test: Tidy up comments and variable name The 'result' variable counts the number of failures in running the tests. Rename it to 'failures' to make this more obvious. Also tidy up a few comments. Signed-off-by: Simon Glass --- test/run | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/run b/test/run index d9901ae9f72..d64581ab140 100755 --- a/test/run +++ b/test/run @@ -9,10 +9,10 @@ run_test() { echo -n "$1: " shift "$@" - [ $? -ne 0 ] && result=$((result+1)) + [ $? -ne 0 ] && failures=$((failures+1)) } -result=0 +failures=0 # Run all tests that the standard sandbox build can support run_test "sandbox" ./test/py/test.py --bd sandbox --build @@ -21,7 +21,10 @@ run_test "sandbox" ./test/py/test.py --bd sandbox --build run_test "sandbox_spl" ./test/py/test.py --bd sandbox_spl --build \ -k test_ofplatdata.py -# Run tests for the flat DT version of sandbox +# Run tests for the flat-device-tree version of sandbox. This is a special +# build which does not enable CONFIG_OF_LIVE for the live device tree, so we can +# check that functionality is the same. The standard sandbox build (above) uses +# CONFIG_OF_LIVE. run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree --build # Set up a path to dtc (device-tree compiler) and libfdt.py, a library it @@ -33,6 +36,7 @@ export DTC=${DTC_DIR}/dtc run_test "binman" ./tools/binman/binman -t run_test "patman" ./tools/patman/patman --test run_test "buildman" ./tools/buildman/buildman -t +run_test "fdt" ./tools/dtoc/test_fdt -t run_test "dtoc" ./tools/dtoc/dtoc -t # This needs you to set up Python test coverage tools. @@ -42,7 +46,7 @@ run_test "binman code coverage" ./tools/binman/binman -T run_test "dtoc code coverage" ./tools/dtoc/dtoc -T run_test "fdt code coverage" ./tools/dtoc/test_fdt -T -if [ $result == 0 ]; then +if [ $failures == 0 ]; then echo "Tests passed!" else echo "Tests FAILED" -- cgit v1.3.1 From 2673afe221d17b8d43df3ecae3e3a6024b209ffe Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 21:12:46 -0600 Subject: test: Reduce the number of tests run with sandbox_flattree We only need to run driver-model tests with this config, since this is the only thing that is different when CONFIG_OF_LIVE is not defined. Filter out the other tests to same time. Signed-off-by: Simon Glass --- test/run | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/run b/test/run index d64581ab140..fb8ff5da0cb 100755 --- a/test/run +++ b/test/run @@ -25,7 +25,8 @@ run_test "sandbox_spl" ./test/py/test.py --bd sandbox_spl --build \ # build which does not enable CONFIG_OF_LIVE for the live device tree, so we can # check that functionality is the same. The standard sandbox build (above) uses # CONFIG_OF_LIVE. -run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree --build +run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree --build \ + -k test_ut # Set up a path to dtc (device-tree compiler) and libfdt.py, a library it # provides and which is built by the sandbox_spl config. -- cgit v1.3.1 From 11ae93eef40c09280f36104b6a8cf5d807f0bb0d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 21:12:47 -0600 Subject: binman: Run tests concurrently At present the tests run one after the other using a single CPU. This is not very efficient. Bring in the concurrencytest module and run the tests concurrently, using one process for each CPU by default. A -P option allows this to be overridden, which is necessary for code-coverage to function correctly. This requires fixing a few tests which are currently not fully independent. At some point we might consider doing this across all pytests in U-Boot. There is a pytest version that supports specifying the number of processes to use, but it did not work for me. Signed-off-by: Simon Glass --- .travis.yml | 1 + test/py/README.md | 1 + tools/binman/binman.py | 26 ++++-- tools/binman/cmdline.py | 2 + tools/binman/entry_test.py | 7 +- tools/binman/ftest.py | 34 ++++---- tools/concurrencytest/.gitignore | 1 + tools/concurrencytest/README.md | 74 ++++++++++++++++ tools/concurrencytest/concurrencytest.py | 144 +++++++++++++++++++++++++++++++ tools/dtoc/dtoc.py | 2 + tools/dtoc/test_fdt.py | 2 + tools/patman/test_util.py | 2 +- 12 files changed, 274 insertions(+), 22 deletions(-) create mode 100644 tools/concurrencytest/.gitignore create mode 100644 tools/concurrencytest/README.md create mode 100644 tools/concurrencytest/concurrencytest.py (limited to 'test') diff --git a/.travis.yml b/.travis.yml index 2b759c9d686..f78749afb56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,6 +47,7 @@ install: - virtualenv /tmp/venv - . /tmp/venv/bin/activate - pip install pytest + - pip install python-subunit - grub-mkimage -o ~/grub_x86.efi -O i386-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd - mkdir ~/grub2-arm - ( cd ~/grub2-arm; wget -O - http://download.opensuse.org/ports/armv7hl/distribution/leap/42.2/repo/oss/suse/armv7hl/grub2-arm-efi-2.02~beta2-87.1.armv7hl.rpm | rpm2cpio | cpio -di ) diff --git a/test/py/README.md b/test/py/README.md index aed2fd063a8..4d9d2b81d1e 100644 --- a/test/py/README.md +++ b/test/py/README.md @@ -29,6 +29,7 @@ tests. Similar package names should exist in other distributions. | -------------- | ----------------------------- | | python | 2.7.5-5ubuntu3 | | python-pytest | 2.5.1-1 | +| python-subunit | - | | gdisk | 0.8.8-1ubuntu0.1 | | dfu-util | 0.5-1 | | dtc | 1.4.0+dfsg-1 | diff --git a/tools/binman/binman.py b/tools/binman/binman.py index f5af5359f3c..439908e6650 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -10,6 +10,7 @@ """See README for more information""" import glob +import multiprocessing import os import sys import traceback @@ -17,7 +18,7 @@ import unittest # Bring in the patman and dtoc libraries our_path = os.path.dirname(os.path.realpath(__file__)) -for dirname in ['../patman', '../dtoc', '..']: +for dirname in ['../patman', '../dtoc', '..', '../concurrencytest']: sys.path.insert(0, os.path.join(our_path, dirname)) # Bring in the libfdt module @@ -27,16 +28,22 @@ sys.path.insert(0, os.path.join(our_path, import cmdline import command +use_concurrent = True +try: + from concurrencytest import ConcurrentTestSuite, fork_for_tests +except: + use_concurrent = False import control import test_util -def RunTests(debug, args): +def RunTests(debug, processes, args): """Run the functional tests and any embedded doctests Args: debug: True to enable debugging, which shows a full stack trace on error args: List of positional args provided to binman. This can hold a test name to execute (as in 'binman -t testSections', for example) + processes: Number of processes to use to run tests (None=same as #CPUs) """ import elf_test import entry_test @@ -54,19 +61,28 @@ def RunTests(debug, args): sys.argv = [sys.argv[0]] if debug: sys.argv.append('-D') + if debug: + sys.argv.append('-D') # Run the entry tests first ,since these need to be the first to import the # 'entry' module. test_name = args and args[0] or None + suite = unittest.TestSuite() + loader = unittest.TestLoader() for module in (entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt, elf_test.TestElf, image_test.TestImage): if test_name: try: - suite = unittest.TestLoader().loadTestsFromName(test_name, module) + suite.addTests(loader.loadTestsFromName(test_name, module)) except AttributeError: continue else: - suite = unittest.TestLoader().loadTestsFromTestCase(module) + suite.addTests(loader.loadTestsFromTestCase(module)) + if use_concurrent and processes != 1: + concurrent_suite = ConcurrentTestSuite(suite, + fork_for_tests(processes or multiprocessing.cpu_count())) + concurrent_suite.run(result) + else: suite.run(result) print result @@ -115,7 +131,7 @@ def RunBinman(options, args): sys.tracebacklimit = 0 if options.test: - ret_code = RunTests(options.debug, args[1:]) + ret_code = RunTests(options.debug, options.processes, args[1:]) elif options.test_coverage: RunTestCoverage() diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py index f8caa7d2841..3886d52b3a0 100644 --- a/tools/binman/cmdline.py +++ b/tools/binman/cmdline.py @@ -46,6 +46,8 @@ def ParseArgs(argv): parser.add_option('-p', '--preserve', action='store_true',\ help='Preserve temporary output directory even if option -O is not ' 'given') + parser.add_option('-P', '--processes', type=int, + help='set number of processes to use for running tests') parser.add_option('-t', '--test', action='store_true', default=False, help='run tests') parser.add_option('-T', '--test-coverage', action='store_true', diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py index a8bc938f9e9..17ab2290140 100644 --- a/tools/binman/entry_test.py +++ b/tools/binman/entry_test.py @@ -13,6 +13,8 @@ import fdt import fdt_util import tools +entry = None + class TestEntry(unittest.TestCase): def setUp(self): tools.PrepareOutputDir(None) @@ -38,7 +40,10 @@ class TestEntry(unittest.TestCase): def test2EntryImportLib(self): del sys.modules['importlib'] global entry - reload(entry) + if entry: + reload(entry) + else: + import entry entry.Entry.Create(None, self.GetNode(), 'u-boot-spl') del entry diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index ed787745606..9f21027bd40 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -367,6 +367,16 @@ class TestFunctional(unittest.TestCase): os.makedirs(pathname) return pathname + @classmethod + def _SetupSplElf(self, src_fname='bss_data'): + """Set up an ELF file with a '_dt_ucode_base_size' symbol + + Args: + Filename of ELF file to use as SPL + """ + with open(self.TestFile(src_fname)) as fd: + TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) + @classmethod def TestFile(self, fname): return os.path.join(self._binman_dir, 'test', fname) @@ -715,8 +725,7 @@ class TestFunctional(unittest.TestCase): def testImagePadByte(self): """Test that the image pad byte can be specified""" - with open(self.TestFile('bss_data')) as fd: - TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) + self._SetupSplElf() data = self._DoReadFile('21_image_pad.dts') self.assertEqual(U_BOOT_SPL_DATA + (chr(0xff) * 1) + U_BOOT_DATA, data) @@ -739,6 +748,7 @@ class TestFunctional(unittest.TestCase): def testPackSorted(self): """Test that entries can be sorted""" + self._SetupSplElf() data = self._DoReadFile('24_sorted.dts') self.assertEqual(chr(0) * 1 + U_BOOT_SPL_DATA + chr(0) * 2 + U_BOOT_DATA, data) @@ -781,6 +791,7 @@ class TestFunctional(unittest.TestCase): def testPackX86Rom(self): """Test that a basic x86 ROM can be created""" + self._SetupSplElf() data = self._DoReadFile('29_x86-rom.dts') self.assertEqual(U_BOOT_DATA + chr(0) * 7 + U_BOOT_SPL_DATA + chr(0) * 2, data) @@ -1017,15 +1028,13 @@ class TestFunctional(unittest.TestCase): def testSplBssPad(self): """Test that we can pad SPL's BSS with zeros""" # ELF file with a '__bss_size' symbol - with open(self.TestFile('bss_data')) as fd: - TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) + self._SetupSplElf() data = self._DoReadFile('47_spl_bss_pad.dts') self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data) def testSplBssPadMissing(self): """Test that a missing symbol is detected""" - with open(self.TestFile('u_boot_ucode_ptr')) as fd: - TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) + self._SetupSplElf('u_boot_ucode_ptr') with self.assertRaises(ValueError) as e: self._DoReadFile('47_spl_bss_pad.dts') self.assertIn('Expected __bss_size symbol in spl/u-boot-spl', @@ -1050,9 +1059,7 @@ class TestFunctional(unittest.TestCase): ucode_second: True if the microsecond entry is second instead of third """ - # ELF file with a '_dt_ucode_base_size' symbol - with open(self.TestFile('u_boot_ucode_ptr')) as fd: - TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) + self._SetupSplElf('u_boot_ucode_ptr') first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA, ucode_second=ucode_second) self.assertEqual('splnodtb with microc' + pos_and_size + @@ -1094,8 +1101,7 @@ class TestFunctional(unittest.TestCase): addr = elf.GetSymbolAddress(elf_fname, '__image_copy_start') self.assertEqual(syms['_binman_u_boot_spl_prop_offset'].address, addr) - with open(self.TestFile('u_boot_binman_syms')) as fd: - TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) + self._SetupSplElf('u_boot_binman_syms') data = self._DoReadFile('53_symbols.dts') sym_values = struct.pack(' Date: Mon, 1 Oct 2018 11:55:06 -0600 Subject: log: Add helpers for common log levels At present to output a log message you need something like: log(UCLASS_SPI, LOCL_INFO, "message1"); log(UCLASS_SPI, LOCL_INFO, "message2"); but many files use the same category throughout. Also it is helpful to shorten the length of log names, providing helpers for common logging levels. Add some macros so that it is possible to do: (top of file, before #includes) #define LOG_CATEGORY UCLASS_SPI (later in the file) log_info("message1"); log_debug("message2"); log_err("message3"); Signed-off-by: Simon Glass --- configs/sandbox_flattree_defconfig | 1 + include/log.h | 14 ++++++++++++++ test/log/log_test.c | 13 +++++++++++++ test/py/tests/test_log.py | 6 ++++++ 4 files changed, 34 insertions(+) (limited to 'test') diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index 9f672e50635..2f8a98c379c 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -15,6 +15,7 @@ CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_SILENT_CONSOLE=y +CONFIG_LOG_MAX_LEVEL=6 CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y diff --git a/include/log.h b/include/log.h index 75ff1e1160c..1d936ec9523 100644 --- a/include/log.h +++ b/include/log.h @@ -88,8 +88,22 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, */ #if CONFIG_IS_ENABLED(LOG) #define _LOG_MAX_LEVEL CONFIG_VAL(LOG_MAX_LEVEL) +#define log_err(_fmt...) log(LOG_CATEGORY, LOGL_ERR, ##_fmt) +#define log_warning(_fmt...) log(LOG_CATEGORY, LOGL_WARNING, ##_fmt) +#define log_notice(_fmt...) log(LOG_CATEGORY, LOGL_NOTICE, ##_fmt) +#define log_info(_fmt...) log(LOG_CATEGORY, LOGL_INFO, ##_fmt) +#define log_debug(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG, ##_fmt) +#define log_content(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG_CONTENT, ##_fmt) +#define log_io(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt) #else #define _LOG_MAX_LEVEL LOGL_INFO +#define log_err(_fmt...) +#define log_warning(_fmt...) +#define log_notice(_fmt...) +#define log_info(_fmt...) +#define log_debug(_fmt...) +#define log_content(_fmt...) +#define log_io(_fmt...) #endif /* Emit a log record if the level is less that the maximum */ diff --git a/test/log/log_test.c b/test/log/log_test.c index de431b0823e..febc2c1252a 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -181,6 +181,19 @@ static int log_test(int testnum) return ret; break; } + case 10: { + log_err("level %d\n", LOGL_EMERG); + log_err("level %d\n", LOGL_ALERT); + log_err("level %d\n", LOGL_CRIT); + log_err("level %d\n", LOGL_ERR); + log_warning("level %d\n", LOGL_WARNING); + log_notice("level %d\n", LOGL_NOTICE); + log_info("level %d\n", LOGL_INFO); + log_debug("level %d\n", LOGL_DEBUG); + log_content("level %d\n", LOGL_DEBUG_CONTENT); + log_io("level %d\n", LOGL_DEBUG_IO); + break; + } } return 0; diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py index 605275b0399..cb183444c6f 100644 --- a/test/py/tests/test_log.py +++ b/test/py/tests/test_log.py @@ -85,6 +85,11 @@ def test_log(u_boot_console): lines = run_test(9) check_log_entries(lines, 3) + def test10(): + lines = run_test(10) + for i in range(7): + assert 'log_test() level %d' % i == lines.next() + # TODO(sjg@chromium.org): Consider structuring this as separate tests cons = u_boot_console test0() @@ -97,6 +102,7 @@ def test_log(u_boot_console): test7() test8() test9() + test10() @pytest.mark.buildconfigspec('cmd_log') def test_log_format(u_boot_console): -- cgit v1.3.1 From 55d39911c0579b91a27f0acf3d0c1e123bb29ac1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 11:55:14 -0600 Subject: sandbox: video: Speed up video output At present there are many situations where sandbox syncs the display to the SDL frame buffer. This is a very expensive operation but is only needed every now and then. Update video_sync() so that we can specify whether this operation is really needed. At present this flag is not used on other architectures. It could also be used for reducing writeback-cache flushes but the benefit of that would need to be investigated. Signed-off-by: Simon Glass Reviewed-by: Anatolij Gustschin --- drivers/video/vidconsole-uclass.c | 12 ++++++------ drivers/video/video-uclass.c | 6 +++--- drivers/video/video_bmp.c | 2 +- include/video.h | 4 +++- test/dm/video.c | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 7f95e9c6e56..89ac8b3cc8f 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -86,7 +86,7 @@ static int vidconsole_back(struct udevice *dev) if (priv->ycur < 0) priv->ycur = 0; } - video_sync(dev->parent); + video_sync(dev->parent, false); return 0; } @@ -113,7 +113,7 @@ static void vidconsole_newline(struct udevice *dev) } priv->last_ch = 0; - video_sync(dev->parent); + video_sync(dev->parent, false); } static const struct vid_rgb colors[VID_COLOR_COUNT] = { @@ -293,7 +293,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) if (mode == 2) { video_clear(dev->parent); - video_sync(dev->parent); + video_sync(dev->parent, false); priv->ycur = 0; priv->xcur_frac = priv->xstart_frac; } else { @@ -449,7 +449,7 @@ static void vidconsole_putc(struct stdio_dev *sdev, const char ch) struct udevice *dev = sdev->priv; vidconsole_put_char(dev, ch); - video_sync(dev->parent); + video_sync(dev->parent, false); } static void vidconsole_puts(struct stdio_dev *sdev, const char *s) @@ -458,7 +458,7 @@ static void vidconsole_puts(struct stdio_dev *sdev, const char *s) while (*s) vidconsole_put_char(dev, *s++); - video_sync(dev->parent); + video_sync(dev->parent, false); } /* Set up the number of rows and colours (rotated drivers override this) */ @@ -547,7 +547,7 @@ static int do_video_puts(cmd_tbl_t *cmdtp, int flag, int argc, for (s = argv[1]; *s; s++) vidconsole_put_char(dev, *s); - video_sync(dev->parent); + video_sync(dev->parent, false); return 0; } diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index dd0873767ba..fea0886c415 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -128,7 +128,7 @@ void video_set_default_colors(struct video_priv *priv) } /* Flush video activity to the caches */ -void video_sync(struct udevice *vid) +void video_sync(struct udevice *vid, bool force) { /* * flush_dcache_range() is declared in common.h but it seems that some @@ -147,7 +147,7 @@ void video_sync(struct udevice *vid) struct video_priv *priv = dev_get_uclass_priv(vid); static ulong last_sync; - if (get_timer(last_sync) > 10) { + if (force || get_timer(last_sync) > 10) { sandbox_sdl_sync(priv->fb); last_sync = get_timer(0); } @@ -162,7 +162,7 @@ void video_sync_all(void) dev; uclass_find_next_device(&dev)) { if (device_active(dev)) - video_sync(dev); + video_sync(dev, true); } } diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c index aeff65648c1..1377e190817 100644 --- a/drivers/video/video_bmp.c +++ b/drivers/video/video_bmp.c @@ -345,7 +345,7 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, break; }; - video_sync(dev); + video_sync(dev, false); return 0; } diff --git a/include/video.h b/include/video.h index e7fc5c94e2e..cd5558f86eb 100644 --- a/include/video.h +++ b/include/video.h @@ -131,8 +131,10 @@ void video_clear(struct udevice *dev); * buffer are displayed to the user. * * @dev: Device to sync + * @force: True to force a sync even if there was one recently (this is + * very expensive on sandbox) */ -void video_sync(struct udevice *vid); +void video_sync(struct udevice *vid, bool force); /** * video_sync_all() - Sync all devices' frame buffers with there hardware diff --git a/test/dm/video.c b/test/dm/video.c index ef74c2de721..7def338058e 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -169,7 +169,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts) /* reference clear: */ video_clear(con->parent); - video_sync(con->parent); + video_sync(con->parent, false); ut_asserteq(46, compress_frame_buffer(dev)); /* test clear escape sequence: [2J */ -- cgit v1.3.1 From cdb6aa0afb52da34306c4339f2f4d6cbd3b0ad02 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:07 -0600 Subject: dm: core: Add a function to find the first inactive child Some devices have children and want to press an existing inactive child into service when needed. Add a function to help with this. Signed-off-by: Simon Glass --- drivers/core/device.c | 18 ++++++++++++++++++ include/dm/device.h | 15 +++++++++++++++ test/dm/core.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) (limited to 'test') diff --git a/drivers/core/device.c b/drivers/core/device.c index a9e5906e7cd..5176aa3f866 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -681,6 +681,24 @@ int device_find_next_child(struct udevice **devp) return 0; } +int device_find_first_inactive_child(struct udevice *parent, + enum uclass_id uclass_id, + struct udevice **devp) +{ + struct udevice *dev; + + *devp = NULL; + list_for_each_entry(dev, &parent->child_head, sibling_node) { + if (!device_active(dev) && + device_get_uclass_id(dev) == uclass_id) { + *devp = dev; + return 0; + } + } + + return -ENODEV; +} + struct udevice *dev_get_parent(const struct udevice *child) { return child->parent; diff --git a/include/dm/device.h b/include/dm/device.h index f873fc66e12..847934425bb 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -519,6 +519,21 @@ int device_find_first_child(struct udevice *parent, struct udevice **devp); */ int device_find_next_child(struct udevice **devp); +/** + * device_find_first_inactive_child() - Find the first inactive child + * + * This is used to locate an existing child of a device which is of a given + * uclass. + * + * @parent: Parent device to search + * @uclass_id: Uclass to look for + * @devp: Returns device found, if any + * @return 0 if found, else -ENODEV + */ +int device_find_first_inactive_child(struct udevice *parent, + enum uclass_id uclass_id, + struct udevice **devp); + /** * device_has_children() - check if a device has any children * diff --git a/test/dm/core.c b/test/dm/core.c index c15a8406c09..260f6494a2e 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -870,3 +870,34 @@ static int dm_test_uclass_names(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_uclass_names, DM_TESTF_SCAN_PDATA); + +static int dm_test_inactive_child(struct unit_test_state *uts) +{ + struct dm_test_state *dms = uts->priv; + struct udevice *parent, *dev1, *dev2; + + /* Skip the behaviour in test_post_probe() */ + dms->skip_post_probe = 1; + + ut_assertok(uclass_first_device_err(UCLASS_TEST, &parent)); + + /* + * Create a child but do not activate it. Calling the function again + * should return the same child. + */ + ut_asserteq(-ENODEV, device_find_first_inactive_child(parent, + UCLASS_TEST, &dev1)); + ut_assertok(device_bind_ofnode(parent, DM_GET_DRIVER(test_drv), + "test_child", 0, ofnode_null(), &dev1)); + + ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST, + &dev2)); + ut_asserteq_ptr(dev1, dev2); + + ut_assertok(device_probe(dev1)); + ut_asserteq(-ENODEV, device_find_first_inactive_child(parent, + UCLASS_TEST, &dev2)); + + return 0; +} +DM_TEST(dm_test_inactive_child, DM_TESTF_SCAN_PDATA); -- cgit v1.3.1 From e6c5c94a79d9e1dd20f869a3169bf2be00d53d14 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:08 -0600 Subject: dm: core: Update ofnode to read binman-style flash entry At present ofnode_read_fmap_entry() reads a flash map entry in a format which is not supported by binman. To allow use to use binman-format descriptions, update this function. Also add a simple test. Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox.dts | 20 ++++++++++---------- arch/sandbox/dts/sandbox64.dts | 20 ++++++++++---------- arch/sandbox/dts/test.dts | 29 +++++++++++++++++++++++++++++ drivers/core/of_extra.c | 27 +++++++++++++++++++-------- drivers/misc/cros_ec.c | 33 +++++++++++++++++---------------- include/dm/of_extra.h | 3 ++- test/dm/ofnode.c | 16 ++++++++++++++++ 7 files changed, 103 insertions(+), 45 deletions(-) (limited to 'test') diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index 48db7818d70..fb866e88079 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -18,7 +18,7 @@ stdout-path = "/serial"; }; - cros_ec: cros-ec@0 { + cros_ec: cros-ec { reg = <0 0>; compatible = "google,cros-ec-sandbox"; @@ -26,23 +26,23 @@ * This describes the flash memory within the EC. Note * that the STM32L flash erases to 0, not 0xff. */ - #address-cells = <1>; - #size-cells = <1>; - flash@8000000 { - reg = <0x08000000 0x20000>; + flash { + image-pos = <0x08000000>; + size = <0x20000>; erase-value = <0>; - #address-cells = <1>; - #size-cells = <1>; /* Information for sandbox */ ro { - reg = <0 0xf000>; + image-pos = <0>; + size = <0xf000>; }; wp-ro { - reg = <0xf000 0x1000>; + image-pos = <0xf000>; + size = <0x1000>; }; rw { - reg = <0x10000 0x10000>; + image-pos = <0x10000>; + size = <0x10000>; }; }; }; diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts index 0e32fdad9d8..2c6d3513815 100644 --- a/arch/sandbox/dts/sandbox64.dts +++ b/arch/sandbox/dts/sandbox64.dts @@ -17,7 +17,7 @@ stdout-path = "/serial"; }; - cros_ec: cros-ec@0 { + cros_ec: cros-ec { reg = <0 0 0 0>; compatible = "google,cros-ec-sandbox"; @@ -25,23 +25,23 @@ * This describes the flash memory within the EC. Note * that the STM32L flash erases to 0, not 0xff. */ - #address-cells = <1>; - #size-cells = <1>; - flash@8000000 { - reg = <0x08000000 0x20000>; + flash { + image-pos = <0x08000000>; + size = <0x20000>; erase-value = <0>; - #address-cells = <1>; - #size-cells = <1>; /* Information for sandbox */ ro { - reg = <0 0xf000>; + image-pos = <0>; + size = <0xf000>; }; wp-ro { - reg = <0xf000 0x1000>; + image-pos = <0xf000>; + size = <0x1000>; }; rw { - reg = <0x10000 0x10000>; + image-pos = <0x10000>; + size = <0x10000>; }; }; }; diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index ad94901fa18..05bccd7694e 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -40,6 +40,35 @@ osd0 = "/osd"; }; + cros_ec: cros-ec { + reg = <0 0>; + compatible = "google,cros-ec-sandbox"; + + /* + * This describes the flash memory within the EC. Note + * that the STM32L flash erases to 0, not 0xff. + */ + flash { + image-pos = <0x08000000>; + size = <0x20000>; + erase-value = <0>; + + /* Information for sandbox */ + ro { + image-pos = <0>; + size = <0xf000>; + }; + wp-ro { + image-pos = <0xf000>; + size = <0x1000>; + }; + rw { + image-pos = <0x10000>; + size = <0x10000>; + }; + }; + }; + a-test { reg = <0 1>; compatible = "denx,u-boot-fdt-test"; diff --git a/drivers/core/of_extra.c b/drivers/core/of_extra.c index aa48917dddf..f1f393c3598 100644 --- a/drivers/core/of_extra.c +++ b/drivers/core/of_extra.c @@ -13,19 +13,30 @@ int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry) { const char *prop; - u32 reg[2]; - if (ofnode_read_u32_array(node, "reg", reg, 2)) { - debug("Node '%s' has bad/missing 'reg' property\n", + if (ofnode_read_u32(node, "image-pos", &entry->offset)) { + debug("Node '%s' has bad/missing 'image-pos' property\n", ofnode_get_name(node)); - return -log_ret(ENOENT); + return log_ret(-ENOENT); + } + if (ofnode_read_u32(node, "size", &entry->length)) { + debug("Node '%s' has bad/missing 'size' property\n", + ofnode_get_name(node)); + return log_ret(-ENOENT); } - entry->offset = reg[0]; - entry->length = reg[1]; entry->used = ofnode_read_s32_default(node, "used", entry->length); prop = ofnode_read_string(node, "compress"); - entry->compress_algo = prop && !strcmp(prop, "lzo") ? - FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE; + if (prop) { + if (!strcmp(prop, "lz4")) + entry->compress_algo = FMAP_COMPRESS_LZ4; + else + return log_msg_ret("Unknown compression algo", + -EINVAL); + } else { + entry->compress_algo = FMAP_COMPRESS_NONE; + } + entry->unc_length = ofnode_read_s32_default(node, "uncomp-size", + entry->length); prop = ofnode_read_string(node, "hash"); if (prop) entry->hash_size = strlen(prop); diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 6f299d407a4..c5ac03d027d 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -263,8 +263,8 @@ static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, * @return number of bytes in response, or -ve on error */ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd, - int cmd_version, const void *dout, int dout_len, uint8_t **dinp, - int din_len) + int cmd_version, const void *dout, int dout_len, + uint8_t **dinp, int din_len) { uint8_t *din = NULL; int len; @@ -409,7 +409,7 @@ int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp) } int cros_ec_read_current_image(struct cros_ec_dev *dev, - enum ec_current_image *image) + enum ec_current_image *image) { struct ec_response_get_version *r; @@ -422,7 +422,7 @@ int cros_ec_read_current_image(struct cros_ec_dev *dev, } static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev, - struct ec_response_vboot_hash *hash) + struct ec_response_vboot_hash *hash) { struct ec_params_vboot_hash p; ulong start; @@ -446,7 +446,7 @@ static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev, int cros_ec_read_hash(struct cros_ec_dev *dev, - struct ec_response_vboot_hash *hash) + struct ec_response_vboot_hash *hash) { struct ec_params_vboot_hash p; int rv; @@ -515,7 +515,7 @@ static int cros_ec_invalidate_hash(struct cros_ec_dev *dev) } int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd, - uint8_t flags) + uint8_t flags) { struct ec_params_reboot_ec p; @@ -601,8 +601,8 @@ int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events) } int cros_ec_flash_protect(struct cros_ec_dev *dev, - uint32_t set_mask, uint32_t set_flags, - struct ec_response_flash_protect *resp) + uint32_t set_mask, uint32_t set_flags, + struct ec_response_flash_protect *resp) { struct ec_params_flash_protect params; @@ -742,7 +742,8 @@ int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size) * @return 0 if ok, -1 on error */ static int cros_ec_flash_write_block(struct cros_ec_dev *dev, - const uint8_t *data, uint32_t offset, uint32_t size) + const uint8_t *data, uint32_t offset, + uint32_t size) { struct ec_params_flash_write *p; int ret; @@ -802,7 +803,7 @@ static int cros_ec_data_is_erased(const uint32_t *data, int size) * @param info Pointer to output flash info struct */ int cros_ec_read_flashinfo(struct cros_ec_dev *dev, - struct ec_response_flash_info *info) + struct ec_response_flash_info *info) { int ret; @@ -815,7 +816,7 @@ int cros_ec_read_flashinfo(struct cros_ec_dev *dev, } int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data, - uint32_t offset, uint32_t size) + uint32_t offset, uint32_t size) { uint32_t burst = cros_ec_flash_write_burst_size(dev); uint32_t end, off; @@ -832,7 +833,7 @@ int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data, /* If the data is empty, there is no point in programming it */ todo = min(end - off, burst); if (dev->optimise_flash_write && - cros_ec_data_is_erased((uint32_t *)data, todo)) + cros_ec_data_is_erased((uint32_t *)data, todo)) continue; ret = cros_ec_flash_write_block(dev, data, off, todo); @@ -859,7 +860,7 @@ int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data, * @return 0 if ok, -1 on error */ static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data, - uint32_t offset, uint32_t size) + uint32_t offset, uint32_t size) { struct ec_params_flash_read p; @@ -871,7 +872,7 @@ static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data, } int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset, - uint32_t size) + uint32_t size) { uint32_t burst = cros_ec_flash_write_burst_size(dev); uint32_t end, off; @@ -888,8 +889,8 @@ int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset, return 0; } -int cros_ec_flash_update_rw(struct cros_ec_dev *dev, - const uint8_t *image, int image_size) +int cros_ec_flash_update_rw(struct cros_ec_dev *dev, const uint8_t *image, + int image_size) { uint32_t rw_offset, rw_size; int ret; diff --git a/include/dm/of_extra.h b/include/dm/of_extra.h index 97988b66632..ca15df21b06 100644 --- a/include/dm/of_extra.h +++ b/include/dm/of_extra.h @@ -11,7 +11,7 @@ enum fmap_compress_t { FMAP_COMPRESS_NONE, - FMAP_COMPRESS_LZO, + FMAP_COMPRESS_LZ4, }; enum fmap_hash_t { @@ -26,6 +26,7 @@ struct fmap_entry { uint32_t length; uint32_t used; /* Number of bytes used in region */ enum fmap_compress_t compress_algo; /* Compression type */ + uint32_t unc_length; /* Uncompressed length */ enum fmap_hash_t hash_algo; /* Hash algorithm */ const uint8_t *hash; /* Hash value */ int hash_size; /* Hash size */ diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 907d1ddbdb6..745de50c7ba 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -42,3 +43,18 @@ static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_by_prop_value, DM_TESTF_SCAN_FDT); + +static int dm_test_ofnode_fmap(struct unit_test_state *uts) +{ + struct fmap_entry entry; + ofnode node; + + node = ofnode_path("/cros-ec/flash"); + ut_assert(ofnode_valid(node)); + ut_assertok(ofnode_read_fmap_entry(node, &entry)); + ut_asserteq(0x08000000, entry.offset); + ut_asserteq(0x20000, entry.length); + + return 0; +} +DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- cgit v1.3.1 From 5d9a88f44a93daf623906fee7ca20fa396460ae2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:40 -0600 Subject: test: panel: Add a test for the panel uclass At present this uclass has no tests. Add a simple one which checks the PWM configuration, regulator and GPIO. Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox_pmic.dtsi | 2 +- arch/sandbox/dts/test.dts | 20 ++++++++++++++- arch/sandbox/include/asm/test.h | 15 ++++++++++++ drivers/pwm/sandbox_pwm.c | 25 +++++++++++++++++++ test/dm/Makefile | 1 + test/dm/panel.c | 50 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 test/dm/panel.c (limited to 'test') diff --git a/arch/sandbox/dts/sandbox_pmic.dtsi b/arch/sandbox/dts/sandbox_pmic.dtsi index 403656f25e5..5ecafaab364 100644 --- a/arch/sandbox/dts/sandbox_pmic.dtsi +++ b/arch/sandbox/dts/sandbox_pmic.dtsi @@ -60,7 +60,7 @@ regulator-max-microvolt = <3300000>; }; - ldo1 { + ldo_1: ldo1 { regulator-name = "VDD_EMMC_1.8V"; regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 05bccd7694e..420b72f4dbc 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -11,6 +11,8 @@ eth0 = "/eth@10002000"; eth3 = ð_3; eth5 = ð_5; + gpio1 = &gpio_a; + gpio2 = &gpio_b; i2c0 = "/i2c@0"; mmc0 = "/mmc0"; mmc1 = "/mmc1"; @@ -91,6 +93,15 @@ reg = <2 1>; }; + backlight: backlight { + compatible = "pwm-backlight"; + enable-gpios = <&gpio_a 1>; + power-supply = <&ldo_1>; + pwms = <&pwm 0 1000>; + default-brightness-level = <5>; + brightness-levels = <0 16 32 64 128 170 202 234 255>; + }; + bind-test { bind-test-child1 { compatible = "sandbox,phy"; @@ -441,12 +452,14 @@ power-domains = <&pwrdom 2>; }; - pwm { + pwm: pwm { compatible = "sandbox,pwm"; + #pwm-cells = <2>; }; pwm2 { compatible = "sandbox,pwm"; + #pwm-cells = <2>; }; ram { @@ -483,6 +496,11 @@ remoteproc-name = "remoteproc-test-dev2"; }; + panel { + compatible = "simple-panel"; + backlight = <&backlight 0 100>; + }; + smem@0 { compatible = "sandbox,smem"; }; diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 89f3d90c734..8e60f80ae7f 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -98,4 +98,19 @@ int sandbox_usb_keyb_add_string(struct udevice *dev, const char *str); * @buflen: length of buffer in bytes */ int sandbox_osd_get_mem(struct udevice *dev, u8 *buf, size_t buflen); + +/** + * sandbox_pwm_get_config() - get the PWM config for a channel + * + * @dev: Device to check + * @channel: Channel number to check + * @period_ns: Period of the PWM in nanoseconds + * @duty_ns: Current duty cycle of the PWM in nanoseconds + * @enable: true if the PWM is enabled + * @polarity: true if the PWM polarity is active high + * @return 0 if OK, -ENOSPC if the PWM number is invalid + */ +int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp, + uint *duty_nsp, bool *enablep, bool *polarityp); + #endif diff --git a/drivers/pwm/sandbox_pwm.c b/drivers/pwm/sandbox_pwm.c index 4b50b19c618..28988187e03 100644 --- a/drivers/pwm/sandbox_pwm.c +++ b/drivers/pwm/sandbox_pwm.c @@ -14,6 +14,14 @@ enum { NUM_CHANNELS = 3, }; +/** + * struct sandbox_pwm_chan - a sandbox PWM channel + * + * @period_ns: Period of the PWM in nanoseconds + * @duty_ns: Current duty cycle of the PWM in nanoseconds + * @enable: true if the PWM is enabled + * @polarity: true if the PWM polarity is active high + */ struct sandbox_pwm_chan { uint period_ns; uint duty_ns; @@ -25,6 +33,23 @@ struct sandbox_pwm_priv { struct sandbox_pwm_chan chan[NUM_CHANNELS]; }; +int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp, + uint *duty_nsp, bool *enablep, bool *polarityp) +{ + struct sandbox_pwm_priv *priv = dev_get_priv(dev); + struct sandbox_pwm_chan *chan; + + if (channel >= NUM_CHANNELS) + return -ENOSPC; + chan = &priv->chan[channel]; + *period_nsp = chan->period_ns; + *duty_nsp = chan->duty_ns; + *enablep = chan->enable; + *polarityp = chan->polarity; + + return 0; +} + static int sandbox_pwm_set_config(struct udevice *dev, uint channel, uint period_ns, uint duty_ns) { diff --git a/test/dm/Makefile b/test/dm/Makefile index 57c7dfbcaf9..b490cf28623 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_DM_MAILBOX) += mailbox.o obj-$(CONFIG_DM_MMC) += mmc.o obj-y += ofnode.o obj-$(CONFIG_OSD) += osd.o +obj-$(CONFIG_DM_VIDEO) += panel.o obj-$(CONFIG_DM_PCI) += pci.o obj-$(CONFIG_PHY) += phy.o obj-$(CONFIG_POWER_DOMAIN) += power-domain.o diff --git a/test/dm/panel.c b/test/dm/panel.c new file mode 100644 index 00000000000..ca032409f8c --- /dev/null +++ b/test/dm/panel.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for panel uclass + * + * Copyright (c) 2018 Google, Inc + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Basic test of the panel uclass */ +static int dm_test_panel(struct unit_test_state *uts) +{ + struct udevice *dev, *pwm, *gpio, *reg; + uint period_ns; + uint duty_ns; + bool enable; + bool polarity; + + ut_assertok(uclass_first_device_err(UCLASS_PANEL, &dev)); + ut_assertok(uclass_first_device_err(UCLASS_PWM, &pwm)); + ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio)); + ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", ®)); + ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, + &enable, &polarity)); + ut_asserteq(false, enable); + ut_asserteq(false, regulator_get_enable(reg)); + + ut_assertok(panel_enable_backlight(dev)); + ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, + &enable, &polarity)); + ut_asserteq(1000, period_ns); + ut_asserteq(170 * 1000 / 256, duty_ns); + ut_asserteq(true, enable); + ut_asserteq(false, polarity); + ut_asserteq(1, sandbox_gpio_get_value(gpio, 1)); + ut_asserteq(true, regulator_get_enable(reg)); + + return 0; +} +DM_TEST(dm_test_panel, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- cgit v1.3.1 From a4f737a9c39abb45a5bde47f313df48e645331f7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:41 -0600 Subject: panel: Expand the backlight support At present the panel can be turned on but not off, and the brightness cannot be controlled at run-time. Add a new API function to both the panel and backlight uclasses to handle this. Enhance the PWM backlight driver to deal with custom levels properly and allow the backlight to be turned on and off. Update the test to cover thes new features. Signed-off-by: Simon Glass --- drivers/video/backlight-uclass.c | 10 +++ drivers/video/panel-uclass.c | 18 ++++ drivers/video/pwm_backlight.c | 187 ++++++++++++++++++++++++++++++++------- drivers/video/simple_panel.c | 20 ++++- include/backlight.h | 25 ++++++ include/panel.h | 22 ++++- test/dm/panel.c | 29 ++++++ 7 files changed, 274 insertions(+), 37 deletions(-) (limited to 'test') diff --git a/drivers/video/backlight-uclass.c b/drivers/video/backlight-uclass.c index 92715e2f130..0aadf8a1f97 100644 --- a/drivers/video/backlight-uclass.c +++ b/drivers/video/backlight-uclass.c @@ -18,6 +18,16 @@ int backlight_enable(struct udevice *dev) return ops->enable(dev); } +int backlight_set_brightness(struct udevice *dev, int percent) +{ + const struct backlight_ops *ops = backlight_get_ops(dev); + + if (!ops->set_brightness) + return -ENOSYS; + + return ops->set_brightness(dev, percent); +} + UCLASS_DRIVER(backlight) = { .id = UCLASS_PANEL_BACKLIGHT, .name = "backlight", diff --git a/drivers/video/panel-uclass.c b/drivers/video/panel-uclass.c index aec44a8bf7a..246d1b2836d 100644 --- a/drivers/video/panel-uclass.c +++ b/drivers/video/panel-uclass.c @@ -18,6 +18,24 @@ int panel_enable_backlight(struct udevice *dev) return ops->enable_backlight(dev); } +/** + * panel_set_backlight - Set brightness for the panel backlight + * + * @dev: Panel device containing the backlight to update + * @percent: Brightness value (0=off, 1=min brightness, + * 100=full brightness) + * @return 0 if OK, -ve on error + */ +int panel_set_backlight(struct udevice *dev, int percent) +{ + struct panel_ops *ops = panel_get_ops(dev); + + if (!ops->set_backlight) + return -ENOSYS; + + return ops->set_backlight(dev, percent); +} + int panel_get_display_timing(struct udevice *dev, struct display_timing *timings) { diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c index 53953179bfb..c13a9077090 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_PANEL_BACKLIGHT + #include #include #include @@ -11,48 +13,156 @@ #include #include +/** + * Private information for the PWM backlight + * + * If @num_levels is 0 then the levels are simple values with the backlight + * value going between the minimum (default 0) and the maximum (default 255). + * Otherwise the levels are an index into @levels (0..n-1). + * + * @reg: Regulator to enable to turn the backlight on (NULL if none) + * @enable, GPIO to set to enable the backlight (can be missing) + * @pwm: PWM to use to change the backlight brightness + * @channel: PWM channel to use + * @period_ns: Period of the backlight in nanoseconds + * @levels: Levels for the backlight, or NULL if not using indexed levels + * @num_levels: Number of levels + * @cur_level: Current level for the backlight (index or value) + * @default_level: Default level for the backlight (index or value) + * @min_level: Minimum level of the backlight (full off) + * @min_level: Maximum level of the backlight (full on) + * @enabled: true if backlight is enabled + */ struct pwm_backlight_priv { struct udevice *reg; struct gpio_desc enable; struct udevice *pwm; uint channel; uint period_ns; + u32 *levels; + int num_levels; uint default_level; + int cur_level; uint min_level; uint max_level; + bool enabled; }; -static int pwm_backlight_enable(struct udevice *dev) +static int set_pwm(struct pwm_backlight_priv *priv) { - struct pwm_backlight_priv *priv = dev_get_priv(dev); - struct dm_regulator_uclass_platdata *plat; uint duty_cycle; int ret; - if (priv->reg) { - plat = dev_get_uclass_platdata(priv->reg); - debug("%s: Enable '%s', regulator '%s'/'%s'\n", __func__, - dev->name, priv->reg->name, plat->name); - ret = regulator_set_enable(priv->reg, true); - if (ret) { - debug("%s: Cannot enable regulator for PWM '%s'\n", - __func__, dev->name); - return ret; - } - mdelay(120); - } - - duty_cycle = priv->period_ns * (priv->default_level - priv->min_level) / + duty_cycle = priv->period_ns * (priv->cur_level - priv->min_level) / (priv->max_level - priv->min_level + 1); ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns, duty_cycle); + + return log_ret(ret); +} + +static int enable_sequence(struct udevice *dev, int seq) +{ + struct pwm_backlight_priv *priv = dev_get_priv(dev); + int ret; + + switch (seq) { + case 0: + if (priv->reg) { + __maybe_unused struct dm_regulator_uclass_platdata + *plat; + + plat = dev_get_uclass_platdata(priv->reg); + log_debug("Enable '%s', regulator '%s'/'%s'\n", + dev->name, priv->reg->name, plat->name); + ret = regulator_set_enable(priv->reg, true); + if (ret) { + log_debug("Cannot enable regulator for PWM '%s'\n", + __func__, dev->name); + return log_ret(ret); + } + mdelay(120); + } + break; + case 1: + mdelay(10); + dm_gpio_set_value(&priv->enable, 1); + break; + } + + return 0; +} + +static int pwm_backlight_enable(struct udevice *dev) +{ + struct pwm_backlight_priv *priv = dev_get_priv(dev); + int ret; + + ret = enable_sequence(dev, 0); + if (ret) + return log_ret(ret); + ret = set_pwm(priv); if (ret) - return ret; + return log_ret(ret); ret = pwm_set_enable(priv->pwm, priv->channel, true); if (ret) - return ret; - mdelay(10); - dm_gpio_set_value(&priv->enable, 1); + return log_ret(ret); + ret = enable_sequence(dev, 1); + if (ret) + return log_ret(ret); + priv->enabled = true; + + return 0; +} + +static int pwm_backlight_set_brightness(struct udevice *dev, int percent) +{ + struct pwm_backlight_priv *priv = dev_get_priv(dev); + bool disable = false; + int level; + int ret; + + if (!priv->enabled) { + ret = enable_sequence(dev, 0); + if (ret) + return log_ret(ret); + } + if (percent == BACKLIGHT_OFF) { + disable = true; + percent = 0; + } + if (percent == BACKLIGHT_DEFAULT) { + level = priv->default_level; + } else { + if (priv->levels) { + level = priv->levels[percent * (priv->num_levels - 1) + / 100]; + } else { + level = priv->min_level + + (priv->max_level - priv->min_level) * + percent / 100; + } + } + priv->cur_level = level; + + ret = set_pwm(priv); + if (ret) + return log_ret(ret); + if (!priv->enabled) { + ret = enable_sequence(dev, 1); + if (ret) + return log_ret(ret); + priv->enabled = true; + } + if (disable) { + dm_gpio_set_value(&priv->enable, 0); + if (priv->reg) { + ret = regulator_set_enable(priv->reg, false); + if (ret) + return log_ret(ret); + } + priv->enabled = false; + } return 0; } @@ -64,31 +174,32 @@ static int pwm_backlight_ofdata_to_platdata(struct udevice *dev) int index, ret, count, len; const u32 *cell; - debug("%s: start\n", __func__); + log_debug("start\n"); ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, "power-supply", &priv->reg); if (ret) - debug("%s: Cannot get power supply: ret=%d\n", __func__, ret); + log_debug("Cannot get power supply: ret=%d\n", ret); ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable, GPIOD_IS_OUT); if (ret) { - debug("%s: Warning: cannot get enable GPIO: ret=%d\n", - __func__, ret); + log_debug("Warning: cannot get enable GPIO: ret=%d\n", ret); if (ret != -ENOENT) - return ret; + return log_ret(ret); } ret = dev_read_phandle_with_args(dev, "pwms", "#pwm-cells", 0, 0, &args); if (ret) { - debug("%s: Cannot get PWM phandle: ret=%d\n", __func__, ret); - return ret; + log_debug("Cannot get PWM phandle: ret=%d\n", ret); + return log_ret(ret); } ret = uclass_get_device_by_ofnode(UCLASS_PWM, args.node, &priv->pwm); if (ret) { - debug("%s: Cannot get PWM: ret=%d\n", __func__, ret); - return ret; + log_debug("Cannot get PWM: ret=%d\n", ret); + return log_ret(ret); } + if (args.args_count < 2) + return log_msg_ret("Not enough arguments to pwm\n", -EINVAL); priv->channel = args.args[0]; priv->period_ns = args.args[1]; @@ -96,13 +207,20 @@ static int pwm_backlight_ofdata_to_platdata(struct udevice *dev) cell = dev_read_prop(dev, "brightness-levels", &len); count = len / sizeof(u32); if (cell && count > index) { - priv->default_level = fdt32_to_cpu(cell[index]); - priv->max_level = fdt32_to_cpu(cell[count - 1]); + priv->levels = malloc(len); + if (!priv->levels) + return log_ret(-ENOMEM); + dev_read_u32_array(dev, "brightness-levels", priv->levels, + count); + priv->num_levels = count; + priv->default_level = priv->levels[index]; + priv->max_level = priv->levels[count - 1]; } else { priv->default_level = index; priv->max_level = 255; } - debug("%s: done\n", __func__); + priv->cur_level = priv->default_level; + log_debug("done\n"); return 0; @@ -114,7 +232,8 @@ static int pwm_backlight_probe(struct udevice *dev) } static const struct backlight_ops pwm_backlight_ops = { - .enable = pwm_backlight_enable, + .enable = pwm_backlight_enable, + .set_brightness = pwm_backlight_set_brightness, }; static const struct udevice_id pwm_backlight_ids[] = { diff --git a/drivers/video/simple_panel.c b/drivers/video/simple_panel.c index 6c604f9bedb..7a968e740c5 100644 --- a/drivers/video/simple_panel.c +++ b/drivers/video/simple_panel.c @@ -32,6 +32,21 @@ static int simple_panel_enable_backlight(struct udevice *dev) return 0; } +static int simple_panel_set_backlight(struct udevice *dev, int percent) +{ + struct simple_panel_priv *priv = dev_get_priv(dev); + int ret; + + debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); + dm_gpio_set_value(&priv->enable, 1); + ret = backlight_set_brightness(priv->backlight, percent); + debug("%s: done, ret = %d\n", __func__, ret); + if (ret) + return ret; + + return 0; +} + static int simple_panel_ofdata_to_platdata(struct udevice *dev) { struct simple_panel_priv *priv = dev_get_priv(dev); @@ -51,7 +66,7 @@ static int simple_panel_ofdata_to_platdata(struct udevice *dev) "backlight", &priv->backlight); if (ret) { debug("%s: Cannot get backlight: ret=%d\n", __func__, ret); - return ret; + return log_ret(ret); } ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable, GPIOD_IS_OUT); @@ -59,7 +74,7 @@ static int simple_panel_ofdata_to_platdata(struct udevice *dev) debug("%s: Warning: cannot get enable GPIO: ret=%d\n", __func__, ret); if (ret != -ENOENT) - return ret; + return log_ret(ret); } return 0; @@ -82,6 +97,7 @@ static int simple_panel_probe(struct udevice *dev) static const struct panel_ops simple_panel_ops = { .enable_backlight = simple_panel_enable_backlight, + .set_backlight = simple_panel_set_backlight, }; static const struct udevice_id simple_panel_ids[] = { diff --git a/include/backlight.h b/include/backlight.h index a304c36e019..ac59eb293b4 100644 --- a/include/backlight.h +++ b/include/backlight.h @@ -7,6 +7,13 @@ #ifndef _BACKLIGHT_H #define _BACKLIGHT_H +enum { + BACKLIGHT_MAX = 100, + BACKLIGHT_MIN = 0, + BACKLIGHT_OFF = -1, + BACKLIGHT_DEFAULT = -2, +}; + struct backlight_ops { /** * enable() - Enable a backlight @@ -15,6 +22,15 @@ struct backlight_ops { * @return 0 if OK, -ve on error */ int (*enable)(struct udevice *dev); + + /** + * set_brightness - Set brightness + * + * @dev: Backlight device to update + * @percent: Brightness value (0 to 100, or BACKLIGHT_... value) + * @return 0 if OK, -ve on error + */ + int (*set_brightness)(struct udevice *dev, int percent); }; #define backlight_get_ops(dev) ((struct backlight_ops *)(dev)->driver->ops) @@ -27,4 +43,13 @@ struct backlight_ops { */ int backlight_enable(struct udevice *dev); +/** + * backlight_set_brightness - Set brightness + * + * @dev: Backlight device to update + * @percent: Brightness value (0 to 100, or BACKLIGHT_... value) + * @return 0 if OK, -ve on error + */ +int backlight_set_brightness(struct udevice *dev, int percent); + #endif diff --git a/include/panel.h b/include/panel.h index 6237d32657d..cd596d48c02 100644 --- a/include/panel.h +++ b/include/panel.h @@ -15,6 +15,16 @@ struct panel_ops { * @return 0 if OK, -ve on error */ int (*enable_backlight)(struct udevice *dev); + + /** + * set_backlight - Set panel backlight brightness + * + * @dev: Panel device containing the backlight to update + * @percent: Brightness value (0 to 100, or BACKLIGHT_... value) + * @return 0 if OK, -ve on error + */ + int (*set_backlight)(struct udevice *dev, int percent); + /** * get_timings() - Get display timings from panel. * @@ -29,13 +39,23 @@ struct panel_ops { #define panel_get_ops(dev) ((struct panel_ops *)(dev)->driver->ops) /** - * panel_enable_backlight() - Enable the panel backlight + * panel_enable_backlight() - Enable/disable the panel backlight * * @dev: Panel device containing the backlight to enable + * @enable: true to enable the backlight, false to dis * @return 0 if OK, -ve on error */ int panel_enable_backlight(struct udevice *dev); +/** + * panel_set_backlight - Set brightness for the panel backlight + * + * @dev: Panel device containing the backlight to update + * @percent: Brightness value (0 to 100, or BACKLIGHT_... value) + * @return 0 if OK, -ve on error + */ +int panel_set_backlight(struct udevice *dev, int percent); + /** * panel_get_display_timing() - Get display timings from panel. * diff --git a/test/dm/panel.c b/test/dm/panel.c index ca032409f8c..7e4ebd6d81e 100644 --- a/test/dm/panel.c +++ b/test/dm/panel.c @@ -45,6 +45,35 @@ static int dm_test_panel(struct unit_test_state *uts) ut_asserteq(1, sandbox_gpio_get_value(gpio, 1)); ut_asserteq(true, regulator_get_enable(reg)); + ut_assertok(panel_set_backlight(dev, 40)); + ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, + &enable, &polarity)); + ut_asserteq(64 * 1000 / 256, duty_ns); + + ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX)); + ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, + &enable, &polarity)); + ut_asserteq(255 * 1000 / 256, duty_ns); + + ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN)); + ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, + &enable, &polarity)); + ut_asserteq(0 * 1000 / 256, duty_ns); + ut_asserteq(1, sandbox_gpio_get_value(gpio, 1)); + + ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT)); + ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, + &enable, &polarity)); + ut_asserteq(true, enable); + ut_asserteq(170 * 1000 / 256, duty_ns); + + ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF)); + ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, + &enable, &polarity)); + ut_asserteq(0 * 1000 / 256, duty_ns); + ut_asserteq(0, sandbox_gpio_get_value(gpio, 1)); + ut_asserteq(false, regulator_get_enable(reg)); + return 0; } DM_TEST(dm_test_panel, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- cgit v1.3.1 From eb517315a67320e770cf4a100a922e8ae18fa54e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:45 -0600 Subject: sysreset: Tidy up a few comments and logging Some comments are incorrect or missing pieces. Fix these and use logging to print the error. Signed-off-by: Simon Glass --- drivers/sysreset/sysreset-uclass.c | 4 +++- include/sysreset.h | 4 +++- test/dm/sysreset.c | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/drivers/sysreset/sysreset-uclass.c b/drivers/sysreset/sysreset-uclass.c index 06ef0ed96c7..e38814b3ed1 100644 --- a/drivers/sysreset/sysreset-uclass.c +++ b/drivers/sysreset/sysreset-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_SYSRESET + #include #include #include @@ -64,7 +66,7 @@ void sysreset_walk_halt(enum sysreset_t type) mdelay(100); /* Still no reset? Give up */ - debug("System reset not supported on this platform\n"); + log_err("System reset not supported on this platform\n"); hang(); } diff --git a/include/sysreset.h b/include/sysreset.h index a5c0b74a473..343e46f1aa5 100644 --- a/include/sysreset.h +++ b/include/sysreset.h @@ -31,6 +31,7 @@ struct sysreset_ops { /** * get_status() - get printable reset status information * + * @dev: Device to check * @buf: Buffer to receive the textual reset information * @size: Size of the passed buffer * @return 0 if OK, -ve on error @@ -49,8 +50,9 @@ struct sysreset_ops { int sysreset_request(struct udevice *dev, enum sysreset_t type); /** - * get_status() - get printable reset status information + * sysreset_get_status() - get printable reset status information * + * @dev: Device to check * @buf: Buffer to receive the textual reset information * @size: Size of the passed buffer * @return 0 if OK, -ve on error diff --git a/test/dm/sysreset.c b/test/dm/sysreset.c index 04d4621d9e1..218cc239cc6 100644 --- a/test/dm/sysreset.c +++ b/test/dm/sysreset.c @@ -62,7 +62,6 @@ static int dm_test_sysreset_get_status(struct unit_test_state *uts) return 0; } - DM_TEST(dm_test_sysreset_get_status, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); /* Test that we can walk through the sysreset devices */ -- cgit v1.3.1 From 751fed426f87204517df14de76762461cd2a4203 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:46 -0600 Subject: sysreset: Add a way to find the last reset We have a method to return the last reset as a string for humans, but not a method that allows it to be used programmatically. Add a new method that returns the last reset as an enum. Signed-off-by: Simon Glass --- drivers/sysreset/sysreset-uclass.c | 30 ++++++++++++++++++++++++++++++ drivers/sysreset/sysreset_sandbox.c | 15 +++++++++++++++ include/sysreset.h | 30 ++++++++++++++++++++++++++++++ test/dm/sysreset.c | 20 ++++++++++++++++++++ 4 files changed, 95 insertions(+) (limited to 'test') diff --git a/drivers/sysreset/sysreset-uclass.c b/drivers/sysreset/sysreset-uclass.c index e38814b3ed1..ad831c703a9 100644 --- a/drivers/sysreset/sysreset-uclass.c +++ b/drivers/sysreset/sysreset-uclass.c @@ -36,6 +36,16 @@ int sysreset_get_status(struct udevice *dev, char *buf, int size) return ops->get_status(dev, buf, size); } +int sysreset_get_last(struct udevice *dev) +{ + struct sysreset_ops *ops = sysreset_get_ops(dev); + + if (!ops->get_last) + return -ENOSYS; + + return ops->get_last(dev); +} + int sysreset_walk(enum sysreset_t type) { struct udevice *dev; @@ -55,6 +65,26 @@ int sysreset_walk(enum sysreset_t type) return ret; } +int sysreset_get_last_walk(void) +{ + struct udevice *dev; + int value = -ENOENT; + + for (uclass_first_device(UCLASS_SYSRESET, &dev); + dev; + uclass_next_device(&dev)) { + int ret; + + ret = sysreset_get_last(dev); + if (ret >= 0) { + value = ret; + break; + } + } + + return value; +} + void sysreset_walk_halt(enum sysreset_t type) { int ret; diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c index 75004d9f774..7f6d4186e16 100644 --- a/drivers/sysreset/sysreset_sandbox.c +++ b/drivers/sysreset/sysreset_sandbox.c @@ -36,6 +36,11 @@ int sandbox_warm_sysreset_get_status(struct udevice *dev, char *buf, int size) return 0; } +int sandbox_warm_sysreset_get_last(struct udevice *dev) +{ + return SYSRESET_WARM; +} + static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) { struct sandbox_state *state = state_get_current(); @@ -58,6 +63,9 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) return -EACCES; sandbox_exit(); break; + case SYSRESET_POWER_OFF: + if (!state->sysreset_allowed[type]) + return -EACCES; default: return -ENOSYS; } @@ -74,9 +82,15 @@ int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size) return 0; } +int sandbox_sysreset_get_last(struct udevice *dev) +{ + return SYSRESET_COLD; +} + static struct sysreset_ops sandbox_sysreset_ops = { .request = sandbox_sysreset_request, .get_status = sandbox_sysreset_get_status, + .get_last = sandbox_sysreset_get_last, }; static const struct udevice_id sandbox_sysreset_ids[] = { @@ -94,6 +108,7 @@ U_BOOT_DRIVER(sysreset_sandbox) = { static struct sysreset_ops sandbox_warm_sysreset_ops = { .request = sandbox_warm_sysreset_request, .get_status = sandbox_warm_sysreset_get_status, + .get_last = sandbox_warm_sysreset_get_last, }; static const struct udevice_id sandbox_warm_sysreset_ids[] = { diff --git a/include/sysreset.h b/include/sysreset.h index 343e46f1aa5..61295e3fcbb 100644 --- a/include/sysreset.h +++ b/include/sysreset.h @@ -11,6 +11,7 @@ enum sysreset_t { SYSRESET_WARM, /* Reset CPU, keep GPIOs active */ SYSRESET_COLD, /* Reset CPU and GPIOs */ SYSRESET_POWER, /* Reset PMIC (remove and restore power) */ + SYSRESET_POWER_OFF, /* Turn off power */ SYSRESET_COUNT, }; @@ -37,6 +38,14 @@ struct sysreset_ops { * @return 0 if OK, -ve on error */ int (*get_status)(struct udevice *dev, char *buf, int size); + + /** + * get_last() - get information on the last reset + * + * @dev: Device to check + * @return last reset state (enum sysreset_t) or -ve error + */ + int (*get_last)(struct udevice *dev); }; #define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops) @@ -59,6 +68,14 @@ int sysreset_request(struct udevice *dev, enum sysreset_t type); */ int sysreset_get_status(struct udevice *dev, char *buf, int size); +/** + * sysreset_get_last() - get information on the last reset + * + * @dev: Device to check + * @return last reset state (enum sysreset_t) or -ve error + */ +int sysreset_get_last(struct udevice *dev); + /** * sysreset_walk() - cause a system reset * @@ -73,6 +90,19 @@ int sysreset_get_status(struct udevice *dev, char *buf, int size); */ int sysreset_walk(enum sysreset_t type); +/** + * sysreset_get_last_walk() - get information on the last reset + * + * This works through the available sysreset devices until it finds one that can + * perform a reset. If the provided sysreset type is not available, the next one + * will be tried. + * + * If no device prives the information, this function returns -ENOENT + * + * @return last reset state (enum sysreset_t) or -ve error + */ +int sysreset_get_last_walk(void); + /** * sysreset_walk_halt() - try to reset, otherwise halt * diff --git a/test/dm/sysreset.c b/test/dm/sysreset.c index 218cc239cc6..e1b7bf5277d 100644 --- a/test/dm/sysreset.c +++ b/test/dm/sysreset.c @@ -71,6 +71,7 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts) /* If we generate a power sysreset, we will exit sandbox! */ state->sysreset_allowed[SYSRESET_POWER] = false; + state->sysreset_allowed[SYSRESET_POWER_OFF] = false; ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM)); ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD)); ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); @@ -90,3 +91,22 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int dm_test_sysreset_get_last(struct unit_test_state *uts) +{ + struct udevice *dev; + + /* Device 1 is the warm sysreset device */ + ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev)); + ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev)); + + /* Device 2 is the cold sysreset device */ + ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev)); + ut_asserteq(SYSRESET_COLD, sysreset_get_last(dev)); + + /* This is device 0, the non-DT one */ + ut_asserteq(SYSRESET_COLD, sysreset_get_last_walk()); + + return 0; +} +DM_TEST(dm_test_sysreset_get_last, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- cgit v1.3.1