26 #include <linux/list.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/bitmap.h>
31 #include <linux/i2c.h>
43 #define TUNER_MODE_FM_RADIO 0
78 u32 _gpio_direction = 0;
82 _gpio_direction = _gpio_direction & 0xFC0003FF;
83 _gpio_direction = _gpio_direction | 0x03FDFC00;
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);
103 verve_write_byte(dev, 0x07, 0x14);
133 u8 afe_power_status = 0;
137 temp = (
u8) (ref_count & 0xff);
142 status = afe_read_byte(dev,
SUP_BLK_TUNE2, &afe_power_status);
146 temp = (
u8) ((ref_count & 0x300) >> 8);
157 while (afe_power_status != 0x18) {
161 ": Init Super Block failed in send cmd\n");
165 status = afe_read_byte(dev,
SUP_BLK_PWRDN, &afe_power_status);
166 afe_power_status &= 0xff;
169 ": Init Super Block failed in receive cmd\n");
175 ": Init Super Block force break in loop !!!!\n");
252 c_value &= (~(0x50));
269 u8 ch1_setting = (
u8) input_mux;
270 u8 ch2_setting = (
u8) (input_mux >> 8);
271 u8 ch3_setting = (
u8) (input_mux >> 16);
275 if (ch1_setting != 0) {
278 value |= (ch1_setting - 1) << 4;
283 if (ch2_setting != 0) {
286 value |= (ch2_setting - 1) << 4;
293 if (ch3_setting != 0) {
296 value |= (ch3_setting - 1) << 4;
344 u8 afe_power_status = 0;
347 switch (dev->
model) {
495 input_mode = (ntf_mode & 0x3) | ((input_mode & 0x6) << 1);
497 switch (input_mode) {
576 " set Power - errCode [%d]!\n",
594 " to set Power - errCode [%d]!\n",
631 "AFE input mux - errCode [%d]!\n",
641 " AFE input mux - errCode [%d]!\n",
648 status = vid_blk_read_word(dev,
AFE_CTRL, &value);
649 value |= (0 << 13) | (1 << 4);
653 value &= (~(0x1ff8000));
656 status = vid_blk_write_word(dev,
AFE_CTRL, value);
658 status = vid_blk_read_word(dev,
OUT_CTRL1, &value);
660 status = vid_blk_write_word(dev,
OUT_CTRL1, value);
667 dev->
board.output_mode);
673 " mode- errCode [%d]!\n",
679 status = vid_blk_read_word(dev,
DFE_CTRL1, &value);
688 status = vid_blk_write_word(dev,
DFE_CTRL1, value);
705 status = vid_blk_read_word(dev,
AFE_CTRL, &value);
708 value &= (~(0x1ff8000));
712 status = vid_blk_write_word(dev,
AFE_CTRL, value);
718 " mode- errCode [%d]!\n",
724 status = vid_blk_read_word(dev,
DFE_CTRL1, &value);
733 status = vid_blk_write_word(dev,
DFE_CTRL1, value);
749 status = vid_blk_read_word(dev,
AFE_CTRL, &value);
757 status = vid_blk_write_word(dev,
AFE_CTRL, value);
765 if (dev->
board.tuner_type == TUNER_XC5000) {
768 status = vid_blk_read_word(dev,
AFE_CTRL, &value);
769 value |= (0 << 13) | (1 << 4);
773 value &= (~(0x1FF8000));
776 status = vid_blk_write_word(dev,
AFE_CTRL, value);
778 status = vid_blk_read_word(dev,
OUT_CTRL1, &value);
780 status = vid_blk_write_word(dev,
OUT_CTRL1, value);
786 dev->
board.output_mode);
793 " mode- errCode [%d]!\n",
799 status = vid_blk_read_word(dev,
DFE_CTRL1, &value);
808 status = vid_blk_write_word(dev,
DFE_CTRL1, value);
829 " mode- errCode [%d]!\n",
844 status = vid_blk_read_word(dev,
DFE_CTRL1, &value);
854 status = vid_blk_write_word(dev,
DFE_CTRL1, value);
863 status = vid_blk_write_word(dev,
DFE_CTRL1, value);
866 status = vid_blk_read_word(dev,
PIN_CTRL, &value);
870 status = vid_blk_write_word(dev,
PIN_CTRL, value);
876 dev->
board.output_mode);
896 status = vid_blk_read_word(dev,
AFE_CTRL, &value);
904 status = vid_blk_write_word(dev,
AFE_CTRL, value);
907 status = vid_blk_read_word(dev,
PIN_CTRL,
909 status = vid_blk_write_word(dev,
PIN_CTRL,
910 (value & 0xFFFFFFEF));
925 status = vid_blk_read_word(dev,
OUT_CTRL1, &value);
928 status = vid_blk_write_word(dev,
OUT_CTRL1, value);
973 (
unsigned int)dev->
norm);
976 status = vid_blk_write_word(dev,
DFE_CTRL3, 0xCD3F0280);
1086 switch (
INPUT(input)->amux) {
1112 status = vid_blk_read_byte(dev,
GENERAL_CTL, &gen_ctrl);
1114 status = vid_blk_write_byte(dev,
GENERAL_CTL, gen_ctrl);
1116 switch (audio_input) {
1121 status = vid_blk_write_word(dev,
AUD_IO_CTRL, value);
1126 status = vid_blk_read_word(dev,
AC97_CTL, &dwval);
1128 status = vid_blk_write_word(dev,
AC97_CTL,
1139 status = vid_blk_write_word(dev,
DL_CTL, 0x3000001);
1140 status = vid_blk_write_word(dev,
PATH1_CTL1, 0x00063073);
1180 status = vid_blk_write_word(dev,
PATH1_CTL1, 0x1F063870);
1183 status = vid_blk_write_word(dev,
PATH1_CTL1, 0x00063870);
1187 switch (dev->
board.tuner_type) {
1196 case TUNER_NXP_TDA18271:
1221 status = vid_blk_write_word(dev,
PATH1_CTL1, 0x1F011012);
1226 status = vid_blk_read_byte(dev,
GENERAL_CTL, &gen_ctrl);
1228 status = vid_blk_write_byte(dev,
GENERAL_CTL, gen_ctrl);
1241 status = vid_blk_read_word(dev,
PIN_CTRL, &value);
1242 value |= (~dev->
board.ctl_pin_status_mask);
1243 status = vid_blk_write_word(dev,
PIN_CTRL, value);
1249 u8 analog_or_digital)
1256 agc_analog_digital_select_gpio, 1);
1260 dev->
board.agc_analog_digital_select_gpio,
1270 bool current_is_port_3;
1272 if (dev->
board.dont_use_port_3)
1279 current_is_port_3 = value[0] &
I2C_DEMOD_EN ?
true :
false;
1282 if (current_is_port_3 == is_port_3)
1323 vid_blk_write_word(dev, 0x104, value);
1325 for (i = 0x100; i < 0x140; i++) {
1326 vid_blk_read_word(dev, i, &value);
1331 for (i = 0x300; i < 0x400; i++) {
1332 vid_blk_read_word(dev, i, &value);
1337 for (i = 0x400; i < 0x440; i++) {
1338 vid_blk_read_word(dev, i, &value);
1358 value[1], value[2], value[3]);
1362 value[1], value[2], value[3]);
1366 value[1], value[2], value[3]);
1370 value[1], value[2], value[3]);
1375 value[1], value[2], value[3]);
1379 value[1], value[2], value[3]);
1383 value[1], value[2], value[3]);
1387 value[1], value[2], value[3]);
1392 value[1], value[2], value[3]);
1396 value[1], value[2], value[3]);
1400 value[1], value[2], value[3]);
1404 value[1], value[2], value[3]);
1409 value[1], value[2], value[3]);
1413 value[1], value[2], value[3]);
1417 value[1], value[2], value[3]);
1421 value[1], value[2], value[3]);
1426 value[1], value[2], value[3]);
1430 value[1], value[2], value[3]);
1441 value = (value & 0xFE)|0x01;
1445 value = (value & 0xFE)|0x00;
1459 value = (value & 0xFC)|0x00;
1463 value = (value & 0xF9)|0x02;
1467 value = (value & 0xFB)|0x04;
1471 value = (value & 0xFC)|0x03;
1475 value = (value & 0xFB)|0x04;
1479 value = (value & 0xF8)|0x06;
1483 value = (value & 0x8F)|0x40;
1487 value = (value & 0xDF)|0x20;
1494 u32 colibri_carrier_offset = 0;
1495 u32 func_mode = 0x01;
1499 cx231xx_info(
"Enter cx231xx_set_Colibri_For_LowIF()\n");
1500 value[0] = (
u8) 0x6F;
1501 value[1] = (
u8) 0x6F;
1502 value[2] = (
u8) 0x6F;
1503 value[3] = (
u8) 0x6F;
1511 standard = dev->
norm;
1513 func_mode, standard);
1519 cx231xx_info(
"colibri_carrier_offset=%d, standard=0x%x\n",
1520 colibri_carrier_offset, standard);
1524 spectral_invert, mode);
1529 u32 colibri_carrier_offset = 0;
1532 colibri_carrier_offset = 1100000;
1534 colibri_carrier_offset = 4832000;
1536 colibri_carrier_offset = 2700000;
1539 colibri_carrier_offset = 2100000;
1542 return colibri_carrier_offset;
1548 unsigned long pll_freq_word;
1549 u32 dif_misc_ctrl_value = 0;
1550 u64 pll_freq_u64 = 0;
1553 cx231xx_info(
"if_freq=%d;spectral_invert=0x%x;mode=0x%x\n",
1554 if_freq, spectral_invert, mode);
1558 pll_freq_word = 0x905A1CAC;
1563 pll_freq_word = if_freq;
1564 pll_freq_u64 = (
u64)pll_freq_word << 28
L;
1565 do_div(pll_freq_u64, 50000000);
1566 pll_freq_word = (
u32)pll_freq_u64;
1570 if (spectral_invert) {
1574 &dif_misc_ctrl_value);
1575 dif_misc_ctrl_value = dif_misc_ctrl_value | 0x00200000;
1577 dif_misc_ctrl_value);
1582 &dif_misc_ctrl_value);
1583 dif_misc_ctrl_value = dif_misc_ctrl_value & 0xFFDFFFFF;
1585 dif_misc_ctrl_value);
1588 if_freq = (if_freq/100000)*100000;
1590 if (if_freq < 3000000)
1593 if (if_freq > 16000000)
1599 for (i = 0; i <
ARRAY_SIZE(Dif_set_array); i++) {
1600 if (Dif_set_array[i].if_freq == if_freq) {
1601 vid_blk_write_word(dev,
1602 Dif_set_array[i].register_address, Dif_set_array[i].
value);
1611 u32 function_mode,
u32 standard)
1707 u32 dif_misc_ctrl_value = 0;
1710 cx231xx_info(
"%s: setStandard to %x\n", __func__, standard);
1712 status = vid_blk_read_word(dev,
DIF_MISC_CTRL, &dif_misc_ctrl_value);
1714 dev->
norm = standard;
1716 switch (dev->
model) {
1736 func_mode, standard);
1743 &dif_misc_ctrl_value);
1746 dif_misc_ctrl_value);
1791 dif_misc_ctrl_value |= 0x3a023F11;
1836 dif_misc_ctrl_value |= 0x3a033F11;
1839 status = vid_blk_write_word(dev,
DIF_PLL_CTRL, 0xFF01FF0C);
1840 status = vid_blk_write_word(dev,
DIF_PLL_CTRL1, 0xbd038c85);
1841 status = vid_blk_write_word(dev,
DIF_PLL_CTRL2, 0x1db4640a);
1842 status = vid_blk_write_word(dev,
DIF_PLL_CTRL3, 0x00008800);
1863 dif_misc_ctrl_value |= 0x3A0A3F10;
1866 status = vid_blk_write_word(dev,
DIF_PLL_CTRL, 0xFF01FF0C);
1867 status = vid_blk_write_word(dev,
DIF_PLL_CTRL1, 0xbd038c85);
1868 status = vid_blk_write_word(dev,
DIF_PLL_CTRL2, 0x1db4640a);
1869 status = vid_blk_write_word(dev,
DIF_PLL_CTRL3, 0x00008800);
1891 dif_misc_ctrl_value = 0x3A093F10;
1892 }
else if (standard &
1940 dif_misc_ctrl_value |= 0x3a023F11;
1987 dif_misc_ctrl_value |= 0x3a023F11;
1999 status = vid_blk_write_word(dev,
DIF_PLL_CTRL, 0x6503BC0C);
2000 status = vid_blk_write_word(dev,
DIF_PLL_CTRL1, 0xBD038C85);
2001 status = vid_blk_write_word(dev,
DIF_PLL_CTRL2, 0x1DB4640A);
2002 status = vid_blk_write_word(dev,
DIF_PLL_CTRL3, 0x00008800);
2028 dif_misc_ctrl_value |= 0x3a003F10;
2074 dif_misc_ctrl_value |= 0x3a013F11;
2085 dif_misc_ctrl_value = 0x7a080000;
2088 status = vid_blk_write_word(dev,
DIF_MISC_CTRL, dif_misc_ctrl_value);
2101 dwval |= 0x33000000;
2112 cx231xx_info(
"cx231xx_tuner_post_channel_change dev->tuner_type =0%d\n",
2123 dwval |= 0x88000300;
2125 dwval |= 0x88000000;
2129 dwval |= 0xCC000300;
2131 dwval |= 0x44000000;
2185 switch (audio_input) {
2214 cx231xx_info(
" setPowerMode::mode = %d, No Change req.\n",
2224 tmp = *((
u32 *) value);
2232 value[0] = (
u8) tmp;
2233 value[1] = (
u8) (tmp >> 8);
2234 value[2] = (
u8) (tmp >> 16);
2235 value[3] = (
u8) (tmp >> 24);
2241 value[0] = (
u8) tmp;
2242 value[1] = (
u8) (tmp >> 8);
2243 value[2] = (
u8) (tmp >> 16);
2244 value[3] = (
u8) (tmp >> 24);
2251 value[0] = (
u8) tmp;
2252 value[1] = (
u8) (tmp >> 8);
2253 value[2] = (
u8) (tmp >> 16);
2254 value[3] = (
u8) (tmp >> 24);
2266 value[0] = (
u8) tmp;
2267 value[1] = (
u8) (tmp >> 8);
2268 value[2] = (
u8) (tmp >> 16);
2269 value[3] = (
u8) (tmp >> 24);
2276 value[0] = (
u8) tmp;
2277 value[1] = (
u8) (tmp >> 8);
2278 value[2] = (
u8) (tmp >> 16);
2279 value[3] = (
u8) (tmp >> 24);
2287 value[0] = (
u8) tmp;
2288 value[1] = (
u8) (tmp >> 8);
2289 value[2] = (
u8) (tmp >> 16);
2290 value[3] = (
u8) (tmp >> 24);
2297 value[0] = (
u8) tmp;
2298 value[1] = (
u8) (tmp >> 8);
2299 value[2] = (
u8) (tmp >> 16);
2300 value[3] = (
u8) (tmp >> 24);
2308 value[0] = (
u8) tmp;
2309 value[1] = (
u8) (tmp >> 8);
2310 value[2] = (
u8) (tmp >> 16);
2311 value[3] = (
u8) (tmp >> 24);
2317 if (dev->
board.tuner_type != TUNER_ABSENT) {
2322 if (dev->
board.tuner_gpio)
2332 if (!(tmp & PWR_TUNER_EN)) {
2334 value[0] = (
u8) tmp;
2335 value[1] = (
u8) (tmp >> 8);
2336 value[2] = (
u8) (tmp >> 16);
2337 value[3] = (
u8) (tmp >> 24);
2342 if (!(tmp & PWR_AV_EN)) {
2344 value[0] = (
u8) tmp;
2345 value[1] = (
u8) (tmp >> 8);
2346 value[2] = (
u8) (tmp >> 16);
2347 value[3] = (
u8) (tmp >> 24);
2352 if (!(tmp & PWR_ISO_EN)) {
2354 value[0] = (
u8) tmp;
2355 value[1] = (
u8) (tmp >> 8);
2356 value[2] = (
u8) (tmp >> 16);
2357 value[3] = (
u8) (tmp >> 24);
2365 value[0] = (
u8) tmp;
2366 value[1] = (
u8) (tmp >> 8);
2367 value[2] = (
u8) (tmp >> 16);
2368 value[3] = (
u8) (tmp >> 24);
2375 value[0] = (
u8) tmp;
2376 value[1] = (
u8) (tmp >> 8);
2377 value[2] = (
u8) (tmp >> 16);
2378 value[3] = (
u8) (tmp >> 24);
2384 if (dev->
board.tuner_type != TUNER_ABSENT) {
2395 if (dev->
board.tuner_gpio)
2413 value[0] = (
u8) tmp;
2414 value[1] = (
u8) (tmp >> 8);
2415 value[2] = (
u8) (tmp >> 16);
2416 value[3] = (
u8) (tmp >> 24);
2445 tmp = *((
u32 *) value);
2448 value[0] = (
u8) tmp;
2449 value[1] = (
u8) (tmp >> 8);
2450 value[2] = (
u8) (tmp >> 16);
2451 value[3] = (
u8) (tmp >> 24);
2463 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
2467 cx231xx_info(
"cx231xx_start_stream():: ep_mask = %x\n", ep_mask);
2473 tmp = *((
u32 *) value);
2475 value[0] = (
u8) tmp;
2476 value[1] = (
u8) (tmp >> 8);
2477 value[2] = (
u8) (tmp >> 16);
2478 value[3] = (
u8) (tmp >> 24);
2488 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
2492 cx231xx_info(
"cx231xx_stop_stream():: ep_mask = %x\n", ep_mask);
2498 tmp = *((
u32 *) value);
2500 value[0] = (
u8) tmp;
2501 value[1] = (
u8) (tmp >> 8);
2502 value[2] = (
u8) (tmp >> 16);
2503 value[3] = (
u8) (tmp >> 24);
2515 u8 val[4] = { 0, 0, 0, 0 };
2518 switch (media_type) {
2544 if (dev->
board.has_417) {
2546 value &= 0xFFFFFFFC;
2596 switch (media_type) {
2676 int pin_number,
int pin_value)
2682 if (pin_number >= 32)
2687 value = dev->
gpio_dir & (~(1 << pin_number));
2689 value = dev->
gpio_dir | (1 << pin_number);
2716 if (pin_number >= 32)
2720 if ((dev->
gpio_dir & (1 << pin_number)) == 0x00) {
2722 value = dev->
gpio_dir | (1 << pin_number);
2730 value = dev->
gpio_val & (~(1 << pin_number));
2732 value = dev->
gpio_val | (1 << pin_number);
2824 for (i = 0; i < 8; i++) {
2825 if (((data << i) & 0x80) == 0) {
2866 u32 gpio_logic_value = 0;
2870 for (i = 0; i < 8; i++) {
2886 if ((dev->
gpio_val & (1 << dev->
board.tuner_sda_gpio)) != 0)
2887 value |= (1 << (8 - i - 1));
2899 *buf = value & 0xff;
2907 u32 gpio_logic_value = 0;
2925 (1 << dev->
board.tuner_scl_gpio)) == 0) &&
2939 if ((dev->
gpio_val & 1 << dev->
board.tuner_sda_gpio) == 0) {
3030 for (i = 0; i < len; i++) {
3035 if ((i + 1) != len) {
3072 for (i = 0; i < len; i++) {