From ddae9fcddc48d1e624c941148d0df5a4fc7d7d5c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 10 Apr 2017 11:34:54 -0600 Subject: dm: led: Adjust the LED uclass At present this is very simple, supporting only on and off. We want to also support toggling and blinking. As a first step, change the name of the main method and use an enum to indicate the state. Signed-off-by: Simon Glass Reviewed-by: Ziping Chen --- test/dm/led.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/dm') diff --git a/test/dm/led.c b/test/dm/led.c index 8ee075cf1c..ebb9b46584 100644 --- a/test/dm/led.c +++ b/test/dm/led.c @@ -41,9 +41,10 @@ static int dm_test_led_gpio(struct unit_test_state *uts) 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)); - led_set_on(dev, 1); + ut_assertok(led_set_state(dev, LEDST_ON)); ut_asserteq(1, sandbox_gpio_get_value(gpio, offset)); - led_set_on(dev, 0); + + ut_assertok(led_set_state(dev, LEDST_OFF)); ut_asserteq(0, sandbox_gpio_get_value(gpio, offset)); return 0; -- cgit From 8f4b612333ee0381eedf767c1c005a830886df27 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 10 Apr 2017 11:34:55 -0600 Subject: dm: led: Add support for getting the state of an LED It is useful to be able to read the LED as well as write it. Add this to the uclass and update the GPIO driver. Signed-off-by: Simon Glass Reviewed-by: Ziping Chen --- test/dm/led.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/dm') diff --git a/test/dm/led.c b/test/dm/led.c index ebb9b46584..68aa39bd4d 100644 --- a/test/dm/led.c +++ b/test/dm/led.c @@ -43,9 +43,11 @@ static int dm_test_led_gpio(struct unit_test_state *uts) ut_asserteq(0, sandbox_gpio_get_value(gpio, offset)); ut_assertok(led_set_state(dev, LEDST_ON)); ut_asserteq(1, sandbox_gpio_get_value(gpio, offset)); + ut_asserteq(LEDST_ON, led_get_state(dev)); ut_assertok(led_set_state(dev, LEDST_OFF)); ut_asserteq(0, sandbox_gpio_get_value(gpio, offset)); + ut_asserteq(LEDST_OFF, led_get_state(dev)); return 0; } -- cgit From 9413ad4f0def2e06a5042106a6e1650a1aa03a5a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 10 Apr 2017 11:34:56 -0600 Subject: 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 Reviewed-by: Ziping Chen --- test/dm/led.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/dm') diff --git a/test/dm/led.c b/test/dm/led.c index 68aa39bd4d..2cc24127e2 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) { -- cgit From 53378dac8dc33e3fd5f07d60bd7a5f8258ac7a20 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 10 Apr 2017 11:34:57 -0600 Subject: dm: led: Add support for blinking LEDs Allow LEDs to be blinked if the driver supports it. Enable this for sandbox so that the tests run. Signed-off-by: Simon Glass Reviewed-by: Ziping Chen --- test/dm/led.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/dm') diff --git a/test/dm/led.c b/test/dm/led.c index 2cc24127e2..fde700be38 100644 --- a/test/dm/led.c +++ b/test/dm/led.c @@ -98,3 +98,27 @@ static int dm_test_led_label(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_led_label, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test LED blinking */ +#ifdef CONFIG_LED_BLINK +static int dm_test_led_blink(struct unit_test_state *uts) +{ + const int offset = 1; + struct udevice *dev, *gpio; + + /* + * Check that we get an error when trying to blink an LED, since it is + * not supported by the GPIO LED driver. + */ + 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_asserteq(-ENOSYS, led_set_state(dev, LEDST_BLINK)); + ut_asserteq(0, sandbox_gpio_get_value(gpio, offset)); + ut_asserteq(LEDST_OFF, led_get_state(dev)); + ut_asserteq(-ENOSYS, led_set_period(dev, 100)); + + return 0; +} +DM_TEST(dm_test_led_blink, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +#endif -- cgit