1 | /* $NetBSD: nouveau_subdev_bios_volt.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright 2012 Nouveau Community |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | * and/or sell copies of the Software, and to permit persons to whom the |
11 | * Software is furnished to do so, subject to the following conditions: |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
22 | * OTHER DEALINGS IN THE SOFTWARE. |
23 | * |
24 | * Authors: Martin Peres |
25 | */ |
26 | |
27 | #include <sys/cdefs.h> |
28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_bios_volt.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $" ); |
29 | |
30 | #include <subdev/bios.h> |
31 | #include <subdev/bios/bit.h> |
32 | #include <subdev/bios/volt.h> |
33 | |
34 | u16 |
35 | nvbios_volt_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len) |
36 | { |
37 | struct bit_entry bit_P; |
38 | u16 volt = 0x0000; |
39 | |
40 | if (!bit_entry(bios, 'P', &bit_P)) { |
41 | if (bit_P.version == 2) |
42 | volt = nv_ro16(bios, bit_P.offset + 0x0c); |
43 | else |
44 | if (bit_P.version == 1) |
45 | volt = nv_ro16(bios, bit_P.offset + 0x10); |
46 | |
47 | if (volt) { |
48 | *ver = nv_ro08(bios, volt + 0); |
49 | switch (*ver) { |
50 | case 0x12: |
51 | *hdr = 5; |
52 | *cnt = nv_ro08(bios, volt + 2); |
53 | *len = nv_ro08(bios, volt + 1); |
54 | return volt; |
55 | case 0x20: |
56 | *hdr = nv_ro08(bios, volt + 1); |
57 | *cnt = nv_ro08(bios, volt + 2); |
58 | *len = nv_ro08(bios, volt + 3); |
59 | return volt; |
60 | case 0x30: |
61 | case 0x40: |
62 | case 0x50: |
63 | *hdr = nv_ro08(bios, volt + 1); |
64 | *cnt = nv_ro08(bios, volt + 3); |
65 | *len = nv_ro08(bios, volt + 2); |
66 | return volt; |
67 | } |
68 | } |
69 | } |
70 | |
71 | return 0x0000; |
72 | } |
73 | |
74 | u16 |
75 | nvbios_volt_parse(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len, |
76 | struct nvbios_volt *info) |
77 | { |
78 | u16 volt = nvbios_volt_table(bios, ver, hdr, cnt, len); |
79 | memset(info, 0x00, sizeof(*info)); |
80 | switch (!!volt * *ver) { |
81 | case 0x12: |
82 | info->vidmask = nv_ro08(bios, volt + 0x04); |
83 | break; |
84 | case 0x20: |
85 | info->vidmask = nv_ro08(bios, volt + 0x05); |
86 | break; |
87 | case 0x30: |
88 | info->vidmask = nv_ro08(bios, volt + 0x04); |
89 | break; |
90 | case 0x40: |
91 | info->base = nv_ro32(bios, volt + 0x04); |
92 | info->step = nv_ro16(bios, volt + 0x08); |
93 | info->vidmask = nv_ro08(bios, volt + 0x0b); |
94 | /*XXX*/ |
95 | info->min = 0; |
96 | info->max = info->base; |
97 | break; |
98 | case 0x50: |
99 | info->vidmask = nv_ro08(bios, volt + 0x06); |
100 | info->min = nv_ro32(bios, volt + 0x0a); |
101 | info->max = nv_ro32(bios, volt + 0x0e); |
102 | info->base = nv_ro32(bios, volt + 0x12) & 0x00ffffff; |
103 | info->step = nv_ro16(bios, volt + 0x16); |
104 | break; |
105 | } |
106 | return volt; |
107 | } |
108 | |
109 | u16 |
110 | nvbios_volt_entry(struct nouveau_bios *bios, int idx, u8 *ver, u8 *len) |
111 | { |
112 | u8 hdr, cnt; |
113 | u16 volt = nvbios_volt_table(bios, ver, &hdr, &cnt, len); |
114 | if (volt && idx < cnt) { |
115 | volt = volt + hdr + (idx * *len); |
116 | return volt; |
117 | } |
118 | return 0x0000; |
119 | } |
120 | |
121 | u16 |
122 | nvbios_volt_entry_parse(struct nouveau_bios *bios, int idx, u8 *ver, u8 *len, |
123 | struct nvbios_volt_entry *info) |
124 | { |
125 | u16 volt = nvbios_volt_entry(bios, idx, ver, len); |
126 | memset(info, 0x00, sizeof(*info)); |
127 | switch (!!volt * *ver) { |
128 | case 0x12: |
129 | case 0x20: |
130 | info->voltage = nv_ro08(bios, volt + 0x00) * 10000; |
131 | info->vid = nv_ro08(bios, volt + 0x01); |
132 | break; |
133 | case 0x30: |
134 | info->voltage = nv_ro08(bios, volt + 0x00) * 10000; |
135 | info->vid = nv_ro08(bios, volt + 0x01) >> 2; |
136 | break; |
137 | case 0x40: |
138 | case 0x50: |
139 | break; |
140 | } |
141 | return volt; |
142 | } |
143 | |