dibusb-mc-common.c 4.3 KB

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