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.
24 #include <subdev/bios.h>
25 #include <subdev/bios/bit.h>
26 #include <subdev/bios/cstep.h>
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;
35 if (!bit_entry(bios, 'P', &bit_P)) {
36 if (bit_P.version == 2)
37 cstep = nvbios_rd16(bios, bit_P.offset + 0x34);
40 *ver = nvbios_rd08(bios, cstep + 0);
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);
59 nvbios_cstepEe(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
61 u8 cnt, len, xnr, xsz;
62 u16 data = nvbios_cstepTe(bios, ver, hdr, &cnt, &len, &xnr, &xsz);
63 if (data && idx < cnt) {
64 data = data + *hdr + (idx * len);
72 nvbios_cstepEp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
73 struct nvbios_cstepE *info)
75 u16 data = nvbios_cstepEe(bios, idx, ver, hdr);
76 memset(info, 0x00, sizeof(*info));
78 info->pstate = (nvbios_rd16(bios, data + 0x00) & 0x01e0) >> 5;
79 info->index = nvbios_rd08(bios, data + 0x03);
85 nvbios_cstepEm(struct nvkm_bios *bios, u8 pstate, u8 *ver, u8 *hdr,
86 struct nvbios_cstepE *info)
89 while ((data = nvbios_cstepEp(bios, idx++, ver, hdr, info))) {
90 if (info->pstate == pstate)
97 nvbios_cstepXe(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
99 u8 cnt, len, xnr, xsz;
100 u16 data = nvbios_cstepTe(bios, ver, hdr, &cnt, &len, &xnr, &xsz);
101 if (data && idx < xnr) {
102 data = data + *hdr + (cnt * len) + (idx * xsz);
110 nvbios_cstepXp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
111 struct nvbios_cstepX *info)
113 u16 data = nvbios_cstepXe(bios, idx, ver, hdr);
114 memset(info, 0x00, sizeof(*info));
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);