dvb-pll.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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/slab.h>
  21. #include <linux/module.h>
  22. #include <linux/dvb/frontend.h>
  23. #include <asm/types.h>
  24. #include "dvb-pll.h"
  25. struct dvb_pll_priv {
  26. /* pll number */
  27. int nr;
  28. /* i2c details */
  29. int pll_i2c_address;
  30. struct i2c_adapter *i2c;
  31. /* the PLL descriptor */
  32. struct dvb_pll_desc *pll_desc;
  33. /* cached frequency/bandwidth */
  34. u32 frequency;
  35. u32 bandwidth;
  36. };
  37. #define DVB_PLL_MAX 64
  38. static unsigned int dvb_pll_devcount;
  39. static int debug;
  40. module_param(debug, int, 0644);
  41. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  42. static unsigned int id[DVB_PLL_MAX] =
  43. { [ 0 ... (DVB_PLL_MAX-1) ] = DVB_PLL_UNDEFINED };
  44. module_param_array(id, int, NULL, 0644);
  45. MODULE_PARM_DESC(id, "force pll id to use (DEBUG ONLY)");
  46. /* ----------------------------------------------------------- */
  47. struct dvb_pll_desc {
  48. char *name;
  49. u32 min;
  50. u32 max;
  51. u32 iffreq;
  52. void (*set)(struct dvb_frontend *fe, u8 *buf,
  53. const struct dvb_frontend_parameters *params);
  54. u8 *initdata;
  55. u8 *initdata2;
  56. u8 *sleepdata;
  57. int count;
  58. struct {
  59. u32 limit;
  60. u32 stepsize;
  61. u8 config;
  62. u8 cb;
  63. } entries[12];
  64. };
  65. /* ----------------------------------------------------------- */
  66. /* descriptions */
  67. static struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
  68. .name = "Thomson dtt7579",
  69. .min = 177000000,
  70. .max = 858000000,
  71. .iffreq= 36166667,
  72. .sleepdata = (u8[]){ 2, 0xb4, 0x03 },
  73. .count = 4,
  74. .entries = {
  75. { 443250000, 166667, 0xb4, 0x02 },
  76. { 542000000, 166667, 0xb4, 0x08 },
  77. { 771000000, 166667, 0xbc, 0x08 },
  78. { 999999999, 166667, 0xf4, 0x08 },
  79. },
  80. };
  81. static void thomson_dtt759x_bw(struct dvb_frontend *fe, u8 *buf,
  82. const struct dvb_frontend_parameters *params)
  83. {
  84. if (BANDWIDTH_7_MHZ == params->u.ofdm.bandwidth)
  85. buf[3] |= 0x10;
  86. }
  87. static struct dvb_pll_desc dvb_pll_thomson_dtt759x = {
  88. .name = "Thomson dtt759x",
  89. .min = 177000000,
  90. .max = 896000000,
  91. .set = thomson_dtt759x_bw,
  92. .iffreq= 36166667,
  93. .sleepdata = (u8[]){ 2, 0x84, 0x03 },
  94. .count = 5,
  95. .entries = {
  96. { 264000000, 166667, 0xb4, 0x02 },
  97. { 470000000, 166667, 0xbc, 0x02 },
  98. { 735000000, 166667, 0xbc, 0x08 },
  99. { 835000000, 166667, 0xf4, 0x08 },
  100. { 999999999, 166667, 0xfc, 0x08 },
  101. },
  102. };
  103. static struct dvb_pll_desc dvb_pll_lg_z201 = {
  104. .name = "LG z201",
  105. .min = 174000000,
  106. .max = 862000000,
  107. .iffreq= 36166667,
  108. .sleepdata = (u8[]){ 2, 0xbc, 0x03 },
  109. .count = 5,
  110. .entries = {
  111. { 157500000, 166667, 0xbc, 0x01 },
  112. { 443250000, 166667, 0xbc, 0x02 },
  113. { 542000000, 166667, 0xbc, 0x04 },
  114. { 830000000, 166667, 0xf4, 0x04 },
  115. { 999999999, 166667, 0xfc, 0x04 },
  116. },
  117. };
  118. static struct dvb_pll_desc dvb_pll_unknown_1 = {
  119. .name = "unknown 1", /* used by dntv live dvb-t */
  120. .min = 174000000,
  121. .max = 862000000,
  122. .iffreq= 36166667,
  123. .count = 9,
  124. .entries = {
  125. { 150000000, 166667, 0xb4, 0x01 },
  126. { 173000000, 166667, 0xbc, 0x01 },
  127. { 250000000, 166667, 0xb4, 0x02 },
  128. { 400000000, 166667, 0xbc, 0x02 },
  129. { 420000000, 166667, 0xf4, 0x02 },
  130. { 470000000, 166667, 0xfc, 0x02 },
  131. { 600000000, 166667, 0xbc, 0x08 },
  132. { 730000000, 166667, 0xf4, 0x08 },
  133. { 999999999, 166667, 0xfc, 0x08 },
  134. },
  135. };
  136. /* Infineon TUA6010XS
  137. * used in Thomson Cable Tuner
  138. */
  139. static struct dvb_pll_desc dvb_pll_tua6010xs = {
  140. .name = "Infineon TUA6010XS",
  141. .min = 44250000,
  142. .max = 858000000,
  143. .iffreq= 36125000,
  144. .count = 3,
  145. .entries = {
  146. { 115750000, 62500, 0x8e, 0x03 },
  147. { 403250000, 62500, 0x8e, 0x06 },
  148. { 999999999, 62500, 0x8e, 0x85 },
  149. },
  150. };
  151. /* Panasonic env57h1xd5 (some Philips PLL ?) */
  152. static struct dvb_pll_desc dvb_pll_env57h1xd5 = {
  153. .name = "Panasonic ENV57H1XD5",
  154. .min = 44250000,
  155. .max = 858000000,
  156. .iffreq= 36125000,
  157. .count = 4,
  158. .entries = {
  159. { 153000000, 166667, 0xc2, 0x41 },
  160. { 470000000, 166667, 0xc2, 0x42 },
  161. { 526000000, 166667, 0xc2, 0x84 },
  162. { 999999999, 166667, 0xc2, 0xa4 },
  163. },
  164. };
  165. /* Philips TDA6650/TDA6651
  166. * used in Panasonic ENV77H11D5
  167. */
  168. static void tda665x_bw(struct dvb_frontend *fe, u8 *buf,
  169. const struct dvb_frontend_parameters *params)
  170. {
  171. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  172. buf[3] |= 0x08;
  173. }
  174. static struct dvb_pll_desc dvb_pll_tda665x = {
  175. .name = "Philips TDA6650/TDA6651",
  176. .min = 44250000,
  177. .max = 858000000,
  178. .set = tda665x_bw,
  179. .iffreq= 36166667,
  180. .initdata = (u8[]){ 4, 0x0b, 0xf5, 0x85, 0xab },
  181. .count = 12,
  182. .entries = {
  183. { 93834000, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
  184. { 123834000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  185. { 161000000, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  186. { 163834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  187. { 253834000, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
  188. { 383834000, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
  189. { 443834000, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  190. { 444000000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
  191. { 583834000, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ },
  192. { 793834000, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ },
  193. { 444834000, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
  194. { 861000000, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ },
  195. }
  196. };
  197. /* Infineon TUA6034
  198. * used in LG TDTP E102P
  199. */
  200. static void tua6034_bw(struct dvb_frontend *fe, u8 *buf,
  201. const struct dvb_frontend_parameters *params)
  202. {
  203. if (BANDWIDTH_7_MHZ != params->u.ofdm.bandwidth)
  204. buf[3] |= 0x08;
  205. }
  206. static struct dvb_pll_desc dvb_pll_tua6034 = {
  207. .name = "Infineon TUA6034",
  208. .min = 44250000,
  209. .max = 858000000,
  210. .iffreq= 36166667,
  211. .count = 3,
  212. .set = tua6034_bw,
  213. .entries = {
  214. { 174500000, 62500, 0xce, 0x01 },
  215. { 230000000, 62500, 0xce, 0x02 },
  216. { 999999999, 62500, 0xce, 0x04 },
  217. },
  218. };
  219. /* ALPS TDED4
  220. * used in Nebula-Cards and USB boxes
  221. */
  222. static void tded4_bw(struct dvb_frontend *fe, u8 *buf,
  223. const struct dvb_frontend_parameters *params)
  224. {
  225. if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  226. buf[3] |= 0x04;
  227. }
  228. static struct dvb_pll_desc dvb_pll_tded4 = {
  229. .name = "ALPS TDED4",
  230. .min = 47000000,
  231. .max = 863000000,
  232. .iffreq= 36166667,
  233. .set = tded4_bw,
  234. .count = 4,
  235. .entries = {
  236. { 153000000, 166667, 0x85, 0x01 },
  237. { 470000000, 166667, 0x85, 0x02 },
  238. { 823000000, 166667, 0x85, 0x08 },
  239. { 999999999, 166667, 0x85, 0x88 },
  240. }
  241. };
  242. /* ALPS TDHU2
  243. * used in AverTVHD MCE A180
  244. */
  245. static struct dvb_pll_desc dvb_pll_tdhu2 = {
  246. .name = "ALPS TDHU2",
  247. .min = 54000000,
  248. .max = 864000000,
  249. .iffreq= 44000000,
  250. .count = 4,
  251. .entries = {
  252. { 162000000, 62500, 0x85, 0x01 },
  253. { 426000000, 62500, 0x85, 0x02 },
  254. { 782000000, 62500, 0x85, 0x08 },
  255. { 999999999, 62500, 0x85, 0x88 },
  256. }
  257. };
  258. /* Samsung TBMV30111IN / TBMV30712IN1
  259. * used in Air2PC ATSC - 2nd generation (nxt2002)
  260. */
  261. static struct dvb_pll_desc dvb_pll_samsung_tbmv = {
  262. .name = "Samsung TBMV30111IN / TBMV30712IN1",
  263. .min = 54000000,
  264. .max = 860000000,
  265. .iffreq= 44000000,
  266. .count = 6,
  267. .entries = {
  268. { 172000000, 166667, 0xb4, 0x01 },
  269. { 214000000, 166667, 0xb4, 0x02 },
  270. { 467000000, 166667, 0xbc, 0x02 },
  271. { 721000000, 166667, 0xbc, 0x08 },
  272. { 841000000, 166667, 0xf4, 0x08 },
  273. { 999999999, 166667, 0xfc, 0x02 },
  274. }
  275. };
  276. /*
  277. * Philips SD1878 Tuner.
  278. */
  279. static struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
  280. .name = "Philips SD1878",
  281. .min = 950000,
  282. .max = 2150000,
  283. .iffreq= 249, /* zero-IF, offset 249 is to round up */
  284. .count = 4,
  285. .entries = {
  286. { 1250000, 500, 0xc4, 0x00},
  287. { 1450000, 500, 0xc4, 0x40},
  288. { 2050000, 500, 0xc4, 0x80},
  289. { 2150000, 500, 0xc4, 0xc0},
  290. },
  291. };
  292. static void opera1_bw(struct dvb_frontend *fe, u8 *buf,
  293. const struct dvb_frontend_parameters *params)
  294. {
  295. struct dvb_pll_priv *priv = fe->tuner_priv;
  296. u32 b_w = (params->u.qpsk.symbol_rate * 27) / 32000;
  297. struct i2c_msg msg = {
  298. .addr = priv->pll_i2c_address,
  299. .flags = 0,
  300. .buf = buf,
  301. .len = 4
  302. };
  303. int result;
  304. u8 lpf;
  305. if (fe->ops.i2c_gate_ctrl)
  306. fe->ops.i2c_gate_ctrl(fe, 1);
  307. result = i2c_transfer(priv->i2c, &msg, 1);
  308. if (result != 1)
  309. printk(KERN_ERR "%s: i2c_transfer failed:%d",
  310. __func__, result);
  311. if (b_w <= 10000)
  312. lpf = 0xc;
  313. else if (b_w <= 12000)
  314. lpf = 0x2;
  315. else if (b_w <= 14000)
  316. lpf = 0xa;
  317. else if (b_w <= 16000)
  318. lpf = 0x6;
  319. else if (b_w <= 18000)
  320. lpf = 0xe;
  321. else if (b_w <= 20000)
  322. lpf = 0x1;
  323. else if (b_w <= 22000)
  324. lpf = 0x9;
  325. else if (b_w <= 24000)
  326. lpf = 0x5;
  327. else if (b_w <= 26000)
  328. lpf = 0xd;
  329. else if (b_w <= 28000)
  330. lpf = 0x3;
  331. else
  332. lpf = 0xb;
  333. buf[2] ^= 0x1c; /* Flip bits 3-5 */
  334. /* Set lpf */
  335. buf[2] |= ((lpf >> 2) & 0x3) << 3;
  336. buf[3] |= (lpf & 0x3) << 2;
  337. return;
  338. }
  339. static struct dvb_pll_desc dvb_pll_opera1 = {
  340. .name = "Opera Tuner",
  341. .min = 900000,
  342. .max = 2250000,
  343. .initdata = (u8[]){ 4, 0x08, 0xe5, 0xe1, 0x00 },
  344. .initdata2 = (u8[]){ 4, 0x08, 0xe5, 0xe5, 0x00 },
  345. .iffreq= 0,
  346. .set = opera1_bw,
  347. .count = 8,
  348. .entries = {
  349. { 1064000, 500, 0xf9, 0xc2 },
  350. { 1169000, 500, 0xf9, 0xe2 },
  351. { 1299000, 500, 0xf9, 0x20 },
  352. { 1444000, 500, 0xf9, 0x40 },
  353. { 1606000, 500, 0xf9, 0x60 },
  354. { 1777000, 500, 0xf9, 0x80 },
  355. { 1941000, 500, 0xf9, 0xa0 },
  356. { 2250000, 500, 0xf9, 0xc0 },
  357. }
  358. };
  359. static void samsung_dtos403ih102a_set(struct dvb_frontend *fe, u8 *buf,
  360. const struct dvb_frontend_parameters *params)
  361. {
  362. struct dvb_pll_priv *priv = fe->tuner_priv;
  363. struct i2c_msg msg = {
  364. .addr = priv->pll_i2c_address,
  365. .flags = 0,
  366. .buf = buf,
  367. .len = 4
  368. };
  369. int result;
  370. if (fe->ops.i2c_gate_ctrl)
  371. fe->ops.i2c_gate_ctrl(fe, 1);
  372. result = i2c_transfer(priv->i2c, &msg, 1);
  373. if (result != 1)
  374. printk(KERN_ERR "%s: i2c_transfer failed:%d",
  375. __func__, result);
  376. buf[2] = 0x9e;
  377. buf[3] = 0x90;
  378. return;
  379. }
  380. /* unknown pll used in Samsung DTOS403IH102A DVB-C tuner */
  381. static struct dvb_pll_desc dvb_pll_samsung_dtos403ih102a = {
  382. .name = "Samsung DTOS403IH102A",
  383. .min = 44250000,
  384. .max = 858000000,
  385. .iffreq = 36125000,
  386. .count = 8,
  387. .set = samsung_dtos403ih102a_set,
  388. .entries = {
  389. { 135000000, 62500, 0xbe, 0x01 },
  390. { 177000000, 62500, 0xf6, 0x01 },
  391. { 370000000, 62500, 0xbe, 0x02 },
  392. { 450000000, 62500, 0xf6, 0x02 },
  393. { 466000000, 62500, 0xfe, 0x02 },
  394. { 538000000, 62500, 0xbe, 0x08 },
  395. { 826000000, 62500, 0xf6, 0x08 },
  396. { 999999999, 62500, 0xfe, 0x08 },
  397. }
  398. };
  399. /* Samsung TDTC9251DH0 DVB-T NIM, as used on AirStar 2 */
  400. static struct dvb_pll_desc dvb_pll_samsung_tdtc9251dh0 = {
  401. .name = "Samsung TDTC9251DH0",
  402. .min = 48000000,
  403. .max = 863000000,
  404. .iffreq = 36166667,
  405. .count = 3,
  406. .entries = {
  407. { 157500000, 166667, 0xcc, 0x09 },
  408. { 443000000, 166667, 0xcc, 0x0a },
  409. { 863000000, 166667, 0xcc, 0x08 },
  410. }
  411. };
  412. /* Samsung TBDU18132 DVB-S NIM with TSA5059 PLL, used in SkyStar2 DVB-S 2.3 */
  413. static struct dvb_pll_desc dvb_pll_samsung_tbdu18132 = {
  414. .name = "Samsung TBDU18132",
  415. .min = 950000,
  416. .max = 2150000, /* guesses */
  417. .iffreq = 0,
  418. .count = 2,
  419. .entries = {
  420. { 1550000, 125, 0x84, 0x82 },
  421. { 4095937, 125, 0x84, 0x80 },
  422. }
  423. /* TSA5059 PLL has a 17 bit divisor rather than the 15 bits supported
  424. * by this driver. The two extra bits are 0x60 in the third byte. 15
  425. * bits is enough for over 4 GHz, which is enough to cover the range
  426. * of this tuner. We could use the additional divisor bits by adding
  427. * more entries, e.g.
  428. { 0x0ffff * 125 + 125/2, 125, 0x84 | 0x20, },
  429. { 0x17fff * 125 + 125/2, 125, 0x84 | 0x40, },
  430. { 0x1ffff * 125 + 125/2, 125, 0x84 | 0x60, }, */
  431. };
  432. /* Samsung TBMU24112 DVB-S NIM with SL1935 zero-IF tuner */
  433. static struct dvb_pll_desc dvb_pll_samsung_tbmu24112 = {
  434. .name = "Samsung TBMU24112",
  435. .min = 950000,
  436. .max = 2150000, /* guesses */
  437. .iffreq = 0,
  438. .count = 2,
  439. .entries = {
  440. { 1500000, 125, 0x84, 0x18 },
  441. { 9999999, 125, 0x84, 0x08 },
  442. }
  443. };
  444. /* Alps TDEE4 DVB-C NIM, used on Cablestar 2 */
  445. /* byte 4 : 1 * * AGD R3 R2 R1 R0
  446. * byte 5 : C1 * RE RTS BS4 BS3 BS2 BS1
  447. * AGD = 1, R3 R2 R1 R0 = 0 1 0 1 => byte 4 = 1**10101 = 0x95
  448. * Range(MHz) C1 * RE RTS BS4 BS3 BS2 BS1 Byte 5
  449. * 47 - 153 0 * 0 0 0 0 0 1 0x01
  450. * 153 - 430 0 * 0 0 0 0 1 0 0x02
  451. * 430 - 822 0 * 0 0 1 0 0 0 0x08
  452. * 822 - 862 1 * 0 0 1 0 0 0 0x88 */
  453. static struct dvb_pll_desc dvb_pll_alps_tdee4 = {
  454. .name = "ALPS TDEE4",
  455. .min = 47000000,
  456. .max = 862000000,
  457. .iffreq = 36125000,
  458. .count = 4,
  459. .entries = {
  460. { 153000000, 62500, 0x95, 0x01 },
  461. { 430000000, 62500, 0x95, 0x02 },
  462. { 822000000, 62500, 0x95, 0x08 },
  463. { 999999999, 62500, 0x95, 0x88 },
  464. }
  465. };
  466. /* ----------------------------------------------------------- */
  467. static struct dvb_pll_desc *pll_list[] = {
  468. [DVB_PLL_UNDEFINED] = NULL,
  469. [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579,
  470. [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x,
  471. [DVB_PLL_LG_Z201] = &dvb_pll_lg_z201,
  472. [DVB_PLL_UNKNOWN_1] = &dvb_pll_unknown_1,
  473. [DVB_PLL_TUA6010XS] = &dvb_pll_tua6010xs,
  474. [DVB_PLL_ENV57H1XD5] = &dvb_pll_env57h1xd5,
  475. [DVB_PLL_TUA6034] = &dvb_pll_tua6034,
  476. [DVB_PLL_TDA665X] = &dvb_pll_tda665x,
  477. [DVB_PLL_TDED4] = &dvb_pll_tded4,
  478. [DVB_PLL_TDEE4] = &dvb_pll_alps_tdee4,
  479. [DVB_PLL_TDHU2] = &dvb_pll_tdhu2,
  480. [DVB_PLL_SAMSUNG_TBMV] = &dvb_pll_samsung_tbmv,
  481. [DVB_PLL_PHILIPS_SD1878_TDA8261] = &dvb_pll_philips_sd1878_tda8261,
  482. [DVB_PLL_OPERA1] = &dvb_pll_opera1,
  483. [DVB_PLL_SAMSUNG_DTOS403IH102A] = &dvb_pll_samsung_dtos403ih102a,
  484. [DVB_PLL_SAMSUNG_TDTC9251DH0] = &dvb_pll_samsung_tdtc9251dh0,
  485. [DVB_PLL_SAMSUNG_TBDU18132] = &dvb_pll_samsung_tbdu18132,
  486. [DVB_PLL_SAMSUNG_TBMU24112] = &dvb_pll_samsung_tbmu24112,
  487. };
  488. /* ----------------------------------------------------------- */
  489. /* code */
  490. static int dvb_pll_configure(struct dvb_frontend *fe, u8 *buf,
  491. const struct dvb_frontend_parameters *params)
  492. {
  493. struct dvb_pll_priv *priv = fe->tuner_priv;
  494. struct dvb_pll_desc *desc = priv->pll_desc;
  495. u32 div;
  496. int i;
  497. if (params->frequency != 0 && (params->frequency < desc->min ||
  498. params->frequency > desc->max))
  499. return -EINVAL;
  500. for (i = 0; i < desc->count; i++) {
  501. if (params->frequency > desc->entries[i].limit)
  502. continue;
  503. break;
  504. }
  505. if (debug)
  506. printk("pll: %s: freq=%d | i=%d/%d\n", desc->name,
  507. params->frequency, i, desc->count);
  508. if (i == desc->count)
  509. return -EINVAL;
  510. div = (params->frequency + desc->iffreq +
  511. desc->entries[i].stepsize/2) / desc->entries[i].stepsize;
  512. buf[0] = div >> 8;
  513. buf[1] = div & 0xff;
  514. buf[2] = desc->entries[i].config;
  515. buf[3] = desc->entries[i].cb;
  516. if (desc->set)
  517. desc->set(fe, buf, params);
  518. if (debug)
  519. printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
  520. desc->name, div, buf[0], buf[1], buf[2], buf[3]);
  521. // calculate the frequency we set it to
  522. return (div * desc->entries[i].stepsize) - desc->iffreq;
  523. }
  524. static int dvb_pll_release(struct dvb_frontend *fe)
  525. {
  526. kfree(fe->tuner_priv);
  527. fe->tuner_priv = NULL;
  528. return 0;
  529. }
  530. static int dvb_pll_sleep(struct dvb_frontend *fe)
  531. {
  532. struct dvb_pll_priv *priv = fe->tuner_priv;
  533. if (priv->i2c == NULL)
  534. return -EINVAL;
  535. if (priv->pll_desc->sleepdata) {
  536. struct i2c_msg msg = { .flags = 0,
  537. .addr = priv->pll_i2c_address,
  538. .buf = priv->pll_desc->sleepdata + 1,
  539. .len = priv->pll_desc->sleepdata[0] };
  540. int result;
  541. if (fe->ops.i2c_gate_ctrl)
  542. fe->ops.i2c_gate_ctrl(fe, 1);
  543. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  544. return result;
  545. }
  546. return 0;
  547. }
  548. /* Shouldn't be called when initdata is NULL, maybe BUG()? */
  549. return -EINVAL;
  550. }
  551. static int dvb_pll_set_params(struct dvb_frontend *fe,
  552. struct dvb_frontend_parameters *params)
  553. {
  554. struct dvb_pll_priv *priv = fe->tuner_priv;
  555. u8 buf[4];
  556. struct i2c_msg msg =
  557. { .addr = priv->pll_i2c_address, .flags = 0,
  558. .buf = buf, .len = sizeof(buf) };
  559. int result;
  560. u32 frequency = 0;
  561. if (priv->i2c == NULL)
  562. return -EINVAL;
  563. if ((result = dvb_pll_configure(fe, buf, params)) < 0)
  564. return result;
  565. else
  566. frequency = result;
  567. if (fe->ops.i2c_gate_ctrl)
  568. fe->ops.i2c_gate_ctrl(fe, 1);
  569. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  570. return result;
  571. }
  572. priv->frequency = frequency;
  573. priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
  574. return 0;
  575. }
  576. static int dvb_pll_calc_regs(struct dvb_frontend *fe,
  577. struct dvb_frontend_parameters *params,
  578. u8 *buf, int buf_len)
  579. {
  580. struct dvb_pll_priv *priv = fe->tuner_priv;
  581. int result;
  582. u32 frequency = 0;
  583. if (buf_len < 5)
  584. return -EINVAL;
  585. if ((result = dvb_pll_configure(fe, buf+1, params)) < 0)
  586. return result;
  587. else
  588. frequency = result;
  589. buf[0] = priv->pll_i2c_address;
  590. priv->frequency = frequency;
  591. priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
  592. return 5;
  593. }
  594. static int dvb_pll_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  595. {
  596. struct dvb_pll_priv *priv = fe->tuner_priv;
  597. *frequency = priv->frequency;
  598. return 0;
  599. }
  600. static int dvb_pll_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
  601. {
  602. struct dvb_pll_priv *priv = fe->tuner_priv;
  603. *bandwidth = priv->bandwidth;
  604. return 0;
  605. }
  606. static int dvb_pll_init(struct dvb_frontend *fe)
  607. {
  608. struct dvb_pll_priv *priv = fe->tuner_priv;
  609. if (priv->i2c == NULL)
  610. return -EINVAL;
  611. if (priv->pll_desc->initdata) {
  612. struct i2c_msg msg = { .flags = 0,
  613. .addr = priv->pll_i2c_address,
  614. .buf = priv->pll_desc->initdata + 1,
  615. .len = priv->pll_desc->initdata[0] };
  616. int result;
  617. if (fe->ops.i2c_gate_ctrl)
  618. fe->ops.i2c_gate_ctrl(fe, 1);
  619. result = i2c_transfer(priv->i2c, &msg, 1);
  620. if (result != 1)
  621. return result;
  622. if (priv->pll_desc->initdata2) {
  623. msg.buf = priv->pll_desc->initdata2 + 1;
  624. msg.len = priv->pll_desc->initdata2[0];
  625. if (fe->ops.i2c_gate_ctrl)
  626. fe->ops.i2c_gate_ctrl(fe, 1);
  627. result = i2c_transfer(priv->i2c, &msg, 1);
  628. if (result != 1)
  629. return result;
  630. }
  631. return 0;
  632. }
  633. /* Shouldn't be called when initdata is NULL, maybe BUG()? */
  634. return -EINVAL;
  635. }
  636. static struct dvb_tuner_ops dvb_pll_tuner_ops = {
  637. .release = dvb_pll_release,
  638. .sleep = dvb_pll_sleep,
  639. .init = dvb_pll_init,
  640. .set_params = dvb_pll_set_params,
  641. .calc_regs = dvb_pll_calc_regs,
  642. .get_frequency = dvb_pll_get_frequency,
  643. .get_bandwidth = dvb_pll_get_bandwidth,
  644. };
  645. struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
  646. struct i2c_adapter *i2c,
  647. unsigned int pll_desc_id)
  648. {
  649. u8 b1 [] = { 0 };
  650. struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD,
  651. .buf = b1, .len = 1 };
  652. struct dvb_pll_priv *priv = NULL;
  653. int ret;
  654. struct dvb_pll_desc *desc;
  655. if ((id[dvb_pll_devcount] > DVB_PLL_UNDEFINED) &&
  656. (id[dvb_pll_devcount] < ARRAY_SIZE(pll_list)))
  657. pll_desc_id = id[dvb_pll_devcount];
  658. BUG_ON(pll_desc_id < 1 || pll_desc_id >= ARRAY_SIZE(pll_list));
  659. desc = pll_list[pll_desc_id];
  660. if (i2c != NULL) {
  661. if (fe->ops.i2c_gate_ctrl)
  662. fe->ops.i2c_gate_ctrl(fe, 1);
  663. ret = i2c_transfer (i2c, &msg, 1);
  664. if (ret != 1)
  665. return NULL;
  666. if (fe->ops.i2c_gate_ctrl)
  667. fe->ops.i2c_gate_ctrl(fe, 0);
  668. }
  669. priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL);
  670. if (priv == NULL)
  671. return NULL;
  672. priv->pll_i2c_address = pll_addr;
  673. priv->i2c = i2c;
  674. priv->pll_desc = desc;
  675. priv->nr = dvb_pll_devcount++;
  676. memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops,
  677. sizeof(struct dvb_tuner_ops));
  678. strncpy(fe->ops.tuner_ops.info.name, desc->name,
  679. sizeof(fe->ops.tuner_ops.info.name));
  680. fe->ops.tuner_ops.info.frequency_min = desc->min;
  681. fe->ops.tuner_ops.info.frequency_max = desc->max;
  682. if (!desc->initdata)
  683. fe->ops.tuner_ops.init = NULL;
  684. if (!desc->sleepdata)
  685. fe->ops.tuner_ops.sleep = NULL;
  686. fe->tuner_priv = priv;
  687. if ((debug) || (id[priv->nr] == pll_desc_id)) {
  688. printk("dvb-pll[%d]", priv->nr);
  689. if (i2c != NULL)
  690. printk(" %d-%04x", i2c_adapter_id(i2c), pll_addr);
  691. printk(": id# %d (%s) attached, %s\n", pll_desc_id, desc->name,
  692. id[priv->nr] == pll_desc_id ?
  693. "insmod option" : "autodetected");
  694. }
  695. return fe;
  696. }
  697. EXPORT_SYMBOL(dvb_pll_attach);
  698. MODULE_DESCRIPTION("dvb pll library");
  699. MODULE_AUTHOR("Gerd Knorr");
  700. MODULE_LICENSE("GPL");