em28xx-dvb.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  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 "tda18271.h"
  36. #include "s921.h"
  37. #include "drxd.h"
  38. #include "cxd2820r.h"
  39. #include "tda18271c2dd.h"
  40. #include "drxk.h"
  41. #include "tda10071.h"
  42. #include "a8293.h"
  43. #include "qt1010.h"
  44. #include "mb86a20s.h"
  45. MODULE_DESCRIPTION("driver for em28xx based DVB cards");
  46. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  47. MODULE_LICENSE("GPL");
  48. static unsigned int debug;
  49. module_param(debug, int, 0644);
  50. MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
  51. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  52. #define dprintk(level, fmt, arg...) do { \
  53. if (debug >= level) \
  54. printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
  55. } while (0)
  56. struct em28xx_dvb {
  57. struct dvb_frontend *fe[2];
  58. /* feed count management */
  59. struct mutex lock;
  60. int nfeeds;
  61. /* general boilerplate stuff */
  62. struct dvb_adapter adapter;
  63. struct dvb_demux demux;
  64. struct dmxdev dmxdev;
  65. struct dmx_frontend fe_hw;
  66. struct dmx_frontend fe_mem;
  67. struct dvb_net net;
  68. /* Due to DRX-K - probably need changes */
  69. int (*gate_ctrl)(struct dvb_frontend *, int);
  70. struct semaphore pll_mutex;
  71. bool dont_attach_fe1;
  72. int lna_gpio;
  73. };
  74. static inline void print_err_status(struct em28xx *dev,
  75. int packet, int status)
  76. {
  77. char *errmsg = "Unknown";
  78. switch (status) {
  79. case -ENOENT:
  80. errmsg = "unlinked synchronuously";
  81. break;
  82. case -ECONNRESET:
  83. errmsg = "unlinked asynchronuously";
  84. break;
  85. case -ENOSR:
  86. errmsg = "Buffer error (overrun)";
  87. break;
  88. case -EPIPE:
  89. errmsg = "Stalled (device not responding)";
  90. break;
  91. case -EOVERFLOW:
  92. errmsg = "Babble (bad cable?)";
  93. break;
  94. case -EPROTO:
  95. errmsg = "Bit-stuff error (bad cable?)";
  96. break;
  97. case -EILSEQ:
  98. errmsg = "CRC/Timeout (could be anything)";
  99. break;
  100. case -ETIME:
  101. errmsg = "Device does not respond";
  102. break;
  103. }
  104. if (packet < 0) {
  105. dprintk(1, "URB status %d [%s].\n", status, errmsg);
  106. } else {
  107. dprintk(1, "URB packet %d, status %d [%s].\n",
  108. packet, status, errmsg);
  109. }
  110. }
  111. static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
  112. {
  113. int xfer_bulk, num_packets, i;
  114. if (!dev)
  115. return 0;
  116. if (dev->disconnected)
  117. return 0;
  118. if (urb->status < 0)
  119. print_err_status(dev, -1, urb->status);
  120. xfer_bulk = usb_pipebulk(urb->pipe);
  121. if (xfer_bulk) /* bulk */
  122. num_packets = 1;
  123. else /* isoc */
  124. num_packets = urb->number_of_packets;
  125. for (i = 0; i < num_packets; i++) {
  126. if (xfer_bulk) {
  127. if (urb->status < 0) {
  128. print_err_status(dev, i, urb->status);
  129. if (urb->status != -EPROTO)
  130. continue;
  131. }
  132. dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
  133. urb->actual_length);
  134. } else {
  135. if (urb->iso_frame_desc[i].status < 0) {
  136. print_err_status(dev, i,
  137. urb->iso_frame_desc[i].status);
  138. if (urb->iso_frame_desc[i].status != -EPROTO)
  139. continue;
  140. }
  141. dvb_dmx_swfilter(&dev->dvb->demux,
  142. urb->transfer_buffer +
  143. urb->iso_frame_desc[i].offset,
  144. urb->iso_frame_desc[i].actual_length);
  145. }
  146. }
  147. return 0;
  148. }
  149. static int em28xx_start_streaming(struct em28xx_dvb *dvb)
  150. {
  151. int rc;
  152. struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
  153. struct em28xx *dev = i2c_bus->dev;
  154. int dvb_max_packet_size, packet_multiplier, dvb_alt;
  155. if (dev->dvb_xfer_bulk) {
  156. if (!dev->dvb_ep_bulk)
  157. return -ENODEV;
  158. dvb_max_packet_size = 512; /* USB 2.0 spec */
  159. packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
  160. dvb_alt = 0;
  161. } else { /* isoc */
  162. if (!dev->dvb_ep_isoc)
  163. return -ENODEV;
  164. dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
  165. if (dvb_max_packet_size < 0)
  166. return dvb_max_packet_size;
  167. packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
  168. dvb_alt = dev->dvb_alt_isoc;
  169. }
  170. usb_set_interface(dev->udev, 0, dvb_alt);
  171. rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  172. if (rc < 0)
  173. return rc;
  174. dprintk(1, "Using %d buffers each with %d x %d bytes\n",
  175. EM28XX_DVB_NUM_BUFS,
  176. packet_multiplier,
  177. dvb_max_packet_size);
  178. return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
  179. dev->dvb_xfer_bulk,
  180. EM28XX_DVB_NUM_BUFS,
  181. dvb_max_packet_size,
  182. packet_multiplier,
  183. em28xx_dvb_urb_data_copy);
  184. }
  185. static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
  186. {
  187. struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
  188. struct em28xx *dev = i2c_bus->dev;
  189. em28xx_stop_urbs(dev);
  190. return 0;
  191. }
  192. static int em28xx_start_feed(struct dvb_demux_feed *feed)
  193. {
  194. struct dvb_demux *demux = feed->demux;
  195. struct em28xx_dvb *dvb = demux->priv;
  196. int rc, ret;
  197. if (!demux->dmx.frontend)
  198. return -EINVAL;
  199. mutex_lock(&dvb->lock);
  200. dvb->nfeeds++;
  201. rc = dvb->nfeeds;
  202. if (dvb->nfeeds == 1) {
  203. ret = em28xx_start_streaming(dvb);
  204. if (ret < 0)
  205. rc = ret;
  206. }
  207. mutex_unlock(&dvb->lock);
  208. return rc;
  209. }
  210. static int em28xx_stop_feed(struct dvb_demux_feed *feed)
  211. {
  212. struct dvb_demux *demux = feed->demux;
  213. struct em28xx_dvb *dvb = demux->priv;
  214. int err = 0;
  215. mutex_lock(&dvb->lock);
  216. dvb->nfeeds--;
  217. if (0 == dvb->nfeeds)
  218. err = em28xx_stop_streaming(dvb);
  219. mutex_unlock(&dvb->lock);
  220. return err;
  221. }
  222. /* ------------------------------------------------------------------ */
  223. static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
  224. {
  225. struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
  226. struct em28xx *dev = i2c_bus->dev;
  227. if (acquire)
  228. return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  229. else
  230. return em28xx_set_mode(dev, EM28XX_SUSPEND);
  231. }
  232. /* ------------------------------------------------------------------ */
  233. static struct lgdt330x_config em2880_lgdt3303_dev = {
  234. .demod_address = 0x0e,
  235. .demod_chip = LGDT3303,
  236. };
  237. static struct lgdt3305_config em2870_lgdt3304_dev = {
  238. .i2c_addr = 0x0e,
  239. .demod_chip = LGDT3304,
  240. .spectral_inversion = 1,
  241. .deny_i2c_rptr = 1,
  242. .mpeg_mode = LGDT3305_MPEG_PARALLEL,
  243. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  244. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  245. .vsb_if_khz = 3250,
  246. .qam_if_khz = 4000,
  247. };
  248. static struct lgdt3305_config em2874_lgdt3305_dev = {
  249. .i2c_addr = 0x0e,
  250. .demod_chip = LGDT3305,
  251. .spectral_inversion = 1,
  252. .deny_i2c_rptr = 0,
  253. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  254. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  255. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  256. .vsb_if_khz = 3250,
  257. .qam_if_khz = 4000,
  258. };
  259. static struct s921_config sharp_isdbt = {
  260. .demod_address = 0x30 >> 1
  261. };
  262. static struct zl10353_config em28xx_zl10353_with_xc3028 = {
  263. .demod_address = (0x1e >> 1),
  264. .no_tuner = 1,
  265. .parallel_ts = 1,
  266. .if2 = 45600,
  267. };
  268. static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
  269. .demod_address = 0x32 >> 1,
  270. .output_mode = S5H1409_PARALLEL_OUTPUT,
  271. .gpio = S5H1409_GPIO_OFF,
  272. .inversion = S5H1409_INVERSION_OFF,
  273. .status_mode = S5H1409_DEMODLOCKING,
  274. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
  275. };
  276. static struct tda18271_std_map kworld_a340_std_map = {
  277. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
  278. .if_lvl = 1, .rfagc_top = 0x37, },
  279. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
  280. .if_lvl = 1, .rfagc_top = 0x37, },
  281. };
  282. static struct tda18271_config kworld_a340_config = {
  283. .std_map = &kworld_a340_std_map,
  284. };
  285. static struct tda18271_config kworld_ub435q_v2_config = {
  286. .std_map = &kworld_a340_std_map,
  287. .gate = TDA18271_GATE_DIGITAL,
  288. };
  289. static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
  290. .demod_address = (0x1e >> 1),
  291. .no_tuner = 1,
  292. .disable_i2c_gate_ctrl = 1,
  293. .parallel_ts = 1,
  294. .if2 = 45600,
  295. };
  296. static struct drxd_config em28xx_drxd = {
  297. .demod_address = 0x70,
  298. .demod_revision = 0xa2,
  299. .pll_type = DRXD_PLL_NONE,
  300. .clock = 12000,
  301. .insert_rs_byte = 1,
  302. .IF = 42800000,
  303. .disable_i2c_gate_ctrl = 1,
  304. };
  305. static struct drxk_config terratec_h5_drxk = {
  306. .adr = 0x29,
  307. .single_master = 1,
  308. .no_i2c_bridge = 1,
  309. .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
  310. .qam_demod_parameter_count = 2,
  311. .load_firmware_sync = true,
  312. };
  313. static struct drxk_config hauppauge_930c_drxk = {
  314. .adr = 0x29,
  315. .single_master = 1,
  316. .no_i2c_bridge = 1,
  317. .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
  318. .chunk_size = 56,
  319. .qam_demod_parameter_count = 2,
  320. .load_firmware_sync = true,
  321. };
  322. static struct drxk_config terratec_htc_stick_drxk = {
  323. .adr = 0x29,
  324. .single_master = 1,
  325. .no_i2c_bridge = 1,
  326. .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
  327. .chunk_size = 54,
  328. .qam_demod_parameter_count = 2,
  329. /* Required for the antenna_gpio to disable LNA. */
  330. .antenna_dvbt = true,
  331. /* The windows driver uses the same. This will disable LNA. */
  332. .antenna_gpio = 0x6,
  333. .load_firmware_sync = true,
  334. };
  335. static struct drxk_config maxmedia_ub425_tc_drxk = {
  336. .adr = 0x29,
  337. .single_master = 1,
  338. .no_i2c_bridge = 1,
  339. .microcode_name = "dvb-demod-drxk-01.fw",
  340. .chunk_size = 62,
  341. .load_firmware_sync = true,
  342. .qam_demod_parameter_count = 2,
  343. };
  344. static struct drxk_config pctv_520e_drxk = {
  345. .adr = 0x29,
  346. .single_master = 1,
  347. .microcode_name = "dvb-demod-drxk-pctv.fw",
  348. .qam_demod_parameter_count = 2,
  349. .chunk_size = 58,
  350. .antenna_dvbt = true, /* disable LNA */
  351. .antenna_gpio = (1 << 2), /* disable LNA */
  352. .load_firmware_sync = true,
  353. };
  354. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  355. {
  356. struct em28xx_dvb *dvb = fe->sec_priv;
  357. int status;
  358. if (!dvb)
  359. return -EINVAL;
  360. if (enable) {
  361. down(&dvb->pll_mutex);
  362. status = dvb->gate_ctrl(fe, 1);
  363. } else {
  364. status = dvb->gate_ctrl(fe, 0);
  365. up(&dvb->pll_mutex);
  366. }
  367. return status;
  368. }
  369. static void hauppauge_hvr930c_init(struct em28xx *dev)
  370. {
  371. int i;
  372. struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
  373. {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
  374. {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
  375. {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
  376. { -1, -1, -1, -1},
  377. };
  378. struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
  379. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
  380. {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
  381. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
  382. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
  383. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
  384. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
  385. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
  386. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
  387. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
  388. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
  389. { -1, -1, -1, -1},
  390. };
  391. struct {
  392. unsigned char r[4];
  393. int len;
  394. } regs[] = {
  395. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  396. {{ 0x01, 0x02 }, 2},
  397. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  398. {{ 0x01, 0x00 }, 2},
  399. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  400. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  401. {{ 0x01, 0x00 }, 2},
  402. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  403. {{ 0x04, 0x00 }, 2},
  404. {{ 0x00, 0x04 }, 2},
  405. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  406. {{ 0x04, 0x14 }, 2},
  407. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  408. };
  409. em28xx_gpio_set(dev, hauppauge_hvr930c_init);
  410. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  411. msleep(10);
  412. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  413. msleep(10);
  414. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  415. for (i = 0; i < ARRAY_SIZE(regs); i++)
  416. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  417. em28xx_gpio_set(dev, hauppauge_hvr930c_end);
  418. msleep(100);
  419. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  420. msleep(30);
  421. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
  422. msleep(10);
  423. }
  424. static void terratec_h5_init(struct em28xx *dev)
  425. {
  426. int i;
  427. struct em28xx_reg_seq terratec_h5_init[] = {
  428. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  429. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  430. {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
  431. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  432. { -1, -1, -1, -1},
  433. };
  434. struct em28xx_reg_seq terratec_h5_end[] = {
  435. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  436. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
  437. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  438. { -1, -1, -1, -1},
  439. };
  440. struct {
  441. unsigned char r[4];
  442. int len;
  443. } regs[] = {
  444. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  445. {{ 0x01, 0x02 }, 2},
  446. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  447. {{ 0x01, 0x00 }, 2},
  448. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  449. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  450. {{ 0x01, 0x00 }, 2},
  451. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  452. {{ 0x04, 0x00 }, 2},
  453. {{ 0x00, 0x04 }, 2},
  454. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  455. {{ 0x04, 0x14 }, 2},
  456. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  457. };
  458. em28xx_gpio_set(dev, terratec_h5_init);
  459. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  460. msleep(10);
  461. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
  462. msleep(10);
  463. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  464. for (i = 0; i < ARRAY_SIZE(regs); i++)
  465. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  466. em28xx_gpio_set(dev, terratec_h5_end);
  467. };
  468. static void terratec_htc_stick_init(struct em28xx *dev)
  469. {
  470. int i;
  471. /*
  472. * GPIO configuration:
  473. * 0xff: unknown (does not affect DVB-T).
  474. * 0xf6: DRX-K (demodulator).
  475. * 0xe6: unknown (does not affect DVB-T).
  476. * 0xb6: unknown (does not affect DVB-T).
  477. */
  478. struct em28xx_reg_seq terratec_htc_stick_init[] = {
  479. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  480. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  481. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
  482. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  483. { -1, -1, -1, -1},
  484. };
  485. struct em28xx_reg_seq terratec_htc_stick_end[] = {
  486. {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
  487. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
  488. { -1, -1, -1, -1},
  489. };
  490. /*
  491. * Init the analog decoder (not yet supported), but
  492. * it's probably still a good idea.
  493. */
  494. struct {
  495. unsigned char r[4];
  496. int len;
  497. } regs[] = {
  498. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  499. {{ 0x01, 0x02 }, 2},
  500. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  501. {{ 0x01, 0x00 }, 2},
  502. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  503. };
  504. em28xx_gpio_set(dev, terratec_htc_stick_init);
  505. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  506. msleep(10);
  507. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  508. msleep(10);
  509. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  510. for (i = 0; i < ARRAY_SIZE(regs); i++)
  511. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  512. em28xx_gpio_set(dev, terratec_htc_stick_end);
  513. };
  514. static void terratec_htc_usb_xs_init(struct em28xx *dev)
  515. {
  516. int i;
  517. struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
  518. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  519. {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
  520. {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
  521. {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
  522. { -1, -1, -1, -1},
  523. };
  524. struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
  525. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
  526. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
  527. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  528. { -1, -1, -1, -1},
  529. };
  530. /*
  531. * Init the analog decoder (not yet supported), but
  532. * it's probably still a good idea.
  533. */
  534. struct {
  535. unsigned char r[4];
  536. int len;
  537. } regs[] = {
  538. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  539. {{ 0x01, 0x02 }, 2},
  540. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  541. {{ 0x01, 0x00 }, 2},
  542. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  543. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  544. {{ 0x01, 0x00 }, 2},
  545. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  546. {{ 0x04, 0x00 }, 2},
  547. {{ 0x00, 0x04 }, 2},
  548. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  549. {{ 0x04, 0x14 }, 2},
  550. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  551. };
  552. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  553. em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
  554. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  555. msleep(10);
  556. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  557. msleep(10);
  558. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  559. for (i = 0; i < ARRAY_SIZE(regs); i++)
  560. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  561. em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
  562. };
  563. static void pctv_520e_init(struct em28xx *dev)
  564. {
  565. /*
  566. * Init AVF4910B analog decoder. Looks like I2C traffic to
  567. * digital demodulator and tuner are routed via AVF4910B.
  568. */
  569. int i;
  570. struct {
  571. unsigned char r[4];
  572. int len;
  573. } regs[] = {
  574. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  575. {{ 0x01, 0x02 }, 2},
  576. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  577. {{ 0x01, 0x00 }, 2},
  578. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  579. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  580. {{ 0x01, 0x00 }, 2},
  581. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  582. };
  583. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
  584. for (i = 0; i < ARRAY_SIZE(regs); i++)
  585. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  586. };
  587. static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
  588. {
  589. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  590. struct em28xx *dev = fe->dvb->priv;
  591. #ifdef CONFIG_GPIOLIB
  592. struct em28xx_dvb *dvb = dev->dvb;
  593. int ret;
  594. unsigned long flags;
  595. if (c->lna == 1)
  596. flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
  597. else
  598. flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
  599. ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
  600. if (ret)
  601. em28xx_errdev("gpio request failed %d\n", ret);
  602. else
  603. gpio_free(dvb->lna_gpio);
  604. return ret;
  605. #else
  606. dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
  607. KBUILD_MODNAME, c->lna);
  608. return 0;
  609. #endif
  610. }
  611. static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
  612. {
  613. /* Values extracted from a USB trace of the Terratec Windows driver */
  614. static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
  615. static u8 reset[] = { RESET, 0x80 };
  616. static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
  617. static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
  618. static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
  619. static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
  620. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  621. static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
  622. static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
  623. static u8 tuner_go[] = { TUNER_GO, 0x01};
  624. mt352_write(fe, clock_config, sizeof(clock_config));
  625. udelay(200);
  626. mt352_write(fe, reset, sizeof(reset));
  627. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  628. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  629. mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
  630. mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
  631. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  632. mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
  633. mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
  634. mt352_write(fe, tuner_go, sizeof(tuner_go));
  635. return 0;
  636. }
  637. static struct mt352_config terratec_xs_mt352_cfg = {
  638. .demod_address = (0x1e >> 1),
  639. .no_tuner = 1,
  640. .if2 = 45600,
  641. .demod_init = em28xx_mt352_terratec_xs_init,
  642. };
  643. static struct tda10023_config em28xx_tda10023_config = {
  644. .demod_address = 0x0c,
  645. .invert = 1,
  646. };
  647. static struct cxd2820r_config em28xx_cxd2820r_config = {
  648. .i2c_address = (0xd8 >> 1),
  649. .ts_mode = CXD2820R_TS_SERIAL,
  650. };
  651. static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
  652. .output_opt = TDA18271_OUTPUT_LT_OFF,
  653. .gate = TDA18271_GATE_DIGITAL,
  654. };
  655. static const struct tda10071_config em28xx_tda10071_config = {
  656. .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
  657. .tuner_i2c_addr = 0x14,
  658. .i2c_wr_max = 64,
  659. .ts_mode = TDA10071_TS_SERIAL,
  660. .spec_inv = 0,
  661. .xtal = 40444000, /* 40.444 MHz */
  662. .pll_multiplier = 20,
  663. };
  664. static const struct a8293_config em28xx_a8293_config = {
  665. .i2c_addr = 0x08, /* (0x10 >> 1) */
  666. };
  667. static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
  668. .demod_address = (0x1e >> 1),
  669. .disable_i2c_gate_ctrl = 1,
  670. .no_tuner = 1,
  671. .parallel_ts = 1,
  672. };
  673. static struct qt1010_config em28xx_qt1010_config = {
  674. .i2c_address = 0x62
  675. };
  676. static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
  677. .demod_address = 0x10,
  678. .is_serial = true,
  679. };
  680. static struct tda18271_std_map mb86a20s_tda18271_config = {
  681. .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
  682. .if_lvl = 1, .rfagc_top = 0x37, },
  683. };
  684. static struct tda18271_config c3tech_duo_tda18271_config = {
  685. .std_map = &mb86a20s_tda18271_config,
  686. .gate = TDA18271_GATE_DIGITAL,
  687. .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
  688. };
  689. /* ------------------------------------------------------------------ */
  690. static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
  691. {
  692. struct dvb_frontend *fe;
  693. struct xc2028_config cfg;
  694. memset(&cfg, 0, sizeof(cfg));
  695. cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
  696. cfg.i2c_addr = addr;
  697. if (!dev->dvb->fe[0]) {
  698. em28xx_errdev("/2: dvb frontend not attached. "
  699. "Can't attach xc3028\n");
  700. return -EINVAL;
  701. }
  702. fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
  703. if (!fe) {
  704. em28xx_errdev("/2: xc3028 attach failed\n");
  705. dvb_frontend_detach(dev->dvb->fe[0]);
  706. dev->dvb->fe[0] = NULL;
  707. return -EINVAL;
  708. }
  709. em28xx_info("%s/2: xc3028 attached\n", dev->name);
  710. return 0;
  711. }
  712. /* ------------------------------------------------------------------ */
  713. static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
  714. struct em28xx *dev, struct device *device)
  715. {
  716. int result;
  717. mutex_init(&dvb->lock);
  718. /* register adapter */
  719. result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
  720. adapter_nr);
  721. if (result < 0) {
  722. printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
  723. dev->name, result);
  724. goto fail_adapter;
  725. }
  726. /* Ensure all frontends negotiate bus access */
  727. dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  728. if (dvb->fe[1])
  729. dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  730. dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
  731. /* register frontend */
  732. result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
  733. if (result < 0) {
  734. printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
  735. dev->name, result);
  736. goto fail_frontend0;
  737. }
  738. /* register 2nd frontend */
  739. if (dvb->fe[1]) {
  740. result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
  741. if (result < 0) {
  742. printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
  743. dev->name, result);
  744. goto fail_frontend1;
  745. }
  746. }
  747. /* register demux stuff */
  748. dvb->demux.dmx.capabilities =
  749. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  750. DMX_MEMORY_BASED_FILTERING;
  751. dvb->demux.priv = dvb;
  752. dvb->demux.filternum = 256;
  753. dvb->demux.feednum = 256;
  754. dvb->demux.start_feed = em28xx_start_feed;
  755. dvb->demux.stop_feed = em28xx_stop_feed;
  756. result = dvb_dmx_init(&dvb->demux);
  757. if (result < 0) {
  758. printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
  759. dev->name, result);
  760. goto fail_dmx;
  761. }
  762. dvb->dmxdev.filternum = 256;
  763. dvb->dmxdev.demux = &dvb->demux.dmx;
  764. dvb->dmxdev.capabilities = 0;
  765. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  766. if (result < 0) {
  767. printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
  768. dev->name, result);
  769. goto fail_dmxdev;
  770. }
  771. dvb->fe_hw.source = DMX_FRONTEND_0;
  772. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  773. if (result < 0) {
  774. printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  775. dev->name, result);
  776. goto fail_fe_hw;
  777. }
  778. dvb->fe_mem.source = DMX_MEMORY_FE;
  779. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  780. if (result < 0) {
  781. printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  782. dev->name, result);
  783. goto fail_fe_mem;
  784. }
  785. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  786. if (result < 0) {
  787. printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
  788. dev->name, result);
  789. goto fail_fe_conn;
  790. }
  791. /* register network adapter */
  792. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  793. return 0;
  794. fail_fe_conn:
  795. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  796. fail_fe_mem:
  797. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  798. fail_fe_hw:
  799. dvb_dmxdev_release(&dvb->dmxdev);
  800. fail_dmxdev:
  801. dvb_dmx_release(&dvb->demux);
  802. fail_dmx:
  803. if (dvb->fe[1])
  804. dvb_unregister_frontend(dvb->fe[1]);
  805. dvb_unregister_frontend(dvb->fe[0]);
  806. fail_frontend1:
  807. if (dvb->fe[1])
  808. dvb_frontend_detach(dvb->fe[1]);
  809. fail_frontend0:
  810. dvb_frontend_detach(dvb->fe[0]);
  811. dvb_unregister_adapter(&dvb->adapter);
  812. fail_adapter:
  813. return result;
  814. }
  815. static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
  816. {
  817. dvb_net_release(&dvb->net);
  818. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  819. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  820. dvb_dmxdev_release(&dvb->dmxdev);
  821. dvb_dmx_release(&dvb->demux);
  822. if (dvb->fe[1])
  823. dvb_unregister_frontend(dvb->fe[1]);
  824. dvb_unregister_frontend(dvb->fe[0]);
  825. if (dvb->fe[1] && !dvb->dont_attach_fe1)
  826. dvb_frontend_detach(dvb->fe[1]);
  827. dvb_frontend_detach(dvb->fe[0]);
  828. dvb_unregister_adapter(&dvb->adapter);
  829. }
  830. static int em28xx_dvb_init(struct em28xx *dev)
  831. {
  832. int result = 0, mfe_shared = 0;
  833. struct em28xx_dvb *dvb;
  834. if (!dev->board.has_dvb) {
  835. /* This device does not support the extension */
  836. printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
  837. return 0;
  838. }
  839. dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
  840. if (dvb == NULL) {
  841. em28xx_info("em28xx_dvb: memory allocation failed\n");
  842. return -ENOMEM;
  843. }
  844. dev->dvb = dvb;
  845. dvb->fe[0] = dvb->fe[1] = NULL;
  846. mutex_lock(&dev->lock);
  847. em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  848. /* init frontend */
  849. switch (dev->model) {
  850. case EM2874_BOARD_LEADERSHIP_ISDBT:
  851. dvb->fe[0] = dvb_attach(s921_attach,
  852. &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
  853. if (!dvb->fe[0]) {
  854. result = -EINVAL;
  855. goto out_free;
  856. }
  857. break;
  858. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
  859. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
  860. case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
  861. case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
  862. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  863. &em2880_lgdt3303_dev,
  864. &dev->i2c_adap[dev->def_i2c_bus]);
  865. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  866. result = -EINVAL;
  867. goto out_free;
  868. }
  869. break;
  870. case EM2880_BOARD_KWORLD_DVB_310U:
  871. dvb->fe[0] = dvb_attach(zl10353_attach,
  872. &em28xx_zl10353_with_xc3028,
  873. &dev->i2c_adap[dev->def_i2c_bus]);
  874. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  875. result = -EINVAL;
  876. goto out_free;
  877. }
  878. break;
  879. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  880. case EM2882_BOARD_TERRATEC_HYBRID_XS:
  881. case EM2880_BOARD_EMPIRE_DUAL_TV:
  882. dvb->fe[0] = dvb_attach(zl10353_attach,
  883. &em28xx_zl10353_xc3028_no_i2c_gate,
  884. &dev->i2c_adap[dev->def_i2c_bus]);
  885. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  886. result = -EINVAL;
  887. goto out_free;
  888. }
  889. break;
  890. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  891. case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
  892. case EM2881_BOARD_PINNACLE_HYBRID_PRO:
  893. case EM2882_BOARD_DIKOM_DK300:
  894. case EM2882_BOARD_KWORLD_VS_DVBT:
  895. dvb->fe[0] = dvb_attach(zl10353_attach,
  896. &em28xx_zl10353_xc3028_no_i2c_gate,
  897. &dev->i2c_adap[dev->def_i2c_bus]);
  898. if (dvb->fe[0] == NULL) {
  899. /* This board could have either a zl10353 or a mt352.
  900. If the chip id isn't for zl10353, try mt352 */
  901. dvb->fe[0] = dvb_attach(mt352_attach,
  902. &terratec_xs_mt352_cfg,
  903. &dev->i2c_adap[dev->def_i2c_bus]);
  904. }
  905. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  906. result = -EINVAL;
  907. goto out_free;
  908. }
  909. break;
  910. case EM2870_BOARD_KWORLD_355U:
  911. dvb->fe[0] = dvb_attach(zl10353_attach,
  912. &em28xx_zl10353_no_i2c_gate_dev,
  913. &dev->i2c_adap[dev->def_i2c_bus]);
  914. if (dvb->fe[0] != NULL)
  915. dvb_attach(qt1010_attach, dvb->fe[0],
  916. &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
  917. break;
  918. case EM2883_BOARD_KWORLD_HYBRID_330U:
  919. case EM2882_BOARD_EVGA_INDTUBE:
  920. dvb->fe[0] = dvb_attach(s5h1409_attach,
  921. &em28xx_s5h1409_with_xc3028,
  922. &dev->i2c_adap[dev->def_i2c_bus]);
  923. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  924. result = -EINVAL;
  925. goto out_free;
  926. }
  927. break;
  928. case EM2882_BOARD_KWORLD_ATSC_315U:
  929. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  930. &em2880_lgdt3303_dev,
  931. &dev->i2c_adap[dev->def_i2c_bus]);
  932. if (dvb->fe[0] != NULL) {
  933. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  934. &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
  935. result = -EINVAL;
  936. goto out_free;
  937. }
  938. }
  939. break;
  940. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
  941. case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
  942. dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
  943. &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
  944. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  945. result = -EINVAL;
  946. goto out_free;
  947. }
  948. break;
  949. case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
  950. /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
  951. dvb->fe[0] = dvb_attach(tda10023_attach,
  952. &em28xx_tda10023_config,
  953. &dev->i2c_adap[dev->def_i2c_bus], 0x48);
  954. if (dvb->fe[0]) {
  955. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  956. &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
  957. result = -EINVAL;
  958. goto out_free;
  959. }
  960. }
  961. break;
  962. case EM2870_BOARD_KWORLD_A340:
  963. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  964. &em2870_lgdt3304_dev,
  965. &dev->i2c_adap[dev->def_i2c_bus]);
  966. if (dvb->fe[0] != NULL)
  967. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  968. &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
  969. break;
  970. case EM28174_BOARD_PCTV_290E:
  971. /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
  972. dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
  973. CXD2820R_GPIO_L;
  974. dvb->fe[0] = dvb_attach(cxd2820r_attach,
  975. &em28xx_cxd2820r_config,
  976. &dev->i2c_adap[dev->def_i2c_bus],
  977. &dvb->lna_gpio);
  978. if (dvb->fe[0]) {
  979. /* FE 0 attach tuner */
  980. if (!dvb_attach(tda18271_attach,
  981. dvb->fe[0],
  982. 0x60,
  983. &dev->i2c_adap[dev->def_i2c_bus],
  984. &em28xx_cxd2820r_tda18271_config)) {
  985. dvb_frontend_detach(dvb->fe[0]);
  986. result = -EINVAL;
  987. goto out_free;
  988. }
  989. #ifdef CONFIG_GPIOLIB
  990. /* enable LNA for DVB-T, DVB-T2 and DVB-C */
  991. result = gpio_request_one(dvb->lna_gpio,
  992. GPIOF_OUT_INIT_LOW, NULL);
  993. if (result)
  994. em28xx_errdev("gpio request failed %d\n",
  995. result);
  996. else
  997. gpio_free(dvb->lna_gpio);
  998. result = 0; /* continue even set LNA fails */
  999. #endif
  1000. dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
  1001. }
  1002. break;
  1003. case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
  1004. {
  1005. struct xc5000_config cfg;
  1006. hauppauge_hvr930c_init(dev);
  1007. dvb->fe[0] = dvb_attach(drxk_attach,
  1008. &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
  1009. if (!dvb->fe[0]) {
  1010. result = -EINVAL;
  1011. goto out_free;
  1012. }
  1013. /* FIXME: do we need a pll semaphore? */
  1014. dvb->fe[0]->sec_priv = dvb;
  1015. sema_init(&dvb->pll_mutex, 1);
  1016. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  1017. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  1018. /* Attach xc5000 */
  1019. memset(&cfg, 0, sizeof(cfg));
  1020. cfg.i2c_address = 0x61;
  1021. cfg.if_khz = 4000;
  1022. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1023. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  1024. if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
  1025. &cfg)) {
  1026. result = -EINVAL;
  1027. goto out_free;
  1028. }
  1029. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1030. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  1031. break;
  1032. }
  1033. case EM2884_BOARD_TERRATEC_H5:
  1034. terratec_h5_init(dev);
  1035. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
  1036. if (!dvb->fe[0]) {
  1037. result = -EINVAL;
  1038. goto out_free;
  1039. }
  1040. /* FIXME: do we need a pll semaphore? */
  1041. dvb->fe[0]->sec_priv = dvb;
  1042. sema_init(&dvb->pll_mutex, 1);
  1043. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  1044. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  1045. /* Attach tda18271 to DVB-C frontend */
  1046. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1047. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  1048. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
  1049. result = -EINVAL;
  1050. goto out_free;
  1051. }
  1052. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1053. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  1054. break;
  1055. case EM2884_BOARD_C3TECH_DIGITAL_DUO:
  1056. dvb->fe[0] = dvb_attach(mb86a20s_attach,
  1057. &c3tech_duo_mb86a20s_config,
  1058. &dev->i2c_adap[dev->def_i2c_bus]);
  1059. if (dvb->fe[0] != NULL)
  1060. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1061. &dev->i2c_adap[dev->def_i2c_bus],
  1062. &c3tech_duo_tda18271_config);
  1063. break;
  1064. case EM28174_BOARD_PCTV_460E:
  1065. /* attach demod */
  1066. dvb->fe[0] = dvb_attach(tda10071_attach,
  1067. &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
  1068. /* attach SEC */
  1069. if (dvb->fe[0])
  1070. dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
  1071. &em28xx_a8293_config);
  1072. break;
  1073. case EM2874_BOARD_DELOCK_61959:
  1074. case EM2874_BOARD_MAXMEDIA_UB425_TC:
  1075. /* attach demodulator */
  1076. dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
  1077. &dev->i2c_adap[dev->def_i2c_bus]);
  1078. if (dvb->fe[0]) {
  1079. /* disable I2C-gate */
  1080. dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
  1081. /* attach tuner */
  1082. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1083. &dev->i2c_adap[dev->def_i2c_bus],
  1084. &em28xx_cxd2820r_tda18271_config)) {
  1085. dvb_frontend_detach(dvb->fe[0]);
  1086. result = -EINVAL;
  1087. goto out_free;
  1088. }
  1089. }
  1090. break;
  1091. case EM2884_BOARD_PCTV_510E:
  1092. case EM2884_BOARD_PCTV_520E:
  1093. pctv_520e_init(dev);
  1094. /* attach demodulator */
  1095. dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
  1096. &dev->i2c_adap[dev->def_i2c_bus]);
  1097. if (dvb->fe[0]) {
  1098. /* attach tuner */
  1099. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1100. &dev->i2c_adap[dev->def_i2c_bus],
  1101. &em28xx_cxd2820r_tda18271_config)) {
  1102. dvb_frontend_detach(dvb->fe[0]);
  1103. result = -EINVAL;
  1104. goto out_free;
  1105. }
  1106. }
  1107. break;
  1108. case EM2884_BOARD_CINERGY_HTC_STICK:
  1109. terratec_htc_stick_init(dev);
  1110. /* attach demodulator */
  1111. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1112. &dev->i2c_adap[dev->def_i2c_bus]);
  1113. if (!dvb->fe[0]) {
  1114. result = -EINVAL;
  1115. goto out_free;
  1116. }
  1117. /* Attach the demodulator. */
  1118. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1119. &dev->i2c_adap[dev->def_i2c_bus],
  1120. &em28xx_cxd2820r_tda18271_config)) {
  1121. result = -EINVAL;
  1122. goto out_free;
  1123. }
  1124. break;
  1125. case EM2884_BOARD_TERRATEC_HTC_USB_XS:
  1126. terratec_htc_usb_xs_init(dev);
  1127. /* attach demodulator */
  1128. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1129. &dev->i2c_adap[dev->def_i2c_bus]);
  1130. if (!dvb->fe[0]) {
  1131. result = -EINVAL;
  1132. goto out_free;
  1133. }
  1134. /* Attach the demodulator. */
  1135. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1136. &dev->i2c_adap[dev->def_i2c_bus],
  1137. &em28xx_cxd2820r_tda18271_config)) {
  1138. result = -EINVAL;
  1139. goto out_free;
  1140. }
  1141. break;
  1142. case EM2874_BOARD_KWORLD_UB435Q_V2:
  1143. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  1144. &em2874_lgdt3305_dev,
  1145. &dev->i2c_adap[dev->def_i2c_bus]);
  1146. if (!dvb->fe[0]) {
  1147. result = -EINVAL;
  1148. goto out_free;
  1149. }
  1150. /* Attach the demodulator. */
  1151. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1152. &dev->i2c_adap[dev->def_i2c_bus],
  1153. &kworld_ub435q_v2_config)) {
  1154. result = -EINVAL;
  1155. goto out_free;
  1156. }
  1157. break;
  1158. default:
  1159. em28xx_errdev("/2: The frontend of your DVB/ATSC card"
  1160. " isn't supported yet\n");
  1161. break;
  1162. }
  1163. if (NULL == dvb->fe[0]) {
  1164. em28xx_errdev("/2: frontend initialization failed\n");
  1165. result = -EINVAL;
  1166. goto out_free;
  1167. }
  1168. /* define general-purpose callback pointer */
  1169. dvb->fe[0]->callback = em28xx_tuner_callback;
  1170. if (dvb->fe[1])
  1171. dvb->fe[1]->callback = em28xx_tuner_callback;
  1172. /* register everything */
  1173. result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
  1174. if (result < 0)
  1175. goto out_free;
  1176. /* MFE lock */
  1177. dvb->adapter.mfe_shared = mfe_shared;
  1178. em28xx_info("Successfully loaded em28xx-dvb\n");
  1179. ret:
  1180. em28xx_set_mode(dev, EM28XX_SUSPEND);
  1181. mutex_unlock(&dev->lock);
  1182. return result;
  1183. out_free:
  1184. kfree(dvb);
  1185. dev->dvb = NULL;
  1186. goto ret;
  1187. }
  1188. static inline void prevent_sleep(struct dvb_frontend_ops *ops)
  1189. {
  1190. ops->set_voltage = NULL;
  1191. ops->sleep = NULL;
  1192. ops->tuner_ops.sleep = NULL;
  1193. }
  1194. static int em28xx_dvb_fini(struct em28xx *dev)
  1195. {
  1196. if (!dev->board.has_dvb) {
  1197. /* This device does not support the extension */
  1198. return 0;
  1199. }
  1200. if (dev->dvb) {
  1201. struct em28xx_dvb *dvb = dev->dvb;
  1202. if (dev->disconnected) {
  1203. /* We cannot tell the device to sleep
  1204. * once it has been unplugged. */
  1205. if (dvb->fe[0])
  1206. prevent_sleep(&dvb->fe[0]->ops);
  1207. if (dvb->fe[1])
  1208. prevent_sleep(&dvb->fe[1]->ops);
  1209. }
  1210. em28xx_unregister_dvb(dvb);
  1211. kfree(dvb);
  1212. dev->dvb = NULL;
  1213. }
  1214. return 0;
  1215. }
  1216. static struct em28xx_ops dvb_ops = {
  1217. .id = EM28XX_DVB,
  1218. .name = "Em28xx dvb Extension",
  1219. .init = em28xx_dvb_init,
  1220. .fini = em28xx_dvb_fini,
  1221. };
  1222. static int __init em28xx_dvb_register(void)
  1223. {
  1224. return em28xx_register_extension(&dvb_ops);
  1225. }
  1226. static void __exit em28xx_dvb_unregister(void)
  1227. {
  1228. em28xx_unregister_extension(&dvb_ops);
  1229. }
  1230. module_init(em28xx_dvb_register);
  1231. module_exit(em28xx_dvb_unregister);