mt20xx.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * i2c tv tuner chip device driver
  3. * controls microtune tuners, mt2032 + mt2050 at the moment.
  4. *
  5. * This "mt20xx" module was split apart from the original "tuner" module.
  6. */
  7. #include <linux/delay.h>
  8. #include <linux/i2c.h>
  9. #include <linux/slab.h>
  10. #include <linux/videodev2.h>
  11. #include "tuner-i2c.h"
  12. #include "mt20xx.h"
  13. static int debug;
  14. module_param(debug, int, 0644);
  15. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  16. /* ---------------------------------------------------------------------- */
  17. static unsigned int optimize_vco = 1;
  18. module_param(optimize_vco, int, 0644);
  19. static unsigned int tv_antenna = 1;
  20. module_param(tv_antenna, int, 0644);
  21. static unsigned int radio_antenna;
  22. module_param(radio_antenna, int, 0644);
  23. /* ---------------------------------------------------------------------- */
  24. #define MT2032 0x04
  25. #define MT2030 0x06
  26. #define MT2040 0x07
  27. #define MT2050 0x42
  28. static char *microtune_part[] = {
  29. [ MT2030 ] = "MT2030",
  30. [ MT2032 ] = "MT2032",
  31. [ MT2040 ] = "MT2040",
  32. [ MT2050 ] = "MT2050",
  33. };
  34. struct microtune_priv {
  35. struct tuner_i2c_props i2c_props;
  36. unsigned int xogc;
  37. //unsigned int radio_if2;
  38. u32 frequency;
  39. };
  40. static void microtune_release(struct dvb_frontend *fe)
  41. {
  42. kfree(fe->tuner_priv);
  43. fe->tuner_priv = NULL;
  44. }
  45. static int microtune_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  46. {
  47. struct microtune_priv *priv = fe->tuner_priv;
  48. *frequency = priv->frequency;
  49. return 0;
  50. }
  51. // IsSpurInBand()?
  52. static int mt2032_spurcheck(struct dvb_frontend *fe,
  53. int f1, int f2, int spectrum_from,int spectrum_to)
  54. {
  55. struct microtune_priv *priv = fe->tuner_priv;
  56. int n1=1,n2,f;
  57. f1=f1/1000; //scale to kHz to avoid 32bit overflows
  58. f2=f2/1000;
  59. spectrum_from/=1000;
  60. spectrum_to/=1000;
  61. tuner_dbg("spurcheck f1=%d f2=%d from=%d to=%d\n",
  62. f1,f2,spectrum_from,spectrum_to);
  63. do {
  64. n2=-n1;
  65. f=n1*(f1-f2);
  66. do {
  67. n2--;
  68. f=f-f2;
  69. tuner_dbg("spurtest n1=%d n2=%d ftest=%d\n",n1,n2,f);
  70. if( (f>spectrum_from) && (f<spectrum_to))
  71. tuner_dbg("mt2032 spurcheck triggered: %d\n",n1);
  72. } while ( (f>(f2-spectrum_to)) || (n2>-5));
  73. n1++;
  74. } while (n1<5);
  75. return 1;
  76. }
  77. static int mt2032_compute_freq(struct dvb_frontend *fe,
  78. unsigned int rfin,
  79. unsigned int if1, unsigned int if2,
  80. unsigned int spectrum_from,
  81. unsigned int spectrum_to,
  82. unsigned char *buf,
  83. int *ret_sel,
  84. unsigned int xogc) //all in Hz
  85. {
  86. struct microtune_priv *priv = fe->tuner_priv;
  87. unsigned int fref,lo1,lo1n,lo1a,s,sel,lo1freq, desired_lo1,
  88. desired_lo2,lo2,lo2n,lo2a,lo2num,lo2freq;
  89. fref= 5250 *1000; //5.25MHz
  90. desired_lo1=rfin+if1;
  91. lo1=(2*(desired_lo1/1000)+(fref/1000)) / (2*fref/1000);
  92. lo1n=lo1/8;
  93. lo1a=lo1-(lo1n*8);
  94. s=rfin/1000/1000+1090;
  95. if(optimize_vco) {
  96. if(s>1890) sel=0;
  97. else if(s>1720) sel=1;
  98. else if(s>1530) sel=2;
  99. else if(s>1370) sel=3;
  100. else sel=4; // >1090
  101. }
  102. else {
  103. if(s>1790) sel=0; // <1958
  104. else if(s>1617) sel=1;
  105. else if(s>1449) sel=2;
  106. else if(s>1291) sel=3;
  107. else sel=4; // >1090
  108. }
  109. *ret_sel=sel;
  110. lo1freq=(lo1a+8*lo1n)*fref;
  111. tuner_dbg("mt2032: rfin=%d lo1=%d lo1n=%d lo1a=%d sel=%d, lo1freq=%d\n",
  112. rfin,lo1,lo1n,lo1a,sel,lo1freq);
  113. desired_lo2=lo1freq-rfin-if2;
  114. lo2=(desired_lo2)/fref;
  115. lo2n=lo2/8;
  116. lo2a=lo2-(lo2n*8);
  117. lo2num=((desired_lo2/1000)%(fref/1000))* 3780/(fref/1000); //scale to fit in 32bit arith
  118. lo2freq=(lo2a+8*lo2n)*fref + lo2num*(fref/1000)/3780*1000;
  119. tuner_dbg("mt2032: rfin=%d lo2=%d lo2n=%d lo2a=%d num=%d lo2freq=%d\n",
  120. rfin,lo2,lo2n,lo2a,lo2num,lo2freq);
  121. if (lo1a > 7 || lo1n < 17 || lo1n > 48 || lo2a > 7 || lo2n < 17 ||
  122. lo2n > 30) {
  123. tuner_info("mt2032: frequency parameters out of range: %d %d %d %d\n",
  124. lo1a, lo1n, lo2a,lo2n);
  125. return(-1);
  126. }
  127. mt2032_spurcheck(fe, lo1freq, desired_lo2, spectrum_from, spectrum_to);
  128. // should recalculate lo1 (one step up/down)
  129. // set up MT2032 register map for transfer over i2c
  130. buf[0]=lo1n-1;
  131. buf[1]=lo1a | (sel<<4);
  132. buf[2]=0x86; // LOGC
  133. buf[3]=0x0f; //reserved
  134. buf[4]=0x1f;
  135. buf[5]=(lo2n-1) | (lo2a<<5);
  136. if(rfin >400*1000*1000)
  137. buf[6]=0xe4;
  138. else
  139. buf[6]=0xf4; // set PKEN per rev 1.2
  140. buf[7]=8+xogc;
  141. buf[8]=0xc3; //reserved
  142. buf[9]=0x4e; //reserved
  143. buf[10]=0xec; //reserved
  144. buf[11]=(lo2num&0xff);
  145. buf[12]=(lo2num>>8) |0x80; // Lo2RST
  146. return 0;
  147. }
  148. static int mt2032_check_lo_lock(struct dvb_frontend *fe)
  149. {
  150. struct microtune_priv *priv = fe->tuner_priv;
  151. int try,lock=0;
  152. unsigned char buf[2];
  153. for(try=0;try<10;try++) {
  154. buf[0]=0x0e;
  155. tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
  156. tuner_i2c_xfer_recv(&priv->i2c_props,buf,1);
  157. tuner_dbg("mt2032 Reg.E=0x%02x\n",buf[0]);
  158. lock=buf[0] &0x06;
  159. if (lock==6)
  160. break;
  161. tuner_dbg("mt2032: pll wait 1ms for lock (0x%2x)\n",buf[0]);
  162. udelay(1000);
  163. }
  164. return lock;
  165. }
  166. static int mt2032_optimize_vco(struct dvb_frontend *fe,int sel,int lock)
  167. {
  168. struct microtune_priv *priv = fe->tuner_priv;
  169. unsigned char buf[2];
  170. int tad1;
  171. buf[0]=0x0f;
  172. tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
  173. tuner_i2c_xfer_recv(&priv->i2c_props,buf,1);
  174. tuner_dbg("mt2032 Reg.F=0x%02x\n",buf[0]);
  175. tad1=buf[0]&0x07;
  176. if(tad1 ==0) return lock;
  177. if(tad1 ==1) return lock;
  178. if(tad1==2) {
  179. if(sel==0)
  180. return lock;
  181. else sel--;
  182. }
  183. else {
  184. if(sel<4)
  185. sel++;
  186. else
  187. return lock;
  188. }
  189. tuner_dbg("mt2032 optimize_vco: sel=%d\n",sel);
  190. buf[0]=0x0f;
  191. buf[1]=sel;
  192. tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
  193. lock=mt2032_check_lo_lock(fe);
  194. return lock;
  195. }
  196. static void mt2032_set_if_freq(struct dvb_frontend *fe, unsigned int rfin,
  197. unsigned int if1, unsigned int if2,
  198. unsigned int from, unsigned int to)
  199. {
  200. unsigned char buf[21];
  201. int lint_try,ret,sel,lock=0;
  202. struct microtune_priv *priv = fe->tuner_priv;
  203. tuner_dbg("mt2032_set_if_freq rfin=%d if1=%d if2=%d from=%d to=%d\n",
  204. rfin,if1,if2,from,to);
  205. buf[0]=0;
  206. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
  207. tuner_i2c_xfer_recv(&priv->i2c_props,buf,21);
  208. buf[0]=0;
  209. ret=mt2032_compute_freq(fe,rfin,if1,if2,from,to,&buf[1],&sel,priv->xogc);
  210. if (ret<0)
  211. return;
  212. // send only the relevant registers per Rev. 1.2
  213. buf[0]=0;
  214. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,4);
  215. buf[5]=5;
  216. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+5,4);
  217. buf[11]=11;
  218. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+11,3);
  219. if(ret!=3)
  220. tuner_warn("i2c i/o error: rc == %d (should be 3)\n",ret);
  221. // wait for PLLs to lock (per manual), retry LINT if not.
  222. for(lint_try=0; lint_try<2; lint_try++) {
  223. lock=mt2032_check_lo_lock(fe);
  224. if(optimize_vco)
  225. lock=mt2032_optimize_vco(fe,sel,lock);
  226. if(lock==6) break;
  227. tuner_dbg("mt2032: re-init PLLs by LINT\n");
  228. buf[0]=7;
  229. buf[1]=0x80 +8+priv->xogc; // set LINT to re-init PLLs
  230. tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
  231. mdelay(10);
  232. buf[1]=8+priv->xogc;
  233. tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
  234. }
  235. if (lock!=6)
  236. tuner_warn("MT2032 Fatal Error: PLLs didn't lock.\n");
  237. buf[0]=2;
  238. buf[1]=0x20; // LOGC for optimal phase noise
  239. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
  240. if (ret!=2)
  241. tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret);
  242. }
  243. static int mt2032_set_tv_freq(struct dvb_frontend *fe,
  244. struct analog_parameters *params)
  245. {
  246. int if2,from,to;
  247. // signal bandwidth and picture carrier
  248. if (params->std & V4L2_STD_525_60) {
  249. // NTSC
  250. from = 40750*1000;
  251. to = 46750*1000;
  252. if2 = 45750*1000;
  253. } else {
  254. // PAL
  255. from = 32900*1000;
  256. to = 39900*1000;
  257. if2 = 38900*1000;
  258. }
  259. mt2032_set_if_freq(fe, params->frequency*62500,
  260. 1090*1000*1000, if2, from, to);
  261. return 0;
  262. }
  263. static int mt2032_set_radio_freq(struct dvb_frontend *fe,
  264. struct analog_parameters *params)
  265. {
  266. struct microtune_priv *priv = fe->tuner_priv;
  267. int if2;
  268. if (params->std & V4L2_STD_525_60) {
  269. tuner_dbg("pinnacle ntsc\n");
  270. if2 = 41300 * 1000;
  271. } else {
  272. tuner_dbg("pinnacle pal\n");
  273. if2 = 33300 * 1000;
  274. }
  275. // per Manual for FM tuning: first if center freq. 1085 MHz
  276. mt2032_set_if_freq(fe, params->frequency * 125 / 2,
  277. 1085*1000*1000,if2,if2,if2);
  278. return 0;
  279. }
  280. static int mt2032_set_params(struct dvb_frontend *fe,
  281. struct analog_parameters *params)
  282. {
  283. struct microtune_priv *priv = fe->tuner_priv;
  284. int ret = -EINVAL;
  285. switch (params->mode) {
  286. case V4L2_TUNER_RADIO:
  287. ret = mt2032_set_radio_freq(fe, params);
  288. priv->frequency = params->frequency * 125 / 2;
  289. break;
  290. case V4L2_TUNER_ANALOG_TV:
  291. case V4L2_TUNER_DIGITAL_TV:
  292. ret = mt2032_set_tv_freq(fe, params);
  293. priv->frequency = params->frequency * 62500;
  294. break;
  295. }
  296. return ret;
  297. }
  298. static const struct dvb_tuner_ops mt2032_tuner_ops = {
  299. .set_analog_params = mt2032_set_params,
  300. .release = microtune_release,
  301. .get_frequency = microtune_get_frequency,
  302. };
  303. // Initialization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001
  304. static int mt2032_init(struct dvb_frontend *fe)
  305. {
  306. struct microtune_priv *priv = fe->tuner_priv;
  307. unsigned char buf[21];
  308. int ret,xogc,xok=0;
  309. // Initialize Registers per spec.
  310. buf[1]=2; // Index to register 2
  311. buf[2]=0xff;
  312. buf[3]=0x0f;
  313. buf[4]=0x1f;
  314. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+1,4);
  315. buf[5]=6; // Index register 6
  316. buf[6]=0xe4;
  317. buf[7]=0x8f;
  318. buf[8]=0xc3;
  319. buf[9]=0x4e;
  320. buf[10]=0xec;
  321. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+5,6);
  322. buf[12]=13; // Index register 13
  323. buf[13]=0x32;
  324. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+12,2);
  325. // Adjust XOGC (register 7), wait for XOK
  326. xogc=7;
  327. do {
  328. tuner_dbg("mt2032: xogc = 0x%02x\n",xogc&0x07);
  329. mdelay(10);
  330. buf[0]=0x0e;
  331. tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
  332. tuner_i2c_xfer_recv(&priv->i2c_props,buf,1);
  333. xok=buf[0]&0x01;
  334. tuner_dbg("mt2032: xok = 0x%02x\n",xok);
  335. if (xok == 1) break;
  336. xogc--;
  337. tuner_dbg("mt2032: xogc = 0x%02x\n",xogc&0x07);
  338. if (xogc == 3) {
  339. xogc=4; // min. 4 per spec
  340. break;
  341. }
  342. buf[0]=0x07;
  343. buf[1]=0x88 + xogc;
  344. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
  345. if (ret!=2)
  346. tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret);
  347. } while (xok != 1 );
  348. priv->xogc=xogc;
  349. memcpy(&fe->ops.tuner_ops, &mt2032_tuner_ops, sizeof(struct dvb_tuner_ops));
  350. return(1);
  351. }
  352. static void mt2050_set_antenna(struct dvb_frontend *fe, unsigned char antenna)
  353. {
  354. struct microtune_priv *priv = fe->tuner_priv;
  355. unsigned char buf[2];
  356. buf[0] = 6;
  357. buf[1] = antenna ? 0x11 : 0x10;
  358. tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
  359. tuner_dbg("mt2050: enabled antenna connector %d\n", antenna);
  360. }
  361. static void mt2050_set_if_freq(struct dvb_frontend *fe,unsigned int freq, unsigned int if2)
  362. {
  363. struct microtune_priv *priv = fe->tuner_priv;
  364. unsigned int if1=1218*1000*1000;
  365. unsigned int f_lo1,f_lo2,lo1,lo2,f_lo1_modulo,f_lo2_modulo,num1,num2,div1a,div1b,div2a,div2b;
  366. int ret;
  367. unsigned char buf[6];
  368. tuner_dbg("mt2050_set_if_freq freq=%d if1=%d if2=%d\n",
  369. freq,if1,if2);
  370. f_lo1=freq+if1;
  371. f_lo1=(f_lo1/1000000)*1000000;
  372. f_lo2=f_lo1-freq-if2;
  373. f_lo2=(f_lo2/50000)*50000;
  374. lo1=f_lo1/4000000;
  375. lo2=f_lo2/4000000;
  376. f_lo1_modulo= f_lo1-(lo1*4000000);
  377. f_lo2_modulo= f_lo2-(lo2*4000000);
  378. num1=4*f_lo1_modulo/4000000;
  379. num2=4096*(f_lo2_modulo/1000)/4000;
  380. // todo spurchecks
  381. div1a=(lo1/12)-1;
  382. div1b=lo1-(div1a+1)*12;
  383. div2a=(lo2/8)-1;
  384. div2b=lo2-(div2a+1)*8;
  385. if (debug > 1) {
  386. tuner_dbg("lo1 lo2 = %d %d\n", lo1, lo2);
  387. tuner_dbg("num1 num2 div1a div1b div2a div2b= %x %x %x %x %x %x\n",
  388. num1,num2,div1a,div1b,div2a,div2b);
  389. }
  390. buf[0]=1;
  391. buf[1]= 4*div1b + num1;
  392. if(freq<275*1000*1000) buf[1] = buf[1]|0x80;
  393. buf[2]=div1a;
  394. buf[3]=32*div2b + num2/256;
  395. buf[4]=num2-(num2/256)*256;
  396. buf[5]=div2a;
  397. if(num2!=0) buf[5]=buf[5]|0x40;
  398. if (debug > 1)
  399. tuner_dbg("bufs is: %*ph\n", 6, buf);
  400. ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,6);
  401. if (ret!=6)
  402. tuner_warn("i2c i/o error: rc == %d (should be 6)\n",ret);
  403. }
  404. static int mt2050_set_tv_freq(struct dvb_frontend *fe,
  405. struct analog_parameters *params)
  406. {
  407. unsigned int if2;
  408. if (params->std & V4L2_STD_525_60) {
  409. // NTSC
  410. if2 = 45750*1000;
  411. } else {
  412. // PAL
  413. if2 = 38900*1000;
  414. }
  415. if (V4L2_TUNER_DIGITAL_TV == params->mode) {
  416. // DVB (pinnacle 300i)
  417. if2 = 36150*1000;
  418. }
  419. mt2050_set_if_freq(fe, params->frequency*62500, if2);
  420. mt2050_set_antenna(fe, tv_antenna);
  421. return 0;
  422. }
  423. static int mt2050_set_radio_freq(struct dvb_frontend *fe,
  424. struct analog_parameters *params)
  425. {
  426. struct microtune_priv *priv = fe->tuner_priv;
  427. int if2;
  428. if (params->std & V4L2_STD_525_60) {
  429. tuner_dbg("pinnacle ntsc\n");
  430. if2 = 41300 * 1000;
  431. } else {
  432. tuner_dbg("pinnacle pal\n");
  433. if2 = 33300 * 1000;
  434. }
  435. mt2050_set_if_freq(fe, params->frequency * 125 / 2, if2);
  436. mt2050_set_antenna(fe, radio_antenna);
  437. return 0;
  438. }
  439. static int mt2050_set_params(struct dvb_frontend *fe,
  440. struct analog_parameters *params)
  441. {
  442. struct microtune_priv *priv = fe->tuner_priv;
  443. int ret = -EINVAL;
  444. switch (params->mode) {
  445. case V4L2_TUNER_RADIO:
  446. ret = mt2050_set_radio_freq(fe, params);
  447. priv->frequency = params->frequency * 125 / 2;
  448. break;
  449. case V4L2_TUNER_ANALOG_TV:
  450. case V4L2_TUNER_DIGITAL_TV:
  451. ret = mt2050_set_tv_freq(fe, params);
  452. priv->frequency = params->frequency * 62500;
  453. break;
  454. }
  455. return ret;
  456. }
  457. static const struct dvb_tuner_ops mt2050_tuner_ops = {
  458. .set_analog_params = mt2050_set_params,
  459. .release = microtune_release,
  460. .get_frequency = microtune_get_frequency,
  461. };
  462. static int mt2050_init(struct dvb_frontend *fe)
  463. {
  464. struct microtune_priv *priv = fe->tuner_priv;
  465. unsigned char buf[2];
  466. buf[0] = 6;
  467. buf[1] = 0x10;
  468. tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); /* power */
  469. buf[0] = 0x0f;
  470. buf[1] = 0x0f;
  471. tuner_i2c_xfer_send(&priv->i2c_props, buf, 2); /* m1lo */
  472. buf[0] = 0x0d;
  473. tuner_i2c_xfer_send(&priv->i2c_props, buf, 1);
  474. tuner_i2c_xfer_recv(&priv->i2c_props, buf, 1);
  475. tuner_dbg("mt2050: sro is %x\n", buf[0]);
  476. memcpy(&fe->ops.tuner_ops, &mt2050_tuner_ops, sizeof(struct dvb_tuner_ops));
  477. return 0;
  478. }
  479. struct dvb_frontend *microtune_attach(struct dvb_frontend *fe,
  480. struct i2c_adapter* i2c_adap,
  481. u8 i2c_addr)
  482. {
  483. struct microtune_priv *priv = NULL;
  484. char *name;
  485. unsigned char buf[21];
  486. int company_code;
  487. priv = kzalloc(sizeof(struct microtune_priv), GFP_KERNEL);
  488. if (priv == NULL)
  489. return NULL;
  490. fe->tuner_priv = priv;
  491. priv->i2c_props.addr = i2c_addr;
  492. priv->i2c_props.adap = i2c_adap;
  493. priv->i2c_props.name = "mt20xx";
  494. //priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */
  495. memset(buf,0,sizeof(buf));
  496. name = "unknown";
  497. tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
  498. tuner_i2c_xfer_recv(&priv->i2c_props,buf,21);
  499. if (debug)
  500. tuner_dbg("MT20xx hexdump: %*ph\n", 21, buf);
  501. company_code = buf[0x11] << 8 | buf[0x12];
  502. tuner_info("microtune: companycode=%04x part=%02x rev=%02x\n",
  503. company_code,buf[0x13],buf[0x14]);
  504. if (buf[0x13] < ARRAY_SIZE(microtune_part) &&
  505. NULL != microtune_part[buf[0x13]])
  506. name = microtune_part[buf[0x13]];
  507. switch (buf[0x13]) {
  508. case MT2032:
  509. mt2032_init(fe);
  510. break;
  511. case MT2050:
  512. mt2050_init(fe);
  513. break;
  514. default:
  515. tuner_info("microtune %s found, not (yet?) supported, sorry :-/\n",
  516. name);
  517. return NULL;
  518. }
  519. strlcpy(fe->ops.tuner_ops.info.name, name,
  520. sizeof(fe->ops.tuner_ops.info.name));
  521. tuner_info("microtune %s found, OK\n",name);
  522. return fe;
  523. }
  524. EXPORT_SYMBOL_GPL(microtune_attach);
  525. MODULE_DESCRIPTION("Microtune tuner driver");
  526. MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
  527. MODULE_LICENSE("GPL");