[media] saa7164: monitor the RISC cpu load via a thread
[deliverable/linux.git] / drivers / media / video / saa7164 / saa7164-api.c
1 /*
2 * Driver for the NXP SAA7164 PCIe bridge
3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include <linux/wait.h>
23 #include <linux/slab.h>
24
25 #include "saa7164.h"
26
27 int saa7164_api_get_load_info(struct saa7164_dev *dev, tmFwInfoStruct_t *i)
28 {
29 int ret, debug;
30
31 if (!(debug & DBGLVL_CPU))
32 return 0;
33
34 dprintk(DBGLVL_API, "%s()\n", __func__);
35
36 i->deviceinst = 0;
37 i->devicespec = 0;
38 i->mode = 0;
39 i->status = 0;
40
41 ret = saa7164_cmd_send(dev, 0, GET_CUR,
42 GET_FW_STATUS_CONTROL, sizeof(tmFwInfoStruct_t), i);
43 if (ret != SAA_OK) {
44 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
45 }
46
47 printk(KERN_INFO "saa7164[%d]-CPU: %d percent", dev->nr, i->CPULoad);
48
49 return ret;
50 }
51
52 int saa7164_api_collect_debug(struct saa7164_dev *dev)
53 {
54 tmComResDebugGetData_t d;
55 u8 more = 255;
56 int ret;
57
58 dprintk(DBGLVL_API, "%s()\n", __func__);
59
60 while (more--) {
61
62 memset(&d, 0, sizeof(d));
63
64 ret = saa7164_cmd_send(dev, 0, GET_CUR,
65 GET_DEBUG_DATA_CONTROL, sizeof(d), &d);
66 if (ret != SAA_OK) {
67 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
68 }
69
70 if (d.dwResult != SAA_OK)
71 break;
72
73 printk(KERN_INFO "saa7164[%d]-FWMSG: %s", dev->nr, d.ucDebugData);
74 }
75
76 return 0;
77 }
78
79 int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level)
80 {
81 tmComResDebugSetLevel_t lvl;
82 int ret;
83
84 dprintk(DBGLVL_API, "%s(level=%d)\n", __func__, level);
85
86 /* Retrieve current state */
87 ret = saa7164_cmd_send(dev, 0, GET_CUR,
88 SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl);
89 if (ret != SAA_OK) {
90 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
91 }
92 dprintk(DBGLVL_API, "%s() Was %d\n", __func__, lvl.dwDebugLevel);
93
94 lvl.dwDebugLevel = level;
95
96 /* set new state */
97 ret = saa7164_cmd_send(dev, 0, SET_CUR,
98 SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl);
99 if (ret != SAA_OK) {
100 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
101 }
102
103 return ret;
104 }
105
106 int saa7164_api_set_vbi_format(struct saa7164_port *port)
107 {
108 struct saa7164_dev *dev = port->dev;
109 tmComResProbeCommit_t fmt, rsp;
110 int ret;
111
112 dprintk(DBGLVL_API, "%s(nr=%d, unitid=0x%x)\n", __func__,
113 port->nr, port->hwcfg.unitid);
114
115 fmt.bmHint = 0;
116 fmt.bFormatIndex = 1;
117 fmt.bFrameIndex = 1;
118
119 /* Probe, see if it can support this format */
120 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
121 SET_CUR, SAA_PROBE_CONTROL, sizeof(fmt), &fmt);
122 if (ret != SAA_OK)
123 printk(KERN_ERR "%s() set error, ret = 0x%x\n", __func__, ret);
124
125 /* See of the format change was successful */
126 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
127 GET_CUR, SAA_PROBE_CONTROL, sizeof(rsp), &rsp);
128 if (ret != SAA_OK) {
129 printk(KERN_ERR "%s() get error, ret = 0x%x\n", __func__, ret);
130 } else {
131 /* Compare requested vs received, should be same */
132 if (memcmp(&fmt, &rsp, sizeof(rsp)) == 0) {
133 dprintk(DBGLVL_API, "SET/PROBE Verified\n");
134
135 /* Ask the device to select the negotiated format */
136 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
137 SET_CUR, SAA_COMMIT_CONTROL, sizeof(fmt), &fmt);
138 if (ret != SAA_OK)
139 printk(KERN_ERR "%s() commit error, ret = 0x%x\n",
140 __func__, ret);
141
142 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
143 GET_CUR, SAA_COMMIT_CONTROL, sizeof(rsp), &rsp);
144 if (ret != SAA_OK)
145 printk(KERN_ERR "%s() GET commit error, ret = 0x%x\n",
146 __func__, ret);
147
148 if (memcmp(&fmt, &rsp, sizeof(rsp)) != 0) {
149 printk(KERN_ERR "%s() memcmp error, ret = 0x%x\n",
150 __func__, ret);
151 } else
152 dprintk(DBGLVL_API, "SET/COMMIT Verified\n");
153
154 dprintk(DBGLVL_API, "rsp.bmHint = 0x%x\n", rsp.bmHint);
155 dprintk(DBGLVL_API, "rsp.bFormatIndex = 0x%x\n", rsp.bFormatIndex);
156 dprintk(DBGLVL_API, "rsp.bFrameIndex = 0x%x\n", rsp.bFrameIndex);
157 } else
158 printk(KERN_ERR "%s() compare failed\n", __func__);
159 }
160
161 if (ret == SAA_OK)
162 dprintk(DBGLVL_API, "%s(nr=%d) Success\n", __func__, port->nr);
163
164 return ret;
165 }
166
167 int saa7164_api_set_gop_size(struct saa7164_port *port)
168 {
169 struct saa7164_dev *dev = port->dev;
170 tmComResEncVideoGopStructure_t gs;
171 int ret;
172
173 dprintk(DBGLVL_ENC, "%s()\n", __func__);
174
175 gs.ucRefFrameDist = port->encoder_params.refdist;
176 gs.ucGOPSize = port->encoder_params.gop_size;
177 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
178 EU_VIDEO_GOP_STRUCTURE_CONTROL,
179 sizeof(gs), &gs);
180 if (ret != SAA_OK)
181 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
182
183 return ret;
184 }
185
186 int saa7164_api_set_encoder(struct saa7164_port *port)
187 {
188 struct saa7164_dev *dev = port->dev;
189 tmComResEncVideoBitRate_t vb;
190 tmComResEncAudioBitRate_t ab;
191 int ret;
192
193 dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__,
194 port->hwcfg.sourceid);
195
196 if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS)
197 port->encoder_profile = EU_PROFILE_PS_DVD;
198 else
199 port->encoder_profile = EU_PROFILE_TS_HQ;
200
201 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
202 EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
203 if (ret != SAA_OK)
204 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
205
206 /* Resolution */
207 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
208 EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
209 if (ret != SAA_OK)
210 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
211
212 /* Establish video bitrates */
213 if (port->encoder_params.bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
214 vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_CONSTANT;
215 else
216 vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK;
217 vb.dwVideoBitRate = port->encoder_params.bitrate;
218 vb.dwVideoBitRatePeak = port->encoder_params.bitrate_peak;
219 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
220 EU_VIDEO_BIT_RATE_CONTROL, sizeof(tmComResEncVideoBitRate_t), &vb);
221 if (ret != SAA_OK)
222 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
223
224 /* Establish audio bitrates */
225 ab.ucAudioBitRateMode = 0;
226 ab.dwAudioBitRate = 384000;
227 ab.dwAudioBitRatePeak = ab.dwAudioBitRate;
228 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
229 EU_AUDIO_BIT_RATE_CONTROL, sizeof(tmComResEncAudioBitRate_t), &ab);
230 if (ret != SAA_OK)
231 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
232
233 saa7164_api_set_aspect_ratio(port);
234 saa7164_api_set_gop_size(port);
235
236 return ret;
237 }
238
239 int saa7164_api_get_encoder(struct saa7164_port *port)
240 {
241 struct saa7164_dev *dev = port->dev;
242 tmComResEncVideoBitRate_t v;
243 tmComResEncAudioBitRate_t a;
244 tmComResEncVideoInputAspectRatio_t ar;
245 int ret;
246
247 dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, port->hwcfg.sourceid);
248
249 port->encoder_profile = 0;
250 port->video_format = 0;
251 port->video_resolution = 0;
252 port->audio_format = 0;
253
254 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
255 EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
256 if (ret != SAA_OK)
257 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
258
259 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
260 EU_VIDEO_RESOLUTION_CONTROL, sizeof(u8), &port->video_resolution);
261 if (ret != SAA_OK)
262 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
263
264 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
265 EU_VIDEO_FORMAT_CONTROL, sizeof(u8), &port->video_format);
266 if (ret != SAA_OK)
267 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
268
269 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
270 EU_VIDEO_BIT_RATE_CONTROL, sizeof(v), &v);
271 if (ret != SAA_OK)
272 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
273
274 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
275 EU_AUDIO_FORMAT_CONTROL, sizeof(u8), &port->audio_format);
276 if (ret != SAA_OK)
277 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
278
279 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
280 EU_AUDIO_BIT_RATE_CONTROL, sizeof(a), &a);
281 if (ret != SAA_OK)
282 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
283
284 /* Aspect Ratio */
285 ar.width = 0;
286 ar.height = 0;
287 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
288 EU_VIDEO_INPUT_ASPECT_CONTROL,
289 sizeof(tmComResEncVideoInputAspectRatio_t), &ar);
290 if (ret != SAA_OK)
291 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
292
293 dprintk(DBGLVL_ENC, "encoder_profile = %d\n", port->encoder_profile);
294 dprintk(DBGLVL_ENC, "video_format = %d\n", port->video_format);
295 dprintk(DBGLVL_ENC, "audio_format = %d\n", port->audio_format);
296 dprintk(DBGLVL_ENC, "video_resolution= %d\n", port->video_resolution);
297 dprintk(DBGLVL_ENC, "v.ucVideoBitRateMode = %d\n", v.ucVideoBitRateMode);
298 dprintk(DBGLVL_ENC, "v.dwVideoBitRate = %d\n", v.dwVideoBitRate);
299 dprintk(DBGLVL_ENC, "v.dwVideoBitRatePeak = %d\n", v.dwVideoBitRatePeak);
300 dprintk(DBGLVL_ENC, "a.ucVideoBitRateMode = %d\n", a.ucAudioBitRateMode);
301 dprintk(DBGLVL_ENC, "a.dwVideoBitRate = %d\n", a.dwAudioBitRate);
302 dprintk(DBGLVL_ENC, "a.dwVideoBitRatePeak = %d\n", a.dwAudioBitRatePeak);
303 dprintk(DBGLVL_ENC, "aspect.width / height = %d:%d\n", ar.width, ar.height);
304
305 return ret;
306 }
307
308 int saa7164_api_set_aspect_ratio(struct saa7164_port *port)
309 {
310 struct saa7164_dev *dev = port->dev;
311 tmComResEncVideoInputAspectRatio_t ar;
312 int ret;
313
314 dprintk(DBGLVL_ENC, "%s(%d)\n", __func__,
315 port->encoder_params.ctl_aspect);
316
317 switch (port->encoder_params.ctl_aspect) {
318 case V4L2_MPEG_VIDEO_ASPECT_1x1:
319 ar.width = 1;
320 ar.height = 1;
321 break;
322 case V4L2_MPEG_VIDEO_ASPECT_4x3:
323 ar.width = 4;
324 ar.height = 3;
325 break;
326 case V4L2_MPEG_VIDEO_ASPECT_16x9:
327 ar.width = 16;
328 ar.height = 9;
329 break;
330 case V4L2_MPEG_VIDEO_ASPECT_221x100:
331 ar.width = 221;
332 ar.height = 100;
333 break;
334 default:
335 BUG();
336 }
337
338 dprintk(DBGLVL_ENC, "%s(%d) now %d:%d\n", __func__,
339 port->encoder_params.ctl_aspect,
340 ar.width, ar.height);
341
342 /* Aspect Ratio */
343 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
344 EU_VIDEO_INPUT_ASPECT_CONTROL,
345 sizeof(tmComResEncVideoInputAspectRatio_t), &ar);
346 if (ret != SAA_OK)
347 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
348
349 return ret;
350 }
351
352 int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl)
353 {
354 struct saa7164_dev *dev = port->dev;
355 int ret;
356 u16 val;
357
358 if (ctl == PU_BRIGHTNESS_CONTROL)
359 val = port->ctl_brightness;
360 else
361 if (ctl == PU_CONTRAST_CONTROL)
362 val = port->ctl_contrast;
363 else
364 if (ctl == PU_HUE_CONTROL)
365 val = port->ctl_hue;
366 else
367 if (ctl == PU_SATURATION_CONTROL)
368 val = port->ctl_saturation;
369 else
370 if (ctl == PU_SHARPNESS_CONTROL)
371 val = port->ctl_sharpness;
372 else
373 return -EINVAL;
374
375 dprintk(DBGLVL_ENC, "%s() unitid=0x%x ctl=%d, val=%d\n",
376 __func__, port->encunit.vsourceid, ctl, val);
377
378 ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, SET_CUR,
379 ctl, sizeof(u16), &val);
380 if (ret != SAA_OK)
381 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
382
383 return ret;
384 }
385
386 int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl)
387 {
388 struct saa7164_dev *dev = port->dev;
389 int ret;
390 u16 val;
391
392 ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, GET_CUR,
393 ctl, sizeof(u16), &val);
394 if (ret != SAA_OK) {
395 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
396 return ret;
397 }
398
399 dprintk(DBGLVL_ENC, "%s() ctl=%d, val=%d\n",
400 __func__, ctl, val);
401
402 if (ctl == PU_BRIGHTNESS_CONTROL)
403 port->ctl_brightness = val;
404 else
405 if (ctl == PU_CONTRAST_CONTROL)
406 port->ctl_contrast = val;
407 else
408 if (ctl == PU_HUE_CONTROL)
409 port->ctl_hue = val;
410 else
411 if (ctl == PU_SATURATION_CONTROL)
412 port->ctl_saturation = val;
413 else
414 if (ctl == PU_SHARPNESS_CONTROL)
415 port->ctl_sharpness = val;
416
417 return ret;
418 }
419
420 int saa7164_api_set_videomux(struct saa7164_port *port)
421 {
422 struct saa7164_dev *dev = port->dev;
423 u8 inputs[] = { 1, 2, 2, 2, 5, 5, 5 };
424 int ret;
425
426 dprintk(DBGLVL_ENC, "%s() v_mux=%d a_mux=%d\n",
427 __func__, port->mux_input, inputs[ port->mux_input - 1 ]);
428
429 /* Audio Mute */
430 ret = saa7164_api_audio_mute(port, 1);
431 if (ret != SAA_OK)
432 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
433
434 /* Video Mux */
435 ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, SET_CUR,
436 SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input);
437 if (ret != SAA_OK)
438 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
439 /* Audio Mux */
440 ret = saa7164_cmd_send(port->dev, port->audfeat.sourceid, SET_CUR,
441 SU_INPUT_SELECT_CONTROL, sizeof(u8), &inputs[ port->mux_input - 1 ]);
442 if (ret != SAA_OK)
443 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
444 /* Audio UnMute */
445 ret = saa7164_api_audio_mute(port, 0);
446 if (ret != SAA_OK)
447 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
448
449 return ret;
450 }
451
452 int saa7164_api_audio_mute(struct saa7164_port *port, int mute)
453 {
454 struct saa7164_dev *dev = port->dev;
455 u8 v = mute;
456 int ret;
457
458 dprintk(DBGLVL_API, "%s(%d)\n", __func__, mute);
459
460 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
461 MUTE_CONTROL, sizeof(u8), &v);
462 if (ret != SAA_OK)
463 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
464
465 return ret;
466 }
467
468 /* 0 = silence, 0xff = full */
469 int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level)
470 {
471 struct saa7164_dev *dev = port->dev;
472 s16 v, min, max;
473 int ret;
474
475 dprintk(DBGLVL_API, "%s(%d)\n", __func__, level);
476
477 /* Obtain the min/max ranges */
478 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MIN,
479 VOLUME_CONTROL, sizeof(u16), &min);
480 if (ret != SAA_OK)
481 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
482
483 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MAX,
484 VOLUME_CONTROL, sizeof(u16), &max);
485 if (ret != SAA_OK)
486 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
487
488 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR,
489 ( 0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v);
490 if (ret != SAA_OK)
491 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
492
493 dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v);
494
495 v = level;
496 if (v < min)
497 v = min;
498 if (v > max)
499 v = max;
500
501 /* Left */
502 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
503 ( 0x01 << 8 ) | VOLUME_CONTROL, sizeof(s16), &v);
504 if (ret != SAA_OK)
505 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
506
507 /* Right */
508 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
509 ( 0x02 << 8 ) | VOLUME_CONTROL, sizeof(s16), &v);
510 if (ret != SAA_OK)
511 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
512
513 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR,
514 ( 0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v);
515 if (ret != SAA_OK)
516 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
517
518 dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v);
519
520 return ret;
521 }
522
523 int saa7164_api_set_audio_std(struct saa7164_port *port)
524 {
525 struct saa7164_dev *dev = port->dev;
526 tmComResAudioDefaults_t lvl;
527 tmComResTunerStandard_t tvaudio;
528 int ret;
529
530 dprintk(DBGLVL_API, "%s()\n", __func__);
531
532 /* Establish default levels */
533 lvl.ucDecoderLevel = TMHW_LEV_ADJ_DECLEV_DEFAULT;
534 lvl.ucDecoderFM_Level = TMHW_LEV_ADJ_DECLEV_DEFAULT;
535 lvl.ucMonoLevel = TMHW_LEV_ADJ_MONOLEV_DEFAULT;
536 lvl.ucNICAM_Level = TMHW_LEV_ADJ_NICLEV_DEFAULT;
537 lvl.ucSAP_Level = TMHW_LEV_ADJ_SAPLEV_DEFAULT;
538 lvl.ucADC_Level = TMHW_LEV_ADJ_ADCLEV_DEFAULT;
539 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
540 AUDIO_DEFAULT_CONTROL, sizeof(tmComResAudioDefaults_t), &lvl);
541 if (ret != SAA_OK)
542 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
543
544 /* Manually select the appropriate TV audio standard */
545 if (port->encodernorm.id & V4L2_STD_NTSC) {
546 tvaudio.std = TU_STANDARD_NTSC_M;
547 tvaudio.country = 1;
548 } else {
549 tvaudio.std = TU_STANDARD_PAL_I;
550 tvaudio.country = 44;
551 }
552
553 ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
554 TU_STANDARD_CONTROL, sizeof(tvaudio), &tvaudio);
555 if (ret != SAA_OK)
556 printk(KERN_ERR "%s() TU_STANDARD_CONTROL error, ret = 0x%x\n", __func__, ret);
557 return ret;
558 }
559
560 int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect)
561 {
562 struct saa7164_dev *dev = port->dev;
563 tmComResTunerStandardAuto_t p;
564 int ret;
565
566 dprintk(DBGLVL_API, "%s(%d)\n", __func__, autodetect);
567
568 /* Disable TV Audio autodetect if not already set (buggy) */
569 if (autodetect)
570 p.mode = TU_STANDARD_AUTO;
571 else
572 p.mode = TU_STANDARD_MANUAL;
573 ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
574 TU_STANDARD_AUTO_CONTROL, sizeof(p), &p);
575 if (ret != SAA_OK)
576 printk(KERN_ERR "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n", __func__, ret);
577
578 return ret;
579 }
580
581 int saa7164_api_get_videomux(struct saa7164_port *port)
582 {
583 struct saa7164_dev *dev = port->dev;
584 int ret;
585
586 ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, GET_CUR,
587 SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input);
588 if (ret != SAA_OK)
589 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
590
591 dprintk(DBGLVL_ENC, "%s() v_mux=%d\n",
592 __func__, port->mux_input);
593
594 return ret;
595 }
596
597 int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val)
598 {
599 struct saa7164_dev *dev = port->dev;
600
601 u16 len = 0;
602 u8 buf[256];
603 int ret;
604 u8 mas;
605
606 dprintk(DBGLVL_API, "%s(nr=%d type=%d val=%x)\n", __func__,
607 port->nr, port->type, val);
608
609 if (port->nr == 0)
610 mas = 0xd0;
611 else
612 mas = 0xe0;
613
614 memset(buf, 0, sizeof(buf));
615
616 buf[0x00] = 0x04;
617 buf[0x01] = 0x00;
618 buf[0x02] = 0x00;
619 buf[0x03] = 0x00;
620
621 buf[0x04] = 0x04;
622 buf[0x05] = 0x00;
623 buf[0x06] = 0x00;
624 buf[0x07] = 0x00;
625
626 buf[0x08] = reg;
627 buf[0x09] = 0x26;
628 buf[0x0a] = mas;
629 buf[0x0b] = 0xb0;
630
631 buf[0x0c] = val;
632 buf[0x0d] = 0x00;
633 buf[0x0e] = 0x00;
634 buf[0x0f] = 0x00;
635
636 ret = saa7164_cmd_send(dev, port->ifunit.unitid, GET_LEN,
637 EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
638 if (ret != SAA_OK) {
639 printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
640 return -EIO;
641 }
642
643 ret = saa7164_cmd_send(dev, port->ifunit.unitid, SET_CUR,
644 EXU_REGISTER_ACCESS_CONTROL, len, &buf);
645 if (ret != SAA_OK)
646 printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
647
648 //saa7164_dumphex16(dev, buf, 16);
649
650 return ret == SAA_OK ? 0 : -EIO;
651 }
652
653 /* Disable the IF block AGC controls */
654 int saa7164_api_configure_dif(struct saa7164_port *port, u32 std)
655 {
656 struct saa7164_dev *dev = port->dev;
657 int ret = 0;
658 u8 agc_disable;
659
660 dprintk(DBGLVL_API, "%s(nr=%d, 0x%x)\n", __func__, port->nr, std);
661
662 if (std & V4L2_STD_NTSC) {
663 dprintk(DBGLVL_API, " NTSC\n");
664 saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
665 agc_disable = 0;
666 } else if (std & V4L2_STD_PAL_I) {
667 dprintk(DBGLVL_API, " PAL-I\n");
668 saa7164_api_set_dif(port, 0x00, 0x08); /* Video Standard */
669 agc_disable = 0;
670 } else if (std & V4L2_STD_PAL_M) {
671 dprintk(DBGLVL_API, " PAL-M\n");
672 saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
673 agc_disable = 0;
674 } else if (std & V4L2_STD_PAL_N) {
675 dprintk(DBGLVL_API, " PAL-N\n");
676 saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
677 agc_disable = 0;
678 } else if (std & V4L2_STD_PAL_Nc) {
679 dprintk(DBGLVL_API, " PAL-Nc\n");
680 saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
681 agc_disable = 0;
682 } else if (std & V4L2_STD_PAL_B) {
683 dprintk(DBGLVL_API, " PAL-B\n");
684 saa7164_api_set_dif(port, 0x00, 0x02); /* Video Standard */
685 agc_disable = 0;
686 } else if (std & V4L2_STD_PAL_DK) {
687 dprintk(DBGLVL_API, " PAL-DK\n");
688 saa7164_api_set_dif(port, 0x00, 0x10); /* Video Standard */
689 agc_disable = 0;
690 } else if (std & V4L2_STD_SECAM_L) {
691 dprintk(DBGLVL_API, " SECAM-L\n");
692 saa7164_api_set_dif(port, 0x00, 0x20); /* Video Standard */
693 agc_disable = 0;
694 } else {
695 /* Unknown standard, assume DTV */
696 dprintk(DBGLVL_API, " Unknown (assuming DTV)\n");
697 saa7164_api_set_dif(port, 0x00, 0x80); /* Undefined Video Standard */
698 agc_disable = 1;
699 }
700
701 saa7164_api_set_dif(port, 0x48, 0xa0); /* AGC Functions 1 */
702 saa7164_api_set_dif(port, 0xc0, agc_disable); /* AGC Output Disable */
703 saa7164_api_set_dif(port, 0x7c, 0x04); /* CVBS EQ */
704 saa7164_api_set_dif(port, 0x04, 0x01); /* Active */
705 msleep(100);
706 saa7164_api_set_dif(port, 0x04, 0x00); /* Active (again) */
707 msleep(100);
708
709 return ret;
710 }
711
712 /* Ensure the dif is in the correct state for the operating mode
713 * (analog / dtv). We only configure the diff through the analog encoder
714 * so when we're in digital mode we need to find the appropriate encoder
715 * and use it to configure the DIF.
716 */
717 int saa7164_api_initialize_dif(struct saa7164_port *port)
718 {
719 struct saa7164_dev *dev = port->dev;
720 struct saa7164_port *p = 0;
721 int ret = -EINVAL;
722 u32 std = 0;
723
724 dprintk(DBGLVL_API, "%s(nr=%d type=%d)\n", __func__,
725 port->nr, port->type);
726
727 if (port->type == SAA7164_MPEG_ENCODER) {
728 /* Pick any analog standard to init the diff.
729 * we'll come back during encoder_init'
730 * and set the correct standard if requried.
731 */
732 std = V4L2_STD_NTSC;
733 } else
734 if (port->type == SAA7164_MPEG_DVB) {
735 if (port->nr == SAA7164_PORT_TS1)
736 p = &dev->ports[ SAA7164_PORT_ENC1 ];
737 else
738 p = &dev->ports[ SAA7164_PORT_ENC2 ];
739 } else
740 if (port->type == SAA7164_MPEG_VBI) {
741 std = V4L2_STD_NTSC;
742 if (port->nr == SAA7164_PORT_VBI1)
743 p = &dev->ports[ SAA7164_PORT_ENC1 ];
744 else
745 p = &dev->ports[ SAA7164_PORT_ENC2 ];
746 } else
747 BUG();
748
749 if (p)
750 ret = saa7164_api_configure_dif(p, std);
751
752 return ret;
753 }
754
755 int saa7164_api_transition_port(struct saa7164_port *port, u8 mode)
756 {
757 struct saa7164_dev *dev = port->dev;
758
759 int ret;
760
761 dprintk(DBGLVL_API, "%s(nr=%d unitid=0x%x,%d)\n",
762 __func__, port->nr, port->hwcfg.unitid, mode);
763
764 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR,
765 SAA_STATE_CONTROL, sizeof(mode), &mode);
766 if (ret != SAA_OK)
767 printk(KERN_ERR "%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
768 __func__, port->nr, port->hwcfg.unitid, ret);
769
770 return ret;
771 }
772
773 int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version)
774 {
775 int ret;
776
777 ret = saa7164_cmd_send(dev, 0, GET_CUR,
778 GET_FW_VERSION_CONTROL, sizeof(u32), version);
779 if (ret != SAA_OK)
780 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
781
782 return ret;
783 }
784
785 int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen)
786 {
787 u8 reg[] = { 0x0f, 0x00 };
788
789 if (buflen < 128)
790 return -ENOMEM;
791
792 /* Assumption: Hauppauge eeprom is at 0xa0 on on bus 0 */
793 /* TODO: Pull the details from the boards struct */
794 return saa7164_api_i2c_read(&dev->i2c_bus[0], 0xa0 >> 1, sizeof(reg),
795 &reg[0], 128, buf);
796 }
797
798
799 int saa7164_api_configure_port_vbi(struct saa7164_dev *dev,
800 struct saa7164_port *port)
801 {
802 tmComResVBIFormatDescrHeader_t *fmt = &port->vbi_fmt_ntsc;
803
804 dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex);
805 dprintk(DBGLVL_API, " VideoStandard = 0x%x\n", fmt->VideoStandard);
806 dprintk(DBGLVL_API, " StartLine = %d\n", fmt->StartLine);
807 dprintk(DBGLVL_API, " EndLine = %d\n", fmt->EndLine);
808 dprintk(DBGLVL_API, " FieldRate = %d\n", fmt->FieldRate);
809 dprintk(DBGLVL_API, " bNumLines = %d\n", fmt->bNumLines);
810
811 /* Cache the hardware configuration in the port */
812
813 port->bufcounter = port->hwcfg.BARLocation;
814 port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
815 port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
816 port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
817 port->bufptr32l = port->hwcfg.BARLocation +
818 (4 * sizeof(u32)) +
819 (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
820 port->bufptr32h = port->hwcfg.BARLocation +
821 (4 * sizeof(u32)) +
822 (sizeof(u32) * port->hwcfg.buffercount);
823 port->bufptr64 = port->hwcfg.BARLocation +
824 (4 * sizeof(u32)) +
825 (sizeof(u32) * port->hwcfg.buffercount);
826 dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
827 port->hwcfg.BARLocation);
828
829 dprintk(DBGLVL_API, " = VS_FORMAT_VBI (becomes dev->en[%d])\n",
830 port->nr);
831
832 return 0;
833 }
834
835 int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev,
836 struct saa7164_port *port,
837 tmComResTSFormatDescrHeader_t *tsfmt)
838 {
839 dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", tsfmt->bFormatIndex);
840 dprintk(DBGLVL_API, " bDataOffset = 0x%x\n", tsfmt->bDataOffset);
841 dprintk(DBGLVL_API, " bPacketLength= 0x%x\n", tsfmt->bPacketLength);
842 dprintk(DBGLVL_API, " bStrideLength= 0x%x\n", tsfmt->bStrideLength);
843 dprintk(DBGLVL_API, " bguid = (....)\n");
844
845 /* Cache the hardware configuration in the port */
846
847 port->bufcounter = port->hwcfg.BARLocation;
848 port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
849 port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
850 port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
851 port->bufptr32l = port->hwcfg.BARLocation +
852 (4 * sizeof(u32)) +
853 (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
854 port->bufptr32h = port->hwcfg.BARLocation +
855 (4 * sizeof(u32)) +
856 (sizeof(u32) * port->hwcfg.buffercount);
857 port->bufptr64 = port->hwcfg.BARLocation +
858 (4 * sizeof(u32)) +
859 (sizeof(u32) * port->hwcfg.buffercount);
860 dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
861 port->hwcfg.BARLocation);
862
863 dprintk(DBGLVL_API, " = VS_FORMAT_MPEGTS (becomes dev->ts[%d])\n",
864 port->nr);
865
866 return 0;
867 }
868
869 int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev *dev,
870 struct saa7164_port *port,
871 tmComResPSFormatDescrHeader_t *fmt)
872 {
873 dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex);
874 dprintk(DBGLVL_API, " wPacketLength= 0x%x\n", fmt->wPacketLength);
875 dprintk(DBGLVL_API, " wPackLength= 0x%x\n", fmt->wPackLength);
876 dprintk(DBGLVL_API, " bPackDataType= 0x%x\n", fmt->bPackDataType);
877
878 /* Cache the hardware configuration in the port */
879 /* TODO: CHECK THIS in the port config */
880 port->bufcounter = port->hwcfg.BARLocation;
881 port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
882 port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
883 port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
884 port->bufptr32l = port->hwcfg.BARLocation +
885 (4 * sizeof(u32)) +
886 (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
887 port->bufptr32h = port->hwcfg.BARLocation +
888 (4 * sizeof(u32)) +
889 (sizeof(u32) * port->hwcfg.buffercount);
890 port->bufptr64 = port->hwcfg.BARLocation +
891 (4 * sizeof(u32)) +
892 (sizeof(u32) * port->hwcfg.buffercount);
893 dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
894 port->hwcfg.BARLocation);
895
896 dprintk(DBGLVL_API, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
897 port->nr);
898
899 return 0;
900 }
901
902 int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
903 {
904 struct saa7164_port *tsport = 0;
905 struct saa7164_port *encport = 0;
906 struct saa7164_port *vbiport = 0;
907 u32 idx, next_offset;
908 int i;
909 tmComResDescrHeader_t *hdr, *t;
910 tmComResExtDevDescrHeader_t *exthdr;
911 tmComResPathDescrHeader_t *pathhdr;
912 tmComResAntTermDescrHeader_t *anttermhdr;
913 tmComResTunerDescrHeader_t *tunerunithdr;
914 tmComResDMATermDescrHeader_t *vcoutputtermhdr;
915 tmComResTSFormatDescrHeader_t *tsfmt;
916 tmComResPSFormatDescrHeader_t *psfmt;
917 tmComResSelDescrHeader_t *psel;
918 tmComResProcDescrHeader_t *pdh;
919 tmComResAFeatureDescrHeader_t *afd;
920 tmComResEncoderDescrHeader_t *edh;
921 tmComResVBIFormatDescrHeader_t *vbifmt;
922 u32 currpath = 0;
923
924 dprintk(DBGLVL_API,
925 "%s(?,?,%d) sizeof(tmComResDescrHeader_t) = %d bytes\n",
926 __func__, len, (u32)sizeof(tmComResDescrHeader_t));
927
928 for (idx = 0; idx < (len - sizeof(tmComResDescrHeader_t)); ) {
929
930 hdr = (tmComResDescrHeader_t *)(buf + idx);
931
932 if (hdr->type != CS_INTERFACE)
933 return SAA_ERR_NOT_SUPPORTED;
934
935 dprintk(DBGLVL_API, "@ 0x%x = \n", idx);
936 switch (hdr->subtype) {
937 case GENERAL_REQUEST:
938 dprintk(DBGLVL_API, " GENERAL_REQUEST\n");
939 break;
940 case VC_TUNER_PATH:
941 dprintk(DBGLVL_API, " VC_TUNER_PATH\n");
942 pathhdr = (tmComResPathDescrHeader_t *)(buf + idx);
943 dprintk(DBGLVL_API, " pathid = 0x%x\n",
944 pathhdr->pathid);
945 currpath = pathhdr->pathid;
946 break;
947 case VC_INPUT_TERMINAL:
948 dprintk(DBGLVL_API, " VC_INPUT_TERMINAL\n");
949 anttermhdr =
950 (tmComResAntTermDescrHeader_t *)(buf + idx);
951 dprintk(DBGLVL_API, " terminalid = 0x%x\n",
952 anttermhdr->terminalid);
953 dprintk(DBGLVL_API, " terminaltype = 0x%x\n",
954 anttermhdr->terminaltype);
955 switch (anttermhdr->terminaltype) {
956 case ITT_ANTENNA:
957 dprintk(DBGLVL_API, " = ITT_ANTENNA\n");
958 break;
959 case LINE_CONNECTOR:
960 dprintk(DBGLVL_API, " = LINE_CONNECTOR\n");
961 break;
962 case SPDIF_CONNECTOR:
963 dprintk(DBGLVL_API, " = SPDIF_CONNECTOR\n");
964 break;
965 case COMPOSITE_CONNECTOR:
966 dprintk(DBGLVL_API,
967 " = COMPOSITE_CONNECTOR\n");
968 break;
969 case SVIDEO_CONNECTOR:
970 dprintk(DBGLVL_API, " = SVIDEO_CONNECTOR\n");
971 break;
972 case COMPONENT_CONNECTOR:
973 dprintk(DBGLVL_API,
974 " = COMPONENT_CONNECTOR\n");
975 break;
976 case STANDARD_DMA:
977 dprintk(DBGLVL_API, " = STANDARD_DMA\n");
978 break;
979 default:
980 dprintk(DBGLVL_API, " = undefined (0x%x)\n",
981 anttermhdr->terminaltype);
982 }
983 dprintk(DBGLVL_API, " assocterminal= 0x%x\n",
984 anttermhdr->assocterminal);
985 dprintk(DBGLVL_API, " iterminal = 0x%x\n",
986 anttermhdr->iterminal);
987 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
988 anttermhdr->controlsize);
989 break;
990 case VC_OUTPUT_TERMINAL:
991 dprintk(DBGLVL_API, " VC_OUTPUT_TERMINAL\n");
992 vcoutputtermhdr =
993 (tmComResDMATermDescrHeader_t *)(buf + idx);
994 dprintk(DBGLVL_API, " unitid = 0x%x\n",
995 vcoutputtermhdr->unitid);
996 dprintk(DBGLVL_API, " terminaltype = 0x%x\n",
997 vcoutputtermhdr->terminaltype);
998 switch (vcoutputtermhdr->terminaltype) {
999 case ITT_ANTENNA:
1000 dprintk(DBGLVL_API, " = ITT_ANTENNA\n");
1001 break;
1002 case LINE_CONNECTOR:
1003 dprintk(DBGLVL_API, " = LINE_CONNECTOR\n");
1004 break;
1005 case SPDIF_CONNECTOR:
1006 dprintk(DBGLVL_API, " = SPDIF_CONNECTOR\n");
1007 break;
1008 case COMPOSITE_CONNECTOR:
1009 dprintk(DBGLVL_API,
1010 " = COMPOSITE_CONNECTOR\n");
1011 break;
1012 case SVIDEO_CONNECTOR:
1013 dprintk(DBGLVL_API, " = SVIDEO_CONNECTOR\n");
1014 break;
1015 case COMPONENT_CONNECTOR:
1016 dprintk(DBGLVL_API,
1017 " = COMPONENT_CONNECTOR\n");
1018 break;
1019 case STANDARD_DMA:
1020 dprintk(DBGLVL_API, " = STANDARD_DMA\n");
1021 break;
1022 default:
1023 dprintk(DBGLVL_API, " = undefined (0x%x)\n",
1024 vcoutputtermhdr->terminaltype);
1025 }
1026 dprintk(DBGLVL_API, " assocterminal= 0x%x\n",
1027 vcoutputtermhdr->assocterminal);
1028 dprintk(DBGLVL_API, " sourceid = 0x%x\n",
1029 vcoutputtermhdr->sourceid);
1030 dprintk(DBGLVL_API, " iterminal = 0x%x\n",
1031 vcoutputtermhdr->iterminal);
1032 dprintk(DBGLVL_API, " BARLocation = 0x%x\n",
1033 vcoutputtermhdr->BARLocation);
1034 dprintk(DBGLVL_API, " flags = 0x%x\n",
1035 vcoutputtermhdr->flags);
1036 dprintk(DBGLVL_API, " interruptid = 0x%x\n",
1037 vcoutputtermhdr->interruptid);
1038 dprintk(DBGLVL_API, " buffercount = 0x%x\n",
1039 vcoutputtermhdr->buffercount);
1040 dprintk(DBGLVL_API, " metadatasize = 0x%x\n",
1041 vcoutputtermhdr->metadatasize);
1042 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
1043 vcoutputtermhdr->controlsize);
1044 dprintk(DBGLVL_API, " numformats = 0x%x\n",
1045 vcoutputtermhdr->numformats);
1046
1047 t = (tmComResDescrHeader_t *)
1048 ((tmComResDMATermDescrHeader_t *)(buf + idx));
1049 next_offset = idx + (vcoutputtermhdr->len);
1050 for (i = 0; i < vcoutputtermhdr->numformats; i++) {
1051 t = (tmComResDescrHeader_t *)
1052 (buf + next_offset);
1053 switch (t->subtype) {
1054 case VS_FORMAT_MPEG2TS:
1055 tsfmt =
1056 (tmComResTSFormatDescrHeader_t *)t;
1057 if (currpath == 1)
1058 tsport = &dev->ports[ SAA7164_PORT_TS1 ];
1059 else
1060 tsport = &dev->ports[ SAA7164_PORT_TS2 ];
1061 memcpy(&tsport->hwcfg, vcoutputtermhdr,
1062 sizeof(*vcoutputtermhdr));
1063 saa7164_api_configure_port_mpeg2ts(dev,
1064 tsport, tsfmt);
1065 break;
1066 case VS_FORMAT_MPEG2PS:
1067 psfmt =
1068 (tmComResPSFormatDescrHeader_t *)t;
1069 if (currpath == 1)
1070 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
1071 else
1072 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
1073 memcpy(&encport->hwcfg, vcoutputtermhdr,
1074 sizeof(*vcoutputtermhdr));
1075 saa7164_api_configure_port_mpeg2ps(dev,
1076 encport, psfmt);
1077 break;
1078 case VS_FORMAT_VBI:
1079 vbifmt =
1080 (tmComResVBIFormatDescrHeader_t *)t;
1081 if (currpath == 1)
1082 vbiport = &dev->ports[ SAA7164_PORT_VBI1 ];
1083 else
1084 vbiport = &dev->ports[ SAA7164_PORT_VBI2 ];
1085 memcpy(&vbiport->hwcfg, vcoutputtermhdr,
1086 sizeof(*vcoutputtermhdr));
1087 memcpy(&vbiport->vbi_fmt_ntsc, vbifmt, sizeof(*vbifmt));
1088 saa7164_api_configure_port_vbi(dev,
1089 vbiport);
1090 break;
1091 case VS_FORMAT_RDS:
1092 dprintk(DBGLVL_API,
1093 " = VS_FORMAT_RDS\n");
1094 break;
1095 case VS_FORMAT_UNCOMPRESSED:
1096 dprintk(DBGLVL_API,
1097 " = VS_FORMAT_UNCOMPRESSED\n");
1098 break;
1099 case VS_FORMAT_TYPE:
1100 dprintk(DBGLVL_API,
1101 " = VS_FORMAT_TYPE\n");
1102 break;
1103 default:
1104 dprintk(DBGLVL_API,
1105 " = undefined (0x%x)\n",
1106 t->subtype);
1107 }
1108 next_offset += t->len;
1109 }
1110
1111 break;
1112 case TUNER_UNIT:
1113 dprintk(DBGLVL_API, " TUNER_UNIT\n");
1114 tunerunithdr =
1115 (tmComResTunerDescrHeader_t *)(buf + idx);
1116 dprintk(DBGLVL_API, " unitid = 0x%x\n",
1117 tunerunithdr->unitid);
1118 dprintk(DBGLVL_API, " sourceid = 0x%x\n",
1119 tunerunithdr->sourceid);
1120 dprintk(DBGLVL_API, " iunit = 0x%x\n",
1121 tunerunithdr->iunit);
1122 dprintk(DBGLVL_API, " tuningstandards = 0x%x\n",
1123 tunerunithdr->tuningstandards);
1124 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
1125 tunerunithdr->controlsize);
1126 dprintk(DBGLVL_API, " controls = 0x%x\n",
1127 tunerunithdr->controls);
1128
1129 if (tunerunithdr->unitid == tunerunithdr->iunit) {
1130 if (currpath == 1)
1131 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
1132 else
1133 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
1134 memcpy(&encport->tunerunit, tunerunithdr,
1135 sizeof(tmComResTunerDescrHeader_t));
1136 dprintk(DBGLVL_API, " (becomes dev->enc[%d] tuner)\n", encport->nr);
1137 }
1138 break;
1139 case VC_SELECTOR_UNIT:
1140 psel = (tmComResSelDescrHeader_t *)(buf + idx);
1141 dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n");
1142 dprintk(DBGLVL_API, " unitid = 0x%x\n",
1143 psel->unitid);
1144 dprintk(DBGLVL_API, " nrinpins = 0x%x\n",
1145 psel->nrinpins);
1146 dprintk(DBGLVL_API, " sourceid = 0x%x\n",
1147 psel->sourceid);
1148 break;
1149 case VC_PROCESSING_UNIT:
1150 pdh = (tmComResProcDescrHeader_t *)(buf + idx);
1151 dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n");
1152 dprintk(DBGLVL_API, " unitid = 0x%x\n",
1153 pdh->unitid);
1154 dprintk(DBGLVL_API, " sourceid = 0x%x\n",
1155 pdh->sourceid);
1156 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
1157 pdh->controlsize);
1158 if (pdh->controlsize == 0x04) {
1159 if (currpath == 1)
1160 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
1161 else
1162 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
1163 memcpy(&encport->vidproc, pdh,
1164 sizeof(tmComResProcDescrHeader_t));
1165 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr);
1166 }
1167 break;
1168 case FEATURE_UNIT:
1169 afd = (tmComResAFeatureDescrHeader_t *)(buf + idx);
1170 dprintk(DBGLVL_API, " FEATURE_UNIT\n");
1171 dprintk(DBGLVL_API, " unitid = 0x%x\n",
1172 afd->unitid);
1173 dprintk(DBGLVL_API, " sourceid = 0x%x\n",
1174 afd->sourceid);
1175 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
1176 afd->controlsize);
1177 if (currpath == 1)
1178 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
1179 else
1180 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
1181 memcpy(&encport->audfeat, afd,
1182 sizeof(tmComResAFeatureDescrHeader_t));
1183 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr);
1184 break;
1185 case ENCODER_UNIT:
1186 edh = (tmComResEncoderDescrHeader_t *)(buf + idx);
1187 dprintk(DBGLVL_API, " ENCODER_UNIT\n");
1188 dprintk(DBGLVL_API, " subtype = 0x%x\n", edh->subtype);
1189 dprintk(DBGLVL_API, " unitid = 0x%x\n", edh->unitid);
1190 dprintk(DBGLVL_API, " vsourceid = 0x%x\n", edh->vsourceid);
1191 dprintk(DBGLVL_API, " asourceid = 0x%x\n", edh->asourceid);
1192 dprintk(DBGLVL_API, " iunit = 0x%x\n", edh->iunit);
1193 if (edh->iunit == edh->unitid) {
1194 if (currpath == 1)
1195 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
1196 else
1197 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
1198 memcpy(&encport->encunit, edh,
1199 sizeof(tmComResEncoderDescrHeader_t));
1200 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr);
1201 }
1202 break;
1203 case EXTENSION_UNIT:
1204 dprintk(DBGLVL_API, " EXTENSION_UNIT\n");
1205 exthdr = (tmComResExtDevDescrHeader_t *)(buf + idx);
1206 dprintk(DBGLVL_API, " unitid = 0x%x\n",
1207 exthdr->unitid);
1208 dprintk(DBGLVL_API, " deviceid = 0x%x\n",
1209 exthdr->deviceid);
1210 dprintk(DBGLVL_API, " devicetype = 0x%x\n",
1211 exthdr->devicetype);
1212 if (exthdr->devicetype & 0x1)
1213 dprintk(DBGLVL_API, " = Decoder Device\n");
1214 if (exthdr->devicetype & 0x2)
1215 dprintk(DBGLVL_API, " = GPIO Source\n");
1216 if (exthdr->devicetype & 0x4)
1217 dprintk(DBGLVL_API, " = Video Decoder\n");
1218 if (exthdr->devicetype & 0x8)
1219 dprintk(DBGLVL_API, " = Audio Decoder\n");
1220 if (exthdr->devicetype & 0x20)
1221 dprintk(DBGLVL_API, " = Crossbar\n");
1222 if (exthdr->devicetype & 0x40)
1223 dprintk(DBGLVL_API, " = Tuner\n");
1224 if (exthdr->devicetype & 0x80)
1225 dprintk(DBGLVL_API, " = IF PLL\n");
1226 if (exthdr->devicetype & 0x100)
1227 dprintk(DBGLVL_API, " = Demodulator\n");
1228 if (exthdr->devicetype & 0x200)
1229 dprintk(DBGLVL_API, " = RDS Decoder\n");
1230 if (exthdr->devicetype & 0x400)
1231 dprintk(DBGLVL_API, " = Encoder\n");
1232 if (exthdr->devicetype & 0x800)
1233 dprintk(DBGLVL_API, " = IR Decoder\n");
1234 if (exthdr->devicetype & 0x1000)
1235 dprintk(DBGLVL_API, " = EEPROM\n");
1236 if (exthdr->devicetype & 0x2000)
1237 dprintk(DBGLVL_API,
1238 " = VBI Decoder\n");
1239 if (exthdr->devicetype & 0x10000)
1240 dprintk(DBGLVL_API,
1241 " = Streaming Device\n");
1242 if (exthdr->devicetype & 0x20000)
1243 dprintk(DBGLVL_API,
1244 " = DRM Device\n");
1245 if (exthdr->devicetype & 0x40000000)
1246 dprintk(DBGLVL_API,
1247 " = Generic Device\n");
1248 if (exthdr->devicetype & 0x80000000)
1249 dprintk(DBGLVL_API,
1250 " = Config Space Device\n");
1251 dprintk(DBGLVL_API, " numgpiopins = 0x%x\n",
1252 exthdr->numgpiopins);
1253 dprintk(DBGLVL_API, " numgpiogroups = 0x%x\n",
1254 exthdr->numgpiogroups);
1255 dprintk(DBGLVL_API, " controlsize = 0x%x\n",
1256 exthdr->controlsize);
1257 if (exthdr->devicetype & 0x80) {
1258 if (currpath == 1)
1259 encport = &dev->ports[ SAA7164_PORT_ENC1 ];
1260 else
1261 encport = &dev->ports[ SAA7164_PORT_ENC2 ];
1262 memcpy(&encport->ifunit, exthdr,
1263 sizeof(tmComResExtDevDescrHeader_t));
1264 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr);
1265 }
1266 break;
1267 case PVC_INFRARED_UNIT:
1268 dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n");
1269 break;
1270 case DRM_UNIT:
1271 dprintk(DBGLVL_API, " DRM_UNIT\n");
1272 break;
1273 default:
1274 dprintk(DBGLVL_API, "default %d\n", hdr->subtype);
1275 }
1276
1277 dprintk(DBGLVL_API, " 1.%x\n", hdr->len);
1278 dprintk(DBGLVL_API, " 2.%x\n", hdr->type);
1279 dprintk(DBGLVL_API, " 3.%x\n", hdr->subtype);
1280 dprintk(DBGLVL_API, " 4.%x\n", hdr->unitid);
1281
1282 idx += hdr->len;
1283 }
1284
1285 return 0;
1286 }
1287
1288 int saa7164_api_enum_subdevs(struct saa7164_dev *dev)
1289 {
1290 int ret;
1291 u32 buflen = 0;
1292 u8 *buf;
1293
1294 dprintk(DBGLVL_API, "%s()\n", __func__);
1295
1296 /* Get the total descriptor length */
1297 ret = saa7164_cmd_send(dev, 0, GET_LEN,
1298 GET_DESCRIPTORS_CONTROL, sizeof(buflen), &buflen);
1299 if (ret != SAA_OK)
1300 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
1301
1302 dprintk(DBGLVL_API, "%s() total descriptor size = %d bytes.\n",
1303 __func__, buflen);
1304
1305 /* Allocate enough storage for all of the descs */
1306 buf = kzalloc(buflen, GFP_KERNEL);
1307 if (buf == NULL)
1308 return SAA_ERR_NO_RESOURCES;
1309
1310 /* Retrieve them */
1311 ret = saa7164_cmd_send(dev, 0, GET_CUR,
1312 GET_DESCRIPTORS_CONTROL, buflen, buf);
1313 if (ret != SAA_OK) {
1314 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
1315 goto out;
1316 }
1317
1318 if (saa_debug & DBGLVL_API)
1319 saa7164_dumphex16(dev, buf, (buflen/16)*16);
1320
1321 saa7164_api_dump_subdevs(dev, buf, buflen);
1322
1323 out:
1324 kfree(buf);
1325 return ret;
1326 }
1327
1328 int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
1329 u32 datalen, u8 *data)
1330 {
1331 struct saa7164_dev *dev = bus->dev;
1332 u16 len = 0;
1333 int unitid;
1334 u32 regval;
1335 u8 buf[256];
1336 int ret;
1337
1338 dprintk(DBGLVL_API, "%s()\n", __func__);
1339
1340 if (reglen > 4)
1341 return -EIO;
1342
1343 if (reglen == 1)
1344 regval = *(reg);
1345 else
1346 if (reglen == 2)
1347 regval = ((*(reg) << 8) || *(reg+1));
1348 else
1349 if (reglen == 3)
1350 regval = ((*(reg) << 16) | (*(reg+1) << 8) | *(reg+2));
1351 else
1352 if (reglen == 4)
1353 regval = ((*(reg) << 24) | (*(reg+1) << 16) |
1354 (*(reg+2) << 8) | *(reg+3));
1355
1356 /* Prepare the send buffer */
1357 /* Bytes 00-03 source register length
1358 * 04-07 source bytes to read
1359 * 08... register address
1360 */
1361 memset(buf, 0, sizeof(buf));
1362 memcpy((buf + 2 * sizeof(u32) + 0), reg, reglen);
1363 *((u32 *)(buf + 0 * sizeof(u32))) = reglen;
1364 *((u32 *)(buf + 1 * sizeof(u32))) = datalen;
1365
1366 unitid = saa7164_i2caddr_to_unitid(bus, addr);
1367 if (unitid < 0) {
1368 printk(KERN_ERR
1369 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1370 __func__, addr);
1371 return -EIO;
1372 }
1373
1374 ret = saa7164_cmd_send(bus->dev, unitid, GET_LEN,
1375 EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
1376 if (ret != SAA_OK) {
1377 printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
1378 return -EIO;
1379 }
1380
1381 dprintk(DBGLVL_API, "%s() len = %d bytes\n", __func__, len);
1382
1383 if (saa_debug & DBGLVL_I2C)
1384 saa7164_dumphex16(dev, buf, 2 * 16);
1385
1386 ret = saa7164_cmd_send(bus->dev, unitid, GET_CUR,
1387 EXU_REGISTER_ACCESS_CONTROL, len, &buf);
1388 if (ret != SAA_OK)
1389 printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
1390 else {
1391 if (saa_debug & DBGLVL_I2C)
1392 saa7164_dumphex16(dev, buf, sizeof(buf));
1393 memcpy(data, (buf + 2 * sizeof(u32) + reglen), datalen);
1394 }
1395
1396 return ret == SAA_OK ? 0 : -EIO;
1397 }
1398
1399 /* For a given 8 bit i2c address device, write the buffer */
1400 int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, u32 datalen,
1401 u8 *data)
1402 {
1403 struct saa7164_dev *dev = bus->dev;
1404 u16 len = 0;
1405 int unitid;
1406 int reglen;
1407 u8 buf[256];
1408 int ret;
1409
1410 dprintk(DBGLVL_API, "%s()\n", __func__);
1411
1412 if ((datalen == 0) || (datalen > 232))
1413 return -EIO;
1414
1415 memset(buf, 0, sizeof(buf));
1416
1417 unitid = saa7164_i2caddr_to_unitid(bus, addr);
1418 if (unitid < 0) {
1419 printk(KERN_ERR
1420 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1421 __func__, addr);
1422 return -EIO;
1423 }
1424
1425 reglen = saa7164_i2caddr_to_reglen(bus, addr);
1426 if (reglen < 0) {
1427 printk(KERN_ERR
1428 "%s() error, cannot translate regaddr to reglen\n",
1429 __func__);
1430 return -EIO;
1431 }
1432
1433 ret = saa7164_cmd_send(bus->dev, unitid, GET_LEN,
1434 EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
1435 if (ret != SAA_OK) {
1436 printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
1437 return -EIO;
1438 }
1439
1440 dprintk(DBGLVL_API, "%s() len = %d bytes\n", __func__, len);
1441
1442 /* Prepare the send buffer */
1443 /* Bytes 00-03 dest register length
1444 * 04-07 dest bytes to write
1445 * 08... register address
1446 */
1447 *((u32 *)(buf + 0 * sizeof(u32))) = reglen;
1448 *((u32 *)(buf + 1 * sizeof(u32))) = datalen - reglen;
1449 memcpy((buf + 2 * sizeof(u32)), data, datalen);
1450
1451 if (saa_debug & DBGLVL_I2C)
1452 saa7164_dumphex16(dev, buf, sizeof(buf));
1453
1454 ret = saa7164_cmd_send(bus->dev, unitid, SET_CUR,
1455 EXU_REGISTER_ACCESS_CONTROL, len, &buf);
1456 if (ret != SAA_OK)
1457 printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
1458
1459 return ret == SAA_OK ? 0 : -EIO;
1460 }
1461
1462
1463 int saa7164_api_modify_gpio(struct saa7164_dev *dev, u8 unitid,
1464 u8 pin, u8 state)
1465 {
1466 int ret;
1467 tmComResGPIO_t t;
1468
1469 dprintk(DBGLVL_API, "%s(0x%x, %d, %d)\n",
1470 __func__, unitid, pin, state);
1471
1472 if ((pin > 7) || (state > 2))
1473 return SAA_ERR_BAD_PARAMETER;
1474
1475 t.pin = pin;
1476 t.state = state;
1477
1478 ret = saa7164_cmd_send(dev, unitid, SET_CUR,
1479 EXU_GPIO_CONTROL, sizeof(t), &t);
1480 if (ret != SAA_OK)
1481 printk(KERN_ERR "%s() error, ret = 0x%x\n",
1482 __func__, ret);
1483
1484 return ret;
1485 }
1486
1487 int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid,
1488 u8 pin)
1489 {
1490 return saa7164_api_modify_gpio(dev, unitid, pin, 1);
1491 }
1492
1493 int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid,
1494 u8 pin)
1495 {
1496 return saa7164_api_modify_gpio(dev, unitid, pin, 0);
1497 }
1498
1499
1500
This page took 0.087454 seconds and 5 git commands to generate.