]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: sandbox: pwm: Add a basic pwm test
authorSimon Glass <sjg@chromium.org>
Mon, 17 Apr 2017 03:01:11 +0000 (21:01 -0600)
committerTom Rini <trini@konsulko.com>
Thu, 27 Apr 2017 20:49:02 +0000 (16:49 -0400)
Unfortunately a test for the PWM uclass was not included when it was
submitted. This was noticed when trying to add more functionality:

   http://patchwork.ozlabs.org/patch/748172/

Add a simple test to get us started.

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

index fff175d1b7a2da54a1d636b02c51a36571e55275..50bcdebf74d01a641bbd91077741ada6fdef609b 100644 (file)
                power-domains = <&pwrdom 2>;
        };
 
+       pwm {
+               compatible = "sandbox,pwm";
+       };
+
+       pwm2 {
+               compatible = "sandbox,pwm";
+       };
+
        ram {
                compatible = "sandbox,ram";
        };
index 9814ea3b819779b9c1a8333adcb4eda828e327f2..cdaf3bb74333bbc2d94d6edcc3f11a5f1cf98f75 100644 (file)
@@ -173,3 +173,5 @@ CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_UT_ENV=y
+CONFIG_DM_PWM=y
+CONFIG_PWM_SANDBOX=y
index bba744332c25cd7245a62ed75fd2362443b29d0b..087c7a84fc4ca118623c67d92ff21430362fb323 100644 (file)
@@ -175,3 +175,5 @@ CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_UT_ENV=y
+CONFIG_DM_PWM=y
+CONFIG_PWM_SANDBOX=y
index 6fe21254fd802f7db595cbe5cc11bbd0f98fb67c..ffdd15b6b58ea8c56118a42e2f699ce1b1a1dba2 100644 (file)
@@ -179,3 +179,5 @@ CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_UT_ENV=y
+CONFIG_DM_PWM=y
+CONFIG_PWM_SANDBOX=y
index 37ea2b88eae1f8b46cac62fb3074320be719aa99..e82755805247b07c787e8d2b05cb6e9a26b88cf2 100644 (file)
@@ -27,6 +27,14 @@ config PWM_ROCKCHIP
          Various options provided in the hardware (such as capture mode and
          continuous/single-shot) are not supported by the driver.
 
+config PWM_SANDBOX
+       bool "Enable support for the sandbox PWM"
+       help
+         This is a sandbox PWM used for testing. It provides 3 channels and
+         records the settings passed into it, but otherwise does nothing
+         useful. The PWM can be enabled but is not connected to any outputs
+         so this is not very useful.
+
 config PWM_TEGRA
        bool "Enable support for the Tegra PWM"
        depends on DM_PWM
index b037130385155dc30a6c0f5fc7ac913dd55463d4..29d59916cb95ad4b77599222070056c8daa96979 100644 (file)
@@ -15,4 +15,5 @@ obj-$(CONFIG_DM_PWM)          += pwm-uclass.o
 obj-$(CONFIG_PWM_EXYNOS)       += exynos_pwm.o
 obj-$(CONFIG_PWM_IMX)          += pwm-imx.o pwm-imx-util.o
 obj-$(CONFIG_PWM_ROCKCHIP)     += rk_pwm.o
+obj-$(CONFIG_PWM_SANDBOX)      += sandbox_pwm.o
 obj-$(CONFIG_PWM_TEGRA)                += tegra_pwm.o
diff --git a/drivers/pwm/sandbox_pwm.c b/drivers/pwm/sandbox_pwm.c
new file mode 100644 (file)
index 0000000..c2ce974
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <pwm.h>
+#include <asm/test.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+enum {
+       NUM_CHANNELS    = 3,
+};
+
+struct sandbox_pwm_chan {
+       uint period_ns;
+       uint duty_ns;
+       bool enable;
+};
+
+struct sandbox_pwm_priv {
+       struct sandbox_pwm_chan chan[NUM_CHANNELS];
+};
+
+static int sandbox_pwm_set_config(struct udevice *dev, uint channel,
+                                 uint period_ns, uint duty_ns)
+{
+       struct sandbox_pwm_priv *priv = dev_get_priv(dev);
+       struct sandbox_pwm_chan *chan;
+
+       if (channel >= NUM_CHANNELS)
+               return -ENOSPC;
+       chan = &priv->chan[channel];
+       chan->period_ns = period_ns;
+       chan->duty_ns = duty_ns;
+
+       return 0;
+}
+
+static int sandbox_pwm_set_enable(struct udevice *dev, uint channel,
+                                 bool enable)
+{
+       struct sandbox_pwm_priv *priv = dev_get_priv(dev);
+       struct sandbox_pwm_chan *chan;
+
+       if (channel >= NUM_CHANNELS)
+               return -ENOSPC;
+       chan = &priv->chan[channel];
+       chan->enable = enable;
+
+       return 0;
+}
+
+static const struct pwm_ops sandbox_pwm_ops = {
+       .set_config     = sandbox_pwm_set_config,
+       .set_enable     = sandbox_pwm_set_enable,
+};
+
+static const struct udevice_id sandbox_pwm_ids[] = {
+       { .compatible = "sandbox,pwm" },
+       { }
+};
+
+U_BOOT_DRIVER(warm_pwm_sandbox) = {
+       .name           = "pwm_sandbox",
+       .id             = UCLASS_PWM,
+       .of_match       = sandbox_pwm_ids,
+       .ops            = &sandbox_pwm_ops,
+       .priv_auto_alloc_size   = sizeof(struct sandbox_pwm_priv),
+};
index 1885e17c38d39d2dfa65238288db8898951460b7..e956915bc3d287efb15fecd30ab025ac4e1fd6ee 100644 (file)
@@ -25,6 +25,7 @@ obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
 obj-$(CONFIG_DM_PCI) += pci.o
 obj-$(CONFIG_POWER_DOMAIN) += power-domain.o
+obj-$(CONFIG_DM_PWM) += pwm.o
 obj-$(CONFIG_RAM) += ram.o
 obj-y += regmap.o
 obj-$(CONFIG_REMOTEPROC) += remoteproc.o
diff --git a/test/dm/pwm.c b/test/dm/pwm.c
new file mode 100644 (file)
index 0000000..7bdc75a
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2017 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <pwm.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Basic test of the pwm uclass */
+static int dm_test_pwm_base(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
+       ut_assertok(pwm_set_config(dev, 0, 100, 50));
+       ut_assertok(pwm_set_enable(dev, 0, true));
+       ut_assertok(pwm_set_enable(dev, 1, true));
+       ut_assertok(pwm_set_enable(dev, 2, true));
+       ut_asserteq(-ENOSPC, pwm_set_enable(dev, 3, true));
+
+       ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
+       ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 2, &dev));
+
+       return 0;
+}
+DM_TEST(dm_test_pwm_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);