All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 36/45] test: panel: Add a test for the panel uclass
Date: Mon,  1 Oct 2018 12:22:40 -0600	[thread overview]
Message-ID: <20181001182249.129565-37-sjg@chromium.org> (raw)
In-Reply-To: <20181001182249.129565-1-sjg@chromium.org>

At present this uclass has no tests. Add a simple one which checks the PWM
configuration, regulator and GPIO.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/dts/sandbox_pmic.dtsi |  2 +-
 arch/sandbox/dts/test.dts          | 20 +++++++++++-
 arch/sandbox/include/asm/test.h    | 15 +++++++++
 drivers/pwm/sandbox_pwm.c          | 25 +++++++++++++++
 test/dm/Makefile                   |  1 +
 test/dm/panel.c                    | 50 ++++++++++++++++++++++++++++++
 6 files changed, 111 insertions(+), 2 deletions(-)
 create mode 100644 test/dm/panel.c

diff --git a/arch/sandbox/dts/sandbox_pmic.dtsi b/arch/sandbox/dts/sandbox_pmic.dtsi
index 403656f25e5..5ecafaab364 100644
--- a/arch/sandbox/dts/sandbox_pmic.dtsi
+++ b/arch/sandbox/dts/sandbox_pmic.dtsi
@@ -60,7 +60,7 @@
 		regulator-max-microvolt = <3300000>;
 	};
 
-	ldo1 {
+	ldo_1: ldo1 {
 		regulator-name = "VDD_EMMC_1.8V";
 		regulator-min-microvolt = <1800000>;
 		regulator-max-microvolt = <1800000>;
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 491f889f3b9..43f79509f75 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -11,6 +11,8 @@
 		eth0 = "/eth at 10002000";
 		eth3 = &eth_3;
 		eth5 = &eth_5;
+		gpio1 = &gpio_a;
+		gpio2 = &gpio_b;
 		i2c0 = "/i2c at 0";
 		mmc0 = "/mmc0";
 		mmc1 = "/mmc1";
@@ -62,6 +64,15 @@
 		reg = <2 1>;
 	};
 
+	backlight: backlight {
+		compatible = "pwm-backlight";
+		enable-gpios = <&gpio_a 1>;
+		power-supply = <&ldo_1>;
+		pwms = <&pwm 0 1000>;
+		default-brightness-level = <5>;
+		brightness-levels = <0 16 32 64 128 170 202 234 255>;
+	};
+
 	bind-test {
 		bind-test-child1 {
 			compatible = "sandbox,phy";
@@ -412,12 +423,14 @@
 		power-domains = <&pwrdom 2>;
 	};
 
-	pwm {
+	pwm: pwm {
 		compatible = "sandbox,pwm";
+		#pwm-cells = <2>;
 	};
 
 	pwm2 {
 		compatible = "sandbox,pwm";
+		#pwm-cells = <2>;
 	};
 
 	ram {
@@ -454,6 +467,11 @@
 		remoteproc-name = "remoteproc-test-dev2";
 	};
 
+	panel {
+		compatible = "simple-panel";
+		backlight = <&backlight 0 100>;
+	};
+
 	smem at 0 {
 		compatible = "sandbox,smem";
 	};
diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index 89f3d90c734..8e60f80ae7f 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -98,4 +98,19 @@ int sandbox_usb_keyb_add_string(struct udevice *dev, const char *str);
  * @buflen:	length of buffer in bytes
  */
 int sandbox_osd_get_mem(struct udevice *dev, u8 *buf, size_t buflen);
+
+/**
+ * sandbox_pwm_get_config() - get the PWM config for a channel
+ *
+ * @dev: Device to check
+ * @channel: Channel number to check
+ * @period_ns: Period of the PWM in nanoseconds
+ * @duty_ns: Current duty cycle of the PWM in nanoseconds
+ * @enable: true if the PWM is enabled
+ * @polarity: true if the PWM polarity is active high
+ * @return 0 if OK, -ENOSPC if the PWM number is invalid
+ */
+int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp,
+			   uint *duty_nsp, bool *enablep, bool *polarityp);
+
 #endif
diff --git a/drivers/pwm/sandbox_pwm.c b/drivers/pwm/sandbox_pwm.c
index 4b50b19c618..28988187e03 100644
--- a/drivers/pwm/sandbox_pwm.c
+++ b/drivers/pwm/sandbox_pwm.c
@@ -14,6 +14,14 @@ enum {
 	NUM_CHANNELS	= 3,
 };
 
+/**
+ * struct sandbox_pwm_chan - a sandbox PWM channel
+ *
+ * @period_ns: Period of the PWM in nanoseconds
+ * @duty_ns: Current duty cycle of the PWM in nanoseconds
+ * @enable: true if the PWM is enabled
+ * @polarity: true if the PWM polarity is active high
+ */
 struct sandbox_pwm_chan {
 	uint period_ns;
 	uint duty_ns;
@@ -25,6 +33,23 @@ struct sandbox_pwm_priv {
 	struct sandbox_pwm_chan chan[NUM_CHANNELS];
 };
 
+int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp,
+			   uint *duty_nsp, bool *enablep, bool *polarityp)
+{
+	struct sandbox_pwm_priv *priv = dev_get_priv(dev);
+	struct sandbox_pwm_chan *chan;
+
+	if (channel >= NUM_CHANNELS)
+		return -ENOSPC;
+	chan = &priv->chan[channel];
+	*period_nsp = chan->period_ns;
+	*duty_nsp = chan->duty_ns;
+	*enablep = chan->enable;
+	*polarityp = chan->polarity;
+
+	return 0;
+}
+
 static int sandbox_pwm_set_config(struct udevice *dev, uint channel,
 				  uint period_ns, uint duty_ns)
 {
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 264f12633ff..2da762ddc8e 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
 obj-y += ofnode.o
 obj-$(CONFIG_OSD) += osd.o
+obj-$(CONFIG_DM_VIDEO) += panel.o
 obj-$(CONFIG_DM_PCI) += pci.o
 obj-$(CONFIG_PHY) += phy.o
 obj-$(CONFIG_POWER_DOMAIN) += power-domain.o
diff --git a/test/dm/panel.c b/test/dm/panel.c
new file mode 100644
index 00000000000..ca032409f8c
--- /dev/null
+++ b/test/dm/panel.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for panel uclass
+ *
+ * Copyright (c) 2018 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <backlight.h>
+#include <dm.h>
+#include <panel.h>
+#include <video.h>
+#include <asm/gpio.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <power/regulator.h>
+
+/* Basic test of the panel uclass */
+static int dm_test_panel(struct unit_test_state *uts)
+{
+	struct udevice *dev, *pwm, *gpio, *reg;
+	uint period_ns;
+	uint duty_ns;
+	bool enable;
+	bool polarity;
+
+	ut_assertok(uclass_first_device_err(UCLASS_PANEL, &dev));
+	ut_assertok(uclass_first_device_err(UCLASS_PWM, &pwm));
+	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
+	ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", &reg));
+	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+					   &enable, &polarity));
+	ut_asserteq(false, enable);
+	ut_asserteq(false, regulator_get_enable(reg));
+
+	ut_assertok(panel_enable_backlight(dev));
+	ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+					   &enable, &polarity));
+	ut_asserteq(1000, period_ns);
+	ut_asserteq(170 * 1000 / 256, duty_ns);
+	ut_asserteq(true, enable);
+	ut_asserteq(false, polarity);
+	ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
+	ut_asserteq(true, regulator_get_enable(reg));
+
+	return 0;
+}
+DM_TEST(dm_test_panel, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.19.0.605.g01d371f741-goog

  parent reply	other threads:[~2018-10-01 18:22 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 18:22 [U-Boot] [PATCH 00/45] Various fixes and improvements Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 01/45] dm: core: Alloc uclass-private data to be cache-aligned Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 02/45] dm: core: Update some functions to use const Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 03/45] dm: core: Add a function to find the first inactive child Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 04/45] dm: core: Update ofnode to read binman-style flash entry Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 05/45] sf: Avoid allocating memory on every read operation Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 06/45] spl: input: Allow input in SPL and TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 07/45] Makefile: Add a warning if SPL/TPL cannot be built Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 08/45] spl: misc: Allow misc drivers in SPL and TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 09/45] blk: Support block drivers in TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 10/45] Kconfig: Convert CONFIG_RTC_MC146818 to Kconfig Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 11/45] rtc: Allow use of RTC in SPL and TPL Simon Glass
2018-10-11 19:21   ` [U-Boot] [U-Boot,11/45] " Heinrich Schuchardt
2018-10-11 19:56     ` Heinrich Schuchardt
2018-10-13  2:46       ` Bin Meng
2018-10-19  3:25         ` Simon Glass
2018-10-19  4:20           ` Bin Meng
2018-10-01 18:22 ` [U-Boot] [PATCH 12/45] fdt: Document the fact that dtc is now built Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 13/45] doc: Update docs for device tree in SPL, TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 14/45] fdt: Allow indicating a node is for U-Boot proper only Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 15/45] tpm: Add support for SPL and TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 16/45] serial: Allow serial to be absent in TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 17/45] fdt: Allow libfdt " Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 18/45] cros: Update cros_ec code to use struct udevice Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 19/45] cros: Adjust board_get_cros_ec_dev() to return a udevice Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 20/45] dm: spi: Add logging of some return values Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 21/45] fdt: Remove fdtdec_decode_region() function Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 22/45] video: Adjust video_clear() to return an error Simon Glass
2018-10-01 19:23   ` Anatolij Gustschin
2018-10-09 23:55   ` sjg at google.com
2018-10-01 18:22 ` [U-Boot] [PATCH 23/45] tpm: Use livetree and allow children Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 24/45] tpm: Tidy up logging in tpm-common.c Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 25/45] tpm: Add a few new commands for v1 Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 26/45] binman: Move to three-digit test-file numbers Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 27/45] binman: Add a test for Intel reference code Simon Glass
2018-10-22 20:54   ` [U-Boot] [U-Boot, " Tom Rini
2018-10-01 18:22 ` [U-Boot] [PATCH 28/45] log: Add comments to the rest of the log categories Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 29/45] malloc_simple: Add logging of allocations Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 30/45] Add a header file for strings Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 31/45] Rename GPT_HEADER_SIGNATURE to avoid conflict Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 32/45] cros: Update ec_commands to latest version Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 33/45] x86: Update mtrr functions to allow leaving cache alone Simon Glass
2018-10-02 13:41   ` Bin Meng
2018-10-09 23:54   ` sjg at google.com
2018-10-01 18:22 ` [U-Boot] [PATCH 34/45] cros_ec: Update cros_ec_read_hash() to specify the image Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 35/45] cros_ec: Add support for v3 messages on LPC Simon Glass
2018-10-01 18:22 ` Simon Glass [this message]
2018-10-01 18:22 ` [U-Boot] [PATCH 37/45] panel: Expand the backlight support Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 38/45] ctags: Minor changes to fix ctags output Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 39/45] fdt: Allow C++ comments in link scripts and DT files Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 40/45] pci: Add a little more debugging to pci_rom Simon Glass
2018-10-02 13:37   ` Bin Meng
2018-10-09 23:54   ` sjg at google.com
2018-10-01 18:22 ` [U-Boot] [PATCH 41/45] sysreset: Tidy up a few comments and logging Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 42/45] sysreset: Add a way to find the last reset Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 43/45] video: at91: Adjust vidconsole_position_cursor() to use char pos Simon Glass
2018-10-01 20:22   ` Anatolij Gustschin
2018-10-02  7:37     ` Eugen Hristev
2018-10-09  3:40       ` Simon Glass
2018-10-09 10:44         ` Eugen.Hristev at microchip.com
2018-10-09 23:54         ` sjg at google.com
2018-10-09  3:41     ` Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 44/45] video: Tidy up a few comments in video.o Simon Glass
2018-10-01 19:25   ` Anatolij Gustschin
2018-10-09 23:54   ` sjg at google.com
2018-10-01 18:22 ` [U-Boot] [PATCH 45/45] dtoc: Fix the value of SetInt() Simon Glass
2018-10-09 23:54 ` sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 42/45] sysreset: Add a way to find the last reset sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 41/45] sysreset: Tidy up a few comments and logging sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 38/45] ctags: Minor changes to fix ctags output sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 39/45] fdt: Allow C++ comments in link scripts and DT files sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 37/45] panel: Expand the backlight support sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 36/45] test: panel: Add a test for the panel uclass sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 35/45] cros_ec: Add support for v3 messages on LPC sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 34/45] cros_ec: Update cros_ec_read_hash() to specify the image sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 32/45] cros: Update ec_commands to latest version sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 31/45] Rename GPT_HEADER_SIGNATURE to avoid conflict sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 30/45] Add a header file for strings sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 29/45] malloc_simple: Add logging of allocations sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 28/45] log: Add comments to the rest of the log categories sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 27/45] binman: Add a test for Intel reference code sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 26/45] binman: Move to three-digit test-file numbers sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 25/45] tpm: Add a few new commands for v1 sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 24/45] tpm: Tidy up logging in tpm-common.c sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 23/45] tpm: Use livetree and allow children sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 21/45] fdt: Remove fdtdec_decode_region() function sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 20/45] dm: spi: Add logging of some return values sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 19/45] cros: Adjust board_get_cros_ec_dev() to return a udevice sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 18/45] cros: Update cros_ec code to use struct udevice sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 17/45] fdt: Allow libfdt in TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 16/45] serial: Allow serial to be absent " sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 15/45] tpm: Add support for SPL and TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 14/45] fdt: Allow indicating a node is for U-Boot proper only sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 13/45] doc: Update docs for device tree in SPL, TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 12/45] fdt: Document the fact that dtc is now built sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 11/45] rtc: Allow use of RTC in SPL and TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 10/45] Kconfig: Convert CONFIG_RTC_MC146818 to Kconfig sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 09/45] blk: Support block drivers in TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 08/45] spl: misc: Allow misc drivers in SPL and TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 07/45] Makefile: Add a warning if SPL/TPL cannot be built sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 06/45] spl: input: Allow input in SPL and TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 05/45] sf: Avoid allocating memory on every read operation sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 04/45] dm: core: Update ofnode to read binman-style flash entry sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 03/45] dm: core: Add a function to find the first inactive child sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 02/45] dm: core: Update some functions to use const sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 01/45] dm: core: Alloc uclass-private data to be cache-aligned sjg at google.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181001182249.129565-37-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.