dvb-pll.c 21 KB

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