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