summaryrefslogtreecommitdiff
path: root/drivers/pwm
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-04-17 03:01:11 (GMT)
committerTom Rini <trini@konsulko.com>2017-04-27 20:49:02 (GMT)
commit43b41566f72c3ff1074fe686f37227ebe33e11f9 (patch)
tree8fb90db0bfe55a22257930fdd5512e0e2fc03f89 /drivers/pwm
parent29f089a60547178cd59b5482c57e6a87bdd11089 (diff)
downloadu-boot-fsl-qoriq-43b41566f72c3ff1074fe686f37227ebe33e11f9.tar.xz
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. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/Kconfig8
-rw-r--r--drivers/pwm/Makefile1
-rw-r--r--drivers/pwm/sandbox_pwm.c75
3 files changed, 84 insertions, 0 deletions
diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 37ea2b8..e827558 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -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
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index b037130..29d5991 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -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
index 0000000..c2ce974
--- /dev/null
+++ b/drivers/pwm/sandbox_pwm.c
@@ -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),
+};