em28xx-dvb.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  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 "m88ts2022.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. };
  83. static inline void print_err_status(struct em28xx *dev,
  84. int packet, int status)
  85. {
  86. char *errmsg = "Unknown";
  87. switch (status) {
  88. case -ENOENT:
  89. errmsg = "unlinked synchronuously";
  90. break;
  91. case -ECONNRESET:
  92. errmsg = "unlinked asynchronuously";
  93. break;
  94. case -ENOSR:
  95. errmsg = "Buffer error (overrun)";
  96. break;
  97. case -EPIPE:
  98. errmsg = "Stalled (device not responding)";
  99. break;
  100. case -EOVERFLOW:
  101. errmsg = "Babble (bad cable?)";
  102. break;
  103. case -EPROTO:
  104. errmsg = "Bit-stuff error (bad cable?)";
  105. break;
  106. case -EILSEQ:
  107. errmsg = "CRC/Timeout (could be anything)";
  108. break;
  109. case -ETIME:
  110. errmsg = "Device does not respond";
  111. break;
  112. }
  113. if (packet < 0) {
  114. dprintk(1, "URB status %d [%s].\n", status, errmsg);
  115. } else {
  116. dprintk(1, "URB packet %d, status %d [%s].\n",
  117. packet, status, errmsg);
  118. }
  119. }
  120. static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
  121. {
  122. int xfer_bulk, num_packets, i;
  123. if (!dev)
  124. return 0;
  125. if (dev->disconnected)
  126. return 0;
  127. if (urb->status < 0)
  128. print_err_status(dev, -1, urb->status);
  129. xfer_bulk = usb_pipebulk(urb->pipe);
  130. if (xfer_bulk) /* bulk */
  131. num_packets = 1;
  132. else /* isoc */
  133. num_packets = urb->number_of_packets;
  134. for (i = 0; i < num_packets; i++) {
  135. if (xfer_bulk) {
  136. if (urb->status < 0) {
  137. print_err_status(dev, i, urb->status);
  138. if (urb->status != -EPROTO)
  139. continue;
  140. }
  141. if (!urb->actual_length)
  142. continue;
  143. dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
  144. urb->actual_length);
  145. } else {
  146. if (urb->iso_frame_desc[i].status < 0) {
  147. print_err_status(dev, i,
  148. urb->iso_frame_desc[i].status);
  149. if (urb->iso_frame_desc[i].status != -EPROTO)
  150. continue;
  151. }
  152. if (!urb->iso_frame_desc[i].actual_length)
  153. continue;
  154. dvb_dmx_swfilter(&dev->dvb->demux,
  155. urb->transfer_buffer +
  156. urb->iso_frame_desc[i].offset,
  157. urb->iso_frame_desc[i].actual_length);
  158. }
  159. }
  160. return 0;
  161. }
  162. static int em28xx_start_streaming(struct em28xx_dvb *dvb)
  163. {
  164. int rc;
  165. struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
  166. struct em28xx *dev = i2c_bus->dev;
  167. int dvb_max_packet_size, packet_multiplier, dvb_alt;
  168. if (dev->dvb_xfer_bulk) {
  169. if (!dev->dvb_ep_bulk)
  170. return -ENODEV;
  171. dvb_max_packet_size = 512; /* USB 2.0 spec */
  172. packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
  173. dvb_alt = 0;
  174. } else { /* isoc */
  175. if (!dev->dvb_ep_isoc)
  176. return -ENODEV;
  177. dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
  178. if (dvb_max_packet_size < 0)
  179. return dvb_max_packet_size;
  180. packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
  181. dvb_alt = dev->dvb_alt_isoc;
  182. }
  183. usb_set_interface(dev->udev, dev->ifnum, dvb_alt);
  184. rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  185. if (rc < 0)
  186. return rc;
  187. dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
  188. EM28XX_DVB_NUM_BUFS,
  189. packet_multiplier,
  190. dvb_max_packet_size, dvb_alt);
  191. return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
  192. dev->dvb_xfer_bulk,
  193. EM28XX_DVB_NUM_BUFS,
  194. dvb_max_packet_size,
  195. packet_multiplier,
  196. em28xx_dvb_urb_data_copy);
  197. }
  198. static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
  199. {
  200. struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
  201. struct em28xx *dev = i2c_bus->dev;
  202. em28xx_stop_urbs(dev);
  203. return 0;
  204. }
  205. static int em28xx_start_feed(struct dvb_demux_feed *feed)
  206. {
  207. struct dvb_demux *demux = feed->demux;
  208. struct em28xx_dvb *dvb = demux->priv;
  209. int rc, ret;
  210. if (!demux->dmx.frontend)
  211. return -EINVAL;
  212. mutex_lock(&dvb->lock);
  213. dvb->nfeeds++;
  214. rc = dvb->nfeeds;
  215. if (dvb->nfeeds == 1) {
  216. ret = em28xx_start_streaming(dvb);
  217. if (ret < 0)
  218. rc = ret;
  219. }
  220. mutex_unlock(&dvb->lock);
  221. return rc;
  222. }
  223. static int em28xx_stop_feed(struct dvb_demux_feed *feed)
  224. {
  225. struct dvb_demux *demux = feed->demux;
  226. struct em28xx_dvb *dvb = demux->priv;
  227. int err = 0;
  228. mutex_lock(&dvb->lock);
  229. dvb->nfeeds--;
  230. if (0 == dvb->nfeeds)
  231. err = em28xx_stop_streaming(dvb);
  232. mutex_unlock(&dvb->lock);
  233. return err;
  234. }
  235. /* ------------------------------------------------------------------ */
  236. static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
  237. {
  238. struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
  239. struct em28xx *dev = i2c_bus->dev;
  240. if (acquire)
  241. return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  242. else
  243. return em28xx_set_mode(dev, EM28XX_SUSPEND);
  244. }
  245. /* ------------------------------------------------------------------ */
  246. static struct lgdt330x_config em2880_lgdt3303_dev = {
  247. .demod_address = 0x0e,
  248. .demod_chip = LGDT3303,
  249. };
  250. static struct lgdt3305_config em2870_lgdt3304_dev = {
  251. .i2c_addr = 0x0e,
  252. .demod_chip = LGDT3304,
  253. .spectral_inversion = 1,
  254. .deny_i2c_rptr = 1,
  255. .mpeg_mode = LGDT3305_MPEG_PARALLEL,
  256. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  257. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  258. .vsb_if_khz = 3250,
  259. .qam_if_khz = 4000,
  260. };
  261. static struct lgdt3305_config em2874_lgdt3305_dev = {
  262. .i2c_addr = 0x0e,
  263. .demod_chip = LGDT3305,
  264. .spectral_inversion = 1,
  265. .deny_i2c_rptr = 0,
  266. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  267. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  268. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  269. .vsb_if_khz = 3250,
  270. .qam_if_khz = 4000,
  271. };
  272. static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
  273. .i2c_addr = 0x0e,
  274. .demod_chip = LGDT3305,
  275. .spectral_inversion = 1,
  276. .deny_i2c_rptr = 1,
  277. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  278. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  279. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  280. .vsb_if_khz = 3600,
  281. .qam_if_khz = 3600,
  282. };
  283. static struct s921_config sharp_isdbt = {
  284. .demod_address = 0x30 >> 1
  285. };
  286. static struct zl10353_config em28xx_zl10353_with_xc3028 = {
  287. .demod_address = (0x1e >> 1),
  288. .no_tuner = 1,
  289. .parallel_ts = 1,
  290. .if2 = 45600,
  291. };
  292. static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
  293. .demod_address = 0x32 >> 1,
  294. .output_mode = S5H1409_PARALLEL_OUTPUT,
  295. .gpio = S5H1409_GPIO_OFF,
  296. .inversion = S5H1409_INVERSION_OFF,
  297. .status_mode = S5H1409_DEMODLOCKING,
  298. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
  299. };
  300. static struct tda18271_std_map kworld_a340_std_map = {
  301. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
  302. .if_lvl = 1, .rfagc_top = 0x37, },
  303. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
  304. .if_lvl = 1, .rfagc_top = 0x37, },
  305. };
  306. static struct tda18271_config kworld_a340_config = {
  307. .std_map = &kworld_a340_std_map,
  308. };
  309. static struct tda18271_config kworld_ub435q_v2_config = {
  310. .std_map = &kworld_a340_std_map,
  311. .gate = TDA18271_GATE_DIGITAL,
  312. };
  313. static struct tda18212_config kworld_ub435q_v3_config = {
  314. .i2c_address = 0x60,
  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 const struct tda10071_config em28xx_tda10071_config = {
  693. .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
  694. .tuner_i2c_addr = 0x14,
  695. .i2c_wr_max = 64,
  696. .ts_mode = TDA10071_TS_SERIAL,
  697. .spec_inv = 0,
  698. .xtal = 40444000, /* 40.444 MHz */
  699. .pll_multiplier = 20,
  700. };
  701. static const struct a8293_config em28xx_a8293_config = {
  702. .i2c_addr = 0x08, /* (0x10 >> 1) */
  703. };
  704. static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
  705. .demod_address = (0x1e >> 1),
  706. .disable_i2c_gate_ctrl = 1,
  707. .no_tuner = 1,
  708. .parallel_ts = 1,
  709. };
  710. static struct qt1010_config em28xx_qt1010_config = {
  711. .i2c_address = 0x62
  712. };
  713. static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
  714. .demod_address = 0x10,
  715. .is_serial = true,
  716. };
  717. static struct tda18271_std_map mb86a20s_tda18271_config = {
  718. .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
  719. .if_lvl = 1, .rfagc_top = 0x37, },
  720. };
  721. static struct tda18271_config c3tech_duo_tda18271_config = {
  722. .std_map = &mb86a20s_tda18271_config,
  723. .gate = TDA18271_GATE_DIGITAL,
  724. .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
  725. };
  726. static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
  727. .i2c_addr = 0x68,
  728. .clock = 27000000,
  729. .i2c_wr_max = 33,
  730. .clock_out = 0,
  731. .ts_mode = M88DS3103_TS_PARALLEL_16,
  732. .agc = 0x99,
  733. };
  734. static struct tda18271_std_map drx_j_std_map = {
  735. .atsc_6 = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
  736. .rfagc_top = 0x37, },
  737. .qam_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
  738. .rfagc_top = 0x37, },
  739. };
  740. static struct tda18271_config pinnacle_80e_dvb_config = {
  741. .std_map = &drx_j_std_map,
  742. .gate = TDA18271_GATE_DIGITAL,
  743. .role = TDA18271_MASTER,
  744. };
  745. /* ------------------------------------------------------------------ */
  746. static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
  747. {
  748. struct dvb_frontend *fe;
  749. struct xc2028_config cfg;
  750. struct xc2028_ctrl ctl;
  751. memset(&cfg, 0, sizeof(cfg));
  752. cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
  753. cfg.i2c_addr = addr;
  754. memset(&ctl, 0, sizeof(ctl));
  755. em28xx_setup_xc3028(dev, &ctl);
  756. cfg.ctrl = &ctl;
  757. if (!dev->dvb->fe[0]) {
  758. em28xx_errdev("/2: dvb frontend not attached. "
  759. "Can't attach xc3028\n");
  760. return -EINVAL;
  761. }
  762. fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
  763. if (!fe) {
  764. em28xx_errdev("/2: xc3028 attach failed\n");
  765. dvb_frontend_detach(dev->dvb->fe[0]);
  766. dev->dvb->fe[0] = NULL;
  767. return -EINVAL;
  768. }
  769. em28xx_info("%s/2: xc3028 attached\n", dev->name);
  770. return 0;
  771. }
  772. /* ------------------------------------------------------------------ */
  773. static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
  774. struct em28xx *dev, struct device *device)
  775. {
  776. int result;
  777. mutex_init(&dvb->lock);
  778. /* register adapter */
  779. result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
  780. adapter_nr);
  781. if (result < 0) {
  782. printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
  783. dev->name, result);
  784. goto fail_adapter;
  785. }
  786. /* Ensure all frontends negotiate bus access */
  787. dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  788. if (dvb->fe[1])
  789. dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  790. dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
  791. /* register frontend */
  792. result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
  793. if (result < 0) {
  794. printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
  795. dev->name, result);
  796. goto fail_frontend0;
  797. }
  798. /* register 2nd frontend */
  799. if (dvb->fe[1]) {
  800. result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
  801. if (result < 0) {
  802. printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
  803. dev->name, result);
  804. goto fail_frontend1;
  805. }
  806. }
  807. /* register demux stuff */
  808. dvb->demux.dmx.capabilities =
  809. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  810. DMX_MEMORY_BASED_FILTERING;
  811. dvb->demux.priv = dvb;
  812. dvb->demux.filternum = 256;
  813. dvb->demux.feednum = 256;
  814. dvb->demux.start_feed = em28xx_start_feed;
  815. dvb->demux.stop_feed = em28xx_stop_feed;
  816. result = dvb_dmx_init(&dvb->demux);
  817. if (result < 0) {
  818. printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
  819. dev->name, result);
  820. goto fail_dmx;
  821. }
  822. dvb->dmxdev.filternum = 256;
  823. dvb->dmxdev.demux = &dvb->demux.dmx;
  824. dvb->dmxdev.capabilities = 0;
  825. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  826. if (result < 0) {
  827. printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
  828. dev->name, result);
  829. goto fail_dmxdev;
  830. }
  831. dvb->fe_hw.source = DMX_FRONTEND_0;
  832. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  833. if (result < 0) {
  834. printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  835. dev->name, result);
  836. goto fail_fe_hw;
  837. }
  838. dvb->fe_mem.source = DMX_MEMORY_FE;
  839. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  840. if (result < 0) {
  841. printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  842. dev->name, result);
  843. goto fail_fe_mem;
  844. }
  845. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  846. if (result < 0) {
  847. printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
  848. dev->name, result);
  849. goto fail_fe_conn;
  850. }
  851. /* register network adapter */
  852. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  853. return 0;
  854. fail_fe_conn:
  855. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  856. fail_fe_mem:
  857. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  858. fail_fe_hw:
  859. dvb_dmxdev_release(&dvb->dmxdev);
  860. fail_dmxdev:
  861. dvb_dmx_release(&dvb->demux);
  862. fail_dmx:
  863. if (dvb->fe[1])
  864. dvb_unregister_frontend(dvb->fe[1]);
  865. dvb_unregister_frontend(dvb->fe[0]);
  866. fail_frontend1:
  867. if (dvb->fe[1])
  868. dvb_frontend_detach(dvb->fe[1]);
  869. fail_frontend0:
  870. dvb_frontend_detach(dvb->fe[0]);
  871. dvb_unregister_adapter(&dvb->adapter);
  872. fail_adapter:
  873. return result;
  874. }
  875. static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
  876. {
  877. dvb_net_release(&dvb->net);
  878. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  879. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  880. dvb_dmxdev_release(&dvb->dmxdev);
  881. dvb_dmx_release(&dvb->demux);
  882. if (dvb->fe[1])
  883. dvb_unregister_frontend(dvb->fe[1]);
  884. dvb_unregister_frontend(dvb->fe[0]);
  885. if (dvb->fe[1] && !dvb->dont_attach_fe1)
  886. dvb_frontend_detach(dvb->fe[1]);
  887. dvb_frontend_detach(dvb->fe[0]);
  888. dvb_unregister_adapter(&dvb->adapter);
  889. }
  890. static int em28xx_dvb_init(struct em28xx *dev)
  891. {
  892. int result = 0, mfe_shared = 0;
  893. struct em28xx_dvb *dvb;
  894. if (dev->is_audio_only) {
  895. /* Shouldn't initialize IR for this interface */
  896. return 0;
  897. }
  898. if (!dev->board.has_dvb) {
  899. /* This device does not support the extension */
  900. return 0;
  901. }
  902. em28xx_info("Binding DVB extension\n");
  903. dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
  904. if (dvb == NULL) {
  905. em28xx_info("em28xx_dvb: memory allocation failed\n");
  906. return -ENOMEM;
  907. }
  908. dev->dvb = dvb;
  909. dvb->fe[0] = dvb->fe[1] = NULL;
  910. /* pre-allocate DVB usb transfer buffers */
  911. if (dev->dvb_xfer_bulk) {
  912. result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
  913. dev->dvb_xfer_bulk,
  914. EM28XX_DVB_NUM_BUFS,
  915. 512,
  916. EM28XX_DVB_BULK_PACKET_MULTIPLIER);
  917. } else {
  918. result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
  919. dev->dvb_xfer_bulk,
  920. EM28XX_DVB_NUM_BUFS,
  921. dev->dvb_max_pkt_size_isoc,
  922. EM28XX_DVB_NUM_ISOC_PACKETS);
  923. }
  924. if (result) {
  925. em28xx_errdev("em28xx_dvb: failed to pre-allocate USB transfer buffers for DVB.\n");
  926. kfree(dvb);
  927. dev->dvb = NULL;
  928. return result;
  929. }
  930. mutex_lock(&dev->lock);
  931. em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  932. /* init frontend */
  933. switch (dev->model) {
  934. case EM2874_BOARD_LEADERSHIP_ISDBT:
  935. dvb->fe[0] = dvb_attach(s921_attach,
  936. &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
  937. if (!dvb->fe[0]) {
  938. result = -EINVAL;
  939. goto out_free;
  940. }
  941. break;
  942. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
  943. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
  944. case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
  945. case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
  946. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  947. &em2880_lgdt3303_dev,
  948. &dev->i2c_adap[dev->def_i2c_bus]);
  949. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  950. result = -EINVAL;
  951. goto out_free;
  952. }
  953. break;
  954. case EM2880_BOARD_KWORLD_DVB_310U:
  955. dvb->fe[0] = dvb_attach(zl10353_attach,
  956. &em28xx_zl10353_with_xc3028,
  957. &dev->i2c_adap[dev->def_i2c_bus]);
  958. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  959. result = -EINVAL;
  960. goto out_free;
  961. }
  962. break;
  963. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  964. case EM2882_BOARD_TERRATEC_HYBRID_XS:
  965. case EM2880_BOARD_EMPIRE_DUAL_TV:
  966. dvb->fe[0] = dvb_attach(zl10353_attach,
  967. &em28xx_zl10353_xc3028_no_i2c_gate,
  968. &dev->i2c_adap[dev->def_i2c_bus]);
  969. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  970. result = -EINVAL;
  971. goto out_free;
  972. }
  973. break;
  974. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  975. case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
  976. case EM2881_BOARD_PINNACLE_HYBRID_PRO:
  977. case EM2882_BOARD_DIKOM_DK300:
  978. case EM2882_BOARD_KWORLD_VS_DVBT:
  979. dvb->fe[0] = dvb_attach(zl10353_attach,
  980. &em28xx_zl10353_xc3028_no_i2c_gate,
  981. &dev->i2c_adap[dev->def_i2c_bus]);
  982. if (dvb->fe[0] == NULL) {
  983. /* This board could have either a zl10353 or a mt352.
  984. If the chip id isn't for zl10353, try mt352 */
  985. dvb->fe[0] = dvb_attach(mt352_attach,
  986. &terratec_xs_mt352_cfg,
  987. &dev->i2c_adap[dev->def_i2c_bus]);
  988. }
  989. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  990. result = -EINVAL;
  991. goto out_free;
  992. }
  993. break;
  994. case EM2870_BOARD_KWORLD_355U:
  995. dvb->fe[0] = dvb_attach(zl10353_attach,
  996. &em28xx_zl10353_no_i2c_gate_dev,
  997. &dev->i2c_adap[dev->def_i2c_bus]);
  998. if (dvb->fe[0] != NULL)
  999. dvb_attach(qt1010_attach, dvb->fe[0],
  1000. &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
  1001. break;
  1002. case EM2883_BOARD_KWORLD_HYBRID_330U:
  1003. case EM2882_BOARD_EVGA_INDTUBE:
  1004. dvb->fe[0] = dvb_attach(s5h1409_attach,
  1005. &em28xx_s5h1409_with_xc3028,
  1006. &dev->i2c_adap[dev->def_i2c_bus]);
  1007. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  1008. result = -EINVAL;
  1009. goto out_free;
  1010. }
  1011. break;
  1012. case EM2882_BOARD_KWORLD_ATSC_315U:
  1013. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  1014. &em2880_lgdt3303_dev,
  1015. &dev->i2c_adap[dev->def_i2c_bus]);
  1016. if (dvb->fe[0] != NULL) {
  1017. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  1018. &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
  1019. result = -EINVAL;
  1020. goto out_free;
  1021. }
  1022. }
  1023. break;
  1024. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
  1025. case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
  1026. dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
  1027. &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
  1028. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  1029. result = -EINVAL;
  1030. goto out_free;
  1031. }
  1032. break;
  1033. case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
  1034. /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
  1035. dvb->fe[0] = dvb_attach(tda10023_attach,
  1036. &em28xx_tda10023_config,
  1037. &dev->i2c_adap[dev->def_i2c_bus], 0x48);
  1038. if (dvb->fe[0]) {
  1039. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  1040. &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
  1041. result = -EINVAL;
  1042. goto out_free;
  1043. }
  1044. }
  1045. break;
  1046. case EM2870_BOARD_KWORLD_A340:
  1047. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  1048. &em2870_lgdt3304_dev,
  1049. &dev->i2c_adap[dev->def_i2c_bus]);
  1050. if (dvb->fe[0] != NULL)
  1051. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1052. &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
  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. /* attach demod */
  1150. dvb->fe[0] = dvb_attach(tda10071_attach,
  1151. &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
  1152. /* attach SEC */
  1153. if (dvb->fe[0])
  1154. dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
  1155. &em28xx_a8293_config);
  1156. break;
  1157. case EM2874_BOARD_DELOCK_61959:
  1158. case EM2874_BOARD_MAXMEDIA_UB425_TC:
  1159. /* attach demodulator */
  1160. dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
  1161. &dev->i2c_adap[dev->def_i2c_bus]);
  1162. if (dvb->fe[0]) {
  1163. /* disable I2C-gate */
  1164. dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
  1165. /* attach tuner */
  1166. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1167. &dev->i2c_adap[dev->def_i2c_bus],
  1168. &em28xx_cxd2820r_tda18271_config)) {
  1169. dvb_frontend_detach(dvb->fe[0]);
  1170. result = -EINVAL;
  1171. goto out_free;
  1172. }
  1173. }
  1174. break;
  1175. case EM2884_BOARD_PCTV_510E:
  1176. case EM2884_BOARD_PCTV_520E:
  1177. pctv_520e_init(dev);
  1178. /* attach demodulator */
  1179. dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
  1180. &dev->i2c_adap[dev->def_i2c_bus]);
  1181. if (dvb->fe[0]) {
  1182. /* attach tuner */
  1183. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1184. &dev->i2c_adap[dev->def_i2c_bus],
  1185. &em28xx_cxd2820r_tda18271_config)) {
  1186. dvb_frontend_detach(dvb->fe[0]);
  1187. result = -EINVAL;
  1188. goto out_free;
  1189. }
  1190. }
  1191. break;
  1192. case EM2884_BOARD_CINERGY_HTC_STICK:
  1193. terratec_htc_stick_init(dev);
  1194. /* attach demodulator */
  1195. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1196. &dev->i2c_adap[dev->def_i2c_bus]);
  1197. if (!dvb->fe[0]) {
  1198. result = -EINVAL;
  1199. goto out_free;
  1200. }
  1201. /* Attach the demodulator. */
  1202. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1203. &dev->i2c_adap[dev->def_i2c_bus],
  1204. &em28xx_cxd2820r_tda18271_config)) {
  1205. result = -EINVAL;
  1206. goto out_free;
  1207. }
  1208. break;
  1209. case EM2884_BOARD_TERRATEC_HTC_USB_XS:
  1210. terratec_htc_usb_xs_init(dev);
  1211. /* attach demodulator */
  1212. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1213. &dev->i2c_adap[dev->def_i2c_bus]);
  1214. if (!dvb->fe[0]) {
  1215. result = -EINVAL;
  1216. goto out_free;
  1217. }
  1218. /* Attach the demodulator. */
  1219. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1220. &dev->i2c_adap[dev->def_i2c_bus],
  1221. &em28xx_cxd2820r_tda18271_config)) {
  1222. result = -EINVAL;
  1223. goto out_free;
  1224. }
  1225. break;
  1226. case EM2874_BOARD_KWORLD_UB435Q_V2:
  1227. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  1228. &em2874_lgdt3305_dev,
  1229. &dev->i2c_adap[dev->def_i2c_bus]);
  1230. if (!dvb->fe[0]) {
  1231. result = -EINVAL;
  1232. goto out_free;
  1233. }
  1234. /* Attach the demodulator. */
  1235. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1236. &dev->i2c_adap[dev->def_i2c_bus],
  1237. &kworld_ub435q_v2_config)) {
  1238. result = -EINVAL;
  1239. goto out_free;
  1240. }
  1241. break;
  1242. case EM2874_BOARD_KWORLD_UB435Q_V3:
  1243. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  1244. &em2874_lgdt3305_nogate_dev,
  1245. &dev->i2c_adap[dev->def_i2c_bus]);
  1246. if (!dvb->fe[0]) {
  1247. result = -EINVAL;
  1248. goto out_free;
  1249. }
  1250. /* Attach the demodulator. */
  1251. if (!dvb_attach(tda18212_attach, dvb->fe[0],
  1252. &dev->i2c_adap[dev->def_i2c_bus],
  1253. &kworld_ub435q_v3_config)) {
  1254. result = -EINVAL;
  1255. goto out_free;
  1256. }
  1257. break;
  1258. case EM2874_BOARD_PCTV_HD_MINI_80E:
  1259. dvb->fe[0] = dvb_attach(drx39xxj_attach, &dev->i2c_adap[dev->def_i2c_bus]);
  1260. if (dvb->fe[0] != NULL) {
  1261. dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1262. &dev->i2c_adap[dev->def_i2c_bus],
  1263. &pinnacle_80e_dvb_config);
  1264. if (!dvb->fe[0]) {
  1265. result = -EINVAL;
  1266. goto out_free;
  1267. }
  1268. }
  1269. break;
  1270. case EM28178_BOARD_PCTV_461E:
  1271. {
  1272. /* demod I2C adapter */
  1273. struct i2c_adapter *i2c_adapter;
  1274. struct i2c_client *client;
  1275. struct i2c_board_info info;
  1276. struct m88ts2022_config m88ts2022_config = {
  1277. .clock = 27000000,
  1278. };
  1279. memset(&info, 0, sizeof(struct i2c_board_info));
  1280. /* attach demod */
  1281. dvb->fe[0] = dvb_attach(m88ds3103_attach,
  1282. &pctv_461e_m88ds3103_config,
  1283. &dev->i2c_adap[dev->def_i2c_bus],
  1284. &i2c_adapter);
  1285. if (dvb->fe[0] == NULL) {
  1286. result = -ENODEV;
  1287. goto out_free;
  1288. }
  1289. /* attach tuner */
  1290. m88ts2022_config.fe = dvb->fe[0];
  1291. strlcpy(info.type, "m88ts2022", I2C_NAME_SIZE);
  1292. info.addr = 0x60;
  1293. info.platform_data = &m88ts2022_config;
  1294. request_module("m88ts2022");
  1295. client = i2c_new_device(i2c_adapter, &info);
  1296. if (client == NULL || client->dev.driver == NULL) {
  1297. dvb_frontend_detach(dvb->fe[0]);
  1298. result = -ENODEV;
  1299. goto out_free;
  1300. }
  1301. if (!try_module_get(client->dev.driver->owner)) {
  1302. i2c_unregister_device(client);
  1303. dvb_frontend_detach(dvb->fe[0]);
  1304. result = -ENODEV;
  1305. goto out_free;
  1306. }
  1307. /* delegate signal strength measurement to tuner */
  1308. dvb->fe[0]->ops.read_signal_strength =
  1309. dvb->fe[0]->ops.tuner_ops.get_rf_strength;
  1310. /* attach SEC */
  1311. if (!dvb_attach(a8293_attach, dvb->fe[0],
  1312. &dev->i2c_adap[dev->def_i2c_bus],
  1313. &em28xx_a8293_config)) {
  1314. module_put(client->dev.driver->owner);
  1315. i2c_unregister_device(client);
  1316. dvb_frontend_detach(dvb->fe[0]);
  1317. result = -ENODEV;
  1318. goto out_free;
  1319. }
  1320. dvb->i2c_client_tuner = client;
  1321. }
  1322. break;
  1323. case EM28178_BOARD_PCTV_292E:
  1324. {
  1325. struct i2c_adapter *adapter;
  1326. struct i2c_client *client;
  1327. struct i2c_board_info info;
  1328. struct si2168_config si2168_config;
  1329. struct si2157_config si2157_config;
  1330. /* attach demod */
  1331. si2168_config.i2c_adapter = &adapter;
  1332. si2168_config.fe = &dvb->fe[0];
  1333. memset(&info, 0, sizeof(struct i2c_board_info));
  1334. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  1335. info.addr = 0x64;
  1336. info.platform_data = &si2168_config;
  1337. request_module(info.type);
  1338. client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
  1339. if (client == NULL || client->dev.driver == NULL) {
  1340. result = -ENODEV;
  1341. goto out_free;
  1342. }
  1343. if (!try_module_get(client->dev.driver->owner)) {
  1344. i2c_unregister_device(client);
  1345. result = -ENODEV;
  1346. goto out_free;
  1347. }
  1348. dvb->i2c_client_demod = client;
  1349. /* attach tuner */
  1350. si2157_config.fe = dvb->fe[0];
  1351. memset(&info, 0, sizeof(struct i2c_board_info));
  1352. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  1353. info.addr = 0x60;
  1354. info.platform_data = &si2157_config;
  1355. request_module(info.type);
  1356. client = i2c_new_device(adapter, &info);
  1357. if (client == NULL || client->dev.driver == NULL) {
  1358. module_put(dvb->i2c_client_demod->dev.driver->owner);
  1359. i2c_unregister_device(dvb->i2c_client_demod);
  1360. result = -ENODEV;
  1361. goto out_free;
  1362. }
  1363. if (!try_module_get(client->dev.driver->owner)) {
  1364. i2c_unregister_device(client);
  1365. module_put(dvb->i2c_client_demod->dev.driver->owner);
  1366. i2c_unregister_device(dvb->i2c_client_demod);
  1367. result = -ENODEV;
  1368. goto out_free;
  1369. }
  1370. dvb->i2c_client_tuner = client;
  1371. dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
  1372. }
  1373. break;
  1374. default:
  1375. em28xx_errdev("/2: The frontend of your DVB/ATSC card"
  1376. " isn't supported yet\n");
  1377. break;
  1378. }
  1379. if (NULL == dvb->fe[0]) {
  1380. em28xx_errdev("/2: frontend initialization failed\n");
  1381. result = -EINVAL;
  1382. goto out_free;
  1383. }
  1384. /* define general-purpose callback pointer */
  1385. dvb->fe[0]->callback = em28xx_tuner_callback;
  1386. if (dvb->fe[1])
  1387. dvb->fe[1]->callback = em28xx_tuner_callback;
  1388. /* register everything */
  1389. result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
  1390. if (result < 0)
  1391. goto out_free;
  1392. /* MFE lock */
  1393. dvb->adapter.mfe_shared = mfe_shared;
  1394. em28xx_info("DVB extension successfully initialized\n");
  1395. kref_get(&dev->ref);
  1396. ret:
  1397. em28xx_set_mode(dev, EM28XX_SUSPEND);
  1398. mutex_unlock(&dev->lock);
  1399. return result;
  1400. out_free:
  1401. kfree(dvb);
  1402. dev->dvb = NULL;
  1403. goto ret;
  1404. }
  1405. static inline void prevent_sleep(struct dvb_frontend_ops *ops)
  1406. {
  1407. ops->set_voltage = NULL;
  1408. ops->sleep = NULL;
  1409. ops->tuner_ops.sleep = NULL;
  1410. }
  1411. static int em28xx_dvb_fini(struct em28xx *dev)
  1412. {
  1413. struct em28xx_dvb *dvb;
  1414. struct i2c_client *client;
  1415. if (dev->is_audio_only) {
  1416. /* Shouldn't initialize IR for this interface */
  1417. return 0;
  1418. }
  1419. if (!dev->board.has_dvb) {
  1420. /* This device does not support the extension */
  1421. return 0;
  1422. }
  1423. if (!dev->dvb)
  1424. return 0;
  1425. em28xx_info("Closing DVB extension");
  1426. dvb = dev->dvb;
  1427. client = dvb->i2c_client_tuner;
  1428. em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
  1429. if (dev->disconnected) {
  1430. /* We cannot tell the device to sleep
  1431. * once it has been unplugged. */
  1432. if (dvb->fe[0])
  1433. prevent_sleep(&dvb->fe[0]->ops);
  1434. if (dvb->fe[1])
  1435. prevent_sleep(&dvb->fe[1]->ops);
  1436. }
  1437. /* remove I2C tuner */
  1438. if (client) {
  1439. module_put(client->dev.driver->owner);
  1440. i2c_unregister_device(client);
  1441. }
  1442. /* remove I2C demod */
  1443. client = dvb->i2c_client_demod;
  1444. if (client) {
  1445. module_put(client->dev.driver->owner);
  1446. i2c_unregister_device(client);
  1447. }
  1448. em28xx_unregister_dvb(dvb);
  1449. kfree(dvb);
  1450. dev->dvb = NULL;
  1451. kref_put(&dev->ref, em28xx_free_device);
  1452. return 0;
  1453. }
  1454. static int em28xx_dvb_suspend(struct em28xx *dev)
  1455. {
  1456. int ret = 0;
  1457. if (dev->is_audio_only)
  1458. return 0;
  1459. if (!dev->board.has_dvb)
  1460. return 0;
  1461. em28xx_info("Suspending DVB extension");
  1462. if (dev->dvb) {
  1463. struct em28xx_dvb *dvb = dev->dvb;
  1464. if (dvb->fe[0]) {
  1465. ret = dvb_frontend_suspend(dvb->fe[0]);
  1466. em28xx_info("fe0 suspend %d", ret);
  1467. }
  1468. if (dvb->fe[1]) {
  1469. dvb_frontend_suspend(dvb->fe[1]);
  1470. em28xx_info("fe1 suspend %d", ret);
  1471. }
  1472. }
  1473. return 0;
  1474. }
  1475. static int em28xx_dvb_resume(struct em28xx *dev)
  1476. {
  1477. int ret = 0;
  1478. if (dev->is_audio_only)
  1479. return 0;
  1480. if (!dev->board.has_dvb)
  1481. return 0;
  1482. em28xx_info("Resuming DVB extension");
  1483. if (dev->dvb) {
  1484. struct em28xx_dvb *dvb = dev->dvb;
  1485. struct i2c_client *client = dvb->i2c_client_tuner;
  1486. if (dvb->fe[0]) {
  1487. ret = dvb_frontend_resume(dvb->fe[0]);
  1488. em28xx_info("fe0 resume %d", ret);
  1489. }
  1490. if (dvb->fe[1]) {
  1491. ret = dvb_frontend_resume(dvb->fe[1]);
  1492. em28xx_info("fe1 resume %d", ret);
  1493. }
  1494. /* remove I2C tuner */
  1495. if (client) {
  1496. module_put(client->dev.driver->owner);
  1497. i2c_unregister_device(client);
  1498. }
  1499. /* remove I2C demod */
  1500. client = dvb->i2c_client_demod;
  1501. if (client) {
  1502. module_put(client->dev.driver->owner);
  1503. i2c_unregister_device(client);
  1504. }
  1505. em28xx_unregister_dvb(dvb);
  1506. kfree(dvb);
  1507. dev->dvb = NULL;
  1508. }
  1509. return 0;
  1510. }
  1511. static struct em28xx_ops dvb_ops = {
  1512. .id = EM28XX_DVB,
  1513. .name = "Em28xx dvb Extension",
  1514. .init = em28xx_dvb_init,
  1515. .fini = em28xx_dvb_fini,
  1516. .suspend = em28xx_dvb_suspend,
  1517. .resume = em28xx_dvb_resume,
  1518. };
  1519. static int __init em28xx_dvb_register(void)
  1520. {
  1521. return em28xx_register_extension(&dvb_ops);
  1522. }
  1523. static void __exit em28xx_dvb_unregister(void)
  1524. {
  1525. em28xx_unregister_extension(&dvb_ops);
  1526. }
  1527. module_init(em28xx_dvb_register);
  1528. module_exit(em28xx_dvb_unregister);