diff mbox

[v3,1/4] drm/crtc: Add property for aspect ratio

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

Commit Message

vandana.kannan@intel.com June 5, 2014, 9:10 a.m. UTC
Added a property to enable user space to set aspect ratio.
This patch contains declaration of the property and code to create the
property.

v2: Thierry's review comments.
	- Made aspect ratio enum generic instead of HDMI/CEA specfic
	- Removed usage of temporary aspect_ratio variable

v3: Thierry's review comments.
	- Fixed indentation drm_mode_create_aspect_ratio_property()

Signed-off-by: Vandana Kannan <vandana.kannan@intel.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
---
 drivers/gpu/drm/drm_crtc.c  | 27 +++++++++++++++++++++++++++
 include/drm/drm_crtc.h      |  2 ++
 include/uapi/drm/drm_mode.h |  5 +++++
 3 files changed, 34 insertions(+)

Comments

Thierry Reding June 5, 2014, 9:28 a.m. UTC | #1
On Thu, Jun 05, 2014 at 02:40:08PM +0530, Vandana Kannan wrote:
[...]
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
[...]
>  /**
> + * drm_mode_create_aspect_ratio_property - create aspect ratio property
> + * @dev: DRM device
> + *
> + * Called by a driver the first time it's needed, must be attached to desired
> + * connectors.
> + */
> +int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
> +{
> +	if (dev->mode_config.aspect_ratio_property)
> +		return 0;
> +
> +	dev->mode_config.aspect_ratio_property =
> +		drm_property_create_enum(dev, 0, "aspect ratio",
> +				drm_aspect_ratio_enum_list,
> +				ARRAY_SIZE(drm_aspect_ratio_enum_list));
> +
> +	return 0;

Sorry for not noticing this before: what if drm_propert_create_enum()
fails? Should that return an error? This function will currently
silently ignore failure to create the property.

Thierry
vandana.kannan@intel.com June 10, 2014, 8:30 a.m. UTC | #2
On Jun-05-2014 2:58 PM, Thierry Reding wrote:
> On Thu, Jun 05, 2014 at 02:40:08PM +0530, Vandana Kannan wrote:
> [...]
>> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> [...]
>>  /**
>> + * drm_mode_create_aspect_ratio_property - create aspect ratio property
>> + * @dev: DRM device
>> + *
>> + * Called by a driver the first time it's needed, must be attached to desired
>> + * connectors.
>> + */
>> +int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
>> +{
>> +	if (dev->mode_config.aspect_ratio_property)
>> +		return 0;
>> +
>> +	dev->mode_config.aspect_ratio_property =
>> +		drm_property_create_enum(dev, 0, "aspect ratio",
>> +				drm_aspect_ratio_enum_list,
>> +				ARRAY_SIZE(drm_aspect_ratio_enum_list));
>> +
>> +	return 0;
> 
> Sorry for not noticing this before: what if drm_propert_create_enum()
> fails? Should that return an error? This function will currently
> silently ignore failure to create the property.
> 
> Thierry
> 
Yes..
I can
1. modify this to return the property (which would be NULL if create
fails) and have a NULL check at the calling end or
2. have a NULL check for the property at the calling end keeping the
existing implementation or
3. return a non-zero value in case of failure.

Please let me know your inputs on this..
- Vandana
Thierry Reding June 10, 2014, 11:15 a.m. UTC | #3
On Tue, Jun 10, 2014 at 02:00:37PM +0530, Vandana Kannan wrote:
> On Jun-05-2014 2:58 PM, Thierry Reding wrote:
> > On Thu, Jun 05, 2014 at 02:40:08PM +0530, Vandana Kannan wrote:
> > [...]
> >> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> > [...]
> >>  /**
> >> + * drm_mode_create_aspect_ratio_property - create aspect ratio property
> >> + * @dev: DRM device
> >> + *
> >> + * Called by a driver the first time it's needed, must be attached to desired
> >> + * connectors.
> >> + */
> >> +int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
> >> +{
> >> +	if (dev->mode_config.aspect_ratio_property)
> >> +		return 0;
> >> +
> >> +	dev->mode_config.aspect_ratio_property =
> >> +		drm_property_create_enum(dev, 0, "aspect ratio",
> >> +				drm_aspect_ratio_enum_list,
> >> +				ARRAY_SIZE(drm_aspect_ratio_enum_list));
> >> +
> >> +	return 0;
> > 
> > Sorry for not noticing this before: what if drm_propert_create_enum()
> > fails? Should that return an error? This function will currently
> > silently ignore failure to create the property.
> > 
> > Thierry
> > 
> Yes..
> I can
> 1. modify this to return the property (which would be NULL if create
> fails) and have a NULL check at the calling end or
> 2. have a NULL check for the property at the calling end keeping the
> existing implementation or
> 3. return a non-zero value in case of failure.

I prefer 3. -ENOMEM sounds like a good candidate here.

Thierry
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 37a3e07..dcbc033 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -139,6 +139,12 @@  static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] =
 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
 };
 
+static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
+	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
+	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
+	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
+};
+
 /*
  * Non-global properties, but "required" for certain connectors.
  */
@@ -1344,6 +1350,27 @@  int drm_mode_create_scaling_mode_property(struct drm_device *dev)
 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
 
 /**
+ * drm_mode_create_aspect_ratio_property - create aspect ratio property
+ * @dev: DRM device
+ *
+ * Called by a driver the first time it's needed, must be attached to desired
+ * connectors.
+ */
+int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
+{
+	if (dev->mode_config.aspect_ratio_property)
+		return 0;
+
+	dev->mode_config.aspect_ratio_property =
+		drm_property_create_enum(dev, 0, "aspect ratio",
+				drm_aspect_ratio_enum_list,
+				ARRAY_SIZE(drm_aspect_ratio_enum_list));
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
+
+/**
  * drm_mode_create_dirty_property - create dirty property
  * @dev: DRM device
  *
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 5c1c31c..1149617 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -801,6 +801,7 @@  struct drm_mode_config {
 
 	/* Optional properties */
 	struct drm_property *scaling_mode_property;
+	struct drm_property *aspect_ratio_property;
 	struct drm_property *dirty_info_property;
 
 	/* dumb ioctl parameters */
@@ -971,6 +972,7 @@  extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
 extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
 				     char *formats[]);
 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
+extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
 extern const char *drm_get_encoder_name(const struct drm_encoder *encoder);
 
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index f104c26..943b377 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -88,6 +88,11 @@ 
 #define DRM_MODE_SCALE_CENTER		2 /* Centered, no scaling */
 #define DRM_MODE_SCALE_ASPECT		3 /* Full screen, preserve aspect */
 
+/* Picture aspect ratio options */
+#define DRM_MODE_PICTURE_ASPECT_NONE	0
+#define DRM_MODE_PICTURE_ASPECT_4_3	1
+#define DRM_MODE_PICTURE_ASPECT_16_9	2
+
 /* Dithering mode options */
 #define DRM_MODE_DITHERING_OFF	0
 #define DRM_MODE_DITHERING_ON	1