em28xx-dvb.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. DVB device driver for em28xx
  3. (c) 2008-2011 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 <linux/gpio.h>
  25. #include "lgdt330x.h"
  26. #include "lgdt3305.h"
  27. #include "zl10353.h"
  28. #include "s5h1409.h"
  29. #include "mt352.h"
  30. #include "mt352_priv.h" /* FIXME */
  31. #include "tda1002x.h"
  32. #include "tda18271.h"
  33. #include "s921.h"
  34. #include "drxd.h"
  35. #include "cxd2820r.h"
  36. #include "tda18271c2dd.h"
  37. #include "drxk.h"
  38. #include "tda10071.h"
  39. #include "a8293.h"
  40. #include "qt1010.h"
  41. MODULE_DESCRIPTION("driver for em28xx based DVB cards");
  42. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  43. MODULE_LICENSE("GPL");
  44. static unsigned int debug;
  45. module_param(debug, int, 0644);
  46. MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
  47. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  48. #define dprintk(level, fmt, arg...) do { \
  49. if (debug >= level) \
  50. printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
  51. } while (0)
  52. struct em28xx_dvb {
  53. struct dvb_frontend *fe[2];
  54. /* feed count management */
  55. struct mutex lock;
  56. int nfeeds;
  57. /* general boilerplate stuff */
  58. struct dvb_adapter adapter;
  59. struct dvb_demux demux;
  60. struct dmxdev dmxdev;
  61. struct dmx_frontend fe_hw;
  62. struct dmx_frontend fe_mem;
  63. struct dvb_net net;
  64. /* Due to DRX-K - probably need changes */
  65. int (*gate_ctrl)(struct dvb_frontend *, int);
  66. struct semaphore pll_mutex;
  67. bool dont_attach_fe1;
  68. int lna_gpio;
  69. };
  70. static inline void print_err_status(struct em28xx *dev,
  71. int packet, int status)
  72. {
  73. char *errmsg = "Unknown";
  74. switch (status) {
  75. case -ENOENT:
  76. errmsg = "unlinked synchronuously";
  77. break;
  78. case -ECONNRESET:
  79. errmsg = "unlinked asynchronuously";
  80. break;
  81. case -ENOSR:
  82. errmsg = "Buffer error (overrun)";
  83. break;
  84. case -EPIPE:
  85. errmsg = "Stalled (device not responding)";
  86. break;
  87. case -EOVERFLOW:
  88. errmsg = "Babble (bad cable?)";
  89. break;
  90. case -EPROTO:
  91. errmsg = "Bit-stuff error (bad cable?)";
  92. break;
  93. case -EILSEQ:
  94. errmsg = "CRC/Timeout (could be anything)";
  95. break;
  96. case -ETIME:
  97. errmsg = "Device does not respond";
  98. break;
  99. }
  100. if (packet < 0) {
  101. dprintk(1, "URB status %d [%s].\n", status, errmsg);
  102. } else {
  103. dprintk(1, "URB packet %d, status %d [%s].\n",
  104. packet, status, errmsg);
  105. }
  106. }
  107. static inline int em28xx_dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
  108. {
  109. int i;
  110. if (!dev)
  111. return 0;
  112. if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
  113. return 0;
  114. if (urb->status < 0) {
  115. print_err_status(dev, -1, urb->status);
  116. if (urb->status == -ENOENT)
  117. return 0;
  118. }
  119. for (i = 0; i < urb->number_of_packets; i++) {
  120. int status = urb->iso_frame_desc[i].status;
  121. if (status < 0) {
  122. print_err_status(dev, i, status);
  123. if (urb->iso_frame_desc[i].status != -EPROTO)
  124. continue;
  125. }
  126. dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
  127. urb->iso_frame_desc[i].offset,
  128. urb->iso_frame_desc[i].actual_length);
  129. }
  130. return 0;
  131. }
  132. static int em28xx_start_streaming(struct em28xx_dvb *dvb)
  133. {
  134. int rc;
  135. struct em28xx *dev = dvb->adapter.priv;
  136. int max_dvb_packet_size;
  137. usb_set_interface(dev->udev, 0, dev->dvb_alt);
  138. rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  139. if (rc < 0)
  140. return rc;
  141. max_dvb_packet_size = dev->dvb_max_pkt_size;
  142. if (max_dvb_packet_size < 0)
  143. return max_dvb_packet_size;
  144. dprintk(1, "Using %d buffers each with %d x %d bytes\n",
  145. EM28XX_DVB_NUM_BUFS,
  146. EM28XX_DVB_MAX_PACKETS,
  147. max_dvb_packet_size);
  148. return em28xx_init_isoc(dev, EM28XX_DIGITAL_MODE,
  149. EM28XX_DVB_MAX_PACKETS, EM28XX_DVB_NUM_BUFS,
  150. max_dvb_packet_size, em28xx_dvb_isoc_copy);
  151. }
  152. static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
  153. {
  154. struct em28xx *dev = dvb->adapter.priv;
  155. em28xx_stop_urbs(dev);
  156. em28xx_set_mode(dev, EM28XX_SUSPEND);
  157. return 0;
  158. }
  159. static int em28xx_start_feed(struct dvb_demux_feed *feed)
  160. {
  161. struct dvb_demux *demux = feed->demux;
  162. struct em28xx_dvb *dvb = demux->priv;
  163. int rc, ret;
  164. if (!demux->dmx.frontend)
  165. return -EINVAL;
  166. mutex_lock(&dvb->lock);
  167. dvb->nfeeds++;
  168. rc = dvb->nfeeds;
  169. if (dvb->nfeeds == 1) {
  170. ret = em28xx_start_streaming(dvb);
  171. if (ret < 0)
  172. rc = ret;
  173. }
  174. mutex_unlock(&dvb->lock);
  175. return rc;
  176. }
  177. static int em28xx_stop_feed(struct dvb_demux_feed *feed)
  178. {
  179. struct dvb_demux *demux = feed->demux;
  180. struct em28xx_dvb *dvb = demux->priv;
  181. int err = 0;
  182. mutex_lock(&dvb->lock);
  183. dvb->nfeeds--;
  184. if (0 == dvb->nfeeds)
  185. err = em28xx_stop_streaming(dvb);
  186. mutex_unlock(&dvb->lock);
  187. return err;
  188. }
  189. /* ------------------------------------------------------------------ */
  190. static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
  191. {
  192. struct em28xx *dev = fe->dvb->priv;
  193. if (acquire)
  194. return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  195. else
  196. return em28xx_set_mode(dev, EM28XX_SUSPEND);
  197. }
  198. /* ------------------------------------------------------------------ */
  199. static struct lgdt330x_config em2880_lgdt3303_dev = {
  200. .demod_address = 0x0e,
  201. .demod_chip = LGDT3303,
  202. };
  203. static struct lgdt3305_config em2870_lgdt3304_dev = {
  204. .i2c_addr = 0x0e,
  205. .demod_chip = LGDT3304,
  206. .spectral_inversion = 1,
  207. .deny_i2c_rptr = 1,
  208. .mpeg_mode = LGDT3305_MPEG_PARALLEL,
  209. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  210. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  211. .vsb_if_khz = 3250,
  212. .qam_if_khz = 4000,
  213. };
  214. static struct s921_config sharp_isdbt = {
  215. .demod_address = 0x30 >> 1
  216. };
  217. static struct zl10353_config em28xx_zl10353_with_xc3028 = {
  218. .demod_address = (0x1e >> 1),
  219. .no_tuner = 1,
  220. .parallel_ts = 1,
  221. .if2 = 45600,
  222. };
  223. static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
  224. .demod_address = 0x32 >> 1,
  225. .output_mode = S5H1409_PARALLEL_OUTPUT,
  226. .gpio = S5H1409_GPIO_OFF,
  227. .inversion = S5H1409_INVERSION_OFF,
  228. .status_mode = S5H1409_DEMODLOCKING,
  229. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
  230. };
  231. static struct tda18271_std_map kworld_a340_std_map = {
  232. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
  233. .if_lvl = 1, .rfagc_top = 0x37, },
  234. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
  235. .if_lvl = 1, .rfagc_top = 0x37, },
  236. };
  237. static struct tda18271_config kworld_a340_config = {
  238. .std_map = &kworld_a340_std_map,
  239. };
  240. static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
  241. .demod_address = (0x1e >> 1),
  242. .no_tuner = 1,
  243. .disable_i2c_gate_ctrl = 1,
  244. .parallel_ts = 1,
  245. .if2 = 45600,
  246. };
  247. static struct drxd_config em28xx_drxd = {
  248. .demod_address = 0x70,
  249. .demod_revision = 0xa2,
  250. .pll_type = DRXD_PLL_NONE,
  251. .clock = 12000,
  252. .insert_rs_byte = 1,
  253. .IF = 42800000,
  254. .disable_i2c_gate_ctrl = 1,
  255. };
  256. static struct drxk_config terratec_h5_drxk = {
  257. .adr = 0x29,
  258. .single_master = 1,
  259. .no_i2c_bridge = 1,
  260. .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
  261. .qam_demod_parameter_count = 2,
  262. .load_firmware_sync = true,
  263. };
  264. static struct drxk_config hauppauge_930c_drxk = {
  265. .adr = 0x29,
  266. .single_master = 1,
  267. .no_i2c_bridge = 1,
  268. .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
  269. .chunk_size = 56,
  270. .qam_demod_parameter_count = 2,
  271. .load_firmware_sync = true,
  272. };
  273. struct drxk_config terratec_htc_stick_drxk = {
  274. .adr = 0x29,
  275. .single_master = 1,
  276. .no_i2c_bridge = 1,
  277. .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
  278. .chunk_size = 54,
  279. .qam_demod_parameter_count = 2,
  280. /* Required for the antenna_gpio to disable LNA. */
  281. .antenna_dvbt = true,
  282. /* The windows driver uses the same. This will disable LNA. */
  283. .antenna_gpio = 0x6,
  284. .load_firmware_sync = true,
  285. };
  286. static struct drxk_config maxmedia_ub425_tc_drxk = {
  287. .adr = 0x29,
  288. .single_master = 1,
  289. .no_i2c_bridge = 1,
  290. .load_firmware_sync = true,
  291. };
  292. static struct drxk_config pctv_520e_drxk = {
  293. .adr = 0x29,
  294. .single_master = 1,
  295. .microcode_name = "dvb-demod-drxk-pctv.fw",
  296. .qam_demod_parameter_count = 2,
  297. .chunk_size = 58,
  298. .antenna_dvbt = true, /* disable LNA */
  299. .antenna_gpio = (1 << 2), /* disable LNA */
  300. .load_firmware_sync = true,
  301. };
  302. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  303. {
  304. struct em28xx_dvb *dvb = fe->sec_priv;
  305. int status;
  306. if (!dvb)
  307. return -EINVAL;
  308. if (enable) {
  309. down(&dvb->pll_mutex);
  310. status = dvb->gate_ctrl(fe, 1);
  311. } else {
  312. status = dvb->gate_ctrl(fe, 0);
  313. up(&dvb->pll_mutex);
  314. }
  315. return status;
  316. }
  317. static void hauppauge_hvr930c_init(struct em28xx *dev)
  318. {
  319. int i;
  320. struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
  321. {EM2874_R80_GPIO, 0xff, 0xff, 0x65},
  322. {EM2874_R80_GPIO, 0xfb, 0xff, 0x32},
  323. {EM2874_R80_GPIO, 0xff, 0xff, 0xb8},
  324. { -1, -1, -1, -1},
  325. };
  326. struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
  327. {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
  328. {EM2874_R80_GPIO, 0xaf, 0xff, 0x65},
  329. {EM2874_R80_GPIO, 0xef, 0xff, 0x76},
  330. {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
  331. {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
  332. {EM2874_R80_GPIO, 0xef, 0xff, 0x40},
  333. {EM2874_R80_GPIO, 0xcf, 0xff, 0x65},
  334. {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
  335. {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
  336. {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
  337. { -1, -1, -1, -1},
  338. };
  339. struct {
  340. unsigned char r[4];
  341. int len;
  342. } regs[] = {
  343. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  344. {{ 0x01, 0x02 }, 2},
  345. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  346. {{ 0x01, 0x00 }, 2},
  347. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  348. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  349. {{ 0x01, 0x00 }, 2},
  350. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  351. {{ 0x04, 0x00 }, 2},
  352. {{ 0x00, 0x04 }, 2},
  353. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  354. {{ 0x04, 0x14 }, 2},
  355. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  356. };
  357. em28xx_gpio_set(dev, hauppauge_hvr930c_init);
  358. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  359. msleep(10);
  360. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  361. msleep(10);
  362. dev->i2c_client.addr = 0x82 >> 1;
  363. for (i = 0; i < ARRAY_SIZE(regs); i++)
  364. i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
  365. em28xx_gpio_set(dev, hauppauge_hvr930c_end);
  366. msleep(100);
  367. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  368. msleep(30);
  369. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
  370. msleep(10);
  371. }
  372. static void terratec_h5_init(struct em28xx *dev)
  373. {
  374. int i;
  375. struct em28xx_reg_seq terratec_h5_init[] = {
  376. {EM28XX_R08_GPIO, 0xff, 0xff, 10},
  377. {EM2874_R80_GPIO, 0xf6, 0xff, 100},
  378. {EM2874_R80_GPIO, 0xf2, 0xff, 50},
  379. {EM2874_R80_GPIO, 0xf6, 0xff, 100},
  380. { -1, -1, -1, -1},
  381. };
  382. struct em28xx_reg_seq terratec_h5_end[] = {
  383. {EM2874_R80_GPIO, 0xe6, 0xff, 100},
  384. {EM2874_R80_GPIO, 0xa6, 0xff, 50},
  385. {EM2874_R80_GPIO, 0xe6, 0xff, 100},
  386. { -1, -1, -1, -1},
  387. };
  388. struct {
  389. unsigned char r[4];
  390. int len;
  391. } regs[] = {
  392. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  393. {{ 0x01, 0x02 }, 2},
  394. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  395. {{ 0x01, 0x00 }, 2},
  396. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  397. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  398. {{ 0x01, 0x00 }, 2},
  399. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  400. {{ 0x04, 0x00 }, 2},
  401. {{ 0x00, 0x04 }, 2},
  402. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  403. {{ 0x04, 0x14 }, 2},
  404. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  405. };
  406. em28xx_gpio_set(dev, terratec_h5_init);
  407. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  408. msleep(10);
  409. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
  410. msleep(10);
  411. dev->i2c_client.addr = 0x82 >> 1;
  412. for (i = 0; i < ARRAY_SIZE(regs); i++)
  413. i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
  414. em28xx_gpio_set(dev, terratec_h5_end);
  415. };
  416. static void terratec_htc_stick_init(struct em28xx *dev)
  417. {
  418. int i;
  419. /*
  420. * GPIO configuration:
  421. * 0xff: unknown (does not affect DVB-T).
  422. * 0xf6: DRX-K (demodulator).
  423. * 0xe6: unknown (does not affect DVB-T).
  424. * 0xb6: unknown (does not affect DVB-T).
  425. */
  426. struct em28xx_reg_seq terratec_htc_stick_init[] = {
  427. {EM28XX_R08_GPIO, 0xff, 0xff, 10},
  428. {EM2874_R80_GPIO, 0xf6, 0xff, 100},
  429. {EM2874_R80_GPIO, 0xe6, 0xff, 50},
  430. {EM2874_R80_GPIO, 0xf6, 0xff, 100},
  431. { -1, -1, -1, -1},
  432. };
  433. struct em28xx_reg_seq terratec_htc_stick_end[] = {
  434. {EM2874_R80_GPIO, 0xb6, 0xff, 100},
  435. {EM2874_R80_GPIO, 0xf6, 0xff, 50},
  436. { -1, -1, -1, -1},
  437. };
  438. /* Init the analog decoder? */
  439. struct {
  440. unsigned char r[4];
  441. int len;
  442. } regs[] = {
  443. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  444. {{ 0x01, 0x02 }, 2},
  445. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  446. {{ 0x01, 0x00 }, 2},
  447. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  448. };
  449. em28xx_gpio_set(dev, terratec_htc_stick_init);
  450. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  451. msleep(10);
  452. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  453. msleep(10);
  454. dev->i2c_client.addr = 0x82 >> 1;
  455. for (i = 0; i < ARRAY_SIZE(regs); i++)
  456. i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
  457. em28xx_gpio_set(dev, terratec_htc_stick_end);
  458. };
  459. static void pctv_520e_init(struct em28xx *dev)
  460. {
  461. /*
  462. * Init AVF4910B analog decoder. Looks like I2C traffic to
  463. * digital demodulator and tuner are routed via AVF4910B.
  464. */
  465. int i;
  466. struct {
  467. unsigned char r[4];
  468. int len;
  469. } regs[] = {
  470. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  471. {{ 0x01, 0x02 }, 2},
  472. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  473. {{ 0x01, 0x00 }, 2},
  474. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  475. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  476. {{ 0x01, 0x00 }, 2},
  477. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  478. };
  479. dev->i2c_client.addr = 0x82 >> 1; /* 0x41 */
  480. for (i = 0; i < ARRAY_SIZE(regs); i++)
  481. i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
  482. };
  483. static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
  484. {
  485. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  486. struct em28xx *dev = fe->dvb->priv;
  487. #ifdef CONFIG_GPIOLIB
  488. struct em28xx_dvb *dvb = dev->dvb;
  489. int ret;
  490. unsigned long flags;
  491. if (c->lna == 1)
  492. flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
  493. else
  494. flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
  495. ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
  496. if (ret)
  497. em28xx_errdev("gpio request failed %d\n", ret);
  498. else
  499. gpio_free(dvb->lna_gpio);
  500. return ret;
  501. #else
  502. dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
  503. KBUILD_MODNAME, c->lna);
  504. return 0;
  505. #endif
  506. }
  507. static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
  508. {
  509. /* Values extracted from a USB trace of the Terratec Windows driver */
  510. static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
  511. static u8 reset[] = { RESET, 0x80 };
  512. static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
  513. static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
  514. static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
  515. static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
  516. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  517. static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
  518. static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
  519. static u8 tuner_go[] = { TUNER_GO, 0x01};
  520. mt352_write(fe, clock_config, sizeof(clock_config));
  521. udelay(200);
  522. mt352_write(fe, reset, sizeof(reset));
  523. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  524. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  525. mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
  526. mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
  527. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  528. mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
  529. mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
  530. mt352_write(fe, tuner_go, sizeof(tuner_go));
  531. return 0;
  532. }
  533. static struct mt352_config terratec_xs_mt352_cfg = {
  534. .demod_address = (0x1e >> 1),
  535. .no_tuner = 1,
  536. .if2 = 45600,
  537. .demod_init = em28xx_mt352_terratec_xs_init,
  538. };
  539. static struct tda10023_config em28xx_tda10023_config = {
  540. .demod_address = 0x0c,
  541. .invert = 1,
  542. };
  543. static struct cxd2820r_config em28xx_cxd2820r_config = {
  544. .i2c_address = (0xd8 >> 1),
  545. .ts_mode = CXD2820R_TS_SERIAL,
  546. };
  547. static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
  548. .output_opt = TDA18271_OUTPUT_LT_OFF,
  549. .gate = TDA18271_GATE_DIGITAL,
  550. };
  551. static const struct tda10071_config em28xx_tda10071_config = {
  552. .i2c_address = 0x55, /* (0xaa >> 1) */
  553. .i2c_wr_max = 64,
  554. .ts_mode = TDA10071_TS_SERIAL,
  555. .spec_inv = 0,
  556. .xtal = 40444000, /* 40.444 MHz */
  557. .pll_multiplier = 20,
  558. };
  559. static const struct a8293_config em28xx_a8293_config = {
  560. .i2c_addr = 0x08, /* (0x10 >> 1) */
  561. };
  562. static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
  563. .demod_address = (0x1e >> 1),
  564. .disable_i2c_gate_ctrl = 1,
  565. .no_tuner = 1,
  566. .parallel_ts = 1,
  567. };
  568. static struct qt1010_config em28xx_qt1010_config = {
  569. .i2c_address = 0x62
  570. };
  571. /* ------------------------------------------------------------------ */
  572. static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
  573. {
  574. struct dvb_frontend *fe;
  575. struct xc2028_config cfg;
  576. memset(&cfg, 0, sizeof(cfg));
  577. cfg.i2c_adap = &dev->i2c_adap;
  578. cfg.i2c_addr = addr;
  579. if (!dev->dvb->fe[0]) {
  580. em28xx_errdev("/2: dvb frontend not attached. "
  581. "Can't attach xc3028\n");
  582. return -EINVAL;
  583. }
  584. fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
  585. if (!fe) {
  586. em28xx_errdev("/2: xc3028 attach failed\n");
  587. dvb_frontend_detach(dev->dvb->fe[0]);
  588. dev->dvb->fe[0] = NULL;
  589. return -EINVAL;
  590. }
  591. em28xx_info("%s/2: xc3028 attached\n", dev->name);
  592. return 0;
  593. }
  594. /* ------------------------------------------------------------------ */
  595. static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
  596. struct em28xx *dev, struct device *device)
  597. {
  598. int result;
  599. mutex_init(&dvb->lock);
  600. /* register adapter */
  601. result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
  602. adapter_nr);
  603. if (result < 0) {
  604. printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
  605. dev->name, result);
  606. goto fail_adapter;
  607. }
  608. /* Ensure all frontends negotiate bus access */
  609. dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  610. if (dvb->fe[1])
  611. dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  612. dvb->adapter.priv = dev;
  613. /* register frontend */
  614. result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
  615. if (result < 0) {
  616. printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
  617. dev->name, result);
  618. goto fail_frontend0;
  619. }
  620. /* register 2nd frontend */
  621. if (dvb->fe[1]) {
  622. result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
  623. if (result < 0) {
  624. printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
  625. dev->name, result);
  626. goto fail_frontend1;
  627. }
  628. }
  629. /* register demux stuff */
  630. dvb->demux.dmx.capabilities =
  631. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  632. DMX_MEMORY_BASED_FILTERING;
  633. dvb->demux.priv = dvb;
  634. dvb->demux.filternum = 256;
  635. dvb->demux.feednum = 256;
  636. dvb->demux.start_feed = em28xx_start_feed;
  637. dvb->demux.stop_feed = em28xx_stop_feed;
  638. result = dvb_dmx_init(&dvb->demux);
  639. if (result < 0) {
  640. printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
  641. dev->name, result);
  642. goto fail_dmx;
  643. }
  644. dvb->dmxdev.filternum = 256;
  645. dvb->dmxdev.demux = &dvb->demux.dmx;
  646. dvb->dmxdev.capabilities = 0;
  647. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  648. if (result < 0) {
  649. printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
  650. dev->name, result);
  651. goto fail_dmxdev;
  652. }
  653. dvb->fe_hw.source = DMX_FRONTEND_0;
  654. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  655. if (result < 0) {
  656. printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  657. dev->name, result);
  658. goto fail_fe_hw;
  659. }
  660. dvb->fe_mem.source = DMX_MEMORY_FE;
  661. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  662. if (result < 0) {
  663. printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  664. dev->name, result);
  665. goto fail_fe_mem;
  666. }
  667. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  668. if (result < 0) {
  669. printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
  670. dev->name, result);
  671. goto fail_fe_conn;
  672. }
  673. /* register network adapter */
  674. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  675. return 0;
  676. fail_fe_conn:
  677. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  678. fail_fe_mem:
  679. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  680. fail_fe_hw:
  681. dvb_dmxdev_release(&dvb->dmxdev);
  682. fail_dmxdev:
  683. dvb_dmx_release(&dvb->demux);
  684. fail_dmx:
  685. if (dvb->fe[1])
  686. dvb_unregister_frontend(dvb->fe[1]);
  687. dvb_unregister_frontend(dvb->fe[0]);
  688. fail_frontend1:
  689. if (dvb->fe[1])
  690. dvb_frontend_detach(dvb->fe[1]);
  691. fail_frontend0:
  692. dvb_frontend_detach(dvb->fe[0]);
  693. dvb_unregister_adapter(&dvb->adapter);
  694. fail_adapter:
  695. return result;
  696. }
  697. static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
  698. {
  699. dvb_net_release(&dvb->net);
  700. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  701. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  702. dvb_dmxdev_release(&dvb->dmxdev);
  703. dvb_dmx_release(&dvb->demux);
  704. if (dvb->fe[1])
  705. dvb_unregister_frontend(dvb->fe[1]);
  706. dvb_unregister_frontend(dvb->fe[0]);
  707. if (dvb->fe[1] && !dvb->dont_attach_fe1)
  708. dvb_frontend_detach(dvb->fe[1]);
  709. dvb_frontend_detach(dvb->fe[0]);
  710. dvb_unregister_adapter(&dvb->adapter);
  711. }
  712. static int em28xx_dvb_init(struct em28xx *dev)
  713. {
  714. int result = 0, mfe_shared = 0;
  715. struct em28xx_dvb *dvb;
  716. if (!dev->board.has_dvb) {
  717. /* This device does not support the extension */
  718. printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
  719. return 0;
  720. }
  721. dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
  722. if (dvb == NULL) {
  723. em28xx_info("em28xx_dvb: memory allocation failed\n");
  724. return -ENOMEM;
  725. }
  726. dev->dvb = dvb;
  727. dvb->fe[0] = dvb->fe[1] = NULL;
  728. mutex_lock(&dev->lock);
  729. em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  730. /* init frontend */
  731. switch (dev->model) {
  732. case EM2874_BOARD_LEADERSHIP_ISDBT:
  733. dvb->fe[0] = dvb_attach(s921_attach,
  734. &sharp_isdbt, &dev->i2c_adap);
  735. if (!dvb->fe[0]) {
  736. result = -EINVAL;
  737. goto out_free;
  738. }
  739. break;
  740. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
  741. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
  742. case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
  743. case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
  744. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  745. &em2880_lgdt3303_dev,
  746. &dev->i2c_adap);
  747. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  748. result = -EINVAL;
  749. goto out_free;
  750. }
  751. break;
  752. case EM2880_BOARD_KWORLD_DVB_310U:
  753. dvb->fe[0] = dvb_attach(zl10353_attach,
  754. &em28xx_zl10353_with_xc3028,
  755. &dev->i2c_adap);
  756. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  757. result = -EINVAL;
  758. goto out_free;
  759. }
  760. break;
  761. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  762. case EM2882_BOARD_TERRATEC_HYBRID_XS:
  763. case EM2880_BOARD_EMPIRE_DUAL_TV:
  764. dvb->fe[0] = dvb_attach(zl10353_attach,
  765. &em28xx_zl10353_xc3028_no_i2c_gate,
  766. &dev->i2c_adap);
  767. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  768. result = -EINVAL;
  769. goto out_free;
  770. }
  771. break;
  772. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  773. case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
  774. case EM2881_BOARD_PINNACLE_HYBRID_PRO:
  775. case EM2882_BOARD_DIKOM_DK300:
  776. case EM2882_BOARD_KWORLD_VS_DVBT:
  777. dvb->fe[0] = dvb_attach(zl10353_attach,
  778. &em28xx_zl10353_xc3028_no_i2c_gate,
  779. &dev->i2c_adap);
  780. if (dvb->fe[0] == NULL) {
  781. /* This board could have either a zl10353 or a mt352.
  782. If the chip id isn't for zl10353, try mt352 */
  783. dvb->fe[0] = dvb_attach(mt352_attach,
  784. &terratec_xs_mt352_cfg,
  785. &dev->i2c_adap);
  786. }
  787. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  788. result = -EINVAL;
  789. goto out_free;
  790. }
  791. break;
  792. case EM2870_BOARD_KWORLD_355U:
  793. dvb->fe[0] = dvb_attach(zl10353_attach,
  794. &em28xx_zl10353_no_i2c_gate_dev,
  795. &dev->i2c_adap);
  796. if (dvb->fe[0] != NULL)
  797. dvb_attach(qt1010_attach, dvb->fe[0],
  798. &dev->i2c_adap, &em28xx_qt1010_config);
  799. break;
  800. case EM2883_BOARD_KWORLD_HYBRID_330U:
  801. case EM2882_BOARD_EVGA_INDTUBE:
  802. dvb->fe[0] = dvb_attach(s5h1409_attach,
  803. &em28xx_s5h1409_with_xc3028,
  804. &dev->i2c_adap);
  805. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  806. result = -EINVAL;
  807. goto out_free;
  808. }
  809. break;
  810. case EM2882_BOARD_KWORLD_ATSC_315U:
  811. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  812. &em2880_lgdt3303_dev,
  813. &dev->i2c_adap);
  814. if (dvb->fe[0] != NULL) {
  815. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  816. &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
  817. result = -EINVAL;
  818. goto out_free;
  819. }
  820. }
  821. break;
  822. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
  823. case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
  824. dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
  825. &dev->i2c_adap, &dev->udev->dev);
  826. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  827. result = -EINVAL;
  828. goto out_free;
  829. }
  830. break;
  831. case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
  832. /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
  833. dvb->fe[0] = dvb_attach(tda10023_attach,
  834. &em28xx_tda10023_config,
  835. &dev->i2c_adap, 0x48);
  836. if (dvb->fe[0]) {
  837. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  838. &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
  839. result = -EINVAL;
  840. goto out_free;
  841. }
  842. }
  843. break;
  844. case EM2870_BOARD_KWORLD_A340:
  845. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  846. &em2870_lgdt3304_dev,
  847. &dev->i2c_adap);
  848. if (dvb->fe[0] != NULL)
  849. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  850. &dev->i2c_adap, &kworld_a340_config);
  851. break;
  852. case EM28174_BOARD_PCTV_290E:
  853. /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
  854. dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
  855. CXD2820R_GPIO_L;
  856. dvb->fe[0] = dvb_attach(cxd2820r_attach,
  857. &em28xx_cxd2820r_config,
  858. &dev->i2c_adap,
  859. &dvb->lna_gpio);
  860. if (dvb->fe[0]) {
  861. /* FE 0 attach tuner */
  862. if (!dvb_attach(tda18271_attach,
  863. dvb->fe[0],
  864. 0x60,
  865. &dev->i2c_adap,
  866. &em28xx_cxd2820r_tda18271_config)) {
  867. dvb_frontend_detach(dvb->fe[0]);
  868. result = -EINVAL;
  869. goto out_free;
  870. }
  871. #ifdef CONFIG_GPIOLIB
  872. /* enable LNA for DVB-T, DVB-T2 and DVB-C */
  873. result = gpio_request_one(dvb->lna_gpio,
  874. GPIOF_OUT_INIT_LOW, NULL);
  875. if (result)
  876. em28xx_errdev("gpio request failed %d\n",
  877. result);
  878. else
  879. gpio_free(dvb->lna_gpio);
  880. result = 0; /* continue even set LNA fails */
  881. #endif
  882. dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
  883. }
  884. break;
  885. case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
  886. {
  887. struct xc5000_config cfg;
  888. hauppauge_hvr930c_init(dev);
  889. dvb->fe[0] = dvb_attach(drxk_attach,
  890. &hauppauge_930c_drxk, &dev->i2c_adap);
  891. if (!dvb->fe[0]) {
  892. result = -EINVAL;
  893. goto out_free;
  894. }
  895. /* FIXME: do we need a pll semaphore? */
  896. dvb->fe[0]->sec_priv = dvb;
  897. sema_init(&dvb->pll_mutex, 1);
  898. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  899. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  900. /* Attach xc5000 */
  901. memset(&cfg, 0, sizeof(cfg));
  902. cfg.i2c_address = 0x61;
  903. cfg.if_khz = 4000;
  904. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  905. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  906. if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap,
  907. &cfg)) {
  908. result = -EINVAL;
  909. goto out_free;
  910. }
  911. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  912. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  913. break;
  914. }
  915. case EM2884_BOARD_TERRATEC_H5:
  916. terratec_h5_init(dev);
  917. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap);
  918. if (!dvb->fe[0]) {
  919. result = -EINVAL;
  920. goto out_free;
  921. }
  922. /* FIXME: do we need a pll semaphore? */
  923. dvb->fe[0]->sec_priv = dvb;
  924. sema_init(&dvb->pll_mutex, 1);
  925. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  926. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  927. /* Attach tda18271 to DVB-C frontend */
  928. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  929. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  930. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
  931. result = -EINVAL;
  932. goto out_free;
  933. }
  934. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  935. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  936. break;
  937. case EM28174_BOARD_PCTV_460E:
  938. /* attach demod */
  939. dvb->fe[0] = dvb_attach(tda10071_attach,
  940. &em28xx_tda10071_config, &dev->i2c_adap);
  941. /* attach SEC */
  942. if (dvb->fe[0])
  943. dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap,
  944. &em28xx_a8293_config);
  945. break;
  946. case EM2874_BOARD_MAXMEDIA_UB425_TC:
  947. /* attach demodulator */
  948. dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
  949. &dev->i2c_adap);
  950. if (dvb->fe[0]) {
  951. /* disable I2C-gate */
  952. dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
  953. /* attach tuner */
  954. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
  955. &dev->i2c_adap, 0x60)) {
  956. dvb_frontend_detach(dvb->fe[0]);
  957. result = -EINVAL;
  958. goto out_free;
  959. }
  960. }
  961. /* TODO: we need drx-3913k firmware in order to support DVB-T */
  962. em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \
  963. "driver version\n");
  964. break;
  965. case EM2884_BOARD_PCTV_510E:
  966. case EM2884_BOARD_PCTV_520E:
  967. pctv_520e_init(dev);
  968. /* attach demodulator */
  969. dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
  970. &dev->i2c_adap);
  971. if (dvb->fe[0]) {
  972. /* attach tuner */
  973. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  974. &dev->i2c_adap,
  975. &em28xx_cxd2820r_tda18271_config)) {
  976. dvb_frontend_detach(dvb->fe[0]);
  977. result = -EINVAL;
  978. goto out_free;
  979. }
  980. }
  981. break;
  982. case EM2884_BOARD_CINERGY_HTC_STICK:
  983. terratec_htc_stick_init(dev);
  984. /* attach demodulator */
  985. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  986. &dev->i2c_adap);
  987. if (!dvb->fe[0]) {
  988. result = -EINVAL;
  989. goto out_free;
  990. }
  991. /* Attach the demodulator. */
  992. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  993. &dev->i2c_adap,
  994. &em28xx_cxd2820r_tda18271_config)) {
  995. result = -EINVAL;
  996. goto out_free;
  997. }
  998. break;
  999. default:
  1000. em28xx_errdev("/2: The frontend of your DVB/ATSC card"
  1001. " isn't supported yet\n");
  1002. break;
  1003. }
  1004. if (NULL == dvb->fe[0]) {
  1005. em28xx_errdev("/2: frontend initialization failed\n");
  1006. result = -EINVAL;
  1007. goto out_free;
  1008. }
  1009. /* define general-purpose callback pointer */
  1010. dvb->fe[0]->callback = em28xx_tuner_callback;
  1011. if (dvb->fe[1])
  1012. dvb->fe[1]->callback = em28xx_tuner_callback;
  1013. /* register everything */
  1014. result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
  1015. if (result < 0)
  1016. goto out_free;
  1017. /* MFE lock */
  1018. dvb->adapter.mfe_shared = mfe_shared;
  1019. em28xx_info("Successfully loaded em28xx-dvb\n");
  1020. ret:
  1021. em28xx_set_mode(dev, EM28XX_SUSPEND);
  1022. mutex_unlock(&dev->lock);
  1023. return result;
  1024. out_free:
  1025. kfree(dvb);
  1026. dev->dvb = NULL;
  1027. goto ret;
  1028. }
  1029. static inline void prevent_sleep(struct dvb_frontend_ops *ops)
  1030. {
  1031. ops->set_voltage = NULL;
  1032. ops->sleep = NULL;
  1033. ops->tuner_ops.sleep = NULL;
  1034. }
  1035. static int em28xx_dvb_fini(struct em28xx *dev)
  1036. {
  1037. if (!dev->board.has_dvb) {
  1038. /* This device does not support the extension */
  1039. return 0;
  1040. }
  1041. if (dev->dvb) {
  1042. struct em28xx_dvb *dvb = dev->dvb;
  1043. if (dev->state & DEV_DISCONNECTED) {
  1044. /* We cannot tell the device to sleep
  1045. * once it has been unplugged. */
  1046. if (dvb->fe[0])
  1047. prevent_sleep(&dvb->fe[0]->ops);
  1048. if (dvb->fe[1])
  1049. prevent_sleep(&dvb->fe[1]->ops);
  1050. }
  1051. em28xx_unregister_dvb(dvb);
  1052. kfree(dvb);
  1053. dev->dvb = NULL;
  1054. }
  1055. return 0;
  1056. }
  1057. static struct em28xx_ops dvb_ops = {
  1058. .id = EM28XX_DVB,
  1059. .name = "Em28xx dvb Extension",
  1060. .init = em28xx_dvb_init,
  1061. .fini = em28xx_dvb_fini,
  1062. };
  1063. static int __init em28xx_dvb_register(void)
  1064. {
  1065. return em28xx_register_extension(&dvb_ops);
  1066. }
  1067. static void __exit em28xx_dvb_unregister(void)
  1068. {
  1069. em28xx_unregister_extension(&dvb_ops);
  1070. }
  1071. module_init(em28xx_dvb_register);
  1072. module_exit(em28xx_dvb_unregister);