Commit df0e9248 authored by Chris Wilson's avatar Chris Wilson
Browse files

drm/i915: Make the connector->encoder relationship explicit



Currently we have a exact mapping of a connector onto an encoder for its
whole lifetime. Make this an explicit property of the structure and so
simplify the code.

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent f875c15a
Loading
Loading
Loading
Loading
+11 −14
Original line number Diff line number Diff line
@@ -404,8 +404,7 @@ intel_crt_load_detect(struct drm_crtc *crtc, struct intel_encoder *intel_encoder
static enum drm_connector_status intel_crt_detect(struct drm_connector *connector)
{
	struct drm_device *dev = connector->dev;
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
	struct intel_encoder *encoder = intel_attached_encoder(connector);
	struct drm_crtc *crtc;
	int dpms_mode;
	enum drm_connector_status status;
@@ -417,18 +416,18 @@ static enum drm_connector_status intel_crt_detect(struct drm_connector *connecto
			return connector_status_disconnected;
	}

	if (intel_crt_detect_ddc(encoder))
	if (intel_crt_detect_ddc(&encoder->base))
		return connector_status_connected;

	/* for pre-945g platforms use load detect */
	if (encoder->crtc && encoder->crtc->enabled) {
		status = intel_crt_load_detect(encoder->crtc, intel_encoder);
	if (encoder->base.crtc && encoder->base.crtc->enabled) {
		status = intel_crt_load_detect(encoder->base.crtc, encoder);
	} else {
		crtc = intel_get_load_detect_pipe(intel_encoder, connector,
		crtc = intel_get_load_detect_pipe(encoder, connector,
						  NULL, &dpms_mode);
		if (crtc) {
			status = intel_crt_load_detect(crtc, intel_encoder);
			intel_release_load_detect_pipe(intel_encoder,
			status = intel_crt_load_detect(crtc, encoder);
			intel_release_load_detect_pipe(encoder,
						       connector, dpms_mode);
		} else
			status = connector_status_unknown;
@@ -447,13 +446,12 @@ static void intel_crt_destroy(struct drm_connector *connector)
static int intel_crt_get_modes(struct drm_connector *connector)
{
	int ret;
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
	struct intel_encoder *encoder = intel_attached_encoder(connector);
	struct i2c_adapter *ddc_bus;
	struct drm_device *dev = connector->dev;


	ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
	ret = intel_ddc_get_modes(connector, encoder->ddc_bus);
	if (ret || !IS_G4X(dev))
		goto end;

@@ -504,7 +502,7 @@ static const struct drm_connector_funcs intel_crt_connector_funcs = {
static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs = {
	.mode_valid = intel_crt_mode_valid,
	.get_modes = intel_crt_get_modes,
	.best_encoder = intel_attached_encoder,
	.best_encoder = intel_best_encoder,
};

static const struct drm_encoder_funcs intel_crt_enc_funcs = {
@@ -536,8 +534,7 @@ void intel_crt_init(struct drm_device *dev)
	drm_encoder_init(dev, &intel_encoder->base, &intel_crt_enc_funcs,
			 DRM_MODE_ENCODER_DAC);

	drm_mode_connector_attach_encoder(&intel_connector->base,
					  &intel_encoder->base);
	intel_connector_attach_encoder(intel_connector, intel_encoder);

	/* Set up the DDC bus. */
	if (HAS_PCH_SPLIT(dev))
+9 −18
Original line number Diff line number Diff line
@@ -6120,26 +6120,17 @@ void intel_modeset_cleanup(struct drm_device *dev)
/*
 * Return which encoder is currently attached for connector.
 */
struct drm_encoder *intel_attached_encoder (struct drm_connector *connector)
struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
{
	struct drm_mode_object *obj;
	struct drm_encoder *encoder;
	int i;

	for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
		if (connector->encoder_ids[i] == 0)
			break;

		obj = drm_mode_object_find(connector->dev,
                                           connector->encoder_ids[i],
                                           DRM_MODE_OBJECT_ENCODER);
		if (!obj)
			continue;

		encoder = obj_to_encoder(obj);
		return encoder;
	return &intel_attached_encoder(connector)->base;
}
	return NULL;

void intel_connector_attach_encoder(struct intel_connector *connector,
				    struct intel_encoder *encoder)
{
	connector->encoder = encoder;
	drm_mode_connector_attach_encoder(&connector->base,
					  &encoder->base);
}

/*
+12 −11
Original line number Diff line number Diff line
@@ -67,6 +67,12 @@ static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
	return container_of(encoder, struct intel_dp, base.base);
}

static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
{
	return container_of(intel_attached_encoder(connector),
			    struct intel_dp, base);
}

static void intel_dp_start_link_train(struct intel_dp *intel_dp);
static void intel_dp_complete_link_train(struct intel_dp *intel_dp);
static void intel_dp_link_down(struct intel_dp *intel_dp);
@@ -148,8 +154,7 @@ static int
intel_dp_mode_valid(struct drm_connector *connector,
		    struct drm_display_mode *mode)
{
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
	struct intel_dp *intel_dp = intel_attached_dp(connector);
	struct drm_device *dev = connector->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
@@ -1405,8 +1410,7 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
static enum drm_connector_status
ironlake_dp_detect(struct drm_connector *connector)
{
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
	struct intel_dp *intel_dp = intel_attached_dp(connector);
	enum drm_connector_status status;

	/* Panel needs power for AUX to work */
@@ -1436,8 +1440,7 @@ ironlake_dp_detect(struct drm_connector *connector)
static enum drm_connector_status
intel_dp_detect(struct drm_connector *connector)
{
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
	struct intel_dp *intel_dp = intel_attached_dp(connector);
	struct drm_device *dev = intel_dp->base.base.dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	uint32_t temp, bit;
@@ -1480,8 +1483,7 @@ intel_dp_detect(struct drm_connector *connector)

static int intel_dp_get_modes(struct drm_connector *connector)
{
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
	struct intel_dp *intel_dp = intel_attached_dp(connector);
	struct drm_device *dev = intel_dp->base.base.dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	int ret;
@@ -1554,7 +1556,7 @@ static const struct drm_connector_funcs intel_dp_connector_funcs = {
static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
	.get_modes = intel_dp_get_modes,
	.mode_valid = intel_dp_mode_valid,
	.best_encoder = intel_attached_encoder,
	.best_encoder = intel_best_encoder,
};

static const struct drm_encoder_funcs intel_dp_enc_funcs = {
@@ -1674,8 +1676,7 @@ intel_dp_init(struct drm_device *dev, int output_reg)
			 DRM_MODE_ENCODER_TMDS);
	drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);

	drm_mode_connector_attach_encoder(&intel_connector->base,
					  &intel_encoder->base);
	intel_connector_attach_encoder(intel_connector, intel_encoder);
	drm_sysfs_connector_add(connector);

	/* Set up the DDC bus. */
+9 −1
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ struct intel_encoder {

struct intel_connector {
	struct drm_connector base;
	struct intel_encoder *encoder;
};

struct intel_crtc {
@@ -234,7 +235,14 @@ extern void intel_encoder_prepare (struct drm_encoder *encoder);
extern void intel_encoder_commit (struct drm_encoder *encoder);
extern void intel_encoder_destroy(struct drm_encoder *encoder);

extern struct drm_encoder *intel_attached_encoder(struct drm_connector *connector);
static inline struct intel_encoder *intel_attached_encoder(struct drm_connector *connector)
{
	return to_intel_connector(connector)->encoder;
}

extern void intel_connector_attach_encoder(struct intel_connector *connector,
					   struct intel_encoder *encoder);
extern struct drm_encoder *intel_best_encoder(struct drm_connector *connector);

extern struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
						    struct drm_crtc *crtc);
+12 −12
Original line number Diff line number Diff line
@@ -91,6 +91,12 @@ static struct intel_dvo *enc_to_intel_dvo(struct drm_encoder *encoder)
	return container_of(encoder, struct intel_dvo, base.base);
}

static struct intel_dvo *intel_attached_dvo(struct drm_connector *connector)
{
	return container_of(intel_attached_encoder(connector),
			    struct intel_dvo, base);
}

static void intel_dvo_dpms(struct drm_encoder *encoder, int mode)
{
	struct drm_i915_private *dev_priv = encoder->dev->dev_private;
@@ -112,8 +118,7 @@ static void intel_dvo_dpms(struct drm_encoder *encoder, int mode)
static int intel_dvo_mode_valid(struct drm_connector *connector,
				struct drm_display_mode *mode)
{
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_dvo *intel_dvo = enc_to_intel_dvo(encoder);
	struct intel_dvo *intel_dvo = intel_attached_dvo(connector);

	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
		return MODE_NO_DBLESCAN;
@@ -223,16 +228,13 @@ static void intel_dvo_mode_set(struct drm_encoder *encoder,
 */
static enum drm_connector_status intel_dvo_detect(struct drm_connector *connector)
{
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_dvo *intel_dvo = enc_to_intel_dvo(encoder);

	struct intel_dvo *intel_dvo = intel_attached_dvo(connector);
	return intel_dvo->dev.dev_ops->detect(&intel_dvo->dev);
}

static int intel_dvo_get_modes(struct drm_connector *connector)
{
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_dvo *intel_dvo = enc_to_intel_dvo(encoder);
	struct intel_dvo *intel_dvo = intel_attached_dvo(connector);

	/* We should probably have an i2c driver get_modes function for those
	 * devices which will have a fixed set of modes determined by the chip
@@ -280,7 +282,7 @@ static const struct drm_connector_funcs intel_dvo_connector_funcs = {
static const struct drm_connector_helper_funcs intel_dvo_connector_helper_funcs = {
	.mode_valid = intel_dvo_mode_valid,
	.get_modes = intel_dvo_get_modes,
	.best_encoder = intel_attached_encoder,
	.best_encoder = intel_best_encoder,
};

static void intel_dvo_enc_destroy(struct drm_encoder *encoder)
@@ -310,8 +312,7 @@ intel_dvo_get_current_mode(struct drm_connector *connector)
{
	struct drm_device *dev = connector->dev;
	struct drm_i915_private *dev_priv = dev->dev_private;
	struct drm_encoder *encoder = intel_attached_encoder(connector);
	struct intel_dvo *intel_dvo = enc_to_intel_dvo(encoder);
	struct intel_dvo *intel_dvo = intel_attached_dvo(connector);
	uint32_t dvo_val = I915_READ(intel_dvo->dev.dvo_reg);
	struct drm_display_mode *mode = NULL;

@@ -431,8 +432,7 @@ void intel_dvo_init(struct drm_device *dev)
		drm_encoder_helper_add(&intel_encoder->base,
				       &intel_dvo_helper_funcs);

		drm_mode_connector_attach_encoder(&intel_connector->base,
						  &intel_encoder->base);
		intel_connector_attach_encoder(intel_connector, intel_encoder);
		if (dvo->type == INTEL_DVO_CHIP_LVDS) {
			/* For our LVDS chipsets, we should hopefully be able
			 * to dig the fixed panel mode out of the BIOS data.
Loading