[RFC v1 09/10] regulator: tps62864: add roadtest

From: Vincent Whitchurch
Date: Fri Mar 11 2022 - 11:26:11 EST


Add a roadtest for the recently-added tps62864 regulator driver. It
tests voltage setting, mode setting, as well as devicetree mode
translation. It uses the recently-added devicetree support in
regulator-virtual-consumer.

All the variants supported by the driver have identical register
interfaces so only one test/model is added.

It requires the following patches which are, as of writing, not in
mainline:

- regulator: Add support for TPS6286x
https://lore.kernel.org/lkml/20220204155241.576342-3-vincent.whitchurch@xxxxxxxx/

- regulator: virtual: add devicetree support
https://lore.kernel.org/lkml/20220301111831.3742383-4-vincent.whitchurch@xxxxxxxx/

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@xxxxxxxx>
---
.../roadtest/tests/regulator/__init__.py | 0
.../roadtest/roadtest/tests/regulator/config | 4 +
.../roadtest/tests/regulator/test_tps62864.py | 187 ++++++++++++++++++
3 files changed, 191 insertions(+)
create mode 100644 tools/testing/roadtest/roadtest/tests/regulator/__init__.py
create mode 100644 tools/testing/roadtest/roadtest/tests/regulator/config
create mode 100644 tools/testing/roadtest/roadtest/tests/regulator/test_tps62864.py

diff --git a/tools/testing/roadtest/roadtest/tests/regulator/__init__.py b/tools/testing/roadtest/roadtest/tests/regulator/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/tools/testing/roadtest/roadtest/tests/regulator/config b/tools/testing/roadtest/roadtest/tests/regulator/config
new file mode 100644
index 000000000000..b2b503947e70
--- /dev/null
+++ b/tools/testing/roadtest/roadtest/tests/regulator/config
@@ -0,0 +1,4 @@
+CONFIG_REGULATOR=y
+CONFIG_REGULATOR_DEBUG=y
+CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
+CONFIG_REGULATOR_TPS6286X=m
diff --git a/tools/testing/roadtest/roadtest/tests/regulator/test_tps62864.py b/tools/testing/roadtest/roadtest/tests/regulator/test_tps62864.py
new file mode 100644
index 000000000000..f7db4293d840
--- /dev/null
+++ b/tools/testing/roadtest/roadtest/tests/regulator/test_tps62864.py
@@ -0,0 +1,187 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright Axis Communications AB
+
+from typing import Any, Final
+
+from roadtest.backend.i2c import SimpleSMBusModel
+from roadtest.core.devicetree import DtFragment, DtVar
+from roadtest.core.hardware import Hardware
+from roadtest.core.modules import insmod, rmmod
+from roadtest.core.suite import UMLTestCase
+from roadtest.core.sysfs import (
+ I2CDriver,
+ PlatformDriver,
+ read_str,
+ write_int,
+ write_str,
+)
+
+REG_VOUT1: Final = 0x01
+REG_VOUT2: Final = 0x02
+REG_CONTROL: Final = 0x03
+REG_STATUS: Final = 0x05
+
+
+class TPS62864(SimpleSMBusModel):
+ def __init__(self, **kwargs: Any) -> None:
+ super().__init__(
+ # From datasheet section 8.6 Register map
+ # XXX does not match reality -- recheck
+ regs={
+ REG_VOUT1: 0x64,
+ REG_VOUT2: 0x64,
+ REG_CONTROL: 0x00,
+ REG_STATUS: 0x00,
+ },
+ regbytes=1,
+ **kwargs,
+ )
+
+
+class TestTPS62864(UMLTestCase):
+ dts = DtFragment(
+ src="""
+#include <dt-bindings/regulator/ti,tps62864.h>
+
+&i2c {
+ regulator@$normal$ {
+ compatible = "ti,tps62864";
+ reg = <0x$normal$>;
+
+ regulators {
+ tps62864_normal: SW {
+ regulator-name = "+0.85V";
+ regulator-min-microvolt = <400000>;
+ regulator-max-microvolt = <1675000>;
+ regulator-allowed-modes = <TPS62864_MODE_NORMAL TPS62864_MODE_FPWM>;
+ };
+ };
+ };
+
+ regulator@$fpwm$ {
+ compatible = "ti,tps62864";
+ reg = <0x$fpwm$>;
+
+ regulators {
+ tps62864_fpwm: SW {
+ regulator-name = "+0.85V";
+ regulator-min-microvolt = <400000>;
+ regulator-max-microvolt = <1675000>;
+ regulator-initial-mode = <TPS62864_MODE_FPWM>;
+ };
+ };
+ };
+};
+
+/ {
+ tps62864_normal_consumer {
+ compatible = "regulator-virtual-consumer";
+ default-supply = <&tps62864_normal>;
+ };
+
+ tps62864_fpwm_consumer {
+ compatible = "regulator-virtual-consumer";
+ default-supply = <&tps62864_fpwm>;
+ };
+};
+ """,
+ variables={
+ "normal": DtVar.I2C_ADDR,
+ "fpwm": DtVar.I2C_ADDR,
+ },
+ )
+
+ @classmethod
+ def setUpClass(cls) -> None:
+ insmod("tps6286x-regulator")
+
+ @classmethod
+ def tearDownClass(cls) -> None:
+ rmmod("tps6286x-regulator")
+
+ def setUp(self) -> None:
+ self.driver = I2CDriver("tps6286x")
+ self.hw = Hardware("i2c")
+ self.hw.load_model(TPS62864)
+
+ def tearDown(self) -> None:
+ self.hw.close()
+
+ def test_voltage(self) -> None:
+ with (
+ self.driver.bind(self.dts["normal"]),
+ PlatformDriver("reg-virt-consumer").bind(
+ "tps62864_normal_consumer"
+ ) as consumerdev,
+ ):
+ maxfile = consumerdev.path / "max_microvolts"
+ minfile = consumerdev.path / "min_microvolts"
+
+ write_int(maxfile, 1675000)
+ write_int(minfile, 800000)
+
+ mock = self.hw.update_mock()
+ mock.assert_reg_write_once(self, REG_CONTROL, 1 << 5)
+ mock.assert_reg_write_once(self, REG_VOUT1, 0x50)
+ mock.reset_mock()
+
+ mV = 1000
+ data = [
+ (400 * mV, 0x00),
+ (900 * mV, 0x64),
+ (1675 * mV, 0xFF),
+ ]
+
+ for voltage, val in data:
+ write_int(minfile, voltage)
+ mock = self.hw.update_mock()
+ mock.assert_reg_write_once(self, REG_VOUT1, val)
+ mock.reset_mock()
+
+ write_int(minfile, 0)
+ mock = self.hw.update_mock()
+ mock.assert_reg_write_once(self, REG_CONTROL, 0)
+ mock.reset_mock()
+
+ def test_modes(self) -> None:
+ with (
+ self.driver.bind(self.dts["normal"]),
+ PlatformDriver("reg-virt-consumer").bind(
+ "tps62864_normal_consumer"
+ ) as consumerdev,
+ ):
+ modefile = consumerdev.path / "mode"
+ write_str(modefile, "fast")
+
+ mock = self.hw.update_mock()
+ mock.assert_reg_write_once(self, REG_CONTROL, 1 << 4)
+ mock.reset_mock()
+
+ write_str(modefile, "normal")
+ mock = self.hw.update_mock()
+ mock.assert_reg_write_once(self, REG_CONTROL, 0)
+ mock.reset_mock()
+
+ def test_dt_force_pwm(self) -> None:
+ with (
+ self.driver.bind(self.dts["fpwm"]),
+ PlatformDriver("reg-virt-consumer").bind(
+ "tps62864_fpwm_consumer"
+ ) as consumerdev,
+ ):
+ mock = self.hw.update_mock()
+ mock.assert_reg_write_once(self, REG_CONTROL, 1 << 4)
+ mock.reset_mock()
+
+ modefile = consumerdev.path / "mode"
+ self.assertEquals(read_str(modefile), "fast")
+
+ maxfile = consumerdev.path / "max_microvolts"
+ minfile = consumerdev.path / "min_microvolts"
+
+ write_int(maxfile, 1675000)
+ write_int(minfile, 800000)
+
+ mock = self.hw.update_mock()
+ mock.assert_reg_write_once(self, REG_CONTROL, 1 << 5 | 1 << 4)
+ mock.reset_mock()
--
2.34.1