m88rs6000t.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * Driver for the internal tuner of Montage M88RS6000
  3. *
  4. * Copyright (C) 2014 Max nibble <nibble.max@gmail.com>
  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. #include "m88rs6000t.h"
  17. #include <linux/regmap.h>
  18. struct m88rs6000t_dev {
  19. struct m88rs6000t_config cfg;
  20. struct i2c_client *client;
  21. struct regmap *regmap;
  22. u32 frequency_khz;
  23. };
  24. struct m88rs6000t_reg_val {
  25. u8 reg;
  26. u8 val;
  27. };
  28. /* set demod main mclk and ts mclk */
  29. static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)
  30. {
  31. struct m88rs6000t_dev *dev = fe->tuner_priv;
  32. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  33. u8 reg11, reg15, reg16, reg1D, reg1E, reg1F;
  34. u8 N, f0 = 0, f1 = 0, f2 = 0, f3 = 0;
  35. u16 pll_div_fb;
  36. u32 div, ts_mclk;
  37. unsigned int utmp;
  38. int ret;
  39. /* select demod main mclk */
  40. ret = regmap_read(dev->regmap, 0x15, &utmp);
  41. if (ret)
  42. goto err;
  43. reg15 = utmp;
  44. if (c->symbol_rate > 45010000) {
  45. reg11 = 0x0E;
  46. reg15 |= 0x02;
  47. reg16 = 115; /* mclk = 110.25MHz */
  48. } else {
  49. reg11 = 0x0A;
  50. reg15 &= ~0x02;
  51. reg16 = 96; /* mclk = 96MHz */
  52. }
  53. /* set ts mclk */
  54. if (c->delivery_system == SYS_DVBS)
  55. ts_mclk = 96000;
  56. else
  57. ts_mclk = 144000;
  58. pll_div_fb = (reg15 & 0x01) << 8;
  59. pll_div_fb += reg16;
  60. pll_div_fb += 32;
  61. div = 36000 * pll_div_fb;
  62. div /= ts_mclk;
  63. if (div <= 32) {
  64. N = 2;
  65. f0 = 0;
  66. f1 = div / 2;
  67. f2 = div - f1;
  68. f3 = 0;
  69. } else if (div <= 48) {
  70. N = 3;
  71. f0 = div / 3;
  72. f1 = (div - f0) / 2;
  73. f2 = div - f0 - f1;
  74. f3 = 0;
  75. } else if (div <= 64) {
  76. N = 4;
  77. f0 = div / 4;
  78. f1 = (div - f0) / 3;
  79. f2 = (div - f0 - f1) / 2;
  80. f3 = div - f0 - f1 - f2;
  81. } else {
  82. N = 4;
  83. f0 = 16;
  84. f1 = 16;
  85. f2 = 16;
  86. f3 = 16;
  87. }
  88. if (f0 == 16)
  89. f0 = 0;
  90. if (f1 == 16)
  91. f1 = 0;
  92. if (f2 == 16)
  93. f2 = 0;
  94. if (f3 == 16)
  95. f3 = 0;
  96. ret = regmap_read(dev->regmap, 0x1D, &utmp);
  97. if (ret)
  98. goto err;
  99. reg1D = utmp;
  100. reg1D &= ~0x03;
  101. reg1D |= N - 1;
  102. reg1E = ((f3 << 4) + f2) & 0xFF;
  103. reg1F = ((f1 << 4) + f0) & 0xFF;
  104. /* program and recalibrate demod PLL */
  105. ret = regmap_write(dev->regmap, 0x05, 0x40);
  106. if (ret)
  107. goto err;
  108. ret = regmap_write(dev->regmap, 0x11, 0x08);
  109. if (ret)
  110. goto err;
  111. ret = regmap_write(dev->regmap, 0x15, reg15);
  112. if (ret)
  113. goto err;
  114. ret = regmap_write(dev->regmap, 0x16, reg16);
  115. if (ret)
  116. goto err;
  117. ret = regmap_write(dev->regmap, 0x1D, reg1D);
  118. if (ret)
  119. goto err;
  120. ret = regmap_write(dev->regmap, 0x1E, reg1E);
  121. if (ret)
  122. goto err;
  123. ret = regmap_write(dev->regmap, 0x1F, reg1F);
  124. if (ret)
  125. goto err;
  126. ret = regmap_write(dev->regmap, 0x17, 0xc1);
  127. if (ret)
  128. goto err;
  129. ret = regmap_write(dev->regmap, 0x17, 0x81);
  130. if (ret)
  131. goto err;
  132. usleep_range(5000, 50000);
  133. ret = regmap_write(dev->regmap, 0x05, 0x00);
  134. if (ret)
  135. goto err;
  136. ret = regmap_write(dev->regmap, 0x11, reg11);
  137. if (ret)
  138. goto err;
  139. usleep_range(5000, 50000);
  140. err:
  141. if (ret)
  142. dev_dbg(&dev->client->dev, "failed=%d\n", ret);
  143. return ret;
  144. }
  145. static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
  146. u32 tuner_freq_MHz)
  147. {
  148. u32 fcry_KHz, ulNDiv1, ulNDiv2, ulNDiv;
  149. u8 refDiv, ucLoDiv1, ucLomod1, ucLoDiv2, ucLomod2, ucLoDiv, ucLomod;
  150. u8 reg27, reg29, reg42, reg42buf;
  151. unsigned int utmp;
  152. int ret;
  153. fcry_KHz = 27000; /* in kHz */
  154. refDiv = 27;
  155. ret = regmap_write(dev->regmap, 0x36, (refDiv - 8));
  156. if (ret)
  157. goto err;
  158. ret = regmap_write(dev->regmap, 0x31, 0x00);
  159. if (ret)
  160. goto err;
  161. ret = regmap_write(dev->regmap, 0x2c, 0x02);
  162. if (ret)
  163. goto err;
  164. if (tuner_freq_MHz >= 1550) {
  165. ucLoDiv1 = 2;
  166. ucLomod1 = 0;
  167. ucLoDiv2 = 2;
  168. ucLomod2 = 0;
  169. } else if (tuner_freq_MHz >= 1380) {
  170. ucLoDiv1 = 3;
  171. ucLomod1 = 16;
  172. ucLoDiv2 = 2;
  173. ucLomod2 = 0;
  174. } else if (tuner_freq_MHz >= 1070) {
  175. ucLoDiv1 = 3;
  176. ucLomod1 = 16;
  177. ucLoDiv2 = 3;
  178. ucLomod2 = 16;
  179. } else if (tuner_freq_MHz >= 1000) {
  180. ucLoDiv1 = 3;
  181. ucLomod1 = 16;
  182. ucLoDiv2 = 4;
  183. ucLomod2 = 64;
  184. } else if (tuner_freq_MHz >= 775) {
  185. ucLoDiv1 = 4;
  186. ucLomod1 = 64;
  187. ucLoDiv2 = 4;
  188. ucLomod2 = 64;
  189. } else if (tuner_freq_MHz >= 700) {
  190. ucLoDiv1 = 6;
  191. ucLomod1 = 48;
  192. ucLoDiv2 = 4;
  193. ucLomod2 = 64;
  194. } else if (tuner_freq_MHz >= 520) {
  195. ucLoDiv1 = 6;
  196. ucLomod1 = 48;
  197. ucLoDiv2 = 6;
  198. ucLomod2 = 48;
  199. } else {
  200. ucLoDiv1 = 8;
  201. ucLomod1 = 96;
  202. ucLoDiv2 = 8;
  203. ucLomod2 = 96;
  204. }
  205. ulNDiv1 = ((tuner_freq_MHz * ucLoDiv1 * 1000) * refDiv
  206. / fcry_KHz - 1024) / 2;
  207. ulNDiv2 = ((tuner_freq_MHz * ucLoDiv2 * 1000) * refDiv
  208. / fcry_KHz - 1024) / 2;
  209. reg27 = (((ulNDiv1 >> 8) & 0x0F) + ucLomod1) & 0x7F;
  210. ret = regmap_write(dev->regmap, 0x27, reg27);
  211. if (ret)
  212. goto err;
  213. ret = regmap_write(dev->regmap, 0x28, (u8)(ulNDiv1 & 0xFF));
  214. if (ret)
  215. goto err;
  216. reg29 = (((ulNDiv2 >> 8) & 0x0F) + ucLomod2) & 0x7f;
  217. ret = regmap_write(dev->regmap, 0x29, reg29);
  218. if (ret)
  219. goto err;
  220. ret = regmap_write(dev->regmap, 0x2a, (u8)(ulNDiv2 & 0xFF));
  221. if (ret)
  222. goto err;
  223. ret = regmap_write(dev->regmap, 0x2F, 0xf5);
  224. if (ret)
  225. goto err;
  226. ret = regmap_write(dev->regmap, 0x30, 0x05);
  227. if (ret)
  228. goto err;
  229. ret = regmap_write(dev->regmap, 0x08, 0x1f);
  230. if (ret)
  231. goto err;
  232. ret = regmap_write(dev->regmap, 0x08, 0x3f);
  233. if (ret)
  234. goto err;
  235. ret = regmap_write(dev->regmap, 0x09, 0x20);
  236. if (ret)
  237. goto err;
  238. ret = regmap_write(dev->regmap, 0x09, 0x00);
  239. if (ret)
  240. goto err;
  241. ret = regmap_write(dev->regmap, 0x3e, 0x11);
  242. if (ret)
  243. goto err;
  244. ret = regmap_write(dev->regmap, 0x08, 0x2f);
  245. if (ret)
  246. goto err;
  247. ret = regmap_write(dev->regmap, 0x08, 0x3f);
  248. if (ret)
  249. goto err;
  250. ret = regmap_write(dev->regmap, 0x09, 0x10);
  251. if (ret)
  252. goto err;
  253. ret = regmap_write(dev->regmap, 0x09, 0x00);
  254. if (ret)
  255. goto err;
  256. usleep_range(2000, 50000);
  257. ret = regmap_read(dev->regmap, 0x42, &utmp);
  258. if (ret)
  259. goto err;
  260. reg42 = utmp;
  261. ret = regmap_write(dev->regmap, 0x3e, 0x10);
  262. if (ret)
  263. goto err;
  264. ret = regmap_write(dev->regmap, 0x08, 0x2f);
  265. if (ret)
  266. goto err;
  267. ret = regmap_write(dev->regmap, 0x08, 0x3f);
  268. if (ret)
  269. goto err;
  270. ret = regmap_write(dev->regmap, 0x09, 0x10);
  271. if (ret)
  272. goto err;
  273. ret = regmap_write(dev->regmap, 0x09, 0x00);
  274. if (ret)
  275. goto err;
  276. usleep_range(2000, 50000);
  277. ret = regmap_read(dev->regmap, 0x42, &utmp);
  278. if (ret)
  279. goto err;
  280. reg42buf = utmp;
  281. if (reg42buf < reg42) {
  282. ret = regmap_write(dev->regmap, 0x3e, 0x11);
  283. if (ret)
  284. goto err;
  285. }
  286. usleep_range(5000, 50000);
  287. ret = regmap_read(dev->regmap, 0x2d, &utmp);
  288. if (ret)
  289. goto err;
  290. ret = regmap_write(dev->regmap, 0x2d, utmp);
  291. if (ret)
  292. goto err;
  293. ret = regmap_read(dev->regmap, 0x2e, &utmp);
  294. if (ret)
  295. goto err;
  296. ret = regmap_write(dev->regmap, 0x2e, utmp);
  297. if (ret)
  298. goto err;
  299. ret = regmap_read(dev->regmap, 0x27, &utmp);
  300. if (ret)
  301. goto err;
  302. reg27 = utmp & 0x70;
  303. ret = regmap_read(dev->regmap, 0x83, &utmp);
  304. if (ret)
  305. goto err;
  306. if (reg27 == (utmp & 0x70)) {
  307. ucLoDiv = ucLoDiv1;
  308. ulNDiv = ulNDiv1;
  309. ucLomod = ucLomod1 / 16;
  310. } else {
  311. ucLoDiv = ucLoDiv2;
  312. ulNDiv = ulNDiv2;
  313. ucLomod = ucLomod2 / 16;
  314. }
  315. if ((ucLoDiv == 3) || (ucLoDiv == 6)) {
  316. refDiv = 18;
  317. ret = regmap_write(dev->regmap, 0x36, (refDiv - 8));
  318. if (ret)
  319. goto err;
  320. ulNDiv = ((tuner_freq_MHz * ucLoDiv * 1000) * refDiv
  321. / fcry_KHz - 1024) / 2;
  322. }
  323. reg27 = (0x80 + ((ucLomod << 4) & 0x70)
  324. + ((ulNDiv >> 8) & 0x0F)) & 0xFF;
  325. ret = regmap_write(dev->regmap, 0x27, reg27);
  326. if (ret)
  327. goto err;
  328. ret = regmap_write(dev->regmap, 0x28, (u8)(ulNDiv & 0xFF));
  329. if (ret)
  330. goto err;
  331. ret = regmap_write(dev->regmap, 0x29, 0x80);
  332. if (ret)
  333. goto err;
  334. ret = regmap_write(dev->regmap, 0x31, 0x03);
  335. if (ret)
  336. goto err;
  337. if (ucLoDiv == 3)
  338. utmp = 0xCE;
  339. else
  340. utmp = 0x8A;
  341. ret = regmap_write(dev->regmap, 0x3b, utmp);
  342. if (ret)
  343. goto err;
  344. dev->frequency_khz = fcry_KHz * (ulNDiv * 2 + 1024) / refDiv / ucLoDiv;
  345. dev_dbg(&dev->client->dev,
  346. "actual tune frequency=%d\n", dev->frequency_khz);
  347. err:
  348. if (ret)
  349. dev_dbg(&dev->client->dev, "failed=%d\n", ret);
  350. return ret;
  351. }
  352. static int m88rs6000t_set_bb(struct m88rs6000t_dev *dev,
  353. u32 symbol_rate_KSs, s32 lpf_offset_KHz)
  354. {
  355. u32 f3dB;
  356. u8 reg40;
  357. f3dB = symbol_rate_KSs * 9 / 14 + 2000;
  358. f3dB += lpf_offset_KHz;
  359. f3dB = clamp_val(f3dB, 6000U, 43000U);
  360. reg40 = f3dB / 1000;
  361. return regmap_write(dev->regmap, 0x40, reg40);
  362. }
  363. static int m88rs6000t_set_params(struct dvb_frontend *fe)
  364. {
  365. struct m88rs6000t_dev *dev = fe->tuner_priv;
  366. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  367. int ret;
  368. s32 lpf_offset_KHz;
  369. u32 realFreq, freq_MHz;
  370. dev_dbg(&dev->client->dev,
  371. "frequency=%d symbol_rate=%d\n",
  372. c->frequency, c->symbol_rate);
  373. if (c->symbol_rate < 5000000)
  374. lpf_offset_KHz = 3000;
  375. else
  376. lpf_offset_KHz = 0;
  377. realFreq = c->frequency + lpf_offset_KHz;
  378. /* set tuner pll.*/
  379. freq_MHz = (realFreq + 500) / 1000;
  380. ret = m88rs6000t_set_pll_freq(dev, freq_MHz);
  381. if (ret)
  382. goto err;
  383. ret = m88rs6000t_set_bb(dev, c->symbol_rate / 1000, lpf_offset_KHz);
  384. if (ret)
  385. goto err;
  386. ret = regmap_write(dev->regmap, 0x00, 0x01);
  387. if (ret)
  388. goto err;
  389. ret = regmap_write(dev->regmap, 0x00, 0x00);
  390. if (ret)
  391. goto err;
  392. /* set demod mlck */
  393. ret = m88rs6000t_set_demod_mclk(fe);
  394. err:
  395. if (ret)
  396. dev_dbg(&dev->client->dev, "failed=%d\n", ret);
  397. return ret;
  398. }
  399. static int m88rs6000t_init(struct dvb_frontend *fe)
  400. {
  401. struct m88rs6000t_dev *dev = fe->tuner_priv;
  402. int ret;
  403. dev_dbg(&dev->client->dev, "%s:\n", __func__);
  404. ret = regmap_update_bits(dev->regmap, 0x11, 0x08, 0x08);
  405. if (ret)
  406. goto err;
  407. usleep_range(5000, 50000);
  408. ret = regmap_update_bits(dev->regmap, 0x10, 0x01, 0x01);
  409. if (ret)
  410. goto err;
  411. usleep_range(10000, 50000);
  412. ret = regmap_write(dev->regmap, 0x07, 0x7d);
  413. err:
  414. if (ret)
  415. dev_dbg(&dev->client->dev, "failed=%d\n", ret);
  416. return ret;
  417. }
  418. static int m88rs6000t_sleep(struct dvb_frontend *fe)
  419. {
  420. struct m88rs6000t_dev *dev = fe->tuner_priv;
  421. int ret;
  422. dev_dbg(&dev->client->dev, "%s:\n", __func__);
  423. ret = regmap_write(dev->regmap, 0x07, 0x6d);
  424. if (ret)
  425. goto err;
  426. usleep_range(5000, 10000);
  427. err:
  428. if (ret)
  429. dev_dbg(&dev->client->dev, "failed=%d\n", ret);
  430. return ret;
  431. }
  432. static int m88rs6000t_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  433. {
  434. struct m88rs6000t_dev *dev = fe->tuner_priv;
  435. dev_dbg(&dev->client->dev, "\n");
  436. *frequency = dev->frequency_khz;
  437. return 0;
  438. }
  439. static int m88rs6000t_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
  440. {
  441. struct m88rs6000t_dev *dev = fe->tuner_priv;
  442. dev_dbg(&dev->client->dev, "\n");
  443. *frequency = 0; /* Zero-IF */
  444. return 0;
  445. }
  446. static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
  447. {
  448. struct m88rs6000t_dev *dev = fe->tuner_priv;
  449. unsigned int val, i;
  450. int ret;
  451. u16 gain;
  452. u32 PGA2_cri_GS = 46, PGA2_crf_GS = 290, TIA_GS = 290;
  453. u32 RF_GC = 1200, IF_GC = 1100, BB_GC = 300;
  454. u32 PGA2_GC = 300, TIA_GC = 300, PGA2_cri = 0, PGA2_crf = 0;
  455. u32 RFG = 0, IFG = 0, BBG = 0, PGA2G = 0, TIAG = 0;
  456. u32 RFGS[13] = {0, 245, 266, 268, 270, 285,
  457. 298, 295, 283, 285, 285, 300, 300};
  458. u32 IFGS[12] = {0, 300, 230, 270, 270, 285,
  459. 295, 285, 290, 295, 295, 310};
  460. u32 BBGS[14] = {0, 286, 275, 290, 294, 300, 290,
  461. 290, 285, 283, 260, 295, 290, 260};
  462. ret = regmap_read(dev->regmap, 0x5A, &val);
  463. if (ret)
  464. goto err;
  465. RF_GC = val & 0x0f;
  466. ret = regmap_read(dev->regmap, 0x5F, &val);
  467. if (ret)
  468. goto err;
  469. IF_GC = val & 0x0f;
  470. ret = regmap_read(dev->regmap, 0x3F, &val);
  471. if (ret)
  472. goto err;
  473. TIA_GC = (val >> 4) & 0x07;
  474. ret = regmap_read(dev->regmap, 0x77, &val);
  475. if (ret)
  476. goto err;
  477. BB_GC = (val >> 4) & 0x0f;
  478. ret = regmap_read(dev->regmap, 0x76, &val);
  479. if (ret)
  480. goto err;
  481. PGA2_GC = val & 0x3f;
  482. PGA2_cri = PGA2_GC >> 2;
  483. PGA2_crf = PGA2_GC & 0x03;
  484. for (i = 0; i <= RF_GC; i++)
  485. RFG += RFGS[i];
  486. if (RF_GC == 0)
  487. RFG += 400;
  488. if (RF_GC == 1)
  489. RFG += 300;
  490. if (RF_GC == 2)
  491. RFG += 200;
  492. if (RF_GC == 3)
  493. RFG += 100;
  494. for (i = 0; i <= IF_GC; i++)
  495. IFG += IFGS[i];
  496. TIAG = TIA_GC * TIA_GS;
  497. for (i = 0; i <= BB_GC; i++)
  498. BBG += BBGS[i];
  499. PGA2G = PGA2_cri * PGA2_cri_GS + PGA2_crf * PGA2_crf_GS;
  500. gain = RFG + IFG - TIAG + BBG + PGA2G;
  501. /* scale value to 0x0000-0xffff */
  502. gain = clamp_val(gain, 1000U, 10500U);
  503. *strength = (10500 - gain) * 0xffff / (10500 - 1000);
  504. err:
  505. if (ret)
  506. dev_dbg(&dev->client->dev, "failed=%d\n", ret);
  507. return ret;
  508. }
  509. static const struct dvb_tuner_ops m88rs6000t_tuner_ops = {
  510. .info = {
  511. .name = "Montage M88RS6000 Internal Tuner",
  512. .frequency_min = 950000,
  513. .frequency_max = 2150000,
  514. },
  515. .init = m88rs6000t_init,
  516. .sleep = m88rs6000t_sleep,
  517. .set_params = m88rs6000t_set_params,
  518. .get_frequency = m88rs6000t_get_frequency,
  519. .get_if_frequency = m88rs6000t_get_if_frequency,
  520. .get_rf_strength = m88rs6000t_get_rf_strength,
  521. };
  522. static int m88rs6000t_probe(struct i2c_client *client,
  523. const struct i2c_device_id *id)
  524. {
  525. struct m88rs6000t_config *cfg = client->dev.platform_data;
  526. struct dvb_frontend *fe = cfg->fe;
  527. struct m88rs6000t_dev *dev;
  528. int ret, i;
  529. unsigned int utmp;
  530. static const struct regmap_config regmap_config = {
  531. .reg_bits = 8,
  532. .val_bits = 8,
  533. };
  534. static const struct m88rs6000t_reg_val reg_vals[] = {
  535. {0x10, 0xfb},
  536. {0x24, 0x38},
  537. {0x11, 0x0a},
  538. {0x12, 0x00},
  539. {0x2b, 0x1c},
  540. {0x44, 0x48},
  541. {0x54, 0x24},
  542. {0x55, 0x06},
  543. {0x59, 0x00},
  544. {0x5b, 0x4c},
  545. {0x60, 0x8b},
  546. {0x61, 0xf4},
  547. {0x65, 0x07},
  548. {0x6d, 0x6f},
  549. {0x6e, 0x31},
  550. {0x3c, 0xf3},
  551. {0x37, 0x0f},
  552. {0x48, 0x28},
  553. {0x49, 0xd8},
  554. {0x70, 0x66},
  555. {0x71, 0xCF},
  556. {0x72, 0x81},
  557. {0x73, 0xA7},
  558. {0x74, 0x4F},
  559. {0x75, 0xFC},
  560. };
  561. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  562. if (!dev) {
  563. ret = -ENOMEM;
  564. dev_err(&client->dev, "kzalloc() failed\n");
  565. goto err;
  566. }
  567. memcpy(&dev->cfg, cfg, sizeof(struct m88rs6000t_config));
  568. dev->client = client;
  569. dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
  570. if (IS_ERR(dev->regmap)) {
  571. ret = PTR_ERR(dev->regmap);
  572. goto err;
  573. }
  574. ret = regmap_update_bits(dev->regmap, 0x11, 0x08, 0x08);
  575. if (ret)
  576. goto err;
  577. usleep_range(5000, 50000);
  578. ret = regmap_update_bits(dev->regmap, 0x10, 0x01, 0x01);
  579. if (ret)
  580. goto err;
  581. usleep_range(10000, 50000);
  582. ret = regmap_write(dev->regmap, 0x07, 0x7d);
  583. if (ret)
  584. goto err;
  585. ret = regmap_write(dev->regmap, 0x04, 0x01);
  586. if (ret)
  587. goto err;
  588. /* check tuner chip id */
  589. ret = regmap_read(dev->regmap, 0x01, &utmp);
  590. if (ret)
  591. goto err;
  592. dev_info(&dev->client->dev, "chip_id=%02x\n", utmp);
  593. if (utmp != 0x64) {
  594. ret = -ENODEV;
  595. goto err;
  596. }
  597. /* tuner init. */
  598. ret = regmap_write(dev->regmap, 0x05, 0x40);
  599. if (ret)
  600. goto err;
  601. ret = regmap_write(dev->regmap, 0x11, 0x08);
  602. if (ret)
  603. goto err;
  604. ret = regmap_write(dev->regmap, 0x15, 0x6c);
  605. if (ret)
  606. goto err;
  607. ret = regmap_write(dev->regmap, 0x17, 0xc1);
  608. if (ret)
  609. goto err;
  610. ret = regmap_write(dev->regmap, 0x17, 0x81);
  611. if (ret)
  612. goto err;
  613. usleep_range(10000, 50000);
  614. ret = regmap_write(dev->regmap, 0x05, 0x00);
  615. if (ret)
  616. goto err;
  617. ret = regmap_write(dev->regmap, 0x11, 0x0a);
  618. if (ret)
  619. goto err;
  620. for (i = 0; i < ARRAY_SIZE(reg_vals); i++) {
  621. ret = regmap_write(dev->regmap,
  622. reg_vals[i].reg, reg_vals[i].val);
  623. if (ret)
  624. goto err;
  625. }
  626. dev_info(&dev->client->dev, "Montage M88RS6000 internal tuner successfully identified\n");
  627. fe->tuner_priv = dev;
  628. memcpy(&fe->ops.tuner_ops, &m88rs6000t_tuner_ops,
  629. sizeof(struct dvb_tuner_ops));
  630. i2c_set_clientdata(client, dev);
  631. return 0;
  632. err:
  633. dev_dbg(&client->dev, "failed=%d\n", ret);
  634. kfree(dev);
  635. return ret;
  636. }
  637. static int m88rs6000t_remove(struct i2c_client *client)
  638. {
  639. struct m88rs6000t_dev *dev = i2c_get_clientdata(client);
  640. struct dvb_frontend *fe = dev->cfg.fe;
  641. dev_dbg(&client->dev, "\n");
  642. memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
  643. fe->tuner_priv = NULL;
  644. kfree(dev);
  645. return 0;
  646. }
  647. static const struct i2c_device_id m88rs6000t_id[] = {
  648. {"m88rs6000t", 0},
  649. {}
  650. };
  651. MODULE_DEVICE_TABLE(i2c, m88rs6000t_id);
  652. static struct i2c_driver m88rs6000t_driver = {
  653. .driver = {
  654. .name = "m88rs6000t",
  655. },
  656. .probe = m88rs6000t_probe,
  657. .remove = m88rs6000t_remove,
  658. .id_table = m88rs6000t_id,
  659. };
  660. module_i2c_driver(m88rs6000t_driver);
  661. MODULE_AUTHOR("Max nibble <nibble.max@gmail.com>");
  662. MODULE_DESCRIPTION("Montage M88RS6000 internal tuner driver");
  663. MODULE_LICENSE("GPL");