mt20xx.c 15 KB

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