dvb-pll.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. /* ----------------------------------------------------------- */
  355. static struct dvb_pll_desc *pll_list[] = {
  356. [DVB_PLL_UNDEFINED] = NULL,
  357. [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579,
  358. [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x,
  359. [DVB_PLL_LG_Z201] = &dvb_pll_lg_z201,
  360. [DVB_PLL_UNKNOWN_1] = &dvb_pll_unknown_1,
  361. [DVB_PLL_TUA6010XS] = &dvb_pll_tua6010xs,
  362. [DVB_PLL_ENV57H1XD5] = &dvb_pll_env57h1xd5,
  363. [DVB_PLL_TUA6034] = &dvb_pll_tua6034,
  364. [DVB_PLL_TDA665X] = &dvb_pll_tda665x,
  365. [DVB_PLL_TDED4] = &dvb_pll_tded4,
  366. [DVB_PLL_TDHU2] = &dvb_pll_tdhu2,
  367. [DVB_PLL_SAMSUNG_TBMV] = &dvb_pll_samsung_tbmv,
  368. [DVB_PLL_PHILIPS_SD1878_TDA8261] = &dvb_pll_philips_sd1878_tda8261,
  369. [DVB_PLL_OPERA1] = &dvb_pll_opera1,
  370. [DVB_PLL_SAMSUNG_DTOS403IH102A] = &dvb_pll_samsung_dtos403ih102a,
  371. };
  372. /* ----------------------------------------------------------- */
  373. /* code */
  374. static int dvb_pll_configure(struct dvb_frontend *fe, u8 *buf,
  375. const struct dvb_frontend_parameters *params)
  376. {
  377. struct dvb_pll_priv *priv = fe->tuner_priv;
  378. struct dvb_pll_desc *desc = priv->pll_desc;
  379. u32 div;
  380. int i;
  381. if (params->frequency != 0 && (params->frequency < desc->min ||
  382. params->frequency > desc->max))
  383. return -EINVAL;
  384. for (i = 0; i < desc->count; i++) {
  385. if (params->frequency > desc->entries[i].limit)
  386. continue;
  387. break;
  388. }
  389. if (debug)
  390. printk("pll: %s: freq=%d | i=%d/%d\n", desc->name,
  391. params->frequency, i, desc->count);
  392. if (i == desc->count)
  393. return -EINVAL;
  394. div = (params->frequency + desc->iffreq +
  395. desc->entries[i].stepsize/2) / desc->entries[i].stepsize;
  396. buf[0] = div >> 8;
  397. buf[1] = div & 0xff;
  398. buf[2] = desc->entries[i].config;
  399. buf[3] = desc->entries[i].cb;
  400. if (desc->set)
  401. desc->set(fe, buf, params);
  402. if (debug)
  403. printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
  404. desc->name, div, buf[0], buf[1], buf[2], buf[3]);
  405. // calculate the frequency we set it to
  406. return (div * desc->entries[i].stepsize) - desc->iffreq;
  407. }
  408. static int dvb_pll_release(struct dvb_frontend *fe)
  409. {
  410. kfree(fe->tuner_priv);
  411. fe->tuner_priv = NULL;
  412. return 0;
  413. }
  414. static int dvb_pll_sleep(struct dvb_frontend *fe)
  415. {
  416. struct dvb_pll_priv *priv = fe->tuner_priv;
  417. if (priv->i2c == NULL)
  418. return -EINVAL;
  419. if (priv->pll_desc->sleepdata) {
  420. struct i2c_msg msg = { .flags = 0,
  421. .addr = priv->pll_i2c_address,
  422. .buf = priv->pll_desc->sleepdata + 1,
  423. .len = priv->pll_desc->sleepdata[0] };
  424. int result;
  425. if (fe->ops.i2c_gate_ctrl)
  426. fe->ops.i2c_gate_ctrl(fe, 1);
  427. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  428. return result;
  429. }
  430. return 0;
  431. }
  432. /* Shouldn't be called when initdata is NULL, maybe BUG()? */
  433. return -EINVAL;
  434. }
  435. static int dvb_pll_set_params(struct dvb_frontend *fe,
  436. struct dvb_frontend_parameters *params)
  437. {
  438. struct dvb_pll_priv *priv = fe->tuner_priv;
  439. u8 buf[4];
  440. struct i2c_msg msg =
  441. { .addr = priv->pll_i2c_address, .flags = 0,
  442. .buf = buf, .len = sizeof(buf) };
  443. int result;
  444. u32 frequency = 0;
  445. if (priv->i2c == NULL)
  446. return -EINVAL;
  447. if ((result = dvb_pll_configure(fe, buf, params)) < 0)
  448. return result;
  449. else
  450. frequency = result;
  451. if (fe->ops.i2c_gate_ctrl)
  452. fe->ops.i2c_gate_ctrl(fe, 1);
  453. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  454. return result;
  455. }
  456. priv->frequency = frequency;
  457. priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
  458. return 0;
  459. }
  460. static int dvb_pll_calc_regs(struct dvb_frontend *fe,
  461. struct dvb_frontend_parameters *params,
  462. u8 *buf, int buf_len)
  463. {
  464. struct dvb_pll_priv *priv = fe->tuner_priv;
  465. int result;
  466. u32 frequency = 0;
  467. if (buf_len < 5)
  468. return -EINVAL;
  469. if ((result = dvb_pll_configure(fe, buf+1, params)) < 0)
  470. return result;
  471. else
  472. frequency = result;
  473. buf[0] = priv->pll_i2c_address;
  474. priv->frequency = frequency;
  475. priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
  476. return 5;
  477. }
  478. static int dvb_pll_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  479. {
  480. struct dvb_pll_priv *priv = fe->tuner_priv;
  481. *frequency = priv->frequency;
  482. return 0;
  483. }
  484. static int dvb_pll_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
  485. {
  486. struct dvb_pll_priv *priv = fe->tuner_priv;
  487. *bandwidth = priv->bandwidth;
  488. return 0;
  489. }
  490. static int dvb_pll_init(struct dvb_frontend *fe)
  491. {
  492. struct dvb_pll_priv *priv = fe->tuner_priv;
  493. if (priv->i2c == NULL)
  494. return -EINVAL;
  495. if (priv->pll_desc->initdata) {
  496. struct i2c_msg msg = { .flags = 0,
  497. .addr = priv->pll_i2c_address,
  498. .buf = priv->pll_desc->initdata + 1,
  499. .len = priv->pll_desc->initdata[0] };
  500. int result;
  501. if (fe->ops.i2c_gate_ctrl)
  502. fe->ops.i2c_gate_ctrl(fe, 1);
  503. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  504. return result;
  505. }
  506. return 0;
  507. }
  508. /* Shouldn't be called when initdata is NULL, maybe BUG()? */
  509. return -EINVAL;
  510. }
  511. static struct dvb_tuner_ops dvb_pll_tuner_ops = {
  512. .release = dvb_pll_release,
  513. .sleep = dvb_pll_sleep,
  514. .init = dvb_pll_init,
  515. .set_params = dvb_pll_set_params,
  516. .calc_regs = dvb_pll_calc_regs,
  517. .get_frequency = dvb_pll_get_frequency,
  518. .get_bandwidth = dvb_pll_get_bandwidth,
  519. };
  520. struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
  521. struct i2c_adapter *i2c,
  522. unsigned int pll_desc_id)
  523. {
  524. u8 b1 [] = { 0 };
  525. struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD,
  526. .buf = b1, .len = 1 };
  527. struct dvb_pll_priv *priv = NULL;
  528. int ret;
  529. struct dvb_pll_desc *desc;
  530. if ((id[dvb_pll_devcount] > DVB_PLL_UNDEFINED) &&
  531. (id[dvb_pll_devcount] < ARRAY_SIZE(pll_list)))
  532. pll_desc_id = id[dvb_pll_devcount];
  533. BUG_ON(pll_desc_id < 1 || pll_desc_id >= ARRAY_SIZE(pll_list));
  534. desc = pll_list[pll_desc_id];
  535. if (i2c != NULL) {
  536. if (fe->ops.i2c_gate_ctrl)
  537. fe->ops.i2c_gate_ctrl(fe, 1);
  538. ret = i2c_transfer (i2c, &msg, 1);
  539. if (ret != 1)
  540. return NULL;
  541. if (fe->ops.i2c_gate_ctrl)
  542. fe->ops.i2c_gate_ctrl(fe, 0);
  543. }
  544. priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL);
  545. if (priv == NULL)
  546. return NULL;
  547. priv->pll_i2c_address = pll_addr;
  548. priv->i2c = i2c;
  549. priv->pll_desc = desc;
  550. priv->nr = dvb_pll_devcount++;
  551. memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops,
  552. sizeof(struct dvb_tuner_ops));
  553. strncpy(fe->ops.tuner_ops.info.name, desc->name,
  554. sizeof(fe->ops.tuner_ops.info.name));
  555. fe->ops.tuner_ops.info.frequency_min = desc->min;
  556. fe->ops.tuner_ops.info.frequency_max = desc->max;
  557. if (!desc->initdata)
  558. fe->ops.tuner_ops.init = NULL;
  559. if (!desc->sleepdata)
  560. fe->ops.tuner_ops.sleep = NULL;
  561. fe->tuner_priv = priv;
  562. if ((debug) || (id[priv->nr] == pll_desc_id)) {
  563. printk("dvb-pll[%d]", priv->nr);
  564. if (i2c != NULL)
  565. printk(" %d-%04x", i2c_adapter_id(i2c), pll_addr);
  566. printk(": id# %d (%s) attached, %s\n", pll_desc_id, desc->name,
  567. id[priv->nr] == pll_desc_id ?
  568. "insmod option" : "autodetected");
  569. }
  570. return fe;
  571. }
  572. EXPORT_SYMBOL(dvb_pll_attach);
  573. MODULE_DESCRIPTION("dvb pll library");
  574. MODULE_AUTHOR("Gerd Knorr");
  575. MODULE_LICENSE("GPL");