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>
32 #include <linux/version.h>
34 #include <linux/mutex.h>
36 #include <media/v4l2-common.h>
37 #include <media/v4l2-ioctl.h>
38 #include <media/v4l2-chip-ident.h>
42 /******************************************************************************
43 -: BLOCK ARRANGEMENT :-
44 I2S block ----------------------|
47 Analog Front End --> Direct IF -|-> Cx25840 --> Audio
48 [video & audio] | [Audio]
53 *******************************************************************************/
55 /******************************************************************************
56 * A F E - B L O C K C O N T R O L functions *
57 * [ANALOG FRONT END] *
58 ******************************************************************************/
59 static int afe_write_byte(struct cx231xx *dev, u16 saddr, u8 data)
61 return cx231xx_write_i2c_data(dev, AFE_DEVICE_ADDRESS,
65 static int afe_read_byte(struct cx231xx *dev, u16 saddr, u8 *data)
70 status = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
76 int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count)
80 u8 afe_power_status = 0;
83 /* super block initialize */
84 temp = (u8) (ref_count & 0xff);
85 status = afe_write_byte(dev, SUP_BLK_TUNE2, temp);
89 status = afe_read_byte(dev, SUP_BLK_TUNE2, &afe_power_status);
93 temp = (u8) ((ref_count & 0x300) >> 8);
95 status = afe_write_byte(dev, SUP_BLK_TUNE1, temp);
99 status = afe_write_byte(dev, SUP_BLK_PLL2, 0x0f);
104 while (afe_power_status != 0x18) {
105 status = afe_write_byte(dev, SUP_BLK_PWRDN, 0x18);
108 ": Init Super Block failed in send cmd\n");
112 status = afe_read_byte(dev, SUP_BLK_PWRDN, &afe_power_status);
113 afe_power_status &= 0xff;
116 ": Init Super Block failed in receive cmd\n");
122 ": Init Super Block force break in loop !!!!\n");
131 /* start tuning filter */
132 status = afe_write_byte(dev, SUP_BLK_TUNE3, 0x40);
139 status = afe_write_byte(dev, SUP_BLK_TUNE3, 0x00);
144 int cx231xx_afe_init_channels(struct cx231xx *dev)
148 /* power up all 3 channels, clear pd_buffer */
149 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, 0x00);
150 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, 0x00);
151 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, 0x00);
153 /* Enable quantizer calibration */
154 status = afe_write_byte(dev, ADC_COM_QUANT, 0x02);
156 /* channel initialize, force modulator (fb) reset */
157 status = afe_write_byte(dev, ADC_FB_FRCRST_CH1, 0x17);
158 status = afe_write_byte(dev, ADC_FB_FRCRST_CH2, 0x17);
159 status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, 0x17);
161 /* start quantilizer calibration */
162 status = afe_write_byte(dev, ADC_CAL_ATEST_CH1, 0x10);
163 status = afe_write_byte(dev, ADC_CAL_ATEST_CH2, 0x10);
164 status = afe_write_byte(dev, ADC_CAL_ATEST_CH3, 0x10);
167 /* exit modulator (fb) reset */
168 status = afe_write_byte(dev, ADC_FB_FRCRST_CH1, 0x07);
169 status = afe_write_byte(dev, ADC_FB_FRCRST_CH2, 0x07);
170 status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, 0x07);
172 /* enable the pre_clamp in each channel for single-ended input */
173 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH1, 0xf0);
174 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH2, 0xf0);
175 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH3, 0xf0);
177 /* use diode instead of resistor, so set term_en to 0, res_en to 0 */
178 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
179 ADC_QGAIN_RES_TRM_CH1, 3, 7, 0x00);
180 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
181 ADC_QGAIN_RES_TRM_CH2, 3, 7, 0x00);
182 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
183 ADC_QGAIN_RES_TRM_CH3, 3, 7, 0x00);
185 /* dynamic element matching off */
186 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH1, 0x03);
187 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH2, 0x03);
188 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH3, 0x03);
193 int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev)
198 status = afe_read_byte(dev, ADC_PWRDN_CLAMP_CH2, &c_value);
199 c_value &= (~(0x50));
200 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, c_value);
206 The Analog Front End in Cx231xx has 3 channels. These
207 channels are used to share between different inputs
208 like tuner, s-video and composite inputs.
210 channel 1 ----- pin 1 to pin4(in reg is 1-4)
211 channel 2 ----- pin 5 to pin8(in reg is 5-8)
212 channel 3 ----- pin 9 to pin 12(in reg is 9-11)
214 int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux)
216 u8 ch1_setting = (u8) input_mux;
217 u8 ch2_setting = (u8) (input_mux >> 8);
218 u8 ch3_setting = (u8) (input_mux >> 16);
222 if (ch1_setting != 0) {
223 status = afe_read_byte(dev, ADC_INPUT_CH1, &value);
224 value &= (!INPUT_SEL_MASK);
225 value |= (ch1_setting - 1) << 4;
227 status = afe_write_byte(dev, ADC_INPUT_CH1, value);
230 if (ch2_setting != 0) {
231 status = afe_read_byte(dev, ADC_INPUT_CH2, &value);
232 value &= (!INPUT_SEL_MASK);
233 value |= (ch2_setting - 1) << 4;
235 status = afe_write_byte(dev, ADC_INPUT_CH2, value);
238 /* For ch3_setting, the value to put in the register is
239 7 less than the input number */
240 if (ch3_setting != 0) {
241 status = afe_read_byte(dev, ADC_INPUT_CH3, &value);
242 value &= (!INPUT_SEL_MASK);
243 value |= (ch3_setting - 1) << 4;
245 status = afe_write_byte(dev, ADC_INPUT_CH3, value);
251 int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode)
256 * FIXME: We need to implement the AFE code for LOW IF and for HI IF.
257 * Currently, only baseband works.
261 case AFE_MODE_LOW_IF:
262 /* SetupAFEforLowIF(); */
264 case AFE_MODE_BASEBAND:
265 status = cx231xx_afe_setup_AFE_for_baseband(dev);
267 case AFE_MODE_EU_HI_IF:
268 /* SetupAFEforEuHiIF(); */
270 case AFE_MODE_US_HI_IF:
271 /* SetupAFEforUsHiIF(); */
273 case AFE_MODE_JAPAN_HI_IF:
274 /* SetupAFEforJapanHiIF(); */
278 if ((mode != dev->afe_mode) &&
279 (dev->video_input == CX231XX_VMUX_TELEVISION))
280 status = cx231xx_afe_adjust_ref_count(dev,
281 CX231XX_VMUX_TELEVISION);
283 dev->afe_mode = mode;
288 int cx231xx_afe_update_power_control(struct cx231xx *dev,
291 u8 afe_power_status = 0;
294 switch (dev->model) {
295 case CX231XX_BOARD_CNXT_RDE_250:
296 case CX231XX_BOARD_CNXT_RDU_250:
297 if (avmode == POLARIS_AVMODE_ANALOGT_TV) {
298 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
299 FLD_PWRDN_ENABLE_PLL)) {
300 status = afe_write_byte(dev, SUP_BLK_PWRDN,
301 FLD_PWRDN_TUNING_BIAS |
302 FLD_PWRDN_ENABLE_PLL);
303 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
309 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
311 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
313 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
315 } else if (avmode == POLARIS_AVMODE_DIGITAL) {
316 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
318 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
320 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
323 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
325 afe_power_status |= FLD_PWRDN_PD_BANDGAP |
328 status |= afe_write_byte(dev, SUP_BLK_PWRDN,
330 } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) {
331 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
332 FLD_PWRDN_ENABLE_PLL)) {
333 status = afe_write_byte(dev, SUP_BLK_PWRDN,
334 FLD_PWRDN_TUNING_BIAS |
335 FLD_PWRDN_ENABLE_PLL);
336 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
342 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
344 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
346 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
349 cx231xx_info("Invalid AV mode input\n");
354 if (avmode == POLARIS_AVMODE_ANALOGT_TV) {
355 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
356 FLD_PWRDN_ENABLE_PLL)) {
357 status = afe_write_byte(dev, SUP_BLK_PWRDN,
358 FLD_PWRDN_TUNING_BIAS |
359 FLD_PWRDN_ENABLE_PLL);
360 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
366 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
368 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
370 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
372 } else if (avmode == POLARIS_AVMODE_DIGITAL) {
373 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
375 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
377 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
380 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
382 afe_power_status |= FLD_PWRDN_PD_BANDGAP |
385 status |= afe_write_byte(dev, SUP_BLK_PWRDN,
387 } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) {
388 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
389 FLD_PWRDN_ENABLE_PLL)) {
390 status = afe_write_byte(dev, SUP_BLK_PWRDN,
391 FLD_PWRDN_TUNING_BIAS |
392 FLD_PWRDN_ENABLE_PLL);
393 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
399 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
401 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
403 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
406 cx231xx_info("Invalid AV mode input\n");
414 int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input)
420 dev->video_input = video_input;
422 if (video_input == CX231XX_VMUX_TELEVISION) {
423 status = afe_read_byte(dev, ADC_INPUT_CH3, &input_mode);
424 status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH3,
427 status = afe_read_byte(dev, ADC_INPUT_CH1, &input_mode);
428 status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH1,
432 input_mode = (ntf_mode & 0x3) | ((input_mode & 0x6) << 1);
434 switch (input_mode) {
436 dev->afe_ref_count = 0x23C;
439 dev->afe_ref_count = 0x24C;
442 dev->afe_ref_count = 0x258;
445 dev->afe_ref_count = 0x260;
451 status = cx231xx_afe_init_super_block(dev, dev->afe_ref_count);
456 /******************************************************************************
457 * 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 *
458 ******************************************************************************/
459 static int vid_blk_write_byte(struct cx231xx *dev, u16 saddr, u8 data)
461 return cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS,
465 static int vid_blk_read_byte(struct cx231xx *dev, u16 saddr, u8 *data)
470 status = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
476 static int vid_blk_write_word(struct cx231xx *dev, u16 saddr, u32 data)
478 return cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS,
482 static int vid_blk_read_word(struct cx231xx *dev, u16 saddr, u32 *data)
484 return cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
488 int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input)
492 switch (INPUT(input)->type) {
493 case CX231XX_VMUX_COMPOSITE1:
494 case CX231XX_VMUX_SVIDEO:
495 if ((dev->current_pcb_config.type == USB_BUS_POWER) &&
496 (dev->power_mode != POLARIS_AVMODE_ENXTERNAL_AV)) {
498 status = cx231xx_set_power_mode(dev,
499 POLARIS_AVMODE_ENXTERNAL_AV);
501 cx231xx_errdev("%s: set_power_mode : Failed to"
502 " set Power - errCode [%d]!\n",
507 status = cx231xx_set_decoder_video_input(dev,
511 case CX231XX_VMUX_TELEVISION:
512 case CX231XX_VMUX_CABLE:
513 if ((dev->current_pcb_config.type == USB_BUS_POWER) &&
514 (dev->power_mode != POLARIS_AVMODE_ANALOGT_TV)) {
516 status = cx231xx_set_power_mode(dev,
517 POLARIS_AVMODE_ANALOGT_TV);
519 cx231xx_errdev("%s: set_power_mode:Failed"
520 " to set Power - errCode [%d]!\n",
525 status = cx231xx_set_decoder_video_input(dev,
526 CX231XX_VMUX_COMPOSITE1,
530 cx231xx_errdev("%s: set_power_mode : Unknown Input %d !\n",
531 __func__, INPUT(input)->type);
535 /* save the selection */
536 dev->video_input = input;
541 int cx231xx_set_decoder_video_input(struct cx231xx *dev,
542 u8 pin_type, u8 input)
547 if (pin_type != dev->video_input) {
548 status = cx231xx_afe_adjust_ref_count(dev, pin_type);
550 cx231xx_errdev("%s: adjust_ref_count :Failed to set"
551 "AFE input mux - errCode [%d]!\n",
557 /* call afe block to set video inputs */
558 status = cx231xx_afe_set_input_mux(dev, input);
560 cx231xx_errdev("%s: set_input_mux :Failed to set"
561 " AFE input mux - errCode [%d]!\n",
567 case CX231XX_VMUX_COMPOSITE1:
568 status = vid_blk_read_word(dev, AFE_CTRL, &value);
569 value |= (0 << 13) | (1 << 4);
572 /* set [24:23] [22:15] to 0 */
573 value &= (~(0x1ff8000));
574 /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */
576 status = vid_blk_write_word(dev, AFE_CTRL, value);
578 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
580 status = vid_blk_write_word(dev, OUT_CTRL1, value);
582 /* Set vip 1.1 output mode */
583 status = cx231xx_read_modify_write_i2c_dword(dev,
589 /* Tell DIF object to go to baseband mode */
590 status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND);
592 cx231xx_errdev("%s: cx231xx_dif set to By pass"
593 " mode- errCode [%d]!\n",
598 /* Read the DFE_CTRL1 register */
599 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
601 /* enable the VBI_GATE_EN */
602 value |= FLD_VBI_GATE_EN;
604 /* Enable the auto-VGA enable */
605 value |= FLD_VGA_AUTO_EN;
608 status = vid_blk_write_word(dev, DFE_CTRL1, value);
610 /* Disable auto config of registers */
611 status = cx231xx_read_modify_write_i2c_dword(dev,
613 MODE_CTRL, FLD_ACFG_DIS,
614 cx231xx_set_field(FLD_ACFG_DIS, 1));
616 /* Set CVBS input mode */
617 status = cx231xx_read_modify_write_i2c_dword(dev,
619 MODE_CTRL, FLD_INPUT_MODE,
620 cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_CVBS_0));
622 case CX231XX_VMUX_SVIDEO:
623 /* Disable the use of DIF */
625 status = vid_blk_read_word(dev, AFE_CTRL, &value);
627 /* set [24:23] [22:15] to 0 */
628 value &= (~(0x1ff8000));
629 /* set FUNC_MODE[24:23] = 2
630 IF_MOD[22:15] = 0 DCR_BYP_CH2[4:4] = 1; */
632 status = vid_blk_write_word(dev, AFE_CTRL, value);
634 /* Tell DIF object to go to baseband mode */
635 status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND);
637 cx231xx_errdev("%s: cx231xx_dif set to By pass"
638 " mode- errCode [%d]!\n",
643 /* Read the DFE_CTRL1 register */
644 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
646 /* enable the VBI_GATE_EN */
647 value |= FLD_VBI_GATE_EN;
649 /* Enable the auto-VGA enable */
650 value |= FLD_VGA_AUTO_EN;
653 status = vid_blk_write_word(dev, DFE_CTRL1, value);
655 /* Disable auto config of registers */
656 status = cx231xx_read_modify_write_i2c_dword(dev,
658 MODE_CTRL, FLD_ACFG_DIS,
659 cx231xx_set_field(FLD_ACFG_DIS, 1));
661 /* Set YC input mode */
662 status = cx231xx_read_modify_write_i2c_dword(dev,
666 cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_YC_1));
669 status = vid_blk_read_word(dev, AFE_CTRL, &value);
670 value |= FLD_CHROMA_IN_SEL; /* set the chroma in select */
672 /* Clear VGA_SEL_CH2 and VGA_SEL_CH3 (bits 7 and 8)
673 This sets them to use video
674 rather than audio. Only one of the two will be in use. */
675 value &= ~(FLD_VGA_SEL_CH2 | FLD_VGA_SEL_CH3);
677 status = vid_blk_write_word(dev, AFE_CTRL, value);
679 status = cx231xx_afe_set_mode(dev, AFE_MODE_BASEBAND);
681 case CX231XX_VMUX_TELEVISION:
682 case CX231XX_VMUX_CABLE:
684 switch (dev->model) {
685 case CX231XX_BOARD_CNXT_RDE_250:
686 case CX231XX_BOARD_CNXT_RDU_250:
687 /* Disable the use of DIF */
689 status = vid_blk_read_word(dev, AFE_CTRL, &value);
690 value |= (0 << 13) | (1 << 4);
693 /* set [24:23] [22:15] to 0 */
694 value &= (~(0x1FF8000));
695 /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */
697 status = vid_blk_write_word(dev, AFE_CTRL, value);
699 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
701 status = vid_blk_write_word(dev, OUT_CTRL1, value);
703 /* Set vip 1.1 output mode */
704 status = cx231xx_read_modify_write_i2c_dword(dev,
706 OUT_CTRL1, FLD_OUT_MODE,
709 /* Tell DIF object to go to baseband mode */
710 status = cx231xx_dif_set_standard(dev,
713 cx231xx_errdev("%s: cx231xx_dif set to By pass"
714 " mode- errCode [%d]!\n",
719 /* Read the DFE_CTRL1 register */
720 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
722 /* enable the VBI_GATE_EN */
723 value |= FLD_VBI_GATE_EN;
725 /* Enable the auto-VGA enable */
726 value |= FLD_VGA_AUTO_EN;
729 status = vid_blk_write_word(dev, DFE_CTRL1, value);
731 /* Disable auto config of registers */
732 status = cx231xx_read_modify_write_i2c_dword(dev,
734 MODE_CTRL, FLD_ACFG_DIS,
735 cx231xx_set_field(FLD_ACFG_DIS, 1));
737 /* Set CVBS input mode */
738 status = cx231xx_read_modify_write_i2c_dword(dev,
740 MODE_CTRL, FLD_INPUT_MODE,
741 cx231xx_set_field(FLD_INPUT_MODE,
745 /* Enable the DIF for the tuner */
747 /* Reinitialize the DIF */
748 status = cx231xx_dif_set_standard(dev, dev->norm);
750 cx231xx_errdev("%s: cx231xx_dif set to By pass"
751 " mode- errCode [%d]!\n",
756 /* Make sure bypass is cleared */
757 status = vid_blk_read_word(dev, DIF_MISC_CTRL, &value);
759 /* Clear the bypass bit */
760 value &= ~FLD_DIF_DIF_BYPASS;
762 /* Enable the use of the DIF block */
763 status = vid_blk_write_word(dev, DIF_MISC_CTRL, value);
765 /* Read the DFE_CTRL1 register */
766 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
768 /* Disable the VBI_GATE_EN */
769 value &= ~FLD_VBI_GATE_EN;
771 /* Enable the auto-VGA enable, AGC, and
772 set the skip count to 2 */
773 value |= FLD_VGA_AUTO_EN | FLD_AGC_AUTO_EN | 0x00200000;
776 status = vid_blk_write_word(dev, DFE_CTRL1, value);
778 /* Wait until AGC locks up */
781 /* Disable the auto-VGA enable AGC */
782 value &= ~(FLD_VGA_AUTO_EN);
785 status = vid_blk_write_word(dev, DFE_CTRL1, value);
787 /* Enable Polaris B0 AGC output */
788 status = vid_blk_read_word(dev, PIN_CTRL, &value);
789 value |= (FLD_OEF_AGC_RF) |
790 (FLD_OEF_AGC_IFVGA) |
792 status = vid_blk_write_word(dev, PIN_CTRL, value);
794 /* Set vip 1.1 output mode */
795 status = cx231xx_read_modify_write_i2c_dword(dev,
797 OUT_CTRL1, FLD_OUT_MODE,
800 /* Disable auto config of registers */
801 status = cx231xx_read_modify_write_i2c_dword(dev,
803 MODE_CTRL, FLD_ACFG_DIS,
804 cx231xx_set_field(FLD_ACFG_DIS, 1));
806 /* Set CVBS input mode */
807 status = cx231xx_read_modify_write_i2c_dword(dev,
809 MODE_CTRL, FLD_INPUT_MODE,
810 cx231xx_set_field(FLD_INPUT_MODE,
813 /* Set some bits in AFE_CTRL so that channel 2 or 3
814 * is ready to receive audio */
815 /* Clear clamp for channels 2 and 3 (bit 16-17) */
816 /* Clear droop comp (bit 19-20) */
817 /* Set VGA_SEL (for audio control) (bit 7-8) */
818 status = vid_blk_read_word(dev, AFE_CTRL, &value);
820 value |= FLD_VGA_SEL_CH3 | FLD_VGA_SEL_CH2;
822 status = vid_blk_write_word(dev, AFE_CTRL, value);
829 /* Set raw VBI mode */
830 status = cx231xx_read_modify_write_i2c_dword(dev,
832 OUT_CTRL1, FLD_VBIHACTRAW_EN,
833 cx231xx_set_field(FLD_VBIHACTRAW_EN, 1));
835 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
838 status = vid_blk_write_word(dev, OUT_CTRL1, value);
845 * Handle any video-mode specific overrides that are different
846 * on a per video standards basis after touching the MODE_CTRL
847 * register which resets many values for autodetect
849 int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev)
853 cx231xx_info("do_mode_ctrl_overrides : 0x%x\n",
854 (unsigned int)dev->norm);
856 /* Change the DFE_CTRL3 bp_percent to fix flagging */
857 status = vid_blk_write_word(dev, DFE_CTRL3, 0xCD3F0280);
859 if (dev->norm & (V4L2_STD_NTSC | V4L2_STD_PAL_M)) {
860 cx231xx_info("do_mode_ctrl_overrides NTSC\n");
862 /* Move the close caption lines out of active video,
863 adjust the active video start point */
864 status = cx231xx_read_modify_write_i2c_dword(dev,
867 FLD_VBLANK_CNT, 0x18);
868 status = cx231xx_read_modify_write_i2c_dword(dev,
873 status = cx231xx_read_modify_write_i2c_dword(dev,
879 status = cx231xx_read_modify_write_i2c_dword(dev,
884 (FLD_HBLANK_CNT, 0x79));
885 } else if (dev->norm & V4L2_STD_SECAM) {
886 cx231xx_info("do_mode_ctrl_overrides SECAM\n");
887 status = cx231xx_read_modify_write_i2c_dword(dev,
890 FLD_VBLANK_CNT, 0x24);
891 /* Adjust the active video horizontal start point */
892 status = cx231xx_read_modify_write_i2c_dword(dev,
897 (FLD_HBLANK_CNT, 0x85));
899 cx231xx_info("do_mode_ctrl_overrides PAL\n");
900 status = cx231xx_read_modify_write_i2c_dword(dev,
903 FLD_VBLANK_CNT, 0x24);
904 /* Adjust the active video horizontal start point */
905 status = cx231xx_read_modify_write_i2c_dword(dev,
910 (FLD_HBLANK_CNT, 0x85));
916 int cx231xx_set_audio_input(struct cx231xx *dev, u8 input)
919 enum AUDIO_INPUT ainput = AUDIO_INPUT_LINE;
921 switch (INPUT(input)->amux) {
922 case CX231XX_AMUX_VIDEO:
923 ainput = AUDIO_INPUT_TUNER_TV;
925 case CX231XX_AMUX_LINE_IN:
926 status = cx231xx_i2s_blk_set_audio_input(dev, input);
927 ainput = AUDIO_INPUT_LINE;
933 status = cx231xx_set_audio_decoder_input(dev, ainput);
938 int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
939 enum AUDIO_INPUT audio_input)
946 /* Put it in soft reset */
947 status = vid_blk_read_byte(dev, GENERAL_CTL, &gen_ctrl);
949 status = vid_blk_write_byte(dev, GENERAL_CTL, gen_ctrl);
951 switch (audio_input) {
952 case AUDIO_INPUT_LINE:
953 /* setup AUD_IO control from Merlin paralle output */
954 value = cx231xx_set_field(FLD_AUD_CHAN1_SRC,
955 AUD_CHAN_SRC_PARALLEL);
956 status = vid_blk_write_word(dev, AUD_IO_CTRL, value);
958 /* setup input to Merlin, SRC2 connect to AC97
959 bypass upsample-by-2, slave mode, sony mode, left justify
960 adr 091c, dat 01000000 */
961 status = vid_blk_read_word(dev, AC97_CTL, &dwval);
963 status = vid_blk_write_word(dev, AC97_CTL,
964 (dwval | FLD_AC97_UP2X_BYPASS));
966 /* select the parallel1 and SRC3 */
967 status = vid_blk_write_word(dev, BAND_OUT_SEL,
968 cx231xx_set_field(FLD_SRC3_IN_SEL, 0x0) |
969 cx231xx_set_field(FLD_SRC3_CLK_SEL, 0x0) |
970 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x0));
972 /* unmute all, AC97 in, independence mode
973 adr 08d0, data 0x00063073 */
974 status = vid_blk_write_word(dev, PATH1_CTL1, 0x00063073);
976 /* set AVC maximum threshold, adr 08d4, dat ffff0024 */
977 status = vid_blk_read_word(dev, PATH1_VOL_CTL, &dwval);
978 status = vid_blk_write_word(dev, PATH1_VOL_CTL,
979 (dwval | FLD_PATH1_AVC_THRESHOLD));
981 /* set SC maximum threshold, adr 08ec, dat ffffb3a3 */
982 status = vid_blk_read_word(dev, PATH1_SC_CTL, &dwval);
983 status = vid_blk_write_word(dev, PATH1_SC_CTL,
984 (dwval | FLD_PATH1_SC_THRESHOLD));
987 case AUDIO_INPUT_TUNER_TV:
990 /* Setup SRC sources and clocks */
991 status = vid_blk_write_word(dev, BAND_OUT_SEL,
992 cx231xx_set_field(FLD_SRC6_IN_SEL, 0x00) |
993 cx231xx_set_field(FLD_SRC6_CLK_SEL, 0x01) |
994 cx231xx_set_field(FLD_SRC5_IN_SEL, 0x00) |
995 cx231xx_set_field(FLD_SRC5_CLK_SEL, 0x02) |
996 cx231xx_set_field(FLD_SRC4_IN_SEL, 0x02) |
997 cx231xx_set_field(FLD_SRC4_CLK_SEL, 0x03) |
998 cx231xx_set_field(FLD_SRC3_IN_SEL, 0x00) |
999 cx231xx_set_field(FLD_SRC3_CLK_SEL, 0x00) |
1000 cx231xx_set_field(FLD_BASEBAND_BYPASS_CTL, 0x00) |
1001 cx231xx_set_field(FLD_AC97_SRC_SEL, 0x03) |
1002 cx231xx_set_field(FLD_I2S_SRC_SEL, 0x00) |
1003 cx231xx_set_field(FLD_PARALLEL2_SRC_SEL, 0x02) |
1004 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x01));
1006 /* Setup the AUD_IO control */
1007 status = vid_blk_write_word(dev, AUD_IO_CTRL,
1008 cx231xx_set_field(FLD_I2S_PORT_DIR, 0x00) |
1009 cx231xx_set_field(FLD_I2S_OUT_SRC, 0x00) |
1010 cx231xx_set_field(FLD_AUD_CHAN3_SRC, 0x00) |
1011 cx231xx_set_field(FLD_AUD_CHAN2_SRC, 0x00) |
1012 cx231xx_set_field(FLD_AUD_CHAN1_SRC, 0x03));
1014 status = vid_blk_write_word(dev, PATH1_CTL1, 0x1F063870);
1016 /* setAudioStandard(_audio_standard); */
1018 status = vid_blk_write_word(dev, PATH1_CTL1, 0x00063870);
1019 switch (dev->model) {
1020 case CX231XX_BOARD_CNXT_RDE_250:
1021 case CX231XX_BOARD_CNXT_RDU_250:
1022 status = cx231xx_read_modify_write_i2c_dword(dev,
1023 VID_BLK_I2C_ADDRESS,
1026 cx231xx_set_field(FLD_SIF_EN, 1));
1033 case AUDIO_INPUT_TUNER_FM:
1034 /* use SIF for FM radio
1036 setAudioStandard(_audio_standard);
1040 case AUDIO_INPUT_MUTE:
1041 status = vid_blk_write_word(dev, PATH1_CTL1, 0x1F011012);
1045 /* Take it out of soft reset */
1046 status = vid_blk_read_byte(dev, GENERAL_CTL, &gen_ctrl);
1048 status = vid_blk_write_byte(dev, GENERAL_CTL, gen_ctrl);
1053 /* Set resolution of the video */
1054 int cx231xx_resolution_set(struct cx231xx *dev)
1061 height = dev->height;
1063 get_scale(dev, width, height, &hscale, &vscale);
1065 /* set horzontal scale */
1066 status = vid_blk_write_word(dev, HSCALE_CTRL, hscale);
1068 /* set vertical scale */
1069 status = vid_blk_write_word(dev, VSCALE_CTRL, vscale);
1074 /******************************************************************************
1075 * C H I P Specific C O N T R O L functions *
1076 ******************************************************************************/
1077 int cx231xx_init_ctrl_pin_status(struct cx231xx *dev)
1082 status = vid_blk_read_word(dev, PIN_CTRL, &value);
1083 value |= (~dev->board.ctl_pin_status_mask);
1084 status = vid_blk_write_word(dev, PIN_CTRL, value);
1089 int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
1090 u8 analog_or_digital)
1094 /* first set the direction to output */
1095 status = cx231xx_set_gpio_direction(dev,
1097 agc_analog_digital_select_gpio, 1);
1099 /* 0 - demod ; 1 - Analog mode */
1100 status = cx231xx_set_gpio_value(dev,
1101 dev->board.agc_analog_digital_select_gpio,
1107 int cx231xx_enable_i2c_for_tuner(struct cx231xx *dev, u8 I2CIndex)
1109 u8 value[4] = { 0, 0, 0, 0 };
1112 cx231xx_info("Changing the i2c port for tuner to %d\n", I2CIndex);
1114 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
1115 PWR_CTL_EN, value, 4);
1119 if (I2CIndex == I2C_1) {
1120 if (value[0] & I2C_DEMOD_EN) {
1121 value[0] &= ~I2C_DEMOD_EN;
1122 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1123 PWR_CTL_EN, value, 4);
1126 if (!(value[0] & I2C_DEMOD_EN)) {
1127 value[0] |= I2C_DEMOD_EN;
1128 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1129 PWR_CTL_EN, value, 4);
1137 /******************************************************************************
1138 * D I F - B L O C K C O N T R O L functions *
1139 ******************************************************************************/
1140 int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
1141 u32 function_mode, u32 standard)
1145 if (mode == V4L2_TUNER_RADIO) {
1147 /* lo if big signal */
1148 status = cx231xx_reg_mask_write(dev,
1149 VID_BLK_I2C_ADDRESS, 32,
1150 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1151 /* FUNC_MODE = DIF */
1152 status = cx231xx_reg_mask_write(dev,
1153 VID_BLK_I2C_ADDRESS, 32,
1154 AFE_CTRL_C2HH_SRC_CTRL, 23, 24, function_mode);
1156 status = cx231xx_reg_mask_write(dev,
1157 VID_BLK_I2C_ADDRESS, 32,
1158 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xFF);
1160 status = cx231xx_reg_mask_write(dev,
1161 VID_BLK_I2C_ADDRESS, 32,
1162 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1163 } else if (standard != DIF_USE_BASEBAND) {
1164 if (standard & V4L2_STD_MN) {
1165 /* lo if big signal */
1166 status = cx231xx_reg_mask_write(dev,
1167 VID_BLK_I2C_ADDRESS, 32,
1168 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1169 /* FUNC_MODE = DIF */
1170 status = cx231xx_reg_mask_write(dev,
1171 VID_BLK_I2C_ADDRESS, 32,
1172 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1175 status = cx231xx_reg_mask_write(dev,
1176 VID_BLK_I2C_ADDRESS, 32,
1177 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xb);
1179 status = cx231xx_reg_mask_write(dev,
1180 VID_BLK_I2C_ADDRESS, 32,
1181 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1182 /* 0x124, AUD_CHAN1_SRC = 0x3 */
1183 status = cx231xx_reg_mask_write(dev,
1184 VID_BLK_I2C_ADDRESS, 32,
1185 AUD_IO_CTRL, 0, 31, 0x00000003);
1186 } else if ((standard == V4L2_STD_PAL_I) |
1187 (standard & V4L2_STD_SECAM)) {
1189 /* lo if big signal */
1190 status = cx231xx_reg_mask_write(dev,
1191 VID_BLK_I2C_ADDRESS, 32,
1192 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1193 /* FUNC_MODE = DIF */
1194 status = cx231xx_reg_mask_write(dev,
1195 VID_BLK_I2C_ADDRESS, 32,
1196 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1199 status = cx231xx_reg_mask_write(dev,
1200 VID_BLK_I2C_ADDRESS, 32,
1201 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xF);
1203 status = cx231xx_reg_mask_write(dev,
1204 VID_BLK_I2C_ADDRESS, 32,
1205 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1207 /* default PAL BG */
1209 /* lo if big signal */
1210 status = cx231xx_reg_mask_write(dev,
1211 VID_BLK_I2C_ADDRESS, 32,
1212 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1213 /* FUNC_MODE = DIF */
1214 status = cx231xx_reg_mask_write(dev,
1215 VID_BLK_I2C_ADDRESS, 32,
1216 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1219 status = cx231xx_reg_mask_write(dev,
1220 VID_BLK_I2C_ADDRESS, 32,
1221 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xE);
1223 status = cx231xx_reg_mask_write(dev,
1224 VID_BLK_I2C_ADDRESS, 32,
1225 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1232 int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard)
1235 u32 dif_misc_ctrl_value = 0;
1238 cx231xx_info("%s: setStandard to %x\n", __func__, standard);
1240 status = vid_blk_read_word(dev, DIF_MISC_CTRL, &dif_misc_ctrl_value);
1241 if (standard != DIF_USE_BASEBAND)
1242 dev->norm = standard;
1244 switch (dev->model) {
1245 case CX231XX_BOARD_CNXT_RDE_250:
1246 case CX231XX_BOARD_CNXT_RDU_250:
1253 status = cx231xx_dif_configure_C2HH_for_low_IF(dev, dev->active_mode,
1254 func_mode, standard);
1256 if (standard == DIF_USE_BASEBAND) { /* base band */
1257 /* There is a different SRC_PHASE_INC value
1258 for baseband vs. DIF */
1259 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC, 0xDF7DF83);
1260 status = vid_blk_read_word(dev, DIF_MISC_CTRL,
1261 &dif_misc_ctrl_value);
1262 dif_misc_ctrl_value |= FLD_DIF_DIF_BYPASS;
1263 status = vid_blk_write_word(dev, DIF_MISC_CTRL,
1264 dif_misc_ctrl_value);
1265 } else if (standard & V4L2_STD_PAL_D) {
1266 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1267 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1268 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1269 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1270 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1271 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1272 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1273 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1274 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1275 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
1276 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1277 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
1278 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1279 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
1280 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1281 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
1282 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1283 DIF_AGC_IF_INT_CURRENT, 0, 31,
1285 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1286 DIF_AGC_RF_CURRENT, 0, 31,
1288 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1289 DIF_VIDEO_AGC_CTRL, 0, 31,
1291 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1292 DIF_VID_AUD_OVERRIDE, 0, 31,
1294 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1295 DIF_AV_SEP_CTRL, 0, 31, 0x3F3934EA);
1296 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1297 DIF_COMP_FLT_CTRL, 0, 31,
1299 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1300 DIF_SRC_PHASE_INC, 0, 31,
1302 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1303 DIF_SRC_GAIN_CONTROL, 0, 31,
1305 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1306 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1307 /* Save the Spec Inversion value */
1308 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1309 dif_misc_ctrl_value |= 0x3a023F11;
1310 } else if (standard & V4L2_STD_PAL_I) {
1311 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1312 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1313 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1314 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1315 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1316 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1317 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1318 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1319 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1320 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
1321 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1322 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
1323 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1324 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
1325 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1326 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
1327 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1328 DIF_AGC_IF_INT_CURRENT, 0, 31,
1330 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1331 DIF_AGC_RF_CURRENT, 0, 31,
1333 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1334 DIF_VIDEO_AGC_CTRL, 0, 31,
1336 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1337 DIF_VID_AUD_OVERRIDE, 0, 31,
1339 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1340 DIF_AV_SEP_CTRL, 0, 31, 0x5F39A934);
1341 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1342 DIF_COMP_FLT_CTRL, 0, 31,
1344 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1345 DIF_SRC_PHASE_INC, 0, 31,
1347 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1348 DIF_SRC_GAIN_CONTROL, 0, 31,
1350 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1351 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1352 /* Save the Spec Inversion value */
1353 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1354 dif_misc_ctrl_value |= 0x3a033F11;
1355 } else if (standard & V4L2_STD_PAL_M) {
1356 /* improved Low Frequency Phase Noise */
1357 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0xFF01FF0C);
1358 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xbd038c85);
1359 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1db4640a);
1360 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
1361 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C1380);
1362 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
1364 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
1366 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
1368 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
1370 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, 0x012c405d);
1371 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
1373 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
1375 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
1377 status = vid_blk_write_word(dev, DIF_SOFT_RST_CTRL_REVB,
1379 /* Save the Spec Inversion value */
1380 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1381 dif_misc_ctrl_value |= 0x3A0A3F10;
1382 } else if (standard & (V4L2_STD_PAL_N | V4L2_STD_PAL_Nc)) {
1383 /* improved Low Frequency Phase Noise */
1384 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0xFF01FF0C);
1385 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xbd038c85);
1386 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1db4640a);
1387 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
1388 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C1380);
1389 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
1391 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
1393 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
1395 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
1397 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL,
1399 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
1401 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
1403 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
1405 status = vid_blk_write_word(dev, DIF_SOFT_RST_CTRL_REVB,
1407 /* Save the Spec Inversion value */
1408 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1409 dif_misc_ctrl_value = 0x3A093F10;
1410 } else if (standard &
1411 (V4L2_STD_SECAM_B | V4L2_STD_SECAM_D | V4L2_STD_SECAM_G |
1412 V4L2_STD_SECAM_K | V4L2_STD_SECAM_K1)) {
1414 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1415 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1416 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1417 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1418 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1419 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1420 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1421 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1422 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1423 DIF_AGC_IF_REF, 0, 31, 0x888C0380);
1424 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1425 DIF_AGC_CTRL_IF, 0, 31, 0xe0262600);
1426 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1427 DIF_AGC_CTRL_INT, 0, 31, 0xc2171700);
1428 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1429 DIF_AGC_CTRL_RF, 0, 31, 0xc2262600);
1430 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1431 DIF_AGC_IF_INT_CURRENT, 0, 31,
1433 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1434 DIF_AGC_RF_CURRENT, 0, 31,
1436 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1437 DIF_VID_AUD_OVERRIDE, 0, 31,
1439 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1440 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec);
1441 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1442 DIF_COMP_FLT_CTRL, 0, 31,
1444 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1445 DIF_SRC_PHASE_INC, 0, 31,
1447 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1448 DIF_SRC_GAIN_CONTROL, 0, 31,
1450 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1451 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1452 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1453 DIF_VIDEO_AGC_CTRL, 0, 31,
1456 /* Save the Spec Inversion value */
1457 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1458 dif_misc_ctrl_value |= 0x3a023F11;
1459 } else if (standard & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) {
1460 /* Is it SECAM_L1? */
1461 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1462 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1463 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1464 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1465 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1466 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1467 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1468 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1469 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1470 DIF_AGC_IF_REF, 0, 31, 0x888C0380);
1471 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1472 DIF_AGC_CTRL_IF, 0, 31, 0xe0262600);
1473 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1474 DIF_AGC_CTRL_INT, 0, 31, 0xc2171700);
1475 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1476 DIF_AGC_CTRL_RF, 0, 31, 0xc2262600);
1477 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1478 DIF_AGC_IF_INT_CURRENT, 0, 31,
1480 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1481 DIF_AGC_RF_CURRENT, 0, 31,
1483 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1484 DIF_VID_AUD_OVERRIDE, 0, 31,
1486 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1487 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec);
1488 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1489 DIF_COMP_FLT_CTRL, 0, 31,
1491 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1492 DIF_SRC_PHASE_INC, 0, 31,
1494 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1495 DIF_SRC_GAIN_CONTROL, 0, 31,
1497 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1498 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1499 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1500 DIF_VIDEO_AGC_CTRL, 0, 31,
1503 /* Save the Spec Inversion value */
1504 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1505 dif_misc_ctrl_value |= 0x3a023F11;
1507 } else if (standard & V4L2_STD_NTSC_M) {
1508 /* V4L2_STD_NTSC_M (75 IRE Setup) Or
1509 V4L2_STD_NTSC_M_JP (Japan, 0 IRE Setup) */
1511 /* For NTSC the centre frequency of video coming out of
1512 sidewinder is around 7.1MHz or 3.6MHz depending on the
1513 spectral inversion. so for a non spectrally inverted channel
1514 the pll freq word is 0x03420c49
1517 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0x6503BC0C);
1518 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xBD038C85);
1519 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1DB4640A);
1520 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
1521 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C0380);
1522 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
1524 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
1526 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
1528 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
1530 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, 0x01296e1f);
1532 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
1534 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
1536 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
1539 status = vid_blk_write_word(dev, DIF_AGC_CTRL_IF, 0xC2262600);
1540 status = vid_blk_write_word(dev, DIF_AGC_CTRL_INT,
1542 status = vid_blk_write_word(dev, DIF_AGC_CTRL_RF, 0xC2262600);
1544 /* Save the Spec Inversion value */
1545 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1546 dif_misc_ctrl_value |= 0x3a003F10;
1548 /* default PAL BG */
1549 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1550 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1551 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1552 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1553 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1554 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1555 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1556 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1557 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1558 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
1559 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1560 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
1561 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1562 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
1563 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1564 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
1565 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1566 DIF_AGC_IF_INT_CURRENT, 0, 31,
1568 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1569 DIF_AGC_RF_CURRENT, 0, 31,
1571 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1572 DIF_VIDEO_AGC_CTRL, 0, 31,
1574 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1575 DIF_VID_AUD_OVERRIDE, 0, 31,
1577 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1578 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530EC);
1579 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1580 DIF_COMP_FLT_CTRL, 0, 31,
1582 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1583 DIF_SRC_PHASE_INC, 0, 31,
1585 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1586 DIF_SRC_GAIN_CONTROL, 0, 31,
1588 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1589 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1590 /* Save the Spec Inversion value */
1591 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1592 dif_misc_ctrl_value |= 0x3a013F11;
1595 /* The AGC values should be the same for all standards,
1596 AUD_SRC_SEL[19] should always be disabled */
1597 dif_misc_ctrl_value &= ~FLD_DIF_AUD_SRC_SEL;
1599 /* It is still possible to get Set Standard calls even when we
1601 This is done to override the value for FM. */
1602 if (dev->active_mode == V4L2_TUNER_RADIO)
1603 dif_misc_ctrl_value = 0x7a080000;
1605 /* Write the calculated value for misc ontrol register */
1606 status = vid_blk_write_word(dev, DIF_MISC_CTRL, dif_misc_ctrl_value);
1611 int cx231xx_tuner_pre_channel_change(struct cx231xx *dev)
1616 /* Set the RF and IF k_agc values to 3 */
1617 status = vid_blk_read_word(dev, DIF_AGC_IF_REF, &dwval);
1618 dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF);
1619 dwval |= 0x33000000;
1621 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval);
1626 int cx231xx_tuner_post_channel_change(struct cx231xx *dev)
1631 /* Set the RF and IF k_agc values to 4 for PAL/NTSC and 8 for
1632 * SECAM L/B/D standards */
1633 status = vid_blk_read_word(dev, DIF_AGC_IF_REF, &dwval);
1634 dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF);
1636 if (dev->norm & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_B |
1638 dwval |= 0x88000000;
1640 dwval |= 0x44000000;
1642 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval);
1647 /******************************************************************************
1648 * I 2 S - B L O C K C O N T R O L functions *
1649 ******************************************************************************/
1650 int cx231xx_i2s_blk_initialize(struct cx231xx *dev)
1655 status = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1656 CH_PWR_CTRL1, 1, &value, 1);
1657 /* enables clock to delta-sigma and decimation filter */
1659 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1660 CH_PWR_CTRL1, 1, value, 1);
1661 /* power up all channel */
1662 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1663 CH_PWR_CTRL2, 1, 0x00, 1);
1668 int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev,
1669 enum AV_MODE avmode)
1674 if (avmode != POLARIS_AVMODE_ENXTERNAL_AV) {
1675 status = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1676 CH_PWR_CTRL2, 1, &value, 1);
1678 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1679 CH_PWR_CTRL2, 1, value, 1);
1681 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1682 CH_PWR_CTRL2, 1, 0x00, 1);
1688 /* set i2s_blk for audio input types */
1689 int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input)
1693 switch (audio_input) {
1694 case CX231XX_AMUX_LINE_IN:
1695 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1696 CH_PWR_CTRL2, 1, 0x00, 1);
1697 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1698 CH_PWR_CTRL1, 1, 0x80, 1);
1700 case CX231XX_AMUX_VIDEO:
1705 dev->ctl_ainput = audio_input;
1710 /******************************************************************************
1711 * P O W E R C O N T R O L functions *
1712 ******************************************************************************/
1713 int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode)
1715 u8 value[4] = { 0, 0, 0, 0 };
1719 if (dev->power_mode != mode)
1720 dev->power_mode = mode;
1722 cx231xx_info(" setPowerMode::mode = %d, No Change req.\n",
1727 cx231xx_info(" setPowerMode::mode = %d\n", mode);
1729 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value,
1734 tmp = *((u32 *) value);
1737 case POLARIS_AVMODE_ENXTERNAL_AV:
1739 tmp &= (~PWR_MODE_MASK);
1742 value[0] = (u8) tmp;
1743 value[1] = (u8) (tmp >> 8);
1744 value[2] = (u8) (tmp >> 16);
1745 value[3] = (u8) (tmp >> 24);
1746 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1747 PWR_CTL_EN, value, 4);
1748 msleep(PWR_SLEEP_INTERVAL);
1751 value[0] = (u8) tmp;
1752 value[1] = (u8) (tmp >> 8);
1753 value[2] = (u8) (tmp >> 16);
1754 value[3] = (u8) (tmp >> 24);
1756 cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, PWR_CTL_EN,
1758 msleep(PWR_SLEEP_INTERVAL);
1760 tmp |= POLARIS_AVMODE_ENXTERNAL_AV;
1761 value[0] = (u8) tmp;
1762 value[1] = (u8) (tmp >> 8);
1763 value[2] = (u8) (tmp >> 16);
1764 value[3] = (u8) (tmp >> 24);
1765 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1766 PWR_CTL_EN, value, 4);
1768 /* reset state of xceive tuner */
1769 dev->xc_fw_load_done = 0;
1772 case POLARIS_AVMODE_ANALOGT_TV:
1774 tmp &= (~PWR_DEMOD_EN);
1775 tmp |= (I2C_DEMOD_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);
1784 if (!(tmp & PWR_TUNER_EN)) {
1785 tmp |= (PWR_TUNER_EN);
1786 value[0] = (u8) tmp;
1787 value[1] = (u8) (tmp >> 8);
1788 value[2] = (u8) (tmp >> 16);
1789 value[3] = (u8) (tmp >> 24);
1790 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1791 PWR_CTL_EN, value, 4);
1792 msleep(PWR_SLEEP_INTERVAL);
1795 if (!(tmp & PWR_AV_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);
1805 if (!(tmp & PWR_ISO_EN)) {
1807 value[0] = (u8) tmp;
1808 value[1] = (u8) (tmp >> 8);
1809 value[2] = (u8) (tmp >> 16);
1810 value[3] = (u8) (tmp >> 24);
1811 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1812 PWR_CTL_EN, value, 4);
1813 msleep(PWR_SLEEP_INTERVAL);
1816 if (!(tmp & POLARIS_AVMODE_ANALOGT_TV)) {
1817 tmp |= POLARIS_AVMODE_ANALOGT_TV;
1818 value[0] = (u8) tmp;
1819 value[1] = (u8) (tmp >> 8);
1820 value[2] = (u8) (tmp >> 16);
1821 value[3] = (u8) (tmp >> 24);
1822 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1823 PWR_CTL_EN, value, 4);
1824 msleep(PWR_SLEEP_INTERVAL);
1827 if ((dev->model == CX231XX_BOARD_CNXT_RDE_250) ||
1828 (dev->model == CX231XX_BOARD_CNXT_RDU_250)) {
1829 /* tuner path to channel 1 from port 3 */
1830 cx231xx_enable_i2c_for_tuner(dev, I2C_3);
1832 if (dev->cx231xx_reset_analog_tuner)
1833 dev->cx231xx_reset_analog_tuner(dev);
1837 case POLARIS_AVMODE_DIGITAL:
1838 if (!(tmp & PWR_TUNER_EN)) {
1839 tmp |= (PWR_TUNER_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_AV_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);
1858 if (!(tmp & PWR_ISO_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);
1869 tmp |= POLARIS_AVMODE_DIGITAL | I2C_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);
1878 if (!(tmp & PWR_DEMOD_EN)) {
1879 tmp |= PWR_DEMOD_EN;
1880 value[0] = (u8) tmp;
1881 value[1] = (u8) (tmp >> 8);
1882 value[2] = (u8) (tmp >> 16);
1883 value[3] = (u8) (tmp >> 24);
1884 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1885 PWR_CTL_EN, value, 4);
1886 msleep(PWR_SLEEP_INTERVAL);
1889 if ((dev->model == CX231XX_BOARD_CNXT_RDE_250) ||
1890 (dev->model == CX231XX_BOARD_CNXT_RDU_250)) {
1891 /* tuner path to channel 1 from port 3 */
1892 cx231xx_enable_i2c_for_tuner(dev, I2C_3);
1894 if (dev->cx231xx_reset_analog_tuner)
1895 dev->cx231xx_reset_analog_tuner(dev);
1903 msleep(PWR_SLEEP_INTERVAL);
1905 /* For power saving, only enable Pwr_resetout_n
1906 when digital TV is selected. */
1907 if (mode == POLARIS_AVMODE_DIGITAL) {
1908 tmp |= PWR_RESETOUT_EN;
1909 value[0] = (u8) tmp;
1910 value[1] = (u8) (tmp >> 8);
1911 value[2] = (u8) (tmp >> 16);
1912 value[3] = (u8) (tmp >> 24);
1913 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1914 PWR_CTL_EN, value, 4);
1915 msleep(PWR_SLEEP_INTERVAL);
1918 /* update power control for afe */
1919 status = cx231xx_afe_update_power_control(dev, mode);
1921 /* update power control for i2s_blk */
1922 status = cx231xx_i2s_blk_update_power_control(dev, mode);
1924 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value,
1926 cx231xx_info(" The data of PWR_CTL_EN register 0x74"
1927 "=0x%0x,0x%0x,0x%0x,0x%0x\n",
1928 value[0], value[1], value[2], value[3]);
1933 int cx231xx_power_suspend(struct cx231xx *dev)
1935 u8 value[4] = { 0, 0, 0, 0 };
1939 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN,
1944 tmp = *((u32 *) value);
1945 tmp &= (~PWR_MODE_MASK);
1947 value[0] = (u8) tmp;
1948 value[1] = (u8) (tmp >> 8);
1949 value[2] = (u8) (tmp >> 16);
1950 value[3] = (u8) (tmp >> 24);
1951 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, PWR_CTL_EN,
1957 /******************************************************************************
1958 * S T R E A M C O N T R O L functions *
1959 ******************************************************************************/
1960 int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask)
1962 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
1966 cx231xx_info("cx231xx_start_stream():: ep_mask = %x\n", ep_mask);
1967 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET,
1972 tmp = *((u32 *) value);
1974 value[0] = (u8) tmp;
1975 value[1] = (u8) (tmp >> 8);
1976 value[2] = (u8) (tmp >> 16);
1977 value[3] = (u8) (tmp >> 24);
1979 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, EP_MODE_SET,
1985 int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask)
1987 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
1991 cx231xx_info("cx231xx_stop_stream():: ep_mask = %x\n", ep_mask);
1993 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET, value, 4);
1997 tmp = *((u32 *) value);
1999 value[0] = (u8) tmp;
2000 value[1] = (u8) (tmp >> 8);
2001 value[2] = (u8) (tmp >> 16);
2002 value[3] = (u8) (tmp >> 24);
2004 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, EP_MODE_SET,
2010 int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type)
2014 if (dev->udev->speed == USB_SPEED_HIGH) {
2015 switch (media_type) {
2016 case 81: /* audio */
2017 cx231xx_info("%s: Audio enter HANC\n", __func__);
2019 cx231xx_mode_register(dev, TS_MODE_REG, 0x9300);
2023 cx231xx_info("%s: set vanc registers\n", __func__);
2024 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x300);
2027 case 3: /* sliced cc */
2028 cx231xx_info("%s: set hanc registers\n", __func__);
2030 cx231xx_mode_register(dev, TS_MODE_REG, 0x1300);
2034 cx231xx_info("%s: set video registers\n", __func__);
2035 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x100);
2039 cx231xx_info("%s: set ts1 registers\n", __func__);
2040 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x101);
2041 status = cx231xx_mode_register(dev, TS1_CFG_REG, 0x400);
2043 case 6: /* ts1 parallel mode */
2044 cx231xx_info("%s: set ts1 parrallel mode registers\n",
2046 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x100);
2047 status = cx231xx_mode_register(dev, TS1_CFG_REG, 0x400);
2051 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x101);
2057 int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type)
2061 struct pcb_config *pcb_config;
2063 /* get EP for media type */
2064 pcb_config = (struct pcb_config *)&dev->current_pcb_config;
2066 if (pcb_config->config_num == 1) {
2067 switch (media_type) {
2069 ep_mask = ENABLE_EP4; /* ep4 [00:1000] */
2072 ep_mask = ENABLE_EP3; /* ep3 [00:0100] */
2075 ep_mask = ENABLE_EP5; /* ep5 [01:0000] */
2077 case 3: /* Sliced_cc */
2078 ep_mask = ENABLE_EP6; /* ep6 [10:0000] */
2081 case 6: /* ts1 parallel mode */
2082 ep_mask = ENABLE_EP1; /* ep1 [00:0001] */
2085 ep_mask = ENABLE_EP2; /* ep2 [00:0010] */
2089 } else if (pcb_config->config_num > 1) {
2090 switch (media_type) {
2092 ep_mask = ENABLE_EP4; /* ep4 [00:1000] */
2095 ep_mask = ENABLE_EP3; /* ep3 [00:0100] */
2098 ep_mask = ENABLE_EP5; /* ep5 [01:0000] */
2100 case 3: /* Sliced_cc */
2101 ep_mask = ENABLE_EP6; /* ep6 [10:0000] */
2104 case 6: /* ts1 parallel mode */
2105 ep_mask = ENABLE_EP1; /* ep1 [00:0001] */
2108 ep_mask = ENABLE_EP2; /* ep2 [00:0010] */
2115 rc = cx231xx_initialize_stream_xfer(dev, media_type);
2120 /* enable video capture */
2122 rc = cx231xx_start_stream(dev, ep_mask);
2124 /* disable video capture */
2126 rc = cx231xx_stop_stream(dev, ep_mask);
2129 if (dev->mode == CX231XX_ANALOG_MODE)
2130 ;/* do any in Analog mode */
2132 ;/* do any in digital mode */
2136 EXPORT_SYMBOL_GPL(cx231xx_capture_start);
2138 /*****************************************************************************
2139 * G P I O B I T control functions *
2140 ******************************************************************************/
2141 int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val)
2145 status = cx231xx_send_gpio_cmd(dev, gpio_bit, gpio_val, 4, 0, 0);
2150 int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val)
2154 status = cx231xx_send_gpio_cmd(dev, gpio_bit, gpio_val, 4, 0, 1);
2160 * cx231xx_set_gpio_direction
2161 * Sets the direction of the GPIO pin to input or output
2164 * pin_number : The GPIO Pin number to program the direction for
2166 * pin_value : The Direction of the GPIO Pin under reference.
2167 * 0 = Input direction
2168 * 1 = Output direction
2170 int cx231xx_set_gpio_direction(struct cx231xx *dev,
2171 int pin_number, int pin_value)
2176 /* Check for valid pin_number - if 32 , bail out */
2177 if (pin_number >= 32)
2182 value = dev->gpio_dir & (~(1 << pin_number)); /* clear */
2184 value = dev->gpio_dir | (1 << pin_number);
2186 status = cx231xx_set_gpio_bit(dev, value, (u8 *) &dev->gpio_val);
2188 /* cache the value for future */
2189 dev->gpio_dir = value;
2195 * cx231xx_set_gpio_value
2196 * Sets the value of the GPIO pin to Logic high or low. The Pin under
2197 * reference should ALREADY BE SET IN OUTPUT MODE !!!!!!!!!
2200 * pin_number : The GPIO Pin number to program the direction for
2201 * pin_value : The value of the GPIO Pin under reference.
2205 int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value)
2210 /* Check for valid pin_number - if 0xFF , bail out */
2211 if (pin_number >= 32)
2214 /* first do a sanity check - if the Pin is not output, make it output */
2215 if ((dev->gpio_dir & (1 << pin_number)) == 0x00) {
2216 /* It was in input mode */
2217 value = dev->gpio_dir | (1 << pin_number);
2218 dev->gpio_dir = value;
2219 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2220 (u8 *) &dev->gpio_val);
2225 value = dev->gpio_val & (~(1 << pin_number));
2227 value = dev->gpio_val | (1 << pin_number);
2229 /* store the value */
2230 dev->gpio_val = value;
2232 /* toggle bit0 of GP_IO */
2233 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2238 /*****************************************************************************
2239 * G P I O I2C related functions *
2240 ******************************************************************************/
2241 int cx231xx_gpio_i2c_start(struct cx231xx *dev)
2245 /* set SCL to output 1 ; set SDA to output 1 */
2246 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2247 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2248 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2249 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio;
2251 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2255 /* set SCL to output 1; set SDA to output 0 */
2256 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2257 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2259 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2263 /* set SCL to output 0; set SDA to output 0 */
2264 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2265 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2267 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2274 int cx231xx_gpio_i2c_end(struct cx231xx *dev)
2278 /* set SCL to output 0; set SDA to output 0 */
2279 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2280 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2282 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2283 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2285 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2289 /* set SCL to output 1; set SDA to output 0 */
2290 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2291 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2293 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2297 /* set SCL to input ,release SCL cable control
2298 set SDA to input ,release SDA cable control */
2299 dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio);
2300 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2303 cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2310 int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data)
2315 /* set SCL to output ; set SDA to output */
2316 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2317 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2319 for (i = 0; i < 8; i++) {
2320 if (((data << i) & 0x80) == 0) {
2321 /* set SCL to output 0; set SDA to output 0 */
2322 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2323 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2324 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2325 (u8 *)&dev->gpio_val);
2327 /* set SCL to output 1; set SDA to output 0 */
2328 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2329 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2330 (u8 *)&dev->gpio_val);
2332 /* set SCL to output 0; set SDA to output 0 */
2333 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2334 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2335 (u8 *)&dev->gpio_val);
2337 /* set SCL to output 0; set SDA to output 1 */
2338 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2339 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio;
2340 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2341 (u8 *)&dev->gpio_val);
2343 /* set SCL to output 1; set SDA to output 1 */
2344 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2345 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2346 (u8 *)&dev->gpio_val);
2348 /* set SCL to output 0; set SDA to output 1 */
2349 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2350 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2351 (u8 *)&dev->gpio_val);
2357 int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 * buf)
2361 u32 gpio_logic_value = 0;
2365 for (i = 0; i < 8; i++) { /* send write I2c addr */
2367 /* set SCL to output 0; set SDA to input */
2368 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2369 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2370 (u8 *)&dev->gpio_val);
2372 /* set SCL to output 1; set SDA to input */
2373 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2374 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2375 (u8 *)&dev->gpio_val);
2377 /* get SDA data bit */
2378 gpio_logic_value = dev->gpio_val;
2379 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir,
2380 (u8 *)&dev->gpio_val);
2381 if ((dev->gpio_val & (1 << dev->board.tuner_sda_gpio)) != 0)
2382 value |= (1 << (8 - i - 1));
2384 dev->gpio_val = gpio_logic_value;
2387 /* set SCL to output 0,finish the read latest SCL signal.
2388 !!!set SDA to input, never to modify SDA direction at
2390 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2391 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2393 /* store the value */
2394 *buf = value & 0xff;
2399 int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev)
2402 u32 gpio_logic_value = 0;
2406 /* clock stretch; set SCL to input; set SDA to input;
2407 get SCL value till SCL = 1 */
2408 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2409 dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio);
2411 gpio_logic_value = dev->gpio_val;
2412 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2416 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir,
2417 (u8 *)&dev->gpio_val);
2419 } while (((dev->gpio_val &
2420 (1 << dev->board.tuner_scl_gpio)) == 0) &&
2424 cx231xx_info("No ACK after %d msec -GPIO I2C failed!",
2428 throuth clock stretch ,slave has given a SCL signal,
2429 so the SDA data can be directly read. */
2430 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2432 if ((dev->gpio_val & 1 << dev->board.tuner_sda_gpio) == 0) {
2433 dev->gpio_val = gpio_logic_value;
2434 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2437 dev->gpio_val = gpio_logic_value;
2438 dev->gpio_val |= (1 << dev->board.tuner_sda_gpio);
2441 /* read SDA end, set the SCL to output 0, after this operation,
2442 SDA direction can be changed. */
2443 dev->gpio_val = gpio_logic_value;
2444 dev->gpio_dir |= (1 << dev->board.tuner_scl_gpio);
2445 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2446 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2451 int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev)
2455 /* set SDA to ouput */
2456 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2457 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2459 /* set SCL = 0 (output); set SDA = 0 (output) */
2460 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2461 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2462 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2464 /* set SCL = 1 (output); set SDA = 0 (output) */
2465 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2466 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2468 /* set SCL = 0 (output); set SDA = 0 (output) */
2469 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2470 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2472 /* set SDA to input,and then the slave will read data from SDA. */
2473 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2474 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2479 int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev)
2483 /* set scl to output ; set sda to input */
2484 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2485 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2486 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2488 /* set scl to output 0; set sda to input */
2489 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2490 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2492 /* set scl to output 1; set sda to input */
2493 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2494 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2499 /*****************************************************************************
2500 * G P I O I2C related functions *
2501 ******************************************************************************/
2502 /* cx231xx_gpio_i2c_read
2503 * Function to read data from gpio based I2C interface
2505 int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 * buf, u8 len)
2511 mutex_lock(&dev->gpio_i2c_lock);
2514 status = cx231xx_gpio_i2c_start(dev);
2516 /* write dev_addr */
2517 status = cx231xx_gpio_i2c_write_byte(dev, (dev_addr << 1) + 1);
2520 status = cx231xx_gpio_i2c_read_ack(dev);
2523 for (i = 0; i < len; i++) {
2526 status = cx231xx_gpio_i2c_read_byte(dev, &buf[i]);
2528 if ((i + 1) != len) {
2529 /* only do write ack if we more length */
2530 status = cx231xx_gpio_i2c_write_ack(dev);
2534 /* write NAK - inform reads are complete */
2535 status = cx231xx_gpio_i2c_write_nak(dev);
2538 status = cx231xx_gpio_i2c_end(dev);
2540 /* release the lock */
2541 mutex_unlock(&dev->gpio_i2c_lock);
2546 /* cx231xx_gpio_i2c_write
2547 * Function to write data to gpio based I2C interface
2549 int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 * buf, u8 len)
2555 mutex_lock(&dev->gpio_i2c_lock);
2558 status = cx231xx_gpio_i2c_start(dev);
2560 /* write dev_addr */
2561 status = cx231xx_gpio_i2c_write_byte(dev, dev_addr << 1);
2564 status = cx231xx_gpio_i2c_read_ack(dev);
2566 for (i = 0; i < len; i++) {
2568 status = cx231xx_gpio_i2c_write_byte(dev, buf[i]);
2571 status = cx231xx_gpio_i2c_read_ack(dev);
2575 status = cx231xx_gpio_i2c_end(dev);
2577 /* release the lock */
2578 mutex_unlock(&dev->gpio_i2c_lock);