All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Cc: Boris Brezillon <bbrezillon@kernel.org>,
	Sean Paul <sean@poorly.run>,
	Sebastian Reichel <sebastian.reichel@collabora.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Sam Ravnborg <sam@ravnborg.org>
Subject: [PATCH v3 45/50] drm/omap: dpi: Register a drm_bridge
Date: Wed, 11 Dec 2019 00:57:45 +0200	[thread overview]
Message-ID: <20191210225750.15709-46-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20191210225750.15709-1-laurent.pinchart@ideasonboard.com>

In order to integrate with a chain of drm_bridge, the internal DPI
output has to expose its operations through the drm_bridge API.
Register a bridge at initialisation time to do so and remove the
omap_dss_device operations that are now unused.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v2:

- Unregister bridge if port initialisation fails
---
 drivers/gpu/drm/omapdrm/dss/dpi.c | 197 ++++++++++++++++++------------
 1 file changed, 119 insertions(+), 78 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/dpi.c b/drivers/gpu/drm/omapdrm/dss/dpi.c
index c167bd1116ec..e228766f613d 100644
--- a/drivers/gpu/drm/omapdrm/dss/dpi.c
+++ b/drivers/gpu/drm/omapdrm/dss/dpi.c
@@ -21,6 +21,8 @@
 #include <linux/string.h>
 #include <linux/sys_soc.h>
 
+#include <drm/drm_bridge.h>
+
 #include "dss.h"
 #include "omapdss.h"
 
@@ -41,12 +43,10 @@ struct dpi_data {
 	int data_lines;
 
 	struct omap_dss_device output;
+	struct drm_bridge bridge;
 };
 
-static struct dpi_data *dpi_get_data_from_dssdev(struct omap_dss_device *dssdev)
-{
-	return container_of(dssdev, struct dpi_data, output);
-}
+#define drm_bridge_to_dpi(bridge) container_of(bridge, struct dpi_data, bridge)
 
 /* -----------------------------------------------------------------------------
  * Clock Handling and PLL
@@ -354,6 +354,32 @@ static void dpi_config_lcd_manager(struct dpi_data *dpi)
 	dss_mgr_set_lcd_config(&dpi->output, &dpi->mgr_config);
 }
 
+static int dpi_clock_update(struct dpi_data *dpi, unsigned long *clock)
+{
+	int lck_div, pck_div;
+	unsigned long fck;
+	struct dpi_clk_calc_ctx ctx;
+
+	if (dpi->pll) {
+		if (!dpi_pll_clk_calc(dpi, *clock, &ctx))
+			return -EINVAL;
+
+		fck = ctx.pll_cinfo.clkout[ctx.clkout_idx];
+	} else {
+		if (!dpi_dss_clk_calc(dpi, *clock, &ctx))
+			return -EINVAL;
+
+		fck = ctx.fck;
+	}
+
+	lck_div = ctx.dispc_cinfo.lck_div;
+	pck_div = ctx.dispc_cinfo.pck_div;
+
+	*clock = fck / lck_div / pck_div;
+
+	return 0;
+}
+
 static int dpi_verify_pll(struct dss_pll *pll)
 {
 	int r;
@@ -391,29 +417,76 @@ static void dpi_init_pll(struct dpi_data *dpi)
 }
 
 /* -----------------------------------------------------------------------------
- * omap_dss_device Operations
+ * DRM Bridge Operations
  */
 
-static int dpi_connect(struct omap_dss_device *src,
-		       struct omap_dss_device *dst)
+static int dpi_bridge_attach(struct drm_bridge *bridge,
+			     enum drm_bridge_attach_flags flags)
 {
-	struct dpi_data *dpi = dpi_get_data_from_dssdev(dst);
+	struct dpi_data *dpi = drm_bridge_to_dpi(bridge);
+
+	if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))
+		return -EINVAL;
 
 	dpi_init_pll(dpi);
 
-	return omapdss_device_connect(dst->dss, dst, dst->next);
+	return drm_bridge_attach(bridge->encoder, dpi->output.next_bridge,
+				 bridge, flags);
 }
 
-static void dpi_disconnect(struct omap_dss_device *src,
-			   struct omap_dss_device *dst)
+static enum drm_mode_status
+dpi_bridge_mode_valid(struct drm_bridge *bridge,
+		       const struct drm_display_mode *mode)
 {
-	omapdss_device_disconnect(dst, dst->next);
+	struct dpi_data *dpi = drm_bridge_to_dpi(bridge);
+	unsigned long clock = mode->clock * 1000;
+	int ret;
+
+	if (mode->hdisplay % 8 != 0)
+		return MODE_BAD_WIDTH;
+
+	if (mode->clock == 0)
+		return MODE_NOCLOCK;
+
+	ret = dpi_clock_update(dpi, &clock);
+	if (ret < 0)
+		return MODE_CLOCK_RANGE;
+
+	return MODE_OK;
 }
 
-static void dpi_display_enable(struct omap_dss_device *dssdev)
+static bool dpi_bridge_mode_fixup(struct drm_bridge *bridge,
+				   const struct drm_display_mode *mode,
+				   struct drm_display_mode *adjusted_mode)
 {
-	struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
-	struct omap_dss_device *out = &dpi->output;
+	struct dpi_data *dpi = drm_bridge_to_dpi(bridge);
+	unsigned long clock = mode->clock * 1000;
+	int ret;
+
+	ret = dpi_clock_update(dpi, &clock);
+	if (ret < 0)
+		return false;
+
+	adjusted_mode->clock = clock / 1000;
+
+	return true;
+}
+
+static void dpi_bridge_mode_set(struct drm_bridge *bridge,
+				 const struct drm_display_mode *mode,
+				 const struct drm_display_mode *adjusted_mode)
+{
+	struct dpi_data *dpi = drm_bridge_to_dpi(bridge);
+
+	mutex_lock(&dpi->lock);
+	dpi->pixelclock = adjusted_mode->clock * 1000;
+	mutex_unlock(&dpi->lock);
+}
+
+static void dpi_bridge_enable(struct drm_bridge *bridge,
+			       struct drm_atomic_state *state)
+{
+	struct dpi_data *dpi = drm_bridge_to_dpi(bridge);
 	int r;
 
 	mutex_lock(&dpi->lock);
@@ -428,7 +501,7 @@ static void dpi_display_enable(struct omap_dss_device *dssdev)
 	if (r)
 		goto err_get_dispc;
 
-	r = dss_dpi_select_source(dpi->dss, dpi->id, out->dispc_channel);
+	r = dss_dpi_select_source(dpi->dss, dpi->id, dpi->output.dispc_channel);
 	if (r)
 		goto err_src_sel;
 
@@ -468,9 +541,10 @@ static void dpi_display_enable(struct omap_dss_device *dssdev)
 	mutex_unlock(&dpi->lock);
 }
 
-static void dpi_display_disable(struct omap_dss_device *dssdev)
+static void dpi_bridge_disable(struct drm_bridge *bridge,
+				struct drm_atomic_state *state)
 {
-	struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
+	struct dpi_data *dpi = drm_bridge_to_dpi(bridge);
 
 	mutex_lock(&dpi->lock);
 
@@ -490,70 +564,32 @@ static void dpi_display_disable(struct omap_dss_device *dssdev)
 	mutex_unlock(&dpi->lock);
 }
 
-static int dpi_check_timings(struct omap_dss_device *dssdev,
-			     struct drm_display_mode *mode)
-{
-	struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
-	int lck_div, pck_div;
-	unsigned long fck;
-	unsigned long pck;
-	struct dpi_clk_calc_ctx ctx;
-	bool ok;
-
-	if (mode->hdisplay % 8 != 0)
-		return -EINVAL;
-
-	if (mode->clock == 0)
-		return -EINVAL;
-
-	if (dpi->pll) {
-		ok = dpi_pll_clk_calc(dpi, mode->clock * 1000, &ctx);
-		if (!ok)
-			return -EINVAL;
-
-		fck = ctx.pll_cinfo.clkout[ctx.clkout_idx];
-	} else {
-		ok = dpi_dss_clk_calc(dpi, mode->clock * 1000, &ctx);
-		if (!ok)
-			return -EINVAL;
-
-		fck = ctx.fck;
-	}
-
-	lck_div = ctx.dispc_cinfo.lck_div;
-	pck_div = ctx.dispc_cinfo.pck_div;
-
-	pck = fck / lck_div / pck_div;
+static const struct drm_bridge_funcs dpi_bridge_funcs = {
+	.attach = dpi_bridge_attach,
+	.mode_valid = dpi_bridge_mode_valid,
+	.mode_fixup = dpi_bridge_mode_fixup,
+	.mode_set = dpi_bridge_mode_set,
+	.atomic_enable = dpi_bridge_enable,
+	.atomic_disable = dpi_bridge_disable,
+};
 
-	mode->clock = pck / 1000;
+static void dpi_bridge_init(struct dpi_data *dpi)
+{
+	dpi->bridge.funcs = &dpi_bridge_funcs;
+	dpi->bridge.of_node = dpi->pdev->dev.of_node;
+	dpi->bridge.type = DRM_MODE_CONNECTOR_DPI;
 
-	return 0;
+	drm_bridge_add(&dpi->bridge);
 }
 
-static void dpi_set_timings(struct omap_dss_device *dssdev,
-			    const struct drm_display_mode *mode)
+static void dpi_bridge_cleanup(struct dpi_data *dpi)
 {
-	struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
-
-	DSSDBG("dpi_set_timings\n");
-
-	mutex_lock(&dpi->lock);
-
-	dpi->pixelclock = mode->clock * 1000;
-
-	mutex_unlock(&dpi->lock);
+	drm_bridge_remove(&dpi->bridge);
 }
 
-static const struct omap_dss_device_ops dpi_ops = {
-	.connect = dpi_connect,
-	.disconnect = dpi_disconnect,
-
-	.enable = dpi_display_enable,
-	.disable = dpi_display_disable,
-
-	.check_timings = dpi_check_timings,
-	.set_timings = dpi_set_timings,
-};
+/* -----------------------------------------------------------------------------
+ * Initialisation and Cleanup
+ */
 
 /*
  * Return a hardcoded channel for the DPI output. This should work for
@@ -597,6 +633,8 @@ static int dpi_init_output_port(struct dpi_data *dpi, struct device_node *port)
 	u32 port_num = 0;
 	int r;
 
+	dpi_bridge_init(dpi);
+
 	of_property_read_u32(port, "reg", &port_num);
 	dpi->id = port_num <= 2 ? port_num : 0;
 
@@ -618,12 +656,13 @@ static int dpi_init_output_port(struct dpi_data *dpi, struct device_node *port)
 	out->type = OMAP_DISPLAY_TYPE_DPI;
 	out->dispc_channel = dpi_get_channel(dpi);
 	out->of_port = port_num;
-	out->ops = &dpi_ops;
 	out->owner = THIS_MODULE;
 
-	r = omapdss_device_init_output(out, NULL);
-	if (r < 0)
+	r = omapdss_device_init_output(out, &dpi->bridge);
+	if (r < 0) {
+		dpi_bridge_cleanup(dpi);
 		return r;
+	}
 
 	omapdss_device_register(out);
 
@@ -637,6 +676,8 @@ static void dpi_uninit_output_port(struct device_node *port)
 
 	omapdss_device_unregister(out);
 	omapdss_device_cleanup_output(out);
+
+	dpi_bridge_cleanup(dpi);
 }
 
 /* -----------------------------------------------------------------------------
-- 
Regards,

Laurent Pinchart

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

  parent reply	other threads:[~2019-12-10 22:59 UTC|newest]

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

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=20191210225750.15709-46-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=bbrezillon@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sam@ravnborg.org \
    --cc=sean@poorly.run \
    --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.