aboutsummaryrefslogtreecommitdiff
path: root/test/dm/led.c
diff options
context:
space:
mode:
authorSimon Glass2017-04-10 11:34:56 -0600
committerSimon Glass2017-04-14 19:38:57 -0600
commit9413ad4f0def2e06a5042106a6e1650a1aa03a5a (patch)
treec5c98725d3892bdda04e907ec2500502f16435b2 /test/dm/led.c
parent8f4b612333ee0381eedf767c1c005a830886df27 (diff)
dm: led: Support toggling LEDs
Add support for toggling an LED into the uclass interface. This can be efficiently implemented by the driver. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Ziping Chen <techping.chan@gmail.com>
Diffstat (limited to 'test/dm/led.c')
-rw-r--r--test/dm/led.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/dm/led.c b/test/dm/led.c
index 68aa39bd4d0..2cc24127e2a 100644
--- a/test/dm/led.c
+++ b/test/dm/led.c
@@ -53,6 +53,31 @@ static int dm_test_led_gpio(struct unit_test_state *uts)
}
DM_TEST(dm_test_led_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+/* Test that we can toggle LEDs */
+static int dm_test_led_toggle(struct unit_test_state *uts)
+{
+ const int offset = 1;
+ struct udevice *dev, *gpio;
+
+ /*
+ * Check that we can manipulate an LED. LED 1 is connected to GPIO
+ * bank gpio_a, offset 1.
+ */
+ ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
+ ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
+ ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
+ ut_assertok(led_set_state(dev, LEDST_TOGGLE));
+ ut_asserteq(1, sandbox_gpio_get_value(gpio, offset));
+ ut_asserteq(LEDST_ON, led_get_state(dev));
+
+ ut_assertok(led_set_state(dev, LEDST_TOGGLE));
+ ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_led_toggle, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
/* Test obtaining an LED by label */
static int dm_test_led_label(struct unit_test_state *uts)
{