dvb-pll.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * descriptions + helper functions for simple dvb plls.
  3. *
  4. * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/dvb/frontend.h>
  22. #include <asm/types.h>
  23. #include "dvb-pll.h"
  24. /* ----------------------------------------------------------- */
  25. /* descriptions */
  26. struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
  27. .name = "Thomson dtt7579",
  28. .min = 177000000,
  29. .max = 858000000,
  30. .count = 5,
  31. .entries = {
  32. { 0, 36166667, 166666, 0xb4, 0x03 }, /* go sleep */
  33. { 443250000, 36166667, 166666, 0xb4, 0x02 },
  34. { 542000000, 36166667, 166666, 0xb4, 0x08 },
  35. { 771000000, 36166667, 166666, 0xbc, 0x08 },
  36. { 999999999, 36166667, 166666, 0xf4, 0x08 },
  37. },
  38. };
  39. EXPORT_SYMBOL(dvb_pll_thomson_dtt7579);
  40. struct dvb_pll_desc dvb_pll_thomson_dtt7610 = {
  41. .name = "Thomson dtt7610",
  42. .min = 44000000,
  43. .max = 958000000,
  44. .count = 3,
  45. .entries = {
  46. { 157250000, 44000000, 62500, 0x8e, 0x39 },
  47. { 454000000, 44000000, 62500, 0x8e, 0x3a },
  48. { 999999999, 44000000, 62500, 0x8e, 0x3c },
  49. },
  50. };
  51. EXPORT_SYMBOL(dvb_pll_thomson_dtt7610);
  52. static void thomson_dtt759x_bw(u8 *buf, u32 freq, int bandwidth)
  53. {
  54. if (BANDWIDTH_7_MHZ == bandwidth)
  55. buf[3] |= 0x10;
  56. }
  57. struct dvb_pll_desc dvb_pll_thomson_dtt759x = {
  58. .name = "Thomson dtt759x",
  59. .min = 177000000,
  60. .max = 896000000,
  61. .setbw = thomson_dtt759x_bw,
  62. .count = 6,
  63. .entries = {
  64. { 0, 36166667, 166666, 0x84, 0x03 },
  65. { 264000000, 36166667, 166666, 0xb4, 0x02 },
  66. { 470000000, 36166667, 166666, 0xbc, 0x02 },
  67. { 735000000, 36166667, 166666, 0xbc, 0x08 },
  68. { 835000000, 36166667, 166666, 0xf4, 0x08 },
  69. { 999999999, 36166667, 166666, 0xfc, 0x08 },
  70. },
  71. };
  72. EXPORT_SYMBOL(dvb_pll_thomson_dtt759x);
  73. struct dvb_pll_desc dvb_pll_lg_z201 = {
  74. .name = "LG z201",
  75. .min = 174000000,
  76. .max = 862000000,
  77. .count = 5,
  78. .entries = {
  79. { 0, 36166667, 166666, 0xbc, 0x03 },
  80. { 443250000, 36166667, 166666, 0xbc, 0x01 },
  81. { 542000000, 36166667, 166666, 0xbc, 0x02 },
  82. { 830000000, 36166667, 166666, 0xf4, 0x02 },
  83. { 999999999, 36166667, 166666, 0xfc, 0x02 },
  84. },
  85. };
  86. EXPORT_SYMBOL(dvb_pll_lg_z201);
  87. struct dvb_pll_desc dvb_pll_microtune_4042 = {
  88. .name = "Microtune 4042 FI5",
  89. .min = 57000000,
  90. .max = 858000000,
  91. .count = 3,
  92. .entries = {
  93. { 162000000, 44000000, 62500, 0x8e, 0xa1 },
  94. { 457000000, 44000000, 62500, 0x8e, 0x91 },
  95. { 999999999, 44000000, 62500, 0x8e, 0x31 },
  96. },
  97. };
  98. EXPORT_SYMBOL(dvb_pll_microtune_4042);
  99. struct dvb_pll_desc dvb_pll_thomson_dtt7611 = {
  100. .name = "Thomson dtt7611",
  101. .min = 44000000,
  102. .max = 958000000,
  103. .count = 3,
  104. .entries = {
  105. { 157250000, 44000000, 62500, 0x8e, 0x39 },
  106. { 454000000, 44000000, 62500, 0x8e, 0x3a },
  107. { 999999999, 44000000, 62500, 0x8e, 0x3c },
  108. },
  109. };
  110. EXPORT_SYMBOL(dvb_pll_thomson_dtt7611);
  111. struct dvb_pll_desc dvb_pll_unknown_1 = {
  112. .name = "unknown 1", /* used by dntv live dvb-t */
  113. .min = 174000000,
  114. .max = 862000000,
  115. .count = 9,
  116. .entries = {
  117. { 150000000, 36166667, 166666, 0xb4, 0x01 },
  118. { 173000000, 36166667, 166666, 0xbc, 0x01 },
  119. { 250000000, 36166667, 166666, 0xb4, 0x02 },
  120. { 400000000, 36166667, 166666, 0xbc, 0x02 },
  121. { 420000000, 36166667, 166666, 0xf4, 0x02 },
  122. { 470000000, 36166667, 166666, 0xfc, 0x02 },
  123. { 600000000, 36166667, 166666, 0xbc, 0x08 },
  124. { 730000000, 36166667, 166666, 0xf4, 0x08 },
  125. { 999999999, 36166667, 166666, 0xfc, 0x08 },
  126. },
  127. };
  128. EXPORT_SYMBOL(dvb_pll_unknown_1);
  129. /* Infineon TUA6010XS
  130. * used in Thomson Cable Tuner
  131. */
  132. struct dvb_pll_desc dvb_pll_tua6010xs = {
  133. .name = "Infineon TUA6010XS",
  134. .min = 44250000,
  135. .max = 858000000,
  136. .count = 3,
  137. .entries = {
  138. { 115750000, 36125000, 62500, 0x8e, 0x03 },
  139. { 403250000, 36125000, 62500, 0x8e, 0x06 },
  140. { 999999999, 36125000, 62500, 0x8e, 0x85 },
  141. },
  142. };
  143. EXPORT_SYMBOL(dvb_pll_tua6010xs);
  144. /* Panasonic env57h1xd5 (some Philips PLL ?) */
  145. struct dvb_pll_desc dvb_pll_env57h1xd5 = {
  146. .name = "Panasonic ENV57H1XD5",
  147. .min = 44250000,
  148. .max = 858000000,
  149. .count = 4,
  150. .entries = {
  151. { 153000000, 36291666, 166666, 0xc2, 0x41 },
  152. { 470000000, 36291666, 166666, 0xc2, 0x42 },
  153. { 526000000, 36291666, 166666, 0xc2, 0x84 },
  154. { 999999999, 36291666, 166666, 0xc2, 0xa4 },
  155. },
  156. };
  157. EXPORT_SYMBOL(dvb_pll_env57h1xd5);
  158. /* Philips TDA6650/TDA6651
  159. * used in Panasonic ENV77H11D5
  160. */
  161. static void tda665x_bw(u8 *buf, u32 freq, int bandwidth)
  162. {
  163. if (bandwidth == BANDWIDTH_8_MHZ)
  164. buf[3] |= 0x08;
  165. }
  166. struct dvb_pll_desc dvb_pll_tda665x = {
  167. .name = "Philips TDA6650/TDA6651",
  168. .min = 44250000,
  169. .max = 858000000,
  170. .setbw = tda665x_bw,
  171. .count = 12,
  172. .entries = {
  173. { 93834000, 36249333, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
  174. { 123834000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  175. { 161000000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  176. { 163834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  177. { 253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
  178. { 383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
  179. { 443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  180. { 444000000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ },
  181. { 583834000, 36249333, 166667, 0xca, 0x63 /* 011 0 0 0 11 */ },
  182. { 793834000, 36249333, 166667, 0xca, 0xa3 /* 101 0 0 0 11 */ },
  183. { 444834000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ },
  184. { 861000000, 36249333, 166667, 0xca, 0xe3 /* 111 0 0 0 11 */ },
  185. }
  186. };
  187. EXPORT_SYMBOL(dvb_pll_tda665x);
  188. /* Infineon TUA6034
  189. * used in LG TDTP E102P
  190. */
  191. static void tua6034_bw(u8 *buf, u32 freq, int bandwidth)
  192. {
  193. if (BANDWIDTH_7_MHZ != bandwidth)
  194. buf[3] |= 0x08;
  195. }
  196. struct dvb_pll_desc dvb_pll_tua6034 = {
  197. .name = "Infineon TUA6034",
  198. .min = 44250000,
  199. .max = 858000000,
  200. .count = 3,
  201. .setbw = tua6034_bw,
  202. .entries = {
  203. { 174500000, 36166667, 62500, 0xce, 0x01 },
  204. { 230000000, 36166667, 62500, 0xce, 0x02 },
  205. { 999999999, 36166667, 62500, 0xce, 0x04 },
  206. },
  207. };
  208. EXPORT_SYMBOL(dvb_pll_tua6034);
  209. /* Philips FMD1216ME
  210. * used in Medion Hybrid PCMCIA card and USB Box
  211. */
  212. static void fmd1216me_bw(u8 *buf, u32 freq, int bandwidth)
  213. {
  214. if (bandwidth == BANDWIDTH_8_MHZ && freq >= 158870000)
  215. buf[3] |= 0x08;
  216. }
  217. struct dvb_pll_desc dvb_pll_fmd1216me = {
  218. .name = "Philips FMD1216ME",
  219. .min = 50870000,
  220. .max = 858000000,
  221. .setbw = fmd1216me_bw,
  222. .count = 7,
  223. .entries = {
  224. { 143870000, 36213333, 166667, 0xbc, 0x41 },
  225. { 158870000, 36213333, 166667, 0xf4, 0x41 },
  226. { 329870000, 36213333, 166667, 0xbc, 0x42 },
  227. { 441870000, 36213333, 166667, 0xf4, 0x42 },
  228. { 625870000, 36213333, 166667, 0xbc, 0x44 },
  229. { 803870000, 36213333, 166667, 0xf4, 0x44 },
  230. { 999999999, 36213333, 166667, 0xfc, 0x44 },
  231. }
  232. };
  233. EXPORT_SYMBOL(dvb_pll_fmd1216me);
  234. /* ALPS TDED4
  235. * used in Nebula-Cards and USB boxes
  236. */
  237. static void tded4_bw(u8 *buf, u32 freq, int bandwidth)
  238. {
  239. if (bandwidth == BANDWIDTH_8_MHZ)
  240. buf[3] |= 0x04;
  241. }
  242. struct dvb_pll_desc dvb_pll_tded4 = {
  243. .name = "ALPS TDED4",
  244. .min = 47000000,
  245. .max = 863000000,
  246. .setbw = tded4_bw,
  247. .count = 4,
  248. .entries = {
  249. { 153000000, 36166667, 166667, 0x85, 0x01 },
  250. { 470000000, 36166667, 166667, 0x85, 0x02 },
  251. { 823000000, 36166667, 166667, 0x85, 0x08 },
  252. { 999999999, 36166667, 166667, 0x85, 0x88 },
  253. }
  254. };
  255. EXPORT_SYMBOL(dvb_pll_tded4);
  256. /* ----------------------------------------------------------- */
  257. /* code */
  258. static int debug = 0;
  259. module_param(debug, int, 0644);
  260. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  261. int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
  262. u32 freq, int bandwidth)
  263. {
  264. u32 div;
  265. int i;
  266. if (freq != 0 && (freq < desc->min || freq > desc->max))
  267. return -EINVAL;
  268. for (i = 0; i < desc->count; i++) {
  269. if (freq > desc->entries[i].limit)
  270. continue;
  271. break;
  272. }
  273. if (debug)
  274. printk("pll: %s: freq=%d bw=%d | i=%d/%d\n",
  275. desc->name, freq, bandwidth, i, desc->count);
  276. BUG_ON(i == desc->count);
  277. div = (freq + desc->entries[i].offset) / desc->entries[i].stepsize;
  278. buf[0] = div >> 8;
  279. buf[1] = div & 0xff;
  280. buf[2] = desc->entries[i].cb1;
  281. buf[3] = desc->entries[i].cb2;
  282. if (desc->setbw)
  283. desc->setbw(buf, freq, bandwidth);
  284. if (debug)
  285. printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
  286. desc->name, div, buf[0], buf[1], buf[2], buf[3]);
  287. return 0;
  288. }
  289. EXPORT_SYMBOL(dvb_pll_configure);
  290. MODULE_DESCRIPTION("dvb pll library");
  291. MODULE_AUTHOR("Gerd Knorr");
  292. MODULE_LICENSE("GPL");