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>
35 #include <media/v4l2-common.h>
36 #include <media/v4l2-ioctl.h>
37 #include <media/v4l2-chip-ident.h>
41 /******************************************************************************
42 -: BLOCK ARRANGEMENT :-
43 I2S block ----------------------|
46 Analog Front End --> Direct IF -|-> Cx25840 --> Audio
47 [video & audio] | [Audio]
52 *******************************************************************************/
54 /******************************************************************************
55 * A F E - B L O C K C O N T R O L functions *
56 * [ANALOG FRONT END] *
57 ******************************************************************************/
58 static int afe_write_byte(struct cx231xx
*dev
, u16 saddr
, u8 data
)
60 return cx231xx_write_i2c_data(dev
, AFE_DEVICE_ADDRESS
,
64 static int afe_read_byte(struct cx231xx
*dev
, u16 saddr
, u8
*data
)
69 status
= cx231xx_read_i2c_data(dev
, AFE_DEVICE_ADDRESS
,
75 int cx231xx_afe_init_super_block(struct cx231xx
*dev
, u32 ref_count
)
79 u8 afe_power_status
= 0;
82 /* super block initialize */
83 temp
= (u8
) (ref_count
& 0xff);
84 status
= afe_write_byte(dev
, SUP_BLK_TUNE2
, temp
);
88 status
= afe_read_byte(dev
, SUP_BLK_TUNE2
, &afe_power_status
);
92 temp
= (u8
) ((ref_count
& 0x300) >> 8);
94 status
= afe_write_byte(dev
, SUP_BLK_TUNE1
, temp
);
98 status
= afe_write_byte(dev
, SUP_BLK_PLL2
, 0x0f);
103 while (afe_power_status
!= 0x18) {
104 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
, 0x18);
107 ": Init Super Block failed in send cmd\n");
111 status
= afe_read_byte(dev
, SUP_BLK_PWRDN
, &afe_power_status
);
112 afe_power_status
&= 0xff;
115 ": Init Super Block failed in receive cmd\n");
121 ": Init Super Block force break in loop !!!!\n");
130 /* start tuning filter */
131 status
= afe_write_byte(dev
, SUP_BLK_TUNE3
, 0x40);
138 status
= afe_write_byte(dev
, SUP_BLK_TUNE3
, 0x00);
143 int cx231xx_afe_init_channels(struct cx231xx
*dev
)
147 /* power up all 3 channels, clear pd_buffer */
148 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
, 0x00);
149 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
, 0x00);
150 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
, 0x00);
152 /* Enable quantizer calibration */
153 status
= afe_write_byte(dev
, ADC_COM_QUANT
, 0x02);
155 /* channel initialize, force modulator (fb) reset */
156 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH1
, 0x17);
157 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH2
, 0x17);
158 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH3
, 0x17);
160 /* start quantilizer calibration */
161 status
= afe_write_byte(dev
, ADC_CAL_ATEST_CH1
, 0x10);
162 status
= afe_write_byte(dev
, ADC_CAL_ATEST_CH2
, 0x10);
163 status
= afe_write_byte(dev
, ADC_CAL_ATEST_CH3
, 0x10);
166 /* exit modulator (fb) reset */
167 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH1
, 0x07);
168 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH2
, 0x07);
169 status
= afe_write_byte(dev
, ADC_FB_FRCRST_CH3
, 0x07);
171 /* enable the pre_clamp in each channel for single-ended input */
172 status
= afe_write_byte(dev
, ADC_NTF_PRECLMP_EN_CH1
, 0xf0);
173 status
= afe_write_byte(dev
, ADC_NTF_PRECLMP_EN_CH2
, 0xf0);
174 status
= afe_write_byte(dev
, ADC_NTF_PRECLMP_EN_CH3
, 0xf0);
176 /* use diode instead of resistor, so set term_en to 0, res_en to 0 */
177 status
= cx231xx_reg_mask_write(dev
, AFE_DEVICE_ADDRESS
, 8,
178 ADC_QGAIN_RES_TRM_CH1
, 3, 7, 0x00);
179 status
= cx231xx_reg_mask_write(dev
, AFE_DEVICE_ADDRESS
, 8,
180 ADC_QGAIN_RES_TRM_CH2
, 3, 7, 0x00);
181 status
= cx231xx_reg_mask_write(dev
, AFE_DEVICE_ADDRESS
, 8,
182 ADC_QGAIN_RES_TRM_CH3
, 3, 7, 0x00);
184 /* dynamic element matching off */
185 status
= afe_write_byte(dev
, ADC_DCSERVO_DEM_CH1
, 0x03);
186 status
= afe_write_byte(dev
, ADC_DCSERVO_DEM_CH2
, 0x03);
187 status
= afe_write_byte(dev
, ADC_DCSERVO_DEM_CH3
, 0x03);
192 int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx
*dev
)
197 status
= afe_read_byte(dev
, ADC_PWRDN_CLAMP_CH2
, &c_value
);
198 c_value
&= (~(0x50));
199 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
, c_value
);
205 The Analog Front End in Cx231xx has 3 channels. These
206 channels are used to share between different inputs
207 like tuner, s-video and composite inputs.
209 channel 1 ----- pin 1 to pin4(in reg is 1-4)
210 channel 2 ----- pin 5 to pin8(in reg is 5-8)
211 channel 3 ----- pin 9 to pin 12(in reg is 9-11)
213 int cx231xx_afe_set_input_mux(struct cx231xx
*dev
, u32 input_mux
)
215 u8 ch1_setting
= (u8
) input_mux
;
216 u8 ch2_setting
= (u8
) (input_mux
>> 8);
217 u8 ch3_setting
= (u8
) (input_mux
>> 16);
221 if (ch1_setting
!= 0) {
222 status
= afe_read_byte(dev
, ADC_INPUT_CH1
, &value
);
223 value
&= (!INPUT_SEL_MASK
);
224 value
|= (ch1_setting
- 1) << 4;
226 status
= afe_write_byte(dev
, ADC_INPUT_CH1
, value
);
229 if (ch2_setting
!= 0) {
230 status
= afe_read_byte(dev
, ADC_INPUT_CH2
, &value
);
231 value
&= (!INPUT_SEL_MASK
);
232 value
|= (ch2_setting
- 1) << 4;
234 status
= afe_write_byte(dev
, ADC_INPUT_CH2
, value
);
237 /* For ch3_setting, the value to put in the register is
238 7 less than the input number */
239 if (ch3_setting
!= 0) {
240 status
= afe_read_byte(dev
, ADC_INPUT_CH3
, &value
);
241 value
&= (!INPUT_SEL_MASK
);
242 value
|= (ch3_setting
- 1) << 4;
244 status
= afe_write_byte(dev
, ADC_INPUT_CH3
, value
);
250 int cx231xx_afe_set_mode(struct cx231xx
*dev
, enum AFE_MODE mode
)
255 * FIXME: We need to implement the AFE code for LOW IF and for HI IF.
256 * Currently, only baseband works.
260 case AFE_MODE_LOW_IF
:
261 /* SetupAFEforLowIF(); */
263 case AFE_MODE_BASEBAND
:
264 status
= cx231xx_afe_setup_AFE_for_baseband(dev
);
266 case AFE_MODE_EU_HI_IF
:
267 /* SetupAFEforEuHiIF(); */
269 case AFE_MODE_US_HI_IF
:
270 /* SetupAFEforUsHiIF(); */
272 case AFE_MODE_JAPAN_HI_IF
:
273 /* SetupAFEforJapanHiIF(); */
277 if ((mode
!= dev
->afe_mode
) &&
278 (dev
->video_input
== CX231XX_VMUX_TELEVISION
))
279 status
= cx231xx_afe_adjust_ref_count(dev
,
280 CX231XX_VMUX_TELEVISION
);
282 dev
->afe_mode
= mode
;
287 int cx231xx_afe_update_power_control(struct cx231xx
*dev
,
290 u8 afe_power_status
= 0;
293 switch (dev
->model
) {
294 case CX231XX_BOARD_CNXT_RDE_250
:
295 case CX231XX_BOARD_CNXT_RDU_250
:
296 if (avmode
== POLARIS_AVMODE_ANALOGT_TV
) {
297 while (afe_power_status
!= (FLD_PWRDN_TUNING_BIAS
|
298 FLD_PWRDN_ENABLE_PLL
)) {
299 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
,
300 FLD_PWRDN_TUNING_BIAS
|
301 FLD_PWRDN_ENABLE_PLL
);
302 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
308 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
310 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
312 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
314 } else if (avmode
== POLARIS_AVMODE_DIGITAL
) {
315 status
= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
317 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
319 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
322 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
324 afe_power_status
|= FLD_PWRDN_PD_BANDGAP
|
327 status
|= afe_write_byte(dev
, SUP_BLK_PWRDN
,
329 } else if (avmode
== POLARIS_AVMODE_ENXTERNAL_AV
) {
330 while (afe_power_status
!= (FLD_PWRDN_TUNING_BIAS
|
331 FLD_PWRDN_ENABLE_PLL
)) {
332 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
,
333 FLD_PWRDN_TUNING_BIAS
|
334 FLD_PWRDN_ENABLE_PLL
);
335 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
341 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
343 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
345 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
348 cx231xx_info("Invalid AV mode input\n");
353 if (avmode
== POLARIS_AVMODE_ANALOGT_TV
) {
354 while (afe_power_status
!= (FLD_PWRDN_TUNING_BIAS
|
355 FLD_PWRDN_ENABLE_PLL
)) {
356 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
,
357 FLD_PWRDN_TUNING_BIAS
|
358 FLD_PWRDN_ENABLE_PLL
);
359 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
365 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
367 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
369 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
371 } else if (avmode
== POLARIS_AVMODE_DIGITAL
) {
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
,
379 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
381 afe_power_status
|= FLD_PWRDN_PD_BANDGAP
|
384 status
|= afe_write_byte(dev
, SUP_BLK_PWRDN
,
386 } else if (avmode
== POLARIS_AVMODE_ENXTERNAL_AV
) {
387 while (afe_power_status
!= (FLD_PWRDN_TUNING_BIAS
|
388 FLD_PWRDN_ENABLE_PLL
)) {
389 status
= afe_write_byte(dev
, SUP_BLK_PWRDN
,
390 FLD_PWRDN_TUNING_BIAS
|
391 FLD_PWRDN_ENABLE_PLL
);
392 status
|= afe_read_byte(dev
, SUP_BLK_PWRDN
,
398 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH1
,
400 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH2
,
402 status
|= afe_write_byte(dev
, ADC_PWRDN_CLAMP_CH3
,
405 cx231xx_info("Invalid AV mode input\n");
413 int cx231xx_afe_adjust_ref_count(struct cx231xx
*dev
, u32 video_input
)
419 dev
->video_input
= video_input
;
421 if (video_input
== CX231XX_VMUX_TELEVISION
) {
422 status
= afe_read_byte(dev
, ADC_INPUT_CH3
, &input_mode
);
423 status
= afe_read_byte(dev
, ADC_NTF_PRECLMP_EN_CH3
,
426 status
= afe_read_byte(dev
, ADC_INPUT_CH1
, &input_mode
);
427 status
= afe_read_byte(dev
, ADC_NTF_PRECLMP_EN_CH1
,
431 input_mode
= (ntf_mode
& 0x3) | ((input_mode
& 0x6) << 1);
433 switch (input_mode
) {
435 dev
->afe_ref_count
= 0x23C;
438 dev
->afe_ref_count
= 0x24C;
441 dev
->afe_ref_count
= 0x258;
444 dev
->afe_ref_count
= 0x260;
450 status
= cx231xx_afe_init_super_block(dev
, dev
->afe_ref_count
);
455 /******************************************************************************
456 * 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 *
457 ******************************************************************************/
458 static int vid_blk_write_byte(struct cx231xx
*dev
, u16 saddr
, u8 data
)
460 return cx231xx_write_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
464 static int vid_blk_read_byte(struct cx231xx
*dev
, u16 saddr
, u8
*data
)
469 status
= cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
475 static int vid_blk_write_word(struct cx231xx
*dev
, u16 saddr
, u32 data
)
477 return cx231xx_write_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
481 static int vid_blk_read_word(struct cx231xx
*dev
, u16 saddr
, u32
*data
)
483 return cx231xx_read_i2c_data(dev
, VID_BLK_I2C_ADDRESS
,
487 int cx231xx_set_video_input_mux(struct cx231xx
*dev
, u8 input
)
491 switch (INPUT(input
)->type
) {
492 case CX231XX_VMUX_COMPOSITE1
:
493 case CX231XX_VMUX_SVIDEO
:
494 if ((dev
->current_pcb_config
.type
== USB_BUS_POWER
) &&
495 (dev
->power_mode
!= POLARIS_AVMODE_ENXTERNAL_AV
)) {
497 status
= cx231xx_set_power_mode(dev
,
498 POLARIS_AVMODE_ENXTERNAL_AV
);
500 cx231xx_errdev("%s: set_power_mode : Failed to"
501 " set Power - errCode [%d]!\n",
506 status
= cx231xx_set_decoder_video_input(dev
,
510 case CX231XX_VMUX_TELEVISION
:
511 case CX231XX_VMUX_CABLE
:
512 if ((dev
->current_pcb_config
.type
== USB_BUS_POWER
) &&
513 (dev
->power_mode
!= POLARIS_AVMODE_ANALOGT_TV
)) {
515 status
= cx231xx_set_power_mode(dev
,
516 POLARIS_AVMODE_ANALOGT_TV
);
518 cx231xx_errdev("%s: set_power_mode:Failed"
519 " to set Power - errCode [%d]!\n",
524 status
= cx231xx_set_decoder_video_input(dev
,
525 CX231XX_VMUX_COMPOSITE1
,
529 cx231xx_errdev("%s: set_power_mode : Unknown Input %d !\n",
530 __func__
, INPUT(input
)->type
);
534 /* save the selection */
535 dev
->video_input
= input
;
540 int cx231xx_set_decoder_video_input(struct cx231xx
*dev
,
541 u8 pin_type
, u8 input
)
546 if (pin_type
!= dev
->video_input
) {
547 status
= cx231xx_afe_adjust_ref_count(dev
, pin_type
);
549 cx231xx_errdev("%s: adjust_ref_count :Failed to set"
550 "AFE input mux - errCode [%d]!\n",
556 /* call afe block to set video inputs */
557 status
= cx231xx_afe_set_input_mux(dev
, input
);
559 cx231xx_errdev("%s: set_input_mux :Failed to set"
560 " AFE input mux - errCode [%d]!\n",
566 case CX231XX_VMUX_COMPOSITE1
:
567 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
568 value
|= (0 << 13) | (1 << 4);
571 /* set [24:23] [22:15] to 0 */
572 value
&= (~(0x1ff8000));
573 /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */
575 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
577 status
= vid_blk_read_word(dev
, OUT_CTRL1
, &value
);
579 status
= vid_blk_write_word(dev
, OUT_CTRL1
, value
);
581 /* Set vip 1.1 output mode */
582 status
= cx231xx_read_modify_write_i2c_dword(dev
,
588 /* Tell DIF object to go to baseband mode */
589 status
= cx231xx_dif_set_standard(dev
, DIF_USE_BASEBAND
);
591 cx231xx_errdev("%s: cx231xx_dif set to By pass"
592 " mode- errCode [%d]!\n",
597 /* Read the DFE_CTRL1 register */
598 status
= vid_blk_read_word(dev
, DFE_CTRL1
, &value
);
600 /* enable the VBI_GATE_EN */
601 value
|= FLD_VBI_GATE_EN
;
603 /* Enable the auto-VGA enable */
604 value
|= FLD_VGA_AUTO_EN
;
607 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
609 /* Disable auto config of registers */
610 status
= cx231xx_read_modify_write_i2c_dword(dev
,
612 MODE_CTRL
, FLD_ACFG_DIS
,
613 cx231xx_set_field(FLD_ACFG_DIS
, 1));
615 /* Set CVBS input mode */
616 status
= cx231xx_read_modify_write_i2c_dword(dev
,
618 MODE_CTRL
, FLD_INPUT_MODE
,
619 cx231xx_set_field(FLD_INPUT_MODE
, INPUT_MODE_CVBS_0
));
621 case CX231XX_VMUX_SVIDEO
:
622 /* Disable the use of DIF */
624 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
626 /* set [24:23] [22:15] to 0 */
627 value
&= (~(0x1ff8000));
628 /* set FUNC_MODE[24:23] = 2
629 IF_MOD[22:15] = 0 DCR_BYP_CH2[4:4] = 1; */
631 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
633 /* Tell DIF object to go to baseband mode */
634 status
= cx231xx_dif_set_standard(dev
, DIF_USE_BASEBAND
);
636 cx231xx_errdev("%s: cx231xx_dif set to By pass"
637 " mode- errCode [%d]!\n",
642 /* Read the DFE_CTRL1 register */
643 status
= vid_blk_read_word(dev
, DFE_CTRL1
, &value
);
645 /* enable the VBI_GATE_EN */
646 value
|= FLD_VBI_GATE_EN
;
648 /* Enable the auto-VGA enable */
649 value
|= FLD_VGA_AUTO_EN
;
652 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
654 /* Disable auto config of registers */
655 status
= cx231xx_read_modify_write_i2c_dword(dev
,
657 MODE_CTRL
, FLD_ACFG_DIS
,
658 cx231xx_set_field(FLD_ACFG_DIS
, 1));
660 /* Set YC input mode */
661 status
= cx231xx_read_modify_write_i2c_dword(dev
,
665 cx231xx_set_field(FLD_INPUT_MODE
, INPUT_MODE_YC_1
));
668 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
669 value
|= FLD_CHROMA_IN_SEL
; /* set the chroma in select */
671 /* Clear VGA_SEL_CH2 and VGA_SEL_CH3 (bits 7 and 8)
672 This sets them to use video
673 rather than audio. Only one of the two will be in use. */
674 value
&= ~(FLD_VGA_SEL_CH2
| FLD_VGA_SEL_CH3
);
676 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
678 status
= cx231xx_afe_set_mode(dev
, AFE_MODE_BASEBAND
);
680 case CX231XX_VMUX_TELEVISION
:
681 case CX231XX_VMUX_CABLE
:
683 switch (dev
->model
) {
684 case CX231XX_BOARD_CNXT_RDE_250
:
685 case CX231XX_BOARD_CNXT_RDU_250
:
686 /* Disable the use of DIF */
688 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
689 value
|= (0 << 13) | (1 << 4);
692 /* set [24:23] [22:15] to 0 */
693 value
&= (~(0x1FF8000));
694 /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */
696 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
698 status
= vid_blk_read_word(dev
, OUT_CTRL1
, &value
);
700 status
= vid_blk_write_word(dev
, OUT_CTRL1
, value
);
702 /* Set vip 1.1 output mode */
703 status
= cx231xx_read_modify_write_i2c_dword(dev
,
705 OUT_CTRL1
, FLD_OUT_MODE
,
708 /* Tell DIF object to go to baseband mode */
709 status
= cx231xx_dif_set_standard(dev
,
712 cx231xx_errdev("%s: cx231xx_dif set to By pass"
713 " mode- errCode [%d]!\n",
718 /* Read the DFE_CTRL1 register */
719 status
= vid_blk_read_word(dev
, DFE_CTRL1
, &value
);
721 /* enable the VBI_GATE_EN */
722 value
|= FLD_VBI_GATE_EN
;
724 /* Enable the auto-VGA enable */
725 value
|= FLD_VGA_AUTO_EN
;
728 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
730 /* Disable auto config of registers */
731 status
= cx231xx_read_modify_write_i2c_dword(dev
,
733 MODE_CTRL
, FLD_ACFG_DIS
,
734 cx231xx_set_field(FLD_ACFG_DIS
, 1));
736 /* Set CVBS input mode */
737 status
= cx231xx_read_modify_write_i2c_dword(dev
,
739 MODE_CTRL
, FLD_INPUT_MODE
,
740 cx231xx_set_field(FLD_INPUT_MODE
,
744 /* Enable the DIF for the tuner */
746 /* Reinitialize the DIF */
747 status
= cx231xx_dif_set_standard(dev
, dev
->norm
);
749 cx231xx_errdev("%s: cx231xx_dif set to By pass"
750 " mode- errCode [%d]!\n",
755 /* Make sure bypass is cleared */
756 status
= vid_blk_read_word(dev
, DIF_MISC_CTRL
, &value
);
758 /* Clear the bypass bit */
759 value
&= ~FLD_DIF_DIF_BYPASS
;
761 /* Enable the use of the DIF block */
762 status
= vid_blk_write_word(dev
, DIF_MISC_CTRL
, value
);
764 /* Read the DFE_CTRL1 register */
765 status
= vid_blk_read_word(dev
, DFE_CTRL1
, &value
);
767 /* Disable the VBI_GATE_EN */
768 value
&= ~FLD_VBI_GATE_EN
;
770 /* Enable the auto-VGA enable, AGC, and
771 set the skip count to 2 */
772 value
|= FLD_VGA_AUTO_EN
| FLD_AGC_AUTO_EN
| 0x00200000;
775 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
777 /* Wait until AGC locks up */
780 /* Disable the auto-VGA enable AGC */
781 value
&= ~(FLD_VGA_AUTO_EN
);
784 status
= vid_blk_write_word(dev
, DFE_CTRL1
, value
);
786 /* Enable Polaris B0 AGC output */
787 status
= vid_blk_read_word(dev
, PIN_CTRL
, &value
);
788 value
|= (FLD_OEF_AGC_RF
) |
789 (FLD_OEF_AGC_IFVGA
) |
791 status
= vid_blk_write_word(dev
, PIN_CTRL
, value
);
793 /* Set vip 1.1 output mode */
794 status
= cx231xx_read_modify_write_i2c_dword(dev
,
796 OUT_CTRL1
, FLD_OUT_MODE
,
799 /* Disable auto config of registers */
800 status
= cx231xx_read_modify_write_i2c_dword(dev
,
802 MODE_CTRL
, FLD_ACFG_DIS
,
803 cx231xx_set_field(FLD_ACFG_DIS
, 1));
805 /* Set CVBS input mode */
806 status
= cx231xx_read_modify_write_i2c_dword(dev
,
808 MODE_CTRL
, FLD_INPUT_MODE
,
809 cx231xx_set_field(FLD_INPUT_MODE
,
812 /* Set some bits in AFE_CTRL so that channel 2 or 3
813 * is ready to receive audio */
814 /* Clear clamp for channels 2 and 3 (bit 16-17) */
815 /* Clear droop comp (bit 19-20) */
816 /* Set VGA_SEL (for audio control) (bit 7-8) */
817 status
= vid_blk_read_word(dev
, AFE_CTRL
, &value
);
819 value
|= FLD_VGA_SEL_CH3
| FLD_VGA_SEL_CH2
;
821 status
= vid_blk_write_word(dev
, AFE_CTRL
, value
);
828 /* Set raw VBI mode */
829 status
= cx231xx_read_modify_write_i2c_dword(dev
,
831 OUT_CTRL1
, FLD_VBIHACTRAW_EN
,
832 cx231xx_set_field(FLD_VBIHACTRAW_EN
, 1));
834 status
= vid_blk_read_word(dev
, OUT_CTRL1
, &value
);
837 status
= vid_blk_write_word(dev
, OUT_CTRL1
, value
);
844 * Handle any video-mode specific overrides that are different
845 * on a per video standards basis after touching the MODE_CTRL
846 * register which resets many values for autodetect
848 int cx231xx_do_mode_ctrl_overrides(struct cx231xx
*dev
)
852 cx231xx_info("do_mode_ctrl_overrides : 0x%x\n",
853 (unsigned int)dev
->norm
);
855 /* Change the DFE_CTRL3 bp_percent to fix flagging */
856 status
= vid_blk_write_word(dev
, DFE_CTRL3
, 0xCD3F0280);
858 if (dev
->norm
& (V4L2_STD_NTSC
| V4L2_STD_PAL_M
)) {
859 cx231xx_info("do_mode_ctrl_overrides NTSC\n");
861 /* Move the close caption lines out of active video,
862 adjust the active video start point */
863 status
= cx231xx_read_modify_write_i2c_dword(dev
,
866 FLD_VBLANK_CNT
, 0x18);
867 status
= cx231xx_read_modify_write_i2c_dword(dev
,
872 status
= cx231xx_read_modify_write_i2c_dword(dev
,
878 status
= cx231xx_read_modify_write_i2c_dword(dev
,
883 (FLD_HBLANK_CNT
, 0x79));
884 } else if (dev
->norm
& V4L2_STD_SECAM
) {
885 cx231xx_info("do_mode_ctrl_overrides SECAM\n");
886 status
= cx231xx_read_modify_write_i2c_dword(dev
,
889 FLD_VBLANK_CNT
, 0x24);
890 /* Adjust the active video horizontal start point */
891 status
= cx231xx_read_modify_write_i2c_dword(dev
,
896 (FLD_HBLANK_CNT
, 0x85));
898 cx231xx_info("do_mode_ctrl_overrides PAL\n");
899 status
= cx231xx_read_modify_write_i2c_dword(dev
,
902 FLD_VBLANK_CNT
, 0x24);
903 /* Adjust the active video horizontal start point */
904 status
= cx231xx_read_modify_write_i2c_dword(dev
,
909 (FLD_HBLANK_CNT
, 0x85));
915 int cx231xx_set_audio_input(struct cx231xx
*dev
, u8 input
)
918 enum AUDIO_INPUT ainput
= AUDIO_INPUT_LINE
;
920 switch (INPUT(input
)->amux
) {
921 case CX231XX_AMUX_VIDEO
:
922 ainput
= AUDIO_INPUT_TUNER_TV
;
924 case CX231XX_AMUX_LINE_IN
:
925 status
= cx231xx_i2s_blk_set_audio_input(dev
, input
);
926 ainput
= AUDIO_INPUT_LINE
;
932 status
= cx231xx_set_audio_decoder_input(dev
, ainput
);
937 int cx231xx_set_audio_decoder_input(struct cx231xx
*dev
,
938 enum AUDIO_INPUT audio_input
)
945 /* Put it in soft reset */
946 status
= vid_blk_read_byte(dev
, GENERAL_CTL
, &gen_ctrl
);
948 status
= vid_blk_write_byte(dev
, GENERAL_CTL
, gen_ctrl
);
950 switch (audio_input
) {
951 case AUDIO_INPUT_LINE
:
952 /* setup AUD_IO control from Merlin paralle output */
953 value
= cx231xx_set_field(FLD_AUD_CHAN1_SRC
,
954 AUD_CHAN_SRC_PARALLEL
);
955 status
= vid_blk_write_word(dev
, AUD_IO_CTRL
, value
);
957 /* setup input to Merlin, SRC2 connect to AC97
958 bypass upsample-by-2, slave mode, sony mode, left justify
959 adr 091c, dat 01000000 */
960 status
= vid_blk_read_word(dev
, AC97_CTL
, &dwval
);
962 status
= vid_blk_write_word(dev
, AC97_CTL
,
963 (dwval
| FLD_AC97_UP2X_BYPASS
));
965 /* select the parallel1 and SRC3 */
966 status
= vid_blk_write_word(dev
, BAND_OUT_SEL
,
967 cx231xx_set_field(FLD_SRC3_IN_SEL
, 0x0) |
968 cx231xx_set_field(FLD_SRC3_CLK_SEL
, 0x0) |
969 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL
, 0x0));
971 /* unmute all, AC97 in, independence mode
972 adr 08d0, data 0x00063073 */
973 status
= vid_blk_write_word(dev
, PATH1_CTL1
, 0x00063073);
975 /* set AVC maximum threshold, adr 08d4, dat ffff0024 */
976 status
= vid_blk_read_word(dev
, PATH1_VOL_CTL
, &dwval
);
977 status
= vid_blk_write_word(dev
, PATH1_VOL_CTL
,
978 (dwval
| FLD_PATH1_AVC_THRESHOLD
));
980 /* set SC maximum threshold, adr 08ec, dat ffffb3a3 */
981 status
= vid_blk_read_word(dev
, PATH1_SC_CTL
, &dwval
);
982 status
= vid_blk_write_word(dev
, PATH1_SC_CTL
,
983 (dwval
| FLD_PATH1_SC_THRESHOLD
));
986 case AUDIO_INPUT_TUNER_TV
:
989 /* Setup SRC sources and clocks */
990 status
= vid_blk_write_word(dev
, BAND_OUT_SEL
,
991 cx231xx_set_field(FLD_SRC6_IN_SEL
, 0x00) |
992 cx231xx_set_field(FLD_SRC6_CLK_SEL
, 0x01) |
993 cx231xx_set_field(FLD_SRC5_IN_SEL
, 0x00) |
994 cx231xx_set_field(FLD_SRC5_CLK_SEL
, 0x02) |
995 cx231xx_set_field(FLD_SRC4_IN_SEL
, 0x02) |
996 cx231xx_set_field(FLD_SRC4_CLK_SEL
, 0x03) |
997 cx231xx_set_field(FLD_SRC3_IN_SEL
, 0x00) |
998 cx231xx_set_field(FLD_SRC3_CLK_SEL
, 0x00) |
999 cx231xx_set_field(FLD_BASEBAND_BYPASS_CTL
, 0x00) |
1000 cx231xx_set_field(FLD_AC97_SRC_SEL
, 0x03) |
1001 cx231xx_set_field(FLD_I2S_SRC_SEL
, 0x00) |
1002 cx231xx_set_field(FLD_PARALLEL2_SRC_SEL
, 0x02) |
1003 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL
, 0x01));
1005 /* Setup the AUD_IO control */
1006 status
= vid_blk_write_word(dev
, AUD_IO_CTRL
,
1007 cx231xx_set_field(FLD_I2S_PORT_DIR
, 0x00) |
1008 cx231xx_set_field(FLD_I2S_OUT_SRC
, 0x00) |
1009 cx231xx_set_field(FLD_AUD_CHAN3_SRC
, 0x00) |
1010 cx231xx_set_field(FLD_AUD_CHAN2_SRC
, 0x00) |
1011 cx231xx_set_field(FLD_AUD_CHAN1_SRC
, 0x03));
1013 status
= vid_blk_write_word(dev
, PATH1_CTL1
, 0x1F063870);
1015 /* setAudioStandard(_audio_standard); */
1017 status
= vid_blk_write_word(dev
, PATH1_CTL1
, 0x00063870);
1018 switch (dev
->model
) {
1019 case CX231XX_BOARD_CNXT_RDE_250
:
1020 case CX231XX_BOARD_CNXT_RDU_250
:
1021 status
= cx231xx_read_modify_write_i2c_dword(dev
,
1022 VID_BLK_I2C_ADDRESS
,
1025 cx231xx_set_field(FLD_SIF_EN
, 1));
1032 case AUDIO_INPUT_TUNER_FM
:
1033 /* use SIF for FM radio
1035 setAudioStandard(_audio_standard);
1039 case AUDIO_INPUT_MUTE
:
1040 status
= vid_blk_write_word(dev
, PATH1_CTL1
, 0x1F011012);
1044 /* Take it out of soft reset */
1045 status
= vid_blk_read_byte(dev
, GENERAL_CTL
, &gen_ctrl
);
1047 status
= vid_blk_write_byte(dev
, GENERAL_CTL
, gen_ctrl
);
1052 /* Set resolution of the video */
1053 int cx231xx_resolution_set(struct cx231xx
*dev
)
1055 /* set horzontal scale */
1056 int status
= vid_blk_write_word(dev
, HSCALE_CTRL
, dev
->hscale
);
1060 /* set vertical scale */
1061 return vid_blk_write_word(dev
, VSCALE_CTRL
, dev
->vscale
);
1064 /******************************************************************************
1065 * C H I P Specific C O N T R O L functions *
1066 ******************************************************************************/
1067 int cx231xx_init_ctrl_pin_status(struct cx231xx
*dev
)
1072 status
= vid_blk_read_word(dev
, PIN_CTRL
, &value
);
1073 value
|= (~dev
->board
.ctl_pin_status_mask
);
1074 status
= vid_blk_write_word(dev
, PIN_CTRL
, value
);
1079 int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx
*dev
,
1080 u8 analog_or_digital
)
1084 /* first set the direction to output */
1085 status
= cx231xx_set_gpio_direction(dev
,
1087 agc_analog_digital_select_gpio
, 1);
1089 /* 0 - demod ; 1 - Analog mode */
1090 status
= cx231xx_set_gpio_value(dev
,
1091 dev
->board
.agc_analog_digital_select_gpio
,
1097 int cx231xx_enable_i2c_for_tuner(struct cx231xx
*dev
, u8 I2CIndex
)
1099 u8 value
[4] = { 0, 0, 0, 0 };
1102 cx231xx_info("Changing the i2c port for tuner to %d\n", I2CIndex
);
1104 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
,
1105 PWR_CTL_EN
, value
, 4);
1109 if (I2CIndex
== I2C_1
) {
1110 if (value
[0] & I2C_DEMOD_EN
) {
1111 value
[0] &= ~I2C_DEMOD_EN
;
1112 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1113 PWR_CTL_EN
, value
, 4);
1116 if (!(value
[0] & I2C_DEMOD_EN
)) {
1117 value
[0] |= I2C_DEMOD_EN
;
1118 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1119 PWR_CTL_EN
, value
, 4);
1127 /******************************************************************************
1128 * D I F - B L O C K C O N T R O L functions *
1129 ******************************************************************************/
1130 int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx
*dev
, u32 mode
,
1131 u32 function_mode
, u32 standard
)
1135 if (mode
== V4L2_TUNER_RADIO
) {
1137 /* lo if big signal */
1138 status
= cx231xx_reg_mask_write(dev
,
1139 VID_BLK_I2C_ADDRESS
, 32,
1140 AFE_CTRL_C2HH_SRC_CTRL
, 30, 31, 0x1);
1141 /* FUNC_MODE = DIF */
1142 status
= cx231xx_reg_mask_write(dev
,
1143 VID_BLK_I2C_ADDRESS
, 32,
1144 AFE_CTRL_C2HH_SRC_CTRL
, 23, 24, function_mode
);
1146 status
= cx231xx_reg_mask_write(dev
,
1147 VID_BLK_I2C_ADDRESS
, 32,
1148 AFE_CTRL_C2HH_SRC_CTRL
, 15, 22, 0xFF);
1150 status
= cx231xx_reg_mask_write(dev
,
1151 VID_BLK_I2C_ADDRESS
, 32,
1152 AFE_CTRL_C2HH_SRC_CTRL
, 9, 9, 0x1);
1153 } else if (standard
!= DIF_USE_BASEBAND
) {
1154 if (standard
& V4L2_STD_MN
) {
1155 /* lo if big signal */
1156 status
= cx231xx_reg_mask_write(dev
,
1157 VID_BLK_I2C_ADDRESS
, 32,
1158 AFE_CTRL_C2HH_SRC_CTRL
, 30, 31, 0x1);
1159 /* FUNC_MODE = DIF */
1160 status
= cx231xx_reg_mask_write(dev
,
1161 VID_BLK_I2C_ADDRESS
, 32,
1162 AFE_CTRL_C2HH_SRC_CTRL
, 23, 24,
1165 status
= cx231xx_reg_mask_write(dev
,
1166 VID_BLK_I2C_ADDRESS
, 32,
1167 AFE_CTRL_C2HH_SRC_CTRL
, 15, 22, 0xb);
1169 status
= cx231xx_reg_mask_write(dev
,
1170 VID_BLK_I2C_ADDRESS
, 32,
1171 AFE_CTRL_C2HH_SRC_CTRL
, 9, 9, 0x1);
1172 /* 0x124, AUD_CHAN1_SRC = 0x3 */
1173 status
= cx231xx_reg_mask_write(dev
,
1174 VID_BLK_I2C_ADDRESS
, 32,
1175 AUD_IO_CTRL
, 0, 31, 0x00000003);
1176 } else if ((standard
== V4L2_STD_PAL_I
) |
1177 (standard
& V4L2_STD_SECAM
)) {
1179 /* lo if big signal */
1180 status
= cx231xx_reg_mask_write(dev
,
1181 VID_BLK_I2C_ADDRESS
, 32,
1182 AFE_CTRL_C2HH_SRC_CTRL
, 30, 31, 0x1);
1183 /* FUNC_MODE = DIF */
1184 status
= cx231xx_reg_mask_write(dev
,
1185 VID_BLK_I2C_ADDRESS
, 32,
1186 AFE_CTRL_C2HH_SRC_CTRL
, 23, 24,
1189 status
= cx231xx_reg_mask_write(dev
,
1190 VID_BLK_I2C_ADDRESS
, 32,
1191 AFE_CTRL_C2HH_SRC_CTRL
, 15, 22, 0xF);
1193 status
= cx231xx_reg_mask_write(dev
,
1194 VID_BLK_I2C_ADDRESS
, 32,
1195 AFE_CTRL_C2HH_SRC_CTRL
, 9, 9, 0x1);
1197 /* default PAL BG */
1199 /* lo if big signal */
1200 status
= cx231xx_reg_mask_write(dev
,
1201 VID_BLK_I2C_ADDRESS
, 32,
1202 AFE_CTRL_C2HH_SRC_CTRL
, 30, 31, 0x1);
1203 /* FUNC_MODE = DIF */
1204 status
= cx231xx_reg_mask_write(dev
,
1205 VID_BLK_I2C_ADDRESS
, 32,
1206 AFE_CTRL_C2HH_SRC_CTRL
, 23, 24,
1209 status
= cx231xx_reg_mask_write(dev
,
1210 VID_BLK_I2C_ADDRESS
, 32,
1211 AFE_CTRL_C2HH_SRC_CTRL
, 15, 22, 0xE);
1213 status
= cx231xx_reg_mask_write(dev
,
1214 VID_BLK_I2C_ADDRESS
, 32,
1215 AFE_CTRL_C2HH_SRC_CTRL
, 9, 9, 0x1);
1222 int cx231xx_dif_set_standard(struct cx231xx
*dev
, u32 standard
)
1225 u32 dif_misc_ctrl_value
= 0;
1228 cx231xx_info("%s: setStandard to %x\n", __func__
, standard
);
1230 status
= vid_blk_read_word(dev
, DIF_MISC_CTRL
, &dif_misc_ctrl_value
);
1231 if (standard
!= DIF_USE_BASEBAND
)
1232 dev
->norm
= standard
;
1234 switch (dev
->model
) {
1235 case CX231XX_BOARD_CNXT_RDE_250
:
1236 case CX231XX_BOARD_CNXT_RDU_250
:
1243 status
= cx231xx_dif_configure_C2HH_for_low_IF(dev
, dev
->active_mode
,
1244 func_mode
, standard
);
1246 if (standard
== DIF_USE_BASEBAND
) { /* base band */
1247 /* There is a different SRC_PHASE_INC value
1248 for baseband vs. DIF */
1249 status
= vid_blk_write_word(dev
, DIF_SRC_PHASE_INC
, 0xDF7DF83);
1250 status
= vid_blk_read_word(dev
, DIF_MISC_CTRL
,
1251 &dif_misc_ctrl_value
);
1252 dif_misc_ctrl_value
|= FLD_DIF_DIF_BYPASS
;
1253 status
= vid_blk_write_word(dev
, DIF_MISC_CTRL
,
1254 dif_misc_ctrl_value
);
1255 } else if (standard
& V4L2_STD_PAL_D
) {
1256 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1257 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1258 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1259 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1260 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1261 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1262 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1263 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1264 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1265 DIF_AGC_IF_REF
, 0, 31, 0x444C1380);
1266 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1267 DIF_AGC_CTRL_IF
, 0, 31, 0xDA302600);
1268 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1269 DIF_AGC_CTRL_INT
, 0, 31, 0xDA261700);
1270 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1271 DIF_AGC_CTRL_RF
, 0, 31, 0xDA262600);
1272 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1273 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1275 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1276 DIF_AGC_RF_CURRENT
, 0, 31,
1278 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1279 DIF_VIDEO_AGC_CTRL
, 0, 31,
1281 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1282 DIF_VID_AUD_OVERRIDE
, 0, 31,
1284 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1285 DIF_AV_SEP_CTRL
, 0, 31, 0x3F3934EA);
1286 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1287 DIF_COMP_FLT_CTRL
, 0, 31,
1289 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1290 DIF_SRC_PHASE_INC
, 0, 31,
1292 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1293 DIF_SRC_GAIN_CONTROL
, 0, 31,
1295 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1296 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1297 /* Save the Spec Inversion value */
1298 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1299 dif_misc_ctrl_value
|= 0x3a023F11;
1300 } else if (standard
& V4L2_STD_PAL_I
) {
1301 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1302 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1303 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1304 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1305 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1306 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1307 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1308 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1309 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1310 DIF_AGC_IF_REF
, 0, 31, 0x444C1380);
1311 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1312 DIF_AGC_CTRL_IF
, 0, 31, 0xDA302600);
1313 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1314 DIF_AGC_CTRL_INT
, 0, 31, 0xDA261700);
1315 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1316 DIF_AGC_CTRL_RF
, 0, 31, 0xDA262600);
1317 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1318 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1320 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1321 DIF_AGC_RF_CURRENT
, 0, 31,
1323 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1324 DIF_VIDEO_AGC_CTRL
, 0, 31,
1326 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1327 DIF_VID_AUD_OVERRIDE
, 0, 31,
1329 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1330 DIF_AV_SEP_CTRL
, 0, 31, 0x5F39A934);
1331 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1332 DIF_COMP_FLT_CTRL
, 0, 31,
1334 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1335 DIF_SRC_PHASE_INC
, 0, 31,
1337 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1338 DIF_SRC_GAIN_CONTROL
, 0, 31,
1340 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1341 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1342 /* Save the Spec Inversion value */
1343 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1344 dif_misc_ctrl_value
|= 0x3a033F11;
1345 } else if (standard
& V4L2_STD_PAL_M
) {
1346 /* improved Low Frequency Phase Noise */
1347 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL
, 0xFF01FF0C);
1348 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL1
, 0xbd038c85);
1349 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL2
, 0x1db4640a);
1350 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL3
, 0x00008800);
1351 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, 0x444C1380);
1352 status
= vid_blk_write_word(dev
, DIF_AGC_IF_INT_CURRENT
,
1354 status
= vid_blk_write_word(dev
, DIF_AGC_RF_CURRENT
,
1356 status
= vid_blk_write_word(dev
, DIF_VIDEO_AGC_CTRL
,
1358 status
= vid_blk_write_word(dev
, DIF_VID_AUD_OVERRIDE
,
1360 status
= vid_blk_write_word(dev
, DIF_AV_SEP_CTRL
, 0x012c405d);
1361 status
= vid_blk_write_word(dev
, DIF_COMP_FLT_CTRL
,
1363 status
= vid_blk_write_word(dev
, DIF_SRC_PHASE_INC
,
1365 status
= vid_blk_write_word(dev
, DIF_SRC_GAIN_CONTROL
,
1367 status
= vid_blk_write_word(dev
, DIF_SOFT_RST_CTRL_REVB
,
1369 /* Save the Spec Inversion value */
1370 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1371 dif_misc_ctrl_value
|= 0x3A0A3F10;
1372 } else if (standard
& (V4L2_STD_PAL_N
| V4L2_STD_PAL_Nc
)) {
1373 /* improved Low Frequency Phase Noise */
1374 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL
, 0xFF01FF0C);
1375 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL1
, 0xbd038c85);
1376 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL2
, 0x1db4640a);
1377 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL3
, 0x00008800);
1378 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, 0x444C1380);
1379 status
= vid_blk_write_word(dev
, DIF_AGC_IF_INT_CURRENT
,
1381 status
= vid_blk_write_word(dev
, DIF_AGC_RF_CURRENT
,
1383 status
= vid_blk_write_word(dev
, DIF_VIDEO_AGC_CTRL
,
1385 status
= vid_blk_write_word(dev
, DIF_VID_AUD_OVERRIDE
,
1387 status
= vid_blk_write_word(dev
, DIF_AV_SEP_CTRL
,
1389 status
= vid_blk_write_word(dev
, DIF_COMP_FLT_CTRL
,
1391 status
= vid_blk_write_word(dev
, DIF_SRC_PHASE_INC
,
1393 status
= vid_blk_write_word(dev
, DIF_SRC_GAIN_CONTROL
,
1395 status
= vid_blk_write_word(dev
, DIF_SOFT_RST_CTRL_REVB
,
1397 /* Save the Spec Inversion value */
1398 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1399 dif_misc_ctrl_value
= 0x3A093F10;
1400 } else if (standard
&
1401 (V4L2_STD_SECAM_B
| V4L2_STD_SECAM_D
| V4L2_STD_SECAM_G
|
1402 V4L2_STD_SECAM_K
| V4L2_STD_SECAM_K1
)) {
1404 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1405 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1406 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1407 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1408 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1409 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1410 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1411 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1412 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1413 DIF_AGC_IF_REF
, 0, 31, 0x888C0380);
1414 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1415 DIF_AGC_CTRL_IF
, 0, 31, 0xe0262600);
1416 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1417 DIF_AGC_CTRL_INT
, 0, 31, 0xc2171700);
1418 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1419 DIF_AGC_CTRL_RF
, 0, 31, 0xc2262600);
1420 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1421 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1423 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1424 DIF_AGC_RF_CURRENT
, 0, 31,
1426 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1427 DIF_VID_AUD_OVERRIDE
, 0, 31,
1429 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1430 DIF_AV_SEP_CTRL
, 0, 31, 0x3F3530ec);
1431 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1432 DIF_COMP_FLT_CTRL
, 0, 31,
1434 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1435 DIF_SRC_PHASE_INC
, 0, 31,
1437 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1438 DIF_SRC_GAIN_CONTROL
, 0, 31,
1440 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1441 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1442 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1443 DIF_VIDEO_AGC_CTRL
, 0, 31,
1446 /* Save the Spec Inversion value */
1447 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1448 dif_misc_ctrl_value
|= 0x3a023F11;
1449 } else if (standard
& (V4L2_STD_SECAM_L
| V4L2_STD_SECAM_LC
)) {
1450 /* Is it SECAM_L1? */
1451 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1452 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1453 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1454 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1455 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1456 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1457 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1458 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1459 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1460 DIF_AGC_IF_REF
, 0, 31, 0x888C0380);
1461 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1462 DIF_AGC_CTRL_IF
, 0, 31, 0xe0262600);
1463 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1464 DIF_AGC_CTRL_INT
, 0, 31, 0xc2171700);
1465 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1466 DIF_AGC_CTRL_RF
, 0, 31, 0xc2262600);
1467 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1468 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1470 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1471 DIF_AGC_RF_CURRENT
, 0, 31,
1473 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1474 DIF_VID_AUD_OVERRIDE
, 0, 31,
1476 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1477 DIF_AV_SEP_CTRL
, 0, 31, 0x3F3530ec);
1478 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1479 DIF_COMP_FLT_CTRL
, 0, 31,
1481 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1482 DIF_SRC_PHASE_INC
, 0, 31,
1484 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1485 DIF_SRC_GAIN_CONTROL
, 0, 31,
1487 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1488 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1489 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1490 DIF_VIDEO_AGC_CTRL
, 0, 31,
1493 /* Save the Spec Inversion value */
1494 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1495 dif_misc_ctrl_value
|= 0x3a023F11;
1497 } else if (standard
& V4L2_STD_NTSC_M
) {
1498 /* V4L2_STD_NTSC_M (75 IRE Setup) Or
1499 V4L2_STD_NTSC_M_JP (Japan, 0 IRE Setup) */
1501 /* For NTSC the centre frequency of video coming out of
1502 sidewinder is around 7.1MHz or 3.6MHz depending on the
1503 spectral inversion. so for a non spectrally inverted channel
1504 the pll freq word is 0x03420c49
1507 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL
, 0x6503BC0C);
1508 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL1
, 0xBD038C85);
1509 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL2
, 0x1DB4640A);
1510 status
= vid_blk_write_word(dev
, DIF_PLL_CTRL3
, 0x00008800);
1511 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, 0x444C0380);
1512 status
= vid_blk_write_word(dev
, DIF_AGC_IF_INT_CURRENT
,
1514 status
= vid_blk_write_word(dev
, DIF_AGC_RF_CURRENT
,
1516 status
= vid_blk_write_word(dev
, DIF_VIDEO_AGC_CTRL
,
1518 status
= vid_blk_write_word(dev
, DIF_VID_AUD_OVERRIDE
,
1520 status
= vid_blk_write_word(dev
, DIF_AV_SEP_CTRL
, 0x01296e1f);
1522 status
= vid_blk_write_word(dev
, DIF_COMP_FLT_CTRL
,
1524 status
= vid_blk_write_word(dev
, DIF_SRC_PHASE_INC
,
1526 status
= vid_blk_write_word(dev
, DIF_SRC_GAIN_CONTROL
,
1529 status
= vid_blk_write_word(dev
, DIF_AGC_CTRL_IF
, 0xC2262600);
1530 status
= vid_blk_write_word(dev
, DIF_AGC_CTRL_INT
,
1532 status
= vid_blk_write_word(dev
, DIF_AGC_CTRL_RF
, 0xC2262600);
1534 /* Save the Spec Inversion value */
1535 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1536 dif_misc_ctrl_value
|= 0x3a003F10;
1538 /* default PAL BG */
1539 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1540 DIF_PLL_CTRL
, 0, 31, 0x6503bc0c);
1541 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1542 DIF_PLL_CTRL1
, 0, 31, 0xbd038c85);
1543 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1544 DIF_PLL_CTRL2
, 0, 31, 0x1db4640a);
1545 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1546 DIF_PLL_CTRL3
, 0, 31, 0x00008800);
1547 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1548 DIF_AGC_IF_REF
, 0, 31, 0x444C1380);
1549 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1550 DIF_AGC_CTRL_IF
, 0, 31, 0xDA302600);
1551 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1552 DIF_AGC_CTRL_INT
, 0, 31, 0xDA261700);
1553 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1554 DIF_AGC_CTRL_RF
, 0, 31, 0xDA262600);
1555 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1556 DIF_AGC_IF_INT_CURRENT
, 0, 31,
1558 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1559 DIF_AGC_RF_CURRENT
, 0, 31,
1561 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1562 DIF_VIDEO_AGC_CTRL
, 0, 31,
1564 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1565 DIF_VID_AUD_OVERRIDE
, 0, 31,
1567 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1568 DIF_AV_SEP_CTRL
, 0, 31, 0x3F3530EC);
1569 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1570 DIF_COMP_FLT_CTRL
, 0, 31,
1572 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1573 DIF_SRC_PHASE_INC
, 0, 31,
1575 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1576 DIF_SRC_GAIN_CONTROL
, 0, 31,
1578 status
= cx231xx_reg_mask_write(dev
, VID_BLK_I2C_ADDRESS
, 32,
1579 DIF_RPT_VARIANCE
, 0, 31, 0x00000000);
1580 /* Save the Spec Inversion value */
1581 dif_misc_ctrl_value
&= FLD_DIF_SPEC_INV
;
1582 dif_misc_ctrl_value
|= 0x3a013F11;
1585 /* The AGC values should be the same for all standards,
1586 AUD_SRC_SEL[19] should always be disabled */
1587 dif_misc_ctrl_value
&= ~FLD_DIF_AUD_SRC_SEL
;
1589 /* It is still possible to get Set Standard calls even when we
1591 This is done to override the value for FM. */
1592 if (dev
->active_mode
== V4L2_TUNER_RADIO
)
1593 dif_misc_ctrl_value
= 0x7a080000;
1595 /* Write the calculated value for misc ontrol register */
1596 status
= vid_blk_write_word(dev
, DIF_MISC_CTRL
, dif_misc_ctrl_value
);
1601 int cx231xx_tuner_pre_channel_change(struct cx231xx
*dev
)
1606 /* Set the RF and IF k_agc values to 3 */
1607 status
= vid_blk_read_word(dev
, DIF_AGC_IF_REF
, &dwval
);
1608 dwval
&= ~(FLD_DIF_K_AGC_RF
| FLD_DIF_K_AGC_IF
);
1609 dwval
|= 0x33000000;
1611 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, dwval
);
1616 int cx231xx_tuner_post_channel_change(struct cx231xx
*dev
)
1621 /* Set the RF and IF k_agc values to 4 for PAL/NTSC and 8 for
1622 * SECAM L/B/D standards */
1623 status
= vid_blk_read_word(dev
, DIF_AGC_IF_REF
, &dwval
);
1624 dwval
&= ~(FLD_DIF_K_AGC_RF
| FLD_DIF_K_AGC_IF
);
1626 if (dev
->norm
& (V4L2_STD_SECAM_L
| V4L2_STD_SECAM_B
|
1628 dwval
|= 0x88000000;
1630 dwval
|= 0x44000000;
1632 status
= vid_blk_write_word(dev
, DIF_AGC_IF_REF
, dwval
);
1637 /******************************************************************************
1638 * I 2 S - B L O C K C O N T R O L functions *
1639 ******************************************************************************/
1640 int cx231xx_i2s_blk_initialize(struct cx231xx
*dev
)
1645 status
= cx231xx_read_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1646 CH_PWR_CTRL1
, 1, &value
, 1);
1647 /* enables clock to delta-sigma and decimation filter */
1649 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1650 CH_PWR_CTRL1
, 1, value
, 1);
1651 /* power up all channel */
1652 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1653 CH_PWR_CTRL2
, 1, 0x00, 1);
1658 int cx231xx_i2s_blk_update_power_control(struct cx231xx
*dev
,
1659 enum AV_MODE avmode
)
1664 if (avmode
!= POLARIS_AVMODE_ENXTERNAL_AV
) {
1665 status
= cx231xx_read_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1666 CH_PWR_CTRL2
, 1, &value
, 1);
1668 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1669 CH_PWR_CTRL2
, 1, value
, 1);
1671 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1672 CH_PWR_CTRL2
, 1, 0x00, 1);
1678 /* set i2s_blk for audio input types */
1679 int cx231xx_i2s_blk_set_audio_input(struct cx231xx
*dev
, u8 audio_input
)
1683 switch (audio_input
) {
1684 case CX231XX_AMUX_LINE_IN
:
1685 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1686 CH_PWR_CTRL2
, 1, 0x00, 1);
1687 status
= cx231xx_write_i2c_data(dev
, I2S_BLK_DEVICE_ADDRESS
,
1688 CH_PWR_CTRL1
, 1, 0x80, 1);
1690 case CX231XX_AMUX_VIDEO
:
1695 dev
->ctl_ainput
= audio_input
;
1700 /******************************************************************************
1701 * P O W E R C O N T R O L functions *
1702 ******************************************************************************/
1703 int cx231xx_set_power_mode(struct cx231xx
*dev
, enum AV_MODE mode
)
1705 u8 value
[4] = { 0, 0, 0, 0 };
1709 if (dev
->power_mode
!= mode
)
1710 dev
->power_mode
= mode
;
1712 cx231xx_info(" setPowerMode::mode = %d, No Change req.\n",
1717 cx231xx_info(" setPowerMode::mode = %d\n", mode
);
1719 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
, value
,
1724 tmp
= *((u32
*) value
);
1727 case POLARIS_AVMODE_ENXTERNAL_AV
:
1729 tmp
&= (~PWR_MODE_MASK
);
1732 value
[0] = (u8
) tmp
;
1733 value
[1] = (u8
) (tmp
>> 8);
1734 value
[2] = (u8
) (tmp
>> 16);
1735 value
[3] = (u8
) (tmp
>> 24);
1736 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1737 PWR_CTL_EN
, value
, 4);
1738 msleep(PWR_SLEEP_INTERVAL
);
1741 value
[0] = (u8
) tmp
;
1742 value
[1] = (u8
) (tmp
>> 8);
1743 value
[2] = (u8
) (tmp
>> 16);
1744 value
[3] = (u8
) (tmp
>> 24);
1746 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, PWR_CTL_EN
,
1748 msleep(PWR_SLEEP_INTERVAL
);
1750 tmp
|= POLARIS_AVMODE_ENXTERNAL_AV
;
1751 value
[0] = (u8
) tmp
;
1752 value
[1] = (u8
) (tmp
>> 8);
1753 value
[2] = (u8
) (tmp
>> 16);
1754 value
[3] = (u8
) (tmp
>> 24);
1755 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1756 PWR_CTL_EN
, value
, 4);
1758 /* reset state of xceive tuner */
1759 dev
->xc_fw_load_done
= 0;
1762 case POLARIS_AVMODE_ANALOGT_TV
:
1764 tmp
&= (~PWR_DEMOD_EN
);
1765 tmp
|= (I2C_DEMOD_EN
);
1766 value
[0] = (u8
) tmp
;
1767 value
[1] = (u8
) (tmp
>> 8);
1768 value
[2] = (u8
) (tmp
>> 16);
1769 value
[3] = (u8
) (tmp
>> 24);
1770 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1771 PWR_CTL_EN
, value
, 4);
1772 msleep(PWR_SLEEP_INTERVAL
);
1774 if (!(tmp
& PWR_TUNER_EN
)) {
1775 tmp
|= (PWR_TUNER_EN
);
1776 value
[0] = (u8
) tmp
;
1777 value
[1] = (u8
) (tmp
>> 8);
1778 value
[2] = (u8
) (tmp
>> 16);
1779 value
[3] = (u8
) (tmp
>> 24);
1780 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1781 PWR_CTL_EN
, value
, 4);
1782 msleep(PWR_SLEEP_INTERVAL
);
1785 if (!(tmp
& PWR_AV_EN
)) {
1787 value
[0] = (u8
) tmp
;
1788 value
[1] = (u8
) (tmp
>> 8);
1789 value
[2] = (u8
) (tmp
>> 16);
1790 value
[3] = (u8
) (tmp
>> 24);
1791 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1792 PWR_CTL_EN
, value
, 4);
1793 msleep(PWR_SLEEP_INTERVAL
);
1795 if (!(tmp
& PWR_ISO_EN
)) {
1797 value
[0] = (u8
) tmp
;
1798 value
[1] = (u8
) (tmp
>> 8);
1799 value
[2] = (u8
) (tmp
>> 16);
1800 value
[3] = (u8
) (tmp
>> 24);
1801 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1802 PWR_CTL_EN
, value
, 4);
1803 msleep(PWR_SLEEP_INTERVAL
);
1806 if (!(tmp
& POLARIS_AVMODE_ANALOGT_TV
)) {
1807 tmp
|= POLARIS_AVMODE_ANALOGT_TV
;
1808 value
[0] = (u8
) tmp
;
1809 value
[1] = (u8
) (tmp
>> 8);
1810 value
[2] = (u8
) (tmp
>> 16);
1811 value
[3] = (u8
) (tmp
>> 24);
1812 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1813 PWR_CTL_EN
, value
, 4);
1814 msleep(PWR_SLEEP_INTERVAL
);
1817 if ((dev
->model
== CX231XX_BOARD_CNXT_RDE_250
) ||
1818 (dev
->model
== CX231XX_BOARD_CNXT_RDU_250
)) {
1819 /* tuner path to channel 1 from port 3 */
1820 cx231xx_enable_i2c_for_tuner(dev
, I2C_3
);
1822 if (dev
->cx231xx_reset_analog_tuner
)
1823 dev
->cx231xx_reset_analog_tuner(dev
);
1827 case POLARIS_AVMODE_DIGITAL
:
1828 if (!(tmp
& PWR_TUNER_EN
)) {
1829 tmp
|= (PWR_TUNER_EN
);
1830 value
[0] = (u8
) tmp
;
1831 value
[1] = (u8
) (tmp
>> 8);
1832 value
[2] = (u8
) (tmp
>> 16);
1833 value
[3] = (u8
) (tmp
>> 24);
1834 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1835 PWR_CTL_EN
, value
, 4);
1836 msleep(PWR_SLEEP_INTERVAL
);
1838 if (!(tmp
& PWR_AV_EN
)) {
1840 value
[0] = (u8
) tmp
;
1841 value
[1] = (u8
) (tmp
>> 8);
1842 value
[2] = (u8
) (tmp
>> 16);
1843 value
[3] = (u8
) (tmp
>> 24);
1844 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1845 PWR_CTL_EN
, value
, 4);
1846 msleep(PWR_SLEEP_INTERVAL
);
1848 if (!(tmp
& PWR_ISO_EN
)) {
1850 value
[0] = (u8
) tmp
;
1851 value
[1] = (u8
) (tmp
>> 8);
1852 value
[2] = (u8
) (tmp
>> 16);
1853 value
[3] = (u8
) (tmp
>> 24);
1854 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1855 PWR_CTL_EN
, value
, 4);
1856 msleep(PWR_SLEEP_INTERVAL
);
1859 tmp
|= POLARIS_AVMODE_DIGITAL
| I2C_DEMOD_EN
;
1860 value
[0] = (u8
) tmp
;
1861 value
[1] = (u8
) (tmp
>> 8);
1862 value
[2] = (u8
) (tmp
>> 16);
1863 value
[3] = (u8
) (tmp
>> 24);
1864 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1865 PWR_CTL_EN
, value
, 4);
1866 msleep(PWR_SLEEP_INTERVAL
);
1868 if (!(tmp
& PWR_DEMOD_EN
)) {
1869 tmp
|= PWR_DEMOD_EN
;
1870 value
[0] = (u8
) tmp
;
1871 value
[1] = (u8
) (tmp
>> 8);
1872 value
[2] = (u8
) (tmp
>> 16);
1873 value
[3] = (u8
) (tmp
>> 24);
1874 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1875 PWR_CTL_EN
, value
, 4);
1876 msleep(PWR_SLEEP_INTERVAL
);
1879 if ((dev
->model
== CX231XX_BOARD_CNXT_RDE_250
) ||
1880 (dev
->model
== CX231XX_BOARD_CNXT_RDU_250
)) {
1881 /* tuner path to channel 1 from port 3 */
1882 cx231xx_enable_i2c_for_tuner(dev
, I2C_3
);
1884 if (dev
->cx231xx_reset_analog_tuner
)
1885 dev
->cx231xx_reset_analog_tuner(dev
);
1893 msleep(PWR_SLEEP_INTERVAL
);
1895 /* For power saving, only enable Pwr_resetout_n
1896 when digital TV is selected. */
1897 if (mode
== POLARIS_AVMODE_DIGITAL
) {
1898 tmp
|= PWR_RESETOUT_EN
;
1899 value
[0] = (u8
) tmp
;
1900 value
[1] = (u8
) (tmp
>> 8);
1901 value
[2] = (u8
) (tmp
>> 16);
1902 value
[3] = (u8
) (tmp
>> 24);
1903 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1904 PWR_CTL_EN
, value
, 4);
1905 msleep(PWR_SLEEP_INTERVAL
);
1908 /* update power control for afe */
1909 status
= cx231xx_afe_update_power_control(dev
, mode
);
1911 /* update power control for i2s_blk */
1912 status
= cx231xx_i2s_blk_update_power_control(dev
, mode
);
1914 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
, value
,
1916 cx231xx_info(" The data of PWR_CTL_EN register 0x74"
1917 "=0x%0x,0x%0x,0x%0x,0x%0x\n",
1918 value
[0], value
[1], value
[2], value
[3]);
1923 int cx231xx_power_suspend(struct cx231xx
*dev
)
1925 u8 value
[4] = { 0, 0, 0, 0 };
1929 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
,
1934 tmp
= *((u32
*) value
);
1935 tmp
&= (~PWR_MODE_MASK
);
1937 value
[0] = (u8
) tmp
;
1938 value
[1] = (u8
) (tmp
>> 8);
1939 value
[2] = (u8
) (tmp
>> 16);
1940 value
[3] = (u8
) (tmp
>> 24);
1941 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, PWR_CTL_EN
,
1947 /******************************************************************************
1948 * S T R E A M C O N T R O L functions *
1949 ******************************************************************************/
1950 int cx231xx_start_stream(struct cx231xx
*dev
, u32 ep_mask
)
1952 u8 value
[4] = { 0x0, 0x0, 0x0, 0x0 };
1956 cx231xx_info("cx231xx_start_stream():: ep_mask = %x\n", ep_mask
);
1957 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, EP_MODE_SET
,
1962 tmp
= *((u32
*) value
);
1964 value
[0] = (u8
) tmp
;
1965 value
[1] = (u8
) (tmp
>> 8);
1966 value
[2] = (u8
) (tmp
>> 16);
1967 value
[3] = (u8
) (tmp
>> 24);
1969 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, EP_MODE_SET
,
1975 int cx231xx_stop_stream(struct cx231xx
*dev
, u32 ep_mask
)
1977 u8 value
[4] = { 0x0, 0x0, 0x0, 0x0 };
1981 cx231xx_info("cx231xx_stop_stream():: ep_mask = %x\n", ep_mask
);
1983 cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, EP_MODE_SET
, value
, 4);
1987 tmp
= *((u32
*) value
);
1989 value
[0] = (u8
) tmp
;
1990 value
[1] = (u8
) (tmp
>> 8);
1991 value
[2] = (u8
) (tmp
>> 16);
1992 value
[3] = (u8
) (tmp
>> 24);
1994 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, EP_MODE_SET
,
2000 int cx231xx_initialize_stream_xfer(struct cx231xx
*dev
, u32 media_type
)
2004 if (dev
->udev
->speed
== USB_SPEED_HIGH
) {
2005 switch (media_type
) {
2006 case 81: /* audio */
2007 cx231xx_info("%s: Audio enter HANC\n", __func__
);
2009 cx231xx_mode_register(dev
, TS_MODE_REG
, 0x9300);
2013 cx231xx_info("%s: set vanc registers\n", __func__
);
2014 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x300);
2017 case 3: /* sliced cc */
2018 cx231xx_info("%s: set hanc registers\n", __func__
);
2020 cx231xx_mode_register(dev
, TS_MODE_REG
, 0x1300);
2024 cx231xx_info("%s: set video registers\n", __func__
);
2025 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x100);
2029 cx231xx_info("%s: set ts1 registers\n", __func__
);
2030 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x101);
2031 status
= cx231xx_mode_register(dev
, TS1_CFG_REG
, 0x400);
2033 case 6: /* ts1 parallel mode */
2034 cx231xx_info("%s: set ts1 parrallel mode registers\n",
2036 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x100);
2037 status
= cx231xx_mode_register(dev
, TS1_CFG_REG
, 0x400);
2041 status
= cx231xx_mode_register(dev
, TS_MODE_REG
, 0x101);
2047 int cx231xx_capture_start(struct cx231xx
*dev
, int start
, u8 media_type
)
2051 struct pcb_config
*pcb_config
;
2053 /* get EP for media type */
2054 pcb_config
= (struct pcb_config
*)&dev
->current_pcb_config
;
2056 if (pcb_config
->config_num
== 1) {
2057 switch (media_type
) {
2059 ep_mask
= ENABLE_EP4
; /* ep4 [00:1000] */
2062 ep_mask
= ENABLE_EP3
; /* ep3 [00:0100] */
2065 ep_mask
= ENABLE_EP5
; /* ep5 [01:0000] */
2067 case 3: /* Sliced_cc */
2068 ep_mask
= ENABLE_EP6
; /* ep6 [10:0000] */
2071 case 6: /* ts1 parallel mode */
2072 ep_mask
= ENABLE_EP1
; /* ep1 [00:0001] */
2075 ep_mask
= ENABLE_EP2
; /* ep2 [00:0010] */
2079 } else if (pcb_config
->config_num
> 1) {
2080 switch (media_type
) {
2082 ep_mask
= ENABLE_EP4
; /* ep4 [00:1000] */
2085 ep_mask
= ENABLE_EP3
; /* ep3 [00:0100] */
2088 ep_mask
= ENABLE_EP5
; /* ep5 [01:0000] */
2090 case 3: /* Sliced_cc */
2091 ep_mask
= ENABLE_EP6
; /* ep6 [10:0000] */
2094 case 6: /* ts1 parallel mode */
2095 ep_mask
= ENABLE_EP1
; /* ep1 [00:0001] */
2098 ep_mask
= ENABLE_EP2
; /* ep2 [00:0010] */
2105 rc
= cx231xx_initialize_stream_xfer(dev
, media_type
);
2110 /* enable video capture */
2112 rc
= cx231xx_start_stream(dev
, ep_mask
);
2114 /* disable video capture */
2116 rc
= cx231xx_stop_stream(dev
, ep_mask
);
2119 if (dev
->mode
== CX231XX_ANALOG_MODE
)
2120 ;/* do any in Analog mode */
2122 ;/* do any in digital mode */
2126 EXPORT_SYMBOL_GPL(cx231xx_capture_start
);
2128 /*****************************************************************************
2129 * G P I O B I T control functions *
2130 ******************************************************************************/
2131 int cx231xx_set_gpio_bit(struct cx231xx
*dev
, u32 gpio_bit
, u8
* gpio_val
)
2135 status
= cx231xx_send_gpio_cmd(dev
, gpio_bit
, gpio_val
, 4, 0, 0);
2140 int cx231xx_get_gpio_bit(struct cx231xx
*dev
, u32 gpio_bit
, u8
* gpio_val
)
2144 status
= cx231xx_send_gpio_cmd(dev
, gpio_bit
, gpio_val
, 4, 0, 1);
2150 * cx231xx_set_gpio_direction
2151 * Sets the direction of the GPIO pin to input or output
2154 * pin_number : The GPIO Pin number to program the direction for
2156 * pin_value : The Direction of the GPIO Pin under reference.
2157 * 0 = Input direction
2158 * 1 = Output direction
2160 int cx231xx_set_gpio_direction(struct cx231xx
*dev
,
2161 int pin_number
, int pin_value
)
2166 /* Check for valid pin_number - if 32 , bail out */
2167 if (pin_number
>= 32)
2172 value
= dev
->gpio_dir
& (~(1 << pin_number
)); /* clear */
2174 value
= dev
->gpio_dir
| (1 << pin_number
);
2176 status
= cx231xx_set_gpio_bit(dev
, value
, (u8
*) &dev
->gpio_val
);
2178 /* cache the value for future */
2179 dev
->gpio_dir
= value
;
2185 * cx231xx_set_gpio_value
2186 * Sets the value of the GPIO pin to Logic high or low. The Pin under
2187 * reference should ALREADY BE SET IN OUTPUT MODE !!!!!!!!!
2190 * pin_number : The GPIO Pin number to program the direction for
2191 * pin_value : The value of the GPIO Pin under reference.
2195 int cx231xx_set_gpio_value(struct cx231xx
*dev
, int pin_number
, int pin_value
)
2200 /* Check for valid pin_number - if 0xFF , bail out */
2201 if (pin_number
>= 32)
2204 /* first do a sanity check - if the Pin is not output, make it output */
2205 if ((dev
->gpio_dir
& (1 << pin_number
)) == 0x00) {
2206 /* It was in input mode */
2207 value
= dev
->gpio_dir
| (1 << pin_number
);
2208 dev
->gpio_dir
= value
;
2209 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2210 (u8
*) &dev
->gpio_val
);
2215 value
= dev
->gpio_val
& (~(1 << pin_number
));
2217 value
= dev
->gpio_val
| (1 << pin_number
);
2219 /* store the value */
2220 dev
->gpio_val
= value
;
2222 /* toggle bit0 of GP_IO */
2223 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2228 /*****************************************************************************
2229 * G P I O I2C related functions *
2230 ******************************************************************************/
2231 int cx231xx_gpio_i2c_start(struct cx231xx
*dev
)
2235 /* set SCL to output 1 ; set SDA to output 1 */
2236 dev
->gpio_dir
|= 1 << dev
->board
.tuner_scl_gpio
;
2237 dev
->gpio_dir
|= 1 << dev
->board
.tuner_sda_gpio
;
2238 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2239 dev
->gpio_val
|= 1 << dev
->board
.tuner_sda_gpio
;
2241 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2245 /* set SCL to output 1; set SDA to output 0 */
2246 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2247 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2249 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2253 /* set SCL to output 0; set SDA to output 0 */
2254 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2255 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2257 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2264 int cx231xx_gpio_i2c_end(struct cx231xx
*dev
)
2268 /* set SCL to output 0; set SDA to output 0 */
2269 dev
->gpio_dir
|= 1 << dev
->board
.tuner_scl_gpio
;
2270 dev
->gpio_dir
|= 1 << dev
->board
.tuner_sda_gpio
;
2272 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2273 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2275 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2279 /* set SCL to output 1; set SDA to output 0 */
2280 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2281 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2283 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2287 /* set SCL to input ,release SCL cable control
2288 set SDA to input ,release SDA cable control */
2289 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2290 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2293 cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2300 int cx231xx_gpio_i2c_write_byte(struct cx231xx
*dev
, u8 data
)
2305 /* set SCL to output ; set SDA to output */
2306 dev
->gpio_dir
|= 1 << dev
->board
.tuner_scl_gpio
;
2307 dev
->gpio_dir
|= 1 << dev
->board
.tuner_sda_gpio
;
2309 for (i
= 0; i
< 8; i
++) {
2310 if (((data
<< i
) & 0x80) == 0) {
2311 /* set SCL to output 0; set SDA to output 0 */
2312 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2313 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2314 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2315 (u8
*)&dev
->gpio_val
);
2317 /* set SCL to output 1; set SDA to output 0 */
2318 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2319 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2320 (u8
*)&dev
->gpio_val
);
2322 /* set SCL to output 0; set SDA to output 0 */
2323 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2324 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2325 (u8
*)&dev
->gpio_val
);
2327 /* set SCL to output 0; set SDA to output 1 */
2328 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2329 dev
->gpio_val
|= 1 << dev
->board
.tuner_sda_gpio
;
2330 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2331 (u8
*)&dev
->gpio_val
);
2333 /* set SCL to output 1; set SDA to output 1 */
2334 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2335 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2336 (u8
*)&dev
->gpio_val
);
2338 /* set SCL to output 0; set SDA to output 1 */
2339 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2340 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2341 (u8
*)&dev
->gpio_val
);
2347 int cx231xx_gpio_i2c_read_byte(struct cx231xx
*dev
, u8
* buf
)
2351 u32 gpio_logic_value
= 0;
2355 for (i
= 0; i
< 8; i
++) { /* send write I2c addr */
2357 /* set SCL to output 0; set SDA to input */
2358 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2359 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2360 (u8
*)&dev
->gpio_val
);
2362 /* set SCL to output 1; set SDA to input */
2363 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2364 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
,
2365 (u8
*)&dev
->gpio_val
);
2367 /* get SDA data bit */
2368 gpio_logic_value
= dev
->gpio_val
;
2369 status
= cx231xx_get_gpio_bit(dev
, dev
->gpio_dir
,
2370 (u8
*)&dev
->gpio_val
);
2371 if ((dev
->gpio_val
& (1 << dev
->board
.tuner_sda_gpio
)) != 0)
2372 value
|= (1 << (8 - i
- 1));
2374 dev
->gpio_val
= gpio_logic_value
;
2377 /* set SCL to output 0,finish the read latest SCL signal.
2378 !!!set SDA to input, never to modify SDA direction at
2380 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2381 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2383 /* store the value */
2384 *buf
= value
& 0xff;
2389 int cx231xx_gpio_i2c_read_ack(struct cx231xx
*dev
)
2392 u32 gpio_logic_value
= 0;
2396 /* clock stretch; set SCL to input; set SDA to input;
2397 get SCL value till SCL = 1 */
2398 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2399 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2401 gpio_logic_value
= dev
->gpio_val
;
2402 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2406 status
= cx231xx_get_gpio_bit(dev
, dev
->gpio_dir
,
2407 (u8
*)&dev
->gpio_val
);
2409 } while (((dev
->gpio_val
&
2410 (1 << dev
->board
.tuner_scl_gpio
)) == 0) &&
2414 cx231xx_info("No ACK after %d msec -GPIO I2C failed!",
2418 throuth clock stretch ,slave has given a SCL signal,
2419 so the SDA data can be directly read. */
2420 status
= cx231xx_get_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2422 if ((dev
->gpio_val
& 1 << dev
->board
.tuner_sda_gpio
) == 0) {
2423 dev
->gpio_val
= gpio_logic_value
;
2424 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2427 dev
->gpio_val
= gpio_logic_value
;
2428 dev
->gpio_val
|= (1 << dev
->board
.tuner_sda_gpio
);
2431 /* read SDA end, set the SCL to output 0, after this operation,
2432 SDA direction can be changed. */
2433 dev
->gpio_val
= gpio_logic_value
;
2434 dev
->gpio_dir
|= (1 << dev
->board
.tuner_scl_gpio
);
2435 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2436 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2441 int cx231xx_gpio_i2c_write_ack(struct cx231xx
*dev
)
2445 /* set SDA to ouput */
2446 dev
->gpio_dir
|= 1 << dev
->board
.tuner_sda_gpio
;
2447 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2449 /* set SCL = 0 (output); set SDA = 0 (output) */
2450 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2451 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2452 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2454 /* set SCL = 1 (output); set SDA = 0 (output) */
2455 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2456 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2458 /* set SCL = 0 (output); set SDA = 0 (output) */
2459 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2460 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2462 /* set SDA to input,and then the slave will read data from SDA. */
2463 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2464 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2469 int cx231xx_gpio_i2c_write_nak(struct cx231xx
*dev
)
2473 /* set scl to output ; set sda to input */
2474 dev
->gpio_dir
|= 1 << dev
->board
.tuner_scl_gpio
;
2475 dev
->gpio_dir
&= ~(1 << dev
->board
.tuner_sda_gpio
);
2476 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2478 /* set scl to output 0; set sda to input */
2479 dev
->gpio_val
&= ~(1 << dev
->board
.tuner_scl_gpio
);
2480 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2482 /* set scl to output 1; set sda to input */
2483 dev
->gpio_val
|= 1 << dev
->board
.tuner_scl_gpio
;
2484 status
= cx231xx_set_gpio_bit(dev
, dev
->gpio_dir
, (u8
*)&dev
->gpio_val
);
2489 /*****************************************************************************
2490 * G P I O I2C related functions *
2491 ******************************************************************************/
2492 /* cx231xx_gpio_i2c_read
2493 * Function to read data from gpio based I2C interface
2495 int cx231xx_gpio_i2c_read(struct cx231xx
*dev
, u8 dev_addr
, u8
* buf
, u8 len
)
2501 mutex_lock(&dev
->gpio_i2c_lock
);
2504 status
= cx231xx_gpio_i2c_start(dev
);
2506 /* write dev_addr */
2507 status
= cx231xx_gpio_i2c_write_byte(dev
, (dev_addr
<< 1) + 1);
2510 status
= cx231xx_gpio_i2c_read_ack(dev
);
2513 for (i
= 0; i
< len
; i
++) {
2516 status
= cx231xx_gpio_i2c_read_byte(dev
, &buf
[i
]);
2518 if ((i
+ 1) != len
) {
2519 /* only do write ack if we more length */
2520 status
= cx231xx_gpio_i2c_write_ack(dev
);
2524 /* write NAK - inform reads are complete */
2525 status
= cx231xx_gpio_i2c_write_nak(dev
);
2528 status
= cx231xx_gpio_i2c_end(dev
);
2530 /* release the lock */
2531 mutex_unlock(&dev
->gpio_i2c_lock
);
2536 /* cx231xx_gpio_i2c_write
2537 * Function to write data to gpio based I2C interface
2539 int cx231xx_gpio_i2c_write(struct cx231xx
*dev
, u8 dev_addr
, u8
* buf
, u8 len
)
2545 mutex_lock(&dev
->gpio_i2c_lock
);
2548 status
= cx231xx_gpio_i2c_start(dev
);
2550 /* write dev_addr */
2551 status
= cx231xx_gpio_i2c_write_byte(dev
, dev_addr
<< 1);
2554 status
= cx231xx_gpio_i2c_read_ack(dev
);
2556 for (i
= 0; i
< len
; i
++) {
2558 status
= cx231xx_gpio_i2c_write_byte(dev
, buf
[i
]);
2561 status
= cx231xx_gpio_i2c_read_ack(dev
);
2565 status
= cx231xx_gpio_i2c_end(dev
);
2567 /* release the lock */
2568 mutex_unlock(&dev
->gpio_i2c_lock
);