dibusb-mc-common.c 4.3 KB

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