aboutsummaryrefslogtreecommitdiffstats
path: root/open_firmware.c
blob: 2170e7064d9179ca5c8f589a6acb11bd0f9ec3fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <sys/types.h>
#include <sys/mman.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "get-edid.h"
#include "minifind.h"

int get_edid(char *edid)
{
	struct pathNode *n;
	struct findNode *list;
	FILE* edid_file = NULL;
	char *path = NULL;

	list = (struct findNode *) malloc(sizeof(struct findNode));
        list->result = (struct pathNode *) malloc(sizeof(struct pathNode));
        list->result->path = NULL;
        list->result->next = list->result;

	minifind("/proc/device-tree", "EDID", list);

	for (n = list->result->next; n != list->result; n = n->next)
	{
		path = n->path;
		break;
	}

	if (path)
		edid_file = fopen(path, "rb");

	if (edid_file)
	{
		int size = fread(edid, sizeof(unsigned char), 0x80, edid_file);
		fclose(edid_file);
		return size == 0x80 ? 0x80 : 0;
	} else
		return 0;

#if 0
	memcpy(&man, &ret->manufacturer_name, 2);
	man = ntohs(man);
	memcpy(&ret->manufacturer_name, &man, 2);

	/* byteswap to match the contents of MonitorsDB */
	ret->product_code = ((ret->product_code >> 8) & 0xff) | ((ret->product_code & 0xff) << 8);
#endif
}