All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Sam Ravnborg <sam@ravnborg.org>,
	Sebastian Reichel <sebastian.reichel@collabora.com>,
	Boris Brezillon <bbrezillon@kernel.org>
Subject: [PATCH v5 13/52] drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter
Date: Fri, 24 Jan 2020 05:54:06 +0200	[thread overview]
Message-ID: <20200124035445.1830-14-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20200124035445.1830-1-laurent.pinchart@ideasonboard.com>

The TI TPD12S015 is an HDMI level shifter and ESD protector controlled
through GPIOs. Add a DRM bridge driver for the device.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
---
Changes since v2:

- Control CT_CP_HPD GPIO from .hpd_enable() and .hpd_disable()
- Remove unneeded hpd_gpio zero check
- Update copyright notice

Changes since v1:

- Remove empty .hpd_enable() and .hpd_disable() operations
---
 drivers/gpu/drm/bridge/Kconfig        |   8 +
 drivers/gpu/drm/bridge/Makefile       |   1 +
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 211 ++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/ti-tpd12s015.c

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index f69e7f52013e..90add8d03aaa 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -150,6 +150,14 @@ config DRM_TI_SN65DSI86
 	help
 	  Texas Instruments SN65DSI86 DSI to eDP Bridge driver
 
+config DRM_TI_TPD12S015
+	tristate "TI TPD12S015 HDMI level shifter and ESD protection"
+	depends on OF
+	select DRM_KMS_HELPER
+	help
+	  Texas Instruments TPD12S015 HDMI level shifter and ESD protection
+	  driver.
+
 source "drivers/gpu/drm/bridge/analogix/Kconfig"
 
 source "drivers/gpu/drm/bridge/adv7511/Kconfig"
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index f77b34854b78..8ea09b4116d5 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_DRM_TOSHIBA_TC358767) += tc358767.o
 obj-$(CONFIG_DRM_I2C_ADV7511) += adv7511/
 obj-$(CONFIG_DRM_TI_SN65DSI86) += ti-sn65dsi86.o
 obj-$(CONFIG_DRM_TI_TFP410) += ti-tfp410.o
+obj-$(CONFIG_DRM_TI_TPD12S015) += ti-tpd12s015.o
 
 obj-y += analogix/
 obj-y += synopsys/
diff --git a/drivers/gpu/drm/bridge/ti-tpd12s015.c b/drivers/gpu/drm/bridge/ti-tpd12s015.c
new file mode 100644
index 000000000000..514cbf0eac75
--- /dev/null
+++ b/drivers/gpu/drm/bridge/ti-tpd12s015.c
@@ -0,0 +1,211 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * TPD12S015 HDMI ESD protection & level shifter chip driver
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated
+ *
+ * Based on the omapdrm-specific encoder-opa362 driver
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated
+ * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_graph.h>
+#include <linux/platform_device.h>
+
+#include <drm/drm_bridge.h>
+
+struct tpd12s015_device {
+	struct drm_bridge bridge;
+
+	struct gpio_desc *ct_cp_hpd_gpio;
+	struct gpio_desc *ls_oe_gpio;
+	struct gpio_desc *hpd_gpio;
+	int hpd_irq;
+
+	struct drm_bridge *next_bridge;
+};
+
+static inline struct tpd12s015_device *to_tpd12s015(struct drm_bridge *bridge)
+{
+	return container_of(bridge, struct tpd12s015_device, bridge);
+}
+
+static int tpd12s015_attach(struct drm_bridge *bridge,
+			    enum drm_bridge_attach_flags flags)
+{
+	struct tpd12s015_device *tpd = to_tpd12s015(bridge);
+	int ret;
+
+	if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))
+		return -EINVAL;
+
+	ret = drm_bridge_attach(bridge->encoder, tpd->next_bridge,
+				bridge, flags);
+	if (ret < 0)
+		return ret;
+
+	gpiod_set_value_cansleep(tpd->ls_oe_gpio, 1);
+
+	/* DC-DC converter needs at max 300us to get to 90% of 5V. */
+	usleep_range(300, 1000);
+
+	return 0;
+}
+
+static void tpd12s015_detach(struct drm_bridge *bridge)
+{
+	struct tpd12s015_device *tpd = to_tpd12s015(bridge);
+
+	gpiod_set_value_cansleep(tpd->ls_oe_gpio, 0);
+}
+
+static enum drm_connector_status tpd12s015_detect(struct drm_bridge *bridge)
+{
+	struct tpd12s015_device *tpd = to_tpd12s015(bridge);
+
+	if (gpiod_get_value_cansleep(tpd->hpd_gpio))
+		return connector_status_connected;
+	else
+		return connector_status_disconnected;
+}
+
+static void tpd12s015_hpd_enable(struct drm_bridge *bridge)
+{
+	struct tpd12s015_device *tpd = to_tpd12s015(bridge);
+
+	gpiod_set_value_cansleep(tpd->ct_cp_hpd_gpio, 1);
+}
+
+static void tpd12s015_hpd_disable(struct drm_bridge *bridge)
+{
+	struct tpd12s015_device *tpd = to_tpd12s015(bridge);
+
+	gpiod_set_value_cansleep(tpd->ct_cp_hpd_gpio, 0);
+}
+
+static const struct drm_bridge_funcs tpd12s015_bridge_funcs = {
+	.attach			= tpd12s015_attach,
+	.detach			= tpd12s015_detach,
+	.detect			= tpd12s015_detect,
+	.hpd_enable		= tpd12s015_hpd_enable,
+	.hpd_disable		= tpd12s015_hpd_disable,
+};
+
+static irqreturn_t tpd12s015_hpd_isr(int irq, void *data)
+{
+	struct tpd12s015_device *tpd = data;
+	struct drm_bridge *bridge = &tpd->bridge;
+
+	drm_bridge_hpd_notify(bridge, tpd12s015_detect(bridge));
+
+	return IRQ_HANDLED;
+}
+
+static int tpd12s015_probe(struct platform_device *pdev)
+{
+	struct tpd12s015_device *tpd;
+	struct device_node *node;
+	struct gpio_desc *gpio;
+	int ret;
+
+	tpd = devm_kzalloc(&pdev->dev, sizeof(*tpd), GFP_KERNEL);
+	if (!tpd)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, tpd);
+
+	tpd->bridge.funcs = &tpd12s015_bridge_funcs;
+	tpd->bridge.of_node = pdev->dev.of_node;
+	tpd->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
+	tpd->bridge.ops = DRM_BRIDGE_OP_DETECT;
+
+	/* Get the next bridge, connected to port@1. */
+	node = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
+	if (!node)
+		return -ENODEV;
+
+	tpd->next_bridge = of_drm_find_bridge(node);
+	of_node_put(node);
+
+	if (!tpd->next_bridge)
+		return -EPROBE_DEFER;
+
+	/* Get the control and HPD GPIOs. */
+	gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0,
+					     GPIOD_OUT_LOW);
+	if (IS_ERR(gpio))
+		return PTR_ERR(gpio);
+
+	tpd->ct_cp_hpd_gpio = gpio;
+
+	gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1,
+					     GPIOD_OUT_LOW);
+	if (IS_ERR(gpio))
+		return PTR_ERR(gpio);
+
+	tpd->ls_oe_gpio = gpio;
+
+	gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_IN);
+	if (IS_ERR(gpio))
+		return PTR_ERR(gpio);
+
+	tpd->hpd_gpio = gpio;
+
+	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
+	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
+	if (tpd->hpd_irq) {
+		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
+						tpd12s015_hpd_isr,
+						IRQF_TRIGGER_RISING |
+						IRQF_TRIGGER_FALLING |
+						IRQF_ONESHOT,
+						"tpd12s015 hpd", tpd);
+		if (ret)
+			return ret;
+
+		tpd->bridge.ops |= DRM_BRIDGE_OP_HPD;
+	}
+
+	/* Register the DRM bridge. */
+	drm_bridge_add(&tpd->bridge);
+
+	return 0;
+}
+
+static int __exit tpd12s015_remove(struct platform_device *pdev)
+{
+	struct tpd12s015_device *tpd = platform_get_drvdata(pdev);
+
+	drm_bridge_remove(&tpd->bridge);
+
+	return 0;
+}
+
+static const struct of_device_id tpd12s015_of_match[] = {
+	{ .compatible = "ti,tpd12s015", },
+	{},
+};
+
+MODULE_DEVICE_TABLE(of, tpd12s015_of_match);
+
+static struct platform_driver tpd12s015_driver = {
+	.probe	= tpd12s015_probe,
+	.remove	= __exit_p(tpd12s015_remove),
+	.driver	= {
+		.name	= "tpd12s015",
+		.of_match_table = tpd12s015_of_match,
+	},
+};
+
+module_platform_driver(tpd12s015_driver);
+
+MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
+MODULE_DESCRIPTION("TPD12S015 HDMI level shifter and ESD protection driver");
+MODULE_LICENSE("GPL");
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2020-01-24  3:55 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24  3:53 [PATCH v5 00/52] drm/omap: Replace custom display drivers with drm_bridge and drm_panel Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 01/52] video: hdmi: Change return type of hdmi_avi_infoframe_init() to void Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 02/52] drm/connector: Add helper to get a connector type name Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 03/52] drm/edid: Add flag to drm_display_info to identify HDMI sinks Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 04/52] drm/bridge: Add connector-related bridge operations and data Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 05/52] drm/bridge: Add interlace_allowed flag to drm_bridge Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 06/52] drm/bridge: Extend bridge API to disable connector creation Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 07/52] drm/bridge: dumb-vga-dac: Rename internal symbols to simple-bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 08/52] drm/bridge: dumb-vga-dac: Rename driver " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 09/52] drm/bridge: simple-bridge: Add support for non-VGA bridges Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 10/52] drm/bridge: simple-bridge: Add support for enable GPIO Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 11/52] drm/bridge: simple-bridge: Add support for the TI OPA362 Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 12/52] drm/bridge: Add bridge driver for display connectors Laurent Pinchart
2020-01-24  3:54 ` Laurent Pinchart [this message]
2020-01-24  3:54 ` [PATCH v5 14/52] drm/bridge: panel: Implement bridge connector operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 15/52] drm/bridge: tfp410: Replace manual connector handling with bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 16/52] drm/bridge: tfp410: Allow operation without drm_connector Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 17/52] drm: Add helper to create a connector for a chain of bridges Laurent Pinchart
2020-01-28 11:19   ` Tomi Valkeinen
2020-02-16 15:39     ` Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 18/52] drm/omap: Fix possible object reference leak Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 19/52] drm/omap: dss: Cleanup DSS ports on initialisation failure Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 20/52] drm/omap: Simplify HDMI mode and infoframe configuration Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 21/52] drm/omap: Factor out display type to connector type conversion Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 22/52] drm/omap: Use the drm_panel_bridge API Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 23/52] drm/omap: dss: Fix output next device lookup in DT Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 24/52] drm/omap: Add infrastructure to support drm_bridge local to DSS outputs Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 25/52] drm/omap: dss: Make omap_dss_device_ops optional Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 26/52] drm/omap: hdmi: Allocate EDID in the .read_edid() operation Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 27/52] drm/omap: hdmi4: Rework EDID read to isolate data read Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 28/52] drm/omap: hdmi5: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 29/52] drm/omap: hdmi4: Register a drm_bridge for EDID read Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 30/52] drm/omap: hdmi5: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 31/52] drm/omap: hdmi4: Move mode set, enable and disable operations to bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 32/52] drm/omap: hdmi5: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 33/52] drm/omap: hdmi4: Implement drm_bridge .hpd_notify() operation Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 34/52] drm/omap: dss: Remove .set_hdmi_mode() and .set_infoframe() operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 35/52] drm/omap: venc: Register a drm_bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 36/52] drm/omap: Create connector for bridges Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 37/52] drm/omap: Switch the HDMI and VENC outputs to drm_bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 38/52] drm/omap: Remove HPD, detect and EDID omapdss operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 39/52] drm/omap: hdmi: Remove omap_dss_device operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 40/52] drm/omap: venc: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 41/52] drm/omap: hdmi4: Simplify EDID read Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 42/52] drm/omap: hdmi5: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 43/52] drm/omap: dpi: Sort includes alphabetically Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 44/52] drm/omap: dpi: Reorder functions in sections Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 45/52] drm/omap: dpi: Simplify clock setting API Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 46/52] drm/omap: dpi: Register a drm_bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 47/52] drm/omap: sdi: Sort includes alphabetically Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 48/52] drm/omap: sdi: Register a drm_bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 49/52] drm/omap: Hardcode omap_connector type to DSI Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 50/52] drm/omap: dss: Remove unused omap_dss_device operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 51/52] drm/omap: dss: Inline the omapdss_display_get() function Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 52/52] drm/omap: dss: Remove unused omapdss_of_find_connected_device() function Laurent Pinchart

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=20200124035445.1830-14-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=bbrezillon@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sam@ravnborg.org \
    --cc=sebastian.reichel@collabora.com \
    --cc=tomi.valkeinen@ti.com \
    /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.