xref: /openbmc/linux/drivers/video/fbdev/nvidia/nv_of.c (revision c4f7ac64)
1 /*
2  * linux/drivers/video/nvidia/nv_of.c
3  *
4  * Copyright 2004 Antonino A. Daplas <adaplas @pol.net>
5  *
6  * Based on rivafb-i2c.c
7  *
8  * This file is subject to the terms and conditions of the GNU General Public
9  * License.  See the file COPYING in the main directory of this archive
10  * for more details.
11  */
12 
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/delay.h>
16 #include <linux/gfp.h>
17 #include <linux/pci.h>
18 #include <linux/fb.h>
19 
20 #include <asm/io.h>
21 
22 #include "nv_type.h"
23 #include "nv_local.h"
24 #include "nv_proto.h"
25 
26 #include "../edid.h"
27 
28 int nvidia_probe_of_connector(struct fb_info *info, int conn, u8 **out_edid)
29 {
30 	struct nvidia_par *par = info->par;
31 	struct device_node *parent, *dp;
32 	const unsigned char *pedid = NULL;
33 	static char *propnames[] = {
34 		"DFP,EDID", "LCD,EDID", "EDID", "EDID1",
35 		"EDID,B", "EDID,A", NULL };
36 	int i;
37 
38 	parent = pci_device_to_OF_node(par->pci_dev);
39 	if (parent == NULL)
40 		return -1;
41 	if (par->twoHeads) {
42 		const char *pname;
43 		int len;
44 
45 		for_each_child_of_node(parent, dp) {
46 			pname = of_get_property(dp, "name", NULL);
47 			if (!pname)
48 				continue;
49 			len = strlen(pname);
50 			if ((pname[len-1] == 'A' && conn == 1) ||
51 			    (pname[len-1] == 'B' && conn == 2)) {
52 				for (i = 0; propnames[i] != NULL; ++i) {
53 					pedid = of_get_property(dp,
54 							propnames[i], NULL);
55 					if (pedid != NULL)
56 						break;
57 				}
58 				of_node_put(dp);
59 				break;
60 			}
61 		}
62 	}
63 	if (pedid == NULL) {
64 		for (i = 0; propnames[i] != NULL; ++i) {
65 			pedid = of_get_property(parent, propnames[i], NULL);
66 			if (pedid != NULL)
67 				break;
68 		}
69 	}
70 	if (pedid) {
71 		*out_edid = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
72 		if (*out_edid == NULL)
73 			return -1;
74 		printk(KERN_DEBUG "nvidiafb: Found OF EDID for head %d\n", conn);
75 		return 0;
76 	}
77 	return -1;
78 }
79