em28xx-dvb.c 59 KB

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