Linux-libre 3.16.41-gnu
[librecmc/linux-libre.git] / drivers / gpu / drm / nouveau / core / subdev / bios / conn.c
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24
25 #include <core/device.h>
26
27 #include <subdev/bios.h>
28 #include <subdev/bios/dcb.h>
29 #include <subdev/bios/conn.h>
30
31 u32
32 nvbios_connTe(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
33 {
34         u32 dcb = dcb_table(bios, ver, hdr, cnt, len);
35         if (dcb && *ver >= 0x30 && *hdr >= 0x16) {
36                 u32 data = nv_ro16(bios, dcb + 0x14);
37                 if (data) {
38                         *ver = nv_ro08(bios, data + 0);
39                         *hdr = nv_ro08(bios, data + 1);
40                         *cnt = nv_ro08(bios, data + 2);
41                         *len = nv_ro08(bios, data + 3);
42                         return data;
43                 }
44         }
45         return 0x00000000;
46 }
47
48 u32
49 nvbios_connTp(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
50               struct nvbios_connT *info)
51 {
52         u32 data = nvbios_connTe(bios, ver, hdr, cnt, len);
53         memset(info, 0x00, sizeof(*info));
54         switch (!!data * *ver) {
55         case 0x30:
56         case 0x40:
57                 return data;
58         default:
59                 break;
60         }
61         return 0x00000000;
62 }
63
64 u32
65 nvbios_connEe(struct nouveau_bios *bios, u8 idx, u8 *ver, u8 *len)
66 {
67         u8  hdr, cnt;
68         u32 data = nvbios_connTe(bios, ver, &hdr, &cnt, len);
69         if (data && idx < cnt)
70                 return data + hdr + (idx * *len);
71         return 0x00000000;
72 }
73
74 u32
75 nvbios_connEp(struct nouveau_bios *bios, u8 idx, u8 *ver, u8 *len,
76               struct nvbios_connE *info)
77 {
78         u32 data = nvbios_connEe(bios, idx, ver, len);
79         memset(info, 0x00, sizeof(*info));
80         switch (!!data * *ver) {
81         case 0x30:
82         case 0x40:
83                 info->type     =  nv_ro08(bios, data + 0x00);
84                 info->location =  nv_ro08(bios, data + 0x01) & 0x0f;
85                 info->hpd      = (nv_ro08(bios, data + 0x01) & 0x30) >> 4;
86                 info->dp       = (nv_ro08(bios, data + 0x01) & 0xc0) >> 6;
87                 if (*len < 4)
88                         return data;
89                 info->hpd     |= (nv_ro08(bios, data + 0x02) & 0x03) << 2;
90                 info->dp      |=  nv_ro08(bios, data + 0x02) & 0x0c;
91                 info->di       = (nv_ro08(bios, data + 0x02) & 0xf0) >> 4;
92                 info->hpd     |= (nv_ro08(bios, data + 0x03) & 0x07) << 4;
93                 info->sr       = (nv_ro08(bios, data + 0x03) & 0x08) >> 3;
94                 info->lcdid    = (nv_ro08(bios, data + 0x03) & 0x70) >> 4;
95                 return data;
96         default:
97                 break;
98         }
99         return 0x00000000;
100 }