em28xx-dvb.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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 s921_config sharp_isdbt = {
  249. .demod_address = 0x30 >> 1
  250. };
  251. static struct zl10353_config em28xx_zl10353_with_xc3028 = {
  252. .demod_address = (0x1e >> 1),
  253. .no_tuner = 1,
  254. .parallel_ts = 1,
  255. .if2 = 45600,
  256. };
  257. static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
  258. .demod_address = 0x32 >> 1,
  259. .output_mode = S5H1409_PARALLEL_OUTPUT,
  260. .gpio = S5H1409_GPIO_OFF,
  261. .inversion = S5H1409_INVERSION_OFF,
  262. .status_mode = S5H1409_DEMODLOCKING,
  263. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
  264. };
  265. static struct tda18271_std_map kworld_a340_std_map = {
  266. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
  267. .if_lvl = 1, .rfagc_top = 0x37, },
  268. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
  269. .if_lvl = 1, .rfagc_top = 0x37, },
  270. };
  271. static struct tda18271_config kworld_a340_config = {
  272. .std_map = &kworld_a340_std_map,
  273. };
  274. static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
  275. .demod_address = (0x1e >> 1),
  276. .no_tuner = 1,
  277. .disable_i2c_gate_ctrl = 1,
  278. .parallel_ts = 1,
  279. .if2 = 45600,
  280. };
  281. static struct drxd_config em28xx_drxd = {
  282. .demod_address = 0x70,
  283. .demod_revision = 0xa2,
  284. .pll_type = DRXD_PLL_NONE,
  285. .clock = 12000,
  286. .insert_rs_byte = 1,
  287. .IF = 42800000,
  288. .disable_i2c_gate_ctrl = 1,
  289. };
  290. static struct drxk_config terratec_h5_drxk = {
  291. .adr = 0x29,
  292. .single_master = 1,
  293. .no_i2c_bridge = 1,
  294. .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
  295. .qam_demod_parameter_count = 2,
  296. .load_firmware_sync = true,
  297. };
  298. static struct drxk_config hauppauge_930c_drxk = {
  299. .adr = 0x29,
  300. .single_master = 1,
  301. .no_i2c_bridge = 1,
  302. .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
  303. .chunk_size = 56,
  304. .qam_demod_parameter_count = 2,
  305. .load_firmware_sync = true,
  306. };
  307. static struct drxk_config terratec_htc_stick_drxk = {
  308. .adr = 0x29,
  309. .single_master = 1,
  310. .no_i2c_bridge = 1,
  311. .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
  312. .chunk_size = 54,
  313. .qam_demod_parameter_count = 2,
  314. /* Required for the antenna_gpio to disable LNA. */
  315. .antenna_dvbt = true,
  316. /* The windows driver uses the same. This will disable LNA. */
  317. .antenna_gpio = 0x6,
  318. .load_firmware_sync = true,
  319. };
  320. static struct drxk_config maxmedia_ub425_tc_drxk = {
  321. .adr = 0x29,
  322. .single_master = 1,
  323. .no_i2c_bridge = 1,
  324. .load_firmware_sync = true,
  325. };
  326. static struct drxk_config pctv_520e_drxk = {
  327. .adr = 0x29,
  328. .single_master = 1,
  329. .microcode_name = "dvb-demod-drxk-pctv.fw",
  330. .qam_demod_parameter_count = 2,
  331. .chunk_size = 58,
  332. .antenna_dvbt = true, /* disable LNA */
  333. .antenna_gpio = (1 << 2), /* disable LNA */
  334. .load_firmware_sync = true,
  335. };
  336. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  337. {
  338. struct em28xx_dvb *dvb = fe->sec_priv;
  339. int status;
  340. if (!dvb)
  341. return -EINVAL;
  342. if (enable) {
  343. down(&dvb->pll_mutex);
  344. status = dvb->gate_ctrl(fe, 1);
  345. } else {
  346. status = dvb->gate_ctrl(fe, 0);
  347. up(&dvb->pll_mutex);
  348. }
  349. return status;
  350. }
  351. static void hauppauge_hvr930c_init(struct em28xx *dev)
  352. {
  353. int i;
  354. struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
  355. {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
  356. {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
  357. {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
  358. { -1, -1, -1, -1},
  359. };
  360. struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
  361. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
  362. {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
  363. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
  364. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
  365. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
  366. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
  367. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
  368. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
  369. {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
  370. {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
  371. { -1, -1, -1, -1},
  372. };
  373. struct {
  374. unsigned char r[4];
  375. int len;
  376. } regs[] = {
  377. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  378. {{ 0x01, 0x02 }, 2},
  379. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  380. {{ 0x01, 0x00 }, 2},
  381. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  382. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  383. {{ 0x01, 0x00 }, 2},
  384. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  385. {{ 0x04, 0x00 }, 2},
  386. {{ 0x00, 0x04 }, 2},
  387. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  388. {{ 0x04, 0x14 }, 2},
  389. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  390. };
  391. em28xx_gpio_set(dev, hauppauge_hvr930c_init);
  392. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  393. msleep(10);
  394. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  395. msleep(10);
  396. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  397. for (i = 0; i < ARRAY_SIZE(regs); i++)
  398. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  399. em28xx_gpio_set(dev, hauppauge_hvr930c_end);
  400. msleep(100);
  401. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  402. msleep(30);
  403. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
  404. msleep(10);
  405. }
  406. static void terratec_h5_init(struct em28xx *dev)
  407. {
  408. int i;
  409. struct em28xx_reg_seq terratec_h5_init[] = {
  410. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  411. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  412. {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
  413. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  414. { -1, -1, -1, -1},
  415. };
  416. struct em28xx_reg_seq terratec_h5_end[] = {
  417. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  418. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
  419. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  420. { -1, -1, -1, -1},
  421. };
  422. struct {
  423. unsigned char r[4];
  424. int len;
  425. } regs[] = {
  426. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  427. {{ 0x01, 0x02 }, 2},
  428. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  429. {{ 0x01, 0x00 }, 2},
  430. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  431. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  432. {{ 0x01, 0x00 }, 2},
  433. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  434. {{ 0x04, 0x00 }, 2},
  435. {{ 0x00, 0x04 }, 2},
  436. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  437. {{ 0x04, 0x14 }, 2},
  438. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  439. };
  440. em28xx_gpio_set(dev, terratec_h5_init);
  441. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  442. msleep(10);
  443. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
  444. msleep(10);
  445. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  446. for (i = 0; i < ARRAY_SIZE(regs); i++)
  447. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  448. em28xx_gpio_set(dev, terratec_h5_end);
  449. };
  450. static void terratec_htc_stick_init(struct em28xx *dev)
  451. {
  452. int i;
  453. /*
  454. * GPIO configuration:
  455. * 0xff: unknown (does not affect DVB-T).
  456. * 0xf6: DRX-K (demodulator).
  457. * 0xe6: unknown (does not affect DVB-T).
  458. * 0xb6: unknown (does not affect DVB-T).
  459. */
  460. struct em28xx_reg_seq terratec_htc_stick_init[] = {
  461. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  462. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  463. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
  464. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
  465. { -1, -1, -1, -1},
  466. };
  467. struct em28xx_reg_seq terratec_htc_stick_end[] = {
  468. {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
  469. {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
  470. { -1, -1, -1, -1},
  471. };
  472. /*
  473. * Init the analog decoder (not yet supported), but
  474. * it's probably still a good idea.
  475. */
  476. struct {
  477. unsigned char r[4];
  478. int len;
  479. } regs[] = {
  480. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  481. {{ 0x01, 0x02 }, 2},
  482. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  483. {{ 0x01, 0x00 }, 2},
  484. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  485. };
  486. em28xx_gpio_set(dev, terratec_htc_stick_init);
  487. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  488. msleep(10);
  489. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  490. msleep(10);
  491. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  492. for (i = 0; i < ARRAY_SIZE(regs); i++)
  493. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  494. em28xx_gpio_set(dev, terratec_htc_stick_end);
  495. };
  496. static void terratec_htc_usb_xs_init(struct em28xx *dev)
  497. {
  498. int i;
  499. struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
  500. {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
  501. {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
  502. {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
  503. {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
  504. { -1, -1, -1, -1},
  505. };
  506. struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
  507. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
  508. {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
  509. {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
  510. { -1, -1, -1, -1},
  511. };
  512. /*
  513. * Init the analog decoder (not yet supported), but
  514. * it's probably still a good idea.
  515. */
  516. struct {
  517. unsigned char r[4];
  518. int len;
  519. } regs[] = {
  520. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  521. {{ 0x01, 0x02 }, 2},
  522. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  523. {{ 0x01, 0x00 }, 2},
  524. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  525. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  526. {{ 0x01, 0x00 }, 2},
  527. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  528. {{ 0x04, 0x00 }, 2},
  529. {{ 0x00, 0x04 }, 2},
  530. {{ 0x00, 0x04, 0x00, 0x0a }, 4},
  531. {{ 0x04, 0x14 }, 2},
  532. {{ 0x04, 0x14, 0x00, 0x00 }, 4},
  533. };
  534. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  535. em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
  536. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
  537. msleep(10);
  538. em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
  539. msleep(10);
  540. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
  541. for (i = 0; i < ARRAY_SIZE(regs); i++)
  542. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  543. em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
  544. };
  545. static void pctv_520e_init(struct em28xx *dev)
  546. {
  547. /*
  548. * Init AVF4910B analog decoder. Looks like I2C traffic to
  549. * digital demodulator and tuner are routed via AVF4910B.
  550. */
  551. int i;
  552. struct {
  553. unsigned char r[4];
  554. int len;
  555. } regs[] = {
  556. {{ 0x06, 0x02, 0x00, 0x31 }, 4},
  557. {{ 0x01, 0x02 }, 2},
  558. {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
  559. {{ 0x01, 0x00 }, 2},
  560. {{ 0x01, 0x00, 0xff, 0xaf }, 4},
  561. {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
  562. {{ 0x01, 0x00 }, 2},
  563. {{ 0x01, 0x00, 0x73, 0xaf }, 4},
  564. };
  565. dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
  566. for (i = 0; i < ARRAY_SIZE(regs); i++)
  567. i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
  568. };
  569. static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
  570. {
  571. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  572. struct em28xx *dev = fe->dvb->priv;
  573. #ifdef CONFIG_GPIOLIB
  574. struct em28xx_dvb *dvb = dev->dvb;
  575. int ret;
  576. unsigned long flags;
  577. if (c->lna == 1)
  578. flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
  579. else
  580. flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
  581. ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
  582. if (ret)
  583. em28xx_errdev("gpio request failed %d\n", ret);
  584. else
  585. gpio_free(dvb->lna_gpio);
  586. return ret;
  587. #else
  588. dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
  589. KBUILD_MODNAME, c->lna);
  590. return 0;
  591. #endif
  592. }
  593. static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
  594. {
  595. /* Values extracted from a USB trace of the Terratec Windows driver */
  596. static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
  597. static u8 reset[] = { RESET, 0x80 };
  598. static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
  599. static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
  600. static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
  601. static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
  602. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  603. static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
  604. static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
  605. static u8 tuner_go[] = { TUNER_GO, 0x01};
  606. mt352_write(fe, clock_config, sizeof(clock_config));
  607. udelay(200);
  608. mt352_write(fe, reset, sizeof(reset));
  609. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  610. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  611. mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
  612. mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
  613. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  614. mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
  615. mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
  616. mt352_write(fe, tuner_go, sizeof(tuner_go));
  617. return 0;
  618. }
  619. static struct mt352_config terratec_xs_mt352_cfg = {
  620. .demod_address = (0x1e >> 1),
  621. .no_tuner = 1,
  622. .if2 = 45600,
  623. .demod_init = em28xx_mt352_terratec_xs_init,
  624. };
  625. static struct tda10023_config em28xx_tda10023_config = {
  626. .demod_address = 0x0c,
  627. .invert = 1,
  628. };
  629. static struct cxd2820r_config em28xx_cxd2820r_config = {
  630. .i2c_address = (0xd8 >> 1),
  631. .ts_mode = CXD2820R_TS_SERIAL,
  632. };
  633. static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
  634. .output_opt = TDA18271_OUTPUT_LT_OFF,
  635. .gate = TDA18271_GATE_DIGITAL,
  636. };
  637. static const struct tda10071_config em28xx_tda10071_config = {
  638. .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
  639. .tuner_i2c_addr = 0x14,
  640. .i2c_wr_max = 64,
  641. .ts_mode = TDA10071_TS_SERIAL,
  642. .spec_inv = 0,
  643. .xtal = 40444000, /* 40.444 MHz */
  644. .pll_multiplier = 20,
  645. };
  646. static const struct a8293_config em28xx_a8293_config = {
  647. .i2c_addr = 0x08, /* (0x10 >> 1) */
  648. };
  649. static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
  650. .demod_address = (0x1e >> 1),
  651. .disable_i2c_gate_ctrl = 1,
  652. .no_tuner = 1,
  653. .parallel_ts = 1,
  654. };
  655. static struct qt1010_config em28xx_qt1010_config = {
  656. .i2c_address = 0x62
  657. };
  658. static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
  659. .demod_address = 0x10,
  660. .is_serial = true,
  661. };
  662. static struct tda18271_std_map mb86a20s_tda18271_config = {
  663. .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
  664. .if_lvl = 1, .rfagc_top = 0x37, },
  665. };
  666. static struct tda18271_config c3tech_duo_tda18271_config = {
  667. .std_map = &mb86a20s_tda18271_config,
  668. .gate = TDA18271_GATE_DIGITAL,
  669. .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
  670. };
  671. /* ------------------------------------------------------------------ */
  672. static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
  673. {
  674. struct dvb_frontend *fe;
  675. struct xc2028_config cfg;
  676. memset(&cfg, 0, sizeof(cfg));
  677. cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
  678. cfg.i2c_addr = addr;
  679. if (!dev->dvb->fe[0]) {
  680. em28xx_errdev("/2: dvb frontend not attached. "
  681. "Can't attach xc3028\n");
  682. return -EINVAL;
  683. }
  684. fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
  685. if (!fe) {
  686. em28xx_errdev("/2: xc3028 attach failed\n");
  687. dvb_frontend_detach(dev->dvb->fe[0]);
  688. dev->dvb->fe[0] = NULL;
  689. return -EINVAL;
  690. }
  691. em28xx_info("%s/2: xc3028 attached\n", dev->name);
  692. return 0;
  693. }
  694. /* ------------------------------------------------------------------ */
  695. static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
  696. struct em28xx *dev, struct device *device)
  697. {
  698. int result;
  699. mutex_init(&dvb->lock);
  700. /* register adapter */
  701. result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
  702. adapter_nr);
  703. if (result < 0) {
  704. printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
  705. dev->name, result);
  706. goto fail_adapter;
  707. }
  708. /* Ensure all frontends negotiate bus access */
  709. dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  710. if (dvb->fe[1])
  711. dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
  712. dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
  713. /* register frontend */
  714. result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
  715. if (result < 0) {
  716. printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
  717. dev->name, result);
  718. goto fail_frontend0;
  719. }
  720. /* register 2nd frontend */
  721. if (dvb->fe[1]) {
  722. result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
  723. if (result < 0) {
  724. printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
  725. dev->name, result);
  726. goto fail_frontend1;
  727. }
  728. }
  729. /* register demux stuff */
  730. dvb->demux.dmx.capabilities =
  731. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  732. DMX_MEMORY_BASED_FILTERING;
  733. dvb->demux.priv = dvb;
  734. dvb->demux.filternum = 256;
  735. dvb->demux.feednum = 256;
  736. dvb->demux.start_feed = em28xx_start_feed;
  737. dvb->demux.stop_feed = em28xx_stop_feed;
  738. result = dvb_dmx_init(&dvb->demux);
  739. if (result < 0) {
  740. printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
  741. dev->name, result);
  742. goto fail_dmx;
  743. }
  744. dvb->dmxdev.filternum = 256;
  745. dvb->dmxdev.demux = &dvb->demux.dmx;
  746. dvb->dmxdev.capabilities = 0;
  747. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  748. if (result < 0) {
  749. printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
  750. dev->name, result);
  751. goto fail_dmxdev;
  752. }
  753. dvb->fe_hw.source = DMX_FRONTEND_0;
  754. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  755. if (result < 0) {
  756. printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  757. dev->name, result);
  758. goto fail_fe_hw;
  759. }
  760. dvb->fe_mem.source = DMX_MEMORY_FE;
  761. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  762. if (result < 0) {
  763. printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  764. dev->name, result);
  765. goto fail_fe_mem;
  766. }
  767. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  768. if (result < 0) {
  769. printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
  770. dev->name, result);
  771. goto fail_fe_conn;
  772. }
  773. /* register network adapter */
  774. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  775. return 0;
  776. fail_fe_conn:
  777. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  778. fail_fe_mem:
  779. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  780. fail_fe_hw:
  781. dvb_dmxdev_release(&dvb->dmxdev);
  782. fail_dmxdev:
  783. dvb_dmx_release(&dvb->demux);
  784. fail_dmx:
  785. if (dvb->fe[1])
  786. dvb_unregister_frontend(dvb->fe[1]);
  787. dvb_unregister_frontend(dvb->fe[0]);
  788. fail_frontend1:
  789. if (dvb->fe[1])
  790. dvb_frontend_detach(dvb->fe[1]);
  791. fail_frontend0:
  792. dvb_frontend_detach(dvb->fe[0]);
  793. dvb_unregister_adapter(&dvb->adapter);
  794. fail_adapter:
  795. return result;
  796. }
  797. static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
  798. {
  799. dvb_net_release(&dvb->net);
  800. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  801. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  802. dvb_dmxdev_release(&dvb->dmxdev);
  803. dvb_dmx_release(&dvb->demux);
  804. if (dvb->fe[1])
  805. dvb_unregister_frontend(dvb->fe[1]);
  806. dvb_unregister_frontend(dvb->fe[0]);
  807. if (dvb->fe[1] && !dvb->dont_attach_fe1)
  808. dvb_frontend_detach(dvb->fe[1]);
  809. dvb_frontend_detach(dvb->fe[0]);
  810. dvb_unregister_adapter(&dvb->adapter);
  811. }
  812. static int em28xx_dvb_init(struct em28xx *dev)
  813. {
  814. int result = 0, mfe_shared = 0;
  815. struct em28xx_dvb *dvb;
  816. if (!dev->board.has_dvb) {
  817. /* This device does not support the extension */
  818. printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
  819. return 0;
  820. }
  821. dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
  822. if (dvb == NULL) {
  823. em28xx_info("em28xx_dvb: memory allocation failed\n");
  824. return -ENOMEM;
  825. }
  826. dev->dvb = dvb;
  827. dvb->fe[0] = dvb->fe[1] = NULL;
  828. mutex_lock(&dev->lock);
  829. em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
  830. /* init frontend */
  831. switch (dev->model) {
  832. case EM2874_BOARD_LEADERSHIP_ISDBT:
  833. dvb->fe[0] = dvb_attach(s921_attach,
  834. &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
  835. if (!dvb->fe[0]) {
  836. result = -EINVAL;
  837. goto out_free;
  838. }
  839. break;
  840. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
  841. case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
  842. case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
  843. case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
  844. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  845. &em2880_lgdt3303_dev,
  846. &dev->i2c_adap[dev->def_i2c_bus]);
  847. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  848. result = -EINVAL;
  849. goto out_free;
  850. }
  851. break;
  852. case EM2880_BOARD_KWORLD_DVB_310U:
  853. dvb->fe[0] = dvb_attach(zl10353_attach,
  854. &em28xx_zl10353_with_xc3028,
  855. &dev->i2c_adap[dev->def_i2c_bus]);
  856. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  857. result = -EINVAL;
  858. goto out_free;
  859. }
  860. break;
  861. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  862. case EM2882_BOARD_TERRATEC_HYBRID_XS:
  863. case EM2880_BOARD_EMPIRE_DUAL_TV:
  864. dvb->fe[0] = dvb_attach(zl10353_attach,
  865. &em28xx_zl10353_xc3028_no_i2c_gate,
  866. &dev->i2c_adap[dev->def_i2c_bus]);
  867. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  868. result = -EINVAL;
  869. goto out_free;
  870. }
  871. break;
  872. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  873. case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
  874. case EM2881_BOARD_PINNACLE_HYBRID_PRO:
  875. case EM2882_BOARD_DIKOM_DK300:
  876. case EM2882_BOARD_KWORLD_VS_DVBT:
  877. dvb->fe[0] = dvb_attach(zl10353_attach,
  878. &em28xx_zl10353_xc3028_no_i2c_gate,
  879. &dev->i2c_adap[dev->def_i2c_bus]);
  880. if (dvb->fe[0] == NULL) {
  881. /* This board could have either a zl10353 or a mt352.
  882. If the chip id isn't for zl10353, try mt352 */
  883. dvb->fe[0] = dvb_attach(mt352_attach,
  884. &terratec_xs_mt352_cfg,
  885. &dev->i2c_adap[dev->def_i2c_bus]);
  886. }
  887. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  888. result = -EINVAL;
  889. goto out_free;
  890. }
  891. break;
  892. case EM2870_BOARD_KWORLD_355U:
  893. dvb->fe[0] = dvb_attach(zl10353_attach,
  894. &em28xx_zl10353_no_i2c_gate_dev,
  895. &dev->i2c_adap[dev->def_i2c_bus]);
  896. if (dvb->fe[0] != NULL)
  897. dvb_attach(qt1010_attach, dvb->fe[0],
  898. &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
  899. break;
  900. case EM2883_BOARD_KWORLD_HYBRID_330U:
  901. case EM2882_BOARD_EVGA_INDTUBE:
  902. dvb->fe[0] = dvb_attach(s5h1409_attach,
  903. &em28xx_s5h1409_with_xc3028,
  904. &dev->i2c_adap[dev->def_i2c_bus]);
  905. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  906. result = -EINVAL;
  907. goto out_free;
  908. }
  909. break;
  910. case EM2882_BOARD_KWORLD_ATSC_315U:
  911. dvb->fe[0] = dvb_attach(lgdt330x_attach,
  912. &em2880_lgdt3303_dev,
  913. &dev->i2c_adap[dev->def_i2c_bus]);
  914. if (dvb->fe[0] != NULL) {
  915. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  916. &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
  917. result = -EINVAL;
  918. goto out_free;
  919. }
  920. }
  921. break;
  922. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
  923. case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
  924. dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
  925. &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
  926. if (em28xx_attach_xc3028(0x61, dev) < 0) {
  927. result = -EINVAL;
  928. goto out_free;
  929. }
  930. break;
  931. case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
  932. /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
  933. dvb->fe[0] = dvb_attach(tda10023_attach,
  934. &em28xx_tda10023_config,
  935. &dev->i2c_adap[dev->def_i2c_bus], 0x48);
  936. if (dvb->fe[0]) {
  937. if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
  938. &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
  939. result = -EINVAL;
  940. goto out_free;
  941. }
  942. }
  943. break;
  944. case EM2870_BOARD_KWORLD_A340:
  945. dvb->fe[0] = dvb_attach(lgdt3305_attach,
  946. &em2870_lgdt3304_dev,
  947. &dev->i2c_adap[dev->def_i2c_bus]);
  948. if (dvb->fe[0] != NULL)
  949. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  950. &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
  951. break;
  952. case EM28174_BOARD_PCTV_290E:
  953. /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
  954. dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
  955. CXD2820R_GPIO_L;
  956. dvb->fe[0] = dvb_attach(cxd2820r_attach,
  957. &em28xx_cxd2820r_config,
  958. &dev->i2c_adap[dev->def_i2c_bus],
  959. &dvb->lna_gpio);
  960. if (dvb->fe[0]) {
  961. /* FE 0 attach tuner */
  962. if (!dvb_attach(tda18271_attach,
  963. dvb->fe[0],
  964. 0x60,
  965. &dev->i2c_adap[dev->def_i2c_bus],
  966. &em28xx_cxd2820r_tda18271_config)) {
  967. dvb_frontend_detach(dvb->fe[0]);
  968. result = -EINVAL;
  969. goto out_free;
  970. }
  971. #ifdef CONFIG_GPIOLIB
  972. /* enable LNA for DVB-T, DVB-T2 and DVB-C */
  973. result = gpio_request_one(dvb->lna_gpio,
  974. GPIOF_OUT_INIT_LOW, NULL);
  975. if (result)
  976. em28xx_errdev("gpio request failed %d\n",
  977. result);
  978. else
  979. gpio_free(dvb->lna_gpio);
  980. result = 0; /* continue even set LNA fails */
  981. #endif
  982. dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
  983. }
  984. break;
  985. case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
  986. {
  987. struct xc5000_config cfg;
  988. hauppauge_hvr930c_init(dev);
  989. dvb->fe[0] = dvb_attach(drxk_attach,
  990. &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
  991. if (!dvb->fe[0]) {
  992. result = -EINVAL;
  993. goto out_free;
  994. }
  995. /* FIXME: do we need a pll semaphore? */
  996. dvb->fe[0]->sec_priv = dvb;
  997. sema_init(&dvb->pll_mutex, 1);
  998. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  999. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  1000. /* Attach xc5000 */
  1001. memset(&cfg, 0, sizeof(cfg));
  1002. cfg.i2c_address = 0x61;
  1003. cfg.if_khz = 4000;
  1004. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1005. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  1006. if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
  1007. &cfg)) {
  1008. result = -EINVAL;
  1009. goto out_free;
  1010. }
  1011. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1012. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  1013. break;
  1014. }
  1015. case EM2884_BOARD_TERRATEC_H5:
  1016. terratec_h5_init(dev);
  1017. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
  1018. if (!dvb->fe[0]) {
  1019. result = -EINVAL;
  1020. goto out_free;
  1021. }
  1022. /* FIXME: do we need a pll semaphore? */
  1023. dvb->fe[0]->sec_priv = dvb;
  1024. sema_init(&dvb->pll_mutex, 1);
  1025. dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
  1026. dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  1027. /* Attach tda18271 to DVB-C frontend */
  1028. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1029. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
  1030. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
  1031. result = -EINVAL;
  1032. goto out_free;
  1033. }
  1034. if (dvb->fe[0]->ops.i2c_gate_ctrl)
  1035. dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
  1036. break;
  1037. case EM2884_BOARD_C3TECH_DIGITAL_DUO:
  1038. dvb->fe[0] = dvb_attach(mb86a20s_attach,
  1039. &c3tech_duo_mb86a20s_config,
  1040. &dev->i2c_adap[dev->def_i2c_bus]);
  1041. if (dvb->fe[0] != NULL)
  1042. dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1043. &dev->i2c_adap[dev->def_i2c_bus],
  1044. &c3tech_duo_tda18271_config);
  1045. break;
  1046. case EM28174_BOARD_PCTV_460E:
  1047. /* attach demod */
  1048. dvb->fe[0] = dvb_attach(tda10071_attach,
  1049. &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
  1050. /* attach SEC */
  1051. if (dvb->fe[0])
  1052. dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
  1053. &em28xx_a8293_config);
  1054. break;
  1055. case EM2874_BOARD_DELOCK_61959:
  1056. case EM2874_BOARD_MAXMEDIA_UB425_TC:
  1057. /* attach demodulator */
  1058. dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
  1059. &dev->i2c_adap[dev->def_i2c_bus]);
  1060. if (dvb->fe[0]) {
  1061. /* disable I2C-gate */
  1062. dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
  1063. /* attach tuner */
  1064. if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
  1065. &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
  1066. dvb_frontend_detach(dvb->fe[0]);
  1067. result = -EINVAL;
  1068. goto out_free;
  1069. }
  1070. }
  1071. /* TODO: we need drx-3913k firmware in order to support DVB-T */
  1072. em28xx_info("MaxMedia UB425-TC/Delock 61959: only DVB-C " \
  1073. "supported by that driver version\n");
  1074. break;
  1075. case EM2884_BOARD_PCTV_510E:
  1076. case EM2884_BOARD_PCTV_520E:
  1077. pctv_520e_init(dev);
  1078. /* attach demodulator */
  1079. dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
  1080. &dev->i2c_adap[dev->def_i2c_bus]);
  1081. if (dvb->fe[0]) {
  1082. /* attach tuner */
  1083. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1084. &dev->i2c_adap[dev->def_i2c_bus],
  1085. &em28xx_cxd2820r_tda18271_config)) {
  1086. dvb_frontend_detach(dvb->fe[0]);
  1087. result = -EINVAL;
  1088. goto out_free;
  1089. }
  1090. }
  1091. break;
  1092. case EM2884_BOARD_CINERGY_HTC_STICK:
  1093. terratec_htc_stick_init(dev);
  1094. /* attach demodulator */
  1095. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1096. &dev->i2c_adap[dev->def_i2c_bus]);
  1097. if (!dvb->fe[0]) {
  1098. result = -EINVAL;
  1099. goto out_free;
  1100. }
  1101. /* Attach the demodulator. */
  1102. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1103. &dev->i2c_adap[dev->def_i2c_bus],
  1104. &em28xx_cxd2820r_tda18271_config)) {
  1105. result = -EINVAL;
  1106. goto out_free;
  1107. }
  1108. break;
  1109. case EM2884_BOARD_TERRATEC_HTC_USB_XS:
  1110. terratec_htc_usb_xs_init(dev);
  1111. /* attach demodulator */
  1112. dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
  1113. &dev->i2c_adap[dev->def_i2c_bus]);
  1114. if (!dvb->fe[0]) {
  1115. result = -EINVAL;
  1116. goto out_free;
  1117. }
  1118. /* Attach the demodulator. */
  1119. if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
  1120. &dev->i2c_adap[dev->def_i2c_bus],
  1121. &em28xx_cxd2820r_tda18271_config)) {
  1122. result = -EINVAL;
  1123. goto out_free;
  1124. }
  1125. break;
  1126. default:
  1127. em28xx_errdev("/2: The frontend of your DVB/ATSC card"
  1128. " isn't supported yet\n");
  1129. break;
  1130. }
  1131. if (NULL == dvb->fe[0]) {
  1132. em28xx_errdev("/2: frontend initialization failed\n");
  1133. result = -EINVAL;
  1134. goto out_free;
  1135. }
  1136. /* define general-purpose callback pointer */
  1137. dvb->fe[0]->callback = em28xx_tuner_callback;
  1138. if (dvb->fe[1])
  1139. dvb->fe[1]->callback = em28xx_tuner_callback;
  1140. /* register everything */
  1141. result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
  1142. if (result < 0)
  1143. goto out_free;
  1144. /* MFE lock */
  1145. dvb->adapter.mfe_shared = mfe_shared;
  1146. em28xx_info("Successfully loaded em28xx-dvb\n");
  1147. ret:
  1148. em28xx_set_mode(dev, EM28XX_SUSPEND);
  1149. mutex_unlock(&dev->lock);
  1150. return result;
  1151. out_free:
  1152. kfree(dvb);
  1153. dev->dvb = NULL;
  1154. goto ret;
  1155. }
  1156. static inline void prevent_sleep(struct dvb_frontend_ops *ops)
  1157. {
  1158. ops->set_voltage = NULL;
  1159. ops->sleep = NULL;
  1160. ops->tuner_ops.sleep = NULL;
  1161. }
  1162. static int em28xx_dvb_fini(struct em28xx *dev)
  1163. {
  1164. if (!dev->board.has_dvb) {
  1165. /* This device does not support the extension */
  1166. return 0;
  1167. }
  1168. if (dev->dvb) {
  1169. struct em28xx_dvb *dvb = dev->dvb;
  1170. if (dev->disconnected) {
  1171. /* We cannot tell the device to sleep
  1172. * once it has been unplugged. */
  1173. if (dvb->fe[0])
  1174. prevent_sleep(&dvb->fe[0]->ops);
  1175. if (dvb->fe[1])
  1176. prevent_sleep(&dvb->fe[1]->ops);
  1177. }
  1178. em28xx_unregister_dvb(dvb);
  1179. kfree(dvb);
  1180. dev->dvb = NULL;
  1181. }
  1182. return 0;
  1183. }
  1184. static struct em28xx_ops dvb_ops = {
  1185. .id = EM28XX_DVB,
  1186. .name = "Em28xx dvb Extension",
  1187. .init = em28xx_dvb_init,
  1188. .fini = em28xx_dvb_fini,
  1189. };
  1190. static int __init em28xx_dvb_register(void)
  1191. {
  1192. return em28xx_register_extension(&dvb_ops);
  1193. }
  1194. static void __exit em28xx_dvb_unregister(void)
  1195. {
  1196. em28xx_unregister_extension(&dvb_ops);
  1197. }
  1198. module_init(em28xx_dvb_register);
  1199. module_exit(em28xx_dvb_unregister);