From patchwork Wed Nov 21 15:01:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1781281 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 1F332DF230 for ; Wed, 21 Nov 2012 15:08:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 191BAE64C6 for ; Wed, 21 Nov 2012 07:08:10 -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.17.9]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C149E5C54 for ; Wed, 21 Nov 2012 07:02:02 -0800 (PST) Received: from mailbox.adnet.avionic-design.de (mailbox.avionic-design.de [109.75.18.3]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0LznVv-1TFnL42dtL-014sTP; Wed, 21 Nov 2012 16:01:58 +0100 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id C56F52A280F4; Wed, 21 Nov 2012 16:01:56 +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 z0IrTqO4jOrv; Wed, 21 Nov 2012 16:01:55 +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 1E4442A280F2; Wed, 21 Nov 2012 16:01:55 +0100 (CET) From: Thierry Reding To: Dave Airlie Subject: [RFC 1/2] video: Add generic HDMI helpers Date: Wed, 21 Nov 2012 16:01:52 +0100 Message-Id: <1353510113-4388-2-git-send-email-thierry.reding@avionic-design.de> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1353510113-4388-1-git-send-email-thierry.reding@avionic-design.de> References: <1353510113-4388-1-git-send-email-thierry.reding@avionic-design.de> X-Provags-ID: V02:K0:QUTnPUSjSnUEsYGQYVKiFTYvSb8bmlgcwyhXomJPJhV Ftons4EPTnW+7Yn/KL4b4wDTGiTEUGE/5OROpYSLUCz33jppbR 8UWlbrs97ShbwNC3P2R7WtZPUGeynM/faEhvWp6Le4MSjWqUhj iqkEC2JSCmZhbamGvxEWNgTKiV/GVGZO2OLIzYAg/kC6P7WRwN E+X0isnV71U6YhDYygne5ZFlqMCY14erHKv3W+6+kP/AHFQjGt VnbdgGSExdHE1w8f/DbH7ldhleuP9f/oAUFZ6Nkc0mfSYEpl77 1T2P4DT9bPkvqpiZU6ChdX+EYQSLVbWURrH9LwpmXimdzj2pMa 80+PwpmV21wgG5fnztTGPmrbsXlMZ8Xkil3iMWszgG58D7+emb kcHsu0Pp0REcomvpaM+C5C4+JorvRQ1pX/XQScqnlZ0clRX2Pe kh2AY Cc: dri-devel@lists.freedesktop.org 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 generic helpers to pack HDMI infoframes into a binary buffers. Signed-off-by: Thierry Reding --- drivers/video/Kconfig | 3 ++ drivers/video/Makefile | 1 + drivers/video/hdmi.c | 84 ++++++++++++++++++++++++++++++++++ include/linux/hdmi.h | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 207 insertions(+) create mode 100644 drivers/video/hdmi.c create mode 100644 include/linux/hdmi.h diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index fb9a14e..17ac897 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -52,6 +52,9 @@ config OF_VIDEOMODE help helper to get videomodes from the devicetree +config HDMI + bool + menuconfig FB tristate "Support for frame buffer devices" ---help--- diff --git a/drivers/video/Makefile b/drivers/video/Makefile index b936b00..d1d38ea 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -5,6 +5,7 @@ # Each configuration option enables a list of files. obj-$(CONFIG_VGASTATE) += vgastate.o +obj-$(CONFIG_HDMI) += hdmi.o obj-y += fb_notify.o obj-$(CONFIG_FB) += fb.o fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o \ diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c new file mode 100644 index 0000000..3d6ee5e --- /dev/null +++ b/drivers/video/hdmi.c @@ -0,0 +1,84 @@ +/* + * 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 + +/** + * hdmi_avi_infoframe_pack() - write HDMI AVI infoframe to binary buffer + * @frame: HDMI AVI infoframe + * @buffer: destination buffer + * @size: size of buffer + * + * Packs the information contained in the @frame structure into a binary + * representation that can be written into the corresponding controller + * registers. Also computes the checksum as required by section 5.3.5 of the + * HDMI 1.4 specification. + */ +ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer, + size_t size) +{ + u8 *ptr = buffer; + unsigned int i; + u8 csum = 0; + + if (frame->length > 0x1f) + return -EINVAL; + + ptr[0] = frame->type; + ptr[1] = frame->version; + ptr[2] = frame->length; + ptr[3] = 0; /* checksum */ + ptr[4] = ((frame->colorspace & 0x3) << 5) | (frame->scan_mode & 0x3); + + if (frame->active_info_valid) + ptr[4] |= BIT(4); + + if (frame->horizontal_bar_valid) + ptr[4] |= BIT(3); + + if (frame->vertical_bar_valid) + ptr[4] |= BIT(2); + + ptr[5] = ((frame->colorimetry & 0x3) << 6) | + ((frame->picture_aspect & 0x3) << 4) | + (frame->active_aspect & 0xf); + + ptr[6] = ((frame->extended_colorimetry & 0x7) << 4) | + ((frame->quantization_range & 0x3) << 2) | + (frame->nups & 0x3); + + if (frame->itc) + ptr[6] |= BIT(7); + + ptr[7] = frame->video_code & 0x7f; + + ptr[8] = ((frame->ycc_quantization_range & 0x3) << 6) | + ((frame->content_type & 0x3) << 4) | + (frame->pixel_repeat & 0xf); + + ptr[9] = frame->top_bar & 0xff; + ptr[10] = (frame->top_bar >> 8) & 0xff; + ptr[11] = frame->bottom_bar & 0xff; + ptr[12] = (frame->bottom_bar >> 8) & 0xff; + ptr[13] = frame->left_bar & 0xff; + ptr[14] = (frame->left_bar >> 8) & 0xff; + ptr[15] = frame->right_bar & 0xff; + ptr[16] = (frame->right_bar >> 8) & 0xff; + + /* compute checksum */ + for (i = 0; i < 4 + frame->length; i++) + csum += ptr[i]; + + ptr[3] = 256 - csum; + + return 4 + frame->length; +} +EXPORT_SYMBOL_GPL(hdmi_avi_infoframe_pack); diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h new file mode 100644 index 0000000..132556f --- /dev/null +++ b/include/linux/hdmi.h @@ -0,0 +1,119 @@ +/* + * 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 __LINUX_HDMI_H_ +#define __LINUX_HDMI_H_ + +#include + +enum hdmi_infoframe_type { + HDMI_INFOFRAME_TYPE_AVI, +}; + +enum hdmi_colorspace { + HDMI_COLORSPACE_RGB, + HDMI_COLORSPACE_YUV422, + HDMI_COLORSPACE_YUV444, +}; + +enum hdmi_scan_mode { + HDMI_SCAN_MODE_NONE, + HDMI_SCAN_MODE_OVERSCAN, + HDMI_SCAN_MODE_UNDERSCAN, +}; + +enum hdmi_colorimetry { + HDMI_COLORIMETRY_NONE, + HDMI_COLORIMETRY_ITU_601, + HDMI_COLORIMETRY_ITU_709, + HDMI_COLORIMETRY_EXTENDED, +}; + +enum hdmi_picture_aspect { + HDMI_PICTURE_ASPECT_NONE, + HDMI_PICTURE_ASPECT_4_3, + HDMI_PICTURE_ASPECT_16_9, +}; + +enum hdmi_active_aspect { + HDMI_ACTIVE_ASPECT_16_9_TOP = 2, + HDMI_ACTIVE_ASPECT_14_9_TOP = 3, + HDMI_ACTIVE_ASPECT_16_9_CENTER = 4, + HDMI_ACTIVE_ASPECT_PICTURE = 8, + HDMI_ACTIVE_ASPECT_4_3 = 9, + HDMI_ACTIVE_ASPECT_16_9 = 10, + HDMI_ACTIVE_ASPECT_14_9 = 11, + HDMI_ACTIVE_ASPECT_4_3_SP_14_9 = 13, + HDMI_ACTIVE_ASPECT_16_9_SP_14_9 = 14, + HDMI_ACTIVE_ASPECT_16_9_SP_4_3 = 15, +}; + +enum hdmi_extended_colorimetry { + HDMI_EXTENDED_COLORIMETRY_XV_YCC_601, + HDMI_EXTENDED_COLORIMETRY_XV_YCC_709, + HDMI_EXTENDED_COLORIMETRY_S_YCC_601, + HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601, + HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB, +}; + +enum hdmi_quantization_range { + HDMI_QUANTIZATION_RANGE_DEFAULT, + HDMI_QUANTIZATION_RANGE_LIMITED, + HDMI_QUANTIZATION_RANGE_FULL, +}; + +/* non-uniform picture scaling */ +enum hdmi_nups { + HDMI_NUPS_UNKNOWN, + HDMI_NUPS_HORIZONTAL, + HDMI_NUPS_VERTICAL, + HDMI_NUPS_BOTH, +}; + +enum hdmi_ycc_quantization_range { + HDMI_YCC_QUANTIZATION_RANGE_LIMITED, + HDMI_YCC_QUANTIZATION_RANGE_FULL, +}; + +enum hdmi_content_type { + HDMI_CONTENT_TYPE_NONE, + HDMI_CONTENT_TYPE_PHOTO, + HDMI_CONTENT_TYPE_CINEMA, + HDMI_CONTENT_TYPE_GAME, +}; + +struct hdmi_avi_infoframe { + enum hdmi_infoframe_type type; + unsigned char version; + unsigned char length; + enum hdmi_colorspace colorspace; + bool active_info_valid; + bool horizontal_bar_valid; + bool vertical_bar_valid; + enum hdmi_scan_mode scan_mode; + enum hdmi_colorimetry colorimetry; + enum hdmi_picture_aspect picture_aspect; + enum hdmi_active_aspect active_aspect; + bool itc; + enum hdmi_extended_colorimetry extended_colorimetry; + enum hdmi_quantization_range quantization_range; + enum hdmi_nups nups; + unsigned char video_code; + enum hdmi_ycc_quantization_range ycc_quantization_range; + enum hdmi_content_type content_type; + unsigned char pixel_repeat; + unsigned short top_bar; + unsigned short bottom_bar; + unsigned short left_bar; + unsigned short right_bar; +}; + +ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer, + size_t size); + +#endif /* _DRM_HDMI_H */