[U-Boot] [PATCH v4 4/4] dm: sanbox: pwm: add test for pwm_set_invert()

Kever Yang kever.yang at rock-chips.com
Mon Apr 24 02:27:52 UTC 2017


Add test case for new interface set_invert().

Signed-off-by: Kever Yang <kever.yang at rock-chips.com>
Acked-by: Simon Glass <sjg at chromium.org>
---

Changes in v4: None
Changes in v3:
- add sanbox test

Changes in v2: None

 drivers/pwm/sandbox_pwm.c | 16 ++++++++++++++++
 test/dm/pwm.c             |  1 +
 2 files changed, 17 insertions(+)

diff --git a/drivers/pwm/sandbox_pwm.c b/drivers/pwm/sandbox_pwm.c
index c2ce974..50a35d9 100644
--- a/drivers/pwm/sandbox_pwm.c
+++ b/drivers/pwm/sandbox_pwm.c
@@ -21,6 +21,7 @@ struct sandbox_pwm_chan {
 	uint period_ns;
 	uint duty_ns;
 	bool enable;
+	bool polarity;
 };
 
 struct sandbox_pwm_priv {
@@ -56,9 +57,24 @@ static int sandbox_pwm_set_enable(struct udevice *dev, uint channel,
 	return 0;
 }
 
+static int sandbox_pwm_set_invert(struct udevice *dev, uint channel,
+				  bool polarity);
+{
+	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->polarity = polarity;
+
+	return 0;
+}
+
 static const struct pwm_ops sandbox_pwm_ops = {
 	.set_config	= sandbox_pwm_set_config,
 	.set_enable	= sandbox_pwm_set_enable,
+	.set_invert	= sandbox_pwm_set_invert,
 };
 
 static const struct udevice_id sandbox_pwm_ids[] = {
diff --git a/test/dm/pwm.c b/test/dm/pwm.c
index 7bdc75a..f1e38c7 100644
--- a/test/dm/pwm.c
+++ b/test/dm/pwm.c
@@ -23,6 +23,7 @@ static int dm_test_pwm_base(struct unit_test_state *uts)
 	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(pwm_set_invert(dev, 0, true));
 
 	ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
 	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 2, &dev));
-- 
1.9.1



More information about the U-Boot mailing list