[U-Boot] [PATCH 33/51] drivers: Add transmitter uclass

Mario Six mario.six at gdsys.cc
Fri Jul 14 12:55:19 UTC 2017


This patch adds a simple transmitter uclass meant for DVI or DisplayPort
transmitters. The only driver functionality implemented are power_on and
power_off methods for powering the transmitter device on and off,
respectively.

Signed-off-by: Mario Six <mario.six at gdsys.cc>
---

 arch/sandbox/dts/sandbox.dts              |  4 ++
 arch/sandbox/dts/test.dts                 |  4 ++
 configs/sandbox_defconfig                 |  2 +
 drivers/Kconfig                           |  2 +
 drivers/Makefile                          |  1 +
 drivers/transmitter/Kconfig               | 16 +++++++
 drivers/transmitter/Makefile              |  9 ++++
 drivers/transmitter/sandbox_transmitter.c | 74 +++++++++++++++++++++++++++++++
 drivers/transmitter/transmitter-uclass.c  | 36 +++++++++++++++
 include/dm/uclass-id.h                    |  1 +
 include/transmitter.h                     | 49 ++++++++++++++++++++
 test/dm/Makefile                          |  1 +
 test/dm/transmitter.c                     | 31 +++++++++++++
 13 files changed, 230 insertions(+)
 create mode 100644 drivers/transmitter/Kconfig
 create mode 100644 drivers/transmitter/Makefile
 create mode 100644 drivers/transmitter/sandbox_transmitter.c
 create mode 100644 drivers/transmitter/transmitter-uclass.c
 create mode 100644 include/transmitter.h
 create mode 100644 test/dm/transmitter.c

diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 0aba6c9a6d..0e84b840e7 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -238,6 +238,10 @@
 		compatible = "google,sandbox-tpm";
 	};
 
+	transmitter {
+		compatible = "sandbox,transmitter";
+	};
+
 	triangle {
 		compatible = "demo-shape";
 		colour = "cyan";
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 65b2f8ecda..36255809d3 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -392,6 +392,10 @@
 		clock-frequency = <1000000>;
 	};
 
+	transmitter {
+		compatible = "sandbox,transmitter";
+	};
+
 	uart0: serial {
 		compatible = "sandbox,serial";
 		u-boot,dm-pre-reloc;
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 7a1b9ef052..7e1eebee67 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -167,6 +167,8 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_TPM_TIS_SANDBOX=y
+CONFIG_TRANSMITTER=y
+CONFIG_SANDBOX_TRANSMITTER=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EMUL=y
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 2e03133c43..2d15e4ea09 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -90,6 +90,8 @@ source "drivers/timer/Kconfig"
 
 source "drivers/tpm/Kconfig"
 
+source "drivers/transmitter/Kconfig"
+
 source "drivers/usb/Kconfig"
 
 source "drivers/video/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 8624bd86f1..37cd6396fa 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -87,6 +87,7 @@ obj-y += sound/
 obj-y += spmi/
 obj-y += sysreset/
 obj-y += timer/
+obj-y += transmitter/
 obj-y += tpm/
 obj-y += video/
 obj-y += watchdog/
diff --git a/drivers/transmitter/Kconfig b/drivers/transmitter/Kconfig
new file mode 100644
index 0000000000..64ca08f8b8
--- /dev/null
+++ b/drivers/transmitter/Kconfig
@@ -0,0 +1,16 @@
+#
+# Transmitter drivers configuration
+#
+
+menuconfig TRANSMITTER
+	bool "DVI/DP Transmitters"
+
+if TRANSMITTER
+
+config SANDBOX_TRANSMITTER
+	bool "Enable sandbox transmitter driver"
+	depends on DM
+	help
+	  Enable the dummy transmitter for the sandbox.
+
+endif
diff --git a/drivers/transmitter/Makefile b/drivers/transmitter/Makefile
new file mode 100644
index 0000000000..b873e63e28
--- /dev/null
+++ b/drivers/transmitter/Makefile
@@ -0,0 +1,9 @@
+#
+# (C) Copyright 2017
+# Mario Six,  Guntermann & Drunck GmbH, mario.six at gdsys.cc
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y += transmitter-uclass.o
+obj-$(CONFIG_SANDBOX_TRANSMITTER) += sandbox_transmitter.o
diff --git a/drivers/transmitter/sandbox_transmitter.c b/drivers/transmitter/sandbox_transmitter.c
new file mode 100644
index 0000000000..cb4c1e81e8
--- /dev/null
+++ b/drivers/transmitter/sandbox_transmitter.c
@@ -0,0 +1,74 @@
+/*
+ * (C) Copyright 2017
+ * Mario Six,  Guntermann & Drunck GmbH, mario.six at gdsys.cc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <transmitter.h>
+
+struct sandbox_transmitter_priv {
+	int power_state;
+};
+
+void sandbox_transmitter_set_state(struct udevice *dev, int power_state)
+{
+	struct sandbox_transmitter_priv *priv = dev_get_priv(dev);
+
+	priv->power_state = power_state;
+}
+
+int sandbox_transmitter_get_state(struct udevice *dev)
+{
+	struct sandbox_transmitter_priv *priv = dev_get_priv(dev);
+
+	return priv->power_state;
+}
+
+int sandbox_transmitter_power_on(struct udevice *dev, void *data)
+{
+	struct sandbox_transmitter_priv *priv = dev_get_priv(dev);
+
+	priv->power_state = 1;
+
+	return 0;
+}
+
+int sandbox_transmitter_power_off(struct udevice *dev)
+{
+	struct sandbox_transmitter_priv *priv = dev_get_priv(dev);
+
+	priv->power_state = 0;
+
+	return 0;
+}
+
+int sandbox_transmitter_probe(struct udevice *dev)
+{
+	struct sandbox_transmitter_priv *priv = dev_get_priv(dev);
+
+	priv->power_state = 0;
+
+	return 0;
+}
+
+struct transmitter_ops sandbox_transmitter_ops = {
+	.power_on = sandbox_transmitter_power_on,
+	.power_off = sandbox_transmitter_power_off,
+};
+
+static const struct udevice_id sandbox_transmitter_ids[] = {
+	{ .compatible = "sandbox,transmitter" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(sandbox_transmitter) = {
+	.name			= "sandbox_transmitter",
+	.id			= UCLASS_TRANSMITTER,
+	.of_match		= sandbox_transmitter_ids,
+	.probe			= sandbox_transmitter_probe,
+	.priv_auto_alloc_size	= sizeof(struct sandbox_transmitter_priv),
+	.ops			= &sandbox_transmitter_ops,
+};
diff --git a/drivers/transmitter/transmitter-uclass.c b/drivers/transmitter/transmitter-uclass.c
new file mode 100644
index 0000000000..cfcb8ed178
--- /dev/null
+++ b/drivers/transmitter/transmitter-uclass.c
@@ -0,0 +1,36 @@
+/*
+ * (C) Copyright 2017
+ * Mario Six,  Guntermann & Drunck GmbH, mario.six at gdsys.cc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <transmitter.h>
+
+int transmitter_power_on(struct udevice *dev, void *data)
+{
+	const struct transmitter_ops *ops = device_get_ops(dev);
+
+	if (!ops->power_on)
+		return -ENOSYS;
+
+	return ops->power_on(dev, data);
+}
+
+int transmitter_power_off(struct udevice *dev)
+{
+	const struct transmitter_ops *ops = device_get_ops(dev);
+
+	if (!ops->power_off)
+		return -ENOSYS;
+
+	return ops->power_off(dev);
+}
+
+UCLASS_DRIVER(transmitter) = {
+	.id		= UCLASS_TRANSMITTER,
+	.name		= "transmitter",
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 56fbedaa9d..8eee8534ab 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -82,6 +82,7 @@ enum uclass_id {
 	UCLASS_THERMAL,		/* Thermal sensor */
 	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
+	UCLASS_TRANSMITTER,	/* DVI and DP transmitters*/
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
 	UCLASS_USB_HUB,		/* USB hub */
diff --git a/include/transmitter.h b/include/transmitter.h
new file mode 100644
index 0000000000..4765c1f17e
--- /dev/null
+++ b/include/transmitter.h
@@ -0,0 +1,49 @@
+/*
+ * (C) Copyright 2017
+ * Mario Six,  Guntermann & Drunck GmbH, mario.six at gdsys.cc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _TRANSMITTER_H_
+#define _TRANSMITTER_H_
+
+struct transmitter_ops {
+	/*
+	 * Power on the transmitter device.
+	 *
+	 * This function is optional.
+	 *
+	 * @dev: The transmitter device to power on.
+	 * @return: 0 if OK, -ve on error
+	 */
+	int (*power_on)(struct udevice *dev, void *data);
+
+	/*
+	 * Power off the transmitter device.
+	 *
+	 * This function is optional.
+	 *
+	 * @dev: The transmitter device to power off.
+	 * @return: 0 if OK, -ve on error
+	 */
+	int (*power_off)(struct udevice *dev);
+};
+
+/*
+ * Power on a transmitter device.
+ *
+ * @dev: The transmitter device to power on.
+ * @return: 0 if OK, -ve on error
+ */
+int transmitter_power_on(struct udevice *dev, void *data);
+
+/*
+ * Power off a transmitter device.
+ *
+ * @dev: The transmitter device to power off.
+ * @return: 0 if OK, -ve on error
+ */
+int transmitter_power_off(struct udevice *dev);
+
+#endif	/* _TRANSMITTER_H_ */
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 513c4561ad..fcc9432c26 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -44,4 +44,5 @@ obj-$(CONFIG_DM_VIDEO) += video.o
 obj-$(CONFIG_ADC) += adc.o
 obj-$(CONFIG_SPMI) += spmi.o
 obj-$(CONFIG_WDT) += wdt.o
+obj-$(CONFIG_TRANSMITTER) += transmitter.o
 endif
diff --git a/test/dm/transmitter.c b/test/dm/transmitter.c
new file mode 100644
index 0000000000..6ea74a06b7
--- /dev/null
+++ b/test/dm/transmitter.c
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2017
+ * Mario Six,  Guntermann & Drunck GmbH, mario.six at gdsys.cc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+static int dm_test_transmitter(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_TRANSMITTER, "transmitter",
+					      &dev));
+
+	sandbox_transmitter_set_state(dev, 0);
+	ut_asserteq(0, sandbox_transmitter_get_state(dev));
+
+	ut_assertok(sandbox_transmitter_power_on(dev));
+	ut_asserteq(1, sandbox_transmitter_get_state(dev));
+
+	ut_assertok(sandbox_transmitter_power_off(dev));
+	ut_asserteq(0, sandbox_transmitter_get_state(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_transmitter, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.11.0



More information about the U-Boot mailing list