em28xx-dvb.c 53 KB

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