Skip to contentSkip to conversation

sandbox: cros-ec: Add tests for the Chrome OS PWM driver

PATCH Superseded Alper Nebi Yasak 2 participants 3 messages May 19, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sandbox: cros-ec: Add tests for the Chrome OS PWM driver

This patch adds a limited pulse-width modulator to sandbox's Chrome OS Embedded Controller emulation. The emulated PWM device supports multiple channels but can only set a duty cycle for each, as the actual EC doesn't expose any functionality or information other than that. Though the EC supports specifying the PWM channel by its type (e.g. display backlight, keyboard backlight), this is not implemented in the emulation as nothing in U-Boot uses this type specification.

This emulated PWM device is then used to test the Chrome OS PWM driver in sandbox. Adding the required device node to the sandbox test device-tree unfortunately makes it the first PWM device, so this also touches some other tests to make sure they still use the sandbox PWM.

---
This depends on a small fix [1] for cros-ec-pwm which otherwise fails to build.

[1] https://patchwork.ozlabs.org/project/uboot/patch/20210514134840.19380-1-alpernebiyasak at gmail.com/

Changes in v2:
- Try to clarify commit message

v1: https://patchwork.ozlabs.org/project/uboot/patch/20210516154144.141945-1-alpernebiyasak at gmail.com/

 arch/sandbox/dts/test.dts          |  6 +++
 arch/sandbox/include/asm/test.h    | 10 +++++
 configs/sandbox64_defconfig        |  1 +
 configs/sandbox_defconfig          |  1 +
 configs/sandbox_flattree_defconfig |  1 +
 configs/sandbox_noinst_defconfig   |  1 +
 configs/sandbox_spl_defconfig      |  1 +
 drivers/misc/cros_ec_sandbox.c     | 47 +++++++++++++++++++++++
 test/cmd/pwm.c                     | 32 +++++++++++++++-
 test/dm/Makefile                   |  1 +
 test/dm/cros_ec_pwm.c              | 60 ++++++++++++++++++++++++++++++
 test/dm/panel.c                    |  2 +-
 test/dm/pwm.c                      |  6 ++-
 13 files changed, 164 insertions(+), 5 deletions(-)
 create mode 100644 test/dm/cros_ec_pwm.c
arch/sandbox/dts/test.dts +6 -0
index 5ca3bc502a43..c684ff0b6db8 100644
@@ -139,6 +139,12 @@
 				size = <0x10000>;
 			};
 		};
+
+		cros_ec_pwm: cros-ec-pwm {
+			compatible = "google,cros-ec-pwm";
+			#pwm-cells = <1>;
+		};
+
 	};
 
 	dsi_host: dsi_host {
arch/sandbox/include/asm/test.h +10 -0
index 1cb960ac240d..dab1a4ea01b3 100644
@@ -275,4 +275,14 @@ void sandbox_set_enable_memio(bool enable);
  */
 void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags);
 
+/**
+ * sandbox_cros_ec_get_pwm_duty() - Get EC PWM config for testing purposes
+ *
+ * @dev: Device to check
+ * @index: PWM channel index
+ * @duty: Current duty cycle in 0..EC_PWM_MAX_DUTY range.
+ * @return 0 if OK, -ENOSPC if the PWM number is invalid
+ */
+int sandbox_cros_ec_get_pwm_duty(struct udevice *dev, uint index, uint *duty);
+
 #endif
configs/sandbox64_defconfig +1 -0
index 9a373bab6fe3..188ce05cfbf1 100644
@@ -186,6 +186,7 @@ CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_PWM=y
+CONFIG_PWM_CROS_EC=y
 CONFIG_PWM_SANDBOX=y
 CONFIG_RAM=y
 CONFIG_REMOTEPROC_SANDBOX=y
configs/sandbox_defconfig +1 -0
index bdbf714e2bd9..6c7a2f02718b 100644
@@ -223,6 +223,7 @@ CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_REGULATOR_SCMI=y
 CONFIG_DM_PWM=y
+CONFIG_PWM_CROS_EC=y
 CONFIG_PWM_SANDBOX=y
 CONFIG_RAM=y
 CONFIG_REMOTEPROC_SANDBOX=y
configs/sandbox_flattree_defconfig +1 -0
index 853c9440ea02..0844d6ec23eb 100644
@@ -163,6 +163,7 @@ CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_PWM=y
+CONFIG_PWM_CROS_EC=y
 CONFIG_PWM_SANDBOX=y
 CONFIG_RAM=y
 CONFIG_REMOTEPROC_SANDBOX=y
configs/sandbox_noinst_defconfig +1 -0
index c7fc98b5569a..629bde1f7ed6 100644
@@ -181,6 +181,7 @@ CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_PWM=y
+CONFIG_PWM_CROS_EC=y
 CONFIG_PWM_SANDBOX=y
 CONFIG_RAM=y
 CONFIG_REMOTEPROC_SANDBOX=y
configs/sandbox_spl_defconfig +1 -0
index 87223a54d873..aa629e231753 100644
@@ -183,6 +183,7 @@ CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
 CONFIG_DM_PWM=y
+CONFIG_PWM_CROS_EC=y
 CONFIG_PWM_SANDBOX=y
 CONFIG_RAM=y
 CONFIG_REMOTEPROC_SANDBOX=y
drivers/misc/cros_ec_sandbox.c +47 -0

83 lines not on this page · raw message

test/cmd/pwm.c +30 -2
index 5343af83fa34..2fc0b5e40704 100644
@@ -18,16 +18,20 @@ static int dm_test_pwm_cmd(struct unit_test_state *uts)
 {
 	struct udevice *dev;
 
+	/* cros-ec-pwm */
 	ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
 	ut_assertnonnull(dev);
 
 	ut_assertok(console_record_reset_enable());
 
 	/* pwm <invert> <pwm_dev_num> <channel> <polarity> */
-	ut_assertok(run_command("pwm invert 0 0 1", 0));
+	/* cros-ec-pwm doesn't support invert */
+	ut_asserteq(1, run_command("pwm invert 0 0 1", 0));
+	ut_assert_nextline("error(-38)")
 	ut_assert_console_end();
 
-	ut_assertok(run_command("pwm invert 0 0 0", 0));
+	ut_asserteq(1, run_command("pwm invert 0 0 0", 0));
+	ut_assert_nextline("error(-38)")
 	ut_assert_console_end();
 
 	/* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
@@ -41,6 +45,30 @@ static int dm_test_pwm_cmd(struct unit_test_state *uts)
 	ut_assertok(run_command("pwm disable 0 0", 0));
 	ut_assert_console_end();
 
+	/* sandbox-pwm */
+	ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
+	ut_assertnonnull(dev);
+
+	ut_assertok(console_record_reset_enable());
+
+	/* pwm <invert> <pwm_dev_num> <channel> <polarity> */
+	ut_assertok(run_command("pwm invert 1 0 1", 0));
+	ut_assert_console_end();
+
+	ut_assertok(run_command("pwm invert 1 0 0", 0));
+	ut_assert_console_end();
+
+	/* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
+	ut_assertok(run_command("pwm config 1 0 10 50", 0));
+	ut_assert_console_end();
+
+	/* pwm <enable/disable> <pwm_dev_num> <channel> */
+	ut_assertok(run_command("pwm enable 1 0", 0));
+	ut_assert_console_end();
+
+	ut_assertok(run_command("pwm disable 1 0", 0));
+	ut_assert_console_end();
+
 	return 0;
 }
 
test/dm/Makefile +1 -0
index c9644617a1fe..9ef9171a1cbc 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o
 obj-$(CONFIG_CLK) += clk.o clk_ccf.o
 obj-$(CONFIG_CPU) += cpu.o
 obj-$(CONFIG_CROS_EC) += cros_ec.o
+obj-$(CONFIG_PWM_CROS_EC) += cros_ec_pwm.o
 obj-$(CONFIG_DEVRES) += devres.o
 obj-$(CONFIG_DMA) += dma.o
 obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
test/dm/cros_ec_pwm.c new file +60 -0

60 lines not on this page · raw message

test/dm/panel.c +1 -1
index 49f5ac7169d3..4d435a0d255c 100644
@@ -28,7 +28,7 @@ static int dm_test_panel(struct unit_test_state *uts)
 	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_by_name(UCLASS_PWM, "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,
test/dm/pwm.c +4 -2
index b624cf3d6558..dff626c771ac 100644
@@ -20,7 +20,7 @@ static int dm_test_pwm_base(struct unit_test_state *uts)
 	bool enable;
 	bool polarity;
 
-	ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
+	ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev));
 	ut_assertnonnull(dev);
 	ut_assertok(pwm_set_config(dev, 0, 100, 50));
 	ut_assertok(pwm_set_enable(dev, 0, true));
@@ -35,8 +35,10 @@ static int dm_test_pwm_base(struct unit_test_state *uts)
 	ut_asserteq(period_ns, 4096);
 	ut_asserteq(duty_ns, 50 * 4096 / 100);
 
+	ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
 	ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
-	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 2, &dev));
+	ut_assertok(uclass_get_device(UCLASS_PWM, 2, &dev));
+	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 3, &dev));
 
 	return 0;
 }
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/1 sandbox: cros-ec: Add tests for the Chrome OS PWM driver

Hi Alpher,

Quoted 10 lines · Alper Nebi Yasak

This patch adds a limited pulse-width modulator to sandbox's Chrome OS Embedded Controller emulation. The emulated PWM device supports multiple channels but can only set a duty cycle for each, as the actual EC doesn't expose any functionality or information other than that. Though the EC supports specifying the PWM channel by its type (e.g. display backlight, keyboard backlight), this is not implemented in the emulation as nothing in U-Boot uses this type specification.

This emulated PWM device is then used to test the Chrome OS PWM driver

Typically we use "Chromium OS" for open-source software.

Quoted 16 lines

in sandbox. Adding the required device node to the sandbox test device-tree unfortunately makes it the first PWM device, so this also touches some other tests to make sure they still use the sandbox PWM.

---
This depends on a small fix [1] for cros-ec-pwm which otherwise fails to build.

[1] https://patchwork.ozlabs.org/project/uboot/patch/20210514134840.19380-1-alpernebiyasak at gmail.com/

Changes in v2:
- Try to clarify commit message

v1: https://patchwork.ozlabs.org/project/uboot/patch/20210516154144.141945-1-alpernebiyasak at gmail.com/

Quoted 15 lines
 arch/sandbox/dts/test.dts          |  6 +++
 arch/sandbox/include/asm/test.h    | 10 +++++
 configs/sandbox64_defconfig        |  1 +
 configs/sandbox_defconfig          |  1 +
 configs/sandbox_flattree_defconfig |  1 +
 configs/sandbox_noinst_defconfig   |  1 +
 configs/sandbox_spl_defconfig      |  1 +
 drivers/misc/cros_ec_sandbox.c     | 47 +++++++++++++++++++++++
 test/cmd/pwm.c                     | 32 +++++++++++++++-
 test/dm/Makefile                   |  1 +
 test/dm/cros_ec_pwm.c              | 60 ++++++++++++++++++++++++++++++
 test/dm/panel.c                    |  2 +-
 test/dm/pwm.c                      |  6 ++-
 13 files changed, 164 insertions(+), 5 deletions(-)
 create mode 100644 test/dm/cros_ec_pwm.c
#2 lore raw

PATCH v2 1/1 sandbox: cros-ec: Add tests for the Chrome OS PWM driver

Quoted 12 lines · Simon Glass

Hi Alpher,

Quoted 9 lines · Alper Nebi Yasak

This patch adds a limited pulse-width modulator to sandbox's Chrome OS Embedded Controller emulation. The emulated PWM device supports multiple channels but can only set a duty cycle for each, as the actual EC doesn't expose any functionality or information other than that. Though the EC supports specifying the PWM channel by its type (e.g. display backlight, keyboard backlight), this is not implemented in the emulation as nothing in U-Boot uses this type specification.

Quoted 3 lines
Quoted 1 line

This emulated PWM device is then used to test the Chrome OS PWM driver

Typically we use "Chromium OS" for open-source software.

OK. I'll switch to that instead and send a v3 shortly.

(I also noticed that I forgot "EC" in the subject line...)

Quoted 34 lines
Quoted 16 lines

in sandbox. Adding the required device node to the sandbox test device-tree unfortunately makes it the first PWM device, so this also touches some other tests to make sure they still use the sandbox PWM.

---
This depends on a small fix [1] for cros-ec-pwm which otherwise fails to build.

[1] https://patchwork.ozlabs.org/project/uboot/patch/20210514134840.19380-1-alpernebiyasak at gmail.com/

Changes in v2:
- Try to clarify commit message

v1: https://patchwork.ozlabs.org/project/uboot/patch/20210516154144.141945-1-alpernebiyasak at gmail.com/

Quoted 15 lines
 arch/sandbox/dts/test.dts          |  6 +++
 arch/sandbox/include/asm/test.h    | 10 +++++
 configs/sandbox64_defconfig        |  1 +
 configs/sandbox_defconfig          |  1 +
 configs/sandbox_flattree_defconfig |  1 +
 configs/sandbox_noinst_defconfig   |  1 +
 configs/sandbox_spl_defconfig      |  1 +
 drivers/misc/cros_ec_sandbox.c     | 47 +++++++++++++++++++++++
 test/cmd/pwm.c                     | 32 +++++++++++++++-
 test/dm/Makefile                   |  1 +
 test/dm/cros_ec_pwm.c              | 60 ++++++++++++++++++++++++++++++
 test/dm/panel.c                    |  2 +-
 test/dm/pwm.c                      |  6 ++-
 13 files changed, 164 insertions(+), 5 deletions(-)
 create mode 100644 test/dm/cros_ec_pwm.c