cx18-dvb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * cx18 functions for DVB support
  3. *
  4. * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
  5. * Copyright (C) 2008 Andy Walls <awalls@md.metrocast.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. *
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include "cx18-version.h"
  23. #include "cx18-dvb.h"
  24. #include "cx18-io.h"
  25. #include "cx18-queue.h"
  26. #include "cx18-streams.h"
  27. #include "cx18-cards.h"
  28. #include "cx18-gpio.h"
  29. #include "s5h1409.h"
  30. #include "mxl5005s.h"
  31. #include "s5h1411.h"
  32. #include "tda18271.h"
  33. #include "zl10353.h"
  34. #include <linux/firmware.h>
  35. #include "mt352.h"
  36. #include "mt352_priv.h"
  37. #include "tuner-xc2028.h"
  38. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  39. #define CX18_REG_DMUX_NUM_PORT_0_CONTROL 0xd5a000
  40. #define CX18_CLOCK_ENABLE2 0xc71024
  41. #define CX18_DMUX_CLK_MASK 0x0080
  42. /*
  43. * CX18_CARD_HVR_1600_ESMT
  44. * CX18_CARD_HVR_1600_SAMSUNG
  45. */
  46. static struct mxl5005s_config hauppauge_hvr1600_tuner = {
  47. .i2c_address = 0xC6 >> 1,
  48. .if_freq = IF_FREQ_5380000HZ,
  49. .xtal_freq = CRYSTAL_FREQ_16000000HZ,
  50. .agc_mode = MXL_SINGLE_AGC,
  51. .tracking_filter = MXL_TF_C_H,
  52. .rssi_enable = MXL_RSSI_ENABLE,
  53. .cap_select = MXL_CAP_SEL_ENABLE,
  54. .div_out = MXL_DIV_OUT_4,
  55. .clock_out = MXL_CLOCK_OUT_DISABLE,
  56. .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
  57. .top = MXL5005S_TOP_25P2,
  58. .mod_mode = MXL_DIGITAL_MODE,
  59. .if_mode = MXL_ZERO_IF,
  60. .qam_gain = 0x02,
  61. .AgcMasterByte = 0x00,
  62. };
  63. static struct s5h1409_config hauppauge_hvr1600_config = {
  64. .demod_address = 0x32 >> 1,
  65. .output_mode = S5H1409_SERIAL_OUTPUT,
  66. .gpio = S5H1409_GPIO_ON,
  67. .qam_if = 44000,
  68. .inversion = S5H1409_INVERSION_OFF,
  69. .status_mode = S5H1409_DEMODLOCKING,
  70. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  71. .hvr1600_opt = S5H1409_HVR1600_OPTIMIZE
  72. };
  73. /*
  74. * CX18_CARD_HVR_1600_S5H1411
  75. */
  76. static struct s5h1411_config hcw_s5h1411_config = {
  77. .output_mode = S5H1411_SERIAL_OUTPUT,
  78. .gpio = S5H1411_GPIO_OFF,
  79. .vsb_if = S5H1411_IF_44000,
  80. .qam_if = S5H1411_IF_4000,
  81. .inversion = S5H1411_INVERSION_ON,
  82. .status_mode = S5H1411_DEMODLOCKING,
  83. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  84. };
  85. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  86. .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
  87. .if_lvl = 6, .rfagc_top = 0x37 },
  88. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  89. .if_lvl = 6, .rfagc_top = 0x37 },
  90. };
  91. static struct tda18271_config hauppauge_tda18271_config = {
  92. .std_map = &hauppauge_tda18271_std_map,
  93. .gate = TDA18271_GATE_DIGITAL,
  94. .output_opt = TDA18271_OUTPUT_LT_OFF,
  95. };
  96. /*
  97. * CX18_CARD_LEADTEK_DVR3100H
  98. */
  99. /* Information/confirmation of proper config values provided by Terry Wu */
  100. static struct zl10353_config leadtek_dvr3100h_demod = {
  101. .demod_address = 0x1e >> 1, /* Datasheet suggested straps */
  102. .if2 = 45600, /* 4.560 MHz IF from the XC3028 */
  103. .parallel_ts = 1, /* Not a serial TS */
  104. .no_tuner = 1, /* XC3028 is not behind the gate */
  105. .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */
  106. };
  107. /*
  108. * CX18_CARD_YUAN_MPC718
  109. */
  110. /*
  111. * Due to
  112. *
  113. * 1. an absence of information on how to prgram the MT352
  114. * 2. the Linux mt352 module pushing MT352 initialzation off onto us here
  115. *
  116. * We have to use an init sequence that *you* must extract from the Windows
  117. * driver (yuanrap.sys) and which we load as a firmware.
  118. *
  119. * If someone can provide me with a Zarlink MT352 (Intel CE6352?) Design Manual
  120. * with chip programming details, then I can remove this annoyance.
  121. */
  122. static int yuan_mpc718_mt352_reqfw(struct cx18_stream *stream,
  123. const struct firmware **fw)
  124. {
  125. struct cx18 *cx = stream->cx;
  126. const char *fn = "dvb-cx18-mpc718-mt352.fw";
  127. int ret;
  128. ret = request_firmware(fw, fn, &cx->pci_dev->dev);
  129. if (ret)
  130. CX18_ERR("Unable to open firmware file %s\n", fn);
  131. else {
  132. size_t sz = (*fw)->size;
  133. if (sz < 2 || sz > 64 || (sz % 2) != 0) {
  134. CX18_ERR("Firmware %s has a bad size: %lu bytes\n",
  135. fn, (unsigned long) sz);
  136. ret = -EILSEQ;
  137. release_firmware(*fw);
  138. *fw = NULL;
  139. }
  140. }
  141. if (ret) {
  142. CX18_ERR("The MPC718 board variant with the MT352 DVB-T"
  143. "demodualtor will not work without it\n");
  144. CX18_ERR("Run 'linux/Documentation/dvb/get_dvb_firmware "
  145. "mpc718' if you need the firmware\n");
  146. }
  147. return ret;
  148. }
  149. static int yuan_mpc718_mt352_init(struct dvb_frontend *fe)
  150. {
  151. struct cx18_dvb *dvb = container_of(fe->dvb,
  152. struct cx18_dvb, dvb_adapter);
  153. struct cx18_stream *stream = dvb->stream;
  154. const struct firmware *fw = NULL;
  155. int ret;
  156. int i;
  157. u8 buf[3];
  158. ret = yuan_mpc718_mt352_reqfw(stream, &fw);
  159. if (ret)
  160. return ret;
  161. /* Loop through all the register-value pairs in the firmware file */
  162. for (i = 0; i < fw->size; i += 2) {
  163. buf[0] = fw->data[i];
  164. /* Intercept a few registers we want to set ourselves */
  165. switch (buf[0]) {
  166. case TRL_NOMINAL_RATE_0:
  167. /* Set our custom OFDM bandwidth in the case below */
  168. break;
  169. case TRL_NOMINAL_RATE_1:
  170. /* 6 MHz: 64/7 * 6/8 / 20.48 * 2^16 = 0x55b6.db6 */
  171. /* 7 MHz: 64/7 * 7/8 / 20.48 * 2^16 = 0x6400 */
  172. /* 8 MHz: 64/7 * 8/8 / 20.48 * 2^16 = 0x7249.249 */
  173. buf[1] = 0x72;
  174. buf[2] = 0x49;
  175. mt352_write(fe, buf, 3);
  176. break;
  177. case INPUT_FREQ_0:
  178. /* Set our custom IF in the case below */
  179. break;
  180. case INPUT_FREQ_1:
  181. /* 4.56 MHz IF: (20.48 - 4.56)/20.48 * 2^14 = 0x31c0 */
  182. buf[1] = 0x31;
  183. buf[2] = 0xc0;
  184. mt352_write(fe, buf, 3);
  185. break;
  186. default:
  187. /* Pass through the register-value pair from the fw */
  188. buf[1] = fw->data[i+1];
  189. mt352_write(fe, buf, 2);
  190. break;
  191. }
  192. }
  193. buf[0] = (u8) TUNER_GO;
  194. buf[1] = 0x01; /* Go */
  195. mt352_write(fe, buf, 2);
  196. release_firmware(fw);
  197. return 0;
  198. }
  199. static struct mt352_config yuan_mpc718_mt352_demod = {
  200. .demod_address = 0x1e >> 1,
  201. .adc_clock = 20480, /* 20.480 MHz */
  202. .if2 = 4560, /* 4.560 MHz */
  203. .no_tuner = 1, /* XC3028 is not behind the gate */
  204. .demod_init = yuan_mpc718_mt352_init,
  205. };
  206. static struct zl10353_config yuan_mpc718_zl10353_demod = {
  207. .demod_address = 0x1e >> 1, /* Datasheet suggested straps */
  208. .if2 = 45600, /* 4.560 MHz IF from the XC3028 */
  209. .parallel_ts = 1, /* Not a serial TS */
  210. .no_tuner = 1, /* XC3028 is not behind the gate */
  211. .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */
  212. };
  213. static struct zl10353_config gotview_dvd3_zl10353_demod = {
  214. .demod_address = 0x1e >> 1, /* Datasheet suggested straps */
  215. .if2 = 45600, /* 4.560 MHz IF from the XC3028 */
  216. .parallel_ts = 1, /* Not a serial TS */
  217. .no_tuner = 1, /* XC3028 is not behind the gate */
  218. .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */
  219. };
  220. static int dvb_register(struct cx18_stream *stream);
  221. /* Kernel DVB framework calls this when the feed needs to start.
  222. * The CX18 framework should enable the transport DMA handling
  223. * and queue processing.
  224. */
  225. static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
  226. {
  227. struct dvb_demux *demux = feed->demux;
  228. struct cx18_stream *stream = (struct cx18_stream *) demux->priv;
  229. struct cx18 *cx;
  230. int ret;
  231. u32 v;
  232. if (!stream)
  233. return -EINVAL;
  234. cx = stream->cx;
  235. CX18_DEBUG_INFO("Start feed: pid = 0x%x index = %d\n",
  236. feed->pid, feed->index);
  237. mutex_lock(&cx->serialize_lock);
  238. ret = cx18_init_on_first_open(cx);
  239. mutex_unlock(&cx->serialize_lock);
  240. if (ret) {
  241. CX18_ERR("Failed to initialize firmware starting DVB feed\n");
  242. return ret;
  243. }
  244. ret = -EINVAL;
  245. switch (cx->card->type) {
  246. case CX18_CARD_HVR_1600_ESMT:
  247. case CX18_CARD_HVR_1600_SAMSUNG:
  248. case CX18_CARD_HVR_1600_S5H1411:
  249. v = cx18_read_reg(cx, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
  250. v |= 0x00400000; /* Serial Mode */
  251. v |= 0x00002000; /* Data Length - Byte */
  252. v |= 0x00010000; /* Error - Polarity */
  253. v |= 0x00020000; /* Error - Passthru */
  254. v |= 0x000c0000; /* Error - Ignore */
  255. cx18_write_reg(cx, v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
  256. break;
  257. case CX18_CARD_LEADTEK_DVR3100H:
  258. case CX18_CARD_YUAN_MPC718:
  259. case CX18_CARD_GOTVIEW_PCI_DVD3:
  260. default:
  261. /* Assumption - Parallel transport - Signalling
  262. * undefined or default.
  263. */
  264. break;
  265. }
  266. if (!demux->dmx.frontend)
  267. return -EINVAL;
  268. mutex_lock(&stream->dvb->feedlock);
  269. if (stream->dvb->feeding++ == 0) {
  270. CX18_DEBUG_INFO("Starting Transport DMA\n");
  271. mutex_lock(&cx->serialize_lock);
  272. set_bit(CX18_F_S_STREAMING, &stream->s_flags);
  273. ret = cx18_start_v4l2_encode_stream(stream);
  274. if (ret < 0) {
  275. CX18_DEBUG_INFO("Failed to start Transport DMA\n");
  276. stream->dvb->feeding--;
  277. if (stream->dvb->feeding == 0)
  278. clear_bit(CX18_F_S_STREAMING, &stream->s_flags);
  279. }
  280. mutex_unlock(&cx->serialize_lock);
  281. } else
  282. ret = 0;
  283. mutex_unlock(&stream->dvb->feedlock);
  284. return ret;
  285. }
  286. /* Kernel DVB framework calls this when the feed needs to stop. */
  287. static int cx18_dvb_stop_feed(struct dvb_demux_feed *feed)
  288. {
  289. struct dvb_demux *demux = feed->demux;
  290. struct cx18_stream *stream = (struct cx18_stream *)demux->priv;
  291. struct cx18 *cx;
  292. int ret = -EINVAL;
  293. if (stream) {
  294. cx = stream->cx;
  295. CX18_DEBUG_INFO("Stop feed: pid = 0x%x index = %d\n",
  296. feed->pid, feed->index);
  297. mutex_lock(&stream->dvb->feedlock);
  298. if (--stream->dvb->feeding == 0) {
  299. CX18_DEBUG_INFO("Stopping Transport DMA\n");
  300. mutex_lock(&cx->serialize_lock);
  301. ret = cx18_stop_v4l2_encode_stream(stream, 0);
  302. mutex_unlock(&cx->serialize_lock);
  303. } else
  304. ret = 0;
  305. mutex_unlock(&stream->dvb->feedlock);
  306. }
  307. return ret;
  308. }
  309. int cx18_dvb_register(struct cx18_stream *stream)
  310. {
  311. struct cx18 *cx = stream->cx;
  312. struct cx18_dvb *dvb = stream->dvb;
  313. struct dvb_adapter *dvb_adapter;
  314. struct dvb_demux *dvbdemux;
  315. struct dmx_demux *dmx;
  316. int ret;
  317. if (!dvb)
  318. return -EINVAL;
  319. dvb->enabled = 0;
  320. dvb->stream = stream;
  321. ret = dvb_register_adapter(&dvb->dvb_adapter,
  322. CX18_DRIVER_NAME,
  323. THIS_MODULE, &cx->pci_dev->dev, adapter_nr);
  324. if (ret < 0)
  325. goto err_out;
  326. dvb_adapter = &dvb->dvb_adapter;
  327. dvbdemux = &dvb->demux;
  328. dvbdemux->priv = (void *)stream;
  329. dvbdemux->filternum = 256;
  330. dvbdemux->feednum = 256;
  331. dvbdemux->start_feed = cx18_dvb_start_feed;
  332. dvbdemux->stop_feed = cx18_dvb_stop_feed;
  333. dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
  334. DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
  335. ret = dvb_dmx_init(dvbdemux);
  336. if (ret < 0)
  337. goto err_dvb_unregister_adapter;
  338. dmx = &dvbdemux->dmx;
  339. dvb->hw_frontend.source = DMX_FRONTEND_0;
  340. dvb->mem_frontend.source = DMX_MEMORY_FE;
  341. dvb->dmxdev.filternum = 256;
  342. dvb->dmxdev.demux = dmx;
  343. ret = dvb_dmxdev_init(&dvb->dmxdev, dvb_adapter);
  344. if (ret < 0)
  345. goto err_dvb_dmx_release;
  346. ret = dmx->add_frontend(dmx, &dvb->hw_frontend);
  347. if (ret < 0)
  348. goto err_dvb_dmxdev_release;
  349. ret = dmx->add_frontend(dmx, &dvb->mem_frontend);
  350. if (ret < 0)
  351. goto err_remove_hw_frontend;
  352. ret = dmx->connect_frontend(dmx, &dvb->hw_frontend);
  353. if (ret < 0)
  354. goto err_remove_mem_frontend;
  355. ret = dvb_register(stream);
  356. if (ret < 0)
  357. goto err_disconnect_frontend;
  358. dvb_net_init(dvb_adapter, &dvb->dvbnet, dmx);
  359. CX18_INFO("DVB Frontend registered\n");
  360. CX18_INFO("Registered DVB adapter%d for %s (%d x %d.%02d kB)\n",
  361. stream->dvb->dvb_adapter.num, stream->name,
  362. stream->buffers, stream->buf_size/1024,
  363. (stream->buf_size * 100 / 1024) % 100);
  364. mutex_init(&dvb->feedlock);
  365. dvb->enabled = 1;
  366. return ret;
  367. err_disconnect_frontend:
  368. dmx->disconnect_frontend(dmx);
  369. err_remove_mem_frontend:
  370. dmx->remove_frontend(dmx, &dvb->mem_frontend);
  371. err_remove_hw_frontend:
  372. dmx->remove_frontend(dmx, &dvb->hw_frontend);
  373. err_dvb_dmxdev_release:
  374. dvb_dmxdev_release(&dvb->dmxdev);
  375. err_dvb_dmx_release:
  376. dvb_dmx_release(dvbdemux);
  377. err_dvb_unregister_adapter:
  378. dvb_unregister_adapter(dvb_adapter);
  379. err_out:
  380. return ret;
  381. }
  382. void cx18_dvb_unregister(struct cx18_stream *stream)
  383. {
  384. struct cx18 *cx = stream->cx;
  385. struct cx18_dvb *dvb = stream->dvb;
  386. struct dvb_adapter *dvb_adapter;
  387. struct dvb_demux *dvbdemux;
  388. struct dmx_demux *dmx;
  389. CX18_INFO("unregister DVB\n");
  390. if (dvb == NULL || !dvb->enabled)
  391. return;
  392. dvb_adapter = &dvb->dvb_adapter;
  393. dvbdemux = &dvb->demux;
  394. dmx = &dvbdemux->dmx;
  395. dmx->close(dmx);
  396. dvb_net_release(&dvb->dvbnet);
  397. dmx->remove_frontend(dmx, &dvb->mem_frontend);
  398. dmx->remove_frontend(dmx, &dvb->hw_frontend);
  399. dvb_dmxdev_release(&dvb->dmxdev);
  400. dvb_dmx_release(dvbdemux);
  401. dvb_unregister_frontend(dvb->fe);
  402. dvb_frontend_detach(dvb->fe);
  403. dvb_unregister_adapter(dvb_adapter);
  404. }
  405. /* All the DVB attach calls go here, this function get's modified
  406. * for each new card. cx18_dvb_start_feed() will also need changes.
  407. */
  408. static int dvb_register(struct cx18_stream *stream)
  409. {
  410. struct cx18_dvb *dvb = stream->dvb;
  411. struct cx18 *cx = stream->cx;
  412. int ret = 0;
  413. switch (cx->card->type) {
  414. case CX18_CARD_HVR_1600_ESMT:
  415. case CX18_CARD_HVR_1600_SAMSUNG:
  416. dvb->fe = dvb_attach(s5h1409_attach,
  417. &hauppauge_hvr1600_config,
  418. &cx->i2c_adap[0]);
  419. if (dvb->fe != NULL) {
  420. dvb_attach(mxl5005s_attach, dvb->fe,
  421. &cx->i2c_adap[0],
  422. &hauppauge_hvr1600_tuner);
  423. ret = 0;
  424. }
  425. break;
  426. case CX18_CARD_HVR_1600_S5H1411:
  427. dvb->fe = dvb_attach(s5h1411_attach,
  428. &hcw_s5h1411_config,
  429. &cx->i2c_adap[0]);
  430. if (dvb->fe != NULL)
  431. dvb_attach(tda18271_attach, dvb->fe,
  432. 0x60, &cx->i2c_adap[0],
  433. &hauppauge_tda18271_config);
  434. break;
  435. case CX18_CARD_LEADTEK_DVR3100H:
  436. dvb->fe = dvb_attach(zl10353_attach,
  437. &leadtek_dvr3100h_demod,
  438. &cx->i2c_adap[1]);
  439. if (dvb->fe != NULL) {
  440. struct dvb_frontend *fe;
  441. struct xc2028_config cfg = {
  442. .i2c_adap = &cx->i2c_adap[1],
  443. .i2c_addr = 0xc2 >> 1,
  444. .ctrl = NULL,
  445. };
  446. static struct xc2028_ctrl ctrl = {
  447. .fname = XC2028_DEFAULT_FIRMWARE,
  448. .max_len = 64,
  449. .demod = XC3028_FE_ZARLINK456,
  450. .type = XC2028_AUTO,
  451. };
  452. fe = dvb_attach(xc2028_attach, dvb->fe, &cfg);
  453. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  454. fe->ops.tuner_ops.set_config(fe, &ctrl);
  455. }
  456. break;
  457. case CX18_CARD_YUAN_MPC718:
  458. /*
  459. * TODO
  460. * Apparently, these cards also could instead have a
  461. * DiBcom demod supported by one of the db7000 drivers
  462. */
  463. dvb->fe = dvb_attach(mt352_attach,
  464. &yuan_mpc718_mt352_demod,
  465. &cx->i2c_adap[1]);
  466. if (dvb->fe == NULL)
  467. dvb->fe = dvb_attach(zl10353_attach,
  468. &yuan_mpc718_zl10353_demod,
  469. &cx->i2c_adap[1]);
  470. if (dvb->fe != NULL) {
  471. struct dvb_frontend *fe;
  472. struct xc2028_config cfg = {
  473. .i2c_adap = &cx->i2c_adap[1],
  474. .i2c_addr = 0xc2 >> 1,
  475. .ctrl = NULL,
  476. };
  477. static struct xc2028_ctrl ctrl = {
  478. .fname = XC2028_DEFAULT_FIRMWARE,
  479. .max_len = 64,
  480. .demod = XC3028_FE_ZARLINK456,
  481. .type = XC2028_AUTO,
  482. };
  483. fe = dvb_attach(xc2028_attach, dvb->fe, &cfg);
  484. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  485. fe->ops.tuner_ops.set_config(fe, &ctrl);
  486. }
  487. break;
  488. case CX18_CARD_GOTVIEW_PCI_DVD3:
  489. dvb->fe = dvb_attach(zl10353_attach,
  490. &gotview_dvd3_zl10353_demod,
  491. &cx->i2c_adap[1]);
  492. if (dvb->fe != NULL) {
  493. struct dvb_frontend *fe;
  494. struct xc2028_config cfg = {
  495. .i2c_adap = &cx->i2c_adap[1],
  496. .i2c_addr = 0xc2 >> 1,
  497. .ctrl = NULL,
  498. };
  499. static struct xc2028_ctrl ctrl = {
  500. .fname = XC2028_DEFAULT_FIRMWARE,
  501. .max_len = 64,
  502. .demod = XC3028_FE_ZARLINK456,
  503. .type = XC2028_AUTO,
  504. };
  505. fe = dvb_attach(xc2028_attach, dvb->fe, &cfg);
  506. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  507. fe->ops.tuner_ops.set_config(fe, &ctrl);
  508. }
  509. break;
  510. default:
  511. /* No Digital Tv Support */
  512. break;
  513. }
  514. if (dvb->fe == NULL) {
  515. CX18_ERR("frontend initialization failed\n");
  516. return -1;
  517. }
  518. dvb->fe->callback = cx18_reset_tuner_gpio;
  519. ret = dvb_register_frontend(&dvb->dvb_adapter, dvb->fe);
  520. if (ret < 0) {
  521. if (dvb->fe->ops.release)
  522. dvb->fe->ops.release(dvb->fe);
  523. return ret;
  524. }
  525. /*
  526. * The firmware seems to enable the TS DMUX clock
  527. * under various circumstances. However, since we know we
  528. * might use it, let's just turn it on ourselves here.
  529. */
  530. cx18_write_reg_expect(cx,
  531. (CX18_DMUX_CLK_MASK << 16) | CX18_DMUX_CLK_MASK,
  532. CX18_CLOCK_ENABLE2,
  533. CX18_DMUX_CLK_MASK,
  534. (CX18_DMUX_CLK_MASK << 16) | CX18_DMUX_CLK_MASK);
  535. return ret;
  536. }