tda8290.c 22 KB

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