em28xx-dvb.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  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. MODULE_DESCRIPTION("driver for em28xx based DVB cards");
  45. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  46. MODULE_LICENSE("GPL");
  47. static unsigned int debug;
  48. module_param(debug, int, 0644);
  49. MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
  50. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  51. #define dprintk(level, fmt, arg...) do { \
  52. if (debug >= level) \
  53. printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
  54. } while (0)
  55. struct em28xx_dvb {
  56. struct dvb_frontend *fe[2];
  57. /* feed count management */
  58. struct mutex lock;
  59. int nfeeds;
  60. /* general boilerplate stuff */
  61. struct dvb_adapter adapter;
  62. struct dvb_demux demux;
  63. struct dmxdev dmxdev;
  64. struct dmx_frontend fe_hw;
  65. struct dmx_frontend fe_mem;
  66. struct dvb_net net;
  67. /* Due to DRX-K - probably need changes */
  68. int (*gate_ctrl)(struct dvb_frontend *, int);
  69. struct semaphore pll_mutex;
  70. bool dont_attach_fe1;
  71. int lna_gpio;
  72. };
  73. static inline void print_err_status(struct em28xx *dev,
  74. int packet, int status)
  75. {
  76. char *errmsg = "Unknown";
  77. switch (status) {
  78. case -ENOENT:
  79. errmsg = "unlinked synchronuously";
  80. break;
  81. case -ECONNRESET:
  82. errmsg = "unlinked asynchronuously";
  83. break;
  84. case -ENOSR:
  85. errmsg = "Buffer error (overrun)";
  86. break;
  87. case -EPIPE:
  88. errmsg = "Stalled (device not responding)";
  89. break;
  90. case -EOVERFLOW:
  91. errmsg = "Babble (bad cable?)";
  92. break;
  93. case -EPROTO:
  94. errmsg = "Bit-stuff error (bad cable?)";
  95. break;
  96. case -EILSEQ:
  97. errmsg = "CRC/Timeout (could be anything)";
  98. break;
  99. case -ETIME:
  100. errmsg = "Device does not respond";
  101. break;
  102. }
  103. if (packet < 0) {
  104. dprintk(1, "URB status %d [%s].\n", status, errmsg);
  105. } else {
  106. dprintk(1, "URB packet %d, status %d [%s].\n",
  107. packet, status, errmsg);
  108. }
  109. }
  110. static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
  111. {
  112. int xfer_bulk, num_packets, i;
  113. if (!dev)
  114. return 0;
  115. if (dev->disconnected)
  116. return 0;
  117. if (urb->status < 0)
  118. print_err_status(dev, -1, urb->status);
  119. xfer_bulk = usb_pipebulk(urb->pipe);
  120. if (xfer_bulk) /* bulk */
  121. num_packets = 1;
  122. else /* isoc */
  123. num_packets = urb->number_of_packets;
  124. for (i = 0; i < num_packets; i++) {
  125. if (xfer_bulk) {
  126. if (urb->status < 0) {
  127. print_err_status(dev, i, urb->status);
  128. if (urb->status != -EPROTO)
  129. continue;
  130. }
  131. dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
  132. urb->actual_length);
  133. } else {
  134. if (urb->iso_frame_desc[i].status < 0) {
  135. print_err_status(dev, i,
  136. urb->iso_frame_desc[i].status);
  137. if (urb->iso_frame_desc[i].status != -EPROTO)
  138. continue;
  139. }
  140. dvb_dmx_swfilter(&dev->dvb->demux,
  141. urb->transfer_buffer +
  142. urb->iso_frame_desc[i].offset,
  143. urb->iso_frame_desc[i].actual_length);
  144. }
  145. }
  146. return 0;
  147. }
  148. static int em28xx_start_streaming(struct em28xx_dvb *dvb)
  149. {
  150. int rc;
  151. struct em28xx *dev = dvb->adapter.priv;
  152. int dvb_max_packet_size, packet_multiplier, dvb_alt;
  153. if (dev->dvb_xfer_bulk) {
  154. if (!dev->dvb_ep_bulk)
  155. return -ENODEV;
  156. dvb_max_packet_size = 512; /* USB 2.0 spec */
  157. packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
  158. dvb_alt = 0;
  159. } else { /* isoc */
  160. if (!dev->dvb_ep_isoc)
  161. return -ENODEV;
  162. dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
  163. if (dvb_max_packet_size < 0)
  164. return dvb_max_packet_size;
  165. packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
  166. dvb_alt = dev->dvb_alt_isoc;
  167. }
  168. usb_set_interface(dev->udev, 0, dvb_alt);
  169. rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  170. if (rc < 0)
  171. return rc;
  172. dprintk(1, "Using %d buffers each with %d x %d bytes\n",
  173. EM28XX_DVB_NUM_BUFS,
  174. packet_multiplier,
  175. dvb_max_packet_size);
  176. return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
  177. dev->dvb_xfer_bulk,
  178. EM28XX_DVB_NUM_BUFS,
  179. dvb_max_packet_size,
  180. packet_multiplier,
  181. em28xx_dvb_urb_data_copy);
  182. }
  183. static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
  184. {
  185. struct em28xx *dev = dvb->adapter.priv;
  186. em28xx_stop_urbs(dev);
  187. em28xx_set_mode(dev, EM28XX_SUSPEND);
  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.addr = 0x82 >> 1;
  394. for (i = 0; i < ARRAY_SIZE(regs); i++)
  395. i2c_master_send(&dev->i2c_client, 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.addr = 0x82 >> 1;
  443. for (i = 0; i < ARRAY_SIZE(regs); i++)
  444. i2c_master_send(&dev->i2c_client, 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.addr = 0x82 >> 1;
  489. for (i = 0; i < ARRAY_SIZE(regs); i++)
  490. i2c_master_send(&dev->i2c_client, 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.addr = 0x82 >> 1;
  538. for (i = 0; i < ARRAY_SIZE(regs); i++)
  539. i2c_master_send(&dev->i2c_client, 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.addr = 0x82 >> 1; /* 0x41 */
  563. for (i = 0; i < ARRAY_SIZE(regs); i++)
  564. i2c_master_send(&dev->i2c_client, 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. /* ------------------------------------------------------------------ */
  656. static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
  657. {
  658. struct dvb_frontend *fe;
  659. struct xc2028_config cfg;
  660. memset(&cfg, 0, sizeof(cfg));
  661. cfg.i2c_adap = &dev->i2c_adap;
  662. cfg.i2c_addr = addr;
  663. if (!dev->dvb->fe[0]) {
  664. em28xx_errdev("/2: dvb frontend not attached. "
  665. "Can't attach xc3028\n");
  666. return -EINVAL;
  667. }
  668. fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
  669. if (!fe) {
  670. em28xx_errdev("/2: xc3028 attach failed\n");
  671. dvb_frontend_detach(dev->dvb->fe[0]);
  672. dev->dvb->fe[0] = NULL;
  673. return -EINVAL;
  674. }
  675. em28xx_info("%s/2: xc3028 attached\n", dev->name);
  676. return 0;
  677. }
  678. /* ------------------------------------------------------------------ */
  679. static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
  680. struct em28xx *dev, struct device *device)
  681. {
  682. int result;
  683. mutex_init(&dvb->lock);
  684. /* register adapter */
  685. result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
  686. adapter_nr);
  687. if (result < 0) {
  688. printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
  689. dev->name, result);
  690. goto fail_adapter;
  691. }
  692. /* Ensure all frontends negotiate bus access */
  693. dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  694. if (dvb->fe[1])
  695. dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  696. dvb->adapter.priv = dev;
  697. /* register frontend */
  698. result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
  699. if (result < 0) {
  700. printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
  701. dev->name, result);
  702. goto fail_frontend0;
  703. }
  704. /* register 2nd frontend */
  705. if (dvb->fe[1]) {
  706. result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
  707. if (result < 0) {
  708. printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
  709. dev->name, result);
  710. goto fail_frontend1;
  711. }
  712. }
  713. /* register demux stuff */
  714. dvb->demux.dmx.capabilities =
  715. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  716. DMX_MEMORY_BASED_FILTERING;
  717. dvb->demux.priv = dvb;
  718. dvb->demux.filternum = 256;
  719. dvb->demux.feednum = 256;
  720. dvb->demux.start_feed = em28xx_start_feed;
  721. dvb->demux.stop_feed = em28xx_stop_feed;
  722. result = dvb_dmx_init(&dvb->demux);
  723. if (result < 0) {
  724. printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
  725. dev->name, result);
  726. goto fail_dmx;
  727. }
  728. dvb->dmxdev.filternum = 256;
  729. dvb->dmxdev.demux = &dvb->demux.dmx;
  730. dvb->dmxdev.capabilities = 0;
  731. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  732. if (result < 0) {
  733. printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
  734. dev->name, result);
  735. goto fail_dmxdev;
  736. }
  737. dvb->fe_hw.source = DMX_FRONTEND_0;
  738. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  739. if (result < 0) {
  740. printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  741. dev->name, result);
  742. goto fail_fe_hw;
  743. }
  744. dvb->fe_mem.source = DMX_MEMORY_FE;
  745. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  746. if (result < 0) {
  747. printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  748. dev->name, result);
  749. goto fail_fe_mem;
  750. }
  751. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  752. if (result < 0) {
  753. printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
  754. dev->name, result);
  755. goto fail_fe_conn;
  756. }
  757. /* register network adapter */
  758. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  759. return 0;
  760. fail_fe_conn:
  761. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  762. fail_fe_mem:
  763. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  764. fail_fe_hw:
  765. dvb_dmxdev_release(&dvb->dmxdev);
  766. fail_dmxdev:
  767. dvb_dmx_release(&dvb->demux);
  768. fail_dmx:
  769. if (dvb->fe[1])
  770. dvb_unregister_frontend(dvb->fe[1]);
  771. dvb_unregister_frontend(dvb->fe[0]);
  772. fail_frontend1:
  773. if (dvb->fe[1])
  774. dvb_frontend_detach(dvb->fe[1]);
  775. fail_frontend0:
  776. dvb_frontend_detach(dvb->fe[0]);
  777. dvb_unregister_adapter(&dvb->adapter);
  778. fail_adapter:
  779. return result;
  780. }
  781. static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
  782. {
  783. dvb_net_release(&dvb->net);
  784. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  785. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  786. dvb_dmxdev_release(&dvb->dmxdev);
  787. dvb_dmx_release(&dvb->demux);
  788. if (dvb->fe[1])
  789. dvb_unregister_frontend(dvb->fe[1]);
  790. dvb_unregister_frontend(dvb->fe[0]);
  791. if (dvb->fe[1] && !dvb->dont_attach_fe1)
  792. dvb_frontend_detach(dvb->fe[1]);
  793. dvb_frontend_detach(dvb->fe[0]);
  794. dvb_unregister_adapter(&dvb->adapter);
  795. }
  796. static int em28xx_dvb_init(struct em28xx *dev)
  797. {
  798. int result = 0, mfe_shared = 0;
  799. struct em28xx_dvb *dvb;
  800. if (!dev->board.has_dvb) {
  801. /* This device does not support the extension */
  802. printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
  803. return 0;
  804. }
  805. dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
  806. if (dvb == NULL) {
  807. em28xx_info("em28xx_dvb: memory allocation failed\n");
  808. return -ENOMEM;
  809. }
  810. dev->dvb = dvb;
  811. dvb->fe[0] = dvb->fe[1] = NULL;
  812. mutex_lock(&dev->lock);
  813. em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  814. /* init frontend */
  815. switch (dev->model) {
  816. case EM2874_BOARD_LEADERSHIP_ISDBT:
  817. dvb->fe[0] = dvb_attach(s921_attach,
  818. &sharp_isdbt, &dev->i2c_adap);
  819. if (!dvb->fe[0]) {
  820. result = -EINVAL;
  821. goto out_free;
  822. }
  823. break;
  824. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
  825. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
  826. case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
  827. case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
  828. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  829. &em2880_lgdt3303_dev,
  830. &dev->i2c_adap);
  831. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  832. result = -EINVAL;
  833. goto out_free;
  834. }
  835. break;
  836. case EM2880_BOARD_KWORLD_DVB_310U:
  837. dvb->fe[0] = dvb_attach(zl10353_attach,
  838. &em28xx_zl10353_with_xc3028,
  839. &dev->i2c_adap);
  840. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  841. result = -EINVAL;
  842. goto out_free;
  843. }
  844. break;
  845. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  846. case EM2882_BOARD_TERRATEC_HYBRID_XS:
  847. case EM2880_BOARD_EMPIRE_DUAL_TV:
  848. dvb->fe[0] = dvb_attach(zl10353_attach,
  849. &em28xx_zl10353_xc3028_no_i2c_gate,
  850. &dev->i2c_adap);
  851. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  852. result = -EINVAL;
  853. goto out_free;
  854. }
  855. break;
  856. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  857. case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
  858. case EM2881_BOARD_PINNACLE_HYBRID_PRO:
  859. case EM2882_BOARD_DIKOM_DK300:
  860. case EM2882_BOARD_KWORLD_VS_DVBT:
  861. dvb->fe[0] = dvb_attach(zl10353_attach,
  862. &em28xx_zl10353_xc3028_no_i2c_gate,
  863. &dev->i2c_adap);
  864. if (dvb->fe[0] == NULL) {
  865. /* This board could have either a zl10353 or a mt352.
  866. If the chip id isn't for zl10353, try mt352 */
  867. dvb->fe[0] = dvb_attach(mt352_attach,
  868. &terratec_xs_mt352_cfg,
  869. &dev->i2c_adap);
  870. }
  871. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  872. result = -EINVAL;
  873. goto out_free;
  874. }
  875. break;
  876. case EM2870_BOARD_KWORLD_355U:
  877. dvb->fe[0] = dvb_attach(zl10353_attach,
  878. &em28xx_zl10353_no_i2c_gate_dev,
  879. &dev->i2c_adap);
  880. if (dvb->fe[0] != NULL)
  881. dvb_attach(qt1010_attach, dvb->fe[0],
  882. &dev->i2c_adap, &em28xx_qt1010_config);
  883. break;
  884. case EM2883_BOARD_KWORLD_HYBRID_330U:
  885. case EM2882_BOARD_EVGA_INDTUBE:
  886. dvb->fe[0] = dvb_attach(s5h1409_attach,
  887. &em28xx_s5h1409_with_xc3028,
  888. &dev->i2c_adap);
  889. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  890. result = -EINVAL;
  891. goto out_free;
  892. }
  893. break;
  894. case EM2882_BOARD_KWORLD_ATSC_315U:
  895. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  896. &em2880_lgdt3303_dev,
  897. &dev->i2c_adap);
  898. if (dvb->fe[0] != NULL) {
  899. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  900. &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
  901. result = -EINVAL;
  902. goto out_free;
  903. }
  904. }
  905. break;
  906. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
  907. case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
  908. dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
  909. &dev->i2c_adap, &dev->udev->dev);
  910. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  911. result = -EINVAL;
  912. goto out_free;
  913. }
  914. break;
  915. case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
  916. /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
  917. dvb->fe[0] = dvb_attach(tda10023_attach,
  918. &em28xx_tda10023_config,
  919. &dev->i2c_adap, 0x48);
  920. if (dvb->fe[0]) {
  921. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  922. &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
  923. result = -EINVAL;
  924. goto out_free;
  925. }
  926. }
  927. break;
  928. case EM2870_BOARD_KWORLD_A340:
  929. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  930. &em2870_lgdt3304_dev,
  931. &dev->i2c_adap);
  932. if (dvb->fe[0] != NULL)
  933. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  934. &dev->i2c_adap, &kworld_a340_config);
  935. break;
  936. case EM28174_BOARD_PCTV_290E:
  937. /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
  938. dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
  939. CXD2820R_GPIO_L;
  940. dvb->fe[0] = dvb_attach(cxd2820r_attach,
  941. &em28xx_cxd2820r_config,
  942. &dev->i2c_adap,
  943. &dvb->lna_gpio);
  944. if (dvb->fe[0]) {
  945. /* FE 0 attach tuner */
  946. if (!dvb_attach(tda18271_attach,
  947. dvb->fe[0],
  948. 0x60,
  949. &dev->i2c_adap,
  950. &em28xx_cxd2820r_tda18271_config)) {
  951. dvb_frontend_detach(dvb->fe[0]);
  952. result = -EINVAL;
  953. goto out_free;
  954. }
  955. #ifdef CONFIG_GPIOLIB
  956. /* enable LNA for DVB-T, DVB-T2 and DVB-C */
  957. result = gpio_request_one(dvb->lna_gpio,
  958. GPIOF_OUT_INIT_LOW, NULL);
  959. if (result)
  960. em28xx_errdev("gpio request failed %d\n",
  961. result);
  962. else
  963. gpio_free(dvb->lna_gpio);
  964. result = 0; /* continue even set LNA fails */
  965. #endif
  966. dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
  967. }
  968. break;
  969. case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
  970. {
  971. struct xc5000_config cfg;
  972. hauppauge_hvr930c_init(dev);
  973. dvb->fe[0] = dvb_attach(drxk_attach,
  974. &hauppauge_930c_drxk, &dev->i2c_adap);
  975. if (!dvb->fe[0]) {
  976. result = -EINVAL;
  977. goto out_free;
  978. }
  979. /* FIXME: do we need a pll semaphore? */
  980. dvb->fe[0]->sec_priv = dvb;
  981. sema_init(&dvb->pll_mutex, 1);
  982. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  983. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  984. /* Attach xc5000 */
  985. memset(&cfg, 0, sizeof(cfg));
  986. cfg.i2c_address = 0x61;
  987. cfg.if_khz = 4000;
  988. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  989. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  990. if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap,
  991. &cfg)) {
  992. result = -EINVAL;
  993. goto out_free;
  994. }
  995. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  996. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  997. break;
  998. }
  999. case EM2884_BOARD_TERRATEC_H5:
  1000. terratec_h5_init(dev);
  1001. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap);
  1002. if (!dvb->fe[0]) {
  1003. result = -EINVAL;
  1004. goto out_free;
  1005. }
  1006. /* FIXME: do we need a pll semaphore? */
  1007. dvb->fe[0]->sec_priv = dvb;
  1008. sema_init(&dvb->pll_mutex, 1);
  1009. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  1010. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  1011. /* Attach tda18271 to DVB-C frontend */
  1012. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1013. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  1014. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
  1015. result = -EINVAL;
  1016. goto out_free;
  1017. }
  1018. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1019. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  1020. break;
  1021. case EM28174_BOARD_PCTV_460E:
  1022. /* attach demod */
  1023. dvb->fe[0] = dvb_attach(tda10071_attach,
  1024. &em28xx_tda10071_config, &dev->i2c_adap);
  1025. /* attach SEC */
  1026. if (dvb->fe[0])
  1027. dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap,
  1028. &em28xx_a8293_config);
  1029. break;
  1030. case EM2874_BOARD_MAXMEDIA_UB425_TC:
  1031. /* attach demodulator */
  1032. dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
  1033. &dev->i2c_adap);
  1034. if (dvb->fe[0]) {
  1035. /* disable I2C-gate */
  1036. dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
  1037. /* attach tuner */
  1038. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
  1039. &dev->i2c_adap, 0x60)) {
  1040. dvb_frontend_detach(dvb->fe[0]);
  1041. result = -EINVAL;
  1042. goto out_free;
  1043. }
  1044. }
  1045. /* TODO: we need drx-3913k firmware in order to support DVB-T */
  1046. em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \
  1047. "driver version\n");
  1048. break;
  1049. case EM2884_BOARD_PCTV_510E:
  1050. case EM2884_BOARD_PCTV_520E:
  1051. pctv_520e_init(dev);
  1052. /* attach demodulator */
  1053. dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
  1054. &dev->i2c_adap);
  1055. if (dvb->fe[0]) {
  1056. /* attach tuner */
  1057. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1058. &dev->i2c_adap,
  1059. &em28xx_cxd2820r_tda18271_config)) {
  1060. dvb_frontend_detach(dvb->fe[0]);
  1061. result = -EINVAL;
  1062. goto out_free;
  1063. }
  1064. }
  1065. break;
  1066. case EM2884_BOARD_CINERGY_HTC_STICK:
  1067. terratec_htc_stick_init(dev);
  1068. /* attach demodulator */
  1069. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1070. &dev->i2c_adap);
  1071. if (!dvb->fe[0]) {
  1072. result = -EINVAL;
  1073. goto out_free;
  1074. }
  1075. /* Attach the demodulator. */
  1076. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1077. &dev->i2c_adap,
  1078. &em28xx_cxd2820r_tda18271_config)) {
  1079. result = -EINVAL;
  1080. goto out_free;
  1081. }
  1082. break;
  1083. case EM2884_BOARD_TERRATEC_HTC_USB_XS:
  1084. terratec_htc_usb_xs_init(dev);
  1085. /* attach demodulator */
  1086. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1087. &dev->i2c_adap);
  1088. if (!dvb->fe[0]) {
  1089. result = -EINVAL;
  1090. goto out_free;
  1091. }
  1092. /* Attach the demodulator. */
  1093. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1094. &dev->i2c_adap,
  1095. &em28xx_cxd2820r_tda18271_config)) {
  1096. result = -EINVAL;
  1097. goto out_free;
  1098. }
  1099. break;
  1100. default:
  1101. em28xx_errdev("/2: The frontend of your DVB/ATSC card"
  1102. " isn't supported yet\n");
  1103. break;
  1104. }
  1105. if (NULL == dvb->fe[0]) {
  1106. em28xx_errdev("/2: frontend initialization failed\n");
  1107. result = -EINVAL;
  1108. goto out_free;
  1109. }
  1110. /* define general-purpose callback pointer */
  1111. dvb->fe[0]->callback = em28xx_tuner_callback;
  1112. if (dvb->fe[1])
  1113. dvb->fe[1]->callback = em28xx_tuner_callback;
  1114. /* register everything */
  1115. result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
  1116. if (result < 0)
  1117. goto out_free;
  1118. /* MFE lock */
  1119. dvb->adapter.mfe_shared = mfe_shared;
  1120. em28xx_info("Successfully loaded em28xx-dvb\n");
  1121. ret:
  1122. em28xx_set_mode(dev, EM28XX_SUSPEND);
  1123. mutex_unlock(&dev->lock);
  1124. return result;
  1125. out_free:
  1126. kfree(dvb);
  1127. dev->dvb = NULL;
  1128. goto ret;
  1129. }
  1130. static inline void prevent_sleep(struct dvb_frontend_ops *ops)
  1131. {
  1132. ops->set_voltage = NULL;
  1133. ops->sleep = NULL;
  1134. ops->tuner_ops.sleep = NULL;
  1135. }
  1136. static int em28xx_dvb_fini(struct em28xx *dev)
  1137. {
  1138. if (!dev->board.has_dvb) {
  1139. /* This device does not support the extension */
  1140. return 0;
  1141. }
  1142. if (dev->dvb) {
  1143. struct em28xx_dvb *dvb = dev->dvb;
  1144. if (dev->disconnected) {
  1145. /* We cannot tell the device to sleep
  1146. * once it has been unplugged. */
  1147. if (dvb->fe[0])
  1148. prevent_sleep(&dvb->fe[0]->ops);
  1149. if (dvb->fe[1])
  1150. prevent_sleep(&dvb->fe[1]->ops);
  1151. }
  1152. em28xx_unregister_dvb(dvb);
  1153. kfree(dvb);
  1154. dev->dvb = NULL;
  1155. }
  1156. return 0;
  1157. }
  1158. static struct em28xx_ops dvb_ops = {
  1159. .id = EM28XX_DVB,
  1160. .name = "Em28xx dvb Extension",
  1161. .init = em28xx_dvb_init,
  1162. .fini = em28xx_dvb_fini,
  1163. };
  1164. static int __init em28xx_dvb_register(void)
  1165. {
  1166. return em28xx_register_extension(&dvb_ops);
  1167. }
  1168. static void __exit em28xx_dvb_unregister(void)
  1169. {
  1170. em28xx_unregister_extension(&dvb_ops);
  1171. }
  1172. module_init(em28xx_dvb_register);
  1173. module_exit(em28xx_dvb_unregister);