linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: <linux-kernel@vger.kernel.org>
Cc: <kernel@axis.com>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	<devicetree@vger.kernel.org>, <linux-um@lists.infradead.org>,
	<shuah@kernel.org>, <brendanhiggins@google.com>,
	<linux-kselftest@vger.kernel.org>, <jic23@kernel.org>,
	<linux-iio@vger.kernel.org>, <lgirdwood@gmail.com>,
	<broonie@kernel.org>, <a.zummo@towertech.it>,
	<alexandre.belloni@bootlin.com>, <linux-rtc@vger.kernel.org>,
	<corbet@lwn.net>, <linux-doc@vger.kernel.org>
Subject: [RFC v1 09/10] regulator: tps62864: add roadtest
Date: Fri, 11 Mar 2022 17:24:44 +0100	[thread overview]
Message-ID: <20220311162445.346685-10-vincent.whitchurch@axis.com> (raw)
In-Reply-To: <20220311162445.346685-1-vincent.whitchurch@axis.com>

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@axis.com/

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

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 .../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


  parent reply	other threads:[~2022-03-11 16:26 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 16:24 [RFC v1 00/10] roadtest: a driver testing framework Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 01/10] roadtest: import libvhost-user from QEMU Vincent Whitchurch
2022-03-24 13:00   ` Johannes Berg
2022-04-05 13:54     ` Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 02/10] roadtest: add C backend Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 03/10] roadtest: add framework Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 04/10] roadtest: add base config Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 05/10] roadtest: add build files Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 06/10] roadtest: add documentation Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 07/10] iio: light: opt3001: add roadtest Vincent Whitchurch
2022-03-14 23:11   ` Brendan Higgins
2022-03-18 15:49     ` Vincent Whitchurch
2022-03-18 20:09       ` Johannes Berg
2022-03-29 14:43         ` Vincent Whitchurch
2022-03-29 14:50           ` Johannes Berg
2022-03-29 14:52             ` Johannes Berg
2022-03-11 16:24 ` [RFC v1 08/10] iio: light: vcnl4000: " Vincent Whitchurch
2022-03-20 17:02   ` Jonathan Cameron
2022-04-05 13:48     ` Vincent Whitchurch
2022-04-06 13:08       ` Jonathan Cameron
2022-04-14 10:20         ` Vincent Whitchurch
2022-03-11 16:24 ` Vincent Whitchurch [this message]
2022-03-11 18:06   ` [RFC v1 09/10] regulator: tps62864: " Mark Brown
2022-03-17 15:13     ` Vincent Whitchurch
2022-03-17 17:53       ` Mark Brown
2022-04-05 14:02         ` Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 10/10] rtc: pcf8563: " Vincent Whitchurch
2022-03-14 22:24 ` [RFC v1 00/10] roadtest: a driver testing framework Brendan Higgins
2022-03-17 16:09   ` Vincent Whitchurch
2022-04-18 19:44 ` Jonathan Cameron

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=20220311162445.346685-10-vincent.whitchurch@axis.com \
    --to=vincent.whitchurch@axis.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=brendanhiggins@google.com \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=kernel@axis.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=shuah@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).