dibusb-mc-common.c 4.1 KB

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