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"
26 int cx18_av_write(struct cx18 *cx, u16 addr, u8 value)
28 u32 x = readl(cx->reg_mem + 0xc40000 + (addr & ~3));
30 int shift = (addr & 3) * 8;
32 x = (x & ~(mask << shift)) | ((u32)value << shift);
33 writel(x, cx->reg_mem + 0xc40000 + (addr & ~3));
37 int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value)
39 writel(value, cx->reg_mem + 0xc40000 + addr);
43 u8 cx18_av_read(struct cx18 *cx, u16 addr)
45 u32 x = readl(cx->reg_mem + 0xc40000 + (addr & ~3));
46 int shift = (addr & 3) * 8;
48 return (x >> shift) & 0xff;
51 u32 cx18_av_read4(struct cx18 *cx, u16 addr)
53 return readl(cx->reg_mem + 0xc40000 + addr);
56 int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned and_mask,
59 return cx18_av_write(cx, addr,
60 (cx18_av_read(cx, addr) & and_mask) |
64 int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 and_mask,
67 return cx18_av_write4(cx, addr,
68 (cx18_av_read4(cx, addr) & and_mask) |
72 /* ----------------------------------------------------------------------- */
74 static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
75 enum cx18_av_audio_input aud_input);
76 static void log_audio_status(struct cx18 *cx);
77 static void log_video_status(struct cx18 *cx);
79 /* ----------------------------------------------------------------------- */
81 static void cx18_av_initialize(struct cx18 *cx)
83 struct cx18_av_state *state = &cx->av_state;
87 /* Stop 8051 code execution */
88 cx18_av_write4(cx, CXADEC_DL_CTL, 0x03000000);
90 /* initallize the PLL by toggling sleep bit */
91 v = cx18_av_read4(cx, CXADEC_HOST_REG1);
92 /* enable sleep mode */
93 cx18_av_write4(cx, CXADEC_HOST_REG1, v | 1);
94 /* disable sleep mode */
95 cx18_av_write4(cx, CXADEC_HOST_REG1, v & 0xfffe);
98 v = cx18_av_read4(cx, CXADEC_DLL1_DIAG_CTRL) & 0xE1FFFEFF;
100 cx18_av_write4(cx, CXADEC_DLL1_DIAG_CTRL, v);
102 cx18_av_write4(cx, CXADEC_DLL1_DIAG_CTRL, v | 0x10000100);
104 v = cx18_av_read4(cx, CXADEC_DLL2_DIAG_CTRL) & 0xE1FFFEFF;
106 cx18_av_write4(cx, CXADEC_DLL2_DIAG_CTRL, v);
108 cx18_av_write4(cx, CXADEC_DLL2_DIAG_CTRL, v | 0x06000100);
110 /* set analog bias currents. Set Vreg to 1.20V. */
111 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL1, 0x000A1802);
113 v = cx18_av_read4(cx, CXADEC_AFE_DIAG_CTRL3) | 1;
114 /* enable TUNE_FIL_RST */
115 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL3, v);
116 /* disable TUNE_FIL_RST */
117 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL3, v & 0xFFFFFFFE);
119 /* enable 656 output */
120 cx18_av_and_or4(cx, CXADEC_PIN_CTRL1, ~0, 0x040C00);
122 /* video output drive strength */
123 cx18_av_and_or4(cx, CXADEC_PIN_CTRL2, ~0, 0x2);
126 cx18_av_write4(cx, CXADEC_SOFT_RST_CTRL, 0x8000);
127 cx18_av_write4(cx, CXADEC_SOFT_RST_CTRL, 0);
129 /* set video to auto-detect */
130 /* Clear bits 11-12 to enable slow locking mode. Set autodetect mode */
131 /* set the comb notch = 1 */
132 cx18_av_and_or4(cx, CXADEC_MODE_CTRL, 0xFFF7E7F0, 0x02040800);
134 /* Enable wtw_en in CRUSH_CTRL (Set bit 22) */
135 /* Enable maj_sel in CRUSH_CTRL (Set bit 20) */
136 cx18_av_and_or4(cx, CXADEC_CRUSH_CTRL, ~0, 0x00500000);
138 /* Set VGA_TRACK_RANGE to 0x20 */
139 cx18_av_and_or4(cx, CXADEC_DFE_CTRL2, 0xFFFF00FF, 0x00002000);
141 /* Enable VBI capture */
142 cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010253F);
143 /* cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010253E); */
145 /* Set the video input.
146 The setting in MODE_CTRL gets lost when we do the above setup */
147 /* EncSetSignalStd(dwDevNum, pEnc->dwSigStd); */
148 /* EncSetVideoInput(dwDevNum, pEnc->VidIndSelection); */
150 v = cx18_av_read4(cx, CXADEC_AFE_CTRL);
151 v &= 0xFFFBFFFF; /* turn OFF bit 18 for droop_comp_ch1 */
152 v &= 0xFFFF7FFF; /* turn OFF bit 9 for clamp_sel_ch1 */
153 v &= 0xFFFFFFFE; /* turn OFF bit 0 for 12db_ch1 */
154 /* v |= 0x00000001;*/ /* turn ON bit 0 for 12db_ch1 */
155 cx18_av_write4(cx, CXADEC_AFE_CTRL, v);
157 /* if(dwEnable && dw3DCombAvailable) { */
158 /* CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x7728021F); */
160 /* CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x6628021F); */
162 cx18_av_write4(cx, CXADEC_SRC_COMB_CFG, 0x6628021F);
163 state->default_volume = 228 - cx18_av_read(cx, 0x8d4);
164 state->default_volume = ((state->default_volume / 2) + 23) << 9;
167 /* ----------------------------------------------------------------------- */
169 void cx18_av_std_setup(struct cx18 *cx)
171 struct cx18_av_state *state = &cx->av_state;
172 v4l2_std_id std = state->std;
173 int hblank, hactive, burst, vblank, vactive, sc;
174 int vblank656, src_decimation;
175 int luma_lpf, uv_lpf, comb;
176 u32 pll_int, pll_frac, pll_post;
178 /* datasheet startup, step 8d */
179 if (std & ~V4L2_STD_NTSC)
180 cx18_av_write(cx, 0x49f, 0x11);
182 cx18_av_write(cx, 0x49f, 0x14);
184 if (std & V4L2_STD_625_50) {
191 src_decimation = 0x21f;
194 if (std & V4L2_STD_PAL) {
198 } else if (std == V4L2_STD_PAL_Nc) {
216 src_decimation = 0x21f;
217 if (std == V4L2_STD_PAL_60) {
222 } else if (std == V4L2_STD_PAL_M) {
233 /* DEBUG: Displays configured PLL frequency */
234 pll_int = cx18_av_read(cx, 0x108);
235 pll_frac = cx18_av_read4(cx, 0x10c) & 0x1ffffff;
236 pll_post = cx18_av_read(cx, 0x109);
237 CX18_DEBUG_INFO("PLL regs = int: %u, frac: %u, post: %u\n",
238 pll_int, pll_frac, pll_post);
242 int pll = 28636363L * ((((u64)pll_int) << 25) + pll_frac);
246 CX18_DEBUG_INFO("PLL = %d.%06d MHz\n",
247 pll / 1000000, pll % 1000000);
248 CX18_DEBUG_INFO("PLL/8 = %d.%06d MHz\n",
249 pll / 8000000, (pll / 8) % 1000000);
251 fin = ((u64)src_decimation * pll) >> 12;
252 CX18_DEBUG_INFO("ADC Sampling freq = %d.%06d MHz\n",
253 fin / 1000000, fin % 1000000);
255 fsc = (((u64)sc) * pll) >> 24L;
256 CX18_DEBUG_INFO("Chroma sub-carrier freq = %d.%06d MHz\n",
257 fsc / 1000000, fsc % 1000000);
259 CX18_DEBUG_INFO("hblank %i, hactive %i, "
260 "vblank %i , vactive %i, vblank656 %i, src_dec %i,"
261 "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x,"
263 hblank, hactive, vblank, vactive, vblank656,
264 src_decimation, burst, luma_lpf, uv_lpf, comb, sc);
267 /* Sets horizontal blanking delay and active lines */
268 cx18_av_write(cx, 0x470, hblank);
269 cx18_av_write(cx, 0x471, 0xff & (((hblank >> 8) & 0x3) |
271 cx18_av_write(cx, 0x472, hactive >> 4);
273 /* Sets burst gate delay */
274 cx18_av_write(cx, 0x473, burst);
276 /* Sets vertical blanking delay and active duration */
277 cx18_av_write(cx, 0x474, vblank);
278 cx18_av_write(cx, 0x475, 0xff & (((vblank >> 8) & 0x3) |
280 cx18_av_write(cx, 0x476, vactive >> 4);
281 cx18_av_write(cx, 0x477, vblank656);
283 /* Sets src decimation rate */
284 cx18_av_write(cx, 0x478, 0xff & src_decimation);
285 cx18_av_write(cx, 0x479, 0xff & (src_decimation >> 8));
287 /* Sets Luma and UV Low pass filters */
288 cx18_av_write(cx, 0x47a, luma_lpf << 6 | ((uv_lpf << 4) & 0x30));
290 /* Enables comb filters */
291 cx18_av_write(cx, 0x47b, comb);
294 cx18_av_write(cx, 0x47c, sc);
295 cx18_av_write(cx, 0x47d, 0xff & sc >> 8);
296 cx18_av_write(cx, 0x47e, 0xff & sc >> 16);
298 /* Sets VBI parameters */
299 if (std & V4L2_STD_625_50) {
300 cx18_av_write(cx, 0x47f, 0x01);
301 state->vbi_line_offset = 5;
303 cx18_av_write(cx, 0x47f, 0x00);
304 state->vbi_line_offset = 8;
308 /* ----------------------------------------------------------------------- */
310 static void input_change(struct cx18 *cx)
312 struct cx18_av_state *state = &cx->av_state;
313 v4l2_std_id std = state->std;
315 /* Follow step 8c and 8d of section 3.16 in the cx18_av datasheet */
316 cx18_av_write(cx, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
317 cx18_av_and_or(cx, 0x401, ~0x60, 0);
318 cx18_av_and_or(cx, 0x401, ~0x60, 0x60);
320 if (std & V4L2_STD_525_60) {
321 if (std == V4L2_STD_NTSC_M_JP) {
322 /* Japan uses EIAJ audio standard */
323 cx18_av_write(cx, 0x808, 0xf7);
324 cx18_av_write(cx, 0x80b, 0x02);
325 } else if (std == V4L2_STD_NTSC_M_KR) {
326 /* South Korea uses A2 audio standard */
327 cx18_av_write(cx, 0x808, 0xf8);
328 cx18_av_write(cx, 0x80b, 0x03);
330 /* Others use the BTSC audio standard */
331 cx18_av_write(cx, 0x808, 0xf6);
332 cx18_av_write(cx, 0x80b, 0x01);
334 } else if (std & V4L2_STD_PAL) {
335 /* Follow tuner change procedure for PAL */
336 cx18_av_write(cx, 0x808, 0xff);
337 cx18_av_write(cx, 0x80b, 0x03);
338 } else if (std & V4L2_STD_SECAM) {
339 /* Select autodetect for SECAM */
340 cx18_av_write(cx, 0x808, 0xff);
341 cx18_av_write(cx, 0x80b, 0x03);
344 if (cx18_av_read(cx, 0x803) & 0x10) {
345 /* restart audio decoder microcontroller */
346 cx18_av_and_or(cx, 0x803, ~0x10, 0x00);
347 cx18_av_and_or(cx, 0x803, ~0x10, 0x10);
351 static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
352 enum cx18_av_audio_input aud_input)
354 struct cx18_av_state *state = &cx->av_state;
355 u8 is_composite = (vid_input >= CX18_AV_COMPOSITE1 &&
356 vid_input <= CX18_AV_COMPOSITE8);
359 CX18_DEBUG_INFO("decoder set video input %d, audio input %d\n",
360 vid_input, aud_input);
363 reg = 0xf0 + (vid_input - CX18_AV_COMPOSITE1);
365 int luma = vid_input & 0xf0;
366 int chroma = vid_input & 0xf00;
368 if ((vid_input & ~0xff0) ||
369 luma < CX18_AV_SVIDEO_LUMA1 ||
370 luma > CX18_AV_SVIDEO_LUMA8 ||
371 chroma < CX18_AV_SVIDEO_CHROMA4 ||
372 chroma > CX18_AV_SVIDEO_CHROMA8) {
373 CX18_ERR("0x%04x is not a valid video input!\n",
377 reg = 0xf0 + ((luma - CX18_AV_SVIDEO_LUMA1) >> 4);
378 if (chroma >= CX18_AV_SVIDEO_CHROMA7) {
380 reg |= (chroma - CX18_AV_SVIDEO_CHROMA7) >> 2;
383 reg |= (chroma - CX18_AV_SVIDEO_CHROMA4) >> 4;
388 case CX18_AV_AUDIO_SERIAL1:
389 case CX18_AV_AUDIO_SERIAL2:
390 /* do nothing, use serial audio input */
392 case CX18_AV_AUDIO4: reg &= ~0x30; break;
393 case CX18_AV_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
394 case CX18_AV_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
395 case CX18_AV_AUDIO7: reg &= ~0xc0; break;
396 case CX18_AV_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
399 CX18_ERR("0x%04x is not a valid audio input!\n", aud_input);
403 cx18_av_write(cx, 0x103, reg);
404 /* Set INPUT_MODE to Composite (0) or S-Video (1) */
405 cx18_av_and_or(cx, 0x401, ~0x6, is_composite ? 0 : 0x02);
406 /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
407 cx18_av_and_or(cx, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
408 /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
409 if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
410 cx18_av_and_or(cx, 0x102, ~0x4, 4);
412 cx18_av_and_or(cx, 0x102, ~0x4, 0);
413 /*cx18_av_and_or4(cx, 0x104, ~0x001b4180, 0x00004180);*/
415 state->vid_input = vid_input;
416 state->aud_input = aud_input;
417 cx18_av_audio_set_path(cx);
422 /* ----------------------------------------------------------------------- */
424 static int set_v4lstd(struct cx18 *cx)
426 struct cx18_av_state *state = &cx->av_state;
427 u8 fmt = 0; /* zero is autodetect */
430 /* First tests should be against specific std */
431 if (state->std == V4L2_STD_NTSC_M_JP) {
433 } else if (state->std == V4L2_STD_NTSC_443) {
435 } else if (state->std == V4L2_STD_PAL_M) {
438 } else if (state->std == V4L2_STD_PAL_N) {
440 } else if (state->std == V4L2_STD_PAL_Nc) {
442 } else if (state->std == V4L2_STD_PAL_60) {
445 /* Then, test against generic ones */
446 if (state->std & V4L2_STD_NTSC)
448 else if (state->std & V4L2_STD_PAL)
450 else if (state->std & V4L2_STD_SECAM)
454 CX18_DEBUG_INFO("changing video std to fmt %i\n", fmt);
456 /* Follow step 9 of section 3.16 in the cx18_av datasheet.
457 Without this PAL may display a vertical ghosting effect.
458 This happens for example with the Yuan MPC622. */
459 if (fmt >= 4 && fmt < 8) {
460 /* Set format to NTSC-M */
461 cx18_av_and_or(cx, 0x400, ~0xf, 1);
463 cx18_av_and_or(cx, 0x47b, ~6, 0);
465 cx18_av_and_or(cx, 0x400, ~0x2f, fmt | 0x20);
466 cx18_av_and_or(cx, 0x403, ~0x3, pal_m);
467 cx18_av_std_setup(cx);
472 /* ----------------------------------------------------------------------- */
474 static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
477 case V4L2_CID_BRIGHTNESS:
478 if (ctrl->value < 0 || ctrl->value > 255) {
479 CX18_ERR("invalid brightness setting %d\n",
484 cx18_av_write(cx, 0x414, ctrl->value - 128);
487 case V4L2_CID_CONTRAST:
488 if (ctrl->value < 0 || ctrl->value > 127) {
489 CX18_ERR("invalid contrast setting %d\n",
494 cx18_av_write(cx, 0x415, ctrl->value << 1);
497 case V4L2_CID_SATURATION:
498 if (ctrl->value < 0 || ctrl->value > 127) {
499 CX18_ERR("invalid saturation setting %d\n",
504 cx18_av_write(cx, 0x420, ctrl->value << 1);
505 cx18_av_write(cx, 0x421, ctrl->value << 1);
509 if (ctrl->value < -127 || ctrl->value > 127) {
510 CX18_ERR("invalid hue setting %d\n", ctrl->value);
514 cx18_av_write(cx, 0x422, ctrl->value);
517 case V4L2_CID_AUDIO_VOLUME:
518 case V4L2_CID_AUDIO_BASS:
519 case V4L2_CID_AUDIO_TREBLE:
520 case V4L2_CID_AUDIO_BALANCE:
521 case V4L2_CID_AUDIO_MUTE:
522 return cx18_av_audio(cx, VIDIOC_S_CTRL, ctrl);
531 static int get_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
534 case V4L2_CID_BRIGHTNESS:
535 ctrl->value = (s8)cx18_av_read(cx, 0x414) + 128;
537 case V4L2_CID_CONTRAST:
538 ctrl->value = cx18_av_read(cx, 0x415) >> 1;
540 case V4L2_CID_SATURATION:
541 ctrl->value = cx18_av_read(cx, 0x420) >> 1;
544 ctrl->value = (s8)cx18_av_read(cx, 0x422);
546 case V4L2_CID_AUDIO_VOLUME:
547 case V4L2_CID_AUDIO_BASS:
548 case V4L2_CID_AUDIO_TREBLE:
549 case V4L2_CID_AUDIO_BALANCE:
550 case V4L2_CID_AUDIO_MUTE:
551 return cx18_av_audio(cx, VIDIOC_G_CTRL, ctrl);
559 /* ----------------------------------------------------------------------- */
561 static int get_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
564 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
565 return cx18_av_vbi(cx, VIDIOC_G_FMT, fmt);
573 static int set_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
575 struct cx18_av_state *state = &cx->av_state;
576 struct v4l2_pix_format *pix;
577 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
578 int is_50Hz = !(state->std & V4L2_STD_525_60);
581 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
582 pix = &(fmt->fmt.pix);
584 Vsrc = (cx18_av_read(cx, 0x476) & 0x3f) << 4;
585 Vsrc |= (cx18_av_read(cx, 0x475) & 0xf0) >> 4;
587 Hsrc = (cx18_av_read(cx, 0x472) & 0x3f) << 4;
588 Hsrc |= (cx18_av_read(cx, 0x471) & 0xf0) >> 4;
590 Vlines = pix->height + (is_50Hz ? 4 : 7);
592 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
593 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
594 CX18_ERR("%dx%d is not a valid size!\n",
595 pix->width, pix->height);
599 HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20);
600 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
603 if (pix->width >= 385)
605 else if (pix->width > 192)
607 else if (pix->width > 96)
612 CX18_DEBUG_INFO("decoder set size %dx%d -> scale %ux%u\n",
613 pix->width, pix->height, HSC, VSC);
616 cx18_av_write(cx, 0x418, HSC & 0xff);
617 cx18_av_write(cx, 0x419, (HSC >> 8) & 0xff);
618 cx18_av_write(cx, 0x41a, HSC >> 16);
620 cx18_av_write(cx, 0x41c, VSC & 0xff);
621 cx18_av_write(cx, 0x41d, VSC >> 8);
622 /* VS_INTRLACE=1 VFILT=filter */
623 cx18_av_write(cx, 0x41e, 0x8 | filter);
626 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
627 return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt);
629 case V4L2_BUF_TYPE_VBI_CAPTURE:
630 return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt);
639 /* ----------------------------------------------------------------------- */
641 int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg)
643 struct cx18_av_state *state = &cx->av_state;
644 struct v4l2_tuner *vt = arg;
645 struct v4l2_routing *route = arg;
647 /* ignore these commands */
649 case TUNER_SET_TYPE_ADDR:
653 if (!state->is_initialized) {
654 CX18_DEBUG_INFO("cmd %08x triggered fw load\n", cmd);
655 /* initialize on first use */
656 state->is_initialized = 1;
657 cx18_av_initialize(cx);
661 case VIDIOC_INT_DECODE_VBI_LINE:
662 return cx18_av_vbi(cx, cmd, arg);
664 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
665 return cx18_av_audio(cx, cmd, arg);
667 case VIDIOC_STREAMON:
668 CX18_DEBUG_INFO("enable output\n");
669 cx18_av_write(cx, 0x115, 0x8c);
670 cx18_av_write(cx, 0x116, 0x07);
673 case VIDIOC_STREAMOFF:
674 CX18_DEBUG_INFO("disable output\n");
675 cx18_av_write(cx, 0x115, 0x00);
676 cx18_av_write(cx, 0x116, 0x00);
679 case VIDIOC_LOG_STATUS:
680 log_video_status(cx);
681 log_audio_status(cx);
685 return get_v4lctrl(cx, (struct v4l2_control *)arg);
688 return set_v4lctrl(cx, (struct v4l2_control *)arg);
690 case VIDIOC_QUERYCTRL:
692 struct v4l2_queryctrl *qc = arg;
695 case V4L2_CID_BRIGHTNESS:
696 case V4L2_CID_CONTRAST:
697 case V4L2_CID_SATURATION:
699 return v4l2_ctrl_query_fill_std(qc);
705 case V4L2_CID_AUDIO_VOLUME:
706 return v4l2_ctrl_query_fill(qc, 0, 65535,
707 65535 / 100, state->default_volume);
708 case V4L2_CID_AUDIO_MUTE:
709 case V4L2_CID_AUDIO_BALANCE:
710 case V4L2_CID_AUDIO_BASS:
711 case V4L2_CID_AUDIO_TREBLE:
712 return v4l2_ctrl_query_fill_std(qc);
720 *(v4l2_std_id *)arg = state->std;
724 if (state->radio == 0 && state->std == *(v4l2_std_id *)arg)
727 state->std = *(v4l2_std_id *)arg;
728 return set_v4lstd(cx);
734 case VIDIOC_INT_G_VIDEO_ROUTING:
735 route->input = state->vid_input;
739 case VIDIOC_INT_S_VIDEO_ROUTING:
740 return set_input(cx, route->input, state->aud_input);
742 case VIDIOC_INT_G_AUDIO_ROUTING:
743 route->input = state->aud_input;
747 case VIDIOC_INT_S_AUDIO_ROUTING:
748 return set_input(cx, state->vid_input, route->input);
750 case VIDIOC_S_FREQUENCY:
756 u8 vpres = cx18_av_read(cx, 0x40e) & 0x20;
763 vt->signal = vpres ? 0xffff : 0x0;
766 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
767 V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
769 mode = cx18_av_read(cx, 0x804);
771 /* get rxsubchans and audmode */
772 if ((mode & 0xf) == 1)
773 val |= V4L2_TUNER_SUB_STEREO;
775 val |= V4L2_TUNER_SUB_MONO;
777 if (mode == 2 || mode == 4)
778 val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
781 val |= V4L2_TUNER_SUB_SAP;
783 vt->rxsubchans = val;
784 vt->audmode = state->audmode;
792 switch (vt->audmode) {
793 case V4L2_TUNER_MODE_MONO:
796 bilingual -> lang1 */
797 cx18_av_and_or(cx, 0x809, ~0xf, 0x00);
799 case V4L2_TUNER_MODE_STEREO:
800 case V4L2_TUNER_MODE_LANG1:
803 bilingual -> lang1 */
804 cx18_av_and_or(cx, 0x809, ~0xf, 0x04);
806 case V4L2_TUNER_MODE_LANG1_LANG2:
809 bilingual -> lang1/lang2 */
810 cx18_av_and_or(cx, 0x809, ~0xf, 0x07);
812 case V4L2_TUNER_MODE_LANG2:
815 bilingual -> lang2 */
816 cx18_av_and_or(cx, 0x809, ~0xf, 0x01);
821 state->audmode = vt->audmode;
825 return get_v4lfmt(cx, (struct v4l2_format *)arg);
828 return set_v4lfmt(cx, (struct v4l2_format *)arg);
830 case VIDIOC_INT_RESET:
831 cx18_av_initialize(cx);
841 /* ----------------------------------------------------------------------- */
843 /* ----------------------------------------------------------------------- */
845 static void log_video_status(struct cx18 *cx)
847 static const char *const fmt_strs[] = {
849 "NTSC-M", "NTSC-J", "NTSC-4.43",
850 "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
856 struct cx18_av_state *state = &cx->av_state;
857 u8 vidfmt_sel = cx18_av_read(cx, 0x400) & 0xf;
858 u8 gen_stat1 = cx18_av_read(cx, 0x40d);
859 u8 gen_stat2 = cx18_av_read(cx, 0x40e);
860 int vid_input = state->vid_input;
862 CX18_INFO("Video signal: %spresent\n",
863 (gen_stat2 & 0x20) ? "" : "not ");
864 CX18_INFO("Detected format: %s\n",
865 fmt_strs[gen_stat1 & 0xf]);
867 CX18_INFO("Specified standard: %s\n",
868 vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
870 if (vid_input >= CX18_AV_COMPOSITE1 &&
871 vid_input <= CX18_AV_COMPOSITE8) {
872 CX18_INFO("Specified video input: Composite %d\n",
873 vid_input - CX18_AV_COMPOSITE1 + 1);
875 CX18_INFO("Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
876 (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
879 CX18_INFO("Specified audioclock freq: %d Hz\n", state->audclk_freq);
882 /* ----------------------------------------------------------------------- */
884 static void log_audio_status(struct cx18 *cx)
886 struct cx18_av_state *state = &cx->av_state;
887 u8 download_ctl = cx18_av_read(cx, 0x803);
888 u8 mod_det_stat0 = cx18_av_read(cx, 0x804);
889 u8 mod_det_stat1 = cx18_av_read(cx, 0x805);
890 u8 audio_config = cx18_av_read(cx, 0x808);
891 u8 pref_mode = cx18_av_read(cx, 0x809);
892 u8 afc0 = cx18_av_read(cx, 0x80b);
893 u8 mute_ctl = cx18_av_read(cx, 0x8d3);
894 int aud_input = state->aud_input;
897 switch (mod_det_stat0) {
898 case 0x00: p = "mono"; break;
899 case 0x01: p = "stereo"; break;
900 case 0x02: p = "dual"; break;
901 case 0x04: p = "tri"; break;
902 case 0x10: p = "mono with SAP"; break;
903 case 0x11: p = "stereo with SAP"; break;
904 case 0x12: p = "dual with SAP"; break;
905 case 0x14: p = "tri with SAP"; break;
906 case 0xfe: p = "forced mode"; break;
907 default: p = "not defined"; break;
909 CX18_INFO("Detected audio mode: %s\n", p);
911 switch (mod_det_stat1) {
912 case 0x00: p = "not defined"; break;
913 case 0x01: p = "EIAJ"; break;
914 case 0x02: p = "A2-M"; break;
915 case 0x03: p = "A2-BG"; break;
916 case 0x04: p = "A2-DK1"; break;
917 case 0x05: p = "A2-DK2"; break;
918 case 0x06: p = "A2-DK3"; break;
919 case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
920 case 0x08: p = "AM-L"; break;
921 case 0x09: p = "NICAM-BG"; break;
922 case 0x0a: p = "NICAM-DK"; break;
923 case 0x0b: p = "NICAM-I"; break;
924 case 0x0c: p = "NICAM-L"; break;
925 case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
926 case 0x0e: p = "IF FM Radio"; break;
927 case 0x0f: p = "BTSC"; break;
928 case 0x10: p = "detected chrominance"; break;
929 case 0xfd: p = "unknown audio standard"; break;
930 case 0xfe: p = "forced audio standard"; break;
931 case 0xff: p = "no detected audio standard"; break;
932 default: p = "not defined"; break;
934 CX18_INFO("Detected audio standard: %s\n", p);
935 CX18_INFO("Audio muted: %s\n",
936 (mute_ctl & 0x2) ? "yes" : "no");
937 CX18_INFO("Audio microcontroller: %s\n",
938 (download_ctl & 0x10) ? "running" : "stopped");
940 switch (audio_config >> 4) {
941 case 0x00: p = "undefined"; break;
942 case 0x01: p = "BTSC"; break;
943 case 0x02: p = "EIAJ"; break;
944 case 0x03: p = "A2-M"; break;
945 case 0x04: p = "A2-BG"; break;
946 case 0x05: p = "A2-DK1"; break;
947 case 0x06: p = "A2-DK2"; break;
948 case 0x07: p = "A2-DK3"; break;
949 case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
950 case 0x09: p = "AM-L"; break;
951 case 0x0a: p = "NICAM-BG"; break;
952 case 0x0b: p = "NICAM-DK"; break;
953 case 0x0c: p = "NICAM-I"; break;
954 case 0x0d: p = "NICAM-L"; break;
955 case 0x0e: p = "FM radio"; break;
956 case 0x0f: p = "automatic detection"; break;
957 default: p = "undefined"; break;
959 CX18_INFO("Configured audio standard: %s\n", p);
961 if ((audio_config >> 4) < 0xF) {
962 switch (audio_config & 0xF) {
963 case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
964 case 0x01: p = "MONO2 (LANGUAGE B)"; break;
965 case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
966 case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
967 case 0x04: p = "STEREO"; break;
968 case 0x05: p = "DUAL1 (AC)"; break;
969 case 0x06: p = "DUAL2 (BC)"; break;
970 case 0x07: p = "DUAL3 (AB)"; break;
971 default: p = "undefined";
973 CX18_INFO("Configured audio mode: %s\n", p);
975 switch (audio_config & 0xF) {
976 case 0x00: p = "BG"; break;
977 case 0x01: p = "DK1"; break;
978 case 0x02: p = "DK2"; break;
979 case 0x03: p = "DK3"; break;
980 case 0x04: p = "I"; break;
981 case 0x05: p = "L"; break;
982 case 0x06: p = "BTSC"; break;
983 case 0x07: p = "EIAJ"; break;
984 case 0x08: p = "A2-M"; break;
985 case 0x09: p = "FM Radio (4.5 MHz)"; break;
986 case 0x0a: p = "FM Radio (5.5 MHz)"; break;
987 case 0x0b: p = "S-Video"; break;
988 case 0x0f: p = "automatic standard and mode detection"; break;
989 default: p = "undefined"; break;
991 CX18_INFO("Configured audio system: %s\n", p);
995 CX18_INFO("Specified audio input: Tuner (In%d)\n",
998 CX18_INFO("Specified audio input: External\n");
1000 switch (pref_mode & 0xf) {
1001 case 0: p = "mono/language A"; break;
1002 case 1: p = "language B"; break;
1003 case 2: p = "language C"; break;
1004 case 3: p = "analog fallback"; break;
1005 case 4: p = "stereo"; break;
1006 case 5: p = "language AC"; break;
1007 case 6: p = "language BC"; break;
1008 case 7: p = "language AB"; break;
1009 default: p = "undefined"; break;
1011 CX18_INFO("Preferred audio mode: %s\n", p);
1013 if ((audio_config & 0xf) == 0xf) {
1014 switch ((afc0 >> 3) & 0x1) {
1015 case 0: p = "system DK"; break;
1016 case 1: p = "system L"; break;
1018 CX18_INFO("Selected 65 MHz format: %s\n", p);
1020 switch (afc0 & 0x7) {
1021 case 0: p = "Chroma"; break;
1022 case 1: p = "BTSC"; break;
1023 case 2: p = "EIAJ"; break;
1024 case 3: p = "A2-M"; break;
1025 case 4: p = "autodetect"; break;
1026 default: p = "undefined"; break;
1028 CX18_INFO("Selected 45 MHz format: %s\n", p);