aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7164/saa7164-api.c
diff options
context:
space:
mode:
authorSteven Toth <stoth@kernellabs.com>2010-07-31 13:44:53 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-10-21 05:54:34 -0400
commit7615e434aefd95181eae099c4f019e021b024eb6 (patch)
tree22901c7326d8edfe0b8ac1208cb289fcc55241ad /drivers/media/video/saa7164/saa7164-api.c
parentadd3f580a4342b8bca7e0fb4737fe9eeaefa4319 (diff)
[media] saa7164: add various encoder message functions
Signed-off-by: Steven Toth <stoth@kernellabs.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/saa7164/saa7164-api.c')
-rw-r--r--drivers/media/video/saa7164/saa7164-api.c669
1 files changed, 662 insertions, 7 deletions
diff --git a/drivers/media/video/saa7164/saa7164-api.c b/drivers/media/video/saa7164/saa7164-api.c
index a810e6d8827..5e05723fe44 100644
--- a/drivers/media/video/saa7164/saa7164-api.c
+++ b/drivers/media/video/saa7164/saa7164-api.c
@@ -24,6 +24,543 @@
24 24
25#include "saa7164.h" 25#include "saa7164.h"
26 26
27int saa7164_api_set_encoder(struct saa7164_port *port)
28{
29 struct saa7164_dev *dev = port->dev;
30 tmComResEncVideoBitRate_t vb;
31 tmComResEncAudioBitRate_t ab;
32 int ret;
33
34 dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, port->hwcfg.sourceid);
35
36 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
37 EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
38 if (ret != SAA_OK)
39 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
40
41 /* Establish video bitrates */
42 vb.ucVideoBitRateMode = 0;
43 vb.dwVideoBitRate = port->encoder_params.bitrate;
44 vb.dwVideoBitRatePeak = vb.dwVideoBitRate;
45 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
46 EU_VIDEO_BIT_RATE_CONTROL, sizeof(tmComResEncVideoBitRate_t), &vb);
47 if (ret != SAA_OK)
48 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
49
50 /* Establish audio bitrates */
51 ab.ucAudioBitRateMode = 0;
52 ab.dwAudioBitRate = 384000;
53 ab.dwAudioBitRatePeak = ab.dwAudioBitRate;
54 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
55 EU_AUDIO_BIT_RATE_CONTROL, sizeof(tmComResEncAudioBitRate_t), &ab);
56 if (ret != SAA_OK)
57 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
58
59 saa7164_api_set_aspect_ratio(port);
60
61 return ret;
62}
63
64int saa7164_api_get_encoder(struct saa7164_port *port)
65{
66 struct saa7164_dev *dev = port->dev;
67 tmComResEncVideoBitRate_t v;
68 tmComResEncAudioBitRate_t a;
69 tmComResEncVideoInputAspectRatio_t ar;
70 int ret;
71
72 dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, port->hwcfg.sourceid);
73
74 port->encoder_profile = 0;
75 port->video_format = 0;
76 port->video_resolution = 0;
77 port->audio_format = 0;
78
79 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
80 EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
81 if (ret != SAA_OK)
82 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
83
84 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
85 EU_VIDEO_FORMAT_CONTROL, sizeof(u8), &port->video_format);
86 if (ret != SAA_OK)
87 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
88
89 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
90 EU_VIDEO_BIT_RATE_CONTROL, sizeof(v), &v);
91 if (ret != SAA_OK)
92 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
93
94 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
95 EU_AUDIO_FORMAT_CONTROL, sizeof(u8), &port->audio_format);
96 if (ret != SAA_OK)
97 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
98
99 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
100 EU_AUDIO_BIT_RATE_CONTROL, sizeof(a), &a);
101 if (ret != SAA_OK)
102 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
103
104 /* Aspect Ratio */
105 ar.width = 0;
106 ar.height = 0;
107 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
108 EU_VIDEO_INPUT_ASPECT_CONTROL,
109 sizeof(tmComResEncVideoInputAspectRatio_t), &ar);
110 if (ret != SAA_OK)
111 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
112
113 dprintk(DBGLVL_ENC, "encoder_profile = %d\n", port->encoder_profile);
114 dprintk(DBGLVL_ENC, "video_format = %d\n", port->video_format);
115 dprintk(DBGLVL_ENC, "audio_format = %d\n", port->audio_format);
116 dprintk(DBGLVL_ENC, "video_resolution= %d\n", port->video_resolution);
117 dprintk(DBGLVL_ENC, "v.ucVideoBitRateMode = %d\n", v.ucVideoBitRateMode);
118 dprintk(DBGLVL_ENC, "v.dwVideoBitRate = %d\n", v.dwVideoBitRate);
119 dprintk(DBGLVL_ENC, "v.dwVideoBitRatePeak = %d\n", v.dwVideoBitRatePeak);
120 dprintk(DBGLVL_ENC, "a.ucVideoBitRateMode = %d\n", a.ucAudioBitRateMode);
121 dprintk(DBGLVL_ENC, "a.dwVideoBitRate = %d\n", a.dwAudioBitRate);
122 dprintk(DBGLVL_ENC, "a.dwVideoBitRatePeak = %d\n", a.dwAudioBitRatePeak);
123 dprintk(DBGLVL_ENC, "aspect.width / height = %d:%d\n", ar.width, ar.height);
124
125 return ret;
126}
127
128int saa7164_api_set_aspect_ratio(struct saa7164_port *port)
129{
130 struct saa7164_dev *dev = port->dev;
131 tmComResEncVideoInputAspectRatio_t ar;
132 int ret;
133
134 dprintk(DBGLVL_ENC, "%s(%d)\n", __func__,
135 port->encoder_params.ctl_aspect);
136
137 switch (port->encoder_params.ctl_aspect) {
138 case V4L2_MPEG_VIDEO_ASPECT_1x1:
139 ar.width = 1;
140 ar.height = 1;
141 break;
142 case V4L2_MPEG_VIDEO_ASPECT_4x3:
143 ar.width = 4;
144 ar.height = 3;
145 break;
146 case V4L2_MPEG_VIDEO_ASPECT_16x9:
147 ar.width = 16;
148 ar.height = 9;
149 break;
150 case V4L2_MPEG_VIDEO_ASPECT_221x100:
151 ar.width = 221;
152 ar.height = 100;
153 break;
154 default:
155 BUG();
156 }
157
158 dprintk(DBGLVL_ENC, "%s(%d) now %d:%d\n", __func__,
159 port->encoder_params.ctl_aspect,
160 ar.width, ar.height);
161
162 /* Aspect Ratio */
163 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
164 EU_VIDEO_INPUT_ASPECT_CONTROL,
165 sizeof(tmComResEncVideoInputAspectRatio_t), &ar);
166 if (ret != SAA_OK)
167 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
168
169 return ret;
170}
171
172int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl)
173{
174 struct saa7164_dev *dev = port->dev;
175 int ret;
176 u16 val;
177
178 if (ctl == PU_BRIGHTNESS_CONTROL)
179 val = port->ctl_brightness;
180 else
181 if (ctl == PU_CONTRAST_CONTROL)
182 val = port->ctl_contrast;
183 else
184 if (ctl == PU_HUE_CONTROL)
185 val = port->ctl_hue;
186 else
187 if (ctl == PU_SATURATION_CONTROL)
188 val = port->ctl_saturation;
189 else
190 if (ctl == PU_SHARPNESS_CONTROL)
191 val = port->ctl_sharpness;
192 else
193 return -EINVAL;
194
195 dprintk(DBGLVL_ENC, "%s() unitid=0x%x ctl=%d, val=%d\n",
196 __func__, port->encunit.vsourceid, ctl, val);
197
198 ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, SET_CUR,
199 ctl, sizeof(u16), &val);
200 if (ret != SAA_OK)
201 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
202
203 return ret;
204}
205
206int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl)
207{
208 struct saa7164_dev *dev = port->dev;
209 int ret;
210 u16 val;
211
212 ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, GET_CUR,
213 ctl, sizeof(u16), &val);
214 if (ret != SAA_OK) {
215 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
216 return ret;
217 }
218
219 dprintk(DBGLVL_ENC, "%s() ctl=%d, val=%d\n",
220 __func__, ctl, val);
221
222 if (ctl == PU_BRIGHTNESS_CONTROL)
223 port->ctl_brightness = val;
224 else
225 if (ctl == PU_CONTRAST_CONTROL)
226 port->ctl_contrast = val;
227 else
228 if (ctl == PU_HUE_CONTROL)
229 port->ctl_hue = val;
230 else
231 if (ctl == PU_SATURATION_CONTROL)
232 port->ctl_saturation = val;
233 else
234 if (ctl == PU_SHARPNESS_CONTROL)
235 port->ctl_sharpness = val;
236
237 return ret;
238}
239
240int saa7164_api_set_videomux(struct saa7164_port *port)
241{
242 struct saa7164_dev *dev = port->dev;
243 u8 inputs[] = { 1, 2, 2, 2, 5, 5, 5 };
244 int ret;
245
246 dprintk(DBGLVL_ENC, "%s() v_mux=%d a_mux=%d\n",
247 __func__, port->mux_input, inputs[ port->mux_input - 1 ]);
248
249 /* Audio Mute */
250 ret = saa7164_api_audio_mute(port, 1);
251 if (ret != SAA_OK)
252 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
253
254 /* Video Mux */
255 ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, SET_CUR,
256 SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input);
257 if (ret != SAA_OK)
258 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
259 /* Audio Mux */
260 ret = saa7164_cmd_send(port->dev, port->audfeat.sourceid, SET_CUR,
261 SU_INPUT_SELECT_CONTROL, sizeof(u8), &inputs[ port->mux_input - 1 ]);
262 if (ret != SAA_OK)
263 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
264 /* Audio UnMute */
265 ret = saa7164_api_audio_mute(port, 0);
266 if (ret != SAA_OK)
267 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
268
269 return ret;
270}
271
272int saa7164_api_audio_mute(struct saa7164_port *port, int mute)
273{
274 struct saa7164_dev *dev = port->dev;
275 u8 v = mute;
276 int ret;
277
278 dprintk(DBGLVL_API, "%s(%d)\n", __func__, mute);
279
280 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
281 MUTE_CONTROL, sizeof(u8), &v);
282 if (ret != SAA_OK)
283 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
284
285 return ret;
286}
287
288/* 0 = silence, 0xff = full */
289int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level)
290{
291 struct saa7164_dev *dev = port->dev;
292 s16 v, min, max;
293 int ret;
294
295 dprintk(DBGLVL_API, "%s(%d)\n", __func__, level);
296
297 /* Obtain the min/max ranges */
298 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MIN,
299 VOLUME_CONTROL, sizeof(u16), &min);
300 if (ret != SAA_OK)
301 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
302
303 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MAX,
304 VOLUME_CONTROL, sizeof(u16), &max);
305 if (ret != SAA_OK)
306 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
307
308 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR,
309 ( 0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v);
310 if (ret != SAA_OK)
311 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
312
313 dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v);
314
315 v = level;
316 if (v < min)
317 v = min;
318 if (v > max)
319 v = max;
320
321 /* Left */
322 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
323 ( 0x01 << 8 ) | VOLUME_CONTROL, sizeof(s16), &v);
324 if (ret != SAA_OK)
325 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
326
327 /* Right */
328 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
329 ( 0x02 << 8 ) | VOLUME_CONTROL, sizeof(s16), &v);
330 if (ret != SAA_OK)
331 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
332
333 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR,
334 ( 0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v);
335 if (ret != SAA_OK)
336 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
337
338 dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v);
339
340 return ret;
341}
342
343int saa7164_api_set_audio_std(struct saa7164_port *port)
344{
345 struct saa7164_dev *dev = port->dev;
346 tmComResAudioDefaults_t lvl;
347 tmComResTunerStandard_t tvaudio;
348 int ret;
349
350 dprintk(DBGLVL_API, "%s()\n", __func__);
351
352 /* Establish default levels */
353 lvl.ucDecoderLevel = TMHW_LEV_ADJ_DECLEV_DEFAULT;
354 lvl.ucDecoderFM_Level = TMHW_LEV_ADJ_DECLEV_DEFAULT;
355 lvl.ucMonoLevel = TMHW_LEV_ADJ_MONOLEV_DEFAULT;
356 lvl.ucNICAM_Level = TMHW_LEV_ADJ_NICLEV_DEFAULT;
357 lvl.ucSAP_Level = TMHW_LEV_ADJ_SAPLEV_DEFAULT;
358 lvl.ucADC_Level = TMHW_LEV_ADJ_ADCLEV_DEFAULT;
359 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
360 AUDIO_DEFAULT_CONTROL, sizeof(tmComResAudioDefaults_t), &lvl);
361 if (ret != SAA_OK)
362 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
363
364 /* Manually select the appropriate TV audio standard */
365 if (port->encodernorm.id & V4L2_STD_NTSC) {
366 tvaudio.std = TU_STANDARD_NTSC_M;
367 tvaudio.country = 1;
368 } else {
369 tvaudio.std = TU_STANDARD_PAL_I;
370 tvaudio.country = 44;
371 }
372
373 ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
374 TU_STANDARD_CONTROL, sizeof(tvaudio), &tvaudio);
375 if (ret != SAA_OK)
376 printk(KERN_ERR "%s() TU_STANDARD_CONTROL error, ret = 0x%x\n", __func__, ret);
377 return ret;
378}
379
380int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect)
381{
382 struct saa7164_dev *dev = port->dev;
383 tmComResTunerStandardAuto_t p;
384 int ret;
385
386 dprintk(DBGLVL_API, "%s(%d)\n", __func__, autodetect);
387
388 /* Disable TV Audio autodetect if not already set (buggy) */
389 if (autodetect)
390 p.mode = TU_STANDARD_AUTO;
391 else
392 p.mode = TU_STANDARD_MANUAL;
393 ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
394 TU_STANDARD_AUTO_CONTROL, sizeof(p), &p);
395 if (ret != SAA_OK)
396 printk(KERN_ERR "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n", __func__, ret);
397
398 return ret;
399}
400
401int saa7164_api_get_videomux(struct saa7164_port *port)
402{
403 struct saa7164_dev *dev = port->dev;
404 int ret;
405
406 ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, GET_CUR,
407 SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input);
408 if (ret != SAA_OK)
409 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
410
411 dprintk(DBGLVL_ENC, "%s() v_mux=%d\n",
412 __func__, port->mux_input);
413
414 return ret;
415}
416
417int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val)
418{
419 struct saa7164_dev *dev = port->dev;
420
421 u16 len = 0;
422 u8 buf[256];
423 int ret;
424 u8 mas;
425
426 dprintk(DBGLVL_API, "%s()\n", __func__);
427
428 if (port->nr == 0)
429 mas = 0xd0;
430 else
431 mas = 0xe0;
432
433 memset(buf, 0, sizeof(buf));
434
435 buf[0x00] = 0x04;
436 buf[0x01] = 0x00;
437 buf[0x02] = 0x00;
438 buf[0x03] = 0x00;
439
440 buf[0x04] = 0x04;
441 buf[0x05] = 0x00;
442 buf[0x06] = 0x00;
443 buf[0x07] = 0x00;
444
445 buf[0x08] = reg;
446 buf[0x09] = 0x26;
447 buf[0x0a] = mas;
448 buf[0x0b] = 0xb0;
449
450 buf[0x0c] = val;
451 buf[0x0d] = 0x00;
452 buf[0x0e] = 0x00;
453 buf[0x0f] = 0x00;
454
455 ret = saa7164_cmd_send(dev, port->ifunit.unitid, GET_LEN,
456 EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
457 if (ret != SAA_OK) {
458 printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
459 return -EIO;
460 }
461
462 ret = saa7164_cmd_send(dev, port->ifunit.unitid, SET_CUR,
463 EXU_REGISTER_ACCESS_CONTROL, len, &buf);
464 if (ret != SAA_OK)
465 printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
466
467 //saa7164_dumphex16(dev, buf, 16);
468
469 return ret == SAA_OK ? 0 : -EIO;
470}
471
472/* Disable the IF block AGC controls */
473int saa7164_api_configure_dif(struct saa7164_port *port, u32 std)
474{
475 struct saa7164_dev *dev = port->dev;
476 int ret = 0;
477 u8 agc_disable;
478
479 dprintk(DBGLVL_API, "%s(%p, 0x%x)\n", __func__, port, std);
480
481 if (std & V4L2_STD_NTSC) {
482 dprintk(DBGLVL_API, " NTSC\n");
483 saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
484 agc_disable = 0;
485 } else if (std & V4L2_STD_PAL_I) {
486 dprintk(DBGLVL_API, " PAL-I\n");
487 saa7164_api_set_dif(port, 0x00, 0x08); /* Video Standard */
488 agc_disable = 0;
489 } else if (std & V4L2_STD_PAL_M) {
490 dprintk(DBGLVL_API, " PAL-M\n");
491 saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
492 agc_disable = 0;
493 } else if (std & V4L2_STD_PAL_N) {
494 dprintk(DBGLVL_API, " PAL-N\n");
495 saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
496 agc_disable = 0;
497 } else if (std & V4L2_STD_PAL_Nc) {
498 dprintk(DBGLVL_API, " PAL-Nc\n");
499 saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
500 agc_disable = 0;
501 } else if (std & V4L2_STD_PAL_B) {
502 dprintk(DBGLVL_API, " PAL-B\n");
503 saa7164_api_set_dif(port, 0x00, 0x02); /* Video Standard */
504 agc_disable = 0;
505 } else if (std & V4L2_STD_PAL_DK) {
506 dprintk(DBGLVL_API, " PAL-DK\n");
507 saa7164_api_set_dif(port, 0x00, 0x10); /* Video Standard */
508 agc_disable = 0;
509 } else if (std & V4L2_STD_SECAM_L) {
510 dprintk(DBGLVL_API, " SECAM-L\n");
511 saa7164_api_set_dif(port, 0x00, 0x20); /* Video Standard */
512 agc_disable = 0;
513 } else {
514 /* Unknown standard, assume DTV */
515 dprintk(DBGLVL_API, " Unknown (assuming DTV)\n");
516 saa7164_api_set_dif(port, 0x00, 0x80); /* Undefined Video Standard */
517 agc_disable = 1;
518 }
519
520 saa7164_api_set_dif(port, 0x48, 0xa0); /* AGC Functions 1 */
521 saa7164_api_set_dif(port, 0xc0, agc_disable); /* AGC Output Disable */
522 saa7164_api_set_dif(port, 0x7c, 0x04); /* CVBS EQ */
523 saa7164_api_set_dif(port, 0x04, 0x01); /* Active */
524 msleep(100);
525 saa7164_api_set_dif(port, 0x04, 0x00); /* Active (again) */
526 msleep(100);
527
528 return ret;
529}
530
531/* Ensure the dif is in the correct state for the operating mode
532 * (analog / dtv). We only configure the diff through the analog encoder
533 * so when we're in digital mode we need to find the appropriate encoder
534 * and use it to configure the DIF.
535 */
536int saa7164_api_initialize_dif(struct saa7164_port *port)
537{
538 struct saa7164_dev *dev = port->dev;
539 struct saa7164_port *p = 0;
540 int ret = -EINVAL;
541 u32 std = 0;
542
543 if (port->type == SAA7164_MPEG_ENCODER) {
544 /* Pick any analog standard to init the diff.
545 * we'll come back during encoder_init'
546 * and set the correct standard if requried.
547 */
548 std = V4L2_STD_NTSC;
549 } else
550 if (port->type == SAA7164_MPEG_DVB) {
551 if (port->nr == SAA7164_PORT_TS1)
552 p = &dev->ports[ SAA7164_PORT_ENC1 ];
553 else
554 p = &dev->ports[ SAA7164_PORT_ENC2 ];
555 } else
556 BUG();
557
558 if (p)
559 ret = saa7164_api_configure_dif(p, std);
560
561 return ret;
562}
563
27int saa7164_api_transition_port(struct saa7164_port *port, u8 mode) 564int saa7164_api_transition_port(struct saa7164_port *port, u8 mode)
28{ 565{
29 int ret; 566 int ret;
@@ -96,9 +633,43 @@ int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev,
96 return 0; 633 return 0;
97} 634}
98 635
636int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev *dev,
637 struct saa7164_port *port,
638 tmComResPSFormatDescrHeader_t *fmt)
639{
640 dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex);
641 dprintk(DBGLVL_API, " wPacketLength= 0x%x\n", fmt->wPacketLength);
642 dprintk(DBGLVL_API, " wPackLength= 0x%x\n", fmt->wPackLength);
643 dprintk(DBGLVL_API, " bPackDataType= 0x%x\n", fmt->bPackDataType);
644
645 /* Cache the hardware configuration in the port */
646 /* TODO: CHECK THIS in the port config */
647 port->bufcounter = port->hwcfg.BARLocation;
648 port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
649 port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
650 port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
651 port->bufptr32l = port->hwcfg.BARLocation +
652 (4 * sizeof(u32)) +
653 (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
654 port->bufptr32h = port->hwcfg.BARLocation +
655 (4 * sizeof(u32)) +
656 (sizeof(u32) * port->hwcfg.buffercount);
657 port->bufptr64 = port->hwcfg.BARLocation +
658 (4 * sizeof(u32)) +
659 (sizeof(u32) * port->hwcfg.buffercount);
660 dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
661 port->hwcfg.BARLocation);
662
663 dprintk(DBGLVL_API, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
664 port->nr);
665
666 return 0;
667}
668
99int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) 669int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
100{ 670{
101 struct saa7164_port *port = 0; 671 struct saa7164_port *tsport = 0;
672 struct saa7164_port *encport = 0;
102 u32 idx, next_offset; 673 u32 idx, next_offset;
103 int i; 674 int i;
104 tmComResDescrHeader_t *hdr, *t; 675 tmComResDescrHeader_t *hdr, *t;
@@ -108,6 +679,11 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
108 tmComResTunerDescrHeader_t *tunerunithdr; 679 tmComResTunerDescrHeader_t *tunerunithdr;
109 tmComResDMATermDescrHeader_t *vcoutputtermhdr; 680 tmComResDMATermDescrHeader_t *vcoutputtermhdr;
110 tmComResTSFormatDescrHeader_t *tsfmt; 681 tmComResTSFormatDescrHeader_t *tsfmt;
682 tmComResPSFormatDescrHeader_t *psfmt;
683 tmComResSelDescrHeader_t *psel;
684 tmComResProcDescrHeader_t *pdh;
685 tmComResAFeatureDescrHeader_t *afd;
686 tmComResEncoderDescrHeader_t *edh;
111 u32 currpath = 0; 687 u32 currpath = 0;
112 688
113 dprintk(DBGLVL_API, 689 dprintk(DBGLVL_API,
@@ -244,17 +820,25 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
244 tsfmt = 820 tsfmt =
245 (tmComResTSFormatDescrHeader_t *)t; 821 (tmComResTSFormatDescrHeader_t *)t;
246 if (currpath == 1) 822 if (currpath == 1)
247 port = &dev->ts1; 823 tsport = &dev->ports[ SAA7164_PORT_TS1 ];
248 else 824 else
249 port = &dev->ts2; 825 tsport = &dev->ports[ SAA7164_PORT_TS2 ];
250 memcpy(&port->hwcfg, vcoutputtermhdr, 826 memcpy(&tsport->hwcfg, vcoutputtermhdr,
251 sizeof(*vcoutputtermhdr)); 827 sizeof(*vcoutputtermhdr));
252 saa7164_api_configure_port_mpeg2ts(dev, 828 saa7164_api_configure_port_mpeg2ts(dev,
253 port, tsfmt); 829 tsport, tsfmt);
254 break; 830 break;
255 case VS_FORMAT_MPEG2PS: 831 case VS_FORMAT_MPEG2PS:
256 dprintk(DBGLVL_API, 832 psfmt =
257 " = VS_FORMAT_MPEG2PS\n"); 833 (tmComResPSFormatDescrHeader_t *)t;
834 if (currpath == 1)
835 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
836 else
837 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
838 memcpy(&encport->hwcfg, vcoutputtermhdr,
839 sizeof(*vcoutputtermhdr));
840 saa7164_api_configure_port_mpeg2ps(dev,
841 encport, psfmt);
258 break; 842 break;
259 case VS_FORMAT_VBI: 843 case VS_FORMAT_VBI:
260 dprintk(DBGLVL_API, 844 dprintk(DBGLVL_API,
@@ -297,18 +881,80 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
297 tunerunithdr->controlsize); 881 tunerunithdr->controlsize);
298 dprintk(DBGLVL_API, " controls = 0x%x\n", 882 dprintk(DBGLVL_API, " controls = 0x%x\n",
299 tunerunithdr->controls); 883 tunerunithdr->controls);
884
885 if (tunerunithdr->unitid == tunerunithdr->iunit) {
886 if (currpath == 1)
887 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
888 else
889 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
890 memcpy(&encport->tunerunit, tunerunithdr,
891 sizeof(tmComResTunerDescrHeader_t));
892 dprintk(DBGLVL_API, " (becomes dev->enc[%d] tuner)\n", encport->nr);
893 }
300 break; 894 break;
301 case VC_SELECTOR_UNIT: 895 case VC_SELECTOR_UNIT:
896 psel = (tmComResSelDescrHeader_t *)(buf + idx);
302 dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n"); 897 dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n");
898 dprintk(DBGLVL_API, " unitid = 0x%x\n",
899 psel->unitid);
900 dprintk(DBGLVL_API, " nrinpins = 0x%x\n",
901 psel->nrinpins);
902 dprintk(DBGLVL_API, " sourceid = 0x%x\n",
903 psel->sourceid);
303 break; 904 break;
304 case VC_PROCESSING_UNIT: 905 case VC_PROCESSING_UNIT:
906 pdh = (tmComResProcDescrHeader_t *)(buf + idx);
305 dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n"); 907 dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n");
908 dprintk(DBGLVL_API, " unitid = 0x%x\n",
909 pdh->unitid);
910 dprintk(DBGLVL_API, " sourceid = 0x%x\n",
911 pdh->sourceid);
912 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
913 pdh->controlsize);
914 if (pdh->controlsize == 0x04) {
915 if (currpath == 1)
916 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
917 else
918 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
919 memcpy(&encport->vidproc, pdh,
920 sizeof(tmComResProcDescrHeader_t));
921 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr);
922 }
306 break; 923 break;
307 case FEATURE_UNIT: 924 case FEATURE_UNIT:
925 afd = (tmComResAFeatureDescrHeader_t *)(buf + idx);
308 dprintk(DBGLVL_API, " FEATURE_UNIT\n"); 926 dprintk(DBGLVL_API, " FEATURE_UNIT\n");
927 dprintk(DBGLVL_API, " unitid = 0x%x\n",
928 afd->unitid);
929 dprintk(DBGLVL_API, " sourceid = 0x%x\n",
930 afd->sourceid);
931 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
932 afd->controlsize);
933 if (currpath == 1)
934 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
935 else
936 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
937 memcpy(&encport->audfeat, afd,
938 sizeof(tmComResAFeatureDescrHeader_t));
939 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr);
309 break; 940 break;
310 case ENCODER_UNIT: 941 case ENCODER_UNIT:
942 edh = (tmComResEncoderDescrHeader_t *)(buf + idx);
311 dprintk(DBGLVL_API, " ENCODER_UNIT\n"); 943 dprintk(DBGLVL_API, " ENCODER_UNIT\n");
944 dprintk(DBGLVL_API, " subtype = 0x%x\n", edh->subtype);
945 dprintk(DBGLVL_API, " unitid = 0x%x\n", edh->unitid);
946 dprintk(DBGLVL_API, " vsourceid = 0x%x\n", edh->vsourceid);
947 dprintk(DBGLVL_API, " asourceid = 0x%x\n", edh->asourceid);
948 dprintk(DBGLVL_API, " iunit = 0x%x\n", edh->iunit);
949 if (edh->iunit == edh->unitid) {
950 if (currpath == 1)
951 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
952 else
953 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
954 memcpy(&encport->encunit, edh,
955 sizeof(tmComResEncoderDescrHeader_t));
956 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr);
957 }
312 break; 958 break;
313 case EXTENSION_UNIT: 959 case EXTENSION_UNIT:
314 dprintk(DBGLVL_API, " EXTENSION_UNIT\n"); 960 dprintk(DBGLVL_API, " EXTENSION_UNIT\n");
@@ -364,6 +1010,15 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
364 exthdr->numgpiogroups); 1010 exthdr->numgpiogroups);
365 dprintk(DBGLVL_API, " controlsize = 0x%x\n", 1011 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
366 exthdr->controlsize); 1012 exthdr->controlsize);
1013 if (exthdr->devicetype & 0x80) {
1014 if (currpath == 1)
1015 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
1016 else
1017 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
1018 memcpy(&encport->ifunit, exthdr,
1019 sizeof(tmComResExtDevDescrHeader_t));
1020 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr);
1021 }
367 break; 1022 break;
368 case PVC_INFRARED_UNIT: 1023 case PVC_INFRARED_UNIT:
369 dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n"); 1024 dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n");