dvb-pll.c 18 KB

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