diff mbox

drm/i915: Add property to set HDMI aspect ratio

Message ID 1395721021-22041-1-git-send-email-vandana.kannan@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

vandana.kannan@intel.com March 25, 2014, 4:17 a.m. UTC
Added a property to enable user space to set aspect ratio for HDMI displays.
If there is no user specified value, then PAR_NONE/Automatic option is set
by default. User can select aspect ratio 4:3 or 16:9. The aspect ratio
selected by user would come into effect with a mode set.

Signed-off-by: Vandana Kannan <vandana.kannan@intel.com>
Cc: Jesse Barnes <jesse.barnes@intel.com>
Cc: Vijay Purushothaman <vijay.a.purushothaman@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h    |    1 +
 drivers/gpu/drm/i915/intel_drv.h   |    2 ++
 drivers/gpu/drm/i915/intel_hdmi.c  |   10 ++++++++++
 drivers/gpu/drm/i915/intel_modes.c |   28 ++++++++++++++++++++++++++++
 4 files changed, 41 insertions(+)

Comments

Daniel Vetter March 25, 2014, 9:48 a.m. UTC | #1
On Tue, Mar 25, 2014 at 09:47:01AM +0530, Vandana Kannan wrote:
> Added a property to enable user space to set aspect ratio for HDMI displays.
> If there is no user specified value, then PAR_NONE/Automatic option is set
> by default. User can select aspect ratio 4:3 or 16:9. The aspect ratio
> selected by user would come into effect with a mode set.
> 
> Signed-off-by: Vandana Kannan <vandana.kannan@intel.com>
> Cc: Jesse Barnes <jesse.barnes@intel.com>
> Cc: Vijay Purushothaman <vijay.a.purushothaman@intel.com>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>

Traditionally we do a full modeset to update the property when it is set.
That leads to a redundant modeset right now, but that should go away again
once we have all the atomic stuff. And doing the full modeset is needed
since we don't track this state, and the next modeset might get optimized
to a simple pageflip. Which means there's no easy way to set this value.

For examples see the other property implementations.
-Daniel
> ---
>  drivers/gpu/drm/i915/i915_drv.h    |    1 +
>  drivers/gpu/drm/i915/intel_drv.h   |    2 ++
>  drivers/gpu/drm/i915/intel_hdmi.c  |   10 ++++++++++
>  drivers/gpu/drm/i915/intel_modes.c |   28 ++++++++++++++++++++++++++++
>  4 files changed, 41 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 9b8c1e0..628ba2e 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1588,6 +1588,7 @@ typedef struct drm_i915_private {
>  
>  	struct drm_property *broadcast_rgb_property;
>  	struct drm_property *force_audio_property;
> +	struct drm_property *aspect_ratio_property;
>  
>  	uint32_t hw_context_size;
>  	struct list_head context_list;
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index fa99104..262142f 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -474,6 +474,7 @@ struct intel_hdmi {
>  	bool has_audio;
>  	enum hdmi_force_audio force_audio;
>  	bool rgb_quant_range_selectable;
> +	enum hdmi_picture_aspect aspect_ratio;
>  	void (*write_infoframe)(struct drm_encoder *encoder,
>  				enum hdmi_infoframe_type type,
>  				const void *frame, ssize_t len);
> @@ -834,6 +835,7 @@ int intel_connector_update_modes(struct drm_connector *connector,
>  int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter);
>  void intel_attach_force_audio_property(struct drm_connector *connector);
>  void intel_attach_broadcast_rgb_property(struct drm_connector *connector);
> +void intel_attach_aspect_ratio_property(struct drm_connector *connector);
>  
>  
>  /* intel_overlay.c */
> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> index b0413e1..ae7628e 100644
> --- a/drivers/gpu/drm/i915/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> @@ -367,6 +367,9 @@ static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
>  	union hdmi_infoframe frame;
>  	int ret;
>  
> +	/* Set user selected PAR to incoming mode's member */
> +	adjusted_mode->picture_aspect_ratio = intel_hdmi->aspect_ratio;
> +
>  	ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
>  						       adjusted_mode);
>  	if (ret < 0) {
> @@ -1094,6 +1097,9 @@ intel_hdmi_set_property(struct drm_connector *connector,
>  		goto done;
>  	}
>  
> +	if (property == dev_priv->aspect_ratio_property)
> +		intel_hdmi->aspect_ratio = val;
> +
>  	return -EINVAL;
>  
>  done:
> @@ -1227,6 +1233,7 @@ intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *c
>  {
>  	intel_attach_force_audio_property(connector);
>  	intel_attach_broadcast_rgb_property(connector);
> +	intel_attach_aspect_ratio_property(connector);
>  	intel_hdmi->color_range_auto = true;
>  }
>  
> @@ -1291,6 +1298,9 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
>  		intel_connector->get_hw_state = intel_connector_get_hw_state;
>  	intel_connector->unregister = intel_connector_unregister;
>  
> +	/* Initialize aspect ratio member of intel_hdmi */
> +	intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
> +
>  	intel_hdmi_add_properties(intel_hdmi, connector);
>  
>  	intel_connector_attach_encoder(intel_connector, intel_encoder);
> diff --git a/drivers/gpu/drm/i915/intel_modes.c b/drivers/gpu/drm/i915/intel_modes.c
> index 0e860f3..6f814da 100644
> --- a/drivers/gpu/drm/i915/intel_modes.c
> +++ b/drivers/gpu/drm/i915/intel_modes.c
> @@ -126,3 +126,31 @@ intel_attach_broadcast_rgb_property(struct drm_connector *connector)
>  
>  	drm_object_attach_property(&connector->base, prop, 0);
>  }
> +
> +static const struct drm_prop_enum_list aspect_ratio_names[] = {
> +	{ HDMI_PICTURE_ASPECT_NONE, "Automatic" },
> +	{ HDMI_PICTURE_ASPECT_4_3, "4:3" },
> +	{ HDMI_PICTURE_ASPECT_16_9, "16:9" },
> +};
> +
> +void
> +intel_attach_aspect_ratio_property(struct drm_connector *connector)
> +{
> +	struct drm_device *dev = connector->dev;
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	struct drm_property *prop;
> +
> +	prop = dev_priv->aspect_ratio_property;
> +	if (prop == NULL) {
> +		prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
> +					   "HDMI aspect ratio",
> +					   aspect_ratio_names,
> +					   ARRAY_SIZE(aspect_ratio_names));
> +		if (prop == NULL)
> +			return;
> +
> +		dev_priv->aspect_ratio_property = prop;
> +	}
> +
> +	drm_object_attach_property(&connector->base, prop, 0);
> +}
> -- 
> 1.7.9.5
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 9b8c1e0..628ba2e 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1588,6 +1588,7 @@  typedef struct drm_i915_private {
 
 	struct drm_property *broadcast_rgb_property;
 	struct drm_property *force_audio_property;
+	struct drm_property *aspect_ratio_property;
 
 	uint32_t hw_context_size;
 	struct list_head context_list;
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index fa99104..262142f 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -474,6 +474,7 @@  struct intel_hdmi {
 	bool has_audio;
 	enum hdmi_force_audio force_audio;
 	bool rgb_quant_range_selectable;
+	enum hdmi_picture_aspect aspect_ratio;
 	void (*write_infoframe)(struct drm_encoder *encoder,
 				enum hdmi_infoframe_type type,
 				const void *frame, ssize_t len);
@@ -834,6 +835,7 @@  int intel_connector_update_modes(struct drm_connector *connector,
 int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter);
 void intel_attach_force_audio_property(struct drm_connector *connector);
 void intel_attach_broadcast_rgb_property(struct drm_connector *connector);
+void intel_attach_aspect_ratio_property(struct drm_connector *connector);
 
 
 /* intel_overlay.c */
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index b0413e1..ae7628e 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -367,6 +367,9 @@  static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
 	union hdmi_infoframe frame;
 	int ret;
 
+	/* Set user selected PAR to incoming mode's member */
+	adjusted_mode->picture_aspect_ratio = intel_hdmi->aspect_ratio;
+
 	ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
 						       adjusted_mode);
 	if (ret < 0) {
@@ -1094,6 +1097,9 @@  intel_hdmi_set_property(struct drm_connector *connector,
 		goto done;
 	}
 
+	if (property == dev_priv->aspect_ratio_property)
+		intel_hdmi->aspect_ratio = val;
+
 	return -EINVAL;
 
 done:
@@ -1227,6 +1233,7 @@  intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *c
 {
 	intel_attach_force_audio_property(connector);
 	intel_attach_broadcast_rgb_property(connector);
+	intel_attach_aspect_ratio_property(connector);
 	intel_hdmi->color_range_auto = true;
 }
 
@@ -1291,6 +1298,9 @@  void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
 		intel_connector->get_hw_state = intel_connector_get_hw_state;
 	intel_connector->unregister = intel_connector_unregister;
 
+	/* Initialize aspect ratio member of intel_hdmi */
+	intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
+
 	intel_hdmi_add_properties(intel_hdmi, connector);
 
 	intel_connector_attach_encoder(intel_connector, intel_encoder);
diff --git a/drivers/gpu/drm/i915/intel_modes.c b/drivers/gpu/drm/i915/intel_modes.c
index 0e860f3..6f814da 100644
--- a/drivers/gpu/drm/i915/intel_modes.c
+++ b/drivers/gpu/drm/i915/intel_modes.c
@@ -126,3 +126,31 @@  intel_attach_broadcast_rgb_property(struct drm_connector *connector)
 
 	drm_object_attach_property(&connector->base, prop, 0);
 }
+
+static const struct drm_prop_enum_list aspect_ratio_names[] = {
+	{ HDMI_PICTURE_ASPECT_NONE, "Automatic" },
+	{ HDMI_PICTURE_ASPECT_4_3, "4:3" },
+	{ HDMI_PICTURE_ASPECT_16_9, "16:9" },
+};
+
+void
+intel_attach_aspect_ratio_property(struct drm_connector *connector)
+{
+	struct drm_device *dev = connector->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_property *prop;
+
+	prop = dev_priv->aspect_ratio_property;
+	if (prop == NULL) {
+		prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
+					   "HDMI aspect ratio",
+					   aspect_ratio_names,
+					   ARRAY_SIZE(aspect_ratio_names));
+		if (prop == NULL)
+			return;
+
+		dev_priv->aspect_ratio_property = prop;
+	}
+
+	drm_object_attach_property(&connector->base, prop, 0);
+}