cx88-dvb.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. /*
  2. *
  3. * device driver for Conexant 2388x based TV cards
  4. * MPEG Transport Stream (DVB) routines
  5. *
  6. * (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
  7. * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/device.h>
  26. #include <linux/fs.h>
  27. #include <linux/kthread.h>
  28. #include <linux/file.h>
  29. #include <linux/suspend.h>
  30. #include "cx88.h"
  31. #include "dvb-pll.h"
  32. #include <media/v4l2-common.h>
  33. #ifdef HAVE_MT352
  34. # include "mt352.h"
  35. # include "mt352_priv.h"
  36. # ifdef HAVE_VP3054_I2C
  37. # include "cx88-vp3054-i2c.h"
  38. # endif
  39. #endif
  40. #ifdef HAVE_CX22702
  41. # include "cx22702.h"
  42. #endif
  43. #ifdef HAVE_OR51132
  44. # include "or51132.h"
  45. #endif
  46. #ifdef HAVE_LGDT330X
  47. # include "lgdt330x.h"
  48. #endif
  49. #ifdef HAVE_NXT200X
  50. # include "nxt200x.h"
  51. #endif
  52. #ifdef HAVE_CX24123
  53. # include "cx24123.h"
  54. #endif
  55. MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
  56. MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
  57. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  58. MODULE_LICENSE("GPL");
  59. static unsigned int debug = 0;
  60. module_param(debug, int, 0644);
  61. MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
  62. #define dprintk(level,fmt, arg...) if (debug >= level) \
  63. printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
  64. /* ------------------------------------------------------------------ */
  65. static int dvb_buf_setup(struct videobuf_queue *q,
  66. unsigned int *count, unsigned int *size)
  67. {
  68. struct cx8802_dev *dev = q->priv_data;
  69. dev->ts_packet_size = 188 * 4;
  70. dev->ts_packet_count = 32;
  71. *size = dev->ts_packet_size * dev->ts_packet_count;
  72. *count = 32;
  73. return 0;
  74. }
  75. static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
  76. enum v4l2_field field)
  77. {
  78. struct cx8802_dev *dev = q->priv_data;
  79. return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb,field);
  80. }
  81. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  82. {
  83. struct cx8802_dev *dev = q->priv_data;
  84. cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
  85. }
  86. static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
  87. {
  88. struct cx8802_dev *dev = q->priv_data;
  89. cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb);
  90. }
  91. static struct videobuf_queue_ops dvb_qops = {
  92. .buf_setup = dvb_buf_setup,
  93. .buf_prepare = dvb_buf_prepare,
  94. .buf_queue = dvb_buf_queue,
  95. .buf_release = dvb_buf_release,
  96. };
  97. /* ------------------------------------------------------------------ */
  98. #ifdef HAVE_MT352
  99. static int generic_mt352_demod_init(struct dvb_frontend* fe)
  100. {
  101. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
  102. static u8 reset [] = { RESET, 0x80 };
  103. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  104. static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
  105. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  106. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  107. mt352_write(fe, clock_config, sizeof(clock_config));
  108. udelay(200);
  109. mt352_write(fe, reset, sizeof(reset));
  110. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  111. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  112. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  113. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  114. return 0;
  115. }
  116. static int dvico_dual_demod_init(struct dvb_frontend *fe)
  117. {
  118. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x38 };
  119. static u8 reset [] = { RESET, 0x80 };
  120. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  121. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };
  122. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  123. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  124. mt352_write(fe, clock_config, sizeof(clock_config));
  125. udelay(200);
  126. mt352_write(fe, reset, sizeof(reset));
  127. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  128. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  129. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  130. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  131. return 0;
  132. }
  133. static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
  134. {
  135. static u8 clock_config [] = { 0x89, 0x38, 0x39 };
  136. static u8 reset [] = { 0x50, 0x80 };
  137. static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  138. static u8 agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
  139. 0x00, 0xFF, 0x00, 0x40, 0x40 };
  140. static u8 dntv_extra[] = { 0xB5, 0x7A };
  141. static u8 capt_range_cfg[] = { 0x75, 0x32 };
  142. mt352_write(fe, clock_config, sizeof(clock_config));
  143. udelay(2000);
  144. mt352_write(fe, reset, sizeof(reset));
  145. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  146. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  147. udelay(2000);
  148. mt352_write(fe, dntv_extra, sizeof(dntv_extra));
  149. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  150. return 0;
  151. }
  152. static int mt352_pll_set(struct dvb_frontend* fe,
  153. struct dvb_frontend_parameters* params,
  154. u8* pllbuf)
  155. {
  156. struct cx8802_dev *dev= fe->dvb->priv;
  157. pllbuf[0] = dev->core->pll_addr << 1;
  158. dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
  159. params->frequency,
  160. params->u.ofdm.bandwidth);
  161. return 0;
  162. }
  163. static struct mt352_config dvico_fusionhdtv = {
  164. .demod_address = 0x0F,
  165. .demod_init = generic_mt352_demod_init,
  166. .pll_set = mt352_pll_set,
  167. };
  168. static struct mt352_config dntv_live_dvbt_config = {
  169. .demod_address = 0x0f,
  170. .demod_init = dntv_live_dvbt_demod_init,
  171. .pll_set = mt352_pll_set,
  172. };
  173. static struct mt352_config dvico_fusionhdtv_dual = {
  174. .demod_address = 0x0F,
  175. .demod_init = dvico_dual_demod_init,
  176. .pll_set = mt352_pll_set,
  177. };
  178. #ifdef HAVE_VP3054_I2C
  179. static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
  180. {
  181. struct cx8802_dev *dev= fe->dvb->priv;
  182. /* this message is to set up ATC and ALC */
  183. static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
  184. struct i2c_msg msg =
  185. { .addr = dev->core->pll_addr, .flags = 0,
  186. .buf = fmd1216_init, .len = sizeof(fmd1216_init) };
  187. int err;
  188. if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
  189. if (err < 0)
  190. return err;
  191. else
  192. return -EREMOTEIO;
  193. }
  194. return 0;
  195. }
  196. static int dntv_live_dvbt_pro_pll_set(struct dvb_frontend* fe,
  197. struct dvb_frontend_parameters* params,
  198. u8* pllbuf)
  199. {
  200. struct cx8802_dev *dev= fe->dvb->priv;
  201. struct i2c_msg msg =
  202. { .addr = dev->core->pll_addr, .flags = 0,
  203. .buf = pllbuf+1, .len = 4 };
  204. int err;
  205. /* Switch PLL to DVB mode */
  206. err = philips_fmd1216_pll_init(fe);
  207. if (err)
  208. return err;
  209. /* Tune PLL */
  210. pllbuf[0] = dev->core->pll_addr << 1;
  211. dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
  212. params->frequency,
  213. params->u.ofdm.bandwidth);
  214. if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
  215. printk(KERN_WARNING "cx88-dvb: %s error "
  216. "(addr %02x <- %02x, err = %i)\n",
  217. __FUNCTION__, pllbuf[0], pllbuf[1], err);
  218. if (err < 0)
  219. return err;
  220. else
  221. return -EREMOTEIO;
  222. }
  223. return 0;
  224. }
  225. static struct mt352_config dntv_live_dvbt_pro_config = {
  226. .demod_address = 0x0f,
  227. .no_tuner = 1,
  228. .demod_init = generic_mt352_demod_init,
  229. .pll_set = dntv_live_dvbt_pro_pll_set,
  230. };
  231. #endif
  232. #endif
  233. #ifdef HAVE_CX22702
  234. static struct cx22702_config connexant_refboard_config = {
  235. .demod_address = 0x43,
  236. .output_mode = CX22702_SERIAL_OUTPUT,
  237. .pll_address = 0x60,
  238. .pll_desc = &dvb_pll_thomson_dtt7579,
  239. };
  240. static struct cx22702_config hauppauge_novat_config = {
  241. .demod_address = 0x43,
  242. .output_mode = CX22702_SERIAL_OUTPUT,
  243. .pll_address = 0x61,
  244. .pll_desc = &dvb_pll_thomson_dtt759x,
  245. };
  246. static struct cx22702_config hauppauge_hvr1100_config = {
  247. .demod_address = 0x63,
  248. .output_mode = CX22702_SERIAL_OUTPUT,
  249. .pll_address = 0x61,
  250. .pll_desc = &dvb_pll_fmd1216me,
  251. };
  252. #endif
  253. #ifdef HAVE_OR51132
  254. static int or51132_set_ts_param(struct dvb_frontend* fe,
  255. int is_punctured)
  256. {
  257. struct cx8802_dev *dev= fe->dvb->priv;
  258. dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
  259. return 0;
  260. }
  261. static struct or51132_config pchdtv_hd3000 = {
  262. .demod_address = 0x15,
  263. .pll_address = 0x61,
  264. .pll_desc = &dvb_pll_thomson_dtt7610,
  265. .set_ts_params = or51132_set_ts_param,
  266. };
  267. #endif
  268. #ifdef HAVE_LGDT330X
  269. static int lgdt330x_pll_set(struct dvb_frontend* fe,
  270. struct dvb_frontend_parameters* params)
  271. {
  272. /* FIXME make this routine use the tuner-simple code.
  273. * It could probably be shared with a number of ATSC
  274. * frontends. Many share the same tuner with analog TV. */
  275. struct cx8802_dev *dev= fe->dvb->priv;
  276. struct cx88_core *core = dev->core;
  277. u8 buf[4];
  278. struct i2c_msg msg =
  279. { .addr = dev->core->pll_addr, .flags = 0, .buf = buf, .len = 4 };
  280. int err;
  281. /* Put the analog decoder in standby to keep it quiet */
  282. cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
  283. dvb_pll_configure(core->pll_desc, buf, params->frequency, 0);
  284. dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
  285. __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]);
  286. if ((err = i2c_transfer(&core->i2c_adap, &msg, 1)) != 1) {
  287. printk(KERN_WARNING "cx88-dvb: %s error "
  288. "(addr %02x <- %02x, err = %i)\n",
  289. __FUNCTION__, buf[0], buf[1], err);
  290. if (err < 0)
  291. return err;
  292. else
  293. return -EREMOTEIO;
  294. }
  295. if (core->tuner_type == TUNER_LG_TDVS_H062F) {
  296. /* Set the Auxiliary Byte. */
  297. buf[2] &= ~0x20;
  298. buf[2] |= 0x18;
  299. buf[3] = 0x50;
  300. i2c_transfer(&core->i2c_adap, &msg, 1);
  301. }
  302. return 0;
  303. }
  304. static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
  305. {
  306. struct cx8802_dev *dev= fe->dvb->priv;
  307. struct cx88_core *core = dev->core;
  308. dprintk(1, "%s: index = %d\n", __FUNCTION__, index);
  309. if (index == 0)
  310. cx_clear(MO_GP0_IO, 8);
  311. else
  312. cx_set(MO_GP0_IO, 8);
  313. return 0;
  314. }
  315. static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
  316. {
  317. struct cx8802_dev *dev= fe->dvb->priv;
  318. if (is_punctured)
  319. dev->ts_gen_cntrl |= 0x04;
  320. else
  321. dev->ts_gen_cntrl &= ~0x04;
  322. return 0;
  323. }
  324. static struct lgdt330x_config fusionhdtv_3_gold = {
  325. .demod_address = 0x0e,
  326. .demod_chip = LGDT3302,
  327. .serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
  328. .pll_set = lgdt330x_pll_set,
  329. .set_ts_params = lgdt330x_set_ts_param,
  330. };
  331. static struct lgdt330x_config fusionhdtv_5_gold = {
  332. .demod_address = 0x0e,
  333. .demod_chip = LGDT3303,
  334. .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
  335. .pll_set = lgdt330x_pll_set,
  336. .set_ts_params = lgdt330x_set_ts_param,
  337. };
  338. #endif
  339. #ifdef HAVE_NXT200X
  340. static int nxt200x_set_ts_param(struct dvb_frontend* fe,
  341. int is_punctured)
  342. {
  343. struct cx8802_dev *dev= fe->dvb->priv;
  344. dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
  345. return 0;
  346. }
  347. static int nxt200x_set_pll_input(u8* buf, int input)
  348. {
  349. if (input)
  350. buf[3] |= 0x08;
  351. else
  352. buf[3] &= ~0x08;
  353. return 0;
  354. }
  355. static struct nxt200x_config ati_hdtvwonder = {
  356. .demod_address = 0x0a,
  357. .pll_address = 0x61,
  358. .pll_desc = &dvb_pll_tuv1236d,
  359. .set_pll_input = nxt200x_set_pll_input,
  360. .set_ts_params = nxt200x_set_ts_param,
  361. };
  362. #endif
  363. #ifdef HAVE_CX24123
  364. static int cx24123_set_ts_param(struct dvb_frontend* fe,
  365. int is_punctured)
  366. {
  367. struct cx8802_dev *dev= fe->dvb->priv;
  368. dev->ts_gen_cntrl = 0x2;
  369. return 0;
  370. }
  371. static void cx24123_enable_lnb_voltage(struct dvb_frontend* fe, int on)
  372. {
  373. struct cx8802_dev *dev= fe->dvb->priv;
  374. struct cx88_core *core = dev->core;
  375. if (on)
  376. cx_write(MO_GP0_IO, 0x000006f9);
  377. else
  378. cx_write(MO_GP0_IO, 0x000006fB);
  379. }
  380. static struct cx24123_config hauppauge_novas_config = {
  381. .demod_address = 0x55,
  382. .use_isl6421 = 1,
  383. .set_ts_params = cx24123_set_ts_param,
  384. };
  385. static struct cx24123_config kworld_dvbs_100_config = {
  386. .demod_address = 0x15,
  387. .use_isl6421 = 0,
  388. .set_ts_params = cx24123_set_ts_param,
  389. .enable_lnb_voltage = cx24123_enable_lnb_voltage,
  390. };
  391. #endif
  392. static int dvb_register(struct cx8802_dev *dev)
  393. {
  394. /* init struct videobuf_dvb */
  395. dev->dvb.name = dev->core->name;
  396. dev->ts_gen_cntrl = 0x0c;
  397. /* init frontend */
  398. switch (dev->core->board) {
  399. #ifdef HAVE_CX22702
  400. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  401. dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
  402. &dev->core->i2c_adap);
  403. break;
  404. case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
  405. case CX88_BOARD_CONEXANT_DVB_T1:
  406. case CX88_BOARD_KWORLD_DVB_T_CX22702:
  407. case CX88_BOARD_WINFAST_DTV1000:
  408. dev->dvb.frontend = cx22702_attach(&connexant_refboard_config,
  409. &dev->core->i2c_adap);
  410. break;
  411. case CX88_BOARD_HAUPPAUGE_HVR1100:
  412. case CX88_BOARD_HAUPPAUGE_HVR1100LP:
  413. dev->dvb.frontend = cx22702_attach(&hauppauge_hvr1100_config,
  414. &dev->core->i2c_adap);
  415. break;
  416. #endif
  417. #ifdef HAVE_MT352
  418. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
  419. dev->core->pll_addr = 0x61;
  420. dev->core->pll_desc = &dvb_pll_lg_z201;
  421. dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
  422. &dev->core->i2c_adap);
  423. break;
  424. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
  425. dev->core->pll_addr = 0x60;
  426. dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
  427. dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
  428. &dev->core->i2c_adap);
  429. break;
  430. case CX88_BOARD_KWORLD_DVB_T:
  431. case CX88_BOARD_DNTV_LIVE_DVB_T:
  432. case CX88_BOARD_ADSTECH_DVB_T_PCI:
  433. dev->core->pll_addr = 0x61;
  434. dev->core->pll_desc = &dvb_pll_unknown_1;
  435. dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
  436. &dev->core->i2c_adap);
  437. break;
  438. case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
  439. #ifdef HAVE_VP3054_I2C
  440. dev->core->pll_addr = 0x61;
  441. dev->core->pll_desc = &dvb_pll_fmd1216me;
  442. dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_pro_config,
  443. &((struct vp3054_i2c_state *)dev->card_priv)->adap);
  444. #else
  445. printk("%s: built without vp3054 support\n", dev->core->name);
  446. #endif
  447. break;
  448. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
  449. /* The tin box says DEE1601, but it seems to be DTT7579
  450. * compatible, with a slightly different MT352 AGC gain. */
  451. dev->core->pll_addr = 0x61;
  452. dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
  453. dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv_dual,
  454. &dev->core->i2c_adap);
  455. break;
  456. #endif
  457. #ifdef HAVE_OR51132
  458. case CX88_BOARD_PCHDTV_HD3000:
  459. dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
  460. &dev->core->i2c_adap);
  461. break;
  462. #endif
  463. #ifdef HAVE_LGDT330X
  464. case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
  465. dev->ts_gen_cntrl = 0x08;
  466. {
  467. /* Do a hardware reset of chip before using it. */
  468. struct cx88_core *core = dev->core;
  469. cx_clear(MO_GP0_IO, 1);
  470. mdelay(100);
  471. cx_set(MO_GP0_IO, 1);
  472. mdelay(200);
  473. /* Select RF connector callback */
  474. fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
  475. dev->core->pll_addr = 0x61;
  476. dev->core->pll_desc = &dvb_pll_microtune_4042;
  477. dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold,
  478. &dev->core->i2c_adap);
  479. }
  480. break;
  481. case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
  482. dev->ts_gen_cntrl = 0x08;
  483. {
  484. /* Do a hardware reset of chip before using it. */
  485. struct cx88_core *core = dev->core;
  486. cx_clear(MO_GP0_IO, 1);
  487. mdelay(100);
  488. cx_set(MO_GP0_IO, 9);
  489. mdelay(200);
  490. dev->core->pll_addr = 0x61;
  491. dev->core->pll_desc = &dvb_pll_thomson_dtt761x;
  492. dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold,
  493. &dev->core->i2c_adap);
  494. }
  495. break;
  496. case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
  497. dev->ts_gen_cntrl = 0x08;
  498. {
  499. /* Do a hardware reset of chip before using it. */
  500. struct cx88_core *core = dev->core;
  501. cx_clear(MO_GP0_IO, 1);
  502. mdelay(100);
  503. cx_set(MO_GP0_IO, 1);
  504. mdelay(200);
  505. dev->core->pll_addr = 0x61;
  506. dev->core->pll_desc = &dvb_pll_tdvs_tua6034;
  507. dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_5_gold,
  508. &dev->core->i2c_adap);
  509. }
  510. break;
  511. #endif
  512. #ifdef HAVE_NXT200X
  513. case CX88_BOARD_ATI_HDTVWONDER:
  514. dev->dvb.frontend = nxt200x_attach(&ati_hdtvwonder,
  515. &dev->core->i2c_adap);
  516. break;
  517. #endif
  518. #ifdef HAVE_CX24123
  519. case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
  520. case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
  521. dev->dvb.frontend = cx24123_attach(&hauppauge_novas_config,
  522. &dev->core->i2c_adap);
  523. break;
  524. case CX88_BOARD_KWORLD_DVBS_100:
  525. dev->dvb.frontend = cx24123_attach(&kworld_dvbs_100_config,
  526. &dev->core->i2c_adap);
  527. break;
  528. #endif
  529. default:
  530. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  531. dev->core->name);
  532. break;
  533. }
  534. if (NULL == dev->dvb.frontend) {
  535. printk("%s: frontend initialization failed\n",dev->core->name);
  536. return -1;
  537. }
  538. if (dev->core->pll_desc) {
  539. dev->dvb.frontend->ops->info.frequency_min = dev->core->pll_desc->min;
  540. dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max;
  541. }
  542. /* Put the analog decoder in standby to keep it quiet */
  543. cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
  544. /* register everything */
  545. return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
  546. }
  547. /* ----------------------------------------------------------- */
  548. static int __devinit dvb_probe(struct pci_dev *pci_dev,
  549. const struct pci_device_id *pci_id)
  550. {
  551. struct cx8802_dev *dev;
  552. struct cx88_core *core;
  553. int err;
  554. /* general setup */
  555. core = cx88_core_get(pci_dev);
  556. if (NULL == core)
  557. return -EINVAL;
  558. err = -ENODEV;
  559. if (!cx88_boards[core->board].dvb)
  560. goto fail_core;
  561. err = -ENOMEM;
  562. dev = kmalloc(sizeof(*dev),GFP_KERNEL);
  563. if (NULL == dev)
  564. goto fail_core;
  565. memset(dev,0,sizeof(*dev));
  566. dev->pci = pci_dev;
  567. dev->core = core;
  568. err = cx8802_init_common(dev);
  569. if (0 != err)
  570. goto fail_free;
  571. #ifdef HAVE_VP3054_I2C
  572. err = vp3054_i2c_probe(dev);
  573. if (0 != err)
  574. goto fail_free;
  575. #endif
  576. /* dvb stuff */
  577. printk("%s/2: cx2388x based dvb card\n", core->name);
  578. videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
  579. dev->pci, &dev->slock,
  580. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  581. V4L2_FIELD_TOP,
  582. sizeof(struct cx88_buffer),
  583. dev);
  584. err = dvb_register(dev);
  585. if (0 != err)
  586. goto fail_fini;
  587. /* Maintain a reference to cx88-video can query the 8802 device. */
  588. core->dvbdev = dev;
  589. return 0;
  590. fail_fini:
  591. cx8802_fini_common(dev);
  592. fail_free:
  593. kfree(dev);
  594. fail_core:
  595. cx88_core_put(core,pci_dev);
  596. return err;
  597. }
  598. static void __devexit dvb_remove(struct pci_dev *pci_dev)
  599. {
  600. struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
  601. /* Destroy any 8802 reference. */
  602. dev->core->dvbdev = NULL;
  603. /* dvb */
  604. videobuf_dvb_unregister(&dev->dvb);
  605. #ifdef HAVE_VP3054_I2C
  606. vp3054_i2c_remove(dev);
  607. #endif
  608. /* common */
  609. cx8802_fini_common(dev);
  610. cx88_core_put(dev->core,dev->pci);
  611. kfree(dev);
  612. }
  613. static struct pci_device_id cx8802_pci_tbl[] = {
  614. {
  615. .vendor = 0x14f1,
  616. .device = 0x8802,
  617. .subvendor = PCI_ANY_ID,
  618. .subdevice = PCI_ANY_ID,
  619. },{
  620. /* --- end of list --- */
  621. }
  622. };
  623. MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
  624. static struct pci_driver dvb_pci_driver = {
  625. .name = "cx88-dvb",
  626. .id_table = cx8802_pci_tbl,
  627. .probe = dvb_probe,
  628. .remove = __devexit_p(dvb_remove),
  629. .suspend = cx8802_suspend_common,
  630. .resume = cx8802_resume_common,
  631. };
  632. static int dvb_init(void)
  633. {
  634. printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
  635. (CX88_VERSION_CODE >> 16) & 0xff,
  636. (CX88_VERSION_CODE >> 8) & 0xff,
  637. CX88_VERSION_CODE & 0xff);
  638. #ifdef SNAPSHOT
  639. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  640. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  641. #endif
  642. return pci_register_driver(&dvb_pci_driver);
  643. }
  644. static void dvb_fini(void)
  645. {
  646. pci_unregister_driver(&dvb_pci_driver);
  647. }
  648. module_init(dvb_init);
  649. module_exit(dvb_fini);
  650. /*
  651. * Local variables:
  652. * c-basic-offset: 8
  653. * compile-command: "make DVB=1"
  654. * End:
  655. */