em28xx-dvb.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  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. static 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. /*
  439. * Init the analog decoder (not yet supported), but
  440. * it's probably still a good idea.
  441. */
  442. struct {
  443. unsigned char r[4];
  444. int len;
  445. } regs[] = {
  446. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  447. {{ 0x01, 0x02 }, 2},
  448. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  449. {{ 0x01, 0x00 }, 2},
  450. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  451. };
  452. em28xx_gpio_set(dev, terratec_htc_stick_init);
  453. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  454. msleep(10);
  455. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  456. msleep(10);
  457. dev->i2c_client.addr = 0x82 >> 1;
  458. for (i = 0; i < ARRAY_SIZE(regs); i++)
  459. i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
  460. em28xx_gpio_set(dev, terratec_htc_stick_end);
  461. };
  462. static void terratec_htc_usb_xs_init(struct em28xx *dev)
  463. {
  464. int i;
  465. struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
  466. {EM28XX_R08_GPIO, 0xff, 0xff, 10},
  467. {EM2874_R80_GPIO, 0xb2, 0xff, 100},
  468. {EM2874_R80_GPIO, 0xb2, 0xff, 50},
  469. {EM2874_R80_GPIO, 0xb6, 0xff, 100},
  470. { -1, -1, -1, -1},
  471. };
  472. struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
  473. {EM2874_R80_GPIO, 0xa6, 0xff, 100},
  474. {EM2874_R80_GPIO, 0xa6, 0xff, 50},
  475. {EM2874_R80_GPIO, 0xe6, 0xff, 100},
  476. { -1, -1, -1, -1},
  477. };
  478. /*
  479. * Init the analog decoder (not yet supported), but
  480. * it's probably still a good idea.
  481. */
  482. struct {
  483. unsigned char r[4];
  484. int len;
  485. } regs[] = {
  486. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  487. {{ 0x01, 0x02 }, 2},
  488. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  489. {{ 0x01, 0x00 }, 2},
  490. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  491. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  492. {{ 0x01, 0x00 }, 2},
  493. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  494. {{ 0x04, 0x00 }, 2},
  495. {{ 0x00, 0x04 }, 2},
  496. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  497. {{ 0x04, 0x14 }, 2},
  498. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  499. };
  500. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  501. em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
  502. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  503. msleep(10);
  504. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  505. msleep(10);
  506. dev->i2c_client.addr = 0x82 >> 1;
  507. for (i = 0; i < ARRAY_SIZE(regs); i++)
  508. i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
  509. em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
  510. };
  511. static void pctv_520e_init(struct em28xx *dev)
  512. {
  513. /*
  514. * Init AVF4910B analog decoder. Looks like I2C traffic to
  515. * digital demodulator and tuner are routed via AVF4910B.
  516. */
  517. int i;
  518. struct {
  519. unsigned char r[4];
  520. int len;
  521. } regs[] = {
  522. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  523. {{ 0x01, 0x02 }, 2},
  524. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  525. {{ 0x01, 0x00 }, 2},
  526. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  527. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  528. {{ 0x01, 0x00 }, 2},
  529. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  530. };
  531. dev->i2c_client.addr = 0x82 >> 1; /* 0x41 */
  532. for (i = 0; i < ARRAY_SIZE(regs); i++)
  533. i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
  534. };
  535. static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
  536. {
  537. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  538. struct em28xx *dev = fe->dvb->priv;
  539. #ifdef CONFIG_GPIOLIB
  540. struct em28xx_dvb *dvb = dev->dvb;
  541. int ret;
  542. unsigned long flags;
  543. if (c->lna == 1)
  544. flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
  545. else
  546. flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
  547. ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
  548. if (ret)
  549. em28xx_errdev("gpio request failed %d\n", ret);
  550. else
  551. gpio_free(dvb->lna_gpio);
  552. return ret;
  553. #else
  554. dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
  555. KBUILD_MODNAME, c->lna);
  556. return 0;
  557. #endif
  558. }
  559. static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
  560. {
  561. /* Values extracted from a USB trace of the Terratec Windows driver */
  562. static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
  563. static u8 reset[] = { RESET, 0x80 };
  564. static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
  565. static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
  566. static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
  567. static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
  568. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  569. static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
  570. static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
  571. static u8 tuner_go[] = { TUNER_GO, 0x01};
  572. mt352_write(fe, clock_config, sizeof(clock_config));
  573. udelay(200);
  574. mt352_write(fe, reset, sizeof(reset));
  575. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  576. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  577. mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
  578. mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
  579. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  580. mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
  581. mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
  582. mt352_write(fe, tuner_go, sizeof(tuner_go));
  583. return 0;
  584. }
  585. static struct mt352_config terratec_xs_mt352_cfg = {
  586. .demod_address = (0x1e >> 1),
  587. .no_tuner = 1,
  588. .if2 = 45600,
  589. .demod_init = em28xx_mt352_terratec_xs_init,
  590. };
  591. static struct tda10023_config em28xx_tda10023_config = {
  592. .demod_address = 0x0c,
  593. .invert = 1,
  594. };
  595. static struct cxd2820r_config em28xx_cxd2820r_config = {
  596. .i2c_address = (0xd8 >> 1),
  597. .ts_mode = CXD2820R_TS_SERIAL,
  598. };
  599. static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
  600. .output_opt = TDA18271_OUTPUT_LT_OFF,
  601. .gate = TDA18271_GATE_DIGITAL,
  602. };
  603. static const struct tda10071_config em28xx_tda10071_config = {
  604. .i2c_address = 0x55, /* (0xaa >> 1) */
  605. .i2c_wr_max = 64,
  606. .ts_mode = TDA10071_TS_SERIAL,
  607. .spec_inv = 0,
  608. .xtal = 40444000, /* 40.444 MHz */
  609. .pll_multiplier = 20,
  610. };
  611. static const struct a8293_config em28xx_a8293_config = {
  612. .i2c_addr = 0x08, /* (0x10 >> 1) */
  613. };
  614. static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
  615. .demod_address = (0x1e >> 1),
  616. .disable_i2c_gate_ctrl = 1,
  617. .no_tuner = 1,
  618. .parallel_ts = 1,
  619. };
  620. static struct qt1010_config em28xx_qt1010_config = {
  621. .i2c_address = 0x62
  622. };
  623. /* ------------------------------------------------------------------ */
  624. static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
  625. {
  626. struct dvb_frontend *fe;
  627. struct xc2028_config cfg;
  628. memset(&cfg, 0, sizeof(cfg));
  629. cfg.i2c_adap = &dev->i2c_adap;
  630. cfg.i2c_addr = addr;
  631. if (!dev->dvb->fe[0]) {
  632. em28xx_errdev("/2: dvb frontend not attached. "
  633. "Can't attach xc3028\n");
  634. return -EINVAL;
  635. }
  636. fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
  637. if (!fe) {
  638. em28xx_errdev("/2: xc3028 attach failed\n");
  639. dvb_frontend_detach(dev->dvb->fe[0]);
  640. dev->dvb->fe[0] = NULL;
  641. return -EINVAL;
  642. }
  643. em28xx_info("%s/2: xc3028 attached\n", dev->name);
  644. return 0;
  645. }
  646. /* ------------------------------------------------------------------ */
  647. static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
  648. struct em28xx *dev, struct device *device)
  649. {
  650. int result;
  651. mutex_init(&dvb->lock);
  652. /* register adapter */
  653. result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
  654. adapter_nr);
  655. if (result < 0) {
  656. printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
  657. dev->name, result);
  658. goto fail_adapter;
  659. }
  660. /* Ensure all frontends negotiate bus access */
  661. dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  662. if (dvb->fe[1])
  663. dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  664. dvb->adapter.priv = dev;
  665. /* register frontend */
  666. result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
  667. if (result < 0) {
  668. printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
  669. dev->name, result);
  670. goto fail_frontend0;
  671. }
  672. /* register 2nd frontend */
  673. if (dvb->fe[1]) {
  674. result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
  675. if (result < 0) {
  676. printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
  677. dev->name, result);
  678. goto fail_frontend1;
  679. }
  680. }
  681. /* register demux stuff */
  682. dvb->demux.dmx.capabilities =
  683. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  684. DMX_MEMORY_BASED_FILTERING;
  685. dvb->demux.priv = dvb;
  686. dvb->demux.filternum = 256;
  687. dvb->demux.feednum = 256;
  688. dvb->demux.start_feed = em28xx_start_feed;
  689. dvb->demux.stop_feed = em28xx_stop_feed;
  690. result = dvb_dmx_init(&dvb->demux);
  691. if (result < 0) {
  692. printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
  693. dev->name, result);
  694. goto fail_dmx;
  695. }
  696. dvb->dmxdev.filternum = 256;
  697. dvb->dmxdev.demux = &dvb->demux.dmx;
  698. dvb->dmxdev.capabilities = 0;
  699. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  700. if (result < 0) {
  701. printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
  702. dev->name, result);
  703. goto fail_dmxdev;
  704. }
  705. dvb->fe_hw.source = DMX_FRONTEND_0;
  706. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  707. if (result < 0) {
  708. printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  709. dev->name, result);
  710. goto fail_fe_hw;
  711. }
  712. dvb->fe_mem.source = DMX_MEMORY_FE;
  713. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  714. if (result < 0) {
  715. printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  716. dev->name, result);
  717. goto fail_fe_mem;
  718. }
  719. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  720. if (result < 0) {
  721. printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
  722. dev->name, result);
  723. goto fail_fe_conn;
  724. }
  725. /* register network adapter */
  726. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  727. return 0;
  728. fail_fe_conn:
  729. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  730. fail_fe_mem:
  731. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  732. fail_fe_hw:
  733. dvb_dmxdev_release(&dvb->dmxdev);
  734. fail_dmxdev:
  735. dvb_dmx_release(&dvb->demux);
  736. fail_dmx:
  737. if (dvb->fe[1])
  738. dvb_unregister_frontend(dvb->fe[1]);
  739. dvb_unregister_frontend(dvb->fe[0]);
  740. fail_frontend1:
  741. if (dvb->fe[1])
  742. dvb_frontend_detach(dvb->fe[1]);
  743. fail_frontend0:
  744. dvb_frontend_detach(dvb->fe[0]);
  745. dvb_unregister_adapter(&dvb->adapter);
  746. fail_adapter:
  747. return result;
  748. }
  749. static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
  750. {
  751. dvb_net_release(&dvb->net);
  752. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  753. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  754. dvb_dmxdev_release(&dvb->dmxdev);
  755. dvb_dmx_release(&dvb->demux);
  756. if (dvb->fe[1])
  757. dvb_unregister_frontend(dvb->fe[1]);
  758. dvb_unregister_frontend(dvb->fe[0]);
  759. if (dvb->fe[1] && !dvb->dont_attach_fe1)
  760. dvb_frontend_detach(dvb->fe[1]);
  761. dvb_frontend_detach(dvb->fe[0]);
  762. dvb_unregister_adapter(&dvb->adapter);
  763. }
  764. static int em28xx_dvb_init(struct em28xx *dev)
  765. {
  766. int result = 0, mfe_shared = 0;
  767. struct em28xx_dvb *dvb;
  768. if (!dev->board.has_dvb) {
  769. /* This device does not support the extension */
  770. printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
  771. return 0;
  772. }
  773. dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
  774. if (dvb == NULL) {
  775. em28xx_info("em28xx_dvb: memory allocation failed\n");
  776. return -ENOMEM;
  777. }
  778. dev->dvb = dvb;
  779. dvb->fe[0] = dvb->fe[1] = NULL;
  780. mutex_lock(&dev->lock);
  781. em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  782. /* init frontend */
  783. switch (dev->model) {
  784. case EM2874_BOARD_LEADERSHIP_ISDBT:
  785. dvb->fe[0] = dvb_attach(s921_attach,
  786. &sharp_isdbt, &dev->i2c_adap);
  787. if (!dvb->fe[0]) {
  788. result = -EINVAL;
  789. goto out_free;
  790. }
  791. break;
  792. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
  793. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
  794. case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
  795. case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
  796. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  797. &em2880_lgdt3303_dev,
  798. &dev->i2c_adap);
  799. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  800. result = -EINVAL;
  801. goto out_free;
  802. }
  803. break;
  804. case EM2880_BOARD_KWORLD_DVB_310U:
  805. dvb->fe[0] = dvb_attach(zl10353_attach,
  806. &em28xx_zl10353_with_xc3028,
  807. &dev->i2c_adap);
  808. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  809. result = -EINVAL;
  810. goto out_free;
  811. }
  812. break;
  813. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  814. case EM2882_BOARD_TERRATEC_HYBRID_XS:
  815. case EM2880_BOARD_EMPIRE_DUAL_TV:
  816. dvb->fe[0] = dvb_attach(zl10353_attach,
  817. &em28xx_zl10353_xc3028_no_i2c_gate,
  818. &dev->i2c_adap);
  819. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  820. result = -EINVAL;
  821. goto out_free;
  822. }
  823. break;
  824. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  825. case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
  826. case EM2881_BOARD_PINNACLE_HYBRID_PRO:
  827. case EM2882_BOARD_DIKOM_DK300:
  828. case EM2882_BOARD_KWORLD_VS_DVBT:
  829. dvb->fe[0] = dvb_attach(zl10353_attach,
  830. &em28xx_zl10353_xc3028_no_i2c_gate,
  831. &dev->i2c_adap);
  832. if (dvb->fe[0] == NULL) {
  833. /* This board could have either a zl10353 or a mt352.
  834. If the chip id isn't for zl10353, try mt352 */
  835. dvb->fe[0] = dvb_attach(mt352_attach,
  836. &terratec_xs_mt352_cfg,
  837. &dev->i2c_adap);
  838. }
  839. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  840. result = -EINVAL;
  841. goto out_free;
  842. }
  843. break;
  844. case EM2870_BOARD_KWORLD_355U:
  845. dvb->fe[0] = dvb_attach(zl10353_attach,
  846. &em28xx_zl10353_no_i2c_gate_dev,
  847. &dev->i2c_adap);
  848. if (dvb->fe[0] != NULL)
  849. dvb_attach(qt1010_attach, dvb->fe[0],
  850. &dev->i2c_adap, &em28xx_qt1010_config);
  851. break;
  852. case EM2883_BOARD_KWORLD_HYBRID_330U:
  853. case EM2882_BOARD_EVGA_INDTUBE:
  854. dvb->fe[0] = dvb_attach(s5h1409_attach,
  855. &em28xx_s5h1409_with_xc3028,
  856. &dev->i2c_adap);
  857. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  858. result = -EINVAL;
  859. goto out_free;
  860. }
  861. break;
  862. case EM2882_BOARD_KWORLD_ATSC_315U:
  863. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  864. &em2880_lgdt3303_dev,
  865. &dev->i2c_adap);
  866. if (dvb->fe[0] != NULL) {
  867. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  868. &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
  869. result = -EINVAL;
  870. goto out_free;
  871. }
  872. }
  873. break;
  874. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
  875. case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
  876. dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
  877. &dev->i2c_adap, &dev->udev->dev);
  878. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  879. result = -EINVAL;
  880. goto out_free;
  881. }
  882. break;
  883. case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
  884. /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
  885. dvb->fe[0] = dvb_attach(tda10023_attach,
  886. &em28xx_tda10023_config,
  887. &dev->i2c_adap, 0x48);
  888. if (dvb->fe[0]) {
  889. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  890. &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
  891. result = -EINVAL;
  892. goto out_free;
  893. }
  894. }
  895. break;
  896. case EM2870_BOARD_KWORLD_A340:
  897. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  898. &em2870_lgdt3304_dev,
  899. &dev->i2c_adap);
  900. if (dvb->fe[0] != NULL)
  901. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  902. &dev->i2c_adap, &kworld_a340_config);
  903. break;
  904. case EM28174_BOARD_PCTV_290E:
  905. /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
  906. dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
  907. CXD2820R_GPIO_L;
  908. dvb->fe[0] = dvb_attach(cxd2820r_attach,
  909. &em28xx_cxd2820r_config,
  910. &dev->i2c_adap,
  911. &dvb->lna_gpio);
  912. if (dvb->fe[0]) {
  913. /* FE 0 attach tuner */
  914. if (!dvb_attach(tda18271_attach,
  915. dvb->fe[0],
  916. 0x60,
  917. &dev->i2c_adap,
  918. &em28xx_cxd2820r_tda18271_config)) {
  919. dvb_frontend_detach(dvb->fe[0]);
  920. result = -EINVAL;
  921. goto out_free;
  922. }
  923. #ifdef CONFIG_GPIOLIB
  924. /* enable LNA for DVB-T, DVB-T2 and DVB-C */
  925. result = gpio_request_one(dvb->lna_gpio,
  926. GPIOF_OUT_INIT_LOW, NULL);
  927. if (result)
  928. em28xx_errdev("gpio request failed %d\n",
  929. result);
  930. else
  931. gpio_free(dvb->lna_gpio);
  932. result = 0; /* continue even set LNA fails */
  933. #endif
  934. dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
  935. }
  936. break;
  937. case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
  938. {
  939. struct xc5000_config cfg;
  940. hauppauge_hvr930c_init(dev);
  941. dvb->fe[0] = dvb_attach(drxk_attach,
  942. &hauppauge_930c_drxk, &dev->i2c_adap);
  943. if (!dvb->fe[0]) {
  944. result = -EINVAL;
  945. goto out_free;
  946. }
  947. /* FIXME: do we need a pll semaphore? */
  948. dvb->fe[0]->sec_priv = dvb;
  949. sema_init(&dvb->pll_mutex, 1);
  950. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  951. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  952. /* Attach xc5000 */
  953. memset(&cfg, 0, sizeof(cfg));
  954. cfg.i2c_address = 0x61;
  955. cfg.if_khz = 4000;
  956. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  957. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  958. if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap,
  959. &cfg)) {
  960. result = -EINVAL;
  961. goto out_free;
  962. }
  963. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  964. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  965. break;
  966. }
  967. case EM2884_BOARD_TERRATEC_H5:
  968. terratec_h5_init(dev);
  969. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap);
  970. if (!dvb->fe[0]) {
  971. result = -EINVAL;
  972. goto out_free;
  973. }
  974. /* FIXME: do we need a pll semaphore? */
  975. dvb->fe[0]->sec_priv = dvb;
  976. sema_init(&dvb->pll_mutex, 1);
  977. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  978. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  979. /* Attach tda18271 to DVB-C frontend */
  980. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  981. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  982. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
  983. result = -EINVAL;
  984. goto out_free;
  985. }
  986. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  987. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  988. break;
  989. case EM28174_BOARD_PCTV_460E:
  990. /* attach demod */
  991. dvb->fe[0] = dvb_attach(tda10071_attach,
  992. &em28xx_tda10071_config, &dev->i2c_adap);
  993. /* attach SEC */
  994. if (dvb->fe[0])
  995. dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap,
  996. &em28xx_a8293_config);
  997. break;
  998. case EM2874_BOARD_MAXMEDIA_UB425_TC:
  999. /* attach demodulator */
  1000. dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
  1001. &dev->i2c_adap);
  1002. if (dvb->fe[0]) {
  1003. /* disable I2C-gate */
  1004. dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
  1005. /* attach tuner */
  1006. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
  1007. &dev->i2c_adap, 0x60)) {
  1008. dvb_frontend_detach(dvb->fe[0]);
  1009. result = -EINVAL;
  1010. goto out_free;
  1011. }
  1012. }
  1013. /* TODO: we need drx-3913k firmware in order to support DVB-T */
  1014. em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \
  1015. "driver version\n");
  1016. break;
  1017. case EM2884_BOARD_PCTV_510E:
  1018. case EM2884_BOARD_PCTV_520E:
  1019. pctv_520e_init(dev);
  1020. /* attach demodulator */
  1021. dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
  1022. &dev->i2c_adap);
  1023. if (dvb->fe[0]) {
  1024. /* attach tuner */
  1025. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1026. &dev->i2c_adap,
  1027. &em28xx_cxd2820r_tda18271_config)) {
  1028. dvb_frontend_detach(dvb->fe[0]);
  1029. result = -EINVAL;
  1030. goto out_free;
  1031. }
  1032. }
  1033. break;
  1034. case EM2884_BOARD_CINERGY_HTC_STICK:
  1035. terratec_htc_stick_init(dev);
  1036. /* attach demodulator */
  1037. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1038. &dev->i2c_adap);
  1039. if (!dvb->fe[0]) {
  1040. result = -EINVAL;
  1041. goto out_free;
  1042. }
  1043. /* Attach the demodulator. */
  1044. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1045. &dev->i2c_adap,
  1046. &em28xx_cxd2820r_tda18271_config)) {
  1047. result = -EINVAL;
  1048. goto out_free;
  1049. }
  1050. break;
  1051. case EM2884_BOARD_TERRATEC_HTC_USB_XS:
  1052. terratec_htc_usb_xs_init(dev);
  1053. /* attach demodulator */
  1054. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1055. &dev->i2c_adap);
  1056. if (!dvb->fe[0]) {
  1057. result = -EINVAL;
  1058. goto out_free;
  1059. }
  1060. /* Attach the demodulator. */
  1061. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1062. &dev->i2c_adap,
  1063. &em28xx_cxd2820r_tda18271_config)) {
  1064. result = -EINVAL;
  1065. goto out_free;
  1066. }
  1067. break;
  1068. default:
  1069. em28xx_errdev("/2: The frontend of your DVB/ATSC card"
  1070. " isn't supported yet\n");
  1071. break;
  1072. }
  1073. if (NULL == dvb->fe[0]) {
  1074. em28xx_errdev("/2: frontend initialization failed\n");
  1075. result = -EINVAL;
  1076. goto out_free;
  1077. }
  1078. /* define general-purpose callback pointer */
  1079. dvb->fe[0]->callback = em28xx_tuner_callback;
  1080. if (dvb->fe[1])
  1081. dvb->fe[1]->callback = em28xx_tuner_callback;
  1082. /* register everything */
  1083. result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
  1084. if (result < 0)
  1085. goto out_free;
  1086. /* MFE lock */
  1087. dvb->adapter.mfe_shared = mfe_shared;
  1088. em28xx_info("Successfully loaded em28xx-dvb\n");
  1089. ret:
  1090. em28xx_set_mode(dev, EM28XX_SUSPEND);
  1091. mutex_unlock(&dev->lock);
  1092. return result;
  1093. out_free:
  1094. kfree(dvb);
  1095. dev->dvb = NULL;
  1096. goto ret;
  1097. }
  1098. static inline void prevent_sleep(struct dvb_frontend_ops *ops)
  1099. {
  1100. ops->set_voltage = NULL;
  1101. ops->sleep = NULL;
  1102. ops->tuner_ops.sleep = NULL;
  1103. }
  1104. static int em28xx_dvb_fini(struct em28xx *dev)
  1105. {
  1106. if (!dev->board.has_dvb) {
  1107. /* This device does not support the extension */
  1108. return 0;
  1109. }
  1110. if (dev->dvb) {
  1111. struct em28xx_dvb *dvb = dev->dvb;
  1112. if (dev->state & DEV_DISCONNECTED) {
  1113. /* We cannot tell the device to sleep
  1114. * once it has been unplugged. */
  1115. if (dvb->fe[0])
  1116. prevent_sleep(&dvb->fe[0]->ops);
  1117. if (dvb->fe[1])
  1118. prevent_sleep(&dvb->fe[1]->ops);
  1119. }
  1120. em28xx_unregister_dvb(dvb);
  1121. kfree(dvb);
  1122. dev->dvb = NULL;
  1123. }
  1124. return 0;
  1125. }
  1126. static struct em28xx_ops dvb_ops = {
  1127. .id = EM28XX_DVB,
  1128. .name = "Em28xx dvb Extension",
  1129. .init = em28xx_dvb_init,
  1130. .fini = em28xx_dvb_fini,
  1131. };
  1132. static int __init em28xx_dvb_register(void)
  1133. {
  1134. return em28xx_register_extension(&dvb_ops);
  1135. }
  1136. static void __exit em28xx_dvb_unregister(void)
  1137. {
  1138. em28xx_unregister_extension(&dvb_ops);
  1139. }
  1140. module_init(em28xx_dvb_register);
  1141. module_exit(em28xx_dvb_unregister);