diff mbox

[U-Boot,v2,07/11] edid: Add an edid_check_checksum() helper function

Message ID 1419009041-31057-8-git-send-email-hdegoede@redhat.com
State Accepted
Delegated to: Ian Campbell
Headers show

Commit Message

Hans de Goede Dec. 19, 2014, 5:10 p.m. UTC
Add a helper function to check the checksum of an EDID data block.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 common/edid.c  | 12 ++++++++++++
 include/edid.h |  9 +++++++++
 2 files changed, 21 insertions(+)

Comments

Anatolij Gustschin Jan. 8, 2015, 3:55 p.m. UTC | #1
On Fri, 19 Dec 2014 18:10:37 +0100
Hans de Goede <hdegoede@redhat.com> wrote:

> Add a helper function to check the checksum of an EDID data block.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Acked-by: Anatolij Gustschin <agust@denx.de>
diff mbox

Patch

diff --git a/common/edid.c b/common/edid.c
index e66108f..df797fc 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>
 
@@ -29,6 +30,17 @@  int edid_check_info(struct edid1_info *edid_info)
 	return 0;
 }
 
+int edid_check_checksum(u8 *edid_block)
+{
+	u8 checksum = 0;
+	int i;
+
+	for (i = 0; i < 128; i++)
+		checksum += edid_block[i];
+
+	return (checksum == 0) ? 0 : -EINVAL;
+}
+
 int edid_get_ranges(struct edid1_info *edid, unsigned int *hmin,
 		    unsigned int *hmax, unsigned int *vmin,
 		    unsigned int *vmax)
diff --git a/include/edid.h b/include/edid.h
index d3cc523..a69f43a 100644
--- a/include/edid.h
+++ b/include/edid.h
@@ -246,6 +246,15 @@  void edid_print_info(struct edid1_info *edid_info);
 int edid_check_info(struct edid1_info *info);
 
 /**
+ * Check checksum of a 128 bytes EDID data block
+ *
+ * @param edid_block	EDID block data
+ *
+ * @return 0 on success, or a negative errno on error
+ */
+int edid_check_checksum(u8 *edid_block);
+
+/**
  * Get the horizontal and vertical rate ranges of the monitor.
  *
  * @param edid	The EDID info