1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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/mm.h>
33#include <linux/mutex.h>
34#include <media/tuner.h>
35
36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-chip-ident.h>
39
40#include "cx231xx.h"
41#include "cx231xx-dif.h"
42
43#define TUNER_MODE_FM_RADIO 0
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60static int verve_write_byte(struct cx231xx *dev, u8 saddr, u8 data)
61{
62 return cx231xx_write_i2c_data(dev, VERVE_I2C_ADDRESS,
63 saddr, 1, data, 1);
64}
65
66static int verve_read_byte(struct cx231xx *dev, u8 saddr, u8 *data)
67{
68 int status;
69 u32 temp = 0;
70
71 status = cx231xx_read_i2c_data(dev, VERVE_I2C_ADDRESS,
72 saddr, 1, &temp, 1);
73 *data = (u8) temp;
74 return status;
75}
76void initGPIO(struct cx231xx *dev)
77{
78 u32 _gpio_direction = 0;
79 u32 value = 0;
80 u8 val = 0;
81
82 _gpio_direction = _gpio_direction & 0xFC0003FF;
83 _gpio_direction = _gpio_direction | 0x03FDFC00;
84 cx231xx_send_gpio_cmd(dev, _gpio_direction, (u8 *)&value, 4, 0, 0);
85
86 verve_read_byte(dev, 0x07, &val);
87 cx231xx_info(" verve_read_byte address0x07=0x%x\n", val);
88 verve_write_byte(dev, 0x07, 0xF4);
89 verve_read_byte(dev, 0x07, &val);
90 cx231xx_info(" verve_read_byte address0x07=0x%x\n", val);
91
92 cx231xx_capture_start(dev, 1, 2);
93
94 cx231xx_mode_register(dev, EP_MODE_SET, 0x0500FE00);
95 cx231xx_mode_register(dev, GBULK_BIT_EN, 0xFFFDFFFF);
96
97}
98void uninitGPIO(struct cx231xx *dev)
99{
100 u8 value[4] = { 0, 0, 0, 0 };
101
102 cx231xx_capture_start(dev, 0, 2);
103 verve_write_byte(dev, 0x07, 0x14);
104 cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
105 0x68, value, 4);
106}
107
108
109
110
111
112static int afe_write_byte(struct cx231xx *dev, u16 saddr, u8 data)
113{
114 return cx231xx_write_i2c_data(dev, AFE_DEVICE_ADDRESS,
115 saddr, 2, data, 1);
116}
117
118static int afe_read_byte(struct cx231xx *dev, u16 saddr, u8 *data)
119{
120 int status;
121 u32 temp = 0;
122
123 status = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
124 saddr, 2, &temp, 1);
125 *data = (u8) temp;
126 return status;
127}
128
129int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count)
130{
131 int status = 0;
132 u8 temp = 0;
133 u8 afe_power_status = 0;
134 int i = 0;
135
136
137 temp = (u8) (ref_count & 0xff);
138 status = afe_write_byte(dev, SUP_BLK_TUNE2, temp);
139 if (status < 0)
140 return status;
141
142 status = afe_read_byte(dev, SUP_BLK_TUNE2, &afe_power_status);
143 if (status < 0)
144 return status;
145
146 temp = (u8) ((ref_count & 0x300) >> 8);
147 temp |= 0x40;
148 status = afe_write_byte(dev, SUP_BLK_TUNE1, temp);
149 if (status < 0)
150 return status;
151
152 status = afe_write_byte(dev, SUP_BLK_PLL2, 0x0f);
153 if (status < 0)
154 return status;
155
156
157 while (afe_power_status != 0x18) {
158 status = afe_write_byte(dev, SUP_BLK_PWRDN, 0x18);
159 if (status < 0) {
160 cx231xx_info(
161 ": Init Super Block failed in send cmd\n");
162 break;
163 }
164
165 status = afe_read_byte(dev, SUP_BLK_PWRDN, &afe_power_status);
166 afe_power_status &= 0xff;
167 if (status < 0) {
168 cx231xx_info(
169 ": Init Super Block failed in receive cmd\n");
170 break;
171 }
172 i++;
173 if (i == 10) {
174 cx231xx_info(
175 ": Init Super Block force break in loop !!!!\n");
176 status = -1;
177 break;
178 }
179 }
180
181 if (status < 0)
182 return status;
183
184
185 status = afe_write_byte(dev, SUP_BLK_TUNE3, 0x40);
186 if (status < 0)
187 return status;
188
189 msleep(5);
190
191
192 status = afe_write_byte(dev, SUP_BLK_TUNE3, 0x00);
193
194 return status;
195}
196
197int cx231xx_afe_init_channels(struct cx231xx *dev)
198{
199 int status = 0;
200
201
202 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, 0x00);
203 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, 0x00);
204 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, 0x00);
205
206
207 status = afe_write_byte(dev, ADC_COM_QUANT, 0x02);
208
209
210 status = afe_write_byte(dev, ADC_FB_FRCRST_CH1, 0x17);
211 status = afe_write_byte(dev, ADC_FB_FRCRST_CH2, 0x17);
212 status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, 0x17);
213
214
215 status = afe_write_byte(dev, ADC_CAL_ATEST_CH1, 0x10);
216 status = afe_write_byte(dev, ADC_CAL_ATEST_CH2, 0x10);
217 status = afe_write_byte(dev, ADC_CAL_ATEST_CH3, 0x10);
218 msleep(5);
219
220
221 status = afe_write_byte(dev, ADC_FB_FRCRST_CH1, 0x07);
222 status = afe_write_byte(dev, ADC_FB_FRCRST_CH2, 0x07);
223 status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, 0x07);
224
225
226 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH1, 0xf0);
227 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH2, 0xf0);
228 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH3, 0xf0);
229
230
231 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
232 ADC_QGAIN_RES_TRM_CH1, 3, 7, 0x00);
233 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
234 ADC_QGAIN_RES_TRM_CH2, 3, 7, 0x00);
235 status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8,
236 ADC_QGAIN_RES_TRM_CH3, 3, 7, 0x00);
237
238
239 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH1, 0x03);
240 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH2, 0x03);
241 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH3, 0x03);
242
243 return status;
244}
245
246int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev)
247{
248 u8 c_value = 0;
249 int status = 0;
250
251 status = afe_read_byte(dev, ADC_PWRDN_CLAMP_CH2, &c_value);
252 c_value &= (~(0x50));
253 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, c_value);
254
255 return status;
256}
257
258
259
260
261
262
263
264
265
266
267int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux)
268{
269 u8 ch1_setting = (u8) input_mux;
270 u8 ch2_setting = (u8) (input_mux >> 8);
271 u8 ch3_setting = (u8) (input_mux >> 16);
272 int status = 0;
273 u8 value = 0;
274
275 if (ch1_setting != 0) {
276 status = afe_read_byte(dev, ADC_INPUT_CH1, &value);
277 value &= ~INPUT_SEL_MASK;
278 value |= (ch1_setting - 1) << 4;
279 value &= 0xff;
280 status = afe_write_byte(dev, ADC_INPUT_CH1, value);
281 }
282
283 if (ch2_setting != 0) {
284 status = afe_read_byte(dev, ADC_INPUT_CH2, &value);
285 value &= ~INPUT_SEL_MASK;
286 value |= (ch2_setting - 1) << 4;
287 value &= 0xff;
288 status = afe_write_byte(dev, ADC_INPUT_CH2, value);
289 }
290
291
292
293 if (ch3_setting != 0) {
294 status = afe_read_byte(dev, ADC_INPUT_CH3, &value);
295 value &= ~INPUT_SEL_MASK;
296 value |= (ch3_setting - 1) << 4;
297 value &= 0xff;
298 status = afe_write_byte(dev, ADC_INPUT_CH3, value);
299 }
300
301 return status;
302}
303
304int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode)
305{
306 int status = 0;
307
308
309
310
311
312
313 switch (mode) {
314 case AFE_MODE_LOW_IF:
315 cx231xx_Setup_AFE_for_LowIF(dev);
316 break;
317 case AFE_MODE_BASEBAND:
318 status = cx231xx_afe_setup_AFE_for_baseband(dev);
319 break;
320 case AFE_MODE_EU_HI_IF:
321
322 break;
323 case AFE_MODE_US_HI_IF:
324
325 break;
326 case AFE_MODE_JAPAN_HI_IF:
327
328 break;
329 }
330
331 if ((mode != dev->afe_mode) &&
332 (dev->video_input == CX231XX_VMUX_TELEVISION))
333 status = cx231xx_afe_adjust_ref_count(dev,
334 CX231XX_VMUX_TELEVISION);
335
336 dev->afe_mode = mode;
337
338 return status;
339}
340
341int cx231xx_afe_update_power_control(struct cx231xx *dev,
342 enum AV_MODE avmode)
343{
344 u8 afe_power_status = 0;
345 int status = 0;
346
347 switch (dev->model) {
348 case CX231XX_BOARD_CNXT_CARRAERA:
349 case CX231XX_BOARD_CNXT_RDE_250:
350 case CX231XX_BOARD_CNXT_SHELBY:
351 case CX231XX_BOARD_CNXT_RDU_250:
352 case CX231XX_BOARD_CNXT_RDE_253S:
353 case CX231XX_BOARD_CNXT_RDU_253S:
354 case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
355 case CX231XX_BOARD_HAUPPAUGE_EXETER:
356 case CX231XX_BOARD_HAUPPAUGE_USBLIVE2:
357 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
358 if (avmode == POLARIS_AVMODE_ANALOGT_TV) {
359 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
360 FLD_PWRDN_ENABLE_PLL)) {
361 status = afe_write_byte(dev, SUP_BLK_PWRDN,
362 FLD_PWRDN_TUNING_BIAS |
363 FLD_PWRDN_ENABLE_PLL);
364 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
365 &afe_power_status);
366 if (status < 0)
367 break;
368 }
369
370 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
371 0x00);
372 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
373 0x00);
374 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
375 0x00);
376 } else if (avmode == POLARIS_AVMODE_DIGITAL) {
377 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
378 0x70);
379 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
380 0x70);
381 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
382 0x70);
383
384 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
385 &afe_power_status);
386 afe_power_status |= FLD_PWRDN_PD_BANDGAP |
387 FLD_PWRDN_PD_BIAS |
388 FLD_PWRDN_PD_TUNECK;
389 status |= afe_write_byte(dev, SUP_BLK_PWRDN,
390 afe_power_status);
391 } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) {
392 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
393 FLD_PWRDN_ENABLE_PLL)) {
394 status = afe_write_byte(dev, SUP_BLK_PWRDN,
395 FLD_PWRDN_TUNING_BIAS |
396 FLD_PWRDN_ENABLE_PLL);
397 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
398 &afe_power_status);
399 if (status < 0)
400 break;
401 }
402
403 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
404 0x00);
405 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
406 0x00);
407 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
408 0x00);
409 } else {
410 cx231xx_info("Invalid AV mode input\n");
411 status = -1;
412 }
413 break;
414 default:
415 if (avmode == POLARIS_AVMODE_ANALOGT_TV) {
416 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
417 FLD_PWRDN_ENABLE_PLL)) {
418 status = afe_write_byte(dev, SUP_BLK_PWRDN,
419 FLD_PWRDN_TUNING_BIAS |
420 FLD_PWRDN_ENABLE_PLL);
421 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
422 &afe_power_status);
423 if (status < 0)
424 break;
425 }
426
427 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
428 0x40);
429 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
430 0x40);
431 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
432 0x00);
433 } else if (avmode == POLARIS_AVMODE_DIGITAL) {
434 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
435 0x70);
436 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
437 0x70);
438 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
439 0x70);
440
441 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
442 &afe_power_status);
443 afe_power_status |= FLD_PWRDN_PD_BANDGAP |
444 FLD_PWRDN_PD_BIAS |
445 FLD_PWRDN_PD_TUNECK;
446 status |= afe_write_byte(dev, SUP_BLK_PWRDN,
447 afe_power_status);
448 } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) {
449 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
450 FLD_PWRDN_ENABLE_PLL)) {
451 status = afe_write_byte(dev, SUP_BLK_PWRDN,
452 FLD_PWRDN_TUNING_BIAS |
453 FLD_PWRDN_ENABLE_PLL);
454 status |= afe_read_byte(dev, SUP_BLK_PWRDN,
455 &afe_power_status);
456 if (status < 0)
457 break;
458 }
459
460 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1,
461 0x00);
462 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2,
463 0x00);
464 status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3,
465 0x40);
466 } else {
467 cx231xx_info("Invalid AV mode input\n");
468 status = -1;
469 }
470 }
471
472 return status;
473}
474
475int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input)
476{
477 u8 input_mode = 0;
478 u8 ntf_mode = 0;
479 int status = 0;
480
481 dev->video_input = video_input;
482
483 if (video_input == CX231XX_VMUX_TELEVISION) {
484 status = afe_read_byte(dev, ADC_INPUT_CH3, &input_mode);
485 status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH3,
486 &ntf_mode);
487 } else {
488 status = afe_read_byte(dev, ADC_INPUT_CH1, &input_mode);
489 status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH1,
490 &ntf_mode);
491 }
492
493 input_mode = (ntf_mode & 0x3) | ((input_mode & 0x6) << 1);
494
495 switch (input_mode) {
496 case SINGLE_ENDED:
497 dev->afe_ref_count = 0x23C;
498 break;
499 case LOW_IF:
500 dev->afe_ref_count = 0x24C;
501 break;
502 case EU_IF:
503 dev->afe_ref_count = 0x258;
504 break;
505 case US_IF:
506 dev->afe_ref_count = 0x260;
507 break;
508 default:
509 break;
510 }
511
512 status = cx231xx_afe_init_super_block(dev, dev->afe_ref_count);
513
514 return status;
515}
516
517
518
519
520static int vid_blk_write_byte(struct cx231xx *dev, u16 saddr, u8 data)
521{
522 return cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS,
523 saddr, 2, data, 1);
524}
525
526static int vid_blk_read_byte(struct cx231xx *dev, u16 saddr, u8 *data)
527{
528 int status;
529 u32 temp = 0;
530
531 status = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
532 saddr, 2, &temp, 1);
533 *data = (u8) temp;
534 return status;
535}
536
537static int vid_blk_write_word(struct cx231xx *dev, u16 saddr, u32 data)
538{
539 return cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS,
540 saddr, 2, data, 4);
541}
542
543static int vid_blk_read_word(struct cx231xx *dev, u16 saddr, u32 *data)
544{
545 return cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
546 saddr, 2, data, 4);
547}
548int cx231xx_check_fw(struct cx231xx *dev)
549{
550 u8 temp = 0;
551 int status = 0;
552 status = vid_blk_read_byte(dev, DL_CTL_ADDRESS_LOW, &temp);
553 if (status < 0)
554 return status;
555 else
556 return temp;
557
558}
559
560int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input)
561{
562 int status = 0;
563
564 switch (INPUT(input)->type) {
565 case CX231XX_VMUX_COMPOSITE1:
566 case CX231XX_VMUX_SVIDEO:
567 if ((dev->current_pcb_config.type == USB_BUS_POWER) &&
568 (dev->power_mode != POLARIS_AVMODE_ENXTERNAL_AV)) {
569
570 status = cx231xx_set_power_mode(dev,
571 POLARIS_AVMODE_ENXTERNAL_AV);
572 if (status < 0) {
573 cx231xx_errdev("%s: set_power_mode : Failed to"
574 " set Power - errCode [%d]!\n",
575 __func__, status);
576 return status;
577 }
578 }
579 status = cx231xx_set_decoder_video_input(dev,
580 INPUT(input)->type,
581 INPUT(input)->vmux);
582 break;
583 case CX231XX_VMUX_TELEVISION:
584 case CX231XX_VMUX_CABLE:
585 if ((dev->current_pcb_config.type == USB_BUS_POWER) &&
586 (dev->power_mode != POLARIS_AVMODE_ANALOGT_TV)) {
587
588 status = cx231xx_set_power_mode(dev,
589 POLARIS_AVMODE_ANALOGT_TV);
590 if (status < 0) {
591 cx231xx_errdev("%s: set_power_mode:Failed"
592 " to set Power - errCode [%d]!\n",
593 __func__, status);
594 return status;
595 }
596 }
597 if (dev->tuner_type == TUNER_NXP_TDA18271)
598 status = cx231xx_set_decoder_video_input(dev,
599 CX231XX_VMUX_TELEVISION,
600 INPUT(input)->vmux);
601 else
602 status = cx231xx_set_decoder_video_input(dev,
603 CX231XX_VMUX_COMPOSITE1,
604 INPUT(input)->vmux);
605
606 break;
607 default:
608 cx231xx_errdev("%s: set_power_mode : Unknown Input %d !\n",
609 __func__, INPUT(input)->type);
610 break;
611 }
612
613
614 dev->video_input = input;
615
616 return status;
617}
618
619int cx231xx_set_decoder_video_input(struct cx231xx *dev,
620 u8 pin_type, u8 input)
621{
622 int status = 0;
623 u32 value = 0;
624
625 if (pin_type != dev->video_input) {
626 status = cx231xx_afe_adjust_ref_count(dev, pin_type);
627 if (status < 0) {
628 cx231xx_errdev("%s: adjust_ref_count :Failed to set"
629 "AFE input mux - errCode [%d]!\n",
630 __func__, status);
631 return status;
632 }
633 }
634
635
636 status = cx231xx_afe_set_input_mux(dev, input);
637 if (status < 0) {
638 cx231xx_errdev("%s: set_input_mux :Failed to set"
639 " AFE input mux - errCode [%d]!\n",
640 __func__, status);
641 return status;
642 }
643
644 switch (pin_type) {
645 case CX231XX_VMUX_COMPOSITE1:
646 status = vid_blk_read_word(dev, AFE_CTRL, &value);
647 value |= (0 << 13) | (1 << 4);
648 value &= ~(1 << 5);
649
650
651 value &= (~(0x1ff8000));
652
653 value |= 0x1000000;
654 status = vid_blk_write_word(dev, AFE_CTRL, value);
655
656 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
657 value |= (1 << 7);
658 status = vid_blk_write_word(dev, OUT_CTRL1, value);
659
660
661 status = cx231xx_read_modify_write_i2c_dword(dev,
662 VID_BLK_I2C_ADDRESS,
663 OUT_CTRL1,
664 FLD_OUT_MODE,
665 dev->board.output_mode);
666
667
668 status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND);
669 if (status < 0) {
670 cx231xx_errdev("%s: cx231xx_dif set to By pass"
671 " mode- errCode [%d]!\n",
672 __func__, status);
673 return status;
674 }
675
676
677 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
678
679
680 value |= FLD_VBI_GATE_EN;
681
682
683 value |= FLD_VGA_AUTO_EN;
684
685
686 status = vid_blk_write_word(dev, DFE_CTRL1, value);
687
688
689 status = cx231xx_read_modify_write_i2c_dword(dev,
690 VID_BLK_I2C_ADDRESS,
691 MODE_CTRL, FLD_ACFG_DIS,
692 cx231xx_set_field(FLD_ACFG_DIS, 1));
693
694
695 status = cx231xx_read_modify_write_i2c_dword(dev,
696 VID_BLK_I2C_ADDRESS,
697 MODE_CTRL, FLD_INPUT_MODE,
698 cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_CVBS_0));
699 break;
700 case CX231XX_VMUX_SVIDEO:
701
702
703 status = vid_blk_read_word(dev, AFE_CTRL, &value);
704
705
706 value &= (~(0x1ff8000));
707
708
709 value |= 0x1000010;
710 status = vid_blk_write_word(dev, AFE_CTRL, value);
711
712
713 status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND);
714 if (status < 0) {
715 cx231xx_errdev("%s: cx231xx_dif set to By pass"
716 " mode- errCode [%d]!\n",
717 __func__, status);
718 return status;
719 }
720
721
722 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
723
724
725 value |= FLD_VBI_GATE_EN;
726
727
728 value |= FLD_VGA_AUTO_EN;
729
730
731 status = vid_blk_write_word(dev, DFE_CTRL1, value);
732
733
734 status = cx231xx_read_modify_write_i2c_dword(dev,
735 VID_BLK_I2C_ADDRESS,
736 MODE_CTRL, FLD_ACFG_DIS,
737 cx231xx_set_field(FLD_ACFG_DIS, 1));
738
739
740 status = cx231xx_read_modify_write_i2c_dword(dev,
741 VID_BLK_I2C_ADDRESS,
742 MODE_CTRL,
743 FLD_INPUT_MODE,
744 cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_YC_1));
745
746
747 status = vid_blk_read_word(dev, AFE_CTRL, &value);
748 value |= FLD_CHROMA_IN_SEL;
749
750
751
752
753 value &= ~(FLD_VGA_SEL_CH2 | FLD_VGA_SEL_CH3);
754
755 status = vid_blk_write_word(dev, AFE_CTRL, value);
756
757 status = cx231xx_afe_set_mode(dev, AFE_MODE_BASEBAND);
758 break;
759 case CX231XX_VMUX_TELEVISION:
760 case CX231XX_VMUX_CABLE:
761 default:
762 switch (dev->model) {
763 case CX231XX_BOARD_CNXT_CARRAERA:
764 case CX231XX_BOARD_CNXT_RDE_250:
765 case CX231XX_BOARD_CNXT_SHELBY:
766 case CX231XX_BOARD_CNXT_RDU_250:
767
768
769 status = vid_blk_read_word(dev, AFE_CTRL, &value);
770 value |= (0 << 13) | (1 << 4);
771 value &= ~(1 << 5);
772
773
774 value &= (~(0x1FF8000));
775
776 value |= 0x1000000;
777 status = vid_blk_write_word(dev, AFE_CTRL, value);
778
779 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
780 value |= (1 << 7);
781 status = vid_blk_write_word(dev, OUT_CTRL1, value);
782
783
784 status = cx231xx_read_modify_write_i2c_dword(dev,
785 VID_BLK_I2C_ADDRESS,
786 OUT_CTRL1, FLD_OUT_MODE,
787 dev->board.output_mode);
788
789
790 status = cx231xx_dif_set_standard(dev,
791 DIF_USE_BASEBAND);
792 if (status < 0) {
793 cx231xx_errdev("%s: cx231xx_dif set to By pass"
794 " mode- errCode [%d]!\n",
795 __func__, status);
796 return status;
797 }
798
799
800 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
801
802
803 value |= FLD_VBI_GATE_EN;
804
805
806 value |= FLD_VGA_AUTO_EN;
807
808
809 status = vid_blk_write_word(dev, DFE_CTRL1, value);
810
811
812 status = cx231xx_read_modify_write_i2c_dword(dev,
813 VID_BLK_I2C_ADDRESS,
814 MODE_CTRL, FLD_ACFG_DIS,
815 cx231xx_set_field(FLD_ACFG_DIS, 1));
816
817
818 status = cx231xx_read_modify_write_i2c_dword(dev,
819 VID_BLK_I2C_ADDRESS,
820 MODE_CTRL, FLD_INPUT_MODE,
821 cx231xx_set_field(FLD_INPUT_MODE,
822 INPUT_MODE_CVBS_0));
823 break;
824 default:
825
826
827
828 status = cx231xx_dif_set_standard(dev, dev->norm);
829 if (status < 0) {
830 cx231xx_errdev("%s: cx231xx_dif set to By pass"
831 " mode- errCode [%d]!\n",
832 __func__, status);
833 return status;
834 }
835
836
837 status = vid_blk_read_word(dev, DIF_MISC_CTRL, &value);
838
839
840 value &= ~FLD_DIF_DIF_BYPASS;
841
842
843 status = vid_blk_write_word(dev, DIF_MISC_CTRL, value);
844
845
846 status = vid_blk_read_word(dev, DFE_CTRL1, &value);
847
848
849 value &= ~FLD_VBI_GATE_EN;
850
851
852
853 value |= FLD_VGA_AUTO_EN | FLD_AGC_AUTO_EN | 0x00200000;
854
855
856 status = vid_blk_write_word(dev, DFE_CTRL1, value);
857
858
859 msleep(1);
860
861
862 value &= ~(FLD_VGA_AUTO_EN);
863
864
865 status = vid_blk_write_word(dev, DFE_CTRL1, value);
866
867
868 status = vid_blk_read_word(dev, PIN_CTRL, &value);
869 value |= (FLD_OEF_AGC_RF) |
870 (FLD_OEF_AGC_IFVGA) |
871 (FLD_OEF_AGC_IF);
872 status = vid_blk_write_word(dev, PIN_CTRL, value);
873
874
875 status = cx231xx_read_modify_write_i2c_dword(dev,
876 VID_BLK_I2C_ADDRESS,
877 OUT_CTRL1, FLD_OUT_MODE,
878 dev->board.output_mode);
879
880
881 status = cx231xx_read_modify_write_i2c_dword(dev,
882 VID_BLK_I2C_ADDRESS,
883 MODE_CTRL, FLD_ACFG_DIS,
884 cx231xx_set_field(FLD_ACFG_DIS, 1));
885
886
887 status = cx231xx_read_modify_write_i2c_dword(dev,
888 VID_BLK_I2C_ADDRESS,
889 MODE_CTRL, FLD_INPUT_MODE,
890 cx231xx_set_field(FLD_INPUT_MODE,
891 INPUT_MODE_CVBS_0));
892
893
894
895
896
897
898 status = vid_blk_read_word(dev, AFE_CTRL, &value);
899
900
901 value &= (~(FLD_FUNC_MODE));
902 value |= 0x800000;
903
904 value |= FLD_VGA_SEL_CH3 | FLD_VGA_SEL_CH2;
905
906 status = vid_blk_write_word(dev, AFE_CTRL, value);
907
908 if (dev->tuner_type == TUNER_NXP_TDA18271) {
909 status = vid_blk_read_word(dev, PIN_CTRL,
910 &value);
911 status = vid_blk_write_word(dev, PIN_CTRL,
912 (value & 0xFFFFFFEF));
913 }
914
915 break;
916
917 }
918 break;
919 }
920
921
922 status = cx231xx_read_modify_write_i2c_dword(dev,
923 VID_BLK_I2C_ADDRESS,
924 OUT_CTRL1, FLD_VBIHACTRAW_EN,
925 cx231xx_set_field(FLD_VBIHACTRAW_EN, 1));
926
927 status = vid_blk_read_word(dev, OUT_CTRL1, &value);
928 if (value & 0x02) {
929 value |= (1 << 19);
930 status = vid_blk_write_word(dev, OUT_CTRL1, value);
931 }
932
933 return status;
934}
935
936void cx231xx_enable656(struct cx231xx *dev)
937{
938 u8 temp = 0;
939 int status;
940
941
942 status = vid_blk_write_byte(dev, TS1_PIN_CTL0, 0xFF);
943
944
945
946 status = vid_blk_read_byte(dev, TS1_PIN_CTL1, &temp);
947 temp = temp|0x04;
948
949 status = vid_blk_write_byte(dev, TS1_PIN_CTL1, temp);
950
951}
952EXPORT_SYMBOL_GPL(cx231xx_enable656);
953
954void cx231xx_disable656(struct cx231xx *dev)
955{
956 u8 temp = 0;
957 int status;
958
959
960 status = vid_blk_write_byte(dev, TS1_PIN_CTL0, 0x00);
961
962 status = vid_blk_read_byte(dev, TS1_PIN_CTL1, &temp);
963 temp = temp&0xFB;
964
965 status = vid_blk_write_byte(dev, TS1_PIN_CTL1, temp);
966}
967EXPORT_SYMBOL_GPL(cx231xx_disable656);
968
969
970
971
972
973
974int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev)
975{
976 int status = 0;
977
978 cx231xx_info("do_mode_ctrl_overrides : 0x%x\n",
979 (unsigned int)dev->norm);
980
981
982 status = vid_blk_write_word(dev, DFE_CTRL3, 0xCD3F0280);
983
984 if (dev->norm & (V4L2_STD_NTSC | V4L2_STD_PAL_M)) {
985 cx231xx_info("do_mode_ctrl_overrides NTSC\n");
986
987
988
989 status = cx231xx_read_modify_write_i2c_dword(dev,
990 VID_BLK_I2C_ADDRESS,
991 VERT_TIM_CTRL,
992 FLD_VBLANK_CNT, 0x18);
993 status = cx231xx_read_modify_write_i2c_dword(dev,
994 VID_BLK_I2C_ADDRESS,
995 VERT_TIM_CTRL,
996 FLD_VACTIVE_CNT,
997 0x1E7000);
998 status = cx231xx_read_modify_write_i2c_dword(dev,
999 VID_BLK_I2C_ADDRESS,
1000 VERT_TIM_CTRL,
1001 FLD_V656BLANK_CNT,
1002 0x1C000000);
1003
1004 status = cx231xx_read_modify_write_i2c_dword(dev,
1005 VID_BLK_I2C_ADDRESS,
1006 HORIZ_TIM_CTRL,
1007 FLD_HBLANK_CNT,
1008 cx231xx_set_field
1009 (FLD_HBLANK_CNT, 0x79));
1010
1011 } else if (dev->norm & V4L2_STD_SECAM) {
1012 cx231xx_info("do_mode_ctrl_overrides SECAM\n");
1013 status = cx231xx_read_modify_write_i2c_dword(dev,
1014 VID_BLK_I2C_ADDRESS,
1015 VERT_TIM_CTRL,
1016 FLD_VBLANK_CNT, 0x20);
1017 status = cx231xx_read_modify_write_i2c_dword(dev,
1018 VID_BLK_I2C_ADDRESS,
1019 VERT_TIM_CTRL,
1020 FLD_VACTIVE_CNT,
1021 cx231xx_set_field
1022 (FLD_VACTIVE_CNT,
1023 0x244));
1024 status = cx231xx_read_modify_write_i2c_dword(dev,
1025 VID_BLK_I2C_ADDRESS,
1026 VERT_TIM_CTRL,
1027 FLD_V656BLANK_CNT,
1028 cx231xx_set_field
1029 (FLD_V656BLANK_CNT,
1030 0x24));
1031
1032 status = cx231xx_read_modify_write_i2c_dword(dev,
1033 VID_BLK_I2C_ADDRESS,
1034 HORIZ_TIM_CTRL,
1035 FLD_HBLANK_CNT,
1036 cx231xx_set_field
1037 (FLD_HBLANK_CNT, 0x85));
1038 } else {
1039 cx231xx_info("do_mode_ctrl_overrides PAL\n");
1040 status = cx231xx_read_modify_write_i2c_dword(dev,
1041 VID_BLK_I2C_ADDRESS,
1042 VERT_TIM_CTRL,
1043 FLD_VBLANK_CNT, 0x20);
1044 status = cx231xx_read_modify_write_i2c_dword(dev,
1045 VID_BLK_I2C_ADDRESS,
1046 VERT_TIM_CTRL,
1047 FLD_VACTIVE_CNT,
1048 cx231xx_set_field
1049 (FLD_VACTIVE_CNT,
1050 0x244));
1051 status = cx231xx_read_modify_write_i2c_dword(dev,
1052 VID_BLK_I2C_ADDRESS,
1053 VERT_TIM_CTRL,
1054 FLD_V656BLANK_CNT,
1055 cx231xx_set_field
1056 (FLD_V656BLANK_CNT,
1057 0x24));
1058
1059 status = cx231xx_read_modify_write_i2c_dword(dev,
1060 VID_BLK_I2C_ADDRESS,
1061 HORIZ_TIM_CTRL,
1062 FLD_HBLANK_CNT,
1063 cx231xx_set_field
1064 (FLD_HBLANK_CNT, 0x85));
1065
1066 }
1067
1068 return status;
1069}
1070
1071int cx231xx_unmute_audio(struct cx231xx *dev)
1072{
1073 return vid_blk_write_byte(dev, PATH1_VOL_CTL, 0x24);
1074}
1075EXPORT_SYMBOL_GPL(cx231xx_unmute_audio);
1076
1077int stopAudioFirmware(struct cx231xx *dev)
1078{
1079 return vid_blk_write_byte(dev, DL_CTL_CONTROL, 0x03);
1080}
1081
1082int restartAudioFirmware(struct cx231xx *dev)
1083{
1084 return vid_blk_write_byte(dev, DL_CTL_CONTROL, 0x13);
1085}
1086
1087int cx231xx_set_audio_input(struct cx231xx *dev, u8 input)
1088{
1089 int status = 0;
1090 enum AUDIO_INPUT ainput = AUDIO_INPUT_LINE;
1091
1092 switch (INPUT(input)->amux) {
1093 case CX231XX_AMUX_VIDEO:
1094 ainput = AUDIO_INPUT_TUNER_TV;
1095 break;
1096 case CX231XX_AMUX_LINE_IN:
1097 status = cx231xx_i2s_blk_set_audio_input(dev, input);
1098 ainput = AUDIO_INPUT_LINE;
1099 break;
1100 default:
1101 break;
1102 }
1103
1104 status = cx231xx_set_audio_decoder_input(dev, ainput);
1105
1106 return status;
1107}
1108
1109int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
1110 enum AUDIO_INPUT audio_input)
1111{
1112 u32 dwval;
1113 int status;
1114 u8 gen_ctrl;
1115 u32 value = 0;
1116
1117
1118 status = vid_blk_read_byte(dev, GENERAL_CTL, &gen_ctrl);
1119 gen_ctrl |= 1;
1120 status = vid_blk_write_byte(dev, GENERAL_CTL, gen_ctrl);
1121
1122 switch (audio_input) {
1123 case AUDIO_INPUT_LINE:
1124
1125 value = cx231xx_set_field(FLD_AUD_CHAN1_SRC,
1126 AUD_CHAN_SRC_PARALLEL);
1127 status = vid_blk_write_word(dev, AUD_IO_CTRL, value);
1128
1129
1130
1131
1132 status = vid_blk_read_word(dev, AC97_CTL, &dwval);
1133
1134 status = vid_blk_write_word(dev, AC97_CTL,
1135 (dwval | FLD_AC97_UP2X_BYPASS));
1136
1137
1138 status = vid_blk_write_word(dev, BAND_OUT_SEL,
1139 cx231xx_set_field(FLD_SRC3_IN_SEL, 0x0) |
1140 cx231xx_set_field(FLD_SRC3_CLK_SEL, 0x0) |
1141 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x0));
1142
1143
1144
1145 status = vid_blk_write_word(dev, DL_CTL, 0x3000001);
1146 status = vid_blk_write_word(dev, PATH1_CTL1, 0x00063073);
1147
1148
1149 status = vid_blk_read_word(dev, PATH1_VOL_CTL, &dwval);
1150 status = vid_blk_write_word(dev, PATH1_VOL_CTL,
1151 (dwval | FLD_PATH1_AVC_THRESHOLD));
1152
1153
1154 status = vid_blk_read_word(dev, PATH1_SC_CTL, &dwval);
1155 status = vid_blk_write_word(dev, PATH1_SC_CTL,
1156 (dwval | FLD_PATH1_SC_THRESHOLD));
1157 break;
1158
1159 case AUDIO_INPUT_TUNER_TV:
1160 default:
1161 status = stopAudioFirmware(dev);
1162
1163 status = vid_blk_write_word(dev, BAND_OUT_SEL,
1164 cx231xx_set_field(FLD_SRC6_IN_SEL, 0x00) |
1165 cx231xx_set_field(FLD_SRC6_CLK_SEL, 0x01) |
1166 cx231xx_set_field(FLD_SRC5_IN_SEL, 0x00) |
1167 cx231xx_set_field(FLD_SRC5_CLK_SEL, 0x02) |
1168 cx231xx_set_field(FLD_SRC4_IN_SEL, 0x02) |
1169 cx231xx_set_field(FLD_SRC4_CLK_SEL, 0x03) |
1170 cx231xx_set_field(FLD_SRC3_IN_SEL, 0x00) |
1171 cx231xx_set_field(FLD_SRC3_CLK_SEL, 0x00) |
1172 cx231xx_set_field(FLD_BASEBAND_BYPASS_CTL, 0x00) |
1173 cx231xx_set_field(FLD_AC97_SRC_SEL, 0x03) |
1174 cx231xx_set_field(FLD_I2S_SRC_SEL, 0x00) |
1175 cx231xx_set_field(FLD_PARALLEL2_SRC_SEL, 0x02) |
1176 cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x01));
1177
1178
1179 status = vid_blk_write_word(dev, AUD_IO_CTRL,
1180 cx231xx_set_field(FLD_I2S_PORT_DIR, 0x00) |
1181 cx231xx_set_field(FLD_I2S_OUT_SRC, 0x00) |
1182 cx231xx_set_field(FLD_AUD_CHAN3_SRC, 0x00) |
1183 cx231xx_set_field(FLD_AUD_CHAN2_SRC, 0x00) |
1184 cx231xx_set_field(FLD_AUD_CHAN1_SRC, 0x03));
1185
1186 status = vid_blk_write_word(dev, PATH1_CTL1, 0x1F063870);
1187
1188
1189 status = vid_blk_write_word(dev, PATH1_CTL1, 0x00063870);
1190
1191 status = restartAudioFirmware(dev);
1192
1193 switch (dev->board.tuner_type) {
1194 case TUNER_XC5000:
1195
1196 status = cx231xx_read_modify_write_i2c_dword(dev,
1197 VID_BLK_I2C_ADDRESS,
1198 CHIP_CTRL,
1199 FLD_SIF_EN,
1200 cx231xx_set_field(FLD_SIF_EN, 1));
1201 break;
1202 case TUNER_NXP_TDA18271:
1203
1204 status = cx231xx_read_modify_write_i2c_dword(dev,
1205 VID_BLK_I2C_ADDRESS,
1206 CHIP_CTRL,
1207 FLD_SIF_EN,
1208 cx231xx_set_field(FLD_SIF_EN, 0));
1209 break;
1210 default:
1211
1212
1213
1214 printk(KERN_INFO "Unknown tuner type configuring SIF");
1215 break;
1216 }
1217 break;
1218
1219 case AUDIO_INPUT_TUNER_FM:
1220
1221
1222
1223
1224 break;
1225
1226 case AUDIO_INPUT_MUTE:
1227 status = vid_blk_write_word(dev, PATH1_CTL1, 0x1F011012);
1228 break;
1229 }
1230
1231
1232 status = vid_blk_read_byte(dev, GENERAL_CTL, &gen_ctrl);
1233 gen_ctrl &= ~1;
1234 status = vid_blk_write_byte(dev, GENERAL_CTL, gen_ctrl);
1235
1236 return status;
1237}
1238
1239
1240
1241
1242int cx231xx_init_ctrl_pin_status(struct cx231xx *dev)
1243{
1244 u32 value;
1245 int status = 0;
1246
1247 status = vid_blk_read_word(dev, PIN_CTRL, &value);
1248 value |= (~dev->board.ctl_pin_status_mask);
1249 status = vid_blk_write_word(dev, PIN_CTRL, value);
1250
1251 return status;
1252}
1253
1254int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
1255 u8 analog_or_digital)
1256{
1257 int status = 0;
1258
1259
1260 status = cx231xx_set_gpio_direction(dev,
1261 dev->board.
1262 agc_analog_digital_select_gpio, 1);
1263
1264
1265 status = cx231xx_set_gpio_value(dev,
1266 dev->board.agc_analog_digital_select_gpio,
1267 analog_or_digital);
1268
1269 return status;
1270}
1271
1272int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3)
1273{
1274 u8 value[4] = { 0, 0, 0, 0 };
1275 int status = 0;
1276 bool current_is_port_3;
1277
1278 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
1279 PWR_CTL_EN, value, 4);
1280 if (status < 0)
1281 return status;
1282
1283 current_is_port_3 = value[0] & I2C_DEMOD_EN ? true : false;
1284
1285
1286 if (current_is_port_3 == is_port_3)
1287 return 0;
1288
1289 if (is_port_3)
1290 value[0] |= I2C_DEMOD_EN;
1291 else
1292 value[0] &= ~I2C_DEMOD_EN;
1293
1294 cx231xx_info("Changing the i2c master port to %d\n",
1295 is_port_3 ? 3 : 1);
1296
1297 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1298 PWR_CTL_EN, value, 4);
1299
1300 return status;
1301
1302}
1303EXPORT_SYMBOL_GPL(cx231xx_enable_i2c_port_3);
1304
1305void update_HH_register_after_set_DIF(struct cx231xx *dev)
1306{
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319}
1320
1321void cx231xx_dump_HH_reg(struct cx231xx *dev)
1322{
1323 u8 status = 0;
1324 u32 value = 0;
1325 u16 i = 0;
1326
1327 value = 0x45005390;
1328 status = vid_blk_write_word(dev, 0x104, value);
1329
1330 for (i = 0x100; i < 0x140; i++) {
1331 status = vid_blk_read_word(dev, i, &value);
1332 cx231xx_info("reg0x%x=0x%x\n", i, value);
1333 i = i+3;
1334 }
1335
1336 for (i = 0x300; i < 0x400; i++) {
1337 status = vid_blk_read_word(dev, i, &value);
1338 cx231xx_info("reg0x%x=0x%x\n", i, value);
1339 i = i+3;
1340 }
1341
1342 for (i = 0x400; i < 0x440; i++) {
1343 status = vid_blk_read_word(dev, i, &value);
1344 cx231xx_info("reg0x%x=0x%x\n", i, value);
1345 i = i+3;
1346 }
1347
1348 status = vid_blk_read_word(dev, AFE_CTRL_C2HH_SRC_CTRL, &value);
1349 cx231xx_info("AFE_CTRL_C2HH_SRC_CTRL=0x%x\n", value);
1350 vid_blk_write_word(dev, AFE_CTRL_C2HH_SRC_CTRL, 0x4485D390);
1351 status = vid_blk_read_word(dev, AFE_CTRL_C2HH_SRC_CTRL, &value);
1352 cx231xx_info("AFE_CTRL_C2HH_SRC_CTRL=0x%x\n", value);
1353}
1354
1355void cx231xx_dump_SC_reg(struct cx231xx *dev)
1356{
1357 u8 value[4] = { 0, 0, 0, 0 };
1358 int status = 0;
1359 cx231xx_info("cx231xx_dump_SC_reg %s!\n", __TIME__);
1360
1361 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, BOARD_CFG_STAT,
1362 value, 4);
1363 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", BOARD_CFG_STAT, value[0],
1364 value[1], value[2], value[3]);
1365 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS_MODE_REG,
1366 value, 4);
1367 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS_MODE_REG, value[0],
1368 value[1], value[2], value[3]);
1369 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS1_CFG_REG,
1370 value, 4);
1371 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS1_CFG_REG, value[0],
1372 value[1], value[2], value[3]);
1373 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS1_LENGTH_REG,
1374 value, 4);
1375 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS1_LENGTH_REG, value[0],
1376 value[1], value[2], value[3]);
1377
1378 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS2_CFG_REG,
1379 value, 4);
1380 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS2_CFG_REG, value[0],
1381 value[1], value[2], value[3]);
1382 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, TS2_LENGTH_REG,
1383 value, 4);
1384 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", TS2_LENGTH_REG, value[0],
1385 value[1], value[2], value[3]);
1386 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET,
1387 value, 4);
1388 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", EP_MODE_SET, value[0],
1389 value[1], value[2], value[3]);
1390 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_PTN1,
1391 value, 4);
1392 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN1, value[0],
1393 value[1], value[2], value[3]);
1394
1395 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_PTN2,
1396 value, 4);
1397 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN2, value[0],
1398 value[1], value[2], value[3]);
1399 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_PTN3,
1400 value, 4);
1401 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_PTN3, value[0],
1402 value[1], value[2], value[3]);
1403 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_MASK0,
1404 value, 4);
1405 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK0, value[0],
1406 value[1], value[2], value[3]);
1407 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_MASK1,
1408 value, 4);
1409 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK1, value[0],
1410 value[1], value[2], value[3]);
1411
1412 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_PWR_MASK2,
1413 value, 4);
1414 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_PWR_MASK2, value[0],
1415 value[1], value[2], value[3]);
1416 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_GAIN,
1417 value, 4);
1418 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_GAIN, value[0],
1419 value[1], value[2], value[3]);
1420 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_CAR_REG,
1421 value, 4);
1422 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_CAR_REG, value[0],
1423 value[1], value[2], value[3]);
1424 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_OT_CFG1,
1425 value, 4);
1426 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_OT_CFG1, value[0],
1427 value[1], value[2], value[3]);
1428
1429 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, CIR_OT_CFG2,
1430 value, 4);
1431 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", CIR_OT_CFG2, value[0],
1432 value[1], value[2], value[3]);
1433 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN,
1434 value, 4);
1435 cx231xx_info("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", PWR_CTL_EN, value[0],
1436 value[1], value[2], value[3]);
1437
1438
1439}
1440
1441void cx231xx_Setup_AFE_for_LowIF(struct cx231xx *dev)
1442
1443{
1444 u8 status = 0;
1445 u8 value = 0;
1446
1447
1448
1449 status = afe_read_byte(dev, ADC_STATUS2_CH3, &value);
1450 value = (value & 0xFE)|0x01;
1451 status = afe_write_byte(dev, ADC_STATUS2_CH3, value);
1452
1453 status = afe_read_byte(dev, ADC_STATUS2_CH3, &value);
1454 value = (value & 0xFE)|0x00;
1455 status = afe_write_byte(dev, ADC_STATUS2_CH3, value);
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467 status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH3, &value);
1468 value = (value & 0xFC)|0x00;
1469 status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH3, value);
1470
1471 status = afe_read_byte(dev, ADC_INPUT_CH3, &value);
1472 value = (value & 0xF9)|0x02;
1473 status = afe_write_byte(dev, ADC_INPUT_CH3, value);
1474
1475 status = afe_read_byte(dev, ADC_FB_FRCRST_CH3, &value);
1476 value = (value & 0xFB)|0x04;
1477 status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, value);
1478
1479 status = afe_read_byte(dev, ADC_DCSERVO_DEM_CH3, &value);
1480 value = (value & 0xFC)|0x03;
1481 status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH3, value);
1482
1483 status = afe_read_byte(dev, ADC_CTRL_DAC1_CH3, &value);
1484 value = (value & 0xFB)|0x04;
1485 status = afe_write_byte(dev, ADC_CTRL_DAC1_CH3, value);
1486
1487 status = afe_read_byte(dev, ADC_CTRL_DAC23_CH3, &value);
1488 value = (value & 0xF8)|0x06;
1489 status = afe_write_byte(dev, ADC_CTRL_DAC23_CH3, value);
1490
1491 status = afe_read_byte(dev, ADC_CTRL_DAC23_CH3, &value);
1492 value = (value & 0x8F)|0x40;
1493 status = afe_write_byte(dev, ADC_CTRL_DAC23_CH3, value);
1494
1495 status = afe_read_byte(dev, ADC_PWRDN_CLAMP_CH3, &value);
1496 value = (value & 0xDF)|0x20;
1497 status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, value);
1498}
1499
1500void cx231xx_set_Colibri_For_LowIF(struct cx231xx *dev, u32 if_freq,
1501 u8 spectral_invert, u32 mode)
1502{
1503 u32 colibri_carrier_offset = 0;
1504 u8 status = 0;
1505 u32 func_mode = 0x01;
1506 u32 standard = 0;
1507 u8 value[4] = { 0, 0, 0, 0 };
1508
1509 cx231xx_info("Enter cx231xx_set_Colibri_For_LowIF()\n");
1510 value[0] = (u8) 0x6F;
1511 value[1] = (u8) 0x6F;
1512 value[2] = (u8) 0x6F;
1513 value[3] = (u8) 0x6F;
1514 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1515 PWR_CTL_EN, value, 4);
1516
1517
1518 status = cx231xx_afe_set_mode(dev, AFE_MODE_LOW_IF);
1519
1520
1521 standard = dev->norm;
1522 status = cx231xx_dif_configure_C2HH_for_low_IF(dev, dev->active_mode,
1523 func_mode, standard);
1524
1525
1526 colibri_carrier_offset = cx231xx_Get_Colibri_CarrierOffset(mode,
1527 standard);
1528
1529 cx231xx_info("colibri_carrier_offset=%d, standard=0x%x\n",
1530 colibri_carrier_offset, standard);
1531
1532
1533 cx231xx_set_DIF_bandpass(dev, (if_freq+colibri_carrier_offset),
1534 spectral_invert, mode);
1535}
1536
1537u32 cx231xx_Get_Colibri_CarrierOffset(u32 mode, u32 standerd)
1538{
1539 u32 colibri_carrier_offset = 0;
1540
1541 if (mode == TUNER_MODE_FM_RADIO) {
1542 colibri_carrier_offset = 1100000;
1543 } else if (standerd & (V4L2_STD_MN | V4L2_STD_NTSC_M_JP)) {
1544 colibri_carrier_offset = 4832000;
1545 } else if (standerd & (V4L2_STD_PAL_B | V4L2_STD_PAL_G)) {
1546 colibri_carrier_offset = 2700000;
1547 } else if (standerd & (V4L2_STD_PAL_D | V4L2_STD_PAL_I
1548 | V4L2_STD_SECAM)) {
1549 colibri_carrier_offset = 2100000;
1550 }
1551
1552 return colibri_carrier_offset;
1553}
1554
1555void cx231xx_set_DIF_bandpass(struct cx231xx *dev, u32 if_freq,
1556 u8 spectral_invert, u32 mode)
1557{
1558 unsigned long pll_freq_word;
1559 int status = 0;
1560 u32 dif_misc_ctrl_value = 0;
1561 u64 pll_freq_u64 = 0;
1562 u32 i = 0;
1563
1564 cx231xx_info("if_freq=%d;spectral_invert=0x%x;mode=0x%x\n",
1565 if_freq, spectral_invert, mode);
1566
1567
1568 if (mode == TUNER_MODE_FM_RADIO) {
1569 pll_freq_word = 0x905A1CAC;
1570 status = vid_blk_write_word(dev, DIF_PLL_FREQ_WORD, pll_freq_word);
1571
1572 } else {
1573
1574 pll_freq_word = if_freq;
1575 pll_freq_u64 = (u64)pll_freq_word << 28L;
1576 do_div(pll_freq_u64, 50000000);
1577 pll_freq_word = (u32)pll_freq_u64;
1578
1579 status = vid_blk_write_word(dev, DIF_PLL_FREQ_WORD, pll_freq_word);
1580
1581 if (spectral_invert) {
1582 if_freq -= 400000;
1583
1584 status = vid_blk_read_word(dev, DIF_MISC_CTRL,
1585 &dif_misc_ctrl_value);
1586 dif_misc_ctrl_value = dif_misc_ctrl_value | 0x00200000;
1587 status = vid_blk_write_word(dev, DIF_MISC_CTRL,
1588 dif_misc_ctrl_value);
1589 } else {
1590 if_freq += 400000;
1591
1592 status = vid_blk_read_word(dev, DIF_MISC_CTRL,
1593 &dif_misc_ctrl_value);
1594 dif_misc_ctrl_value = dif_misc_ctrl_value & 0xFFDFFFFF;
1595 status = vid_blk_write_word(dev, DIF_MISC_CTRL,
1596 dif_misc_ctrl_value);
1597 }
1598
1599 if_freq = (if_freq/100000)*100000;
1600
1601 if (if_freq < 3000000)
1602 if_freq = 3000000;
1603
1604 if (if_freq > 16000000)
1605 if_freq = 16000000;
1606 }
1607
1608 cx231xx_info("Enter IF=%zd\n",
1609 sizeof(Dif_set_array)/sizeof(struct dif_settings));
1610 for (i = 0; i < sizeof(Dif_set_array)/sizeof(struct dif_settings); i++) {
1611 if (Dif_set_array[i].if_freq == if_freq) {
1612 status = vid_blk_write_word(dev,
1613 Dif_set_array[i].register_address, Dif_set_array[i].value);
1614 }
1615 }
1616}
1617
1618
1619
1620
1621int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
1622 u32 function_mode, u32 standard)
1623{
1624 int status = 0;
1625
1626
1627 if (mode == V4L2_TUNER_RADIO) {
1628
1629
1630 status = cx231xx_reg_mask_write(dev,
1631 VID_BLK_I2C_ADDRESS, 32,
1632 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1633
1634 status = cx231xx_reg_mask_write(dev,
1635 VID_BLK_I2C_ADDRESS, 32,
1636 AFE_CTRL_C2HH_SRC_CTRL, 23, 24, function_mode);
1637
1638 status = cx231xx_reg_mask_write(dev,
1639 VID_BLK_I2C_ADDRESS, 32,
1640 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xFF);
1641
1642 status = cx231xx_reg_mask_write(dev,
1643 VID_BLK_I2C_ADDRESS, 32,
1644 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1645 } else if (standard != DIF_USE_BASEBAND) {
1646 if (standard & V4L2_STD_MN) {
1647
1648 status = cx231xx_reg_mask_write(dev,
1649 VID_BLK_I2C_ADDRESS, 32,
1650 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1651
1652 status = cx231xx_reg_mask_write(dev,
1653 VID_BLK_I2C_ADDRESS, 32,
1654 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1655 function_mode);
1656
1657 status = cx231xx_reg_mask_write(dev,
1658 VID_BLK_I2C_ADDRESS, 32,
1659 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xb);
1660
1661 status = cx231xx_reg_mask_write(dev,
1662 VID_BLK_I2C_ADDRESS, 32,
1663 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1664
1665 status = cx231xx_reg_mask_write(dev,
1666 VID_BLK_I2C_ADDRESS, 32,
1667 AUD_IO_CTRL, 0, 31, 0x00000003);
1668 } else if ((standard == V4L2_STD_PAL_I) |
1669 (standard & V4L2_STD_PAL_D) |
1670 (standard & V4L2_STD_SECAM)) {
1671
1672
1673 status = cx231xx_reg_mask_write(dev,
1674 VID_BLK_I2C_ADDRESS, 32,
1675 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1676
1677 status = cx231xx_reg_mask_write(dev,
1678 VID_BLK_I2C_ADDRESS, 32,
1679 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1680 function_mode);
1681
1682 status = cx231xx_reg_mask_write(dev,
1683 VID_BLK_I2C_ADDRESS, 32,
1684 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xF);
1685
1686 status = cx231xx_reg_mask_write(dev,
1687 VID_BLK_I2C_ADDRESS, 32,
1688 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1689 } else {
1690
1691
1692
1693 status = cx231xx_reg_mask_write(dev,
1694 VID_BLK_I2C_ADDRESS, 32,
1695 AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1);
1696
1697 status = cx231xx_reg_mask_write(dev,
1698 VID_BLK_I2C_ADDRESS, 32,
1699 AFE_CTRL_C2HH_SRC_CTRL, 23, 24,
1700 function_mode);
1701
1702 status = cx231xx_reg_mask_write(dev,
1703 VID_BLK_I2C_ADDRESS, 32,
1704 AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xE);
1705
1706 status = cx231xx_reg_mask_write(dev,
1707 VID_BLK_I2C_ADDRESS, 32,
1708 AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1);
1709 }
1710 }
1711
1712 return status;
1713}
1714
1715int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard)
1716{
1717 int status = 0;
1718 u32 dif_misc_ctrl_value = 0;
1719 u32 func_mode = 0;
1720
1721 cx231xx_info("%s: setStandard to %x\n", __func__, standard);
1722
1723 status = vid_blk_read_word(dev, DIF_MISC_CTRL, &dif_misc_ctrl_value);
1724 if (standard != DIF_USE_BASEBAND)
1725 dev->norm = standard;
1726
1727 switch (dev->model) {
1728 case CX231XX_BOARD_CNXT_CARRAERA:
1729 case CX231XX_BOARD_CNXT_RDE_250:
1730 case CX231XX_BOARD_CNXT_SHELBY:
1731 case CX231XX_BOARD_CNXT_RDU_250:
1732 case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
1733 case CX231XX_BOARD_HAUPPAUGE_EXETER:
1734 func_mode = 0x03;
1735 break;
1736 case CX231XX_BOARD_CNXT_RDE_253S:
1737 case CX231XX_BOARD_CNXT_RDU_253S:
1738 func_mode = 0x01;
1739 break;
1740 default:
1741 func_mode = 0x01;
1742 }
1743
1744 status = cx231xx_dif_configure_C2HH_for_low_IF(dev, dev->active_mode,
1745 func_mode, standard);
1746
1747 if (standard == DIF_USE_BASEBAND) {
1748
1749
1750 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC, 0xDF7DF83);
1751 status = vid_blk_read_word(dev, DIF_MISC_CTRL,
1752 &dif_misc_ctrl_value);
1753 dif_misc_ctrl_value |= FLD_DIF_DIF_BYPASS;
1754 status = vid_blk_write_word(dev, DIF_MISC_CTRL,
1755 dif_misc_ctrl_value);
1756 } else if (standard & V4L2_STD_PAL_D) {
1757 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1758 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1759 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1760 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1761 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1762 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1763 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1764 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1765 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1766 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
1767 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1768 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
1769 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1770 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
1771 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1772 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
1773 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1774 DIF_AGC_IF_INT_CURRENT, 0, 31,
1775 0x26001700);
1776 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1777 DIF_AGC_RF_CURRENT, 0, 31,
1778 0x00002660);
1779 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1780 DIF_VIDEO_AGC_CTRL, 0, 31,
1781 0x72500800);
1782 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1783 DIF_VID_AUD_OVERRIDE, 0, 31,
1784 0x27000100);
1785 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1786 DIF_AV_SEP_CTRL, 0, 31, 0x3F3934EA);
1787 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1788 DIF_COMP_FLT_CTRL, 0, 31,
1789 0x00000000);
1790 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1791 DIF_SRC_PHASE_INC, 0, 31,
1792 0x1befbf06);
1793 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1794 DIF_SRC_GAIN_CONTROL, 0, 31,
1795 0x000035e8);
1796 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1797 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1798
1799 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1800 dif_misc_ctrl_value |= 0x3a023F11;
1801 } else if (standard & V4L2_STD_PAL_I) {
1802 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1803 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1804 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1805 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1806 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1807 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1808 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1809 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1810 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1811 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
1812 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1813 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
1814 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1815 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
1816 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1817 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
1818 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1819 DIF_AGC_IF_INT_CURRENT, 0, 31,
1820 0x26001700);
1821 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1822 DIF_AGC_RF_CURRENT, 0, 31,
1823 0x00002660);
1824 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1825 DIF_VIDEO_AGC_CTRL, 0, 31,
1826 0x72500800);
1827 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1828 DIF_VID_AUD_OVERRIDE, 0, 31,
1829 0x27000100);
1830 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1831 DIF_AV_SEP_CTRL, 0, 31, 0x5F39A934);
1832 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1833 DIF_COMP_FLT_CTRL, 0, 31,
1834 0x00000000);
1835 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1836 DIF_SRC_PHASE_INC, 0, 31,
1837 0x1befbf06);
1838 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1839 DIF_SRC_GAIN_CONTROL, 0, 31,
1840 0x000035e8);
1841 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1842 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1843
1844 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1845 dif_misc_ctrl_value |= 0x3a033F11;
1846 } else if (standard & V4L2_STD_PAL_M) {
1847
1848 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0xFF01FF0C);
1849 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xbd038c85);
1850 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1db4640a);
1851 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
1852 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C1380);
1853 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
1854 0x26001700);
1855 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
1856 0x00002660);
1857 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
1858 0x72500800);
1859 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
1860 0x27000100);
1861 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, 0x012c405d);
1862 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
1863 0x009f50c1);
1864 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
1865 0x1befbf06);
1866 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
1867 0x000035e8);
1868 status = vid_blk_write_word(dev, DIF_SOFT_RST_CTRL_REVB,
1869 0x00000000);
1870
1871 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1872 dif_misc_ctrl_value |= 0x3A0A3F10;
1873 } else if (standard & (V4L2_STD_PAL_N | V4L2_STD_PAL_Nc)) {
1874
1875 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0xFF01FF0C);
1876 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xbd038c85);
1877 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1db4640a);
1878 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
1879 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C1380);
1880 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
1881 0x26001700);
1882 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
1883 0x00002660);
1884 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
1885 0x72500800);
1886 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
1887 0x27000100);
1888 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL,
1889 0x012c405d);
1890 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
1891 0x009f50c1);
1892 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
1893 0x1befbf06);
1894 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
1895 0x000035e8);
1896 status = vid_blk_write_word(dev, DIF_SOFT_RST_CTRL_REVB,
1897 0x00000000);
1898
1899 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1900 dif_misc_ctrl_value = 0x3A093F10;
1901 } else if (standard &
1902 (V4L2_STD_SECAM_B | V4L2_STD_SECAM_D | V4L2_STD_SECAM_G |
1903 V4L2_STD_SECAM_K | V4L2_STD_SECAM_K1)) {
1904
1905 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1906 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1907 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1908 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1909 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1910 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1911 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1912 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1913 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1914 DIF_AGC_IF_REF, 0, 31, 0x888C0380);
1915 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1916 DIF_AGC_CTRL_IF, 0, 31, 0xe0262600);
1917 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1918 DIF_AGC_CTRL_INT, 0, 31, 0xc2171700);
1919 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1920 DIF_AGC_CTRL_RF, 0, 31, 0xc2262600);
1921 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1922 DIF_AGC_IF_INT_CURRENT, 0, 31,
1923 0x26001700);
1924 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1925 DIF_AGC_RF_CURRENT, 0, 31,
1926 0x00002660);
1927 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1928 DIF_VID_AUD_OVERRIDE, 0, 31,
1929 0x27000100);
1930 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1931 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec);
1932 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1933 DIF_COMP_FLT_CTRL, 0, 31,
1934 0x00000000);
1935 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1936 DIF_SRC_PHASE_INC, 0, 31,
1937 0x1befbf06);
1938 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1939 DIF_SRC_GAIN_CONTROL, 0, 31,
1940 0x000035e8);
1941 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1942 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1943 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1944 DIF_VIDEO_AGC_CTRL, 0, 31,
1945 0xf4000000);
1946
1947
1948 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1949 dif_misc_ctrl_value |= 0x3a023F11;
1950 } else if (standard & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) {
1951
1952 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1953 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
1954 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1955 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
1956 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1957 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
1958 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1959 DIF_PLL_CTRL3, 0, 31, 0x00008800);
1960 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1961 DIF_AGC_IF_REF, 0, 31, 0x888C0380);
1962 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1963 DIF_AGC_CTRL_IF, 0, 31, 0xe0262600);
1964 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1965 DIF_AGC_CTRL_INT, 0, 31, 0xc2171700);
1966 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1967 DIF_AGC_CTRL_RF, 0, 31, 0xc2262600);
1968 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1969 DIF_AGC_IF_INT_CURRENT, 0, 31,
1970 0x26001700);
1971 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1972 DIF_AGC_RF_CURRENT, 0, 31,
1973 0x00002660);
1974 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1975 DIF_VID_AUD_OVERRIDE, 0, 31,
1976 0x27000100);
1977 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1978 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec);
1979 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1980 DIF_COMP_FLT_CTRL, 0, 31,
1981 0x00000000);
1982 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1983 DIF_SRC_PHASE_INC, 0, 31,
1984 0x1befbf06);
1985 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1986 DIF_SRC_GAIN_CONTROL, 0, 31,
1987 0x000035e8);
1988 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1989 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
1990 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
1991 DIF_VIDEO_AGC_CTRL, 0, 31,
1992 0xf2560000);
1993
1994
1995 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
1996 dif_misc_ctrl_value |= 0x3a023F11;
1997
1998 } else if (standard & V4L2_STD_NTSC_M) {
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008 status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0x6503BC0C);
2009 status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xBD038C85);
2010 status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1DB4640A);
2011 status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800);
2012 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C0380);
2013 status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT,
2014 0x26001700);
2015 status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT,
2016 0x00002660);
2017 status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL,
2018 0x04000800);
2019 status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE,
2020 0x27000100);
2021 status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, 0x01296e1f);
2022
2023 status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL,
2024 0x009f50c1);
2025 status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC,
2026 0x1befbf06);
2027 status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL,
2028 0x000035e8);
2029
2030 status = vid_blk_write_word(dev, DIF_AGC_CTRL_IF, 0xC2262600);
2031 status = vid_blk_write_word(dev, DIF_AGC_CTRL_INT,
2032 0xC2262600);
2033 status = vid_blk_write_word(dev, DIF_AGC_CTRL_RF, 0xC2262600);
2034
2035
2036 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
2037 dif_misc_ctrl_value |= 0x3a003F10;
2038 } else {
2039
2040 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2041 DIF_PLL_CTRL, 0, 31, 0x6503bc0c);
2042 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2043 DIF_PLL_CTRL1, 0, 31, 0xbd038c85);
2044 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2045 DIF_PLL_CTRL2, 0, 31, 0x1db4640a);
2046 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2047 DIF_PLL_CTRL3, 0, 31, 0x00008800);
2048 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2049 DIF_AGC_IF_REF, 0, 31, 0x444C1380);
2050 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2051 DIF_AGC_CTRL_IF, 0, 31, 0xDA302600);
2052 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2053 DIF_AGC_CTRL_INT, 0, 31, 0xDA261700);
2054 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2055 DIF_AGC_CTRL_RF, 0, 31, 0xDA262600);
2056 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2057 DIF_AGC_IF_INT_CURRENT, 0, 31,
2058 0x26001700);
2059 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2060 DIF_AGC_RF_CURRENT, 0, 31,
2061 0x00002660);
2062 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2063 DIF_VIDEO_AGC_CTRL, 0, 31,
2064 0x72500800);
2065 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2066 DIF_VID_AUD_OVERRIDE, 0, 31,
2067 0x27000100);
2068 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2069 DIF_AV_SEP_CTRL, 0, 31, 0x3F3530EC);
2070 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2071 DIF_COMP_FLT_CTRL, 0, 31,
2072 0x00A653A8);
2073 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2074 DIF_SRC_PHASE_INC, 0, 31,
2075 0x1befbf06);
2076 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2077 DIF_SRC_GAIN_CONTROL, 0, 31,
2078 0x000035e8);
2079 status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32,
2080 DIF_RPT_VARIANCE, 0, 31, 0x00000000);
2081
2082 dif_misc_ctrl_value &= FLD_DIF_SPEC_INV;
2083 dif_misc_ctrl_value |= 0x3a013F11;
2084 }
2085
2086
2087
2088 dif_misc_ctrl_value &= ~FLD_DIF_AUD_SRC_SEL;
2089
2090
2091
2092
2093 if (dev->active_mode == V4L2_TUNER_RADIO)
2094 dif_misc_ctrl_value = 0x7a080000;
2095
2096
2097 status = vid_blk_write_word(dev, DIF_MISC_CTRL, dif_misc_ctrl_value);
2098
2099 return status;
2100}
2101
2102int cx231xx_tuner_pre_channel_change(struct cx231xx *dev)
2103{
2104 int status = 0;
2105 u32 dwval;
2106
2107
2108 status = vid_blk_read_word(dev, DIF_AGC_IF_REF, &dwval);
2109 dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF);
2110 dwval |= 0x33000000;
2111
2112 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval);
2113
2114 return status;
2115}
2116
2117int cx231xx_tuner_post_channel_change(struct cx231xx *dev)
2118{
2119 int status = 0;
2120 u32 dwval;
2121 cx231xx_info("cx231xx_tuner_post_channel_change dev->tuner_type =0%d\n",
2122 dev->tuner_type);
2123
2124
2125 status = vid_blk_read_word(dev, DIF_AGC_IF_REF, &dwval);
2126 dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF);
2127
2128 if (dev->norm & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_B |
2129 V4L2_STD_SECAM_D)) {
2130 if (dev->tuner_type == TUNER_NXP_TDA18271) {
2131 dwval &= ~FLD_DIF_IF_REF;
2132 dwval |= 0x88000300;
2133 } else
2134 dwval |= 0x88000000;
2135 } else {
2136 if (dev->tuner_type == TUNER_NXP_TDA18271) {
2137 dwval &= ~FLD_DIF_IF_REF;
2138 dwval |= 0xCC000300;
2139 } else
2140 dwval |= 0x44000000;
2141 }
2142
2143 status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval);
2144
2145 return status;
2146}
2147
2148
2149
2150
2151int cx231xx_i2s_blk_initialize(struct cx231xx *dev)
2152{
2153 int status = 0;
2154 u32 value;
2155
2156 status = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2157 CH_PWR_CTRL1, 1, &value, 1);
2158
2159 value |= 0x80;
2160 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2161 CH_PWR_CTRL1, 1, value, 1);
2162
2163 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2164 CH_PWR_CTRL2, 1, 0x00, 1);
2165
2166 return status;
2167}
2168
2169int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev,
2170 enum AV_MODE avmode)
2171{
2172 int status = 0;
2173 u32 value = 0;
2174
2175 if (avmode != POLARIS_AVMODE_ENXTERNAL_AV) {
2176 status = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2177 CH_PWR_CTRL2, 1, &value, 1);
2178 value |= 0xfe;
2179 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2180 CH_PWR_CTRL2, 1, value, 1);
2181 } else {
2182 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2183 CH_PWR_CTRL2, 1, 0x00, 1);
2184 }
2185
2186 return status;
2187}
2188
2189
2190int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input)
2191{
2192 int status = 0;
2193
2194 switch (audio_input) {
2195 case CX231XX_AMUX_LINE_IN:
2196 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2197 CH_PWR_CTRL2, 1, 0x00, 1);
2198 status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
2199 CH_PWR_CTRL1, 1, 0x80, 1);
2200 break;
2201 case CX231XX_AMUX_VIDEO:
2202 default:
2203 break;
2204 }
2205
2206 dev->ctl_ainput = audio_input;
2207
2208 return status;
2209}
2210
2211
2212
2213
2214int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode)
2215{
2216 u8 value[4] = { 0, 0, 0, 0 };
2217 u32 tmp = 0;
2218 int status = 0;
2219
2220 if (dev->power_mode != mode)
2221 dev->power_mode = mode;
2222 else {
2223 cx231xx_info(" setPowerMode::mode = %d, No Change req.\n",
2224 mode);
2225 return 0;
2226 }
2227
2228 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value,
2229 4);
2230 if (status < 0)
2231 return status;
2232
2233 tmp = *((u32 *) value);
2234
2235 switch (mode) {
2236 case POLARIS_AVMODE_ENXTERNAL_AV:
2237
2238 tmp &= (~PWR_MODE_MASK);
2239
2240 tmp |= PWR_AV_EN;
2241 value[0] = (u8) tmp;
2242 value[1] = (u8) (tmp >> 8);
2243 value[2] = (u8) (tmp >> 16);
2244 value[3] = (u8) (tmp >> 24);
2245 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2246 PWR_CTL_EN, value, 4);
2247 msleep(PWR_SLEEP_INTERVAL);
2248
2249 tmp |= PWR_ISO_EN;
2250 value[0] = (u8) tmp;
2251 value[1] = (u8) (tmp >> 8);
2252 value[2] = (u8) (tmp >> 16);
2253 value[3] = (u8) (tmp >> 24);
2254 status =
2255 cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, PWR_CTL_EN,
2256 value, 4);
2257 msleep(PWR_SLEEP_INTERVAL);
2258
2259 tmp |= POLARIS_AVMODE_ENXTERNAL_AV;
2260 value[0] = (u8) tmp;
2261 value[1] = (u8) (tmp >> 8);
2262 value[2] = (u8) (tmp >> 16);
2263 value[3] = (u8) (tmp >> 24);
2264 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2265 PWR_CTL_EN, value, 4);
2266
2267
2268 dev->xc_fw_load_done = 0;
2269 break;
2270
2271 case POLARIS_AVMODE_ANALOGT_TV:
2272
2273 tmp |= PWR_DEMOD_EN;
2274 tmp |= (I2C_DEMOD_EN);
2275 value[0] = (u8) tmp;
2276 value[1] = (u8) (tmp >> 8);
2277 value[2] = (u8) (tmp >> 16);
2278 value[3] = (u8) (tmp >> 24);
2279 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2280 PWR_CTL_EN, value, 4);
2281 msleep(PWR_SLEEP_INTERVAL);
2282
2283 if (!(tmp & PWR_TUNER_EN)) {
2284 tmp |= (PWR_TUNER_EN);
2285 value[0] = (u8) tmp;
2286 value[1] = (u8) (tmp >> 8);
2287 value[2] = (u8) (tmp >> 16);
2288 value[3] = (u8) (tmp >> 24);
2289 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2290 PWR_CTL_EN, value, 4);
2291 msleep(PWR_SLEEP_INTERVAL);
2292 }
2293
2294 if (!(tmp & PWR_AV_EN)) {
2295 tmp |= PWR_AV_EN;
2296 value[0] = (u8) tmp;
2297 value[1] = (u8) (tmp >> 8);
2298 value[2] = (u8) (tmp >> 16);
2299 value[3] = (u8) (tmp >> 24);
2300 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2301 PWR_CTL_EN, value, 4);
2302 msleep(PWR_SLEEP_INTERVAL);
2303 }
2304 if (!(tmp & PWR_ISO_EN)) {
2305 tmp |= PWR_ISO_EN;
2306 value[0] = (u8) tmp;
2307 value[1] = (u8) (tmp >> 8);
2308 value[2] = (u8) (tmp >> 16);
2309 value[3] = (u8) (tmp >> 24);
2310 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2311 PWR_CTL_EN, value, 4);
2312 msleep(PWR_SLEEP_INTERVAL);
2313 }
2314
2315 if (!(tmp & POLARIS_AVMODE_ANALOGT_TV)) {
2316 tmp |= POLARIS_AVMODE_ANALOGT_TV;
2317 value[0] = (u8) tmp;
2318 value[1] = (u8) (tmp >> 8);
2319 value[2] = (u8) (tmp >> 16);
2320 value[3] = (u8) (tmp >> 24);
2321 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2322 PWR_CTL_EN, value, 4);
2323 msleep(PWR_SLEEP_INTERVAL);
2324 }
2325
2326 if (dev->board.tuner_type != TUNER_ABSENT) {
2327
2328 cx231xx_enable_i2c_port_3(dev, true);
2329
2330
2331 if (dev->board.tuner_gpio)
2332 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
2333
2334 if (dev->cx231xx_reset_analog_tuner)
2335 dev->cx231xx_reset_analog_tuner(dev);
2336 }
2337
2338 break;
2339
2340 case POLARIS_AVMODE_DIGITAL:
2341 if (!(tmp & PWR_TUNER_EN)) {
2342 tmp |= (PWR_TUNER_EN);
2343 value[0] = (u8) tmp;
2344 value[1] = (u8) (tmp >> 8);
2345 value[2] = (u8) (tmp >> 16);
2346 value[3] = (u8) (tmp >> 24);
2347 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2348 PWR_CTL_EN, value, 4);
2349 msleep(PWR_SLEEP_INTERVAL);
2350 }
2351 if (!(tmp & PWR_AV_EN)) {
2352 tmp |= PWR_AV_EN;
2353 value[0] = (u8) tmp;
2354 value[1] = (u8) (tmp >> 8);
2355 value[2] = (u8) (tmp >> 16);
2356 value[3] = (u8) (tmp >> 24);
2357 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2358 PWR_CTL_EN, value, 4);
2359 msleep(PWR_SLEEP_INTERVAL);
2360 }
2361 if (!(tmp & PWR_ISO_EN)) {
2362 tmp |= PWR_ISO_EN;
2363 value[0] = (u8) tmp;
2364 value[1] = (u8) (tmp >> 8);
2365 value[2] = (u8) (tmp >> 16);
2366 value[3] = (u8) (tmp >> 24);
2367 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2368 PWR_CTL_EN, value, 4);
2369 msleep(PWR_SLEEP_INTERVAL);
2370 }
2371
2372 tmp &= (~PWR_AV_MODE);
2373 tmp |= POLARIS_AVMODE_DIGITAL | I2C_DEMOD_EN;
2374 value[0] = (u8) tmp;
2375 value[1] = (u8) (tmp >> 8);
2376 value[2] = (u8) (tmp >> 16);
2377 value[3] = (u8) (tmp >> 24);
2378 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2379 PWR_CTL_EN, value, 4);
2380 msleep(PWR_SLEEP_INTERVAL);
2381
2382 if (!(tmp & PWR_DEMOD_EN)) {
2383 tmp |= PWR_DEMOD_EN;
2384 value[0] = (u8) tmp;
2385 value[1] = (u8) (tmp >> 8);
2386 value[2] = (u8) (tmp >> 16);
2387 value[3] = (u8) (tmp >> 24);
2388 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2389 PWR_CTL_EN, value, 4);
2390 msleep(PWR_SLEEP_INTERVAL);
2391 }
2392
2393 if (dev->board.tuner_type != TUNER_ABSENT) {
2394
2395
2396
2397
2398 if (dev->model == CX231XX_BOARD_HAUPPAUGE_EXETER)
2399 cx231xx_enable_i2c_port_3(dev, false);
2400 else
2401 cx231xx_enable_i2c_port_3(dev, true);
2402
2403
2404 if (dev->board.tuner_gpio)
2405 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
2406
2407 if (dev->cx231xx_reset_analog_tuner)
2408 dev->cx231xx_reset_analog_tuner(dev);
2409 }
2410 break;
2411
2412 default:
2413 break;
2414 }
2415
2416 msleep(PWR_SLEEP_INTERVAL);
2417
2418
2419
2420 if (mode == POLARIS_AVMODE_DIGITAL) {
2421 tmp |= PWR_RESETOUT_EN;
2422 value[0] = (u8) tmp;
2423 value[1] = (u8) (tmp >> 8);
2424 value[2] = (u8) (tmp >> 16);
2425 value[3] = (u8) (tmp >> 24);
2426 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2427 PWR_CTL_EN, value, 4);
2428 msleep(PWR_SLEEP_INTERVAL);
2429 }
2430
2431
2432 status = cx231xx_afe_update_power_control(dev, mode);
2433
2434
2435 status = cx231xx_i2s_blk_update_power_control(dev, mode);
2436
2437 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value,
2438 4);
2439
2440 return status;
2441}
2442
2443int cx231xx_power_suspend(struct cx231xx *dev)
2444{
2445 u8 value[4] = { 0, 0, 0, 0 };
2446 u32 tmp = 0;
2447 int status = 0;
2448
2449 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN,
2450 value, 4);
2451 if (status > 0)
2452 return status;
2453
2454 tmp = *((u32 *) value);
2455 tmp &= (~PWR_MODE_MASK);
2456
2457 value[0] = (u8) tmp;
2458 value[1] = (u8) (tmp >> 8);
2459 value[2] = (u8) (tmp >> 16);
2460 value[3] = (u8) (tmp >> 24);
2461 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, PWR_CTL_EN,
2462 value, 4);
2463
2464 return status;
2465}
2466
2467
2468
2469
2470int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask)
2471{
2472 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
2473 u32 tmp = 0;
2474 int status = 0;
2475
2476 cx231xx_info("cx231xx_start_stream():: ep_mask = %x\n", ep_mask);
2477 status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET,
2478 value, 4);
2479 if (status < 0)
2480 return status;
2481
2482 tmp = *((u32 *) value);
2483 tmp |= ep_mask;
2484 value[0] = (u8) tmp;
2485 value[1] = (u8) (tmp >> 8);
2486 value[2] = (u8) (tmp >> 16);
2487 value[3] = (u8) (tmp >> 24);
2488
2489 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, EP_MODE_SET,
2490 value, 4);
2491
2492 return status;
2493}
2494
2495int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask)
2496{
2497 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
2498 u32 tmp = 0;
2499 int status = 0;
2500
2501 cx231xx_info("cx231xx_stop_stream():: ep_mask = %x\n", ep_mask);
2502 status =
2503 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET, value, 4);
2504 if (status < 0)
2505 return status;
2506
2507 tmp = *((u32 *) value);
2508 tmp &= (~ep_mask);
2509 value[0] = (u8) tmp;
2510 value[1] = (u8) (tmp >> 8);
2511 value[2] = (u8) (tmp >> 16);
2512 value[3] = (u8) (tmp >> 24);
2513
2514 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, EP_MODE_SET,
2515 value, 4);
2516
2517 return status;
2518}
2519
2520int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type)
2521{
2522 int status = 0;
2523 u32 value = 0;
2524 u8 val[4] = { 0, 0, 0, 0 };
2525
2526 if (dev->udev->speed == USB_SPEED_HIGH) {
2527 switch (media_type) {
2528 case 81:
2529 cx231xx_info("%s: Audio enter HANC\n", __func__);
2530 status =
2531 cx231xx_mode_register(dev, TS_MODE_REG, 0x9300);
2532 break;
2533
2534 case 2:
2535 cx231xx_info("%s: set vanc registers\n", __func__);
2536 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x300);
2537 break;
2538
2539 case 3:
2540 cx231xx_info("%s: set hanc registers\n", __func__);
2541 status =
2542 cx231xx_mode_register(dev, TS_MODE_REG, 0x1300);
2543 break;
2544
2545 case 0:
2546 cx231xx_info("%s: set video registers\n", __func__);
2547 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x100);
2548 break;
2549
2550 case 4:
2551 cx231xx_info("%s: set ts1 registers", __func__);
2552
2553 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
2554 cx231xx_info(" MPEG\n");
2555 value &= 0xFFFFFFFC;
2556 value |= 0x3;
2557
2558 status = cx231xx_mode_register(dev, TS_MODE_REG, value);
2559
2560 val[0] = 0x04;
2561 val[1] = 0xA3;
2562 val[2] = 0x3B;
2563 val[3] = 0x00;
2564 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2565 TS1_CFG_REG, val, 4);
2566
2567 val[0] = 0x00;
2568 val[1] = 0x08;
2569 val[2] = 0x00;
2570 val[3] = 0x08;
2571 status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
2572 TS1_LENGTH_REG, val, 4);
2573
2574 } else {
2575 cx231xx_info(" BDA\n");
2576 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x101);
2577 status = cx231xx_mode_register(dev, TS1_CFG_REG, 0x010);
2578 }
2579 break;
2580
2581 case 6:
2582 cx231xx_info("%s: set ts1 parrallel mode registers\n",
2583 __func__);
2584 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x100);
2585 status = cx231xx_mode_register(dev, TS1_CFG_REG, 0x400);
2586 break;
2587 }
2588 } else {
2589 status = cx231xx_mode_register(dev, TS_MODE_REG, 0x101);
2590 }
2591
2592 return status;
2593}
2594
2595int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type)
2596{
2597 int rc = -1;
2598 u32 ep_mask = -1;
2599 struct pcb_config *pcb_config;
2600
2601
2602 pcb_config = (struct pcb_config *)&dev->current_pcb_config;
2603
2604 if (pcb_config->config_num == 1) {
2605 switch (media_type) {
2606 case 0:
2607 ep_mask = ENABLE_EP4;
2608 break;
2609 case 1:
2610 ep_mask = ENABLE_EP3;
2611 break;
2612 case 2:
2613 ep_mask = ENABLE_EP5;
2614 break;
2615 case 3:
2616 ep_mask = ENABLE_EP6;
2617 break;
2618 case 4:
2619 case 6:
2620 ep_mask = ENABLE_EP1;
2621 break;
2622 case 5:
2623 ep_mask = ENABLE_EP2;
2624 break;
2625 }
2626
2627 } else if (pcb_config->config_num > 1) {
2628 switch (media_type) {
2629 case 0:
2630 ep_mask = ENABLE_EP4;
2631 break;
2632 case 1:
2633 ep_mask = ENABLE_EP3;
2634 break;
2635 case 2:
2636 ep_mask = ENABLE_EP5;
2637 break;
2638 case 3:
2639 ep_mask = ENABLE_EP6;
2640 break;
2641 case 4:
2642 case 6:
2643 ep_mask = ENABLE_EP1;
2644 break;
2645 case 5:
2646 ep_mask = ENABLE_EP2;
2647 break;
2648 }
2649
2650 }
2651
2652 if (start) {
2653 rc = cx231xx_initialize_stream_xfer(dev, media_type);
2654
2655 if (rc < 0)
2656 return rc;
2657
2658
2659 if (ep_mask > 0)
2660 rc = cx231xx_start_stream(dev, ep_mask);
2661 } else {
2662
2663 if (ep_mask > 0)
2664 rc = cx231xx_stop_stream(dev, ep_mask);
2665 }
2666
2667 if (dev->mode == CX231XX_ANALOG_MODE)
2668 ;
2669 else
2670 ;
2671
2672 return rc;
2673}
2674EXPORT_SYMBOL_GPL(cx231xx_capture_start);
2675
2676
2677
2678
2679int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val)
2680{
2681 int status = 0;
2682
2683 status = cx231xx_send_gpio_cmd(dev, gpio_bit, gpio_val, 4, 0, 0);
2684
2685 return status;
2686}
2687
2688int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val)
2689{
2690 int status = 0;
2691
2692 status = cx231xx_send_gpio_cmd(dev, gpio_bit, gpio_val, 4, 0, 1);
2693
2694 return status;
2695}
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708int cx231xx_set_gpio_direction(struct cx231xx *dev,
2709 int pin_number, int pin_value)
2710{
2711 int status = 0;
2712 u32 value = 0;
2713
2714
2715 if (pin_number >= 32)
2716 return -EINVAL;
2717
2718
2719 if (pin_value == 0)
2720 value = dev->gpio_dir & (~(1 << pin_number));
2721 else
2722 value = dev->gpio_dir | (1 << pin_number);
2723
2724 status = cx231xx_set_gpio_bit(dev, value, (u8 *) &dev->gpio_val);
2725
2726
2727 dev->gpio_dir = value;
2728
2729 return status;
2730}
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value)
2744{
2745 int status = 0;
2746 u32 value = 0;
2747
2748
2749 if (pin_number >= 32)
2750 return -EINVAL;
2751
2752
2753 if ((dev->gpio_dir & (1 << pin_number)) == 0x00) {
2754
2755 value = dev->gpio_dir | (1 << pin_number);
2756 dev->gpio_dir = value;
2757 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2758 (u8 *) &dev->gpio_val);
2759 value = 0;
2760 }
2761
2762 if (pin_value == 0)
2763 value = dev->gpio_val & (~(1 << pin_number));
2764 else
2765 value = dev->gpio_val | (1 << pin_number);
2766
2767
2768 dev->gpio_val = value;
2769
2770
2771 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2772
2773 return status;
2774}
2775
2776
2777
2778
2779int cx231xx_gpio_i2c_start(struct cx231xx *dev)
2780{
2781 int status = 0;
2782
2783
2784 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2785 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2786 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2787 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio;
2788
2789 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2790 if (status < 0)
2791 return -EINVAL;
2792
2793
2794 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2795 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2796
2797 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2798 if (status < 0)
2799 return -EINVAL;
2800
2801
2802 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2803 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2804
2805 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2806 if (status < 0)
2807 return -EINVAL;
2808
2809 return status;
2810}
2811
2812int cx231xx_gpio_i2c_end(struct cx231xx *dev)
2813{
2814 int status = 0;
2815
2816
2817 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2818 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2819
2820 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2821 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2822
2823 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2824 if (status < 0)
2825 return -EINVAL;
2826
2827
2828 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2829 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2830
2831 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2832 if (status < 0)
2833 return -EINVAL;
2834
2835
2836
2837 dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio);
2838 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2839
2840 status =
2841 cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2842 if (status < 0)
2843 return -EINVAL;
2844
2845 return status;
2846}
2847
2848int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data)
2849{
2850 int status = 0;
2851 u8 i;
2852
2853
2854 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
2855 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2856
2857 for (i = 0; i < 8; i++) {
2858 if (((data << i) & 0x80) == 0) {
2859
2860 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2861 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2862 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2863 (u8 *)&dev->gpio_val);
2864
2865
2866 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2867 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2868 (u8 *)&dev->gpio_val);
2869
2870
2871 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2872 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2873 (u8 *)&dev->gpio_val);
2874 } else {
2875
2876 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2877 dev->gpio_val |= 1 << dev->board.tuner_sda_gpio;
2878 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2879 (u8 *)&dev->gpio_val);
2880
2881
2882 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2883 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2884 (u8 *)&dev->gpio_val);
2885
2886
2887 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2888 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2889 (u8 *)&dev->gpio_val);
2890 }
2891 }
2892 return status;
2893}
2894
2895int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf)
2896{
2897 u8 value = 0;
2898 int status = 0;
2899 u32 gpio_logic_value = 0;
2900 u8 i;
2901
2902
2903 for (i = 0; i < 8; i++) {
2904
2905
2906 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2907 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2908 (u8 *)&dev->gpio_val);
2909
2910
2911 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
2912 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir,
2913 (u8 *)&dev->gpio_val);
2914
2915
2916 gpio_logic_value = dev->gpio_val;
2917 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir,
2918 (u8 *)&dev->gpio_val);
2919 if ((dev->gpio_val & (1 << dev->board.tuner_sda_gpio)) != 0)
2920 value |= (1 << (8 - i - 1));
2921
2922 dev->gpio_val = gpio_logic_value;
2923 }
2924
2925
2926
2927
2928 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2929 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2930
2931
2932 *buf = value & 0xff;
2933
2934 return status;
2935}
2936
2937int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev)
2938{
2939 int status = 0;
2940 u32 gpio_logic_value = 0;
2941 int nCnt = 10;
2942 int nInit = nCnt;
2943
2944
2945
2946 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
2947 dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio);
2948
2949 gpio_logic_value = dev->gpio_val;
2950 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2951
2952 do {
2953 msleep(2);
2954 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir,
2955 (u8 *)&dev->gpio_val);
2956 nCnt--;
2957 } while (((dev->gpio_val &
2958 (1 << dev->board.tuner_scl_gpio)) == 0) &&
2959 (nCnt > 0));
2960
2961 if (nCnt == 0)
2962 cx231xx_info("No ACK after %d msec -GPIO I2C failed!",
2963 nInit * 10);
2964
2965
2966
2967
2968
2969
2970 status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2971
2972 if ((dev->gpio_val & 1 << dev->board.tuner_sda_gpio) == 0) {
2973 dev->gpio_val = gpio_logic_value;
2974 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
2975 status = 0;
2976 } else {
2977 dev->gpio_val = gpio_logic_value;
2978 dev->gpio_val |= (1 << dev->board.tuner_sda_gpio);
2979 }
2980
2981
2982
2983 dev->gpio_val = gpio_logic_value;
2984 dev->gpio_dir |= (1 << dev->board.tuner_scl_gpio);
2985 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
2986 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2987
2988 return status;
2989}
2990
2991int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev)
2992{
2993 int status = 0;
2994
2995
2996 dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio;
2997 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
2998
2999
3000 dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio);
3001 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
3002 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
3003
3004
3005 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
3006 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
3007
3008
3009 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
3010 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
3011
3012
3013 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
3014 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
3015
3016 return status;
3017}
3018
3019int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev)
3020{
3021 int status = 0;
3022
3023
3024 dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio;
3025 dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio);
3026 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
3027
3028
3029 dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio);
3030 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
3031
3032
3033 dev->gpio_val |= 1 << dev->board.tuner_scl_gpio;
3034 status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val);
3035
3036 return status;
3037}
3038
3039
3040
3041
3042
3043
3044
3045int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len)
3046{
3047 int status = 0;
3048 int i = 0;
3049
3050
3051 mutex_lock(&dev->gpio_i2c_lock);
3052
3053
3054 status = cx231xx_gpio_i2c_start(dev);
3055
3056
3057 status = cx231xx_gpio_i2c_write_byte(dev, (dev_addr << 1) + 1);
3058
3059
3060 status = cx231xx_gpio_i2c_read_ack(dev);
3061
3062
3063 for (i = 0; i < len; i++) {
3064
3065 buf[i] = 0;
3066 status = cx231xx_gpio_i2c_read_byte(dev, &buf[i]);
3067
3068 if ((i + 1) != len) {
3069
3070 status = cx231xx_gpio_i2c_write_ack(dev);
3071 }
3072 }
3073
3074
3075 status = cx231xx_gpio_i2c_write_nak(dev);
3076
3077
3078 status = cx231xx_gpio_i2c_end(dev);
3079
3080
3081 mutex_unlock(&dev->gpio_i2c_lock);
3082
3083 return status;
3084}
3085
3086
3087
3088
3089int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len)
3090{
3091 int status = 0;
3092 int i = 0;
3093
3094
3095 mutex_lock(&dev->gpio_i2c_lock);
3096
3097
3098 status = cx231xx_gpio_i2c_start(dev);
3099
3100
3101 status = cx231xx_gpio_i2c_write_byte(dev, dev_addr << 1);
3102
3103
3104 status = cx231xx_gpio_i2c_read_ack(dev);
3105
3106 for (i = 0; i < len; i++) {
3107
3108 status = cx231xx_gpio_i2c_write_byte(dev, buf[i]);
3109
3110
3111 status = cx231xx_gpio_i2c_read_ack(dev);
3112 }
3113
3114
3115 status = cx231xx_gpio_i2c_end(dev);
3116
3117
3118 mutex_unlock(&dev->gpio_i2c_lock);
3119
3120 return 0;
3121}
3122