tda8290.c 22 KB

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