em28xx-dvb.c 33 KB

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