[Intel-gfx] [RFC PATCH 3/4] drm/i915/dsi: switch from custom sub-encoder model to drm_bridge

Jani Nikula jani.nikula at intel.com
Fri Sep 20 14:31:36 CEST 2013


Drop intel_dsi_device and intel_dsi_dev_ops, and switch to drm_bridge
and its own drm_bridge_funcs for sub-encoder (panel driver) callbacks.

Push DSI connector creation and initialization to bridge drivers, which
is more natural than the current approach.

Leave the connector callbacks (now prefixed as intel_dsi_connector_*)
around as helpers the bridge drivers can choose to use.

This is fairly straightforward as no panel drivers have been merged yet.

Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
 drivers/gpu/drm/i915/intel_dsi.c |  119 +++++++++-----------------------------
 drivers/gpu/drm/i915/intel_dsi.h |   50 ++++------------
 2 files changed, 38 insertions(+), 131 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dsi.c b/drivers/gpu/drm/i915/intel_dsi.c
index 0d49540..0dff575 100644
--- a/drivers/gpu/drm/i915/intel_dsi.c
+++ b/drivers/gpu/drm/i915/intel_dsi.c
@@ -34,9 +34,13 @@
 #include "intel_dsi_cmd.h"
 
 /* the sub-encoders aka panel drivers */
-static const struct intel_dsi_device intel_dsi_devices[] = {
+struct intel_dsi_device {
+	uint16_t id;
+	struct drm_bridge *(*init)(struct intel_dsi *intel_dsi, uint16_t id);
 };
 
+static const struct intel_dsi_device intel_dsi_devices[] = {
+};
 
 static void vlv_cck_modify(struct drm_i915_private *dev_priv, u32 reg, u32 val,
 			   u32 mask)
@@ -82,46 +86,28 @@ static void band_gap_wa(struct drm_i915_private *dev_priv)
 	msleep(100);
 }
 
-static struct intel_dsi *intel_attached_dsi(struct drm_connector *connector)
-{
-	return container_of(intel_attached_encoder(connector),
-			    struct intel_dsi, base);
-}
-
 static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
 {
-	return intel_dsi->dev.type == INTEL_DSI_VIDEO_MODE;
+	return intel_dsi->type == INTEL_DSI_VIDEO_MODE;
 }
 
 static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
 {
-	return intel_dsi->dev.type == INTEL_DSI_COMMAND_MODE;
+	return intel_dsi->type == INTEL_DSI_COMMAND_MODE;
 }
 
 static bool intel_dsi_compute_config(struct intel_encoder *encoder,
 				     struct intel_crtc_config *config)
 {
-	struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
-						   base);
-	struct intel_connector *intel_connector = intel_dsi->attached_connector;
-	struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
 	struct drm_display_mode *adjusted_mode = &config->adjusted_mode;
 	struct drm_display_mode *mode = &config->requested_mode;
 	struct drm_bridge *bridge = encoder->base.bridge;
 
 	DRM_DEBUG_KMS("\n");
 
-	if (fixed_mode)
-		intel_fixed_panel_mode(fixed_mode, adjusted_mode);
-
 	if (bridge && bridge->funcs->mode_fixup)
 		return bridge->funcs->mode_fixup(bridge, mode, adjusted_mode);
 
-	/* transitional, will go away */
-	if (intel_dsi->dev.dev_ops->mode_fixup)
-		return intel_dsi->dev.dev_ops->mode_fixup(&intel_dsi->dev,
-							  mode, adjusted_mode);
-
 	return true;
 }
 
@@ -184,9 +170,6 @@ static void intel_dsi_enable(struct intel_encoder *encoder)
 
 	if (bridge)
 		bridge->funcs->enable(bridge);
-
-	/* transitional, will go away */
-	intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
 }
 
 static void intel_dsi_disable(struct intel_encoder *encoder)
@@ -203,9 +186,6 @@ static void intel_dsi_disable(struct intel_encoder *encoder)
 	if (bridge)
 		bridge->funcs->disable(bridge);
 
-	/* transitional, will go away */
-	intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
-
 	if (is_vid_mode(intel_dsi)) {
 		dpi_send_cmd(intel_dsi, SHUTDOWN);
 		msleep(10);
@@ -271,12 +251,11 @@ static void intel_dsi_get_config(struct intel_encoder *encoder,
 	/* XXX: read flags, set to adjusted_mode */
 }
 
-static int intel_dsi_mode_valid(struct drm_connector *connector,
-				struct drm_display_mode *mode)
+int intel_dsi_connector_mode_valid(struct drm_connector *connector,
+				   struct drm_display_mode *mode)
 {
 	struct intel_connector *intel_connector = to_intel_connector(connector);
 	struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
-	struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
 
 	DRM_DEBUG_KMS("\n");
 
@@ -292,7 +271,7 @@ static int intel_dsi_mode_valid(struct drm_connector *connector,
 			return MODE_PANEL;
 	}
 
-	return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
+	return MODE_OK;
 }
 
 /* return txclkesc cycles in terms of divider and duration in us */
@@ -493,15 +472,14 @@ static void intel_dsi_mode_set(struct intel_encoder *intel_encoder)
 		bridge->funcs->mode_set(bridge, requested_mode, adjusted_mode);
 }
 
-static enum drm_connector_status
-intel_dsi_detect(struct drm_connector *connector, bool force)
+enum drm_connector_status
+intel_dsi_connector_detect(struct drm_connector *connector, bool force)
 {
-	struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
 	DRM_DEBUG_KMS("\n");
-	return intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
+	return connector_status_connected;
 }
 
-static int intel_dsi_get_modes(struct drm_connector *connector)
+int intel_dsi_connector_get_modes(struct drm_connector *connector)
 {
 	struct intel_connector *intel_connector = to_intel_connector(connector);
 	struct drm_display_mode *mode;
@@ -524,7 +502,7 @@ static int intel_dsi_get_modes(struct drm_connector *connector)
 	return 1;
 }
 
-static void intel_dsi_destroy(struct drm_connector *connector)
+void intel_dsi_connector_destroy(struct drm_connector *connector)
 {
 	struct intel_connector *intel_connector = to_intel_connector(connector);
 
@@ -539,28 +517,13 @@ static const struct drm_encoder_funcs intel_dsi_funcs = {
 	.destroy = intel_encoder_destroy,
 };
 
-static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
-	.get_modes = intel_dsi_get_modes,
-	.mode_valid = intel_dsi_mode_valid,
-	.best_encoder = intel_best_encoder,
-};
-
-static const struct drm_connector_funcs intel_dsi_connector_funcs = {
-	.dpms = intel_connector_dpms,
-	.detect = intel_dsi_detect,
-	.destroy = intel_dsi_destroy,
-	.fill_modes = drm_helper_probe_single_connector_modes,
-};
-
 bool intel_dsi_init(struct drm_device *dev)
 {
+	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_dsi *intel_dsi;
 	struct intel_encoder *intel_encoder;
 	struct drm_encoder *encoder;
-	struct intel_connector *intel_connector;
-	struct drm_connector *connector;
-	struct drm_display_mode *fixed_mode = NULL;
-	const struct intel_dsi_device *dsi;
+	struct drm_bridge *bridge = NULL;
 	unsigned int i;
 
 	DRM_DEBUG_KMS("\n");
@@ -569,17 +532,8 @@ bool intel_dsi_init(struct drm_device *dev)
 	if (!intel_dsi)
 		return false;
 
-	intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
-	if (!intel_connector) {
-		kfree(intel_dsi);
-		return false;
-	}
-
 	intel_encoder = &intel_dsi->base;
 	encoder = &intel_encoder->base;
-	intel_dsi->attached_connector = intel_connector;
-
-	connector = &intel_connector->base;
 
 	drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
 
@@ -594,53 +548,34 @@ bool intel_dsi_init(struct drm_device *dev)
 	intel_encoder->get_hw_state = intel_dsi_get_hw_state;
 	intel_encoder->get_config = intel_dsi_get_config;
 
-	intel_connector->get_hw_state = intel_connector_get_hw_state;
-
 	for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
-		dsi = &intel_dsi_devices[i];
-		intel_dsi->dev = *dsi;
+		const struct intel_dsi_device *dsi = &intel_dsi_devices[i];
 
-		if (dsi->dev_ops->init(&intel_dsi->dev))
+		if (dsi->id && dsi->id != dev_priv->vbt.dsi.panel_id)
+			continue;
+
+		/* bridge creates connector and attaches to encoder */
+		bridge = dsi->init(intel_dsi, dev_priv->vbt.dsi.panel_id);
+		if (!IS_ERR_OR_NULL(bridge))
 			break;
 	}
 
-	if (i == ARRAY_SIZE(intel_dsi_devices)) {
+	if (IS_ERR_OR_NULL(bridge)) {
 		DRM_DEBUG_KMS("no device found\n");
 		goto err;
 	}
 
+	encoder->bridge = bridge;
+
 	intel_encoder->type = INTEL_OUTPUT_DSI;
 	intel_encoder->crtc_mask = (1 << 0); /* XXX */
-
 	intel_encoder->cloneable = false;
-	drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
-			   DRM_MODE_CONNECTOR_DSI);
-
-	drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
-
-	connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
-	connector->interlace_allowed = false;
-	connector->doublescan_allowed = false;
-
-	intel_connector_attach_encoder(intel_connector, intel_encoder);
-
-	drm_sysfs_connector_add(connector);
-
-	fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
-	if (!fixed_mode) {
-		DRM_DEBUG_KMS("no fixed mode\n");
-		goto err;
-	}
-
-	fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
-	intel_panel_init(&intel_connector->panel, fixed_mode);
 
 	return true;
 
 err:
 	drm_encoder_cleanup(&intel_encoder->base);
 	kfree(intel_dsi);
-	kfree(intel_connector);
 
 	return false;
 }
diff --git a/drivers/gpu/drm/i915/intel_dsi.h b/drivers/gpu/drm/i915/intel_dsi.h
index c7765f3..979d781 100644
--- a/drivers/gpu/drm/i915/intel_dsi.h
+++ b/drivers/gpu/drm/i915/intel_dsi.h
@@ -28,50 +28,14 @@
 #include <drm/drm_crtc.h>
 #include "intel_drv.h"
 
-struct intel_dsi_device {
-	unsigned int panel_id;
-	const char *name;
-	int type;
-	const struct intel_dsi_dev_ops *dev_ops;
-	void *dev_priv;
-};
-
-struct intel_dsi_dev_ops {
-	bool (*init)(struct intel_dsi_device *dsi);
-
-	/* This callback must be able to assume DSI commands can be sent */
-	void (*enable)(struct intel_dsi_device *dsi);
-
-	/* This callback must be able to assume DSI commands can be sent */
-	void (*disable)(struct intel_dsi_device *dsi);
-
-	int (*mode_valid)(struct intel_dsi_device *dsi,
-			  struct drm_display_mode *mode);
-
-	bool (*mode_fixup)(struct intel_dsi_device *dsi,
-			   const struct drm_display_mode *mode,
-			   struct drm_display_mode *adjusted_mode);
-
-	void (*mode_set)(struct intel_dsi_device *dsi,
-			 struct drm_display_mode *mode,
-			 struct drm_display_mode *adjusted_mode);
-
-	enum drm_connector_status (*detect)(struct intel_dsi_device *dsi);
-
-	bool (*get_hw_state)(struct intel_dsi_device *dev);
-
-	struct drm_display_mode *(*get_modes)(struct intel_dsi_device *dsi);
-
-	void (*destroy) (struct intel_dsi_device *dsi);
-};
-
 struct intel_dsi {
 	struct intel_encoder base;
 
-	struct intel_dsi_device dev;
-
 	struct intel_connector *attached_connector;
 
+	/* video vs. command mode */
+	int type;
+
 	/* if true, use HS mode, otherwise LP */
 	bool hs;
 
@@ -99,4 +63,12 @@ static inline struct intel_dsi *enc_to_intel_dsi(struct drm_encoder *encoder)
 extern void vlv_enable_dsi_pll(struct intel_encoder *encoder);
 extern void vlv_disable_dsi_pll(struct intel_encoder *encoder);
 
+int intel_dsi_connector_mode_valid(struct drm_connector *connector,
+				   struct drm_display_mode *mode);
+enum drm_connector_status
+intel_dsi_connector_detect(struct drm_connector *connector, bool force);
+int intel_dsi_connector_get_modes(struct drm_connector *connector);
+void intel_dsi_connector_destroy(struct drm_connector *connector);
+
+
 #endif /* _INTEL_DSI_H */
-- 
1.7.9.5




More information about the Intel-gfx mailing list