2 * Driver for the NXP SAA7164 PCIe bridge
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com>
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.
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
15 * GNU General Public License for more details.
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.
22 #include <linux/wait.h>
23 #include <linux/slab.h>
27 int saa7164_api_get_load_info(struct saa7164_dev
*dev
, tmFwInfoStruct_t
*i
)
31 if (!(debug
& DBGLVL_CPU
))
34 dprintk(DBGLVL_API
, "%s()\n", __func__
);
41 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
42 GET_FW_STATUS_CONTROL
, sizeof(tmFwInfoStruct_t
), i
);
44 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
47 printk(KERN_INFO
"saa7164[%d]-CPU: %d percent", dev
->nr
, i
->CPULoad
);
52 int saa7164_api_collect_debug(struct saa7164_dev
*dev
)
54 tmComResDebugGetData_t d
;
58 dprintk(DBGLVL_API
, "%s()\n", __func__
);
62 memset(&d
, 0, sizeof(d
));
64 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
65 GET_DEBUG_DATA_CONTROL
, sizeof(d
), &d
);
67 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
70 if (d
.dwResult
!= SAA_OK
)
73 printk(KERN_INFO
"saa7164[%d]-FWMSG: %s", dev
->nr
, d
.ucDebugData
);
79 int saa7164_api_set_debug(struct saa7164_dev
*dev
, u8 level
)
81 tmComResDebugSetLevel_t lvl
;
84 dprintk(DBGLVL_API
, "%s(level=%d)\n", __func__
, level
);
86 /* Retrieve current state */
87 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
88 SET_DEBUG_LEVEL_CONTROL
, sizeof(lvl
), &lvl
);
90 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
92 dprintk(DBGLVL_API
, "%s() Was %d\n", __func__
, lvl
.dwDebugLevel
);
94 lvl
.dwDebugLevel
= level
;
97 ret
= saa7164_cmd_send(dev
, 0, SET_CUR
,
98 SET_DEBUG_LEVEL_CONTROL
, sizeof(lvl
), &lvl
);
100 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
106 int saa7164_api_set_vbi_format(struct saa7164_port
*port
)
108 struct saa7164_dev
*dev
= port
->dev
;
109 tmComResProbeCommit_t fmt
, rsp
;
112 dprintk(DBGLVL_API
, "%s(nr=%d, unitid=0x%x)\n", __func__
,
113 port
->nr
, port
->hwcfg
.unitid
);
116 fmt
.bFormatIndex
= 1;
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
);
123 printk(KERN_ERR
"%s() set error, ret = 0x%x\n", __func__
, ret
);
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
);
129 printk(KERN_ERR
"%s() get error, ret = 0x%x\n", __func__
, ret
);
131 /* Compare requested vs received, should be same */
132 if (memcmp(&fmt
, &rsp
, sizeof(rsp
)) == 0) {
133 dprintk(DBGLVL_API
, "SET/PROBE Verified\n");
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
);
139 printk(KERN_ERR
"%s() commit error, ret = 0x%x\n",
142 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
143 GET_CUR
, SAA_COMMIT_CONTROL
, sizeof(rsp
), &rsp
);
145 printk(KERN_ERR
"%s() GET commit error, ret = 0x%x\n",
148 if (memcmp(&fmt
, &rsp
, sizeof(rsp
)) != 0) {
149 printk(KERN_ERR
"%s() memcmp error, ret = 0x%x\n",
152 dprintk(DBGLVL_API
, "SET/COMMIT Verified\n");
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
);
158 printk(KERN_ERR
"%s() compare failed\n", __func__
);
162 dprintk(DBGLVL_API
, "%s(nr=%d) Success\n", __func__
, port
->nr
);
167 int saa7164_api_set_gop_size(struct saa7164_port
*port
)
169 struct saa7164_dev
*dev
= port
->dev
;
170 tmComResEncVideoGopStructure_t gs
;
173 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
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
,
181 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
186 int saa7164_api_set_encoder(struct saa7164_port
*port
)
188 struct saa7164_dev
*dev
= port
->dev
;
189 tmComResEncVideoBitRate_t vb
;
190 tmComResEncAudioBitRate_t ab
;
193 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x\n", __func__
,
194 port
->hwcfg
.sourceid
);
196 if (port
->encoder_params
.stream_type
== V4L2_MPEG_STREAM_TYPE_MPEG2_PS
)
197 port
->encoder_profile
= EU_PROFILE_PS_DVD
;
199 port
->encoder_profile
= EU_PROFILE_TS_HQ
;
201 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
202 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
204 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
207 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
208 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
210 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
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
;
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
);
222 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
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
);
231 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
233 saa7164_api_set_aspect_ratio(port
);
234 saa7164_api_set_gop_size(port
);
239 int saa7164_api_get_encoder(struct saa7164_port
*port
)
241 struct saa7164_dev
*dev
= port
->dev
;
242 tmComResEncVideoBitRate_t v
;
243 tmComResEncAudioBitRate_t a
;
244 tmComResEncVideoInputAspectRatio_t ar
;
247 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x\n", __func__
, port
->hwcfg
.sourceid
);
249 port
->encoder_profile
= 0;
250 port
->video_format
= 0;
251 port
->video_resolution
= 0;
252 port
->audio_format
= 0;
254 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
255 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
257 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
259 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
260 EU_VIDEO_RESOLUTION_CONTROL
, sizeof(u8
), &port
->video_resolution
);
262 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
264 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
265 EU_VIDEO_FORMAT_CONTROL
, sizeof(u8
), &port
->video_format
);
267 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
269 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
270 EU_VIDEO_BIT_RATE_CONTROL
, sizeof(v
), &v
);
272 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
274 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
275 EU_AUDIO_FORMAT_CONTROL
, sizeof(u8
), &port
->audio_format
);
277 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
279 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
280 EU_AUDIO_BIT_RATE_CONTROL
, sizeof(a
), &a
);
282 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
287 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
288 EU_VIDEO_INPUT_ASPECT_CONTROL
,
289 sizeof(tmComResEncVideoInputAspectRatio_t
), &ar
);
291 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
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
);
308 int saa7164_api_set_aspect_ratio(struct saa7164_port
*port
)
310 struct saa7164_dev
*dev
= port
->dev
;
311 tmComResEncVideoInputAspectRatio_t ar
;
314 dprintk(DBGLVL_ENC
, "%s(%d)\n", __func__
,
315 port
->encoder_params
.ctl_aspect
);
317 switch (port
->encoder_params
.ctl_aspect
) {
318 case V4L2_MPEG_VIDEO_ASPECT_1x1
:
322 case V4L2_MPEG_VIDEO_ASPECT_4x3
:
326 case V4L2_MPEG_VIDEO_ASPECT_16x9
:
330 case V4L2_MPEG_VIDEO_ASPECT_221x100
:
338 dprintk(DBGLVL_ENC
, "%s(%d) now %d:%d\n", __func__
,
339 port
->encoder_params
.ctl_aspect
,
340 ar
.width
, ar
.height
);
343 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
344 EU_VIDEO_INPUT_ASPECT_CONTROL
,
345 sizeof(tmComResEncVideoInputAspectRatio_t
), &ar
);
347 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
352 int saa7164_api_set_usercontrol(struct saa7164_port
*port
, u8 ctl
)
354 struct saa7164_dev
*dev
= port
->dev
;
358 if (ctl
== PU_BRIGHTNESS_CONTROL
)
359 val
= port
->ctl_brightness
;
361 if (ctl
== PU_CONTRAST_CONTROL
)
362 val
= port
->ctl_contrast
;
364 if (ctl
== PU_HUE_CONTROL
)
367 if (ctl
== PU_SATURATION_CONTROL
)
368 val
= port
->ctl_saturation
;
370 if (ctl
== PU_SHARPNESS_CONTROL
)
371 val
= port
->ctl_sharpness
;
375 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x ctl=%d, val=%d\n",
376 __func__
, port
->encunit
.vsourceid
, ctl
, val
);
378 ret
= saa7164_cmd_send(port
->dev
, port
->encunit
.vsourceid
, SET_CUR
,
379 ctl
, sizeof(u16
), &val
);
381 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
386 int saa7164_api_get_usercontrol(struct saa7164_port
*port
, u8 ctl
)
388 struct saa7164_dev
*dev
= port
->dev
;
392 ret
= saa7164_cmd_send(port
->dev
, port
->encunit
.vsourceid
, GET_CUR
,
393 ctl
, sizeof(u16
), &val
);
395 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
399 dprintk(DBGLVL_ENC
, "%s() ctl=%d, val=%d\n",
402 if (ctl
== PU_BRIGHTNESS_CONTROL
)
403 port
->ctl_brightness
= val
;
405 if (ctl
== PU_CONTRAST_CONTROL
)
406 port
->ctl_contrast
= val
;
408 if (ctl
== PU_HUE_CONTROL
)
411 if (ctl
== PU_SATURATION_CONTROL
)
412 port
->ctl_saturation
= val
;
414 if (ctl
== PU_SHARPNESS_CONTROL
)
415 port
->ctl_sharpness
= val
;
420 int saa7164_api_set_videomux(struct saa7164_port
*port
)
422 struct saa7164_dev
*dev
= port
->dev
;
423 u8 inputs
[] = { 1, 2, 2, 2, 5, 5, 5 };
426 dprintk(DBGLVL_ENC
, "%s() v_mux=%d a_mux=%d\n",
427 __func__
, port
->mux_input
, inputs
[ port
->mux_input
- 1 ]);
430 ret
= saa7164_api_audio_mute(port
, 1);
432 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
435 ret
= saa7164_cmd_send(port
->dev
, port
->vidproc
.sourceid
, SET_CUR
,
436 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &port
->mux_input
);
438 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
440 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.sourceid
, SET_CUR
,
441 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &inputs
[ port
->mux_input
- 1 ]);
443 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
445 ret
= saa7164_api_audio_mute(port
, 0);
447 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
452 int saa7164_api_audio_mute(struct saa7164_port
*port
, int mute
)
454 struct saa7164_dev
*dev
= port
->dev
;
458 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, mute
);
460 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
461 MUTE_CONTROL
, sizeof(u8
), &v
);
463 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
468 /* 0 = silence, 0xff = full */
469 int saa7164_api_set_audio_volume(struct saa7164_port
*port
, s8 level
)
471 struct saa7164_dev
*dev
= port
->dev
;
475 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, level
);
477 /* Obtain the min/max ranges */
478 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_MIN
,
479 VOLUME_CONTROL
, sizeof(u16
), &min
);
481 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
483 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_MAX
,
484 VOLUME_CONTROL
, sizeof(u16
), &max
);
486 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
488 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_CUR
,
489 ( 0x01 << 8) | VOLUME_CONTROL
, sizeof(u16
), &v
);
491 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
493 dprintk(DBGLVL_API
, "%s(%d) min=%d max=%d cur=%d\n", __func__
, level
, min
, max
, v
);
502 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
503 ( 0x01 << 8 ) | VOLUME_CONTROL
, sizeof(s16
), &v
);
505 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
508 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
509 ( 0x02 << 8 ) | VOLUME_CONTROL
, sizeof(s16
), &v
);
511 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
513 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_CUR
,
514 ( 0x01 << 8) | VOLUME_CONTROL
, sizeof(u16
), &v
);
516 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
518 dprintk(DBGLVL_API
, "%s(%d) min=%d max=%d cur=%d\n", __func__
, level
, min
, max
, v
);
523 int saa7164_api_set_audio_std(struct saa7164_port
*port
)
525 struct saa7164_dev
*dev
= port
->dev
;
526 tmComResAudioDefaults_t lvl
;
527 tmComResTunerStandard_t tvaudio
;
530 dprintk(DBGLVL_API
, "%s()\n", __func__
);
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
);
542 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
544 /* Manually select the appropriate TV audio standard */
545 if (port
->encodernorm
.id
& V4L2_STD_NTSC
) {
546 tvaudio
.std
= TU_STANDARD_NTSC_M
;
549 tvaudio
.std
= TU_STANDARD_PAL_I
;
550 tvaudio
.country
= 44;
553 ret
= saa7164_cmd_send(port
->dev
, port
->tunerunit
.unitid
, SET_CUR
,
554 TU_STANDARD_CONTROL
, sizeof(tvaudio
), &tvaudio
);
556 printk(KERN_ERR
"%s() TU_STANDARD_CONTROL error, ret = 0x%x\n", __func__
, ret
);
560 int saa7164_api_set_audio_detection(struct saa7164_port
*port
, int autodetect
)
562 struct saa7164_dev
*dev
= port
->dev
;
563 tmComResTunerStandardAuto_t p
;
566 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, autodetect
);
568 /* Disable TV Audio autodetect if not already set (buggy) */
570 p
.mode
= TU_STANDARD_AUTO
;
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
);
576 printk(KERN_ERR
"%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n", __func__
, ret
);
581 int saa7164_api_get_videomux(struct saa7164_port
*port
)
583 struct saa7164_dev
*dev
= port
->dev
;
586 ret
= saa7164_cmd_send(port
->dev
, port
->vidproc
.sourceid
, GET_CUR
,
587 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &port
->mux_input
);
589 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
591 dprintk(DBGLVL_ENC
, "%s() v_mux=%d\n",
592 __func__
, port
->mux_input
);
597 int saa7164_api_set_dif(struct saa7164_port
*port
, u8 reg
, u8 val
)
599 struct saa7164_dev
*dev
= port
->dev
;
606 dprintk(DBGLVL_API
, "%s(nr=%d type=%d val=%x)\n", __func__
,
607 port
->nr
, port
->type
, val
);
614 memset(buf
, 0, sizeof(buf
));
636 ret
= saa7164_cmd_send(dev
, port
->ifunit
.unitid
, GET_LEN
,
637 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
639 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
643 ret
= saa7164_cmd_send(dev
, port
->ifunit
.unitid
, SET_CUR
,
644 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
646 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
648 //saa7164_dumphex16(dev, buf, 16);
650 return ret
== SAA_OK
? 0 : -EIO
;
653 /* Disable the IF block AGC controls */
654 int saa7164_api_configure_dif(struct saa7164_port
*port
, u32 std
)
656 struct saa7164_dev
*dev
= port
->dev
;
660 dprintk(DBGLVL_API
, "%s(nr=%d, 0x%x)\n", __func__
, port
->nr
, std
);
662 if (std
& V4L2_STD_NTSC
) {
663 dprintk(DBGLVL_API
, " NTSC\n");
664 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
695 /* Unknown standard, assume DTV */
696 dprintk(DBGLVL_API
, " Unknown (assuming DTV)\n");
697 saa7164_api_set_dif(port
, 0x00, 0x80); /* Undefined Video Standard */
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 */
706 saa7164_api_set_dif(port
, 0x04, 0x00); /* Active (again) */
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.
717 int saa7164_api_initialize_dif(struct saa7164_port
*port
)
719 struct saa7164_dev
*dev
= port
->dev
;
720 struct saa7164_port
*p
= 0;
724 dprintk(DBGLVL_API
, "%s(nr=%d type=%d)\n", __func__
,
725 port
->nr
, port
->type
);
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.
734 if (port
->type
== SAA7164_MPEG_DVB
) {
735 if (port
->nr
== SAA7164_PORT_TS1
)
736 p
= &dev
->ports
[ SAA7164_PORT_ENC1
];
738 p
= &dev
->ports
[ SAA7164_PORT_ENC2
];
740 if (port
->type
== SAA7164_MPEG_VBI
) {
742 if (port
->nr
== SAA7164_PORT_VBI1
)
743 p
= &dev
->ports
[ SAA7164_PORT_ENC1
];
745 p
= &dev
->ports
[ SAA7164_PORT_ENC2
];
750 ret
= saa7164_api_configure_dif(p
, std
);
755 int saa7164_api_transition_port(struct saa7164_port
*port
, u8 mode
)
757 struct saa7164_dev
*dev
= port
->dev
;
761 dprintk(DBGLVL_API
, "%s(nr=%d unitid=0x%x,%d)\n",
762 __func__
, port
->nr
, port
->hwcfg
.unitid
, mode
);
764 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
, SET_CUR
,
765 SAA_STATE_CONTROL
, sizeof(mode
), &mode
);
767 printk(KERN_ERR
"%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
768 __func__
, port
->nr
, port
->hwcfg
.unitid
, ret
);
773 int saa7164_api_get_fw_version(struct saa7164_dev
*dev
, u32
*version
)
777 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
778 GET_FW_VERSION_CONTROL
, sizeof(u32
), version
);
780 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
785 int saa7164_api_read_eeprom(struct saa7164_dev
*dev
, u8
*buf
, int buflen
)
787 u8 reg
[] = { 0x0f, 0x00 };
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
),
799 int saa7164_api_configure_port_vbi(struct saa7164_dev
*dev
,
800 struct saa7164_port
*port
)
802 tmComResVBIFormatDescrHeader_t
*fmt
= &port
->vbi_fmt_ntsc
;
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
);
811 /* Cache the hardware configuration in the port */
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
+
819 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
820 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
822 (sizeof(u32
) * port
->hwcfg
.buffercount
);
823 port
->bufptr64
= port
->hwcfg
.BARLocation
+
825 (sizeof(u32
) * port
->hwcfg
.buffercount
);
826 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
827 port
->hwcfg
.BARLocation
);
829 dprintk(DBGLVL_API
, " = VS_FORMAT_VBI (becomes dev->en[%d])\n",
835 int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev
*dev
,
836 struct saa7164_port
*port
,
837 tmComResTSFormatDescrHeader_t
*tsfmt
)
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");
845 /* Cache the hardware configuration in the port */
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
+
853 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
854 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
856 (sizeof(u32
) * port
->hwcfg
.buffercount
);
857 port
->bufptr64
= port
->hwcfg
.BARLocation
+
859 (sizeof(u32
) * port
->hwcfg
.buffercount
);
860 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
861 port
->hwcfg
.BARLocation
);
863 dprintk(DBGLVL_API
, " = VS_FORMAT_MPEGTS (becomes dev->ts[%d])\n",
869 int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev
*dev
,
870 struct saa7164_port
*port
,
871 tmComResPSFormatDescrHeader_t
*fmt
)
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
);
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
+
886 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
887 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
889 (sizeof(u32
) * port
->hwcfg
.buffercount
);
890 port
->bufptr64
= port
->hwcfg
.BARLocation
+
892 (sizeof(u32
) * port
->hwcfg
.buffercount
);
893 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
894 port
->hwcfg
.BARLocation
);
896 dprintk(DBGLVL_API
, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
902 int saa7164_api_dump_subdevs(struct saa7164_dev
*dev
, u8
*buf
, int len
)
904 struct saa7164_port
*tsport
= 0;
905 struct saa7164_port
*encport
= 0;
906 struct saa7164_port
*vbiport
= 0;
907 u32 idx
, next_offset
;
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
;
925 "%s(?,?,%d) sizeof(tmComResDescrHeader_t) = %d bytes\n",
926 __func__
, len
, (u32
)sizeof(tmComResDescrHeader_t
));
928 for (idx
= 0; idx
< (len
- sizeof(tmComResDescrHeader_t
)); ) {
930 hdr
= (tmComResDescrHeader_t
*)(buf
+ idx
);
932 if (hdr
->type
!= CS_INTERFACE
)
933 return SAA_ERR_NOT_SUPPORTED
;
935 dprintk(DBGLVL_API
, "@ 0x%x = \n", idx
);
936 switch (hdr
->subtype
) {
937 case GENERAL_REQUEST
:
938 dprintk(DBGLVL_API
, " GENERAL_REQUEST\n");
941 dprintk(DBGLVL_API
, " VC_TUNER_PATH\n");
942 pathhdr
= (tmComResPathDescrHeader_t
*)(buf
+ idx
);
943 dprintk(DBGLVL_API
, " pathid = 0x%x\n",
945 currpath
= pathhdr
->pathid
;
947 case VC_INPUT_TERMINAL
:
948 dprintk(DBGLVL_API
, " VC_INPUT_TERMINAL\n");
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
) {
957 dprintk(DBGLVL_API
, " = ITT_ANTENNA\n");
960 dprintk(DBGLVL_API
, " = LINE_CONNECTOR\n");
962 case SPDIF_CONNECTOR
:
963 dprintk(DBGLVL_API
, " = SPDIF_CONNECTOR\n");
965 case COMPOSITE_CONNECTOR
:
967 " = COMPOSITE_CONNECTOR\n");
969 case SVIDEO_CONNECTOR
:
970 dprintk(DBGLVL_API
, " = SVIDEO_CONNECTOR\n");
972 case COMPONENT_CONNECTOR
:
974 " = COMPONENT_CONNECTOR\n");
977 dprintk(DBGLVL_API
, " = STANDARD_DMA\n");
980 dprintk(DBGLVL_API
, " = undefined (0x%x)\n",
981 anttermhdr
->terminaltype
);
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
);
990 case VC_OUTPUT_TERMINAL
:
991 dprintk(DBGLVL_API
, " VC_OUTPUT_TERMINAL\n");
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
) {
1000 dprintk(DBGLVL_API
, " = ITT_ANTENNA\n");
1002 case LINE_CONNECTOR
:
1003 dprintk(DBGLVL_API
, " = LINE_CONNECTOR\n");
1005 case SPDIF_CONNECTOR
:
1006 dprintk(DBGLVL_API
, " = SPDIF_CONNECTOR\n");
1008 case COMPOSITE_CONNECTOR
:
1010 " = COMPOSITE_CONNECTOR\n");
1012 case SVIDEO_CONNECTOR
:
1013 dprintk(DBGLVL_API
, " = SVIDEO_CONNECTOR\n");
1015 case COMPONENT_CONNECTOR
:
1017 " = COMPONENT_CONNECTOR\n");
1020 dprintk(DBGLVL_API
, " = STANDARD_DMA\n");
1023 dprintk(DBGLVL_API
, " = undefined (0x%x)\n",
1024 vcoutputtermhdr
->terminaltype
);
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
);
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
:
1056 (tmComResTSFormatDescrHeader_t
*)t
;
1058 tsport
= &dev
->ports
[ SAA7164_PORT_TS1
];
1060 tsport
= &dev
->ports
[ SAA7164_PORT_TS2
];
1061 memcpy(&tsport
->hwcfg
, vcoutputtermhdr
,
1062 sizeof(*vcoutputtermhdr
));
1063 saa7164_api_configure_port_mpeg2ts(dev
,
1066 case VS_FORMAT_MPEG2PS
:
1068 (tmComResPSFormatDescrHeader_t
*)t
;
1070 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
1072 encport
= &dev
->ports
[ SAA7164_PORT_ENC2
];
1073 memcpy(&encport
->hwcfg
, vcoutputtermhdr
,
1074 sizeof(*vcoutputtermhdr
));
1075 saa7164_api_configure_port_mpeg2ps(dev
,
1080 (tmComResVBIFormatDescrHeader_t
*)t
;
1082 vbiport
= &dev
->ports
[ SAA7164_PORT_VBI1
];
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
,
1093 " = VS_FORMAT_RDS\n");
1095 case VS_FORMAT_UNCOMPRESSED
:
1097 " = VS_FORMAT_UNCOMPRESSED\n");
1099 case VS_FORMAT_TYPE
:
1101 " = VS_FORMAT_TYPE\n");
1105 " = undefined (0x%x)\n",
1108 next_offset
+= t
->len
;
1113 dprintk(DBGLVL_API
, " TUNER_UNIT\n");
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
);
1129 if (tunerunithdr
->unitid
== tunerunithdr
->iunit
) {
1131 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
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
);
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",
1144 dprintk(DBGLVL_API
, " nrinpins = 0x%x\n",
1146 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
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",
1154 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1156 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1158 if (pdh
->controlsize
== 0x04) {
1160 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
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
);
1169 afd
= (tmComResAFeatureDescrHeader_t
*)(buf
+ idx
);
1170 dprintk(DBGLVL_API
, " FEATURE_UNIT\n");
1171 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1173 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1175 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1178 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
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
);
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
) {
1195 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
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
);
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",
1208 dprintk(DBGLVL_API
, " deviceid = 0x%x\n",
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)
1238 " = VBI Decoder\n");
1239 if (exthdr
->devicetype
& 0x10000)
1241 " = Streaming Device\n");
1242 if (exthdr
->devicetype
& 0x20000)
1245 if (exthdr
->devicetype
& 0x40000000)
1247 " = Generic Device\n");
1248 if (exthdr
->devicetype
& 0x80000000)
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) {
1259 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
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
);
1267 case PVC_INFRARED_UNIT
:
1268 dprintk(DBGLVL_API
, " PVC_INFRARED_UNIT\n");
1271 dprintk(DBGLVL_API
, " DRM_UNIT\n");
1274 dprintk(DBGLVL_API
, "default %d\n", hdr
->subtype
);
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
);
1288 int saa7164_api_enum_subdevs(struct saa7164_dev
*dev
)
1294 dprintk(DBGLVL_API
, "%s()\n", __func__
);
1296 /* Get the total descriptor length */
1297 ret
= saa7164_cmd_send(dev
, 0, GET_LEN
,
1298 GET_DESCRIPTORS_CONTROL
, sizeof(buflen
), &buflen
);
1300 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
1302 dprintk(DBGLVL_API
, "%s() total descriptor size = %d bytes.\n",
1305 /* Allocate enough storage for all of the descs */
1306 buf
= kzalloc(buflen
, GFP_KERNEL
);
1308 return SAA_ERR_NO_RESOURCES
;
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
);
1318 if (saa_debug
& DBGLVL_API
)
1319 saa7164_dumphex16(dev
, buf
, (buflen
/16)*16);
1321 saa7164_api_dump_subdevs(dev
, buf
, buflen
);
1328 int saa7164_api_i2c_read(struct saa7164_i2c
*bus
, u8 addr
, u32 reglen
, u8
*reg
,
1329 u32 datalen
, u8
*data
)
1331 struct saa7164_dev
*dev
= bus
->dev
;
1338 dprintk(DBGLVL_API
, "%s()\n", __func__
);
1347 regval
= ((*(reg
) << 8) || *(reg
+1));
1350 regval
= ((*(reg
) << 16) | (*(reg
+1) << 8) | *(reg
+2));
1353 regval
= ((*(reg
) << 24) | (*(reg
+1) << 16) |
1354 (*(reg
+2) << 8) | *(reg
+3));
1356 /* Prepare the send buffer */
1357 /* Bytes 00-03 source register length
1358 * 04-07 source bytes to read
1359 * 08... register address
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
;
1366 unitid
= saa7164_i2caddr_to_unitid(bus
, addr
);
1369 "%s() error, cannot translate regaddr 0x%x to unitid\n",
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
);
1381 dprintk(DBGLVL_API
, "%s() len = %d bytes\n", __func__
, len
);
1383 if (saa_debug
& DBGLVL_I2C
)
1384 saa7164_dumphex16(dev
, buf
, 2 * 16);
1386 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_CUR
,
1387 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
1389 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
1391 if (saa_debug
& DBGLVL_I2C
)
1392 saa7164_dumphex16(dev
, buf
, sizeof(buf
));
1393 memcpy(data
, (buf
+ 2 * sizeof(u32
) + reglen
), datalen
);
1396 return ret
== SAA_OK
? 0 : -EIO
;
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
,
1403 struct saa7164_dev
*dev
= bus
->dev
;
1410 dprintk(DBGLVL_API
, "%s()\n", __func__
);
1412 if ((datalen
== 0) || (datalen
> 232))
1415 memset(buf
, 0, sizeof(buf
));
1417 unitid
= saa7164_i2caddr_to_unitid(bus
, addr
);
1420 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1425 reglen
= saa7164_i2caddr_to_reglen(bus
, addr
);
1428 "%s() error, cannot translate regaddr to reglen\n",
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
);
1440 dprintk(DBGLVL_API
, "%s() len = %d bytes\n", __func__
, len
);
1442 /* Prepare the send buffer */
1443 /* Bytes 00-03 dest register length
1444 * 04-07 dest bytes to write
1445 * 08... register address
1447 *((u32
*)(buf
+ 0 * sizeof(u32
))) = reglen
;
1448 *((u32
*)(buf
+ 1 * sizeof(u32
))) = datalen
- reglen
;
1449 memcpy((buf
+ 2 * sizeof(u32
)), data
, datalen
);
1451 if (saa_debug
& DBGLVL_I2C
)
1452 saa7164_dumphex16(dev
, buf
, sizeof(buf
));
1454 ret
= saa7164_cmd_send(bus
->dev
, unitid
, SET_CUR
,
1455 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
1457 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
1459 return ret
== SAA_OK
? 0 : -EIO
;
1463 int saa7164_api_modify_gpio(struct saa7164_dev
*dev
, u8 unitid
,
1469 dprintk(DBGLVL_API
, "%s(0x%x, %d, %d)\n",
1470 __func__
, unitid
, pin
, state
);
1472 if ((pin
> 7) || (state
> 2))
1473 return SAA_ERR_BAD_PARAMETER
;
1478 ret
= saa7164_cmd_send(dev
, unitid
, SET_CUR
,
1479 EXU_GPIO_CONTROL
, sizeof(t
), &t
);
1481 printk(KERN_ERR
"%s() error, ret = 0x%x\n",
1487 int saa7164_api_set_gpiobit(struct saa7164_dev
*dev
, u8 unitid
,
1490 return saa7164_api_modify_gpio(dev
, unitid
, pin
, 1);
1493 int saa7164_api_clear_gpiobit(struct saa7164_dev
*dev
, u8 unitid
,
1496 return saa7164_api_modify_gpio(dev
, unitid
, pin
, 0);