dvb-pll.c 20 KB

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