xref: /linux/drivers/gpu/drm/nouveau/nvkm/engine/disp/hdmi.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1b7019ac5SIlia Mirkin // SPDX-License-Identifier: MIT
2af85389cSBen Skeggs #include "hdmi.h"
3af85389cSBen Skeggs 
pack_hdmi_infoframe(struct packed_hdmi_infoframe * packed_frame,u8 * raw_frame,ssize_t len)4af85389cSBen Skeggs void pack_hdmi_infoframe(struct packed_hdmi_infoframe *packed_frame,
5af85389cSBen Skeggs 			 u8 *raw_frame, ssize_t len)
6af85389cSBen Skeggs {
7af85389cSBen Skeggs 	u32 header = 0;
8af85389cSBen Skeggs 	u32 subpack0_low = 0;
9af85389cSBen Skeggs 	u32 subpack0_high = 0;
10af85389cSBen Skeggs 	u32 subpack1_low = 0;
11af85389cSBen Skeggs 	u32 subpack1_high = 0;
12af85389cSBen Skeggs 
13af85389cSBen Skeggs 	switch (len) {
14af85389cSBen Skeggs 		/*
15af85389cSBen Skeggs 		 * "When in doubt, use brute force."
16af85389cSBen Skeggs 		 *     -- Ken Thompson.
17af85389cSBen Skeggs 		 */
18af85389cSBen Skeggs 	default:
19af85389cSBen Skeggs 		/*
20af85389cSBen Skeggs 		 * We presume that no valid frame is longer than 17
21af85389cSBen Skeggs 		 * octets, including header...  And truncate to that
22af85389cSBen Skeggs 		 * if it's longer.
23af85389cSBen Skeggs 		 */
24af85389cSBen Skeggs 	case 17:
25af85389cSBen Skeggs 		subpack1_high = (raw_frame[16] << 16);
26*f6e7393eSGustavo A. R. Silva 		fallthrough;
27af85389cSBen Skeggs 	case 16:
28af85389cSBen Skeggs 		subpack1_high |= (raw_frame[15] << 8);
29*f6e7393eSGustavo A. R. Silva 		fallthrough;
30af85389cSBen Skeggs 	case 15:
31af85389cSBen Skeggs 		subpack1_high |= raw_frame[14];
32*f6e7393eSGustavo A. R. Silva 		fallthrough;
33af85389cSBen Skeggs 	case 14:
34af85389cSBen Skeggs 		subpack1_low = (raw_frame[13] << 24);
35*f6e7393eSGustavo A. R. Silva 		fallthrough;
36af85389cSBen Skeggs 	case 13:
37af85389cSBen Skeggs 		subpack1_low |= (raw_frame[12] << 16);
38*f6e7393eSGustavo A. R. Silva 		fallthrough;
39af85389cSBen Skeggs 	case 12:
40af85389cSBen Skeggs 		subpack1_low |= (raw_frame[11] << 8);
41*f6e7393eSGustavo A. R. Silva 		fallthrough;
42af85389cSBen Skeggs 	case 11:
43af85389cSBen Skeggs 		subpack1_low |= raw_frame[10];
44*f6e7393eSGustavo A. R. Silva 		fallthrough;
45af85389cSBen Skeggs 	case 10:
46af85389cSBen Skeggs 		subpack0_high = (raw_frame[9] << 16);
47*f6e7393eSGustavo A. R. Silva 		fallthrough;
48af85389cSBen Skeggs 	case 9:
49af85389cSBen Skeggs 		subpack0_high |= (raw_frame[8] << 8);
50*f6e7393eSGustavo A. R. Silva 		fallthrough;
51af85389cSBen Skeggs 	case 8:
52af85389cSBen Skeggs 		subpack0_high |= raw_frame[7];
53*f6e7393eSGustavo A. R. Silva 		fallthrough;
54af85389cSBen Skeggs 	case 7:
55af85389cSBen Skeggs 		subpack0_low = (raw_frame[6] << 24);
56*f6e7393eSGustavo A. R. Silva 		fallthrough;
57af85389cSBen Skeggs 	case 6:
58af85389cSBen Skeggs 		subpack0_low |= (raw_frame[5] << 16);
59*f6e7393eSGustavo A. R. Silva 		fallthrough;
60af85389cSBen Skeggs 	case 5:
61af85389cSBen Skeggs 		subpack0_low |= (raw_frame[4] << 8);
62*f6e7393eSGustavo A. R. Silva 		fallthrough;
63af85389cSBen Skeggs 	case 4:
64af85389cSBen Skeggs 		subpack0_low |= raw_frame[3];
65*f6e7393eSGustavo A. R. Silva 		fallthrough;
66af85389cSBen Skeggs 	case 3:
67af85389cSBen Skeggs 		header = (raw_frame[2] << 16);
68*f6e7393eSGustavo A. R. Silva 		fallthrough;
69af85389cSBen Skeggs 	case 2:
70af85389cSBen Skeggs 		header |= (raw_frame[1] << 8);
71*f6e7393eSGustavo A. R. Silva 		fallthrough;
72af85389cSBen Skeggs 	case 1:
73af85389cSBen Skeggs 		header |= raw_frame[0];
74*f6e7393eSGustavo A. R. Silva 		fallthrough;
75af85389cSBen Skeggs 	case 0:
76af85389cSBen Skeggs 		break;
77af85389cSBen Skeggs 	}
78af85389cSBen Skeggs 
79af85389cSBen Skeggs 	packed_frame->header = header;
80af85389cSBen Skeggs 	packed_frame->subpack0_low = subpack0_low;
81af85389cSBen Skeggs 	packed_frame->subpack0_high = subpack0_high;
82af85389cSBen Skeggs 	packed_frame->subpack1_low = subpack1_low;
83af85389cSBen Skeggs 	packed_frame->subpack1_high = subpack1_high;
84af85389cSBen Skeggs }
85