summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Jackson <ajax@redhat.com>2009-10-02 13:38:38 -0400
committerAdam Jackson <ajax@redhat.com>2009-10-02 13:38:38 -0400
commita824611d28cfdab57e14146e1f834d1dc26b5d81 (patch)
tree9b0278e586970c4e26a70b3c2a75c2d288fd6bd2
parent782fd3be6f6036be41fcf608ca37d2e1214107aa (diff)
EDID probe
-rw-r--r--edid.c33
-rw-r--r--monitor.c3
2 files changed, 35 insertions, 1 deletions
diff --git a/edid.c b/edid.c
index f97d8ad..01072f1 100644
--- a/edid.c
+++ b/edid.c
@@ -1,8 +1,39 @@
#include "minitru-int.h"
+static const uint8_t header[] = {
+ 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
+};
+
+static uint32_t
+edid_valid_checksum(uint8_t *x)
+{
+ unsigned char sum = 0;
+ int i;
+ for (i = 0; i < 128; i++)
+ sum += x[i];
+ return !sum;
+}
+
static uint32_t edid_probe(struct mt_monitor *mon)
{
- return 0;
+ uint8_t *block = mon->block;
+ int i, blocks;
+
+ if (mon->len < 128 || mon->len % 128)
+ return 0;
+
+ blocks = block[0x7e] + 1;
+ if (blocks * 128 != mon->len)
+ return 0;
+
+ if (!memcmp(block, header, 8))
+ return 0;
+
+ for (i = 0; i < 128; i++)
+ if (!edid_valid_checksum(block + (i * 128)))
+ return 0;
+
+ return 1;
}
static struct mt_mode *
diff --git a/monitor.c b/monitor.c
index 0503cee..3263f3f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -12,6 +12,9 @@ mt_create_monitor(void *block, uint32_t len)
struct mt_monitor *mon = calloc(1, sizeof(*mon));
int i;
+ if (!block || !len)
+ return NULL;
+
mon->block = block;
mon->len = len;