Skip to contentSkip to conversation

dm: sandbox: pwm: Add a basic pwm test

PATCH In review Simon Glass 2 participants 2 messages Apr 17, 2017 – Apr 28, 2017 PWM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: sandbox: pwm: Add a basic pwm test

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.

---

 arch/sandbox/dts/test.dts       |  8 +++++
 configs/sandbox_defconfig       |  2 ++
 configs/sandbox_noblk_defconfig |  2 ++
 configs/sandbox_spl_defconfig   |  2 ++
 drivers/pwm/Kconfig             |  8 +++++
 drivers/pwm/Makefile            |  1 +
 drivers/pwm/sandbox_pwm.c       | 75 +++++++++++++++++++++++++++++++++++++++++
 test/dm/Makefile                |  1 +
 test/dm/pwm.c                   | 32 ++++++++++++++++++
 9 files changed, 131 insertions(+)
 create mode 100644 drivers/pwm/sandbox_pwm.c
 create mode 100644 test/dm/pwm.c
arch/sandbox/dts/test.dts +8 -0
index fff175d1b7..50bcdebf74 100644
@@ -272,6 +272,14 @@
 		power-domains = <&pwrdom 2>;
 	};
 
+	pwm {
+		compatible = "sandbox,pwm";
+	};
+
+	pwm2 {
+		compatible = "sandbox,pwm";
+	};
+
 	ram {
 		compatible = "sandbox,ram";
 	};
configs/sandbox_defconfig +2 -0
index 7f3f5ac809..cdd76eb7a6 100644
@@ -172,3 +172,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
configs/sandbox_noblk_defconfig +2 -0
index 3f8e70d523..6a48d81198 100644
@@ -174,3 +174,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
configs/sandbox_spl_defconfig +2 -0
index ade67143b1..9d3e38b7b4 100644
@@ -178,3 +178,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
drivers/pwm/Kconfig +8 -0
index 37ea2b88ea..e827558052 100644
@@ -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
drivers/pwm/Makefile +1 -0
index b037130385..29d59916cb 100644
@@ -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
drivers/pwm/sandbox_pwm.c new file +75 -0

75 lines not on this page · raw message

test/dm/Makefile +1 -0
index 1885e17c38..e956915bc3 100644
@@ -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
test/dm/pwm.c new file +32 -0
new file mode 100644
index 0000000000..7bdc75af09
@@ -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);
Signature · 1 line
2.12.2.762.g0e3151a226-goog
#1 lore raw
Quoted 8 lines · Simon Glass

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.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170428/e9d067da/attachment.sig>