27 #include <linux/module.h>
29 #include <linux/time.h>
31 #include <linux/device.h>
32 #include <linux/i2c.h>
34 #include <linux/slab.h>
35 #include <asm/byteorder.h>
41 #define FLAG_MODE_MJPEG (1)
42 #define FLAG_MODE_MPEG1 (1<<1)
43 #define FLAG_MODE_MPEG2 (1<<2)
44 #define FLAG_MODE_MPEG4 (1<<3)
45 #define FLAG_MODE_H263 (1<<4)
46 #define FLAG_MODE_ALL (FLAG_MODE_MJPEG | FLAG_MODE_MPEG1 | \
47 FLAG_MODE_MPEG2 | FLAG_MODE_MPEG4 | \
49 #define FLAG_SPECIAL (1<<8)
51 #define SPECIAL_FRM_HEAD 0
52 #define SPECIAL_BRC_CTRL 1
53 #define SPECIAL_CONFIG 2
54 #define SPECIAL_SEQHEAD 3
55 #define SPECIAL_AV_SYNC 4
56 #define SPECIAL_FINAL 5
57 #define SPECIAL_AUDIO 6
58 #define SPECIAL_MODET 7
69 #define CODE_GEN(name, dest) struct code_gen name = { dest, 0, 32, 0 }
71 #define CODE_ADD(name, val, length) do { \
73 name.a |= (val) << name.b; \
74 while (name.b <= 24) { \
75 *name.p = name.a >> 24; \
83 #define CODE_LENGTH(name) (name.len + (32 - name.b))
87 static const s16 converge_speed_ip[101] = {
88 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
89 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
90 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
91 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
92 2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
93 3, 3, 3, 3, 3, 4, 4, 4, 4, 4,
94 5, 5, 5, 6, 6, 6, 7, 7, 8, 8,
95 9, 10, 10, 11, 12, 13, 14, 15, 16, 17,
96 19, 20, 22, 23, 25, 27, 30, 32, 35, 38,
97 41, 45, 49, 53, 58, 63, 69, 76, 83, 91,
101 static const s16 converge_speed_ipb[101] = {
102 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
103 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
104 3, 3, 3, 3, 3, 4, 4, 4, 4, 4,
105 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
106 6, 6, 6, 7, 7, 7, 7, 8, 8, 9,
107 9, 9, 10, 10, 11, 12, 12, 13, 14, 14,
108 15, 16, 17, 18, 19, 20, 22, 23, 25, 26,
109 28, 30, 32, 34, 37, 40, 42, 46, 49, 53,
110 57, 61, 66, 71, 77, 83, 90, 97, 106, 115,
111 125, 135, 147, 161, 175, 191, 209, 228, 249, 273,
115 static const s16 LAMBDA_table[4][101] = {
116 { 16, 16, 16, 16, 17, 17, 17, 18, 18, 18,
117 19, 19, 19, 20, 20, 20, 21, 21, 22, 22,
118 22, 23, 23, 24, 24, 25, 25, 25, 26, 26,
119 27, 27, 28, 28, 29, 29, 30, 31, 31, 32,
120 32, 33, 33, 34, 35, 35, 36, 37, 37, 38,
121 39, 39, 40, 41, 42, 42, 43, 44, 45, 46,
122 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
123 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
124 67, 68, 69, 70, 72, 73, 74, 76, 77, 78,
125 80, 81, 83, 84, 86, 87, 89, 90, 92, 94,
129 20, 20, 20, 21, 21, 21, 22, 22, 23, 23,
130 23, 24, 24, 25, 25, 26, 26, 27, 27, 28,
131 28, 29, 29, 30, 30, 31, 31, 32, 33, 33,
132 34, 34, 35, 36, 36, 37, 38, 38, 39, 40,
133 40, 41, 42, 43, 43, 44, 45, 46, 47, 48,
134 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
135 58, 59, 60, 61, 62, 64, 65, 66, 67, 68,
136 70, 71, 72, 73, 75, 76, 78, 79, 80, 82,
137 83, 85, 86, 88, 90, 91, 93, 95, 96, 98,
138 100, 102, 103, 105, 107, 109, 111, 113, 115, 117,
142 24, 24, 24, 25, 25, 26, 26, 27, 27, 28,
143 28, 29, 29, 30, 30, 31, 31, 32, 33, 33,
144 34, 34, 35, 36, 36, 37, 38, 38, 39, 40,
145 41, 41, 42, 43, 44, 44, 45, 46, 47, 48,
146 49, 50, 50, 51, 52, 53, 54, 55, 56, 57,
147 58, 59, 60, 62, 63, 64, 65, 66, 67, 69,
148 70, 71, 72, 74, 75, 76, 78, 79, 81, 82,
149 84, 85, 87, 88, 90, 92, 93, 95, 97, 98,
150 100, 102, 104, 106, 108, 110, 112, 114, 116, 118,
151 120, 122, 124, 127, 129, 131, 134, 136, 138, 141,
155 32, 32, 33, 33, 34, 34, 35, 36, 36, 37,
156 38, 38, 39, 40, 41, 41, 42, 43, 44, 44,
157 45, 46, 47, 48, 49, 50, 50, 51, 52, 53,
158 54, 55, 56, 57, 58, 59, 60, 62, 63, 64,
159 65, 66, 67, 69, 70, 71, 72, 74, 75, 76,
160 78, 79, 81, 82, 84, 85, 87, 88, 90, 92,
161 93, 95, 97, 98, 100, 102, 104, 106, 108, 110,
162 112, 114, 116, 118, 120, 122, 124, 127, 129, 131,
163 134, 136, 139, 141, 144, 146, 149, 152, 154, 157,
164 160, 163, 166, 169, 172, 175, 178, 181, 185, 188,
179 static const u32 addrinctab[33][2] = {
180 { 0x01, 1 }, { 0x03, 3 }, { 0x02, 3 }, { 0x03, 4 },
181 { 0x02, 4 }, { 0x03, 5 }, { 0x02, 5 }, { 0x07, 7 },
182 { 0x06, 7 }, { 0x0b, 8 }, { 0x0a, 8 }, { 0x09, 8 },
183 { 0x08, 8 }, { 0x07, 8 }, { 0x06, 8 }, { 0x17, 10 },
184 { 0x16, 10 }, { 0x15, 10 }, { 0x14, 10 }, { 0x13, 10 },
185 { 0x12, 10 }, { 0x23, 11 }, { 0x22, 11 }, { 0x21, 11 },
186 { 0x20, 11 }, { 0x1f, 11 }, { 0x1e, 11 }, { 0x1d, 11 },
187 { 0x1c, 11 }, { 0x1b, 11 }, { 0x1a, 11 }, { 0x19, 11 },
193 static const u8 default_intra_quant_table[] = {
194 8, 16, 19, 22, 26, 27, 29, 34,
195 16, 16, 22, 24, 27, 29, 34, 37,
196 19, 22, 26, 27, 29, 34, 34, 38,
197 22, 22, 26, 27, 29, 34, 37, 40,
198 22, 26, 27, 29, 32, 35, 40, 48,
199 26, 27, 29, 32, 35, 40, 48, 58,
200 26, 27, 29, 34, 38, 46, 56, 69,
201 27, 29, 35, 38, 46, 56, 69, 83
204 static const u8 bits_dc_luminance[] = {
205 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
208 static const u8 val_dc_luminance[] = {
209 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
212 static const u8 bits_dc_chrominance[] = {
213 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
216 static const u8 val_dc_chrominance[] = {
217 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
220 static const u8 bits_ac_luminance[] = {
221 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d
224 static const u8 val_ac_luminance[] = {
225 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
226 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
227 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
228 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
229 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
230 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
231 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
232 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
233 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
234 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
235 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
236 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
237 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
238 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
239 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
240 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
241 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
242 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
243 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
244 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
248 static const u8 bits_ac_chrominance[] = {
249 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77
252 static const u8 val_ac_chrominance[] = {
253 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
254 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
255 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
256 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
257 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
258 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
259 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
260 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
261 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
262 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
263 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
264 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
265 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
266 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
267 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
268 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
269 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
270 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
271 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
272 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
281 static const int zz[64] = {
282 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
283 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
284 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
285 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
290 int i,
cnt = pkg_cnt * 32;
295 for (i = 0; i <
cnt; ++
i)
301 static int mjpeg_frame_header(
struct go7007 *
go,
unsigned char *
buf,
int q)
312 buf[p++] = default_intra_quant_table[0];
313 for (i = 1; i < 64; ++
i)
315 buf[p++] = (default_intra_quant_table[zz[i]] * q) >> 3;
321 buf[p++] = go->
height >> 8;
322 buf[p++] = go->
height & 0xff;
323 buf[p++] = go->
width >> 8;
324 buf[p++] = go->
width & 0xff;
338 buf[p++] = 418 & 0xff;
340 memcpy(buf + p, bits_dc_luminance + 1, 16);
342 memcpy(buf + p, val_dc_luminance,
sizeof(val_dc_luminance));
343 p +=
sizeof(val_dc_luminance);
345 memcpy(buf + p, bits_dc_chrominance + 1, 16);
347 memcpy(buf + p, val_dc_chrominance,
sizeof(val_dc_chrominance));
348 p +=
sizeof(val_dc_chrominance);
350 memcpy(buf + p, bits_ac_luminance + 1, 16);
352 memcpy(buf + p, val_ac_luminance,
sizeof(val_ac_luminance));
353 p +=
sizeof(val_ac_luminance);
355 memcpy(buf + p, bits_ac_chrominance + 1, 16);
357 memcpy(buf + p, val_ac_chrominance,
sizeof(val_ac_chrominance));
358 p +=
sizeof(val_ac_chrominance);
376 static int gen_mjpeghdr_to_package(
struct go7007 *go,
__le16 *
code,
int space)
380 unsigned int addr = 0x19;
386 "firmware construction\n");
390 for (i = 1; i < 32; ++
i) {
391 mjpeg_frame_header(go, buf + size, i);
394 chunk = mjpeg_frame_header(go, buf + size, 1);
399 if (space - off < 32) {
407 if (mem +
chunk > 0x4000)
409 if (i + 2 *
chunk > size)
430 static int mpeg1_frame_header(
struct go7007 *go,
unsigned char *buf,
433 int i,
j, mb_code, mb_len;
455 mb_code = mb_len = 0;
493 for (i = 0; i <
rows; ++
i) {
501 CODE_ADD(
c, pict_struct == 1 ? 0x0 : 0x1, 1);
506 CODE_ADD(
c, pict_struct == 1 ? 0x0 : 0x1, 1);
509 for (j = (go->
width >> 4) - 2; j >= 33; j -= 33)
511 CODE_ADD(
c, addrinctab[j][0], addrinctab[j][1]);
515 CODE_ADD(
c, pict_struct == 1 ? 0x0 : 0x1, 1);
520 CODE_ADD(
c, pict_struct == 1 ? 0x0 : 0x1, 1);
538 static int mpeg1_sequence_header(
struct go7007 *go,
unsigned char *buf,
int ext)
540 int i, aspect_ratio, picture_rate;
546 aspect_ratio = go->
standard == GO7007_STD_NTSC ? 3 : 2;
549 aspect_ratio = go->
standard == GO7007_STD_NTSC ? 5 : 4;
645 static int gen_mpeg1hdr_to_package(
struct go7007 *go,
646 __le16 *code,
int space,
int *framelen)
650 unsigned int addr = 0x19;
656 "firmware construction\n");
659 framelen[0] = mpeg1_frame_header(go, buf, 0, 1,
PFRAME);
661 framelen[0] += mpeg1_frame_header(go, buf + framelen[0] / 8,
663 buf[0] = framelen[0] & 0xff;
664 buf[1] = framelen[0] >> 8;
666 framelen[1] = mpeg1_frame_header(go, buf + i, 0, 1,
BFRAME_PRE);
668 framelen[1] += mpeg1_frame_header(go, buf + i + framelen[1] / 8,
670 buf[
i] = framelen[1] & 0xff;
671 buf[i + 1] = framelen[1] >> 8;
673 framelen[2] = mpeg1_frame_header(go, buf + i, 0, 1,
BFRAME_POST);
675 framelen[2] += mpeg1_frame_header(go, buf + i + framelen[2] / 8,
677 buf[
i] = framelen[2] & 0xff;
678 buf[i + 1] = framelen[2] >> 8;
680 framelen[3] = mpeg1_frame_header(go, buf + i, 0, 1,
BFRAME_BIDIR);
682 framelen[3] += mpeg1_frame_header(go, buf + i + framelen[3] / 8,
684 buf[
i] = framelen[3] & 0xff;
685 buf[i + 1] = framelen[3] >> 8;
687 mpeg1_sequence_header(go, buf + i, 0);
689 for (i = 0; i < 5120; i +=
chunk * 2) {
690 if (space - off < 32) {
698 if (mem +
chunk > 0x4000)
700 if (i + 2 *
chunk > 5120)
706 if (mem +
chunk == 0x4000) {
724 static int vti_bitlen(
struct go7007 *go)
728 for (i = 31; (max_time_incr & ((1 <<
i) - 1)) == max_time_incr; --
i);
732 static int mpeg4_frame_header(
struct go7007 *go,
unsigned char *buf,
737 int mb_count = (go->
width >> 4) * (go->
height >> 4);
751 for (i = 0; i < mb_count; ++
i) {
786 static int mpeg4_sequence_header(
struct go7007 *go,
unsigned char *buf,
int ext)
788 const unsigned char head[] = { 0x00, 0x00, 0x01, 0xb0, go->
pali,
789 0x00, 0x00, 0x01, 0xb5, 0x09,
790 0x00, 0x00, 0x01, 0x00,
791 0x00, 0x00, 0x01, 0x20, };
798 aspect_ratio = go->
standard == GO7007_STD_NTSC ? 3 : 2;
801 aspect_ratio = go->
standard == GO7007_STD_NTSC ? 5 : 4;
808 memcpy(buf + 2, head,
sizeof(head));
832 static int gen_mpeg4hdr_to_package(
struct go7007 *go,
833 __le16 *code,
int space,
int *framelen)
837 unsigned int addr = 0x19;
843 "firmware construction\n");
846 framelen[0] = mpeg4_frame_header(go, buf, 0,
PFRAME);
848 framelen[1] = mpeg4_frame_header(go, buf + i, 0,
BFRAME_PRE);
850 framelen[2] = mpeg4_frame_header(go, buf + i, 0,
BFRAME_POST);
852 framelen[3] = mpeg4_frame_header(go, buf + i, 0,
BFRAME_BIDIR);
856 mpeg4_sequence_header(go, buf + i, 0);
858 for (i = 0; i < 5120; i +=
chunk * 2) {
859 if (space - off < 32) {
867 if (mem +
chunk > 0x4000)
869 if (i + 2 *
chunk > 5120)
875 if (mem +
chunk == 0x4000) {
889 addr = go->
ipb ? 0x14f9 : 0x0af9;
891 framelen[4] = mpeg4_frame_header(go, buf, 1,
PFRAME);
893 framelen[5] = mpeg4_frame_header(go, buf + i, 1,
BFRAME_PRE);
895 framelen[6] = mpeg4_frame_header(go, buf + i, 1,
BFRAME_POST);
897 framelen[7] = mpeg4_frame_header(go, buf + i, 1,
BFRAME_BIDIR);
901 for (i = 0; i < 5120; i +=
chunk * 2) {
902 if (space - off < 32) {
910 if (mem +
chunk > 0x4000)
912 if (i + 2 *
chunk > 5120)
918 if (mem +
chunk == 0x4000) {
936 static int brctrl_to_package(
struct go7007 *go,
937 __le16 *code,
int space,
int *framelen)
939 int converge_speed = 0;
942 int peak_rate = 6 * go->
bitrate / 5;
945 (go->
dvd_mode ? 900000 : peak_rate);
949 u32 sgop_expt_addr = go->
bitrate / 32 * (go->
ipb ? 3 : 1) * 1001 / fps;
950 u32 sgop_peak_addr = peak_rate / 32 * 1001 / fps;
951 u32 total_expt_addr = go->
bitrate / 32 * 1000 / fps * (fps / 1000);
952 u32 vbv_alert_addr = vbv_buffer * 3 / (4 * 32);
954 q > 0 ? sgop_expt_addr * q :
956 q > 0 ? sgop_expt_addr * q :
958 q > 0 ? sgop_expt_addr * q :
960 q > 0 ? sgop_expt_addr * q :
963 u32 calc_q = q > 0 ? q : cplx[0] / sgop_expt_addr;
966 0xBF20, go->
ipb ? converge_speed_ipb[converge_speed]
967 : converge_speed_ip[converge_speed],
968 0xBF21, go->
ipb ? 2 : 0,
969 0xBF22, go->
ipb ? LAMBDA_table[0][lambda / 2 + 50]
971 0xBF23, go->
ipb ? LAMBDA_table[1][
lambda] : 32767,
973 0xBF25, lambda > 99 ? 32767 : LAMBDA_table[3][
lambda],
974 0xBF26, sgop_expt_addr & 0x0000FFFF,
975 0xBF27, sgop_expt_addr >> 16,
976 0xBF28, sgop_peak_addr & 0x0000FFFF,
977 0xBF29, sgop_peak_addr >> 16,
978 0xBF2A, vbv_alert_addr & 0x0000FFFF,
979 0xBF2B, vbv_alert_addr >> 16,
985 0xBF2E, vbv_alert_addr & 0x0000FFFF,
986 0xBF2F, vbv_alert_addr >> 16,
987 0xBF30, cplx[0] & 0x0000FFFF,
988 0xBF31, cplx[0] >> 16,
989 0xBF32, cplx[1] & 0x0000FFFF,
990 0xBF33, cplx[1] >> 16,
991 0xBF34, cplx[2] & 0x0000FFFF,
992 0xBF35, cplx[2] >> 16,
993 0xBF36, cplx[3] & 0x0000FFFF,
994 0xBF37, cplx[3] >> 16,
997 0xBF3A, total_expt_addr & 0x0000FFFF,
998 0xBF3B, total_expt_addr >> 16,
1002 0xBF3C, total_expt_addr & 0x0000FFFF,
1003 0xBF3D, total_expt_addr >> 16,
1008 0xBF4A, calc_q < 4 ? 4 : (calc_q > 124 ? 124 : calc_q),
1019 0xBF40, sgop_expt_addr & 0x0000FFFF,
1020 0xBF41, sgop_expt_addr >> 16,
1029 0xBF18, framelen[4],
1030 0xBF19, framelen[5],
1031 0xBF1A, framelen[6],
1032 0xBF1B, framelen[7],
1083 0xBF52, framelen[0],
1084 0xBF53, framelen[1],
1085 0xBF54, framelen[2],
1086 0xBF55, framelen[3],
1090 return copy_packages(code, pack, 6, space);
1093 static int config_package(
struct go7007 *go,
__le16 *code,
int space)
1097 int brc_window_size = fps;
1098 int q_min = 2, q_max = 31;
1099 int THACCoeffSet0 = 0;
1146 0xdd5a, go->
ipb ? 0x14 : 0x0a,
1149 0xc683, THACCoeffSet0,
1150 0xc40a, (go->
width << 4) | rows,
1173 0xbf66, brc_window_size,
1180 0xbfe3, go->
ipb ? 3 : 1,
1186 0xdd88, go->
ipb ? 0x1401 : 0x0a01,
1187 0xdd90, go->
ipb ? 0x1401 : 0x0a01,
1212 return copy_packages(code, pack, 5, space);
1215 static int seqhead_to_package(
struct go7007 *go,
__le16 *code,
int space,
1216 int (*sequence_header_func)(
struct go7007 *go,
1217 unsigned char *buf,
int ext))
1219 int vop_time_increment_bitlength = vti_bitlen(go);
1222 unsigned char buf[40] = { };
1223 int len = sequence_header_func(go, buf, 1);
1228 0xbff2, vop_time_increment_bitlength,
1229 0xbff3, (1 << vop_time_increment_bitlength) - 1,
1231 0xbfe7, (fps / 1000) << 8,
1243 0xc800, buf[2] << 8 | buf[3],
1244 0xc801, buf[4] << 8 | buf[5],
1245 0xc802, buf[6] << 8 | buf[7],
1246 0xc803, buf[8] << 8 | buf[9],
1260 0xc808, buf[10] << 8 | buf[11],
1261 0xc809, buf[12] << 8 | buf[13],
1262 0xc80a, buf[14] << 8 | buf[15],
1263 0xc80b, buf[16] << 8 | buf[17],
1264 0xc80c, buf[18] << 8 | buf[19],
1265 0xc80d, buf[20] << 8 | buf[21],
1266 0xc80e, buf[22] << 8 | buf[23],
1267 0xc80f, buf[24] << 8 | buf[25],
1268 0xc810, buf[26] << 8 | buf[27],
1269 0xc811, buf[28] << 8 | buf[29],
1270 0xc812, buf[30] << 8 | buf[31],
1271 0xc813, buf[32] << 8 | buf[33],
1272 0xc814, buf[34] << 8 | buf[35],
1273 0xc815, buf[36] << 8 | buf[37],
1279 return copy_packages(code, pack, 3, space);
1282 static int relative_prime(
int big,
int little)
1286 while (little != 0) {
1287 remainder = big % little;
1294 static int avsync_to_package(
struct go7007 *go,
__le16 *code,
int space)
1298 int adjratio = ratio * 215 / 100;
1305 0xbf98, (
u16)((-adjratio) & 0xffff),
1306 0xbf99, (
u16)((-adjratio) >> 16),
1309 0xbff4, f1 > f2 ? f1 :
f2,
1310 0xbff5, f1 < f2 ? f1 :
f2,
1311 0xbff6, f1 < f2 ? ratio : ratio + 1,
1312 0xbff7, f1 > f2 ? ratio : ratio + 1,
1315 0xbffa, adjratio & 0xffff,
1316 0xbffb, adjratio >> 16,
1322 return copy_packages(code, pack, 1, space);
1325 static int final_package(
struct go7007 *go,
__le16 *code,
int space)
1339 (1 << 14) | (1 << 9) : 0) |
1356 go->
ipb ? 0xd4c : 0x36b,
1357 (rows << 8) | (go->
width >> 4),
1363 ((go->
ipb ? 3 : 0) << 7) |
1371 go->
ipb ? 0x1f15 : 0x1f0b,
1372 go->
ipb ? 0x0015 : 0x000b,
1373 go->
ipb ? 0xa800 : 0x5800,
1375 0x0020 + 0x034b * 0,
1376 0x0020 + 0x034b * 1,
1377 0x0020 + 0x034b * 2,
1378 0x0020 + 0x034b * 3,
1379 0x0020 + 0x034b * 4,
1380 0x0020 + 0x034b * 5,
1385 return copy_packages(code, pack, 1, space);
1388 static int audio_to_package(
struct go7007 *go,
__le16 *code,
int space)
1390 int clock_config = ((go->
board_info->audio_flags &
1394 (((go->
board_info->audio_bclk_div / 4) - 1) << 4) |
1408 0x9000, clock_config,
1409 0x9001, (go->
board_info->audio_flags & 0xffff) |
1435 return copy_packages(code, pack, 2, space);
1438 static int modet_to_package(
struct go7007 *go,
__le16 *code,
int space)
1442 u16 thresholds[] = {
1444 0xbf82, go->
modet[0].pixel_threshold,
1445 0xbf83, go->
modet[1].pixel_threshold,
1446 0xbf84, go->
modet[2].pixel_threshold,
1447 0xbf85, go->
modet[3].pixel_threshold,
1448 0xbf86, go->
modet[0].motion_threshold,
1449 0xbf87, go->
modet[1].motion_threshold,
1450 0xbf88, go->
modet[2].motion_threshold,
1451 0xbf89, go->
modet[3].motion_threshold,
1452 0xbf8a, go->
modet[0].mb_threshold,
1453 0xbf8b, go->
modet[1].mb_threshold,
1454 0xbf8c, go->
modet[2].mb_threshold,
1455 0xbf8d, go->
modet[3].mb_threshold,
1461 ret = copy_packages(code, thresholds, 1, space);
1469 for (mb = 0; mb < 1624; ++
mb) {
1470 pack[i * 2 + 3] <<= 2;
1474 pack[i * 2 + 2] = addr++;
1476 if (i == 10 || mb == 1623) {
1477 pack[0] = 0x2000 |
i;
1478 ret = copy_packages(code + cnt, pack, 1, space - cnt);
1485 pack[i * 2 + 3] = 0;
1490 for (addr = 0xbb90; addr < 0xbbfa; ++
addr) {
1491 pack[i * 2 + 2] =
addr;
1492 pack[i * 2 + 3] = 0;
1494 if (i == 10 || addr == 0xbbf9) {
1495 pack[0] = 0x2000 |
i;
1496 ret = copy_packages(code + cnt, pack, 1, space - cnt);
1514 return gen_mjpeghdr_to_package(go, code, space);
1517 return gen_mpeg1hdr_to_package(go, code, space,
1520 return gen_mpeg4hdr_to_package(go, code, space,
1524 return brctrl_to_package(go, code, space, framelen);
1526 return config_package(go, code, space);
1531 return seqhead_to_package(go, code, space,
1532 mpeg1_sequence_header);
1534 return seqhead_to_package(go, code, space,
1535 mpeg4_sequence_header);
1540 return avsync_to_package(go, code, space);
1542 return final_package(go, code, space);
1544 return audio_to_package(go, code, space);
1546 return modet_to_package(go, code, space);
1549 "go7007: firmware file contains unsupported feature %04x\n",
1558 int framelen[8] = { };
1559 int codespace = 64 * 1024, i = 0, srclen, chunk_len, chunk_flags;
1581 "go7007: unable to load firmware from file \"%s\"\n",
1588 "firmware construction\n", codespace * 2);
1592 srclen = fw_entry->
size / 2;
1593 while (srclen >= 2) {
1596 if (chunk_len + 2 > srclen) {
1598 "appears to be corrupted\n",
1602 if (chunk_flags & mode_flag) {
1605 &code[i], codespace - i, framelen);
1608 "memory for firmware "
1614 if (codespace - i < chunk_len) {
1616 "memory for firmware "
1620 memcpy(&code[i], &src[2], chunk_len * 2);
1624 srclen -= chunk_len + 2;
1625 src += chunk_len + 2;