dvb-pll.c 21 KB

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