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>
Subject: [PATCH v8 50/54] drm/omap: sdi: Register a drm_bridge
Date: Wed, 26 Feb 2020 13:25:10 +0200	[thread overview]
Message-ID: <20200226112514.12455-51-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20200226112514.12455-1-laurent.pinchart@ideasonboard.com>

In order to integrate with a chain of drm_bridge, the internal SDI
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>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Tested-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/gpu/drm/omapdrm/dss/sdi.c | 168 +++++++++++++++++++-----------
 1 file changed, 109 insertions(+), 59 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/sdi.c b/drivers/gpu/drm/omapdrm/dss/sdi.c
index 7dedfcc86922..417a8740ad0a 100644
--- a/drivers/gpu/drm/omapdrm/dss/sdi.c
+++ b/drivers/gpu/drm/omapdrm/dss/sdi.c
@@ -15,6 +15,8 @@
 #include <linux/regulator/consumer.h>
 #include <linux/string.h>
 
+#include <drm/drm_bridge.h>
+
 #include "dss.h"
 #include "omapdss.h"
 
@@ -30,9 +32,11 @@ struct sdi_device {
 	int datapairs;
 
 	struct omap_dss_device output;
+	struct drm_bridge bridge;
 };
 
-#define dssdev_to_sdi(dssdev) container_of(dssdev, struct sdi_device, output)
+#define drm_bridge_to_sdi(bridge) \
+	container_of(bridge, struct sdi_device, bridge)
 
 struct sdi_clk_calc_ctx {
 	struct sdi_device *sdi;
@@ -118,9 +122,82 @@ static void sdi_config_lcd_manager(struct sdi_device *sdi)
 	dss_mgr_set_lcd_config(&sdi->output, &sdi->mgr_config);
 }
 
-static void sdi_display_enable(struct omap_dss_device *dssdev)
+/* -----------------------------------------------------------------------------
+ * DRM Bridge Operations
+ */
+
+static int sdi_bridge_attach(struct drm_bridge *bridge,
+			     enum drm_bridge_attach_flags flags)
+{
+	struct sdi_device *sdi = drm_bridge_to_sdi(bridge);
+
+	if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))
+		return -EINVAL;
+
+	return drm_bridge_attach(bridge->encoder, sdi->output.next_bridge,
+				 bridge, flags);
+}
+
+static enum drm_mode_status
+sdi_bridge_mode_valid(struct drm_bridge *bridge,
+		      const struct drm_display_mode *mode)
+{
+	struct sdi_device *sdi = drm_bridge_to_sdi(bridge);
+	unsigned long pixelclock = mode->clock * 1000;
+	struct dispc_clock_info dispc_cinfo;
+	unsigned long fck;
+	int ret;
+
+	if (pixelclock == 0)
+		return MODE_NOCLOCK;
+
+	ret = sdi_calc_clock_div(sdi, pixelclock, &fck, &dispc_cinfo);
+	if (ret < 0)
+		return MODE_CLOCK_RANGE;
+
+	return MODE_OK;
+}
+
+static bool sdi_bridge_mode_fixup(struct drm_bridge *bridge,
+				  const struct drm_display_mode *mode,
+				  struct drm_display_mode *adjusted_mode)
+{
+	struct sdi_device *sdi = drm_bridge_to_sdi(bridge);
+	unsigned long pixelclock = mode->clock * 1000;
+	struct dispc_clock_info dispc_cinfo;
+	unsigned long fck;
+	unsigned long pck;
+	int ret;
+
+	ret = sdi_calc_clock_div(sdi, pixelclock, &fck, &dispc_cinfo);
+	if (ret < 0)
+		return false;
+
+	pck = fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div;
+
+	if (pck != pixelclock)
+		dev_dbg(&sdi->pdev->dev,
+			"pixel clock adjusted from %lu Hz to %lu Hz\n",
+			pixelclock, pck);
+
+	adjusted_mode->clock = pck / 1000;
+
+	return true;
+}
+
+static void sdi_bridge_mode_set(struct drm_bridge *bridge,
+				const struct drm_display_mode *mode,
+				const struct drm_display_mode *adjusted_mode)
+{
+	struct sdi_device *sdi = drm_bridge_to_sdi(bridge);
+
+	sdi->pixelclock = adjusted_mode->clock * 1000;
+}
+
+static void sdi_bridge_enable(struct drm_bridge *bridge,
+			      struct drm_bridge_state *bridge_state)
 {
-	struct sdi_device *sdi = dssdev_to_sdi(dssdev);
+	struct sdi_device *sdi = drm_bridge_to_sdi(bridge);
 	struct dispc_clock_info dispc_cinfo;
 	unsigned long fck;
 	int r;
@@ -181,9 +258,10 @@ static void sdi_display_enable(struct omap_dss_device *dssdev)
 	regulator_disable(sdi->vdds_sdi_reg);
 }
 
-static void sdi_display_disable(struct omap_dss_device *dssdev)
+static void sdi_bridge_disable(struct drm_bridge *bridge,
+			       struct drm_bridge_state *bridge_state)
 {
-	struct sdi_device *sdi = dssdev_to_sdi(dssdev);
+	struct sdi_device *sdi = drm_bridge_to_sdi(bridge);
 
 	dss_mgr_disable(&sdi->output);
 
@@ -194,71 +272,40 @@ static void sdi_display_disable(struct omap_dss_device *dssdev)
 	regulator_disable(sdi->vdds_sdi_reg);
 }
 
-static void sdi_set_timings(struct omap_dss_device *dssdev,
-			    const struct drm_display_mode *mode)
-{
-	struct sdi_device *sdi = dssdev_to_sdi(dssdev);
-
-	sdi->pixelclock = mode->clock * 1000;
-}
+static const struct drm_bridge_funcs sdi_bridge_funcs = {
+	.attach = sdi_bridge_attach,
+	.mode_valid = sdi_bridge_mode_valid,
+	.mode_fixup = sdi_bridge_mode_fixup,
+	.mode_set = sdi_bridge_mode_set,
+	.atomic_enable = sdi_bridge_enable,
+	.atomic_disable = sdi_bridge_disable,
+};
 
-static int sdi_check_timings(struct omap_dss_device *dssdev,
-			     struct drm_display_mode *mode)
+static void sdi_bridge_init(struct sdi_device *sdi)
 {
-	struct sdi_device *sdi = dssdev_to_sdi(dssdev);
-	struct dispc_clock_info dispc_cinfo;
-	unsigned long pixelclock = mode->clock * 1000;
-	unsigned long fck;
-	unsigned long pck;
-	int r;
-
-	if (pixelclock == 0)
-		return -EINVAL;
-
-	r = sdi_calc_clock_div(sdi, pixelclock, &fck, &dispc_cinfo);
-	if (r)
-		return r;
+	sdi->bridge.funcs = &sdi_bridge_funcs;
+	sdi->bridge.of_node = sdi->pdev->dev.of_node;
+	sdi->bridge.type = DRM_MODE_CONNECTOR_LVDS;
 
-	pck = fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div;
-
-	if (pck != pixelclock) {
-		DSSWARN("Pixel clock adjusted from %lu Hz to %lu Hz\n",
-			pixelclock, pck);
-
-		mode->clock = pck / 1000;
-	}
-
-	return 0;
+	drm_bridge_add(&sdi->bridge);
 }
 
-static int sdi_connect(struct omap_dss_device *src,
-		       struct omap_dss_device *dst)
+static void sdi_bridge_cleanup(struct sdi_device *sdi)
 {
-	return omapdss_device_connect(dst->dss, dst, dst->next);
+	drm_bridge_remove(&sdi->bridge);
 }
 
-static void sdi_disconnect(struct omap_dss_device *src,
-			   struct omap_dss_device *dst)
-{
-	omapdss_device_disconnect(dst, dst->next);
-}
-
-static const struct omap_dss_device_ops sdi_ops = {
-	.connect = sdi_connect,
-	.disconnect = sdi_disconnect,
-
-	.enable = sdi_display_enable,
-	.disable = sdi_display_disable,
-
-	.check_timings = sdi_check_timings,
-	.set_timings = sdi_set_timings,
-};
+/* -----------------------------------------------------------------------------
+ * Initialisation and Cleanup
+ */
 
 static int sdi_init_output(struct sdi_device *sdi)
 {
 	struct omap_dss_device *out = &sdi->output;
 	int r;
 
+	sdi_bridge_init(sdi);
+
 	out->dev = &sdi->pdev->dev;
 	out->id = OMAP_DSS_OUTPUT_SDI;
 	out->type = OMAP_DISPLAY_TYPE_SDI;
@@ -266,14 +313,15 @@ static int sdi_init_output(struct sdi_device *sdi)
 	out->dispc_channel = OMAP_DSS_CHANNEL_LCD;
 	/* We have SDI only on OMAP3, where it's on port 1 */
 	out->of_port = 1;
-	out->ops = &sdi_ops;
 	out->owner = THIS_MODULE;
 	out->bus_flags = DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE	/* 15.5.9.1.2 */
 		       | DRM_BUS_FLAG_SYNC_DRIVE_POSEDGE;
 
-	r = omapdss_device_init_output(out, NULL);
-	if (r < 0)
+	r = omapdss_device_init_output(out, &sdi->bridge);
+	if (r < 0) {
+		sdi_bridge_cleanup(sdi);
 		return r;
+	}
 
 	omapdss_device_register(out);
 
@@ -284,6 +332,8 @@ static void sdi_uninit_output(struct sdi_device *sdi)
 {
 	omapdss_device_unregister(&sdi->output);
 	omapdss_device_cleanup_output(&sdi->output);
+
+	sdi_bridge_cleanup(sdi);
 }
 
 int sdi_init_port(struct dss_device *dss, struct platform_device *pdev,
-- 
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-26 11:27 UTC|newest]

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