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>
38 #include <media/v4l2-chip-ident.h>
41 #include "cx231xx-dif.h"
43 #define TUNER_MODE_FM_RADIO 0
44 /******************************************************************************
45 -: BLOCK ARRANGEMENT :-
46 I2S block ----------------------|
49 Analog Front End --> Direct IF -|-> Cx25840 --> Audio
50 [video & audio] | [Audio]
55 *******************************************************************************/
56 /******************************************************************************
59 ******************************************************************************/
60 static int verve_write_byte(struct cx231xx
*dev
, u8 saddr
, u8 data
)
62 return cx231xx_write_i2c_data(dev
, VERVE_I2C_ADDRESS
,
66 static int verve_read_byte(struct cx231xx
*dev
, u8 saddr
, u8
*data
)
71 status
= cx231xx_read_i2c_data(dev
, VERVE_I2C_ADDRESS
,
76 void initGPIO(struct cx231xx
*dev
)
78 u32 _gpio_direction
= 0;
82 _gpio_direction
= _gpio_direction
& 0xFC0003FF;
83 _gpio_direction
= _gpio_direction
| 0x03FDFC00;
84 cx231xx_send_gpio_cmd(dev
, _gpio_direction
, (u8
*)&value
, 4, 0, 0);
86 verve_read_byte(dev
, 0x07, &val
);
87 cx231xx_info(" verve_read_byte address0x07=0x%x\n", val
);
88 verve_write_byte(dev
, 0x07, 0xF4);
89 verve_read_byte(dev
, 0x07, &val
);
90 cx231xx_info(" verve_read_byte address0x07=0x%x\n", val
);
92 cx231xx_capture_start(dev
, 1, 2);
94 cx231xx_mode_register(dev
, EP_MODE_SET
, 0x0500FE00);
95 cx231xx_mode_register(dev
, GBULK_BIT_EN
, 0xFFFDFFFF);
98 void uninitGPIO(struct cx231xx
*dev
)
100 u8 value
[4] = { 0, 0, 0, 0 };
102 cx231xx_capture_start(dev
, 0, 2);
103 verve_write_byte(dev
, 0x07, 0x14);
104 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
108 /******************************************************************************
109 * A F E - B L O C K C O N T R O L functions *
110 * [ANALOG FRONT END] *
111 ******************************************************************************/
112 static int afe_write_byte(struct cx231xx
*dev
, u16 saddr
, u8 data
)
114 return cx231xx_write_i2c_data(dev
, AFE_DEVICE_ADDRESS
,
118 static int afe_read_byte(struct cx231xx
*dev
, u16 saddr
, u8
*data
)
123 status
= cx231xx_read_i2c_data(dev
, AFE_DEVICE_ADDRESS
,
129 int cx231xx_afe_init_super_block(struct cx231xx
*dev
, u32 ref_count
)
133 u8 afe_power_status
= 0;
136 /* super block initialize */
137 temp
= (u8
) (ref_count
& 0xff);
138 status
= afe_write_byte(dev
, SUP_BLK_TUNE2
, temp
);
142 status
= afe_read_byte(dev
, SUP_BLK_TUNE2
, &afe_power_status
);
146 temp
= (u8
) ((ref_count
& 0x300) >> 8);
148 status
= afe_write_byte(dev
, SUP_BLK_TUNE1
, temp
);
152 status
= afe_write_byte(dev
, SUP_BLK_PLL2
, 0x0f);
157 while (afe_power_status
!= 0x18) {
158 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
, 0x18);
161 ": Init Super Block failed in send cmd\n");
165 status
= afe_read_byte(dev
, SUP_BLK_PWRDN
, &afe_power_status
);
166 afe_power_status
&= 0xff;
169 ": Init Super Block failed in receive cmd\n");
175 ": Init Super Block force break in loop !!!!\n");
184 /* start tuning filter */
185 status
= afe_write_byte(dev
, SUP_BLK_TUNE3
, 0x40);
192 status
= afe_write_byte(dev
, SUP_BLK_TUNE3
, 0x00);
197 int cx231xx_afe_init_channels(struct cx231xx
*dev
)
201 /* power up all 3 channels, clear pd_buffer */
202 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
, 0x00);
203 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
, 0x00);
204 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
, 0x00);
206 /* Enable quantizer calibration */
207 status
= afe_write_byte(dev
, ADC_COM_QUANT
, 0x02);
209 /* channel initialize, force modulator (fb) reset */
210 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH1
, 0x17);
211 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH2
, 0x17);
212 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH3
, 0x17);
214 /* start quantilizer calibration */
215 status
= afe_write_byte(dev
, ADC_CAL_ATEST_CH1
, 0x10);
216 status
= afe_write_byte(dev
, ADC_CAL_ATEST_CH2
, 0x10);
217 status
= afe_write_byte(dev
, ADC_CAL_ATEST_CH3
, 0x10);
220 /* exit modulator (fb) reset */
221 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH1
, 0x07);
222 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH2
, 0x07);
223 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH3
, 0x07);
225 /* enable the pre_clamp in each channel for single-ended input */
226 status
= afe_write_byte(dev
, ADC_NTF_PRECLMP_EN_CH1
, 0xf0);
227 status
= afe_write_byte(dev
, ADC_NTF_PRECLMP_EN_CH2
, 0xf0);
228 status
= afe_write_byte(dev
, ADC_NTF_PRECLMP_EN_CH3
, 0xf0);
230 /* use diode instead of resistor, so set term_en to 0, res_en to 0 */
231 status
= cx231xx_reg_mask_write(dev
, AFE_DEVICE_ADDRESS
, 8,
232 ADC_QGAIN_RES_TRM_CH1
, 3, 7, 0x00);
233 status
= cx231xx_reg_mask_write(dev
, AFE_DEVICE_ADDRESS
, 8,
234 ADC_QGAIN_RES_TRM_CH2
, 3, 7, 0x00);
235 status
= cx231xx_reg_mask_write(dev
, AFE_DEVICE_ADDRESS
, 8,
236 ADC_QGAIN_RES_TRM_CH3
, 3, 7, 0x00);
238 /* dynamic element matching off */
239 status
= afe_write_byte(dev
, ADC_DCSERVO_DEM_CH1
, 0x03);
240 status
= afe_write_byte(dev
, ADC_DCSERVO_DEM_CH2
, 0x03);
241 status
= afe_write_byte(dev
, ADC_DCSERVO_DEM_CH3
, 0x03);
246 int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx
*dev
)
251 status
= afe_read_byte(dev
, ADC_PWRDN_CLAMP_CH2
, &c_value
);
252 c_value
&= (~(0x50));
253 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
, c_value
);
259 The Analog Front End in Cx231xx has 3 channels. These
260 channels are used to share between different inputs
261 like tuner, s-video and composite inputs.
263 channel 1 ----- pin 1 to pin4(in reg is 1-4)
264 channel 2 ----- pin 5 to pin8(in reg is 5-8)
265 channel 3 ----- pin 9 to pin 12(in reg is 9-11)
267 int cx231xx_afe_set_input_mux(struct cx231xx
*dev
, u32 input_mux
)
269 u8 ch1_setting
= (u8
) input_mux
;
270 u8 ch2_setting
= (u8
) (input_mux
>> 8);
271 u8 ch3_setting
= (u8
) (input_mux
>> 16);
275 if (ch1_setting
!= 0) {
276 status
= afe_read_byte(dev
, ADC_INPUT_CH1
, &value
);
277 value
&= ~INPUT_SEL_MASK
;
278 value
|= (ch1_setting
- 1) << 4;
280 status
= afe_write_byte(dev
, ADC_INPUT_CH1
, value
);
283 if (ch2_setting
!= 0) {
284 status
= afe_read_byte(dev
, ADC_INPUT_CH2
, &value
);
285 value
&= ~INPUT_SEL_MASK
;
286 value
|= (ch2_setting
- 1) << 4;
288 status
= afe_write_byte(dev
, ADC_INPUT_CH2
, value
);
291 /* For ch3_setting, the value to put in the register is
292 7 less than the input number */
293 if (ch3_setting
!= 0) {
294 status
= afe_read_byte(dev
, ADC_INPUT_CH3
, &value
);
295 value
&= ~INPUT_SEL_MASK
;
296 value
|= (ch3_setting
- 1) << 4;
298 status
= afe_write_byte(dev
, ADC_INPUT_CH3
, value
);
304 int cx231xx_afe_set_mode(struct cx231xx
*dev
, enum AFE_MODE mode
)
309 * FIXME: We need to implement the AFE code for LOW IF and for HI IF.
310 * Currently, only baseband works.
314 case AFE_MODE_LOW_IF
:
315 cx231xx_Setup_AFE_for_LowIF(dev
);
317 case AFE_MODE_BASEBAND
:
318 status
= cx231xx_afe_setup_AFE_for_baseband(dev
);
320 case AFE_MODE_EU_HI_IF
:
321 /* SetupAFEforEuHiIF(); */
323 case AFE_MODE_US_HI_IF
:
324 /* SetupAFEforUsHiIF(); */
326 case AFE_MODE_JAPAN_HI_IF
:
327 /* SetupAFEforJapanHiIF(); */
331 if ((mode
!= dev
->afe_mode
) &&
332 (dev
->video_input
== CX231XX_VMUX_TELEVISION
))
333 status
= cx231xx_afe_adjust_ref_count(dev
,
334 CX231XX_VMUX_TELEVISION
);
336 dev
->afe_mode
= mode
;
341 int cx231xx_afe_update_power_control(struct cx231xx
*dev
,
344 u8 afe_power_status
= 0;
347 switch (dev
->model
) {
348 case CX231XX_BOARD_CNXT_CARRAERA
:
349 case CX231XX_BOARD_CNXT_RDE_250
:
350 case CX231XX_BOARD_CNXT_SHELBY
:
351 case CX231XX_BOARD_CNXT_RDU_250
:
352 case CX231XX_BOARD_CNXT_RDE_253S
:
353 case CX231XX_BOARD_CNXT_RDU_253S
:
354 case CX231XX_BOARD_CNXT_VIDEO_GRABBER
:
355 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
356 case CX231XX_BOARD_HAUPPAUGE_USBLIVE2
:
357 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
:
358 if (avmode
== POLARIS_AVMODE_ANALOGT_TV
) {
359 while (afe_power_status
!= (FLD_PWRDN_TUNING_BIAS
|
360 FLD_PWRDN_ENABLE_PLL
)) {
361 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
,
362 FLD_PWRDN_TUNING_BIAS
|
363 FLD_PWRDN_ENABLE_PLL
);
364 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
370 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
372 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
374 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
376 } else if (avmode
== POLARIS_AVMODE_DIGITAL
) {
377 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
379 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
381 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
384 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
386 afe_power_status
|= FLD_PWRDN_PD_BANDGAP
|
389 status
|= afe_write_byte(dev
, SUP_BLK_PWRDN
,
391 } else if (avmode
== POLARIS_AVMODE_ENXTERNAL_AV
) {
392 while (afe_power_status
!= (FLD_PWRDN_TUNING_BIAS
|
393 FLD_PWRDN_ENABLE_PLL
)) {
394 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
,
395 FLD_PWRDN_TUNING_BIAS
|
396 FLD_PWRDN_ENABLE_PLL
);
397 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
403 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
405 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
407 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
410 cx231xx_info("Invalid AV mode input\n");
415 if (avmode
== POLARIS_AVMODE_ANALOGT_TV
) {
416 while (afe_power_status
!= (FLD_PWRDN_TUNING_BIAS
|
417 FLD_PWRDN_ENABLE_PLL
)) {
418 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
,
419 FLD_PWRDN_TUNING_BIAS
|
420 FLD_PWRDN_ENABLE_PLL
);
421 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
427 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
429 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
431 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
433 } else if (avmode
== POLARIS_AVMODE_DIGITAL
) {
434 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
436 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
438 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
441 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
443 afe_power_status
|= FLD_PWRDN_PD_BANDGAP
|
446 status
|= afe_write_byte(dev
, SUP_BLK_PWRDN
,
448 } else if (avmode
== POLARIS_AVMODE_ENXTERNAL_AV
) {
449 while (afe_power_status
!= (FLD_PWRDN_TUNING_BIAS
|
450 FLD_PWRDN_ENABLE_PLL
)) {
451 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
,
452 FLD_PWRDN_TUNING_BIAS
|
453 FLD_PWRDN_ENABLE_PLL
);
454 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
460 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
462 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
464 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
467 cx231xx_info("Invalid AV mode input\n");
475 int cx231xx_afe_adjust_ref_count(struct cx231xx
*dev
, u32 video_input
)
481 dev
->video_input
= video_input
;
483 if (video_input
== CX231XX_VMUX_TELEVISION
) {
484 status
= afe_read_byte(dev
, ADC_INPUT_CH3
, &input_mode
);
485 status
= afe_read_byte(dev
, ADC_NTF_PRECLMP_EN_CH3
,
488 status
= afe_read_byte(dev
, ADC_INPUT_CH1
, &input_mode
);
489 status
= afe_read_byte(dev
, ADC_NTF_PRECLMP_EN_CH1
,
493 input_mode
= (ntf_mode
& 0x3) | ((input_mode
& 0x6) << 1);
495 switch (input_mode
) {
497 dev
->afe_ref_count
= 0x23C;
500 dev
->afe_ref_count
= 0x24C;
503 dev
->afe_ref_count
= 0x258;
506 dev
->afe_ref_count
= 0x260;
512 status
= cx231xx_afe_init_super_block(dev
, dev
->afe_ref_count
);
517 /******************************************************************************
518 * 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 *
519 ******************************************************************************/
520 static int vid_blk_write_byte(struct cx231xx
*dev
, u16 saddr
, u8 data
)
522 return cx231xx_write_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
526 static int vid_blk_read_byte(struct cx231xx
*dev
, u16 saddr
, u8
*data
)
531 status
= cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
537 static int vid_blk_write_word(struct cx231xx
*dev
, u16 saddr
, u32 data
)
539 return cx231xx_write_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
543 static int vid_blk_read_word(struct cx231xx
*dev
, u16 saddr
, u32
*data
)
545 return cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
548 int cx231xx_check_fw(struct cx231xx
*dev
)
552 status
= vid_blk_read_byte(dev
, DL_CTL_ADDRESS_LOW
, &temp
);
560 int cx231xx_set_video_input_mux(struct cx231xx
*dev
, u8 input
)
564 switch (INPUT(input
)->type
) {
565 case CX231XX_VMUX_COMPOSITE1
:
566 case CX231XX_VMUX_SVIDEO
:
567 if ((dev
->current_pcb_config
.type
== USB_BUS_POWER
) &&
568 (dev
->power_mode
!= POLARIS_AVMODE_ENXTERNAL_AV
)) {
570 status
= cx231xx_set_power_mode(dev
,
571 POLARIS_AVMODE_ENXTERNAL_AV
);
573 cx231xx_errdev("%s: set_power_mode : Failed to"
574 " set Power - errCode [%d]!\n",
579 status
= cx231xx_set_decoder_video_input(dev
,
583 case CX231XX_VMUX_TELEVISION
:
584 case CX231XX_VMUX_CABLE
:
585 if ((dev
->current_pcb_config
.type
== USB_BUS_POWER
) &&
586 (dev
->power_mode
!= POLARIS_AVMODE_ANALOGT_TV
)) {
588 status
= cx231xx_set_power_mode(dev
,
589 POLARIS_AVMODE_ANALOGT_TV
);
591 cx231xx_errdev("%s: set_power_mode:Failed"
592 " to set Power - errCode [%d]!\n",
597 if (dev
->tuner_type
== TUNER_NXP_TDA18271
)
598 status
= cx231xx_set_decoder_video_input(dev
,
599 CX231XX_VMUX_TELEVISION
,
602 status
= cx231xx_set_decoder_video_input(dev
,
603 CX231XX_VMUX_COMPOSITE1
,
608 cx231xx_errdev("%s: set_power_mode : Unknown Input %d !\n",
609 __func__
, INPUT(input
)->type
);
613 /* save the selection */
614 dev
->video_input
= input
;
619 int cx231xx_set_decoder_video_input(struct cx231xx
*dev
,
620 u8 pin_type
, u8 input
)
625 if (pin_type
!= dev
->video_input
) {
626 status
= cx231xx_afe_adjust_ref_count(dev
, pin_type
);
628 cx231xx_errdev("%s: adjust_ref_count :Failed to set"
629 "AFE input mux - errCode [%d]!\n",
635 /* call afe block to set video inputs */
636 status
= cx231xx_afe_set_input_mux(dev
, input
);
638 cx231xx_errdev("%s: set_input_mux :Failed to set"
639 " AFE input mux - errCode [%d]!\n",
645 case CX231XX_VMUX_COMPOSITE1
:
646 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
647 value
|= (0 << 13) | (1 << 4);
650 /* set [24:23] [22:15] to 0 */
651 value
&= (~(0x1ff8000));
652 /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */
654 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
656 status
= vid_blk_read_word(dev
, OUT_CTRL1
, &value
);
658 status
= vid_blk_write_word(dev
, OUT_CTRL1
, value
);
660 /* Set output mode */
661 status
= cx231xx_read_modify_write_i2c_dword(dev
,
665 dev
->board
.output_mode
);
667 /* Tell DIF object to go to baseband mode */
668 status
= cx231xx_dif_set_standard(dev
, DIF_USE_BASEBAND
);
670 cx231xx_errdev("%s: cx231xx_dif set to By pass"
671 " mode- errCode [%d]!\n",
676 /* Read the DFE_CTRL1 register */
677 status
= vid_blk_read_word(dev
, DFE_CTRL1
, &value
);
679 /* enable the VBI_GATE_EN */
680 value
|= FLD_VBI_GATE_EN
;
682 /* Enable the auto-VGA enable */
683 value
|= FLD_VGA_AUTO_EN
;
686 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
688 /* Disable auto config of registers */
689 status
= cx231xx_read_modify_write_i2c_dword(dev
,
691 MODE_CTRL
, FLD_ACFG_DIS
,
692 cx231xx_set_field(FLD_ACFG_DIS
, 1));
694 /* Set CVBS input mode */
695 status
= cx231xx_read_modify_write_i2c_dword(dev
,
697 MODE_CTRL
, FLD_INPUT_MODE
,
698 cx231xx_set_field(FLD_INPUT_MODE
, INPUT_MODE_CVBS_0
));
700 case CX231XX_VMUX_SVIDEO
:
701 /* Disable the use of DIF */
703 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
705 /* set [24:23] [22:15] to 0 */
706 value
&= (~(0x1ff8000));
707 /* set FUNC_MODE[24:23] = 2
708 IF_MOD[22:15] = 0 DCR_BYP_CH2[4:4] = 1; */
710 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
712 /* Tell DIF object to go to baseband mode */
713 status
= cx231xx_dif_set_standard(dev
, DIF_USE_BASEBAND
);
715 cx231xx_errdev("%s: cx231xx_dif set to By pass"
716 " mode- errCode [%d]!\n",
721 /* Read the DFE_CTRL1 register */
722 status
= vid_blk_read_word(dev
, DFE_CTRL1
, &value
);
724 /* enable the VBI_GATE_EN */
725 value
|= FLD_VBI_GATE_EN
;
727 /* Enable the auto-VGA enable */
728 value
|= FLD_VGA_AUTO_EN
;
731 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
733 /* Disable auto config of registers */
734 status
= cx231xx_read_modify_write_i2c_dword(dev
,
736 MODE_CTRL
, FLD_ACFG_DIS
,
737 cx231xx_set_field(FLD_ACFG_DIS
, 1));
739 /* Set YC input mode */
740 status
= cx231xx_read_modify_write_i2c_dword(dev
,
744 cx231xx_set_field(FLD_INPUT_MODE
, INPUT_MODE_YC_1
));
747 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
748 value
|= FLD_CHROMA_IN_SEL
; /* set the chroma in select */
750 /* Clear VGA_SEL_CH2 and VGA_SEL_CH3 (bits 7 and 8)
751 This sets them to use video
752 rather than audio. Only one of the two will be in use. */
753 value
&= ~(FLD_VGA_SEL_CH2
| FLD_VGA_SEL_CH3
);
755 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
757 status
= cx231xx_afe_set_mode(dev
, AFE_MODE_BASEBAND
);
759 case CX231XX_VMUX_TELEVISION
:
760 case CX231XX_VMUX_CABLE
:
762 switch (dev
->model
) {
763 case CX231XX_BOARD_CNXT_CARRAERA
:
764 case CX231XX_BOARD_CNXT_RDE_250
:
765 case CX231XX_BOARD_CNXT_SHELBY
:
766 case CX231XX_BOARD_CNXT_RDU_250
:
767 /* Disable the use of DIF */
769 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
770 value
|= (0 << 13) | (1 << 4);
773 /* set [24:23] [22:15] to 0 */
774 value
&= (~(0x1FF8000));
775 /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */
777 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
779 status
= vid_blk_read_word(dev
, OUT_CTRL1
, &value
);
781 status
= vid_blk_write_word(dev
, OUT_CTRL1
, value
);
783 /* Set output mode */
784 status
= cx231xx_read_modify_write_i2c_dword(dev
,
786 OUT_CTRL1
, FLD_OUT_MODE
,
787 dev
->board
.output_mode
);
789 /* Tell DIF object to go to baseband mode */
790 status
= cx231xx_dif_set_standard(dev
,
793 cx231xx_errdev("%s: cx231xx_dif set to By pass"
794 " mode- errCode [%d]!\n",
799 /* Read the DFE_CTRL1 register */
800 status
= vid_blk_read_word(dev
, DFE_CTRL1
, &value
);
802 /* enable the VBI_GATE_EN */
803 value
|= FLD_VBI_GATE_EN
;
805 /* Enable the auto-VGA enable */
806 value
|= FLD_VGA_AUTO_EN
;
809 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
811 /* Disable auto config of registers */
812 status
= cx231xx_read_modify_write_i2c_dword(dev
,
814 MODE_CTRL
, FLD_ACFG_DIS
,
815 cx231xx_set_field(FLD_ACFG_DIS
, 1));
817 /* Set CVBS input mode */
818 status
= cx231xx_read_modify_write_i2c_dword(dev
,
820 MODE_CTRL
, FLD_INPUT_MODE
,
821 cx231xx_set_field(FLD_INPUT_MODE
,
825 /* Enable the DIF for the tuner */
827 /* Reinitialize the DIF */
828 status
= cx231xx_dif_set_standard(dev
, dev
->norm
);
830 cx231xx_errdev("%s: cx231xx_dif set to By pass"
831 " mode- errCode [%d]!\n",
836 /* Make sure bypass is cleared */
837 status
= vid_blk_read_word(dev
, DIF_MISC_CTRL
, &value
);
839 /* Clear the bypass bit */
840 value
&= ~FLD_DIF_DIF_BYPASS
;
842 /* Enable the use of the DIF block */
843 status
= vid_blk_write_word(dev
, DIF_MISC_CTRL
, value
);
845 /* Read the DFE_CTRL1 register */
846 status
= vid_blk_read_word(dev
, DFE_CTRL1
, &value
);
848 /* Disable the VBI_GATE_EN */
849 value
&= ~FLD_VBI_GATE_EN
;
851 /* Enable the auto-VGA enable, AGC, and
852 set the skip count to 2 */
853 value
|= FLD_VGA_AUTO_EN
| FLD_AGC_AUTO_EN
| 0x00200000;
856 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
858 /* Wait until AGC locks up */
861 /* Disable the auto-VGA enable AGC */
862 value
&= ~(FLD_VGA_AUTO_EN
);
865 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
867 /* Enable Polaris B0 AGC output */
868 status
= vid_blk_read_word(dev
, PIN_CTRL
, &value
);
869 value
|= (FLD_OEF_AGC_RF
) |
870 (FLD_OEF_AGC_IFVGA
) |
872 status
= vid_blk_write_word(dev
, PIN_CTRL
, value
);
874 /* Set output mode */
875 status
= cx231xx_read_modify_write_i2c_dword(dev
,
877 OUT_CTRL1
, FLD_OUT_MODE
,
878 dev
->board
.output_mode
);
880 /* Disable auto config of registers */
881 status
= cx231xx_read_modify_write_i2c_dword(dev
,
883 MODE_CTRL
, FLD_ACFG_DIS
,
884 cx231xx_set_field(FLD_ACFG_DIS
, 1));
886 /* Set CVBS input mode */
887 status
= cx231xx_read_modify_write_i2c_dword(dev
,
889 MODE_CTRL
, FLD_INPUT_MODE
,
890 cx231xx_set_field(FLD_INPUT_MODE
,
893 /* Set some bits in AFE_CTRL so that channel 2 or 3
894 * is ready to receive audio */
895 /* Clear clamp for channels 2 and 3 (bit 16-17) */
896 /* Clear droop comp (bit 19-20) */
897 /* Set VGA_SEL (for audio control) (bit 7-8) */
898 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
900 /*Set Func mode:01-DIF 10-baseband 11-YUV*/
901 value
&= (~(FLD_FUNC_MODE
));
904 value
|= FLD_VGA_SEL_CH3
| FLD_VGA_SEL_CH2
;
906 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
908 if (dev
->tuner_type
== TUNER_NXP_TDA18271
) {
909 status
= vid_blk_read_word(dev
, PIN_CTRL
,
911 status
= vid_blk_write_word(dev
, PIN_CTRL
,
912 (value
& 0xFFFFFFEF));
921 /* Set raw VBI mode */
922 status
= cx231xx_read_modify_write_i2c_dword(dev
,
924 OUT_CTRL1
, FLD_VBIHACTRAW_EN
,
925 cx231xx_set_field(FLD_VBIHACTRAW_EN
, 1));
927 status
= vid_blk_read_word(dev
, OUT_CTRL1
, &value
);
930 status
= vid_blk_write_word(dev
, OUT_CTRL1
, value
);
936 void cx231xx_enable656(struct cx231xx
*dev
)
940 /*enable TS1 data[0:7] as output to export 656*/
942 status
= vid_blk_write_byte(dev
, TS1_PIN_CTL0
, 0xFF);
944 /*enable TS1 clock as output to export 656*/
946 status
= vid_blk_read_byte(dev
, TS1_PIN_CTL1
, &temp
);
949 status
= vid_blk_write_byte(dev
, TS1_PIN_CTL1
, temp
);
952 EXPORT_SYMBOL_GPL(cx231xx_enable656
);
954 void cx231xx_disable656(struct cx231xx
*dev
)
960 status
= vid_blk_write_byte(dev
, TS1_PIN_CTL0
, 0x00);
962 status
= vid_blk_read_byte(dev
, TS1_PIN_CTL1
, &temp
);
965 status
= vid_blk_write_byte(dev
, TS1_PIN_CTL1
, temp
);
967 EXPORT_SYMBOL_GPL(cx231xx_disable656
);
970 * Handle any video-mode specific overrides that are different
971 * on a per video standards basis after touching the MODE_CTRL
972 * register which resets many values for autodetect
974 int cx231xx_do_mode_ctrl_overrides(struct cx231xx
*dev
)
978 cx231xx_info("do_mode_ctrl_overrides : 0x%x\n",
979 (unsigned int)dev
->norm
);
981 /* Change the DFE_CTRL3 bp_percent to fix flagging */
982 status
= vid_blk_write_word(dev
, DFE_CTRL3
, 0xCD3F0280);
984 if (dev
->norm
& (V4L2_STD_NTSC
| V4L2_STD_PAL_M
)) {
985 cx231xx_info("do_mode_ctrl_overrides NTSC\n");
987 /* Move the close caption lines out of active video,
988 adjust the active video start point */
989 status
= cx231xx_read_modify_write_i2c_dword(dev
,
992 FLD_VBLANK_CNT
, 0x18);
993 status
= cx231xx_read_modify_write_i2c_dword(dev
,
998 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1004 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1005 VID_BLK_I2C_ADDRESS
,
1009 (FLD_HBLANK_CNT
, 0x79));
1011 } else if (dev
->norm
& V4L2_STD_SECAM
) {
1012 cx231xx_info("do_mode_ctrl_overrides SECAM\n");
1013 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1014 VID_BLK_I2C_ADDRESS
,
1016 FLD_VBLANK_CNT
, 0x20);
1017 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1018 VID_BLK_I2C_ADDRESS
,
1024 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1025 VID_BLK_I2C_ADDRESS
,
1031 /* Adjust the active video horizontal start point */
1032 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1033 VID_BLK_I2C_ADDRESS
,
1037 (FLD_HBLANK_CNT
, 0x85));
1039 cx231xx_info("do_mode_ctrl_overrides PAL\n");
1040 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1041 VID_BLK_I2C_ADDRESS
,
1043 FLD_VBLANK_CNT
, 0x20);
1044 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1045 VID_BLK_I2C_ADDRESS
,
1051 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1052 VID_BLK_I2C_ADDRESS
,
1058 /* Adjust the active video horizontal start point */
1059 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1060 VID_BLK_I2C_ADDRESS
,
1064 (FLD_HBLANK_CNT
, 0x85));
1071 int cx231xx_unmute_audio(struct cx231xx
*dev
)
1073 return vid_blk_write_byte(dev
, PATH1_VOL_CTL
, 0x24);
1075 EXPORT_SYMBOL_GPL(cx231xx_unmute_audio
);
1077 int stopAudioFirmware(struct cx231xx
*dev
)
1079 return vid_blk_write_byte(dev
, DL_CTL_CONTROL
, 0x03);
1082 int restartAudioFirmware(struct cx231xx
*dev
)
1084 return vid_blk_write_byte(dev
, DL_CTL_CONTROL
, 0x13);
1087 int cx231xx_set_audio_input(struct cx231xx
*dev
, u8 input
)
1090 enum AUDIO_INPUT ainput
= AUDIO_INPUT_LINE
;
1092 switch (INPUT(input
)->amux
) {
1093 case CX231XX_AMUX_VIDEO
:
1094 ainput
= AUDIO_INPUT_TUNER_TV
;
1096 case CX231XX_AMUX_LINE_IN
:
1097 status
= cx231xx_i2s_blk_set_audio_input(dev
, input
);
1098 ainput
= AUDIO_INPUT_LINE
;
1104 status
= cx231xx_set_audio_decoder_input(dev
, ainput
);
1109 int cx231xx_set_audio_decoder_input(struct cx231xx
*dev
,
1110 enum AUDIO_INPUT audio_input
)
1117 /* Put it in soft reset */
1118 status
= vid_blk_read_byte(dev
, GENERAL_CTL
, &gen_ctrl
);
1120 status
= vid_blk_write_byte(dev
, GENERAL_CTL
, gen_ctrl
);
1122 switch (audio_input
) {
1123 case AUDIO_INPUT_LINE
:
1124 /* setup AUD_IO control from Merlin paralle output */
1125 value
= cx231xx_set_field(FLD_AUD_CHAN1_SRC
,
1126 AUD_CHAN_SRC_PARALLEL
);
1127 status
= vid_blk_write_word(dev
, AUD_IO_CTRL
, value
);
1129 /* setup input to Merlin, SRC2 connect to AC97
1130 bypass upsample-by-2, slave mode, sony mode, left justify
1131 adr 091c, dat 01000000 */
1132 status
= vid_blk_read_word(dev
, AC97_CTL
, &dwval
);
1134 status
= vid_blk_write_word(dev
, AC97_CTL
,
1135 (dwval
| FLD_AC97_UP2X_BYPASS
));
1137 /* select the parallel1 and SRC3 */
1138 status
= vid_blk_write_word(dev
, BAND_OUT_SEL
,
1139 cx231xx_set_field(FLD_SRC3_IN_SEL
, 0x0) |
1140 cx231xx_set_field(FLD_SRC3_CLK_SEL
, 0x0) |
1141 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL
, 0x0));
1143 /* unmute all, AC97 in, independence mode
1144 adr 08d0, data 0x00063073 */
1145 status
= vid_blk_write_word(dev
, DL_CTL
, 0x3000001);
1146 status
= vid_blk_write_word(dev
, PATH1_CTL1
, 0x00063073);
1148 /* set AVC maximum threshold, adr 08d4, dat ffff0024 */
1149 status
= vid_blk_read_word(dev
, PATH1_VOL_CTL
, &dwval
);
1150 status
= vid_blk_write_word(dev
, PATH1_VOL_CTL
,
1151 (dwval
| FLD_PATH1_AVC_THRESHOLD
));
1153 /* set SC maximum threshold, adr 08ec, dat ffffb3a3 */
1154 status
= vid_blk_read_word(dev
, PATH1_SC_CTL
, &dwval
);
1155 status
= vid_blk_write_word(dev
, PATH1_SC_CTL
,
1156 (dwval
| FLD_PATH1_SC_THRESHOLD
));
1159 case AUDIO_INPUT_TUNER_TV
:
1161 status
= stopAudioFirmware(dev
);
1162 /* Setup SRC sources and clocks */
1163 status
= vid_blk_write_word(dev
, BAND_OUT_SEL
,
1164 cx231xx_set_field(FLD_SRC6_IN_SEL
, 0x00) |
1165 cx231xx_set_field(FLD_SRC6_CLK_SEL
, 0x01) |
1166 cx231xx_set_field(FLD_SRC5_IN_SEL
, 0x00) |
1167 cx231xx_set_field(FLD_SRC5_CLK_SEL
, 0x02) |
1168 cx231xx_set_field(FLD_SRC4_IN_SEL
, 0x02) |
1169 cx231xx_set_field(FLD_SRC4_CLK_SEL
, 0x03) |
1170 cx231xx_set_field(FLD_SRC3_IN_SEL
, 0x00) |
1171 cx231xx_set_field(FLD_SRC3_CLK_SEL
, 0x00) |
1172 cx231xx_set_field(FLD_BASEBAND_BYPASS_CTL
, 0x00) |
1173 cx231xx_set_field(FLD_AC97_SRC_SEL
, 0x03) |
1174 cx231xx_set_field(FLD_I2S_SRC_SEL
, 0x00) |
1175 cx231xx_set_field(FLD_PARALLEL2_SRC_SEL
, 0x02) |
1176 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL
, 0x01));
1178 /* Setup the AUD_IO control */
1179 status
= vid_blk_write_word(dev
, AUD_IO_CTRL
,
1180 cx231xx_set_field(FLD_I2S_PORT_DIR
, 0x00) |
1181 cx231xx_set_field(FLD_I2S_OUT_SRC
, 0x00) |
1182 cx231xx_set_field(FLD_AUD_CHAN3_SRC
, 0x00) |
1183 cx231xx_set_field(FLD_AUD_CHAN2_SRC
, 0x00) |
1184 cx231xx_set_field(FLD_AUD_CHAN1_SRC
, 0x03));
1186 status
= vid_blk_write_word(dev
, PATH1_CTL1
, 0x1F063870);
1188 /* setAudioStandard(_audio_standard); */
1189 status
= vid_blk_write_word(dev
, PATH1_CTL1
, 0x00063870);
1191 status
= restartAudioFirmware(dev
);
1193 switch (dev
->board
.tuner_type
) {
1195 /* SIF passthrough at 28.6363 MHz sample rate */
1196 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1197 VID_BLK_I2C_ADDRESS
,
1200 cx231xx_set_field(FLD_SIF_EN
, 1));
1202 case TUNER_NXP_TDA18271
:
1203 /* Normal mode: SIF passthrough at 14.32 MHz */
1204 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1205 VID_BLK_I2C_ADDRESS
,
1208 cx231xx_set_field(FLD_SIF_EN
, 0));
1211 /* This is just a casual suggestion to people adding
1212 new boards in case they use a tuner type we don't
1213 currently know about */
1214 printk(KERN_INFO
"Unknown tuner type configuring SIF");
1219 case AUDIO_INPUT_TUNER_FM
:
1220 /* use SIF for FM radio
1222 setAudioStandard(_audio_standard);
1226 case AUDIO_INPUT_MUTE
:
1227 status
= vid_blk_write_word(dev
, PATH1_CTL1
, 0x1F011012);
1231 /* Take it out of soft reset */
1232 status
= vid_blk_read_byte(dev
, GENERAL_CTL
, &gen_ctrl
);
1234 status
= vid_blk_write_byte(dev
, GENERAL_CTL
, gen_ctrl
);
1239 /******************************************************************************
1240 * C H I P Specific C O N T R O L functions *
1241 ******************************************************************************/
1242 int cx231xx_init_ctrl_pin_status(struct cx231xx
*dev
)
1247 status
= vid_blk_read_word(dev
, PIN_CTRL
, &value
);
1248 value
|= (~dev
->board
.ctl_pin_status_mask
);
1249 status
= vid_blk_write_word(dev
, PIN_CTRL
, value
);
1254 int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx
*dev
,
1255 u8 analog_or_digital
)
1259 /* first set the direction to output */
1260 status
= cx231xx_set_gpio_direction(dev
,
1262 agc_analog_digital_select_gpio
, 1);
1264 /* 0 - demod ; 1 - Analog mode */
1265 status
= cx231xx_set_gpio_value(dev
,
1266 dev
->board
.agc_analog_digital_select_gpio
,
1272 int cx231xx_enable_i2c_port_3(struct cx231xx
*dev
, bool is_port_3
)
1274 u8 value
[4] = { 0, 0, 0, 0 };
1276 bool current_is_port_3
;
1278 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
,
1279 PWR_CTL_EN
, value
, 4);
1283 current_is_port_3
= value
[0] & I2C_DEMOD_EN
? true : false;
1285 /* Just return, if already using the right port */
1286 if (current_is_port_3
== is_port_3
)
1290 value
[0] |= I2C_DEMOD_EN
;
1292 value
[0] &= ~I2C_DEMOD_EN
;
1294 cx231xx_info("Changing the i2c master port to %d\n",
1297 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1298 PWR_CTL_EN
, value
, 4);
1303 EXPORT_SYMBOL_GPL(cx231xx_enable_i2c_port_3
);
1305 void update_HH_register_after_set_DIF(struct cx231xx
*dev
)
1311 vid_blk_write_word(dev, PIN_CTRL, 0xA0FFF82F);
1312 vid_blk_write_word(dev, DIF_MISC_CTRL, 0x0A203F11);
1313 vid_blk_write_word(dev, DIF_SRC_PHASE_INC, 0x1BEFBF06);
1315 status = vid_blk_read_word(dev, AFE_CTRL_C2HH_SRC_CTRL, &value);
1316 vid_blk_write_word(dev, AFE_CTRL_C2HH_SRC_CTRL, 0x4485D390);
1317 status = vid_blk_read_word(dev, AFE_CTRL_C2HH_SRC_CTRL, &value);
1321 void cx231xx_dump_HH_reg(struct cx231xx
*dev
)
1328 status
= vid_blk_write_word(dev
, 0x104, value
);
1330 for (i
= 0x100; i
< 0x140; i
++) {
1331 status
= vid_blk_read_word(dev
, i
, &value
);
1332 cx231xx_info("reg0x%x=0x%x\n", i
, value
);
1336 for (i
= 0x300; i
< 0x400; i
++) {
1337 status
= vid_blk_read_word(dev
, i
, &value
);
1338 cx231xx_info("reg0x%x=0x%x\n", i
, value
);
1342 for (i
= 0x400; i
< 0x440; i
++) {
1343 status
= vid_blk_read_word(dev
, i
, &value
);
1344 cx231xx_info("reg0x%x=0x%x\n", i
, value
);
1348 status
= vid_blk_read_word(dev
, AFE_CTRL_C2HH_SRC_CTRL
, &value
);
1349 cx231xx_info("AFE_CTRL_C2HH_SRC_CTRL=0x%x\n", value
);
1350 vid_blk_write_word(dev
, AFE_CTRL_C2HH_SRC_CTRL
, 0x4485D390);
1351 status
= vid_blk_read_word(dev
, AFE_CTRL_C2HH_SRC_CTRL
, &value
);
1352 cx231xx_info("AFE_CTRL_C2HH_SRC_CTRL=0x%x\n", value
);
1355 void cx231xx_dump_SC_reg(struct cx231xx
*dev
)
1357 u8 value
[4] = { 0, 0, 0, 0 };
1359 cx231xx_info("cx231xx_dump_SC_reg %s!\n", __TIME__
);
1361 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, BOARD_CFG_STAT
,
1363 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", BOARD_CFG_STAT
, value
[0],
1364 value
[1], value
[2], value
[3]);
1365 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, TS_MODE_REG
,
1367 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS_MODE_REG
, value
[0],
1368 value
[1], value
[2], value
[3]);
1369 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, TS1_CFG_REG
,
1371 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS1_CFG_REG
, value
[0],
1372 value
[1], value
[2], value
[3]);
1373 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, TS1_LENGTH_REG
,
1375 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS1_LENGTH_REG
, value
[0],
1376 value
[1], value
[2], value
[3]);
1378 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, TS2_CFG_REG
,
1380 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS2_CFG_REG
, value
[0],
1381 value
[1], value
[2], value
[3]);
1382 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, TS2_LENGTH_REG
,
1384 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS2_LENGTH_REG
, value
[0],
1385 value
[1], value
[2], value
[3]);
1386 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, EP_MODE_SET
,
1388 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", EP_MODE_SET
, value
[0],
1389 value
[1], value
[2], value
[3]);
1390 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_PWR_PTN1
,
1392 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN1
, value
[0],
1393 value
[1], value
[2], value
[3]);
1395 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_PWR_PTN2
,
1397 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN2
, value
[0],
1398 value
[1], value
[2], value
[3]);
1399 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_PWR_PTN3
,
1401 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN3
, value
[0],
1402 value
[1], value
[2], value
[3]);
1403 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_PWR_MASK0
,
1405 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK0
, value
[0],
1406 value
[1], value
[2], value
[3]);
1407 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_PWR_MASK1
,
1409 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK1
, value
[0],
1410 value
[1], value
[2], value
[3]);
1412 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_PWR_MASK2
,
1414 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK2
, value
[0],
1415 value
[1], value
[2], value
[3]);
1416 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_GAIN
,
1418 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_GAIN
, value
[0],
1419 value
[1], value
[2], value
[3]);
1420 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_CAR_REG
,
1422 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_CAR_REG
, value
[0],
1423 value
[1], value
[2], value
[3]);
1424 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_OT_CFG1
,
1426 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_OT_CFG1
, value
[0],
1427 value
[1], value
[2], value
[3]);
1429 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, CIR_OT_CFG2
,
1431 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_OT_CFG2
, value
[0],
1432 value
[1], value
[2], value
[3]);
1433 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
,
1435 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", PWR_CTL_EN
, value
[0],
1436 value
[1], value
[2], value
[3]);
1441 void cx231xx_Setup_AFE_for_LowIF(struct cx231xx
*dev
)
1449 status
= afe_read_byte(dev
, ADC_STATUS2_CH3
, &value
);
1450 value
= (value
& 0xFE)|0x01;
1451 status
= afe_write_byte(dev
, ADC_STATUS2_CH3
, value
);
1453 status
= afe_read_byte(dev
, ADC_STATUS2_CH3
, &value
);
1454 value
= (value
& 0xFE)|0x00;
1455 status
= afe_write_byte(dev
, ADC_STATUS2_CH3
, value
);
1459 config colibri to lo-if mode
1461 FIXME: ntf_mode = 2'b00 by default. But set 0x1 would reduce
1462 the diff IF input by half,
1464 for low-if agc defect
1467 status
= afe_read_byte(dev
, ADC_NTF_PRECLMP_EN_CH3
, &value
);
1468 value
= (value
& 0xFC)|0x00;
1469 status
= afe_write_byte(dev
, ADC_NTF_PRECLMP_EN_CH3
, value
);
1471 status
= afe_read_byte(dev
, ADC_INPUT_CH3
, &value
);
1472 value
= (value
& 0xF9)|0x02;
1473 status
= afe_write_byte(dev
, ADC_INPUT_CH3
, value
);
1475 status
= afe_read_byte(dev
, ADC_FB_FRCRST_CH3
, &value
);
1476 value
= (value
& 0xFB)|0x04;
1477 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH3
, value
);
1479 status
= afe_read_byte(dev
, ADC_DCSERVO_DEM_CH3
, &value
);
1480 value
= (value
& 0xFC)|0x03;
1481 status
= afe_write_byte(dev
, ADC_DCSERVO_DEM_CH3
, value
);
1483 status
= afe_read_byte(dev
, ADC_CTRL_DAC1_CH3
, &value
);
1484 value
= (value
& 0xFB)|0x04;
1485 status
= afe_write_byte(dev
, ADC_CTRL_DAC1_CH3
, value
);
1487 status
= afe_read_byte(dev
, ADC_CTRL_DAC23_CH3
, &value
);
1488 value
= (value
& 0xF8)|0x06;
1489 status
= afe_write_byte(dev
, ADC_CTRL_DAC23_CH3
, value
);
1491 status
= afe_read_byte(dev
, ADC_CTRL_DAC23_CH3
, &value
);
1492 value
= (value
& 0x8F)|0x40;
1493 status
= afe_write_byte(dev
, ADC_CTRL_DAC23_CH3
, value
);
1495 status
= afe_read_byte(dev
, ADC_PWRDN_CLAMP_CH3
, &value
);
1496 value
= (value
& 0xDF)|0x20;
1497 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
, value
);
1500 void cx231xx_set_Colibri_For_LowIF(struct cx231xx
*dev
, u32 if_freq
,
1501 u8 spectral_invert
, u32 mode
)
1503 u32 colibri_carrier_offset
= 0;
1505 u32 func_mode
= 0x01; /* Device has a DIF if this function is called */
1507 u8 value
[4] = { 0, 0, 0, 0 };
1509 cx231xx_info("Enter cx231xx_set_Colibri_For_LowIF()\n");
1510 value
[0] = (u8
) 0x6F;
1511 value
[1] = (u8
) 0x6F;
1512 value
[2] = (u8
) 0x6F;
1513 value
[3] = (u8
) 0x6F;
1514 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1515 PWR_CTL_EN
, value
, 4);
1517 /*Set colibri for low IF*/
1518 status
= cx231xx_afe_set_mode(dev
, AFE_MODE_LOW_IF
);
1520 /* Set C2HH for low IF operation.*/
1521 standard
= dev
->norm
;
1522 status
= cx231xx_dif_configure_C2HH_for_low_IF(dev
, dev
->active_mode
,
1523 func_mode
, standard
);
1525 /* Get colibri offsets.*/
1526 colibri_carrier_offset
= cx231xx_Get_Colibri_CarrierOffset(mode
,
1529 cx231xx_info("colibri_carrier_offset=%d, standard=0x%x\n",
1530 colibri_carrier_offset
, standard
);
1532 /* Set the band Pass filter for DIF*/
1533 cx231xx_set_DIF_bandpass(dev
, (if_freq
+colibri_carrier_offset
),
1534 spectral_invert
, mode
);
1537 u32
cx231xx_Get_Colibri_CarrierOffset(u32 mode
, u32 standerd
)
1539 u32 colibri_carrier_offset
= 0;
1541 if (mode
== TUNER_MODE_FM_RADIO
) {
1542 colibri_carrier_offset
= 1100000;
1543 } else if (standerd
& (V4L2_STD_MN
| V4L2_STD_NTSC_M_JP
)) {
1544 colibri_carrier_offset
= 4832000; /*4.83MHz */
1545 } else if (standerd
& (V4L2_STD_PAL_B
| V4L2_STD_PAL_G
)) {
1546 colibri_carrier_offset
= 2700000; /*2.70MHz */
1547 } else if (standerd
& (V4L2_STD_PAL_D
| V4L2_STD_PAL_I
1548 | V4L2_STD_SECAM
)) {
1549 colibri_carrier_offset
= 2100000; /*2.10MHz */
1552 return colibri_carrier_offset
;
1555 void cx231xx_set_DIF_bandpass(struct cx231xx
*dev
, u32 if_freq
,
1556 u8 spectral_invert
, u32 mode
)
1558 unsigned long pll_freq_word
;
1560 u32 dif_misc_ctrl_value
= 0;
1561 u64 pll_freq_u64
= 0;
1564 cx231xx_info("if_freq=%d;spectral_invert=0x%x;mode=0x%x\n",
1565 if_freq
, spectral_invert
, mode
);
1568 if (mode
== TUNER_MODE_FM_RADIO
) {
1569 pll_freq_word
= 0x905A1CAC;
1570 status
= vid_blk_write_word(dev
, DIF_PLL_FREQ_WORD
, pll_freq_word
);
1572 } else /*KSPROPERTY_TUNER_MODE_TV*/{
1573 /* Calculate the PLL frequency word based on the adjusted if_freq*/
1574 pll_freq_word
= if_freq
;
1575 pll_freq_u64
= (u64
)pll_freq_word
<< 28L;
1576 do_div(pll_freq_u64
, 50000000);
1577 pll_freq_word
= (u32
)pll_freq_u64
;
1578 /*pll_freq_word = 0x3463497;*/
1579 status
= vid_blk_write_word(dev
, DIF_PLL_FREQ_WORD
, pll_freq_word
);
1581 if (spectral_invert
) {
1583 /* Enable Spectral Invert*/
1584 status
= vid_blk_read_word(dev
, DIF_MISC_CTRL
,
1585 &dif_misc_ctrl_value
);
1586 dif_misc_ctrl_value
= dif_misc_ctrl_value
| 0x00200000;
1587 status
= vid_blk_write_word(dev
, DIF_MISC_CTRL
,
1588 dif_misc_ctrl_value
);
1591 /* Disable Spectral Invert*/
1592 status
= vid_blk_read_word(dev
, DIF_MISC_CTRL
,
1593 &dif_misc_ctrl_value
);
1594 dif_misc_ctrl_value
= dif_misc_ctrl_value
& 0xFFDFFFFF;
1595 status
= vid_blk_write_word(dev
, DIF_MISC_CTRL
,
1596 dif_misc_ctrl_value
);
1599 if_freq
= (if_freq
/100000)*100000;
1601 if (if_freq
< 3000000)
1604 if (if_freq
> 16000000)
1608 cx231xx_info("Enter IF=%zd\n",
1609 sizeof(Dif_set_array
)/sizeof(struct dif_settings
));
1610 for (i
= 0; i
< sizeof(Dif_set_array
)/sizeof(struct dif_settings
); i
++) {
1611 if (Dif_set_array
[i
].if_freq
== if_freq
) {
1612 status
= vid_blk_write_word(dev
,
1613 Dif_set_array
[i
].register_address
, Dif_set_array
[i
].value
);
1618 /******************************************************************************
1619 * D I F - B L O C K C O N T R O L functions *
1620 ******************************************************************************/
1621 int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx
*dev
, u32 mode
,
1622 u32 function_mode
, u32 standard
)
1627 if (mode
== V4L2_TUNER_RADIO
) {
1629 /* lo if big signal */
1630 status
= cx231xx_reg_mask_write(dev
,
1631 VID_BLK_I2C_ADDRESS
, 32,
1632 AFE_CTRL_C2HH_SRC_CTRL
, 30, 31, 0x1);
1633 /* FUNC_MODE = DIF */
1634 status
= cx231xx_reg_mask_write(dev
,
1635 VID_BLK_I2C_ADDRESS
, 32,
1636 AFE_CTRL_C2HH_SRC_CTRL
, 23, 24, function_mode
);
1638 status
= cx231xx_reg_mask_write(dev
,
1639 VID_BLK_I2C_ADDRESS
, 32,
1640 AFE_CTRL_C2HH_SRC_CTRL
, 15, 22, 0xFF);
1642 status
= cx231xx_reg_mask_write(dev
,
1643 VID_BLK_I2C_ADDRESS
, 32,
1644 AFE_CTRL_C2HH_SRC_CTRL
, 9, 9, 0x1);
1645 } else if (standard
!= DIF_USE_BASEBAND
) {
1646 if (standard
& V4L2_STD_MN
) {
1647 /* lo if big signal */
1648 status
= cx231xx_reg_mask_write(dev
,
1649 VID_BLK_I2C_ADDRESS
, 32,
1650 AFE_CTRL_C2HH_SRC_CTRL
, 30, 31, 0x1);
1651 /* FUNC_MODE = DIF */
1652 status
= cx231xx_reg_mask_write(dev
,
1653 VID_BLK_I2C_ADDRESS
, 32,
1654 AFE_CTRL_C2HH_SRC_CTRL
, 23, 24,
1657 status
= cx231xx_reg_mask_write(dev
,
1658 VID_BLK_I2C_ADDRESS
, 32,
1659 AFE_CTRL_C2HH_SRC_CTRL
, 15, 22, 0xb);
1661 status
= cx231xx_reg_mask_write(dev
,
1662 VID_BLK_I2C_ADDRESS
, 32,
1663 AFE_CTRL_C2HH_SRC_CTRL
, 9, 9, 0x1);
1664 /* 0x124, AUD_CHAN1_SRC = 0x3 */
1665 status
= cx231xx_reg_mask_write(dev
,
1666 VID_BLK_I2C_ADDRESS
, 32,
1667 AUD_IO_CTRL
, 0, 31, 0x00000003);
1668 } else if ((standard
== V4L2_STD_PAL_I
) |
1669 (standard
& V4L2_STD_PAL_D
) |
1670 (standard
& V4L2_STD_SECAM
)) {
1672 /* lo if big signal */
1673 status
= cx231xx_reg_mask_write(dev
,
1674 VID_BLK_I2C_ADDRESS
, 32,
1675 AFE_CTRL_C2HH_SRC_CTRL
, 30, 31, 0x1);
1676 /* FUNC_MODE = DIF */
1677 status
= cx231xx_reg_mask_write(dev
,
1678 VID_BLK_I2C_ADDRESS
, 32,
1679 AFE_CTRL_C2HH_SRC_CTRL
, 23, 24,
1682 status
= cx231xx_reg_mask_write(dev
,
1683 VID_BLK_I2C_ADDRESS
, 32,
1684 AFE_CTRL_C2HH_SRC_CTRL
, 15, 22, 0xF);
1686 status
= cx231xx_reg_mask_write(dev
,
1687 VID_BLK_I2C_ADDRESS
, 32,
1688 AFE_CTRL_C2HH_SRC_CTRL
, 9, 9, 0x1);
1690 /* default PAL BG */
1692 /* lo if big signal */
1693 status
= cx231xx_reg_mask_write(dev
,
1694 VID_BLK_I2C_ADDRESS
, 32,
1695 AFE_CTRL_C2HH_SRC_CTRL
, 30, 31, 0x1);
1696 /* FUNC_MODE = DIF */
1697 status
= cx231xx_reg_mask_write(dev
,
1698 VID_BLK_I2C_ADDRESS
, 32,
1699 AFE_CTRL_C2HH_SRC_CTRL
, 23, 24,
1702 status
= cx231xx_reg_mask_write(dev
,
1703 VID_BLK_I2C_ADDRESS
, 32,
1704 AFE_CTRL_C2HH_SRC_CTRL
, 15, 22, 0xE);
1706 status
= cx231xx_reg_mask_write(dev
,
1707 VID_BLK_I2C_ADDRESS
, 32,
1708 AFE_CTRL_C2HH_SRC_CTRL
, 9, 9, 0x1);
1715 int cx231xx_dif_set_standard(struct cx231xx
*dev
, u32 standard
)
1718 u32 dif_misc_ctrl_value
= 0;
1721 cx231xx_info("%s: setStandard to %x\n", __func__
, standard
);
1723 status
= vid_blk_read_word(dev
, DIF_MISC_CTRL
, &dif_misc_ctrl_value
);
1724 if (standard
!= DIF_USE_BASEBAND
)
1725 dev
->norm
= standard
;
1727 switch (dev
->model
) {
1728 case CX231XX_BOARD_CNXT_CARRAERA
:
1729 case CX231XX_BOARD_CNXT_RDE_250
:
1730 case CX231XX_BOARD_CNXT_SHELBY
:
1731 case CX231XX_BOARD_CNXT_RDU_250
:
1732 case CX231XX_BOARD_CNXT_VIDEO_GRABBER
:
1733 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
1736 case CX231XX_BOARD_CNXT_RDE_253S
:
1737 case CX231XX_BOARD_CNXT_RDU_253S
:
1744 status
= cx231xx_dif_configure_C2HH_for_low_IF(dev
, dev
->active_mode
,
1745 func_mode
, standard
);
1747 if (standard
== DIF_USE_BASEBAND
) { /* base band */
1748 /* There is a different SRC_PHASE_INC value
1749 for baseband vs. DIF */
1750 status
= vid_blk_write_word(dev
, DIF_SRC_PHASE_INC
, 0xDF7DF83);
1751 status
= vid_blk_read_word(dev
, DIF_MISC_CTRL
,
1752 &dif_misc_ctrl_value
);
1753 dif_misc_ctrl_value
|= FLD_DIF_DIF_BYPASS
;
1754 status
= vid_blk_write_word(dev
, DIF_MISC_CTRL
,
1755 dif_misc_ctrl_value
);
1756 } else if (standard
& V4L2_STD_PAL_D
) {
1757 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1758 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1759 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1760 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1761 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1762 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1763 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1764 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1765 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1766 DIF_AGC_IF_REF
, 0, 31, 0x444C1380);
1767 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1768 DIF_AGC_CTRL_IF
, 0, 31, 0xDA302600);
1769 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1770 DIF_AGC_CTRL_INT
, 0, 31, 0xDA261700);
1771 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1772 DIF_AGC_CTRL_RF
, 0, 31, 0xDA262600);
1773 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1774 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1776 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1777 DIF_AGC_RF_CURRENT
, 0, 31,
1779 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1780 DIF_VIDEO_AGC_CTRL
, 0, 31,
1782 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1783 DIF_VID_AUD_OVERRIDE
, 0, 31,
1785 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1786 DIF_AV_SEP_CTRL
, 0, 31, 0x3F3934EA);
1787 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1788 DIF_COMP_FLT_CTRL
, 0, 31,
1790 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1791 DIF_SRC_PHASE_INC
, 0, 31,
1793 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1794 DIF_SRC_GAIN_CONTROL
, 0, 31,
1796 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1797 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1798 /* Save the Spec Inversion value */
1799 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1800 dif_misc_ctrl_value
|= 0x3a023F11;
1801 } else if (standard
& V4L2_STD_PAL_I
) {
1802 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1803 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1804 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1805 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1806 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1807 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1808 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1809 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1810 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1811 DIF_AGC_IF_REF
, 0, 31, 0x444C1380);
1812 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1813 DIF_AGC_CTRL_IF
, 0, 31, 0xDA302600);
1814 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1815 DIF_AGC_CTRL_INT
, 0, 31, 0xDA261700);
1816 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1817 DIF_AGC_CTRL_RF
, 0, 31, 0xDA262600);
1818 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1819 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1821 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1822 DIF_AGC_RF_CURRENT
, 0, 31,
1824 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1825 DIF_VIDEO_AGC_CTRL
, 0, 31,
1827 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1828 DIF_VID_AUD_OVERRIDE
, 0, 31,
1830 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1831 DIF_AV_SEP_CTRL
, 0, 31, 0x5F39A934);
1832 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1833 DIF_COMP_FLT_CTRL
, 0, 31,
1835 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1836 DIF_SRC_PHASE_INC
, 0, 31,
1838 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1839 DIF_SRC_GAIN_CONTROL
, 0, 31,
1841 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1842 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1843 /* Save the Spec Inversion value */
1844 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1845 dif_misc_ctrl_value
|= 0x3a033F11;
1846 } else if (standard
& V4L2_STD_PAL_M
) {
1847 /* improved Low Frequency Phase Noise */
1848 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL
, 0xFF01FF0C);
1849 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL1
, 0xbd038c85);
1850 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL2
, 0x1db4640a);
1851 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL3
, 0x00008800);
1852 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, 0x444C1380);
1853 status
= vid_blk_write_word(dev
, DIF_AGC_IF_INT_CURRENT
,
1855 status
= vid_blk_write_word(dev
, DIF_AGC_RF_CURRENT
,
1857 status
= vid_blk_write_word(dev
, DIF_VIDEO_AGC_CTRL
,
1859 status
= vid_blk_write_word(dev
, DIF_VID_AUD_OVERRIDE
,
1861 status
= vid_blk_write_word(dev
, DIF_AV_SEP_CTRL
, 0x012c405d);
1862 status
= vid_blk_write_word(dev
, DIF_COMP_FLT_CTRL
,
1864 status
= vid_blk_write_word(dev
, DIF_SRC_PHASE_INC
,
1866 status
= vid_blk_write_word(dev
, DIF_SRC_GAIN_CONTROL
,
1868 status
= vid_blk_write_word(dev
, DIF_SOFT_RST_CTRL_REVB
,
1870 /* Save the Spec Inversion value */
1871 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1872 dif_misc_ctrl_value
|= 0x3A0A3F10;
1873 } else if (standard
& (V4L2_STD_PAL_N
| V4L2_STD_PAL_Nc
)) {
1874 /* improved Low Frequency Phase Noise */
1875 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL
, 0xFF01FF0C);
1876 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL1
, 0xbd038c85);
1877 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL2
, 0x1db4640a);
1878 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL3
, 0x00008800);
1879 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, 0x444C1380);
1880 status
= vid_blk_write_word(dev
, DIF_AGC_IF_INT_CURRENT
,
1882 status
= vid_blk_write_word(dev
, DIF_AGC_RF_CURRENT
,
1884 status
= vid_blk_write_word(dev
, DIF_VIDEO_AGC_CTRL
,
1886 status
= vid_blk_write_word(dev
, DIF_VID_AUD_OVERRIDE
,
1888 status
= vid_blk_write_word(dev
, DIF_AV_SEP_CTRL
,
1890 status
= vid_blk_write_word(dev
, DIF_COMP_FLT_CTRL
,
1892 status
= vid_blk_write_word(dev
, DIF_SRC_PHASE_INC
,
1894 status
= vid_blk_write_word(dev
, DIF_SRC_GAIN_CONTROL
,
1896 status
= vid_blk_write_word(dev
, DIF_SOFT_RST_CTRL_REVB
,
1898 /* Save the Spec Inversion value */
1899 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1900 dif_misc_ctrl_value
= 0x3A093F10;
1901 } else if (standard
&
1902 (V4L2_STD_SECAM_B
| V4L2_STD_SECAM_D
| V4L2_STD_SECAM_G
|
1903 V4L2_STD_SECAM_K
| V4L2_STD_SECAM_K1
)) {
1905 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1906 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1907 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1908 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1909 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1910 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1911 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1912 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1913 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1914 DIF_AGC_IF_REF
, 0, 31, 0x888C0380);
1915 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1916 DIF_AGC_CTRL_IF
, 0, 31, 0xe0262600);
1917 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1918 DIF_AGC_CTRL_INT
, 0, 31, 0xc2171700);
1919 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1920 DIF_AGC_CTRL_RF
, 0, 31, 0xc2262600);
1921 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1922 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1924 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1925 DIF_AGC_RF_CURRENT
, 0, 31,
1927 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1928 DIF_VID_AUD_OVERRIDE
, 0, 31,
1930 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1931 DIF_AV_SEP_CTRL
, 0, 31, 0x3F3530ec);
1932 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1933 DIF_COMP_FLT_CTRL
, 0, 31,
1935 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1936 DIF_SRC_PHASE_INC
, 0, 31,
1938 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1939 DIF_SRC_GAIN_CONTROL
, 0, 31,
1941 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1942 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1943 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1944 DIF_VIDEO_AGC_CTRL
, 0, 31,
1947 /* Save the Spec Inversion value */
1948 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1949 dif_misc_ctrl_value
|= 0x3a023F11;
1950 } else if (standard
& (V4L2_STD_SECAM_L
| V4L2_STD_SECAM_LC
)) {
1951 /* Is it SECAM_L1? */
1952 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1953 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1954 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1955 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1956 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1957 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1958 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1959 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1960 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1961 DIF_AGC_IF_REF
, 0, 31, 0x888C0380);
1962 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1963 DIF_AGC_CTRL_IF
, 0, 31, 0xe0262600);
1964 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1965 DIF_AGC_CTRL_INT
, 0, 31, 0xc2171700);
1966 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1967 DIF_AGC_CTRL_RF
, 0, 31, 0xc2262600);
1968 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1969 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1971 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1972 DIF_AGC_RF_CURRENT
, 0, 31,
1974 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1975 DIF_VID_AUD_OVERRIDE
, 0, 31,
1977 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1978 DIF_AV_SEP_CTRL
, 0, 31, 0x3F3530ec);
1979 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1980 DIF_COMP_FLT_CTRL
, 0, 31,
1982 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1983 DIF_SRC_PHASE_INC
, 0, 31,
1985 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1986 DIF_SRC_GAIN_CONTROL
, 0, 31,
1988 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1989 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1990 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1991 DIF_VIDEO_AGC_CTRL
, 0, 31,
1994 /* Save the Spec Inversion value */
1995 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1996 dif_misc_ctrl_value
|= 0x3a023F11;
1998 } else if (standard
& V4L2_STD_NTSC_M
) {
1999 /* V4L2_STD_NTSC_M (75 IRE Setup) Or
2000 V4L2_STD_NTSC_M_JP (Japan, 0 IRE Setup) */
2002 /* For NTSC the centre frequency of video coming out of
2003 sidewinder is around 7.1MHz or 3.6MHz depending on the
2004 spectral inversion. so for a non spectrally inverted channel
2005 the pll freq word is 0x03420c49
2008 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL
, 0x6503BC0C);
2009 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL1
, 0xBD038C85);
2010 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL2
, 0x1DB4640A);
2011 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL3
, 0x00008800);
2012 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, 0x444C0380);
2013 status
= vid_blk_write_word(dev
, DIF_AGC_IF_INT_CURRENT
,
2015 status
= vid_blk_write_word(dev
, DIF_AGC_RF_CURRENT
,
2017 status
= vid_blk_write_word(dev
, DIF_VIDEO_AGC_CTRL
,
2019 status
= vid_blk_write_word(dev
, DIF_VID_AUD_OVERRIDE
,
2021 status
= vid_blk_write_word(dev
, DIF_AV_SEP_CTRL
, 0x01296e1f);
2023 status
= vid_blk_write_word(dev
, DIF_COMP_FLT_CTRL
,
2025 status
= vid_blk_write_word(dev
, DIF_SRC_PHASE_INC
,
2027 status
= vid_blk_write_word(dev
, DIF_SRC_GAIN_CONTROL
,
2030 status
= vid_blk_write_word(dev
, DIF_AGC_CTRL_IF
, 0xC2262600);
2031 status
= vid_blk_write_word(dev
, DIF_AGC_CTRL_INT
,
2033 status
= vid_blk_write_word(dev
, DIF_AGC_CTRL_RF
, 0xC2262600);
2035 /* Save the Spec Inversion value */
2036 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
2037 dif_misc_ctrl_value
|= 0x3a003F10;
2039 /* default PAL BG */
2040 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2041 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
2042 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2043 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
2044 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2045 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
2046 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2047 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
2048 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2049 DIF_AGC_IF_REF
, 0, 31, 0x444C1380);
2050 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2051 DIF_AGC_CTRL_IF
, 0, 31, 0xDA302600);
2052 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2053 DIF_AGC_CTRL_INT
, 0, 31, 0xDA261700);
2054 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2055 DIF_AGC_CTRL_RF
, 0, 31, 0xDA262600);
2056 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2057 DIF_AGC_IF_INT_CURRENT
, 0, 31,
2059 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2060 DIF_AGC_RF_CURRENT
, 0, 31,
2062 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2063 DIF_VIDEO_AGC_CTRL
, 0, 31,
2065 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2066 DIF_VID_AUD_OVERRIDE
, 0, 31,
2068 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2069 DIF_AV_SEP_CTRL
, 0, 31, 0x3F3530EC);
2070 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2071 DIF_COMP_FLT_CTRL
, 0, 31,
2073 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2074 DIF_SRC_PHASE_INC
, 0, 31,
2076 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2077 DIF_SRC_GAIN_CONTROL
, 0, 31,
2079 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
2080 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
2081 /* Save the Spec Inversion value */
2082 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
2083 dif_misc_ctrl_value
|= 0x3a013F11;
2086 /* The AGC values should be the same for all standards,
2087 AUD_SRC_SEL[19] should always be disabled */
2088 dif_misc_ctrl_value
&= ~FLD_DIF_AUD_SRC_SEL
;
2090 /* It is still possible to get Set Standard calls even when we
2092 This is done to override the value for FM. */
2093 if (dev
->active_mode
== V4L2_TUNER_RADIO
)
2094 dif_misc_ctrl_value
= 0x7a080000;
2096 /* Write the calculated value for misc ontrol register */
2097 status
= vid_blk_write_word(dev
, DIF_MISC_CTRL
, dif_misc_ctrl_value
);
2102 int cx231xx_tuner_pre_channel_change(struct cx231xx
*dev
)
2107 /* Set the RF and IF k_agc values to 3 */
2108 status
= vid_blk_read_word(dev
, DIF_AGC_IF_REF
, &dwval
);
2109 dwval
&= ~(FLD_DIF_K_AGC_RF
| FLD_DIF_K_AGC_IF
);
2110 dwval
|= 0x33000000;
2112 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, dwval
);
2117 int cx231xx_tuner_post_channel_change(struct cx231xx
*dev
)
2121 cx231xx_info("cx231xx_tuner_post_channel_change dev->tuner_type =0%d\n",
2123 /* Set the RF and IF k_agc values to 4 for PAL/NTSC and 8 for
2124 * SECAM L/B/D standards */
2125 status
= vid_blk_read_word(dev
, DIF_AGC_IF_REF
, &dwval
);
2126 dwval
&= ~(FLD_DIF_K_AGC_RF
| FLD_DIF_K_AGC_IF
);
2128 if (dev
->norm
& (V4L2_STD_SECAM_L
| V4L2_STD_SECAM_B
|
2129 V4L2_STD_SECAM_D
)) {
2130 if (dev
->tuner_type
== TUNER_NXP_TDA18271
) {
2131 dwval
&= ~FLD_DIF_IF_REF
;
2132 dwval
|= 0x88000300;
2134 dwval
|= 0x88000000;
2136 if (dev
->tuner_type
== TUNER_NXP_TDA18271
) {
2137 dwval
&= ~FLD_DIF_IF_REF
;
2138 dwval
|= 0xCC000300;
2140 dwval
|= 0x44000000;
2143 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, dwval
);
2148 /******************************************************************************
2149 * I 2 S - B L O C K C O N T R O L functions *
2150 ******************************************************************************/
2151 int cx231xx_i2s_blk_initialize(struct cx231xx
*dev
)
2156 status
= cx231xx_read_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
2157 CH_PWR_CTRL1
, 1, &value
, 1);
2158 /* enables clock to delta-sigma and decimation filter */
2160 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
2161 CH_PWR_CTRL1
, 1, value
, 1);
2162 /* power up all channel */
2163 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
2164 CH_PWR_CTRL2
, 1, 0x00, 1);
2169 int cx231xx_i2s_blk_update_power_control(struct cx231xx
*dev
,
2170 enum AV_MODE avmode
)
2175 if (avmode
!= POLARIS_AVMODE_ENXTERNAL_AV
) {
2176 status
= cx231xx_read_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
2177 CH_PWR_CTRL2
, 1, &value
, 1);
2179 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
2180 CH_PWR_CTRL2
, 1, value
, 1);
2182 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
2183 CH_PWR_CTRL2
, 1, 0x00, 1);
2189 /* set i2s_blk for audio input types */
2190 int cx231xx_i2s_blk_set_audio_input(struct cx231xx
*dev
, u8 audio_input
)
2194 switch (audio_input
) {
2195 case CX231XX_AMUX_LINE_IN
:
2196 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
2197 CH_PWR_CTRL2
, 1, 0x00, 1);
2198 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
2199 CH_PWR_CTRL1
, 1, 0x80, 1);
2201 case CX231XX_AMUX_VIDEO
:
2206 dev
->ctl_ainput
= audio_input
;
2211 /******************************************************************************
2212 * P O W E R C O N T R O L functions *
2213 ******************************************************************************/
2214 int cx231xx_set_power_mode(struct cx231xx
*dev
, enum AV_MODE mode
)
2216 u8 value
[4] = { 0, 0, 0, 0 };
2220 if (dev
->power_mode
!= mode
)
2221 dev
->power_mode
= mode
;
2223 cx231xx_info(" setPowerMode::mode = %d, No Change req.\n",
2228 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
, value
,
2233 tmp
= *((u32
*) value
);
2236 case POLARIS_AVMODE_ENXTERNAL_AV
:
2238 tmp
&= (~PWR_MODE_MASK
);
2241 value
[0] = (u8
) tmp
;
2242 value
[1] = (u8
) (tmp
>> 8);
2243 value
[2] = (u8
) (tmp
>> 16);
2244 value
[3] = (u8
) (tmp
>> 24);
2245 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2246 PWR_CTL_EN
, value
, 4);
2247 msleep(PWR_SLEEP_INTERVAL
);
2250 value
[0] = (u8
) tmp
;
2251 value
[1] = (u8
) (tmp
>> 8);
2252 value
[2] = (u8
) (tmp
>> 16);
2253 value
[3] = (u8
) (tmp
>> 24);
2255 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, PWR_CTL_EN
,
2257 msleep(PWR_SLEEP_INTERVAL
);
2259 tmp
|= POLARIS_AVMODE_ENXTERNAL_AV
;
2260 value
[0] = (u8
) tmp
;
2261 value
[1] = (u8
) (tmp
>> 8);
2262 value
[2] = (u8
) (tmp
>> 16);
2263 value
[3] = (u8
) (tmp
>> 24);
2264 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2265 PWR_CTL_EN
, value
, 4);
2267 /* reset state of xceive tuner */
2268 dev
->xc_fw_load_done
= 0;
2271 case POLARIS_AVMODE_ANALOGT_TV
:
2273 tmp
|= PWR_DEMOD_EN
;
2274 tmp
|= (I2C_DEMOD_EN
);
2275 value
[0] = (u8
) tmp
;
2276 value
[1] = (u8
) (tmp
>> 8);
2277 value
[2] = (u8
) (tmp
>> 16);
2278 value
[3] = (u8
) (tmp
>> 24);
2279 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2280 PWR_CTL_EN
, value
, 4);
2281 msleep(PWR_SLEEP_INTERVAL
);
2283 if (!(tmp
& PWR_TUNER_EN
)) {
2284 tmp
|= (PWR_TUNER_EN
);
2285 value
[0] = (u8
) tmp
;
2286 value
[1] = (u8
) (tmp
>> 8);
2287 value
[2] = (u8
) (tmp
>> 16);
2288 value
[3] = (u8
) (tmp
>> 24);
2289 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2290 PWR_CTL_EN
, value
, 4);
2291 msleep(PWR_SLEEP_INTERVAL
);
2294 if (!(tmp
& PWR_AV_EN
)) {
2296 value
[0] = (u8
) tmp
;
2297 value
[1] = (u8
) (tmp
>> 8);
2298 value
[2] = (u8
) (tmp
>> 16);
2299 value
[3] = (u8
) (tmp
>> 24);
2300 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2301 PWR_CTL_EN
, value
, 4);
2302 msleep(PWR_SLEEP_INTERVAL
);
2304 if (!(tmp
& PWR_ISO_EN
)) {
2306 value
[0] = (u8
) tmp
;
2307 value
[1] = (u8
) (tmp
>> 8);
2308 value
[2] = (u8
) (tmp
>> 16);
2309 value
[3] = (u8
) (tmp
>> 24);
2310 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2311 PWR_CTL_EN
, value
, 4);
2312 msleep(PWR_SLEEP_INTERVAL
);
2315 if (!(tmp
& POLARIS_AVMODE_ANALOGT_TV
)) {
2316 tmp
|= POLARIS_AVMODE_ANALOGT_TV
;
2317 value
[0] = (u8
) tmp
;
2318 value
[1] = (u8
) (tmp
>> 8);
2319 value
[2] = (u8
) (tmp
>> 16);
2320 value
[3] = (u8
) (tmp
>> 24);
2321 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2322 PWR_CTL_EN
, value
, 4);
2323 msleep(PWR_SLEEP_INTERVAL
);
2326 if (dev
->board
.tuner_type
!= TUNER_ABSENT
) {
2328 cx231xx_enable_i2c_port_3(dev
, true);
2330 /* reset the Tuner */
2331 if (dev
->board
.tuner_gpio
)
2332 cx231xx_gpio_set(dev
, dev
->board
.tuner_gpio
);
2334 if (dev
->cx231xx_reset_analog_tuner
)
2335 dev
->cx231xx_reset_analog_tuner(dev
);
2340 case POLARIS_AVMODE_DIGITAL
:
2341 if (!(tmp
& PWR_TUNER_EN
)) {
2342 tmp
|= (PWR_TUNER_EN
);
2343 value
[0] = (u8
) tmp
;
2344 value
[1] = (u8
) (tmp
>> 8);
2345 value
[2] = (u8
) (tmp
>> 16);
2346 value
[3] = (u8
) (tmp
>> 24);
2347 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2348 PWR_CTL_EN
, value
, 4);
2349 msleep(PWR_SLEEP_INTERVAL
);
2351 if (!(tmp
& PWR_AV_EN
)) {
2353 value
[0] = (u8
) tmp
;
2354 value
[1] = (u8
) (tmp
>> 8);
2355 value
[2] = (u8
) (tmp
>> 16);
2356 value
[3] = (u8
) (tmp
>> 24);
2357 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2358 PWR_CTL_EN
, value
, 4);
2359 msleep(PWR_SLEEP_INTERVAL
);
2361 if (!(tmp
& PWR_ISO_EN
)) {
2363 value
[0] = (u8
) tmp
;
2364 value
[1] = (u8
) (tmp
>> 8);
2365 value
[2] = (u8
) (tmp
>> 16);
2366 value
[3] = (u8
) (tmp
>> 24);
2367 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2368 PWR_CTL_EN
, value
, 4);
2369 msleep(PWR_SLEEP_INTERVAL
);
2372 tmp
&= (~PWR_AV_MODE
);
2373 tmp
|= POLARIS_AVMODE_DIGITAL
| I2C_DEMOD_EN
;
2374 value
[0] = (u8
) tmp
;
2375 value
[1] = (u8
) (tmp
>> 8);
2376 value
[2] = (u8
) (tmp
>> 16);
2377 value
[3] = (u8
) (tmp
>> 24);
2378 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2379 PWR_CTL_EN
, value
, 4);
2380 msleep(PWR_SLEEP_INTERVAL
);
2382 if (!(tmp
& PWR_DEMOD_EN
)) {
2383 tmp
|= PWR_DEMOD_EN
;
2384 value
[0] = (u8
) tmp
;
2385 value
[1] = (u8
) (tmp
>> 8);
2386 value
[2] = (u8
) (tmp
>> 16);
2387 value
[3] = (u8
) (tmp
>> 24);
2388 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2389 PWR_CTL_EN
, value
, 4);
2390 msleep(PWR_SLEEP_INTERVAL
);
2393 if (dev
->board
.tuner_type
!= TUNER_ABSENT
) {
2396 * Hauppauge Exeter seems to need to do something different!
2398 if (dev
->model
== CX231XX_BOARD_HAUPPAUGE_EXETER
)
2399 cx231xx_enable_i2c_port_3(dev
, false);
2401 cx231xx_enable_i2c_port_3(dev
, true);
2403 /* reset the Tuner */
2404 if (dev
->board
.tuner_gpio
)
2405 cx231xx_gpio_set(dev
, dev
->board
.tuner_gpio
);
2407 if (dev
->cx231xx_reset_analog_tuner
)
2408 dev
->cx231xx_reset_analog_tuner(dev
);
2416 msleep(PWR_SLEEP_INTERVAL
);
2418 /* For power saving, only enable Pwr_resetout_n
2419 when digital TV is selected. */
2420 if (mode
== POLARIS_AVMODE_DIGITAL
) {
2421 tmp
|= PWR_RESETOUT_EN
;
2422 value
[0] = (u8
) tmp
;
2423 value
[1] = (u8
) (tmp
>> 8);
2424 value
[2] = (u8
) (tmp
>> 16);
2425 value
[3] = (u8
) (tmp
>> 24);
2426 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2427 PWR_CTL_EN
, value
, 4);
2428 msleep(PWR_SLEEP_INTERVAL
);
2431 /* update power control for afe */
2432 status
= cx231xx_afe_update_power_control(dev
, mode
);
2434 /* update power control for i2s_blk */
2435 status
= cx231xx_i2s_blk_update_power_control(dev
, mode
);
2437 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
, value
,
2443 int cx231xx_power_suspend(struct cx231xx
*dev
)
2445 u8 value
[4] = { 0, 0, 0, 0 };
2449 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
,
2454 tmp
= *((u32
*) value
);
2455 tmp
&= (~PWR_MODE_MASK
);
2457 value
[0] = (u8
) tmp
;
2458 value
[1] = (u8
) (tmp
>> 8);
2459 value
[2] = (u8
) (tmp
>> 16);
2460 value
[3] = (u8
) (tmp
>> 24);
2461 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, PWR_CTL_EN
,
2467 /******************************************************************************
2468 * S T R E A M C O N T R O L functions *
2469 ******************************************************************************/
2470 int cx231xx_start_stream(struct cx231xx
*dev
, u32 ep_mask
)
2472 u8 value
[4] = { 0x0, 0x0, 0x0, 0x0 };
2476 cx231xx_info("cx231xx_start_stream():: ep_mask = %x\n", ep_mask
);
2477 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, EP_MODE_SET
,
2482 tmp
= *((u32
*) value
);
2484 value
[0] = (u8
) tmp
;
2485 value
[1] = (u8
) (tmp
>> 8);
2486 value
[2] = (u8
) (tmp
>> 16);
2487 value
[3] = (u8
) (tmp
>> 24);
2489 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, EP_MODE_SET
,
2495 int cx231xx_stop_stream(struct cx231xx
*dev
, u32 ep_mask
)
2497 u8 value
[4] = { 0x0, 0x0, 0x0, 0x0 };
2501 cx231xx_info("cx231xx_stop_stream():: ep_mask = %x\n", ep_mask
);
2503 cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, EP_MODE_SET
, value
, 4);
2507 tmp
= *((u32
*) value
);
2509 value
[0] = (u8
) tmp
;
2510 value
[1] = (u8
) (tmp
>> 8);
2511 value
[2] = (u8
) (tmp
>> 16);
2512 value
[3] = (u8
) (tmp
>> 24);
2514 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, EP_MODE_SET
,
2520 int cx231xx_initialize_stream_xfer(struct cx231xx
*dev
, u32 media_type
)
2524 u8 val
[4] = { 0, 0, 0, 0 };
2526 if (dev
->udev
->speed
== USB_SPEED_HIGH
) {
2527 switch (media_type
) {
2528 case 81: /* audio */
2529 cx231xx_info("%s: Audio enter HANC\n", __func__
);
2531 cx231xx_mode_register(dev
, TS_MODE_REG
, 0x9300);
2535 cx231xx_info("%s: set vanc registers\n", __func__
);
2536 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x300);
2539 case 3: /* sliced cc */
2540 cx231xx_info("%s: set hanc registers\n", __func__
);
2542 cx231xx_mode_register(dev
, TS_MODE_REG
, 0x1300);
2546 cx231xx_info("%s: set video registers\n", __func__
);
2547 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x100);
2551 cx231xx_info("%s: set ts1 registers", __func__
);
2553 if (dev
->model
== CX231XX_BOARD_CNXT_VIDEO_GRABBER
) {
2554 cx231xx_info(" MPEG\n");
2555 value
&= 0xFFFFFFFC;
2558 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, value
);
2564 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2565 TS1_CFG_REG
, val
, 4);
2571 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
2572 TS1_LENGTH_REG
, val
, 4);
2575 cx231xx_info(" BDA\n");
2576 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x101);
2577 status
= cx231xx_mode_register(dev
, TS1_CFG_REG
, 0x010);
2581 case 6: /* ts1 parallel mode */
2582 cx231xx_info("%s: set ts1 parrallel mode registers\n",
2584 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x100);
2585 status
= cx231xx_mode_register(dev
, TS1_CFG_REG
, 0x400);
2589 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x101);
2595 int cx231xx_capture_start(struct cx231xx
*dev
, int start
, u8 media_type
)
2599 struct pcb_config
*pcb_config
;
2601 /* get EP for media type */
2602 pcb_config
= (struct pcb_config
*)&dev
->current_pcb_config
;
2604 if (pcb_config
->config_num
== 1) {
2605 switch (media_type
) {
2607 ep_mask
= ENABLE_EP4
; /* ep4 [00:1000] */
2610 ep_mask
= ENABLE_EP3
; /* ep3 [00:0100] */
2613 ep_mask
= ENABLE_EP5
; /* ep5 [01:0000] */
2615 case 3: /* Sliced_cc */
2616 ep_mask
= ENABLE_EP6
; /* ep6 [10:0000] */
2619 case 6: /* ts1 parallel mode */
2620 ep_mask
= ENABLE_EP1
; /* ep1 [00:0001] */
2623 ep_mask
= ENABLE_EP2
; /* ep2 [00:0010] */
2627 } else if (pcb_config
->config_num
> 1) {
2628 switch (media_type
) {
2630 ep_mask
= ENABLE_EP4
; /* ep4 [00:1000] */
2633 ep_mask
= ENABLE_EP3
; /* ep3 [00:0100] */
2636 ep_mask
= ENABLE_EP5
; /* ep5 [01:0000] */
2638 case 3: /* Sliced_cc */
2639 ep_mask
= ENABLE_EP6
; /* ep6 [10:0000] */
2642 case 6: /* ts1 parallel mode */
2643 ep_mask
= ENABLE_EP1
; /* ep1 [00:0001] */
2646 ep_mask
= ENABLE_EP2
; /* ep2 [00:0010] */
2653 rc
= cx231xx_initialize_stream_xfer(dev
, media_type
);
2658 /* enable video capture */
2660 rc
= cx231xx_start_stream(dev
, ep_mask
);
2662 /* disable video capture */
2664 rc
= cx231xx_stop_stream(dev
, ep_mask
);
2667 if (dev
->mode
== CX231XX_ANALOG_MODE
)
2668 ;/* do any in Analog mode */
2670 ;/* do any in digital mode */
2674 EXPORT_SYMBOL_GPL(cx231xx_capture_start
);
2676 /*****************************************************************************
2677 * G P I O B I T control functions *
2678 ******************************************************************************/
2679 int cx231xx_set_gpio_bit(struct cx231xx
*dev
, u32 gpio_bit
, u8
*gpio_val
)
2683 status
= cx231xx_send_gpio_cmd(dev
, gpio_bit
, gpio_val
, 4, 0, 0);
2688 int cx231xx_get_gpio_bit(struct cx231xx
*dev
, u32 gpio_bit
, u8
*gpio_val
)
2692 status
= cx231xx_send_gpio_cmd(dev
, gpio_bit
, gpio_val
, 4, 0, 1);
2698 * cx231xx_set_gpio_direction
2699 * Sets the direction of the GPIO pin to input or output
2702 * pin_number : The GPIO Pin number to program the direction for
2704 * pin_value : The Direction of the GPIO Pin under reference.
2705 * 0 = Input direction
2706 * 1 = Output direction
2708 int cx231xx_set_gpio_direction(struct cx231xx
*dev
,
2709 int pin_number
, int pin_value
)
2714 /* Check for valid pin_number - if 32 , bail out */
2715 if (pin_number
>= 32)
2720 value
= dev
->gpio_dir
& (~(1 << pin_number
)); /* clear */
2722 value
= dev
->gpio_dir
| (1 << pin_number
);
2724 status
= cx231xx_set_gpio_bit(dev
, value
, (u8
*) &dev
->gpio_val
);
2726 /* cache the value for future */
2727 dev
->gpio_dir
= value
;
2733 * cx231xx_set_gpio_value
2734 * Sets the value of the GPIO pin to Logic high or low. The Pin under
2735 * reference should ALREADY BE SET IN OUTPUT MODE !!!!!!!!!
2738 * pin_number : The GPIO Pin number to program the direction for
2739 * pin_value : The value of the GPIO Pin under reference.
2743 int cx231xx_set_gpio_value(struct cx231xx
*dev
, int pin_number
, int pin_value
)
2748 /* Check for valid pin_number - if 0xFF , bail out */
2749 if (pin_number
>= 32)
2752 /* first do a sanity check - if the Pin is not output, make it output */
2753 if ((dev
->gpio_dir
& (1 << pin_number
)) == 0x00) {
2754 /* It was in input mode */
2755 value
= dev
->gpio_dir
| (1 << pin_number
);
2756 dev
->gpio_dir
= value
;
2757 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2758 (u8
*) &dev
->gpio_val
);
2763 value
= dev
->gpio_val
& (~(1 << pin_number
));
2765 value
= dev
->gpio_val
| (1 << pin_number
);
2767 /* store the value */
2768 dev
->gpio_val
= value
;
2770 /* toggle bit0 of GP_IO */
2771 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2776 /*****************************************************************************
2777 * G P I O I2C related functions *
2778 ******************************************************************************/
2779 int cx231xx_gpio_i2c_start(struct cx231xx
*dev
)
2783 /* set SCL to output 1 ; set SDA to output 1 */
2784 dev
->gpio_dir
|= 1 << dev
->board
.tuner_scl_gpio
;
2785 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
, (u8
*)&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
, (u8
*)&dev
->gpio_val
);
2801 /* set SCL to output 0; set SDA to output 0 */
2802 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2803 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2805 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2812 int cx231xx_gpio_i2c_end(struct cx231xx
*dev
)
2816 /* set SCL to output 0; set SDA to output 0 */
2817 dev
->gpio_dir
|= 1 << dev
->board
.tuner_scl_gpio
;
2818 dev
->gpio_dir
|= 1 << dev
->board
.tuner_sda_gpio
;
2820 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2821 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2823 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2827 /* set SCL to output 1; set SDA to output 0 */
2828 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2829 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2831 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2835 /* set SCL to input ,release SCL cable control
2836 set SDA to input ,release SDA cable control */
2837 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2838 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2841 cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2848 int cx231xx_gpio_i2c_write_byte(struct cx231xx
*dev
, u8 data
)
2853 /* set SCL to output ; set SDA to output */
2854 dev
->gpio_dir
|= 1 << dev
->board
.tuner_scl_gpio
;
2855 dev
->gpio_dir
|= 1 << dev
->board
.tuner_sda_gpio
;
2857 for (i
= 0; i
< 8; i
++) {
2858 if (((data
<< i
) & 0x80) == 0) {
2859 /* set SCL to output 0; set SDA to output 0 */
2860 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2861 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2862 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2863 (u8
*)&dev
->gpio_val
);
2865 /* set SCL to output 1; set SDA to output 0 */
2866 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2867 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2868 (u8
*)&dev
->gpio_val
);
2870 /* set SCL to output 0; set SDA to output 0 */
2871 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2872 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2873 (u8
*)&dev
->gpio_val
);
2875 /* set SCL to output 0; set SDA to output 1 */
2876 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2877 dev
->gpio_val
|= 1 << dev
->board
.tuner_sda_gpio
;
2878 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2879 (u8
*)&dev
->gpio_val
);
2881 /* set SCL to output 1; set SDA to output 1 */
2882 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2883 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2884 (u8
*)&dev
->gpio_val
);
2886 /* set SCL to output 0; set SDA to output 1 */
2887 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2888 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2889 (u8
*)&dev
->gpio_val
);
2895 int cx231xx_gpio_i2c_read_byte(struct cx231xx
*dev
, u8
*buf
)
2899 u32 gpio_logic_value
= 0;
2903 for (i
= 0; i
< 8; i
++) { /* send write I2c addr */
2905 /* set SCL to output 0; set SDA to input */
2906 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2907 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2908 (u8
*)&dev
->gpio_val
);
2910 /* set SCL to output 1; set SDA to input */
2911 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2912 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2913 (u8
*)&dev
->gpio_val
);
2915 /* get SDA data bit */
2916 gpio_logic_value
= dev
->gpio_val
;
2917 status
= cx231xx_get_gpio_bit(dev
, dev
->gpio_dir
,
2918 (u8
*)&dev
->gpio_val
);
2919 if ((dev
->gpio_val
& (1 << dev
->board
.tuner_sda_gpio
)) != 0)
2920 value
|= (1 << (8 - i
- 1));
2922 dev
->gpio_val
= gpio_logic_value
;
2925 /* set SCL to output 0,finish the read latest SCL signal.
2926 !!!set SDA to input, never to modify SDA direction at
2928 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2929 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2931 /* store the value */
2932 *buf
= value
& 0xff;
2937 int cx231xx_gpio_i2c_read_ack(struct cx231xx
*dev
)
2940 u32 gpio_logic_value
= 0;
2944 /* clock stretch; set SCL to input; set SDA to input;
2945 get SCL value till SCL = 1 */
2946 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2947 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2949 gpio_logic_value
= dev
->gpio_val
;
2950 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2954 status
= cx231xx_get_gpio_bit(dev
, dev
->gpio_dir
,
2955 (u8
*)&dev
->gpio_val
);
2957 } while (((dev
->gpio_val
&
2958 (1 << dev
->board
.tuner_scl_gpio
)) == 0) &&
2962 cx231xx_info("No ACK after %d msec -GPIO I2C failed!",
2967 * through clock stretch, slave has given a SCL signal,
2968 * so the SDA data can be directly read.
2970 status
= cx231xx_get_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2972 if ((dev
->gpio_val
& 1 << dev
->board
.tuner_sda_gpio
) == 0) {
2973 dev
->gpio_val
= gpio_logic_value
;
2974 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2977 dev
->gpio_val
= gpio_logic_value
;
2978 dev
->gpio_val
|= (1 << dev
->board
.tuner_sda_gpio
);
2981 /* read SDA end, set the SCL to output 0, after this operation,
2982 SDA direction can be changed. */
2983 dev
->gpio_val
= gpio_logic_value
;
2984 dev
->gpio_dir
|= (1 << dev
->board
.tuner_scl_gpio
);
2985 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2986 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2991 int cx231xx_gpio_i2c_write_ack(struct cx231xx
*dev
)
2995 /* set SDA to ouput */
2996 dev
->gpio_dir
|= 1 << dev
->board
.tuner_sda_gpio
;
2997 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2999 /* set SCL = 0 (output); set SDA = 0 (output) */
3000 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
3001 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
3002 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
3004 /* set SCL = 1 (output); set SDA = 0 (output) */
3005 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
3006 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
3008 /* set SCL = 0 (output); set SDA = 0 (output) */
3009 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
3010 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
3012 /* set SDA to input,and then the slave will read data from SDA. */
3013 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_sda_gpio
);
3014 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
3019 int cx231xx_gpio_i2c_write_nak(struct cx231xx
*dev
)
3023 /* set scl to output ; set sda to input */
3024 dev
->gpio_dir
|= 1 << dev
->board
.tuner_scl_gpio
;
3025 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_sda_gpio
);
3026 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
3028 /* set scl to output 0; set sda to input */
3029 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
3030 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
3032 /* set scl to output 1; set sda to input */
3033 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
3034 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
3039 /*****************************************************************************
3040 * G P I O I2C related functions *
3041 ******************************************************************************/
3042 /* cx231xx_gpio_i2c_read
3043 * Function to read data from gpio based I2C interface
3045 int cx231xx_gpio_i2c_read(struct cx231xx
*dev
, u8 dev_addr
, u8
*buf
, u8 len
)
3051 mutex_lock(&dev
->gpio_i2c_lock
);
3054 status
= cx231xx_gpio_i2c_start(dev
);
3056 /* write dev_addr */
3057 status
= cx231xx_gpio_i2c_write_byte(dev
, (dev_addr
<< 1) + 1);
3060 status
= cx231xx_gpio_i2c_read_ack(dev
);
3063 for (i
= 0; i
< len
; i
++) {
3066 status
= cx231xx_gpio_i2c_read_byte(dev
, &buf
[i
]);
3068 if ((i
+ 1) != len
) {
3069 /* only do write ack if we more length */
3070 status
= cx231xx_gpio_i2c_write_ack(dev
);
3074 /* write NAK - inform reads are complete */
3075 status
= cx231xx_gpio_i2c_write_nak(dev
);
3078 status
= cx231xx_gpio_i2c_end(dev
);
3080 /* release the lock */
3081 mutex_unlock(&dev
->gpio_i2c_lock
);
3086 /* cx231xx_gpio_i2c_write
3087 * Function to write data to gpio based I2C interface
3089 int cx231xx_gpio_i2c_write(struct cx231xx
*dev
, u8 dev_addr
, u8
*buf
, u8 len
)
3095 mutex_lock(&dev
->gpio_i2c_lock
);
3098 status
= cx231xx_gpio_i2c_start(dev
);
3100 /* write dev_addr */
3101 status
= cx231xx_gpio_i2c_write_byte(dev
, dev_addr
<< 1);
3104 status
= cx231xx_gpio_i2c_read_ack(dev
);
3106 for (i
= 0; i
< len
; i
++) {
3108 status
= cx231xx_gpio_i2c_write_byte(dev
, buf
[i
]);
3111 status
= cx231xx_gpio_i2c_read_ack(dev
);
3115 status
= cx231xx_gpio_i2c_end(dev
);
3117 /* release the lock */
3118 mutex_unlock(&dev
->gpio_i2c_lock
);