dvb-pll.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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. /* ----------------------------------------------------------- */
  25. /* descriptions */
  26. struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
  27. .name = "Thomson dtt7579",
  28. .min = 177000000,
  29. .max = 858000000,
  30. .count = 5,
  31. .entries = {
  32. { 0, 36166667, 166666, 0xb4, 0x03 }, /* go sleep */
  33. { 443250000, 36166667, 166666, 0xb4, 0x02 },
  34. { 542000000, 36166667, 166666, 0xb4, 0x08 },
  35. { 771000000, 36166667, 166666, 0xbc, 0x08 },
  36. { 999999999, 36166667, 166666, 0xf4, 0x08 },
  37. },
  38. };
  39. EXPORT_SYMBOL(dvb_pll_thomson_dtt7579);
  40. struct dvb_pll_desc dvb_pll_thomson_dtt7610 = {
  41. .name = "Thomson dtt7610",
  42. .min = 44000000,
  43. .max = 958000000,
  44. .count = 3,
  45. .entries = {
  46. { 157250000, 44000000, 62500, 0x8e, 0x39 },
  47. { 454000000, 44000000, 62500, 0x8e, 0x3a },
  48. { 999999999, 44000000, 62500, 0x8e, 0x3c },
  49. },
  50. };
  51. EXPORT_SYMBOL(dvb_pll_thomson_dtt7610);
  52. static void thomson_dtt759x_bw(u8 *buf, u32 freq, int bandwidth)
  53. {
  54. if (BANDWIDTH_7_MHZ == bandwidth)
  55. buf[3] |= 0x10;
  56. }
  57. struct dvb_pll_desc dvb_pll_thomson_dtt759x = {
  58. .name = "Thomson dtt759x",
  59. .min = 177000000,
  60. .max = 896000000,
  61. .setbw = thomson_dtt759x_bw,
  62. .count = 6,
  63. .entries = {
  64. { 0, 36166667, 166666, 0x84, 0x03 },
  65. { 264000000, 36166667, 166666, 0xb4, 0x02 },
  66. { 470000000, 36166667, 166666, 0xbc, 0x02 },
  67. { 735000000, 36166667, 166666, 0xbc, 0x08 },
  68. { 835000000, 36166667, 166666, 0xf4, 0x08 },
  69. { 999999999, 36166667, 166666, 0xfc, 0x08 },
  70. },
  71. };
  72. EXPORT_SYMBOL(dvb_pll_thomson_dtt759x);
  73. struct dvb_pll_desc dvb_pll_lg_z201 = {
  74. .name = "LG z201",
  75. .min = 174000000,
  76. .max = 862000000,
  77. .count = 6,
  78. .entries = {
  79. { 0, 36166667, 166666, 0xbc, 0x03 },
  80. { 157500000, 36166667, 166666, 0xbc, 0x01 },
  81. { 443250000, 36166667, 166666, 0xbc, 0x02 },
  82. { 542000000, 36166667, 166666, 0xbc, 0x04 },
  83. { 830000000, 36166667, 166666, 0xf4, 0x04 },
  84. { 999999999, 36166667, 166666, 0xfc, 0x04 },
  85. },
  86. };
  87. EXPORT_SYMBOL(dvb_pll_lg_z201);
  88. struct dvb_pll_desc dvb_pll_microtune_4042 = {
  89. .name = "Microtune 4042 FI5",
  90. .min = 57000000,
  91. .max = 858000000,
  92. .count = 3,
  93. .entries = {
  94. { 162000000, 44000000, 62500, 0x8e, 0xa1 },
  95. { 457000000, 44000000, 62500, 0x8e, 0x91 },
  96. { 999999999, 44000000, 62500, 0x8e, 0x31 },
  97. },
  98. };
  99. EXPORT_SYMBOL(dvb_pll_microtune_4042);
  100. struct dvb_pll_desc dvb_pll_thomson_dtt761x = {
  101. /* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */
  102. .name = "Thomson dtt761x",
  103. .min = 57000000,
  104. .max = 863000000,
  105. .count = 3,
  106. .entries = {
  107. { 147000000, 44000000, 62500, 0x8e, 0x39 },
  108. { 417000000, 44000000, 62500, 0x8e, 0x3a },
  109. { 999999999, 44000000, 62500, 0x8e, 0x3c },
  110. },
  111. };
  112. EXPORT_SYMBOL(dvb_pll_thomson_dtt761x);
  113. struct dvb_pll_desc dvb_pll_unknown_1 = {
  114. .name = "unknown 1", /* used by dntv live dvb-t */
  115. .min = 174000000,
  116. .max = 862000000,
  117. .count = 9,
  118. .entries = {
  119. { 150000000, 36166667, 166666, 0xb4, 0x01 },
  120. { 173000000, 36166667, 166666, 0xbc, 0x01 },
  121. { 250000000, 36166667, 166666, 0xb4, 0x02 },
  122. { 400000000, 36166667, 166666, 0xbc, 0x02 },
  123. { 420000000, 36166667, 166666, 0xf4, 0x02 },
  124. { 470000000, 36166667, 166666, 0xfc, 0x02 },
  125. { 600000000, 36166667, 166666, 0xbc, 0x08 },
  126. { 730000000, 36166667, 166666, 0xf4, 0x08 },
  127. { 999999999, 36166667, 166666, 0xfc, 0x08 },
  128. },
  129. };
  130. EXPORT_SYMBOL(dvb_pll_unknown_1);
  131. /* Infineon TUA6010XS
  132. * used in Thomson Cable Tuner
  133. */
  134. struct dvb_pll_desc dvb_pll_tua6010xs = {
  135. .name = "Infineon TUA6010XS",
  136. .min = 44250000,
  137. .max = 858000000,
  138. .count = 3,
  139. .entries = {
  140. { 115750000, 36125000, 62500, 0x8e, 0x03 },
  141. { 403250000, 36125000, 62500, 0x8e, 0x06 },
  142. { 999999999, 36125000, 62500, 0x8e, 0x85 },
  143. },
  144. };
  145. EXPORT_SYMBOL(dvb_pll_tua6010xs);
  146. /* Panasonic env57h1xd5 (some Philips PLL ?) */
  147. struct dvb_pll_desc dvb_pll_env57h1xd5 = {
  148. .name = "Panasonic ENV57H1XD5",
  149. .min = 44250000,
  150. .max = 858000000,
  151. .count = 4,
  152. .entries = {
  153. { 153000000, 36291666, 166666, 0xc2, 0x41 },
  154. { 470000000, 36291666, 166666, 0xc2, 0x42 },
  155. { 526000000, 36291666, 166666, 0xc2, 0x84 },
  156. { 999999999, 36291666, 166666, 0xc2, 0xa4 },
  157. },
  158. };
  159. EXPORT_SYMBOL(dvb_pll_env57h1xd5);
  160. /* Philips TDA6650/TDA6651
  161. * used in Panasonic ENV77H11D5
  162. */
  163. static void tda665x_bw(u8 *buf, u32 freq, int bandwidth)
  164. {
  165. if (bandwidth == BANDWIDTH_8_MHZ)
  166. buf[3] |= 0x08;
  167. }
  168. struct dvb_pll_desc dvb_pll_tda665x = {
  169. .name = "Philips TDA6650/TDA6651",
  170. .min = 44250000,
  171. .max = 858000000,
  172. .setbw = tda665x_bw,
  173. .count = 12,
  174. .entries = {
  175. { 93834000, 36249333, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
  176. { 123834000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  177. { 161000000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  178. { 163834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  179. { 253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
  180. { 383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
  181. { 443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  182. { 444000000, 36249333, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
  183. { 583834000, 36249333, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ },
  184. { 793834000, 36249333, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ },
  185. { 444834000, 36249333, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
  186. { 861000000, 36249333, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ },
  187. }
  188. };
  189. EXPORT_SYMBOL(dvb_pll_tda665x);
  190. /* Infineon TUA6034
  191. * used in LG TDTP E102P
  192. */
  193. static void tua6034_bw(u8 *buf, u32 freq, int bandwidth)
  194. {
  195. if (BANDWIDTH_7_MHZ != bandwidth)
  196. buf[3] |= 0x08;
  197. }
  198. struct dvb_pll_desc dvb_pll_tua6034 = {
  199. .name = "Infineon TUA6034",
  200. .min = 44250000,
  201. .max = 858000000,
  202. .count = 3,
  203. .setbw = tua6034_bw,
  204. .entries = {
  205. { 174500000, 36166667, 62500, 0xce, 0x01 },
  206. { 230000000, 36166667, 62500, 0xce, 0x02 },
  207. { 999999999, 36166667, 62500, 0xce, 0x04 },
  208. },
  209. };
  210. EXPORT_SYMBOL(dvb_pll_tua6034);
  211. /* Infineon TUA6034
  212. * used in LG TDVS-H061F, LG TDVS-H062F and LG TDVS-H064F
  213. */
  214. struct dvb_pll_desc dvb_pll_lg_tdvs_h06xf = {
  215. .name = "LG TDVS-H06xF",
  216. .min = 54000000,
  217. .max = 863000000,
  218. .count = 3,
  219. .entries = {
  220. { 165000000, 44000000, 62500, 0xce, 0x01 },
  221. { 450000000, 44000000, 62500, 0xce, 0x02 },
  222. { 999999999, 44000000, 62500, 0xce, 0x04 },
  223. },
  224. };
  225. EXPORT_SYMBOL(dvb_pll_lg_tdvs_h06xf);
  226. /* Philips FMD1216ME
  227. * used in Medion Hybrid PCMCIA card and USB Box
  228. */
  229. static void fmd1216me_bw(u8 *buf, u32 freq, int bandwidth)
  230. {
  231. if (bandwidth == BANDWIDTH_8_MHZ && freq >= 158870000)
  232. buf[3] |= 0x08;
  233. }
  234. struct dvb_pll_desc dvb_pll_fmd1216me = {
  235. .name = "Philips FMD1216ME",
  236. .min = 50870000,
  237. .max = 858000000,
  238. .setbw = fmd1216me_bw,
  239. .count = 7,
  240. .entries = {
  241. { 143870000, 36213333, 166667, 0xbc, 0x41 },
  242. { 158870000, 36213333, 166667, 0xf4, 0x41 },
  243. { 329870000, 36213333, 166667, 0xbc, 0x42 },
  244. { 441870000, 36213333, 166667, 0xf4, 0x42 },
  245. { 625870000, 36213333, 166667, 0xbc, 0x44 },
  246. { 803870000, 36213333, 166667, 0xf4, 0x44 },
  247. { 999999999, 36213333, 166667, 0xfc, 0x44 },
  248. }
  249. };
  250. EXPORT_SYMBOL(dvb_pll_fmd1216me);
  251. /* ALPS TDED4
  252. * used in Nebula-Cards and USB boxes
  253. */
  254. static void tded4_bw(u8 *buf, u32 freq, int bandwidth)
  255. {
  256. if (bandwidth == BANDWIDTH_8_MHZ)
  257. buf[3] |= 0x04;
  258. }
  259. struct dvb_pll_desc dvb_pll_tded4 = {
  260. .name = "ALPS TDED4",
  261. .min = 47000000,
  262. .max = 863000000,
  263. .setbw = tded4_bw,
  264. .count = 4,
  265. .entries = {
  266. { 153000000, 36166667, 166667, 0x85, 0x01 },
  267. { 470000000, 36166667, 166667, 0x85, 0x02 },
  268. { 823000000, 36166667, 166667, 0x85, 0x08 },
  269. { 999999999, 36166667, 166667, 0x85, 0x88 },
  270. }
  271. };
  272. EXPORT_SYMBOL(dvb_pll_tded4);
  273. /* ALPS TDHU2
  274. * used in AverTVHD MCE A180
  275. */
  276. struct dvb_pll_desc dvb_pll_tdhu2 = {
  277. .name = "ALPS TDHU2",
  278. .min = 54000000,
  279. .max = 864000000,
  280. .count = 4,
  281. .entries = {
  282. { 162000000, 44000000, 62500, 0x85, 0x01 },
  283. { 426000000, 44000000, 62500, 0x85, 0x02 },
  284. { 782000000, 44000000, 62500, 0x85, 0x08 },
  285. { 999999999, 44000000, 62500, 0x85, 0x88 },
  286. }
  287. };
  288. EXPORT_SYMBOL(dvb_pll_tdhu2);
  289. /* Philips TUV1236D
  290. * used in ATI HDTV Wonder
  291. */
  292. struct dvb_pll_desc dvb_pll_tuv1236d = {
  293. .name = "Philips TUV1236D",
  294. .min = 54000000,
  295. .max = 864000000,
  296. .count = 3,
  297. .entries = {
  298. { 157250000, 44000000, 62500, 0xc6, 0x41 },
  299. { 454000000, 44000000, 62500, 0xc6, 0x42 },
  300. { 999999999, 44000000, 62500, 0xc6, 0x44 },
  301. },
  302. };
  303. EXPORT_SYMBOL(dvb_pll_tuv1236d);
  304. /* Samsung TBMV30111IN / TBMV30712IN1
  305. * used in Air2PC ATSC - 2nd generation (nxt2002)
  306. */
  307. struct dvb_pll_desc dvb_pll_samsung_tbmv = {
  308. .name = "Samsung TBMV30111IN / TBMV30712IN1",
  309. .min = 54000000,
  310. .max = 860000000,
  311. .count = 6,
  312. .entries = {
  313. { 172000000, 44000000, 166666, 0xb4, 0x01 },
  314. { 214000000, 44000000, 166666, 0xb4, 0x02 },
  315. { 467000000, 44000000, 166666, 0xbc, 0x02 },
  316. { 721000000, 44000000, 166666, 0xbc, 0x08 },
  317. { 841000000, 44000000, 166666, 0xf4, 0x08 },
  318. { 999999999, 44000000, 166666, 0xfc, 0x02 },
  319. }
  320. };
  321. EXPORT_SYMBOL(dvb_pll_samsung_tbmv);
  322. /*
  323. * Philips SD1878 Tuner.
  324. */
  325. struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
  326. .name = "Philips SD1878",
  327. .min = 950000,
  328. .max = 2150000,
  329. .count = 4,
  330. .entries = {
  331. { 1250000, 499, 500, 0xc4, 0x00},
  332. { 1550000, 499, 500, 0xc4, 0x40},
  333. { 2050000, 499, 500, 0xc4, 0x80},
  334. { 2150000, 499, 500, 0xc4, 0xc0},
  335. },
  336. };
  337. EXPORT_SYMBOL(dvb_pll_philips_sd1878_tda8261);
  338. /*
  339. * Philips TD1316 Tuner.
  340. */
  341. static void td1316_bw(u8 *buf, u32 freq, int bandwidth)
  342. {
  343. u8 band;
  344. /* determine band */
  345. if (freq < 161000000)
  346. band = 1;
  347. else if (freq < 444000000)
  348. band = 2;
  349. else
  350. band = 4;
  351. buf[3] |= band;
  352. /* setup PLL filter */
  353. if (bandwidth == BANDWIDTH_8_MHZ)
  354. buf[3] |= 1 << 3;
  355. }
  356. struct dvb_pll_desc dvb_pll_philips_td1316 = {
  357. .name = "Philips TD1316",
  358. .min = 87000000,
  359. .max = 895000000,
  360. .setbw = td1316_bw,
  361. .count = 9,
  362. .entries = {
  363. { 93834000, 36166000, 166666, 0xca, 0x60},
  364. { 123834000, 36166000, 166666, 0xca, 0xa0},
  365. { 163834000, 36166000, 166666, 0xca, 0xc0},
  366. { 253834000, 36166000, 166666, 0xca, 0x60},
  367. { 383834000, 36166000, 166666, 0xca, 0xa0},
  368. { 443834000, 36166000, 166666, 0xca, 0xc0},
  369. { 583834000, 36166000, 166666, 0xca, 0x60},
  370. { 793834000, 36166000, 166666, 0xca, 0xa0},
  371. { 858834000, 36166000, 166666, 0xca, 0xe0},
  372. },
  373. };
  374. EXPORT_SYMBOL(dvb_pll_philips_td1316);
  375. /* FE6600 used on DViCO Hybrid */
  376. struct dvb_pll_desc dvb_pll_thomson_fe6600 = {
  377. .name = "Thomson FE6600",
  378. .min = 44250000,
  379. .max = 858000000,
  380. .count = 4,
  381. .entries = {
  382. { 250000000, 36213333, 166667, 0xb4, 0x12 },
  383. { 455000000, 36213333, 166667, 0xfe, 0x11 },
  384. { 775500000, 36213333, 166667, 0xbc, 0x18 },
  385. { 999999999, 36213333, 166667, 0xf4, 0x18 },
  386. }
  387. };
  388. EXPORT_SYMBOL(dvb_pll_thomson_fe6600);
  389. struct dvb_pll_priv {
  390. /* i2c details */
  391. int pll_i2c_address;
  392. struct i2c_adapter *i2c;
  393. /* the PLL descriptor */
  394. struct dvb_pll_desc *pll_desc;
  395. /* cached frequency/bandwidth */
  396. u32 frequency;
  397. u32 bandwidth;
  398. };
  399. /* ----------------------------------------------------------- */
  400. /* code */
  401. static int debug = 0;
  402. module_param(debug, int, 0644);
  403. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  404. int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
  405. u32 freq, int bandwidth)
  406. {
  407. u32 div;
  408. int i;
  409. if (freq != 0 && (freq < desc->min || freq > desc->max))
  410. return -EINVAL;
  411. for (i = 0; i < desc->count; i++) {
  412. if (freq > desc->entries[i].limit)
  413. continue;
  414. break;
  415. }
  416. if (debug)
  417. printk("pll: %s: freq=%d bw=%d | i=%d/%d\n",
  418. desc->name, freq, bandwidth, i, desc->count);
  419. if (i == desc->count)
  420. return -EINVAL;
  421. div = (freq + desc->entries[i].offset) / desc->entries[i].stepsize;
  422. buf[0] = div >> 8;
  423. buf[1] = div & 0xff;
  424. buf[2] = desc->entries[i].config;
  425. buf[3] = desc->entries[i].cb;
  426. if (desc->setbw)
  427. desc->setbw(buf, freq, bandwidth);
  428. if (debug)
  429. printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
  430. desc->name, div, buf[0], buf[1], buf[2], buf[3]);
  431. // calculate the frequency we set it to
  432. return (div * desc->entries[i].stepsize) - desc->entries[i].offset;
  433. }
  434. EXPORT_SYMBOL(dvb_pll_configure);
  435. static int dvb_pll_release(struct dvb_frontend *fe)
  436. {
  437. kfree(fe->tuner_priv);
  438. fe->tuner_priv = NULL;
  439. return 0;
  440. }
  441. static int dvb_pll_sleep(struct dvb_frontend *fe)
  442. {
  443. struct dvb_pll_priv *priv = fe->tuner_priv;
  444. u8 buf[4];
  445. struct i2c_msg msg =
  446. { .addr = priv->pll_i2c_address, .flags = 0,
  447. .buf = buf, .len = sizeof(buf) };
  448. int i;
  449. int result;
  450. if (priv->i2c == NULL)
  451. return -EINVAL;
  452. for (i = 0; i < priv->pll_desc->count; i++) {
  453. if (priv->pll_desc->entries[i].limit == 0)
  454. break;
  455. }
  456. if (i == priv->pll_desc->count)
  457. return 0;
  458. buf[0] = 0;
  459. buf[1] = 0;
  460. buf[2] = priv->pll_desc->entries[i].config;
  461. buf[3] = priv->pll_desc->entries[i].cb;
  462. if (fe->ops.i2c_gate_ctrl)
  463. fe->ops.i2c_gate_ctrl(fe, 1);
  464. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  465. return result;
  466. }
  467. return 0;
  468. }
  469. static int dvb_pll_set_params(struct dvb_frontend *fe,
  470. struct dvb_frontend_parameters *params)
  471. {
  472. struct dvb_pll_priv *priv = fe->tuner_priv;
  473. u8 buf[4];
  474. struct i2c_msg msg =
  475. { .addr = priv->pll_i2c_address, .flags = 0,
  476. .buf = buf, .len = sizeof(buf) };
  477. int result;
  478. u32 bandwidth = 0, frequency = 0;
  479. if (priv->i2c == NULL)
  480. return -EINVAL;
  481. // DVBT bandwidth only just now
  482. if (fe->ops.info.type == FE_OFDM) {
  483. bandwidth = params->u.ofdm.bandwidth;
  484. }
  485. if ((result = dvb_pll_configure(priv->pll_desc, buf,
  486. params->frequency, bandwidth)) < 0)
  487. return result;
  488. else
  489. frequency = result;
  490. if (fe->ops.i2c_gate_ctrl)
  491. fe->ops.i2c_gate_ctrl(fe, 1);
  492. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  493. return result;
  494. }
  495. priv->frequency = frequency;
  496. priv->bandwidth = bandwidth;
  497. return 0;
  498. }
  499. static int dvb_pll_calc_regs(struct dvb_frontend *fe,
  500. struct dvb_frontend_parameters *params,
  501. u8 *buf, int buf_len)
  502. {
  503. struct dvb_pll_priv *priv = fe->tuner_priv;
  504. int result;
  505. u32 bandwidth = 0, frequency = 0;
  506. if (buf_len < 5)
  507. return -EINVAL;
  508. // DVBT bandwidth only just now
  509. if (fe->ops.info.type == FE_OFDM) {
  510. bandwidth = params->u.ofdm.bandwidth;
  511. }
  512. if ((result = dvb_pll_configure(priv->pll_desc, buf+1,
  513. params->frequency, bandwidth)) < 0)
  514. return result;
  515. else
  516. frequency = result;
  517. buf[0] = priv->pll_i2c_address;
  518. priv->frequency = frequency;
  519. priv->bandwidth = bandwidth;
  520. return 5;
  521. }
  522. static int dvb_pll_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  523. {
  524. struct dvb_pll_priv *priv = fe->tuner_priv;
  525. *frequency = priv->frequency;
  526. return 0;
  527. }
  528. static int dvb_pll_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
  529. {
  530. struct dvb_pll_priv *priv = fe->tuner_priv;
  531. *bandwidth = priv->bandwidth;
  532. return 0;
  533. }
  534. static struct dvb_tuner_ops dvb_pll_tuner_ops = {
  535. .release = dvb_pll_release,
  536. .sleep = dvb_pll_sleep,
  537. .set_params = dvb_pll_set_params,
  538. .calc_regs = dvb_pll_calc_regs,
  539. .get_frequency = dvb_pll_get_frequency,
  540. .get_bandwidth = dvb_pll_get_bandwidth,
  541. };
  542. struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
  543. struct i2c_adapter *i2c,
  544. struct dvb_pll_desc *desc)
  545. {
  546. u8 b1 [] = { 0 };
  547. struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD,
  548. .buf = b1, .len = 1 };
  549. struct dvb_pll_priv *priv = NULL;
  550. int ret;
  551. if (i2c != NULL) {
  552. if (fe->ops.i2c_gate_ctrl)
  553. fe->ops.i2c_gate_ctrl(fe, 1);
  554. ret = i2c_transfer (i2c, &msg, 1);
  555. if (ret != 1)
  556. return NULL;
  557. if (fe->ops.i2c_gate_ctrl)
  558. fe->ops.i2c_gate_ctrl(fe, 0);
  559. }
  560. priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL);
  561. if (priv == NULL)
  562. return NULL;
  563. priv->pll_i2c_address = pll_addr;
  564. priv->i2c = i2c;
  565. priv->pll_desc = desc;
  566. memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops,
  567. sizeof(struct dvb_tuner_ops));
  568. strncpy(fe->ops.tuner_ops.info.name, desc->name, 128);
  569. fe->ops.tuner_ops.info.frequency_min = desc->min;
  570. fe->ops.tuner_ops.info.frequency_min = desc->max;
  571. fe->tuner_priv = priv;
  572. return fe;
  573. }
  574. EXPORT_SYMBOL(dvb_pll_attach);
  575. MODULE_DESCRIPTION("dvb pll library");
  576. MODULE_AUTHOR("Gerd Knorr");
  577. MODULE_LICENSE("GPL");