dibusb-mc-common.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* Common methods for dibusb-based-receivers.
  2. *
  3. * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation, version 2.
  8. *
  9. * see Documentation/dvb/README.dvb-usb for more information
  10. */
  11. #include "dibusb.h"
  12. /* 3000MC/P stuff */
  13. // Config Adjacent channels Perf -cal22
  14. static struct dibx000_agc_config dib3000p_mt2060_agc_config = {
  15. .band_caps = BAND_VHF | BAND_UHF,
  16. .setup = (1 << 8) | (5 << 5) | (1 << 4) | (1 << 3) | (0 << 2) | (2 << 0),
  17. .agc1_max = 48497,
  18. .agc1_min = 23593,
  19. .agc2_max = 46531,
  20. .agc2_min = 24904,
  21. .agc1_pt1 = 0x65,
  22. .agc1_pt2 = 0x69,
  23. .agc1_slope1 = 0x51,
  24. .agc1_slope2 = 0x27,
  25. .agc2_pt1 = 0,
  26. .agc2_pt2 = 0x33,
  27. .agc2_slope1 = 0x35,
  28. .agc2_slope2 = 0x37,
  29. };
  30. static struct dib3000mc_config stk3000p_dib3000p_config = {
  31. &dib3000p_mt2060_agc_config,
  32. .max_time = 0x196,
  33. .ln_adc_level = 0x1cc7,
  34. .output_mpeg2_in_188_bytes = 1,
  35. .agc_command1 = 1,
  36. .agc_command2 = 1,
  37. };
  38. static struct dibx000_agc_config dib3000p_panasonic_agc_config = {
  39. .band_caps = BAND_VHF | BAND_UHF,
  40. .setup = (1 << 8) | (5 << 5) | (1 << 4) | (1 << 3) | (0 << 2) | (2 << 0),
  41. .agc1_max = 56361,
  42. .agc1_min = 22282,
  43. .agc2_max = 47841,
  44. .agc2_min = 36045,
  45. .agc1_pt1 = 0x3b,
  46. .agc1_pt2 = 0x6b,
  47. .agc1_slope1 = 0x55,
  48. .agc1_slope2 = 0x1d,
  49. .agc2_pt1 = 0,
  50. .agc2_pt2 = 0x0a,
  51. .agc2_slope1 = 0x95,
  52. .agc2_slope2 = 0x1e,
  53. };
  54. static struct dib3000mc_config mod3000p_dib3000p_config = {
  55. &dib3000p_panasonic_agc_config,
  56. .max_time = 0x51,
  57. .ln_adc_level = 0x1cc7,
  58. .output_mpeg2_in_188_bytes = 1,
  59. .agc_command1 = 1,
  60. .agc_command2 = 1,
  61. };
  62. int dibusb_dib3000mc_frontend_attach(struct dvb_usb_adapter *adap)
  63. {
  64. if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_LITEON &&
  65. le16_to_cpu(adap->dev->udev->descriptor.idProduct) ==
  66. USB_PID_LITEON_DVB_T_WARM) {
  67. msleep(1000);
  68. }
  69. adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach,
  70. &adap->dev->i2c_adap,
  71. DEFAULT_DIB3000P_I2C_ADDRESS,
  72. &mod3000p_dib3000p_config);
  73. if ((adap->fe_adap[0].fe) == NULL)
  74. adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach,
  75. &adap->dev->i2c_adap,
  76. DEFAULT_DIB3000MC_I2C_ADDRESS,
  77. &mod3000p_dib3000p_config);
  78. if ((adap->fe_adap[0].fe) != NULL) {
  79. if (adap->priv != NULL) {
  80. struct dibusb_state *st = adap->priv;
  81. st->ops.pid_parse = dib3000mc_pid_parse;
  82. st->ops.pid_ctrl = dib3000mc_pid_control;
  83. }
  84. return 0;
  85. }
  86. return -ENODEV;
  87. }
  88. EXPORT_SYMBOL(dibusb_dib3000mc_frontend_attach);
  89. static struct mt2060_config stk3000p_mt2060_config = {
  90. 0x60
  91. };
  92. int dibusb_dib3000mc_tuner_attach(struct dvb_usb_adapter *adap)
  93. {
  94. struct dibusb_state *st = adap->priv;
  95. u8 a,b;
  96. u16 if1 = 1220;
  97. struct i2c_adapter *tun_i2c;
  98. // First IF calibration for Liteon Sticks
  99. if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_LITEON &&
  100. le16_to_cpu(adap->dev->udev->descriptor.idProduct) == USB_PID_LITEON_DVB_T_WARM) {
  101. dibusb_read_eeprom_byte(adap->dev,0x7E,&a);
  102. dibusb_read_eeprom_byte(adap->dev,0x7F,&b);
  103. if (a == 0x00)
  104. if1 += b;
  105. else if (a == 0x80)
  106. if1 -= b;
  107. else
  108. warn("LITE-ON DVB-T: Strange IF1 calibration :%2X %2X\n", a, b);
  109. } else if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_DIBCOM &&
  110. le16_to_cpu(adap->dev->udev->descriptor.idProduct) == USB_PID_DIBCOM_MOD3001_WARM) {
  111. u8 desc;
  112. dibusb_read_eeprom_byte(adap->dev, 7, &desc);
  113. if (desc == 2) {
  114. a = 127;
  115. do {
  116. dibusb_read_eeprom_byte(adap->dev, a, &desc);
  117. a--;
  118. } while (a > 7 && (desc == 0xff || desc == 0x00));
  119. if (desc & 0x80)
  120. if1 -= (0xff - desc);
  121. else
  122. if1 += desc;
  123. }
  124. }
  125. tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe_adap[0].fe, 1);
  126. if (dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c, &stk3000p_mt2060_config, if1) == NULL) {
  127. /* not found - use panasonic pll parameters */
  128. if (dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60, tun_i2c, DVB_PLL_ENV57H1XD5) == NULL)
  129. return -ENOMEM;
  130. } else {
  131. st->mt2060_present = 1;
  132. /* set the correct parameters for the dib3000p */
  133. dib3000mc_set_config(adap->fe_adap[0].fe, &stk3000p_dib3000p_config);
  134. }
  135. return 0;
  136. }
  137. EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);