From patchwork Wed Dec 5 16:45:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1842231 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 146963FCF2 for ; Wed, 5 Dec 2012 16:48:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F2A05E65A4 for ; Wed, 5 Dec 2012 08:48:36 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.187]) by gabe.freedesktop.org (Postfix) with ESMTP id 6F5B4E656E for ; Wed, 5 Dec 2012 08:45:51 -0800 (PST) Received: from mailbox.adnet.avionic-design.de (mailbox.avionic-design.de [109.75.18.3]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0M05tI-1TLSQk1wC4-00uhjl; Wed, 05 Dec 2012 17:45:50 +0100 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id CE32D2A2810A for ; Wed, 5 Dec 2012 17:45:49 +0100 (CET) X-Virus-Scanned: amavisd-new at avionic-design.de Received: from mailbox.adnet.avionic-design.de ([127.0.0.1]) by localhost (mailbox.avionic-design.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s0GMlTCVV3eS for ; Wed, 5 Dec 2012 17:45:48 +0100 (CET) Received: from localhost (avionic-0098.adnet.avionic-design.de [172.20.31.233]) (Authenticated sender: thierry.reding) by mailbox.adnet.avionic-design.de (Postfix) with ESMTPA id 071422A280FC for ; Wed, 5 Dec 2012 17:45:48 +0100 (CET) From: Thierry Reding To: dri-devel@lists.freedesktop.org Subject: [RFC v2 3/5] drm: Add HDMI infoframe helpers Date: Wed, 5 Dec 2012 17:45:42 +0100 Message-Id: <1354725944-1862-4-git-send-email-thierry.reding@avionic-design.de> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1354725944-1862-1-git-send-email-thierry.reding@avionic-design.de> References: <1354725944-1862-1-git-send-email-thierry.reding@avionic-design.de> X-Provags-ID: V02:K0:fbTYbyP59lZgJ6JLjj1p3vYmddsNz3OLzotbVv0xSne mEz1bHiVJ0KvPue3B0SeBVo6a/ETU5S4Fj2s/Wa7vwo40oo5MY 5bRaFPeqC64X9zsGEi/Uosvop9SKEvqy1yyw+OiuJrTdsxBroO SvYcv7gy6rDRQ3W6yi+CoUXUP4z7b3AdyW14SfcKQIolqZb9wV cTijoey0zS5I9GE/LRzzJQAYg81PdXnAPba5YRvBEcF4pLn2cN u0ugqv/eRfpoC7yYkQQ84o2dwuwkS5iBAdR3Nq78WkxH8kLYJp G25d86Y/Eop3cnpyWMYP4O78QnCYwIT1x5tqdWvVmMRVMhNvpJ TNzlddSRd43nCV8VV+MxPzpVS5HnOEKwhfi6JFM6eif+wvDyv5 DZoO83X/0O3KmCcB01VOZsFIP3gvRwqOaG8asfp9BPERa331xJ Rrwv/ X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Add a generic helper to fill in an HDMI AVI infoframe with data extracted from a DRM display mode. Signed-off-by: Thierry Reding --- 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 + +#include +#include + +#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