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 v7 37/54] drm/omap: venc: Register a drm_bridge
Date: Sat, 22 Feb 2020 17:00:49 +0200	[thread overview]
Message-ID: <20200222150106.22919-38-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20200222150106.22919-1-laurent.pinchart@ideasonboard.com>

In order to integrate with a chain of drm_bridge, the internal VENC
encoder has to expose the mode valid, fixup and set, the enable and
disable and the get modes operations through the drm_bridge API.
Register a bridge at initialisation time to do so.

Most of those operations are removed from the omap_dss_device as they
are now called through the drm_bridge API by the DRM atomic helpers. The
only exception is the .get_modes() operation that is still invoked
through the omap_dss_device-based pipeline.

For the time being make the next bridge in the chain optional as the
VENC output is still based on omap_dss_device. The create_connector
argument to the bridge attach function is also ignored for the same
reason. This will be changed later when removing the related
omapdrm-specific display drivers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Tested-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
Changes since v5:

- Rebased on top of drm_bridge_state

Changes since v4:

- Set bridge interlace_allowed flag

Changes since v3:

- Drop unneeded venc_lock

Changes since v2:

- Unregister bridge if output initialisation fails
---
 drivers/gpu/drm/omapdrm/dss/venc.c | 242 ++++++++++++++++++-----------
 1 file changed, 154 insertions(+), 88 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/venc.c b/drivers/gpu/drm/omapdrm/dss/venc.c
index 977d8d525b43..cb9a689ed612 100644
--- a/drivers/gpu/drm/omapdrm/dss/venc.c
+++ b/drivers/gpu/drm/omapdrm/dss/venc.c
@@ -13,7 +13,6 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/io.h>
-#include <linux/mutex.h>
 #include <linux/completion.h>
 #include <linux/delay.h>
 #include <linux/string.h>
@@ -26,6 +25,8 @@
 #include <linux/component.h>
 #include <linux/sys_soc.h>
 
+#include <drm/drm_bridge.h>
+
 #include "omapdss.h"
 #include "dss.h"
 
@@ -289,7 +290,6 @@ static const struct drm_display_mode omap_dss_ntsc_mode = {
 struct venc_device {
 	struct platform_device *pdev;
 	void __iomem *base;
-	struct mutex venc_lock;
 	struct regulator *vdda_dac_reg;
 	struct dss_device *dss;
 
@@ -303,9 +303,11 @@ struct venc_device {
 	bool requires_tv_dac_clk;
 
 	struct omap_dss_device output;
+	struct drm_bridge bridge;
 };
 
 #define dssdev_to_venc(dssdev) container_of(dssdev, struct venc_device, output)
+#define drm_bridge_to_venc(b) container_of(b, struct venc_device, bridge)
 
 static inline void venc_write_reg(struct venc_device *venc, int idx, u32 val)
 {
@@ -477,32 +479,6 @@ static void venc_power_off(struct venc_device *venc)
 	venc_runtime_put(venc);
 }
 
-static void venc_display_enable(struct omap_dss_device *dssdev)
-{
-	struct venc_device *venc = dssdev_to_venc(dssdev);
-
-	DSSDBG("venc_display_enable\n");
-
-	mutex_lock(&venc->venc_lock);
-
-	venc_power_on(venc);
-
-	mutex_unlock(&venc->venc_lock);
-}
-
-static void venc_display_disable(struct omap_dss_device *dssdev)
-{
-	struct venc_device *venc = dssdev_to_venc(dssdev);
-
-	DSSDBG("venc_display_disable\n");
-
-	mutex_lock(&venc->venc_lock);
-
-	venc_power_off(venc);
-
-	mutex_unlock(&venc->venc_lock);
-}
-
 static int venc_get_modes(struct omap_dss_device *dssdev,
 			  struct drm_connector *connector)
 {
@@ -545,57 +521,6 @@ static enum venc_videomode venc_get_videomode(const struct drm_display_mode *mod
 	return VENC_MODE_UNKNOWN;
 }
 
-static void venc_set_timings(struct omap_dss_device *dssdev,
-			     const struct drm_display_mode *mode)
-{
-	struct venc_device *venc = dssdev_to_venc(dssdev);
-	enum venc_videomode venc_mode = venc_get_videomode(mode);
-
-	DSSDBG("venc_set_timings\n");
-
-	mutex_lock(&venc->venc_lock);
-
-	switch (venc_mode) {
-	default:
-		WARN_ON_ONCE(1);
-		/* Fall-through */
-	case VENC_MODE_PAL:
-		venc->config = &venc_config_pal_trm;
-		break;
-
-	case VENC_MODE_NTSC:
-		venc->config = &venc_config_ntsc_trm;
-		break;
-	}
-
-	dispc_set_tv_pclk(venc->dss->dispc, 13500000);
-
-	mutex_unlock(&venc->venc_lock);
-}
-
-static int venc_check_timings(struct omap_dss_device *dssdev,
-			      struct drm_display_mode *mode)
-{
-	DSSDBG("venc_check_timings\n");
-
-	switch (venc_get_videomode(mode)) {
-	case VENC_MODE_PAL:
-		drm_mode_copy(mode, &omap_dss_pal_mode);
-		break;
-
-	case VENC_MODE_NTSC:
-		drm_mode_copy(mode, &omap_dss_ntsc_mode);
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
-	drm_mode_set_name(mode);
-	return 0;
-}
-
 static int venc_dump_regs(struct seq_file *s, void *p)
 {
 	struct venc_device *venc = s->private;
@@ -689,15 +614,152 @@ static const struct omap_dss_device_ops venc_ops = {
 	.connect = venc_connect,
 	.disconnect = venc_disconnect,
 
-	.enable = venc_display_enable,
-	.disable = venc_display_disable,
+	.get_modes = venc_get_modes,
+};
 
-	.check_timings = venc_check_timings,
-	.set_timings = venc_set_timings,
+/* -----------------------------------------------------------------------------
+ * DRM Bridge Operations
+ */
 
-	.get_modes = venc_get_modes,
+static int venc_bridge_attach(struct drm_bridge *bridge,
+			      enum drm_bridge_attach_flags flags)
+{
+	struct venc_device *venc = drm_bridge_to_venc(bridge);
+
+	if (venc->output.next_bridge)
+		return 0;
+
+	return drm_bridge_attach(bridge->encoder, venc->output.next_bridge,
+				 bridge, flags);
+}
+
+static enum drm_mode_status
+venc_bridge_mode_valid(struct drm_bridge *bridge,
+		       const struct drm_display_mode *mode)
+{
+	switch (venc_get_videomode(mode)) {
+	case VENC_MODE_PAL:
+	case VENC_MODE_NTSC:
+		return MODE_OK;
+
+	default:
+		return MODE_BAD;
+	}
+}
+
+static bool venc_bridge_mode_fixup(struct drm_bridge *bridge,
+				   const struct drm_display_mode *mode,
+				   struct drm_display_mode *adjusted_mode)
+{
+	const struct drm_display_mode *venc_mode;
+
+	switch (venc_get_videomode(adjusted_mode)) {
+	case VENC_MODE_PAL:
+		venc_mode = &omap_dss_pal_mode;
+		break;
+
+	case VENC_MODE_NTSC:
+		venc_mode = &omap_dss_ntsc_mode;
+		break;
+
+	default:
+		return false;
+	}
+
+	drm_mode_copy(adjusted_mode, venc_mode);
+	drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
+	drm_mode_set_name(adjusted_mode);
+
+	return true;
+}
+
+static void venc_bridge_mode_set(struct drm_bridge *bridge,
+				 const struct drm_display_mode *mode,
+				 const struct drm_display_mode *adjusted_mode)
+{
+	struct venc_device *venc = drm_bridge_to_venc(bridge);
+	enum venc_videomode venc_mode = venc_get_videomode(adjusted_mode);
+
+	switch (venc_mode) {
+	default:
+		WARN_ON_ONCE(1);
+		/* Fall-through */
+	case VENC_MODE_PAL:
+		venc->config = &venc_config_pal_trm;
+		break;
+
+	case VENC_MODE_NTSC:
+		venc->config = &venc_config_ntsc_trm;
+		break;
+	}
+
+	dispc_set_tv_pclk(venc->dss->dispc, 13500000);
+}
+
+static void venc_bridge_enable(struct drm_bridge *bridge)
+{
+	struct venc_device *venc = drm_bridge_to_venc(bridge);
+
+	venc_power_on(venc);
+}
+
+static void venc_bridge_disable(struct drm_bridge *bridge)
+{
+	struct venc_device *venc = drm_bridge_to_venc(bridge);
+
+	venc_power_off(venc);
+}
+
+static int venc_bridge_get_modes(struct drm_bridge *bridge,
+				 struct drm_connector *connector)
+{
+	static const struct drm_display_mode *modes[] = {
+		&omap_dss_pal_mode,
+		&omap_dss_ntsc_mode,
+	};
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(modes); ++i) {
+		struct drm_display_mode *mode;
+
+		mode = drm_mode_duplicate(connector->dev, modes[i]);
+		if (!mode)
+			return i;
+
+		mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+		drm_mode_set_name(mode);
+		drm_mode_probed_add(connector, mode);
+	}
+
+	return ARRAY_SIZE(modes);
+}
+
+static const struct drm_bridge_funcs venc_bridge_funcs = {
+	.attach = venc_bridge_attach,
+	.mode_valid = venc_bridge_mode_valid,
+	.mode_fixup = venc_bridge_mode_fixup,
+	.mode_set = venc_bridge_mode_set,
+	.enable = venc_bridge_enable,
+	.disable = venc_bridge_disable,
+	.get_modes = venc_bridge_get_modes,
 };
 
+static void venc_bridge_init(struct venc_device *venc)
+{
+	venc->bridge.funcs = &venc_bridge_funcs;
+	venc->bridge.of_node = venc->pdev->dev.of_node;
+	venc->bridge.ops = DRM_BRIDGE_OP_MODES;
+	venc->bridge.type = DRM_MODE_CONNECTOR_SVIDEO;
+	venc->bridge.interlace_allowed = true;
+
+	drm_bridge_add(&venc->bridge);
+}
+
+static void venc_bridge_cleanup(struct venc_device *venc)
+{
+	drm_bridge_remove(&venc->bridge);
+}
+
 /* -----------------------------------------------------------------------------
  * Component Bind & Unbind
  */
@@ -747,6 +809,8 @@ static int venc_init_output(struct venc_device *venc)
 	struct omap_dss_device *out = &venc->output;
 	int r;
 
+	venc_bridge_init(venc);
+
 	out->dev = &venc->pdev->dev;
 	out->id = OMAP_DSS_OUTPUT_VENC;
 	out->type = OMAP_DISPLAY_TYPE_VENC;
@@ -757,9 +821,11 @@ static int venc_init_output(struct venc_device *venc)
 	out->of_port = 0;
 	out->ops_flags = OMAP_DSS_DEVICE_OP_MODES;
 
-	r = omapdss_device_init_output(out, NULL);
-	if (r < 0)
+	r = omapdss_device_init_output(out, &venc->bridge);
+	if (r < 0) {
+		venc_bridge_cleanup(venc);
 		return r;
+	}
 
 	omapdss_device_register(out);
 
@@ -770,6 +836,8 @@ static void venc_uninit_output(struct venc_device *venc)
 {
 	omapdss_device_unregister(&venc->output);
 	omapdss_device_cleanup_output(&venc->output);
+
+	venc_bridge_cleanup(venc);
 }
 
 static int venc_probe_of(struct venc_device *venc)
@@ -839,8 +907,6 @@ static int venc_probe(struct platform_device *pdev)
 	if (soc_device_match(venc_soc_devices))
 		venc->requires_tv_dac_clk = true;
 
-	mutex_init(&venc->venc_lock);
-
 	venc->config = &venc_config_pal_trm;
 
 	venc_mem = platform_get_resource(venc->pdev, IORESOURCE_MEM, 0);
-- 
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-02-22 15:02 UTC|newest]

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