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.
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
, struct tmFwInfoStruct
*i
)
31 if (!(saa_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(struct tmFwInfoStruct
), i
);
44 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
46 printk(KERN_INFO
"saa7164[%d]-CPU: %d percent", dev
->nr
, i
->CPULoad
);
51 int saa7164_api_collect_debug(struct saa7164_dev
*dev
)
53 struct tmComResDebugGetData d
;
57 dprintk(DBGLVL_API
, "%s()\n", __func__
);
61 memset(&d
, 0, sizeof(d
));
63 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
64 GET_DEBUG_DATA_CONTROL
, sizeof(d
), &d
);
66 printk(KERN_ERR
"%s() error, ret = 0x%x\n",
69 if (d
.dwResult
!= SAA_OK
)
72 printk(KERN_INFO
"saa7164[%d]-FWMSG: %s", dev
->nr
,
79 int saa7164_api_set_debug(struct saa7164_dev
*dev
, u8 level
)
81 struct tmComResDebugSetLevel 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
);
105 int saa7164_api_set_vbi_format(struct saa7164_port
*port
)
107 struct saa7164_dev
*dev
= port
->dev
;
108 struct tmComResProbeCommit fmt
, rsp
;
111 dprintk(DBGLVL_API
, "%s(nr=%d, unitid=0x%x)\n", __func__
,
112 port
->nr
, port
->hwcfg
.unitid
);
115 fmt
.bFormatIndex
= 1;
118 /* Probe, see if it can support this format */
119 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
120 SET_CUR
, SAA_PROBE_CONTROL
, sizeof(fmt
), &fmt
);
122 printk(KERN_ERR
"%s() set error, ret = 0x%x\n", __func__
, ret
);
124 /* See of the format change was successful */
125 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
126 GET_CUR
, SAA_PROBE_CONTROL
, sizeof(rsp
), &rsp
);
128 printk(KERN_ERR
"%s() get error, ret = 0x%x\n", __func__
, ret
);
130 /* Compare requested vs received, should be same */
131 if (memcmp(&fmt
, &rsp
, sizeof(rsp
)) == 0) {
132 dprintk(DBGLVL_API
, "SET/PROBE Verified\n");
134 /* Ask the device to select the negotiated format */
135 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
136 SET_CUR
, SAA_COMMIT_CONTROL
, sizeof(fmt
), &fmt
);
138 printk(KERN_ERR
"%s() commit error, ret = 0x%x\n",
141 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
,
142 GET_CUR
, SAA_COMMIT_CONTROL
, sizeof(rsp
), &rsp
);
144 printk(KERN_ERR
"%s() GET commit error, ret = 0x%x\n",
147 if (memcmp(&fmt
, &rsp
, sizeof(rsp
)) != 0) {
148 printk(KERN_ERR
"%s() memcmp error, ret = 0x%x\n",
151 dprintk(DBGLVL_API
, "SET/COMMIT Verified\n");
153 dprintk(DBGLVL_API
, "rsp.bmHint = 0x%x\n", rsp
.bmHint
);
154 dprintk(DBGLVL_API
, "rsp.bFormatIndex = 0x%x\n",
156 dprintk(DBGLVL_API
, "rsp.bFrameIndex = 0x%x\n",
159 printk(KERN_ERR
"%s() compare failed\n", __func__
);
163 dprintk(DBGLVL_API
, "%s(nr=%d) Success\n", __func__
, port
->nr
);
168 static int saa7164_api_set_gop_size(struct saa7164_port
*port
)
170 struct saa7164_dev
*dev
= port
->dev
;
171 struct tmComResEncVideoGopStructure gs
;
174 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
176 gs
.ucRefFrameDist
= port
->encoder_params
.refdist
;
177 gs
.ucGOPSize
= port
->encoder_params
.gop_size
;
178 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
179 EU_VIDEO_GOP_STRUCTURE_CONTROL
,
182 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
187 int saa7164_api_set_encoder(struct saa7164_port
*port
)
189 struct saa7164_dev
*dev
= port
->dev
;
190 struct tmComResEncVideoBitRate vb
;
191 struct tmComResEncAudioBitRate ab
;
194 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x\n", __func__
,
195 port
->hwcfg
.sourceid
);
197 if (port
->encoder_params
.stream_type
== V4L2_MPEG_STREAM_TYPE_MPEG2_PS
)
198 port
->encoder_profile
= EU_PROFILE_PS_DVD
;
200 port
->encoder_profile
= EU_PROFILE_TS_HQ
;
202 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
203 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
205 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
208 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
209 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
211 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
213 /* Establish video bitrates */
214 if (port
->encoder_params
.bitrate_mode
==
215 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
)
216 vb
.ucVideoBitRateMode
= EU_VIDEO_BIT_RATE_MODE_CONSTANT
;
218 vb
.ucVideoBitRateMode
= EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK
;
219 vb
.dwVideoBitRate
= port
->encoder_params
.bitrate
;
220 vb
.dwVideoBitRatePeak
= port
->encoder_params
.bitrate_peak
;
221 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
222 EU_VIDEO_BIT_RATE_CONTROL
,
223 sizeof(struct tmComResEncVideoBitRate
),
226 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
228 /* Establish audio bitrates */
229 ab
.ucAudioBitRateMode
= 0;
230 ab
.dwAudioBitRate
= 384000;
231 ab
.dwAudioBitRatePeak
= ab
.dwAudioBitRate
;
232 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
233 EU_AUDIO_BIT_RATE_CONTROL
,
234 sizeof(struct tmComResEncAudioBitRate
),
237 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
,
240 saa7164_api_set_aspect_ratio(port
);
241 saa7164_api_set_gop_size(port
);
246 int saa7164_api_get_encoder(struct saa7164_port
*port
)
248 struct saa7164_dev
*dev
= port
->dev
;
249 struct tmComResEncVideoBitRate v
;
250 struct tmComResEncAudioBitRate a
;
251 struct tmComResEncVideoInputAspectRatio ar
;
254 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x\n", __func__
,
255 port
->hwcfg
.sourceid
);
257 port
->encoder_profile
= 0;
258 port
->video_format
= 0;
259 port
->video_resolution
= 0;
260 port
->audio_format
= 0;
262 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
263 EU_PROFILE_CONTROL
, sizeof(u8
), &port
->encoder_profile
);
265 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
267 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
268 EU_VIDEO_RESOLUTION_CONTROL
, sizeof(u8
),
269 &port
->video_resolution
);
271 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
273 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
274 EU_VIDEO_FORMAT_CONTROL
, sizeof(u8
), &port
->video_format
);
276 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
278 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
279 EU_VIDEO_BIT_RATE_CONTROL
, sizeof(v
), &v
);
281 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
283 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
284 EU_AUDIO_FORMAT_CONTROL
, sizeof(u8
), &port
->audio_format
);
286 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
288 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
289 EU_AUDIO_BIT_RATE_CONTROL
, sizeof(a
), &a
);
291 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
296 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, GET_CUR
,
297 EU_VIDEO_INPUT_ASPECT_CONTROL
,
298 sizeof(struct tmComResEncVideoInputAspectRatio
), &ar
);
300 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
302 dprintk(DBGLVL_ENC
, "encoder_profile = %d\n", port
->encoder_profile
);
303 dprintk(DBGLVL_ENC
, "video_format = %d\n", port
->video_format
);
304 dprintk(DBGLVL_ENC
, "audio_format = %d\n", port
->audio_format
);
305 dprintk(DBGLVL_ENC
, "video_resolution= %d\n", port
->video_resolution
);
306 dprintk(DBGLVL_ENC
, "v.ucVideoBitRateMode = %d\n",
307 v
.ucVideoBitRateMode
);
308 dprintk(DBGLVL_ENC
, "v.dwVideoBitRate = %d\n",
310 dprintk(DBGLVL_ENC
, "v.dwVideoBitRatePeak = %d\n",
311 v
.dwVideoBitRatePeak
);
312 dprintk(DBGLVL_ENC
, "a.ucVideoBitRateMode = %d\n",
313 a
.ucAudioBitRateMode
);
314 dprintk(DBGLVL_ENC
, "a.dwVideoBitRate = %d\n",
316 dprintk(DBGLVL_ENC
, "a.dwVideoBitRatePeak = %d\n",
317 a
.dwAudioBitRatePeak
);
318 dprintk(DBGLVL_ENC
, "aspect.width / height = %d:%d\n",
319 ar
.width
, ar
.height
);
324 int saa7164_api_set_aspect_ratio(struct saa7164_port
*port
)
326 struct saa7164_dev
*dev
= port
->dev
;
327 struct tmComResEncVideoInputAspectRatio ar
;
330 dprintk(DBGLVL_ENC
, "%s(%d)\n", __func__
,
331 port
->encoder_params
.ctl_aspect
);
333 switch (port
->encoder_params
.ctl_aspect
) {
334 case V4L2_MPEG_VIDEO_ASPECT_1x1
:
338 case V4L2_MPEG_VIDEO_ASPECT_4x3
:
342 case V4L2_MPEG_VIDEO_ASPECT_16x9
:
346 case V4L2_MPEG_VIDEO_ASPECT_221x100
:
354 dprintk(DBGLVL_ENC
, "%s(%d) now %d:%d\n", __func__
,
355 port
->encoder_params
.ctl_aspect
,
356 ar
.width
, ar
.height
);
359 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.sourceid
, SET_CUR
,
360 EU_VIDEO_INPUT_ASPECT_CONTROL
,
361 sizeof(struct tmComResEncVideoInputAspectRatio
), &ar
);
363 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
368 int saa7164_api_set_usercontrol(struct saa7164_port
*port
, u8 ctl
)
370 struct saa7164_dev
*dev
= port
->dev
;
374 if (ctl
== PU_BRIGHTNESS_CONTROL
)
375 val
= port
->ctl_brightness
;
377 if (ctl
== PU_CONTRAST_CONTROL
)
378 val
= port
->ctl_contrast
;
380 if (ctl
== PU_HUE_CONTROL
)
383 if (ctl
== PU_SATURATION_CONTROL
)
384 val
= port
->ctl_saturation
;
386 if (ctl
== PU_SHARPNESS_CONTROL
)
387 val
= port
->ctl_sharpness
;
391 dprintk(DBGLVL_ENC
, "%s() unitid=0x%x ctl=%d, val=%d\n",
392 __func__
, port
->encunit
.vsourceid
, ctl
, val
);
394 ret
= saa7164_cmd_send(port
->dev
, port
->encunit
.vsourceid
, SET_CUR
,
395 ctl
, sizeof(u16
), &val
);
397 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
402 int saa7164_api_get_usercontrol(struct saa7164_port
*port
, u8 ctl
)
404 struct saa7164_dev
*dev
= port
->dev
;
408 ret
= saa7164_cmd_send(port
->dev
, port
->encunit
.vsourceid
, GET_CUR
,
409 ctl
, sizeof(u16
), &val
);
411 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
415 dprintk(DBGLVL_ENC
, "%s() ctl=%d, val=%d\n",
418 if (ctl
== PU_BRIGHTNESS_CONTROL
)
419 port
->ctl_brightness
= val
;
421 if (ctl
== PU_CONTRAST_CONTROL
)
422 port
->ctl_contrast
= val
;
424 if (ctl
== PU_HUE_CONTROL
)
427 if (ctl
== PU_SATURATION_CONTROL
)
428 port
->ctl_saturation
= val
;
430 if (ctl
== PU_SHARPNESS_CONTROL
)
431 port
->ctl_sharpness
= val
;
436 int saa7164_api_set_videomux(struct saa7164_port
*port
)
438 struct saa7164_dev
*dev
= port
->dev
;
439 u8 inputs
[] = { 1, 2, 2, 2, 5, 5, 5 };
442 dprintk(DBGLVL_ENC
, "%s() v_mux=%d a_mux=%d\n",
443 __func__
, port
->mux_input
, inputs
[port
->mux_input
- 1]);
446 ret
= saa7164_api_audio_mute(port
, 1);
448 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
451 ret
= saa7164_cmd_send(port
->dev
, port
->vidproc
.sourceid
, SET_CUR
,
452 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &port
->mux_input
);
454 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
457 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.sourceid
, SET_CUR
,
458 SU_INPUT_SELECT_CONTROL
, sizeof(u8
),
459 &inputs
[port
->mux_input
- 1]);
461 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
464 ret
= saa7164_api_audio_mute(port
, 0);
466 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
471 int saa7164_api_audio_mute(struct saa7164_port
*port
, int mute
)
473 struct saa7164_dev
*dev
= port
->dev
;
477 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, mute
);
479 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
480 MUTE_CONTROL
, sizeof(u8
), &v
);
482 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
487 /* 0 = silence, 0xff = full */
488 int saa7164_api_set_audio_volume(struct saa7164_port
*port
, s8 level
)
490 struct saa7164_dev
*dev
= port
->dev
;
494 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, level
);
496 /* Obtain the min/max ranges */
497 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_MIN
,
498 VOLUME_CONTROL
, sizeof(u16
), &min
);
500 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
502 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_MAX
,
503 VOLUME_CONTROL
, sizeof(u16
), &max
);
505 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
507 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_CUR
,
508 (0x01 << 8) | VOLUME_CONTROL
, sizeof(u16
), &v
);
510 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
512 dprintk(DBGLVL_API
, "%s(%d) min=%d max=%d cur=%d\n", __func__
,
522 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
523 (0x01 << 8) | VOLUME_CONTROL
, sizeof(s16
), &v
);
525 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
528 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
529 (0x02 << 8) | VOLUME_CONTROL
, sizeof(s16
), &v
);
531 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
533 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, GET_CUR
,
534 (0x01 << 8) | VOLUME_CONTROL
, sizeof(u16
), &v
);
536 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
538 dprintk(DBGLVL_API
, "%s(%d) min=%d max=%d cur=%d\n", __func__
,
544 int saa7164_api_set_audio_std(struct saa7164_port
*port
)
546 struct saa7164_dev
*dev
= port
->dev
;
547 struct tmComResAudioDefaults lvl
;
548 struct tmComResTunerStandard tvaudio
;
551 dprintk(DBGLVL_API
, "%s()\n", __func__
);
553 /* Establish default levels */
554 lvl
.ucDecoderLevel
= TMHW_LEV_ADJ_DECLEV_DEFAULT
;
555 lvl
.ucDecoderFM_Level
= TMHW_LEV_ADJ_DECLEV_DEFAULT
;
556 lvl
.ucMonoLevel
= TMHW_LEV_ADJ_MONOLEV_DEFAULT
;
557 lvl
.ucNICAM_Level
= TMHW_LEV_ADJ_NICLEV_DEFAULT
;
558 lvl
.ucSAP_Level
= TMHW_LEV_ADJ_SAPLEV_DEFAULT
;
559 lvl
.ucADC_Level
= TMHW_LEV_ADJ_ADCLEV_DEFAULT
;
560 ret
= saa7164_cmd_send(port
->dev
, port
->audfeat
.unitid
, SET_CUR
,
561 AUDIO_DEFAULT_CONTROL
, sizeof(struct tmComResAudioDefaults
),
564 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
566 /* Manually select the appropriate TV audio standard */
567 if (port
->encodernorm
.id
& V4L2_STD_NTSC
) {
568 tvaudio
.std
= TU_STANDARD_NTSC_M
;
571 tvaudio
.std
= TU_STANDARD_PAL_I
;
572 tvaudio
.country
= 44;
575 ret
= saa7164_cmd_send(port
->dev
, port
->tunerunit
.unitid
, SET_CUR
,
576 TU_STANDARD_CONTROL
, sizeof(tvaudio
), &tvaudio
);
578 printk(KERN_ERR
"%s() TU_STANDARD_CONTROL error, ret = 0x%x\n",
583 int saa7164_api_set_audio_detection(struct saa7164_port
*port
, int autodetect
)
585 struct saa7164_dev
*dev
= port
->dev
;
586 struct tmComResTunerStandardAuto p
;
589 dprintk(DBGLVL_API
, "%s(%d)\n", __func__
, autodetect
);
591 /* Disable TV Audio autodetect if not already set (buggy) */
593 p
.mode
= TU_STANDARD_AUTO
;
595 p
.mode
= TU_STANDARD_MANUAL
;
596 ret
= saa7164_cmd_send(port
->dev
, port
->tunerunit
.unitid
, SET_CUR
,
597 TU_STANDARD_AUTO_CONTROL
, sizeof(p
), &p
);
600 "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n",
606 int saa7164_api_get_videomux(struct saa7164_port
*port
)
608 struct saa7164_dev
*dev
= port
->dev
;
611 ret
= saa7164_cmd_send(port
->dev
, port
->vidproc
.sourceid
, GET_CUR
,
612 SU_INPUT_SELECT_CONTROL
, sizeof(u8
), &port
->mux_input
);
614 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
616 dprintk(DBGLVL_ENC
, "%s() v_mux=%d\n",
617 __func__
, port
->mux_input
);
622 static int saa7164_api_set_dif(struct saa7164_port
*port
, u8 reg
, u8 val
)
624 struct saa7164_dev
*dev
= port
->dev
;
631 dprintk(DBGLVL_API
, "%s(nr=%d type=%d val=%x)\n", __func__
,
632 port
->nr
, port
->type
, val
);
639 memset(buf
, 0, sizeof(buf
));
661 ret
= saa7164_cmd_send(dev
, port
->ifunit
.unitid
, GET_LEN
,
662 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
664 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
668 ret
= saa7164_cmd_send(dev
, port
->ifunit
.unitid
, SET_CUR
,
669 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
671 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
673 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1, buf
, 16,
676 return ret
== SAA_OK
? 0 : -EIO
;
679 /* Disable the IF block AGC controls */
680 int saa7164_api_configure_dif(struct saa7164_port
*port
, u32 std
)
682 struct saa7164_dev
*dev
= port
->dev
;
685 dprintk(DBGLVL_API
, "%s(nr=%d, 0x%x)\n", __func__
, port
->nr
, std
);
687 if (std
& V4L2_STD_NTSC
) {
688 dprintk(DBGLVL_API
, " NTSC\n");
689 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
691 } else if (std
& V4L2_STD_PAL_I
) {
692 dprintk(DBGLVL_API
, " PAL-I\n");
693 saa7164_api_set_dif(port
, 0x00, 0x08); /* Video Standard */
695 } else if (std
& V4L2_STD_PAL_M
) {
696 dprintk(DBGLVL_API
, " PAL-M\n");
697 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
699 } else if (std
& V4L2_STD_PAL_N
) {
700 dprintk(DBGLVL_API
, " PAL-N\n");
701 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
703 } else if (std
& V4L2_STD_PAL_Nc
) {
704 dprintk(DBGLVL_API
, " PAL-Nc\n");
705 saa7164_api_set_dif(port
, 0x00, 0x01); /* Video Standard */
707 } else if (std
& V4L2_STD_PAL_B
) {
708 dprintk(DBGLVL_API
, " PAL-B\n");
709 saa7164_api_set_dif(port
, 0x00, 0x02); /* Video Standard */
711 } else if (std
& V4L2_STD_PAL_DK
) {
712 dprintk(DBGLVL_API
, " PAL-DK\n");
713 saa7164_api_set_dif(port
, 0x00, 0x10); /* Video Standard */
715 } else if (std
& V4L2_STD_SECAM_L
) {
716 dprintk(DBGLVL_API
, " SECAM-L\n");
717 saa7164_api_set_dif(port
, 0x00, 0x20); /* Video Standard */
720 /* Unknown standard, assume DTV */
721 dprintk(DBGLVL_API
, " Unknown (assuming DTV)\n");
722 /* Undefinded Video Standard */
723 saa7164_api_set_dif(port
, 0x00, 0x80);
727 saa7164_api_set_dif(port
, 0x48, 0xa0); /* AGC Functions 1 */
728 saa7164_api_set_dif(port
, 0xc0, agc_disable
); /* AGC Output Disable */
729 saa7164_api_set_dif(port
, 0x7c, 0x04); /* CVBS EQ */
730 saa7164_api_set_dif(port
, 0x04, 0x01); /* Active */
732 saa7164_api_set_dif(port
, 0x04, 0x00); /* Active (again) */
738 /* Ensure the dif is in the correct state for the operating mode
739 * (analog / dtv). We only configure the diff through the analog encoder
740 * so when we're in digital mode we need to find the appropriate encoder
741 * and use it to configure the DIF.
743 int saa7164_api_initialize_dif(struct saa7164_port
*port
)
745 struct saa7164_dev
*dev
= port
->dev
;
746 struct saa7164_port
*p
= NULL
;
750 dprintk(DBGLVL_API
, "%s(nr=%d type=%d)\n", __func__
,
751 port
->nr
, port
->type
);
753 if (port
->type
== SAA7164_MPEG_ENCODER
) {
754 /* Pick any analog standard to init the diff.
755 * we'll come back during encoder_init'
756 * and set the correct standard if requried.
760 if (port
->type
== SAA7164_MPEG_DVB
) {
761 if (port
->nr
== SAA7164_PORT_TS1
)
762 p
= &dev
->ports
[SAA7164_PORT_ENC1
];
764 p
= &dev
->ports
[SAA7164_PORT_ENC2
];
766 if (port
->type
== SAA7164_MPEG_VBI
) {
768 if (port
->nr
== SAA7164_PORT_VBI1
)
769 p
= &dev
->ports
[SAA7164_PORT_ENC1
];
771 p
= &dev
->ports
[SAA7164_PORT_ENC2
];
776 ret
= saa7164_api_configure_dif(p
, std
);
781 int saa7164_api_transition_port(struct saa7164_port
*port
, u8 mode
)
783 struct saa7164_dev
*dev
= port
->dev
;
787 dprintk(DBGLVL_API
, "%s(nr=%d unitid=0x%x,%d)\n",
788 __func__
, port
->nr
, port
->hwcfg
.unitid
, mode
);
790 ret
= saa7164_cmd_send(port
->dev
, port
->hwcfg
.unitid
, SET_CUR
,
791 SAA_STATE_CONTROL
, sizeof(mode
), &mode
);
793 printk(KERN_ERR
"%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
794 __func__
, port
->nr
, port
->hwcfg
.unitid
, ret
);
799 int saa7164_api_get_fw_version(struct saa7164_dev
*dev
, u32
*version
)
803 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
804 GET_FW_VERSION_CONTROL
, sizeof(u32
), version
);
806 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
811 int saa7164_api_read_eeprom(struct saa7164_dev
*dev
, u8
*buf
, int buflen
)
813 u8 reg
[] = { 0x0f, 0x00 };
818 /* Assumption: Hauppauge eeprom is at 0xa0 on on bus 0 */
819 /* TODO: Pull the details from the boards struct */
820 return saa7164_api_i2c_read(&dev
->i2c_bus
[0], 0xa0 >> 1, sizeof(reg
),
824 static int saa7164_api_configure_port_vbi(struct saa7164_dev
*dev
,
825 struct saa7164_port
*port
)
827 struct tmComResVBIFormatDescrHeader
*fmt
= &port
->vbi_fmt_ntsc
;
829 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", fmt
->bFormatIndex
);
830 dprintk(DBGLVL_API
, " VideoStandard = 0x%x\n", fmt
->VideoStandard
);
831 dprintk(DBGLVL_API
, " StartLine = %d\n", fmt
->StartLine
);
832 dprintk(DBGLVL_API
, " EndLine = %d\n", fmt
->EndLine
);
833 dprintk(DBGLVL_API
, " FieldRate = %d\n", fmt
->FieldRate
);
834 dprintk(DBGLVL_API
, " bNumLines = %d\n", fmt
->bNumLines
);
836 /* Cache the hardware configuration in the port */
838 port
->bufcounter
= port
->hwcfg
.BARLocation
;
839 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
840 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
841 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
842 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
844 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
845 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
847 (sizeof(u32
) * port
->hwcfg
.buffercount
);
848 port
->bufptr64
= port
->hwcfg
.BARLocation
+
850 (sizeof(u32
) * port
->hwcfg
.buffercount
);
851 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
852 port
->hwcfg
.BARLocation
);
854 dprintk(DBGLVL_API
, " = VS_FORMAT_VBI (becomes dev->en[%d])\n",
861 saa7164_api_configure_port_mpeg2ts(struct saa7164_dev
*dev
,
862 struct saa7164_port
*port
,
863 struct tmComResTSFormatDescrHeader
*tsfmt
)
865 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", tsfmt
->bFormatIndex
);
866 dprintk(DBGLVL_API
, " bDataOffset = 0x%x\n", tsfmt
->bDataOffset
);
867 dprintk(DBGLVL_API
, " bPacketLength= 0x%x\n", tsfmt
->bPacketLength
);
868 dprintk(DBGLVL_API
, " bStrideLength= 0x%x\n", tsfmt
->bStrideLength
);
869 dprintk(DBGLVL_API
, " bguid = (....)\n");
871 /* Cache the hardware configuration in the port */
873 port
->bufcounter
= port
->hwcfg
.BARLocation
;
874 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
875 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
876 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
877 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
879 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
880 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
882 (sizeof(u32
) * port
->hwcfg
.buffercount
);
883 port
->bufptr64
= port
->hwcfg
.BARLocation
+
885 (sizeof(u32
) * port
->hwcfg
.buffercount
);
886 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
887 port
->hwcfg
.BARLocation
);
889 dprintk(DBGLVL_API
, " = VS_FORMAT_MPEGTS (becomes dev->ts[%d])\n",
896 saa7164_api_configure_port_mpeg2ps(struct saa7164_dev
*dev
,
897 struct saa7164_port
*port
,
898 struct tmComResPSFormatDescrHeader
*fmt
)
900 dprintk(DBGLVL_API
, " bFormatIndex = 0x%x\n", fmt
->bFormatIndex
);
901 dprintk(DBGLVL_API
, " wPacketLength= 0x%x\n", fmt
->wPacketLength
);
902 dprintk(DBGLVL_API
, " wPackLength= 0x%x\n", fmt
->wPackLength
);
903 dprintk(DBGLVL_API
, " bPackDataType= 0x%x\n", fmt
->bPackDataType
);
905 /* Cache the hardware configuration in the port */
906 /* TODO: CHECK THIS in the port config */
907 port
->bufcounter
= port
->hwcfg
.BARLocation
;
908 port
->pitch
= port
->hwcfg
.BARLocation
+ (2 * sizeof(u32
));
909 port
->bufsize
= port
->hwcfg
.BARLocation
+ (3 * sizeof(u32
));
910 port
->bufoffset
= port
->hwcfg
.BARLocation
+ (4 * sizeof(u32
));
911 port
->bufptr32l
= port
->hwcfg
.BARLocation
+
913 (sizeof(u32
) * port
->hwcfg
.buffercount
) + sizeof(u32
);
914 port
->bufptr32h
= port
->hwcfg
.BARLocation
+
916 (sizeof(u32
) * port
->hwcfg
.buffercount
);
917 port
->bufptr64
= port
->hwcfg
.BARLocation
+
919 (sizeof(u32
) * port
->hwcfg
.buffercount
);
920 dprintk(DBGLVL_API
, " = port->hwcfg.BARLocation = 0x%x\n",
921 port
->hwcfg
.BARLocation
);
923 dprintk(DBGLVL_API
, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
929 static int saa7164_api_dump_subdevs(struct saa7164_dev
*dev
, u8
*buf
, int len
)
931 struct saa7164_port
*tsport
= NULL
;
932 struct saa7164_port
*encport
= NULL
;
933 struct saa7164_port
*vbiport
= NULL
;
934 u32 idx
, next_offset
;
936 struct tmComResDescrHeader
*hdr
, *t
;
937 struct tmComResExtDevDescrHeader
*exthdr
;
938 struct tmComResPathDescrHeader
*pathhdr
;
939 struct tmComResAntTermDescrHeader
*anttermhdr
;
940 struct tmComResTunerDescrHeader
*tunerunithdr
;
941 struct tmComResDMATermDescrHeader
*vcoutputtermhdr
;
942 struct tmComResTSFormatDescrHeader
*tsfmt
;
943 struct tmComResPSFormatDescrHeader
*psfmt
;
944 struct tmComResSelDescrHeader
*psel
;
945 struct tmComResProcDescrHeader
*pdh
;
946 struct tmComResAFeatureDescrHeader
*afd
;
947 struct tmComResEncoderDescrHeader
*edh
;
948 struct tmComResVBIFormatDescrHeader
*vbifmt
;
952 "%s(?,?,%d) sizeof(struct tmComResDescrHeader) = %d bytes\n",
953 __func__
, len
, (u32
)sizeof(struct tmComResDescrHeader
));
955 for (idx
= 0; idx
< (len
- sizeof(struct tmComResDescrHeader
));) {
957 hdr
= (struct tmComResDescrHeader
*)(buf
+ idx
);
959 if (hdr
->type
!= CS_INTERFACE
)
960 return SAA_ERR_NOT_SUPPORTED
;
962 dprintk(DBGLVL_API
, "@ 0x%x =\n", idx
);
963 switch (hdr
->subtype
) {
964 case GENERAL_REQUEST
:
965 dprintk(DBGLVL_API
, " GENERAL_REQUEST\n");
968 dprintk(DBGLVL_API
, " VC_TUNER_PATH\n");
969 pathhdr
= (struct tmComResPathDescrHeader
*)(buf
+ idx
);
970 dprintk(DBGLVL_API
, " pathid = 0x%x\n",
972 currpath
= pathhdr
->pathid
;
974 case VC_INPUT_TERMINAL
:
975 dprintk(DBGLVL_API
, " VC_INPUT_TERMINAL\n");
977 (struct tmComResAntTermDescrHeader
*)(buf
+ idx
);
978 dprintk(DBGLVL_API
, " terminalid = 0x%x\n",
979 anttermhdr
->terminalid
);
980 dprintk(DBGLVL_API
, " terminaltype = 0x%x\n",
981 anttermhdr
->terminaltype
);
982 switch (anttermhdr
->terminaltype
) {
984 dprintk(DBGLVL_API
, " = ITT_ANTENNA\n");
987 dprintk(DBGLVL_API
, " = LINE_CONNECTOR\n");
989 case SPDIF_CONNECTOR
:
990 dprintk(DBGLVL_API
, " = SPDIF_CONNECTOR\n");
992 case COMPOSITE_CONNECTOR
:
994 " = COMPOSITE_CONNECTOR\n");
996 case SVIDEO_CONNECTOR
:
997 dprintk(DBGLVL_API
, " = SVIDEO_CONNECTOR\n");
999 case COMPONENT_CONNECTOR
:
1001 " = COMPONENT_CONNECTOR\n");
1004 dprintk(DBGLVL_API
, " = STANDARD_DMA\n");
1007 dprintk(DBGLVL_API
, " = undefined (0x%x)\n",
1008 anttermhdr
->terminaltype
);
1010 dprintk(DBGLVL_API
, " assocterminal= 0x%x\n",
1011 anttermhdr
->assocterminal
);
1012 dprintk(DBGLVL_API
, " iterminal = 0x%x\n",
1013 anttermhdr
->iterminal
);
1014 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1015 anttermhdr
->controlsize
);
1017 case VC_OUTPUT_TERMINAL
:
1018 dprintk(DBGLVL_API
, " VC_OUTPUT_TERMINAL\n");
1020 (struct tmComResDMATermDescrHeader
*)(buf
+ idx
);
1021 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1022 vcoutputtermhdr
->unitid
);
1023 dprintk(DBGLVL_API
, " terminaltype = 0x%x\n",
1024 vcoutputtermhdr
->terminaltype
);
1025 switch (vcoutputtermhdr
->terminaltype
) {
1027 dprintk(DBGLVL_API
, " = ITT_ANTENNA\n");
1029 case LINE_CONNECTOR
:
1030 dprintk(DBGLVL_API
, " = LINE_CONNECTOR\n");
1032 case SPDIF_CONNECTOR
:
1033 dprintk(DBGLVL_API
, " = SPDIF_CONNECTOR\n");
1035 case COMPOSITE_CONNECTOR
:
1037 " = COMPOSITE_CONNECTOR\n");
1039 case SVIDEO_CONNECTOR
:
1040 dprintk(DBGLVL_API
, " = SVIDEO_CONNECTOR\n");
1042 case COMPONENT_CONNECTOR
:
1044 " = COMPONENT_CONNECTOR\n");
1047 dprintk(DBGLVL_API
, " = STANDARD_DMA\n");
1050 dprintk(DBGLVL_API
, " = undefined (0x%x)\n",
1051 vcoutputtermhdr
->terminaltype
);
1053 dprintk(DBGLVL_API
, " assocterminal= 0x%x\n",
1054 vcoutputtermhdr
->assocterminal
);
1055 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1056 vcoutputtermhdr
->sourceid
);
1057 dprintk(DBGLVL_API
, " iterminal = 0x%x\n",
1058 vcoutputtermhdr
->iterminal
);
1059 dprintk(DBGLVL_API
, " BARLocation = 0x%x\n",
1060 vcoutputtermhdr
->BARLocation
);
1061 dprintk(DBGLVL_API
, " flags = 0x%x\n",
1062 vcoutputtermhdr
->flags
);
1063 dprintk(DBGLVL_API
, " interruptid = 0x%x\n",
1064 vcoutputtermhdr
->interruptid
);
1065 dprintk(DBGLVL_API
, " buffercount = 0x%x\n",
1066 vcoutputtermhdr
->buffercount
);
1067 dprintk(DBGLVL_API
, " metadatasize = 0x%x\n",
1068 vcoutputtermhdr
->metadatasize
);
1069 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1070 vcoutputtermhdr
->controlsize
);
1071 dprintk(DBGLVL_API
, " numformats = 0x%x\n",
1072 vcoutputtermhdr
->numformats
);
1074 t
= (struct tmComResDescrHeader
*)
1075 ((struct tmComResDMATermDescrHeader
*)(buf
+ idx
));
1076 next_offset
= idx
+ (vcoutputtermhdr
->len
);
1077 for (i
= 0; i
< vcoutputtermhdr
->numformats
; i
++) {
1078 t
= (struct tmComResDescrHeader
*)
1079 (buf
+ next_offset
);
1080 switch (t
->subtype
) {
1081 case VS_FORMAT_MPEG2TS
:
1083 (struct tmComResTSFormatDescrHeader
*)t
;
1085 tsport
= &dev
->ports
[SAA7164_PORT_TS1
];
1087 tsport
= &dev
->ports
[SAA7164_PORT_TS2
];
1088 memcpy(&tsport
->hwcfg
, vcoutputtermhdr
,
1089 sizeof(*vcoutputtermhdr
));
1090 saa7164_api_configure_port_mpeg2ts(dev
,
1093 case VS_FORMAT_MPEG2PS
:
1095 (struct tmComResPSFormatDescrHeader
*)t
;
1097 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1099 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1100 memcpy(&encport
->hwcfg
, vcoutputtermhdr
,
1101 sizeof(*vcoutputtermhdr
));
1102 saa7164_api_configure_port_mpeg2ps(dev
,
1107 (struct tmComResVBIFormatDescrHeader
*)t
;
1109 vbiport
= &dev
->ports
[SAA7164_PORT_VBI1
];
1111 vbiport
= &dev
->ports
[SAA7164_PORT_VBI2
];
1112 memcpy(&vbiport
->hwcfg
, vcoutputtermhdr
,
1113 sizeof(*vcoutputtermhdr
));
1114 memcpy(&vbiport
->vbi_fmt_ntsc
, vbifmt
,
1116 saa7164_api_configure_port_vbi(dev
,
1121 " = VS_FORMAT_RDS\n");
1123 case VS_FORMAT_UNCOMPRESSED
:
1125 " = VS_FORMAT_UNCOMPRESSED\n");
1127 case VS_FORMAT_TYPE
:
1129 " = VS_FORMAT_TYPE\n");
1133 " = undefined (0x%x)\n",
1136 next_offset
+= t
->len
;
1141 dprintk(DBGLVL_API
, " TUNER_UNIT\n");
1143 (struct tmComResTunerDescrHeader
*)(buf
+ idx
);
1144 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1145 tunerunithdr
->unitid
);
1146 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1147 tunerunithdr
->sourceid
);
1148 dprintk(DBGLVL_API
, " iunit = 0x%x\n",
1149 tunerunithdr
->iunit
);
1150 dprintk(DBGLVL_API
, " tuningstandards = 0x%x\n",
1151 tunerunithdr
->tuningstandards
);
1152 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1153 tunerunithdr
->controlsize
);
1154 dprintk(DBGLVL_API
, " controls = 0x%x\n",
1155 tunerunithdr
->controls
);
1157 if (tunerunithdr
->unitid
== tunerunithdr
->iunit
) {
1159 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1161 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1162 memcpy(&encport
->tunerunit
, tunerunithdr
,
1163 sizeof(struct tmComResTunerDescrHeader
));
1165 " (becomes dev->enc[%d] tuner)\n",
1169 case VC_SELECTOR_UNIT
:
1170 psel
= (struct tmComResSelDescrHeader
*)(buf
+ idx
);
1171 dprintk(DBGLVL_API
, " VC_SELECTOR_UNIT\n");
1172 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1174 dprintk(DBGLVL_API
, " nrinpins = 0x%x\n",
1176 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1179 case VC_PROCESSING_UNIT
:
1180 pdh
= (struct tmComResProcDescrHeader
*)(buf
+ idx
);
1181 dprintk(DBGLVL_API
, " VC_PROCESSING_UNIT\n");
1182 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1184 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1186 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1188 if (pdh
->controlsize
== 0x04) {
1190 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1192 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1193 memcpy(&encport
->vidproc
, pdh
,
1194 sizeof(struct tmComResProcDescrHeader
));
1195 dprintk(DBGLVL_API
, " (becomes dev->enc[%d])\n",
1200 afd
= (struct tmComResAFeatureDescrHeader
*)(buf
+ idx
);
1201 dprintk(DBGLVL_API
, " FEATURE_UNIT\n");
1202 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1204 dprintk(DBGLVL_API
, " sourceid = 0x%x\n",
1206 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1209 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1211 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1212 memcpy(&encport
->audfeat
, afd
,
1213 sizeof(struct tmComResAFeatureDescrHeader
));
1214 dprintk(DBGLVL_API
, " (becomes dev->enc[%d])\n",
1218 edh
= (struct tmComResEncoderDescrHeader
*)(buf
+ idx
);
1219 dprintk(DBGLVL_API
, " ENCODER_UNIT\n");
1220 dprintk(DBGLVL_API
, " subtype = 0x%x\n", edh
->subtype
);
1221 dprintk(DBGLVL_API
, " unitid = 0x%x\n", edh
->unitid
);
1222 dprintk(DBGLVL_API
, " vsourceid = 0x%x\n",
1224 dprintk(DBGLVL_API
, " asourceid = 0x%x\n",
1226 dprintk(DBGLVL_API
, " iunit = 0x%x\n", edh
->iunit
);
1227 if (edh
->iunit
== edh
->unitid
) {
1229 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1231 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1232 memcpy(&encport
->encunit
, edh
,
1233 sizeof(struct tmComResEncoderDescrHeader
));
1235 " (becomes dev->enc[%d])\n",
1239 case EXTENSION_UNIT
:
1240 dprintk(DBGLVL_API
, " EXTENSION_UNIT\n");
1241 exthdr
= (struct tmComResExtDevDescrHeader
*)(buf
+ idx
);
1242 dprintk(DBGLVL_API
, " unitid = 0x%x\n",
1244 dprintk(DBGLVL_API
, " deviceid = 0x%x\n",
1246 dprintk(DBGLVL_API
, " devicetype = 0x%x\n",
1247 exthdr
->devicetype
);
1248 if (exthdr
->devicetype
& 0x1)
1249 dprintk(DBGLVL_API
, " = Decoder Device\n");
1250 if (exthdr
->devicetype
& 0x2)
1251 dprintk(DBGLVL_API
, " = GPIO Source\n");
1252 if (exthdr
->devicetype
& 0x4)
1253 dprintk(DBGLVL_API
, " = Video Decoder\n");
1254 if (exthdr
->devicetype
& 0x8)
1255 dprintk(DBGLVL_API
, " = Audio Decoder\n");
1256 if (exthdr
->devicetype
& 0x20)
1257 dprintk(DBGLVL_API
, " = Crossbar\n");
1258 if (exthdr
->devicetype
& 0x40)
1259 dprintk(DBGLVL_API
, " = Tuner\n");
1260 if (exthdr
->devicetype
& 0x80)
1261 dprintk(DBGLVL_API
, " = IF PLL\n");
1262 if (exthdr
->devicetype
& 0x100)
1263 dprintk(DBGLVL_API
, " = Demodulator\n");
1264 if (exthdr
->devicetype
& 0x200)
1265 dprintk(DBGLVL_API
, " = RDS Decoder\n");
1266 if (exthdr
->devicetype
& 0x400)
1267 dprintk(DBGLVL_API
, " = Encoder\n");
1268 if (exthdr
->devicetype
& 0x800)
1269 dprintk(DBGLVL_API
, " = IR Decoder\n");
1270 if (exthdr
->devicetype
& 0x1000)
1271 dprintk(DBGLVL_API
, " = EEPROM\n");
1272 if (exthdr
->devicetype
& 0x2000)
1274 " = VBI Decoder\n");
1275 if (exthdr
->devicetype
& 0x10000)
1277 " = Streaming Device\n");
1278 if (exthdr
->devicetype
& 0x20000)
1281 if (exthdr
->devicetype
& 0x40000000)
1283 " = Generic Device\n");
1284 if (exthdr
->devicetype
& 0x80000000)
1286 " = Config Space Device\n");
1287 dprintk(DBGLVL_API
, " numgpiopins = 0x%x\n",
1288 exthdr
->numgpiopins
);
1289 dprintk(DBGLVL_API
, " numgpiogroups = 0x%x\n",
1290 exthdr
->numgpiogroups
);
1291 dprintk(DBGLVL_API
, " controlsize = 0x%x\n",
1292 exthdr
->controlsize
);
1293 if (exthdr
->devicetype
& 0x80) {
1295 encport
= &dev
->ports
[SAA7164_PORT_ENC1
];
1297 encport
= &dev
->ports
[SAA7164_PORT_ENC2
];
1298 memcpy(&encport
->ifunit
, exthdr
,
1299 sizeof(struct tmComResExtDevDescrHeader
));
1301 " (becomes dev->enc[%d])\n",
1305 case PVC_INFRARED_UNIT
:
1306 dprintk(DBGLVL_API
, " PVC_INFRARED_UNIT\n");
1309 dprintk(DBGLVL_API
, " DRM_UNIT\n");
1312 dprintk(DBGLVL_API
, "default %d\n", hdr
->subtype
);
1315 dprintk(DBGLVL_API
, " 1.%x\n", hdr
->len
);
1316 dprintk(DBGLVL_API
, " 2.%x\n", hdr
->type
);
1317 dprintk(DBGLVL_API
, " 3.%x\n", hdr
->subtype
);
1318 dprintk(DBGLVL_API
, " 4.%x\n", hdr
->unitid
);
1326 int saa7164_api_enum_subdevs(struct saa7164_dev
*dev
)
1332 dprintk(DBGLVL_API
, "%s()\n", __func__
);
1334 /* Get the total descriptor length */
1335 ret
= saa7164_cmd_send(dev
, 0, GET_LEN
,
1336 GET_DESCRIPTORS_CONTROL
, sizeof(buflen
), &buflen
);
1338 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
1340 dprintk(DBGLVL_API
, "%s() total descriptor size = %d bytes.\n",
1343 /* Allocate enough storage for all of the descs */
1344 buf
= kzalloc(buflen
, GFP_KERNEL
);
1346 return SAA_ERR_NO_RESOURCES
;
1349 ret
= saa7164_cmd_send(dev
, 0, GET_CUR
,
1350 GET_DESCRIPTORS_CONTROL
, buflen
, buf
);
1351 if (ret
!= SAA_OK
) {
1352 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
, ret
);
1356 if (saa_debug
& DBGLVL_API
)
1357 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1, buf
,
1358 buflen
& ~15, false);
1360 saa7164_api_dump_subdevs(dev
, buf
, buflen
);
1367 int saa7164_api_i2c_read(struct saa7164_i2c
*bus
, u8 addr
, u32 reglen
, u8
*reg
,
1368 u32 datalen
, u8
*data
)
1370 struct saa7164_dev
*dev
= bus
->dev
;
1376 dprintk(DBGLVL_API
, "%s() addr=%x reglen=%d datalen=%d\n",
1377 __func__
, addr
, reglen
, datalen
);
1382 /* Prepare the send buffer */
1383 /* Bytes 00-03 source register length
1384 * 04-07 source bytes to read
1385 * 08... register address
1387 memset(buf
, 0, sizeof(buf
));
1388 memcpy((buf
+ 2 * sizeof(u32
) + 0), reg
, reglen
);
1389 *((u32
*)(buf
+ 0 * sizeof(u32
))) = reglen
;
1390 *((u32
*)(buf
+ 1 * sizeof(u32
))) = datalen
;
1392 unitid
= saa7164_i2caddr_to_unitid(bus
, addr
);
1395 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1400 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_LEN
,
1401 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
1402 if (ret
!= SAA_OK
) {
1403 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
1407 dprintk(DBGLVL_API
, "%s() len = %d bytes\n", __func__
, len
);
1409 if (saa_debug
& DBGLVL_I2C
)
1410 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1, buf
,
1413 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_CUR
,
1414 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
1416 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
1418 if (saa_debug
& DBGLVL_I2C
)
1419 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1,
1420 buf
, sizeof(buf
), false);
1421 memcpy(data
, (buf
+ 2 * sizeof(u32
) + reglen
), datalen
);
1424 return ret
== SAA_OK
? 0 : -EIO
;
1427 /* For a given 8 bit i2c address device, write the buffer */
1428 int saa7164_api_i2c_write(struct saa7164_i2c
*bus
, u8 addr
, u32 datalen
,
1431 struct saa7164_dev
*dev
= bus
->dev
;
1438 dprintk(DBGLVL_API
, "%s() addr=0x%2x len=0x%x\n",
1439 __func__
, addr
, datalen
);
1441 if ((datalen
== 0) || (datalen
> 232))
1444 memset(buf
, 0, sizeof(buf
));
1446 unitid
= saa7164_i2caddr_to_unitid(bus
, addr
);
1449 "%s() error, cannot translate regaddr 0x%x to unitid\n",
1454 reglen
= saa7164_i2caddr_to_reglen(bus
, addr
);
1457 "%s() error, cannot translate regaddr to reglen\n",
1462 ret
= saa7164_cmd_send(bus
->dev
, unitid
, GET_LEN
,
1463 EXU_REGISTER_ACCESS_CONTROL
, sizeof(len
), &len
);
1464 if (ret
!= SAA_OK
) {
1465 printk(KERN_ERR
"%s() error, ret(1) = 0x%x\n", __func__
, ret
);
1469 dprintk(DBGLVL_API
, "%s() len = %d bytes unitid=0x%x\n", __func__
,
1472 /* Prepare the send buffer */
1473 /* Bytes 00-03 dest register length
1474 * 04-07 dest bytes to write
1475 * 08... register address
1477 *((u32
*)(buf
+ 0 * sizeof(u32
))) = reglen
;
1478 *((u32
*)(buf
+ 1 * sizeof(u32
))) = datalen
- reglen
;
1479 memcpy((buf
+ 2 * sizeof(u32
)), data
, datalen
);
1481 if (saa_debug
& DBGLVL_I2C
)
1482 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_OFFSET
, 16, 1,
1483 buf
, sizeof(buf
), false);
1485 ret
= saa7164_cmd_send(bus
->dev
, unitid
, SET_CUR
,
1486 EXU_REGISTER_ACCESS_CONTROL
, len
, &buf
);
1488 printk(KERN_ERR
"%s() error, ret(2) = 0x%x\n", __func__
, ret
);
1490 return ret
== SAA_OK
? 0 : -EIO
;
1493 static int saa7164_api_modify_gpio(struct saa7164_dev
*dev
, u8 unitid
,
1497 struct tmComResGPIO t
;
1499 dprintk(DBGLVL_API
, "%s(0x%x, %d, %d)\n",
1500 __func__
, unitid
, pin
, state
);
1502 if ((pin
> 7) || (state
> 2))
1503 return SAA_ERR_BAD_PARAMETER
;
1508 ret
= saa7164_cmd_send(dev
, unitid
, SET_CUR
,
1509 EXU_GPIO_CONTROL
, sizeof(t
), &t
);
1511 printk(KERN_ERR
"%s() error, ret = 0x%x\n",
1517 int saa7164_api_set_gpiobit(struct saa7164_dev
*dev
, u8 unitid
,
1520 return saa7164_api_modify_gpio(dev
, unitid
, pin
, 1);
1523 int saa7164_api_clear_gpiobit(struct saa7164_dev
*dev
, u8 unitid
,
1526 return saa7164_api_modify_gpio(dev
, unitid
, pin
, 0);