2 * Driver for the NXP SAA7164 PCIe bridge
4 * Copyright (c) 2010-2015 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.
18 #include <linux/wait.h>
19 #include <linux/slab.h>
23 int saa7164_api_get_load_info(struct saa7164_dev
*dev
, struct tmFwInfoStruct
*i
)
27 if (!(saa_debug
& DBGLVL_CPU
))
30 dprintk(DBGLVL_API
, "%s()\n", __func__
);
37 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
38 GET_FW_STATUS_CONTROL
, sizeof(struct tmFwInfoStruct
), i
);
40 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
42 printk(KERN_INFO
"saa7164[%d]-CPU: %d percent", dev
->nr
, i
->CPULoad
);
47 int saa7164_api_collect_debug(struct saa7164_dev
*dev
)
49 struct tmComResDebugGetData d
;
53 dprintk(DBGLVL_API
, "%s()\n", __func__
);
57 memset(&d
, 0, sizeof(d
));
59 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
60 GET_DEBUG_DATA_CONTROL
, sizeof(d
), &d
);
62 printk(KERN_ERR
"%s() error, ret = 0x%x\n",
65 if (d
.dwResult
!= SAA_OK
)
68 printk(KERN_INFO
"saa7164[%d]-FWMSG: %s", dev
->nr
,
75 int saa7164_api_set_debug(struct saa7164_dev
*dev
, u8 level
)
77 struct tmComResDebugSetLevel lvl
;
80 dprintk(DBGLVL_API
, "%s(level=%d)\n", __func__
, level
);
82 /* Retrieve current state */
83 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
84 SET_DEBUG_LEVEL_CONTROL
, sizeof(lvl
), &lvl
);
86 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
88 dprintk(DBGLVL_API
, "%s() Was %d\n", __func__
, lvl
.dwDebugLevel
);
90 lvl
.dwDebugLevel
= level
;
93 ret
= saa7164_cmd_send(dev
, 0, SET_CUR
,
94 SET_DEBUG_LEVEL_CONTROL
, sizeof(lvl
), &lvl
);
96 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
101 int saa7164_api_set_vbi_format(struct saa7164_port
*port
)
103 struct saa7164_dev
*dev
= port
->dev
;
104 struct tmComResProbeCommit fmt
, rsp
;
107 dprintk(DBGLVL_API
, "%s(nr=%d, unitid=0x%x)\n", __func__
,
108 port
->nr
, port
->hwcfg
.unitid
);
111 fmt
.bFormatIndex
= 1;
114 /* Probe, see if it can support this format */
115 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
116 SET_CUR
, SAA_PROBE_CONTROL
, sizeof(fmt
), &fmt
);
118 printk(KERN_ERR
"%s() set error, ret = 0x%x\n", __func__
, ret
);
120 /* See of the format change was successful */
121 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
122 GET_CUR
, SAA_PROBE_CONTROL
, sizeof(rsp
), &rsp
);
124 printk(KERN_ERR
"%s() get error, ret = 0x%x\n", __func__
, ret
);
126 /* Compare requested vs received, should be same */
127 if (memcmp(&fmt
, &rsp
, sizeof(rsp
)) == 0) {
128 dprintk(DBGLVL_API
, "SET/PROBE Verified\n");
130 /* Ask the device to select the negotiated format */
131 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
132 SET_CUR
, SAA_COMMIT_CONTROL
, sizeof(fmt
), &fmt
);
134 printk(KERN_ERR
"%s() commit error, ret = 0x%x\n",
137 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
138 GET_CUR
, SAA_COMMIT_CONTROL
, sizeof(rsp
), &rsp
);
140 printk(KERN_ERR
"%s() GET commit error, ret = 0x%x\n",
143 if (memcmp(&fmt
, &rsp
, sizeof(rsp
)) != 0) {
144 printk(KERN_ERR
"%s() memcmp error, ret = 0x%x\n",
147 dprintk(DBGLVL_API
, "SET/COMMIT Verified\n");
149 dprintk(DBGLVL_API
, "rsp.bmHint = 0x%x\n", rsp
.bmHint
);
150 dprintk(DBGLVL_API
, "rsp.bFormatIndex = 0x%x\n",
152 dprintk(DBGLVL_API
, "rsp.bFrameIndex = 0x%x\n",
155 printk(KERN_ERR
"%s() compare failed\n", __func__
);
159 dprintk(DBGLVL_API
, "%s(nr=%d) Success\n", __func__
, port
->nr
);
164 static int saa7164_api_set_gop_size(struct saa7164_port
*port
)
166 struct saa7164_dev
*dev
= port
->dev
;
167 struct tmComResEncVideoGopStructure gs
;
170 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
172 gs
.ucRefFrameDist
= port
->encoder_params
.refdist
;
173 gs
.ucGOPSize
= port
->encoder_params
.gop_size
;
174 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
175 EU_VIDEO_GOP_STRUCTURE_CONTROL
,
178 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
183 int saa7164_api_set_encoder(struct saa7164_port
*port
)
185 struct saa7164_dev
*dev
= port
->dev
;
186 struct tmComResEncVideoBitRate vb
;
187 struct tmComResEncAudioBitRate ab
;
190 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x\n", __func__
,
191 port
->hwcfg
.sourceid
);
193 if (port
->encoder_params
.stream_type
== V4L2_MPEG_STREAM_TYPE_MPEG2_PS
)
194 port
->encoder_profile
= EU_PROFILE_PS_DVD
;
196 port
->encoder_profile
= EU_PROFILE_TS_HQ
;
198 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
199 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
201 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
204 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
205 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
207 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
209 /* Establish video bitrates */
210 if (port
->encoder_params
.bitrate_mode
==
211 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
)
212 vb
.ucVideoBitRateMode
= EU_VIDEO_BIT_RATE_MODE_CONSTANT
;
214 vb
.ucVideoBitRateMode
= EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK
;
215 vb
.dwVideoBitRate
= port
->encoder_params
.bitrate
;
216 vb
.dwVideoBitRatePeak
= port
->encoder_params
.bitrate_peak
;
217 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
218 EU_VIDEO_BIT_RATE_CONTROL
,
219 sizeof(struct tmComResEncVideoBitRate
),
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
,
230 sizeof(struct tmComResEncAudioBitRate
),
233 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
,
236 saa7164_api_set_aspect_ratio(port
);
237 saa7164_api_set_gop_size(port
);
242 int saa7164_api_get_encoder(struct saa7164_port
*port
)
244 struct saa7164_dev
*dev
= port
->dev
;
245 struct tmComResEncVideoBitRate v
;
246 struct tmComResEncAudioBitRate a
;
247 struct tmComResEncVideoInputAspectRatio ar
;
250 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x\n", __func__
,
251 port
->hwcfg
.sourceid
);
253 port
->encoder_profile
= 0;
254 port
->video_format
= 0;
255 port
->video_resolution
= 0;
256 port
->audio_format
= 0;
258 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
259 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
261 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
263 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
264 EU_VIDEO_RESOLUTION_CONTROL
, sizeof(u8
),
265 &port
->video_resolution
);
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_FORMAT_CONTROL
, sizeof(u8
), &port
->video_format
);
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_VIDEO_BIT_RATE_CONTROL
, sizeof(v
), &v
);
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_FORMAT_CONTROL
, sizeof(u8
), &port
->audio_format
);
282 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
284 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
285 EU_AUDIO_BIT_RATE_CONTROL
, sizeof(a
), &a
);
287 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
292 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
293 EU_VIDEO_INPUT_ASPECT_CONTROL
,
294 sizeof(struct tmComResEncVideoInputAspectRatio
), &ar
);
296 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
298 dprintk(DBGLVL_ENC
, "encoder_profile = %d\n", port
->encoder_profile
);
299 dprintk(DBGLVL_ENC
, "video_format = %d\n", port
->video_format
);
300 dprintk(DBGLVL_ENC
, "audio_format = %d\n", port
->audio_format
);
301 dprintk(DBGLVL_ENC
, "video_resolution= %d\n", port
->video_resolution
);
302 dprintk(DBGLVL_ENC
, "v.ucVideoBitRateMode = %d\n",
303 v
.ucVideoBitRateMode
);
304 dprintk(DBGLVL_ENC
, "v.dwVideoBitRate = %d\n",
306 dprintk(DBGLVL_ENC
, "v.dwVideoBitRatePeak = %d\n",
307 v
.dwVideoBitRatePeak
);
308 dprintk(DBGLVL_ENC
, "a.ucVideoBitRateMode = %d\n",
309 a
.ucAudioBitRateMode
);
310 dprintk(DBGLVL_ENC
, "a.dwVideoBitRate = %d\n",
312 dprintk(DBGLVL_ENC
, "a.dwVideoBitRatePeak = %d\n",
313 a
.dwAudioBitRatePeak
);
314 dprintk(DBGLVL_ENC
, "aspect.width / height = %d:%d\n",
315 ar
.width
, ar
.height
);
320 int saa7164_api_set_aspect_ratio(struct saa7164_port
*port
)
322 struct saa7164_dev
*dev
= port
->dev
;
323 struct tmComResEncVideoInputAspectRatio ar
;
326 dprintk(DBGLVL_ENC
, "%s(%d)\n", __func__
,
327 port
->encoder_params
.ctl_aspect
);
329 switch (port
->encoder_params
.ctl_aspect
) {
330 case V4L2_MPEG_VIDEO_ASPECT_1x1
:
334 case V4L2_MPEG_VIDEO_ASPECT_4x3
:
338 case V4L2_MPEG_VIDEO_ASPECT_16x9
:
342 case V4L2_MPEG_VIDEO_ASPECT_221x100
:
350 dprintk(DBGLVL_ENC
, "%s(%d) now %d:%d\n", __func__
,
351 port
->encoder_params
.ctl_aspect
,
352 ar
.width
, ar
.height
);
355 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
356 EU_VIDEO_INPUT_ASPECT_CONTROL
,
357 sizeof(struct tmComResEncVideoInputAspectRatio
), &ar
);
359 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
364 int saa7164_api_set_usercontrol(struct saa7164_port
*port
, u8 ctl
)
366 struct saa7164_dev
*dev
= port
->dev
;
370 if (ctl
== PU_BRIGHTNESS_CONTROL
)
371 val
= port
->ctl_brightness
;
373 if (ctl
== PU_CONTRAST_CONTROL
)
374 val
= port
->ctl_contrast
;
376 if (ctl
== PU_HUE_CONTROL
)
379 if (ctl
== PU_SATURATION_CONTROL
)
380 val
= port
->ctl_saturation
;
382 if (ctl
== PU_SHARPNESS_CONTROL
)
383 val
= port
->ctl_sharpness
;
387 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x ctl=%d, val=%d\n",
388 __func__
, port
->encunit
.vsourceid
, ctl
, val
);
390 ret
= saa7164_cmd_send(port
->dev
, port
->encunit
.vsourceid
, SET_CUR
,
391 ctl
, sizeof(u16
), &val
);
393 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
398 int saa7164_api_get_usercontrol(struct saa7164_port
*port
, u8 ctl
)
400 struct saa7164_dev
*dev
= port
->dev
;
404 ret
= saa7164_cmd_send(port
->dev
, port
->encunit
.vsourceid
, GET_CUR
,
405 ctl
, sizeof(u16
), &val
);
407 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
411 dprintk(DBGLVL_ENC
, "%s() ctl=%d, val=%d\n",
414 if (ctl
== PU_BRIGHTNESS_CONTROL
)
415 port
->ctl_brightness
= val
;
417 if (ctl
== PU_CONTRAST_CONTROL
)
418 port
->ctl_contrast
= val
;
420 if (ctl
== PU_HUE_CONTROL
)
423 if (ctl
== PU_SATURATION_CONTROL
)
424 port
->ctl_saturation
= val
;
426 if (ctl
== PU_SHARPNESS_CONTROL
)
427 port
->ctl_sharpness
= val
;
432 int saa7164_api_set_videomux(struct saa7164_port
*port
)
434 struct saa7164_dev
*dev
= port
->dev
;
435 u8 inputs
[] = { 1, 2, 2, 2, 5, 5, 5 };
438 dprintk(DBGLVL_ENC
, "%s() v_mux=%d a_mux=%d\n",
439 __func__
, port
->mux_input
, inputs
[port
->mux_input
- 1]);
442 ret
= saa7164_api_audio_mute(port
, 1);
444 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
447 ret
= saa7164_cmd_send(port
->dev
, port
->vidproc
.sourceid
, SET_CUR
,
448 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &port
->mux_input
);
450 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
453 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.sourceid
, SET_CUR
,
454 SU_INPUT_SELECT_CONTROL
, sizeof(u8
),
455 &inputs
[port
->mux_input
- 1]);
457 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
460 ret
= saa7164_api_audio_mute(port
, 0);
462 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
467 int saa7164_api_audio_mute(struct saa7164_port
*port
, int mute
)
469 struct saa7164_dev
*dev
= port
->dev
;
473 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, mute
);
475 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
476 MUTE_CONTROL
, sizeof(u8
), &v
);
478 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
483 /* 0 = silence, 0xff = full */
484 int saa7164_api_set_audio_volume(struct saa7164_port
*port
, s8 level
)
486 struct saa7164_dev
*dev
= port
->dev
;
490 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, level
);
492 /* Obtain the min/max ranges */
493 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_MIN
,
494 VOLUME_CONTROL
, sizeof(u16
), &min
);
496 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
498 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_MAX
,
499 VOLUME_CONTROL
, sizeof(u16
), &max
);
501 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
503 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_CUR
,
504 (0x01 << 8) | VOLUME_CONTROL
, sizeof(u16
), &v
);
506 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
508 dprintk(DBGLVL_API
, "%s(%d) min=%d max=%d cur=%d\n", __func__
,
518 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
519 (0x01 << 8) | VOLUME_CONTROL
, sizeof(s16
), &v
);
521 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
524 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
525 (0x02 << 8) | VOLUME_CONTROL
, sizeof(s16
), &v
);
527 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
529 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_CUR
,
530 (0x01 << 8) | VOLUME_CONTROL
, sizeof(u16
), &v
);
532 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
534 dprintk(DBGLVL_API
, "%s(%d) min=%d max=%d cur=%d\n", __func__
,
540 int saa7164_api_set_audio_std(struct saa7164_port
*port
)
542 struct saa7164_dev
*dev
= port
->dev
;
543 struct tmComResAudioDefaults lvl
;
544 struct tmComResTunerStandard tvaudio
;
547 dprintk(DBGLVL_API
, "%s()\n", __func__
);
549 /* Establish default levels */
550 lvl
.ucDecoderLevel
= TMHW_LEV_ADJ_DECLEV_DEFAULT
;
551 lvl
.ucDecoderFM_Level
= TMHW_LEV_ADJ_DECLEV_DEFAULT
;
552 lvl
.ucMonoLevel
= TMHW_LEV_ADJ_MONOLEV_DEFAULT
;
553 lvl
.ucNICAM_Level
= TMHW_LEV_ADJ_NICLEV_DEFAULT
;
554 lvl
.ucSAP_Level
= TMHW_LEV_ADJ_SAPLEV_DEFAULT
;
555 lvl
.ucADC_Level
= TMHW_LEV_ADJ_ADCLEV_DEFAULT
;
556 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
557 AUDIO_DEFAULT_CONTROL
, sizeof(struct tmComResAudioDefaults
),
560 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
562 /* Manually select the appropriate TV audio standard */
563 if (port
->encodernorm
.id
& V4L2_STD_NTSC
) {
564 tvaudio
.std
= TU_STANDARD_NTSC_M
;
567 tvaudio
.std
= TU_STANDARD_PAL_I
;
568 tvaudio
.country
= 44;
571 ret
= saa7164_cmd_send(port
->dev
, port
->tunerunit
.unitid
, SET_CUR
,
572 TU_STANDARD_CONTROL
, sizeof(tvaudio
), &tvaudio
);
574 printk(KERN_ERR
"%s() TU_STANDARD_CONTROL error, ret = 0x%x\n",
579 int saa7164_api_set_audio_detection(struct saa7164_port
*port
, int autodetect
)
581 struct saa7164_dev
*dev
= port
->dev
;
582 struct tmComResTunerStandardAuto p
;
585 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, autodetect
);
587 /* Disable TV Audio autodetect if not already set (buggy) */
589 p
.mode
= TU_STANDARD_AUTO
;
591 p
.mode
= TU_STANDARD_MANUAL
;
592 ret
= saa7164_cmd_send(port
->dev
, port
->tunerunit
.unitid
, SET_CUR
,
593 TU_STANDARD_AUTO_CONTROL
, sizeof(p
), &p
);
596 "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n",
602 int saa7164_api_get_videomux(struct saa7164_port
*port
)
604 struct saa7164_dev
*dev
= port
->dev
;
607 ret
= saa7164_cmd_send(port
->dev
, port
->vidproc
.sourceid
, GET_CUR
,
608 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &port
->mux_input
);
610 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
612 dprintk(DBGLVL_ENC
, "%s() v_mux=%d\n",
613 __func__
, port
->mux_input
);
618 static int saa7164_api_set_dif(struct saa7164_port
*port
, u8 reg
, u8 val
)
620 struct saa7164_dev
*dev
= port
->dev
;
627 dprintk(DBGLVL_API
, "%s(nr=%d type=%d val=%x)\n", __func__
,
628 port
->nr
, port
->type
, val
);
635 memset(buf
, 0, sizeof(buf
));
657 ret
= saa7164_cmd_send(dev
, port
->ifunit
.unitid
, GET_LEN
,
658 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
660 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
664 ret
= saa7164_cmd_send(dev
, port
->ifunit
.unitid
, SET_CUR
,
665 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
667 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
669 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1, buf
, 16,
672 return ret
== SAA_OK
? 0 : -EIO
;
675 /* Disable the IF block AGC controls */
676 int saa7164_api_configure_dif(struct saa7164_port
*port
, u32 std
)
678 struct saa7164_dev
*dev
= port
->dev
;
681 dprintk(DBGLVL_API
, "%s(nr=%d, 0x%x)\n", __func__
, port
->nr
, std
);
683 if (std
& V4L2_STD_NTSC
) {
684 dprintk(DBGLVL_API
, " NTSC\n");
685 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
687 } else if (std
& V4L2_STD_PAL_I
) {
688 dprintk(DBGLVL_API
, " PAL-I\n");
689 saa7164_api_set_dif(port
, 0x00, 0x08); /* Video Standard */
691 } else if (std
& V4L2_STD_PAL_M
) {
692 dprintk(DBGLVL_API
, " PAL-M\n");
693 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
695 } else if (std
& V4L2_STD_PAL_N
) {
696 dprintk(DBGLVL_API
, " PAL-N\n");
697 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
699 } else if (std
& V4L2_STD_PAL_Nc
) {
700 dprintk(DBGLVL_API
, " PAL-Nc\n");
701 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
703 } else if (std
& V4L2_STD_PAL_B
) {
704 dprintk(DBGLVL_API
, " PAL-B\n");
705 saa7164_api_set_dif(port
, 0x00, 0x02); /* Video Standard */
707 } else if (std
& V4L2_STD_PAL_DK
) {
708 dprintk(DBGLVL_API
, " PAL-DK\n");
709 saa7164_api_set_dif(port
, 0x00, 0x10); /* Video Standard */
711 } else if (std
& V4L2_STD_SECAM_L
) {
712 dprintk(DBGLVL_API
, " SECAM-L\n");
713 saa7164_api_set_dif(port
, 0x00, 0x20); /* Video Standard */
716 /* Unknown standard, assume DTV */
717 dprintk(DBGLVL_API
, " Unknown (assuming DTV)\n");
718 /* Undefinded Video Standard */
719 saa7164_api_set_dif(port
, 0x00, 0x80);
723 saa7164_api_set_dif(port
, 0x48, 0xa0); /* AGC Functions 1 */
724 saa7164_api_set_dif(port
, 0xc0, agc_disable
); /* AGC Output Disable */
725 saa7164_api_set_dif(port
, 0x7c, 0x04); /* CVBS EQ */
726 saa7164_api_set_dif(port
, 0x04, 0x01); /* Active */
728 saa7164_api_set_dif(port
, 0x04, 0x00); /* Active (again) */
734 /* Ensure the dif is in the correct state for the operating mode
735 * (analog / dtv). We only configure the diff through the analog encoder
736 * so when we're in digital mode we need to find the appropriate encoder
737 * and use it to configure the DIF.
739 int saa7164_api_initialize_dif(struct saa7164_port
*port
)
741 struct saa7164_dev
*dev
= port
->dev
;
742 struct saa7164_port
*p
= NULL
;
746 dprintk(DBGLVL_API
, "%s(nr=%d type=%d)\n", __func__
,
747 port
->nr
, port
->type
);
749 if (port
->type
== SAA7164_MPEG_ENCODER
) {
750 /* Pick any analog standard to init the diff.
751 * we'll come back during encoder_init'
752 * and set the correct standard if requried.
756 if (port
->type
== SAA7164_MPEG_DVB
) {
757 if (port
->nr
== SAA7164_PORT_TS1
)
758 p
= &dev
->ports
[SAA7164_PORT_ENC1
];
760 p
= &dev
->ports
[SAA7164_PORT_ENC2
];
762 if (port
->type
== SAA7164_MPEG_VBI
) {
764 if (port
->nr
== SAA7164_PORT_VBI1
)
765 p
= &dev
->ports
[SAA7164_PORT_ENC1
];
767 p
= &dev
->ports
[SAA7164_PORT_ENC2
];
772 ret
= saa7164_api_configure_dif(p
, std
);
777 int saa7164_api_transition_port(struct saa7164_port
*port
, u8 mode
)
779 struct saa7164_dev
*dev
= port
->dev
;
783 dprintk(DBGLVL_API
, "%s(nr=%d unitid=0x%x,%d)\n",
784 __func__
, port
->nr
, port
->hwcfg
.unitid
, mode
);
786 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
, SET_CUR
,
787 SAA_STATE_CONTROL
, sizeof(mode
), &mode
);
789 printk(KERN_ERR
"%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
790 __func__
, port
->nr
, port
->hwcfg
.unitid
, ret
);
795 int saa7164_api_get_fw_version(struct saa7164_dev
*dev
, u32
*version
)
799 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
800 GET_FW_VERSION_CONTROL
, sizeof(u32
), version
);
802 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
807 int saa7164_api_read_eeprom(struct saa7164_dev
*dev
, u8
*buf
, int buflen
)
809 u8 reg
[] = { 0x0f, 0x00 };
814 /* Assumption: Hauppauge eeprom is at 0xa0 on on bus 0 */
815 /* TODO: Pull the details from the boards struct */
816 return saa7164_api_i2c_read(&dev
->i2c_bus
[0], 0xa0 >> 1, sizeof(reg
),
820 static int saa7164_api_configure_port_vbi(struct saa7164_dev
*dev
,
821 struct saa7164_port
*port
)
823 struct tmComResVBIFormatDescrHeader
*fmt
= &port
->vbi_fmt_ntsc
;
825 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", fmt
->bFormatIndex
);
826 dprintk(DBGLVL_API
, " VideoStandard = 0x%x\n", fmt
->VideoStandard
);
827 dprintk(DBGLVL_API
, " StartLine = %d\n", fmt
->StartLine
);
828 dprintk(DBGLVL_API
, " EndLine = %d\n", fmt
->EndLine
);
829 dprintk(DBGLVL_API
, " FieldRate = %d\n", fmt
->FieldRate
);
830 dprintk(DBGLVL_API
, " bNumLines = %d\n", fmt
->bNumLines
);
832 /* Cache the hardware configuration in the port */
834 port
->bufcounter
= port
->hwcfg
.BARLocation
;
835 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
836 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
837 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
838 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
840 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
841 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
843 (sizeof(u32
) * port
->hwcfg
.buffercount
);
844 port
->bufptr64
= port
->hwcfg
.BARLocation
+
846 (sizeof(u32
) * port
->hwcfg
.buffercount
);
847 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
848 port
->hwcfg
.BARLocation
);
850 dprintk(DBGLVL_API
, " = VS_FORMAT_VBI (becomes dev->en[%d])\n",
857 saa7164_api_configure_port_mpeg2ts(struct saa7164_dev
*dev
,
858 struct saa7164_port
*port
,
859 struct tmComResTSFormatDescrHeader
*tsfmt
)
861 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", tsfmt
->bFormatIndex
);
862 dprintk(DBGLVL_API
, " bDataOffset = 0x%x\n", tsfmt
->bDataOffset
);
863 dprintk(DBGLVL_API
, " bPacketLength= 0x%x\n", tsfmt
->bPacketLength
);
864 dprintk(DBGLVL_API
, " bStrideLength= 0x%x\n", tsfmt
->bStrideLength
);
865 dprintk(DBGLVL_API
, " bguid = (....)\n");
867 /* Cache the hardware configuration in the port */
869 port
->bufcounter
= port
->hwcfg
.BARLocation
;
870 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
871 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
872 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
873 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
875 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
876 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
878 (sizeof(u32
) * port
->hwcfg
.buffercount
);
879 port
->bufptr64
= port
->hwcfg
.BARLocation
+
881 (sizeof(u32
) * port
->hwcfg
.buffercount
);
882 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
883 port
->hwcfg
.BARLocation
);
885 dprintk(DBGLVL_API
, " = VS_FORMAT_MPEGTS (becomes dev->ts[%d])\n",
892 saa7164_api_configure_port_mpeg2ps(struct saa7164_dev
*dev
,
893 struct saa7164_port
*port
,
894 struct tmComResPSFormatDescrHeader
*fmt
)
896 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", fmt
->bFormatIndex
);
897 dprintk(DBGLVL_API
, " wPacketLength= 0x%x\n", fmt
->wPacketLength
);
898 dprintk(DBGLVL_API
, " wPackLength= 0x%x\n", fmt
->wPackLength
);
899 dprintk(DBGLVL_API
, " bPackDataType= 0x%x\n", fmt
->bPackDataType
);
901 /* Cache the hardware configuration in the port */
902 /* TODO: CHECK THIS in the port config */
903 port
->bufcounter
= port
->hwcfg
.BARLocation
;
904 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
905 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
906 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
907 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
909 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
910 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
912 (sizeof(u32
) * port
->hwcfg
.buffercount
);
913 port
->bufptr64
= port
->hwcfg
.BARLocation
+
915 (sizeof(u32
) * port
->hwcfg
.buffercount
);
916 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
917 port
->hwcfg
.BARLocation
);
919 dprintk(DBGLVL_API
, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
925 static int saa7164_api_dump_subdevs(struct saa7164_dev
*dev
, u8
*buf
, int len
)
927 struct saa7164_port
*tsport
= NULL
;
928 struct saa7164_port
*encport
= NULL
;
929 struct saa7164_port
*vbiport
= NULL
;
930 u32 idx
, next_offset
;
932 struct tmComResDescrHeader
*hdr
, *t
;
933 struct tmComResExtDevDescrHeader
*exthdr
;
934 struct tmComResPathDescrHeader
*pathhdr
;
935 struct tmComResAntTermDescrHeader
*anttermhdr
;
936 struct tmComResTunerDescrHeader
*tunerunithdr
;
937 struct tmComResDMATermDescrHeader
*vcoutputtermhdr
;
938 struct tmComResTSFormatDescrHeader
*tsfmt
;
939 struct tmComResPSFormatDescrHeader
*psfmt
;
940 struct tmComResSelDescrHeader
*psel
;
941 struct tmComResProcDescrHeader
*pdh
;
942 struct tmComResAFeatureDescrHeader
*afd
;
943 struct tmComResEncoderDescrHeader
*edh
;
944 struct tmComResVBIFormatDescrHeader
*vbifmt
;
948 "%s(?,?,%d) sizeof(struct tmComResDescrHeader) = %d bytes\n",
949 __func__
, len
, (u32
)sizeof(struct tmComResDescrHeader
));
951 for (idx
= 0; idx
< (len
- sizeof(struct tmComResDescrHeader
));) {
953 hdr
= (struct tmComResDescrHeader
*)(buf
+ idx
);
955 if (hdr
->type
!= CS_INTERFACE
)
956 return SAA_ERR_NOT_SUPPORTED
;
958 dprintk(DBGLVL_API
, "@ 0x%x =\n", idx
);
959 switch (hdr
->subtype
) {
960 case GENERAL_REQUEST
:
961 dprintk(DBGLVL_API
, " GENERAL_REQUEST\n");
964 dprintk(DBGLVL_API
, " VC_TUNER_PATH\n");
965 pathhdr
= (struct tmComResPathDescrHeader
*)(buf
+ idx
);
966 dprintk(DBGLVL_API
, " pathid = 0x%x\n",
968 currpath
= pathhdr
->pathid
;
970 case VC_INPUT_TERMINAL
:
971 dprintk(DBGLVL_API
, " VC_INPUT_TERMINAL\n");
973 (struct tmComResAntTermDescrHeader
*)(buf
+ idx
);
974 dprintk(DBGLVL_API
, " terminalid = 0x%x\n",
975 anttermhdr
->terminalid
);
976 dprintk(DBGLVL_API
, " terminaltype = 0x%x\n",
977 anttermhdr
->terminaltype
);
978 switch (anttermhdr
->terminaltype
) {
980 dprintk(DBGLVL_API
, " = ITT_ANTENNA\n");
983 dprintk(DBGLVL_API
, " = LINE_CONNECTOR\n");
985 case SPDIF_CONNECTOR
:
986 dprintk(DBGLVL_API
, " = SPDIF_CONNECTOR\n");
988 case COMPOSITE_CONNECTOR
:
990 " = COMPOSITE_CONNECTOR\n");
992 case SVIDEO_CONNECTOR
:
993 dprintk(DBGLVL_API
, " = SVIDEO_CONNECTOR\n");
995 case COMPONENT_CONNECTOR
:
997 " = COMPONENT_CONNECTOR\n");
1000 dprintk(DBGLVL_API
, " = STANDARD_DMA\n");
1003 dprintk(DBGLVL_API
, " = undefined (0x%x)\n",
1004 anttermhdr
->terminaltype
);
1006 dprintk(DBGLVL_API
, " assocterminal= 0x%x\n",
1007 anttermhdr
->assocterminal
);
1008 dprintk(DBGLVL_API
, " iterminal = 0x%x\n",
1009 anttermhdr
->iterminal
);
1010 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1011 anttermhdr
->controlsize
);
1013 case VC_OUTPUT_TERMINAL
:
1014 dprintk(DBGLVL_API
, " VC_OUTPUT_TERMINAL\n");
1016 (struct tmComResDMATermDescrHeader
*)(buf
+ idx
);
1017 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1018 vcoutputtermhdr
->unitid
);
1019 dprintk(DBGLVL_API
, " terminaltype = 0x%x\n",
1020 vcoutputtermhdr
->terminaltype
);
1021 switch (vcoutputtermhdr
->terminaltype
) {
1023 dprintk(DBGLVL_API
, " = ITT_ANTENNA\n");
1025 case LINE_CONNECTOR
:
1026 dprintk(DBGLVL_API
, " = LINE_CONNECTOR\n");
1028 case SPDIF_CONNECTOR
:
1029 dprintk(DBGLVL_API
, " = SPDIF_CONNECTOR\n");
1031 case COMPOSITE_CONNECTOR
:
1033 " = COMPOSITE_CONNECTOR\n");
1035 case SVIDEO_CONNECTOR
:
1036 dprintk(DBGLVL_API
, " = SVIDEO_CONNECTOR\n");
1038 case COMPONENT_CONNECTOR
:
1040 " = COMPONENT_CONNECTOR\n");
1043 dprintk(DBGLVL_API
, " = STANDARD_DMA\n");
1046 dprintk(DBGLVL_API
, " = undefined (0x%x)\n",
1047 vcoutputtermhdr
->terminaltype
);
1049 dprintk(DBGLVL_API
, " assocterminal= 0x%x\n",
1050 vcoutputtermhdr
->assocterminal
);
1051 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1052 vcoutputtermhdr
->sourceid
);
1053 dprintk(DBGLVL_API
, " iterminal = 0x%x\n",
1054 vcoutputtermhdr
->iterminal
);
1055 dprintk(DBGLVL_API
, " BARLocation = 0x%x\n",
1056 vcoutputtermhdr
->BARLocation
);
1057 dprintk(DBGLVL_API
, " flags = 0x%x\n",
1058 vcoutputtermhdr
->flags
);
1059 dprintk(DBGLVL_API
, " interruptid = 0x%x\n",
1060 vcoutputtermhdr
->interruptid
);
1061 dprintk(DBGLVL_API
, " buffercount = 0x%x\n",
1062 vcoutputtermhdr
->buffercount
);
1063 dprintk(DBGLVL_API
, " metadatasize = 0x%x\n",
1064 vcoutputtermhdr
->metadatasize
);
1065 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1066 vcoutputtermhdr
->controlsize
);
1067 dprintk(DBGLVL_API
, " numformats = 0x%x\n",
1068 vcoutputtermhdr
->numformats
);
1070 t
= (struct tmComResDescrHeader
*)
1071 ((struct tmComResDMATermDescrHeader
*)(buf
+ idx
));
1072 next_offset
= idx
+ (vcoutputtermhdr
->len
);
1073 for (i
= 0; i
< vcoutputtermhdr
->numformats
; i
++) {
1074 t
= (struct tmComResDescrHeader
*)
1075 (buf
+ next_offset
);
1076 switch (t
->subtype
) {
1077 case VS_FORMAT_MPEG2TS
:
1079 (struct tmComResTSFormatDescrHeader
*)t
;
1081 tsport
= &dev
->ports
[SAA7164_PORT_TS1
];
1083 tsport
= &dev
->ports
[SAA7164_PORT_TS2
];
1084 memcpy(&tsport
->hwcfg
, vcoutputtermhdr
,
1085 sizeof(*vcoutputtermhdr
));
1086 saa7164_api_configure_port_mpeg2ts(dev
,
1089 case VS_FORMAT_MPEG2PS
:
1091 (struct tmComResPSFormatDescrHeader
*)t
;
1093 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1095 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1096 memcpy(&encport
->hwcfg
, vcoutputtermhdr
,
1097 sizeof(*vcoutputtermhdr
));
1098 saa7164_api_configure_port_mpeg2ps(dev
,
1103 (struct tmComResVBIFormatDescrHeader
*)t
;
1105 vbiport
= &dev
->ports
[SAA7164_PORT_VBI1
];
1107 vbiport
= &dev
->ports
[SAA7164_PORT_VBI2
];
1108 memcpy(&vbiport
->hwcfg
, vcoutputtermhdr
,
1109 sizeof(*vcoutputtermhdr
));
1110 memcpy(&vbiport
->vbi_fmt_ntsc
, vbifmt
,
1112 saa7164_api_configure_port_vbi(dev
,
1117 " = VS_FORMAT_RDS\n");
1119 case VS_FORMAT_UNCOMPRESSED
:
1121 " = VS_FORMAT_UNCOMPRESSED\n");
1123 case VS_FORMAT_TYPE
:
1125 " = VS_FORMAT_TYPE\n");
1129 " = undefined (0x%x)\n",
1132 next_offset
+= t
->len
;
1137 dprintk(DBGLVL_API
, " TUNER_UNIT\n");
1139 (struct tmComResTunerDescrHeader
*)(buf
+ idx
);
1140 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1141 tunerunithdr
->unitid
);
1142 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1143 tunerunithdr
->sourceid
);
1144 dprintk(DBGLVL_API
, " iunit = 0x%x\n",
1145 tunerunithdr
->iunit
);
1146 dprintk(DBGLVL_API
, " tuningstandards = 0x%x\n",
1147 tunerunithdr
->tuningstandards
);
1148 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1149 tunerunithdr
->controlsize
);
1150 dprintk(DBGLVL_API
, " controls = 0x%x\n",
1151 tunerunithdr
->controls
);
1153 if (tunerunithdr
->unitid
== tunerunithdr
->iunit
) {
1155 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1157 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1158 memcpy(&encport
->tunerunit
, tunerunithdr
,
1159 sizeof(struct tmComResTunerDescrHeader
));
1161 " (becomes dev->enc[%d] tuner)\n",
1165 case VC_SELECTOR_UNIT
:
1166 psel
= (struct tmComResSelDescrHeader
*)(buf
+ idx
);
1167 dprintk(DBGLVL_API
, " VC_SELECTOR_UNIT\n");
1168 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1170 dprintk(DBGLVL_API
, " nrinpins = 0x%x\n",
1172 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1175 case VC_PROCESSING_UNIT
:
1176 pdh
= (struct tmComResProcDescrHeader
*)(buf
+ idx
);
1177 dprintk(DBGLVL_API
, " VC_PROCESSING_UNIT\n");
1178 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1180 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1182 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1184 if (pdh
->controlsize
== 0x04) {
1186 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1188 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1189 memcpy(&encport
->vidproc
, pdh
,
1190 sizeof(struct tmComResProcDescrHeader
));
1191 dprintk(DBGLVL_API
, " (becomes dev->enc[%d])\n",
1196 afd
= (struct tmComResAFeatureDescrHeader
*)(buf
+ idx
);
1197 dprintk(DBGLVL_API
, " FEATURE_UNIT\n");
1198 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1200 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1202 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1205 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1207 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1208 memcpy(&encport
->audfeat
, afd
,
1209 sizeof(struct tmComResAFeatureDescrHeader
));
1210 dprintk(DBGLVL_API
, " (becomes dev->enc[%d])\n",
1214 edh
= (struct tmComResEncoderDescrHeader
*)(buf
+ idx
);
1215 dprintk(DBGLVL_API
, " ENCODER_UNIT\n");
1216 dprintk(DBGLVL_API
, " subtype = 0x%x\n", edh
->subtype
);
1217 dprintk(DBGLVL_API
, " unitid = 0x%x\n", edh
->unitid
);
1218 dprintk(DBGLVL_API
, " vsourceid = 0x%x\n",
1220 dprintk(DBGLVL_API
, " asourceid = 0x%x\n",
1222 dprintk(DBGLVL_API
, " iunit = 0x%x\n", edh
->iunit
);
1223 if (edh
->iunit
== edh
->unitid
) {
1225 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1227 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1228 memcpy(&encport
->encunit
, edh
,
1229 sizeof(struct tmComResEncoderDescrHeader
));
1231 " (becomes dev->enc[%d])\n",
1235 case EXTENSION_UNIT
:
1236 dprintk(DBGLVL_API
, " EXTENSION_UNIT\n");
1237 exthdr
= (struct tmComResExtDevDescrHeader
*)(buf
+ idx
);
1238 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1240 dprintk(DBGLVL_API
, " deviceid = 0x%x\n",
1242 dprintk(DBGLVL_API
, " devicetype = 0x%x\n",
1243 exthdr
->devicetype
);
1244 if (exthdr
->devicetype
& 0x1)
1245 dprintk(DBGLVL_API
, " = Decoder Device\n");
1246 if (exthdr
->devicetype
& 0x2)
1247 dprintk(DBGLVL_API
, " = GPIO Source\n");
1248 if (exthdr
->devicetype
& 0x4)
1249 dprintk(DBGLVL_API
, " = Video Decoder\n");
1250 if (exthdr
->devicetype
& 0x8)
1251 dprintk(DBGLVL_API
, " = Audio Decoder\n");
1252 if (exthdr
->devicetype
& 0x20)
1253 dprintk(DBGLVL_API
, " = Crossbar\n");
1254 if (exthdr
->devicetype
& 0x40)
1255 dprintk(DBGLVL_API
, " = Tuner\n");
1256 if (exthdr
->devicetype
& 0x80)
1257 dprintk(DBGLVL_API
, " = IF PLL\n");
1258 if (exthdr
->devicetype
& 0x100)
1259 dprintk(DBGLVL_API
, " = Demodulator\n");
1260 if (exthdr
->devicetype
& 0x200)
1261 dprintk(DBGLVL_API
, " = RDS Decoder\n");
1262 if (exthdr
->devicetype
& 0x400)
1263 dprintk(DBGLVL_API
, " = Encoder\n");
1264 if (exthdr
->devicetype
& 0x800)
1265 dprintk(DBGLVL_API
, " = IR Decoder\n");
1266 if (exthdr
->devicetype
& 0x1000)
1267 dprintk(DBGLVL_API
, " = EEPROM\n");
1268 if (exthdr
->devicetype
& 0x2000)
1270 " = VBI Decoder\n");
1271 if (exthdr
->devicetype
& 0x10000)
1273 " = Streaming Device\n");
1274 if (exthdr
->devicetype
& 0x20000)
1277 if (exthdr
->devicetype
& 0x40000000)
1279 " = Generic Device\n");
1280 if (exthdr
->devicetype
& 0x80000000)
1282 " = Config Space Device\n");
1283 dprintk(DBGLVL_API
, " numgpiopins = 0x%x\n",
1284 exthdr
->numgpiopins
);
1285 dprintk(DBGLVL_API
, " numgpiogroups = 0x%x\n",
1286 exthdr
->numgpiogroups
);
1287 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1288 exthdr
->controlsize
);
1289 if (exthdr
->devicetype
& 0x80) {
1291 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1293 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1294 memcpy(&encport
->ifunit
, exthdr
,
1295 sizeof(struct tmComResExtDevDescrHeader
));
1297 " (becomes dev->enc[%d])\n",
1301 case PVC_INFRARED_UNIT
:
1302 dprintk(DBGLVL_API
, " PVC_INFRARED_UNIT\n");
1305 dprintk(DBGLVL_API
, " DRM_UNIT\n");
1308 dprintk(DBGLVL_API
, "default %d\n", hdr
->subtype
);
1311 dprintk(DBGLVL_API
, " 1.%x\n", hdr
->len
);
1312 dprintk(DBGLVL_API
, " 2.%x\n", hdr
->type
);
1313 dprintk(DBGLVL_API
, " 3.%x\n", hdr
->subtype
);
1314 dprintk(DBGLVL_API
, " 4.%x\n", hdr
->unitid
);
1322 int saa7164_api_enum_subdevs(struct saa7164_dev
*dev
)
1328 dprintk(DBGLVL_API
, "%s()\n", __func__
);
1330 /* Get the total descriptor length */
1331 ret
= saa7164_cmd_send(dev
, 0, GET_LEN
,
1332 GET_DESCRIPTORS_CONTROL
, sizeof(buflen
), &buflen
);
1334 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
1336 dprintk(DBGLVL_API
, "%s() total descriptor size = %d bytes.\n",
1339 /* Allocate enough storage for all of the descs */
1340 buf
= kzalloc(buflen
, GFP_KERNEL
);
1342 return SAA_ERR_NO_RESOURCES
;
1345 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
1346 GET_DESCRIPTORS_CONTROL
, buflen
, buf
);
1347 if (ret
!= SAA_OK
) {
1348 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
1352 if (saa_debug
& DBGLVL_API
)
1353 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1, buf
,
1354 buflen
& ~15, false);
1356 saa7164_api_dump_subdevs(dev
, buf
, buflen
);
1363 int saa7164_api_i2c_read(struct saa7164_i2c
*bus
, u8 addr
, u32 reglen
, u8
*reg
,
1364 u32 datalen
, u8
*data
)
1366 struct saa7164_dev
*dev
= bus
->dev
;
1372 dprintk(DBGLVL_API
, "%s() addr=%x reglen=%d datalen=%d\n",
1373 __func__
, addr
, reglen
, datalen
);
1378 /* Prepare the send buffer */
1379 /* Bytes 00-03 source register length
1380 * 04-07 source bytes to read
1381 * 08... register address
1383 memset(buf
, 0, sizeof(buf
));
1384 memcpy((buf
+ 2 * sizeof(u32
) + 0), reg
, reglen
);
1385 *((u32
*)(buf
+ 0 * sizeof(u32
))) = reglen
;
1386 *((u32
*)(buf
+ 1 * sizeof(u32
))) = datalen
;
1388 unitid
= saa7164_i2caddr_to_unitid(bus
, addr
);
1391 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1396 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_LEN
,
1397 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
1398 if (ret
!= SAA_OK
) {
1399 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
1403 dprintk(DBGLVL_API
, "%s() len = %d bytes\n", __func__
, len
);
1405 if (saa_debug
& DBGLVL_I2C
)
1406 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1, buf
,
1409 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_CUR
,
1410 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
1412 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
1414 if (saa_debug
& DBGLVL_I2C
)
1415 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1,
1416 buf
, sizeof(buf
), false);
1417 memcpy(data
, (buf
+ 2 * sizeof(u32
) + reglen
), datalen
);
1420 return ret
== SAA_OK
? 0 : -EIO
;
1423 /* For a given 8 bit i2c address device, write the buffer */
1424 int saa7164_api_i2c_write(struct saa7164_i2c
*bus
, u8 addr
, u32 datalen
,
1427 struct saa7164_dev
*dev
= bus
->dev
;
1434 dprintk(DBGLVL_API
, "%s() addr=0x%2x len=0x%x\n",
1435 __func__
, addr
, datalen
);
1437 if ((datalen
== 0) || (datalen
> 232))
1440 memset(buf
, 0, sizeof(buf
));
1442 unitid
= saa7164_i2caddr_to_unitid(bus
, addr
);
1445 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1450 reglen
= saa7164_i2caddr_to_reglen(bus
, addr
);
1453 "%s() error, cannot translate regaddr to reglen\n",
1458 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_LEN
,
1459 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
1460 if (ret
!= SAA_OK
) {
1461 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
1465 dprintk(DBGLVL_API
, "%s() len = %d bytes unitid=0x%x\n", __func__
,
1468 /* Prepare the send buffer */
1469 /* Bytes 00-03 dest register length
1470 * 04-07 dest bytes to write
1471 * 08... register address
1473 *((u32
*)(buf
+ 0 * sizeof(u32
))) = reglen
;
1474 *((u32
*)(buf
+ 1 * sizeof(u32
))) = datalen
- reglen
;
1475 memcpy((buf
+ 2 * sizeof(u32
)), data
, datalen
);
1477 if (saa_debug
& DBGLVL_I2C
)
1478 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1,
1479 buf
, sizeof(buf
), false);
1481 ret
= saa7164_cmd_send(bus
->dev
, unitid
, SET_CUR
,
1482 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
1484 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
1486 return ret
== SAA_OK
? 0 : -EIO
;
1489 static int saa7164_api_modify_gpio(struct saa7164_dev
*dev
, u8 unitid
,
1493 struct tmComResGPIO t
;
1495 dprintk(DBGLVL_API
, "%s(0x%x, %d, %d)\n",
1496 __func__
, unitid
, pin
, state
);
1498 if ((pin
> 7) || (state
> 2))
1499 return SAA_ERR_BAD_PARAMETER
;
1504 ret
= saa7164_cmd_send(dev
, unitid
, SET_CUR
,
1505 EXU_GPIO_CONTROL
, sizeof(t
), &t
);
1507 printk(KERN_ERR
"%s() error, ret = 0x%x\n",
1513 int saa7164_api_set_gpiobit(struct saa7164_dev
*dev
, u8 unitid
,
1516 return saa7164_api_modify_gpio(dev
, unitid
, pin
, 1);
1519 int saa7164_api_clear_gpiobit(struct saa7164_dev
*dev
, u8 unitid
,
1522 return saa7164_api_modify_gpio(dev
, unitid
, pin
, 0);