]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/core/subdev/bios/gpio.c
Merge commit '6bb27d7349db51b50c40534710fe164ca0d58902' into omap-timer-for-v3.10
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / core / subdev / bios / gpio.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 <subdev/bios.h>
26 #include <subdev/bios/dcb.h>
27 #include <subdev/bios/gpio.h>
28
29 u16
30 dcb_gpio_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
31 {
32         u16 data = 0x0000;
33         u16 dcb = dcb_table(bios, ver, hdr, cnt, len);
34         if (dcb) {
35                 if (*ver >= 0x30 && *hdr >= 0x0c)
36                         data = nv_ro16(bios, dcb + 0x0a);
37                 else
38                 if (*ver >= 0x22 && nv_ro08(bios, dcb - 1) >= 0x13)
39                         data = nv_ro16(bios, dcb - 0x0f);
40
41                 if (data) {
42                         *ver = nv_ro08(bios, data + 0x00);
43                         if (*ver < 0x30) {
44                                 *hdr = 3;
45                                 *cnt = nv_ro08(bios, data + 0x02);
46                                 *len = nv_ro08(bios, data + 0x01);
47                         } else
48                         if (*ver <= 0x41) {
49                                 *hdr = nv_ro08(bios, data + 0x01);
50                                 *cnt = nv_ro08(bios, data + 0x02);
51                                 *len = nv_ro08(bios, data + 0x03);
52                         } else {
53                                 data = 0x0000;
54                         }
55                 }
56         }
57         return data;
58 }
59
60 u16
61 dcb_gpio_entry(struct nouveau_bios *bios, int idx, int ent, u8 *ver, u8 *len)
62 {
63         u8  hdr, cnt;
64         u16 gpio = !idx ? dcb_gpio_table(bios, ver, &hdr, &cnt, len) : 0x0000;
65         if (gpio && ent < cnt)
66                 return gpio + hdr + (ent * *len);
67         return 0x0000;
68 }
69
70 u16
71 dcb_gpio_parse(struct nouveau_bios *bios, int idx, int ent, u8 *ver, u8 *len,
72                struct dcb_gpio_func *gpio)
73 {
74         u16 data = dcb_gpio_entry(bios, idx, ent, ver, len);
75         if (data) {
76                 if (*ver < 0x40) {
77                         u16 info = nv_ro16(bios, data);
78                         *gpio = (struct dcb_gpio_func) {
79                                 .line = (info & 0x001f) >> 0,
80                                 .func = (info & 0x07e0) >> 5,
81                                 .log[0] = (info & 0x1800) >> 11,
82                                 .log[1] = (info & 0x6000) >> 13,
83                                 .param = !!(info & 0x8000),
84                         };
85                 } else
86                 if (*ver < 0x41) {
87                         u32 info = nv_ro32(bios, data);
88                         *gpio = (struct dcb_gpio_func) {
89                                 .line = (info & 0x0000001f) >> 0,
90                                 .func = (info & 0x0000ff00) >> 8,
91                                 .log[0] = (info & 0x18000000) >> 27,
92                                 .log[1] = (info & 0x60000000) >> 29,
93                                 .param = !!(info & 0x80000000),
94                         };
95                 } else {
96                         u32 info = nv_ro32(bios, data + 0);
97                         u8 info1 = nv_ro32(bios, data + 4);
98                         *gpio = (struct dcb_gpio_func) {
99                                 .line = (info & 0x0000003f) >> 0,
100                                 .func = (info & 0x0000ff00) >> 8,
101                                 .log[0] = (info1 & 0x30) >> 4,
102                                 .log[1] = (info1 & 0xc0) >> 6,
103                                 .param = !!(info & 0x80000000),
104                         };
105                 }
106         }
107
108         return data;
109 }
110
111 u16
112 dcb_gpio_match(struct nouveau_bios *bios, int idx, u8 func, u8 line,
113                u8 *ver, u8 *len, struct dcb_gpio_func *gpio)
114 {
115         u8  hdr, cnt, i = 0;
116         u16 data;
117
118         while ((data = dcb_gpio_parse(bios, idx, i++, ver, len, gpio))) {
119                 if ((line == 0xff || line == gpio->line) &&
120                     (func == 0xff || func == gpio->func))
121                         return data;
122         }
123
124         /* DCB 2.2, fixed TVDAC GPIO data */
125         if ((data = dcb_table(bios, ver, &hdr, &cnt, len))) {
126                 if (*ver >= 0x22 && *ver < 0x30 && func == DCB_GPIO_TVDAC0) {
127                         u8 conf = nv_ro08(bios, data - 5);
128                         u8 addr = nv_ro08(bios, data - 4);
129                         if (conf & 0x01) {
130                                 *gpio = (struct dcb_gpio_func) {
131                                         .func = DCB_GPIO_TVDAC0,
132                                         .line = addr >> 4,
133                                         .log[0] = !!(conf & 0x02),
134                                         .log[1] =  !(conf & 0x02),
135                                 };
136                                 *ver = 0x00;
137                                 return data;
138                         }
139                 }
140         }
141
142         return 0x0000;
143 }