dibusb-mc-common.c 4.2 KB

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