Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6
[linux-2.6] / drivers / video / nvidia / nv_of.c
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/config.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/delay.h>
18 #include <linux/pci.h>
19 #include <linux/fb.h>
20
21 #include <asm/io.h>
22
23 #include <asm/prom.h>
24 #include <asm/pci-bridge.h>
25
26 #include "nv_type.h"
27 #include "nv_local.h"
28 #include "nv_proto.h"
29
30 #include "../edid.h"
31
32 int nvidia_probe_of_connector(struct fb_info *info, int conn, u8 **out_edid)
33 {
34         struct nvidia_par *par = info->par;
35         struct device_node *parent, *dp;
36         unsigned char *pedid = NULL;
37         static char *propnames[] = {
38                 "DFP,EDID", "LCD,EDID", "EDID", "EDID1",
39                 "EDID,B", "EDID,A", NULL };
40         int i;
41
42         parent = pci_device_to_OF_node(par->pci_dev);
43         if (parent == NULL)
44                 return -1;
45         if (par->twoHeads) {
46                 char *pname;
47                 int len;
48
49                 for (dp = NULL;
50                      (dp = of_get_next_child(parent, dp)) != NULL;) {
51                         pname = (char *)get_property(dp, "name", NULL);
52                         if (!pname)
53                                 continue;
54                         len = strlen(pname);
55                         if ((pname[len-1] == 'A' && conn == 1) ||
56                             (pname[len-1] == 'B' && conn == 2)) {
57                                 for (i = 0; propnames[i] != NULL; ++i) {
58                                         pedid = (unsigned char *)
59                                                 get_property(dp, propnames[i],
60                                                              NULL);
61                                         if (pedid != NULL)
62                                                 break;
63                                 }
64                                 of_node_put(dp);
65                                 break;
66                         }
67                 }
68         }
69         if (pedid == NULL) {
70                 for (i = 0; propnames[i] != NULL; ++i) {
71                         pedid = (unsigned char *)
72                                 get_property(parent, propnames[i], NULL);
73                         if (pedid != NULL)
74                                 break;
75                 }
76         }
77         if (pedid) {
78                 *out_edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
79                 if (*out_edid == NULL)
80                         return -1;
81                 memcpy(*out_edid, pedid, EDID_LENGTH);
82                 printk(KERN_DEBUG "nvidiafb: Found OF EDID for head %d\n", conn);
83                 return 0;
84         }
85         return -1;
86 }