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