tda8290.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /*
  2. i2c tv tuner chip device driver
  3. controls the philips tda8290+75 tuner chip combo.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. This "tda8290" module was split apart from the original "tuner" module.
  16. */
  17. #include <linux/i2c.h>
  18. #include <linux/delay.h>
  19. #include <linux/videodev.h>
  20. #include "tuner-driver.h"
  21. #include "tuner-i2c.h"
  22. #include "tda8290.h"
  23. #include "tda827x.h"
  24. #include "tda18271.h"
  25. static int debug;
  26. module_param(debug, int, 0644);
  27. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  28. #define PREFIX "tda8290"
  29. /* ---------------------------------------------------------------------- */
  30. struct tda8290_priv {
  31. struct tuner_i2c_props i2c_props;
  32. unsigned char tda8290_easy_mode;
  33. unsigned char tda827x_addr;
  34. unsigned char ver;
  35. #define TDA8290 1
  36. #define TDA8295 2
  37. #define TDA8275 4
  38. #define TDA8275A 8
  39. #define TDA18271 16
  40. struct tda827x_config cfg;
  41. };
  42. /*---------------------------------------------------------------------*/
  43. static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
  44. {
  45. struct tda8290_priv *priv = fe->analog_demod_priv;
  46. unsigned char enable[2] = { 0x21, 0xC0 };
  47. unsigned char disable[2] = { 0x21, 0x00 };
  48. unsigned char *msg;
  49. if (close) {
  50. msg = enable;
  51. tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
  52. /* let the bridge stabilize */
  53. msleep(20);
  54. } else {
  55. msg = disable;
  56. tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
  57. }
  58. return 0;
  59. }
  60. static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
  61. {
  62. struct tda8290_priv *priv = fe->analog_demod_priv;
  63. unsigned char enable[2] = { 0x45, 0xc1 };
  64. unsigned char disable[2] = { 0x46, 0x00 };
  65. unsigned char buf[3] = { 0x45, 0x01, 0x00 };
  66. unsigned char *msg;
  67. if (close) {
  68. msg = enable;
  69. tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
  70. /* let the bridge stabilize */
  71. msleep(20);
  72. } else {
  73. msg = disable;
  74. tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
  75. tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
  76. buf[2] = msg[1];
  77. buf[2] &= ~0x04;
  78. tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
  79. msleep(5);
  80. msg[1] |= 0x04;
  81. tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
  82. }
  83. return 0;
  84. }
  85. /*---------------------------------------------------------------------*/
  86. static void set_audio(struct dvb_frontend *fe,
  87. struct analog_parameters *params)
  88. {
  89. struct tda8290_priv *priv = fe->analog_demod_priv;
  90. char* mode;
  91. if (params->std & V4L2_STD_MN) {
  92. priv->tda8290_easy_mode = 0x01;
  93. mode = "MN";
  94. } else if (params->std & V4L2_STD_B) {
  95. priv->tda8290_easy_mode = 0x02;
  96. mode = "B";
  97. } else if (params->std & V4L2_STD_GH) {
  98. priv->tda8290_easy_mode = 0x04;
  99. mode = "GH";
  100. } else if (params->std & V4L2_STD_PAL_I) {
  101. priv->tda8290_easy_mode = 0x08;
  102. mode = "I";
  103. } else if (params->std & V4L2_STD_DK) {
  104. priv->tda8290_easy_mode = 0x10;
  105. mode = "DK";
  106. } else if (params->std & V4L2_STD_SECAM_L) {
  107. priv->tda8290_easy_mode = 0x20;
  108. mode = "L";
  109. } else if (params->std & V4L2_STD_SECAM_LC) {
  110. priv->tda8290_easy_mode = 0x40;
  111. mode = "LC";
  112. } else {
  113. priv->tda8290_easy_mode = 0x10;
  114. mode = "xx";
  115. }
  116. tuner_dbg("setting tda829x to system %s\n", mode);
  117. }
  118. static void tda8290_set_params(struct dvb_frontend *fe,
  119. struct analog_parameters *params)
  120. {
  121. struct tda8290_priv *priv = fe->analog_demod_priv;
  122. unsigned char soft_reset[] = { 0x00, 0x00 };
  123. unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
  124. unsigned char expert_mode[] = { 0x01, 0x80 };
  125. unsigned char agc_out_on[] = { 0x02, 0x00 };
  126. unsigned char gainset_off[] = { 0x28, 0x14 };
  127. unsigned char if_agc_spd[] = { 0x0f, 0x88 };
  128. unsigned char adc_head_6[] = { 0x05, 0x04 };
  129. unsigned char adc_head_9[] = { 0x05, 0x02 };
  130. unsigned char adc_head_12[] = { 0x05, 0x01 };
  131. unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
  132. unsigned char pll_bw_low[] = { 0x0d, 0x27 };
  133. unsigned char gainset_2[] = { 0x28, 0x64 };
  134. unsigned char agc_rst_on[] = { 0x0e, 0x0b };
  135. unsigned char agc_rst_off[] = { 0x0e, 0x09 };
  136. unsigned char if_agc_set[] = { 0x0f, 0x81 };
  137. unsigned char addr_adc_sat = 0x1a;
  138. unsigned char addr_agc_stat = 0x1d;
  139. unsigned char addr_pll_stat = 0x1b;
  140. unsigned char adc_sat, agc_stat,
  141. pll_stat;
  142. int i;
  143. set_audio(fe, params);
  144. if (priv->cfg.config)
  145. tuner_dbg("tda827xa config is 0x%02x\n", *priv->cfg.config);
  146. tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
  147. tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
  148. tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
  149. msleep(1);
  150. expert_mode[1] = priv->tda8290_easy_mode + 0x80;
  151. tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
  152. tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
  153. tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
  154. if (priv->tda8290_easy_mode & 0x60)
  155. tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
  156. else
  157. tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
  158. tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
  159. tda8290_i2c_bridge(fe, 1);
  160. if (fe->ops.tuner_ops.set_analog_params)
  161. fe->ops.tuner_ops.set_analog_params(fe, params);
  162. for (i = 0; i < 3; i++) {
  163. tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
  164. tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
  165. if (pll_stat & 0x80) {
  166. tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
  167. tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
  168. tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
  169. tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
  170. tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
  171. break;
  172. } else {
  173. tuner_dbg("tda8290 not locked, no signal?\n");
  174. msleep(100);
  175. }
  176. }
  177. /* adjust headroom resp. gain */
  178. if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
  179. tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
  180. agc_stat, adc_sat, pll_stat & 0x80);
  181. tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
  182. msleep(100);
  183. tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
  184. tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
  185. tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
  186. tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
  187. if ((agc_stat > 115) || !(pll_stat & 0x80)) {
  188. tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
  189. agc_stat, pll_stat & 0x80);
  190. if (priv->cfg.agcf)
  191. priv->cfg.agcf(fe);
  192. msleep(100);
  193. tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
  194. tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
  195. tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
  196. tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
  197. if((agc_stat > 115) || !(pll_stat & 0x80)) {
  198. tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
  199. tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
  200. tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
  201. msleep(100);
  202. }
  203. }
  204. }
  205. /* l/ l' deadlock? */
  206. if(priv->tda8290_easy_mode & 0x60) {
  207. tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
  208. tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
  209. tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
  210. tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
  211. if ((adc_sat > 20) || !(pll_stat & 0x80)) {
  212. tuner_dbg("trying to resolve SECAM L deadlock\n");
  213. tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
  214. msleep(40);
  215. tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
  216. }
  217. }
  218. tda8290_i2c_bridge(fe, 0);
  219. tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
  220. }
  221. /*---------------------------------------------------------------------*/
  222. static void tda8295_power(struct dvb_frontend *fe, int enable)
  223. {
  224. struct tda8290_priv *priv = fe->analog_demod_priv;
  225. unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
  226. tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
  227. tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
  228. if (enable)
  229. buf[1] = 0x01;
  230. else
  231. buf[1] = 0x03;
  232. tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
  233. }
  234. static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
  235. {
  236. struct tda8290_priv *priv = fe->analog_demod_priv;
  237. unsigned char buf[] = { 0x01, 0x00 };
  238. tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
  239. tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
  240. if (enable)
  241. buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
  242. else
  243. buf[1] = 0x00; /* reset active bit */
  244. tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
  245. }
  246. static void tda8295_set_video_std(struct dvb_frontend *fe)
  247. {
  248. struct tda8290_priv *priv = fe->analog_demod_priv;
  249. unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
  250. tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
  251. tda8295_set_easy_mode(fe, 1);
  252. msleep(20);
  253. tda8295_set_easy_mode(fe, 0);
  254. }
  255. /*---------------------------------------------------------------------*/
  256. static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
  257. {
  258. struct tda8290_priv *priv = fe->analog_demod_priv;
  259. unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
  260. tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
  261. tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
  262. if (enable)
  263. buf[1] &= ~0x40;
  264. else
  265. buf[1] |= 0x40;
  266. tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
  267. }
  268. static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
  269. {
  270. struct tda8290_priv *priv = fe->analog_demod_priv;
  271. unsigned char set_gpio_cf[] = { 0x44, 0x00 };
  272. unsigned char set_gpio_val[] = { 0x46, 0x00 };
  273. tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
  274. tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
  275. tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
  276. tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
  277. set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
  278. if (enable) {
  279. set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
  280. set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
  281. }
  282. tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
  283. tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
  284. }
  285. static int tda8295_has_signal(struct dvb_frontend *fe)
  286. {
  287. struct tda8290_priv *priv = fe->analog_demod_priv;
  288. unsigned char hvpll_stat = 0x26;
  289. unsigned char ret;
  290. tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
  291. tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
  292. return (ret & 0x01) ? 65535 : 0;
  293. }
  294. /*---------------------------------------------------------------------*/
  295. static void tda8295_set_params(struct dvb_frontend *fe,
  296. struct analog_parameters *params)
  297. {
  298. struct tda8290_priv *priv = fe->analog_demod_priv;
  299. unsigned char blanking_mode[] = { 0x1d, 0x00 };
  300. set_audio(fe, params);
  301. tuner_dbg("%s: freq = %d\n", __FUNCTION__, params->frequency);
  302. tda8295_power(fe, 1);
  303. tda8295_agc1_out(fe, 1);
  304. tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
  305. tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
  306. tda8295_set_video_std(fe);
  307. blanking_mode[1] = 0x03;
  308. tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
  309. msleep(20);
  310. tda8295_i2c_bridge(fe, 1);
  311. if (fe->ops.tuner_ops.set_analog_params)
  312. fe->ops.tuner_ops.set_analog_params(fe, params);
  313. if (priv->cfg.agcf)
  314. priv->cfg.agcf(fe);
  315. if (tda8295_has_signal(fe))
  316. tuner_dbg("tda8295 is locked\n");
  317. else
  318. tuner_dbg("tda8295 not locked, no signal?\n");
  319. tda8295_i2c_bridge(fe, 0);
  320. }
  321. /*---------------------------------------------------------------------*/
  322. static int tda8290_has_signal(struct dvb_frontend *fe)
  323. {
  324. struct tda8290_priv *priv = fe->analog_demod_priv;
  325. unsigned char i2c_get_afc[1] = { 0x1B };
  326. unsigned char afc = 0;
  327. tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
  328. tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
  329. return (afc & 0x80)? 65535:0;
  330. }
  331. /*---------------------------------------------------------------------*/
  332. static void tda8290_standby(struct dvb_frontend *fe)
  333. {
  334. struct tda8290_priv *priv = fe->analog_demod_priv;
  335. unsigned char cb1[] = { 0x30, 0xD0 };
  336. unsigned char tda8290_standby[] = { 0x00, 0x02 };
  337. unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
  338. struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
  339. tda8290_i2c_bridge(fe, 1);
  340. if (priv->ver & TDA8275A)
  341. cb1[1] = 0x90;
  342. i2c_transfer(priv->i2c_props.adap, &msg, 1);
  343. tda8290_i2c_bridge(fe, 0);
  344. tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
  345. tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
  346. }
  347. static void tda8295_standby(struct dvb_frontend *fe)
  348. {
  349. tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
  350. tda8295_power(fe, 0);
  351. }
  352. static void tda8290_init_if(struct dvb_frontend *fe)
  353. {
  354. struct tda8290_priv *priv = fe->analog_demod_priv;
  355. unsigned char set_VS[] = { 0x30, 0x6F };
  356. unsigned char set_GP00_CF[] = { 0x20, 0x01 };
  357. unsigned char set_GP01_CF[] = { 0x20, 0x0B };
  358. if ((priv->cfg.config) &&
  359. ((*priv->cfg.config == 1) || (*priv->cfg.config == 2)))
  360. tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
  361. else
  362. tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
  363. tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
  364. }
  365. static void tda8295_init_if(struct dvb_frontend *fe)
  366. {
  367. struct tda8290_priv *priv = fe->analog_demod_priv;
  368. static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
  369. static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
  370. static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
  371. static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
  372. static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
  373. static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
  374. static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
  375. tda8295_power(fe, 1);
  376. tda8295_set_easy_mode(fe, 0);
  377. tda8295_set_video_std(fe);
  378. tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
  379. tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
  380. tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
  381. tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
  382. tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
  383. tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
  384. tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
  385. tda8295_agc1_out(fe, 0);
  386. tda8295_agc2_out(fe, 0);
  387. }
  388. static void tda8290_init_tuner(struct dvb_frontend *fe)
  389. {
  390. struct tda8290_priv *priv = fe->analog_demod_priv;
  391. unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
  392. 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
  393. unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
  394. 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
  395. struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
  396. .buf=tda8275_init, .len = 14};
  397. if (priv->ver & TDA8275A)
  398. msg.buf = tda8275a_init;
  399. tda8290_i2c_bridge(fe, 1);
  400. i2c_transfer(priv->i2c_props.adap, &msg, 1);
  401. tda8290_i2c_bridge(fe, 0);
  402. }
  403. /*---------------------------------------------------------------------*/
  404. static void tda829x_release(struct dvb_frontend *fe)
  405. {
  406. if (fe->ops.tuner_ops.release)
  407. fe->ops.tuner_ops.release(fe);
  408. kfree(fe->analog_demod_priv);
  409. fe->analog_demod_priv = NULL;
  410. }
  411. static int tda829x_find_tuner(struct dvb_frontend *fe)
  412. {
  413. struct tda8290_priv *priv = fe->analog_demod_priv;
  414. struct analog_tuner_ops *ops = fe->ops.analog_demod_ops;
  415. int i, ret, tuners_found;
  416. u32 tuner_addrs;
  417. u8 data;
  418. struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
  419. if (NULL == ops)
  420. return -EINVAL;
  421. ops->i2c_gate_ctrl(fe, 1);
  422. /* probe for tuner chip */
  423. tuners_found = 0;
  424. tuner_addrs = 0;
  425. for (i = 0x60; i <= 0x63; i++) {
  426. msg.addr = i;
  427. ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
  428. if (ret == 1) {
  429. tuners_found++;
  430. tuner_addrs = (tuner_addrs << 8) + i;
  431. }
  432. }
  433. /* if there is more than one tuner, we expect the right one is
  434. behind the bridge and we choose the highest address that doesn't
  435. give a response now
  436. */
  437. ops->i2c_gate_ctrl(fe, 0);
  438. if (tuners_found > 1)
  439. for (i = 0; i < tuners_found; i++) {
  440. msg.addr = tuner_addrs & 0xff;
  441. ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
  442. if (ret == 1)
  443. tuner_addrs = tuner_addrs >> 8;
  444. else
  445. break;
  446. }
  447. if (tuner_addrs == 0) {
  448. tuner_addrs = 0x60;
  449. tuner_info("could not clearly identify tuner address, "
  450. "defaulting to %x\n", tuner_addrs);
  451. } else {
  452. tuner_addrs = tuner_addrs & 0xff;
  453. tuner_info("setting tuner address to %x\n", tuner_addrs);
  454. }
  455. priv->tda827x_addr = tuner_addrs;
  456. msg.addr = tuner_addrs;
  457. ops->i2c_gate_ctrl(fe, 1);
  458. ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
  459. if (ret != 1) {
  460. tuner_warn("tuner access failed!\n");
  461. return -EREMOTEIO;
  462. }
  463. if (data == 0x83) {
  464. priv->ver |= TDA18271;
  465. tda18271_attach(fe, priv->tda827x_addr,
  466. priv->i2c_props.adap);
  467. } else {
  468. if ((data & 0x3c) == 0)
  469. priv->ver |= TDA8275;
  470. else
  471. priv->ver |= TDA8275A;
  472. tda827x_attach(fe, priv->tda827x_addr,
  473. priv->i2c_props.adap, &priv->cfg);
  474. }
  475. if (fe->ops.tuner_ops.init)
  476. fe->ops.tuner_ops.init(fe);
  477. if (fe->ops.tuner_ops.sleep)
  478. fe->ops.tuner_ops.sleep(fe);
  479. ops->i2c_gate_ctrl(fe, 0);
  480. return 0;
  481. }
  482. static int tda8290_probe(struct tuner_i2c_props *i2c_props)
  483. {
  484. #define TDA8290_ID 0x89
  485. unsigned char tda8290_id[] = { 0x1f, 0x00 };
  486. /* detect tda8290 */
  487. tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
  488. tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
  489. if (tda8290_id[1] == TDA8290_ID) {
  490. if (debug)
  491. printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
  492. __FUNCTION__, i2c_adapter_id(i2c_props->adap),
  493. i2c_props->addr);
  494. return 0;
  495. }
  496. return -ENODEV;
  497. }
  498. static int tda8295_probe(struct tuner_i2c_props *i2c_props)
  499. {
  500. #define TDA8295_ID 0x8a
  501. unsigned char tda8295_id[] = { 0x2f, 0x00 };
  502. /* detect tda8295 */
  503. tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
  504. tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
  505. if (tda8295_id[1] == TDA8295_ID) {
  506. if (debug)
  507. printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n",
  508. __FUNCTION__, i2c_adapter_id(i2c_props->adap),
  509. i2c_props->addr);
  510. return 0;
  511. }
  512. return -ENODEV;
  513. }
  514. static struct analog_tuner_ops tda8290_tuner_ops = {
  515. .info = {
  516. .name = "TDA8290",
  517. },
  518. .set_params = tda8290_set_params,
  519. .has_signal = tda8290_has_signal,
  520. .standby = tda8290_standby,
  521. .release = tda829x_release,
  522. .i2c_gate_ctrl = tda8290_i2c_bridge,
  523. };
  524. static struct analog_tuner_ops tda8295_tuner_ops = {
  525. .info = {
  526. .name = "TDA8295",
  527. },
  528. .set_params = tda8295_set_params,
  529. .has_signal = tda8295_has_signal,
  530. .standby = tda8295_standby,
  531. .release = tda829x_release,
  532. .i2c_gate_ctrl = tda8295_i2c_bridge,
  533. };
  534. struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
  535. struct i2c_adapter *i2c_adap, u8 i2c_addr,
  536. struct tda829x_config *cfg)
  537. {
  538. struct tda8290_priv *priv = NULL;
  539. char *name;
  540. priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
  541. if (priv == NULL)
  542. return NULL;
  543. fe->analog_demod_priv = priv;
  544. priv->i2c_props.addr = i2c_addr;
  545. priv->i2c_props.adap = i2c_adap;
  546. if (cfg) {
  547. priv->cfg.config = cfg->lna_cfg;
  548. priv->cfg.tuner_callback = cfg->tuner_callback;
  549. }
  550. if (tda8290_probe(&priv->i2c_props) == 0) {
  551. priv->ver = TDA8290;
  552. fe->ops.analog_demod_ops = &tda8290_tuner_ops;
  553. }
  554. if (tda8295_probe(&priv->i2c_props) == 0) {
  555. priv->ver = TDA8295;
  556. fe->ops.analog_demod_ops = &tda8295_tuner_ops;
  557. }
  558. if (tda829x_find_tuner(fe) < 0)
  559. goto fail;
  560. switch (priv->ver) {
  561. case TDA8290 | TDA8275:
  562. name = "tda8290+75";
  563. break;
  564. case TDA8295 | TDA8275:
  565. name = "tda8295+75";
  566. break;
  567. case TDA8290 | TDA8275A:
  568. name = "tda8290+75a";
  569. break;
  570. case TDA8295 | TDA8275A:
  571. name = "tda8295+75a";
  572. break;
  573. case TDA8290 | TDA18271:
  574. name = "tda8290+18271";
  575. break;
  576. case TDA8295 | TDA18271:
  577. name = "tda8295+18271";
  578. break;
  579. default:
  580. goto fail;
  581. }
  582. tuner_info("type set to %s\n", name);
  583. if (priv->ver & TDA8290) {
  584. tda8290_init_tuner(fe);
  585. tda8290_init_if(fe);
  586. } else if (priv->ver & TDA8295)
  587. tda8295_init_if(fe);
  588. return fe;
  589. fail:
  590. tda829x_release(fe);
  591. fe->ops.analog_demod_ops = NULL;
  592. return NULL;
  593. }
  594. EXPORT_SYMBOL_GPL(tda829x_attach);
  595. int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
  596. {
  597. struct tuner_i2c_props i2c_props = {
  598. .adap = i2c_adap,
  599. .addr = i2c_addr,
  600. };
  601. unsigned char soft_reset[] = { 0x00, 0x00 };
  602. unsigned char easy_mode_b[] = { 0x01, 0x02 };
  603. unsigned char easy_mode_g[] = { 0x01, 0x04 };
  604. unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
  605. unsigned char addr_dto_lsb = 0x07;
  606. unsigned char data;
  607. #define PROBE_BUFFER_SIZE 8
  608. unsigned char buf[PROBE_BUFFER_SIZE];
  609. int i;
  610. /* rule out tda9887, which would return the same byte repeatedly */
  611. tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
  612. tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
  613. for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
  614. if (buf[i] != buf[0])
  615. break;
  616. }
  617. /* all bytes are equal, not a tda829x - probably a tda9887 */
  618. if (i == PROBE_BUFFER_SIZE)
  619. return -ENODEV;
  620. if ((tda8290_probe(&i2c_props) == 0) ||
  621. (tda8295_probe(&i2c_props) == 0))
  622. return 0;
  623. /* fall back to old probing method */
  624. tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
  625. tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
  626. tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
  627. tuner_i2c_xfer_recv(&i2c_props, &data, 1);
  628. if (data == 0) {
  629. tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
  630. tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
  631. tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
  632. tuner_i2c_xfer_recv(&i2c_props, &data, 1);
  633. if (data == 0x7b) {
  634. return 0;
  635. }
  636. }
  637. tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
  638. return -ENODEV;
  639. }
  640. EXPORT_SYMBOL_GPL(tda829x_probe);
  641. MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
  642. MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
  643. MODULE_LICENSE("GPL");
  644. /*
  645. * Overrides for Emacs so that we follow Linus's tabbing style.
  646. * ---------------------------------------------------------------------------
  647. * Local variables:
  648. * c-basic-offset: 8
  649. * End:
  650. */