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 u8 cx18_av_read(struct cx18 *cx, u16 addr)
47 u32 x = cx18_read_reg(cx, 0xc40000 + (addr & ~3));
48 int shift = (addr & 3) * 8;
50 return (x >> shift) & 0xff;
53 u32 cx18_av_read4(struct cx18 *cx, u16 addr)
55 return cx18_read_reg(cx, 0xc40000 + addr);
58 int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned and_mask,
61 return cx18_av_write(cx, addr,
62 (cx18_av_read(cx, addr) & and_mask) |
66 int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 and_mask,
69 return cx18_av_write4(cx, addr,
70 (cx18_av_read4(cx, addr) & and_mask) |
74 /* ----------------------------------------------------------------------- */
76 static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
77 enum cx18_av_audio_input aud_input);
78 static void log_audio_status(struct cx18 *cx);
79 static void log_video_status(struct cx18 *cx);
81 /* ----------------------------------------------------------------------- */
83 static void cx18_av_initialize(struct cx18 *cx)
85 struct cx18_av_state *state = &cx->av_state;
89 /* Stop 8051 code execution */
90 cx18_av_write4(cx, CXADEC_DL_CTL, 0x03000000);
92 /* initallize the PLL by toggling sleep bit */
93 v = cx18_av_read4(cx, CXADEC_HOST_REG1);
94 /* enable sleep mode */
95 cx18_av_write4(cx, CXADEC_HOST_REG1, v | 1);
96 /* disable sleep mode */
97 cx18_av_write4(cx, CXADEC_HOST_REG1, v & 0xfffe);
100 v = cx18_av_read4(cx, CXADEC_DLL1_DIAG_CTRL) & 0xE1FFFEFF;
102 cx18_av_write4(cx, CXADEC_DLL1_DIAG_CTRL, v);
104 cx18_av_write4(cx, CXADEC_DLL1_DIAG_CTRL, v | 0x10000100);
106 v = cx18_av_read4(cx, CXADEC_DLL2_DIAG_CTRL) & 0xE1FFFEFF;
108 cx18_av_write4(cx, CXADEC_DLL2_DIAG_CTRL, v);
110 cx18_av_write4(cx, CXADEC_DLL2_DIAG_CTRL, v | 0x06000100);
112 /* set analog bias currents. Set Vreg to 1.20V. */
113 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL1, 0x000A1802);
115 v = cx18_av_read4(cx, CXADEC_AFE_DIAG_CTRL3) | 1;
116 /* enable TUNE_FIL_RST */
117 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL3, v);
118 /* disable TUNE_FIL_RST */
119 cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL3, v & 0xFFFFFFFE);
121 /* enable 656 output */
122 cx18_av_and_or4(cx, CXADEC_PIN_CTRL1, ~0, 0x040C00);
124 /* video output drive strength */
125 cx18_av_and_or4(cx, CXADEC_PIN_CTRL2, ~0, 0x2);
128 cx18_av_write4(cx, CXADEC_SOFT_RST_CTRL, 0x8000);
129 cx18_av_write4(cx, CXADEC_SOFT_RST_CTRL, 0);
131 /* set video to auto-detect */
132 /* Clear bits 11-12 to enable slow locking mode. Set autodetect mode */
133 /* set the comb notch = 1 */
134 cx18_av_and_or4(cx, CXADEC_MODE_CTRL, 0xFFF7E7F0, 0x02040800);
136 /* Enable wtw_en in CRUSH_CTRL (Set bit 22) */
137 /* Enable maj_sel in CRUSH_CTRL (Set bit 20) */
138 cx18_av_and_or4(cx, CXADEC_CRUSH_CTRL, ~0, 0x00500000);
140 /* Set VGA_TRACK_RANGE to 0x20 */
141 cx18_av_and_or4(cx, CXADEC_DFE_CTRL2, 0xFFFF00FF, 0x00002000);
143 /* Enable VBI capture */
144 cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010253F);
145 /* cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010253E); */
147 /* Set the video input.
148 The setting in MODE_CTRL gets lost when we do the above setup */
149 /* EncSetSignalStd(dwDevNum, pEnc->dwSigStd); */
150 /* EncSetVideoInput(dwDevNum, pEnc->VidIndSelection); */
152 v = cx18_av_read4(cx, CXADEC_AFE_CTRL);
153 v &= 0xFFFBFFFF; /* turn OFF bit 18 for droop_comp_ch1 */
154 v &= 0xFFFF7FFF; /* turn OFF bit 9 for clamp_sel_ch1 */
155 v &= 0xFFFFFFFE; /* turn OFF bit 0 for 12db_ch1 */
156 /* v |= 0x00000001;*/ /* turn ON bit 0 for 12db_ch1 */
157 cx18_av_write4(cx, CXADEC_AFE_CTRL, v);
159 /* if(dwEnable && dw3DCombAvailable) { */
160 /* CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x7728021F); */
162 /* CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x6628021F); */
164 cx18_av_write4(cx, CXADEC_SRC_COMB_CFG, 0x6628021F);
165 state->default_volume = 228 - cx18_av_read(cx, 0x8d4);
166 state->default_volume = ((state->default_volume / 2) + 23) << 9;
169 /* ----------------------------------------------------------------------- */
171 void cx18_av_std_setup(struct cx18 *cx)
173 struct cx18_av_state *state = &cx->av_state;
174 v4l2_std_id std = state->std;
175 int hblank, hactive, burst, vblank, vactive, sc;
176 int vblank656, src_decimation;
177 int luma_lpf, uv_lpf, comb;
178 u32 pll_int, pll_frac, pll_post;
180 /* datasheet startup, step 8d */
181 if (std & ~V4L2_STD_NTSC)
182 cx18_av_write(cx, 0x49f, 0x11);
184 cx18_av_write(cx, 0x49f, 0x14);
186 if (std & V4L2_STD_625_50) {
193 src_decimation = 0x21f;
196 if (std & V4L2_STD_PAL) {
200 } else if (std == V4L2_STD_PAL_Nc) {
218 src_decimation = 0x21f;
219 if (std == V4L2_STD_PAL_60) {
224 } else if (std == V4L2_STD_PAL_M) {
235 /* DEBUG: Displays configured PLL frequency */
236 pll_int = cx18_av_read(cx, 0x108);
237 pll_frac = cx18_av_read4(cx, 0x10c) & 0x1ffffff;
238 pll_post = cx18_av_read(cx, 0x109);
239 CX18_DEBUG_INFO("PLL regs = int: %u, frac: %u, post: %u\n",
240 pll_int, pll_frac, pll_post);
244 int pll = 28636363L * ((((u64)pll_int) << 25) + pll_frac);
248 CX18_DEBUG_INFO("PLL = %d.%06d MHz\n",
249 pll / 1000000, pll % 1000000);
250 CX18_DEBUG_INFO("PLL/8 = %d.%06d MHz\n",
251 pll / 8000000, (pll / 8) % 1000000);
253 fin = ((u64)src_decimation * pll) >> 12;
254 CX18_DEBUG_INFO("ADC Sampling freq = %d.%06d MHz\n",
255 fin / 1000000, fin % 1000000);
257 fsc = (((u64)sc) * pll) >> 24L;
258 CX18_DEBUG_INFO("Chroma sub-carrier freq = %d.%06d MHz\n",
259 fsc / 1000000, fsc % 1000000);
261 CX18_DEBUG_INFO("hblank %i, hactive %i, "
262 "vblank %i , vactive %i, vblank656 %i, src_dec %i,"
263 "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x,"
265 hblank, hactive, vblank, vactive, vblank656,
266 src_decimation, burst, luma_lpf, uv_lpf, comb, sc);
269 /* Sets horizontal blanking delay and active lines */
270 cx18_av_write(cx, 0x470, hblank);
271 cx18_av_write(cx, 0x471, 0xff & (((hblank >> 8) & 0x3) |
273 cx18_av_write(cx, 0x472, hactive >> 4);
275 /* Sets burst gate delay */
276 cx18_av_write(cx, 0x473, burst);
278 /* Sets vertical blanking delay and active duration */
279 cx18_av_write(cx, 0x474, vblank);
280 cx18_av_write(cx, 0x475, 0xff & (((vblank >> 8) & 0x3) |
282 cx18_av_write(cx, 0x476, vactive >> 4);
283 cx18_av_write(cx, 0x477, vblank656);
285 /* Sets src decimation rate */
286 cx18_av_write(cx, 0x478, 0xff & src_decimation);
287 cx18_av_write(cx, 0x479, 0xff & (src_decimation >> 8));
289 /* Sets Luma and UV Low pass filters */
290 cx18_av_write(cx, 0x47a, luma_lpf << 6 | ((uv_lpf << 4) & 0x30));
292 /* Enables comb filters */
293 cx18_av_write(cx, 0x47b, comb);
296 cx18_av_write(cx, 0x47c, sc);
297 cx18_av_write(cx, 0x47d, 0xff & sc >> 8);
298 cx18_av_write(cx, 0x47e, 0xff & sc >> 16);
300 /* Sets VBI parameters */
301 if (std & V4L2_STD_625_50) {
302 cx18_av_write(cx, 0x47f, 0x01);
303 state->vbi_line_offset = 5;
305 cx18_av_write(cx, 0x47f, 0x00);
306 state->vbi_line_offset = 8;
310 /* ----------------------------------------------------------------------- */
312 static void input_change(struct cx18 *cx)
314 struct cx18_av_state *state = &cx->av_state;
315 v4l2_std_id std = state->std;
317 /* Follow step 8c and 8d of section 3.16 in the cx18_av datasheet */
318 cx18_av_write(cx, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
319 cx18_av_and_or(cx, 0x401, ~0x60, 0);
320 cx18_av_and_or(cx, 0x401, ~0x60, 0x60);
322 if (std & V4L2_STD_525_60) {
323 if (std == V4L2_STD_NTSC_M_JP) {
324 /* Japan uses EIAJ audio standard */
325 cx18_av_write(cx, 0x808, 0xf7);
326 cx18_av_write(cx, 0x80b, 0x02);
327 } else if (std == V4L2_STD_NTSC_M_KR) {
328 /* South Korea uses A2 audio standard */
329 cx18_av_write(cx, 0x808, 0xf8);
330 cx18_av_write(cx, 0x80b, 0x03);
332 /* Others use the BTSC audio standard */
333 cx18_av_write(cx, 0x808, 0xf6);
334 cx18_av_write(cx, 0x80b, 0x01);
336 } else if (std & V4L2_STD_PAL) {
337 /* Follow tuner change procedure for PAL */
338 cx18_av_write(cx, 0x808, 0xff);
339 cx18_av_write(cx, 0x80b, 0x03);
340 } else if (std & V4L2_STD_SECAM) {
341 /* Select autodetect for SECAM */
342 cx18_av_write(cx, 0x808, 0xff);
343 cx18_av_write(cx, 0x80b, 0x03);
346 if (cx18_av_read(cx, 0x803) & 0x10) {
347 /* restart audio decoder microcontroller */
348 cx18_av_and_or(cx, 0x803, ~0x10, 0x00);
349 cx18_av_and_or(cx, 0x803, ~0x10, 0x10);
353 static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
354 enum cx18_av_audio_input aud_input)
356 struct cx18_av_state *state = &cx->av_state;
357 u8 is_composite = (vid_input >= CX18_AV_COMPOSITE1 &&
358 vid_input <= CX18_AV_COMPOSITE8);
361 CX18_DEBUG_INFO("decoder set video input %d, audio input %d\n",
362 vid_input, aud_input);
365 reg = 0xf0 + (vid_input - CX18_AV_COMPOSITE1);
367 int luma = vid_input & 0xf0;
368 int chroma = vid_input & 0xf00;
370 if ((vid_input & ~0xff0) ||
371 luma < CX18_AV_SVIDEO_LUMA1 ||
372 luma > CX18_AV_SVIDEO_LUMA8 ||
373 chroma < CX18_AV_SVIDEO_CHROMA4 ||
374 chroma > CX18_AV_SVIDEO_CHROMA8) {
375 CX18_ERR("0x%04x is not a valid video input!\n",
379 reg = 0xf0 + ((luma - CX18_AV_SVIDEO_LUMA1) >> 4);
380 if (chroma >= CX18_AV_SVIDEO_CHROMA7) {
382 reg |= (chroma - CX18_AV_SVIDEO_CHROMA7) >> 2;
385 reg |= (chroma - CX18_AV_SVIDEO_CHROMA4) >> 4;
390 case CX18_AV_AUDIO_SERIAL1:
391 case CX18_AV_AUDIO_SERIAL2:
392 /* do nothing, use serial audio input */
394 case CX18_AV_AUDIO4: reg &= ~0x30; break;
395 case CX18_AV_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
396 case CX18_AV_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
397 case CX18_AV_AUDIO7: reg &= ~0xc0; break;
398 case CX18_AV_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
401 CX18_ERR("0x%04x is not a valid audio input!\n", aud_input);
405 cx18_av_write(cx, 0x103, reg);
406 /* Set INPUT_MODE to Composite (0) or S-Video (1) */
407 cx18_av_and_or(cx, 0x401, ~0x6, is_composite ? 0 : 0x02);
408 /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
409 cx18_av_and_or(cx, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
410 /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
411 if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
412 cx18_av_and_or(cx, 0x102, ~0x4, 4);
414 cx18_av_and_or(cx, 0x102, ~0x4, 0);
415 /*cx18_av_and_or4(cx, 0x104, ~0x001b4180, 0x00004180);*/
417 state->vid_input = vid_input;
418 state->aud_input = aud_input;
419 cx18_av_audio_set_path(cx);
424 /* ----------------------------------------------------------------------- */
426 static int set_v4lstd(struct cx18 *cx)
428 struct cx18_av_state *state = &cx->av_state;
429 u8 fmt = 0; /* zero is autodetect */
432 /* First tests should be against specific std */
433 if (state->std == V4L2_STD_NTSC_M_JP) {
435 } else if (state->std == V4L2_STD_NTSC_443) {
437 } else if (state->std == V4L2_STD_PAL_M) {
440 } else if (state->std == V4L2_STD_PAL_N) {
442 } else if (state->std == V4L2_STD_PAL_Nc) {
444 } else if (state->std == V4L2_STD_PAL_60) {
447 /* Then, test against generic ones */
448 if (state->std & V4L2_STD_NTSC)
450 else if (state->std & V4L2_STD_PAL)
452 else if (state->std & V4L2_STD_SECAM)
456 CX18_DEBUG_INFO("changing video std to fmt %i\n", fmt);
458 /* Follow step 9 of section 3.16 in the cx18_av datasheet.
459 Without this PAL may display a vertical ghosting effect.
460 This happens for example with the Yuan MPC622. */
461 if (fmt >= 4 && fmt < 8) {
462 /* Set format to NTSC-M */
463 cx18_av_and_or(cx, 0x400, ~0xf, 1);
465 cx18_av_and_or(cx, 0x47b, ~6, 0);
467 cx18_av_and_or(cx, 0x400, ~0x2f, fmt | 0x20);
468 cx18_av_and_or(cx, 0x403, ~0x3, pal_m);
469 cx18_av_std_setup(cx);
474 /* ----------------------------------------------------------------------- */
476 static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
479 case V4L2_CID_BRIGHTNESS:
480 if (ctrl->value < 0 || ctrl->value > 255) {
481 CX18_ERR("invalid brightness setting %d\n",
486 cx18_av_write(cx, 0x414, ctrl->value - 128);
489 case V4L2_CID_CONTRAST:
490 if (ctrl->value < 0 || ctrl->value > 127) {
491 CX18_ERR("invalid contrast setting %d\n",
496 cx18_av_write(cx, 0x415, ctrl->value << 1);
499 case V4L2_CID_SATURATION:
500 if (ctrl->value < 0 || ctrl->value > 127) {
501 CX18_ERR("invalid saturation setting %d\n",
506 cx18_av_write(cx, 0x420, ctrl->value << 1);
507 cx18_av_write(cx, 0x421, ctrl->value << 1);
511 if (ctrl->value < -127 || ctrl->value > 127) {
512 CX18_ERR("invalid hue setting %d\n", ctrl->value);
516 cx18_av_write(cx, 0x422, ctrl->value);
519 case V4L2_CID_AUDIO_VOLUME:
520 case V4L2_CID_AUDIO_BASS:
521 case V4L2_CID_AUDIO_TREBLE:
522 case V4L2_CID_AUDIO_BALANCE:
523 case V4L2_CID_AUDIO_MUTE:
524 return cx18_av_audio(cx, VIDIOC_S_CTRL, ctrl);
533 static int get_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
536 case V4L2_CID_BRIGHTNESS:
537 ctrl->value = (s8)cx18_av_read(cx, 0x414) + 128;
539 case V4L2_CID_CONTRAST:
540 ctrl->value = cx18_av_read(cx, 0x415) >> 1;
542 case V4L2_CID_SATURATION:
543 ctrl->value = cx18_av_read(cx, 0x420) >> 1;
546 ctrl->value = (s8)cx18_av_read(cx, 0x422);
548 case V4L2_CID_AUDIO_VOLUME:
549 case V4L2_CID_AUDIO_BASS:
550 case V4L2_CID_AUDIO_TREBLE:
551 case V4L2_CID_AUDIO_BALANCE:
552 case V4L2_CID_AUDIO_MUTE:
553 return cx18_av_audio(cx, VIDIOC_G_CTRL, ctrl);
561 /* ----------------------------------------------------------------------- */
563 static int get_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
566 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
567 return cx18_av_vbi(cx, VIDIOC_G_FMT, fmt);
575 static int set_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
577 struct cx18_av_state *state = &cx->av_state;
578 struct v4l2_pix_format *pix;
579 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
580 int is_50Hz = !(state->std & V4L2_STD_525_60);
583 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
584 pix = &(fmt->fmt.pix);
586 Vsrc = (cx18_av_read(cx, 0x476) & 0x3f) << 4;
587 Vsrc |= (cx18_av_read(cx, 0x475) & 0xf0) >> 4;
589 Hsrc = (cx18_av_read(cx, 0x472) & 0x3f) << 4;
590 Hsrc |= (cx18_av_read(cx, 0x471) & 0xf0) >> 4;
592 Vlines = pix->height + (is_50Hz ? 4 : 7);
594 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
595 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
596 CX18_ERR("%dx%d is not a valid size!\n",
597 pix->width, pix->height);
601 HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20);
602 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
605 if (pix->width >= 385)
607 else if (pix->width > 192)
609 else if (pix->width > 96)
614 CX18_DEBUG_INFO("decoder set size %dx%d -> scale %ux%u\n",
615 pix->width, pix->height, HSC, VSC);
618 cx18_av_write(cx, 0x418, HSC & 0xff);
619 cx18_av_write(cx, 0x419, (HSC >> 8) & 0xff);
620 cx18_av_write(cx, 0x41a, HSC >> 16);
622 cx18_av_write(cx, 0x41c, VSC & 0xff);
623 cx18_av_write(cx, 0x41d, VSC >> 8);
624 /* VS_INTRLACE=1 VFILT=filter */
625 cx18_av_write(cx, 0x41e, 0x8 | filter);
628 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
629 return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt);
631 case V4L2_BUF_TYPE_VBI_CAPTURE:
632 return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt);
641 /* ----------------------------------------------------------------------- */
643 int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg)
645 struct cx18_av_state *state = &cx->av_state;
646 struct v4l2_tuner *vt = arg;
647 struct v4l2_routing *route = arg;
649 /* ignore these commands */
651 case TUNER_SET_TYPE_ADDR:
655 if (!state->is_initialized) {
656 CX18_DEBUG_INFO("cmd %08x triggered fw load\n", cmd);
657 /* initialize on first use */
658 state->is_initialized = 1;
659 cx18_av_initialize(cx);
663 case VIDIOC_INT_DECODE_VBI_LINE:
664 return cx18_av_vbi(cx, cmd, arg);
666 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
667 return cx18_av_audio(cx, cmd, arg);
669 case VIDIOC_STREAMON:
670 CX18_DEBUG_INFO("enable output\n");
671 cx18_av_write(cx, 0x115, 0x8c);
672 cx18_av_write(cx, 0x116, 0x07);
675 case VIDIOC_STREAMOFF:
676 CX18_DEBUG_INFO("disable output\n");
677 cx18_av_write(cx, 0x115, 0x00);
678 cx18_av_write(cx, 0x116, 0x00);
681 case VIDIOC_LOG_STATUS:
682 log_video_status(cx);
683 log_audio_status(cx);
687 return get_v4lctrl(cx, (struct v4l2_control *)arg);
690 return set_v4lctrl(cx, (struct v4l2_control *)arg);
692 case VIDIOC_QUERYCTRL:
694 struct v4l2_queryctrl *qc = arg;
697 case V4L2_CID_BRIGHTNESS:
698 case V4L2_CID_CONTRAST:
699 case V4L2_CID_SATURATION:
701 return v4l2_ctrl_query_fill_std(qc);
707 case V4L2_CID_AUDIO_VOLUME:
708 return v4l2_ctrl_query_fill(qc, 0, 65535,
709 65535 / 100, state->default_volume);
710 case V4L2_CID_AUDIO_MUTE:
711 case V4L2_CID_AUDIO_BALANCE:
712 case V4L2_CID_AUDIO_BASS:
713 case V4L2_CID_AUDIO_TREBLE:
714 return v4l2_ctrl_query_fill_std(qc);
722 *(v4l2_std_id *)arg = state->std;
726 if (state->radio == 0 && state->std == *(v4l2_std_id *)arg)
729 state->std = *(v4l2_std_id *)arg;
730 return set_v4lstd(cx);
736 case VIDIOC_INT_G_VIDEO_ROUTING:
737 route->input = state->vid_input;
741 case VIDIOC_INT_S_VIDEO_ROUTING:
742 return set_input(cx, route->input, state->aud_input);
744 case VIDIOC_INT_G_AUDIO_ROUTING:
745 route->input = state->aud_input;
749 case VIDIOC_INT_S_AUDIO_ROUTING:
750 return set_input(cx, state->vid_input, route->input);
752 case VIDIOC_S_FREQUENCY:
758 u8 vpres = cx18_av_read(cx, 0x40e) & 0x20;
765 vt->signal = vpres ? 0xffff : 0x0;
768 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
769 V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
771 mode = cx18_av_read(cx, 0x804);
773 /* get rxsubchans and audmode */
774 if ((mode & 0xf) == 1)
775 val |= V4L2_TUNER_SUB_STEREO;
777 val |= V4L2_TUNER_SUB_MONO;
779 if (mode == 2 || mode == 4)
780 val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
783 val |= V4L2_TUNER_SUB_SAP;
785 vt->rxsubchans = val;
786 vt->audmode = state->audmode;
794 switch (vt->audmode) {
795 case V4L2_TUNER_MODE_MONO:
798 bilingual -> lang1 */
799 cx18_av_and_or(cx, 0x809, ~0xf, 0x00);
801 case V4L2_TUNER_MODE_STEREO:
802 case V4L2_TUNER_MODE_LANG1:
805 bilingual -> lang1 */
806 cx18_av_and_or(cx, 0x809, ~0xf, 0x04);
808 case V4L2_TUNER_MODE_LANG1_LANG2:
811 bilingual -> lang1/lang2 */
812 cx18_av_and_or(cx, 0x809, ~0xf, 0x07);
814 case V4L2_TUNER_MODE_LANG2:
817 bilingual -> lang2 */
818 cx18_av_and_or(cx, 0x809, ~0xf, 0x01);
823 state->audmode = vt->audmode;
827 return get_v4lfmt(cx, (struct v4l2_format *)arg);
830 return set_v4lfmt(cx, (struct v4l2_format *)arg);
832 case VIDIOC_INT_RESET:
833 cx18_av_initialize(cx);
843 /* ----------------------------------------------------------------------- */
845 /* ----------------------------------------------------------------------- */
847 static void log_video_status(struct cx18 *cx)
849 static const char *const fmt_strs[] = {
851 "NTSC-M", "NTSC-J", "NTSC-4.43",
852 "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
858 struct cx18_av_state *state = &cx->av_state;
859 u8 vidfmt_sel = cx18_av_read(cx, 0x400) & 0xf;
860 u8 gen_stat1 = cx18_av_read(cx, 0x40d);
861 u8 gen_stat2 = cx18_av_read(cx, 0x40e);
862 int vid_input = state->vid_input;
864 CX18_INFO("Video signal: %spresent\n",
865 (gen_stat2 & 0x20) ? "" : "not ");
866 CX18_INFO("Detected format: %s\n",
867 fmt_strs[gen_stat1 & 0xf]);
869 CX18_INFO("Specified standard: %s\n",
870 vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
872 if (vid_input >= CX18_AV_COMPOSITE1 &&
873 vid_input <= CX18_AV_COMPOSITE8) {
874 CX18_INFO("Specified video input: Composite %d\n",
875 vid_input - CX18_AV_COMPOSITE1 + 1);
877 CX18_INFO("Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
878 (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
881 CX18_INFO("Specified audioclock freq: %d Hz\n", state->audclk_freq);
884 /* ----------------------------------------------------------------------- */
886 static void log_audio_status(struct cx18 *cx)
888 struct cx18_av_state *state = &cx->av_state;
889 u8 download_ctl = cx18_av_read(cx, 0x803);
890 u8 mod_det_stat0 = cx18_av_read(cx, 0x804);
891 u8 mod_det_stat1 = cx18_av_read(cx, 0x805);
892 u8 audio_config = cx18_av_read(cx, 0x808);
893 u8 pref_mode = cx18_av_read(cx, 0x809);
894 u8 afc0 = cx18_av_read(cx, 0x80b);
895 u8 mute_ctl = cx18_av_read(cx, 0x8d3);
896 int aud_input = state->aud_input;
899 switch (mod_det_stat0) {
900 case 0x00: p = "mono"; break;
901 case 0x01: p = "stereo"; break;
902 case 0x02: p = "dual"; break;
903 case 0x04: p = "tri"; break;
904 case 0x10: p = "mono with SAP"; break;
905 case 0x11: p = "stereo with SAP"; break;
906 case 0x12: p = "dual with SAP"; break;
907 case 0x14: p = "tri with SAP"; break;
908 case 0xfe: p = "forced mode"; break;
909 default: p = "not defined"; break;
911 CX18_INFO("Detected audio mode: %s\n", p);
913 switch (mod_det_stat1) {
914 case 0x00: p = "not defined"; break;
915 case 0x01: p = "EIAJ"; break;
916 case 0x02: p = "A2-M"; break;
917 case 0x03: p = "A2-BG"; break;
918 case 0x04: p = "A2-DK1"; break;
919 case 0x05: p = "A2-DK2"; break;
920 case 0x06: p = "A2-DK3"; break;
921 case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
922 case 0x08: p = "AM-L"; break;
923 case 0x09: p = "NICAM-BG"; break;
924 case 0x0a: p = "NICAM-DK"; break;
925 case 0x0b: p = "NICAM-I"; break;
926 case 0x0c: p = "NICAM-L"; break;
927 case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
928 case 0x0e: p = "IF FM Radio"; break;
929 case 0x0f: p = "BTSC"; break;
930 case 0x10: p = "detected chrominance"; break;
931 case 0xfd: p = "unknown audio standard"; break;
932 case 0xfe: p = "forced audio standard"; break;
933 case 0xff: p = "no detected audio standard"; break;
934 default: p = "not defined"; break;
936 CX18_INFO("Detected audio standard: %s\n", p);
937 CX18_INFO("Audio muted: %s\n",
938 (mute_ctl & 0x2) ? "yes" : "no");
939 CX18_INFO("Audio microcontroller: %s\n",
940 (download_ctl & 0x10) ? "running" : "stopped");
942 switch (audio_config >> 4) {
943 case 0x00: p = "undefined"; break;
944 case 0x01: p = "BTSC"; break;
945 case 0x02: p = "EIAJ"; break;
946 case 0x03: p = "A2-M"; break;
947 case 0x04: p = "A2-BG"; break;
948 case 0x05: p = "A2-DK1"; break;
949 case 0x06: p = "A2-DK2"; break;
950 case 0x07: p = "A2-DK3"; break;
951 case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
952 case 0x09: p = "AM-L"; break;
953 case 0x0a: p = "NICAM-BG"; break;
954 case 0x0b: p = "NICAM-DK"; break;
955 case 0x0c: p = "NICAM-I"; break;
956 case 0x0d: p = "NICAM-L"; break;
957 case 0x0e: p = "FM radio"; break;
958 case 0x0f: p = "automatic detection"; break;
959 default: p = "undefined"; break;
961 CX18_INFO("Configured audio standard: %s\n", p);
963 if ((audio_config >> 4) < 0xF) {
964 switch (audio_config & 0xF) {
965 case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
966 case 0x01: p = "MONO2 (LANGUAGE B)"; break;
967 case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
968 case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
969 case 0x04: p = "STEREO"; break;
970 case 0x05: p = "DUAL1 (AC)"; break;
971 case 0x06: p = "DUAL2 (BC)"; break;
972 case 0x07: p = "DUAL3 (AB)"; break;
973 default: p = "undefined";
975 CX18_INFO("Configured audio mode: %s\n", p);
977 switch (audio_config & 0xF) {
978 case 0x00: p = "BG"; break;
979 case 0x01: p = "DK1"; break;
980 case 0x02: p = "DK2"; break;
981 case 0x03: p = "DK3"; break;
982 case 0x04: p = "I"; break;
983 case 0x05: p = "L"; break;
984 case 0x06: p = "BTSC"; break;
985 case 0x07: p = "EIAJ"; break;
986 case 0x08: p = "A2-M"; break;
987 case 0x09: p = "FM Radio (4.5 MHz)"; break;
988 case 0x0a: p = "FM Radio (5.5 MHz)"; break;
989 case 0x0b: p = "S-Video"; break;
990 case 0x0f: p = "automatic standard and mode detection"; break;
991 default: p = "undefined"; break;
993 CX18_INFO("Configured audio system: %s\n", p);
997 CX18_INFO("Specified audio input: Tuner (In%d)\n",
1000 CX18_INFO("Specified audio input: External\n");
1002 switch (pref_mode & 0xf) {
1003 case 0: p = "mono/language A"; break;
1004 case 1: p = "language B"; break;
1005 case 2: p = "language C"; break;
1006 case 3: p = "analog fallback"; break;
1007 case 4: p = "stereo"; break;
1008 case 5: p = "language AC"; break;
1009 case 6: p = "language BC"; break;
1010 case 7: p = "language AB"; break;
1011 default: p = "undefined"; break;
1013 CX18_INFO("Preferred audio mode: %s\n", p);
1015 if ((audio_config & 0xf) == 0xf) {
1016 switch ((afc0 >> 3) & 0x1) {
1017 case 0: p = "system DK"; break;
1018 case 1: p = "system L"; break;
1020 CX18_INFO("Selected 65 MHz format: %s\n", p);
1022 switch (afc0 & 0x7) {
1023 case 0: p = "Chroma"; break;
1024 case 1: p = "BTSC"; break;
1025 case 2: p = "EIAJ"; break;
1026 case 3: p = "A2-M"; break;
1027 case 4: p = "autodetect"; break;
1028 default: p = "undefined"; break;
1030 CX18_INFO("Selected 45 MHz format: %s\n", p);