WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nvkm / subdev / bios / cstep.c
blob7c8c36054f71d5d12327ce957b98469973e1b471
1 /*
2 * Copyright 2013 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs
24 #include <subdev/bios.h>
25 #include <subdev/bios/bit.h>
26 #include <subdev/bios/cstep.h>
28 u32
29 nvbios_cstepTe(struct nvkm_bios *bios,
30 u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *xnr, u8 *xsz)
32 struct bit_entry bit_P;
33 u32 cstep = 0;
35 if (!bit_entry(bios, 'P', &bit_P)) {
36 if (bit_P.version == 2 && bit_P.length >= 0x38)
37 cstep = nvbios_rd32(bios, bit_P.offset + 0x34);
39 if (cstep) {
40 *ver = nvbios_rd08(bios, cstep + 0);
41 switch (*ver) {
42 case 0x10:
43 *hdr = nvbios_rd08(bios, cstep + 1);
44 *cnt = nvbios_rd08(bios, cstep + 3);
45 *len = nvbios_rd08(bios, cstep + 2);
46 *xnr = nvbios_rd08(bios, cstep + 5);
47 *xsz = nvbios_rd08(bios, cstep + 4);
48 return cstep;
49 default:
50 break;
55 return 0;
58 u32
59 nvbios_cstepEe(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
61 u8 cnt, len, xnr, xsz;
62 u32 data = nvbios_cstepTe(bios, ver, hdr, &cnt, &len, &xnr, &xsz);
63 if (data && idx < cnt) {
64 data = data + *hdr + (idx * len);
65 *hdr = len;
66 return data;
68 return 0;
71 u32
72 nvbios_cstepEp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
73 struct nvbios_cstepE *info)
75 u32 data = nvbios_cstepEe(bios, idx, ver, hdr);
76 memset(info, 0x00, sizeof(*info));
77 if (data) {
78 info->pstate = (nvbios_rd16(bios, data + 0x00) & 0x01e0) >> 5;
79 info->index = nvbios_rd08(bios, data + 0x03);
81 return data;
84 u32
85 nvbios_cstepEm(struct nvkm_bios *bios, u8 pstate, u8 *ver, u8 *hdr,
86 struct nvbios_cstepE *info)
88 u32 data, idx = 0;
89 while ((data = nvbios_cstepEp(bios, idx++, ver, hdr, info))) {
90 if (info->pstate == pstate)
91 break;
93 return data;
96 u32
97 nvbios_cstepXe(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
99 u8 cnt, len, xnr, xsz;
100 u32 data = nvbios_cstepTe(bios, ver, hdr, &cnt, &len, &xnr, &xsz);
101 if (data && idx < xnr) {
102 data = data + *hdr + (cnt * len) + (idx * xsz);
103 *hdr = xsz;
104 return data;
106 return 0;
110 nvbios_cstepXp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
111 struct nvbios_cstepX *info)
113 u32 data = nvbios_cstepXe(bios, idx, ver, hdr);
114 memset(info, 0x00, sizeof(*info));
115 if (data) {
116 info->freq = nvbios_rd16(bios, data + 0x00) * 1000;
117 info->unkn[0] = nvbios_rd08(bios, data + 0x02);
118 info->unkn[1] = nvbios_rd08(bios, data + 0x03);
119 info->voltage = nvbios_rd08(bios, data + 0x04);
121 return data;