em28xx-dvb.c 36 KB

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