dvb-pll.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /*
  2. * descriptions + helper functions for simple dvb plls.
  3. *
  4. * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/dvb/frontend.h>
  22. #include <asm/types.h>
  23. #include "dvb-pll.h"
  24. struct dvb_pll_priv {
  25. /* pll number */
  26. int nr;
  27. /* i2c details */
  28. int pll_i2c_address;
  29. struct i2c_adapter *i2c;
  30. /* the PLL descriptor */
  31. struct dvb_pll_desc *pll_desc;
  32. /* cached frequency/bandwidth */
  33. u32 frequency;
  34. u32 bandwidth;
  35. };
  36. #define DVB_PLL_MAX 64
  37. static unsigned int dvb_pll_devcount;
  38. static int debug;
  39. module_param(debug, int, 0644);
  40. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  41. static unsigned int input[DVB_PLL_MAX] = { [ 0 ... (DVB_PLL_MAX-1) ] = 0 };
  42. module_param_array(input, int, NULL, 0644);
  43. MODULE_PARM_DESC(input,"specify rf input choice, 0 for autoselect (default)");
  44. static unsigned int id[DVB_PLL_MAX] =
  45. { [ 0 ... (DVB_PLL_MAX-1) ] = DVB_PLL_UNDEFINED };
  46. module_param_array(id, int, NULL, 0644);
  47. MODULE_PARM_DESC(id, "force pll id to use (DEBUG ONLY)");
  48. /* ----------------------------------------------------------- */
  49. struct dvb_pll_desc {
  50. char *name;
  51. u32 min;
  52. u32 max;
  53. u32 iffreq;
  54. void (*set)(struct dvb_frontend *fe, u8 *buf,
  55. const struct dvb_frontend_parameters *params);
  56. u8 *initdata;
  57. u8 *sleepdata;
  58. int count;
  59. struct {
  60. u32 limit;
  61. u32 stepsize;
  62. u8 config;
  63. u8 cb;
  64. } entries[12];
  65. };
  66. /* ----------------------------------------------------------- */
  67. /* descriptions */
  68. /* Set AGC TOP value to 103 dBuV:
  69. 0x80 = Control Byte
  70. 0x40 = 250 uA charge pump (irrelevant)
  71. 0x18 = Aux Byte to follow
  72. 0x06 = 64.5 kHz divider (irrelevant)
  73. 0x01 = Disable Vt (aka sleep)
  74. 0x00 = AGC Time constant 2s Iagc = 300 nA (vs 0x80 = 9 nA)
  75. 0x50 = AGC Take over point = 103 dBuV */
  76. static u8 tua603x_agc103[] = { 2, 0x80|0x40|0x18|0x06|0x01, 0x00|0x50 };
  77. /* 0x04 = 166.67 kHz divider
  78. 0x80 = AGC Time constant 50ms Iagc = 9 uA
  79. 0x20 = AGC Take over point = 112 dBuV */
  80. static u8 tua603x_agc112[] = { 2, 0x80|0x40|0x18|0x04|0x01, 0x80|0x20 };
  81. static struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
  82. .name = "Thomson dtt7579",
  83. .min = 177000000,
  84. .max = 858000000,
  85. .iffreq= 36166667,
  86. .sleepdata = (u8[]){ 2, 0xb4, 0x03 },
  87. .count = 4,
  88. .entries = {
  89. { 443250000, 166667, 0xb4, 0x02 },
  90. { 542000000, 166667, 0xb4, 0x08 },
  91. { 771000000, 166667, 0xbc, 0x08 },
  92. { 999999999, 166667, 0xf4, 0x08 },
  93. },
  94. };
  95. static void thomson_dtt759x_bw(struct dvb_frontend *fe, u8 *buf,
  96. const struct dvb_frontend_parameters *params)
  97. {
  98. if (BANDWIDTH_7_MHZ == params->u.ofdm.bandwidth)
  99. buf[3] |= 0x10;
  100. }
  101. static struct dvb_pll_desc dvb_pll_thomson_dtt759x = {
  102. .name = "Thomson dtt759x",
  103. .min = 177000000,
  104. .max = 896000000,
  105. .set = thomson_dtt759x_bw,
  106. .iffreq= 36166667,
  107. .sleepdata = (u8[]){ 2, 0x84, 0x03 },
  108. .count = 5,
  109. .entries = {
  110. { 264000000, 166667, 0xb4, 0x02 },
  111. { 470000000, 166667, 0xbc, 0x02 },
  112. { 735000000, 166667, 0xbc, 0x08 },
  113. { 835000000, 166667, 0xf4, 0x08 },
  114. { 999999999, 166667, 0xfc, 0x08 },
  115. },
  116. };
  117. static struct dvb_pll_desc dvb_pll_lg_z201 = {
  118. .name = "LG z201",
  119. .min = 174000000,
  120. .max = 862000000,
  121. .iffreq= 36166667,
  122. .sleepdata = (u8[]){ 2, 0xbc, 0x03 },
  123. .count = 5,
  124. .entries = {
  125. { 157500000, 166667, 0xbc, 0x01 },
  126. { 443250000, 166667, 0xbc, 0x02 },
  127. { 542000000, 166667, 0xbc, 0x04 },
  128. { 830000000, 166667, 0xf4, 0x04 },
  129. { 999999999, 166667, 0xfc, 0x04 },
  130. },
  131. };
  132. static struct dvb_pll_desc dvb_pll_microtune_4042 = {
  133. .name = "Microtune 4042 FI5",
  134. .min = 57000000,
  135. .max = 858000000,
  136. .iffreq= 44000000,
  137. .count = 3,
  138. .entries = {
  139. { 162000000, 62500, 0x8e, 0xa1 },
  140. { 457000000, 62500, 0x8e, 0x91 },
  141. { 999999999, 62500, 0x8e, 0x31 },
  142. },
  143. };
  144. static struct dvb_pll_desc dvb_pll_thomson_dtt761x = {
  145. /* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */
  146. .name = "Thomson dtt761x",
  147. .min = 57000000,
  148. .max = 863000000,
  149. .iffreq= 44000000,
  150. .count = 3,
  151. .initdata = tua603x_agc103,
  152. .entries = {
  153. { 147000000, 62500, 0x8e, 0x39 },
  154. { 417000000, 62500, 0x8e, 0x3a },
  155. { 999999999, 62500, 0x8e, 0x3c },
  156. },
  157. };
  158. static struct dvb_pll_desc dvb_pll_unknown_1 = {
  159. .name = "unknown 1", /* used by dntv live dvb-t */
  160. .min = 174000000,
  161. .max = 862000000,
  162. .iffreq= 36166667,
  163. .count = 9,
  164. .entries = {
  165. { 150000000, 166667, 0xb4, 0x01 },
  166. { 173000000, 166667, 0xbc, 0x01 },
  167. { 250000000, 166667, 0xb4, 0x02 },
  168. { 400000000, 166667, 0xbc, 0x02 },
  169. { 420000000, 166667, 0xf4, 0x02 },
  170. { 470000000, 166667, 0xfc, 0x02 },
  171. { 600000000, 166667, 0xbc, 0x08 },
  172. { 730000000, 166667, 0xf4, 0x08 },
  173. { 999999999, 166667, 0xfc, 0x08 },
  174. },
  175. };
  176. /* Infineon TUA6010XS
  177. * used in Thomson Cable Tuner
  178. */
  179. static struct dvb_pll_desc dvb_pll_tua6010xs = {
  180. .name = "Infineon TUA6010XS",
  181. .min = 44250000,
  182. .max = 858000000,
  183. .iffreq= 36125000,
  184. .count = 3,
  185. .entries = {
  186. { 115750000, 62500, 0x8e, 0x03 },
  187. { 403250000, 62500, 0x8e, 0x06 },
  188. { 999999999, 62500, 0x8e, 0x85 },
  189. },
  190. };
  191. /* Panasonic env57h1xd5 (some Philips PLL ?) */
  192. static struct dvb_pll_desc dvb_pll_env57h1xd5 = {
  193. .name = "Panasonic ENV57H1XD5",
  194. .min = 44250000,
  195. .max = 858000000,
  196. .iffreq= 36125000,
  197. .count = 4,
  198. .entries = {
  199. { 153000000, 166667, 0xc2, 0x41 },
  200. { 470000000, 166667, 0xc2, 0x42 },
  201. { 526000000, 166667, 0xc2, 0x84 },
  202. { 999999999, 166667, 0xc2, 0xa4 },
  203. },
  204. };
  205. /* Philips TDA6650/TDA6651
  206. * used in Panasonic ENV77H11D5
  207. */
  208. static void tda665x_bw(struct dvb_frontend *fe, u8 *buf,
  209. const struct dvb_frontend_parameters *params)
  210. {
  211. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  212. buf[3] |= 0x08;
  213. }
  214. static struct dvb_pll_desc dvb_pll_tda665x = {
  215. .name = "Philips TDA6650/TDA6651",
  216. .min = 44250000,
  217. .max = 858000000,
  218. .set = tda665x_bw,
  219. .iffreq= 36166667,
  220. .initdata = (u8[]){ 4, 0x0b, 0xf5, 0x85, 0xab },
  221. .count = 12,
  222. .entries = {
  223. { 93834000, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
  224. { 123834000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  225. { 161000000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  226. { 163834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  227. { 253834000, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
  228. { 383834000, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
  229. { 443834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  230. { 444000000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
  231. { 583834000, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ },
  232. { 793834000, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ },
  233. { 444834000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
  234. { 861000000, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ },
  235. }
  236. };
  237. /* Infineon TUA6034
  238. * used in LG TDTP E102P
  239. */
  240. static void tua6034_bw(struct dvb_frontend *fe, u8 *buf,
  241. const struct dvb_frontend_parameters *params)
  242. {
  243. if (BANDWIDTH_7_MHZ != params->u.ofdm.bandwidth)
  244. buf[3] |= 0x08;
  245. }
  246. static struct dvb_pll_desc dvb_pll_tua6034 = {
  247. .name = "Infineon TUA6034",
  248. .min = 44250000,
  249. .max = 858000000,
  250. .iffreq= 36166667,
  251. .count = 3,
  252. .set = tua6034_bw,
  253. .entries = {
  254. { 174500000, 62500, 0xce, 0x01 },
  255. { 230000000, 62500, 0xce, 0x02 },
  256. { 999999999, 62500, 0xce, 0x04 },
  257. },
  258. };
  259. /* Infineon TUA6034
  260. * used in LG TDVS-H061F, LG TDVS-H062F and LG TDVS-H064F
  261. */
  262. static struct dvb_pll_desc dvb_pll_lg_tdvs_h06xf = {
  263. .name = "LG TDVS-H06xF",
  264. .min = 54000000,
  265. .max = 863000000,
  266. .iffreq= 44000000,
  267. .initdata = tua603x_agc103,
  268. .count = 3,
  269. .entries = {
  270. { 165000000, 62500, 0xce, 0x01 },
  271. { 450000000, 62500, 0xce, 0x02 },
  272. { 999999999, 62500, 0xce, 0x04 },
  273. },
  274. };
  275. /* Philips FMD1216ME
  276. * used in Medion Hybrid PCMCIA card and USB Box
  277. */
  278. static void fmd1216me_bw(struct dvb_frontend *fe, u8 *buf,
  279. const struct dvb_frontend_parameters *params)
  280. {
  281. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ &&
  282. params->frequency >= 158870000)
  283. buf[3] |= 0x08;
  284. }
  285. static struct dvb_pll_desc dvb_pll_fmd1216me = {
  286. .name = "Philips FMD1216ME",
  287. .min = 50870000,
  288. .max = 858000000,
  289. .iffreq= 36125000,
  290. .set = fmd1216me_bw,
  291. .initdata = tua603x_agc112,
  292. .sleepdata = (u8[]){ 4, 0x9c, 0x60, 0x85, 0x54 },
  293. .count = 7,
  294. .entries = {
  295. { 143870000, 166667, 0xbc, 0x41 },
  296. { 158870000, 166667, 0xf4, 0x41 },
  297. { 329870000, 166667, 0xbc, 0x42 },
  298. { 441870000, 166667, 0xf4, 0x42 },
  299. { 625870000, 166667, 0xbc, 0x44 },
  300. { 803870000, 166667, 0xf4, 0x44 },
  301. { 999999999, 166667, 0xfc, 0x44 },
  302. }
  303. };
  304. /* ALPS TDED4
  305. * used in Nebula-Cards and USB boxes
  306. */
  307. static void tded4_bw(struct dvb_frontend *fe, u8 *buf,
  308. const struct dvb_frontend_parameters *params)
  309. {
  310. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  311. buf[3] |= 0x04;
  312. }
  313. static struct dvb_pll_desc dvb_pll_tded4 = {
  314. .name = "ALPS TDED4",
  315. .min = 47000000,
  316. .max = 863000000,
  317. .iffreq= 36166667,
  318. .set = tded4_bw,
  319. .count = 4,
  320. .entries = {
  321. { 153000000, 166667, 0x85, 0x01 },
  322. { 470000000, 166667, 0x85, 0x02 },
  323. { 823000000, 166667, 0x85, 0x08 },
  324. { 999999999, 166667, 0x85, 0x88 },
  325. }
  326. };
  327. /* ALPS TDHU2
  328. * used in AverTVHD MCE A180
  329. */
  330. static struct dvb_pll_desc dvb_pll_tdhu2 = {
  331. .name = "ALPS TDHU2",
  332. .min = 54000000,
  333. .max = 864000000,
  334. .iffreq= 44000000,
  335. .count = 4,
  336. .entries = {
  337. { 162000000, 62500, 0x85, 0x01 },
  338. { 426000000, 62500, 0x85, 0x02 },
  339. { 782000000, 62500, 0x85, 0x08 },
  340. { 999999999, 62500, 0x85, 0x88 },
  341. }
  342. };
  343. /* Philips TUV1236D
  344. * used in ATI HDTV Wonder
  345. */
  346. static void tuv1236d_rf(struct dvb_frontend *fe, u8 *buf,
  347. const struct dvb_frontend_parameters *params)
  348. {
  349. struct dvb_pll_priv *priv = fe->tuner_priv;
  350. unsigned int new_rf = input[priv->nr];
  351. if ((new_rf == 0) || (new_rf > 2)) {
  352. switch (params->u.vsb.modulation) {
  353. case QAM_64:
  354. case QAM_256:
  355. new_rf = 1;
  356. break;
  357. case VSB_8:
  358. default:
  359. new_rf = 2;
  360. }
  361. }
  362. switch (new_rf) {
  363. case 1:
  364. buf[3] |= 0x08;
  365. break;
  366. case 2:
  367. buf[3] &= ~0x08;
  368. break;
  369. default:
  370. printk(KERN_WARNING
  371. "%s: unhandled rf input selection: %d",
  372. __FUNCTION__, new_rf);
  373. }
  374. }
  375. static struct dvb_pll_desc dvb_pll_tuv1236d = {
  376. .name = "Philips TUV1236D",
  377. .min = 54000000,
  378. .max = 864000000,
  379. .iffreq= 44000000,
  380. .set = tuv1236d_rf,
  381. .count = 3,
  382. .entries = {
  383. { 157250000, 62500, 0xc6, 0x41 },
  384. { 454000000, 62500, 0xc6, 0x42 },
  385. { 999999999, 62500, 0xc6, 0x44 },
  386. },
  387. };
  388. /* Samsung TBMV30111IN / TBMV30712IN1
  389. * used in Air2PC ATSC - 2nd generation (nxt2002)
  390. */
  391. static struct dvb_pll_desc dvb_pll_samsung_tbmv = {
  392. .name = "Samsung TBMV30111IN / TBMV30712IN1",
  393. .min = 54000000,
  394. .max = 860000000,
  395. .iffreq= 44000000,
  396. .count = 6,
  397. .entries = {
  398. { 172000000, 166667, 0xb4, 0x01 },
  399. { 214000000, 166667, 0xb4, 0x02 },
  400. { 467000000, 166667, 0xbc, 0x02 },
  401. { 721000000, 166667, 0xbc, 0x08 },
  402. { 841000000, 166667, 0xf4, 0x08 },
  403. { 999999999, 166667, 0xfc, 0x02 },
  404. }
  405. };
  406. /*
  407. * Philips SD1878 Tuner.
  408. */
  409. static struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
  410. .name = "Philips SD1878",
  411. .min = 950000,
  412. .max = 2150000,
  413. .iffreq= 249, /* zero-IF, offset 249 is to round up */
  414. .count = 4,
  415. .entries = {
  416. { 1250000, 500, 0xc4, 0x00},
  417. { 1550000, 500, 0xc4, 0x40},
  418. { 2050000, 500, 0xc4, 0x80},
  419. { 2150000, 500, 0xc4, 0xc0},
  420. },
  421. };
  422. /*
  423. * Philips TD1316 Tuner.
  424. */
  425. static void td1316_bw(struct dvb_frontend *fe, u8 *buf,
  426. const struct dvb_frontend_parameters *params)
  427. {
  428. u8 band;
  429. /* determine band */
  430. if (params->frequency < 161000000)
  431. band = 1;
  432. else if (params->frequency < 444000000)
  433. band = 2;
  434. else
  435. band = 4;
  436. buf[3] |= band;
  437. /* setup PLL filter */
  438. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  439. buf[3] |= 1 << 3;
  440. }
  441. static struct dvb_pll_desc dvb_pll_philips_td1316 = {
  442. .name = "Philips TD1316",
  443. .min = 87000000,
  444. .max = 895000000,
  445. .iffreq= 36166667,
  446. .set = td1316_bw,
  447. .count = 9,
  448. .entries = {
  449. { 93834000, 166667, 0xca, 0x60},
  450. { 123834000, 166667, 0xca, 0xa0},
  451. { 163834000, 166667, 0xca, 0xc0},
  452. { 253834000, 166667, 0xca, 0x60},
  453. { 383834000, 166667, 0xca, 0xa0},
  454. { 443834000, 166667, 0xca, 0xc0},
  455. { 583834000, 166667, 0xca, 0x60},
  456. { 793834000, 166667, 0xca, 0xa0},
  457. { 858834000, 166667, 0xca, 0xe0},
  458. },
  459. };
  460. /* FE6600 used on DViCO Hybrid */
  461. static struct dvb_pll_desc dvb_pll_thomson_fe6600 = {
  462. .name = "Thomson FE6600",
  463. .min = 44250000,
  464. .max = 858000000,
  465. .iffreq= 36125000,
  466. .count = 4,
  467. .entries = {
  468. { 250000000, 166667, 0xb4, 0x12 },
  469. { 455000000, 166667, 0xfe, 0x11 },
  470. { 775500000, 166667, 0xbc, 0x18 },
  471. { 999999999, 166667, 0xf4, 0x18 },
  472. }
  473. };
  474. static void opera1_bw(struct dvb_frontend *fe, u8 *buf,
  475. const struct dvb_frontend_parameters *params)
  476. {
  477. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  478. buf[2] |= 0x08;
  479. }
  480. static struct dvb_pll_desc dvb_pll_opera1 = {
  481. .name = "Opera Tuner",
  482. .min = 900000,
  483. .max = 2250000,
  484. .iffreq= 0,
  485. .set = opera1_bw,
  486. .count = 8,
  487. .entries = {
  488. { 1064000, 500, 0xe5, 0xc6 },
  489. { 1169000, 500, 0xe5, 0xe6 },
  490. { 1299000, 500, 0xe5, 0x24 },
  491. { 1444000, 500, 0xe5, 0x44 },
  492. { 1606000, 500, 0xe5, 0x64 },
  493. { 1777000, 500, 0xe5, 0x84 },
  494. { 1941000, 500, 0xe5, 0xa4 },
  495. { 2250000, 500, 0xe5, 0xc4 },
  496. }
  497. };
  498. /* Philips FCV1236D
  499. */
  500. static struct dvb_pll_desc dvb_pll_fcv1236d = {
  501. /* Bit_0: RF Input select
  502. * Bit_1: 0=digital, 1=analog
  503. */
  504. .name = "Philips FCV1236D",
  505. .min = 53000000,
  506. .max = 803000000,
  507. .iffreq= 44000000,
  508. .count = 3,
  509. .entries = {
  510. { 159000000, 62500, 0x8e, 0xa0 },
  511. { 453000000, 62500, 0x8e, 0x90 },
  512. { 999999999, 62500, 0x8e, 0x30 },
  513. },
  514. };
  515. /* ----------------------------------------------------------- */
  516. static struct dvb_pll_desc *pll_list[] = {
  517. [DVB_PLL_UNDEFINED] = NULL,
  518. [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579,
  519. [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x,
  520. [DVB_PLL_LG_Z201] = &dvb_pll_lg_z201,
  521. [DVB_PLL_MICROTUNE_4042] = &dvb_pll_microtune_4042,
  522. [DVB_PLL_THOMSON_DTT761X] = &dvb_pll_thomson_dtt761x,
  523. [DVB_PLL_UNKNOWN_1] = &dvb_pll_unknown_1,
  524. [DVB_PLL_TUA6010XS] = &dvb_pll_tua6010xs,
  525. [DVB_PLL_ENV57H1XD5] = &dvb_pll_env57h1xd5,
  526. [DVB_PLL_TUA6034] = &dvb_pll_tua6034,
  527. [DVB_PLL_LG_TDVS_H06XF] = &dvb_pll_lg_tdvs_h06xf,
  528. [DVB_PLL_TDA665X] = &dvb_pll_tda665x,
  529. [DVB_PLL_FMD1216ME] = &dvb_pll_fmd1216me,
  530. [DVB_PLL_TDED4] = &dvb_pll_tded4,
  531. [DVB_PLL_TUV1236D] = &dvb_pll_tuv1236d,
  532. [DVB_PLL_TDHU2] = &dvb_pll_tdhu2,
  533. [DVB_PLL_SAMSUNG_TBMV] = &dvb_pll_samsung_tbmv,
  534. [DVB_PLL_PHILIPS_SD1878_TDA8261] = &dvb_pll_philips_sd1878_tda8261,
  535. [DVB_PLL_PHILIPS_TD1316] = &dvb_pll_philips_td1316,
  536. [DVB_PLL_THOMSON_FE6600] = &dvb_pll_thomson_fe6600,
  537. [DVB_PLL_OPERA1] = &dvb_pll_opera1,
  538. [DVB_PLL_FCV1236D] = &dvb_pll_fcv1236d,
  539. };
  540. /* ----------------------------------------------------------- */
  541. /* code */
  542. static int dvb_pll_configure(struct dvb_frontend *fe, u8 *buf,
  543. const struct dvb_frontend_parameters *params)
  544. {
  545. struct dvb_pll_priv *priv = fe->tuner_priv;
  546. struct dvb_pll_desc *desc = priv->pll_desc;
  547. u32 div;
  548. int i;
  549. if (params->frequency != 0 && (params->frequency < desc->min ||
  550. params->frequency > desc->max))
  551. return -EINVAL;
  552. for (i = 0; i < desc->count; i++) {
  553. if (params->frequency > desc->entries[i].limit)
  554. continue;
  555. break;
  556. }
  557. if (debug)
  558. printk("pll: %s: freq=%d | i=%d/%d\n", desc->name,
  559. params->frequency, i, desc->count);
  560. if (i == desc->count)
  561. return -EINVAL;
  562. div = (params->frequency + desc->iffreq +
  563. desc->entries[i].stepsize/2) / desc->entries[i].stepsize;
  564. buf[0] = div >> 8;
  565. buf[1] = div & 0xff;
  566. buf[2] = desc->entries[i].config;
  567. buf[3] = desc->entries[i].cb;
  568. if (desc->set)
  569. desc->set(fe, buf, params);
  570. if (debug)
  571. printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
  572. desc->name, div, buf[0], buf[1], buf[2], buf[3]);
  573. // calculate the frequency we set it to
  574. return (div * desc->entries[i].stepsize) - desc->iffreq;
  575. }
  576. static int dvb_pll_release(struct dvb_frontend *fe)
  577. {
  578. kfree(fe->tuner_priv);
  579. fe->tuner_priv = NULL;
  580. return 0;
  581. }
  582. static int dvb_pll_sleep(struct dvb_frontend *fe)
  583. {
  584. struct dvb_pll_priv *priv = fe->tuner_priv;
  585. if (priv->i2c == NULL)
  586. return -EINVAL;
  587. if (priv->pll_desc->sleepdata) {
  588. struct i2c_msg msg = { .flags = 0,
  589. .addr = priv->pll_i2c_address,
  590. .buf = priv->pll_desc->sleepdata + 1,
  591. .len = priv->pll_desc->sleepdata[0] };
  592. int result;
  593. if (fe->ops.i2c_gate_ctrl)
  594. fe->ops.i2c_gate_ctrl(fe, 1);
  595. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  596. return result;
  597. }
  598. return 0;
  599. }
  600. /* Shouldn't be called when initdata is NULL, maybe BUG()? */
  601. return -EINVAL;
  602. }
  603. static int dvb_pll_set_params(struct dvb_frontend *fe,
  604. struct dvb_frontend_parameters *params)
  605. {
  606. struct dvb_pll_priv *priv = fe->tuner_priv;
  607. u8 buf[4];
  608. struct i2c_msg msg =
  609. { .addr = priv->pll_i2c_address, .flags = 0,
  610. .buf = buf, .len = sizeof(buf) };
  611. int result;
  612. u32 frequency = 0;
  613. if (priv->i2c == NULL)
  614. return -EINVAL;
  615. if ((result = dvb_pll_configure(fe, buf, params)) < 0)
  616. return result;
  617. else
  618. frequency = result;
  619. if (fe->ops.i2c_gate_ctrl)
  620. fe->ops.i2c_gate_ctrl(fe, 1);
  621. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  622. return result;
  623. }
  624. priv->frequency = frequency;
  625. priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
  626. return 0;
  627. }
  628. static int dvb_pll_calc_regs(struct dvb_frontend *fe,
  629. struct dvb_frontend_parameters *params,
  630. u8 *buf, int buf_len)
  631. {
  632. struct dvb_pll_priv *priv = fe->tuner_priv;
  633. int result;
  634. u32 frequency = 0;
  635. if (buf_len < 5)
  636. return -EINVAL;
  637. if ((result = dvb_pll_configure(fe, buf+1, params)) < 0)
  638. return result;
  639. else
  640. frequency = result;
  641. buf[0] = priv->pll_i2c_address;
  642. priv->frequency = frequency;
  643. priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
  644. return 5;
  645. }
  646. static int dvb_pll_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  647. {
  648. struct dvb_pll_priv *priv = fe->tuner_priv;
  649. *frequency = priv->frequency;
  650. return 0;
  651. }
  652. static int dvb_pll_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
  653. {
  654. struct dvb_pll_priv *priv = fe->tuner_priv;
  655. *bandwidth = priv->bandwidth;
  656. return 0;
  657. }
  658. static int dvb_pll_init(struct dvb_frontend *fe)
  659. {
  660. struct dvb_pll_priv *priv = fe->tuner_priv;
  661. if (priv->i2c == NULL)
  662. return -EINVAL;
  663. if (priv->pll_desc->initdata) {
  664. struct i2c_msg msg = { .flags = 0,
  665. .addr = priv->pll_i2c_address,
  666. .buf = priv->pll_desc->initdata + 1,
  667. .len = priv->pll_desc->initdata[0] };
  668. int result;
  669. if (fe->ops.i2c_gate_ctrl)
  670. fe->ops.i2c_gate_ctrl(fe, 1);
  671. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  672. return result;
  673. }
  674. return 0;
  675. }
  676. /* Shouldn't be called when initdata is NULL, maybe BUG()? */
  677. return -EINVAL;
  678. }
  679. static struct dvb_tuner_ops dvb_pll_tuner_ops = {
  680. .release = dvb_pll_release,
  681. .sleep = dvb_pll_sleep,
  682. .init = dvb_pll_init,
  683. .set_params = dvb_pll_set_params,
  684. .calc_regs = dvb_pll_calc_regs,
  685. .get_frequency = dvb_pll_get_frequency,
  686. .get_bandwidth = dvb_pll_get_bandwidth,
  687. };
  688. struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
  689. struct i2c_adapter *i2c,
  690. unsigned int pll_desc_id)
  691. {
  692. u8 b1 [] = { 0 };
  693. struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD,
  694. .buf = b1, .len = 1 };
  695. struct dvb_pll_priv *priv = NULL;
  696. int ret;
  697. struct dvb_pll_desc *desc;
  698. if ((id[dvb_pll_devcount] > DVB_PLL_UNDEFINED) &&
  699. (id[dvb_pll_devcount] < ARRAY_SIZE(pll_list)))
  700. pll_desc_id = id[dvb_pll_devcount];
  701. BUG_ON(pll_desc_id < 1 || pll_desc_id >= ARRAY_SIZE(pll_list));
  702. desc = pll_list[pll_desc_id];
  703. if (i2c != NULL) {
  704. if (fe->ops.i2c_gate_ctrl)
  705. fe->ops.i2c_gate_ctrl(fe, 1);
  706. ret = i2c_transfer (i2c, &msg, 1);
  707. if (ret != 1)
  708. return NULL;
  709. if (fe->ops.i2c_gate_ctrl)
  710. fe->ops.i2c_gate_ctrl(fe, 0);
  711. }
  712. priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL);
  713. if (priv == NULL)
  714. return NULL;
  715. priv->pll_i2c_address = pll_addr;
  716. priv->i2c = i2c;
  717. priv->pll_desc = desc;
  718. priv->nr = dvb_pll_devcount++;
  719. memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops,
  720. sizeof(struct dvb_tuner_ops));
  721. strncpy(fe->ops.tuner_ops.info.name, desc->name,
  722. sizeof(fe->ops.tuner_ops.info.name));
  723. fe->ops.tuner_ops.info.frequency_min = desc->min;
  724. fe->ops.tuner_ops.info.frequency_max = desc->max;
  725. if (!desc->initdata)
  726. fe->ops.tuner_ops.init = NULL;
  727. if (!desc->sleepdata)
  728. fe->ops.tuner_ops.sleep = NULL;
  729. fe->tuner_priv = priv;
  730. if ((debug) || (id[priv->nr] == pll_desc_id)) {
  731. printk("dvb-pll[%d]", priv->nr);
  732. if (i2c != NULL)
  733. printk(" %d-%04x", i2c_adapter_id(i2c), pll_addr);
  734. printk(": id# %d (%s) attached, %s\n", pll_desc_id, desc->name,
  735. id[priv->nr] == pll_desc_id ?
  736. "insmod option" : "autodetected");
  737. }
  738. if ((debug) || (input[priv->nr] > 0)) {
  739. printk("dvb-pll[%d]", priv->nr);
  740. if (i2c != NULL)
  741. printk(" %d-%04x", i2c_adapter_id(i2c), pll_addr);
  742. printk(": tuner rf input will be ");
  743. switch (input[priv->nr]) {
  744. case 0:
  745. printk("autoselected\n");
  746. break;
  747. default:
  748. printk("set to input %d (insmod option)\n",
  749. input[priv->nr]);
  750. }
  751. }
  752. return fe;
  753. }
  754. EXPORT_SYMBOL(dvb_pll_attach);
  755. MODULE_DESCRIPTION("dvb pll library");
  756. MODULE_AUTHOR("Gerd Knorr");
  757. MODULE_LICENSE("GPL");