1 // SPDX-License-Identifier: GPL-2.0
2 #include "hdmi.h"
3 
4 void pack_hdmi_infoframe(struct packed_hdmi_infoframe *packed_frame,
5 			 u8 *raw_frame, ssize_t len)
6 {
7 	u32 header = 0;
8 	u32 subpack0_low = 0;
9 	u32 subpack0_high = 0;
10 	u32 subpack1_low = 0;
11 	u32 subpack1_high = 0;
12 
13 	switch (len) {
14 		/*
15 		 * "When in doubt, use brute force."
16 		 *     -- Ken Thompson.
17 		 */
18 	default:
19 		/*
20 		 * We presume that no valid frame is longer than 17
21 		 * octets, including header...  And truncate to that
22 		 * if it's longer.
23 		 */
24 	case 17:
25 		subpack1_high = (raw_frame[16] << 16);
26 	case 16:
27 		subpack1_high |= (raw_frame[15] << 8);
28 	case 15:
29 		subpack1_high |= raw_frame[14];
30 	case 14:
31 		subpack1_low = (raw_frame[13] << 24);
32 	case 13:
33 		subpack1_low |= (raw_frame[12] << 16);
34 	case 12:
35 		subpack1_low |= (raw_frame[11] << 8);
36 	case 11:
37 		subpack1_low |= raw_frame[10];
38 	case 10:
39 		subpack0_high = (raw_frame[9] << 16);
40 	case 9:
41 		subpack0_high |= (raw_frame[8] << 8);
42 	case 8:
43 		subpack0_high |= raw_frame[7];
44 	case 7:
45 		subpack0_low = (raw_frame[6] << 24);
46 	case 6:
47 		subpack0_low |= (raw_frame[5] << 16);
48 	case 5:
49 		subpack0_low |= (raw_frame[4] << 8);
50 	case 4:
51 		subpack0_low |= raw_frame[3];
52 	case 3:
53 		header = (raw_frame[2] << 16);
54 	case 2:
55 		header |= (raw_frame[1] << 8);
56 	case 1:
57 		header |= raw_frame[0];
58 	case 0:
59 		break;
60 	}
61 
62 	packed_frame->header = header;
63 	packed_frame->subpack0_low = subpack0_low;
64 	packed_frame->subpack0_high = subpack0_high;
65 	packed_frame->subpack1_low = subpack1_low;
66 	packed_frame->subpack1_high = subpack1_high;
67 }
68