em28xx-dvb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. DVB device driver for em28xx
  3. (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org>
  4. (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
  5. - Fixes for the driver to properly work with HVR-950
  6. - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
  7. - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
  8. (c) 2008 Aidan Thornton <makosoft@googlemail.com>
  9. Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
  10. (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
  11. (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/slab.h>
  18. #include <linux/usb.h>
  19. #include "em28xx.h"
  20. #include <media/v4l2-common.h>
  21. #include <media/videobuf-vmalloc.h>
  22. #include <media/tuner.h>
  23. #include "tuner-simple.h"
  24. #include "lgdt330x.h"
  25. #include "lgdt3305.h"
  26. #include "zl10353.h"
  27. #include "s5h1409.h"
  28. #include "mt352.h"
  29. #include "mt352_priv.h" /* FIXME */
  30. #include "tda1002x.h"
  31. #include "tda18271.h"
  32. #include "s921.h"
  33. MODULE_DESCRIPTION("driver for em28xx based DVB cards");
  34. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  35. MODULE_LICENSE("GPL");
  36. static unsigned int debug;
  37. module_param(debug, int, 0644);
  38. MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
  39. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  40. #define dprintk(level, fmt, arg...) do { \
  41. if (debug >= level) \
  42. printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
  43. } while (0)
  44. #define EM28XX_DVB_NUM_BUFS 5
  45. #define EM28XX_DVB_MAX_PACKETS 64
  46. struct em28xx_dvb {
  47. struct dvb_frontend *frontend;
  48. /* feed count management */
  49. struct mutex lock;
  50. int nfeeds;
  51. /* general boilerplate stuff */
  52. struct dvb_adapter adapter;
  53. struct dvb_demux demux;
  54. struct dmxdev dmxdev;
  55. struct dmx_frontend fe_hw;
  56. struct dmx_frontend fe_mem;
  57. struct dvb_net net;
  58. };
  59. static inline void print_err_status(struct em28xx *dev,
  60. int packet, int status)
  61. {
  62. char *errmsg = "Unknown";
  63. switch (status) {
  64. case -ENOENT:
  65. errmsg = "unlinked synchronuously";
  66. break;
  67. case -ECONNRESET:
  68. errmsg = "unlinked asynchronuously";
  69. break;
  70. case -ENOSR:
  71. errmsg = "Buffer error (overrun)";
  72. break;
  73. case -EPIPE:
  74. errmsg = "Stalled (device not responding)";
  75. break;
  76. case -EOVERFLOW:
  77. errmsg = "Babble (bad cable?)";
  78. break;
  79. case -EPROTO:
  80. errmsg = "Bit-stuff error (bad cable?)";
  81. break;
  82. case -EILSEQ:
  83. errmsg = "CRC/Timeout (could be anything)";
  84. break;
  85. case -ETIME:
  86. errmsg = "Device does not respond";
  87. break;
  88. }
  89. if (packet < 0) {
  90. dprintk(1, "URB status %d [%s].\n", status, errmsg);
  91. } else {
  92. dprintk(1, "URB packet %d, status %d [%s].\n",
  93. packet, status, errmsg);
  94. }
  95. }
  96. static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
  97. {
  98. int i;
  99. if (!dev)
  100. return 0;
  101. if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
  102. return 0;
  103. if (urb->status < 0) {
  104. print_err_status(dev, -1, urb->status);
  105. if (urb->status == -ENOENT)
  106. return 0;
  107. }
  108. for (i = 0; i < urb->number_of_packets; i++) {
  109. int status = urb->iso_frame_desc[i].status;
  110. if (status < 0) {
  111. print_err_status(dev, i, status);
  112. if (urb->iso_frame_desc[i].status != -EPROTO)
  113. continue;
  114. }
  115. dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
  116. urb->iso_frame_desc[i].offset,
  117. urb->iso_frame_desc[i].actual_length);
  118. }
  119. return 0;
  120. }
  121. static int start_streaming(struct em28xx_dvb *dvb)
  122. {
  123. int rc;
  124. struct em28xx *dev = dvb->adapter.priv;
  125. int max_dvb_packet_size;
  126. usb_set_interface(dev->udev, 0, 1);
  127. rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  128. if (rc < 0)
  129. return rc;
  130. max_dvb_packet_size = em28xx_isoc_dvb_max_packetsize(dev);
  131. return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS,
  132. EM28XX_DVB_NUM_BUFS, max_dvb_packet_size,
  133. dvb_isoc_copy);
  134. }
  135. static int stop_streaming(struct em28xx_dvb *dvb)
  136. {
  137. struct em28xx *dev = dvb->adapter.priv;
  138. em28xx_uninit_isoc(dev);
  139. em28xx_set_mode(dev, EM28XX_SUSPEND);
  140. return 0;
  141. }
  142. static int start_feed(struct dvb_demux_feed *feed)
  143. {
  144. struct dvb_demux *demux = feed->demux;
  145. struct em28xx_dvb *dvb = demux->priv;
  146. int rc, ret;
  147. if (!demux->dmx.frontend)
  148. return -EINVAL;
  149. mutex_lock(&dvb->lock);
  150. dvb->nfeeds++;
  151. rc = dvb->nfeeds;
  152. if (dvb->nfeeds == 1) {
  153. ret = start_streaming(dvb);
  154. if (ret < 0)
  155. rc = ret;
  156. }
  157. mutex_unlock(&dvb->lock);
  158. return rc;
  159. }
  160. static int stop_feed(struct dvb_demux_feed *feed)
  161. {
  162. struct dvb_demux *demux = feed->demux;
  163. struct em28xx_dvb *dvb = demux->priv;
  164. int err = 0;
  165. mutex_lock(&dvb->lock);
  166. dvb->nfeeds--;
  167. if (0 == dvb->nfeeds)
  168. err = stop_streaming(dvb);
  169. mutex_unlock(&dvb->lock);
  170. return err;
  171. }
  172. /* ------------------------------------------------------------------ */
  173. static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
  174. {
  175. struct em28xx *dev = fe->dvb->priv;
  176. if (acquire)
  177. return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  178. else
  179. return em28xx_set_mode(dev, EM28XX_SUSPEND);
  180. }
  181. /* ------------------------------------------------------------------ */
  182. static struct lgdt330x_config em2880_lgdt3303_dev = {
  183. .demod_address = 0x0e,
  184. .demod_chip = LGDT3303,
  185. };
  186. static struct lgdt3305_config em2870_lgdt3304_dev = {
  187. .i2c_addr = 0x0e,
  188. .demod_chip = LGDT3304,
  189. .spectral_inversion = 1,
  190. .deny_i2c_rptr = 1,
  191. .mpeg_mode = LGDT3305_MPEG_PARALLEL,
  192. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  193. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  194. .vsb_if_khz = 3250,
  195. .qam_if_khz = 4000,
  196. };
  197. static struct s921_config sharp_isdbt = {
  198. .demod_address = 0x30 >> 1
  199. };
  200. static struct zl10353_config em28xx_zl10353_with_xc3028 = {
  201. .demod_address = (0x1e >> 1),
  202. .no_tuner = 1,
  203. .parallel_ts = 1,
  204. .if2 = 45600,
  205. };
  206. static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
  207. .demod_address = 0x32 >> 1,
  208. .output_mode = S5H1409_PARALLEL_OUTPUT,
  209. .gpio = S5H1409_GPIO_OFF,
  210. .inversion = S5H1409_INVERSION_OFF,
  211. .status_mode = S5H1409_DEMODLOCKING,
  212. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
  213. };
  214. static struct tda18271_std_map kworld_a340_std_map = {
  215. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
  216. .if_lvl = 1, .rfagc_top = 0x37, },
  217. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
  218. .if_lvl = 1, .rfagc_top = 0x37, },
  219. };
  220. static struct tda18271_config kworld_a340_config = {
  221. .std_map = &kworld_a340_std_map,
  222. };
  223. static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
  224. .demod_address = (0x1e >> 1),
  225. .no_tuner = 1,
  226. .disable_i2c_gate_ctrl = 1,
  227. .parallel_ts = 1,
  228. .if2 = 45600,
  229. };
  230. #ifdef EM28XX_DRX397XD_SUPPORT
  231. /* [TODO] djh - not sure yet what the device config needs to contain */
  232. static struct drx397xD_config em28xx_drx397xD_with_xc3028 = {
  233. .demod_address = (0xe0 >> 1),
  234. };
  235. #endif
  236. static int mt352_terratec_xs_init(struct dvb_frontend *fe)
  237. {
  238. /* Values extracted from a USB trace of the Terratec Windows driver */
  239. static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
  240. static u8 reset[] = { RESET, 0x80 };
  241. static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
  242. static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
  243. static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
  244. static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
  245. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  246. static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
  247. static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
  248. static u8 tuner_go[] = { TUNER_GO, 0x01};
  249. mt352_write(fe, clock_config, sizeof(clock_config));
  250. udelay(200);
  251. mt352_write(fe, reset, sizeof(reset));
  252. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  253. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  254. mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
  255. mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
  256. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  257. mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
  258. mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
  259. mt352_write(fe, tuner_go, sizeof(tuner_go));
  260. return 0;
  261. }
  262. static struct mt352_config terratec_xs_mt352_cfg = {
  263. .demod_address = (0x1e >> 1),
  264. .no_tuner = 1,
  265. .if2 = 45600,
  266. .demod_init = mt352_terratec_xs_init,
  267. };
  268. static struct tda10023_config em28xx_tda10023_config = {
  269. .demod_address = 0x0c,
  270. .invert = 1,
  271. };
  272. /* ------------------------------------------------------------------ */
  273. static int attach_xc3028(u8 addr, struct em28xx *dev)
  274. {
  275. struct dvb_frontend *fe;
  276. struct xc2028_config cfg;
  277. memset(&cfg, 0, sizeof(cfg));
  278. cfg.i2c_adap = &dev->i2c_adap;
  279. cfg.i2c_addr = addr;
  280. if (!dev->dvb->frontend) {
  281. em28xx_errdev("/2: dvb frontend not attached. "
  282. "Can't attach xc3028\n");
  283. return -EINVAL;
  284. }
  285. fe = dvb_attach(xc2028_attach, dev->dvb->frontend, &cfg);
  286. if (!fe) {
  287. em28xx_errdev("/2: xc3028 attach failed\n");
  288. dvb_frontend_detach(dev->dvb->frontend);
  289. dev->dvb->frontend = NULL;
  290. return -EINVAL;
  291. }
  292. em28xx_info("%s/2: xc3028 attached\n", dev->name);
  293. return 0;
  294. }
  295. /* ------------------------------------------------------------------ */
  296. static int register_dvb(struct em28xx_dvb *dvb,
  297. struct module *module,
  298. struct em28xx *dev,
  299. struct device *device)
  300. {
  301. int result;
  302. mutex_init(&dvb->lock);
  303. /* register adapter */
  304. result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
  305. adapter_nr);
  306. if (result < 0) {
  307. printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
  308. dev->name, result);
  309. goto fail_adapter;
  310. }
  311. /* Ensure all frontends negotiate bus access */
  312. dvb->frontend->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  313. dvb->adapter.priv = dev;
  314. /* register frontend */
  315. result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
  316. if (result < 0) {
  317. printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
  318. dev->name, result);
  319. goto fail_frontend;
  320. }
  321. /* register demux stuff */
  322. dvb->demux.dmx.capabilities =
  323. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  324. DMX_MEMORY_BASED_FILTERING;
  325. dvb->demux.priv = dvb;
  326. dvb->demux.filternum = 256;
  327. dvb->demux.feednum = 256;
  328. dvb->demux.start_feed = start_feed;
  329. dvb->demux.stop_feed = stop_feed;
  330. result = dvb_dmx_init(&dvb->demux);
  331. if (result < 0) {
  332. printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
  333. dev->name, result);
  334. goto fail_dmx;
  335. }
  336. dvb->dmxdev.filternum = 256;
  337. dvb->dmxdev.demux = &dvb->demux.dmx;
  338. dvb->dmxdev.capabilities = 0;
  339. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  340. if (result < 0) {
  341. printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
  342. dev->name, result);
  343. goto fail_dmxdev;
  344. }
  345. dvb->fe_hw.source = DMX_FRONTEND_0;
  346. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  347. if (result < 0) {
  348. printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  349. dev->name, result);
  350. goto fail_fe_hw;
  351. }
  352. dvb->fe_mem.source = DMX_MEMORY_FE;
  353. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  354. if (result < 0) {
  355. printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  356. dev->name, result);
  357. goto fail_fe_mem;
  358. }
  359. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  360. if (result < 0) {
  361. printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
  362. dev->name, result);
  363. goto fail_fe_conn;
  364. }
  365. /* register network adapter */
  366. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  367. return 0;
  368. fail_fe_conn:
  369. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  370. fail_fe_mem:
  371. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  372. fail_fe_hw:
  373. dvb_dmxdev_release(&dvb->dmxdev);
  374. fail_dmxdev:
  375. dvb_dmx_release(&dvb->demux);
  376. fail_dmx:
  377. dvb_unregister_frontend(dvb->frontend);
  378. fail_frontend:
  379. dvb_frontend_detach(dvb->frontend);
  380. dvb_unregister_adapter(&dvb->adapter);
  381. fail_adapter:
  382. return result;
  383. }
  384. static void unregister_dvb(struct em28xx_dvb *dvb)
  385. {
  386. dvb_net_release(&dvb->net);
  387. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  388. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  389. dvb_dmxdev_release(&dvb->dmxdev);
  390. dvb_dmx_release(&dvb->demux);
  391. dvb_unregister_frontend(dvb->frontend);
  392. dvb_frontend_detach(dvb->frontend);
  393. dvb_unregister_adapter(&dvb->adapter);
  394. }
  395. static int dvb_init(struct em28xx *dev)
  396. {
  397. int result = 0;
  398. struct em28xx_dvb *dvb;
  399. if (!dev->board.has_dvb) {
  400. /* This device does not support the extension */
  401. printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
  402. return 0;
  403. }
  404. dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
  405. if (dvb == NULL) {
  406. em28xx_info("em28xx_dvb: memory allocation failed\n");
  407. return -ENOMEM;
  408. }
  409. dev->dvb = dvb;
  410. mutex_lock(&dev->lock);
  411. em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  412. /* init frontend */
  413. switch (dev->model) {
  414. case EM2874_LEADERSHIP_ISDBT:
  415. dvb->frontend = dvb_attach(s921_attach,
  416. &sharp_isdbt, &dev->i2c_adap);
  417. if (!dvb->frontend) {
  418. result = -EINVAL;
  419. goto out_free;
  420. }
  421. break;
  422. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
  423. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
  424. case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
  425. case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
  426. dvb->frontend = dvb_attach(lgdt330x_attach,
  427. &em2880_lgdt3303_dev,
  428. &dev->i2c_adap);
  429. if (attach_xc3028(0x61, dev) < 0) {
  430. result = -EINVAL;
  431. goto out_free;
  432. }
  433. break;
  434. case EM2880_BOARD_KWORLD_DVB_310U:
  435. dvb->frontend = dvb_attach(zl10353_attach,
  436. &em28xx_zl10353_with_xc3028,
  437. &dev->i2c_adap);
  438. if (attach_xc3028(0x61, dev) < 0) {
  439. result = -EINVAL;
  440. goto out_free;
  441. }
  442. break;
  443. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  444. case EM2882_BOARD_TERRATEC_HYBRID_XS:
  445. case EM2880_BOARD_EMPIRE_DUAL_TV:
  446. dvb->frontend = dvb_attach(zl10353_attach,
  447. &em28xx_zl10353_xc3028_no_i2c_gate,
  448. &dev->i2c_adap);
  449. if (attach_xc3028(0x61, dev) < 0) {
  450. result = -EINVAL;
  451. goto out_free;
  452. }
  453. break;
  454. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  455. case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
  456. case EM2881_BOARD_PINNACLE_HYBRID_PRO:
  457. case EM2882_BOARD_DIKOM_DK300:
  458. case EM2882_BOARD_KWORLD_VS_DVBT:
  459. dvb->frontend = dvb_attach(zl10353_attach,
  460. &em28xx_zl10353_xc3028_no_i2c_gate,
  461. &dev->i2c_adap);
  462. if (dvb->frontend == NULL) {
  463. /* This board could have either a zl10353 or a mt352.
  464. If the chip id isn't for zl10353, try mt352 */
  465. dvb->frontend = dvb_attach(mt352_attach,
  466. &terratec_xs_mt352_cfg,
  467. &dev->i2c_adap);
  468. }
  469. if (attach_xc3028(0x61, dev) < 0) {
  470. result = -EINVAL;
  471. goto out_free;
  472. }
  473. break;
  474. case EM2883_BOARD_KWORLD_HYBRID_330U:
  475. case EM2882_BOARD_EVGA_INDTUBE:
  476. dvb->frontend = dvb_attach(s5h1409_attach,
  477. &em28xx_s5h1409_with_xc3028,
  478. &dev->i2c_adap);
  479. if (attach_xc3028(0x61, dev) < 0) {
  480. result = -EINVAL;
  481. goto out_free;
  482. }
  483. break;
  484. case EM2882_BOARD_KWORLD_ATSC_315U:
  485. dvb->frontend = dvb_attach(lgdt330x_attach,
  486. &em2880_lgdt3303_dev,
  487. &dev->i2c_adap);
  488. if (dvb->frontend != NULL) {
  489. if (!dvb_attach(simple_tuner_attach, dvb->frontend,
  490. &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
  491. result = -EINVAL;
  492. goto out_free;
  493. }
  494. }
  495. break;
  496. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
  497. #ifdef EM28XX_DRX397XD_SUPPORT
  498. /* We don't have the config structure properly populated, so
  499. this is commented out for now */
  500. dvb->frontend = dvb_attach(drx397xD_attach,
  501. &em28xx_drx397xD_with_xc3028,
  502. &dev->i2c_adap);
  503. if (attach_xc3028(0x61, dev) < 0) {
  504. result = -EINVAL;
  505. goto out_free;
  506. }
  507. break;
  508. #endif
  509. case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
  510. /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
  511. dvb->frontend = dvb_attach(tda10023_attach,
  512. &em28xx_tda10023_config,
  513. &dev->i2c_adap, 0x48);
  514. if (dvb->frontend) {
  515. if (!dvb_attach(simple_tuner_attach, dvb->frontend,
  516. &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
  517. result = -EINVAL;
  518. goto out_free;
  519. }
  520. }
  521. break;
  522. case EM2870_BOARD_KWORLD_A340:
  523. dvb->frontend = dvb_attach(lgdt3305_attach,
  524. &em2870_lgdt3304_dev,
  525. &dev->i2c_adap);
  526. if (dvb->frontend != NULL)
  527. dvb_attach(tda18271_attach, dvb->frontend, 0x60,
  528. &dev->i2c_adap, &kworld_a340_config);
  529. break;
  530. default:
  531. em28xx_errdev("/2: The frontend of your DVB/ATSC card"
  532. " isn't supported yet\n");
  533. break;
  534. }
  535. if (NULL == dvb->frontend) {
  536. em28xx_errdev("/2: frontend initialization failed\n");
  537. result = -EINVAL;
  538. goto out_free;
  539. }
  540. /* define general-purpose callback pointer */
  541. dvb->frontend->callback = em28xx_tuner_callback;
  542. /* register everything */
  543. result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
  544. if (result < 0)
  545. goto out_free;
  546. em28xx_info("Successfully loaded em28xx-dvb\n");
  547. ret:
  548. em28xx_set_mode(dev, EM28XX_SUSPEND);
  549. mutex_unlock(&dev->lock);
  550. return result;
  551. out_free:
  552. kfree(dvb);
  553. dev->dvb = NULL;
  554. goto ret;
  555. }
  556. static int dvb_fini(struct em28xx *dev)
  557. {
  558. if (!dev->board.has_dvb) {
  559. /* This device does not support the extension */
  560. return 0;
  561. }
  562. if (dev->dvb) {
  563. unregister_dvb(dev->dvb);
  564. kfree(dev->dvb);
  565. dev->dvb = NULL;
  566. }
  567. return 0;
  568. }
  569. static struct em28xx_ops dvb_ops = {
  570. .id = EM28XX_DVB,
  571. .name = "Em28xx dvb Extension",
  572. .init = dvb_init,
  573. .fini = dvb_fini,
  574. };
  575. static int __init em28xx_dvb_register(void)
  576. {
  577. return em28xx_register_extension(&dvb_ops);
  578. }
  579. static void __exit em28xx_dvb_unregister(void)
  580. {
  581. em28xx_unregister_extension(&dvb_ops);
  582. }
  583. module_init(em28xx_dvb_register);
  584. module_exit(em28xx_dvb_unregister);