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_collect_debug(struct saa7164_dev
*dev
)
29 tmComResDebugGetData_t d
;
33 dprintk(DBGLVL_API
, "%s()\n", __func__
);
37 memset(&d
, 0, sizeof(d
));
39 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
40 GET_DEBUG_DATA_CONTROL
, sizeof(d
), &d
);
42 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
45 if (d
.dwResult
!= SAA_OK
)
48 printk(KERN_INFO
"saa7164[%d]-FWMSG: %s", dev
->nr
, d
.ucDebugData
);
54 int saa7164_api_set_debug(struct saa7164_dev
*dev
, u8 level
)
56 tmComResDebugSetLevel_t lvl
;
59 dprintk(DBGLVL_API
, "%s(level=%d)\n", __func__
, level
);
61 /* Retrieve current state */
62 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
63 SET_DEBUG_LEVEL_CONTROL
, sizeof(lvl
), &lvl
);
65 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
67 dprintk(DBGLVL_API
, "%s() Was %d\n", __func__
, lvl
.dwDebugLevel
);
69 lvl
.dwDebugLevel
= level
;
72 ret
= saa7164_cmd_send(dev
, 0, SET_CUR
,
73 SET_DEBUG_LEVEL_CONTROL
, sizeof(lvl
), &lvl
);
75 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
81 int saa7164_api_set_vbi_format(struct saa7164_port
*port
)
83 struct saa7164_dev
*dev
= port
->dev
;
84 tmComResProbeCommit_t fmt
, rsp
;
87 dprintk(DBGLVL_API
, "%s(nr=%d, unitid=0x%x)\n", __func__
,
88 port
->nr
, port
->hwcfg
.unitid
);
94 /* Probe, see if it can support this format */
95 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
96 SET_CUR
, SAA_PROBE_CONTROL
, sizeof(fmt
), &fmt
);
98 printk(KERN_ERR
"%s() set error, ret = 0x%x\n", __func__
, ret
);
100 /* See of the format change was successful */
101 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
102 GET_CUR
, SAA_PROBE_CONTROL
, sizeof(rsp
), &rsp
);
104 printk(KERN_ERR
"%s() get error, ret = 0x%x\n", __func__
, ret
);
106 /* Compare requested vs received, should be same */
107 if (memcmp(&fmt
, &rsp
, sizeof(rsp
)) == 0) {
108 dprintk(DBGLVL_API
, "SET/PROBE Verified\n");
110 /* Ask the device to select the negotiated format */
111 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
112 SET_CUR
, SAA_COMMIT_CONTROL
, sizeof(fmt
), &fmt
);
114 printk(KERN_ERR
"%s() commit error, ret = 0x%x\n",
117 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
118 GET_CUR
, SAA_COMMIT_CONTROL
, sizeof(rsp
), &rsp
);
120 printk(KERN_ERR
"%s() GET commit error, ret = 0x%x\n",
123 if (memcmp(&fmt
, &rsp
, sizeof(rsp
)) != 0) {
124 printk(KERN_ERR
"%s() memcmp error, ret = 0x%x\n",
127 dprintk(DBGLVL_API
, "SET/COMMIT Verified\n");
129 dprintk(DBGLVL_API
, "rsp.bmHint = 0x%x\n", rsp
.bmHint
);
130 dprintk(DBGLVL_API
, "rsp.bFormatIndex = 0x%x\n", rsp
.bFormatIndex
);
131 dprintk(DBGLVL_API
, "rsp.bFrameIndex = 0x%x\n", rsp
.bFrameIndex
);
133 printk(KERN_ERR
"%s() compare failed\n", __func__
);
137 dprintk(DBGLVL_API
, "%s(nr=%d) Success\n", __func__
, port
->nr
);
142 int saa7164_api_set_gop_size(struct saa7164_port
*port
)
144 struct saa7164_dev
*dev
= port
->dev
;
145 tmComResEncVideoGopStructure_t gs
;
148 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
150 gs
.ucRefFrameDist
= port
->encoder_params
.refdist
;
151 gs
.ucGOPSize
= port
->encoder_params
.gop_size
;
152 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
153 EU_VIDEO_GOP_STRUCTURE_CONTROL
,
156 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
161 int saa7164_api_set_encoder(struct saa7164_port
*port
)
163 struct saa7164_dev
*dev
= port
->dev
;
164 tmComResEncVideoBitRate_t vb
;
165 tmComResEncAudioBitRate_t ab
;
168 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x\n", __func__
,
169 port
->hwcfg
.sourceid
);
171 if (port
->encoder_params
.stream_type
== V4L2_MPEG_STREAM_TYPE_MPEG2_PS
)
172 port
->encoder_profile
= EU_PROFILE_PS_DVD
;
174 port
->encoder_profile
= EU_PROFILE_TS_HQ
;
176 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
177 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
179 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
182 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
183 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
185 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
187 /* Establish video bitrates */
188 if (port
->encoder_params
.bitrate_mode
== V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
)
189 vb
.ucVideoBitRateMode
= EU_VIDEO_BIT_RATE_MODE_CONSTANT
;
191 vb
.ucVideoBitRateMode
= EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK
;
192 vb
.dwVideoBitRate
= port
->encoder_params
.bitrate
;
193 vb
.dwVideoBitRatePeak
= port
->encoder_params
.bitrate_peak
;
194 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
195 EU_VIDEO_BIT_RATE_CONTROL
, sizeof(tmComResEncVideoBitRate_t
), &vb
);
197 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
199 /* Establish audio bitrates */
200 ab
.ucAudioBitRateMode
= 0;
201 ab
.dwAudioBitRate
= 384000;
202 ab
.dwAudioBitRatePeak
= ab
.dwAudioBitRate
;
203 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
204 EU_AUDIO_BIT_RATE_CONTROL
, sizeof(tmComResEncAudioBitRate_t
), &ab
);
206 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
208 saa7164_api_set_aspect_ratio(port
);
209 saa7164_api_set_gop_size(port
);
214 int saa7164_api_get_encoder(struct saa7164_port
*port
)
216 struct saa7164_dev
*dev
= port
->dev
;
217 tmComResEncVideoBitRate_t v
;
218 tmComResEncAudioBitRate_t a
;
219 tmComResEncVideoInputAspectRatio_t ar
;
222 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x\n", __func__
, port
->hwcfg
.sourceid
);
224 port
->encoder_profile
= 0;
225 port
->video_format
= 0;
226 port
->video_resolution
= 0;
227 port
->audio_format
= 0;
229 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
230 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
232 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
234 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
235 EU_VIDEO_RESOLUTION_CONTROL
, sizeof(u8
), &port
->video_resolution
);
237 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
239 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
240 EU_VIDEO_FORMAT_CONTROL
, sizeof(u8
), &port
->video_format
);
242 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
244 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
245 EU_VIDEO_BIT_RATE_CONTROL
, sizeof(v
), &v
);
247 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
249 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
250 EU_AUDIO_FORMAT_CONTROL
, sizeof(u8
), &port
->audio_format
);
252 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
254 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
255 EU_AUDIO_BIT_RATE_CONTROL
, sizeof(a
), &a
);
257 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
262 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
263 EU_VIDEO_INPUT_ASPECT_CONTROL
,
264 sizeof(tmComResEncVideoInputAspectRatio_t
), &ar
);
266 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
268 dprintk(DBGLVL_ENC
, "encoder_profile = %d\n", port
->encoder_profile
);
269 dprintk(DBGLVL_ENC
, "video_format = %d\n", port
->video_format
);
270 dprintk(DBGLVL_ENC
, "audio_format = %d\n", port
->audio_format
);
271 dprintk(DBGLVL_ENC
, "video_resolution= %d\n", port
->video_resolution
);
272 dprintk(DBGLVL_ENC
, "v.ucVideoBitRateMode = %d\n", v
.ucVideoBitRateMode
);
273 dprintk(DBGLVL_ENC
, "v.dwVideoBitRate = %d\n", v
.dwVideoBitRate
);
274 dprintk(DBGLVL_ENC
, "v.dwVideoBitRatePeak = %d\n", v
.dwVideoBitRatePeak
);
275 dprintk(DBGLVL_ENC
, "a.ucVideoBitRateMode = %d\n", a
.ucAudioBitRateMode
);
276 dprintk(DBGLVL_ENC
, "a.dwVideoBitRate = %d\n", a
.dwAudioBitRate
);
277 dprintk(DBGLVL_ENC
, "a.dwVideoBitRatePeak = %d\n", a
.dwAudioBitRatePeak
);
278 dprintk(DBGLVL_ENC
, "aspect.width / height = %d:%d\n", ar
.width
, ar
.height
);
283 int saa7164_api_set_aspect_ratio(struct saa7164_port
*port
)
285 struct saa7164_dev
*dev
= port
->dev
;
286 tmComResEncVideoInputAspectRatio_t ar
;
289 dprintk(DBGLVL_ENC
, "%s(%d)\n", __func__
,
290 port
->encoder_params
.ctl_aspect
);
292 switch (port
->encoder_params
.ctl_aspect
) {
293 case V4L2_MPEG_VIDEO_ASPECT_1x1
:
297 case V4L2_MPEG_VIDEO_ASPECT_4x3
:
301 case V4L2_MPEG_VIDEO_ASPECT_16x9
:
305 case V4L2_MPEG_VIDEO_ASPECT_221x100
:
313 dprintk(DBGLVL_ENC
, "%s(%d) now %d:%d\n", __func__
,
314 port
->encoder_params
.ctl_aspect
,
315 ar
.width
, ar
.height
);
318 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
319 EU_VIDEO_INPUT_ASPECT_CONTROL
,
320 sizeof(tmComResEncVideoInputAspectRatio_t
), &ar
);
322 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
327 int saa7164_api_set_usercontrol(struct saa7164_port
*port
, u8 ctl
)
329 struct saa7164_dev
*dev
= port
->dev
;
333 if (ctl
== PU_BRIGHTNESS_CONTROL
)
334 val
= port
->ctl_brightness
;
336 if (ctl
== PU_CONTRAST_CONTROL
)
337 val
= port
->ctl_contrast
;
339 if (ctl
== PU_HUE_CONTROL
)
342 if (ctl
== PU_SATURATION_CONTROL
)
343 val
= port
->ctl_saturation
;
345 if (ctl
== PU_SHARPNESS_CONTROL
)
346 val
= port
->ctl_sharpness
;
350 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x ctl=%d, val=%d\n",
351 __func__
, port
->encunit
.vsourceid
, ctl
, val
);
353 ret
= saa7164_cmd_send(port
->dev
, port
->encunit
.vsourceid
, SET_CUR
,
354 ctl
, sizeof(u16
), &val
);
356 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
361 int saa7164_api_get_usercontrol(struct saa7164_port
*port
, u8 ctl
)
363 struct saa7164_dev
*dev
= port
->dev
;
367 ret
= saa7164_cmd_send(port
->dev
, port
->encunit
.vsourceid
, GET_CUR
,
368 ctl
, sizeof(u16
), &val
);
370 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
374 dprintk(DBGLVL_ENC
, "%s() ctl=%d, val=%d\n",
377 if (ctl
== PU_BRIGHTNESS_CONTROL
)
378 port
->ctl_brightness
= val
;
380 if (ctl
== PU_CONTRAST_CONTROL
)
381 port
->ctl_contrast
= val
;
383 if (ctl
== PU_HUE_CONTROL
)
386 if (ctl
== PU_SATURATION_CONTROL
)
387 port
->ctl_saturation
= val
;
389 if (ctl
== PU_SHARPNESS_CONTROL
)
390 port
->ctl_sharpness
= val
;
395 int saa7164_api_set_videomux(struct saa7164_port
*port
)
397 struct saa7164_dev
*dev
= port
->dev
;
398 u8 inputs
[] = { 1, 2, 2, 2, 5, 5, 5 };
401 dprintk(DBGLVL_ENC
, "%s() v_mux=%d a_mux=%d\n",
402 __func__
, port
->mux_input
, inputs
[ port
->mux_input
- 1 ]);
405 ret
= saa7164_api_audio_mute(port
, 1);
407 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
410 ret
= saa7164_cmd_send(port
->dev
, port
->vidproc
.sourceid
, SET_CUR
,
411 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &port
->mux_input
);
413 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
415 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.sourceid
, SET_CUR
,
416 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &inputs
[ port
->mux_input
- 1 ]);
418 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
420 ret
= saa7164_api_audio_mute(port
, 0);
422 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
427 int saa7164_api_audio_mute(struct saa7164_port
*port
, int mute
)
429 struct saa7164_dev
*dev
= port
->dev
;
433 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, mute
);
435 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
436 MUTE_CONTROL
, sizeof(u8
), &v
);
438 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
443 /* 0 = silence, 0xff = full */
444 int saa7164_api_set_audio_volume(struct saa7164_port
*port
, s8 level
)
446 struct saa7164_dev
*dev
= port
->dev
;
450 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, level
);
452 /* Obtain the min/max ranges */
453 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_MIN
,
454 VOLUME_CONTROL
, sizeof(u16
), &min
);
456 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
458 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_MAX
,
459 VOLUME_CONTROL
, sizeof(u16
), &max
);
461 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
463 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_CUR
,
464 ( 0x01 << 8) | VOLUME_CONTROL
, sizeof(u16
), &v
);
466 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
468 dprintk(DBGLVL_API
, "%s(%d) min=%d max=%d cur=%d\n", __func__
, level
, min
, max
, v
);
477 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
478 ( 0x01 << 8 ) | VOLUME_CONTROL
, sizeof(s16
), &v
);
480 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
483 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
484 ( 0x02 << 8 ) | VOLUME_CONTROL
, sizeof(s16
), &v
);
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
);
498 int saa7164_api_set_audio_std(struct saa7164_port
*port
)
500 struct saa7164_dev
*dev
= port
->dev
;
501 tmComResAudioDefaults_t lvl
;
502 tmComResTunerStandard_t tvaudio
;
505 dprintk(DBGLVL_API
, "%s()\n", __func__
);
507 /* Establish default levels */
508 lvl
.ucDecoderLevel
= TMHW_LEV_ADJ_DECLEV_DEFAULT
;
509 lvl
.ucDecoderFM_Level
= TMHW_LEV_ADJ_DECLEV_DEFAULT
;
510 lvl
.ucMonoLevel
= TMHW_LEV_ADJ_MONOLEV_DEFAULT
;
511 lvl
.ucNICAM_Level
= TMHW_LEV_ADJ_NICLEV_DEFAULT
;
512 lvl
.ucSAP_Level
= TMHW_LEV_ADJ_SAPLEV_DEFAULT
;
513 lvl
.ucADC_Level
= TMHW_LEV_ADJ_ADCLEV_DEFAULT
;
514 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
515 AUDIO_DEFAULT_CONTROL
, sizeof(tmComResAudioDefaults_t
), &lvl
);
517 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
519 /* Manually select the appropriate TV audio standard */
520 if (port
->encodernorm
.id
& V4L2_STD_NTSC
) {
521 tvaudio
.std
= TU_STANDARD_NTSC_M
;
524 tvaudio
.std
= TU_STANDARD_PAL_I
;
525 tvaudio
.country
= 44;
528 ret
= saa7164_cmd_send(port
->dev
, port
->tunerunit
.unitid
, SET_CUR
,
529 TU_STANDARD_CONTROL
, sizeof(tvaudio
), &tvaudio
);
531 printk(KERN_ERR
"%s() TU_STANDARD_CONTROL error, ret = 0x%x\n", __func__
, ret
);
535 int saa7164_api_set_audio_detection(struct saa7164_port
*port
, int autodetect
)
537 struct saa7164_dev
*dev
= port
->dev
;
538 tmComResTunerStandardAuto_t p
;
541 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, autodetect
);
543 /* Disable TV Audio autodetect if not already set (buggy) */
545 p
.mode
= TU_STANDARD_AUTO
;
547 p
.mode
= TU_STANDARD_MANUAL
;
548 ret
= saa7164_cmd_send(port
->dev
, port
->tunerunit
.unitid
, SET_CUR
,
549 TU_STANDARD_AUTO_CONTROL
, sizeof(p
), &p
);
551 printk(KERN_ERR
"%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n", __func__
, ret
);
556 int saa7164_api_get_videomux(struct saa7164_port
*port
)
558 struct saa7164_dev
*dev
= port
->dev
;
561 ret
= saa7164_cmd_send(port
->dev
, port
->vidproc
.sourceid
, GET_CUR
,
562 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &port
->mux_input
);
564 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
566 dprintk(DBGLVL_ENC
, "%s() v_mux=%d\n",
567 __func__
, port
->mux_input
);
572 int saa7164_api_set_dif(struct saa7164_port
*port
, u8 reg
, u8 val
)
574 struct saa7164_dev
*dev
= port
->dev
;
581 dprintk(DBGLVL_API
, "%s(nr=%d type=%d val=%x)\n", __func__
,
582 port
->nr
, port
->type
, val
);
589 memset(buf
, 0, sizeof(buf
));
611 ret
= saa7164_cmd_send(dev
, port
->ifunit
.unitid
, GET_LEN
,
612 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
614 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
618 ret
= saa7164_cmd_send(dev
, port
->ifunit
.unitid
, SET_CUR
,
619 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
621 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
623 //saa7164_dumphex16(dev, buf, 16);
625 return ret
== SAA_OK
? 0 : -EIO
;
628 /* Disable the IF block AGC controls */
629 int saa7164_api_configure_dif(struct saa7164_port
*port
, u32 std
)
631 struct saa7164_dev
*dev
= port
->dev
;
635 dprintk(DBGLVL_API
, "%s(nr=%d, 0x%x)\n", __func__
, port
->nr
, std
);
637 if (std
& V4L2_STD_NTSC
) {
638 dprintk(DBGLVL_API
, " NTSC\n");
639 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
641 } else if (std
& V4L2_STD_PAL_I
) {
642 dprintk(DBGLVL_API
, " PAL-I\n");
643 saa7164_api_set_dif(port
, 0x00, 0x08); /* Video Standard */
645 } else if (std
& V4L2_STD_PAL_M
) {
646 dprintk(DBGLVL_API
, " PAL-M\n");
647 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
649 } else if (std
& V4L2_STD_PAL_N
) {
650 dprintk(DBGLVL_API
, " PAL-N\n");
651 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
653 } else if (std
& V4L2_STD_PAL_Nc
) {
654 dprintk(DBGLVL_API
, " PAL-Nc\n");
655 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
657 } else if (std
& V4L2_STD_PAL_B
) {
658 dprintk(DBGLVL_API
, " PAL-B\n");
659 saa7164_api_set_dif(port
, 0x00, 0x02); /* Video Standard */
661 } else if (std
& V4L2_STD_PAL_DK
) {
662 dprintk(DBGLVL_API
, " PAL-DK\n");
663 saa7164_api_set_dif(port
, 0x00, 0x10); /* Video Standard */
665 } else if (std
& V4L2_STD_SECAM_L
) {
666 dprintk(DBGLVL_API
, " SECAM-L\n");
667 saa7164_api_set_dif(port
, 0x00, 0x20); /* Video Standard */
670 /* Unknown standard, assume DTV */
671 dprintk(DBGLVL_API
, " Unknown (assuming DTV)\n");
672 saa7164_api_set_dif(port
, 0x00, 0x80); /* Undefined Video Standard */
676 saa7164_api_set_dif(port
, 0x48, 0xa0); /* AGC Functions 1 */
677 saa7164_api_set_dif(port
, 0xc0, agc_disable
); /* AGC Output Disable */
678 saa7164_api_set_dif(port
, 0x7c, 0x04); /* CVBS EQ */
679 saa7164_api_set_dif(port
, 0x04, 0x01); /* Active */
681 saa7164_api_set_dif(port
, 0x04, 0x00); /* Active (again) */
687 /* Ensure the dif is in the correct state for the operating mode
688 * (analog / dtv). We only configure the diff through the analog encoder
689 * so when we're in digital mode we need to find the appropriate encoder
690 * and use it to configure the DIF.
692 int saa7164_api_initialize_dif(struct saa7164_port
*port
)
694 struct saa7164_dev
*dev
= port
->dev
;
695 struct saa7164_port
*p
= 0;
699 dprintk(DBGLVL_API
, "%s(nr=%d type=%d)\n", __func__
,
700 port
->nr
, port
->type
);
702 if (port
->type
== SAA7164_MPEG_ENCODER
) {
703 /* Pick any analog standard to init the diff.
704 * we'll come back during encoder_init'
705 * and set the correct standard if requried.
709 if (port
->type
== SAA7164_MPEG_DVB
) {
710 if (port
->nr
== SAA7164_PORT_TS1
)
711 p
= &dev
->ports
[ SAA7164_PORT_ENC1
];
713 p
= &dev
->ports
[ SAA7164_PORT_ENC2
];
715 if (port
->type
== SAA7164_MPEG_VBI
) {
717 if (port
->nr
== SAA7164_PORT_VBI1
)
718 p
= &dev
->ports
[ SAA7164_PORT_ENC1
];
720 p
= &dev
->ports
[ SAA7164_PORT_ENC2
];
725 ret
= saa7164_api_configure_dif(p
, std
);
730 int saa7164_api_transition_port(struct saa7164_port
*port
, u8 mode
)
732 struct saa7164_dev
*dev
= port
->dev
;
736 dprintk(DBGLVL_API
, "%s(nr=%d unitid=0x%x,%d)\n",
737 __func__
, port
->nr
, port
->hwcfg
.unitid
, mode
);
739 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
, SET_CUR
,
740 SAA_STATE_CONTROL
, sizeof(mode
), &mode
);
742 printk(KERN_ERR
"%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
743 __func__
, port
->nr
, port
->hwcfg
.unitid
, ret
);
748 int saa7164_api_get_fw_version(struct saa7164_dev
*dev
, u32
*version
)
752 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
753 GET_FW_VERSION_CONTROL
, sizeof(u32
), version
);
755 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
760 int saa7164_api_read_eeprom(struct saa7164_dev
*dev
, u8
*buf
, int buflen
)
762 u8 reg
[] = { 0x0f, 0x00 };
767 /* Assumption: Hauppauge eeprom is at 0xa0 on on bus 0 */
768 /* TODO: Pull the details from the boards struct */
769 return saa7164_api_i2c_read(&dev
->i2c_bus
[0], 0xa0 >> 1, sizeof(reg
),
774 int saa7164_api_configure_port_vbi(struct saa7164_dev
*dev
,
775 struct saa7164_port
*port
)
777 tmComResVBIFormatDescrHeader_t
*fmt
= &port
->vbi_fmt_ntsc
;
779 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", fmt
->bFormatIndex
);
780 dprintk(DBGLVL_API
, " VideoStandard = 0x%x\n", fmt
->VideoStandard
);
781 dprintk(DBGLVL_API
, " StartLine = %d\n", fmt
->StartLine
);
782 dprintk(DBGLVL_API
, " EndLine = %d\n", fmt
->EndLine
);
783 dprintk(DBGLVL_API
, " FieldRate = %d\n", fmt
->FieldRate
);
784 dprintk(DBGLVL_API
, " bNumLines = %d\n", fmt
->bNumLines
);
786 /* Cache the hardware configuration in the port */
788 port
->bufcounter
= port
->hwcfg
.BARLocation
;
789 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
790 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
791 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
792 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
794 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
795 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
797 (sizeof(u32
) * port
->hwcfg
.buffercount
);
798 port
->bufptr64
= port
->hwcfg
.BARLocation
+
800 (sizeof(u32
) * port
->hwcfg
.buffercount
);
801 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
802 port
->hwcfg
.BARLocation
);
804 dprintk(DBGLVL_API
, " = VS_FORMAT_VBI (becomes dev->en[%d])\n",
810 int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev
*dev
,
811 struct saa7164_port
*port
,
812 tmComResTSFormatDescrHeader_t
*tsfmt
)
814 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", tsfmt
->bFormatIndex
);
815 dprintk(DBGLVL_API
, " bDataOffset = 0x%x\n", tsfmt
->bDataOffset
);
816 dprintk(DBGLVL_API
, " bPacketLength= 0x%x\n", tsfmt
->bPacketLength
);
817 dprintk(DBGLVL_API
, " bStrideLength= 0x%x\n", tsfmt
->bStrideLength
);
818 dprintk(DBGLVL_API
, " bguid = (....)\n");
820 /* Cache the hardware configuration in the port */
822 port
->bufcounter
= port
->hwcfg
.BARLocation
;
823 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
824 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
825 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
826 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
828 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
829 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
831 (sizeof(u32
) * port
->hwcfg
.buffercount
);
832 port
->bufptr64
= port
->hwcfg
.BARLocation
+
834 (sizeof(u32
) * port
->hwcfg
.buffercount
);
835 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
836 port
->hwcfg
.BARLocation
);
838 dprintk(DBGLVL_API
, " = VS_FORMAT_MPEGTS (becomes dev->ts[%d])\n",
844 int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev
*dev
,
845 struct saa7164_port
*port
,
846 tmComResPSFormatDescrHeader_t
*fmt
)
848 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", fmt
->bFormatIndex
);
849 dprintk(DBGLVL_API
, " wPacketLength= 0x%x\n", fmt
->wPacketLength
);
850 dprintk(DBGLVL_API
, " wPackLength= 0x%x\n", fmt
->wPackLength
);
851 dprintk(DBGLVL_API
, " bPackDataType= 0x%x\n", fmt
->bPackDataType
);
853 /* Cache the hardware configuration in the port */
854 /* TODO: CHECK THIS in the port config */
855 port
->bufcounter
= port
->hwcfg
.BARLocation
;
856 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
857 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
858 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
859 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
861 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
862 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
864 (sizeof(u32
) * port
->hwcfg
.buffercount
);
865 port
->bufptr64
= port
->hwcfg
.BARLocation
+
867 (sizeof(u32
) * port
->hwcfg
.buffercount
);
868 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
869 port
->hwcfg
.BARLocation
);
871 dprintk(DBGLVL_API
, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
877 int saa7164_api_dump_subdevs(struct saa7164_dev
*dev
, u8
*buf
, int len
)
879 struct saa7164_port
*tsport
= 0;
880 struct saa7164_port
*encport
= 0;
881 struct saa7164_port
*vbiport
= 0;
882 u32 idx
, next_offset
;
884 tmComResDescrHeader_t
*hdr
, *t
;
885 tmComResExtDevDescrHeader_t
*exthdr
;
886 tmComResPathDescrHeader_t
*pathhdr
;
887 tmComResAntTermDescrHeader_t
*anttermhdr
;
888 tmComResTunerDescrHeader_t
*tunerunithdr
;
889 tmComResDMATermDescrHeader_t
*vcoutputtermhdr
;
890 tmComResTSFormatDescrHeader_t
*tsfmt
;
891 tmComResPSFormatDescrHeader_t
*psfmt
;
892 tmComResSelDescrHeader_t
*psel
;
893 tmComResProcDescrHeader_t
*pdh
;
894 tmComResAFeatureDescrHeader_t
*afd
;
895 tmComResEncoderDescrHeader_t
*edh
;
896 tmComResVBIFormatDescrHeader_t
*vbifmt
;
900 "%s(?,?,%d) sizeof(tmComResDescrHeader_t) = %d bytes\n",
901 __func__
, len
, (u32
)sizeof(tmComResDescrHeader_t
));
903 for (idx
= 0; idx
< (len
- sizeof(tmComResDescrHeader_t
)); ) {
905 hdr
= (tmComResDescrHeader_t
*)(buf
+ idx
);
907 if (hdr
->type
!= CS_INTERFACE
)
908 return SAA_ERR_NOT_SUPPORTED
;
910 dprintk(DBGLVL_API
, "@ 0x%x = \n", idx
);
911 switch (hdr
->subtype
) {
912 case GENERAL_REQUEST
:
913 dprintk(DBGLVL_API
, " GENERAL_REQUEST\n");
916 dprintk(DBGLVL_API
, " VC_TUNER_PATH\n");
917 pathhdr
= (tmComResPathDescrHeader_t
*)(buf
+ idx
);
918 dprintk(DBGLVL_API
, " pathid = 0x%x\n",
920 currpath
= pathhdr
->pathid
;
922 case VC_INPUT_TERMINAL
:
923 dprintk(DBGLVL_API
, " VC_INPUT_TERMINAL\n");
925 (tmComResAntTermDescrHeader_t
*)(buf
+ idx
);
926 dprintk(DBGLVL_API
, " terminalid = 0x%x\n",
927 anttermhdr
->terminalid
);
928 dprintk(DBGLVL_API
, " terminaltype = 0x%x\n",
929 anttermhdr
->terminaltype
);
930 switch (anttermhdr
->terminaltype
) {
932 dprintk(DBGLVL_API
, " = ITT_ANTENNA\n");
935 dprintk(DBGLVL_API
, " = LINE_CONNECTOR\n");
937 case SPDIF_CONNECTOR
:
938 dprintk(DBGLVL_API
, " = SPDIF_CONNECTOR\n");
940 case COMPOSITE_CONNECTOR
:
942 " = COMPOSITE_CONNECTOR\n");
944 case SVIDEO_CONNECTOR
:
945 dprintk(DBGLVL_API
, " = SVIDEO_CONNECTOR\n");
947 case COMPONENT_CONNECTOR
:
949 " = COMPONENT_CONNECTOR\n");
952 dprintk(DBGLVL_API
, " = STANDARD_DMA\n");
955 dprintk(DBGLVL_API
, " = undefined (0x%x)\n",
956 anttermhdr
->terminaltype
);
958 dprintk(DBGLVL_API
, " assocterminal= 0x%x\n",
959 anttermhdr
->assocterminal
);
960 dprintk(DBGLVL_API
, " iterminal = 0x%x\n",
961 anttermhdr
->iterminal
);
962 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
963 anttermhdr
->controlsize
);
965 case VC_OUTPUT_TERMINAL
:
966 dprintk(DBGLVL_API
, " VC_OUTPUT_TERMINAL\n");
968 (tmComResDMATermDescrHeader_t
*)(buf
+ idx
);
969 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
970 vcoutputtermhdr
->unitid
);
971 dprintk(DBGLVL_API
, " terminaltype = 0x%x\n",
972 vcoutputtermhdr
->terminaltype
);
973 switch (vcoutputtermhdr
->terminaltype
) {
975 dprintk(DBGLVL_API
, " = ITT_ANTENNA\n");
978 dprintk(DBGLVL_API
, " = LINE_CONNECTOR\n");
980 case SPDIF_CONNECTOR
:
981 dprintk(DBGLVL_API
, " = SPDIF_CONNECTOR\n");
983 case COMPOSITE_CONNECTOR
:
985 " = COMPOSITE_CONNECTOR\n");
987 case SVIDEO_CONNECTOR
:
988 dprintk(DBGLVL_API
, " = SVIDEO_CONNECTOR\n");
990 case COMPONENT_CONNECTOR
:
992 " = COMPONENT_CONNECTOR\n");
995 dprintk(DBGLVL_API
, " = STANDARD_DMA\n");
998 dprintk(DBGLVL_API
, " = undefined (0x%x)\n",
999 vcoutputtermhdr
->terminaltype
);
1001 dprintk(DBGLVL_API
, " assocterminal= 0x%x\n",
1002 vcoutputtermhdr
->assocterminal
);
1003 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1004 vcoutputtermhdr
->sourceid
);
1005 dprintk(DBGLVL_API
, " iterminal = 0x%x\n",
1006 vcoutputtermhdr
->iterminal
);
1007 dprintk(DBGLVL_API
, " BARLocation = 0x%x\n",
1008 vcoutputtermhdr
->BARLocation
);
1009 dprintk(DBGLVL_API
, " flags = 0x%x\n",
1010 vcoutputtermhdr
->flags
);
1011 dprintk(DBGLVL_API
, " interruptid = 0x%x\n",
1012 vcoutputtermhdr
->interruptid
);
1013 dprintk(DBGLVL_API
, " buffercount = 0x%x\n",
1014 vcoutputtermhdr
->buffercount
);
1015 dprintk(DBGLVL_API
, " metadatasize = 0x%x\n",
1016 vcoutputtermhdr
->metadatasize
);
1017 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1018 vcoutputtermhdr
->controlsize
);
1019 dprintk(DBGLVL_API
, " numformats = 0x%x\n",
1020 vcoutputtermhdr
->numformats
);
1022 t
= (tmComResDescrHeader_t
*)
1023 ((tmComResDMATermDescrHeader_t
*)(buf
+ idx
));
1024 next_offset
= idx
+ (vcoutputtermhdr
->len
);
1025 for (i
= 0; i
< vcoutputtermhdr
->numformats
; i
++) {
1026 t
= (tmComResDescrHeader_t
*)
1027 (buf
+ next_offset
);
1028 switch (t
->subtype
) {
1029 case VS_FORMAT_MPEG2TS
:
1031 (tmComResTSFormatDescrHeader_t
*)t
;
1033 tsport
= &dev
->ports
[ SAA7164_PORT_TS1
];
1035 tsport
= &dev
->ports
[ SAA7164_PORT_TS2
];
1036 memcpy(&tsport
->hwcfg
, vcoutputtermhdr
,
1037 sizeof(*vcoutputtermhdr
));
1038 saa7164_api_configure_port_mpeg2ts(dev
,
1041 case VS_FORMAT_MPEG2PS
:
1043 (tmComResPSFormatDescrHeader_t
*)t
;
1045 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
1047 encport
= &dev
->ports
[ SAA7164_PORT_ENC2
];
1048 memcpy(&encport
->hwcfg
, vcoutputtermhdr
,
1049 sizeof(*vcoutputtermhdr
));
1050 saa7164_api_configure_port_mpeg2ps(dev
,
1055 (tmComResVBIFormatDescrHeader_t
*)t
;
1057 vbiport
= &dev
->ports
[ SAA7164_PORT_VBI1
];
1059 vbiport
= &dev
->ports
[ SAA7164_PORT_VBI2
];
1060 memcpy(&vbiport
->hwcfg
, vcoutputtermhdr
,
1061 sizeof(*vcoutputtermhdr
));
1062 memcpy(&vbiport
->vbi_fmt_ntsc
, vbifmt
, sizeof(*vbifmt
));
1063 saa7164_api_configure_port_vbi(dev
,
1068 " = VS_FORMAT_RDS\n");
1070 case VS_FORMAT_UNCOMPRESSED
:
1072 " = VS_FORMAT_UNCOMPRESSED\n");
1074 case VS_FORMAT_TYPE
:
1076 " = VS_FORMAT_TYPE\n");
1080 " = undefined (0x%x)\n",
1083 next_offset
+= t
->len
;
1088 dprintk(DBGLVL_API
, " TUNER_UNIT\n");
1090 (tmComResTunerDescrHeader_t
*)(buf
+ idx
);
1091 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1092 tunerunithdr
->unitid
);
1093 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1094 tunerunithdr
->sourceid
);
1095 dprintk(DBGLVL_API
, " iunit = 0x%x\n",
1096 tunerunithdr
->iunit
);
1097 dprintk(DBGLVL_API
, " tuningstandards = 0x%x\n",
1098 tunerunithdr
->tuningstandards
);
1099 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1100 tunerunithdr
->controlsize
);
1101 dprintk(DBGLVL_API
, " controls = 0x%x\n",
1102 tunerunithdr
->controls
);
1104 if (tunerunithdr
->unitid
== tunerunithdr
->iunit
) {
1106 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
1108 encport
= &dev
->ports
[ SAA7164_PORT_ENC2
];
1109 memcpy(&encport
->tunerunit
, tunerunithdr
,
1110 sizeof(tmComResTunerDescrHeader_t
));
1111 dprintk(DBGLVL_API
, " (becomes dev->enc[%d] tuner)\n", encport
->nr
);
1114 case VC_SELECTOR_UNIT
:
1115 psel
= (tmComResSelDescrHeader_t
*)(buf
+ idx
);
1116 dprintk(DBGLVL_API
, " VC_SELECTOR_UNIT\n");
1117 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1119 dprintk(DBGLVL_API
, " nrinpins = 0x%x\n",
1121 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1124 case VC_PROCESSING_UNIT
:
1125 pdh
= (tmComResProcDescrHeader_t
*)(buf
+ idx
);
1126 dprintk(DBGLVL_API
, " VC_PROCESSING_UNIT\n");
1127 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1129 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1131 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1133 if (pdh
->controlsize
== 0x04) {
1135 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
1137 encport
= &dev
->ports
[ SAA7164_PORT_ENC2
];
1138 memcpy(&encport
->vidproc
, pdh
,
1139 sizeof(tmComResProcDescrHeader_t
));
1140 dprintk(DBGLVL_API
, " (becomes dev->enc[%d])\n", encport
->nr
);
1144 afd
= (tmComResAFeatureDescrHeader_t
*)(buf
+ idx
);
1145 dprintk(DBGLVL_API
, " FEATURE_UNIT\n");
1146 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1148 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1150 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1153 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
1155 encport
= &dev
->ports
[ SAA7164_PORT_ENC2
];
1156 memcpy(&encport
->audfeat
, afd
,
1157 sizeof(tmComResAFeatureDescrHeader_t
));
1158 dprintk(DBGLVL_API
, " (becomes dev->enc[%d])\n", encport
->nr
);
1161 edh
= (tmComResEncoderDescrHeader_t
*)(buf
+ idx
);
1162 dprintk(DBGLVL_API
, " ENCODER_UNIT\n");
1163 dprintk(DBGLVL_API
, " subtype = 0x%x\n", edh
->subtype
);
1164 dprintk(DBGLVL_API
, " unitid = 0x%x\n", edh
->unitid
);
1165 dprintk(DBGLVL_API
, " vsourceid = 0x%x\n", edh
->vsourceid
);
1166 dprintk(DBGLVL_API
, " asourceid = 0x%x\n", edh
->asourceid
);
1167 dprintk(DBGLVL_API
, " iunit = 0x%x\n", edh
->iunit
);
1168 if (edh
->iunit
== edh
->unitid
) {
1170 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
1172 encport
= &dev
->ports
[ SAA7164_PORT_ENC2
];
1173 memcpy(&encport
->encunit
, edh
,
1174 sizeof(tmComResEncoderDescrHeader_t
));
1175 dprintk(DBGLVL_API
, " (becomes dev->enc[%d])\n", encport
->nr
);
1178 case EXTENSION_UNIT
:
1179 dprintk(DBGLVL_API
, " EXTENSION_UNIT\n");
1180 exthdr
= (tmComResExtDevDescrHeader_t
*)(buf
+ idx
);
1181 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1183 dprintk(DBGLVL_API
, " deviceid = 0x%x\n",
1185 dprintk(DBGLVL_API
, " devicetype = 0x%x\n",
1186 exthdr
->devicetype
);
1187 if (exthdr
->devicetype
& 0x1)
1188 dprintk(DBGLVL_API
, " = Decoder Device\n");
1189 if (exthdr
->devicetype
& 0x2)
1190 dprintk(DBGLVL_API
, " = GPIO Source\n");
1191 if (exthdr
->devicetype
& 0x4)
1192 dprintk(DBGLVL_API
, " = Video Decoder\n");
1193 if (exthdr
->devicetype
& 0x8)
1194 dprintk(DBGLVL_API
, " = Audio Decoder\n");
1195 if (exthdr
->devicetype
& 0x20)
1196 dprintk(DBGLVL_API
, " = Crossbar\n");
1197 if (exthdr
->devicetype
& 0x40)
1198 dprintk(DBGLVL_API
, " = Tuner\n");
1199 if (exthdr
->devicetype
& 0x80)
1200 dprintk(DBGLVL_API
, " = IF PLL\n");
1201 if (exthdr
->devicetype
& 0x100)
1202 dprintk(DBGLVL_API
, " = Demodulator\n");
1203 if (exthdr
->devicetype
& 0x200)
1204 dprintk(DBGLVL_API
, " = RDS Decoder\n");
1205 if (exthdr
->devicetype
& 0x400)
1206 dprintk(DBGLVL_API
, " = Encoder\n");
1207 if (exthdr
->devicetype
& 0x800)
1208 dprintk(DBGLVL_API
, " = IR Decoder\n");
1209 if (exthdr
->devicetype
& 0x1000)
1210 dprintk(DBGLVL_API
, " = EEPROM\n");
1211 if (exthdr
->devicetype
& 0x2000)
1213 " = VBI Decoder\n");
1214 if (exthdr
->devicetype
& 0x10000)
1216 " = Streaming Device\n");
1217 if (exthdr
->devicetype
& 0x20000)
1220 if (exthdr
->devicetype
& 0x40000000)
1222 " = Generic Device\n");
1223 if (exthdr
->devicetype
& 0x80000000)
1225 " = Config Space Device\n");
1226 dprintk(DBGLVL_API
, " numgpiopins = 0x%x\n",
1227 exthdr
->numgpiopins
);
1228 dprintk(DBGLVL_API
, " numgpiogroups = 0x%x\n",
1229 exthdr
->numgpiogroups
);
1230 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1231 exthdr
->controlsize
);
1232 if (exthdr
->devicetype
& 0x80) {
1234 encport
= &dev
->ports
[ SAA7164_PORT_ENC1
];
1236 encport
= &dev
->ports
[ SAA7164_PORT_ENC2
];
1237 memcpy(&encport
->ifunit
, exthdr
,
1238 sizeof(tmComResExtDevDescrHeader_t
));
1239 dprintk(DBGLVL_API
, " (becomes dev->enc[%d])\n", encport
->nr
);
1242 case PVC_INFRARED_UNIT
:
1243 dprintk(DBGLVL_API
, " PVC_INFRARED_UNIT\n");
1246 dprintk(DBGLVL_API
, " DRM_UNIT\n");
1249 dprintk(DBGLVL_API
, "default %d\n", hdr
->subtype
);
1252 dprintk(DBGLVL_API
, " 1.%x\n", hdr
->len
);
1253 dprintk(DBGLVL_API
, " 2.%x\n", hdr
->type
);
1254 dprintk(DBGLVL_API
, " 3.%x\n", hdr
->subtype
);
1255 dprintk(DBGLVL_API
, " 4.%x\n", hdr
->unitid
);
1263 int saa7164_api_enum_subdevs(struct saa7164_dev
*dev
)
1269 dprintk(DBGLVL_API
, "%s()\n", __func__
);
1271 /* Get the total descriptor length */
1272 ret
= saa7164_cmd_send(dev
, 0, GET_LEN
,
1273 GET_DESCRIPTORS_CONTROL
, sizeof(buflen
), &buflen
);
1275 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
1277 dprintk(DBGLVL_API
, "%s() total descriptor size = %d bytes.\n",
1280 /* Allocate enough storage for all of the descs */
1281 buf
= kzalloc(buflen
, GFP_KERNEL
);
1283 return SAA_ERR_NO_RESOURCES
;
1286 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
1287 GET_DESCRIPTORS_CONTROL
, buflen
, buf
);
1288 if (ret
!= SAA_OK
) {
1289 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
1293 if (saa_debug
& DBGLVL_API
)
1294 saa7164_dumphex16(dev
, buf
, (buflen
/16)*16);
1296 saa7164_api_dump_subdevs(dev
, buf
, buflen
);
1303 int saa7164_api_i2c_read(struct saa7164_i2c
*bus
, u8 addr
, u32 reglen
, u8
*reg
,
1304 u32 datalen
, u8
*data
)
1306 struct saa7164_dev
*dev
= bus
->dev
;
1313 dprintk(DBGLVL_API
, "%s()\n", __func__
);
1322 regval
= ((*(reg
) << 8) || *(reg
+1));
1325 regval
= ((*(reg
) << 16) | (*(reg
+1) << 8) | *(reg
+2));
1328 regval
= ((*(reg
) << 24) | (*(reg
+1) << 16) |
1329 (*(reg
+2) << 8) | *(reg
+3));
1331 /* Prepare the send buffer */
1332 /* Bytes 00-03 source register length
1333 * 04-07 source bytes to read
1334 * 08... register address
1336 memset(buf
, 0, sizeof(buf
));
1337 memcpy((buf
+ 2 * sizeof(u32
) + 0), reg
, reglen
);
1338 *((u32
*)(buf
+ 0 * sizeof(u32
))) = reglen
;
1339 *((u32
*)(buf
+ 1 * sizeof(u32
))) = datalen
;
1341 unitid
= saa7164_i2caddr_to_unitid(bus
, addr
);
1344 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1349 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_LEN
,
1350 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
1351 if (ret
!= SAA_OK
) {
1352 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
1356 dprintk(DBGLVL_API
, "%s() len = %d bytes\n", __func__
, len
);
1358 if (saa_debug
& DBGLVL_I2C
)
1359 saa7164_dumphex16(dev
, buf
, 2 * 16);
1361 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_CUR
,
1362 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
1364 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
1366 if (saa_debug
& DBGLVL_I2C
)
1367 saa7164_dumphex16(dev
, buf
, sizeof(buf
));
1368 memcpy(data
, (buf
+ 2 * sizeof(u32
) + reglen
), datalen
);
1371 return ret
== SAA_OK
? 0 : -EIO
;
1374 /* For a given 8 bit i2c address device, write the buffer */
1375 int saa7164_api_i2c_write(struct saa7164_i2c
*bus
, u8 addr
, u32 datalen
,
1378 struct saa7164_dev
*dev
= bus
->dev
;
1385 dprintk(DBGLVL_API
, "%s()\n", __func__
);
1387 if ((datalen
== 0) || (datalen
> 232))
1390 memset(buf
, 0, sizeof(buf
));
1392 unitid
= saa7164_i2caddr_to_unitid(bus
, addr
);
1395 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1400 reglen
= saa7164_i2caddr_to_reglen(bus
, addr
);
1403 "%s() error, cannot translate regaddr to reglen\n",
1408 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_LEN
,
1409 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
1410 if (ret
!= SAA_OK
) {
1411 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
1415 dprintk(DBGLVL_API
, "%s() len = %d bytes\n", __func__
, len
);
1417 /* Prepare the send buffer */
1418 /* Bytes 00-03 dest register length
1419 * 04-07 dest bytes to write
1420 * 08... register address
1422 *((u32
*)(buf
+ 0 * sizeof(u32
))) = reglen
;
1423 *((u32
*)(buf
+ 1 * sizeof(u32
))) = datalen
- reglen
;
1424 memcpy((buf
+ 2 * sizeof(u32
)), data
, datalen
);
1426 if (saa_debug
& DBGLVL_I2C
)
1427 saa7164_dumphex16(dev
, buf
, sizeof(buf
));
1429 ret
= saa7164_cmd_send(bus
->dev
, unitid
, SET_CUR
,
1430 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
1432 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
1434 return ret
== SAA_OK
? 0 : -EIO
;
1438 int saa7164_api_modify_gpio(struct saa7164_dev
*dev
, u8 unitid
,
1444 dprintk(DBGLVL_API
, "%s(0x%x, %d, %d)\n",
1445 __func__
, unitid
, pin
, state
);
1447 if ((pin
> 7) || (state
> 2))
1448 return SAA_ERR_BAD_PARAMETER
;
1453 ret
= saa7164_cmd_send(dev
, unitid
, SET_CUR
,
1454 EXU_GPIO_CONTROL
, sizeof(t
), &t
);
1456 printk(KERN_ERR
"%s() error, ret = 0x%x\n",
1462 int saa7164_api_set_gpiobit(struct saa7164_dev
*dev
, u8 unitid
,
1465 return saa7164_api_modify_gpio(dev
, unitid
, pin
, 1);
1468 int saa7164_api_clear_gpiobit(struct saa7164_dev
*dev
, u8 unitid
,
1471 return saa7164_api_modify_gpio(dev
, unitid
, pin
, 0);