tda8290.c 22 KB

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