2 * Copyright (C) 2012 Avionic Design GmbH
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/bitops.h>
10 #include <linux/errno.h>
11 #include <linux/export.h>
12 #include <linux/hdmi.h>
13 #include <linux/string.h>
15 static void hdmi_infoframe_checksum(void *buffer, size_t size)
21 /* compute checksum */
22 for (i = 0; i < size; i++)
29 * hdmi_avi_infoframe_init() - initialize an HDMI AVI infoframe
30 * @frame: HDMI AVI infoframe
32 * Returns 0 on success or a negative error code on failure.
34 int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame)
36 memset(frame, 0, sizeof(*frame));
38 frame->type = HDMI_INFOFRAME_TYPE_AVI;
44 EXPORT_SYMBOL(hdmi_avi_infoframe_init);
47 * hdmi_avi_infoframe_pack() - write HDMI AVI infoframe to binary buffer
48 * @frame: HDMI AVI infoframe
49 * @buffer: destination buffer
50 * @size: size of buffer
52 * Packs the information contained in the @frame structure into a binary
53 * representation that can be written into the corresponding controller
54 * registers. Also computes the checksum as required by section 5.3.5 of
55 * the HDMI 1.4 specification.
57 * Returns the number of bytes packed into the binary buffer or a negative
58 * error code on failure.
60 ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
66 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
71 memset(buffer, 0, length);
74 ptr[1] = frame->version;
75 ptr[2] = frame->length;
76 ptr[3] = 0; /* checksum */
78 /* start infoframe payload */
79 ptr += HDMI_INFOFRAME_HEADER_SIZE;
81 ptr[0] = ((frame->colorspace & 0x3) << 5) | (frame->scan_mode & 0x3);
83 if (frame->active_info_valid)
86 if (frame->horizontal_bar_valid)
89 if (frame->vertical_bar_valid)
92 ptr[1] = ((frame->colorimetry & 0x3) << 6) |
93 ((frame->picture_aspect & 0x3) << 4) |
94 (frame->active_aspect & 0xf);
96 ptr[2] = ((frame->extended_colorimetry & 0x7) << 4) |
97 ((frame->quantization_range & 0x3) << 2) |
103 ptr[3] = frame->video_code & 0x7f;
105 ptr[4] = ((frame->ycc_quantization_range & 0x3) << 6) |
106 ((frame->content_type & 0x3) << 4) |
107 (frame->pixel_repeat & 0xf);
109 ptr[5] = frame->top_bar & 0xff;
110 ptr[6] = (frame->top_bar >> 8) & 0xff;
111 ptr[7] = frame->bottom_bar & 0xff;
112 ptr[8] = (frame->bottom_bar >> 8) & 0xff;
113 ptr[9] = frame->left_bar & 0xff;
114 ptr[10] = (frame->left_bar >> 8) & 0xff;
115 ptr[11] = frame->right_bar & 0xff;
116 ptr[12] = (frame->right_bar >> 8) & 0xff;
118 hdmi_infoframe_checksum(buffer, length);
122 EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
125 * hdmi_spd_infoframe_init() - initialize an HDMI SPD infoframe
126 * @frame: HDMI SPD infoframe
127 * @vendor: vendor string
128 * @product: product string
130 * Returns 0 on success or a negative error code on failure.
132 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
133 const char *vendor, const char *product)
135 memset(frame, 0, sizeof(*frame));
137 frame->type = HDMI_INFOFRAME_TYPE_SPD;
141 strncpy(frame->vendor, vendor, sizeof(frame->vendor));
142 strncpy(frame->product, product, sizeof(frame->product));
146 EXPORT_SYMBOL(hdmi_spd_infoframe_init);
149 * hdmi_spd_infoframe_pack() - write HDMI SPD infoframe to binary buffer
150 * @frame: HDMI SPD infoframe
151 * @buffer: destination buffer
152 * @size: size of buffer
154 * Packs the information contained in the @frame structure into a binary
155 * representation that can be written into the corresponding controller
156 * registers. Also computes the checksum as required by section 5.3.5 of
157 * the HDMI 1.4 specification.
159 * Returns the number of bytes packed into the binary buffer or a negative
160 * error code on failure.
162 ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
168 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
173 memset(buffer, 0, length);
175 ptr[0] = frame->type;
176 ptr[1] = frame->version;
177 ptr[2] = frame->length;
178 ptr[3] = 0; /* checksum */
180 /* start infoframe payload */
181 ptr += HDMI_INFOFRAME_HEADER_SIZE;
183 memcpy(ptr, frame->vendor, sizeof(frame->vendor));
184 memcpy(ptr + 8, frame->product, sizeof(frame->product));
186 ptr[24] = frame->sdi;
188 hdmi_infoframe_checksum(buffer, length);
192 EXPORT_SYMBOL(hdmi_spd_infoframe_pack);
195 * hdmi_audio_infoframe_init() - initialize an HDMI audio infoframe
196 * @frame: HDMI audio infoframe
198 * Returns 0 on success or a negative error code on failure.
200 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame)
202 memset(frame, 0, sizeof(*frame));
204 frame->type = HDMI_INFOFRAME_TYPE_AUDIO;
210 EXPORT_SYMBOL(hdmi_audio_infoframe_init);
213 * hdmi_audio_infoframe_pack() - write HDMI audio infoframe to binary buffer
214 * @frame: HDMI audio infoframe
215 * @buffer: destination buffer
216 * @size: size of buffer
218 * Packs the information contained in the @frame structure into a binary
219 * representation that can be written into the corresponding controller
220 * registers. Also computes the checksum as required by section 5.3.5 of
221 * the HDMI 1.4 specification.
223 * Returns the number of bytes packed into the binary buffer or a negative
224 * error code on failure.
226 ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
227 void *buffer, size_t size)
229 unsigned char channels;
233 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
238 memset(buffer, 0, length);
240 if (frame->channels >= 2)
241 channels = frame->channels - 1;
245 ptr[0] = frame->type;
246 ptr[1] = frame->version;
247 ptr[2] = frame->length;
248 ptr[3] = 0; /* checksum */
250 /* start infoframe payload */
251 ptr += HDMI_INFOFRAME_HEADER_SIZE;
253 ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7);
254 ptr[1] = ((frame->sample_frequency & 0x7) << 2) |
255 (frame->sample_size & 0x3);
256 ptr[2] = frame->coding_type_ext & 0x1f;
257 ptr[3] = frame->channel_allocation;
258 ptr[4] = (frame->level_shift_value & 0xf) << 3;
260 if (frame->downmix_inhibit)
263 hdmi_infoframe_checksum(buffer, length);
267 EXPORT_SYMBOL(hdmi_audio_infoframe_pack);
270 * hdmi_vendor_infoframe_pack() - write a HDMI vendor infoframe to binary
272 * @frame: HDMI vendor infoframe
273 * @buffer: destination buffer
274 * @size: size of buffer
276 * Packs the information contained in the @frame structure into a binary
277 * representation that can be written into the corresponding controller
278 * registers. Also computes the checksum as required by section 5.3.5 of
279 * the HDMI 1.4 specification.
281 * Returns the number of bytes packed into the binary buffer or a negative
282 * error code on failure.
284 ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
285 void *buffer, size_t size)
290 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
295 memset(buffer, 0, length);
297 ptr[0] = frame->type;
298 ptr[1] = frame->version;
299 ptr[2] = frame->length;
300 ptr[3] = 0; /* checksum */
302 memcpy(&ptr[HDMI_INFOFRAME_HEADER_SIZE], frame->data, frame->length);
304 hdmi_infoframe_checksum(buffer, length);
308 EXPORT_SYMBOL(hdmi_vendor_infoframe_pack);