2 * cx18 ADEC audio functions
4 * Derived from cx25840-core.c
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "cx18-driver.h"
27 int cx18_av_write(struct cx18 *cx, u16 addr, u8 value)
29 u32 reg = 0xc40000 + (addr & ~3);
31 int shift = (addr & 3) * 8;
32 u32 x = cx18_read_reg(cx, reg);
34 x = (x & ~(mask << shift)) | ((u32)value << shift);
35 cx18_write_reg(cx, x, reg);
39 int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value)
41 cx18_write_reg(cx, value, 0xc40000 + addr);
45 int cx18_av_write4_noretry(struct cx18 *cx, u16 addr, u32 value)
47 cx18_write_reg_noretry(cx, value, 0xc40000 + addr);
51 u8 cx18_av_read(struct cx18 *cx, u16 addr)
53 u32 x = cx18_read_reg(cx, 0xc40000 + (addr & ~3));
54 int shift = (addr & 3) * 8;
56 return (x >> shift) & 0xff;
59 u32 cx18_av_read4(struct cx18 *cx, u16 addr)
61 return cx18_read_reg(cx, 0xc40000 + addr);
64 u32 cx18_av_read4_noretry(struct cx18 *cx, u16 addr)
66 return cx18_read_reg_noretry(cx, 0xc40000 + addr);
69 int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned and_mask,
72 return cx18_av_write(cx, addr,
73 (cx18_av_read(cx, addr) & and_mask) |
77 int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 and_mask,
80 return cx18_av_write4(cx, addr,
81 (cx18_av_read4(cx, addr) & and_mask) |
85 /* ----------------------------------------------------------------------- */
87 static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
88 enum cx18_av_audio_input aud_input);
89 static void log_audio_status(struct cx18 *cx);
90 static void log_video_status(struct cx18 *cx);
92 /* ----------------------------------------------------------------------- */
94 static void cx18_av_initialize(struct cx18 *cx)
96 struct cx18_av_state *state = &cx->av_state;
100 /* Stop 8051 code execution */
101 cx18_av_write4(cx, CXADEC_DL_CTL, 0x03000000);
103 /* initallize the PLL by toggling sleep bit */
104 v = cx18_av_read4(cx, CXADEC_HOST_REG1);
105 /* enable sleep mode */
106 cx18_av_write4(cx, CXADEC_HOST_REG1, v | 1);
107 /* disable sleep mode */
108 cx18_av_write4(cx, CXADEC_HOST_REG1, v & 0xfffe);
110 /* initialize DLLs */
111 v = cx18_av_read4(cx, CXADEC_DLL1_DIAG_CTRL) & 0xE1FFFEFF;
113 cx18_av_write4(cx, CXADEC_DLL1_DIAG_CTRL, v);
115 cx18_av_write4(cx, CXADEC_DLL1_DIAG_CTRL, v | 0x10000100);
117 v = cx18_av_read4(cx, CXADEC_DLL2_DIAG_CTRL) & 0xE1FFFEFF;
119 cx18_av_write4(cx, CXADEC_DLL2_DIAG_CTRL, v);
121 cx18_av_write4(cx, CXADEC_DLL2_DIAG_CTRL, v | 0x06000100);
123 /* set analog bias currents. Set Vreg to 1.20V. */
124 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL1, 0x000A1802);
126 v = cx18_av_read4(cx, CXADEC_AFE_DIAG_CTRL3) | 1;
127 /* enable TUNE_FIL_RST */
128 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL3, v);
129 /* disable TUNE_FIL_RST */
130 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL3, v & 0xFFFFFFFE);
132 /* enable 656 output */
133 cx18_av_and_or4(cx, CXADEC_PIN_CTRL1, ~0, 0x040C00);
135 /* video output drive strength */
136 cx18_av_and_or4(cx, CXADEC_PIN_CTRL2, ~0, 0x2);
139 cx18_av_write4(cx, CXADEC_SOFT_RST_CTRL, 0x8000);
140 cx18_av_write4(cx, CXADEC_SOFT_RST_CTRL, 0);
142 /* set video to auto-detect */
143 /* Clear bits 11-12 to enable slow locking mode. Set autodetect mode */
144 /* set the comb notch = 1 */
145 cx18_av_and_or4(cx, CXADEC_MODE_CTRL, 0xFFF7E7F0, 0x02040800);
147 /* Enable wtw_en in CRUSH_CTRL (Set bit 22) */
148 /* Enable maj_sel in CRUSH_CTRL (Set bit 20) */
149 cx18_av_and_or4(cx, CXADEC_CRUSH_CTRL, ~0, 0x00500000);
151 /* Set VGA_TRACK_RANGE to 0x20 */
152 cx18_av_and_or4(cx, CXADEC_DFE_CTRL2, 0xFFFF00FF, 0x00002000);
154 /* Enable VBI capture */
155 cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010253F);
156 /* cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010253E); */
158 /* Set the video input.
159 The setting in MODE_CTRL gets lost when we do the above setup */
160 /* EncSetSignalStd(dwDevNum, pEnc->dwSigStd); */
161 /* EncSetVideoInput(dwDevNum, pEnc->VidIndSelection); */
163 v = cx18_av_read4(cx, CXADEC_AFE_CTRL);
164 v &= 0xFFFBFFFF; /* turn OFF bit 18 for droop_comp_ch1 */
165 v &= 0xFFFF7FFF; /* turn OFF bit 9 for clamp_sel_ch1 */
166 v &= 0xFFFFFFFE; /* turn OFF bit 0 for 12db_ch1 */
167 /* v |= 0x00000001;*/ /* turn ON bit 0 for 12db_ch1 */
168 cx18_av_write4(cx, CXADEC_AFE_CTRL, v);
170 /* if(dwEnable && dw3DCombAvailable) { */
171 /* CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x7728021F); */
173 /* CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x6628021F); */
175 cx18_av_write4(cx, CXADEC_SRC_COMB_CFG, 0x6628021F);
176 state->default_volume = 228 - cx18_av_read(cx, 0x8d4);
177 state->default_volume = ((state->default_volume / 2) + 23) << 9;
180 /* ----------------------------------------------------------------------- */
182 void cx18_av_std_setup(struct cx18 *cx)
184 struct cx18_av_state *state = &cx->av_state;
185 v4l2_std_id std = state->std;
186 int hblank, hactive, burst, vblank, vactive, sc;
187 int vblank656, src_decimation;
188 int luma_lpf, uv_lpf, comb;
189 u32 pll_int, pll_frac, pll_post;
191 /* datasheet startup, step 8d */
192 if (std & ~V4L2_STD_NTSC)
193 cx18_av_write(cx, 0x49f, 0x11);
195 cx18_av_write(cx, 0x49f, 0x14);
197 if (std & V4L2_STD_625_50) {
204 src_decimation = 0x21f;
207 if (std & V4L2_STD_PAL) {
211 } else if (std == V4L2_STD_PAL_Nc) {
229 src_decimation = 0x21f;
230 if (std == V4L2_STD_PAL_60) {
235 } else if (std == V4L2_STD_PAL_M) {
246 /* DEBUG: Displays configured PLL frequency */
247 pll_int = cx18_av_read(cx, 0x108);
248 pll_frac = cx18_av_read4(cx, 0x10c) & 0x1ffffff;
249 pll_post = cx18_av_read(cx, 0x109);
250 CX18_DEBUG_INFO("PLL regs = int: %u, frac: %u, post: %u\n",
251 pll_int, pll_frac, pll_post);
255 int pll = 28636363L * ((((u64)pll_int) << 25) + pll_frac);
259 CX18_DEBUG_INFO("PLL = %d.%06d MHz\n",
260 pll / 1000000, pll % 1000000);
261 CX18_DEBUG_INFO("PLL/8 = %d.%06d MHz\n",
262 pll / 8000000, (pll / 8) % 1000000);
264 fin = ((u64)src_decimation * pll) >> 12;
265 CX18_DEBUG_INFO("ADC Sampling freq = %d.%06d MHz\n",
266 fin / 1000000, fin % 1000000);
268 fsc = (((u64)sc) * pll) >> 24L;
269 CX18_DEBUG_INFO("Chroma sub-carrier freq = %d.%06d MHz\n",
270 fsc / 1000000, fsc % 1000000);
272 CX18_DEBUG_INFO("hblank %i, hactive %i, "
273 "vblank %i , vactive %i, vblank656 %i, src_dec %i,"
274 "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x,"
276 hblank, hactive, vblank, vactive, vblank656,
277 src_decimation, burst, luma_lpf, uv_lpf, comb, sc);
280 /* Sets horizontal blanking delay and active lines */
281 cx18_av_write(cx, 0x470, hblank);
282 cx18_av_write(cx, 0x471, 0xff & (((hblank >> 8) & 0x3) |
284 cx18_av_write(cx, 0x472, hactive >> 4);
286 /* Sets burst gate delay */
287 cx18_av_write(cx, 0x473, burst);
289 /* Sets vertical blanking delay and active duration */
290 cx18_av_write(cx, 0x474, vblank);
291 cx18_av_write(cx, 0x475, 0xff & (((vblank >> 8) & 0x3) |
293 cx18_av_write(cx, 0x476, vactive >> 4);
294 cx18_av_write(cx, 0x477, vblank656);
296 /* Sets src decimation rate */
297 cx18_av_write(cx, 0x478, 0xff & src_decimation);
298 cx18_av_write(cx, 0x479, 0xff & (src_decimation >> 8));
300 /* Sets Luma and UV Low pass filters */
301 cx18_av_write(cx, 0x47a, luma_lpf << 6 | ((uv_lpf << 4) & 0x30));
303 /* Enables comb filters */
304 cx18_av_write(cx, 0x47b, comb);
307 cx18_av_write(cx, 0x47c, sc);
308 cx18_av_write(cx, 0x47d, 0xff & sc >> 8);
309 cx18_av_write(cx, 0x47e, 0xff & sc >> 16);
311 /* Sets VBI parameters */
312 if (std & V4L2_STD_625_50) {
313 cx18_av_write(cx, 0x47f, 0x01);
314 state->vbi_line_offset = 5;
316 cx18_av_write(cx, 0x47f, 0x00);
317 state->vbi_line_offset = 8;
321 /* ----------------------------------------------------------------------- */
323 static void input_change(struct cx18 *cx)
325 struct cx18_av_state *state = &cx->av_state;
326 v4l2_std_id std = state->std;
328 /* Follow step 8c and 8d of section 3.16 in the cx18_av datasheet */
329 cx18_av_write(cx, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
330 cx18_av_and_or(cx, 0x401, ~0x60, 0);
331 cx18_av_and_or(cx, 0x401, ~0x60, 0x60);
333 if (std & V4L2_STD_525_60) {
334 if (std == V4L2_STD_NTSC_M_JP) {
335 /* Japan uses EIAJ audio standard */
336 cx18_av_write(cx, 0x808, 0xf7);
337 cx18_av_write(cx, 0x80b, 0x02);
338 } else if (std == V4L2_STD_NTSC_M_KR) {
339 /* South Korea uses A2 audio standard */
340 cx18_av_write(cx, 0x808, 0xf8);
341 cx18_av_write(cx, 0x80b, 0x03);
343 /* Others use the BTSC audio standard */
344 cx18_av_write(cx, 0x808, 0xf6);
345 cx18_av_write(cx, 0x80b, 0x01);
347 } else if (std & V4L2_STD_PAL) {
348 /* Follow tuner change procedure for PAL */
349 cx18_av_write(cx, 0x808, 0xff);
350 cx18_av_write(cx, 0x80b, 0x03);
351 } else if (std & V4L2_STD_SECAM) {
352 /* Select autodetect for SECAM */
353 cx18_av_write(cx, 0x808, 0xff);
354 cx18_av_write(cx, 0x80b, 0x03);
357 if (cx18_av_read(cx, 0x803) & 0x10) {
358 /* restart audio decoder microcontroller */
359 cx18_av_and_or(cx, 0x803, ~0x10, 0x00);
360 cx18_av_and_or(cx, 0x803, ~0x10, 0x10);
364 static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
365 enum cx18_av_audio_input aud_input)
367 struct cx18_av_state *state = &cx->av_state;
368 u8 is_composite = (vid_input >= CX18_AV_COMPOSITE1 &&
369 vid_input <= CX18_AV_COMPOSITE8);
372 CX18_DEBUG_INFO("decoder set video input %d, audio input %d\n",
373 vid_input, aud_input);
376 reg = 0xf0 + (vid_input - CX18_AV_COMPOSITE1);
378 int luma = vid_input & 0xf0;
379 int chroma = vid_input & 0xf00;
381 if ((vid_input & ~0xff0) ||
382 luma < CX18_AV_SVIDEO_LUMA1 ||
383 luma > CX18_AV_SVIDEO_LUMA8 ||
384 chroma < CX18_AV_SVIDEO_CHROMA4 ||
385 chroma > CX18_AV_SVIDEO_CHROMA8) {
386 CX18_ERR("0x%04x is not a valid video input!\n",
390 reg = 0xf0 + ((luma - CX18_AV_SVIDEO_LUMA1) >> 4);
391 if (chroma >= CX18_AV_SVIDEO_CHROMA7) {
393 reg |= (chroma - CX18_AV_SVIDEO_CHROMA7) >> 2;
396 reg |= (chroma - CX18_AV_SVIDEO_CHROMA4) >> 4;
401 case CX18_AV_AUDIO_SERIAL1:
402 case CX18_AV_AUDIO_SERIAL2:
403 /* do nothing, use serial audio input */
405 case CX18_AV_AUDIO4: reg &= ~0x30; break;
406 case CX18_AV_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
407 case CX18_AV_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
408 case CX18_AV_AUDIO7: reg &= ~0xc0; break;
409 case CX18_AV_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
412 CX18_ERR("0x%04x is not a valid audio input!\n", aud_input);
416 cx18_av_write(cx, 0x103, reg);
417 /* Set INPUT_MODE to Composite (0) or S-Video (1) */
418 cx18_av_and_or(cx, 0x401, ~0x6, is_composite ? 0 : 0x02);
419 /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
420 cx18_av_and_or(cx, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
421 /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
422 if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
423 cx18_av_and_or(cx, 0x102, ~0x4, 4);
425 cx18_av_and_or(cx, 0x102, ~0x4, 0);
426 /*cx18_av_and_or4(cx, 0x104, ~0x001b4180, 0x00004180);*/
428 state->vid_input = vid_input;
429 state->aud_input = aud_input;
430 cx18_av_audio_set_path(cx);
435 /* ----------------------------------------------------------------------- */
437 static int set_v4lstd(struct cx18 *cx)
439 struct cx18_av_state *state = &cx->av_state;
440 u8 fmt = 0; /* zero is autodetect */
443 /* First tests should be against specific std */
444 if (state->std == V4L2_STD_NTSC_M_JP) {
446 } else if (state->std == V4L2_STD_NTSC_443) {
448 } else if (state->std == V4L2_STD_PAL_M) {
451 } else if (state->std == V4L2_STD_PAL_N) {
453 } else if (state->std == V4L2_STD_PAL_Nc) {
455 } else if (state->std == V4L2_STD_PAL_60) {
458 /* Then, test against generic ones */
459 if (state->std & V4L2_STD_NTSC)
461 else if (state->std & V4L2_STD_PAL)
463 else if (state->std & V4L2_STD_SECAM)
467 CX18_DEBUG_INFO("changing video std to fmt %i\n", fmt);
469 /* Follow step 9 of section 3.16 in the cx18_av datasheet.
470 Without this PAL may display a vertical ghosting effect.
471 This happens for example with the Yuan MPC622. */
472 if (fmt >= 4 && fmt < 8) {
473 /* Set format to NTSC-M */
474 cx18_av_and_or(cx, 0x400, ~0xf, 1);
476 cx18_av_and_or(cx, 0x47b, ~6, 0);
478 cx18_av_and_or(cx, 0x400, ~0x2f, fmt | 0x20);
479 cx18_av_and_or(cx, 0x403, ~0x3, pal_m);
480 cx18_av_std_setup(cx);
485 /* ----------------------------------------------------------------------- */
487 static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
490 case V4L2_CID_BRIGHTNESS:
491 if (ctrl->value < 0 || ctrl->value > 255) {
492 CX18_ERR("invalid brightness setting %d\n",
497 cx18_av_write(cx, 0x414, ctrl->value - 128);
500 case V4L2_CID_CONTRAST:
501 if (ctrl->value < 0 || ctrl->value > 127) {
502 CX18_ERR("invalid contrast setting %d\n",
507 cx18_av_write(cx, 0x415, ctrl->value << 1);
510 case V4L2_CID_SATURATION:
511 if (ctrl->value < 0 || ctrl->value > 127) {
512 CX18_ERR("invalid saturation setting %d\n",
517 cx18_av_write(cx, 0x420, ctrl->value << 1);
518 cx18_av_write(cx, 0x421, ctrl->value << 1);
522 if (ctrl->value < -127 || ctrl->value > 127) {
523 CX18_ERR("invalid hue setting %d\n", ctrl->value);
527 cx18_av_write(cx, 0x422, ctrl->value);
530 case V4L2_CID_AUDIO_VOLUME:
531 case V4L2_CID_AUDIO_BASS:
532 case V4L2_CID_AUDIO_TREBLE:
533 case V4L2_CID_AUDIO_BALANCE:
534 case V4L2_CID_AUDIO_MUTE:
535 return cx18_av_audio(cx, VIDIOC_S_CTRL, ctrl);
544 static int get_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
547 case V4L2_CID_BRIGHTNESS:
548 ctrl->value = (s8)cx18_av_read(cx, 0x414) + 128;
550 case V4L2_CID_CONTRAST:
551 ctrl->value = cx18_av_read(cx, 0x415) >> 1;
553 case V4L2_CID_SATURATION:
554 ctrl->value = cx18_av_read(cx, 0x420) >> 1;
557 ctrl->value = (s8)cx18_av_read(cx, 0x422);
559 case V4L2_CID_AUDIO_VOLUME:
560 case V4L2_CID_AUDIO_BASS:
561 case V4L2_CID_AUDIO_TREBLE:
562 case V4L2_CID_AUDIO_BALANCE:
563 case V4L2_CID_AUDIO_MUTE:
564 return cx18_av_audio(cx, VIDIOC_G_CTRL, ctrl);
572 /* ----------------------------------------------------------------------- */
574 static int get_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
577 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
578 return cx18_av_vbi(cx, VIDIOC_G_FMT, fmt);
586 static int set_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
588 struct cx18_av_state *state = &cx->av_state;
589 struct v4l2_pix_format *pix;
590 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
591 int is_50Hz = !(state->std & V4L2_STD_525_60);
594 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
595 pix = &(fmt->fmt.pix);
597 Vsrc = (cx18_av_read(cx, 0x476) & 0x3f) << 4;
598 Vsrc |= (cx18_av_read(cx, 0x475) & 0xf0) >> 4;
600 Hsrc = (cx18_av_read(cx, 0x472) & 0x3f) << 4;
601 Hsrc |= (cx18_av_read(cx, 0x471) & 0xf0) >> 4;
603 Vlines = pix->height + (is_50Hz ? 4 : 7);
605 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
606 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
607 CX18_ERR("%dx%d is not a valid size!\n",
608 pix->width, pix->height);
612 HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20);
613 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
616 if (pix->width >= 385)
618 else if (pix->width > 192)
620 else if (pix->width > 96)
625 CX18_DEBUG_INFO("decoder set size %dx%d -> scale %ux%u\n",
626 pix->width, pix->height, HSC, VSC);
629 cx18_av_write(cx, 0x418, HSC & 0xff);
630 cx18_av_write(cx, 0x419, (HSC >> 8) & 0xff);
631 cx18_av_write(cx, 0x41a, HSC >> 16);
633 cx18_av_write(cx, 0x41c, VSC & 0xff);
634 cx18_av_write(cx, 0x41d, VSC >> 8);
635 /* VS_INTRLACE=1 VFILT=filter */
636 cx18_av_write(cx, 0x41e, 0x8 | filter);
639 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
640 return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt);
642 case V4L2_BUF_TYPE_VBI_CAPTURE:
643 return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt);
652 /* ----------------------------------------------------------------------- */
654 int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg)
656 struct cx18_av_state *state = &cx->av_state;
657 struct v4l2_tuner *vt = arg;
658 struct v4l2_routing *route = arg;
660 /* ignore these commands */
662 case TUNER_SET_TYPE_ADDR:
666 if (!state->is_initialized) {
667 CX18_DEBUG_INFO("cmd %08x triggered fw load\n", cmd);
668 /* initialize on first use */
669 state->is_initialized = 1;
670 cx18_av_initialize(cx);
674 case VIDIOC_INT_DECODE_VBI_LINE:
675 return cx18_av_vbi(cx, cmd, arg);
677 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
678 return cx18_av_audio(cx, cmd, arg);
680 case VIDIOC_STREAMON:
681 CX18_DEBUG_INFO("enable output\n");
682 cx18_av_write(cx, 0x115, 0x8c);
683 cx18_av_write(cx, 0x116, 0x07);
686 case VIDIOC_STREAMOFF:
687 CX18_DEBUG_INFO("disable output\n");
688 cx18_av_write(cx, 0x115, 0x00);
689 cx18_av_write(cx, 0x116, 0x00);
692 case VIDIOC_LOG_STATUS:
693 log_video_status(cx);
694 log_audio_status(cx);
698 return get_v4lctrl(cx, (struct v4l2_control *)arg);
701 return set_v4lctrl(cx, (struct v4l2_control *)arg);
703 case VIDIOC_QUERYCTRL:
705 struct v4l2_queryctrl *qc = arg;
708 case V4L2_CID_BRIGHTNESS:
709 case V4L2_CID_CONTRAST:
710 case V4L2_CID_SATURATION:
712 return v4l2_ctrl_query_fill_std(qc);
718 case V4L2_CID_AUDIO_VOLUME:
719 return v4l2_ctrl_query_fill(qc, 0, 65535,
720 65535 / 100, state->default_volume);
721 case V4L2_CID_AUDIO_MUTE:
722 case V4L2_CID_AUDIO_BALANCE:
723 case V4L2_CID_AUDIO_BASS:
724 case V4L2_CID_AUDIO_TREBLE:
725 return v4l2_ctrl_query_fill_std(qc);
733 *(v4l2_std_id *)arg = state->std;
737 if (state->radio == 0 && state->std == *(v4l2_std_id *)arg)
740 state->std = *(v4l2_std_id *)arg;
741 return set_v4lstd(cx);
747 case VIDIOC_INT_G_VIDEO_ROUTING:
748 route->input = state->vid_input;
752 case VIDIOC_INT_S_VIDEO_ROUTING:
753 return set_input(cx, route->input, state->aud_input);
755 case VIDIOC_INT_G_AUDIO_ROUTING:
756 route->input = state->aud_input;
760 case VIDIOC_INT_S_AUDIO_ROUTING:
761 return set_input(cx, state->vid_input, route->input);
763 case VIDIOC_S_FREQUENCY:
769 u8 vpres = cx18_av_read(cx, 0x40e) & 0x20;
776 vt->signal = vpres ? 0xffff : 0x0;
779 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
780 V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
782 mode = cx18_av_read(cx, 0x804);
784 /* get rxsubchans and audmode */
785 if ((mode & 0xf) == 1)
786 val |= V4L2_TUNER_SUB_STEREO;
788 val |= V4L2_TUNER_SUB_MONO;
790 if (mode == 2 || mode == 4)
791 val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
794 val |= V4L2_TUNER_SUB_SAP;
796 vt->rxsubchans = val;
797 vt->audmode = state->audmode;
805 switch (vt->audmode) {
806 case V4L2_TUNER_MODE_MONO:
809 bilingual -> lang1 */
810 cx18_av_and_or(cx, 0x809, ~0xf, 0x00);
812 case V4L2_TUNER_MODE_STEREO:
813 case V4L2_TUNER_MODE_LANG1:
816 bilingual -> lang1 */
817 cx18_av_and_or(cx, 0x809, ~0xf, 0x04);
819 case V4L2_TUNER_MODE_LANG1_LANG2:
822 bilingual -> lang1/lang2 */
823 cx18_av_and_or(cx, 0x809, ~0xf, 0x07);
825 case V4L2_TUNER_MODE_LANG2:
828 bilingual -> lang2 */
829 cx18_av_and_or(cx, 0x809, ~0xf, 0x01);
834 state->audmode = vt->audmode;
838 return get_v4lfmt(cx, (struct v4l2_format *)arg);
841 return set_v4lfmt(cx, (struct v4l2_format *)arg);
843 case VIDIOC_INT_RESET:
844 cx18_av_initialize(cx);
854 /* ----------------------------------------------------------------------- */
856 /* ----------------------------------------------------------------------- */
858 static void log_video_status(struct cx18 *cx)
860 static const char *const fmt_strs[] = {
862 "NTSC-M", "NTSC-J", "NTSC-4.43",
863 "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
869 struct cx18_av_state *state = &cx->av_state;
870 u8 vidfmt_sel = cx18_av_read(cx, 0x400) & 0xf;
871 u8 gen_stat1 = cx18_av_read(cx, 0x40d);
872 u8 gen_stat2 = cx18_av_read(cx, 0x40e);
873 int vid_input = state->vid_input;
875 CX18_INFO("Video signal: %spresent\n",
876 (gen_stat2 & 0x20) ? "" : "not ");
877 CX18_INFO("Detected format: %s\n",
878 fmt_strs[gen_stat1 & 0xf]);
880 CX18_INFO("Specified standard: %s\n",
881 vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
883 if (vid_input >= CX18_AV_COMPOSITE1 &&
884 vid_input <= CX18_AV_COMPOSITE8) {
885 CX18_INFO("Specified video input: Composite %d\n",
886 vid_input - CX18_AV_COMPOSITE1 + 1);
888 CX18_INFO("Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
889 (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
892 CX18_INFO("Specified audioclock freq: %d Hz\n", state->audclk_freq);
895 /* ----------------------------------------------------------------------- */
897 static void log_audio_status(struct cx18 *cx)
899 struct cx18_av_state *state = &cx->av_state;
900 u8 download_ctl = cx18_av_read(cx, 0x803);
901 u8 mod_det_stat0 = cx18_av_read(cx, 0x804);
902 u8 mod_det_stat1 = cx18_av_read(cx, 0x805);
903 u8 audio_config = cx18_av_read(cx, 0x808);
904 u8 pref_mode = cx18_av_read(cx, 0x809);
905 u8 afc0 = cx18_av_read(cx, 0x80b);
906 u8 mute_ctl = cx18_av_read(cx, 0x8d3);
907 int aud_input = state->aud_input;
910 switch (mod_det_stat0) {
911 case 0x00: p = "mono"; break;
912 case 0x01: p = "stereo"; break;
913 case 0x02: p = "dual"; break;
914 case 0x04: p = "tri"; break;
915 case 0x10: p = "mono with SAP"; break;
916 case 0x11: p = "stereo with SAP"; break;
917 case 0x12: p = "dual with SAP"; break;
918 case 0x14: p = "tri with SAP"; break;
919 case 0xfe: p = "forced mode"; break;
920 default: p = "not defined"; break;
922 CX18_INFO("Detected audio mode: %s\n", p);
924 switch (mod_det_stat1) {
925 case 0x00: p = "not defined"; break;
926 case 0x01: p = "EIAJ"; break;
927 case 0x02: p = "A2-M"; break;
928 case 0x03: p = "A2-BG"; break;
929 case 0x04: p = "A2-DK1"; break;
930 case 0x05: p = "A2-DK2"; break;
931 case 0x06: p = "A2-DK3"; break;
932 case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
933 case 0x08: p = "AM-L"; break;
934 case 0x09: p = "NICAM-BG"; break;
935 case 0x0a: p = "NICAM-DK"; break;
936 case 0x0b: p = "NICAM-I"; break;
937 case 0x0c: p = "NICAM-L"; break;
938 case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
939 case 0x0e: p = "IF FM Radio"; break;
940 case 0x0f: p = "BTSC"; break;
941 case 0x10: p = "detected chrominance"; break;
942 case 0xfd: p = "unknown audio standard"; break;
943 case 0xfe: p = "forced audio standard"; break;
944 case 0xff: p = "no detected audio standard"; break;
945 default: p = "not defined"; break;
947 CX18_INFO("Detected audio standard: %s\n", p);
948 CX18_INFO("Audio muted: %s\n",
949 (mute_ctl & 0x2) ? "yes" : "no");
950 CX18_INFO("Audio microcontroller: %s\n",
951 (download_ctl & 0x10) ? "running" : "stopped");
953 switch (audio_config >> 4) {
954 case 0x00: p = "undefined"; break;
955 case 0x01: p = "BTSC"; break;
956 case 0x02: p = "EIAJ"; break;
957 case 0x03: p = "A2-M"; break;
958 case 0x04: p = "A2-BG"; break;
959 case 0x05: p = "A2-DK1"; break;
960 case 0x06: p = "A2-DK2"; break;
961 case 0x07: p = "A2-DK3"; break;
962 case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
963 case 0x09: p = "AM-L"; break;
964 case 0x0a: p = "NICAM-BG"; break;
965 case 0x0b: p = "NICAM-DK"; break;
966 case 0x0c: p = "NICAM-I"; break;
967 case 0x0d: p = "NICAM-L"; break;
968 case 0x0e: p = "FM radio"; break;
969 case 0x0f: p = "automatic detection"; break;
970 default: p = "undefined"; break;
972 CX18_INFO("Configured audio standard: %s\n", p);
974 if ((audio_config >> 4) < 0xF) {
975 switch (audio_config & 0xF) {
976 case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
977 case 0x01: p = "MONO2 (LANGUAGE B)"; break;
978 case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
979 case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
980 case 0x04: p = "STEREO"; break;
981 case 0x05: p = "DUAL1 (AC)"; break;
982 case 0x06: p = "DUAL2 (BC)"; break;
983 case 0x07: p = "DUAL3 (AB)"; break;
984 default: p = "undefined";
986 CX18_INFO("Configured audio mode: %s\n", p);
988 switch (audio_config & 0xF) {
989 case 0x00: p = "BG"; break;
990 case 0x01: p = "DK1"; break;
991 case 0x02: p = "DK2"; break;
992 case 0x03: p = "DK3"; break;
993 case 0x04: p = "I"; break;
994 case 0x05: p = "L"; break;
995 case 0x06: p = "BTSC"; break;
996 case 0x07: p = "EIAJ"; break;
997 case 0x08: p = "A2-M"; break;
998 case 0x09: p = "FM Radio (4.5 MHz)"; break;
999 case 0x0a: p = "FM Radio (5.5 MHz)"; break;
1000 case 0x0b: p = "S-Video"; break;
1001 case 0x0f: p = "automatic standard and mode detection"; break;
1002 default: p = "undefined"; break;
1004 CX18_INFO("Configured audio system: %s\n", p);
1008 CX18_INFO("Specified audio input: Tuner (In%d)\n",
1011 CX18_INFO("Specified audio input: External\n");
1013 switch (pref_mode & 0xf) {
1014 case 0: p = "mono/language A"; break;
1015 case 1: p = "language B"; break;
1016 case 2: p = "language C"; break;
1017 case 3: p = "analog fallback"; break;
1018 case 4: p = "stereo"; break;
1019 case 5: p = "language AC"; break;
1020 case 6: p = "language BC"; break;
1021 case 7: p = "language AB"; break;
1022 default: p = "undefined"; break;
1024 CX18_INFO("Preferred audio mode: %s\n", p);
1026 if ((audio_config & 0xf) == 0xf) {
1027 switch ((afc0 >> 3) & 0x1) {
1028 case 0: p = "system DK"; break;
1029 case 1: p = "system L"; break;
1031 CX18_INFO("Selected 65 MHz format: %s\n", p);
1033 switch (afc0 & 0x7) {
1034 case 0: p = "Chroma"; break;
1035 case 1: p = "BTSC"; break;
1036 case 2: p = "EIAJ"; break;
1037 case 3: p = "A2-M"; break;
1038 case 4: p = "autodetect"; break;
1039 default: p = "undefined"; break;
1041 CX18_INFO("Selected 45 MHz format: %s\n", p);