From: Hans de Goede <hdegoede@redhat.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [U-Boot, 3/5] edid: Add an edid_dtd_to_fbmode() helper function
Date: Mon, 24 Nov 2014 22:27:24 +0100 [thread overview]
Message-ID: <5473A2BC.1050708@redhat.com> (raw)
In-Reply-To: <1416845659-11781-4-git-send-email-hdegoede@redhat.com>
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@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_ */
>
next prev parent reply other threads:[~2014-11-24 21:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-24 16:14 [U-Boot] [PATCH 0/5] sunxi: display: Add DDC & EDID support Hans de Goede
2014-11-24 16:14 ` [U-Boot] [PATCH 1/5] sunxi: display: Remove unused HDMI register addr defines Hans de Goede
2014-11-24 16:21 ` Ian Campbell
2014-11-24 19:39 ` Anatolij Gustschin
2014-11-24 16:14 ` [U-Boot] [PATCH 2/5] sunxi: display: Do not use eprintf in early boot Hans de Goede
2014-11-24 16:21 ` Ian Campbell
2014-11-24 19:40 ` Anatolij Gustschin
2014-11-24 16:14 ` [U-Boot] [PATCH 3/5] edid: Add an edid_dtd_to_fbmode() helper function Hans de Goede
2014-11-24 21:27 ` Hans de Goede [this message]
2014-11-24 16:14 ` [U-Boot] [PATCH 4/5] edid: Add an edid_check_checksum() " Hans de Goede
2014-11-24 16:14 ` [U-Boot] [PATCH 5/5] sunxi: display: Add DDC & EDID support Hans de Goede
2014-11-25 8:53 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5473A2BC.1050708@redhat.com \
--to=hdegoede@redhat.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.