]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/gpu/drm/nouveau/nvkm/subdev/mxm/mxms.c
2 * Copyright 2012 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.
26 #define ROM16(x) get_unaligned_le16(&(x))
27 #define ROM32(x) get_unaligned_le32(&(x))
30 mxms_data(struct nvkm_mxm
*mxm
)
37 mxms_version(struct nvkm_mxm
*mxm
)
39 u8
*mxms
= mxms_data(mxm
);
40 u16 version
= (mxms
[4] << 8) | mxms
[5];
50 nvkm_debug(&mxm
->subdev
, "unknown version %d.%d\n", mxms
[4], mxms
[5]);
55 mxms_headerlen(struct nvkm_mxm
*mxm
)
61 mxms_structlen(struct nvkm_mxm
*mxm
)
63 return *(u16
*)&mxms_data(mxm
)[6];
67 mxms_checksum(struct nvkm_mxm
*mxm
)
69 u16 size
= mxms_headerlen(mxm
) + mxms_structlen(mxm
);
70 u8
*mxms
= mxms_data(mxm
), sum
= 0;
74 nvkm_debug(&mxm
->subdev
, "checksum invalid\n");
81 mxms_valid(struct nvkm_mxm
*mxm
)
83 u8
*mxms
= mxms_data(mxm
);
84 if (*(u32
*)mxms
!= 0x5f4d584d) {
85 nvkm_debug(&mxm
->subdev
, "signature invalid\n");
89 if (!mxms_version(mxm
) || !mxms_checksum(mxm
))
96 mxms_foreach(struct nvkm_mxm
*mxm
, u8 types
,
97 bool (*exec
)(struct nvkm_mxm
*, u8
*, void *), void *info
)
99 struct nvkm_subdev
*subdev
= &mxm
->subdev
;
100 u8
*mxms
= mxms_data(mxm
);
101 u8
*desc
= mxms
+ mxms_headerlen(mxm
);
102 u8
*fini
= desc
+ mxms_structlen(mxm
) - 1;
103 while (desc
< fini
) {
104 u8 type
= desc
[0] & 0x0f;
110 case 0: /* Output Device Structure */
111 if (mxms_version(mxm
) >= 0x0300)
116 case 1: /* System Cooling Capability Structure */
117 case 2: /* Thermal Structure */
118 case 3: /* Input Power Structure */
121 case 4: /* GPIO Device Structure */
124 entries
= (ROM32(desc
[0]) & 0x01f00000) >> 20;
126 case 5: /* Vendor Specific Structure */
129 case 6: /* Backlight Control Structure */
130 if (mxms_version(mxm
) >= 0x0300) {
133 entries
= (desc
[1] & 0xf0) >> 4;
138 case 7: /* Fan Control Structure */
141 entries
= desc
[1] & 0x07;
144 nvkm_debug(subdev
, "unknown descriptor type %d\n", type
);
148 if (mxm
->subdev
.debug
>= NV_DBG_DEBUG
&& (exec
== NULL
)) {
149 static const char * mxms_desc
[] = {
150 "ODS", "SCCS", "TS", "IPS",
151 "GSD", "VSS", "BCS", "FCS",
157 for (j
= headerlen
- 1, ptr
= data
; j
>= 0; j
--)
158 ptr
+= sprintf(ptr
, "%02x", dump
[j
]);
161 nvkm_debug(subdev
, "%4s: %s\n", mxms_desc
[type
], data
);
162 for (i
= 0; i
< entries
; i
++, dump
+= recordlen
) {
163 for (j
= recordlen
- 1, ptr
= data
; j
>= 0; j
--)
164 ptr
+= sprintf(ptr
, "%02x", dump
[j
]);
165 nvkm_debug(subdev
, " %s\n", data
);
169 if (types
& (1 << type
)) {
170 if (!exec(mxm
, desc
, info
))
174 desc
+= headerlen
+ (entries
* recordlen
);
181 mxms_output_device(struct nvkm_mxm
*mxm
, u8
*pdata
, struct mxms_odev
*desc
)
183 u64 data
= ROM32(pdata
[0]);
184 if (mxms_version(mxm
) >= 0x0300)
185 data
|= (u64
)ROM16(pdata
[4]) << 32;
187 desc
->outp_type
= (data
& 0x00000000000000f0ULL
) >> 4;
188 desc
->ddc_port
= (data
& 0x0000000000000f00ULL
) >> 8;
189 desc
->conn_type
= (data
& 0x000000000001f000ULL
) >> 12;
190 desc
->dig_conn
= (data
& 0x0000000000780000ULL
) >> 19;