videomodes: Add video_edid_dtd_to_ctfb_res_modes helper function
authorHans de Goede <hdegoede@redhat.com>
Fri, 19 Dec 2014 14:47:37 +0000 (15:47 +0100)
committerHans de Goede <hdegoede@redhat.com>
Wed, 14 Jan 2015 13:56:38 +0000 (14:56 +0100)
Add a video_edid_dtd_to_ctfb_res_modes helper function to convert an EDID
detailed timing to a struct ctfb_res_modes.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Anatolij Gustschin <agust@denx.de>
drivers/video/videomodes.c
drivers/video/videomodes.h
include/edid.h

index 40c3315aa9ef89ed54887169f6a5b7a3eb076e29..cf71ad120ecef3ab2fe49ff4fdb09db5123fdcae 100644 (file)
@@ -58,6 +58,8 @@
 ****************************************************************************/
 
 #include <common.h>
+#include <edid.h>
+#include <errno.h>
 #include <linux/ctype.h>
 
 #include "videomodes.h"
@@ -373,3 +375,73 @@ int video_get_option_int(const char *options, const char *name, int def)
        }
        return def;
 }
+
+/**
+ * Convert an EDID detailed timing to a struct ctfb_res_modes
+ *
+ * @param t            The EDID detailed timing to be converted
+ * @param mode         Returns the converted timing
+ *
+ * @return 0 on success, or a negative errno on error
+ */
+int video_edid_dtd_to_ctfb_res_modes(struct edid_detailed_timing *t,
+                                    struct ctfb_res_modes *mode)
+{
+       int margin, h_total, v_total;
+
+       /* Check all timings are non 0 */
+       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 ||
+           /* 3d formats are not supported*/
+           EDID_DETAILED_TIMING_FLAG_STEREO(*t) != 0)
+               return -EINVAL;
+
+       mode->xres = EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(*t);
+       mode->yres = EDID_DETAILED_TIMING_VERTICAL_ACTIVE(*t);
+
+       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);
+
+       mode->pixclock_khz = EDID_DETAILED_TIMING_PIXEL_CLOCK(*t) / 1000;
+       mode->pixclock = 1000000000L / mode->pixclock_khz;
+
+       mode->right_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->right_margin + mode->hsync_len);
+       if (margin <= 0)
+               return -EINVAL;
+
+       mode->left_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;
+
+       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;
+
+       if (EDID_DETAILED_TIMING_FLAG_INTERLACED(*t))
+               mode->vmode = FB_VMODE_INTERLACED;
+       else
+               mode->vmode = FB_VMODE_NONINTERLACED;
+
+       return 0;
+}
index 047b8a9838b616c8fdc436e0281637778c310695..82190a2aecf7c6f7db378bef113f3eb0fe2aad5f 100644 (file)
@@ -5,6 +5,7 @@
  * SPDX-License-Identifier:    GPL-2.0+
  */
 
+#include <edid.h>
 
 #ifndef CONFIG_SYS_DEFAULT_VIDEO_MODE
 #define CONFIG_SYS_DEFAULT_VIDEO_MODE  0x301
@@ -89,3 +90,6 @@ void video_get_option_string(const char *options, const char *name,
                             char *dest, int dest_len, const char *def);
 
 int video_get_option_int(const char *options, const char *name, int def);
+
+int video_edid_dtd_to_ctfb_res_modes(struct edid_detailed_timing *t,
+                                    struct ctfb_res_modes *mode);
index 480a773d0f64f49c9d7148f714fbcfc7b4bb7728..d3cc5232dec8e87d18fab5f394d34d90f3267414 100644 (file)
@@ -86,6 +86,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__));