[U-Boot] [U-Boot, 3/5] edid: Add an edid_dtd_to_fbmode() helper function
Hans de Goede
hdegoede at redhat.com
Mon Nov 24 22:27:24 CET 2014
Hi,
On 11/24/2014 05:14 PM, Hans de Goede wrote:
> 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 <hdegoede at redhat.com>
> ---
> 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 <common.h>
> #include <edid.h>
> +#include <errno.h>
> #include <linux/ctype.h>
> #include <linux/string.h>
>
> @@ -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;
Note left and right margin are swapped here, I've this fixed in my
local tree.
Regards,
Hans
> +
> + 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 <linux/fb.h>
> #include <linux/types.h>
>
> #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_ */
>
More information about the U-Boot
mailing list