b2c2-common.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * b2c2-common.c - common methods for the B2C2/Technisat SkyStar2 PCI DVB card and
  3. * for the B2C2/Technisat Sky/Cable/AirStar USB devices
  4. * based on the FlexCopII/FlexCopIII by B2C2, Inc.
  5. *
  6. * Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
  7. *
  8. * FIX: DISEQC Tone Burst in flexcop_diseqc_ioctl()
  9. * FIX: FULL soft DiSEqC for skystar2 (FlexCopII rev 130) VP310 equipped
  10. * Vincenzo Di Massa, hawk.it at tiscalinet.it
  11. *
  12. * Converted to Linux coding style
  13. * Misc reorganization, polishing, restyling
  14. * Roberto Ragusa, r.ragusa at libero.it
  15. *
  16. * Added hardware filtering support,
  17. * Niklas Peinecke, peinecke at gdv.uni-hannover.de
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU Lesser General Public License
  21. * as published by the Free Software Foundation; either version 2.1
  22. * of the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Lesser General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  32. *
  33. */
  34. #include "stv0299.h"
  35. #include "mt352.h"
  36. #include "mt312.h"
  37. static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
  38. {
  39. u8 aclk = 0;
  40. u8 bclk = 0;
  41. if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; }
  42. else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; }
  43. else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; }
  44. else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; }
  45. else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; }
  46. else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; }
  47. stv0299_writereg (fe, 0x13, aclk);
  48. stv0299_writereg (fe, 0x14, bclk);
  49. stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
  50. stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
  51. stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
  52. return 0;
  53. }
  54. static int samsung_tbmu24112_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
  55. {
  56. u8 buf[4];
  57. u32 div;
  58. struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
  59. // struct adapter* adapter = (struct adapter*) fe->dvb->priv;
  60. div = params->frequency / 125;
  61. buf[0] = (div >> 8) & 0x7f;
  62. buf[1] = div & 0xff;
  63. buf[2] = 0x84; // 0xC4
  64. buf[3] = 0x08;
  65. if (params->frequency < 1500000) buf[3] |= 0x10;
  66. // if (i2c_transfer (&adapter->i2c_adap, &msg, 1) != 1) return -EIO;
  67. return 0;
  68. }
  69. static u8 samsung_tbmu24112_inittab[] = {
  70. 0x01, 0x15,
  71. 0x02, 0x30,
  72. 0x03, 0x00,
  73. 0x04, 0x7D,
  74. 0x05, 0x35,
  75. 0x06, 0x02,
  76. 0x07, 0x00,
  77. 0x08, 0xC3,
  78. 0x0C, 0x00,
  79. 0x0D, 0x81,
  80. 0x0E, 0x23,
  81. 0x0F, 0x12,
  82. 0x10, 0x7E,
  83. 0x11, 0x84,
  84. 0x12, 0xB9,
  85. 0x13, 0x88,
  86. 0x14, 0x89,
  87. 0x15, 0xC9,
  88. 0x16, 0x00,
  89. 0x17, 0x5C,
  90. 0x18, 0x00,
  91. 0x19, 0x00,
  92. 0x1A, 0x00,
  93. 0x1C, 0x00,
  94. 0x1D, 0x00,
  95. 0x1E, 0x00,
  96. 0x1F, 0x3A,
  97. 0x20, 0x2E,
  98. 0x21, 0x80,
  99. 0x22, 0xFF,
  100. 0x23, 0xC1,
  101. 0x28, 0x00,
  102. 0x29, 0x1E,
  103. 0x2A, 0x14,
  104. 0x2B, 0x0F,
  105. 0x2C, 0x09,
  106. 0x2D, 0x05,
  107. 0x31, 0x1F,
  108. 0x32, 0x19,
  109. 0x33, 0xFE,
  110. 0x34, 0x93,
  111. 0xff, 0xff,
  112. };
  113. static struct stv0299_config samsung_tbmu24112_config = {
  114. .demod_address = 0x68,
  115. .inittab = samsung_tbmu24112_inittab,
  116. .mclk = 88000000UL,
  117. .invert = 0,
  118. .enhanced_tuning = 0,
  119. .skip_reinit = 0,
  120. .lock_output = STV0229_LOCKOUTPUT_LK,
  121. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  122. .min_delay_ms = 100,
  123. .set_symbol_rate = samsung_tbmu24112_set_symbol_rate,
  124. .pll_set = samsung_tbmu24112_pll_set,
  125. };
  126. static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
  127. {
  128. static u8 mt352_clock_config [] = { 0x89, 0x10, 0x2d };
  129. static u8 mt352_reset [] = { 0x50, 0x80 };
  130. static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  131. static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0xa1 };
  132. static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
  133. mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
  134. udelay(2000);
  135. mt352_write(fe, mt352_reset, sizeof(mt352_reset));
  136. mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
  137. mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
  138. mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
  139. return 0;
  140. }
  141. static int samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf)
  142. {
  143. u32 div;
  144. unsigned char bs = 0;
  145. #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
  146. div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
  147. if (params->frequency >= 48000000 && params->frequency <= 154000000) bs = 0x09;
  148. if (params->frequency >= 161000000 && params->frequency <= 439000000) bs = 0x0a;
  149. if (params->frequency >= 447000000 && params->frequency <= 863000000) bs = 0x08;
  150. pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address
  151. pllbuf[1] = div >> 8;
  152. pllbuf[2] = div & 0xff;
  153. pllbuf[3] = 0xcc;
  154. pllbuf[4] = bs;
  155. return 0;
  156. }
  157. static struct mt352_config samsung_tdtc9251dh0_config = {
  158. .demod_address = 0x0f,
  159. .demod_init = samsung_tdtc9251dh0_demod_init,
  160. .pll_set = samsung_tdtc9251dh0_pll_set,
  161. };
  162. static int skystar23_samsung_tbdu18132_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
  163. {
  164. u8 buf[4];
  165. u32 div;
  166. struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
  167. // struct adapter* adapter = (struct adapter*) fe->dvb->priv;
  168. div = (params->frequency + (125/2)) / 125;
  169. buf[0] = (div >> 8) & 0x7f;
  170. buf[1] = (div >> 0) & 0xff;
  171. buf[2] = 0x84 | ((div >> 10) & 0x60);
  172. buf[3] = 0x80;
  173. if (params->frequency < 1550000)
  174. buf[3] |= 0x02;
  175. //if (i2c_transfer (&adapter->i2c_adap, &msg, 1) != 1) return -EIO;
  176. return 0;
  177. }
  178. static struct mt312_config skystar23_samsung_tbdu18132_config = {
  179. .demod_address = 0x0e,
  180. .pll_set = skystar23_samsung_tbdu18132_pll_set,
  181. };