]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: test: Add a test for the LED uclass
authorSimon Glass <sjg@chromium.org>
Mon, 6 Jul 2015 18:54:34 +0000 (12:54 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 21 Jul 2015 23:39:32 +0000 (17:39 -0600)
Add a test to confirm that we can adjust LEDs using the led_gpio driver.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
configs/sandbox_defconfig
drivers/led/led_gpio.c
test/dm/Makefile
test/dm/led.c [new file with mode: 0644]

index 2077e851a6336d4be4cb35743de2c2efe9722b83..4b9861835e145fe1ab26af7cc985081cbbe70ba3 100644 (file)
                };
        };
 
+       leds {
+               compatible = "gpio-leds";
+
+               iracibble {
+                       gpios = <&gpio_a 1 0>;
+                       label = "sandbox:red";
+               };
+
+               martinet {
+                       gpios = <&gpio_a 2 0>;
+                       label = "sandbox:green";
+               };
+       };
+
        mmc {
                compatible = "sandbox,mmc";
        };
index a6e8d6eee03bb83389f88a882642973f24ecd029..56d55ac5b838cf861576edace11b0b255a6b926c 100644 (file)
@@ -49,3 +49,5 @@ CONFIG_CLK=y
 CONFIG_RESET=y
 CONFIG_RAM=y
 CONFIG_DM_MMC=y
+CONFIG_LED=y
+CONFIG_LED_GPIO=y
index a4cd61878745e27bbbd90080a7acd8611bc97cd7..cb6e996931b3d33c18d7cdac3466dc7ffe532377 100644 (file)
@@ -41,10 +41,16 @@ static int led_gpio_probe(struct udevice *dev)
 
 static int led_gpio_remove(struct udevice *dev)
 {
+       /*
+        * The GPIO driver may have already been removed. We will need to
+        * address this more generally.
+        */
+#ifndef CONFIG_SANDBOX
        struct led_gpio_priv *priv = dev_get_priv(dev);
 
        if (dm_gpio_is_valid(&priv->gpio))
                dm_gpio_free(dev, &priv->gpio);
+#endif
 
        return 0;
 }
index 54046d31a1171f5357b70f287a94d550f0111fe8..6242a0265a01071fc35f1a01736454dfaed415b3 100644 (file)
@@ -19,6 +19,7 @@ obj-$(CONFIG_CLK) += clk.o
 obj-$(CONFIG_DM_ETH) += eth.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
 obj-$(CONFIG_DM_I2C) += i2c.o
+obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MMC) += mmc.o
 obj-$(CONFIG_DM_PCI) += pci.o
 obj-$(CONFIG_RAM) += ram.o
diff --git a/test/dm/led.c b/test/dm/led.c
new file mode 100644 (file)
index 0000000..8ee075c
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <led.h>
+#include <asm/gpio.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Base test of the led uclass */
+static int dm_test_led_base(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       /* Get the top-level device */
+       ut_assertok(uclass_get_device(UCLASS_LED, 0, &dev));
+       ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
+       ut_assertok(uclass_get_device(UCLASS_LED, 2, &dev));
+       ut_asserteq(-ENODEV, uclass_get_device(UCLASS_LED, 3, &dev));
+
+       return 0;
+}
+DM_TEST(dm_test_led_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test of the led uclass using the led_gpio driver */
+static int dm_test_led_gpio(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));
+       led_set_on(dev, 1);
+       ut_asserteq(1, sandbox_gpio_get_value(gpio, offset));
+       led_set_on(dev, 0);
+       ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
+
+       return 0;
+}
+DM_TEST(dm_test_led_gpio, 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)
+{
+       struct udevice *dev, *cmp;
+
+       ut_assertok(led_get_by_label("sandbox:red", &dev));
+       ut_asserteq(1, device_active(dev));
+       ut_assertok(uclass_get_device(UCLASS_LED, 1, &cmp));
+       ut_asserteq_ptr(dev, cmp);
+
+       ut_assertok(led_get_by_label("sandbox:green", &dev));
+       ut_asserteq(1, device_active(dev));
+       ut_assertok(uclass_get_device(UCLASS_LED, 2, &cmp));
+       ut_asserteq_ptr(dev, cmp);
+
+       ut_asserteq(-ENODEV, led_get_by_label("sandbox:blue", &dev));
+
+       return 0;
+}
+DM_TEST(dm_test_led_label, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);