dvb-pll.c 22 KB

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