diff mbox

[U-Boot,4/5] edid: Add an edid_check_checksum() helper function

Message ID 1416845659-11781-5-git-send-email-hdegoede@redhat.com
State Superseded
Delegated to: Anatolij Gustschin
Headers show

Commit Message

Hans de Goede Nov. 24, 2014, 4:14 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  | 11 +++++++++++
 include/edid.h |  9 +++++++++
 2 files changed, 20 insertions(+)
diff mbox

Patch

diff --git a/common/edid.c b/common/edid.c
index e41cd3e..e5d35b2 100644
--- a/common/edid.c
+++ b/common/edid.c
@@ -353,3 +353,14 @@  int edid_dtd_to_fbmode(struct edid_detailed_timing *t,
 
 	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;
+}
diff --git a/include/edid.h b/include/edid.h
index d66f76b..b32f42c 100644
--- a/include/edid.h
+++ b/include/edid.h
@@ -273,4 +273,13 @@  int edid_get_ranges(struct edid1_info *edid, unsigned int *hmin,
 int edid_dtd_to_fbmode(struct edid_detailed_timing *t,
 		       struct fb_videomode *mode, char *name, int name_len);
 
+/**
+ * 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);
+
 #endif /* __EDID_H_ */