dvb-pll.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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 id[DVB_PLL_MAX] =
  42. { [ 0 ... (DVB_PLL_MAX-1) ] = DVB_PLL_UNDEFINED };
  43. module_param_array(id, int, NULL, 0644);
  44. MODULE_PARM_DESC(id, "force pll id to use (DEBUG ONLY)");
  45. /* ----------------------------------------------------------- */
  46. struct dvb_pll_desc {
  47. char *name;
  48. u32 min;
  49. u32 max;
  50. u32 iffreq;
  51. void (*set)(struct dvb_frontend *fe, u8 *buf,
  52. const struct dvb_frontend_parameters *params);
  53. u8 *initdata;
  54. u8 *sleepdata;
  55. int count;
  56. struct {
  57. u32 limit;
  58. u32 stepsize;
  59. u8 config;
  60. u8 cb;
  61. } entries[12];
  62. };
  63. /* ----------------------------------------------------------- */
  64. /* descriptions */
  65. static struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
  66. .name = "Thomson dtt7579",
  67. .min = 177000000,
  68. .max = 858000000,
  69. .iffreq= 36166667,
  70. .sleepdata = (u8[]){ 2, 0xb4, 0x03 },
  71. .count = 4,
  72. .entries = {
  73. { 443250000, 166667, 0xb4, 0x02 },
  74. { 542000000, 166667, 0xb4, 0x08 },
  75. { 771000000, 166667, 0xbc, 0x08 },
  76. { 999999999, 166667, 0xf4, 0x08 },
  77. },
  78. };
  79. static void thomson_dtt759x_bw(struct dvb_frontend *fe, u8 *buf,
  80. const struct dvb_frontend_parameters *params)
  81. {
  82. if (BANDWIDTH_7_MHZ == params->u.ofdm.bandwidth)
  83. buf[3] |= 0x10;
  84. }
  85. static struct dvb_pll_desc dvb_pll_thomson_dtt759x = {
  86. .name = "Thomson dtt759x",
  87. .min = 177000000,
  88. .max = 896000000,
  89. .set = thomson_dtt759x_bw,
  90. .iffreq= 36166667,
  91. .sleepdata = (u8[]){ 2, 0x84, 0x03 },
  92. .count = 5,
  93. .entries = {
  94. { 264000000, 166667, 0xb4, 0x02 },
  95. { 470000000, 166667, 0xbc, 0x02 },
  96. { 735000000, 166667, 0xbc, 0x08 },
  97. { 835000000, 166667, 0xf4, 0x08 },
  98. { 999999999, 166667, 0xfc, 0x08 },
  99. },
  100. };
  101. static struct dvb_pll_desc dvb_pll_lg_z201 = {
  102. .name = "LG z201",
  103. .min = 174000000,
  104. .max = 862000000,
  105. .iffreq= 36166667,
  106. .sleepdata = (u8[]){ 2, 0xbc, 0x03 },
  107. .count = 5,
  108. .entries = {
  109. { 157500000, 166667, 0xbc, 0x01 },
  110. { 443250000, 166667, 0xbc, 0x02 },
  111. { 542000000, 166667, 0xbc, 0x04 },
  112. { 830000000, 166667, 0xf4, 0x04 },
  113. { 999999999, 166667, 0xfc, 0x04 },
  114. },
  115. };
  116. static struct dvb_pll_desc dvb_pll_unknown_1 = {
  117. .name = "unknown 1", /* used by dntv live dvb-t */
  118. .min = 174000000,
  119. .max = 862000000,
  120. .iffreq= 36166667,
  121. .count = 9,
  122. .entries = {
  123. { 150000000, 166667, 0xb4, 0x01 },
  124. { 173000000, 166667, 0xbc, 0x01 },
  125. { 250000000, 166667, 0xb4, 0x02 },
  126. { 400000000, 166667, 0xbc, 0x02 },
  127. { 420000000, 166667, 0xf4, 0x02 },
  128. { 470000000, 166667, 0xfc, 0x02 },
  129. { 600000000, 166667, 0xbc, 0x08 },
  130. { 730000000, 166667, 0xf4, 0x08 },
  131. { 999999999, 166667, 0xfc, 0x08 },
  132. },
  133. };
  134. /* Infineon TUA6010XS
  135. * used in Thomson Cable Tuner
  136. */
  137. static struct dvb_pll_desc dvb_pll_tua6010xs = {
  138. .name = "Infineon TUA6010XS",
  139. .min = 44250000,
  140. .max = 858000000,
  141. .iffreq= 36125000,
  142. .count = 3,
  143. .entries = {
  144. { 115750000, 62500, 0x8e, 0x03 },
  145. { 403250000, 62500, 0x8e, 0x06 },
  146. { 999999999, 62500, 0x8e, 0x85 },
  147. },
  148. };
  149. /* Panasonic env57h1xd5 (some Philips PLL ?) */
  150. static struct dvb_pll_desc dvb_pll_env57h1xd5 = {
  151. .name = "Panasonic ENV57H1XD5",
  152. .min = 44250000,
  153. .max = 858000000,
  154. .iffreq= 36125000,
  155. .count = 4,
  156. .entries = {
  157. { 153000000, 166667, 0xc2, 0x41 },
  158. { 470000000, 166667, 0xc2, 0x42 },
  159. { 526000000, 166667, 0xc2, 0x84 },
  160. { 999999999, 166667, 0xc2, 0xa4 },
  161. },
  162. };
  163. /* Philips TDA6650/TDA6651
  164. * used in Panasonic ENV77H11D5
  165. */
  166. static void tda665x_bw(struct dvb_frontend *fe, u8 *buf,
  167. const struct dvb_frontend_parameters *params)
  168. {
  169. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  170. buf[3] |= 0x08;
  171. }
  172. static struct dvb_pll_desc dvb_pll_tda665x = {
  173. .name = "Philips TDA6650/TDA6651",
  174. .min = 44250000,
  175. .max = 858000000,
  176. .set = tda665x_bw,
  177. .iffreq= 36166667,
  178. .initdata = (u8[]){ 4, 0x0b, 0xf5, 0x85, 0xab },
  179. .count = 12,
  180. .entries = {
  181. { 93834000, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
  182. { 123834000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  183. { 161000000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  184. { 163834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  185. { 253834000, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
  186. { 383834000, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
  187. { 443834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  188. { 444000000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
  189. { 583834000, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ },
  190. { 793834000, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ },
  191. { 444834000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
  192. { 861000000, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ },
  193. }
  194. };
  195. /* Infineon TUA6034
  196. * used in LG TDTP E102P
  197. */
  198. static void tua6034_bw(struct dvb_frontend *fe, u8 *buf,
  199. const struct dvb_frontend_parameters *params)
  200. {
  201. if (BANDWIDTH_7_MHZ != params->u.ofdm.bandwidth)
  202. buf[3] |= 0x08;
  203. }
  204. static struct dvb_pll_desc dvb_pll_tua6034 = {
  205. .name = "Infineon TUA6034",
  206. .min = 44250000,
  207. .max = 858000000,
  208. .iffreq= 36166667,
  209. .count = 3,
  210. .set = tua6034_bw,
  211. .entries = {
  212. { 174500000, 62500, 0xce, 0x01 },
  213. { 230000000, 62500, 0xce, 0x02 },
  214. { 999999999, 62500, 0xce, 0x04 },
  215. },
  216. };
  217. /* ALPS TDED4
  218. * used in Nebula-Cards and USB boxes
  219. */
  220. static void tded4_bw(struct dvb_frontend *fe, u8 *buf,
  221. const struct dvb_frontend_parameters *params)
  222. {
  223. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  224. buf[3] |= 0x04;
  225. }
  226. static struct dvb_pll_desc dvb_pll_tded4 = {
  227. .name = "ALPS TDED4",
  228. .min = 47000000,
  229. .max = 863000000,
  230. .iffreq= 36166667,
  231. .set = tded4_bw,
  232. .count = 4,
  233. .entries = {
  234. { 153000000, 166667, 0x85, 0x01 },
  235. { 470000000, 166667, 0x85, 0x02 },
  236. { 823000000, 166667, 0x85, 0x08 },
  237. { 999999999, 166667, 0x85, 0x88 },
  238. }
  239. };
  240. /* ALPS TDHU2
  241. * used in AverTVHD MCE A180
  242. */
  243. static struct dvb_pll_desc dvb_pll_tdhu2 = {
  244. .name = "ALPS TDHU2",
  245. .min = 54000000,
  246. .max = 864000000,
  247. .iffreq= 44000000,
  248. .count = 4,
  249. .entries = {
  250. { 162000000, 62500, 0x85, 0x01 },
  251. { 426000000, 62500, 0x85, 0x02 },
  252. { 782000000, 62500, 0x85, 0x08 },
  253. { 999999999, 62500, 0x85, 0x88 },
  254. }
  255. };
  256. /* Samsung TBMV30111IN / TBMV30712IN1
  257. * used in Air2PC ATSC - 2nd generation (nxt2002)
  258. */
  259. static struct dvb_pll_desc dvb_pll_samsung_tbmv = {
  260. .name = "Samsung TBMV30111IN / TBMV30712IN1",
  261. .min = 54000000,
  262. .max = 860000000,
  263. .iffreq= 44000000,
  264. .count = 6,
  265. .entries = {
  266. { 172000000, 166667, 0xb4, 0x01 },
  267. { 214000000, 166667, 0xb4, 0x02 },
  268. { 467000000, 166667, 0xbc, 0x02 },
  269. { 721000000, 166667, 0xbc, 0x08 },
  270. { 841000000, 166667, 0xf4, 0x08 },
  271. { 999999999, 166667, 0xfc, 0x02 },
  272. }
  273. };
  274. /*
  275. * Philips SD1878 Tuner.
  276. */
  277. static struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
  278. .name = "Philips SD1878",
  279. .min = 950000,
  280. .max = 2150000,
  281. .iffreq= 249, /* zero-IF, offset 249 is to round up */
  282. .count = 4,
  283. .entries = {
  284. { 1250000, 500, 0xc4, 0x00},
  285. { 1450000, 500, 0xc4, 0x40},
  286. { 2050000, 500, 0xc4, 0x80},
  287. { 2150000, 500, 0xc4, 0xc0},
  288. },
  289. };
  290. static void opera1_bw(struct dvb_frontend *fe, u8 *buf,
  291. const struct dvb_frontend_parameters *params)
  292. {
  293. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  294. buf[2] |= 0x08;
  295. }
  296. static struct dvb_pll_desc dvb_pll_opera1 = {
  297. .name = "Opera Tuner",
  298. .min = 900000,
  299. .max = 2250000,
  300. .iffreq= 0,
  301. .set = opera1_bw,
  302. .count = 8,
  303. .entries = {
  304. { 1064000, 500, 0xe5, 0xc6 },
  305. { 1169000, 500, 0xe5, 0xe6 },
  306. { 1299000, 500, 0xe5, 0x24 },
  307. { 1444000, 500, 0xe5, 0x44 },
  308. { 1606000, 500, 0xe5, 0x64 },
  309. { 1777000, 500, 0xe5, 0x84 },
  310. { 1941000, 500, 0xe5, 0xa4 },
  311. { 2250000, 500, 0xe5, 0xc4 },
  312. }
  313. };
  314. static void samsung_dtos403ih102a_set(struct dvb_frontend *fe, u8 *buf,
  315. const struct dvb_frontend_parameters *params)
  316. {
  317. struct dvb_pll_priv *priv = fe->tuner_priv;
  318. struct i2c_msg msg = {
  319. .addr = priv->pll_i2c_address,
  320. .flags = 0,
  321. .buf = buf,
  322. .len = 4
  323. };
  324. int result;
  325. if (fe->ops.i2c_gate_ctrl)
  326. fe->ops.i2c_gate_ctrl(fe, 1);
  327. result = i2c_transfer(priv->i2c, &msg, 1);
  328. if (result != 1)
  329. printk(KERN_ERR "%s: i2c_transfer failed:%d",
  330. __func__, result);
  331. buf[2] = 0x9e;
  332. buf[3] = 0x90;
  333. return;
  334. }
  335. /* unknown pll used in Samsung DTOS403IH102A DVB-C tuner */
  336. static struct dvb_pll_desc dvb_pll_samsung_dtos403ih102a = {
  337. .name = "Samsung DTOS403IH102A",
  338. .min = 44250000,
  339. .max = 858000000,
  340. .iffreq = 36125000,
  341. .count = 8,
  342. .set = samsung_dtos403ih102a_set,
  343. .entries = {
  344. { 135000000, 62500, 0xbe, 0x01 },
  345. { 177000000, 62500, 0xf6, 0x01 },
  346. { 370000000, 62500, 0xbe, 0x02 },
  347. { 450000000, 62500, 0xf6, 0x02 },
  348. { 466000000, 62500, 0xfe, 0x02 },
  349. { 538000000, 62500, 0xbe, 0x08 },
  350. { 826000000, 62500, 0xf6, 0x08 },
  351. { 999999999, 62500, 0xfe, 0x08 },
  352. }
  353. };
  354. /* Samsung TDTC9251DH0 DVB-T NIM, as used on AirStar 2 */
  355. static struct dvb_pll_desc dvb_pll_samsung_tdtc9251dh0 = {
  356. .name = "Samsung TDTC9251DH0",
  357. .min = 48000000,
  358. .max = 863000000,
  359. .iffreq = 36166667,
  360. .count = 3,
  361. .entries = {
  362. { 157500000, 166667, 0xcc, 0x09 },
  363. { 443000000, 166667, 0xcc, 0x0a },
  364. { 863000000, 166667, 0xcc, 0x08 },
  365. }
  366. };
  367. /* ----------------------------------------------------------- */
  368. static struct dvb_pll_desc *pll_list[] = {
  369. [DVB_PLL_UNDEFINED] = NULL,
  370. [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579,
  371. [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x,
  372. [DVB_PLL_LG_Z201] = &dvb_pll_lg_z201,
  373. [DVB_PLL_UNKNOWN_1] = &dvb_pll_unknown_1,
  374. [DVB_PLL_TUA6010XS] = &dvb_pll_tua6010xs,
  375. [DVB_PLL_ENV57H1XD5] = &dvb_pll_env57h1xd5,
  376. [DVB_PLL_TUA6034] = &dvb_pll_tua6034,
  377. [DVB_PLL_TDA665X] = &dvb_pll_tda665x,
  378. [DVB_PLL_TDED4] = &dvb_pll_tded4,
  379. [DVB_PLL_TDHU2] = &dvb_pll_tdhu2,
  380. [DVB_PLL_SAMSUNG_TBMV] = &dvb_pll_samsung_tbmv,
  381. [DVB_PLL_PHILIPS_SD1878_TDA8261] = &dvb_pll_philips_sd1878_tda8261,
  382. [DVB_PLL_OPERA1] = &dvb_pll_opera1,
  383. [DVB_PLL_SAMSUNG_DTOS403IH102A] = &dvb_pll_samsung_dtos403ih102a,
  384. [DVB_PLL_SAMSUNG_TDTC9251DH0] = &dvb_pll_samsung_tdtc9251dh0,
  385. };
  386. /* ----------------------------------------------------------- */
  387. /* code */
  388. static int dvb_pll_configure(struct dvb_frontend *fe, u8 *buf,
  389. const struct dvb_frontend_parameters *params)
  390. {
  391. struct dvb_pll_priv *priv = fe->tuner_priv;
  392. struct dvb_pll_desc *desc = priv->pll_desc;
  393. u32 div;
  394. int i;
  395. if (params->frequency != 0 && (params->frequency < desc->min ||
  396. params->frequency > desc->max))
  397. return -EINVAL;
  398. for (i = 0; i < desc->count; i++) {
  399. if (params->frequency > desc->entries[i].limit)
  400. continue;
  401. break;
  402. }
  403. if (debug)
  404. printk("pll: %s: freq=%d | i=%d/%d\n", desc->name,
  405. params->frequency, i, desc->count);
  406. if (i == desc->count)
  407. return -EINVAL;
  408. div = (params->frequency + desc->iffreq +
  409. desc->entries[i].stepsize/2) / desc->entries[i].stepsize;
  410. buf[0] = div >> 8;
  411. buf[1] = div & 0xff;
  412. buf[2] = desc->entries[i].config;
  413. buf[3] = desc->entries[i].cb;
  414. if (desc->set)
  415. desc->set(fe, buf, params);
  416. if (debug)
  417. printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
  418. desc->name, div, buf[0], buf[1], buf[2], buf[3]);
  419. // calculate the frequency we set it to
  420. return (div * desc->entries[i].stepsize) - desc->iffreq;
  421. }
  422. static int dvb_pll_release(struct dvb_frontend *fe)
  423. {
  424. kfree(fe->tuner_priv);
  425. fe->tuner_priv = NULL;
  426. return 0;
  427. }
  428. static int dvb_pll_sleep(struct dvb_frontend *fe)
  429. {
  430. struct dvb_pll_priv *priv = fe->tuner_priv;
  431. if (priv->i2c == NULL)
  432. return -EINVAL;
  433. if (priv->pll_desc->sleepdata) {
  434. struct i2c_msg msg = { .flags = 0,
  435. .addr = priv->pll_i2c_address,
  436. .buf = priv->pll_desc->sleepdata + 1,
  437. .len = priv->pll_desc->sleepdata[0] };
  438. int result;
  439. if (fe->ops.i2c_gate_ctrl)
  440. fe->ops.i2c_gate_ctrl(fe, 1);
  441. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  442. return result;
  443. }
  444. return 0;
  445. }
  446. /* Shouldn't be called when initdata is NULL, maybe BUG()? */
  447. return -EINVAL;
  448. }
  449. static int dvb_pll_set_params(struct dvb_frontend *fe,
  450. struct dvb_frontend_parameters *params)
  451. {
  452. struct dvb_pll_priv *priv = fe->tuner_priv;
  453. u8 buf[4];
  454. struct i2c_msg msg =
  455. { .addr = priv->pll_i2c_address, .flags = 0,
  456. .buf = buf, .len = sizeof(buf) };
  457. int result;
  458. u32 frequency = 0;
  459. if (priv->i2c == NULL)
  460. return -EINVAL;
  461. if ((result = dvb_pll_configure(fe, buf, params)) < 0)
  462. return result;
  463. else
  464. frequency = result;
  465. if (fe->ops.i2c_gate_ctrl)
  466. fe->ops.i2c_gate_ctrl(fe, 1);
  467. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  468. return result;
  469. }
  470. priv->frequency = frequency;
  471. priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
  472. return 0;
  473. }
  474. static int dvb_pll_calc_regs(struct dvb_frontend *fe,
  475. struct dvb_frontend_parameters *params,
  476. u8 *buf, int buf_len)
  477. {
  478. struct dvb_pll_priv *priv = fe->tuner_priv;
  479. int result;
  480. u32 frequency = 0;
  481. if (buf_len < 5)
  482. return -EINVAL;
  483. if ((result = dvb_pll_configure(fe, buf+1, params)) < 0)
  484. return result;
  485. else
  486. frequency = result;
  487. buf[0] = priv->pll_i2c_address;
  488. priv->frequency = frequency;
  489. priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
  490. return 5;
  491. }
  492. static int dvb_pll_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  493. {
  494. struct dvb_pll_priv *priv = fe->tuner_priv;
  495. *frequency = priv->frequency;
  496. return 0;
  497. }
  498. static int dvb_pll_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
  499. {
  500. struct dvb_pll_priv *priv = fe->tuner_priv;
  501. *bandwidth = priv->bandwidth;
  502. return 0;
  503. }
  504. static int dvb_pll_init(struct dvb_frontend *fe)
  505. {
  506. struct dvb_pll_priv *priv = fe->tuner_priv;
  507. if (priv->i2c == NULL)
  508. return -EINVAL;
  509. if (priv->pll_desc->initdata) {
  510. struct i2c_msg msg = { .flags = 0,
  511. .addr = priv->pll_i2c_address,
  512. .buf = priv->pll_desc->initdata + 1,
  513. .len = priv->pll_desc->initdata[0] };
  514. int result;
  515. if (fe->ops.i2c_gate_ctrl)
  516. fe->ops.i2c_gate_ctrl(fe, 1);
  517. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  518. return result;
  519. }
  520. return 0;
  521. }
  522. /* Shouldn't be called when initdata is NULL, maybe BUG()? */
  523. return -EINVAL;
  524. }
  525. static struct dvb_tuner_ops dvb_pll_tuner_ops = {
  526. .release = dvb_pll_release,
  527. .sleep = dvb_pll_sleep,
  528. .init = dvb_pll_init,
  529. .set_params = dvb_pll_set_params,
  530. .calc_regs = dvb_pll_calc_regs,
  531. .get_frequency = dvb_pll_get_frequency,
  532. .get_bandwidth = dvb_pll_get_bandwidth,
  533. };
  534. struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
  535. struct i2c_adapter *i2c,
  536. unsigned int pll_desc_id)
  537. {
  538. u8 b1 [] = { 0 };
  539. struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD,
  540. .buf = b1, .len = 1 };
  541. struct dvb_pll_priv *priv = NULL;
  542. int ret;
  543. struct dvb_pll_desc *desc;
  544. if ((id[dvb_pll_devcount] > DVB_PLL_UNDEFINED) &&
  545. (id[dvb_pll_devcount] < ARRAY_SIZE(pll_list)))
  546. pll_desc_id = id[dvb_pll_devcount];
  547. BUG_ON(pll_desc_id < 1 || pll_desc_id >= ARRAY_SIZE(pll_list));
  548. desc = pll_list[pll_desc_id];
  549. if (i2c != NULL) {
  550. if (fe->ops.i2c_gate_ctrl)
  551. fe->ops.i2c_gate_ctrl(fe, 1);
  552. ret = i2c_transfer (i2c, &msg, 1);
  553. if (ret != 1)
  554. return NULL;
  555. if (fe->ops.i2c_gate_ctrl)
  556. fe->ops.i2c_gate_ctrl(fe, 0);
  557. }
  558. priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL);
  559. if (priv == NULL)
  560. return NULL;
  561. priv->pll_i2c_address = pll_addr;
  562. priv->i2c = i2c;
  563. priv->pll_desc = desc;
  564. priv->nr = dvb_pll_devcount++;
  565. memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops,
  566. sizeof(struct dvb_tuner_ops));
  567. strncpy(fe->ops.tuner_ops.info.name, desc->name,
  568. sizeof(fe->ops.tuner_ops.info.name));
  569. fe->ops.tuner_ops.info.frequency_min = desc->min;
  570. fe->ops.tuner_ops.info.frequency_max = desc->max;
  571. if (!desc->initdata)
  572. fe->ops.tuner_ops.init = NULL;
  573. if (!desc->sleepdata)
  574. fe->ops.tuner_ops.sleep = NULL;
  575. fe->tuner_priv = priv;
  576. if ((debug) || (id[priv->nr] == pll_desc_id)) {
  577. printk("dvb-pll[%d]", priv->nr);
  578. if (i2c != NULL)
  579. printk(" %d-%04x", i2c_adapter_id(i2c), pll_addr);
  580. printk(": id# %d (%s) attached, %s\n", pll_desc_id, desc->name,
  581. id[priv->nr] == pll_desc_id ?
  582. "insmod option" : "autodetected");
  583. }
  584. return fe;
  585. }
  586. EXPORT_SYMBOL(dvb_pll_attach);
  587. MODULE_DESCRIPTION("dvb pll library");
  588. MODULE_AUTHOR("Gerd Knorr");
  589. MODULE_LICENSE("GPL");