em28xx-dvb.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // DVB device driver for em28xx
  4. //
  5. // (c) 2008-2011 Mauro Carvalho Chehab <mchehab@kernel.org>
  6. //
  7. // (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
  8. // - Fixes for the driver to properly work with HVR-950
  9. // - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
  10. // - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
  11. //
  12. // (c) 2008 Aidan Thornton <makosoft@googlemail.com>
  13. //
  14. // (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
  15. //
  16. // Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
  17. // (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
  18. // (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  19. //
  20. // This program is free software; you can redistribute it and/or modify
  21. // it under the terms of the GNU General Public License as published by
  22. // the Free Software Foundation version 2 of the License.
  23. #include "em28xx.h"
  24. #include <linux/kernel.h>
  25. #include <linux/slab.h>
  26. #include <linux/usb.h>
  27. #include <media/v4l2-common.h>
  28. #include <media/dvb_demux.h>
  29. #include <media/dvb_net.h>
  30. #include <media/dmxdev.h>
  31. #include <media/tuner.h>
  32. #include "tuner-simple.h"
  33. #include <linux/gpio.h>
  34. #include "lgdt330x.h"
  35. #include "lgdt3305.h"
  36. #include "lgdt3306a.h"
  37. #include "zl10353.h"
  38. #include "s5h1409.h"
  39. #include "mt2060.h"
  40. #include "mt352.h"
  41. #include "mt352_priv.h" /* FIXME */
  42. #include "tda1002x.h"
  43. #include "drx39xyj/drx39xxj.h"
  44. #include "tda18271.h"
  45. #include "s921.h"
  46. #include "drxd.h"
  47. #include "cxd2820r.h"
  48. #include "tda18271c2dd.h"
  49. #include "drxk.h"
  50. #include "tda10071.h"
  51. #include "tda18212.h"
  52. #include "a8293.h"
  53. #include "qt1010.h"
  54. #include "mb86a20s.h"
  55. #include "m88ds3103.h"
  56. #include "ts2020.h"
  57. #include "si2168.h"
  58. #include "si2157.h"
  59. #include "tc90522.h"
  60. #include "qm1d1c0042.h"
  61. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@kernel.org>");
  62. MODULE_LICENSE("GPL v2");
  63. MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
  64. MODULE_VERSION(EM28XX_VERSION);
  65. static unsigned int debug;
  66. module_param(debug, int, 0644);
  67. MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
  68. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  69. #define dprintk(level, fmt, arg...) do { \
  70. if (debug >= level) \
  71. dev_printk(KERN_DEBUG, &dev->intf->dev, \
  72. "dvb: " fmt, ## arg); \
  73. } while (0)
  74. struct em28xx_dvb {
  75. struct dvb_frontend *fe[2];
  76. /* feed count management */
  77. struct mutex lock;
  78. int nfeeds;
  79. /* general boilerplate stuff */
  80. struct dvb_adapter adapter;
  81. struct dvb_demux demux;
  82. struct dmxdev dmxdev;
  83. struct dmx_frontend fe_hw;
  84. struct dmx_frontend fe_mem;
  85. struct dvb_net net;
  86. /* Due to DRX-K - probably need changes */
  87. int (*gate_ctrl)(struct dvb_frontend *fe, int gate);
  88. struct semaphore pll_mutex;
  89. bool dont_attach_fe1;
  90. int lna_gpio;
  91. struct i2c_client *i2c_client_demod;
  92. struct i2c_client *i2c_client_tuner;
  93. struct i2c_client *i2c_client_sec;
  94. };
  95. static inline void print_err_status(struct em28xx *dev,
  96. int packet, int status)
  97. {
  98. char *errmsg = "Unknown";
  99. switch (status) {
  100. case -ENOENT:
  101. errmsg = "unlinked synchronously";
  102. break;
  103. case -ECONNRESET:
  104. errmsg = "unlinked asynchronously";
  105. break;
  106. case -ENOSR:
  107. errmsg = "Buffer error (overrun)";
  108. break;
  109. case -EPIPE:
  110. errmsg = "Stalled (device not responding)";
  111. break;
  112. case -EOVERFLOW:
  113. errmsg = "Babble (bad cable?)";
  114. break;
  115. case -EPROTO:
  116. errmsg = "Bit-stuff error (bad cable?)";
  117. break;
  118. case -EILSEQ:
  119. errmsg = "CRC/Timeout (could be anything)";
  120. break;
  121. case -ETIME:
  122. errmsg = "Device does not respond";
  123. break;
  124. }
  125. if (packet < 0) {
  126. dprintk(1, "URB status %d [%s].\n", status, errmsg);
  127. } else {
  128. dprintk(1, "URB packet %d, status %d [%s].\n",
  129. packet, status, errmsg);
  130. }
  131. }
  132. static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
  133. {
  134. int xfer_bulk, num_packets, i;
  135. if (!dev)
  136. return 0;
  137. if (dev->disconnected)
  138. return 0;
  139. if (urb->status < 0)
  140. print_err_status(dev, -1, urb->status);
  141. xfer_bulk = usb_pipebulk(urb->pipe);
  142. if (xfer_bulk) /* bulk */
  143. num_packets = 1;
  144. else /* isoc */
  145. num_packets = urb->number_of_packets;
  146. for (i = 0; i < num_packets; i++) {
  147. if (xfer_bulk) {
  148. if (urb->status < 0) {
  149. print_err_status(dev, i, urb->status);
  150. if (urb->status != -EPROTO)
  151. continue;
  152. }
  153. if (!urb->actual_length)
  154. continue;
  155. dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
  156. urb->actual_length);
  157. } else {
  158. if (urb->iso_frame_desc[i].status < 0) {
  159. print_err_status(dev, i,
  160. urb->iso_frame_desc[i].status);
  161. if (urb->iso_frame_desc[i].status != -EPROTO)
  162. continue;
  163. }
  164. if (!urb->iso_frame_desc[i].actual_length)
  165. continue;
  166. dvb_dmx_swfilter(&dev->dvb->demux,
  167. urb->transfer_buffer +
  168. urb->iso_frame_desc[i].offset,
  169. urb->iso_frame_desc[i].actual_length);
  170. }
  171. }
  172. return 0;
  173. }
  174. static int em28xx_start_streaming(struct em28xx_dvb *dvb)
  175. {
  176. int rc;
  177. struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
  178. struct em28xx *dev = i2c_bus->dev;
  179. struct usb_device *udev = interface_to_usbdev(dev->intf);
  180. int dvb_max_packet_size, packet_multiplier, dvb_alt;
  181. if (dev->dvb_xfer_bulk) {
  182. if (!dev->dvb_ep_bulk)
  183. return -ENODEV;
  184. dvb_max_packet_size = 512; /* USB 2.0 spec */
  185. packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
  186. dvb_alt = 0;
  187. } else { /* isoc */
  188. if (!dev->dvb_ep_isoc)
  189. return -ENODEV;
  190. dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
  191. if (dvb_max_packet_size < 0)
  192. return dvb_max_packet_size;
  193. packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
  194. dvb_alt = dev->dvb_alt_isoc;
  195. }
  196. if (!dev->board.has_dual_ts)
  197. usb_set_interface(udev, dev->ifnum, dvb_alt);
  198. rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  199. if (rc < 0)
  200. return rc;
  201. dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
  202. EM28XX_DVB_NUM_BUFS,
  203. packet_multiplier,
  204. dvb_max_packet_size, dvb_alt);
  205. return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
  206. dev->dvb_xfer_bulk,
  207. EM28XX_DVB_NUM_BUFS,
  208. dvb_max_packet_size,
  209. packet_multiplier,
  210. em28xx_dvb_urb_data_copy);
  211. }
  212. static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
  213. {
  214. struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
  215. struct em28xx *dev = i2c_bus->dev;
  216. em28xx_stop_urbs(dev);
  217. return 0;
  218. }
  219. static int em28xx_start_feed(struct dvb_demux_feed *feed)
  220. {
  221. struct dvb_demux *demux = feed->demux;
  222. struct em28xx_dvb *dvb = demux->priv;
  223. int rc, ret;
  224. if (!demux->dmx.frontend)
  225. return -EINVAL;
  226. mutex_lock(&dvb->lock);
  227. dvb->nfeeds++;
  228. rc = dvb->nfeeds;
  229. if (dvb->nfeeds == 1) {
  230. ret = em28xx_start_streaming(dvb);
  231. if (ret < 0)
  232. rc = ret;
  233. }
  234. mutex_unlock(&dvb->lock);
  235. return rc;
  236. }
  237. static int em28xx_stop_feed(struct dvb_demux_feed *feed)
  238. {
  239. struct dvb_demux *demux = feed->demux;
  240. struct em28xx_dvb *dvb = demux->priv;
  241. int err = 0;
  242. mutex_lock(&dvb->lock);
  243. dvb->nfeeds--;
  244. if (!dvb->nfeeds)
  245. err = em28xx_stop_streaming(dvb);
  246. mutex_unlock(&dvb->lock);
  247. return err;
  248. }
  249. /* ------------------------------------------------------------------ */
  250. static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
  251. {
  252. struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
  253. struct em28xx *dev = i2c_bus->dev;
  254. if (acquire)
  255. return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  256. else
  257. return em28xx_set_mode(dev, EM28XX_SUSPEND);
  258. }
  259. /* ------------------------------------------------------------------ */
  260. static struct lgdt330x_config em2880_lgdt3303_dev = {
  261. .demod_chip = LGDT3303,
  262. };
  263. static struct lgdt3305_config em2870_lgdt3304_dev = {
  264. .i2c_addr = 0x0e,
  265. .demod_chip = LGDT3304,
  266. .spectral_inversion = 1,
  267. .deny_i2c_rptr = 1,
  268. .mpeg_mode = LGDT3305_MPEG_PARALLEL,
  269. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  270. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  271. .vsb_if_khz = 3250,
  272. .qam_if_khz = 4000,
  273. };
  274. static struct lgdt3305_config em2874_lgdt3305_dev = {
  275. .i2c_addr = 0x0e,
  276. .demod_chip = LGDT3305,
  277. .spectral_inversion = 1,
  278. .deny_i2c_rptr = 0,
  279. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  280. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  281. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  282. .vsb_if_khz = 3250,
  283. .qam_if_khz = 4000,
  284. };
  285. static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
  286. .i2c_addr = 0x0e,
  287. .demod_chip = LGDT3305,
  288. .spectral_inversion = 1,
  289. .deny_i2c_rptr = 1,
  290. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  291. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  292. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  293. .vsb_if_khz = 3600,
  294. .qam_if_khz = 3600,
  295. };
  296. static struct s921_config sharp_isdbt = {
  297. .demod_address = 0x30 >> 1
  298. };
  299. static struct zl10353_config em28xx_zl10353_with_xc3028 = {
  300. .demod_address = (0x1e >> 1),
  301. .no_tuner = 1,
  302. .parallel_ts = 1,
  303. .if2 = 45600,
  304. };
  305. static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
  306. .demod_address = 0x32 >> 1,
  307. .output_mode = S5H1409_PARALLEL_OUTPUT,
  308. .gpio = S5H1409_GPIO_OFF,
  309. .inversion = S5H1409_INVERSION_OFF,
  310. .status_mode = S5H1409_DEMODLOCKING,
  311. .mpeg_timing = S5H1409_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK
  312. };
  313. static struct tda18271_std_map kworld_a340_std_map = {
  314. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
  315. .if_lvl = 1, .rfagc_top = 0x37, },
  316. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
  317. .if_lvl = 1, .rfagc_top = 0x37, },
  318. };
  319. static struct tda18271_config kworld_a340_config = {
  320. .std_map = &kworld_a340_std_map,
  321. };
  322. static struct tda18271_config kworld_ub435q_v2_config = {
  323. .std_map = &kworld_a340_std_map,
  324. .gate = TDA18271_GATE_DIGITAL,
  325. };
  326. static struct tda18212_config kworld_ub435q_v3_config = {
  327. .if_atsc_vsb = 3600,
  328. .if_atsc_qam = 3600,
  329. };
  330. static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
  331. .demod_address = (0x1e >> 1),
  332. .no_tuner = 1,
  333. .disable_i2c_gate_ctrl = 1,
  334. .parallel_ts = 1,
  335. .if2 = 45600,
  336. };
  337. static struct drxd_config em28xx_drxd = {
  338. .demod_address = 0x70,
  339. .demod_revision = 0xa2,
  340. .pll_type = DRXD_PLL_NONE,
  341. .clock = 12000,
  342. .insert_rs_byte = 1,
  343. .IF = 42800000,
  344. .disable_i2c_gate_ctrl = 1,
  345. };
  346. static struct drxk_config terratec_h5_drxk = {
  347. .adr = 0x29,
  348. .single_master = 1,
  349. .no_i2c_bridge = 1,
  350. .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
  351. .qam_demod_parameter_count = 2,
  352. };
  353. static struct drxk_config hauppauge_930c_drxk = {
  354. .adr = 0x29,
  355. .single_master = 1,
  356. .no_i2c_bridge = 1,
  357. .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
  358. .chunk_size = 56,
  359. .qam_demod_parameter_count = 2,
  360. };
  361. static struct drxk_config terratec_htc_stick_drxk = {
  362. .adr = 0x29,
  363. .single_master = 1,
  364. .no_i2c_bridge = 1,
  365. .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
  366. .chunk_size = 54,
  367. .qam_demod_parameter_count = 2,
  368. /* Required for the antenna_gpio to disable LNA. */
  369. .antenna_dvbt = true,
  370. /* The windows driver uses the same. This will disable LNA. */
  371. .antenna_gpio = 0x6,
  372. };
  373. static struct drxk_config maxmedia_ub425_tc_drxk = {
  374. .adr = 0x29,
  375. .single_master = 1,
  376. .no_i2c_bridge = 1,
  377. .microcode_name = "dvb-demod-drxk-01.fw",
  378. .chunk_size = 62,
  379. .qam_demod_parameter_count = 2,
  380. };
  381. static struct drxk_config pctv_520e_drxk = {
  382. .adr = 0x29,
  383. .single_master = 1,
  384. .microcode_name = "dvb-demod-drxk-pctv.fw",
  385. .qam_demod_parameter_count = 2,
  386. .chunk_size = 58,
  387. .antenna_dvbt = true, /* disable LNA */
  388. .antenna_gpio = (1 << 2), /* disable LNA */
  389. };
  390. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  391. {
  392. struct em28xx_dvb *dvb = fe->sec_priv;
  393. int status;
  394. if (!dvb)
  395. return -EINVAL;
  396. if (enable) {
  397. down(&dvb->pll_mutex);
  398. status = dvb->gate_ctrl(fe, 1);
  399. } else {
  400. status = dvb->gate_ctrl(fe, 0);
  401. up(&dvb->pll_mutex);
  402. }
  403. return status;
  404. }
  405. static void hauppauge_hvr930c_init(struct em28xx *dev)
  406. {
  407. int i;
  408. struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
  409. {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
  410. {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
  411. {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
  412. { -1, -1, -1, -1},
  413. };
  414. struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
  415. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
  416. {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
  417. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
  418. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
  419. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
  420. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
  421. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
  422. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
  423. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
  424. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
  425. { -1, -1, -1, -1},
  426. };
  427. struct {
  428. unsigned char r[4];
  429. int len;
  430. } regs[] = {
  431. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  432. {{ 0x01, 0x02 }, 2},
  433. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  434. {{ 0x01, 0x00 }, 2},
  435. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  436. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  437. {{ 0x01, 0x00 }, 2},
  438. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  439. {{ 0x04, 0x00 }, 2},
  440. {{ 0x00, 0x04 }, 2},
  441. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  442. {{ 0x04, 0x14 }, 2},
  443. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  444. };
  445. em28xx_gpio_set(dev, hauppauge_hvr930c_init);
  446. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  447. usleep_range(10000, 11000);
  448. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  449. usleep_range(10000, 11000);
  450. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  451. for (i = 0; i < ARRAY_SIZE(regs); i++)
  452. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
  453. regs[i].r, regs[i].len);
  454. em28xx_gpio_set(dev, hauppauge_hvr930c_end);
  455. msleep(100);
  456. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  457. msleep(30);
  458. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
  459. usleep_range(10000, 11000);
  460. }
  461. static void terratec_h5_init(struct em28xx *dev)
  462. {
  463. int i;
  464. struct em28xx_reg_seq terratec_h5_init[] = {
  465. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  466. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  467. {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
  468. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  469. { -1, -1, -1, -1},
  470. };
  471. struct em28xx_reg_seq terratec_h5_end[] = {
  472. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  473. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
  474. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  475. { -1, -1, -1, -1},
  476. };
  477. struct {
  478. unsigned char r[4];
  479. int len;
  480. } regs[] = {
  481. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  482. {{ 0x01, 0x02 }, 2},
  483. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  484. {{ 0x01, 0x00 }, 2},
  485. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  486. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  487. {{ 0x01, 0x00 }, 2},
  488. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  489. {{ 0x04, 0x00 }, 2},
  490. {{ 0x00, 0x04 }, 2},
  491. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  492. {{ 0x04, 0x14 }, 2},
  493. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  494. };
  495. em28xx_gpio_set(dev, terratec_h5_init);
  496. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  497. usleep_range(10000, 11000);
  498. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
  499. usleep_range(10000, 11000);
  500. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  501. for (i = 0; i < ARRAY_SIZE(regs); i++)
  502. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
  503. regs[i].r, regs[i].len);
  504. em28xx_gpio_set(dev, terratec_h5_end);
  505. };
  506. static void terratec_htc_stick_init(struct em28xx *dev)
  507. {
  508. int i;
  509. /*
  510. * GPIO configuration:
  511. * 0xff: unknown (does not affect DVB-T).
  512. * 0xf6: DRX-K (demodulator).
  513. * 0xe6: unknown (does not affect DVB-T).
  514. * 0xb6: unknown (does not affect DVB-T).
  515. */
  516. struct em28xx_reg_seq terratec_htc_stick_init[] = {
  517. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  518. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  519. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
  520. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  521. { -1, -1, -1, -1},
  522. };
  523. struct em28xx_reg_seq terratec_htc_stick_end[] = {
  524. {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
  525. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
  526. { -1, -1, -1, -1},
  527. };
  528. /*
  529. * Init the analog decoder (not yet supported), but
  530. * it's probably still a good idea.
  531. */
  532. struct {
  533. unsigned char r[4];
  534. int len;
  535. } regs[] = {
  536. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  537. {{ 0x01, 0x02 }, 2},
  538. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  539. {{ 0x01, 0x00 }, 2},
  540. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  541. };
  542. em28xx_gpio_set(dev, terratec_htc_stick_init);
  543. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  544. usleep_range(10000, 11000);
  545. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  546. usleep_range(10000, 11000);
  547. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  548. for (i = 0; i < ARRAY_SIZE(regs); i++)
  549. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
  550. regs[i].r, regs[i].len);
  551. em28xx_gpio_set(dev, terratec_htc_stick_end);
  552. };
  553. static void terratec_htc_usb_xs_init(struct em28xx *dev)
  554. {
  555. int i;
  556. struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
  557. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  558. {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
  559. {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
  560. {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
  561. { -1, -1, -1, -1},
  562. };
  563. struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
  564. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
  565. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
  566. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  567. { -1, -1, -1, -1},
  568. };
  569. /*
  570. * Init the analog decoder (not yet supported), but
  571. * it's probably still a good idea.
  572. */
  573. struct {
  574. unsigned char r[4];
  575. int len;
  576. } regs[] = {
  577. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  578. {{ 0x01, 0x02 }, 2},
  579. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  580. {{ 0x01, 0x00 }, 2},
  581. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  582. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  583. {{ 0x01, 0x00 }, 2},
  584. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  585. {{ 0x04, 0x00 }, 2},
  586. {{ 0x00, 0x04 }, 2},
  587. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  588. {{ 0x04, 0x14 }, 2},
  589. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  590. };
  591. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  592. em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
  593. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  594. usleep_range(10000, 11000);
  595. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  596. usleep_range(10000, 11000);
  597. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  598. for (i = 0; i < ARRAY_SIZE(regs); i++)
  599. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
  600. regs[i].r, regs[i].len);
  601. em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
  602. };
  603. static void pctv_520e_init(struct em28xx *dev)
  604. {
  605. /*
  606. * Init AVF4910B analog decoder. Looks like I2C traffic to
  607. * digital demodulator and tuner are routed via AVF4910B.
  608. */
  609. int i;
  610. struct {
  611. unsigned char r[4];
  612. int len;
  613. } regs[] = {
  614. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  615. {{ 0x01, 0x02 }, 2},
  616. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  617. {{ 0x01, 0x00 }, 2},
  618. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  619. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  620. {{ 0x01, 0x00 }, 2},
  621. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  622. };
  623. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
  624. for (i = 0; i < ARRAY_SIZE(regs); i++)
  625. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
  626. regs[i].r, regs[i].len);
  627. };
  628. static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
  629. {
  630. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  631. struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
  632. struct em28xx *dev = i2c_bus->dev;
  633. #ifdef CONFIG_GPIOLIB
  634. struct em28xx_dvb *dvb = dev->dvb;
  635. int ret;
  636. unsigned long flags;
  637. if (c->lna == 1)
  638. flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
  639. else
  640. flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
  641. ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
  642. if (ret)
  643. dev_err(&dev->intf->dev, "gpio request failed %d\n", ret);
  644. else
  645. gpio_free(dvb->lna_gpio);
  646. return ret;
  647. #else
  648. dev_warn(&dev->intf->dev, "%s: LNA control is disabled (lna=%u)\n",
  649. KBUILD_MODNAME, c->lna);
  650. return 0;
  651. #endif
  652. }
  653. static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
  654. {
  655. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  656. struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
  657. struct em28xx *dev = i2c_bus->dev;
  658. u8 lna;
  659. if (c->lna == 1)
  660. lna = 0x01;
  661. else
  662. lna = 0x00;
  663. return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01);
  664. }
  665. static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
  666. {
  667. /* Values extracted from a USB trace of the Terratec Windows driver */
  668. static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
  669. static u8 reset[] = { RESET, 0x80 };
  670. static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
  671. static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
  672. static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
  673. static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
  674. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  675. static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
  676. static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
  677. static u8 tuner_go[] = { TUNER_GO, 0x01};
  678. mt352_write(fe, clock_config, sizeof(clock_config));
  679. usleep_range(200, 250);
  680. mt352_write(fe, reset, sizeof(reset));
  681. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  682. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  683. mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
  684. mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
  685. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  686. mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
  687. mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
  688. mt352_write(fe, tuner_go, sizeof(tuner_go));
  689. return 0;
  690. }
  691. static void px_bcud_init(struct em28xx *dev)
  692. {
  693. int i;
  694. struct {
  695. unsigned char r[4];
  696. int len;
  697. } regs1[] = {
  698. {{ 0x0e, 0x77 }, 2},
  699. {{ 0x0f, 0x77 }, 2},
  700. {{ 0x03, 0x90 }, 2},
  701. }, regs2[] = {
  702. {{ 0x07, 0x01 }, 2},
  703. {{ 0x08, 0x10 }, 2},
  704. {{ 0x13, 0x00 }, 2},
  705. {{ 0x17, 0x00 }, 2},
  706. {{ 0x03, 0x01 }, 2},
  707. {{ 0x10, 0xb1 }, 2},
  708. {{ 0x11, 0x40 }, 2},
  709. {{ 0x85, 0x7a }, 2},
  710. {{ 0x87, 0x04 }, 2},
  711. };
  712. static struct em28xx_reg_seq gpio[] = {
  713. {EM28XX_R06_I2C_CLK, 0x40, 0xff, 300},
  714. {EM2874_R80_GPIO_P0_CTRL, 0xfd, 0xff, 60},
  715. {EM28XX_R15_RGAIN, 0x20, 0xff, 0},
  716. {EM28XX_R16_GGAIN, 0x20, 0xff, 0},
  717. {EM28XX_R17_BGAIN, 0x20, 0xff, 0},
  718. {EM28XX_R18_ROFFSET, 0x00, 0xff, 0},
  719. {EM28XX_R19_GOFFSET, 0x00, 0xff, 0},
  720. {EM28XX_R1A_BOFFSET, 0x00, 0xff, 0},
  721. {EM28XX_R23_UOFFSET, 0x00, 0xff, 0},
  722. {EM28XX_R24_VOFFSET, 0x00, 0xff, 0},
  723. {EM28XX_R26_COMPR, 0x00, 0xff, 0},
  724. {0x13, 0x08, 0xff, 0},
  725. {EM28XX_R12_VINENABLE, 0x27, 0xff, 0},
  726. {EM28XX_R0C_USBSUSP, 0x10, 0xff, 0},
  727. {EM28XX_R27_OUTFMT, 0x00, 0xff, 0},
  728. {EM28XX_R10_VINMODE, 0x00, 0xff, 0},
  729. {EM28XX_R11_VINCTRL, 0x11, 0xff, 0},
  730. {EM2874_R50_IR_CONFIG, 0x01, 0xff, 0},
  731. {EM2874_R5F_TS_ENABLE, 0x80, 0xff, 0},
  732. {EM28XX_R06_I2C_CLK, 0x46, 0xff, 0},
  733. };
  734. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x46);
  735. /* sleeping ISDB-T */
  736. dev->dvb->i2c_client_demod->addr = 0x14;
  737. for (i = 0; i < ARRAY_SIZE(regs1); i++)
  738. i2c_master_send(dev->dvb->i2c_client_demod,
  739. regs1[i].r, regs1[i].len);
  740. /* sleeping ISDB-S */
  741. dev->dvb->i2c_client_demod->addr = 0x15;
  742. for (i = 0; i < ARRAY_SIZE(regs2); i++)
  743. i2c_master_send(dev->dvb->i2c_client_demod, regs2[i].r,
  744. regs2[i].len);
  745. for (i = 0; i < ARRAY_SIZE(gpio); i++) {
  746. em28xx_write_reg_bits(dev, gpio[i].reg, gpio[i].val,
  747. gpio[i].mask);
  748. if (gpio[i].sleep > 0)
  749. msleep(gpio[i].sleep);
  750. }
  751. };
  752. static struct mt352_config terratec_xs_mt352_cfg = {
  753. .demod_address = (0x1e >> 1),
  754. .no_tuner = 1,
  755. .if2 = 45600,
  756. .demod_init = em28xx_mt352_terratec_xs_init,
  757. };
  758. static struct tda10023_config em28xx_tda10023_config = {
  759. .demod_address = 0x0c,
  760. .invert = 1,
  761. };
  762. static struct cxd2820r_config em28xx_cxd2820r_config = {
  763. .i2c_address = (0xd8 >> 1),
  764. .ts_mode = CXD2820R_TS_SERIAL,
  765. };
  766. static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
  767. .output_opt = TDA18271_OUTPUT_LT_OFF,
  768. .gate = TDA18271_GATE_DIGITAL,
  769. };
  770. static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
  771. .demod_address = (0x1e >> 1),
  772. .disable_i2c_gate_ctrl = 1,
  773. .no_tuner = 1,
  774. .parallel_ts = 1,
  775. };
  776. static struct mt2060_config em28xx_mt2060_config = {
  777. .i2c_address = 0x60,
  778. };
  779. static struct qt1010_config em28xx_qt1010_config = {
  780. .i2c_address = 0x62
  781. };
  782. static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
  783. .demod_address = 0x10,
  784. .is_serial = true,
  785. };
  786. static struct tda18271_std_map mb86a20s_tda18271_config = {
  787. .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
  788. .if_lvl = 1, .rfagc_top = 0x37, },
  789. };
  790. static struct tda18271_config c3tech_duo_tda18271_config = {
  791. .std_map = &mb86a20s_tda18271_config,
  792. .gate = TDA18271_GATE_DIGITAL,
  793. .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
  794. };
  795. static struct tda18271_std_map drx_j_std_map = {
  796. .atsc_6 = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
  797. .rfagc_top = 0x37, },
  798. .qam_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
  799. .rfagc_top = 0x37, },
  800. };
  801. static struct tda18271_config pinnacle_80e_dvb_config = {
  802. .std_map = &drx_j_std_map,
  803. .gate = TDA18271_GATE_DIGITAL,
  804. .role = TDA18271_MASTER,
  805. };
  806. static struct lgdt3306a_config hauppauge_01595_lgdt3306a_config = {
  807. .qam_if_khz = 4000,
  808. .vsb_if_khz = 3250,
  809. .spectral_inversion = 0,
  810. .deny_i2c_rptr = 0,
  811. .mpeg_mode = LGDT3306A_MPEG_SERIAL,
  812. .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
  813. .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
  814. .xtalMHz = 25,
  815. };
  816. /* ------------------------------------------------------------------ */
  817. static noinline_for_stack int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
  818. {
  819. struct dvb_frontend *fe;
  820. struct xc2028_config cfg;
  821. struct xc2028_ctrl ctl;
  822. memset(&cfg, 0, sizeof(cfg));
  823. cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
  824. cfg.i2c_addr = addr;
  825. memset(&ctl, 0, sizeof(ctl));
  826. em28xx_setup_xc3028(dev, &ctl);
  827. cfg.ctrl = &ctl;
  828. if (!dev->dvb->fe[0]) {
  829. dev_err(&dev->intf->dev,
  830. "dvb frontend not attached. Can't attach xc3028\n");
  831. return -EINVAL;
  832. }
  833. fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
  834. if (!fe) {
  835. dev_err(&dev->intf->dev, "xc3028 attach failed\n");
  836. dvb_frontend_detach(dev->dvb->fe[0]);
  837. dev->dvb->fe[0] = NULL;
  838. return -EINVAL;
  839. }
  840. dev_info(&dev->intf->dev, "xc3028 attached\n");
  841. return 0;
  842. }
  843. /* ------------------------------------------------------------------ */
  844. static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
  845. struct em28xx *dev, struct device *device)
  846. {
  847. int result;
  848. bool create_rf_connector = false;
  849. mutex_init(&dvb->lock);
  850. /* register adapter */
  851. result = dvb_register_adapter(&dvb->adapter,
  852. dev_name(&dev->intf->dev), module,
  853. device, adapter_nr);
  854. if (result < 0) {
  855. dev_warn(&dev->intf->dev,
  856. "dvb_register_adapter failed (errno = %d)\n",
  857. result);
  858. goto fail_adapter;
  859. }
  860. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  861. dvb->adapter.mdev = dev->media_dev;
  862. #endif
  863. /* Ensure all frontends negotiate bus access */
  864. dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  865. if (dvb->fe[1])
  866. dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  867. dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
  868. /* register frontend */
  869. result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
  870. if (result < 0) {
  871. dev_warn(&dev->intf->dev,
  872. "dvb_register_frontend failed (errno = %d)\n",
  873. result);
  874. goto fail_frontend0;
  875. }
  876. /* register 2nd frontend */
  877. if (dvb->fe[1]) {
  878. result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
  879. if (result < 0) {
  880. dev_warn(&dev->intf->dev,
  881. "2nd dvb_register_frontend failed (errno = %d)\n",
  882. result);
  883. goto fail_frontend1;
  884. }
  885. }
  886. /* register demux stuff */
  887. dvb->demux.dmx.capabilities =
  888. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  889. DMX_MEMORY_BASED_FILTERING;
  890. dvb->demux.priv = dvb;
  891. dvb->demux.filternum = 256;
  892. dvb->demux.feednum = 256;
  893. dvb->demux.start_feed = em28xx_start_feed;
  894. dvb->demux.stop_feed = em28xx_stop_feed;
  895. result = dvb_dmx_init(&dvb->demux);
  896. if (result < 0) {
  897. dev_warn(&dev->intf->dev,
  898. "dvb_dmx_init failed (errno = %d)\n",
  899. result);
  900. goto fail_dmx;
  901. }
  902. dvb->dmxdev.filternum = 256;
  903. dvb->dmxdev.demux = &dvb->demux.dmx;
  904. dvb->dmxdev.capabilities = 0;
  905. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  906. if (result < 0) {
  907. dev_warn(&dev->intf->dev,
  908. "dvb_dmxdev_init failed (errno = %d)\n",
  909. result);
  910. goto fail_dmxdev;
  911. }
  912. dvb->fe_hw.source = DMX_FRONTEND_0;
  913. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  914. if (result < 0) {
  915. dev_warn(&dev->intf->dev,
  916. "add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  917. result);
  918. goto fail_fe_hw;
  919. }
  920. dvb->fe_mem.source = DMX_MEMORY_FE;
  921. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  922. if (result < 0) {
  923. dev_warn(&dev->intf->dev,
  924. "add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  925. result);
  926. goto fail_fe_mem;
  927. }
  928. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  929. if (result < 0) {
  930. dev_warn(&dev->intf->dev,
  931. "connect_frontend failed (errno = %d)\n",
  932. result);
  933. goto fail_fe_conn;
  934. }
  935. /* register network adapter */
  936. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  937. /* If the analog part won't create RF connectors, DVB will do it */
  938. if (!dev->has_video || dev->tuner_type == TUNER_ABSENT)
  939. create_rf_connector = true;
  940. result = dvb_create_media_graph(&dvb->adapter, create_rf_connector);
  941. if (result < 0)
  942. goto fail_create_graph;
  943. return 0;
  944. fail_create_graph:
  945. dvb_net_release(&dvb->net);
  946. fail_fe_conn:
  947. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  948. fail_fe_mem:
  949. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  950. fail_fe_hw:
  951. dvb_dmxdev_release(&dvb->dmxdev);
  952. fail_dmxdev:
  953. dvb_dmx_release(&dvb->demux);
  954. fail_dmx:
  955. if (dvb->fe[1])
  956. dvb_unregister_frontend(dvb->fe[1]);
  957. dvb_unregister_frontend(dvb->fe[0]);
  958. fail_frontend1:
  959. if (dvb->fe[1])
  960. dvb_frontend_detach(dvb->fe[1]);
  961. fail_frontend0:
  962. dvb_frontend_detach(dvb->fe[0]);
  963. dvb_unregister_adapter(&dvb->adapter);
  964. fail_adapter:
  965. return result;
  966. }
  967. static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
  968. {
  969. dvb_net_release(&dvb->net);
  970. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  971. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  972. dvb_dmxdev_release(&dvb->dmxdev);
  973. dvb_dmx_release(&dvb->demux);
  974. if (dvb->fe[1])
  975. dvb_unregister_frontend(dvb->fe[1]);
  976. dvb_unregister_frontend(dvb->fe[0]);
  977. if (dvb->fe[1] && !dvb->dont_attach_fe1)
  978. dvb_frontend_detach(dvb->fe[1]);
  979. dvb_frontend_detach(dvb->fe[0]);
  980. dvb_unregister_adapter(&dvb->adapter);
  981. }
  982. static int em28174_dvb_init_pctv_460e(struct em28xx *dev)
  983. {
  984. struct em28xx_dvb *dvb = dev->dvb;
  985. struct tda10071_platform_data tda10071_pdata = {};
  986. struct a8293_platform_data a8293_pdata = {};
  987. /* attach demod + tuner combo */
  988. tda10071_pdata.clk = 40444000; /* 40.444 MHz */
  989. tda10071_pdata.i2c_wr_max = 64;
  990. tda10071_pdata.ts_mode = TDA10071_TS_SERIAL;
  991. tda10071_pdata.pll_multiplier = 20;
  992. tda10071_pdata.tuner_i2c_addr = 0x14;
  993. dvb->i2c_client_demod = dvb_module_probe("tda10071", "tda10071_cx24118",
  994. &dev->i2c_adap[dev->def_i2c_bus],
  995. 0x55, &tda10071_pdata);
  996. if (!dvb->i2c_client_demod)
  997. return -ENODEV;
  998. dvb->fe[0] = tda10071_pdata.get_dvb_frontend(dvb->i2c_client_demod);
  999. /* attach SEC */
  1000. a8293_pdata.dvb_frontend = dvb->fe[0];
  1001. dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
  1002. &dev->i2c_adap[dev->def_i2c_bus],
  1003. 0x08, &a8293_pdata);
  1004. if (!dvb->i2c_client_sec) {
  1005. dvb_module_release(dvb->i2c_client_demod);
  1006. return -ENODEV;
  1007. }
  1008. return 0;
  1009. }
  1010. static int em28178_dvb_init_pctv_461e(struct em28xx *dev)
  1011. {
  1012. struct em28xx_dvb *dvb = dev->dvb;
  1013. struct i2c_adapter *i2c_adapter;
  1014. struct m88ds3103_platform_data m88ds3103_pdata = {};
  1015. struct ts2020_config ts2020_config = {};
  1016. struct a8293_platform_data a8293_pdata = {};
  1017. /* attach demod */
  1018. m88ds3103_pdata.clk = 27000000;
  1019. m88ds3103_pdata.i2c_wr_max = 33;
  1020. m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
  1021. m88ds3103_pdata.ts_clk = 16000;
  1022. m88ds3103_pdata.ts_clk_pol = 1;
  1023. m88ds3103_pdata.agc = 0x99;
  1024. dvb->i2c_client_demod = dvb_module_probe("m88ds3103", NULL,
  1025. &dev->i2c_adap[dev->def_i2c_bus],
  1026. 0x68, &m88ds3103_pdata);
  1027. if (!dvb->i2c_client_demod)
  1028. return -ENODEV;
  1029. dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(dvb->i2c_client_demod);
  1030. i2c_adapter = m88ds3103_pdata.get_i2c_adapter(dvb->i2c_client_demod);
  1031. /* attach tuner */
  1032. ts2020_config.fe = dvb->fe[0];
  1033. dvb->i2c_client_tuner = dvb_module_probe("ts2020", "ts2022",
  1034. i2c_adapter,
  1035. 0x60, &ts2020_config);
  1036. if (!dvb->i2c_client_tuner) {
  1037. dvb_module_release(dvb->i2c_client_demod);
  1038. return -ENODEV;
  1039. }
  1040. /* delegate signal strength measurement to tuner */
  1041. dvb->fe[0]->ops.read_signal_strength =
  1042. dvb->fe[0]->ops.tuner_ops.get_rf_strength;
  1043. /* attach SEC */
  1044. a8293_pdata.dvb_frontend = dvb->fe[0];
  1045. dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
  1046. &dev->i2c_adap[dev->def_i2c_bus],
  1047. 0x08, &a8293_pdata);
  1048. if (!dvb->i2c_client_sec) {
  1049. dvb_module_release(dvb->i2c_client_tuner);
  1050. dvb_module_release(dvb->i2c_client_demod);
  1051. return -ENODEV;
  1052. }
  1053. return 0;
  1054. }
  1055. static int em28178_dvb_init_pctv_292e(struct em28xx *dev)
  1056. {
  1057. struct em28xx_dvb *dvb = dev->dvb;
  1058. struct i2c_adapter *adapter;
  1059. struct si2168_config si2168_config = {};
  1060. struct si2157_config si2157_config = {};
  1061. /* attach demod */
  1062. si2168_config.i2c_adapter = &adapter;
  1063. si2168_config.fe = &dvb->fe[0];
  1064. si2168_config.ts_mode = SI2168_TS_PARALLEL;
  1065. si2168_config.spectral_inversion = true;
  1066. dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
  1067. &dev->i2c_adap[dev->def_i2c_bus],
  1068. 0x64, &si2168_config);
  1069. if (!dvb->i2c_client_demod)
  1070. return -ENODEV;
  1071. /* attach tuner */
  1072. si2157_config.fe = dvb->fe[0];
  1073. si2157_config.if_port = 1;
  1074. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  1075. si2157_config.mdev = dev->media_dev;
  1076. #endif
  1077. dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
  1078. adapter,
  1079. 0x60, &si2157_config);
  1080. if (!dvb->i2c_client_tuner) {
  1081. dvb_module_release(dvb->i2c_client_demod);
  1082. return -ENODEV;
  1083. }
  1084. dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
  1085. return 0;
  1086. }
  1087. static int em28178_dvb_init_terratec_t2_stick_hd(struct em28xx *dev)
  1088. {
  1089. struct em28xx_dvb *dvb = dev->dvb;
  1090. struct i2c_adapter *adapter;
  1091. struct si2168_config si2168_config = {};
  1092. struct si2157_config si2157_config = {};
  1093. /* attach demod */
  1094. si2168_config.i2c_adapter = &adapter;
  1095. si2168_config.fe = &dvb->fe[0];
  1096. si2168_config.ts_mode = SI2168_TS_PARALLEL;
  1097. dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
  1098. &dev->i2c_adap[dev->def_i2c_bus],
  1099. 0x64, &si2168_config);
  1100. if (!dvb->i2c_client_demod)
  1101. return -ENODEV;
  1102. /* attach tuner */
  1103. memset(&si2157_config, 0, sizeof(si2157_config));
  1104. si2157_config.fe = dvb->fe[0];
  1105. si2157_config.if_port = 0;
  1106. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  1107. si2157_config.mdev = dev->media_dev;
  1108. #endif
  1109. dvb->i2c_client_tuner = dvb_module_probe("si2157", "si2146",
  1110. adapter,
  1111. 0x60, &si2157_config);
  1112. if (!dvb->i2c_client_tuner) {
  1113. dvb_module_release(dvb->i2c_client_demod);
  1114. return -ENODEV;
  1115. }
  1116. return 0;
  1117. }
  1118. static int em28178_dvb_init_plex_px_bcud(struct em28xx *dev)
  1119. {
  1120. struct em28xx_dvb *dvb = dev->dvb;
  1121. struct tc90522_config tc90522_config = {};
  1122. struct qm1d1c0042_config qm1d1c0042_config = {};
  1123. /* attach demod */
  1124. dvb->i2c_client_demod = dvb_module_probe("tc90522", "tc90522sat",
  1125. &dev->i2c_adap[dev->def_i2c_bus],
  1126. 0x15, &tc90522_config);
  1127. if (!dvb->i2c_client_demod)
  1128. return -ENODEV;
  1129. /* attach tuner */
  1130. qm1d1c0042_config.fe = tc90522_config.fe;
  1131. qm1d1c0042_config.lpf = 1;
  1132. dvb->i2c_client_tuner = dvb_module_probe("qm1d1c0042", NULL,
  1133. tc90522_config.tuner_i2c,
  1134. 0x61, &qm1d1c0042_config);
  1135. if (!dvb->i2c_client_tuner) {
  1136. dvb_module_release(dvb->i2c_client_demod);
  1137. return -ENODEV;
  1138. }
  1139. dvb->fe[0] = tc90522_config.fe;
  1140. px_bcud_init(dev);
  1141. return 0;
  1142. }
  1143. static int em28174_dvb_init_hauppauge_wintv_dualhd_dvb(struct em28xx *dev)
  1144. {
  1145. struct em28xx_dvb *dvb = dev->dvb;
  1146. struct i2c_adapter *adapter;
  1147. struct si2168_config si2168_config = {};
  1148. struct si2157_config si2157_config = {};
  1149. unsigned char addr;
  1150. /* attach demod */
  1151. si2168_config.i2c_adapter = &adapter;
  1152. si2168_config.fe = &dvb->fe[0];
  1153. si2168_config.ts_mode = SI2168_TS_SERIAL;
  1154. si2168_config.spectral_inversion = true;
  1155. addr = (dev->ts == PRIMARY_TS) ? 0x64 : 0x67;
  1156. dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
  1157. &dev->i2c_adap[dev->def_i2c_bus],
  1158. addr, &si2168_config);
  1159. if (!dvb->i2c_client_demod)
  1160. return -ENODEV;
  1161. /* attach tuner */
  1162. memset(&si2157_config, 0, sizeof(si2157_config));
  1163. si2157_config.fe = dvb->fe[0];
  1164. si2157_config.if_port = 1;
  1165. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  1166. si2157_config.mdev = dev->media_dev;
  1167. #endif
  1168. addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x63;
  1169. dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
  1170. adapter,
  1171. addr, &si2157_config);
  1172. if (!dvb->i2c_client_tuner) {
  1173. dvb_module_release(dvb->i2c_client_demod);
  1174. return -ENODEV;
  1175. }
  1176. return 0;
  1177. }
  1178. static int em28174_dvb_init_hauppauge_wintv_dualhd_01595(struct em28xx *dev)
  1179. {
  1180. struct em28xx_dvb *dvb = dev->dvb;
  1181. struct i2c_adapter *adapter;
  1182. struct lgdt3306a_config lgdt3306a_config = {};
  1183. struct si2157_config si2157_config = {};
  1184. unsigned char addr;
  1185. /* attach demod */
  1186. lgdt3306a_config = hauppauge_01595_lgdt3306a_config;
  1187. lgdt3306a_config.fe = &dvb->fe[0];
  1188. lgdt3306a_config.i2c_adapter = &adapter;
  1189. addr = (dev->ts == PRIMARY_TS) ? 0x59 : 0x0e;
  1190. dvb->i2c_client_demod = dvb_module_probe("lgdt3306a", NULL,
  1191. &dev->i2c_adap[dev->def_i2c_bus],
  1192. addr, &lgdt3306a_config);
  1193. if (!dvb->i2c_client_demod)
  1194. return -ENODEV;
  1195. /* attach tuner */
  1196. si2157_config.fe = dvb->fe[0];
  1197. si2157_config.if_port = 1;
  1198. si2157_config.inversion = 1;
  1199. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  1200. si2157_config.mdev = dev->media_dev;
  1201. #endif
  1202. addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x62;
  1203. dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
  1204. adapter,
  1205. addr, &si2157_config);
  1206. if (!dvb->i2c_client_tuner) {
  1207. dvb_module_release(dvb->i2c_client_demod);
  1208. return -ENODEV;
  1209. }
  1210. return 0;
  1211. }
  1212. static int em28xx_dvb_init(struct em28xx *dev)
  1213. {
  1214. int result = 0, dvb_alt = 0;
  1215. struct em28xx_dvb *dvb;
  1216. struct usb_device *udev;
  1217. if (dev->is_audio_only) {
  1218. /* Shouldn't initialize IR for this interface */
  1219. return 0;
  1220. }
  1221. if (!dev->board.has_dvb) {
  1222. /* This device does not support the extension */
  1223. return 0;
  1224. }
  1225. dev_info(&dev->intf->dev, "Binding DVB extension\n");
  1226. dvb = kzalloc(sizeof(*dvb), GFP_KERNEL);
  1227. if (!dvb)
  1228. return -ENOMEM;
  1229. dev->dvb = dvb;
  1230. dvb->fe[0] = NULL;
  1231. dvb->fe[1] = NULL;
  1232. /* pre-allocate DVB usb transfer buffers */
  1233. if (dev->dvb_xfer_bulk) {
  1234. result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
  1235. dev->dvb_xfer_bulk,
  1236. EM28XX_DVB_NUM_BUFS,
  1237. 512,
  1238. EM28XX_DVB_BULK_PACKET_MULTIPLIER);
  1239. } else {
  1240. result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
  1241. dev->dvb_xfer_bulk,
  1242. EM28XX_DVB_NUM_BUFS,
  1243. dev->dvb_max_pkt_size_isoc,
  1244. EM28XX_DVB_NUM_ISOC_PACKETS);
  1245. }
  1246. if (result) {
  1247. dev_err(&dev->intf->dev,
  1248. "failed to pre-allocate USB transfer buffers for DVB.\n");
  1249. kfree(dvb);
  1250. dev->dvb = NULL;
  1251. return result;
  1252. }
  1253. mutex_lock(&dev->lock);
  1254. em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  1255. /* init frontend */
  1256. switch (dev->model) {
  1257. case EM2874_BOARD_LEADERSHIP_ISDBT:
  1258. dvb->fe[0] = dvb_attach(s921_attach,
  1259. &sharp_isdbt,
  1260. &dev->i2c_adap[dev->def_i2c_bus]);
  1261. if (!dvb->fe[0]) {
  1262. result = -EINVAL;
  1263. goto out_free;
  1264. }
  1265. break;
  1266. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
  1267. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
  1268. case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
  1269. case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
  1270. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  1271. &em2880_lgdt3303_dev,
  1272. 0x0e,
  1273. &dev->i2c_adap[dev->def_i2c_bus]);
  1274. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  1275. result = -EINVAL;
  1276. goto out_free;
  1277. }
  1278. break;
  1279. case EM2880_BOARD_KWORLD_DVB_310U:
  1280. dvb->fe[0] = dvb_attach(zl10353_attach,
  1281. &em28xx_zl10353_with_xc3028,
  1282. &dev->i2c_adap[dev->def_i2c_bus]);
  1283. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  1284. result = -EINVAL;
  1285. goto out_free;
  1286. }
  1287. break;
  1288. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  1289. case EM2882_BOARD_TERRATEC_HYBRID_XS:
  1290. case EM2880_BOARD_EMPIRE_DUAL_TV:
  1291. case EM2882_BOARD_ZOLID_HYBRID_TV_STICK:
  1292. dvb->fe[0] = dvb_attach(zl10353_attach,
  1293. &em28xx_zl10353_xc3028_no_i2c_gate,
  1294. &dev->i2c_adap[dev->def_i2c_bus]);
  1295. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  1296. result = -EINVAL;
  1297. goto out_free;
  1298. }
  1299. break;
  1300. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  1301. case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
  1302. case EM2881_BOARD_PINNACLE_HYBRID_PRO:
  1303. case EM2882_BOARD_DIKOM_DK300:
  1304. case EM2882_BOARD_KWORLD_VS_DVBT:
  1305. /*
  1306. * Those boards could have either a zl10353 or a mt352.
  1307. * If the chip id isn't for zl10353, try mt352.
  1308. */
  1309. dvb->fe[0] = dvb_attach(zl10353_attach,
  1310. &em28xx_zl10353_xc3028_no_i2c_gate,
  1311. &dev->i2c_adap[dev->def_i2c_bus]);
  1312. if (!dvb->fe[0])
  1313. dvb->fe[0] = dvb_attach(mt352_attach,
  1314. &terratec_xs_mt352_cfg,
  1315. &dev->i2c_adap[dev->def_i2c_bus]);
  1316. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  1317. result = -EINVAL;
  1318. goto out_free;
  1319. }
  1320. break;
  1321. case EM2870_BOARD_TERRATEC_XS_MT2060:
  1322. dvb->fe[0] = dvb_attach(zl10353_attach,
  1323. &em28xx_zl10353_no_i2c_gate_dev,
  1324. &dev->i2c_adap[dev->def_i2c_bus]);
  1325. if (dvb->fe[0]) {
  1326. dvb_attach(mt2060_attach, dvb->fe[0],
  1327. &dev->i2c_adap[dev->def_i2c_bus],
  1328. &em28xx_mt2060_config, 1220);
  1329. }
  1330. break;
  1331. case EM2870_BOARD_KWORLD_355U:
  1332. dvb->fe[0] = dvb_attach(zl10353_attach,
  1333. &em28xx_zl10353_no_i2c_gate_dev,
  1334. &dev->i2c_adap[dev->def_i2c_bus]);
  1335. if (dvb->fe[0])
  1336. dvb_attach(qt1010_attach, dvb->fe[0],
  1337. &dev->i2c_adap[dev->def_i2c_bus],
  1338. &em28xx_qt1010_config);
  1339. break;
  1340. case EM2883_BOARD_KWORLD_HYBRID_330U:
  1341. case EM2882_BOARD_EVGA_INDTUBE:
  1342. dvb->fe[0] = dvb_attach(s5h1409_attach,
  1343. &em28xx_s5h1409_with_xc3028,
  1344. &dev->i2c_adap[dev->def_i2c_bus]);
  1345. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  1346. result = -EINVAL;
  1347. goto out_free;
  1348. }
  1349. break;
  1350. case EM2882_BOARD_KWORLD_ATSC_315U:
  1351. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  1352. &em2880_lgdt3303_dev,
  1353. 0x0e,
  1354. &dev->i2c_adap[dev->def_i2c_bus]);
  1355. if (dvb->fe[0]) {
  1356. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  1357. &dev->i2c_adap[dev->def_i2c_bus],
  1358. 0x61, TUNER_THOMSON_DTT761X)) {
  1359. result = -EINVAL;
  1360. goto out_free;
  1361. }
  1362. }
  1363. break;
  1364. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
  1365. case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
  1366. dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
  1367. &dev->i2c_adap[dev->def_i2c_bus],
  1368. &dev->intf->dev);
  1369. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  1370. result = -EINVAL;
  1371. goto out_free;
  1372. }
  1373. break;
  1374. case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
  1375. /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
  1376. dvb->fe[0] = dvb_attach(tda10023_attach,
  1377. &em28xx_tda10023_config,
  1378. &dev->i2c_adap[dev->def_i2c_bus],
  1379. 0x48);
  1380. if (dvb->fe[0]) {
  1381. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  1382. &dev->i2c_adap[dev->def_i2c_bus],
  1383. 0x60, TUNER_PHILIPS_CU1216L)) {
  1384. result = -EINVAL;
  1385. goto out_free;
  1386. }
  1387. }
  1388. break;
  1389. case EM2870_BOARD_KWORLD_A340:
  1390. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  1391. &em2870_lgdt3304_dev,
  1392. &dev->i2c_adap[dev->def_i2c_bus]);
  1393. if (!dvb->fe[0]) {
  1394. result = -EINVAL;
  1395. goto out_free;
  1396. }
  1397. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1398. &dev->i2c_adap[dev->def_i2c_bus],
  1399. &kworld_a340_config)) {
  1400. dvb_frontend_detach(dvb->fe[0]);
  1401. result = -EINVAL;
  1402. goto out_free;
  1403. }
  1404. break;
  1405. case EM28174_BOARD_PCTV_290E:
  1406. /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
  1407. dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
  1408. CXD2820R_GPIO_L;
  1409. dvb->fe[0] = dvb_attach(cxd2820r_attach,
  1410. &em28xx_cxd2820r_config,
  1411. &dev->i2c_adap[dev->def_i2c_bus],
  1412. &dvb->lna_gpio);
  1413. if (dvb->fe[0]) {
  1414. /* FE 0 attach tuner */
  1415. if (!dvb_attach(tda18271_attach,
  1416. dvb->fe[0],
  1417. 0x60,
  1418. &dev->i2c_adap[dev->def_i2c_bus],
  1419. &em28xx_cxd2820r_tda18271_config)) {
  1420. dvb_frontend_detach(dvb->fe[0]);
  1421. result = -EINVAL;
  1422. goto out_free;
  1423. }
  1424. #ifdef CONFIG_GPIOLIB
  1425. /* enable LNA for DVB-T, DVB-T2 and DVB-C */
  1426. result = gpio_request_one(dvb->lna_gpio,
  1427. GPIOF_OUT_INIT_LOW, NULL);
  1428. if (result)
  1429. dev_err(&dev->intf->dev,
  1430. "gpio request failed %d\n",
  1431. result);
  1432. else
  1433. gpio_free(dvb->lna_gpio);
  1434. result = 0; /* continue even set LNA fails */
  1435. #endif
  1436. dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
  1437. }
  1438. break;
  1439. case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
  1440. {
  1441. struct xc5000_config cfg = {};
  1442. hauppauge_hvr930c_init(dev);
  1443. dvb->fe[0] = dvb_attach(drxk_attach,
  1444. &hauppauge_930c_drxk,
  1445. &dev->i2c_adap[dev->def_i2c_bus]);
  1446. if (!dvb->fe[0]) {
  1447. result = -EINVAL;
  1448. goto out_free;
  1449. }
  1450. /* FIXME: do we need a pll semaphore? */
  1451. dvb->fe[0]->sec_priv = dvb;
  1452. sema_init(&dvb->pll_mutex, 1);
  1453. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  1454. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  1455. /* Attach xc5000 */
  1456. cfg.i2c_address = 0x61;
  1457. cfg.if_khz = 4000;
  1458. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1459. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  1460. if (!dvb_attach(xc5000_attach, dvb->fe[0],
  1461. &dev->i2c_adap[dev->def_i2c_bus], &cfg)) {
  1462. result = -EINVAL;
  1463. goto out_free;
  1464. }
  1465. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1466. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  1467. break;
  1468. }
  1469. case EM2884_BOARD_TERRATEC_H5:
  1470. terratec_h5_init(dev);
  1471. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk,
  1472. &dev->i2c_adap[dev->def_i2c_bus]);
  1473. if (!dvb->fe[0]) {
  1474. result = -EINVAL;
  1475. goto out_free;
  1476. }
  1477. /* FIXME: do we need a pll semaphore? */
  1478. dvb->fe[0]->sec_priv = dvb;
  1479. sema_init(&dvb->pll_mutex, 1);
  1480. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  1481. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  1482. /* Attach tda18271 to DVB-C frontend */
  1483. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1484. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  1485. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
  1486. &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
  1487. result = -EINVAL;
  1488. goto out_free;
  1489. }
  1490. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1491. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  1492. break;
  1493. case EM2884_BOARD_C3TECH_DIGITAL_DUO:
  1494. dvb->fe[0] = dvb_attach(mb86a20s_attach,
  1495. &c3tech_duo_mb86a20s_config,
  1496. &dev->i2c_adap[dev->def_i2c_bus]);
  1497. if (dvb->fe[0])
  1498. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1499. &dev->i2c_adap[dev->def_i2c_bus],
  1500. &c3tech_duo_tda18271_config);
  1501. break;
  1502. case EM28174_BOARD_PCTV_460E:
  1503. result = em28174_dvb_init_pctv_460e(dev);
  1504. if (result)
  1505. goto out_free;
  1506. break;
  1507. case EM2874_BOARD_DELOCK_61959:
  1508. case EM2874_BOARD_MAXMEDIA_UB425_TC:
  1509. /* attach demodulator */
  1510. dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
  1511. &dev->i2c_adap[dev->def_i2c_bus]);
  1512. if (dvb->fe[0]) {
  1513. /* disable I2C-gate */
  1514. dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
  1515. /* attach tuner */
  1516. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1517. &dev->i2c_adap[dev->def_i2c_bus],
  1518. &em28xx_cxd2820r_tda18271_config)) {
  1519. dvb_frontend_detach(dvb->fe[0]);
  1520. result = -EINVAL;
  1521. goto out_free;
  1522. }
  1523. }
  1524. break;
  1525. case EM2884_BOARD_PCTV_510E:
  1526. case EM2884_BOARD_PCTV_520E:
  1527. pctv_520e_init(dev);
  1528. /* attach demodulator */
  1529. dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
  1530. &dev->i2c_adap[dev->def_i2c_bus]);
  1531. if (dvb->fe[0]) {
  1532. /* attach tuner */
  1533. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1534. &dev->i2c_adap[dev->def_i2c_bus],
  1535. &em28xx_cxd2820r_tda18271_config)) {
  1536. dvb_frontend_detach(dvb->fe[0]);
  1537. result = -EINVAL;
  1538. goto out_free;
  1539. }
  1540. }
  1541. break;
  1542. case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008:
  1543. case EM2884_BOARD_CINERGY_HTC_STICK:
  1544. case EM2884_BOARD_TERRATEC_H6:
  1545. terratec_htc_stick_init(dev);
  1546. /* attach demodulator */
  1547. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1548. &dev->i2c_adap[dev->def_i2c_bus]);
  1549. if (!dvb->fe[0]) {
  1550. result = -EINVAL;
  1551. goto out_free;
  1552. }
  1553. /* Attach the demodulator. */
  1554. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1555. &dev->i2c_adap[dev->def_i2c_bus],
  1556. &em28xx_cxd2820r_tda18271_config)) {
  1557. result = -EINVAL;
  1558. goto out_free;
  1559. }
  1560. break;
  1561. case EM2884_BOARD_TERRATEC_HTC_USB_XS:
  1562. terratec_htc_usb_xs_init(dev);
  1563. /* attach demodulator */
  1564. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1565. &dev->i2c_adap[dev->def_i2c_bus]);
  1566. if (!dvb->fe[0]) {
  1567. result = -EINVAL;
  1568. goto out_free;
  1569. }
  1570. /* Attach the demodulator. */
  1571. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1572. &dev->i2c_adap[dev->def_i2c_bus],
  1573. &em28xx_cxd2820r_tda18271_config)) {
  1574. result = -EINVAL;
  1575. goto out_free;
  1576. }
  1577. break;
  1578. case EM2874_BOARD_KWORLD_UB435Q_V2:
  1579. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  1580. &em2874_lgdt3305_dev,
  1581. &dev->i2c_adap[dev->def_i2c_bus]);
  1582. if (!dvb->fe[0]) {
  1583. result = -EINVAL;
  1584. goto out_free;
  1585. }
  1586. /* Attach the demodulator. */
  1587. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1588. &dev->i2c_adap[dev->def_i2c_bus],
  1589. &kworld_ub435q_v2_config)) {
  1590. result = -EINVAL;
  1591. goto out_free;
  1592. }
  1593. break;
  1594. case EM2874_BOARD_KWORLD_UB435Q_V3:
  1595. {
  1596. struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus];
  1597. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  1598. &em2874_lgdt3305_nogate_dev,
  1599. &dev->i2c_adap[dev->def_i2c_bus]);
  1600. if (!dvb->fe[0]) {
  1601. result = -EINVAL;
  1602. goto out_free;
  1603. }
  1604. /* attach tuner */
  1605. kworld_ub435q_v3_config.fe = dvb->fe[0];
  1606. dvb->i2c_client_tuner = dvb_module_probe("tda18212", NULL,
  1607. adapter, 0x60,
  1608. &kworld_ub435q_v3_config);
  1609. if (!dvb->i2c_client_tuner) {
  1610. dvb_frontend_detach(dvb->fe[0]);
  1611. result = -ENODEV;
  1612. goto out_free;
  1613. }
  1614. break;
  1615. }
  1616. case EM2874_BOARD_PCTV_HD_MINI_80E:
  1617. dvb->fe[0] = dvb_attach(drx39xxj_attach,
  1618. &dev->i2c_adap[dev->def_i2c_bus]);
  1619. if (dvb->fe[0]) {
  1620. dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0],
  1621. 0x60,
  1622. &dev->i2c_adap[dev->def_i2c_bus],
  1623. &pinnacle_80e_dvb_config);
  1624. if (!dvb->fe[0]) {
  1625. result = -EINVAL;
  1626. goto out_free;
  1627. }
  1628. }
  1629. break;
  1630. case EM28178_BOARD_PCTV_461E:
  1631. result = em28178_dvb_init_pctv_461e(dev);
  1632. if (result)
  1633. goto out_free;
  1634. break;
  1635. case EM28178_BOARD_PCTV_292E:
  1636. result = em28178_dvb_init_pctv_292e(dev);
  1637. if (result)
  1638. goto out_free;
  1639. break;
  1640. case EM28178_BOARD_TERRATEC_T2_STICK_HD:
  1641. result = em28178_dvb_init_terratec_t2_stick_hd(dev);
  1642. if (result)
  1643. goto out_free;
  1644. break;
  1645. case EM28178_BOARD_PLEX_PX_BCUD:
  1646. result = em28178_dvb_init_plex_px_bcud(dev);
  1647. if (result)
  1648. goto out_free;
  1649. break;
  1650. case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB:
  1651. result = em28174_dvb_init_hauppauge_wintv_dualhd_dvb(dev);
  1652. if (result)
  1653. goto out_free;
  1654. break;
  1655. case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595:
  1656. result = em28174_dvb_init_hauppauge_wintv_dualhd_01595(dev);
  1657. if (result)
  1658. goto out_free;
  1659. break;
  1660. default:
  1661. dev_err(&dev->intf->dev,
  1662. "The frontend of your DVB/ATSC card isn't supported yet\n");
  1663. break;
  1664. }
  1665. if (!dvb->fe[0]) {
  1666. dev_err(&dev->intf->dev, "frontend initialization failed\n");
  1667. result = -EINVAL;
  1668. goto out_free;
  1669. }
  1670. /* define general-purpose callback pointer */
  1671. dvb->fe[0]->callback = em28xx_tuner_callback;
  1672. if (dvb->fe[1])
  1673. dvb->fe[1]->callback = em28xx_tuner_callback;
  1674. /* register everything */
  1675. result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->intf->dev);
  1676. if (result < 0)
  1677. goto out_free;
  1678. if (dev->dvb_xfer_bulk) {
  1679. dvb_alt = 0;
  1680. } else { /* isoc */
  1681. dvb_alt = dev->dvb_alt_isoc;
  1682. }
  1683. udev = interface_to_usbdev(dev->intf);
  1684. usb_set_interface(udev, dev->ifnum, dvb_alt);
  1685. dev_info(&dev->intf->dev, "DVB extension successfully initialized\n");
  1686. kref_get(&dev->ref);
  1687. ret:
  1688. em28xx_set_mode(dev, EM28XX_SUSPEND);
  1689. mutex_unlock(&dev->lock);
  1690. return result;
  1691. out_free:
  1692. kfree(dvb);
  1693. dev->dvb = NULL;
  1694. goto ret;
  1695. }
  1696. static inline void prevent_sleep(struct dvb_frontend_ops *ops)
  1697. {
  1698. ops->set_voltage = NULL;
  1699. ops->sleep = NULL;
  1700. ops->tuner_ops.sleep = NULL;
  1701. }
  1702. static int em28xx_dvb_fini(struct em28xx *dev)
  1703. {
  1704. struct em28xx_dvb *dvb;
  1705. if (dev->is_audio_only) {
  1706. /* Shouldn't initialize IR for this interface */
  1707. return 0;
  1708. }
  1709. if (!dev->board.has_dvb) {
  1710. /* This device does not support the extension */
  1711. return 0;
  1712. }
  1713. if (!dev->dvb)
  1714. return 0;
  1715. dev_info(&dev->intf->dev, "Closing DVB extension\n");
  1716. dvb = dev->dvb;
  1717. em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
  1718. if (dev->disconnected) {
  1719. /*
  1720. * We cannot tell the device to sleep
  1721. * once it has been unplugged.
  1722. */
  1723. if (dvb->fe[0]) {
  1724. prevent_sleep(&dvb->fe[0]->ops);
  1725. dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED;
  1726. }
  1727. if (dvb->fe[1]) {
  1728. prevent_sleep(&dvb->fe[1]->ops);
  1729. dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED;
  1730. }
  1731. }
  1732. em28xx_unregister_dvb(dvb);
  1733. /* release I2C module bindings */
  1734. dvb_module_release(dvb->i2c_client_sec);
  1735. dvb_module_release(dvb->i2c_client_tuner);
  1736. dvb_module_release(dvb->i2c_client_demod);
  1737. kfree(dvb);
  1738. dev->dvb = NULL;
  1739. kref_put(&dev->ref, em28xx_free_device);
  1740. return 0;
  1741. }
  1742. static int em28xx_dvb_suspend(struct em28xx *dev)
  1743. {
  1744. int ret = 0;
  1745. if (dev->is_audio_only)
  1746. return 0;
  1747. if (!dev->board.has_dvb)
  1748. return 0;
  1749. dev_info(&dev->intf->dev, "Suspending DVB extension\n");
  1750. if (dev->dvb) {
  1751. struct em28xx_dvb *dvb = dev->dvb;
  1752. if (dvb->fe[0]) {
  1753. ret = dvb_frontend_suspend(dvb->fe[0]);
  1754. dev_info(&dev->intf->dev, "fe0 suspend %d\n", ret);
  1755. }
  1756. if (dvb->fe[1]) {
  1757. dvb_frontend_suspend(dvb->fe[1]);
  1758. dev_info(&dev->intf->dev, "fe1 suspend %d\n", ret);
  1759. }
  1760. }
  1761. return 0;
  1762. }
  1763. static int em28xx_dvb_resume(struct em28xx *dev)
  1764. {
  1765. int ret = 0;
  1766. if (dev->is_audio_only)
  1767. return 0;
  1768. if (!dev->board.has_dvb)
  1769. return 0;
  1770. dev_info(&dev->intf->dev, "Resuming DVB extension\n");
  1771. if (dev->dvb) {
  1772. struct em28xx_dvb *dvb = dev->dvb;
  1773. if (dvb->fe[0]) {
  1774. ret = dvb_frontend_resume(dvb->fe[0]);
  1775. dev_info(&dev->intf->dev, "fe0 resume %d\n", ret);
  1776. }
  1777. if (dvb->fe[1]) {
  1778. ret = dvb_frontend_resume(dvb->fe[1]);
  1779. dev_info(&dev->intf->dev, "fe1 resume %d\n", ret);
  1780. }
  1781. }
  1782. return 0;
  1783. }
  1784. static struct em28xx_ops dvb_ops = {
  1785. .id = EM28XX_DVB,
  1786. .name = "Em28xx dvb Extension",
  1787. .init = em28xx_dvb_init,
  1788. .fini = em28xx_dvb_fini,
  1789. .suspend = em28xx_dvb_suspend,
  1790. .resume = em28xx_dvb_resume,
  1791. };
  1792. static int __init em28xx_dvb_register(void)
  1793. {
  1794. return em28xx_register_extension(&dvb_ops);
  1795. }
  1796. static void __exit em28xx_dvb_unregister(void)
  1797. {
  1798. em28xx_unregister_extension(&dvb_ops);
  1799. }
  1800. module_init(em28xx_dvb_register);
  1801. module_exit(em28xx_dvb_unregister);