From patchwork Mon Nov 24 16:14:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 414035 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E455C140161 for ; Tue, 25 Nov 2014 03:15:34 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C50974B666; Mon, 24 Nov 2014 17:15:14 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CFC2AwFi7zbB; Mon, 24 Nov 2014 17:15:14 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5B10A4B66F; Mon, 24 Nov 2014 17:14:54 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 195D64B606 for ; Mon, 24 Nov 2014 17:14:44 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uNdp9l3oW2v3 for ; Mon, 24 Nov 2014 17:14:43 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by theia.denx.de (Postfix) with ESMTPS id 11E6F4B60C for ; Mon, 24 Nov 2014 17:14:40 +0100 (CET) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAOGERRZ027247 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 24 Nov 2014 11:14:27 -0500 Received: from shalem.localdomain.com (vpn1-6-228.ams2.redhat.com [10.36.6.228]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAOGELBr016819; Mon, 24 Nov 2014 11:14:26 -0500 From: Hans de Goede To: Anatolij Gustschin , Ian Campbell Date: Mon, 24 Nov 2014 17:14:17 +0100 Message-Id: <1416845659-11781-4-git-send-email-hdegoede@redhat.com> In-Reply-To: <1416845659-11781-1-git-send-email-hdegoede@redhat.com> References: <1416845659-11781-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 3/5] edid: Add an edid_dtd_to_fbmode() helper function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Various u-boot video drivers use fb_videomode structs to store timing info, add a helper function to convert an EDID detailed timing into a fb_videomode struct. Signed-off-by: Hans de Goede --- common/edid.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/edid.h | 18 ++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/common/edid.c b/common/edid.c index e66108f..e41cd3e 100644 --- a/common/edid.c +++ b/common/edid.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -288,3 +289,67 @@ void edid_print_info(struct edid1_info *edid_info) if (!have_timing) printf("\tNone\n"); } + +int edid_dtd_to_fbmode(struct edid_detailed_timing *t, + struct fb_videomode *mode, char *name, int name_len) +{ + int margin, h_total, v_total; + + if (EDID_DETAILED_TIMING_PIXEL_CLOCK(*t) == 0 || + EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(*t) == 0 || + EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*t) == 0 || + EDID_DETAILED_TIMING_VERTICAL_ACTIVE(*t) == 0 || + EDID_DETAILED_TIMING_VERTICAL_BLANKING(*t) == 0 || + EDID_DETAILED_TIMING_HSYNC_OFFSET(*t) == 0 || + EDID_DETAILED_TIMING_HSYNC_PULSE_WIDTH(*t) == 0 || + EDID_DETAILED_TIMING_VSYNC_OFFSET(*t) == 0 || + EDID_DETAILED_TIMING_VSYNC_PULSE_WIDTH(*t) == 0) + return -EINVAL; + + mode->name = name; + mode->xres = EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(*t); + mode->yres = EDID_DETAILED_TIMING_VERTICAL_ACTIVE(*t); + mode->pixclock = (EDID_DETAILED_TIMING_PIXEL_CLOCK(*t) + 500) / + 1000; + + mode->left_margin = EDID_DETAILED_TIMING_HSYNC_OFFSET(*t); + mode->hsync_len = EDID_DETAILED_TIMING_HSYNC_PULSE_WIDTH(*t); + margin = EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*t) - + (mode->left_margin + mode->hsync_len); + if (margin <= 0) + return -EINVAL; + + mode->right_margin = margin; + + mode->lower_margin = EDID_DETAILED_TIMING_VSYNC_OFFSET(*t); + mode->vsync_len = EDID_DETAILED_TIMING_VSYNC_PULSE_WIDTH(*t); + margin = EDID_DETAILED_TIMING_VERTICAL_BLANKING(*t) - + (mode->lower_margin + mode->vsync_len); + if (margin <= 0) + return -EINVAL; + + mode->upper_margin = margin; + + if (EDID_DETAILED_TIMING_FLAG_INTERLEAVED(*t)) + mode->vmode = FB_VMODE_INTERLACED; + else + mode->vmode = FB_VMODE_NONINTERLACED; + + mode->sync = 0; + if (EDID_DETAILED_TIMING_FLAG_HSYNC_POLARITY(*t)) + mode->sync |= FB_SYNC_HOR_HIGH_ACT; + if (EDID_DETAILED_TIMING_FLAG_VSYNC_POLARITY(*t)) + mode->sync |= FB_SYNC_VERT_HIGH_ACT; + + mode->flag = 0; + + h_total = mode->xres + EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*t); + v_total = mode->yres + EDID_DETAILED_TIMING_VERTICAL_BLANKING(*t); + mode->refresh = EDID_DETAILED_TIMING_PIXEL_CLOCK(*t) / + (h_total * v_total); + + snprintf(name, name_len, "%dx%d@%d", mode->xres, mode->yres, + mode->refresh); + + return 0; +} diff --git a/include/edid.h b/include/edid.h index 480a773..d66f76b 100644 --- a/include/edid.h +++ b/include/edid.h @@ -13,6 +13,7 @@ #ifndef __EDID_H_ #define __EDID_H_ +#include #include #define GET_BIT(_x, _pos) \ @@ -86,6 +87,10 @@ struct edid_detailed_timing { GET_BITS((_x).flags, 4, 3) #define EDID_DETAILED_TIMING_FLAG_POLARITY(_x) \ GET_BITS((_x).flags, 2, 1) +#define EDID_DETAILED_TIMING_FLAG_VSYNC_POLARITY(_x) \ + GET_BIT((_x).flags, 2) +#define EDID_DETAILED_TIMING_FLAG_HSYNC_POLARITY(_x) \ + GET_BIT((_x).flags, 1) #define EDID_DETAILED_TIMING_FLAG_INTERLEAVED(_x) \ GET_BIT((_x).flags, 0) } __attribute__ ((__packed__)); @@ -255,4 +260,17 @@ int edid_get_ranges(struct edid1_info *edid, unsigned int *hmin, unsigned int *hmax, unsigned int *vmin, unsigned int *vmax); +/** + * Convert an EDID detailed timing to a fb_videomode + * + * @param t The EDID detailed timing to be converted + * @param mode Returns the converted timing + * @param name Buffer for the mode name mode->name will be set to this + * @param name_len Length of name + * + * @return 0 on success, or a negative errno on error + */ +int edid_dtd_to_fbmode(struct edid_detailed_timing *t, + struct fb_videomode *mode, char *name, int name_len); + #endif /* __EDID_H_ */