diff mbox

[RFC,v2,3/5] drm: Add HDMI infoframe helpers

Message ID 1354725944-1862-4-git-send-email-thierry.reding@avionic-design.de (mailing list archive)
State New, archived
Headers show

Commit Message

Thierry Reding Dec. 5, 2012, 4:45 p.m. UTC
Add a generic helper to fill in an HDMI AVI infoframe with data
extracted from a DRM display mode.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
---
Changes in v2:
- reuse CEA modes defined in drm_edid_modes.h

 drivers/gpu/drm/Kconfig    |  7 +++++
 drivers/gpu/drm/Makefile   |  1 +
 drivers/gpu/drm/drm_hdmi.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_hdmi.h     | 19 +++++++++++++
 4 files changed, 98 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_hdmi.c
 create mode 100644 include/drm/drm_hdmi.h

Comments

Lars-Peter Clausen Dec. 5, 2012, 5:51 p.m. UTC | #1
On 12/05/2012 05:45 PM, Thierry Reding wrote:
> Add a generic helper to fill in an HDMI AVI infoframe with data
> extracted from a DRM display mode.

That's a very nice patch series, comes in pretty handy. Thanks :)

I've just one comment.

> [...]
> +static inline enum hdmi_picture_aspect
> +drm_display_mode_get_aspect(const struct drm_display_mode *mode)
> +{
> +	enum hdmi_picture_aspect aspect = HDMI_PICTURE_ASPECT_NONE;
> +
> +	if ((mode->hdisplay * 9) / 16 == mode->vdisplay)
> +		aspect = HDMI_PICTURE_ASPECT_16_9;
> +	else if ((mode->hdisplay * 3) / 4 == mode->vdisplay)
> +		aspect = HDMI_PICTURE_ASPECT_4_3;
> +
> +	return aspect;
> +}
> +
> +/**
> + * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
> + *                                              data from a DRM display mode
> + * @frame: HDMI AVI infoframe
> + * @mode: DRM display mode
> + *
> + * Returns 0 on success or a negative error code on failure.
> + */
> +int
> +drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
> +					 const struct drm_display_mode *mode)
> +{
[...]
> +
> +	frame->picture_aspect = drm_display_mode_get_aspect(mode);

As far as I know the picture aspect ratio is supposed to be the aspect ratio
of the displayed content not the pixel aspect ratio. The receiver already
knows the pixel aspect ratio since it knows both the pixel width and the
height. The picture aspect ratio is something that could be set by a
userspace application running in fullscreen, e.g. a video player.

> +	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
> +
> +	return 0;
> +}
Thierry Reding Dec. 6, 2012, 7:28 a.m. UTC | #2
On Wed, Dec 05, 2012 at 06:51:20PM +0100, Lars-Peter Clausen wrote:
> On 12/05/2012 05:45 PM, Thierry Reding wrote:
> > Add a generic helper to fill in an HDMI AVI infoframe with data
> > extracted from a DRM display mode.
> 
> That's a very nice patch series, comes in pretty handy. Thanks :)
> 
> I've just one comment.
> 
> > [...]
> > +static inline enum hdmi_picture_aspect
> > +drm_display_mode_get_aspect(const struct drm_display_mode *mode)
> > +{
> > +	enum hdmi_picture_aspect aspect = HDMI_PICTURE_ASPECT_NONE;
> > +
> > +	if ((mode->hdisplay * 9) / 16 == mode->vdisplay)
> > +		aspect = HDMI_PICTURE_ASPECT_16_9;
> > +	else if ((mode->hdisplay * 3) / 4 == mode->vdisplay)
> > +		aspect = HDMI_PICTURE_ASPECT_4_3;
> > +
> > +	return aspect;
> > +}
> > +
> > +/**
> > + * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
> > + *                                              data from a DRM display mode
> > + * @frame: HDMI AVI infoframe
> > + * @mode: DRM display mode
> > + *
> > + * Returns 0 on success or a negative error code on failure.
> > + */
> > +int
> > +drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
> > +					 const struct drm_display_mode *mode)
> > +{
> [...]
> > +
> > +	frame->picture_aspect = drm_display_mode_get_aspect(mode);
> 
> As far as I know the picture aspect ratio is supposed to be the aspect ratio
> of the displayed content not the pixel aspect ratio. The receiver already
> knows the pixel aspect ratio since it knows both the pixel width and the
> height. The picture aspect ratio is something that could be set by a
> userspace application running in fullscreen, e.g. a video player.

Isn't that what the active aspect ratio is supposed to do? Unfortunately
neither the HDMI specification nor CEA-861-D seem to be very specific
about this. What I did in the above was basically just refactoring from
what the Tegra driver does. None of the other drivers are filling in any
useful values here. Most equipment seems to work just fine if you pass a
zeroed out AVI infoframe. =)

Given that we don't have a way to pass any kind of information to the
kernel about this, the only options we have are to either use this or go
with HDMI_PICTURE_ASPECT_NONE. I suppose that the latter will work fine
too.

Does anybody else have more information about what the correct value for
this is?

Thierry
Lars-Peter Clausen Dec. 6, 2012, 8:28 a.m. UTC | #3
On 12/06/2012 08:28 AM, Thierry Reding wrote:
> On Wed, Dec 05, 2012 at 06:51:20PM +0100, Lars-Peter Clausen wrote:
>> On 12/05/2012 05:45 PM, Thierry Reding wrote:
>>> Add a generic helper to fill in an HDMI AVI infoframe with data
>>> extracted from a DRM display mode.
>>
>> That's a very nice patch series, comes in pretty handy. Thanks :)
>>
>> I've just one comment.
>>
>>> [...]
>>> +static inline enum hdmi_picture_aspect
>>> +drm_display_mode_get_aspect(const struct drm_display_mode *mode)
>>> +{
>>> +	enum hdmi_picture_aspect aspect = HDMI_PICTURE_ASPECT_NONE;
>>> +
>>> +	if ((mode->hdisplay * 9) / 16 == mode->vdisplay)
>>> +		aspect = HDMI_PICTURE_ASPECT_16_9;
>>> +	else if ((mode->hdisplay * 3) / 4 == mode->vdisplay)
>>> +		aspect = HDMI_PICTURE_ASPECT_4_3;
>>> +
>>> +	return aspect;
>>> +}
>>> +
>>> +/**
>>> + * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
>>> + *                                              data from a DRM display mode
>>> + * @frame: HDMI AVI infoframe
>>> + * @mode: DRM display mode
>>> + *
>>> + * Returns 0 on success or a negative error code on failure.
>>> + */
>>> +int
>>> +drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
>>> +					 const struct drm_display_mode *mode)
>>> +{
>> [...]
>>> +
>>> +	frame->picture_aspect = drm_display_mode_get_aspect(mode);
>>
>> As far as I know the picture aspect ratio is supposed to be the aspect ratio
>> of the displayed content not the pixel aspect ratio. The receiver already
>> knows the pixel aspect ratio since it knows both the pixel width and the
>> height. The picture aspect ratio is something that could be set by a
>> userspace application running in fullscreen, e.g. a video player.
> 
> Isn't that what the active aspect ratio is supposed to do? Unfortunately
> neither the HDMI specification nor CEA-861-D seem to be very specific
> about this. What I did in the above was basically just refactoring from
> what the Tegra driver does. None of the other drivers are filling in any
> useful values here. Most equipment seems to work just fine if you pass a
> zeroed out AVI infoframe. =)
> 

The active aspect ratio is for when you have black borders on the sides of your
images. The picture aspect field is for when you for example have non square
pixels, which probably does not happen so often with PC like device.

Hm, btw. I think some HDMI VICs are defined to have non-square pixels like for
example 576p I wonder if we should skip these when we select the VIC. Otherwise
the video data may look stretched when displayed on the HDMI sink.

> Given that we don't have a way to pass any kind of information to the
> kernel about this, the only options we have are to either use this or go
> with HDMI_PICTURE_ASPECT_NONE. I suppose that the latter will work fine
> too.
> 

Agreed. HDMI_PICTURE_ASPECT_NONE should hopefully work.
Daniel Vetter Dec. 6, 2012, 2:09 p.m. UTC | #4
On Wed, Dec 05, 2012 at 05:45:42PM +0100, Thierry Reding wrote:
> Add a generic helper to fill in an HDMI AVI infoframe with data
> extracted from a DRM display mode.
> 
> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>

A few quick comments below.

> ---
> Changes in v2:
> - reuse CEA modes defined in drm_edid_modes.h
> 
>  drivers/gpu/drm/Kconfig    |  7 +++++
>  drivers/gpu/drm/Makefile   |  1 +
>  drivers/gpu/drm/drm_hdmi.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_hdmi.h     | 19 +++++++++++++
>  4 files changed, 98 insertions(+)
>  create mode 100644 drivers/gpu/drm/drm_hdmi.c
>  create mode 100644 include/drm/drm_hdmi.h
> 
> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index 983201b..94a4623 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -69,6 +69,13 @@ config DRM_KMS_CMA_HELPER
>  	help
>  	  Choose this if you need the KMS CMA helper functions
>  
> +config DRM_HDMI
> +	bool
> +	depends on DRM
> +	select HDMI
> +	help
> +	  Choose this if you need the HDMI helper functions
> +
>  config DRM_TDFX
>  	tristate "3dfx Banshee/Voodoo3+"
>  	depends on DRM && PCI
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 6f58c81..4a0b781 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -16,6 +16,7 @@ drm-y       :=	drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
>  
>  drm-$(CONFIG_COMPAT) += drm_ioc32.o
>  drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
> +drm-$(CONFIG_DRM_HDMI) += drm_hdmi.o
>  drm-$(CONFIG_PCI) += ati_pcigart.o
>  
>  drm-usb-y   := drm_usb.o
> diff --git a/drivers/gpu/drm/drm_hdmi.c b/drivers/gpu/drm/drm_hdmi.c
> new file mode 100644
> index 0000000..821ca56
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_hdmi.c
> @@ -0,0 +1,71 @@
> +/*
> + * Copyright (C) 2012 Avionic Design GmbH
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/hdmi.h>
> +
> +#include <drm/drm_crtc.h>
> +#include <drm/drm_hdmi.h>
> +
> +#include "drm_edid_modes.h"

This creates a 2nd copy of that massive table. Imo we could just shovel
the infoframe helpers into the drm_edid.c file - allowing different
helpers to be disabled isn't that useful, since most drivers will want
them pretty much all anyway. Or at least most of them.

> +
> +static inline unsigned int
> +drm_mode_cea_vic(const struct drm_display_mode *mode)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < drm_num_cea_modes; i++)
> +		if (drm_mode_equal(mode, &edid_cea_modes[i]))
> +			return i + 1;
> +
> +	return 0;
> +}

Same function in drm_edid will land through drm-intel tree in drm-next
rsn. I'll send that pull request somewhen next week probably.

http://cgit.freedesktop.org/~danvet/drm-intel/commit/?id=374a868a726eb8a1cb28ba88805e51ce34222f8d

> +
> +static inline enum hdmi_picture_aspect
> +drm_display_mode_get_aspect(const struct drm_display_mode *mode)
> +{
> +	enum hdmi_picture_aspect aspect = HDMI_PICTURE_ASPECT_NONE;
> +
> +	if ((mode->hdisplay * 9) / 16 == mode->vdisplay)
> +		aspect = HDMI_PICTURE_ASPECT_16_9;
> +	else if ((mode->hdisplay * 3) / 4 == mode->vdisplay)
> +		aspect = HDMI_PICTURE_ASPECT_4_3;
> +
> +	return aspect;
> +}
> +
> +/**
> + * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
> + *                                              data from a DRM display mode
> + * @frame: HDMI AVI infoframe
> + * @mode: DRM display mode
> + *
> + * Returns 0 on success or a negative error code on failure.
> + */
> +int
> +drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
> +					 const struct drm_display_mode *mode)
> +{
> +	int err;
> +
> +	if (!frame || !mode)
> +		return -EINVAL;
> +
> +	err = hdmi_avi_infoframe_init(frame);
> +	if (err < 0)
> +		return err;
> +
> +	frame->video_code = drm_mode_cea_vic(mode);
> +	if (!frame->video_code)
> +		return 0;
> +
> +	frame->picture_aspect = drm_display_mode_get_aspect(mode);
> +	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;

Note that the intel avi infoframe in intel_hdmi_set_avi_infoframe also
sets the pixel repeat for double clocked modes with:

	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
		avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;

Cheers, Daniel

> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
> diff --git a/include/drm/drm_hdmi.h b/include/drm/drm_hdmi.h
> new file mode 100644
> index 0000000..e20462d
> --- /dev/null
> +++ b/include/drm/drm_hdmi.h
> @@ -0,0 +1,19 @@
> +/*
> + * Copyright (C) 2012 Avionic Design GmbH
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#ifndef _DRM_HDMI_H_
> +#define _DRM_HDMI_H_
> +
> +struct hdmi_avi_infoframe;
> +struct drm_display_mode;
> +
> +int
> +drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
> +					 const struct drm_display_mode *mode);
> +
> +#endif
> -- 
> 1.8.0.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
Thierry Reding Dec. 6, 2012, 2:28 p.m. UTC | #5
On Thu, Dec 06, 2012 at 03:09:00PM +0100, Daniel Vetter wrote:
> On Wed, Dec 05, 2012 at 05:45:42PM +0100, Thierry Reding wrote:
[...]
> > diff --git a/drivers/gpu/drm/drm_hdmi.c b/drivers/gpu/drm/drm_hdmi.c
> > new file mode 100644
> > index 0000000..821ca56
> > --- /dev/null
> > +++ b/drivers/gpu/drm/drm_hdmi.c
> > @@ -0,0 +1,71 @@
> > +/*
> > + * Copyright (C) 2012 Avionic Design GmbH
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +
> > +#include <linux/hdmi.h>
> > +
> > +#include <drm/drm_crtc.h>
> > +#include <drm/drm_hdmi.h>
> > +
> > +#include "drm_edid_modes.h"
> 
> This creates a 2nd copy of that massive table. Imo we could just shovel
> the infoframe helpers into the drm_edid.c file - allowing different
> helpers to be disabled isn't that useful, since most drivers will want
> them pretty much all anyway. Or at least most of them.

I can move this helper to drm_edid.c. But maybe it might be worth moving
the table from the header into a source file and just export it from
there.

> > +
> > +static inline unsigned int
> > +drm_mode_cea_vic(const struct drm_display_mode *mode)
> > +{
> > +	unsigned int i;
> > +
> > +	for (i = 0; i < drm_num_cea_modes; i++)
> > +		if (drm_mode_equal(mode, &edid_cea_modes[i]))
> > +			return i + 1;
> > +
> > +	return 0;
> > +}
> 
> Same function in drm_edid will land through drm-intel tree in drm-next
> rsn. I'll send that pull request somewhen next week probably.
> 
> http://cgit.freedesktop.org/~danvet/drm-intel/commit/?id=374a868a726eb8a1cb28ba88805e51ce34222f8d

Yes, I'm aware of that patch (I reviewed it =) and I was planning on
dropping the implementation in this patch once the above patch makes
it into linux-next.

> > +/**
> > + * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
> > + *                                              data from a DRM display mode
> > + * @frame: HDMI AVI infoframe
> > + * @mode: DRM display mode
> > + *
> > + * Returns 0 on success or a negative error code on failure.
> > + */
> > +int
> > +drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
> > +					 const struct drm_display_mode *mode)
> > +{
> > +	int err;
> > +
> > +	if (!frame || !mode)
> > +		return -EINVAL;
> > +
> > +	err = hdmi_avi_infoframe_init(frame);
> > +	if (err < 0)
> > +		return err;
> > +
> > +	frame->video_code = drm_mode_cea_vic(mode);
> > +	if (!frame->video_code)
> > +		return 0;
> > +
> > +	frame->picture_aspect = drm_display_mode_get_aspect(mode);
> > +	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
> 
> Note that the intel avi infoframe in intel_hdmi_set_avi_infoframe also
> sets the pixel repeat for double clocked modes with:
> 
> 	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
> 		avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;

I left that in place in the Intel driver, but I suppose we can just as
well move it to the infoframe helpers since it should be a generic
option.

Thierry
Daniel Vetter Dec. 6, 2012, 3:44 p.m. UTC | #6
On Thu, Dec 6, 2012 at 3:28 PM, Thierry Reding
<thierry.reding@avionic-design.de> wrote:
>> Note that the intel avi infoframe in intel_hdmi_set_avi_infoframe also
>> sets the pixel repeat for double clocked modes with:
>>
>>       if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
>>               avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
>
> I left that in place in the Intel driver, but I suppose we can just as
> well move it to the infoframe helpers since it should be a generic
> option.

Yeah, noticed that while reading through the drm/i915 patch ;-) If you
move I think that would be good in a 2nd patch, just in case it blows
up somewhere it's easier for other drivers it'd be easier to
root-cause.
-Daniel
Thierry Reding Dec. 6, 2012, 4:02 p.m. UTC | #7
On Thu, Dec 06, 2012 at 04:44:38PM +0100, Daniel Vetter wrote:
> On Thu, Dec 6, 2012 at 3:28 PM, Thierry Reding
> <thierry.reding@avionic-design.de> wrote:
> >> Note that the intel avi infoframe in intel_hdmi_set_avi_infoframe also
> >> sets the pixel repeat for double clocked modes with:
> >>
> >>       if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
> >>               avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
> >
> > I left that in place in the Intel driver, but I suppose we can just as
> > well move it to the infoframe helpers since it should be a generic
> > option.
> 
> Yeah, noticed that while reading through the drm/i915 patch ;-) If you
> move I think that would be good in a 2nd patch, just in case it blows
> up somewhere it's easier for other drivers it'd be easier to
> root-cause.

Okay, will do.

Thierry
Daniel Vetter Dec. 7, 2012, 7 p.m. UTC | #8
On Wed, Dec 05, 2012 at 05:45:42PM +0100, Thierry Reding wrote:
> Add a generic helper to fill in an HDMI AVI infoframe with data
> extracted from a DRM display mode.
> 
> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>

> +/**
> + * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
> + *                                              data from a DRM display mode
> + * @frame: HDMI AVI infoframe
> + * @mode: DRM display mode
> + *
> + * Returns 0 on success or a negative error code on failure.
> + */

Another request: Can you please integrate the kerneldoc reference into the
drm documentation? That way their a bit more accessible, and the kerneldoc
generation also checks whether the function declaration still matches up
with the kerneldoc - some drm core stuff has gotten ridiculously out of
sync with reality ...
-Daniel

> +int
> +drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
> +					 const struct drm_display_mode *mode)
> +{
> +	int err;
> +
> +	if (!frame || !mode)
> +		return -EINVAL;
> +
> +	err = hdmi_avi_infoframe_init(frame);
> +	if (err < 0)
> +		return err;
> +
> +	frame->video_code = drm_mode_cea_vic(mode);
> +	if (!frame->video_code)
> +		return 0;
> +
> +	frame->picture_aspect = drm_display_mode_get_aspect(mode);
> +	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
> diff --git a/include/drm/drm_hdmi.h b/include/drm/drm_hdmi.h
> new file mode 100644
> index 0000000..e20462d
> --- /dev/null
> +++ b/include/drm/drm_hdmi.h
> @@ -0,0 +1,19 @@
> +/*
> + * Copyright (C) 2012 Avionic Design GmbH
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#ifndef _DRM_HDMI_H_
> +#define _DRM_HDMI_H_
> +
> +struct hdmi_avi_infoframe;
> +struct drm_display_mode;
> +
> +int
> +drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
> +					 const struct drm_display_mode *mode);
> +
> +#endif
> -- 
> 1.8.0.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox

Patch

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 983201b..94a4623 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -69,6 +69,13 @@  config DRM_KMS_CMA_HELPER
 	help
 	  Choose this if you need the KMS CMA helper functions
 
+config DRM_HDMI
+	bool
+	depends on DRM
+	select HDMI
+	help
+	  Choose this if you need the HDMI helper functions
+
 config DRM_TDFX
 	tristate "3dfx Banshee/Voodoo3+"
 	depends on DRM && PCI
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 6f58c81..4a0b781 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -16,6 +16,7 @@  drm-y       :=	drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
+drm-$(CONFIG_DRM_HDMI) += drm_hdmi.o
 drm-$(CONFIG_PCI) += ati_pcigart.o
 
 drm-usb-y   := drm_usb.o
diff --git a/drivers/gpu/drm/drm_hdmi.c b/drivers/gpu/drm/drm_hdmi.c
new file mode 100644
index 0000000..821ca56
--- /dev/null
+++ b/drivers/gpu/drm/drm_hdmi.c
@@ -0,0 +1,71 @@ 
+/*
+ * Copyright (C) 2012 Avionic Design GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/hdmi.h>
+
+#include <drm/drm_crtc.h>
+#include <drm/drm_hdmi.h>
+
+#include "drm_edid_modes.h"
+
+static inline unsigned int
+drm_mode_cea_vic(const struct drm_display_mode *mode)
+{
+	unsigned int i;
+
+	for (i = 0; i < drm_num_cea_modes; i++)
+		if (drm_mode_equal(mode, &edid_cea_modes[i]))
+			return i + 1;
+
+	return 0;
+}
+
+static inline enum hdmi_picture_aspect
+drm_display_mode_get_aspect(const struct drm_display_mode *mode)
+{
+	enum hdmi_picture_aspect aspect = HDMI_PICTURE_ASPECT_NONE;
+
+	if ((mode->hdisplay * 9) / 16 == mode->vdisplay)
+		aspect = HDMI_PICTURE_ASPECT_16_9;
+	else if ((mode->hdisplay * 3) / 4 == mode->vdisplay)
+		aspect = HDMI_PICTURE_ASPECT_4_3;
+
+	return aspect;
+}
+
+/**
+ * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
+ *                                              data from a DRM display mode
+ * @frame: HDMI AVI infoframe
+ * @mode: DRM display mode
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int
+drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
+					 const struct drm_display_mode *mode)
+{
+	int err;
+
+	if (!frame || !mode)
+		return -EINVAL;
+
+	err = hdmi_avi_infoframe_init(frame);
+	if (err < 0)
+		return err;
+
+	frame->video_code = drm_mode_cea_vic(mode);
+	if (!frame->video_code)
+		return 0;
+
+	frame->picture_aspect = drm_display_mode_get_aspect(mode);
+	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
diff --git a/include/drm/drm_hdmi.h b/include/drm/drm_hdmi.h
new file mode 100644
index 0000000..e20462d
--- /dev/null
+++ b/include/drm/drm_hdmi.h
@@ -0,0 +1,19 @@ 
+/*
+ * Copyright (C) 2012 Avionic Design GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _DRM_HDMI_H_
+#define _DRM_HDMI_H_
+
+struct hdmi_avi_infoframe;
+struct drm_display_mode;
+
+int
+drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
+					 const struct drm_display_mode *mode);
+
+#endif