diff options
Diffstat (limited to 'drivers/media/video/saa7164/saa7164-api.c')
-rw-r--r-- | drivers/media/video/saa7164/saa7164-api.c | 973 |
1 files changed, 935 insertions, 38 deletions
diff --git a/drivers/media/video/saa7164/saa7164-api.c b/drivers/media/video/saa7164/saa7164-api.c index 3f1262b00cc0..ad3bc4154176 100644 --- a/drivers/media/video/saa7164/saa7164-api.c +++ b/drivers/media/video/saa7164/saa7164-api.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Driver for the NXP SAA7164 PCIe bridge | 2 | * Driver for the NXP SAA7164 PCIe bridge |
3 | * | 3 | * |
4 | * Copyright (c) 2009 Steven Toth <stoth@kernellabs.com> | 4 | * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 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 | 7 | * it under the terms of the GNU General Public License as published by |
@@ -24,14 +24,750 @@ | |||
24 | 24 | ||
25 | #include "saa7164.h" | 25 | #include "saa7164.h" |
26 | 26 | ||
27 | int saa7164_api_transition_port(struct saa7164_tsport *port, u8 mode) | 27 | int saa7164_api_get_load_info(struct saa7164_dev *dev, struct tmFwInfoStruct *i) |
28 | { | 28 | { |
29 | int ret; | 29 | int ret; |
30 | 30 | ||
31 | if (!(saa_debug & DBGLVL_CPU)) | ||
32 | return 0; | ||
33 | |||
34 | dprintk(DBGLVL_API, "%s()\n", __func__); | ||
35 | |||
36 | i->deviceinst = 0; | ||
37 | i->devicespec = 0; | ||
38 | i->mode = 0; | ||
39 | i->status = 0; | ||
40 | |||
41 | ret = saa7164_cmd_send(dev, 0, GET_CUR, | ||
42 | GET_FW_STATUS_CONTROL, sizeof(struct tmFwInfoStruct), i); | ||
43 | if (ret != SAA_OK) { | ||
44 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
45 | } | ||
46 | |||
47 | printk(KERN_INFO "saa7164[%d]-CPU: %d percent", dev->nr, i->CPULoad); | ||
48 | |||
49 | return ret; | ||
50 | } | ||
51 | |||
52 | int saa7164_api_collect_debug(struct saa7164_dev *dev) | ||
53 | { | ||
54 | struct tmComResDebugGetData d; | ||
55 | u8 more = 255; | ||
56 | int ret; | ||
57 | |||
58 | dprintk(DBGLVL_API, "%s()\n", __func__); | ||
59 | |||
60 | while (more--) { | ||
61 | |||
62 | memset(&d, 0, sizeof(d)); | ||
63 | |||
64 | ret = saa7164_cmd_send(dev, 0, GET_CUR, | ||
65 | GET_DEBUG_DATA_CONTROL, sizeof(d), &d); | ||
66 | if (ret != SAA_OK) { | ||
67 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
68 | } | ||
69 | |||
70 | if (d.dwResult != SAA_OK) | ||
71 | break; | ||
72 | |||
73 | printk(KERN_INFO "saa7164[%d]-FWMSG: %s", dev->nr, d.ucDebugData); | ||
74 | } | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level) | ||
80 | { | ||
81 | struct tmComResDebugSetLevel lvl; | ||
82 | int ret; | ||
83 | |||
84 | dprintk(DBGLVL_API, "%s(level=%d)\n", __func__, level); | ||
85 | |||
86 | /* Retrieve current state */ | ||
87 | ret = saa7164_cmd_send(dev, 0, GET_CUR, | ||
88 | SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl); | ||
89 | if (ret != SAA_OK) { | ||
90 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
91 | } | ||
92 | dprintk(DBGLVL_API, "%s() Was %d\n", __func__, lvl.dwDebugLevel); | ||
93 | |||
94 | lvl.dwDebugLevel = level; | ||
95 | |||
96 | /* set new state */ | ||
97 | ret = saa7164_cmd_send(dev, 0, SET_CUR, | ||
98 | SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl); | ||
99 | if (ret != SAA_OK) { | ||
100 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
101 | } | ||
102 | |||
103 | return ret; | ||
104 | } | ||
105 | |||
106 | int saa7164_api_set_vbi_format(struct saa7164_port *port) | ||
107 | { | ||
108 | struct saa7164_dev *dev = port->dev; | ||
109 | struct tmComResProbeCommit fmt, rsp; | ||
110 | int ret; | ||
111 | |||
112 | dprintk(DBGLVL_API, "%s(nr=%d, unitid=0x%x)\n", __func__, | ||
113 | port->nr, port->hwcfg.unitid); | ||
114 | |||
115 | fmt.bmHint = 0; | ||
116 | fmt.bFormatIndex = 1; | ||
117 | fmt.bFrameIndex = 1; | ||
118 | |||
119 | /* Probe, see if it can support this format */ | ||
120 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, | ||
121 | SET_CUR, SAA_PROBE_CONTROL, sizeof(fmt), &fmt); | ||
122 | if (ret != SAA_OK) | ||
123 | printk(KERN_ERR "%s() set error, ret = 0x%x\n", __func__, ret); | ||
124 | |||
125 | /* See of the format change was successful */ | ||
126 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, | ||
127 | GET_CUR, SAA_PROBE_CONTROL, sizeof(rsp), &rsp); | ||
128 | if (ret != SAA_OK) { | ||
129 | printk(KERN_ERR "%s() get error, ret = 0x%x\n", __func__, ret); | ||
130 | } else { | ||
131 | /* Compare requested vs received, should be same */ | ||
132 | if (memcmp(&fmt, &rsp, sizeof(rsp)) == 0) { | ||
133 | dprintk(DBGLVL_API, "SET/PROBE Verified\n"); | ||
134 | |||
135 | /* Ask the device to select the negotiated format */ | ||
136 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, | ||
137 | SET_CUR, SAA_COMMIT_CONTROL, sizeof(fmt), &fmt); | ||
138 | if (ret != SAA_OK) | ||
139 | printk(KERN_ERR "%s() commit error, ret = 0x%x\n", | ||
140 | __func__, ret); | ||
141 | |||
142 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, | ||
143 | GET_CUR, SAA_COMMIT_CONTROL, sizeof(rsp), &rsp); | ||
144 | if (ret != SAA_OK) | ||
145 | printk(KERN_ERR "%s() GET commit error, ret = 0x%x\n", | ||
146 | __func__, ret); | ||
147 | |||
148 | if (memcmp(&fmt, &rsp, sizeof(rsp)) != 0) { | ||
149 | printk(KERN_ERR "%s() memcmp error, ret = 0x%x\n", | ||
150 | __func__, ret); | ||
151 | } else | ||
152 | dprintk(DBGLVL_API, "SET/COMMIT Verified\n"); | ||
153 | |||
154 | dprintk(DBGLVL_API, "rsp.bmHint = 0x%x\n", rsp.bmHint); | ||
155 | dprintk(DBGLVL_API, "rsp.bFormatIndex = 0x%x\n", rsp.bFormatIndex); | ||
156 | dprintk(DBGLVL_API, "rsp.bFrameIndex = 0x%x\n", rsp.bFrameIndex); | ||
157 | } else | ||
158 | printk(KERN_ERR "%s() compare failed\n", __func__); | ||
159 | } | ||
160 | |||
161 | if (ret == SAA_OK) | ||
162 | dprintk(DBGLVL_API, "%s(nr=%d) Success\n", __func__, port->nr); | ||
163 | |||
164 | return ret; | ||
165 | } | ||
166 | |||
167 | int saa7164_api_set_gop_size(struct saa7164_port *port) | ||
168 | { | ||
169 | struct saa7164_dev *dev = port->dev; | ||
170 | struct tmComResEncVideoGopStructure gs; | ||
171 | int ret; | ||
172 | |||
173 | dprintk(DBGLVL_ENC, "%s()\n", __func__); | ||
174 | |||
175 | gs.ucRefFrameDist = port->encoder_params.refdist; | ||
176 | gs.ucGOPSize = port->encoder_params.gop_size; | ||
177 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, | ||
178 | EU_VIDEO_GOP_STRUCTURE_CONTROL, | ||
179 | sizeof(gs), &gs); | ||
180 | if (ret != SAA_OK) | ||
181 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
182 | |||
183 | return ret; | ||
184 | } | ||
185 | |||
186 | int saa7164_api_set_encoder(struct saa7164_port *port) | ||
187 | { | ||
188 | struct saa7164_dev *dev = port->dev; | ||
189 | struct tmComResEncVideoBitRate vb; | ||
190 | struct tmComResEncAudioBitRate ab; | ||
191 | int ret; | ||
192 | |||
193 | dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, | ||
194 | port->hwcfg.sourceid); | ||
195 | |||
196 | if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS) | ||
197 | port->encoder_profile = EU_PROFILE_PS_DVD; | ||
198 | else | ||
199 | port->encoder_profile = EU_PROFILE_TS_HQ; | ||
200 | |||
201 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, | ||
202 | EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile); | ||
203 | if (ret != SAA_OK) | ||
204 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
205 | |||
206 | /* Resolution */ | ||
207 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, | ||
208 | EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile); | ||
209 | if (ret != SAA_OK) | ||
210 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
211 | |||
212 | /* Establish video bitrates */ | ||
213 | if (port->encoder_params.bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) | ||
214 | vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_CONSTANT; | ||
215 | else | ||
216 | vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK; | ||
217 | vb.dwVideoBitRate = port->encoder_params.bitrate; | ||
218 | vb.dwVideoBitRatePeak = port->encoder_params.bitrate_peak; | ||
219 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, | ||
220 | EU_VIDEO_BIT_RATE_CONTROL, sizeof(struct tmComResEncVideoBitRate), &vb); | ||
221 | if (ret != SAA_OK) | ||
222 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
223 | |||
224 | /* Establish audio bitrates */ | ||
225 | ab.ucAudioBitRateMode = 0; | ||
226 | ab.dwAudioBitRate = 384000; | ||
227 | ab.dwAudioBitRatePeak = ab.dwAudioBitRate; | ||
228 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, | ||
229 | EU_AUDIO_BIT_RATE_CONTROL, sizeof(struct tmComResEncAudioBitRate), &ab); | ||
230 | if (ret != SAA_OK) | ||
231 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
232 | |||
233 | saa7164_api_set_aspect_ratio(port); | ||
234 | saa7164_api_set_gop_size(port); | ||
235 | |||
236 | return ret; | ||
237 | } | ||
238 | |||
239 | int saa7164_api_get_encoder(struct saa7164_port *port) | ||
240 | { | ||
241 | struct saa7164_dev *dev = port->dev; | ||
242 | struct tmComResEncVideoBitRate v; | ||
243 | struct tmComResEncAudioBitRate a; | ||
244 | struct tmComResEncVideoInputAspectRatio ar; | ||
245 | int ret; | ||
246 | |||
247 | dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, port->hwcfg.sourceid); | ||
248 | |||
249 | port->encoder_profile = 0; | ||
250 | port->video_format = 0; | ||
251 | port->video_resolution = 0; | ||
252 | port->audio_format = 0; | ||
253 | |||
254 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, | ||
255 | EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile); | ||
256 | if (ret != SAA_OK) | ||
257 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
258 | |||
259 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, | ||
260 | EU_VIDEO_RESOLUTION_CONTROL, sizeof(u8), &port->video_resolution); | ||
261 | if (ret != SAA_OK) | ||
262 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
263 | |||
264 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, | ||
265 | EU_VIDEO_FORMAT_CONTROL, sizeof(u8), &port->video_format); | ||
266 | if (ret != SAA_OK) | ||
267 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
268 | |||
269 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, | ||
270 | EU_VIDEO_BIT_RATE_CONTROL, sizeof(v), &v); | ||
271 | if (ret != SAA_OK) | ||
272 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
273 | |||
274 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, | ||
275 | EU_AUDIO_FORMAT_CONTROL, sizeof(u8), &port->audio_format); | ||
276 | if (ret != SAA_OK) | ||
277 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
278 | |||
279 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, | ||
280 | EU_AUDIO_BIT_RATE_CONTROL, sizeof(a), &a); | ||
281 | if (ret != SAA_OK) | ||
282 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
283 | |||
284 | /* Aspect Ratio */ | ||
285 | ar.width = 0; | ||
286 | ar.height = 0; | ||
287 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, | ||
288 | EU_VIDEO_INPUT_ASPECT_CONTROL, | ||
289 | sizeof(struct tmComResEncVideoInputAspectRatio), &ar); | ||
290 | if (ret != SAA_OK) | ||
291 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
292 | |||
293 | dprintk(DBGLVL_ENC, "encoder_profile = %d\n", port->encoder_profile); | ||
294 | dprintk(DBGLVL_ENC, "video_format = %d\n", port->video_format); | ||
295 | dprintk(DBGLVL_ENC, "audio_format = %d\n", port->audio_format); | ||
296 | dprintk(DBGLVL_ENC, "video_resolution= %d\n", port->video_resolution); | ||
297 | dprintk(DBGLVL_ENC, "v.ucVideoBitRateMode = %d\n", v.ucVideoBitRateMode); | ||
298 | dprintk(DBGLVL_ENC, "v.dwVideoBitRate = %d\n", v.dwVideoBitRate); | ||
299 | dprintk(DBGLVL_ENC, "v.dwVideoBitRatePeak = %d\n", v.dwVideoBitRatePeak); | ||
300 | dprintk(DBGLVL_ENC, "a.ucVideoBitRateMode = %d\n", a.ucAudioBitRateMode); | ||
301 | dprintk(DBGLVL_ENC, "a.dwVideoBitRate = %d\n", a.dwAudioBitRate); | ||
302 | dprintk(DBGLVL_ENC, "a.dwVideoBitRatePeak = %d\n", a.dwAudioBitRatePeak); | ||
303 | dprintk(DBGLVL_ENC, "aspect.width / height = %d:%d\n", ar.width, ar.height); | ||
304 | |||
305 | return ret; | ||
306 | } | ||
307 | |||
308 | int saa7164_api_set_aspect_ratio(struct saa7164_port *port) | ||
309 | { | ||
310 | struct saa7164_dev *dev = port->dev; | ||
311 | struct tmComResEncVideoInputAspectRatio ar; | ||
312 | int ret; | ||
313 | |||
314 | dprintk(DBGLVL_ENC, "%s(%d)\n", __func__, | ||
315 | port->encoder_params.ctl_aspect); | ||
316 | |||
317 | switch (port->encoder_params.ctl_aspect) { | ||
318 | case V4L2_MPEG_VIDEO_ASPECT_1x1: | ||
319 | ar.width = 1; | ||
320 | ar.height = 1; | ||
321 | break; | ||
322 | case V4L2_MPEG_VIDEO_ASPECT_4x3: | ||
323 | ar.width = 4; | ||
324 | ar.height = 3; | ||
325 | break; | ||
326 | case V4L2_MPEG_VIDEO_ASPECT_16x9: | ||
327 | ar.width = 16; | ||
328 | ar.height = 9; | ||
329 | break; | ||
330 | case V4L2_MPEG_VIDEO_ASPECT_221x100: | ||
331 | ar.width = 221; | ||
332 | ar.height = 100; | ||
333 | break; | ||
334 | default: | ||
335 | BUG(); | ||
336 | } | ||
337 | |||
338 | dprintk(DBGLVL_ENC, "%s(%d) now %d:%d\n", __func__, | ||
339 | port->encoder_params.ctl_aspect, | ||
340 | ar.width, ar.height); | ||
341 | |||
342 | /* Aspect Ratio */ | ||
343 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, | ||
344 | EU_VIDEO_INPUT_ASPECT_CONTROL, | ||
345 | sizeof(struct tmComResEncVideoInputAspectRatio), &ar); | ||
346 | if (ret != SAA_OK) | ||
347 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
348 | |||
349 | return ret; | ||
350 | } | ||
351 | |||
352 | int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl) | ||
353 | { | ||
354 | struct saa7164_dev *dev = port->dev; | ||
355 | int ret; | ||
356 | u16 val; | ||
357 | |||
358 | if (ctl == PU_BRIGHTNESS_CONTROL) | ||
359 | val = port->ctl_brightness; | ||
360 | else | ||
361 | if (ctl == PU_CONTRAST_CONTROL) | ||
362 | val = port->ctl_contrast; | ||
363 | else | ||
364 | if (ctl == PU_HUE_CONTROL) | ||
365 | val = port->ctl_hue; | ||
366 | else | ||
367 | if (ctl == PU_SATURATION_CONTROL) | ||
368 | val = port->ctl_saturation; | ||
369 | else | ||
370 | if (ctl == PU_SHARPNESS_CONTROL) | ||
371 | val = port->ctl_sharpness; | ||
372 | else | ||
373 | return -EINVAL; | ||
374 | |||
375 | dprintk(DBGLVL_ENC, "%s() unitid=0x%x ctl=%d, val=%d\n", | ||
376 | __func__, port->encunit.vsourceid, ctl, val); | ||
377 | |||
378 | ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, SET_CUR, | ||
379 | ctl, sizeof(u16), &val); | ||
380 | if (ret != SAA_OK) | ||
381 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
382 | |||
383 | return ret; | ||
384 | } | ||
385 | |||
386 | int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl) | ||
387 | { | ||
388 | struct saa7164_dev *dev = port->dev; | ||
389 | int ret; | ||
390 | u16 val; | ||
391 | |||
392 | ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, GET_CUR, | ||
393 | ctl, sizeof(u16), &val); | ||
394 | if (ret != SAA_OK) { | ||
395 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
396 | return ret; | ||
397 | } | ||
398 | |||
399 | dprintk(DBGLVL_ENC, "%s() ctl=%d, val=%d\n", | ||
400 | __func__, ctl, val); | ||
401 | |||
402 | if (ctl == PU_BRIGHTNESS_CONTROL) | ||
403 | port->ctl_brightness = val; | ||
404 | else | ||
405 | if (ctl == PU_CONTRAST_CONTROL) | ||
406 | port->ctl_contrast = val; | ||
407 | else | ||
408 | if (ctl == PU_HUE_CONTROL) | ||
409 | port->ctl_hue = val; | ||
410 | else | ||
411 | if (ctl == PU_SATURATION_CONTROL) | ||
412 | port->ctl_saturation = val; | ||
413 | else | ||
414 | if (ctl == PU_SHARPNESS_CONTROL) | ||
415 | port->ctl_sharpness = val; | ||
416 | |||
417 | return ret; | ||
418 | } | ||
419 | |||
420 | int saa7164_api_set_videomux(struct saa7164_port *port) | ||
421 | { | ||
422 | struct saa7164_dev *dev = port->dev; | ||
423 | u8 inputs[] = { 1, 2, 2, 2, 5, 5, 5 }; | ||
424 | int ret; | ||
425 | |||
426 | dprintk(DBGLVL_ENC, "%s() v_mux=%d a_mux=%d\n", | ||
427 | __func__, port->mux_input, inputs[port->mux_input - 1]); | ||
428 | |||
429 | /* Audio Mute */ | ||
430 | ret = saa7164_api_audio_mute(port, 1); | ||
431 | if (ret != SAA_OK) | ||
432 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
433 | |||
434 | /* Video Mux */ | ||
435 | ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, SET_CUR, | ||
436 | SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input); | ||
437 | if (ret != SAA_OK) | ||
438 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
439 | |||
440 | /* Audio Mux */ | ||
441 | ret = saa7164_cmd_send(port->dev, port->audfeat.sourceid, SET_CUR, | ||
442 | SU_INPUT_SELECT_CONTROL, sizeof(u8), &inputs[port->mux_input - 1]); | ||
443 | if (ret != SAA_OK) | ||
444 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
445 | |||
446 | /* Audio UnMute */ | ||
447 | ret = saa7164_api_audio_mute(port, 0); | ||
448 | if (ret != SAA_OK) | ||
449 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
450 | |||
451 | return ret; | ||
452 | } | ||
453 | |||
454 | int saa7164_api_audio_mute(struct saa7164_port *port, int mute) | ||
455 | { | ||
456 | struct saa7164_dev *dev = port->dev; | ||
457 | u8 v = mute; | ||
458 | int ret; | ||
459 | |||
460 | dprintk(DBGLVL_API, "%s(%d)\n", __func__, mute); | ||
461 | |||
462 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, | ||
463 | MUTE_CONTROL, sizeof(u8), &v); | ||
464 | if (ret != SAA_OK) | ||
465 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
466 | |||
467 | return ret; | ||
468 | } | ||
469 | |||
470 | /* 0 = silence, 0xff = full */ | ||
471 | int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level) | ||
472 | { | ||
473 | struct saa7164_dev *dev = port->dev; | ||
474 | s16 v, min, max; | ||
475 | int ret; | ||
476 | |||
477 | dprintk(DBGLVL_API, "%s(%d)\n", __func__, level); | ||
478 | |||
479 | /* Obtain the min/max ranges */ | ||
480 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MIN, | ||
481 | VOLUME_CONTROL, sizeof(u16), &min); | ||
482 | if (ret != SAA_OK) | ||
483 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
484 | |||
485 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MAX, | ||
486 | VOLUME_CONTROL, sizeof(u16), &max); | ||
487 | if (ret != SAA_OK) | ||
488 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
489 | |||
490 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR, | ||
491 | (0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v); | ||
492 | if (ret != SAA_OK) | ||
493 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
494 | |||
495 | dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v); | ||
496 | |||
497 | v = level; | ||
498 | if (v < min) | ||
499 | v = min; | ||
500 | if (v > max) | ||
501 | v = max; | ||
502 | |||
503 | /* Left */ | ||
504 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, | ||
505 | (0x01 << 8) | VOLUME_CONTROL, sizeof(s16), &v); | ||
506 | if (ret != SAA_OK) | ||
507 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
508 | |||
509 | /* Right */ | ||
510 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, | ||
511 | (0x02 << 8) | VOLUME_CONTROL, sizeof(s16), &v); | ||
512 | if (ret != SAA_OK) | ||
513 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
514 | |||
515 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR, | ||
516 | (0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v); | ||
517 | if (ret != SAA_OK) | ||
518 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
519 | |||
520 | dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v); | ||
521 | |||
522 | return ret; | ||
523 | } | ||
524 | |||
525 | int saa7164_api_set_audio_std(struct saa7164_port *port) | ||
526 | { | ||
527 | struct saa7164_dev *dev = port->dev; | ||
528 | struct tmComResAudioDefaults lvl; | ||
529 | struct tmComResTunerStandard tvaudio; | ||
530 | int ret; | ||
531 | |||
532 | dprintk(DBGLVL_API, "%s()\n", __func__); | ||
533 | |||
534 | /* Establish default levels */ | ||
535 | lvl.ucDecoderLevel = TMHW_LEV_ADJ_DECLEV_DEFAULT; | ||
536 | lvl.ucDecoderFM_Level = TMHW_LEV_ADJ_DECLEV_DEFAULT; | ||
537 | lvl.ucMonoLevel = TMHW_LEV_ADJ_MONOLEV_DEFAULT; | ||
538 | lvl.ucNICAM_Level = TMHW_LEV_ADJ_NICLEV_DEFAULT; | ||
539 | lvl.ucSAP_Level = TMHW_LEV_ADJ_SAPLEV_DEFAULT; | ||
540 | lvl.ucADC_Level = TMHW_LEV_ADJ_ADCLEV_DEFAULT; | ||
541 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, | ||
542 | AUDIO_DEFAULT_CONTROL, sizeof(struct tmComResAudioDefaults), &lvl); | ||
543 | if (ret != SAA_OK) | ||
544 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
545 | |||
546 | /* Manually select the appropriate TV audio standard */ | ||
547 | if (port->encodernorm.id & V4L2_STD_NTSC) { | ||
548 | tvaudio.std = TU_STANDARD_NTSC_M; | ||
549 | tvaudio.country = 1; | ||
550 | } else { | ||
551 | tvaudio.std = TU_STANDARD_PAL_I; | ||
552 | tvaudio.country = 44; | ||
553 | } | ||
554 | |||
555 | ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR, | ||
556 | TU_STANDARD_CONTROL, sizeof(tvaudio), &tvaudio); | ||
557 | if (ret != SAA_OK) | ||
558 | printk(KERN_ERR "%s() TU_STANDARD_CONTROL error, ret = 0x%x\n", __func__, ret); | ||
559 | return ret; | ||
560 | } | ||
561 | |||
562 | int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect) | ||
563 | { | ||
564 | struct saa7164_dev *dev = port->dev; | ||
565 | struct tmComResTunerStandardAuto p; | ||
566 | int ret; | ||
567 | |||
568 | dprintk(DBGLVL_API, "%s(%d)\n", __func__, autodetect); | ||
569 | |||
570 | /* Disable TV Audio autodetect if not already set (buggy) */ | ||
571 | if (autodetect) | ||
572 | p.mode = TU_STANDARD_AUTO; | ||
573 | else | ||
574 | p.mode = TU_STANDARD_MANUAL; | ||
575 | ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR, | ||
576 | TU_STANDARD_AUTO_CONTROL, sizeof(p), &p); | ||
577 | if (ret != SAA_OK) | ||
578 | printk(KERN_ERR "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n", __func__, ret); | ||
579 | |||
580 | return ret; | ||
581 | } | ||
582 | |||
583 | int saa7164_api_get_videomux(struct saa7164_port *port) | ||
584 | { | ||
585 | struct saa7164_dev *dev = port->dev; | ||
586 | int ret; | ||
587 | |||
588 | ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, GET_CUR, | ||
589 | SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input); | ||
590 | if (ret != SAA_OK) | ||
591 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | ||
592 | |||
593 | dprintk(DBGLVL_ENC, "%s() v_mux=%d\n", | ||
594 | __func__, port->mux_input); | ||
595 | |||
596 | return ret; | ||
597 | } | ||
598 | |||
599 | int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val) | ||
600 | { | ||
601 | struct saa7164_dev *dev = port->dev; | ||
602 | |||
603 | u16 len = 0; | ||
604 | u8 buf[256]; | ||
605 | int ret; | ||
606 | u8 mas; | ||
607 | |||
608 | dprintk(DBGLVL_API, "%s(nr=%d type=%d val=%x)\n", __func__, | ||
609 | port->nr, port->type, val); | ||
610 | |||
611 | if (port->nr == 0) | ||
612 | mas = 0xd0; | ||
613 | else | ||
614 | mas = 0xe0; | ||
615 | |||
616 | memset(buf, 0, sizeof(buf)); | ||
617 | |||
618 | buf[0x00] = 0x04; | ||
619 | buf[0x01] = 0x00; | ||
620 | buf[0x02] = 0x00; | ||
621 | buf[0x03] = 0x00; | ||
622 | |||
623 | buf[0x04] = 0x04; | ||
624 | buf[0x05] = 0x00; | ||
625 | buf[0x06] = 0x00; | ||
626 | buf[0x07] = 0x00; | ||
627 | |||
628 | buf[0x08] = reg; | ||
629 | buf[0x09] = 0x26; | ||
630 | buf[0x0a] = mas; | ||
631 | buf[0x0b] = 0xb0; | ||
632 | |||
633 | buf[0x0c] = val; | ||
634 | buf[0x0d] = 0x00; | ||
635 | buf[0x0e] = 0x00; | ||
636 | buf[0x0f] = 0x00; | ||
637 | |||
638 | ret = saa7164_cmd_send(dev, port->ifunit.unitid, GET_LEN, | ||
639 | EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len); | ||
640 | if (ret != SAA_OK) { | ||
641 | printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret); | ||
642 | return -EIO; | ||
643 | } | ||
644 | |||
645 | ret = saa7164_cmd_send(dev, port->ifunit.unitid, SET_CUR, | ||
646 | EXU_REGISTER_ACCESS_CONTROL, len, &buf); | ||
647 | if (ret != SAA_OK) | ||
648 | printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret); | ||
649 | |||
650 | //saa7164_dumphex16(dev, buf, 16); | ||
651 | |||
652 | return ret == SAA_OK ? 0 : -EIO; | ||
653 | } | ||
654 | |||
655 | /* Disable the IF block AGC controls */ | ||
656 | int saa7164_api_configure_dif(struct saa7164_port *port, u32 std) | ||
657 | { | ||
658 | struct saa7164_dev *dev = port->dev; | ||
659 | int ret = 0; | ||
660 | u8 agc_disable; | ||
661 | |||
662 | dprintk(DBGLVL_API, "%s(nr=%d, 0x%x)\n", __func__, port->nr, std); | ||
663 | |||
664 | if (std & V4L2_STD_NTSC) { | ||
665 | dprintk(DBGLVL_API, " NTSC\n"); | ||
666 | saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */ | ||
667 | agc_disable = 0; | ||
668 | } else if (std & V4L2_STD_PAL_I) { | ||
669 | dprintk(DBGLVL_API, " PAL-I\n"); | ||
670 | saa7164_api_set_dif(port, 0x00, 0x08); /* Video Standard */ | ||
671 | agc_disable = 0; | ||
672 | } else if (std & V4L2_STD_PAL_M) { | ||
673 | dprintk(DBGLVL_API, " PAL-M\n"); | ||
674 | saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */ | ||
675 | agc_disable = 0; | ||
676 | } else if (std & V4L2_STD_PAL_N) { | ||
677 | dprintk(DBGLVL_API, " PAL-N\n"); | ||
678 | saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */ | ||
679 | agc_disable = 0; | ||
680 | } else if (std & V4L2_STD_PAL_Nc) { | ||
681 | dprintk(DBGLVL_API, " PAL-Nc\n"); | ||
682 | saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */ | ||
683 | agc_disable = 0; | ||
684 | } else if (std & V4L2_STD_PAL_B) { | ||
685 | dprintk(DBGLVL_API, " PAL-B\n"); | ||
686 | saa7164_api_set_dif(port, 0x00, 0x02); /* Video Standard */ | ||
687 | agc_disable = 0; | ||
688 | } else if (std & V4L2_STD_PAL_DK) { | ||
689 | dprintk(DBGLVL_API, " PAL-DK\n"); | ||
690 | saa7164_api_set_dif(port, 0x00, 0x10); /* Video Standard */ | ||
691 | agc_disable = 0; | ||
692 | } else if (std & V4L2_STD_SECAM_L) { | ||
693 | dprintk(DBGLVL_API, " SECAM-L\n"); | ||
694 | saa7164_api_set_dif(port, 0x00, 0x20); /* Video Standard */ | ||
695 | agc_disable = 0; | ||
696 | } else { | ||
697 | /* Unknown standard, assume DTV */ | ||
698 | dprintk(DBGLVL_API, " Unknown (assuming DTV)\n"); | ||
699 | saa7164_api_set_dif(port, 0x00, 0x80); /* Undefined Video Standard */ | ||
700 | agc_disable = 1; | ||
701 | } | ||
702 | |||
703 | saa7164_api_set_dif(port, 0x48, 0xa0); /* AGC Functions 1 */ | ||
704 | saa7164_api_set_dif(port, 0xc0, agc_disable); /* AGC Output Disable */ | ||
705 | saa7164_api_set_dif(port, 0x7c, 0x04); /* CVBS EQ */ | ||
706 | saa7164_api_set_dif(port, 0x04, 0x01); /* Active */ | ||
707 | msleep(100); | ||
708 | saa7164_api_set_dif(port, 0x04, 0x00); /* Active (again) */ | ||
709 | msleep(100); | ||
710 | |||
711 | return ret; | ||
712 | } | ||
713 | |||
714 | /* Ensure the dif is in the correct state for the operating mode | ||
715 | * (analog / dtv). We only configure the diff through the analog encoder | ||
716 | * so when we're in digital mode we need to find the appropriate encoder | ||
717 | * and use it to configure the DIF. | ||
718 | */ | ||
719 | int saa7164_api_initialize_dif(struct saa7164_port *port) | ||
720 | { | ||
721 | struct saa7164_dev *dev = port->dev; | ||
722 | struct saa7164_port *p = 0; | ||
723 | int ret = -EINVAL; | ||
724 | u32 std = 0; | ||
725 | |||
726 | dprintk(DBGLVL_API, "%s(nr=%d type=%d)\n", __func__, | ||
727 | port->nr, port->type); | ||
728 | |||
729 | if (port->type == SAA7164_MPEG_ENCODER) { | ||
730 | /* Pick any analog standard to init the diff. | ||
731 | * we'll come back during encoder_init' | ||
732 | * and set the correct standard if requried. | ||
733 | */ | ||
734 | std = V4L2_STD_NTSC; | ||
735 | } else | ||
736 | if (port->type == SAA7164_MPEG_DVB) { | ||
737 | if (port->nr == SAA7164_PORT_TS1) | ||
738 | p = &dev->ports[SAA7164_PORT_ENC1]; | ||
739 | else | ||
740 | p = &dev->ports[SAA7164_PORT_ENC2]; | ||
741 | } else | ||
742 | if (port->type == SAA7164_MPEG_VBI) { | ||
743 | std = V4L2_STD_NTSC; | ||
744 | if (port->nr == SAA7164_PORT_VBI1) | ||
745 | p = &dev->ports[SAA7164_PORT_ENC1]; | ||
746 | else | ||
747 | p = &dev->ports[SAA7164_PORT_ENC2]; | ||
748 | } else | ||
749 | BUG(); | ||
750 | |||
751 | if (p) | ||
752 | ret = saa7164_api_configure_dif(p, std); | ||
753 | |||
754 | return ret; | ||
755 | } | ||
756 | |||
757 | int saa7164_api_transition_port(struct saa7164_port *port, u8 mode) | ||
758 | { | ||
759 | struct saa7164_dev *dev = port->dev; | ||
760 | |||
761 | int ret; | ||
762 | |||
763 | dprintk(DBGLVL_API, "%s(nr=%d unitid=0x%x,%d)\n", | ||
764 | __func__, port->nr, port->hwcfg.unitid, mode); | ||
765 | |||
31 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR, | 766 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR, |
32 | SAA_STATE_CONTROL, sizeof(mode), &mode); | 767 | SAA_STATE_CONTROL, sizeof(mode), &mode); |
33 | if (ret != SAA_OK) | 768 | if (ret != SAA_OK) |
34 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); | 769 | printk(KERN_ERR "%s(portnr %d unitid 0x%x) error, ret = 0x%x\n", |
770 | __func__, port->nr, port->hwcfg.unitid, ret); | ||
35 | 771 | ||
36 | return ret; | 772 | return ret; |
37 | } | 773 | } |
@@ -61,10 +797,45 @@ int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen) | |||
61 | ®[0], 128, buf); | 797 | ®[0], 128, buf); |
62 | } | 798 | } |
63 | 799 | ||
800 | int saa7164_api_configure_port_vbi(struct saa7164_dev *dev, | ||
801 | struct saa7164_port *port) | ||
802 | { | ||
803 | struct tmComResVBIFormatDescrHeader *fmt = &port->vbi_fmt_ntsc; | ||
804 | |||
805 | dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex); | ||
806 | dprintk(DBGLVL_API, " VideoStandard = 0x%x\n", fmt->VideoStandard); | ||
807 | dprintk(DBGLVL_API, " StartLine = %d\n", fmt->StartLine); | ||
808 | dprintk(DBGLVL_API, " EndLine = %d\n", fmt->EndLine); | ||
809 | dprintk(DBGLVL_API, " FieldRate = %d\n", fmt->FieldRate); | ||
810 | dprintk(DBGLVL_API, " bNumLines = %d\n", fmt->bNumLines); | ||
811 | |||
812 | /* Cache the hardware configuration in the port */ | ||
813 | |||
814 | port->bufcounter = port->hwcfg.BARLocation; | ||
815 | port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32)); | ||
816 | port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32)); | ||
817 | port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32)); | ||
818 | port->bufptr32l = port->hwcfg.BARLocation + | ||
819 | (4 * sizeof(u32)) + | ||
820 | (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32); | ||
821 | port->bufptr32h = port->hwcfg.BARLocation + | ||
822 | (4 * sizeof(u32)) + | ||
823 | (sizeof(u32) * port->hwcfg.buffercount); | ||
824 | port->bufptr64 = port->hwcfg.BARLocation + | ||
825 | (4 * sizeof(u32)) + | ||
826 | (sizeof(u32) * port->hwcfg.buffercount); | ||
827 | dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n", | ||
828 | port->hwcfg.BARLocation); | ||
829 | |||
830 | dprintk(DBGLVL_API, " = VS_FORMAT_VBI (becomes dev->en[%d])\n", | ||
831 | port->nr); | ||
832 | |||
833 | return 0; | ||
834 | } | ||
64 | 835 | ||
65 | int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev, | 836 | int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev, |
66 | struct saa7164_tsport *port, | 837 | struct saa7164_port *port, |
67 | tmComResTSFormatDescrHeader_t *tsfmt) | 838 | struct tmComResTSFormatDescrHeader *tsfmt) |
68 | { | 839 | { |
69 | dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", tsfmt->bFormatIndex); | 840 | dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", tsfmt->bFormatIndex); |
70 | dprintk(DBGLVL_API, " bDataOffset = 0x%x\n", tsfmt->bDataOffset); | 841 | dprintk(DBGLVL_API, " bDataOffset = 0x%x\n", tsfmt->bDataOffset); |
@@ -96,27 +867,68 @@ int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev, | |||
96 | return 0; | 867 | return 0; |
97 | } | 868 | } |
98 | 869 | ||
870 | int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev *dev, | ||
871 | struct saa7164_port *port, | ||
872 | struct tmComResPSFormatDescrHeader *fmt) | ||
873 | { | ||
874 | dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex); | ||
875 | dprintk(DBGLVL_API, " wPacketLength= 0x%x\n", fmt->wPacketLength); | ||
876 | dprintk(DBGLVL_API, " wPackLength= 0x%x\n", fmt->wPackLength); | ||
877 | dprintk(DBGLVL_API, " bPackDataType= 0x%x\n", fmt->bPackDataType); | ||
878 | |||
879 | /* Cache the hardware configuration in the port */ | ||
880 | /* TODO: CHECK THIS in the port config */ | ||
881 | port->bufcounter = port->hwcfg.BARLocation; | ||
882 | port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32)); | ||
883 | port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32)); | ||
884 | port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32)); | ||
885 | port->bufptr32l = port->hwcfg.BARLocation + | ||
886 | (4 * sizeof(u32)) + | ||
887 | (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32); | ||
888 | port->bufptr32h = port->hwcfg.BARLocation + | ||
889 | (4 * sizeof(u32)) + | ||
890 | (sizeof(u32) * port->hwcfg.buffercount); | ||
891 | port->bufptr64 = port->hwcfg.BARLocation + | ||
892 | (4 * sizeof(u32)) + | ||
893 | (sizeof(u32) * port->hwcfg.buffercount); | ||
894 | dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n", | ||
895 | port->hwcfg.BARLocation); | ||
896 | |||
897 | dprintk(DBGLVL_API, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n", | ||
898 | port->nr); | ||
899 | |||
900 | return 0; | ||
901 | } | ||
902 | |||
99 | int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) | 903 | int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) |
100 | { | 904 | { |
101 | struct saa7164_tsport *port = 0; | 905 | struct saa7164_port *tsport = 0; |
906 | struct saa7164_port *encport = 0; | ||
907 | struct saa7164_port *vbiport = 0; | ||
102 | u32 idx, next_offset; | 908 | u32 idx, next_offset; |
103 | int i; | 909 | int i; |
104 | tmComResDescrHeader_t *hdr, *t; | 910 | struct tmComResDescrHeader *hdr, *t; |
105 | tmComResExtDevDescrHeader_t *exthdr; | 911 | struct tmComResExtDevDescrHeader *exthdr; |
106 | tmComResPathDescrHeader_t *pathhdr; | 912 | struct tmComResPathDescrHeader *pathhdr; |
107 | tmComResAntTermDescrHeader_t *anttermhdr; | 913 | struct tmComResAntTermDescrHeader *anttermhdr; |
108 | tmComResTunerDescrHeader_t *tunerunithdr; | 914 | struct tmComResTunerDescrHeader *tunerunithdr; |
109 | tmComResDMATermDescrHeader_t *vcoutputtermhdr; | 915 | struct tmComResDMATermDescrHeader *vcoutputtermhdr; |
110 | tmComResTSFormatDescrHeader_t *tsfmt; | 916 | struct tmComResTSFormatDescrHeader *tsfmt; |
917 | struct tmComResPSFormatDescrHeader *psfmt; | ||
918 | struct tmComResSelDescrHeader *psel; | ||
919 | struct tmComResProcDescrHeader *pdh; | ||
920 | struct tmComResAFeatureDescrHeader *afd; | ||
921 | struct tmComResEncoderDescrHeader *edh; | ||
922 | struct tmComResVBIFormatDescrHeader *vbifmt; | ||
111 | u32 currpath = 0; | 923 | u32 currpath = 0; |
112 | 924 | ||
113 | dprintk(DBGLVL_API, | 925 | dprintk(DBGLVL_API, |
114 | "%s(?,?,%d) sizeof(tmComResDescrHeader_t) = %d bytes\n", | 926 | "%s(?,?,%d) sizeof(struct tmComResDescrHeader) = %d bytes\n", |
115 | __func__, len, (u32)sizeof(tmComResDescrHeader_t)); | 927 | __func__, len, (u32)sizeof(struct tmComResDescrHeader)); |
116 | 928 | ||
117 | for (idx = 0; idx < (len - sizeof(tmComResDescrHeader_t)); ) { | 929 | for (idx = 0; idx < (len - sizeof(struct tmComResDescrHeader));) { |
118 | 930 | ||
119 | hdr = (tmComResDescrHeader_t *)(buf + idx); | 931 | hdr = (struct tmComResDescrHeader *)(buf + idx); |
120 | 932 | ||
121 | if (hdr->type != CS_INTERFACE) | 933 | if (hdr->type != CS_INTERFACE) |
122 | return SAA_ERR_NOT_SUPPORTED; | 934 | return SAA_ERR_NOT_SUPPORTED; |
@@ -128,7 +940,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) | |||
128 | break; | 940 | break; |
129 | case VC_TUNER_PATH: | 941 | case VC_TUNER_PATH: |
130 | dprintk(DBGLVL_API, " VC_TUNER_PATH\n"); | 942 | dprintk(DBGLVL_API, " VC_TUNER_PATH\n"); |
131 | pathhdr = (tmComResPathDescrHeader_t *)(buf + idx); | 943 | pathhdr = (struct tmComResPathDescrHeader *)(buf + idx); |
132 | dprintk(DBGLVL_API, " pathid = 0x%x\n", | 944 | dprintk(DBGLVL_API, " pathid = 0x%x\n", |
133 | pathhdr->pathid); | 945 | pathhdr->pathid); |
134 | currpath = pathhdr->pathid; | 946 | currpath = pathhdr->pathid; |
@@ -136,7 +948,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) | |||
136 | case VC_INPUT_TERMINAL: | 948 | case VC_INPUT_TERMINAL: |
137 | dprintk(DBGLVL_API, " VC_INPUT_TERMINAL\n"); | 949 | dprintk(DBGLVL_API, " VC_INPUT_TERMINAL\n"); |
138 | anttermhdr = | 950 | anttermhdr = |
139 | (tmComResAntTermDescrHeader_t *)(buf + idx); | 951 | (struct tmComResAntTermDescrHeader *)(buf + idx); |
140 | dprintk(DBGLVL_API, " terminalid = 0x%x\n", | 952 | dprintk(DBGLVL_API, " terminalid = 0x%x\n", |
141 | anttermhdr->terminalid); | 953 | anttermhdr->terminalid); |
142 | dprintk(DBGLVL_API, " terminaltype = 0x%x\n", | 954 | dprintk(DBGLVL_API, " terminaltype = 0x%x\n", |
@@ -179,7 +991,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) | |||
179 | case VC_OUTPUT_TERMINAL: | 991 | case VC_OUTPUT_TERMINAL: |
180 | dprintk(DBGLVL_API, " VC_OUTPUT_TERMINAL\n"); | 992 | dprintk(DBGLVL_API, " VC_OUTPUT_TERMINAL\n"); |
181 | vcoutputtermhdr = | 993 | vcoutputtermhdr = |
182 | (tmComResDMATermDescrHeader_t *)(buf + idx); | 994 | (struct tmComResDMATermDescrHeader *)(buf + idx); |
183 | dprintk(DBGLVL_API, " unitid = 0x%x\n", | 995 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
184 | vcoutputtermhdr->unitid); | 996 | vcoutputtermhdr->unitid); |
185 | dprintk(DBGLVL_API, " terminaltype = 0x%x\n", | 997 | dprintk(DBGLVL_API, " terminaltype = 0x%x\n", |
@@ -233,32 +1045,49 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) | |||
233 | dprintk(DBGLVL_API, " numformats = 0x%x\n", | 1045 | dprintk(DBGLVL_API, " numformats = 0x%x\n", |
234 | vcoutputtermhdr->numformats); | 1046 | vcoutputtermhdr->numformats); |
235 | 1047 | ||
236 | t = (tmComResDescrHeader_t *) | 1048 | t = (struct tmComResDescrHeader *) |
237 | ((tmComResDMATermDescrHeader_t *)(buf + idx)); | 1049 | ((struct tmComResDMATermDescrHeader *)(buf + idx)); |
238 | next_offset = idx + (vcoutputtermhdr->len); | 1050 | next_offset = idx + (vcoutputtermhdr->len); |
239 | for (i = 0; i < vcoutputtermhdr->numformats; i++) { | 1051 | for (i = 0; i < vcoutputtermhdr->numformats; i++) { |
240 | t = (tmComResDescrHeader_t *) | 1052 | t = (struct tmComResDescrHeader *) |
241 | (buf + next_offset); | 1053 | (buf + next_offset); |
242 | switch (t->subtype) { | 1054 | switch (t->subtype) { |
243 | case VS_FORMAT_MPEG2TS: | 1055 | case VS_FORMAT_MPEG2TS: |
244 | tsfmt = | 1056 | tsfmt = |
245 | (tmComResTSFormatDescrHeader_t *)t; | 1057 | (struct tmComResTSFormatDescrHeader *)t; |
246 | if (currpath == 1) | 1058 | if (currpath == 1) |
247 | port = &dev->ts1; | 1059 | tsport = &dev->ports[SAA7164_PORT_TS1]; |
248 | else | 1060 | else |
249 | port = &dev->ts2; | 1061 | tsport = &dev->ports[SAA7164_PORT_TS2]; |
250 | memcpy(&port->hwcfg, vcoutputtermhdr, | 1062 | memcpy(&tsport->hwcfg, vcoutputtermhdr, |
251 | sizeof(*vcoutputtermhdr)); | 1063 | sizeof(*vcoutputtermhdr)); |
252 | saa7164_api_configure_port_mpeg2ts(dev, | 1064 | saa7164_api_configure_port_mpeg2ts(dev, |
253 | port, tsfmt); | 1065 | tsport, tsfmt); |
254 | break; | 1066 | break; |
255 | case VS_FORMAT_MPEG2PS: | 1067 | case VS_FORMAT_MPEG2PS: |
256 | dprintk(DBGLVL_API, | 1068 | psfmt = |
257 | " = VS_FORMAT_MPEG2PS\n"); | 1069 | (struct tmComResPSFormatDescrHeader *)t; |
1070 | if (currpath == 1) | ||
1071 | encport = &dev->ports[SAA7164_PORT_ENC1]; | ||
1072 | else | ||
1073 | encport = &dev->ports[SAA7164_PORT_ENC2]; | ||
1074 | memcpy(&encport->hwcfg, vcoutputtermhdr, | ||
1075 | sizeof(*vcoutputtermhdr)); | ||
1076 | saa7164_api_configure_port_mpeg2ps(dev, | ||
1077 | encport, psfmt); | ||
258 | break; | 1078 | break; |
259 | case VS_FORMAT_VBI: | 1079 | case VS_FORMAT_VBI: |
260 | dprintk(DBGLVL_API, | 1080 | vbifmt = |
261 | " = VS_FORMAT_VBI\n"); | 1081 | (struct tmComResVBIFormatDescrHeader *)t; |
1082 | if (currpath == 1) | ||
1083 | vbiport = &dev->ports[SAA7164_PORT_VBI1]; | ||
1084 | else | ||
1085 | vbiport = &dev->ports[SAA7164_PORT_VBI2]; | ||
1086 | memcpy(&vbiport->hwcfg, vcoutputtermhdr, | ||
1087 | sizeof(*vcoutputtermhdr)); | ||
1088 | memcpy(&vbiport->vbi_fmt_ntsc, vbifmt, sizeof(*vbifmt)); | ||
1089 | saa7164_api_configure_port_vbi(dev, | ||
1090 | vbiport); | ||
262 | break; | 1091 | break; |
263 | case VS_FORMAT_RDS: | 1092 | case VS_FORMAT_RDS: |
264 | dprintk(DBGLVL_API, | 1093 | dprintk(DBGLVL_API, |
@@ -284,7 +1113,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) | |||
284 | case TUNER_UNIT: | 1113 | case TUNER_UNIT: |
285 | dprintk(DBGLVL_API, " TUNER_UNIT\n"); | 1114 | dprintk(DBGLVL_API, " TUNER_UNIT\n"); |
286 | tunerunithdr = | 1115 | tunerunithdr = |
287 | (tmComResTunerDescrHeader_t *)(buf + idx); | 1116 | (struct tmComResTunerDescrHeader *)(buf + idx); |
288 | dprintk(DBGLVL_API, " unitid = 0x%x\n", | 1117 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
289 | tunerunithdr->unitid); | 1118 | tunerunithdr->unitid); |
290 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", | 1119 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", |
@@ -297,22 +1126,84 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) | |||
297 | tunerunithdr->controlsize); | 1126 | tunerunithdr->controlsize); |
298 | dprintk(DBGLVL_API, " controls = 0x%x\n", | 1127 | dprintk(DBGLVL_API, " controls = 0x%x\n", |
299 | tunerunithdr->controls); | 1128 | tunerunithdr->controls); |
1129 | |||
1130 | if (tunerunithdr->unitid == tunerunithdr->iunit) { | ||
1131 | if (currpath == 1) | ||
1132 | encport = &dev->ports[SAA7164_PORT_ENC1]; | ||
1133 | else | ||
1134 | encport = &dev->ports[SAA7164_PORT_ENC2]; | ||
1135 | memcpy(&encport->tunerunit, tunerunithdr, | ||
1136 | sizeof(struct tmComResTunerDescrHeader)); | ||
1137 | dprintk(DBGLVL_API, " (becomes dev->enc[%d] tuner)\n", encport->nr); | ||
1138 | } | ||
300 | break; | 1139 | break; |
301 | case VC_SELECTOR_UNIT: | 1140 | case VC_SELECTOR_UNIT: |
1141 | psel = (struct tmComResSelDescrHeader *)(buf + idx); | ||
302 | dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n"); | 1142 | dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n"); |
1143 | dprintk(DBGLVL_API, " unitid = 0x%x\n", | ||
1144 | psel->unitid); | ||
1145 | dprintk(DBGLVL_API, " nrinpins = 0x%x\n", | ||
1146 | psel->nrinpins); | ||
1147 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", | ||
1148 | psel->sourceid); | ||
303 | break; | 1149 | break; |
304 | case VC_PROCESSING_UNIT: | 1150 | case VC_PROCESSING_UNIT: |
1151 | pdh = (struct tmComResProcDescrHeader *)(buf + idx); | ||
305 | dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n"); | 1152 | dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n"); |
1153 | dprintk(DBGLVL_API, " unitid = 0x%x\n", | ||
1154 | pdh->unitid); | ||
1155 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", | ||
1156 | pdh->sourceid); | ||
1157 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", | ||
1158 | pdh->controlsize); | ||
1159 | if (pdh->controlsize == 0x04) { | ||
1160 | if (currpath == 1) | ||
1161 | encport = &dev->ports[SAA7164_PORT_ENC1]; | ||
1162 | else | ||
1163 | encport = &dev->ports[SAA7164_PORT_ENC2]; | ||
1164 | memcpy(&encport->vidproc, pdh, | ||
1165 | sizeof(struct tmComResProcDescrHeader)); | ||
1166 | dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); | ||
1167 | } | ||
306 | break; | 1168 | break; |
307 | case FEATURE_UNIT: | 1169 | case FEATURE_UNIT: |
1170 | afd = (struct tmComResAFeatureDescrHeader *)(buf + idx); | ||
308 | dprintk(DBGLVL_API, " FEATURE_UNIT\n"); | 1171 | dprintk(DBGLVL_API, " FEATURE_UNIT\n"); |
1172 | dprintk(DBGLVL_API, " unitid = 0x%x\n", | ||
1173 | afd->unitid); | ||
1174 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", | ||
1175 | afd->sourceid); | ||
1176 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", | ||
1177 | afd->controlsize); | ||
1178 | if (currpath == 1) | ||
1179 | encport = &dev->ports[SAA7164_PORT_ENC1]; | ||
1180 | else | ||
1181 | encport = &dev->ports[SAA7164_PORT_ENC2]; | ||
1182 | memcpy(&encport->audfeat, afd, | ||
1183 | sizeof(struct tmComResAFeatureDescrHeader)); | ||
1184 | dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); | ||
309 | break; | 1185 | break; |
310 | case ENCODER_UNIT: | 1186 | case ENCODER_UNIT: |
1187 | edh = (struct tmComResEncoderDescrHeader *)(buf + idx); | ||
311 | dprintk(DBGLVL_API, " ENCODER_UNIT\n"); | 1188 | dprintk(DBGLVL_API, " ENCODER_UNIT\n"); |
1189 | dprintk(DBGLVL_API, " subtype = 0x%x\n", edh->subtype); | ||
1190 | dprintk(DBGLVL_API, " unitid = 0x%x\n", edh->unitid); | ||
1191 | dprintk(DBGLVL_API, " vsourceid = 0x%x\n", edh->vsourceid); | ||
1192 | dprintk(DBGLVL_API, " asourceid = 0x%x\n", edh->asourceid); | ||
1193 | dprintk(DBGLVL_API, " iunit = 0x%x\n", edh->iunit); | ||
1194 | if (edh->iunit == edh->unitid) { | ||
1195 | if (currpath == 1) | ||
1196 | encport = &dev->ports[SAA7164_PORT_ENC1]; | ||
1197 | else | ||
1198 | encport = &dev->ports[SAA7164_PORT_ENC2]; | ||
1199 | memcpy(&encport->encunit, edh, | ||
1200 | sizeof(struct tmComResEncoderDescrHeader)); | ||
1201 | dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); | ||
1202 | } | ||
312 | break; | 1203 | break; |
313 | case EXTENSION_UNIT: | 1204 | case EXTENSION_UNIT: |
314 | dprintk(DBGLVL_API, " EXTENSION_UNIT\n"); | 1205 | dprintk(DBGLVL_API, " EXTENSION_UNIT\n"); |
315 | exthdr = (tmComResExtDevDescrHeader_t *)(buf + idx); | 1206 | exthdr = (struct tmComResExtDevDescrHeader *)(buf + idx); |
316 | dprintk(DBGLVL_API, " unitid = 0x%x\n", | 1207 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
317 | exthdr->unitid); | 1208 | exthdr->unitid); |
318 | dprintk(DBGLVL_API, " deviceid = 0x%x\n", | 1209 | dprintk(DBGLVL_API, " deviceid = 0x%x\n", |
@@ -364,6 +1255,15 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) | |||
364 | exthdr->numgpiogroups); | 1255 | exthdr->numgpiogroups); |
365 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", | 1256 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", |
366 | exthdr->controlsize); | 1257 | exthdr->controlsize); |
1258 | if (exthdr->devicetype & 0x80) { | ||
1259 | if (currpath == 1) | ||
1260 | encport = &dev->ports[SAA7164_PORT_ENC1]; | ||
1261 | else | ||
1262 | encport = &dev->ports[SAA7164_PORT_ENC2]; | ||
1263 | memcpy(&encport->ifunit, exthdr, | ||
1264 | sizeof(struct tmComResExtDevDescrHeader)); | ||
1265 | dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); | ||
1266 | } | ||
367 | break; | 1267 | break; |
368 | case PVC_INFRARED_UNIT: | 1268 | case PVC_INFRARED_UNIT: |
369 | dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n"); | 1269 | dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n"); |
@@ -560,12 +1460,11 @@ int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, u32 datalen, | |||
560 | return ret == SAA_OK ? 0 : -EIO; | 1460 | return ret == SAA_OK ? 0 : -EIO; |
561 | } | 1461 | } |
562 | 1462 | ||
563 | |||
564 | int saa7164_api_modify_gpio(struct saa7164_dev *dev, u8 unitid, | 1463 | int saa7164_api_modify_gpio(struct saa7164_dev *dev, u8 unitid, |
565 | u8 pin, u8 state) | 1464 | u8 pin, u8 state) |
566 | { | 1465 | { |
567 | int ret; | 1466 | int ret; |
568 | tmComResGPIO_t t; | 1467 | struct tmComResGPIO t; |
569 | 1468 | ||
570 | dprintk(DBGLVL_API, "%s(0x%x, %d, %d)\n", | 1469 | dprintk(DBGLVL_API, "%s(0x%x, %d, %d)\n", |
571 | __func__, unitid, pin, state); | 1470 | __func__, unitid, pin, state); |
@@ -597,5 +1496,3 @@ int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, | |||
597 | return saa7164_api_modify_gpio(dev, unitid, pin, 0); | 1496 | return saa7164_api_modify_gpio(dev, unitid, pin, 0); |
598 | } | 1497 | } |
599 | 1498 | ||
600 | |||
601 | |||