All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Jacques Hiblot <jjhiblot@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 04/11] dm: test: Add tests for the generic PHY uclass
Date: Fri, 14 Apr 2017 13:08:02 +0200	[thread overview]
Message-ID: <1492168089-15437-5-git-send-email-jjhiblot@ti.com> (raw)
In-Reply-To: <1492168089-15437-1-git-send-email-jjhiblot@ti.com>

Those tests check:
- the ability for a phy-user to get a phy device a reference in the
  device-tree
- the ability to perform operations on the phy (init,deinit,on,off)
- the behavior of the uclass when optional operations are not implemented

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---
 arch/sandbox/dts/test.dts       |  9 +++++
 configs/sandbox_defconfig       |  2 +
 configs/sandbox_noblk_defconfig |  2 +
 configs/sandbox_spl_defconfig   |  3 ++
 drivers/phy/Kconfig             |  9 +++++
 drivers/phy/Makefile            |  1 +
 drivers/phy/sandbox-phy.c       | 78 ++++++++++++++++++++++++++++++++++++
 test/dm/Makefile                |  1 +
 test/dm/generic_phy.c           | 89 +++++++++++++++++++++++++++++++++++++++++
 9 files changed, 194 insertions(+)
 create mode 100644 drivers/phy/sandbox-phy.c
 create mode 100644 test/dm/generic_phy.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index fff175d..918c899 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -59,6 +59,15 @@
 		ping-add = <3>;
 	};
 
+	gen_phy: gen_phy {
+		compatible = "sandbox,phy";
+	};
+
+	gen_phy_user: gen_phy_user {
+		compatible = "simple-bus";
+		phy = <&gen_phy>;
+	};
+
 	some-bus {
 		#address-cells = <1>;
 		#size-cells = <0>;
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 7f3f5ac..42116cf 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -164,6 +164,8 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
diff --git a/configs/sandbox_noblk_defconfig b/configs/sandbox_noblk_defconfig
index 3f8e70d..7a5cd4b 100644
--- a/configs/sandbox_noblk_defconfig
+++ b/configs/sandbox_noblk_defconfig
@@ -166,6 +166,8 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig
index ade6714..9b4cf39 100644
--- a/configs/sandbox_spl_defconfig
+++ b/configs/sandbox_spl_defconfig
@@ -170,6 +170,9 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_SPL_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index d66c9e3..032b932 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -29,4 +29,13 @@ config SPL_GENERIC_PHY
 	  compatible as possible with the equivalent framework found in the
 	  linux kernel.
 
+config PHY_SANDBOX
+	bool "Sandbox PHY support"
+	depends on SANDBOX
+	depends on GENERIC_PHY
+	help
+	  This select a dummy sandbox PHY driver. It used only to implement
+	  unit tests for the generic phy framework
+
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index b29a8b9..0125844 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy-uclass.o
+obj-$(CONFIG_PHY_SANDBOX) += sandbox-phy.o
 
diff --git a/drivers/phy/sandbox-phy.c b/drivers/phy/sandbox-phy.c
new file mode 100644
index 0000000..1c60308
--- /dev/null
+++ b/drivers/phy/sandbox-phy.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot  <jjhiblot@ti.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <generic-phy.h>
+
+struct sandbox_phy_priv {
+	int initialized;
+	int on;
+};
+
+static int sandbox_phy_power_on(struct udevice *dev)
+{
+	struct sandbox_phy_priv *priv = dev_get_priv(dev);
+	if (!priv->initialized)
+		return -EIO;
+	priv->on = 1;
+	return 0;
+}
+
+static int sandbox_phy_power_off(struct udevice *dev)
+{
+	struct sandbox_phy_priv *priv = dev_get_priv(dev);
+	if (!priv->initialized)
+		return -EIO;
+	priv->on = 0;
+	return 0;
+}
+
+static int sandbox_phy_init(struct udevice *dev)
+{
+	struct sandbox_phy_priv *priv = dev_get_priv(dev);
+	priv->initialized = 1;
+	priv->on = 0;
+	return 0;
+}
+
+static int sandbox_phy_exit(struct udevice *dev)
+{
+	struct sandbox_phy_priv *priv = dev_get_priv(dev);
+	priv->initialized = 0;
+	priv->on = 0;
+	return 0;
+}
+
+static int sandbox_phy_probe(struct udevice *dev)
+{
+	struct sandbox_phy_priv *priv = dev_get_priv(dev);
+	priv->initialized = 0;
+	priv->on = 0;
+	return 0;
+}
+
+static struct generic_phy_ops sandbox_phy_ops = {
+	.power_on = sandbox_phy_power_on,
+	.power_off = sandbox_phy_power_off,
+	.init = sandbox_phy_init,
+	.exit = sandbox_phy_exit,
+};
+
+static const struct udevice_id sandbox_phy_ids[] = {
+	{ .compatible = "sandbox,phy" },
+	{ }
+};
+
+U_BOOT_DRIVER(phy_sandbox) = {
+	.name		= "phy_sandbox",
+	.id		= UCLASS_PHY,
+	.of_match	= sandbox_phy_ids,
+	.ops		= &sandbox_phy_ops,
+	.probe		= sandbox_phy_probe,
+	.priv_auto_alloc_size = sizeof(struct sandbox_phy_priv),
+};
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 1885e17..e2b7d43 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -41,4 +41,5 @@ obj-$(CONFIG_TIMER) += timer.o
 obj-$(CONFIG_DM_VIDEO) += video.o
 obj-$(CONFIG_ADC) += adc.o
 obj-$(CONFIG_SPMI) += spmi.o
+obj-$(CONFIG_GENERIC_PHY) += generic_phy.o
 endif
diff --git a/test/dm/generic_phy.c b/test/dm/generic_phy.c
new file mode 100644
index 0000000..08b862a
--- /dev/null
+++ b/test/dm/generic_phy.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot  <jjhiblot@ti.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <generic-phy.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Base test of the phy uclass */
+static int dm_test_phy_base(struct unit_test_state *uts)
+{
+	struct udevice *dev_method1;
+	struct udevice *dev_method2;
+	struct udevice *parent;
+
+
+	/* Get the device using the phy device*/
+	ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
+					      "gen_phy_user", &parent));
+	/* Get the phy device with std uclass function */
+	ut_assertok(uclass_get_device_by_name(UCLASS_PHY, "gen_phy",
+					      &dev_method1));
+
+	/*
+	 * Get the phy device from user device and compare with the one
+	 * obtained with the previous method.
+	 */
+	dev_method2 = dm_generic_phy_get(parent, "phy");
+	ut_assertnonnull(dev_method2);
+	ut_assertok_ptr(dev_method2);
+	ut_asserteq_ptr(dev_method1, dev_method2);
+
+	/* Try to get a non-existing phy */
+	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 1, &dev_method2));
+	dev_method2 = dm_generic_phy_get(parent, "phy_not_existing");
+	ut_assert(IS_ERR_OR_NULL(dev_method2));
+
+	return 0;
+}
+DM_TEST(dm_test_phy_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test of the phy uclass using the sandbox phy driver operations */
+static int dm_test_phy_ops(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	struct udevice *parent;
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
+					      "gen_phy_user", &parent));
+	dev = dm_generic_phy_get(parent, "phy");
+	ut_assertnonnull(dev);
+	ut_assertok_ptr(dev);
+
+	/* test normal operations */
+	ut_assertok(generic_phy_init(dev));
+	ut_assertok(generic_phy_power_on(dev));
+	ut_assertok(generic_phy_power_off(dev));
+
+	/*
+	 * test operations after exit().
+	 * The sandbox phy driver does not allow it.
+	 */
+	ut_assertok(generic_phy_exit(dev));
+	ut_assert(generic_phy_power_on(dev) != 0);
+	ut_assert(generic_phy_power_off(dev) != 0);
+
+	/*
+	 * test normal operations again (after re-init)
+	 */
+	ut_assertok(generic_phy_init(dev));
+	ut_assertok(generic_phy_power_on(dev));
+	ut_assertok(generic_phy_power_off(dev));
+
+	/*
+	 * test calling unimplemented feature.
+	 * The call is expected to succeed
+	 */
+	ut_assertok(generic_phy_reset(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_phy_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
1.9.1

  parent reply	other threads:[~2017-04-14 11:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-14 11:07 [U-Boot] [PATCH 00/11] OMAP: Move SATA to use block driver model Jean-Jacques Hiblot
2017-04-14 11:07 ` [U-Boot] [PATCH 01/11] arm: omap: sata: move enable sata clocks to enable_basic_clocks() Jean-Jacques Hiblot
2017-04-14 11:08 ` [U-Boot] [PATCH 02/11] arm: omap: sata: compile out board-level sata code when CONFIG_DM_SCSI is defined Jean-Jacques Hiblot
2017-04-14 11:08 ` [U-Boot] [PATCH 03/11] drivers: phy: add generic PHY framework Jean-Jacques Hiblot
2017-04-15 17:10   ` Simon Glass
2017-04-18 13:32     ` Jean-Jacques Hiblot
2017-04-19  0:12       ` Simon Glass
2017-04-14 11:08 ` Jean-Jacques Hiblot [this message]
2017-04-15 17:10   ` [U-Boot] [PATCH 04/11] dm: test: Add tests for the generic PHY uclass Simon Glass
2017-04-14 11:08 ` [U-Boot] [PATCH 05/11] drivers: phy: add PIPE3 phy driver Jean-Jacques Hiblot
2017-04-14 11:08 ` [U-Boot] [PATCH 06/11] dra7: dtsi: mark ocp2scp bus compatible with "simple-bus" Jean-Jacques Hiblot
2017-04-14 20:06   ` Tom Rini
2017-04-14 11:08 ` [U-Boot] [PATCH 07/11] drivers: block: dwc_ahci: Implement a driver for Synopsys DWC sata device Jean-Jacques Hiblot
2017-04-14 11:08 ` [U-Boot] [PATCH 08/11] scsi: make the LUN a parameter of scsi_detect_dev() Jean-Jacques Hiblot
2017-04-14 11:08 ` [U-Boot] [PATCH 09/11] scsi: move the partition initialization out of the scsi detection Jean-Jacques Hiblot
2017-04-14 11:08 ` [U-Boot] [PATCH 10/11] dm: scsi: fix divide-by-0 error in scsi_scan() Jean-Jacques Hiblot
2017-04-14 11:08 ` [U-Boot] [PATCH 11/11] defconfig: dra7xx_evm: enable CONFIG_BLK and disk driver model for SCSI Jean-Jacques Hiblot
2017-04-14 11:13 ` [U-Boot] [PATCH 00/11] OMAP: Move SATA to use block driver model Jean-Jacques Hiblot

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=1492168089-15437-5-git-send-email-jjhiblot@ti.com \
    --to=jjhiblot@ti.com \
    --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.