2 cx231xx_avcore.c - driver for Conexant Cx23100/101/102
3 USB video capture devices
5 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
7 This program contains the specific code to control the avdecoder chip and
8 other related usb control functions for cx231xx based chipset.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/init.h>
26 #include <linux/list.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/bitmap.h>
30 #include <linux/usb.h>
31 #include <linux/i2c.h>
33 #include <linux/mutex.h>
34 #include <media/tuner.h>
36 #include <media/v4l2-common.h>
37 #include <media/v4l2-ioctl.h>
40 #include "cx231xx-dif.h"
42 #define TUNER_MODE_FM_RADIO 0
43 /******************************************************************************
44 -: BLOCK ARRANGEMENT :-
45 I2S block ----------------------|
48 Analog Front End --> Direct IF -|-> Cx25840 --> Audio
49 [video & audio] | [Audio]
54 *******************************************************************************/
55 /******************************************************************************
58 ******************************************************************************/
59 static int verve_write_byte(struct cx231xx *dev, u8 saddr, u8 data)
61 return cx231xx_write_i2c_data(dev, VERVE_I2C_ADDRESS,
65 static int verve_read_byte(struct cx231xx *dev, u8 saddr, u8 *data)
70 status = cx231xx_read_i2c_data(dev, VERVE_I2C_ADDRESS,
75 void initGPIO(struct cx231xx *dev)
77 u32 _gpio_direction = 0;
81 _gpio_direction = _gpio_direction & 0xFC0003FF;
82 _gpio_direction = _gpio_direction | 0x03FDFC00;
83 cx231xx_send_gpio_cmd(dev, _gpio_direction, (u8 *)&value, 4, 0, 0);
85 verve_read_byte(dev, 0x07, &val);
86 cx231xx_info(" verve_read_byte address0x07=0x%x\n", val);
87 verve_write_byte(dev, 0x07, 0xF4);
88 verve_read_byte(dev, 0x07, &val);
89 cx231xx_info(" verve_read_byte address0x07=0x%x\n", val);
91 cx231xx_capture_start(dev, 1, Vbi);
93 cx231xx_mode_register(dev, EP_MODE_SET, 0x0500FE00);
94 cx231xx_mode_register(dev, GBULK_BIT_EN, 0xFFFDFFFF);
97 void uninitGPIO(struct cx231xx *dev)
99 u8 value[4] = { 0, 0, 0, 0 };
101 cx231xx_capture_start(dev, 0, Vbi);
102 verve_write_byte(dev, 0x07, 0x14);
103 cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
107 /******************************************************************************
108 * A F E - B L O C K C O N T R O L functions *
109 * [ANALOG FRONT END] *
110 ******************************************************************************/
111 static int afe_write_byte(struct cx231xx *dev, u16 saddr, u8 data)
113 return cx231xx_write_i2c_data(dev, AFE_DEVICE_ADDRESS,
117 static int afe_read_byte(struct cx231xx *dev, u16 saddr, u8 *data)
122 status = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
128 int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count)
132 u8 afe_power_status = 0;
135 /* super block initialize */
136 temp = (u8) (ref_count & 0xff);
137 status = afe_write_byte(dev, SUP_BLK_TUNE2, temp);
141 status = afe_read_byte(dev, SUP_BLK_TUNE2, &afe_power_status);
145 temp = (u8) ((ref_count & 0x300) >> 8);
147 status = afe_write_byte(dev, SUP_BLK_TUNE1, temp);
151 status = afe_write_byte(dev, SUP_BLK_PLL2, 0x0f);
156 while (afe_power_status != 0x18) {
157 status = afe_write_byte(dev, SUP_BLK_PWRDN, 0x18);
160 ": Init Super Block failed in send cmd\n");
164 status = afe_read_byte(dev, SUP_BLK_PWRDN, &afe_power_status);
165 afe_power_status &= 0xff;
168 ": Init Super Block failed in receive cmd\n");
174 ": Init Super Block force break in loop !!!!\n");
183 /* start tuning filter */
184 status = afe_write_byte(dev, SUP_BLK_TUNE3, 0x40);
191 status = afe_write_byte(dev, SUP_BLK_TUNE3, 0x00);
196 int cx231xx_afe_init_channels(struct cx231xx *dev)
200 /* power up all 3 channels, clear pd_buffer */
201 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, 0x00);
202 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, 0x00);
203 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, 0x00);
205 /* Enable quantizer calibration */
206 status = afe_write_byte(dev, ADC_COM_QUANT, 0x02);
208 /* channel initialize, force modulator (fb) reset */
209 status = afe_write_byte(dev, ADC_FB_FRCRST_CH1, 0x17);
210 status = afe_write_byte(dev, ADC_FB_FRCRST_CH2, 0x17);
211 status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, 0x17);
213 /* start quantilizer calibration */
214 status = afe_write_byte(dev, ADC_CAL_ATEST_CH1, 0x10);
215 status = afe_write_byte(dev, ADC_CAL_ATEST_CH2, 0x10);
216 status = afe_write_byte(dev, ADC_CAL_ATEST_CH3, 0x10);
219 /* exit modulator (fb) reset */
220 status = afe_write_byte(dev, ADC_FB_FRCRST_CH1, 0x07);
221 status = afe_write_byte(dev, ADC_FB_FRCRST_CH2, 0x07);
222 status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, 0x07);
224 /* enable the pre_clamp in each channel for single-ended input */
225 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH1, 0xf0);
226 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH2, 0xf0);
227 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH3, 0xf0);
229 /* use diode instead of resistor, so set term_en to 0, res_en to 0 */
230 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
231 ADC_QGAIN_RES_TRM_CH1, 3, 7, 0x00);
232 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
233 ADC_QGAIN_RES_TRM_CH2, 3, 7, 0x00);
234 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
235 ADC_QGAIN_RES_TRM_CH3, 3, 7, 0x00);
237 /* dynamic element matching off */
238 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH1, 0x03);
239 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH2, 0x03);
240 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH3, 0x03);
245 int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev)
250 status = afe_read_byte(dev, ADC_PWRDN_CLAMP_CH2, &c_value);
251 c_value &= (~(0x50));
252 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, c_value);
258 The Analog Front End in Cx231xx has 3 channels. These
259 channels are used to share between different inputs
260 like tuner, s-video and composite inputs.
262 channel 1 ----- pin 1 to pin4(in reg is 1-4)
263 channel 2 ----- pin 5 to pin8(in reg is 5-8)
264 channel 3 ----- pin 9 to pin 12(in reg is 9-11)
266 int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux)
268 u8 ch1_setting = (u8) input_mux;
269 u8 ch2_setting = (u8) (input_mux >> 8);
270 u8 ch3_setting = (u8) (input_mux >> 16);
274 if (ch1_setting != 0) {
275 status = afe_read_byte(dev, ADC_INPUT_CH1, &value);
276 value &= ~INPUT_SEL_MASK;
277 value |= (ch1_setting - 1) << 4;
279 status = afe_write_byte(dev, ADC_INPUT_CH1, value);
282 if (ch2_setting != 0) {
283 status = afe_read_byte(dev, ADC_INPUT_CH2, &value);
284 value &= ~INPUT_SEL_MASK;
285 value |= (ch2_setting - 1) << 4;
287 status = afe_write_byte(dev, ADC_INPUT_CH2, value);
290 /* For ch3_setting, the value to put in the register is
291 7 less than the input number */
292 if (ch3_setting != 0) {
293 status = afe_read_byte(dev, ADC_INPUT_CH3, &value);
294 value &= ~INPUT_SEL_MASK;
295 value |= (ch3_setting - 1) << 4;
297 status = afe_write_byte(dev, ADC_INPUT_CH3, value);
303 int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode)
308 * FIXME: We need to implement the AFE code for LOW IF and for HI IF.
309 * Currently, only baseband works.
313 case AFE_MODE_LOW_IF:
314 cx231xx_Setup_AFE_for_LowIF(dev);
316 case AFE_MODE_BASEBAND:
317 status = cx231xx_afe_setup_AFE_for_baseband(dev);
319 case AFE_MODE_EU_HI_IF:
320 /* SetupAFEforEuHiIF(); */
322 case AFE_MODE_US_HI_IF:
323 /* SetupAFEforUsHiIF(); */
325 case AFE_MODE_JAPAN_HI_IF:
326 /* SetupAFEforJapanHiIF(); */
330 if ((mode != dev->afe_mode) &&
331 (dev->video_input == CX231XX_VMUX_TELEVISION))
332 status = cx231xx_afe_adjust_ref_count(dev,
333 CX231XX_VMUX_TELEVISION);
335 dev->afe_mode = mode;
340 int cx231xx_afe_update_power_control(struct cx231xx *dev,
343 u8 afe_power_status = 0;
346 switch (dev->model) {
347 case CX231XX_BOARD_CNXT_CARRAERA:
348 case CX231XX_BOARD_CNXT_RDE_250:
349 case CX231XX_BOARD_CNXT_SHELBY:
350 case CX231XX_BOARD_CNXT_RDU_250:
351 case CX231XX_BOARD_CNXT_RDE_253S:
352 case CX231XX_BOARD_CNXT_RDU_253S:
353 case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
354 case CX231XX_BOARD_HAUPPAUGE_EXETER:
355 case CX231XX_BOARD_HAUPPAUGE_USBLIVE2:
356 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
357 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL:
358 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC:
359 case CX231XX_BOARD_OTG102:
360 if (avmode == POLARIS_AVMODE_ANALOGT_TV) {
361 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
362 FLD_PWRDN_ENABLE_PLL)) {
363 status = afe_write_byte(dev, SUP_BLK_PWRDN,
364 FLD_PWRDN_TUNING_BIAS |
365 FLD_PWRDN_ENABLE_PLL);
366 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
372 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
374 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
376 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
378 } else if (avmode == POLARIS_AVMODE_DIGITAL) {
379 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
381 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
383 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
386 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
388 afe_power_status |= FLD_PWRDN_PD_BANDGAP |
391 status |= afe_write_byte(dev, SUP_BLK_PWRDN,
393 } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) {
394 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
395 FLD_PWRDN_ENABLE_PLL)) {
396 status = afe_write_byte(dev, SUP_BLK_PWRDN,
397 FLD_PWRDN_TUNING_BIAS |
398 FLD_PWRDN_ENABLE_PLL);
399 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
405 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
407 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
409 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
412 cx231xx_info("Invalid AV mode input\n");
417 if (avmode == POLARIS_AVMODE_ANALOGT_TV) {
418 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
419 FLD_PWRDN_ENABLE_PLL)) {
420 status = afe_write_byte(dev, SUP_BLK_PWRDN,
421 FLD_PWRDN_TUNING_BIAS |
422 FLD_PWRDN_ENABLE_PLL);
423 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
429 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
431 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
433 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
435 } else if (avmode == POLARIS_AVMODE_DIGITAL) {
436 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
438 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
440 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
443 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
445 afe_power_status |= FLD_PWRDN_PD_BANDGAP |
448 status |= afe_write_byte(dev, SUP_BLK_PWRDN,
450 } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) {
451 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
452 FLD_PWRDN_ENABLE_PLL)) {
453 status = afe_write_byte(dev, SUP_BLK_PWRDN,
454 FLD_PWRDN_TUNING_BIAS |
455 FLD_PWRDN_ENABLE_PLL);
456 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
462 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
464 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
466 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
469 cx231xx_info("Invalid AV mode input\n");
477 int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input)
483 dev->video_input = video_input;
485 if (video_input == CX231XX_VMUX_TELEVISION) {
486 status = afe_read_byte(dev, ADC_INPUT_CH3, &input_mode);
487 status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH3,
490 status = afe_read_byte(dev, ADC_INPUT_CH1, &input_mode);
491 status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH1,
495 input_mode = (ntf_mode & 0x3) | ((input_mode & 0x6) << 1);
497 switch (input_mode) {
499 dev->afe_ref_count = 0x23C;
502 dev->afe_ref_count = 0x24C;
505 dev->afe_ref_count = 0x258;
508 dev->afe_ref_count = 0x260;
514 status = cx231xx_afe_init_super_block(dev, dev->afe_ref_count);
519 /******************************************************************************
520 * V I D E O / A U D I O D E C O D E R C O N T R O L functions *
521 ******************************************************************************/
522 static int vid_blk_write_byte(struct cx231xx *dev, u16 saddr, u8 data)
524 return cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS,
528 static int vid_blk_read_byte(struct cx231xx *dev, u16 saddr, u8 *data)
533 status = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
539 static int vid_blk_write_word(struct cx231xx *dev, u16 saddr, u32 data)
541 return cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS,
545 static int vid_blk_read_word(struct cx231xx *dev, u16 saddr, u32 *data)
547 return cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
550 int cx231xx_check_fw(struct cx231xx *dev)
554 status = vid_blk_read_byte(dev, DL_CTL_ADDRESS_LOW, &temp);
562 int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input)
566 switch (INPUT(input)->type) {
567 case CX231XX_VMUX_COMPOSITE1:
568 case CX231XX_VMUX_SVIDEO:
569 if ((dev->current_pcb_config.type == USB_BUS_POWER) &&
570 (dev->power_mode != POLARIS_AVMODE_ENXTERNAL_AV)) {
572 status = cx231xx_set_power_mode(dev,
573 POLARIS_AVMODE_ENXTERNAL_AV);
575 cx231xx_errdev("%s: set_power_mode : Failed to"
576 " set Power - errCode [%d]!\n",
581 status = cx231xx_set_decoder_video_input(dev,
585 case CX231XX_VMUX_TELEVISION:
586 case CX231XX_VMUX_CABLE:
587 if ((dev->current_pcb_config.type == USB_BUS_POWER) &&
588 (dev->power_mode != POLARIS_AVMODE_ANALOGT_TV)) {
590 status = cx231xx_set_power_mode(dev,
591 POLARIS_AVMODE_ANALOGT_TV);
593 cx231xx_errdev("%s: set_power_mode:Failed"
594 " to set Power - errCode [%d]!\n",
599 if (dev->tuner_type == TUNER_NXP_TDA18271)
600 status = cx231xx_set_decoder_video_input(dev,
601 CX231XX_VMUX_TELEVISION,
604 status = cx231xx_set_decoder_video_input(dev,
605 CX231XX_VMUX_COMPOSITE1,
610 cx231xx_errdev("%s: set_power_mode : Unknown Input %d !\n",
611 __func__, INPUT(input)->type);
615 /* save the selection */
616 dev->video_input = input;
621 int cx231xx_set_decoder_video_input(struct cx231xx *dev,
622 u8 pin_type, u8 input)
627 if (pin_type != dev->video_input) {
628 status = cx231xx_afe_adjust_ref_count(dev, pin_type);
630 cx231xx_errdev("%s: adjust_ref_count :Failed to set"
631 "AFE input mux - errCode [%d]!\n",
637 /* call afe block to set video inputs */
638 status = cx231xx_afe_set_input_mux(dev, input);
640 cx231xx_errdev("%s: set_input_mux :Failed to set"
641 " AFE input mux - errCode [%d]!\n",
647 case CX231XX_VMUX_COMPOSITE1:
648 status = vid_blk_read_word(dev, AFE_CTRL, &value);
649 value |= (0 << 13) | (1 << 4);
652 /* set [24:23] [22:15] to 0 */
653 value &= (~(0x1ff8000));
654 /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */
656 status = vid_blk_write_word(dev, AFE_CTRL, value);
658 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
660 status = vid_blk_write_word(dev, OUT_CTRL1, value);
662 /* Set output mode */
663 status = cx231xx_read_modify_write_i2c_dword(dev,
667 dev->board.output_mode);
669 /* Tell DIF object to go to baseband mode */
670 status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND);
672 cx231xx_errdev("%s: cx231xx_dif set to By pass"
673 " mode- errCode [%d]!\n",
678 /* Read the DFE_CTRL1 register */
679 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
681 /* enable the VBI_GATE_EN */
682 value |= FLD_VBI_GATE_EN;
684 /* Enable the auto-VGA enable */
685 value |= FLD_VGA_AUTO_EN;
688 status = vid_blk_write_word(dev, DFE_CTRL1, value);
690 /* Disable auto config of registers */
691 status = cx231xx_read_modify_write_i2c_dword(dev,
693 MODE_CTRL, FLD_ACFG_DIS,
694 cx231xx_set_field(FLD_ACFG_DIS, 1));
696 /* Set CVBS input mode */
697 status = cx231xx_read_modify_write_i2c_dword(dev,
699 MODE_CTRL, FLD_INPUT_MODE,
700 cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_CVBS_0));
702 case CX231XX_VMUX_SVIDEO:
703 /* Disable the use of DIF */
705 status = vid_blk_read_word(dev, AFE_CTRL, &value);
707 /* set [24:23] [22:15] to 0 */
708 value &= (~(0x1ff8000));
709 /* set FUNC_MODE[24:23] = 2
710 IF_MOD[22:15] = 0 DCR_BYP_CH2[4:4] = 1; */
712 status = vid_blk_write_word(dev, AFE_CTRL, value);
714 /* Tell DIF object to go to baseband mode */
715 status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND);
717 cx231xx_errdev("%s: cx231xx_dif set to By pass"
718 " mode- errCode [%d]!\n",
723 /* Read the DFE_CTRL1 register */
724 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
726 /* enable the VBI_GATE_EN */
727 value |= FLD_VBI_GATE_EN;
729 /* Enable the auto-VGA enable */
730 value |= FLD_VGA_AUTO_EN;
733 status = vid_blk_write_word(dev, DFE_CTRL1, value);
735 /* Disable auto config of registers */
736 status = cx231xx_read_modify_write_i2c_dword(dev,
738 MODE_CTRL, FLD_ACFG_DIS,
739 cx231xx_set_field(FLD_ACFG_DIS, 1));
741 /* Set YC input mode */
742 status = cx231xx_read_modify_write_i2c_dword(dev,
746 cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_YC_1));
749 status = vid_blk_read_word(dev, AFE_CTRL, &value);
750 value |= FLD_CHROMA_IN_SEL; /* set the chroma in select */
752 /* Clear VGA_SEL_CH2 and VGA_SEL_CH3 (bits 7 and 8)
753 This sets them to use video
754 rather than audio. Only one of the two will be in use. */
755 value &= ~(FLD_VGA_SEL_CH2 | FLD_VGA_SEL_CH3);
757 status = vid_blk_write_word(dev, AFE_CTRL, value);
759 status = cx231xx_afe_set_mode(dev, AFE_MODE_BASEBAND);
761 case CX231XX_VMUX_TELEVISION:
762 case CX231XX_VMUX_CABLE:
764 /* TODO: Test if this is also needed for xc2028/xc3028 */
765 if (dev->board.tuner_type == TUNER_XC5000) {
766 /* Disable the use of DIF */
768 status = vid_blk_read_word(dev, AFE_CTRL, &value);
769 value |= (0 << 13) | (1 << 4);
772 /* set [24:23] [22:15] to 0 */
773 value &= (~(0x1FF8000));
774 /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */
776 status = vid_blk_write_word(dev, AFE_CTRL, value);
778 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
780 status = vid_blk_write_word(dev, OUT_CTRL1, value);
782 /* Set output mode */
783 status = cx231xx_read_modify_write_i2c_dword(dev,
785 OUT_CTRL1, FLD_OUT_MODE,
786 dev->board.output_mode);
788 /* Tell DIF object to go to baseband mode */
789 status = cx231xx_dif_set_standard(dev,
792 cx231xx_errdev("%s: cx231xx_dif set to By pass"
793 " mode- errCode [%d]!\n",
798 /* Read the DFE_CTRL1 register */
799 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
801 /* enable the VBI_GATE_EN */
802 value |= FLD_VBI_GATE_EN;
804 /* Enable the auto-VGA enable */
805 value |= FLD_VGA_AUTO_EN;
808 status = vid_blk_write_word(dev, DFE_CTRL1, value);
810 /* Disable auto config of registers */
811 status = cx231xx_read_modify_write_i2c_dword(dev,
813 MODE_CTRL, FLD_ACFG_DIS,
814 cx231xx_set_field(FLD_ACFG_DIS, 1));
816 /* Set CVBS input mode */
817 status = cx231xx_read_modify_write_i2c_dword(dev,
819 MODE_CTRL, FLD_INPUT_MODE,
820 cx231xx_set_field(FLD_INPUT_MODE,
823 /* Enable the DIF for the tuner */
825 /* Reinitialize the DIF */
826 status = cx231xx_dif_set_standard(dev, dev->norm);
828 cx231xx_errdev("%s: cx231xx_dif set to By pass"
829 " mode- errCode [%d]!\n",
834 /* Make sure bypass is cleared */
835 status = vid_blk_read_word(dev, DIF_MISC_CTRL, &value);
837 /* Clear the bypass bit */
838 value &= ~FLD_DIF_DIF_BYPASS;
840 /* Enable the use of the DIF block */
841 status = vid_blk_write_word(dev, DIF_MISC_CTRL, value);
843 /* Read the DFE_CTRL1 register */
844 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
846 /* Disable the VBI_GATE_EN */
847 value &= ~FLD_VBI_GATE_EN;
849 /* Enable the auto-VGA enable, AGC, and
850 set the skip count to 2 */
851 value |= FLD_VGA_AUTO_EN | FLD_AGC_AUTO_EN | 0x00200000;
854 status = vid_blk_write_word(dev, DFE_CTRL1, value);
856 /* Wait until AGC locks up */
859 /* Disable the auto-VGA enable AGC */
860 value &= ~(FLD_VGA_AUTO_EN);
863 status = vid_blk_write_word(dev, DFE_CTRL1, value);
865 /* Enable Polaris B0 AGC output */
866 status = vid_blk_read_word(dev, PIN_CTRL, &value);
867 value |= (FLD_OEF_AGC_RF) |
868 (FLD_OEF_AGC_IFVGA) |
870 status = vid_blk_write_word(dev, PIN_CTRL, value);
872 /* Set output mode */
873 status = cx231xx_read_modify_write_i2c_dword(dev,
875 OUT_CTRL1, FLD_OUT_MODE,
876 dev->board.output_mode);
878 /* Disable auto config of registers */
879 status = cx231xx_read_modify_write_i2c_dword(dev,
881 MODE_CTRL, FLD_ACFG_DIS,
882 cx231xx_set_field(FLD_ACFG_DIS, 1));
884 /* Set CVBS input mode */
885 status = cx231xx_read_modify_write_i2c_dword(dev,
887 MODE_CTRL, FLD_INPUT_MODE,
888 cx231xx_set_field(FLD_INPUT_MODE,
891 /* Set some bits in AFE_CTRL so that channel 2 or 3
892 * is ready to receive audio */
893 /* Clear clamp for channels 2 and 3 (bit 16-17) */
894 /* Clear droop comp (bit 19-20) */
895 /* Set VGA_SEL (for audio control) (bit 7-8) */
896 status = vid_blk_read_word(dev, AFE_CTRL, &value);
898 /*Set Func mode:01-DIF 10-baseband 11-YUV*/
899 value &= (~(FLD_FUNC_MODE));
902 value |= FLD_VGA_SEL_CH3 | FLD_VGA_SEL_CH2;
904 status = vid_blk_write_word(dev, AFE_CTRL, value);
906 if (dev->tuner_type == TUNER_NXP_TDA18271) {
907 status = vid_blk_read_word(dev, PIN_CTRL,
909 status = vid_blk_write_word(dev, PIN_CTRL,
910 (value & 0xFFFFFFEF));
919 /* Set raw VBI mode */
920 status = cx231xx_read_modify_write_i2c_dword(dev,
922 OUT_CTRL1, FLD_VBIHACTRAW_EN,
923 cx231xx_set_field(FLD_VBIHACTRAW_EN, 1));
925 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
928 status = vid_blk_write_word(dev, OUT_CTRL1, value);
934 void cx231xx_enable656(struct cx231xx *dev)
937 /*enable TS1 data[0:7] as output to export 656*/
939 vid_blk_write_byte(dev, TS1_PIN_CTL0, 0xFF);
941 /*enable TS1 clock as output to export 656*/
943 vid_blk_read_byte(dev, TS1_PIN_CTL1, &temp);
946 vid_blk_write_byte(dev, TS1_PIN_CTL1, temp);
948 EXPORT_SYMBOL_GPL(cx231xx_enable656);
950 void cx231xx_disable656(struct cx231xx *dev)
954 vid_blk_write_byte(dev, TS1_PIN_CTL0, 0x00);
956 vid_blk_read_byte(dev, TS1_PIN_CTL1, &temp);
959 vid_blk_write_byte(dev, TS1_PIN_CTL1, temp);
961 EXPORT_SYMBOL_GPL(cx231xx_disable656);
964 * Handle any video-mode specific overrides that are different
965 * on a per video standards basis after touching the MODE_CTRL
966 * register which resets many values for autodetect
968 int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev)
972 cx231xx_info("do_mode_ctrl_overrides : 0x%x\n",
973 (unsigned int)dev->norm);
975 /* Change the DFE_CTRL3 bp_percent to fix flagging */
976 status = vid_blk_write_word(dev, DFE_CTRL3, 0xCD3F0280);
978 if (dev->norm & (V4L2_STD_NTSC | V4L2_STD_PAL_M)) {
979 cx231xx_info("do_mode_ctrl_overrides NTSC\n");
981 /* Move the close caption lines out of active video,
982 adjust the active video start point */
983 status = cx231xx_read_modify_write_i2c_dword(dev,
986 FLD_VBLANK_CNT, 0x18);
987 status = cx231xx_read_modify_write_i2c_dword(dev,
992 status = cx231xx_read_modify_write_i2c_dword(dev,
998 status = cx231xx_read_modify_write_i2c_dword(dev,
1003 (FLD_HBLANK_CNT, 0x79));
1005 } else if (dev->norm & V4L2_STD_SECAM) {
1006 cx231xx_info("do_mode_ctrl_overrides SECAM\n");
1007 status = cx231xx_read_modify_write_i2c_dword(dev,
1008 VID_BLK_I2C_ADDRESS,
1010 FLD_VBLANK_CNT, 0x20);
1011 status = cx231xx_read_modify_write_i2c_dword(dev,
1012 VID_BLK_I2C_ADDRESS,
1018 status = cx231xx_read_modify_write_i2c_dword(dev,
1019 VID_BLK_I2C_ADDRESS,
1025 /* Adjust the active video horizontal start point */
1026 status = cx231xx_read_modify_write_i2c_dword(dev,
1027 VID_BLK_I2C_ADDRESS,
1031 (FLD_HBLANK_CNT, 0x85));
1033 cx231xx_info("do_mode_ctrl_overrides PAL\n");
1034 status = cx231xx_read_modify_write_i2c_dword(dev,
1035 VID_BLK_I2C_ADDRESS,
1037 FLD_VBLANK_CNT, 0x20);
1038 status = cx231xx_read_modify_write_i2c_dword(dev,
1039 VID_BLK_I2C_ADDRESS,
1045 status = cx231xx_read_modify_write_i2c_dword(dev,
1046 VID_BLK_I2C_ADDRESS,
1052 /* Adjust the active video horizontal start point */
1053 status = cx231xx_read_modify_write_i2c_dword(dev,
1054 VID_BLK_I2C_ADDRESS,
1058 (FLD_HBLANK_CNT, 0x85));
1065 int cx231xx_unmute_audio(struct cx231xx *dev)
1067 return vid_blk_write_byte(dev, PATH1_VOL_CTL, 0x24);
1069 EXPORT_SYMBOL_GPL(cx231xx_unmute_audio);
1071 static int stopAudioFirmware(struct cx231xx *dev)
1073 return vid_blk_write_byte(dev, DL_CTL_CONTROL, 0x03);
1076 static int restartAudioFirmware(struct cx231xx *dev)
1078 return vid_blk_write_byte(dev, DL_CTL_CONTROL, 0x13);
1081 int cx231xx_set_audio_input(struct cx231xx *dev, u8 input)
1084 enum AUDIO_INPUT ainput = AUDIO_INPUT_LINE;
1086 switch (INPUT(input)->amux) {
1087 case CX231XX_AMUX_VIDEO:
1088 ainput = AUDIO_INPUT_TUNER_TV;
1090 case CX231XX_AMUX_LINE_IN:
1091 status = cx231xx_i2s_blk_set_audio_input(dev, input);
1092 ainput = AUDIO_INPUT_LINE;
1098 status = cx231xx_set_audio_decoder_input(dev, ainput);
1103 int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
1104 enum AUDIO_INPUT audio_input)
1111 /* Put it in soft reset */
1112 status = vid_blk_read_byte(dev, GENERAL_CTL, &gen_ctrl);
1114 status = vid_blk_write_byte(dev, GENERAL_CTL, gen_ctrl);
1116 switch (audio_input) {
1117 case AUDIO_INPUT_LINE:
1118 /* setup AUD_IO control from Merlin paralle output */
1119 value = cx231xx_set_field(FLD_AUD_CHAN1_SRC,
1120 AUD_CHAN_SRC_PARALLEL);
1121 status = vid_blk_write_word(dev, AUD_IO_CTRL, value);
1123 /* setup input to Merlin, SRC2 connect to AC97
1124 bypass upsample-by-2, slave mode, sony mode, left justify
1125 adr 091c, dat 01000000 */
1126 status = vid_blk_read_word(dev, AC97_CTL, &dwval);
1128 status = vid_blk_write_word(dev, AC97_CTL,
1129 (dwval | FLD_AC97_UP2X_BYPASS));
1131 /* select the parallel1 and SRC3 */
1132 status = vid_blk_write_word(dev, BAND_OUT_SEL,
1133 cx231xx_set_field(FLD_SRC3_IN_SEL, 0x0) |
1134 cx231xx_set_field(FLD_SRC3_CLK_SEL, 0x0) |
1135 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x0));
1137 /* unmute all, AC97 in, independence mode
1138 adr 08d0, data 0x00063073 */
1139 status = vid_blk_write_word(dev, DL_CTL, 0x3000001);
1140 status = vid_blk_write_word(dev, PATH1_CTL1, 0x00063073);
1142 /* set AVC maximum threshold, adr 08d4, dat ffff0024 */
1143 status = vid_blk_read_word(dev, PATH1_VOL_CTL, &dwval);
1144 status = vid_blk_write_word(dev, PATH1_VOL_CTL,
1145 (dwval | FLD_PATH1_AVC_THRESHOLD));
1147 /* set SC maximum threshold, adr 08ec, dat ffffb3a3 */
1148 status = vid_blk_read_word(dev, PATH1_SC_CTL, &dwval);
1149 status = vid_blk_write_word(dev, PATH1_SC_CTL,
1150 (dwval | FLD_PATH1_SC_THRESHOLD));
1153 case AUDIO_INPUT_TUNER_TV:
1155 status = stopAudioFirmware(dev);
1156 /* Setup SRC sources and clocks */
1157 status = vid_blk_write_word(dev, BAND_OUT_SEL,
1158 cx231xx_set_field(FLD_SRC6_IN_SEL, 0x00) |
1159 cx231xx_set_field(FLD_SRC6_CLK_SEL, 0x01) |
1160 cx231xx_set_field(FLD_SRC5_IN_SEL, 0x00) |
1161 cx231xx_set_field(FLD_SRC5_CLK_SEL, 0x02) |
1162 cx231xx_set_field(FLD_SRC4_IN_SEL, 0x02) |
1163 cx231xx_set_field(FLD_SRC4_CLK_SEL, 0x03) |
1164 cx231xx_set_field(FLD_SRC3_IN_SEL, 0x00) |
1165 cx231xx_set_field(FLD_SRC3_CLK_SEL, 0x00) |
1166 cx231xx_set_field(FLD_BASEBAND_BYPASS_CTL, 0x00) |
1167 cx231xx_set_field(FLD_AC97_SRC_SEL, 0x03) |
1168 cx231xx_set_field(FLD_I2S_SRC_SEL, 0x00) |
1169 cx231xx_set_field(FLD_PARALLEL2_SRC_SEL, 0x02) |
1170 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x01));
1172 /* Setup the AUD_IO control */
1173 status = vid_blk_write_word(dev, AUD_IO_CTRL,
1174 cx231xx_set_field(FLD_I2S_PORT_DIR, 0x00) |
1175 cx231xx_set_field(FLD_I2S_OUT_SRC, 0x00) |
1176 cx231xx_set_field(FLD_AUD_CHAN3_SRC, 0x00) |
1177 cx231xx_set_field(FLD_AUD_CHAN2_SRC, 0x00) |
1178 cx231xx_set_field(FLD_AUD_CHAN1_SRC, 0x03));
1180 status = vid_blk_write_word(dev, PATH1_CTL1, 0x1F063870);
1182 /* setAudioStandard(_audio_standard); */
1183 status = vid_blk_write_word(dev, PATH1_CTL1, 0x00063870);
1185 status = restartAudioFirmware(dev);
1187 switch (dev->board.tuner_type) {
1189 /* SIF passthrough at 28.6363 MHz sample rate */
1190 status = cx231xx_read_modify_write_i2c_dword(dev,
1191 VID_BLK_I2C_ADDRESS,
1194 cx231xx_set_field(FLD_SIF_EN, 1));
1196 case TUNER_NXP_TDA18271:
1197 /* Normal mode: SIF passthrough at 14.32 MHz */
1198 status = cx231xx_read_modify_write_i2c_dword(dev,
1199 VID_BLK_I2C_ADDRESS,
1202 cx231xx_set_field(FLD_SIF_EN, 0));
1205 /* This is just a casual suggestion to people adding
1206 new boards in case they use a tuner type we don't
1207 currently know about */
1208 printk(KERN_INFO "Unknown tuner type configuring SIF");
1213 case AUDIO_INPUT_TUNER_FM:
1214 /* use SIF for FM radio
1216 setAudioStandard(_audio_standard);
1220 case AUDIO_INPUT_MUTE:
1221 status = vid_blk_write_word(dev, PATH1_CTL1, 0x1F011012);
1225 /* Take it out of soft reset */
1226 status = vid_blk_read_byte(dev, GENERAL_CTL, &gen_ctrl);
1228 status = vid_blk_write_byte(dev, GENERAL_CTL, gen_ctrl);
1233 /******************************************************************************
1234 * C H I P Specific C O N T R O L functions *
1235 ******************************************************************************/
1236 int cx231xx_init_ctrl_pin_status(struct cx231xx *dev)
1241 status = vid_blk_read_word(dev, PIN_CTRL, &value);
1242 value |= (~dev->board.ctl_pin_status_mask);
1243 status = vid_blk_write_word(dev, PIN_CTRL, value);
1248 int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
1249 u8 analog_or_digital)
1253 /* first set the direction to output */
1254 status = cx231xx_set_gpio_direction(dev,
1256 agc_analog_digital_select_gpio, 1);
1258 /* 0 - demod ; 1 - Analog mode */
1259 status = cx231xx_set_gpio_value(dev,
1260 dev->board.agc_analog_digital_select_gpio,
1266 int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3)
1268 u8 value[4] = { 0, 0, 0, 0 };
1270 bool current_is_port_3;
1272 if (dev->board.dont_use_port_3)
1274 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
1275 PWR_CTL_EN, value, 4);
1279 current_is_port_3 = value[0] & I2C_DEMOD_EN ? true : false;
1281 /* Just return, if already using the right port */
1282 if (current_is_port_3 == is_port_3)
1286 value[0] |= I2C_DEMOD_EN;
1288 value[0] &= ~I2C_DEMOD_EN;
1290 cx231xx_info("Changing the i2c master port to %d\n",
1293 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1294 PWR_CTL_EN, value, 4);
1299 EXPORT_SYMBOL_GPL(cx231xx_enable_i2c_port_3);
1301 void update_HH_register_after_set_DIF(struct cx231xx *dev)
1307 vid_blk_write_word(dev, PIN_CTRL, 0xA0FFF82F);
1308 vid_blk_write_word(dev, DIF_MISC_CTRL, 0x0A203F11);
1309 vid_blk_write_word(dev, DIF_SRC_PHASE_INC, 0x1BEFBF06);
1311 status = vid_blk_read_word(dev, AFE_CTRL_C2HH_SRC_CTRL, &value);
1312 vid_blk_write_word(dev, AFE_CTRL_C2HH_SRC_CTRL, 0x4485D390);
1313 status = vid_blk_read_word(dev, AFE_CTRL_C2HH_SRC_CTRL, &value);
1317 void cx231xx_dump_HH_reg(struct cx231xx *dev)
1323 vid_blk_write_word(dev, 0x104, value);
1325 for (i = 0x100; i < 0x140; i++) {
1326 vid_blk_read_word(dev, i, &value);
1327 cx231xx_info("reg0x%x=0x%x\n", i, value);
1331 for (i = 0x300; i < 0x400; i++) {
1332 vid_blk_read_word(dev, i, &value);
1333 cx231xx_info("reg0x%x=0x%x\n", i, value);
1337 for (i = 0x400; i < 0x440; i++) {
1338 vid_blk_read_word(dev, i, &value);
1339 cx231xx_info("reg0x%x=0x%x\n", i, value);
1343 vid_blk_read_word(dev, AFE_CTRL_C2HH_SRC_CTRL, &value);
1344 cx231xx_info("AFE_CTRL_C2HH_SRC_CTRL=0x%x\n", value);
1345 vid_blk_write_word(dev, AFE_CTRL_C2HH_SRC_CTRL, 0x4485D390);
1346 vid_blk_read_word(dev, AFE_CTRL_C2HH_SRC_CTRL, &value);
1347 cx231xx_info("AFE_CTRL_C2HH_SRC_CTRL=0x%x\n", value);
1350 void cx231xx_dump_SC_reg(struct cx231xx *dev)
1352 u8 value[4] = { 0, 0, 0, 0 };
1353 cx231xx_info("cx231xx_dump_SC_reg!\n");
1355 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, BOARD_CFG_STAT,
1357 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", BOARD_CFG_STAT, value[0],
1358 value[1], value[2], value[3]);
1359 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS_MODE_REG,
1361 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS_MODE_REG, value[0],
1362 value[1], value[2], value[3]);
1363 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS1_CFG_REG,
1365 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS1_CFG_REG, value[0],
1366 value[1], value[2], value[3]);
1367 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS1_LENGTH_REG,
1369 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS1_LENGTH_REG, value[0],
1370 value[1], value[2], value[3]);
1372 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS2_CFG_REG,
1374 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS2_CFG_REG, value[0],
1375 value[1], value[2], value[3]);
1376 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS2_LENGTH_REG,
1378 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS2_LENGTH_REG, value[0],
1379 value[1], value[2], value[3]);
1380 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET,
1382 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", EP_MODE_SET, value[0],
1383 value[1], value[2], value[3]);
1384 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_PTN1,
1386 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN1, value[0],
1387 value[1], value[2], value[3]);
1389 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_PTN2,
1391 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN2, value[0],
1392 value[1], value[2], value[3]);
1393 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_PTN3,
1395 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN3, value[0],
1396 value[1], value[2], value[3]);
1397 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_MASK0,
1399 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK0, value[0],
1400 value[1], value[2], value[3]);
1401 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_MASK1,
1403 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK1, value[0],
1404 value[1], value[2], value[3]);
1406 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_MASK2,
1408 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK2, value[0],
1409 value[1], value[2], value[3]);
1410 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_GAIN,
1412 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_GAIN, value[0],
1413 value[1], value[2], value[3]);
1414 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_CAR_REG,
1416 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_CAR_REG, value[0],
1417 value[1], value[2], value[3]);
1418 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_OT_CFG1,
1420 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_OT_CFG1, value[0],
1421 value[1], value[2], value[3]);
1423 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_OT_CFG2,
1425 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_OT_CFG2, value[0],
1426 value[1], value[2], value[3]);
1427 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN,
1429 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", PWR_CTL_EN, value[0],
1430 value[1], value[2], value[3]);
1435 void cx231xx_Setup_AFE_for_LowIF(struct cx231xx *dev)
1440 afe_read_byte(dev, ADC_STATUS2_CH3, &value);
1441 value = (value & 0xFE)|0x01;
1442 afe_write_byte(dev, ADC_STATUS2_CH3, value);
1444 afe_read_byte(dev, ADC_STATUS2_CH3, &value);
1445 value = (value & 0xFE)|0x00;
1446 afe_write_byte(dev, ADC_STATUS2_CH3, value);
1450 config colibri to lo-if mode
1452 FIXME: ntf_mode = 2'b00 by default. But set 0x1 would reduce
1453 the diff IF input by half,
1455 for low-if agc defect
1458 afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH3, &value);
1459 value = (value & 0xFC)|0x00;
1460 afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH3, value);
1462 afe_read_byte(dev, ADC_INPUT_CH3, &value);
1463 value = (value & 0xF9)|0x02;
1464 afe_write_byte(dev, ADC_INPUT_CH3, value);
1466 afe_read_byte(dev, ADC_FB_FRCRST_CH3, &value);
1467 value = (value & 0xFB)|0x04;
1468 afe_write_byte(dev, ADC_FB_FRCRST_CH3, value);
1470 afe_read_byte(dev, ADC_DCSERVO_DEM_CH3, &value);
1471 value = (value & 0xFC)|0x03;
1472 afe_write_byte(dev, ADC_DCSERVO_DEM_CH3, value);
1474 afe_read_byte(dev, ADC_CTRL_DAC1_CH3, &value);
1475 value = (value & 0xFB)|0x04;
1476 afe_write_byte(dev, ADC_CTRL_DAC1_CH3, value);
1478 afe_read_byte(dev, ADC_CTRL_DAC23_CH3, &value);
1479 value = (value & 0xF8)|0x06;
1480 afe_write_byte(dev, ADC_CTRL_DAC23_CH3, value);
1482 afe_read_byte(dev, ADC_CTRL_DAC23_CH3, &value);
1483 value = (value & 0x8F)|0x40;
1484 afe_write_byte(dev, ADC_CTRL_DAC23_CH3, value);
1486 afe_read_byte(dev, ADC_PWRDN_CLAMP_CH3, &value);
1487 value = (value & 0xDF)|0x20;
1488 afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, value);
1491 void cx231xx_set_Colibri_For_LowIF(struct cx231xx *dev, u32 if_freq,
1492 u8 spectral_invert, u32 mode)
1494 u32 colibri_carrier_offset = 0;
1495 u32 func_mode = 0x01; /* Device has a DIF if this function is called */
1497 u8 value[4] = { 0, 0, 0, 0 };
1499 cx231xx_info("Enter cx231xx_set_Colibri_For_LowIF()\n");
1500 value[0] = (u8) 0x6F;
1501 value[1] = (u8) 0x6F;
1502 value[2] = (u8) 0x6F;
1503 value[3] = (u8) 0x6F;
1504 cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1505 PWR_CTL_EN, value, 4);
1507 /*Set colibri for low IF*/
1508 cx231xx_afe_set_mode(dev, AFE_MODE_LOW_IF);
1510 /* Set C2HH for low IF operation.*/
1511 standard = dev->norm;
1512 cx231xx_dif_configure_C2HH_for_low_IF(dev, dev->active_mode,
1513 func_mode, standard);
1515 /* Get colibri offsets.*/
1516 colibri_carrier_offset = cx231xx_Get_Colibri_CarrierOffset(mode,
1519 cx231xx_info("colibri_carrier_offset=%d, standard=0x%x\n",
1520 colibri_carrier_offset, standard);
1522 /* Set the band Pass filter for DIF*/
1523 cx231xx_set_DIF_bandpass(dev, (if_freq+colibri_carrier_offset),
1524 spectral_invert, mode);
1527 u32 cx231xx_Get_Colibri_CarrierOffset(u32 mode, u32 standerd)
1529 u32 colibri_carrier_offset = 0;
1531 if (mode == TUNER_MODE_FM_RADIO) {
1532 colibri_carrier_offset = 1100000;
1533 } else if (standerd & (V4L2_STD_MN | V4L2_STD_NTSC_M_JP)) {
1534 colibri_carrier_offset = 4832000; /*4.83MHz */
1535 } else if (standerd & (V4L2_STD_PAL_B | V4L2_STD_PAL_G)) {
1536 colibri_carrier_offset = 2700000; /*2.70MHz */
1537 } else if (standerd & (V4L2_STD_PAL_D | V4L2_STD_PAL_I
1538 | V4L2_STD_SECAM)) {
1539 colibri_carrier_offset = 2100000; /*2.10MHz */
1542 return colibri_carrier_offset;
1545 void cx231xx_set_DIF_bandpass(struct cx231xx *dev, u32 if_freq,
1546 u8 spectral_invert, u32 mode)
1548 unsigned long pll_freq_word;
1549 u32 dif_misc_ctrl_value = 0;
1550 u64 pll_freq_u64 = 0;
1553 cx231xx_info("if_freq=%d;spectral_invert=0x%x;mode=0x%x\n",
1554 if_freq, spectral_invert, mode);
1557 if (mode == TUNER_MODE_FM_RADIO) {
1558 pll_freq_word = 0x905A1CAC;
1559 vid_blk_write_word(dev, DIF_PLL_FREQ_WORD, pll_freq_word);
1561 } else /*KSPROPERTY_TUNER_MODE_TV*/{
1562 /* Calculate the PLL frequency word based on the adjusted if_freq*/
1563 pll_freq_word = if_freq;
1564 pll_freq_u64 = (u64)pll_freq_word << 28L;
1565 do_div(pll_freq_u64, 50000000);
1566 pll_freq_word = (u32)pll_freq_u64;
1567 /*pll_freq_word = 0x3463497;*/
1568 vid_blk_write_word(dev, DIF_PLL_FREQ_WORD, pll_freq_word);
1570 if (spectral_invert) {
1572 /* Enable Spectral Invert*/
1573 vid_blk_read_word(dev, DIF_MISC_CTRL,
1574 &dif_misc_ctrl_value);
1575 dif_misc_ctrl_value = dif_misc_ctrl_value | 0x00200000;
1576 vid_blk_write_word(dev, DIF_MISC_CTRL,
1577 dif_misc_ctrl_value);
1580 /* Disable Spectral Invert*/
1581 vid_blk_read_word(dev, DIF_MISC_CTRL,
1582 &dif_misc_ctrl_value);
1583 dif_misc_ctrl_value = dif_misc_ctrl_value & 0xFFDFFFFF;
1584 vid_blk_write_word(dev, DIF_MISC_CTRL,
1585 dif_misc_ctrl_value);
1588 if_freq = (if_freq/100000)*100000;
1590 if (if_freq < 3000000)
1593 if (if_freq > 16000000)
1597 cx231xx_info("Enter IF=%zd\n",
1598 ARRAY_SIZE(Dif_set_array));
1599 for (i = 0; i < ARRAY_SIZE(Dif_set_array); i++) {
1600 if (Dif_set_array[i].if_freq == if_freq) {
1601 vid_blk_write_word(dev,
1602 Dif_set_array[i].register_address, Dif_set_array[i].value);
1607 /******************************************************************************
1608 * D I F - B L O C K C O N T R O L functions *
1609 ******************************************************************************/
1610 int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
1611 u32 function_mode, u32 standard)
1616 if (mode == V4L2_TUNER_RADIO) {
1618 /* lo if big signal */
1619 status = cx231xx_reg_mask_write(dev,
1620 VID_BLK_I2C_ADDRESS, 32,
1621 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1622 /* FUNC_MODE = DIF */
1623 status = cx231xx_reg_mask_write(dev,
1624 VID_BLK_I2C_ADDRESS, 32,
1625 AFE_CTRL_C2HH_SRC_CTRL, 23, 24, function_mode);
1627 status = cx231xx_reg_mask_write(dev,
1628 VID_BLK_I2C_ADDRESS, 32,
1629 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xFF);
1631 status = cx231xx_reg_mask_write(dev,
1632 VID_BLK_I2C_ADDRESS, 32,
1633 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1634 } else if (standard != DIF_USE_BASEBAND) {
1635 if (standard & V4L2_STD_MN) {
1636 /* lo if big signal */
1637 status = cx231xx_reg_mask_write(dev,
1638 VID_BLK_I2C_ADDRESS, 32,
1639 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1640 /* FUNC_MODE = DIF */
1641 status = cx231xx_reg_mask_write(dev,
1642 VID_BLK_I2C_ADDRESS, 32,
1643 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1646 status = cx231xx_reg_mask_write(dev,
1647 VID_BLK_I2C_ADDRESS, 32,
1648 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xb);
1650 status = cx231xx_reg_mask_write(dev,
1651 VID_BLK_I2C_ADDRESS, 32,
1652 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1653 /* 0x124, AUD_CHAN1_SRC = 0x3 */
1654 status = cx231xx_reg_mask_write(dev,
1655 VID_BLK_I2C_ADDRESS, 32,
1656 AUD_IO_CTRL, 0, 31, 0x00000003);
1657 } else if ((standard == V4L2_STD_PAL_I) |
1658 (standard & V4L2_STD_PAL_D) |
1659 (standard & V4L2_STD_SECAM)) {
1661 /* lo if big signal */
1662 status = cx231xx_reg_mask_write(dev,
1663 VID_BLK_I2C_ADDRESS, 32,
1664 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1665 /* FUNC_MODE = DIF */
1666 status = cx231xx_reg_mask_write(dev,
1667 VID_BLK_I2C_ADDRESS, 32,
1668 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1671 status = cx231xx_reg_mask_write(dev,
1672 VID_BLK_I2C_ADDRESS, 32,
1673 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xF);
1675 status = cx231xx_reg_mask_write(dev,
1676 VID_BLK_I2C_ADDRESS, 32,
1677 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1679 /* default PAL BG */
1681 /* lo if big signal */
1682 status = cx231xx_reg_mask_write(dev,
1683 VID_BLK_I2C_ADDRESS, 32,
1684 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1685 /* FUNC_MODE = DIF */
1686 status = cx231xx_reg_mask_write(dev,
1687 VID_BLK_I2C_ADDRESS, 32,
1688 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1691 status = cx231xx_reg_mask_write(dev,
1692 VID_BLK_I2C_ADDRESS, 32,
1693 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xE);
1695 status = cx231xx_reg_mask_write(dev,
1696 VID_BLK_I2C_ADDRESS, 32,
1697 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1704 int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard)
1707 u32 dif_misc_ctrl_value = 0;
1710 cx231xx_info("%s: setStandard to %x\n", __func__, standard);
1712 status = vid_blk_read_word(dev, DIF_MISC_CTRL, &dif_misc_ctrl_value);
1713 if (standard != DIF_USE_BASEBAND)
1714 dev->norm = standard;
1716 switch (dev->model) {
1717 case CX231XX_BOARD_CNXT_CARRAERA:
1718 case CX231XX_BOARD_CNXT_RDE_250:
1719 case CX231XX_BOARD_CNXT_SHELBY:
1720 case CX231XX_BOARD_CNXT_RDU_250:
1721 case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
1722 case CX231XX_BOARD_HAUPPAUGE_EXETER:
1723 case CX231XX_BOARD_OTG102:
1726 case CX231XX_BOARD_CNXT_RDE_253S:
1727 case CX231XX_BOARD_CNXT_RDU_253S:
1728 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL:
1729 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC:
1736 status = cx231xx_dif_configure_C2HH_for_low_IF(dev, dev->active_mode,
1737 func_mode, standard);
1739 if (standard == DIF_USE_BASEBAND) { /* base band */
1740 /* There is a different SRC_PHASE_INC value
1741 for baseband vs. DIF */
1742 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC, 0xDF7DF83);
1743 status = vid_blk_read_word(dev, DIF_MISC_CTRL,
1744 &dif_misc_ctrl_value);
1745 dif_misc_ctrl_value |= FLD_DIF_DIF_BYPASS;
1746 status = vid_blk_write_word(dev, DIF_MISC_CTRL,
1747 dif_misc_ctrl_value);
1748 } else if (standard & V4L2_STD_PAL_D) {
1749 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1750 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1751 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1752 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1753 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1754 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1755 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1756 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1757 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1758 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
1759 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1760 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
1761 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1762 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
1763 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1764 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
1765 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1766 DIF_AGC_IF_INT_CURRENT, 0, 31,
1768 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1769 DIF_AGC_RF_CURRENT, 0, 31,
1771 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1772 DIF_VIDEO_AGC_CTRL, 0, 31,
1774 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1775 DIF_VID_AUD_OVERRIDE, 0, 31,
1777 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1778 DIF_AV_SEP_CTRL, 0, 31, 0x3F3934EA);
1779 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1780 DIF_COMP_FLT_CTRL, 0, 31,
1782 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1783 DIF_SRC_PHASE_INC, 0, 31,
1785 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1786 DIF_SRC_GAIN_CONTROL, 0, 31,
1788 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1789 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1790 /* Save the Spec Inversion value */
1791 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1792 dif_misc_ctrl_value |= 0x3a023F11;
1793 } else if (standard & V4L2_STD_PAL_I) {
1794 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1795 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1796 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1797 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1798 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1799 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1800 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1801 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1802 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1803 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
1804 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1805 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
1806 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1807 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
1808 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1809 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
1810 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1811 DIF_AGC_IF_INT_CURRENT, 0, 31,
1813 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1814 DIF_AGC_RF_CURRENT, 0, 31,
1816 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1817 DIF_VIDEO_AGC_CTRL, 0, 31,
1819 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1820 DIF_VID_AUD_OVERRIDE, 0, 31,
1822 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1823 DIF_AV_SEP_CTRL, 0, 31, 0x5F39A934);
1824 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1825 DIF_COMP_FLT_CTRL, 0, 31,
1827 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1828 DIF_SRC_PHASE_INC, 0, 31,
1830 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1831 DIF_SRC_GAIN_CONTROL, 0, 31,
1833 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1834 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1835 /* Save the Spec Inversion value */
1836 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1837 dif_misc_ctrl_value |= 0x3a033F11;
1838 } else if (standard & V4L2_STD_PAL_M) {
1839 /* improved Low Frequency Phase Noise */
1840 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0xFF01FF0C);
1841 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xbd038c85);
1842 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1db4640a);
1843 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
1844 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C1380);
1845 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
1847 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
1849 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
1851 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
1853 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, 0x012c405d);
1854 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
1856 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
1858 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
1860 status = vid_blk_write_word(dev, DIF_SOFT_RST_CTRL_REVB,
1862 /* Save the Spec Inversion value */
1863 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1864 dif_misc_ctrl_value |= 0x3A0A3F10;
1865 } else if (standard & (V4L2_STD_PAL_N | V4L2_STD_PAL_Nc)) {
1866 /* improved Low Frequency Phase Noise */
1867 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0xFF01FF0C);
1868 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xbd038c85);
1869 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1db4640a);
1870 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
1871 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C1380);
1872 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
1874 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
1876 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
1878 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
1880 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL,
1882 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
1884 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
1886 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
1888 status = vid_blk_write_word(dev, DIF_SOFT_RST_CTRL_REVB,
1890 /* Save the Spec Inversion value */
1891 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1892 dif_misc_ctrl_value = 0x3A093F10;
1893 } else if (standard &
1894 (V4L2_STD_SECAM_B | V4L2_STD_SECAM_D | V4L2_STD_SECAM_G |
1895 V4L2_STD_SECAM_K | V4L2_STD_SECAM_K1)) {
1897 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1898 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1899 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1900 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1901 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1902 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1903 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1904 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1905 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1906 DIF_AGC_IF_REF, 0, 31, 0x888C0380);
1907 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1908 DIF_AGC_CTRL_IF, 0, 31, 0xe0262600);
1909 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1910 DIF_AGC_CTRL_INT, 0, 31, 0xc2171700);
1911 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1912 DIF_AGC_CTRL_RF, 0, 31, 0xc2262600);
1913 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1914 DIF_AGC_IF_INT_CURRENT, 0, 31,
1916 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1917 DIF_AGC_RF_CURRENT, 0, 31,
1919 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1920 DIF_VID_AUD_OVERRIDE, 0, 31,
1922 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1923 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec);
1924 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1925 DIF_COMP_FLT_CTRL, 0, 31,
1927 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1928 DIF_SRC_PHASE_INC, 0, 31,
1930 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1931 DIF_SRC_GAIN_CONTROL, 0, 31,
1933 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1934 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1935 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1936 DIF_VIDEO_AGC_CTRL, 0, 31,
1939 /* Save the Spec Inversion value */
1940 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1941 dif_misc_ctrl_value |= 0x3a023F11;
1942 } else if (standard & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) {
1943 /* Is it SECAM_L1? */
1944 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1945 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1946 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1947 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1948 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1949 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1950 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1951 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1952 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1953 DIF_AGC_IF_REF, 0, 31, 0x888C0380);
1954 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1955 DIF_AGC_CTRL_IF, 0, 31, 0xe0262600);
1956 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1957 DIF_AGC_CTRL_INT, 0, 31, 0xc2171700);
1958 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1959 DIF_AGC_CTRL_RF, 0, 31, 0xc2262600);
1960 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1961 DIF_AGC_IF_INT_CURRENT, 0, 31,
1963 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1964 DIF_AGC_RF_CURRENT, 0, 31,
1966 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1967 DIF_VID_AUD_OVERRIDE, 0, 31,
1969 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1970 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec);
1971 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1972 DIF_COMP_FLT_CTRL, 0, 31,
1974 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1975 DIF_SRC_PHASE_INC, 0, 31,
1977 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1978 DIF_SRC_GAIN_CONTROL, 0, 31,
1980 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1981 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1982 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1983 DIF_VIDEO_AGC_CTRL, 0, 31,
1986 /* Save the Spec Inversion value */
1987 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1988 dif_misc_ctrl_value |= 0x3a023F11;
1990 } else if (standard & V4L2_STD_NTSC_M) {
1991 /* V4L2_STD_NTSC_M (75 IRE Setup) Or
1992 V4L2_STD_NTSC_M_JP (Japan, 0 IRE Setup) */
1994 /* For NTSC the centre frequency of video coming out of
1995 sidewinder is around 7.1MHz or 3.6MHz depending on the
1996 spectral inversion. so for a non spectrally inverted channel
1997 the pll freq word is 0x03420c49
2000 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0x6503BC0C);
2001 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xBD038C85);
2002 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1DB4640A);
2003 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
2004 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C0380);
2005 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
2007 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
2009 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
2011 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
2013 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, 0x01296e1f);
2015 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
2017 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
2019 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
2022 status = vid_blk_write_word(dev, DIF_AGC_CTRL_IF, 0xC2262600);
2023 status = vid_blk_write_word(dev, DIF_AGC_CTRL_INT,
2025 status = vid_blk_write_word(dev, DIF_AGC_CTRL_RF, 0xC2262600);
2027 /* Save the Spec Inversion value */
2028 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
2029 dif_misc_ctrl_value |= 0x3a003F10;
2031 /* default PAL BG */
2032 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2033 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
2034 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2035 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
2036 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2037 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
2038 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2039 DIF_PLL_CTRL3, 0, 31, 0x00008800);
2040 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2041 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
2042 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2043 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
2044 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2045 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
2046 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2047 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
2048 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2049 DIF_AGC_IF_INT_CURRENT, 0, 31,
2051 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2052 DIF_AGC_RF_CURRENT, 0, 31,
2054 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2055 DIF_VIDEO_AGC_CTRL, 0, 31,
2057 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2058 DIF_VID_AUD_OVERRIDE, 0, 31,
2060 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2061 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530EC);
2062 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2063 DIF_COMP_FLT_CTRL, 0, 31,
2065 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2066 DIF_SRC_PHASE_INC, 0, 31,
2068 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2069 DIF_SRC_GAIN_CONTROL, 0, 31,
2071 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2072 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
2073 /* Save the Spec Inversion value */
2074 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
2075 dif_misc_ctrl_value |= 0x3a013F11;
2078 /* The AGC values should be the same for all standards,
2079 AUD_SRC_SEL[19] should always be disabled */
2080 dif_misc_ctrl_value &= ~FLD_DIF_AUD_SRC_SEL;
2082 /* It is still possible to get Set Standard calls even when we
2084 This is done to override the value for FM. */
2085 if (dev->active_mode == V4L2_TUNER_RADIO)
2086 dif_misc_ctrl_value = 0x7a080000;
2088 /* Write the calculated value for misc ontrol register */
2089 status = vid_blk_write_word(dev, DIF_MISC_CTRL, dif_misc_ctrl_value);
2094 int cx231xx_tuner_pre_channel_change(struct cx231xx *dev)
2099 /* Set the RF and IF k_agc values to 3 */
2100 status = vid_blk_read_word(dev, DIF_AGC_IF_REF, &dwval);
2101 dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF);
2102 dwval |= 0x33000000;
2104 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval);
2109 int cx231xx_tuner_post_channel_change(struct cx231xx *dev)
2113 cx231xx_info("cx231xx_tuner_post_channel_change dev->tuner_type =0%d\n",
2115 /* Set the RF and IF k_agc values to 4 for PAL/NTSC and 8 for
2116 * SECAM L/B/D standards */
2117 status = vid_blk_read_word(dev, DIF_AGC_IF_REF, &dwval);
2118 dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF);
2120 if (dev->norm & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_B |
2121 V4L2_STD_SECAM_D)) {
2122 if (dev->tuner_type == TUNER_NXP_TDA18271) {
2123 dwval &= ~FLD_DIF_IF_REF;
2124 dwval |= 0x88000300;
2126 dwval |= 0x88000000;
2128 if (dev->tuner_type == TUNER_NXP_TDA18271) {
2129 dwval &= ~FLD_DIF_IF_REF;
2130 dwval |= 0xCC000300;
2132 dwval |= 0x44000000;
2135 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval);
2137 return status == sizeof(dwval) ? 0 : -EIO;
2140 /******************************************************************************
2141 * I 2 S - B L O C K C O N T R O L functions *
2142 ******************************************************************************/
2143 int cx231xx_i2s_blk_initialize(struct cx231xx *dev)
2148 status = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2149 CH_PWR_CTRL1, 1, &value, 1);
2150 /* enables clock to delta-sigma and decimation filter */
2152 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2153 CH_PWR_CTRL1, 1, value, 1);
2154 /* power up all channel */
2155 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2156 CH_PWR_CTRL2, 1, 0x00, 1);
2161 int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev,
2162 enum AV_MODE avmode)
2167 if (avmode != POLARIS_AVMODE_ENXTERNAL_AV) {
2168 status = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2169 CH_PWR_CTRL2, 1, &value, 1);
2171 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2172 CH_PWR_CTRL2, 1, value, 1);
2174 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2175 CH_PWR_CTRL2, 1, 0x00, 1);
2181 /* set i2s_blk for audio input types */
2182 int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input)
2186 switch (audio_input) {
2187 case CX231XX_AMUX_LINE_IN:
2188 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2189 CH_PWR_CTRL2, 1, 0x00, 1);
2190 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2191 CH_PWR_CTRL1, 1, 0x80, 1);
2193 case CX231XX_AMUX_VIDEO:
2198 dev->ctl_ainput = audio_input;
2203 /******************************************************************************
2204 * P O W E R C O N T R O L functions *
2205 ******************************************************************************/
2206 int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode)
2208 u8 value[4] = { 0, 0, 0, 0 };
2212 if (dev->power_mode != mode)
2213 dev->power_mode = mode;
2215 cx231xx_info(" setPowerMode::mode = %d, No Change req.\n",
2220 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value,
2225 tmp = le32_to_cpu(*((u32 *) value));
2228 case POLARIS_AVMODE_ENXTERNAL_AV:
2230 tmp &= (~PWR_MODE_MASK);
2233 value[0] = (u8) tmp;
2234 value[1] = (u8) (tmp >> 8);
2235 value[2] = (u8) (tmp >> 16);
2236 value[3] = (u8) (tmp >> 24);
2237 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2238 PWR_CTL_EN, value, 4);
2239 msleep(PWR_SLEEP_INTERVAL);
2242 value[0] = (u8) tmp;
2243 value[1] = (u8) (tmp >> 8);
2244 value[2] = (u8) (tmp >> 16);
2245 value[3] = (u8) (tmp >> 24);
2247 cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, PWR_CTL_EN,
2249 msleep(PWR_SLEEP_INTERVAL);
2251 tmp |= POLARIS_AVMODE_ENXTERNAL_AV;
2252 value[0] = (u8) tmp;
2253 value[1] = (u8) (tmp >> 8);
2254 value[2] = (u8) (tmp >> 16);
2255 value[3] = (u8) (tmp >> 24);
2256 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2257 PWR_CTL_EN, value, 4);
2259 /* reset state of xceive tuner */
2260 dev->xc_fw_load_done = 0;
2263 case POLARIS_AVMODE_ANALOGT_TV:
2265 tmp |= PWR_DEMOD_EN;
2266 tmp |= (I2C_DEMOD_EN);
2267 value[0] = (u8) tmp;
2268 value[1] = (u8) (tmp >> 8);
2269 value[2] = (u8) (tmp >> 16);
2270 value[3] = (u8) (tmp >> 24);
2271 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2272 PWR_CTL_EN, value, 4);
2273 msleep(PWR_SLEEP_INTERVAL);
2275 if (!(tmp & PWR_TUNER_EN)) {
2276 tmp |= (PWR_TUNER_EN);
2277 value[0] = (u8) tmp;
2278 value[1] = (u8) (tmp >> 8);
2279 value[2] = (u8) (tmp >> 16);
2280 value[3] = (u8) (tmp >> 24);
2281 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2282 PWR_CTL_EN, value, 4);
2283 msleep(PWR_SLEEP_INTERVAL);
2286 if (!(tmp & PWR_AV_EN)) {
2288 value[0] = (u8) tmp;
2289 value[1] = (u8) (tmp >> 8);
2290 value[2] = (u8) (tmp >> 16);
2291 value[3] = (u8) (tmp >> 24);
2292 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2293 PWR_CTL_EN, value, 4);
2294 msleep(PWR_SLEEP_INTERVAL);
2296 if (!(tmp & PWR_ISO_EN)) {
2298 value[0] = (u8) tmp;
2299 value[1] = (u8) (tmp >> 8);
2300 value[2] = (u8) (tmp >> 16);
2301 value[3] = (u8) (tmp >> 24);
2302 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2303 PWR_CTL_EN, value, 4);
2304 msleep(PWR_SLEEP_INTERVAL);
2307 if (!(tmp & POLARIS_AVMODE_ANALOGT_TV)) {
2308 tmp |= POLARIS_AVMODE_ANALOGT_TV;
2309 value[0] = (u8) tmp;
2310 value[1] = (u8) (tmp >> 8);
2311 value[2] = (u8) (tmp >> 16);
2312 value[3] = (u8) (tmp >> 24);
2313 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2314 PWR_CTL_EN, value, 4);
2315 msleep(PWR_SLEEP_INTERVAL);
2318 if (dev->board.tuner_type != TUNER_ABSENT) {
2320 cx231xx_enable_i2c_port_3(dev, true);
2322 /* reset the Tuner */
2323 if (dev->board.tuner_gpio)
2324 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
2326 if (dev->cx231xx_reset_analog_tuner)
2327 dev->cx231xx_reset_analog_tuner(dev);
2332 case POLARIS_AVMODE_DIGITAL:
2333 if (!(tmp & PWR_TUNER_EN)) {
2334 tmp |= (PWR_TUNER_EN);
2335 value[0] = (u8) tmp;
2336 value[1] = (u8) (tmp >> 8);
2337 value[2] = (u8) (tmp >> 16);
2338 value[3] = (u8) (tmp >> 24);
2339 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2340 PWR_CTL_EN, value, 4);
2341 msleep(PWR_SLEEP_INTERVAL);
2343 if (!(tmp & PWR_AV_EN)) {
2345 value[0] = (u8) tmp;
2346 value[1] = (u8) (tmp >> 8);
2347 value[2] = (u8) (tmp >> 16);
2348 value[3] = (u8) (tmp >> 24);
2349 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2350 PWR_CTL_EN, value, 4);
2351 msleep(PWR_SLEEP_INTERVAL);
2353 if (!(tmp & PWR_ISO_EN)) {
2355 value[0] = (u8) tmp;
2356 value[1] = (u8) (tmp >> 8);
2357 value[2] = (u8) (tmp >> 16);
2358 value[3] = (u8) (tmp >> 24);
2359 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2360 PWR_CTL_EN, value, 4);
2361 msleep(PWR_SLEEP_INTERVAL);
2364 tmp &= (~PWR_AV_MODE);
2365 tmp |= POLARIS_AVMODE_DIGITAL | I2C_DEMOD_EN;
2366 value[0] = (u8) tmp;
2367 value[1] = (u8) (tmp >> 8);
2368 value[2] = (u8) (tmp >> 16);
2369 value[3] = (u8) (tmp >> 24);
2370 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2371 PWR_CTL_EN, value, 4);
2372 msleep(PWR_SLEEP_INTERVAL);
2374 if (!(tmp & PWR_DEMOD_EN)) {
2375 tmp |= PWR_DEMOD_EN;
2376 value[0] = (u8) tmp;
2377 value[1] = (u8) (tmp >> 8);
2378 value[2] = (u8) (tmp >> 16);
2379 value[3] = (u8) (tmp >> 24);
2380 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2381 PWR_CTL_EN, value, 4);
2382 msleep(PWR_SLEEP_INTERVAL);
2385 if (dev->board.tuner_type != TUNER_ABSENT) {
2388 * Hauppauge Exeter seems to need to do something different!
2390 if (dev->model == CX231XX_BOARD_HAUPPAUGE_EXETER)
2391 cx231xx_enable_i2c_port_3(dev, false);
2393 cx231xx_enable_i2c_port_3(dev, true);
2395 /* reset the Tuner */
2396 if (dev->board.tuner_gpio)
2397 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
2399 if (dev->cx231xx_reset_analog_tuner)
2400 dev->cx231xx_reset_analog_tuner(dev);
2408 msleep(PWR_SLEEP_INTERVAL);
2410 /* For power saving, only enable Pwr_resetout_n
2411 when digital TV is selected. */
2412 if (mode == POLARIS_AVMODE_DIGITAL) {
2413 tmp |= PWR_RESETOUT_EN;
2414 value[0] = (u8) tmp;
2415 value[1] = (u8) (tmp >> 8);
2416 value[2] = (u8) (tmp >> 16);
2417 value[3] = (u8) (tmp >> 24);
2418 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2419 PWR_CTL_EN, value, 4);
2420 msleep(PWR_SLEEP_INTERVAL);
2423 /* update power control for afe */
2424 status = cx231xx_afe_update_power_control(dev, mode);
2426 /* update power control for i2s_blk */
2427 status = cx231xx_i2s_blk_update_power_control(dev, mode);
2429 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value,
2435 int cx231xx_power_suspend(struct cx231xx *dev)
2437 u8 value[4] = { 0, 0, 0, 0 };
2441 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN,
2446 tmp = le32_to_cpu(*((u32 *) value));
2447 tmp &= (~PWR_MODE_MASK);
2449 value[0] = (u8) tmp;
2450 value[1] = (u8) (tmp >> 8);
2451 value[2] = (u8) (tmp >> 16);
2452 value[3] = (u8) (tmp >> 24);
2453 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, PWR_CTL_EN,
2459 /******************************************************************************
2460 * S T R E A M C O N T R O L functions *
2461 ******************************************************************************/
2462 int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask)
2464 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
2468 cx231xx_info("cx231xx_start_stream():: ep_mask = %x\n", ep_mask);
2469 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET,
2474 tmp = le32_to_cpu(*((u32 *) value));
2476 value[0] = (u8) tmp;
2477 value[1] = (u8) (tmp >> 8);
2478 value[2] = (u8) (tmp >> 16);
2479 value[3] = (u8) (tmp >> 24);
2481 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, EP_MODE_SET,
2487 int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask)
2489 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
2493 cx231xx_info("cx231xx_stop_stream():: ep_mask = %x\n", ep_mask);
2495 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET, value, 4);
2499 tmp = le32_to_cpu(*((u32 *) value));
2501 value[0] = (u8) tmp;
2502 value[1] = (u8) (tmp >> 8);
2503 value[2] = (u8) (tmp >> 16);
2504 value[3] = (u8) (tmp >> 24);
2506 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, EP_MODE_SET,
2512 int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type)
2516 u8 val[4] = { 0, 0, 0, 0 };
2518 if (dev->udev->speed == USB_SPEED_HIGH) {
2519 switch (media_type) {
2521 cx231xx_info("%s: Audio enter HANC\n", __func__);
2523 cx231xx_mode_register(dev, TS_MODE_REG, 0x9300);
2527 cx231xx_info("%s: set vanc registers\n", __func__);
2528 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x300);
2532 cx231xx_info("%s: set hanc registers\n", __func__);
2534 cx231xx_mode_register(dev, TS_MODE_REG, 0x1300);
2538 cx231xx_info("%s: set video registers\n", __func__);
2539 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x100);
2542 case TS1_serial_mode:
2543 cx231xx_info("%s: set ts1 registers", __func__);
2545 if (dev->board.has_417) {
2546 cx231xx_info(" MPEG\n");
2547 value &= 0xFFFFFFFC;
2550 status = cx231xx_mode_register(dev, TS_MODE_REG, value);
2556 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2557 TS1_CFG_REG, val, 4);
2563 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2564 TS1_LENGTH_REG, val, 4);
2567 cx231xx_info(" BDA\n");
2568 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x101);
2569 status = cx231xx_mode_register(dev, TS1_CFG_REG, 0x010);
2573 case TS1_parallel_mode:
2574 cx231xx_info("%s: set ts1 parallel mode registers\n",
2576 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x100);
2577 status = cx231xx_mode_register(dev, TS1_CFG_REG, 0x400);
2581 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x101);
2587 int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type)
2591 struct pcb_config *pcb_config;
2593 /* get EP for media type */
2594 pcb_config = (struct pcb_config *)&dev->current_pcb_config;
2596 if (pcb_config->config_num) {
2597 switch (media_type) {
2599 ep_mask = ENABLE_EP4; /* ep4 [00:1000] */
2602 ep_mask = ENABLE_EP3; /* ep3 [00:0100] */
2605 ep_mask = ENABLE_EP5; /* ep5 [01:0000] */
2608 ep_mask = ENABLE_EP6; /* ep6 [10:0000] */
2610 case TS1_serial_mode:
2611 case TS1_parallel_mode:
2612 ep_mask = ENABLE_EP1; /* ep1 [00:0001] */
2615 ep_mask = ENABLE_EP2; /* ep2 [00:0010] */
2621 rc = cx231xx_initialize_stream_xfer(dev, media_type);
2626 /* enable video capture */
2628 rc = cx231xx_start_stream(dev, ep_mask);
2630 /* disable video capture */
2632 rc = cx231xx_stop_stream(dev, ep_mask);
2637 EXPORT_SYMBOL_GPL(cx231xx_capture_start);
2639 /*****************************************************************************
2640 * G P I O B I T control functions *
2641 ******************************************************************************/
2642 static int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u32 gpio_val)
2646 gpio_val = cpu_to_le32(gpio_val);
2647 status = cx231xx_send_gpio_cmd(dev, gpio_bit, (u8 *)&gpio_val, 4, 0, 0);
2652 static int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u32 *gpio_val)
2657 status = cx231xx_send_gpio_cmd(dev, gpio_bit, (u8 *)&tmp, 4, 0, 1);
2658 *gpio_val = le32_to_cpu(tmp);
2664 * cx231xx_set_gpio_direction
2665 * Sets the direction of the GPIO pin to input or output
2668 * pin_number : The GPIO Pin number to program the direction for
2670 * pin_value : The Direction of the GPIO Pin under reference.
2671 * 0 = Input direction
2672 * 1 = Output direction
2674 int cx231xx_set_gpio_direction(struct cx231xx *dev,
2675 int pin_number, int pin_value)
2680 /* Check for valid pin_number - if 32 , bail out */
2681 if (pin_number >= 32)
2686 value = dev->gpio_dir & (~(1 << pin_number)); /* clear */
2688 value = dev->gpio_dir | (1 << pin_number);
2690 status = cx231xx_set_gpio_bit(dev, value, dev->gpio_val);
2692 /* cache the value for future */
2693 dev->gpio_dir = value;
2699 * cx231xx_set_gpio_value
2700 * Sets the value of the GPIO pin to Logic high or low. The Pin under
2701 * reference should ALREADY BE SET IN OUTPUT MODE !!!!!!!!!
2704 * pin_number : The GPIO Pin number to program the direction for
2705 * pin_value : The value of the GPIO Pin under reference.
2709 int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value)
2714 /* Check for valid pin_number - if 0xFF , bail out */
2715 if (pin_number >= 32)
2718 /* first do a sanity check - if the Pin is not output, make it output */
2719 if ((dev->gpio_dir & (1 << pin_number)) == 0x00) {
2720 /* It was in input mode */
2721 value = dev->gpio_dir | (1 << pin_number);
2722 dev->gpio_dir = value;
2723 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2729 value = dev->gpio_val & (~(1 << pin_number));
2731 value = dev->gpio_val | (1 << pin_number);
2733 /* store the value */
2734 dev->gpio_val = value;
2736 /* toggle bit0 of GP_IO */
2737 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2742 /*****************************************************************************
2743 * G P I O I2C related functions *
2744 ******************************************************************************/
2745 int cx231xx_gpio_i2c_start(struct cx231xx *dev)
2749 /* set SCL to output 1 ; set SDA to output 1 */
2750 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2751 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2752 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2753 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio;
2755 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2759 /* set SCL to output 1; set SDA to output 0 */
2760 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2761 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2763 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2767 /* set SCL to output 0; set SDA to output 0 */
2768 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2769 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2771 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2778 int cx231xx_gpio_i2c_end(struct cx231xx *dev)
2782 /* set SCL to output 0; set SDA to output 0 */
2783 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2784 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2786 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2787 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2789 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2793 /* set SCL to output 1; set SDA to output 0 */
2794 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2795 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2797 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2801 /* set SCL to input ,release SCL cable control
2802 set SDA to input ,release SDA cable control */
2803 dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio);
2804 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2807 cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2814 int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data)
2819 /* set SCL to output ; set SDA to output */
2820 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2821 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2823 for (i = 0; i < 8; i++) {
2824 if (((data << i) & 0x80) == 0) {
2825 /* set SCL to output 0; set SDA to output 0 */
2826 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2827 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2828 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2831 /* set SCL to output 1; set SDA to output 0 */
2832 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2833 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2836 /* set SCL to output 0; set SDA to output 0 */
2837 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2838 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2841 /* set SCL to output 0; set SDA to output 1 */
2842 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2843 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio;
2844 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2847 /* set SCL to output 1; set SDA to output 1 */
2848 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2849 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2852 /* set SCL to output 0; set SDA to output 1 */
2853 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2854 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2861 int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf)
2865 u32 gpio_logic_value = 0;
2869 for (i = 0; i < 8; i++) { /* send write I2c addr */
2871 /* set SCL to output 0; set SDA to input */
2872 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2873 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2876 /* set SCL to output 1; set SDA to input */
2877 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2878 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2881 /* get SDA data bit */
2882 gpio_logic_value = dev->gpio_val;
2883 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir,
2885 if ((dev->gpio_val & (1 << dev->board.tuner_sda_gpio)) != 0)
2886 value |= (1 << (8 - i - 1));
2888 dev->gpio_val = gpio_logic_value;
2891 /* set SCL to output 0,finish the read latest SCL signal.
2892 !!!set SDA to input, never to modify SDA direction at
2894 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2895 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2897 /* store the value */
2898 *buf = value & 0xff;
2903 int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev)
2906 u32 gpio_logic_value = 0;
2910 /* clock stretch; set SCL to input; set SDA to input;
2911 get SCL value till SCL = 1 */
2912 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2913 dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio);
2915 gpio_logic_value = dev->gpio_val;
2916 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2920 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir,
2923 } while (((dev->gpio_val &
2924 (1 << dev->board.tuner_scl_gpio)) == 0) &&
2928 cx231xx_info("No ACK after %d msec -GPIO I2C failed!",
2933 * through clock stretch, slave has given a SCL signal,
2934 * so the SDA data can be directly read.
2936 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, &dev->gpio_val);
2938 if ((dev->gpio_val & 1 << dev->board.tuner_sda_gpio) == 0) {
2939 dev->gpio_val = gpio_logic_value;
2940 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2943 dev->gpio_val = gpio_logic_value;
2944 dev->gpio_val |= (1 << dev->board.tuner_sda_gpio);
2947 /* read SDA end, set the SCL to output 0, after this operation,
2948 SDA direction can be changed. */
2949 dev->gpio_val = gpio_logic_value;
2950 dev->gpio_dir |= (1 << dev->board.tuner_scl_gpio);
2951 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2952 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2957 int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev)
2961 /* set SDA to ouput */
2962 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2963 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2965 /* set SCL = 0 (output); set SDA = 0 (output) */
2966 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2967 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2968 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2970 /* set SCL = 1 (output); set SDA = 0 (output) */
2971 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2972 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2974 /* set SCL = 0 (output); set SDA = 0 (output) */
2975 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2976 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2978 /* set SDA to input,and then the slave will read data from SDA. */
2979 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2980 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2985 int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev)
2989 /* set scl to output ; set sda to input */
2990 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2991 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2992 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2994 /* set scl to output 0; set sda to input */
2995 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2996 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
2998 /* set scl to output 1; set sda to input */
2999 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
3000 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, dev->gpio_val);
3005 /*****************************************************************************
3006 * G P I O I2C related functions *
3007 ******************************************************************************/
3008 /* cx231xx_gpio_i2c_read
3009 * Function to read data from gpio based I2C interface
3011 int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len)
3017 mutex_lock(&dev->gpio_i2c_lock);
3020 status = cx231xx_gpio_i2c_start(dev);
3022 /* write dev_addr */
3023 status = cx231xx_gpio_i2c_write_byte(dev, (dev_addr << 1) + 1);
3026 status = cx231xx_gpio_i2c_read_ack(dev);
3029 for (i = 0; i < len; i++) {
3032 status = cx231xx_gpio_i2c_read_byte(dev, &buf[i]);
3034 if ((i + 1) != len) {
3035 /* only do write ack if we more length */
3036 status = cx231xx_gpio_i2c_write_ack(dev);
3040 /* write NAK - inform reads are complete */
3041 status = cx231xx_gpio_i2c_write_nak(dev);
3044 status = cx231xx_gpio_i2c_end(dev);
3046 /* release the lock */
3047 mutex_unlock(&dev->gpio_i2c_lock);
3052 /* cx231xx_gpio_i2c_write
3053 * Function to write data to gpio based I2C interface
3055 int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len)
3060 mutex_lock(&dev->gpio_i2c_lock);
3063 cx231xx_gpio_i2c_start(dev);
3065 /* write dev_addr */
3066 cx231xx_gpio_i2c_write_byte(dev, dev_addr << 1);
3069 cx231xx_gpio_i2c_read_ack(dev);
3071 for (i = 0; i < len; i++) {
3073 cx231xx_gpio_i2c_write_byte(dev, buf[i]);
3076 cx231xx_gpio_i2c_read_ack(dev);
3080 cx231xx_gpio_i2c_end(dev);
3082 /* release the lock */
3083 mutex_unlock(&dev->gpio_i2c_lock);