em28xx-dvb.c 50 KB

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