dvb-pll.c 20 KB

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