dvb-pll.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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_unknown_1 = {
  100. .name = "unknown 1", /* used by dntv live dvb-t */
  101. .min = 174000000,
  102. .max = 862000000,
  103. .count = 9,
  104. .entries = {
  105. { 150000000, 36166667, 166666, 0xb4, 0x01 },
  106. { 173000000, 36166667, 166666, 0xbc, 0x01 },
  107. { 250000000, 36166667, 166666, 0xb4, 0x02 },
  108. { 400000000, 36166667, 166666, 0xbc, 0x02 },
  109. { 420000000, 36166667, 166666, 0xf4, 0x02 },
  110. { 470000000, 36166667, 166666, 0xfc, 0x02 },
  111. { 600000000, 36166667, 166666, 0xbc, 0x08 },
  112. { 730000000, 36166667, 166666, 0xf4, 0x08 },
  113. { 999999999, 36166667, 166666, 0xfc, 0x08 },
  114. },
  115. };
  116. EXPORT_SYMBOL(dvb_pll_unknown_1);
  117. /* Infineon TUA6010XS
  118. * used in Thomson Cable Tuner
  119. */
  120. struct dvb_pll_desc dvb_pll_tua6010xs = {
  121. .name = "Infineon TUA6010XS",
  122. .min = 44250000,
  123. .max = 858000000,
  124. .count = 3,
  125. .entries = {
  126. { 115750000, 36125000, 62500, 0x8e, 0x03 },
  127. { 403250000, 36125000, 62500, 0x8e, 0x06 },
  128. { 999999999, 36125000, 62500, 0x8e, 0x85 },
  129. },
  130. };
  131. EXPORT_SYMBOL(dvb_pll_tua6010xs);
  132. /* Panasonic env57h1xd5 (some Philips PLL ?) */
  133. struct dvb_pll_desc dvb_pll_env57h1xd5 = {
  134. .name = "Panasonic ENV57H1XD5",
  135. .min = 44250000,
  136. .max = 858000000,
  137. .count = 4,
  138. .entries = {
  139. { 153000000, 36291666, 166666, 0xc2, 0x41 },
  140. { 470000000, 36291666, 166666, 0xc2, 0x42 },
  141. { 526000000, 36291666, 166666, 0xc2, 0x84 },
  142. { 999999999, 36291666, 166666, 0xc2, 0xa4 },
  143. },
  144. };
  145. EXPORT_SYMBOL(dvb_pll_env57h1xd5);
  146. /* Philips TDA6650/TDA6651
  147. * used in Panasonic ENV77H11D5
  148. */
  149. static void tda665x_bw(u8 *buf, u32 freq, int bandwidth)
  150. {
  151. if (bandwidth == BANDWIDTH_8_MHZ)
  152. buf[3] |= 0x08;
  153. }
  154. struct dvb_pll_desc dvb_pll_tda665x = {
  155. .name = "Philips TDA6650/TDA6651",
  156. .min = 44250000,
  157. .max = 858000000,
  158. .setbw = tda665x_bw,
  159. .count = 12,
  160. .entries = {
  161. { 93834000, 36249333, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
  162. { 123834000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  163. { 161000000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
  164. { 163834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  165. { 253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
  166. { 383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
  167. { 443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
  168. { 444000000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ },
  169. { 583834000, 36249333, 166667, 0xca, 0x63 /* 011 0 0 0 11 */ },
  170. { 793834000, 36249333, 166667, 0xca, 0xa3 /* 101 0 0 0 11 */ },
  171. { 444834000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ },
  172. { 861000000, 36249333, 166667, 0xca, 0xe3 /* 111 0 0 0 11 */ },
  173. }
  174. };
  175. EXPORT_SYMBOL(dvb_pll_tda665x);
  176. /* Infineon TUA6034
  177. * used in LG TDTP E102P
  178. */
  179. static void tua6034_bw(u8 *buf, u32 freq, int bandwidth)
  180. {
  181. if (BANDWIDTH_7_MHZ != bandwidth)
  182. buf[3] |= 0x08;
  183. }
  184. struct dvb_pll_desc dvb_pll_tua6034 = {
  185. .name = "Infineon TUA6034",
  186. .min = 44250000,
  187. .max = 858000000,
  188. .count = 3,
  189. .setbw = tua6034_bw,
  190. .entries = {
  191. { 174500000, 36166667, 62500, 0xce, 0x01 },
  192. { 230000000, 36166667, 62500, 0xce, 0x02 },
  193. { 999999999, 36166667, 62500, 0xce, 0x04 },
  194. },
  195. };
  196. EXPORT_SYMBOL(dvb_pll_tua6034);
  197. /* Philips FMD1216ME
  198. * used in Medion Hybrid PCMCIA card and USB Box
  199. */
  200. static void fmd1216me_bw(u8 *buf, u32 freq, int bandwidth)
  201. {
  202. if (bandwidth == BANDWIDTH_8_MHZ && freq >= 158870000)
  203. buf[3] |= 0x08;
  204. }
  205. struct dvb_pll_desc dvb_pll_fmd1216me = {
  206. .name = "Philips FMD1216ME",
  207. .min = 50870000,
  208. .max = 858000000,
  209. .setbw = fmd1216me_bw,
  210. .count = 7,
  211. .entries = {
  212. { 143870000, 36213333, 166667, 0xbc, 0x41 },
  213. { 158870000, 36213333, 166667, 0xf4, 0x41 },
  214. { 329870000, 36213333, 166667, 0xbc, 0x42 },
  215. { 441870000, 36213333, 166667, 0xf4, 0x42 },
  216. { 625870000, 36213333, 166667, 0xbc, 0x44 },
  217. { 803870000, 36213333, 166667, 0xf4, 0x44 },
  218. { 999999999, 36213333, 166667, 0xfc, 0x44 },
  219. }
  220. };
  221. EXPORT_SYMBOL(dvb_pll_fmd1216me);
  222. /* ALPS TDED4
  223. * used in Nebula-Cards and USB boxes
  224. */
  225. static void tded4_bw(u8 *buf, u32 freq, int bandwidth)
  226. {
  227. if (bandwidth == BANDWIDTH_8_MHZ)
  228. buf[3] |= 0x04;
  229. }
  230. struct dvb_pll_desc dvb_pll_tded4 = {
  231. .name = "ALPS TDED4",
  232. .min = 47000000,
  233. .max = 863000000,
  234. .setbw = tded4_bw,
  235. .count = 4,
  236. .entries = {
  237. { 153000000, 36166667, 166667, 0x85, 0x01 },
  238. { 470000000, 36166667, 166667, 0x85, 0x02 },
  239. { 823000000, 36166667, 166667, 0x85, 0x08 },
  240. { 999999999, 36166667, 166667, 0x85, 0x88 },
  241. }
  242. };
  243. EXPORT_SYMBOL(dvb_pll_tded4);
  244. /* ----------------------------------------------------------- */
  245. /* code */
  246. static int debug = 0;
  247. module_param(debug, int, 0644);
  248. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  249. int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
  250. u32 freq, int bandwidth)
  251. {
  252. u32 div;
  253. int i;
  254. if (freq != 0 && (freq < desc->min || freq > desc->max))
  255. return -EINVAL;
  256. for (i = 0; i < desc->count; i++) {
  257. if (freq > desc->entries[i].limit)
  258. continue;
  259. break;
  260. }
  261. if (debug)
  262. printk("pll: %s: freq=%d bw=%d | i=%d/%d\n",
  263. desc->name, freq, bandwidth, i, desc->count);
  264. BUG_ON(i == desc->count);
  265. div = (freq + desc->entries[i].offset) / desc->entries[i].stepsize;
  266. buf[0] = div >> 8;
  267. buf[1] = div & 0xff;
  268. buf[2] = desc->entries[i].cb1;
  269. buf[3] = desc->entries[i].cb2;
  270. if (desc->setbw)
  271. desc->setbw(buf, freq, bandwidth);
  272. if (debug)
  273. printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
  274. desc->name, div, buf[0], buf[1], buf[2], buf[3]);
  275. return 0;
  276. }
  277. EXPORT_SYMBOL(dvb_pll_configure);
  278. MODULE_DESCRIPTION("dvb pll library");
  279. MODULE_AUTHOR("Gerd Knorr");
  280. MODULE_LICENSE("GPL");